Remove the dance around old and new attributes. Just don't modify the
previous breakpoint at all until we have verified everything.

Reported-by: Linus Torvalds <[email protected]>
Original-patch-by: Andy Lutomirski <[email protected]>
Signed-off-by: Frederic Weisbecker <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Joel Fernandes <[email protected]>
---
 kernel/events/hw_breakpoint.c | 46 ++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index 7138770..b3814fc 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -461,37 +461,43 @@ register_user_hw_breakpoint(struct perf_event_attr *attr,
 }
 EXPORT_SYMBOL_GPL(register_user_hw_breakpoint);
 
+static void hw_breakpoint_copy_attr(struct perf_event_attr *to,
+                                   struct perf_event_attr *from)
+{
+       to->bp_addr = from->bp_addr;
+       to->bp_type = from->bp_type;
+       to->bp_len  = from->bp_len;
+       to->disabled = from->disabled;
+}
+
 int
 modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr 
*attr,
                                bool check)
 {
-       u64 old_addr = bp->attr.bp_addr;
-       u64 old_len  = bp->attr.bp_len;
-       int old_type = bp->attr.bp_type;
-       bool modify  = attr->bp_type != old_type;
        struct arch_hw_breakpoint hw;
-       int err = 0;
-
-       bp->attr.bp_addr = attr->bp_addr;
-       bp->attr.bp_type = attr->bp_type;
-       bp->attr.bp_len  = attr->bp_len;
-
-       if (check && memcmp(&bp->attr, attr, sizeof(*attr)))
-               return -EINVAL;
+       int err;
 
        err = hw_breakpoint_parse(bp, attr, &hw);
-       if (!err && modify)
-               err = modify_bp_slot(bp, old_type, bp->attr.bp_type);
-
-       if (err) {
-               bp->attr.bp_addr = old_addr;
-               bp->attr.bp_type = old_type;
-               bp->attr.bp_len  = old_len;
+       if (err)
                return err;
+
+       if (check) {
+               struct perf_event_attr old_attr;
+
+               old_attr = bp->attr;
+               hw_breakpoint_copy_attr(&old_attr, attr);
+               if (memcmp(&old_attr, attr, sizeof(*attr)))
+                       return -EINVAL;
+       }
+
+       if (bp->attr.bp_type != attr->bp_type) {
+               err = modify_bp_slot(bp, bp->attr.bp_type, attr->bp_type);
+               if (err)
+                       return err;
        }
 
+       hw_breakpoint_copy_attr(&bp->attr, attr);
        bp->hw.info = hw;
-       bp->attr.disabled = attr->disabled;
 
        return 0;
 }
-- 
2.7.4

Reply via email to