* [PATCH perf/core] uprobes: remove too strict lockdep_assert() condition in hprobe_expire()
@ 2025-02-25 22:32 Andrii Nakryiko
2025-02-26 10:41 ` Jiri Olsa
2025-02-26 11:30 ` Oleg Nesterov
0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2025-02-25 22:32 UTC (permalink / raw)
To: linux-trace-kernel, peterz, mingo
Cc: oleg, bpf, linux-kernel, jolsa, kernel-team, Andrii Nakryiko,
Breno Leitao
hprobe_expire() is used to atomically switch pending uretprobe instance
(struct return_instance) from being SRCU protected to be refcounted.
This can be done from background timer thread, or synchronously within
current thread when task is forked.
In the former case, return_instance has to be protected through RCU read
lock, and that's what hprobe_expire() used to check with
lockdep_assert(rcu_read_lock_held()).
But in the latter case (hprobe_expire() called from dup_utask()) there
is no RCU lock being held, and it's both unnecessary and incovenient.
Inconvenient due to the intervening memory allocations inside
dup_return_instance()'s loop. Unnecessary because dup_utask() is called
synchronously in current thread, and no uretprobe can run at that point,
so return_instance can't be freed either.
So drop rcu_read_lock_held() condition, and expand corresponding comment
to explain necessary lifetime guarantees. lockdep_assert()-detected
issue is a false positive.
Fixes: dd1a7567784e ("uprobes: SRCU-protect uretprobe lifetime (with timeout)")
Reported-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
kernel/events/uprobes.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index e783da1d1762..4d2140cab7ec 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -762,10 +762,14 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)
enum hprobe_state hstate;
/*
- * return_instance's hprobe is protected by RCU.
- * Underlying uprobe is itself protected from reuse by SRCU.
+ * Caller should guarantee that return_instance is not going to be
+ * freed from under us. This can be achieved either through holding
+ * rcu_read_lock() or by owning return_instance in the first place.
+ *
+ * Underlying uprobe is itself protected from reuse by SRCU, so ensure
+ * SRCU lock is held properly.
*/
- lockdep_assert(rcu_read_lock_held() && srcu_read_lock_held(&uretprobes_srcu));
+ lockdep_assert(srcu_read_lock_held(&uretprobes_srcu));
hstate = READ_ONCE(hprobe->state);
switch (hstate) {
--
2.43.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH perf/core] uprobes: remove too strict lockdep_assert() condition in hprobe_expire()
2025-02-25 22:32 [PATCH perf/core] uprobes: remove too strict lockdep_assert() condition in hprobe_expire() Andrii Nakryiko
@ 2025-02-26 10:41 ` Jiri Olsa
2025-02-26 11:30 ` Oleg Nesterov
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2025-02-26 10:41 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: linux-trace-kernel, peterz, mingo, oleg, bpf, linux-kernel,
kernel-team, Breno Leitao
On Tue, Feb 25, 2025 at 02:32:14PM -0800, Andrii Nakryiko wrote:
> hprobe_expire() is used to atomically switch pending uretprobe instance
> (struct return_instance) from being SRCU protected to be refcounted.
> This can be done from background timer thread, or synchronously within
> current thread when task is forked.
>
> In the former case, return_instance has to be protected through RCU read
> lock, and that's what hprobe_expire() used to check with
> lockdep_assert(rcu_read_lock_held()).
>
> But in the latter case (hprobe_expire() called from dup_utask()) there
> is no RCU lock being held, and it's both unnecessary and incovenient.
> Inconvenient due to the intervening memory allocations inside
> dup_return_instance()'s loop. Unnecessary because dup_utask() is called
> synchronously in current thread, and no uretprobe can run at that point,
> so return_instance can't be freed either.
>
> So drop rcu_read_lock_held() condition, and expand corresponding comment
> to explain necessary lifetime guarantees. lockdep_assert()-detected
> issue is a false positive.
>
> Fixes: dd1a7567784e ("uprobes: SRCU-protect uretprobe lifetime (with timeout)")
> Reported-by: Breno Leitao <leitao@debian.org>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
lgtm
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> kernel/events/uprobes.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index e783da1d1762..4d2140cab7ec 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -762,10 +762,14 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)
> enum hprobe_state hstate;
>
> /*
> - * return_instance's hprobe is protected by RCU.
> - * Underlying uprobe is itself protected from reuse by SRCU.
> + * Caller should guarantee that return_instance is not going to be
> + * freed from under us. This can be achieved either through holding
> + * rcu_read_lock() or by owning return_instance in the first place.
> + *
> + * Underlying uprobe is itself protected from reuse by SRCU, so ensure
> + * SRCU lock is held properly.
> */
> - lockdep_assert(rcu_read_lock_held() && srcu_read_lock_held(&uretprobes_srcu));
> + lockdep_assert(srcu_read_lock_held(&uretprobes_srcu));
>
> hstate = READ_ONCE(hprobe->state);
> switch (hstate) {
> --
> 2.43.5
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH perf/core] uprobes: remove too strict lockdep_assert() condition in hprobe_expire()
2025-02-25 22:32 [PATCH perf/core] uprobes: remove too strict lockdep_assert() condition in hprobe_expire() Andrii Nakryiko
2025-02-26 10:41 ` Jiri Olsa
@ 2025-02-26 11:30 ` Oleg Nesterov
1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2025-02-26 11:30 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: linux-trace-kernel, peterz, mingo, bpf, linux-kernel, jolsa,
kernel-team, Breno Leitao
On 02/25, Andrii Nakryiko wrote:
>
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -762,10 +762,14 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)
> enum hprobe_state hstate;
>
> /*
> - * return_instance's hprobe is protected by RCU.
> - * Underlying uprobe is itself protected from reuse by SRCU.
> + * Caller should guarantee that return_instance is not going to be
> + * freed from under us. This can be achieved either through holding
> + * rcu_read_lock() or by owning return_instance in the first place.
> + *
> + * Underlying uprobe is itself protected from reuse by SRCU, so ensure
> + * SRCU lock is held properly.
> */
> - lockdep_assert(rcu_read_lock_held() && srcu_read_lock_held(&uretprobes_srcu));
> + lockdep_assert(srcu_read_lock_held(&uretprobes_srcu));
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-26 11:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-25 22:32 [PATCH perf/core] uprobes: remove too strict lockdep_assert() condition in hprobe_expire() Andrii Nakryiko
2025-02-26 10:41 ` Jiri Olsa
2025-02-26 11:30 ` Oleg Nesterov
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).