Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1418564 > unrolled thread

[PATCH] events/uprobes: move smp_read_barrier_depends() where needed

Started byAndrea Parri <parri.andrea@gmail.com>
First post2016-06-09 20:20 +0200
Last post2016-06-10 15:00 +0200
Articles 7 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] events/uprobes: move smp_read_barrier_depends() where needed Andrea Parri <parri.andrea@gmail.com> - 2016-06-09 20:20 +0200
    Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where  needed Oleg Nesterov <oleg@redhat.com> - 2016-06-10 09:10 +0200
      Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where  needed Oleg Nesterov <oleg@redhat.com> - 2016-06-10 14:30 +0200
        Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where  needed Oleg Nesterov <oleg@redhat.com> - 2016-06-10 15:10 +0200
          Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where  needed Oleg Nesterov <oleg@redhat.com> - 2016-06-10 16:50 +0200
            Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where  needed Oleg Nesterov <oleg@redhat.com> - 2016-06-10 21:40 +0200
      Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where  needed Oleg Nesterov <oleg@redhat.com> - 2016-06-10 15:00 +0200

#1418564 — [PATCH] events/uprobes: move smp_read_barrier_depends() where needed

FromAndrea Parri <parri.andrea@gmail.com>
Date2016-06-09 20:20 +0200
Subject[PATCH] events/uprobes: move smp_read_barrier_depends() where needed
Message-ID<rIcIF-1zJ-1@gated-at.bofh.it>
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().

Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
---
 kernel/events/uprobes.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index b7a525ab2083..b1364acd683e 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -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;
 }
-- 
1.9.1

[toc] | [next] | [standalone]


#1419078 — Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed

FromOleg Nesterov <oleg@redhat.com>
Date2016-06-10 09:10 +0200
SubjectRe: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed
Message-ID<rIoJP-1vU-21@gated-at.bofh.it>
In reply to#1418564
On 06/09, Andrea Parri wrote:
>
> 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,

> While touching this, also make the reads _ONCE().

Why? both xol_area/vaddr can't change.

> Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
> ---
>  kernel/events/uprobes.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index b7a525ab2083..b1364acd683e 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -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;
>  }
> -- 
> 1.9.1
> 

[toc] | [prev] | [next] | [standalone]


#1419338 — Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed

FromOleg Nesterov <oleg@redhat.com>
Date2016-06-10 14:30 +0200
SubjectRe: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed
Message-ID<rItJx-4w2-45@gated-at.bofh.it>
In reply to#1419078
On 06/10, Oleg Nesterov wrote:
>
> On 06/09, Andrea Parri wrote:
> >
> > 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,
>
> > 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.

[toc] | [prev] | [next] | [standalone]


#1419368 — Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed

FromOleg Nesterov <oleg@redhat.com>
Date2016-06-10 15:10 +0200
SubjectRe: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed
Message-ID<rIume-4YI-5@gated-at.bofh.it>
In reply to#1419338
On 06/10, Andrea Parri wrote:
>
> On Fri, Jun 10, 2016 at 2:26 PM, Oleg Nesterov <oleg@redhat.com> wrote:
>
> > On 06/10, Oleg Nesterov wrote:
> > >
> > > On 06/09, Andrea Parri wrote:
> > > >
> > > > 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,
> > >
> > > > 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?
> >
>
> More simply/clean, as you said, maybe; one advantage of keeping
> the "raw" smp_read_barrier_depends() in get_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,

> 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.

[toc] | [prev] | [next] | [standalone]


#1419491 — Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed

FromOleg Nesterov <oleg@redhat.com>
Date2016-06-10 16:50 +0200
SubjectRe: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed
Message-ID<rIvUZ-5O9-7@gated-at.bofh.it>
In reply to#1419368
On 06/10, Oleg Nesterov wrote:
>
> On 06/10, Andrea Parri wrote:
> >
> > More simply/clean, as you said, maybe; one advantage of keeping
> > the "raw" smp_read_barrier_depends() in get_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,

Not to mention that alpha doesn't support uprobes, so this all is currently
cosmetic.

> > 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.

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.

[toc] | [prev] | [next] | [standalone]


#1419678 — Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed

FromOleg Nesterov <oleg@redhat.com>
Date2016-06-10 21:40 +0200
SubjectRe: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed
Message-ID<rIArE-AY-17@gated-at.bofh.it>
In reply to#1419491
On 06/10, Andrea Parri wrote:
>
> On Fri, Jun 10, 2016 at 4:39 PM, Oleg Nesterov <oleg@redhat.com> wrote:
>
> > On 06/10, Oleg Nesterov wrote:
> > >
> > > On 06/10, Andrea Parri wrote:
> > > >
> > > > More simply/clean, as you said, maybe; one advantage of keeping
> > > > the "raw" smp_read_barrier_depends() in get_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,
> >
> > 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.

[toc] | [prev] | [next] | [standalone]


#1419367 — Re: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed

FromOleg Nesterov <oleg@redhat.com>
Date2016-06-10 15:00 +0200
SubjectRe: [PATCH] events/uprobes: move smp_read_barrier_depends() where needed
Message-ID<rIucz-4Ga-49@gated-at.bofh.it>
In reply to#1419078
On 06/10, Andrea Parri wrote:
>
> On Fri, Jun 10, 2016 at 9:03 AM, Oleg Nesterov <oleg@redhat.com> wrote:
>
> > On 06/09, Andrea Parri wrote:
> > >
> > > 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,
> >
> > > While touching this, also make the reads _ONCE().
> >
> > 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_area can 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.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web