Linux Trace Kernel
 help / color / mirror / Atom feed
From: Gabriele Monaco <gmonaco@redhat.com>
To: wen.yang@linux.dev
Cc: Nam Cao <namcao@linutronix.de>,
	linux-trace-kernel@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 09/14] rv: Add generic uprobe infrastructure for RV monitors
Date: Fri, 20 Nov 2026 13:12:40 +0100	[thread overview]
Message-ID: <9709becb82665468bef304ece738c17280550337.camel@redhat.com> (raw)
In-Reply-To: <21469501d58c0b7efc662226f4c9e9a9d7d32847.1793900349.git.wen.yang@linux.dev>

On Fri, 2026-11-06 at 01:49 +0800, wen.yang@linux.dev wrote:
> From: Wen Yang <wen.yang@linux.dev>
> 
> Monitors that instrument user-space function boundaries need to register
> uprobes and deregister them safely.  Provide a thin wrapper so monitors
> share a single implementation of this boilerplate.
> 
> struct rv_uprobe embeds struct uprobe_consumer directly, avoiding a
> separate heap allocation per probe.  The struct holds an inode reference
> (acquired via igrab()) for the probed binary for the full uprobe lifetime,
> as uprobe_register() does not take an inode reference.  On unregister,
> the inode reference is released with iput() only after
> rv_uprobe_unregister_sync().
> 
> rv_uprobe_unregister_sync() calls uprobe_unregister_sync(), draining
> all in-flight handlers before the containing struct may be freed.
> 
> The API provides register, nosync unregister, a global handler barrier
> (rv_uprobe_unregister_sync), and an active-state predicate.
> 
> Suggested-by: Gabriele Monaco <gmonaco@redhat.com>
> Signed-off-by: Wen Yang <wen.yang@linux.dev>
> ---

This API requires a lot of manual steps from the callers. We can refine
it later on but at least I'd simplify the teardown.

I remember we discussed this already. The uprobe registration requires
both inode and mount to stay alive, path_get() does both, so I don't
think we really need also the igrab()/iput().

Do users really need to carry the inode around together with the path?
Other APIs (e.g. bpf_trace.c and trace_uprobe.c) pass only the path and
get the inode internally, I don't see why we cannot do that and mandate
the path is owned by the caller (which is already the case).

All the other logic might be fine in the callers, but at least let's aim
to simplify what is general enough.

Thanks,
Gabriele

>  include/rv/rv_uprobe.h      | 35 +++++++++++++++++++++++
>  kernel/trace/rv/Kconfig     |  4 +++
>  kernel/trace/rv/Makefile    |  1 +
>  kernel/trace/rv/rv_uprobe.c | 56 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 96 insertions(+)
>  create mode 100644 include/rv/rv_uprobe.h
>  create mode 100644 kernel/trace/rv/rv_uprobe.c
> 
> diff --git a/include/rv/rv_uprobe.h b/include/rv/rv_uprobe.h
> new file mode 100644
> index 000000000000..b93c2a81bc22
> --- /dev/null
> +++ b/include/rv/rv_uprobe.h
> @@ -0,0 +1,35 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2026 Wen Yang <wen.yang@linux.dev> */
> +/*
> + * Generic uprobe infrastructure for RV monitors.
> + */
> +
> +#ifndef _RV_UPROBE_H
> +#define _RV_UPROBE_H
> +
> +#include <linux/types.h>
> +#include <linux/uprobes.h>
> +
> +struct inode;
> +struct pt_regs;
> +
> +/*
> + * Free the containing struct only after rv_uprobe_unregister_nosync() +
> + * rv_uprobe_unregister_sync() + iput(p->inode).
> + *
> + * The inode reference does not pin the dentry, so callers that re-resolve
> the
> + * probed path must hold a struct path: 9p cache=none remints an inode per
> + * lookup.
> + */
> +struct rv_uprobe {
> +	struct uprobe_consumer	uc;
> +	struct uprobe		*uprobe;
> +	struct inode		*inode;
> +};
> +
> +bool rv_uprobe_is_registered(const struct rv_uprobe *p);
> +int rv_uprobe_register(struct inode *inode, loff_t offset, struct rv_uprobe
> *p);
> +void rv_uprobe_unregister_nosync(struct rv_uprobe *p);
> +void rv_uprobe_unregister_sync(void);
> +
> +#endif /* _RV_UPROBE_H */
> diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig
> index efa930f94ea4..2bc412304293 100644
> --- a/kernel/trace/rv/Kconfig
> +++ b/kernel/trace/rv/Kconfig
> @@ -86,6 +86,10 @@ source "kernel/trace/rv/monitors/nomiss/Kconfig"
>  
>  # Add new monitors here
>  
> +config RV_UPROBE
> +	bool
> +	depends on RV && UPROBES
> +
>  config RV_REACTORS
>  	bool "Runtime verification reactors"
>  	default y
> diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
> index 4b84b83b942b..8dc14a1819b8 100644
> --- a/kernel/trace/rv/Makefile
> +++ b/kernel/trace/rv/Makefile
> @@ -22,6 +22,7 @@ obj-$(CONFIG_RV_MON_DEADLINE) +=
> monitors/deadline/deadline.o
>  obj-$(CONFIG_RV_MON_NOMISS) += monitors/nomiss/nomiss.o
>  obj-$(CONFIG_RV_MON_WAKEUP) += monitors/wakeup/wakeup.o
>  # Add new monitors here
> +obj-$(CONFIG_RV_UPROBE) += rv_uprobe.o
>  obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
>  obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
>  obj-$(CONFIG_RV_REACT_PANIC) += reactor_panic.o
> diff --git a/kernel/trace/rv/rv_uprobe.c b/kernel/trace/rv/rv_uprobe.c
> new file mode 100644
> index 000000000000..1c7f8466aeed
> --- /dev/null
> +++ b/kernel/trace/rv/rv_uprobe.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Generic uprobe infrastructure for RV monitors.
> + */
> +#include <linux/fs.h>
> +#include <linux/uprobes.h>
> +#include <rv/rv_uprobe.h>
> +
> +/*
> + * uprobe_register() takes no inode reference of its own, so grab one here
> and
> + * drop it only after rv_uprobe_unregister_sync().
> + */
> +int rv_uprobe_register(struct inode *inode, loff_t offset, struct rv_uprobe
> *p)
> +{
> +	int ret;
> +
> +	p->inode = igrab(inode);
> +	if (!p->inode)
> +		return -ESTALE;
> +
> +	p->uprobe = uprobe_register(inode, offset, 0, &p->uc);
> +	if (IS_ERR(p->uprobe)) {
> +		ret = PTR_ERR(p->uprobe);
> +		p->uprobe = NULL;
> +		iput(p->inode);
> +		p->inode = NULL;
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(rv_uprobe_register);
> +
> +bool rv_uprobe_is_registered(const struct rv_uprobe *p)
> +{
> +	return p && p->uprobe;
> +}
> +EXPORT_SYMBOL_GPL(rv_uprobe_is_registered);
> +
> +/* The inode stays held: in-flight handlers may still reach it. */
> +void rv_uprobe_unregister_nosync(struct rv_uprobe *p)
> +{
> +	if (!p || !p->uprobe)
> +		return;
> +
> +	uprobe_unregister_nosync(p->uprobe, &p->uc);
> +	p->uprobe = NULL;
> +}
> +EXPORT_SYMBOL_GPL(rv_uprobe_unregister_nosync);
> +
> +/* Global barrier over every probe dequeued so far. */
> +void rv_uprobe_unregister_sync(void)
> +{
> +	uprobe_unregister_sync();
> +}
> +EXPORT_SYMBOL_GPL(rv_uprobe_unregister_sync);


  reply	other threads:[~2026-11-20 12:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 17:49 [PATCH v8 00/14] rv: Add task latency over budget RV monitor wen.yang
2026-11-05 17:49 ` [PATCH v8 01/14] rv: Force environment reset action on HA monitor start wen.yang
2026-11-05 17:49 ` [PATCH v8 02/14] rv: Fix ha_monitor timer and invariant underflow wen.yang
2026-11-19 14:34   ` Gabriele Monaco
2026-11-05 17:49 ` [PATCH v8 03/14] rv: Add a KUnit test for the HA timer underflow wen.yang
2026-11-19 15:07   ` Gabriele Monaco
2026-11-05 17:49 ` [PATCH v8 04/14] rv: Disarm HA timers on the storage free path wen.yang
2026-11-05 17:49 ` [PATCH v8 05/14] rv: Add a KUnit test for " wen.yang
2026-11-05 17:49 ` [PATCH v8 06/14] rv: Make da_monitor_reset_hook, sync_hook and EVENT_NONE_LBL overridable wen.yang
2026-11-05 17:49 ` [PATCH v8 07/14] rv: Introduce DA_MON_ALLOCATION_STRATEGY wen.yang
2026-11-05 17:49 ` [PATCH v8 08/14] rv: Support embedded target types in per-object DA storage wen.yang
2026-11-20  8:12   ` Gabriele Monaco
2026-11-05 17:49 ` [PATCH v8 09/14] rv: Add generic uprobe infrastructure for RV monitors wen.yang
2026-11-20 12:12   ` Gabriele Monaco [this message]
2026-11-05 17:49 ` [PATCH v8 10/14] rv: Add tlob model DOT file wen.yang
2026-11-05 17:49 ` [PATCH v8 11/14] rv: Add tlob hybrid automaton monitor wen.yang
2026-11-05 17:49 ` [PATCH v8 12/14] rv: Add KUnit tests for the tlob monitor wen.yang
2026-11-05 17:49 ` [PATCH v8 13/14] selftests/verification: Add tlob selftests wen.yang
2026-11-05 17:49 ` [PATCH v8 14/14] selftests/ftrace: Walk up parent dirs to find test.d/functions wen.yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9709becb82665468bef304ece738c17280550337.camel@redhat.com \
    --to=gmonaco@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=namcao@linutronix.de \
    --cc=wen.yang@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox