linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] uprobes: simplify _unregister paths
@ 2024-07-30 12:34 Oleg Nesterov
  2024-07-30 12:34 ` [PATCH 1/3] uprobes: change uprobe_register() to use uprobe_unregister() instead of __uprobe_unregister() Oleg Nesterov
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Oleg Nesterov @ 2024-07-30 12:34 UTC (permalink / raw)
  To: andrii, mhiramat, peterz; +Cc: jolsa, rostedt, linux-kernel, linux-trace-kernel

On top of

	[PATCH v2 0/5] uprobes: misc cleanups/simplifications
	https://lore.kernel.org/all/20240729134444.GA12293@redhat.com/

I sent yesterday.

Oleg.
---

 kernel/events/uprobes.c | 47 ++++++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/3] uprobes: change uprobe_register() to use uprobe_unregister() instead of __uprobe_unregister()
  2024-07-30 12:34 [PATCH 0/3] uprobes: simplify _unregister paths Oleg Nesterov
@ 2024-07-30 12:34 ` Oleg Nesterov
  2024-07-30 15:00   ` Andrii Nakryiko
  2024-07-30 12:34 ` [PATCH 2/3] uprobes: fold __uprobe_unregister() into uprobe_unregister() Oleg Nesterov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Oleg Nesterov @ 2024-07-30 12:34 UTC (permalink / raw)
  To: andrii, mhiramat, peterz; +Cc: jolsa, rostedt, linux-kernel, linux-trace-kernel

If register_for_each_vma() fails uprobe_register() can safely drop
uprobe->register_rwsem and use uprobe_unregister(). There is no worry
about the races with another register/unregister, consumer_add() was
already called so this case doesn't differ from _unregister() right
after the successful _register().

Yes this means the extra up_write() + down_write(), but this is the
slow and unlikely case anyway.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/events/uprobes.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 974474680820..5ea0aabe8774 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1174,16 +1174,18 @@ struct uprobe *uprobe_register(struct inode *inode,
 	if (likely(uprobe_is_active(uprobe))) {
 		consumer_add(uprobe, uc);
 		ret = register_for_each_vma(uprobe, uc);
-		if (ret)
-			__uprobe_unregister(uprobe, uc);
 	}
 	up_write(&uprobe->register_rwsem);
 	put_uprobe(uprobe);
 
-	if (unlikely(ret == -EAGAIN))
-		goto retry;
+	if (ret) {
+		if (unlikely(ret == -EAGAIN))
+			goto retry;
+		uprobe_unregister(uprobe, uc);
+		return ERR_PTR(ret);
+	}
 
-	return ret ? ERR_PTR(ret) : uprobe;
+	return uprobe;
 }
 EXPORT_SYMBOL_GPL(uprobe_register);
 
-- 
2.25.1.362.g51ebf55


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/3] uprobes: fold __uprobe_unregister() into uprobe_unregister()
  2024-07-30 12:34 [PATCH 0/3] uprobes: simplify _unregister paths Oleg Nesterov
  2024-07-30 12:34 ` [PATCH 1/3] uprobes: change uprobe_register() to use uprobe_unregister() instead of __uprobe_unregister() Oleg Nesterov
@ 2024-07-30 12:34 ` Oleg Nesterov
  2024-07-30 15:01   ` Andrii Nakryiko
  2024-07-30 12:34 ` [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister() Oleg Nesterov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Oleg Nesterov @ 2024-07-30 12:34 UTC (permalink / raw)
  To: andrii, mhiramat, peterz; +Cc: jolsa, rostedt, linux-kernel, linux-trace-kernel

Fold __uprobe_unregister() into its single caller, uprobe_unregister().
A separate patch to simplify the next change.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/events/uprobes.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 5ea0aabe8774..c06e1a5f1783 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1085,20 +1085,6 @@ register_for_each_vma(struct uprobe *uprobe, struct uprobe_consumer *new)
 	return err;
 }
 
-static void
-__uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
-{
-	int err;
-
-	if (WARN_ON(!consumer_del(uprobe, uc)))
-		return;
-
-	err = register_for_each_vma(uprobe, NULL);
-	/* TODO : cant unregister? schedule a worker thread */
-	if (!uprobe->consumers && !err)
-		delete_uprobe(uprobe);
-}
-
 /**
  * uprobe_unregister - unregister an already registered probe.
  * @uprobe: uprobe to remove
@@ -1106,9 +1092,18 @@ __uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
  */
 void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
 {
+	int err;
+
 	get_uprobe(uprobe);
 	down_write(&uprobe->register_rwsem);
-	__uprobe_unregister(uprobe, uc);
+	if (WARN_ON(!consumer_del(uprobe, uc)))
+		err = -ENOENT;
+	else
+		err = register_for_each_vma(uprobe, NULL);
+
+	/* TODO : cant unregister? schedule a worker thread */
+	if (!err && !uprobe->consumers)
+		delete_uprobe(uprobe);
 	up_write(&uprobe->register_rwsem);
 	put_uprobe(uprobe);
 }
-- 
2.25.1.362.g51ebf55


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister()
  2024-07-30 12:34 [PATCH 0/3] uprobes: simplify _unregister paths Oleg Nesterov
  2024-07-30 12:34 ` [PATCH 1/3] uprobes: change uprobe_register() to use uprobe_unregister() instead of __uprobe_unregister() Oleg Nesterov
  2024-07-30 12:34 ` [PATCH 2/3] uprobes: fold __uprobe_unregister() into uprobe_unregister() Oleg Nesterov
@ 2024-07-30 12:34 ` Oleg Nesterov
  2024-07-30 15:08   ` Andrii Nakryiko
  2024-07-30 15:10 ` [PATCH 0/3] uprobes: simplify _unregister paths Andrii Nakryiko
  2024-07-31  9:46 ` Masami Hiramatsu
  4 siblings, 1 reply; 14+ messages in thread
From: Oleg Nesterov @ 2024-07-30 12:34 UTC (permalink / raw)
  To: andrii, mhiramat, peterz; +Cc: jolsa, rostedt, linux-kernel, linux-trace-kernel

Kill the extra get_uprobe() + put_uprobe() in uprobe_unregister() and
move the possibly final put_uprobe() from delete_uprobe() to its only
caller, uprobe_unregister().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/events/uprobes.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index c06e1a5f1783..f88b7ff20587 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -939,7 +939,6 @@ static void delete_uprobe(struct uprobe *uprobe)
 	rb_erase(&uprobe->rb_node, &uprobes_tree);
 	write_unlock(&uprobes_treelock);
 	RB_CLEAR_NODE(&uprobe->rb_node); /* for uprobe_is_active() */
-	put_uprobe(uprobe);
 }
 
 struct map_info {
@@ -1094,7 +1093,6 @@ void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
 {
 	int err;
 
-	get_uprobe(uprobe);
 	down_write(&uprobe->register_rwsem);
 	if (WARN_ON(!consumer_del(uprobe, uc)))
 		err = -ENOENT;
@@ -1102,10 +1100,16 @@ void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
 		err = register_for_each_vma(uprobe, NULL);
 
 	/* TODO : cant unregister? schedule a worker thread */
-	if (!err && !uprobe->consumers)
-		delete_uprobe(uprobe);
+	if (!err) {
+		if (!uprobe->consumers)
+			delete_uprobe(uprobe);
+		else
+			err = -EBUSY;
+	}
 	up_write(&uprobe->register_rwsem);
-	put_uprobe(uprobe);
+
+	if (!err)
+		put_uprobe(uprobe);
 }
 EXPORT_SYMBOL_GPL(uprobe_unregister);
 
-- 
2.25.1.362.g51ebf55


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] uprobes: change uprobe_register() to use uprobe_unregister() instead of __uprobe_unregister()
  2024-07-30 12:34 ` [PATCH 1/3] uprobes: change uprobe_register() to use uprobe_unregister() instead of __uprobe_unregister() Oleg Nesterov
@ 2024-07-30 15:00   ` Andrii Nakryiko
  0 siblings, 0 replies; 14+ messages in thread
From: Andrii Nakryiko @ 2024-07-30 15:00 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: andrii, mhiramat, peterz, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 5:34 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> If register_for_each_vma() fails uprobe_register() can safely drop
> uprobe->register_rwsem and use uprobe_unregister(). There is no worry
> about the races with another register/unregister, consumer_add() was
> already called so this case doesn't differ from _unregister() right
> after the successful _register().
>
> Yes this means the extra up_write() + down_write(), but this is the
> slow and unlikely case anyway.
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
>  kernel/events/uprobes.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>

Yep, makes total sense, in my local patches I basically already done
that as well.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 974474680820..5ea0aabe8774 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1174,16 +1174,18 @@ struct uprobe *uprobe_register(struct inode *inode,
>         if (likely(uprobe_is_active(uprobe))) {
>                 consumer_add(uprobe, uc);
>                 ret = register_for_each_vma(uprobe, uc);
> -               if (ret)
> -                       __uprobe_unregister(uprobe, uc);
>         }
>         up_write(&uprobe->register_rwsem);
>         put_uprobe(uprobe);
>
> -       if (unlikely(ret == -EAGAIN))
> -               goto retry;
> +       if (ret) {
> +               if (unlikely(ret == -EAGAIN))
> +                       goto retry;
> +               uprobe_unregister(uprobe, uc);
> +               return ERR_PTR(ret);
> +       }
>
> -       return ret ? ERR_PTR(ret) : uprobe;
> +       return uprobe;
>  }
>  EXPORT_SYMBOL_GPL(uprobe_register);
>
> --
> 2.25.1.362.g51ebf55
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] uprobes: fold __uprobe_unregister() into uprobe_unregister()
  2024-07-30 12:34 ` [PATCH 2/3] uprobes: fold __uprobe_unregister() into uprobe_unregister() Oleg Nesterov
@ 2024-07-30 15:01   ` Andrii Nakryiko
  0 siblings, 0 replies; 14+ messages in thread
From: Andrii Nakryiko @ 2024-07-30 15:01 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: andrii, mhiramat, peterz, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 5:35 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> Fold __uprobe_unregister() into its single caller, uprobe_unregister().
> A separate patch to simplify the next change.
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
>  kernel/events/uprobes.c | 25 ++++++++++---------------
>  1 file changed, 10 insertions(+), 15 deletions(-)
>

LGTM

Acked-by: Andrii Nakryiko <andrii@kernel.org>

> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 5ea0aabe8774..c06e1a5f1783 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1085,20 +1085,6 @@ register_for_each_vma(struct uprobe *uprobe, struct uprobe_consumer *new)
>         return err;
>  }
>
> -static void
> -__uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
> -{
> -       int err;
> -
> -       if (WARN_ON(!consumer_del(uprobe, uc)))
> -               return;
> -
> -       err = register_for_each_vma(uprobe, NULL);
> -       /* TODO : cant unregister? schedule a worker thread */
> -       if (!uprobe->consumers && !err)
> -               delete_uprobe(uprobe);
> -}
> -
>  /**
>   * uprobe_unregister - unregister an already registered probe.
>   * @uprobe: uprobe to remove
> @@ -1106,9 +1092,18 @@ __uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
>   */
>  void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
>  {
> +       int err;
> +
>         get_uprobe(uprobe);
>         down_write(&uprobe->register_rwsem);
> -       __uprobe_unregister(uprobe, uc);
> +       if (WARN_ON(!consumer_del(uprobe, uc)))
> +               err = -ENOENT;
> +       else
> +               err = register_for_each_vma(uprobe, NULL);
> +
> +       /* TODO : cant unregister? schedule a worker thread */
> +       if (!err && !uprobe->consumers)
> +               delete_uprobe(uprobe);
>         up_write(&uprobe->register_rwsem);
>         put_uprobe(uprobe);
>  }
> --
> 2.25.1.362.g51ebf55
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister()
  2024-07-30 12:34 ` [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister() Oleg Nesterov
@ 2024-07-30 15:08   ` Andrii Nakryiko
  2024-07-30 17:17     ` Oleg Nesterov
  2024-07-30 20:55     ` Peter Zijlstra
  0 siblings, 2 replies; 14+ messages in thread
From: Andrii Nakryiko @ 2024-07-30 15:08 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: andrii, mhiramat, peterz, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 5:35 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> Kill the extra get_uprobe() + put_uprobe() in uprobe_unregister() and
> move the possibly final put_uprobe() from delete_uprobe() to its only
> caller, uprobe_unregister().
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
>  kernel/events/uprobes.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>

LGTM as well.

BTW, do you have anything against me changing refcounting so that
uprobes_tree itself doesn't hold a refcount, and all the refcounting
is done based on consumers holding implicit refcount and whatever
temporary get/put uprobe is necessary for runtime uprobe/uretprobe
functioning.

I can do that with a simple refcount_t and refcount_inc_not_zero(), no
fancy custom refcounting. This schema makes most sense to me, it will
also simplify registration by avoiding that annoying
is_uprobe_active() check + retry. Thoughts?

All that would be additional on top of your change. BTW, do you plan
any more clean ups like this? It's a bit of a moving target because of
your refactoring, so I'd appreciate some stability to build upon :)

Also, can you please push this and your previous patch set into some
branch somewhere I can pull from, preferably based on the latest
linux-trace's probes/for-next? Thanks!

Acked-by: Andrii Nakryiko <andrii@kernel.org>

> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index c06e1a5f1783..f88b7ff20587 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -939,7 +939,6 @@ static void delete_uprobe(struct uprobe *uprobe)
>         rb_erase(&uprobe->rb_node, &uprobes_tree);
>         write_unlock(&uprobes_treelock);
>         RB_CLEAR_NODE(&uprobe->rb_node); /* for uprobe_is_active() */
> -       put_uprobe(uprobe);
>  }
>
>  struct map_info {
> @@ -1094,7 +1093,6 @@ void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
>  {
>         int err;
>
> -       get_uprobe(uprobe);
>         down_write(&uprobe->register_rwsem);
>         if (WARN_ON(!consumer_del(uprobe, uc)))
>                 err = -ENOENT;
> @@ -1102,10 +1100,16 @@ void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
>                 err = register_for_each_vma(uprobe, NULL);
>
>         /* TODO : cant unregister? schedule a worker thread */
> -       if (!err && !uprobe->consumers)
> -               delete_uprobe(uprobe);
> +       if (!err) {
> +               if (!uprobe->consumers)
> +                       delete_uprobe(uprobe);
> +               else
> +                       err = -EBUSY;

This bit is weird because really it's not an error... but this makes
this change simpler and moves put_uprobe outside of rwsem. With my
proposed change to refcounting schema this would be unnecessary, but
let's see what you think.

> +       }
>         up_write(&uprobe->register_rwsem);
> -       put_uprobe(uprobe);
> +
> +       if (!err)
> +               put_uprobe(uprobe);
>  }
>  EXPORT_SYMBOL_GPL(uprobe_unregister);
>
> --
> 2.25.1.362.g51ebf55
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/3] uprobes: simplify _unregister paths
  2024-07-30 12:34 [PATCH 0/3] uprobes: simplify _unregister paths Oleg Nesterov
                   ` (2 preceding siblings ...)
  2024-07-30 12:34 ` [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister() Oleg Nesterov
@ 2024-07-30 15:10 ` Andrii Nakryiko
  2024-07-30 20:20   ` Jiri Olsa
  2024-07-31  9:46 ` Masami Hiramatsu
  4 siblings, 1 reply; 14+ messages in thread
From: Andrii Nakryiko @ 2024-07-30 15:10 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: andrii, mhiramat, peterz, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 5:34 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> On top of
>
>         [PATCH v2 0/5] uprobes: misc cleanups/simplifications
>         https://lore.kernel.org/all/20240729134444.GA12293@redhat.com/
>
> I sent yesterday.
>
> Oleg.
> ---
>

Both patch sets look good to me. It would be nice to get them applied
ASAP to have a stable uprobes code base to work on. Rebasing is
painful and error-prone.

>  kernel/events/uprobes.c | 47 ++++++++++++++++++++++++-----------------------
>  1 file changed, 24 insertions(+), 23 deletions(-)
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister()
  2024-07-30 15:08   ` Andrii Nakryiko
@ 2024-07-30 17:17     ` Oleg Nesterov
  2024-07-30 17:27       ` Andrii Nakryiko
  2024-07-30 20:55     ` Peter Zijlstra
  1 sibling, 1 reply; 14+ messages in thread
From: Oleg Nesterov @ 2024-07-30 17:17 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: andrii, mhiramat, peterz, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

Thanks for looking at this!

On 07/30, Andrii Nakryiko wrote:
>
> BTW, do you have anything against me changing refcounting so that
> uprobes_tree itself doesn't hold a refcount, and all the refcounting
> is done based on consumers holding implicit refcount and whatever
> temporary get/put uprobe is necessary for runtime uprobe/uretprobe
> functioning.

No, I have nothing against.

To be honest, I don't really understand the value of this change, but
a) this is probably because I didn't see a separate patch(es) which
does this and b) assuming that it doesn't complicate the code too much
I won't argue in any case ;)

And in fact I had your proposed change in mind when I did these cleanups.
I think that they can even simplify this change, at least I hope they can
not complicate it.

> BTW, do you plan
> any more clean ups like this? It's a bit of a moving target because of
> your refactoring, so I'd appreciate some stability to build upon :)

Well yes... may be this week.

I'd like to (try to) optimize/de-uglify register_for_each_vma() for
the multiple-consumers case. And, more importantly, the case when perf
does uprobe_register() + uprobe_apply().

But. All these changes will only touch the register_for_each_vma() paths,
so this is completely orthogonal to this series and your and/or Peter's
changes.

> Also, can you please push this and your previous patch set into some
> branch somewhere I can pull from, preferably based on the latest
> linux-trace's probes/for-next? Thanks!

Cough ;)

No, sorry, I can't. I lost my kernel.org account years ago (and this is
the second time this has happened!), but since I am a lazy dog I didn't
even bother to try to restore it.

> Acked-by: Andrii Nakryiko <andrii@kernel.org>

Thanks!

> > @@ -1102,10 +1100,16 @@ void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
> >                 err = register_for_each_vma(uprobe, NULL);
> >
> >         /* TODO : cant unregister? schedule a worker thread */
> > -       if (!err && !uprobe->consumers)
> > -               delete_uprobe(uprobe);
> > +       if (!err) {
> > +               if (!uprobe->consumers)
> > +                       delete_uprobe(uprobe);
> > +               else
> > +                       err = -EBUSY;
>
> This bit is weird because really it's not an error... but this makes
> this change simpler and moves put_uprobe outside of rwsem.

Agreed, uprobe->consumers != NULL is not an error. But we don't return
this error code, just we need to ensure that "err == 0" means that
"delete_uprobe() was actually called".

> With my
> proposed change to refcounting schema this would be unnecessary,

Yes.

Oleg.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister()
  2024-07-30 17:17     ` Oleg Nesterov
@ 2024-07-30 17:27       ` Andrii Nakryiko
  0 siblings, 0 replies; 14+ messages in thread
From: Andrii Nakryiko @ 2024-07-30 17:27 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: andrii, mhiramat, peterz, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 10:17 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> Thanks for looking at this!
>
> On 07/30, Andrii Nakryiko wrote:
> >
> > BTW, do you have anything against me changing refcounting so that
> > uprobes_tree itself doesn't hold a refcount, and all the refcounting
> > is done based on consumers holding implicit refcount and whatever
> > temporary get/put uprobe is necessary for runtime uprobe/uretprobe
> > functioning.
>
> No, I have nothing against.
>
> To be honest, I don't really understand the value of this change, but
> a) this is probably because I didn't see a separate patch(es) which
> does this and b) assuming that it doesn't complicate the code too much
> I won't argue in any case ;)
>
> And in fact I had your proposed change in mind when I did these cleanups.
> I think that they can even simplify this change, at least I hope they can
> not complicate it.

I just find this logic to drop refcount if the consumer list is empty
super confusing and hard to intuitively reason about. It's just very
unconventional and seems problematic every time I think about this.

Either way, we can discuss once you see the code, it's not really
complicated if I stick to refcount_t instead of my fancy atomic-based
refcounting.

>
> > BTW, do you plan
> > any more clean ups like this? It's a bit of a moving target because of
> > your refactoring, so I'd appreciate some stability to build upon :)
>
> Well yes... may be this week.
>
> I'd like to (try to) optimize/de-uglify register_for_each_vma() for
> the multiple-consumers case. And, more importantly, the case when perf
> does uprobe_register() + uprobe_apply().
>
> But. All these changes will only touch the register_for_each_vma() paths,
> so this is completely orthogonal to this series and your and/or Peter's
> changes.
>

Ok, sounds good, it would be nice to keep the other part more or less
intact for the time being. Thanks!

> > Also, can you please push this and your previous patch set into some
> > branch somewhere I can pull from, preferably based on the latest
> > linux-trace's probes/for-next? Thanks!
>
> Cough ;)
>
> No, sorry, I can't. I lost my kernel.org account years ago (and this is
> the second time this has happened!), but since I am a lazy dog I didn't
> even bother to try to restore it.

It doesn't have to be kernel.org repo :-P Github would work just fine,
but ok, if it's too much trouble I'll just go download emails one by
one and apply them locally.

>
> > Acked-by: Andrii Nakryiko <andrii@kernel.org>
>
> Thanks!
>
> > > @@ -1102,10 +1100,16 @@ void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
> > >                 err = register_for_each_vma(uprobe, NULL);
> > >
> > >         /* TODO : cant unregister? schedule a worker thread */
> > > -       if (!err && !uprobe->consumers)
> > > -               delete_uprobe(uprobe);
> > > +       if (!err) {
> > > +               if (!uprobe->consumers)
> > > +                       delete_uprobe(uprobe);
> > > +               else
> > > +                       err = -EBUSY;
> >
> > This bit is weird because really it's not an error... but this makes
> > this change simpler and moves put_uprobe outside of rwsem.
>
> Agreed, uprobe->consumers != NULL is not an error. But we don't return
> this error code, just we need to ensure that "err == 0" means that
> "delete_uprobe() was actually called".
>

yep

> > With my
> > proposed change to refcounting schema this would be unnecessary,
>
> Yes.
>
> Oleg.
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/3] uprobes: simplify _unregister paths
  2024-07-30 15:10 ` [PATCH 0/3] uprobes: simplify _unregister paths Andrii Nakryiko
@ 2024-07-30 20:20   ` Jiri Olsa
  0 siblings, 0 replies; 14+ messages in thread
From: Jiri Olsa @ 2024-07-30 20:20 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Oleg Nesterov, andrii, mhiramat, peterz, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 08:10:27AM -0700, Andrii Nakryiko wrote:
> On Tue, Jul 30, 2024 at 5:34 AM Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > On top of
> >
> >         [PATCH v2 0/5] uprobes: misc cleanups/simplifications
> >         https://lore.kernel.org/all/20240729134444.GA12293@redhat.com/
> >
> > I sent yesterday.
> >
> > Oleg.
> > ---
> >
> 
> Both patch sets look good to me. It would be nice to get them applied
> ASAP to have a stable uprobes code base to work on. Rebasing is
> painful and error-prone.

lgtm, +1 for having them applied soon

Reviewed-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister()
  2024-07-30 15:08   ` Andrii Nakryiko
  2024-07-30 17:17     ` Oleg Nesterov
@ 2024-07-30 20:55     ` Peter Zijlstra
  2024-07-30 21:58       ` Andrii Nakryiko
  1 sibling, 1 reply; 14+ messages in thread
From: Peter Zijlstra @ 2024-07-30 20:55 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Oleg Nesterov, andrii, mhiramat, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 08:08:49AM -0700, Andrii Nakryiko wrote:
> Also, can you please push this and your previous patch set into some
> branch somewhere I can pull from, preferably based on the latest
> linux-trace's probes/for-next? Thanks!

I can stick then in tip/perf/core if you want.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister()
  2024-07-30 20:55     ` Peter Zijlstra
@ 2024-07-30 21:58       ` Andrii Nakryiko
  0 siblings, 0 replies; 14+ messages in thread
From: Andrii Nakryiko @ 2024-07-30 21:58 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Oleg Nesterov, andrii, mhiramat, jolsa, rostedt, linux-kernel,
	linux-trace-kernel

On Tue, Jul 30, 2024 at 1:55 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Tue, Jul 30, 2024 at 08:08:49AM -0700, Andrii Nakryiko wrote:
> > Also, can you please push this and your previous patch set into some
> > branch somewhere I can pull from, preferably based on the latest
> > linux-trace's probes/for-next? Thanks!
>
> I can stick then in tip/perf/core if you want.

Whichever tree you and Masami ultimately agreed on, I don't
particularly care. But yeah, this would be great, thanks!

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/3] uprobes: simplify _unregister paths
  2024-07-30 12:34 [PATCH 0/3] uprobes: simplify _unregister paths Oleg Nesterov
                   ` (3 preceding siblings ...)
  2024-07-30 15:10 ` [PATCH 0/3] uprobes: simplify _unregister paths Andrii Nakryiko
@ 2024-07-31  9:46 ` Masami Hiramatsu
  4 siblings, 0 replies; 14+ messages in thread
From: Masami Hiramatsu @ 2024-07-31  9:46 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: andrii, peterz, jolsa, rostedt, linux-kernel, linux-trace-kernel

On Tue, 30 Jul 2024 14:34:21 +0200
Oleg Nesterov <oleg@redhat.com> wrote:

> On top of
> 
> 	[PATCH v2 0/5] uprobes: misc cleanups/simplifications
> 	https://lore.kernel.org/all/20240729134444.GA12293@redhat.com/
> 
> I sent yesterday.
> 

OK, this series looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> Oleg.
> ---
> 
>  kernel/events/uprobes.c | 47 ++++++++++++++++++++++++-----------------------
>  1 file changed, 24 insertions(+), 23 deletions(-)
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-07-31  9:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-30 12:34 [PATCH 0/3] uprobes: simplify _unregister paths Oleg Nesterov
2024-07-30 12:34 ` [PATCH 1/3] uprobes: change uprobe_register() to use uprobe_unregister() instead of __uprobe_unregister() Oleg Nesterov
2024-07-30 15:00   ` Andrii Nakryiko
2024-07-30 12:34 ` [PATCH 2/3] uprobes: fold __uprobe_unregister() into uprobe_unregister() Oleg Nesterov
2024-07-30 15:01   ` Andrii Nakryiko
2024-07-30 12:34 ` [PATCH 3/3] uprobes: shift put_uprobe() from delete_uprobe() to uprobe_unregister() Oleg Nesterov
2024-07-30 15:08   ` Andrii Nakryiko
2024-07-30 17:17     ` Oleg Nesterov
2024-07-30 17:27       ` Andrii Nakryiko
2024-07-30 20:55     ` Peter Zijlstra
2024-07-30 21:58       ` Andrii Nakryiko
2024-07-30 15:10 ` [PATCH 0/3] uprobes: simplify _unregister paths Andrii Nakryiko
2024-07-30 20:20   ` Jiri Olsa
2024-07-31  9:46 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).