events/uprobes: move smp_read_barrier_depends() where needed
Subsystems (2)
PATCH 1/1 events/uprobes: move smp_read_barrier_depends() where needed
There is no need to use the barrier if there is no dereference/ memory access; move it where needed (currently, affecting only Alpha). While touching this, also make the reads _ONCE().
--- kernel/events/uprobes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/events/uprobes.c +5 -4
@@ -1520,10 +1520,11 @@ static unsigned long get_trampoline_vaddr(void)struct xol_area *area;unsigned long trampoline_vaddr =-1 ; - area = current->mm->uprobes_state.xol_area; -smp_read_barrier_depends (); -if (area) - trampoline_vaddr = area->vaddr; + area =READ_ONCE (current->mm->uprobes_state.xol_area); +if (area) { +smp_read_barrier_depends (); + trampoline_vaddr =READ_ONCE (area->vaddr); + }return trampoline_vaddr; }
Signature · 1 line
1.9.1
Oleg Nesterov
maintainerQuoted 4 lines · Andrea Parri
There is no need to use the barrier if there is no dereference/ memory access; move it where needed (currently, affecting only Alpha).
OK, although area == NULL is unlikely case,
Quoted 1 line
While touching this, also make the reads
_ONCE().
Why? both xol_area/vaddr can't change.
Quoted 28 lines
Signed-off-by Andrea Parri <[email protected]>--- kernel/events/uprobes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)kernel/events/uprobes.c +5
-4@@ -1520,10 +1520,11 @@ static unsigned long get_trampoline_vaddr(void)struct xol_area *area;unsigned long trampoline_vaddr =-1 ; - area = current->mm->uprobes_state.xol_area; -smp_read_barrier_depends (); -if (area) - trampoline_vaddr = area->vaddr; + area =READ_ONCE (current->mm->uprobes_state.xol_area); +if (area) { +smp_read_barrier_depends (); + trampoline_vaddr =READ_ONCE (area->vaddr); + }return trampoline_vaddr; }Signature · 1 line
1.9.1
Oleg Nesterov
maintainerQuoted 7 lines · Oleg Nesterov
Quoted 4 lines · Andrea Parri
There is no need to use the barrier if there is no dereference/ memory access; move it where needed (currently, affecting only Alpha).
Quoted 5 lines
OK, although area == NULL is unlikely case,
Quoted 1 line
While touching this, also make the reads
_ONCE().Why? both xol_area/vaddr can't change.
and perhaps it would be better to eliminate this smp_read_barrier_depends() altogether, we have a lot of helpers. I mean,
static unsigned long get_trampoline_vaddr(void)
{
struct xol_area *area;
area = lockless_dereference(current->mm->uprobes_state.xol_area);
if (area)
return area->vaddr;
return -1;
}looks a bit more simple/clean. Note also another smp_read_barrier_depends() in get_xol_area() which can be changed the same way.
What do you think?
Oleg.
Oleg Nesterov
maintainerQuoted 13 lines · Andrea Parri
Quoted 10 lines · Oleg Nesterov
Quoted 4 lines · Andrea Parri
There is no need to use the barrier if there is no dereference/ memory access; move it where needed (currently, affecting only Alpha).
OK, although area == NULL is unlikely case,
Quoted 1 line
While touching this, also make the reads
_ONCE().
Quoted 8 lines
Quoted 2 lines
Why? both xol_area/vaddr can't change.
This is to ensure current (and future) compiler transformations won't optimize out or reorder the reads (do not ask me how ..., IAC the volatile casts will prevent this to happen).
AFAICT,
xol_areacan be "== NULL" and "!= NULL" ...
Yes, but it can't change if it is not NULL. So we do not care if gcc reads xol_area/vaddr twice or reorderes this with other LOADs.
Oleg.
Oleg Nesterov
maintainerQuoted 34 lines · Andrea Parri
Quoted 31 lines · Oleg Nesterov
Quoted 7 lines · Oleg Nesterov
Quoted 4 lines · Andrea Parri
There is no need to use the barrier if there is no dereference/ memory access; move it where needed (currently, affecting only Alpha).
Quoted 5 lines
OK, although area == NULL is unlikely case,
Quoted 1 line
While touching this, also make the reads
_ONCE().Why? both xol_area/vaddr can't change.
and perhaps it would be better to eliminate this
smp_read_barrier_depends()altogether, we have a lot of helpers. I mean,static unsigned long get_trampoline_vaddr(void) { struct xol_area *area; area = lockless_dereference(current->mm->uprobes_state.xol_area); if (area) return area->vaddr; return -1; }looks a bit more simple/clean. Note also another
smp_read_barrier_depends()inget_xol_area()which can be changed the same way.
Quoted 6 lines
Quoted 2 lines
What do you think?
More simply/clean, as you said, maybe; one advantage of keeping the "raw"
smp_read_barrier_depends()inget_trampoline_vaddr()is that we can avoid it when area is NULL;
Do you really think it makes sense to optimize out read_barrier_depends here?
It can only be NULL in handle_swbp(), and in this case we are going to do a lot of work, and in particular install this xol vma,
Quoted 2 lines
a similar solution is adopt-
ed in kernel/task_work.c:task_work_cancel().
Heh ;) this code was written before we had lockless_dereference(). And I do remember I thought that we need such a helper when read_barrier_depends() was added.
Oleg.
Oleg Nesterov
maintainerQuoted 11 lines · Oleg Nesterov
Quoted 4 lines · Andrea Parri
More simply/clean, as you said, maybe; one advantage of keeping the "raw"
smp_read_barrier_depends()inget_trampoline_vaddr()is that we can avoid it when area is NULL;Do you really think it makes sense to optimize out
read_barrier_dependshere?It can only be NULL in
handle_swbp(), and in this case we are going to do a lot of work, and in particular install this xol vma,
Not to mention that alpha doesn't support uprobes, so this all is currently cosmetic.
Quoted 6 lines
Quoted 2 lines
a similar solution is adopt-
ed in kernel/task_work.c:task_work_cancel().Heh ;) this code was written before we had
lockless_dereference(). And I do remember I thought that we need such a helper whenread_barrier_depends()was added.
Plus this code still use ACCESS_ONCE for the same reason. I'll send a simple patch, it should not conflict with "Update spin_unlock_wait users" from Peter.
Oleg.
Oleg Nesterov
maintainerQuoted 15 lines · Andrea Parri
Quoted 12 lines · Oleg Nesterov
Quoted 8 lines · Oleg Nesterov
Quoted 4 lines · Andrea Parri
More simply/clean, as you said, maybe; one advantage of keeping the "raw"
smp_read_barrier_depends()inget_trampoline_vaddr()is that we can avoid it when area is NULL;Do you really think it makes sense to optimize out
read_barrier_dependshere?
Quoted 2 lines
It can only be NULL in
handle_swbp(), and in this case we are going to
Quoted 8 lines
Quoted 6 lines
do a
Quoted 1 line
lot of work, and in particular install this xol vma,
Not to mention that alpha doesn't support uprobes, so this all is currently cosmetic.
Do you mean a "cosmetic" improvement over the current version? ;-)
Yes, if you mean "turn smp_read_barrier_depends into lockless_dereference" ;) So I will be happy to ack this patch if you make it.
But "optimize out smp_read_barrier_depends if NULL" imho makes no sense.
And, speaking of get_trampoline_vaddr() in particular, it is a bit ugly anyway. prepare_uretprobe() can not hit area == NULL and doesn't need a barrier, while handle_swbp() actually wants is_trampoline(bp_vaddr). Not that I really think this needs a cleanup, at least until we change this code to use multiple trampolines (say, for different stacks).
Oleg.