From: Wen Yang <wen.yang@linux.dev>
To: Gabriele Monaco <gmonaco@redhat.com>
Cc: Nam Cao <namcao@linutronix.de>,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/8] rv: add generic uprobe infrastructure for RV monitors
Date: Thu, 20 Aug 2026 02:29:00 +0800 [thread overview]
Message-ID: <030e600b-1df2-4118-93ba-a1e83635b092@linux.dev> (raw)
In-Reply-To: <55912ee1fc569e5c81e25a32d516db54d1986336.camel@redhat.com>
On 7/20/26 23:22, Gabriele Monaco wrote:
> On Wed, 2026-07-08 at 23:38 +0800, wen.yang@linux.dev wrote:
>> From: Wen Yang <wen.yang@linux.dev>
>>
>> +++ b/kernel/trace/rv/Kconfig
>> @@ -59,6 +59,13 @@ config RV_PER_TASK_MONITORS
>> This option configures the maximum number of per-task RV monitors
>> that can run
>> simultaneously.
>>
>> +config RV_UPROBE
>> + bool
>> + depends on RV && UPROBES
>> + help
>> + Generic uprobe infrastructure for RV monitors. Provides path
>> + resolution, registration, and safe synchronous teardown.
>
> This isn't exposed, it's selected automatically when required, I don't
> even think the help text is visible (menuconfig doesn't show it), do we
> really need it?
>
Thanks, the bool config stays (it gates the obj build for monitors that
need it)but the invisible help text is dropped in v5; the entry is now just:
config RV_UPROBE
bool
depends on RV && UPROBES
>> +
>> source "kernel/trace/rv/monitors/wip/Kconfig"
>> source "kernel/trace/rv/monitors/wwnr/Kconfig"
>>
>
> ...
>
>> +++ b/kernel/trace/rv/rv_uprobe.c
>> @@ -0,0 +1,104 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Generic uprobe infrastructure for RV monitors.
>> + *
>> + * struct rv_uprobe embeds struct uprobe_consumer directly. This is safe
>> + * because rv_uprobe_sync() calls uprobe_unregister_sync(), which calls
>> + * synchronize_rcu_tasks_trace(). handler_chain() runs under
>> + * rcu_read_lock_trace(), so after synchronize_rcu_tasks_trace() returns,
>> + * all in-flight handler_chain() iterations, including any pending
>> + * uc->cons_node.next reads, have completed on all CPUs. The caller may
>> + * then free the struct containing rv_uprobe immediately.
>> + */
>> +#include <linux/dcache.h>
>> +#include <linux/fs.h>
>> +#include <linux/namei.h>
>> +#include <linux/uprobes.h>
>> +#include <rv/rv_uprobe.h>
>> +
>> +/**
>> + * rv_uprobe_register - initialise and register an uprobe
>> + */
>> +int rv_uprobe_register(const char *binpath, loff_t offset, struct rv_uprobe
>> *p)
>> +{
>> + struct inode *inode;
>> + struct path path;
>> + int ret;
>> +
>> + if (!p->uc.handler && !p->uc.ret_handler)
>> + return -EINVAL;
>
> uprobe_register() does this already, do we need it here too?
>
>> +
>> + ret = kern_path(binpath, LOOKUP_FOLLOW, &path);
>> + if (ret)
>> + return ret;
>> +
>> + if (!d_is_reg(path.dentry)) {
>> + path_put(&path);
>> + return -EINVAL;
>> + }
>> +
>> + inode = d_real_inode(path.dentry);
>> + p->inode = inode;
>> +
>> + /*
>> + * uprobe_register() requires the inode (and mount) to remain
>> + * referenced across the call. Keep the path alive until after
>> + * uprobe_register() has stored its own reference, then release it.
>> + */
>> + p->uprobe = uprobe_register(inode, offset, 0, &p->uc);
>> + path_put(&path);
>
> I believe I was mistaken here, as sashiko pointed out, uprobe_register()
> doesn't keep a reference to the inode, (explicitly stated in it's docs:
> "Caller of uprobe_register() is required to keep @inode (and the
> containing mount) referenced.").
>
> We should probably revert back to holding path instead of inode and
> putting it after synchronous cleanup. That's also what BPF does.
>
Thanks.
Done in v5: struct rv_uprobe now keeps a struct path to the probed
binary. rv_uprobe_register() resolves it via kern_path() and does not
drop it after uprobe_register(); rv_uprobe_unregister() releases it with
path_put() only after rv_uprobe_sync() has drained in-flight handlers,
so no inode reference outlives the probe.
--
Best wishes,
Wen
>
>> + if (IS_ERR(p->uprobe)) {
>> + ret = PTR_ERR(p->uprobe);
>> + p->uprobe = NULL;
>> + p->inode = NULL;
>> + return ret;
>> + }
>> +
>> + return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(rv_uprobe_register);
>> +
>> +/**
>> + * rv_uprobe_is_registered - test whether an uprobe is currently active
>> + */
>> +bool rv_uprobe_is_registered(const struct rv_uprobe *p)
>> +{
>> + return p && p->uprobe;
>> +}
>> +EXPORT_SYMBOL_GPL(rv_uprobe_is_registered);
>> +
>> +/**
>> + * rv_uprobe_unregister - synchronously unregister a uprobe
>> + */
>> +void rv_uprobe_unregister(struct rv_uprobe *p)
>> +{
>> + if (!p || !p->uprobe)
>> + return;
>> +
>> + rv_uprobe_unregister_nosync(p);
>> + rv_uprobe_sync();
>> +}
>> +EXPORT_SYMBOL_GPL(rv_uprobe_unregister);
>> +
>> +/**
>> + * rv_uprobe_unregister_nosync - dequeue an uprobe without waiting
>> + */
>> +void rv_uprobe_unregister_nosync(struct rv_uprobe *p)
>> +{
>> + if (!p || !p->uprobe)
>> + return;
>> +
>> + uprobe_unregister_nosync(p->uprobe, &p->uc);
>> + p->uprobe = NULL;
>> + p->inode = NULL;
>> +}
>> +EXPORT_SYMBOL_GPL(rv_uprobe_unregister_nosync);
>> +
>> +/**
>> + * rv_uprobe_sync - wait for all in-flight uprobe handlers to complete
>> + */
>> +void rv_uprobe_sync(void)
>> +{
>> + uprobe_unregister_sync();
>> +}
>> +EXPORT_SYMBOL_GPL(rv_uprobe_sync);
>
next prev parent reply other threads:[~2026-08-19 18:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 15:38 [PATCH v4 0/8] rv/tlob: Add task latency over budget RV monitor wen.yang
2026-07-08 15:38 ` [PATCH v4 1/8] rv/da: introduce DA_MON_ALLOCATION_STRATEGY wen.yang
2026-07-17 13:46 ` Gabriele Monaco
2026-08-19 18:25 ` Wen Yang
2026-07-20 10:23 ` Gabriele Monaco
2026-07-08 15:38 ` [PATCH v4 2/8] rv: add generic uprobe infrastructure for RV monitors wen.yang
2026-07-20 15:22 ` Gabriele Monaco
2026-08-19 18:29 ` Wen Yang [this message]
2026-07-08 15:38 ` [PATCH v4 3/8] rv/tlob: add tlob model DOT file wen.yang
2026-07-08 15:38 ` [PATCH v4 4/8] rv/ha: fix ha_invariant_passed_ns silent bypass of invariant check wen.yang
2026-07-20 11:31 ` Gabriele Monaco
2026-07-08 15:38 ` [PATCH v4 5/8] rv/ha: make da_monitor_reset_hook and EVENT_NONE_LBL overridable wen.yang
2026-07-08 15:38 ` [PATCH v4 6/8] rv/tlob: add tlob hybrid automaton monitor wen.yang
2026-07-20 14:49 ` Gabriele Monaco
2026-08-19 18:34 ` Wen Yang
2026-07-08 15:38 ` [PATCH v4 7/8] rv/tlob: add KUnit tests for the tlob monitor wen.yang
2026-07-22 14:42 ` Gabriele Monaco
2026-07-08 15:38 ` [PATCH v4 8/8] selftests/verification: add tlob selftests wen.yang
2026-07-22 13:34 ` Gabriele Monaco
2026-07-22 13:59 ` Gabriele Monaco
2026-07-23 13:29 ` Gabriele Monaco
2026-07-23 11:53 ` [PATCH v4 0/8] rv/tlob: Add task latency over budget RV monitor Gabriele Monaco
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=030e600b-1df2-4118-93ba-a1e83635b092@linux.dev \
--to=wen.yang@linux.dev \
--cc=gmonaco@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=namcao@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.