smp_wmb() in prepare_uprobe()
Subsystems (2)
Hi,
The comment for the smp_wmb() in prepare_uprobe() says:
"pairs with rmb() in find_active_uprobe()"
but I see no (smp_)rmb() in find_active_uprobe(); I see the smp_rmb() in handle_swbp(): is this the intended pairing barrier?
Which memory accesses do you want to "order" with this pairing?
Thanks,
Andrea
Oleg Nesterov
maintainerHi,
Quoted 4 lines · Andrea Parri
The comment for the
smp_wmb()inprepare_uprobe()says:"pairs with
rmb()infind_active_uprobe()"
it seems that this comment was wrong from the very beginning,
Quoted 2 lines
but I see no (smp_)rmb() in
find_active_uprobe(); I see thesmp_rmb()inhandle_swbp(): is this the intended pairing barrier?
Yes, and the comment near this rmb() says "pairs with wmb() in install_breakpoint()", today this is not right too.
Quoted 1 line
Which memory accesses do you want to "order" with this pairing?
See 142b18ddc81439acda4bc4231b291e99fe67d507 ("uprobes: Fix handle_swbp() vs unregister() + register() race") and the comment above this rmb().
Oleg.
Quoted 8 lines · Oleg Nesterov
Hi,
Quoted 4 lines · Andrea Parri
The comment for the
smp_wmb()inprepare_uprobe()says:"pairs with
rmb()infind_active_uprobe()"
Quoted 8 lines
it seems that this comment was wrong from the very beginning,
Quoted 2 lines
but I see no (smp_)rmb() in
find_active_uprobe(); I see thesmp_rmb()inhandle_swbp(): is this the intended pairing barrier?Yes, and the comment near this
rmb()says "pairs withwmb()ininstall_breakpoint()", today this is not right too.
Thanks for the confirmation. So, this is the easy part ;-), maybe something like:
kernel/events/uprobes.c +2 -2
@@ -829,7 +829,7 @@ static int prepare_uprobe(struct uprobe *uprobe, struct file *file,BUG_ON ((uprobe->offset & ~PAGE_MASK ) +UPROBE_SWBP_INSN_SIZE >PAGE_SIZE ); -smp_wmb ();/* pairs with rmb() in find_active_uprobe() */ +smp_wmb ();/* pairs with the smp_rmb() in handle_swbp() */ set_bit (UPROBE_COPY_INSN , &uprobe->flags); out:
@@ -2178,7 +2178,7 @@ static void handle_swbp(struct pt_regs *regs)* After we hit the bp, _unregister + _register can install the * new and not-yet-analyzed uprobe at the same address, restart. */ -smp_rmb ();/* pairs with wmb() in install_breakpoint() */ +smp_rmb ();/* pairs with the smp_wmb() in prepare_uprobe() */ if (unlikely (!test_bit (UPROBE_COPY_INSN , &uprobe->flags))) goto out;
Quoted 5 lines
Quoted 2 lines
Which memory accesses do you want to "order" with this pairing?
See
142b18ddc81439acda4bc4231b291e99fe67d507("uprobes: Fixhandle_swbp()vsunregister()+register()race") and the comment above thisrmb().
Mmh..., at first glance, this suggests me that the above set_bit() and test_bit() to/from uprobe->flags are among these memory accesses. But this doesn't make sense to me: these accesses do not "alternate" (i.e., they both appear after the corresponding barrier..); instead I'd expect something like (on top of the above diff):
kernel/events/uprobes.c +9 -1
@@ -2178,10 +2178,18 @@ static void handle_swbp(struct pt_regs *regs)* After we hit the bp, _unregister + _register can install the * new and not-yet-analyzed uprobe at the same address, restart. */ -smp_rmb ();/* pairs with the smp_wmb() in prepare_uprobe() */ if (unlikely (!test_bit (UPROBE_COPY_INSN , &uprobe->flags))) goto out; +/* +* Pairs with the smp_wmb() in prepare_uprobe(). +* +* Guarantees that if we see the UPROBE_COPY_INSN bit set, then +* we must (can) also see the stores to &uprobe->arch performed +* by prepare_uprobe() (say). +*/ +smp_rmb (); +/* Tracing handlers use ->utask to communicate with fetch methods */ if (!get_utask ()) goto out;
Thoughts?
Andrea
Quoted 3 lines
Oleg.
Oleg Nesterov
maintainerQuoted 20 lines · Andrea Parri
Quoted 3 lines
See
142b18ddc81439acda4bc4231b291e99fe67d507("uprobes: Fixhandle_swbp()vsunregister()+register()race") and the comment above thisrmb().Mmh..., at first glance, this suggests me that the above
set_bit()andtest_bit()to/fromuprobe->flagsare among these memory accesses. But this doesn't make sense to me: these accesses do not "alternate" (i.e., they both appear after the corresponding barrier..); instead I'd expect something like (on top of the above diff):kernel/events/uprobes.c +0
-1@@ -2178,10 +2178,18 @@ static void handle_swbp(struct pt_regs *regs)* After we hit the bp, _unregister + _register can install the * new and not-yet-analyzed uprobe at the same address, restart. */ -smp_rmb ();/* pairs with the smp_wmb() in prepare_uprobe() */ if (unlikely (!test_bit (UPROBE_COPY_INSN , &uprobe->flags)))
kernel/events/uprobes.c static void handle_swbp(struct pt_regs *regs) · line 2191
Quoted 10 lines
kernel/events/uprobes.c +8
-0goto out; +/* +* Pairs with the smp_wmb() in prepare_uprobe(). +* +* Guarantees that if we see the UPROBE_COPY_INSN bit set, then +* we must (can) also see the stores to &uprobe->arch performed +* by prepare_uprobe() (say). +*/ +smp_rmb ();
OOPS, you are right! Thanks.
Oleg.
Quoted 23 lines · Oleg Nesterov
Quoted 22 lines · Andrea Parri
Quoted 3 lines
See
142b18ddc81439acda4bc4231b291e99fe67d507("uprobes: Fixhandle_swbp()vsunregister()+register()race") and the comment above thisrmb().Mmh..., at first glance, this suggests me that the above
set_bit()andtest_bit()to/fromuprobe->flagsare among these memory accesses. But this doesn't make sense to me: these accesses do not "alternate" (i.e., they both appear after the corresponding barrier..); instead I'd expect something like (on top of the above diff):kernel/events/uprobes.c +0
-1@@ -2178,10 +2178,18 @@ static void handle_swbp(struct pt_regs *regs)* After we hit the bp, _unregister + _register can install the * new and not-yet-analyzed uprobe at the same address, restart. */ -smp_rmb ();/* pairs with the smp_wmb() in prepare_uprobe() */ if (unlikely (!test_bit (UPROBE_COPY_INSN , &uprobe->flags))) goto out;
Quoted 10 lines
kernel/events/uprobes.c static void handle_swbp(struct pt_regs *regs) · line 2191
Quoted 8 lines
kernel/events/uprobes.c +8
-0+/* +* Pairs with the smp_wmb() in prepare_uprobe(). +* +* Guarantees that if we see the UPROBE_COPY_INSN bit set, then +* we must (can) also see the stores to &uprobe->arch performed +* by prepare_uprobe() (say). +*/ +smp_rmb ();OOPS, you are right! Thanks.
Thank you for the clarification; I'll send a patch with the fix shortly.
Andrea
Quoted 3 lines
Oleg.