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 11/14] rv: Add tlob hybrid automaton monitor
Date: Fri, 20 Nov 2026 17:37:55 +0100 [thread overview]
Message-ID: <df35b9bf6b509a02b96d8aea8224ad538275e356.camel@redhat.com> (raw)
In-Reply-To: <3471283eefd839c47fdd0fd2cfd6ac4e28a342dc.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>
>
> tlob (task latency over budget) is a per-task hybrid automaton RV
> monitor that tracks wall-clock time across a user-delimited code
> section and emits an error when the elapsed time exceeds a configurable
> budget.
>
> The monitor tracks four states (running, waiting, sleeping, stopped)
> driven by sched_switch and sched_wakeup tracepoints. A single clock
> invariant, clk_elapsed < BUDGET_NS(), is enforced by a per-task hrtimer
> (HRTIMER_MODE_REL_HARD). On expiry error_env_tlob is emitted; which
> phase consumed the budget (running, waiting or sleeping) is recovered
> from event_tlob in user space.
>
> Tasks are registered for monitoring by writing to the tracefs monitor
> file using the ftrace uprobe_events convention:
> echo "p:myregion /path/to/binary:OFFSET_START OFFSET_STOP threshold=NS" \
> >> /sys/kernel/tracing/rv/monitors/tlob/monitor
>
> The per-task monitoring record is embedded directly into struct
> da_monitor_storage via DA_OBJ_EMBEDDED_TYPE, eliminating the need for a
> private mempool, separate RCU reclamation, or parallel OPEN/CLOSED/RETIRED
> states. Window transitions and reentrancy are managed directly by the
> automaton model and framework storage lifecycle.
>
> Suggested-by: Gabriele Monaco <gmonaco@redhat.com>
> Signed-off-by: Wen Yang <wen.yang@linux.dev>
> ---
That's the right direction, I still have a few comments.
Remember the goal here is to keep handlers/constraints as simple as
possible and as close as possible to what rvgen gives, so the source is
an almost direct product of the model.
...
> diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig
> index 2bc412304293..68f0b9bc2dc3 100644
> --- a/kernel/trace/rv/Kconfig
> +++ b/kernel/trace/rv/Kconfig
> @@ -82,6 +82,7 @@ source "kernel/trace/rv/monitors/wakeup/Kconfig"
> source "kernel/trace/rv/monitors/stall/Kconfig"
> source "kernel/trace/rv/monitors/deadline/Kconfig"
> source "kernel/trace/rv/monitors/nomiss/Kconfig"
> +source "kernel/trace/rv/monitors/tlob/Kconfig"
This shouldn't be here, otherwise it's breaking the generation script
for new deadline models.
> # Add new deadline monitors here
>
It should be here (like you had on V7 and like rvgen does).
> # Add new monitors here
> diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
> index 8dc14a1819b8..99a8dceb829f 100644
> --- a/kernel/trace/rv/Makefile
> +++ b/kernel/trace/rv/Makefile
> @@ -20,6 +20,7 @@ obj-$(CONFIG_RV_MON_OPID) += monitors/opid/opid.o
> obj-$(CONFIG_RV_MON_STALL) += monitors/stall/stall.o
> obj-$(CONFIG_RV_MON_DEADLINE) += monitors/deadline/deadline.o
> obj-$(CONFIG_RV_MON_NOMISS) += monitors/nomiss/nomiss.o
> +obj-$(CONFIG_RV_MON_TLOB) += monitors/tlob/tlob.o
> obj-$(CONFIG_RV_MON_WAKEUP) += monitors/wakeup/wakeup.o
> # Add new monitors here
> obj-$(CONFIG_RV_UPROBE) += rv_uprobe.o
> diff --git a/kernel/trace/rv/monitors/tlob/Kconfig
> b/kernel/trace/rv/monitors/tlob/Kconfig
> new file mode 100644
> index 000000000000..4f072a9a4da2
> --- /dev/null
> +++ b/kernel/trace/rv/monitors/tlob/Kconfig
> @@ -0,0 +1,12 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +config RV_MON_TLOB
> + bool "tlob monitor"
> + depends on RV && UPROBES && HIGH_RES_TIMERS
> + select HA_MON_EVENTS_ID
> + select RV_UPROBE
> + help
> + Enable the tlob (task latency over budget) hybrid-automaton RV
> + monitor. tlob tracks per-task elapsed time across a
> + user-delimited code section and emits a violation when the
> + elapsed time exceeds a configurable per-invocation budget.
> diff --git a/kernel/trace/rv/monitors/tlob/tlob.c
> b/kernel/trace/rv/monitors/tlob/tlob.c
> new file mode 100644
> index 000000000000..fe7d88df62f1
> --- /dev/null
> +++ b/kernel/trace/rv/monitors/tlob/tlob.c
> @@ -0,0 +1,732 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * tlob (task latency over budget) RV monitor.
> + *
> + * A per-task hybrid automaton that checks a task's elapsed time against
> + * a configurable budget across a user-delimited code section.
> + */
> +#include <linux/ftrace.h>
> +#include <linux/tracepoint.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/rv.h>
> +#include <linux/fs.h>
> +#include <linux/namei.h>
> +#include <linux/security.h>
> +#include <linux/ctype.h>
> +#include <linux/seq_file.h>
> +#include <rv/instrumentation.h>
> +#include <rv/rv_uprobe.h>
> +#include <rv.h>
It seems you're using some includes that aren't quite needed. I can
build fine without fs, seq_file and ctype.
> +
> +#define MODULE_NAME "tlob"
> +
> +#include <rv_trace.h>
> +#include <trace/events/sched.h>
> +
> +struct tlob_uprobe_binding;
Do you really need to forward declare this struct and define it later?
Cannot you just define it here?
> +
> +/*
> + * Per-task monitoring record, embedded directly in struct da_monitor_storage
> + * via DA_OBJ_EMBEDDED_TYPE. Allocated and freed with the storage.
> + */
> +struct tlob_record {
> + u64 threshold_ns;
> + struct tlob_uprobe_binding *binding;
> +};
> +
> +#define DA_OBJ_EMBEDDED_TYPE struct tlob_record
> +#define RV_MON_TYPE RV_MON_PER_OBJ
> +#define HA_TIMER_TYPE HA_TIMER_HRTIMER
> +#define DA_MON_POOL_SIZE TLOB_MAX_MONITORED
> +#define EVENT_NONE_LBL "budget_exceeded"
> +
> +#include "tlob.h"
> +#include <rv/ha_monitor.h>
> +
> +#define BUDGET_NS(ha_mon) (ha_get_target(ha_mon)->threshold_ns)
> +
> +static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs_tlob env,
> + u64 time_ns)
> +{
> + if (env == clk_elapsed_tlob)
> + return ha_get_clk_ns(ha_mon, env, time_ns);
> + return ENV_INVALID_VALUE;
> +}
> +
> +static void ha_reset_env(struct ha_monitor *ha_mon, enum envs_tlob env,
> + u64 time_ns)
> +{
> + if (env == clk_elapsed_tlob)
> + ha_reset_clk_ns(ha_mon, env, time_ns);
> +}
> +
> +/*
> + * clk_elapsed <= BUDGET_NS in running/waiting/sleeping; stopped exempt.
> + */
These functions significantly deviate from rvgen's output mostly for no
reason. That makes it harder to maintain, please stick to what rvgen
gives you with 1 exception (see later).
> +static inline bool ha_verify_invariants(struct ha_monitor *ha_mon,
> + enum states curr_state,
> + enum events event,
> + enum states next_state,
> + u64 time_ns)
> +{
> + if (curr_state == stopped_tlob)
> + return true;
> + return ha_check_invariant_ns(ha_mon, clk_elapsed_tlob, time_ns,
> + BUDGET_NS(ha_mon));
> +}
The reset_env is called by ha_verify_guards(). The compiler should
produce mostly the same code anyway.
> +
> +static inline void ha_setup_invariants(struct ha_monitor *ha_mon,
> + enum events event,
> + enum states next_state,
> + u64 time_ns)
> +{
Here you're actually doing some optimisation that does make sense,
please at least keep the original prototype (also curr_state) even if
you don't need all arguments.
I couldn't find a trivial way to represent what you're trying to do here
from the generator. rvgen is a bit too zealous with invariants, arms and
cancels every time, since you have a subgraph sharing the same
invariant, it makes sense to keep it stable.
But let's at least make it /looking like/ what rvgen gives you, then in
the future we can think if rvgen can support this case:
static inline void ha_setup_invariants(struct ha_monitor *ha_mon,
enum states curr_state, enum events event,
enum states next_state, u64 time_ns)
{
if (next_state == curr_state)
return;
/*
* Only a start arms the timer. Every other transition keeps
* the anchor, so the timer already points at the right expiry and
* re-arming it would just take the hrtimer base lock on every
* scheduler event of a monitored task.
*/
if (event == start_tlob)
ha_start_timer_ns(ha_mon, clk_elapsed_tlob, BUDGET_NS(ha_mon), time_ns);
else if (next_state == stopped_tlob)
ha_cancel_timer(ha_mon);
}
> + if (next_state == stopped_tlob) {
> + ha_cancel_timer(ha_mon);
> + return;
> + }
> +
> + /*
> + * Only a start re-anchors the clock. Every other transition keeps
> + * the anchor, so the timer already points at the right expiry and
> + * re-arming it would just take the hrtimer base lock on every
> + * scheduler event of a monitored task.
> + */
> + if (event != start_tlob)
> + return;
> +
> + ha_reset_clk_ns(ha_mon, clk_elapsed_tlob, time_ns);
> + ha_start_timer_ns(ha_mon, clk_elapsed_tlob, BUDGET_NS(ha_mon),
> + time_ns);
> +}
> +
> +static bool ha_verify_constraint(struct ha_monitor *ha_mon,
> + enum states curr_state, enum events event,
> + enum states next_state, u64 time_ns)
> +{
> + if (ha_verify_invariants(ha_mon, curr_state, event,
> + next_state, time_ns)) {
> + ha_setup_invariants(ha_mon, event, next_state, time_ns);
> + return true;
> + }
> +
> + /*
> + * The event itself found the budget exceeded, so it reports the
> + * overrun and closes the window. Without the reset the transition
> + * would still be taken with the timer left armed, and the expiry
> + * would report the same overrun a second time.
> + */
> + da_monitor_reset(&ha_mon->da_mon);
> + return false;
> +}
Then you also restore this and you should have equivalent behaviour with
minimal (though justified) modification from rvgen's.
> +
> +/*
> + * One registered uprobe pair. Multiple bindings can be active simultaneously
> + * on different binaries or on disjoint ranges of the same binary.
> + */
> +struct tlob_uprobe_binding {
> + struct list_head list;
> + char name[TLOB_MAX_NAME];
> + char binpath[TLOB_MAX_PATH];
> + loff_t offset_start;
> + loff_t offset_stop;
> + u64 threshold_ns;
> + struct path path;
> + struct rv_uprobe start_probe;
> + struct rv_uprobe stop_probe;
> +};
> +
> +static LIST_HEAD(tlob_uprobe_list);
> +static DEFINE_MUTEX(tlob_uprobe_mutex);
> +
> +static int tlob_start_task(struct task_struct *task, u64 threshold_ns,
> + struct tlob_uprobe_binding *binding)
> +{
This function is over-engineered. Nobody is checking the return value,
why all the reporting?
> + struct tlob_record *rec;
> + struct da_monitor *da_mon;
> +
> + if (!da_monitor_enabled())
> + return -ENODEV;
Alright, I'd skip this but I see you want to short circuit before doing
any other decisions. This isn't a hot path though.
> +
> + if (threshold_ns < TLOB_MIN_THRESHOLD_NS ||
> + threshold_ns > TLOB_MAX_THRESHOLD_NS)
> + return -ERANGE;
This is functional, should stay.
> +
> + scoped_guard(rcu) {
> + da_mon = da_get_monitor(task->pid, NULL);
> + if (da_mon) {
> + rec = da_get_target(da_mon);
> + if (WARN_ON_ONCE(!rec))
> + return -ENODEV;
> + /*
> + * A record left by a removed binding is adopted: the
> + * task is between windows and nothing owns it.
> + * Anything else starting it while it still belongs
> to
> + * another binding would silently shadow that window.
> + */
> + if (rec->binding && rec->binding != binding) {
> + trace_error_tlob(task->pid,
> + model_get_state_name(da_mon-
> >curr_state),
> +
> model_get_event_name(start_tlob));
> + return -EALREADY;
> + }
You aren't supposed to do custom event handling, that can go very wrong
very fast (no reactor, no proper reset, etc.)
> + /*
> + * A START while the window is still open is a model
> + * violation (running/waiting/sleeping x start). Hand
> it
> + * to the model for reporting, but leave the record
> + * untouched: adopting the new budget here would
> change
> + * the window that is already running.
> + */
> + if (da_monitoring(da_mon) &&
> + READ_ONCE(da_mon->curr_state) != stopped_tlob) {
> + da_handle_event(task->pid, NULL, start_tlob);
> + return -EALREADY;
> + }
The model already does exactly this, I see you don't want to update
before the error but it's mostly duplicated code.
> + rec->binding = binding;
> + rec->threshold_ns = threshold_ns;
> + /*
> + * Not da_handle_event(): a violation reset the
> + * monitor, and a plain event is dropped while
> + * !da_monitoring(). This restarts it and runs start.
> + */
> + return da_handle_start_run_event(task->pid, NULL,
> + start_tlob) ? 0 :
> + -
> ENODEV;
> + }
> + }
> +
> + struct tlob_record init_rec = {
> + .threshold_ns = threshold_ns,
> + .binding = binding,
> + };
> +
> + if (da_handle_start_run_event(task->pid, &init_rec, start_tlob))
> + return 0;
> +
> + /*
> + * The framework reports a disabled monitor and an exhausted pool the
> + * same way. Storage is published only once a pool slot was claimed,
> + * so its absence means the pool is what ran out.
> + */
> + scoped_guard(rcu)
> + da_mon = da_get_monitor(task->pid, NULL);
> + if (da_mon)
> + return -ENODEV;
> +
> + pr_warn_once("%s: no free record, task %d stays unmonitored\n",
> + __stringify(MODULE_NAME), task->pid);
> + return -ENOSPC;
> +}
So essentially here you could do pretty much only
da_handle_start_run_event(task->pid, &init_rec, start_tlob)
Then you'd lose:
1. Error on a sequential binding
2. Reporting for no free space
3. After unbinding and re-binding, we no longer update
Is 1. really a use case? I suppose you could create a dummy
"start_shadowed" event only possible in an "unreachable" state and
trigger it on every start with different binding, but do you really have
to?
2. is something we may want to report on a framework level. Essentially
we could transform the unlikely(!da_mon) into a WARN_ON_ONCE(!da_mon)
after da_prepare_storage() and be done with it.
3. I would really like to just destroy the storage during unbind and
have the framework fill it again during the next start, I'm afraid that
might require some care though.
If that gets too complicated, I guess it's alright to just override it
when binding is NULL during start and let the model continue with that.
Would this be enough?
> +
> +static int tlob_stop_task(struct task_struct *task,
> + struct tlob_uprobe_binding *binding)
> +{
> + struct tlob_record *rec;
> + struct da_monitor *da_mon;
> +
> + if (!da_monitor_enabled())
> + return -ENODEV;
> +
> + scoped_guard(rcu) {
> + da_mon = da_get_monitor(task->pid, NULL);
> + if (!da_mon)
> + return -ESRCH;
> +
> + rec = da_get_target(da_mon);
> + if (WARN_ON_ONCE(!rec))
> + return -ENODEV;
> + if (binding && rec->binding && rec->binding != binding)
> + return -EINVAL;
Now I wonder what are all these covering. Why do we need to account for
an invalid event? Can it really happen or are you just being over
cautious? Nobody checks the return value anyway.
I assume this kind of stop during a window happens only for overlapping
windows, which aren't allowed, are they?
> +
> + /*
> + * A budget overrun already closed the window and reset the
> + * monitor; the STOP that follows must not report again.
> + */
> + if (!da_monitoring(da_mon))
> + return 0;
Do you really need this? If you aren't monitoring, the model is already
ignoring the event.
> +
> + da_handle_event(task->pid, NULL, stop_tlob);
> + }
All in all in this function I'd really just da_handle_event(), which
should do everything you need. Then always return 0.
> + return 0;
> +}
> +
> +static void handle_sched_switch(void *data, bool preempt,
> + struct task_struct *prev,
> + struct task_struct *next,
> + unsigned int prev_state)
> +{
> + if (!preempt && prev_state != TASK_RUNNING)
> + da_handle_event(prev->pid, NULL, sleep_tlob);
> + else
> + da_handle_event(prev->pid, NULL, preempt_tlob);
> +
> + da_handle_event(next->pid, NULL, switch_in_tlob);
> +}
> +
> +static void handle_sched_wakeup(void *data, struct task_struct *p)
> +{
> + da_handle_event(p->pid, NULL, wakeup_tlob);
> +}
> +
> +static void handle_sched_process_exit(void *data, struct task_struct *p,
> + bool group_dead)
> +{
> + da_destroy_storage(p->pid);
> +}
> +
> +static int tlob_uprobe_entry_handler(struct uprobe_consumer *self,
> + struct pt_regs *regs, __u64 *data)
> +{
> + struct tlob_uprobe_binding *b =
> + container_of(self, struct tlob_uprobe_binding,
> start_probe.uc);
> +
> + tlob_start_task(current, b->threshold_ns, b);
> + return 0;
> +}
> +
> +static int tlob_uprobe_stop_handler(struct uprobe_consumer *self,
> + struct pt_regs *regs, __u64 *data)
> +{
> + struct tlob_uprobe_binding *b =
> + container_of(self, struct tlob_uprobe_binding,
> stop_probe.uc);
> +
> + tlob_stop_task(current, b);
> + return 0;
> +}
> +
> +/*
> + * tlob_release_binding - stop tracking the windows opened by @binding
> + *
> + * A binding may be removed while tasks are still inside its windows. Their
> + * timers are armed and would report an overrun against a binding that no
> + * longer exists, so reset those monitors once no handler can run anymore.
> + * The record is left in place and its owner cleared: a later START, possibly
> + * from another binding, adopts and restarts it.
> + *
> + * Runs after rv_uprobe_unregister_sync(), which is what makes the walk free
> + * of concurrent writers to rec->binding.
> + */
> +static void tlob_release_binding(struct tlob_uprobe_binding *binding)
> +{
> + struct da_monitor_storage *mon_storage;
> + int bkt;
> +
> + guard(rcu)();
> + hash_for_each_rcu(da_monitor_ht, bkt, mon_storage, node) {
> + struct tlob_record *rec = da_get_target(&mon_storage-
> >rv.da_mon);
> +
> + if (rec && rec->binding == binding) {
> + rec->binding = NULL;
> + da_monitor_reset(&mon_storage->rv.da_mon);
> + }
> + }
> +}
> +
> +static void tlob_unbind(struct tlob_uprobe_binding *b)
> +{
> + rv_uprobe_unregister_nosync(&b->start_probe);
> + rv_uprobe_unregister_nosync(&b->stop_probe);
> + rv_uprobe_unregister_sync();
I wonder if this further sync should be part of the framework (now
it assumes tracepoints only), but it would probably add some duplicate
waiting.
Leave it for now, but it's something to think about.
> +
> + tlob_release_binding(b);
> +
> + iput(b->start_probe.inode);
> + iput(b->stop_probe.inode);
This is what I meant in the uprobe series, cannot we just pass the
path around and let rv_uprobe handle inodes?
> + path_put(&b->path);
> +}
> +
> +static int tlob_remove_uprobe_by_name(const char *name)
> +{
> + struct tlob_uprobe_binding *b, *tmp;
> +
> + guard(mutex)(&tlob_uprobe_mutex);
> +
> + list_for_each_entry_safe(b, tmp, &tlob_uprobe_list, list) {
> + if (strcmp(b->name, name))
> + continue;
> + list_del(&b->list);
> + tlob_unbind(b);
> + kfree(b);
> + return 0;
> + }
> +
> + return -ENOENT;
> +}
> +
> +static void tlob_remove_all_uprobes(void)
> +{
> + struct tlob_uprobe_binding *b, *tmp;
> + LIST_HEAD(pending);
> +
> + guard(mutex)(&tlob_uprobe_mutex);
> +
> + list_for_each_entry_safe(b, tmp, &tlob_uprobe_list, list) {
> + list_move(&b->list, &pending);
> + rv_uprobe_unregister_nosync(&b->start_probe);
> + rv_uprobe_unregister_nosync(&b->stop_probe);
> + }
> +
> + if (list_empty(&pending))
> + return;
> +
> + rv_uprobe_unregister_sync();
> +
> + list_for_each_entry_safe(b, tmp, &pending, list) {
> + list_del(&b->list);
> + tlob_release_binding(b);
> + iput(b->start_probe.inode);
> + iput(b->stop_probe.inode);
> + path_put(&b->path);
> + kfree(b);
> + }
> +}
> +
> +static int tlob_add_uprobe(const char *name, const char *binpath,
> + loff_t offset_start, loff_t offset_stop,
> + u64 threshold_ns)
> +{
> + struct tlob_uprobe_binding *tmp_b;
> + char pathbuf[TLOB_MAX_PATH];
> + struct inode *inode;
> + struct path path __free(path_put) = {};
> + char *canon;
> + int ret;
> +
> + guard(mutex)(&tlob_uprobe_mutex);
> +
> + if (binpath[0] != '/')
> + return -EINVAL;
> +
> + struct tlob_uprobe_binding *b __free(kfree) =
> + kzalloc_obj(*b, GFP_KERNEL);
> + if (!b)
> + return -ENOMEM;
> +
> + strscpy(b->name, name, sizeof(b->name));
> + b->threshold_ns = threshold_ns;
> + b->offset_start = offset_start;
> + b->offset_stop = offset_stop;
> +
> + ret = kern_path(binpath, LOOKUP_FOLLOW, &path);
> + if (ret)
> + return ret;
> +
> + if (!d_is_reg(path.dentry))
> + return -EINVAL;
> +
> + inode = d_real_inode(path.dentry);
> +
> + /*
> + * Names are unique, and so are ranges on the same binary: a task
> + * runs one window at a time, the second would silently shadow the
> + * first. Direction normalised so a reversed start/stop still
> matches.
> + */
> + list_for_each_entry(tmp_b, &tlob_uprobe_list, list) {
> + loff_t s1, e1, s2, e2;
> +
> + if (strcmp(tmp_b->name, name) == 0)
> + return -EEXIST;
> + if (!rv_uprobe_is_registered(&tmp_b->start_probe))
> + continue;
> + if (tmp_b->start_probe.inode != inode)
> + continue;
> +
> + s1 = min(offset_start, offset_stop);
> + e1 = max(offset_start, offset_stop);
> + s2 = min(tmp_b->offset_start, tmp_b->offset_stop);
> + e2 = max(tmp_b->offset_start, tmp_b->offset_stop);
> + if (s1 <= e2 && s2 <= e1)
> + return -EEXIST;
> + }
> +
> + canon = d_path(&path, pathbuf, sizeof(pathbuf));
> + if (IS_ERR(canon))
> + return PTR_ERR(canon);
> + strscpy(b->binpath, canon, sizeof(b->binpath));
> +
> + b->start_probe.uc.handler = tlob_uprobe_entry_handler;
> + ret = rv_uprobe_register(inode, offset_start, &b->start_probe);
> + if (ret)
> + return ret;
> +
> + b->stop_probe.uc.handler = tlob_uprobe_stop_handler;
> + ret = rv_uprobe_register(inode, offset_stop, &b->stop_probe);
> + if (ret) {
> + tlob_unbind(b);
> + return ret;
> + }
> +
> + b->path = path;
> + path_get(&b->path);
Do not path_get() to compensate the cleanup, it's confusing.
This is an unconventional one because it isn't a pointer,
apparently to borrow the path you can do memset(&path, 0, sizeof(path))
(what no_free_ptr would do if it were a pointer), see
__trace_uprobe_create() in kernel/trace/trace_uprobe.c , you can copy
the comment from there.
> +
> + list_add_tail(&no_free_ptr(b)->list, &tlob_uprobe_list);
> + return 0;
> +}
> +
> +static void *tlob_seq_start(struct seq_file *m, loff_t *pos)
> +{
> + mutex_lock(&tlob_uprobe_mutex);
> + return seq_list_start(&tlob_uprobe_list, *pos);
> +}
> +
> +static void *tlob_seq_next(struct seq_file *m, void *v, loff_t *pos)
> +{
> + return seq_list_next(v, &tlob_uprobe_list, pos);
> +}
> +
> +static void tlob_seq_stop(struct seq_file *m, void *v)
> +{
> + mutex_unlock(&tlob_uprobe_mutex);
> +}
> +
> +static int tlob_seq_show(struct seq_file *m, void *v)
> +{
> + struct tlob_uprobe_binding *b =
> + list_entry(v, struct tlob_uprobe_binding, list);
> +
> + seq_printf(m, "p:%s %s:0x%llx 0x%llx threshold=%llu\n",
> + b->name, b->binpath,
> + (unsigned long long)b->offset_start,
> + (unsigned long long)b->offset_stop,
> + b->threshold_ns);
> + return 0;
> +}
> +
> +static const struct seq_operations tlob_monitor_seq_ops = {
> + .start = tlob_seq_start,
> + .next = tlob_seq_next,
> + .stop = tlob_seq_stop,
> + .show = tlob_seq_show,
> +};
> +
> +static int tlob_parse_uprobe_line(char *buf, char **name_out, char
> **path_out,
> + loff_t *start_out, loff_t *stop_out,
> + u64 *thr_out)
> +{
> + unsigned long long thr = 0, stop_val = 0;
> + long long start_val;
> + char *p, *name, *path_token, *token, *colon;
> + bool got_stop = false, got_thr = false;
> +
> + if (buf[0] != 'p' || buf[1] != ':')
> + return -EINVAL;
> +
> + p = buf + 2;
> + while (*p == ' ' || *p == '\t')
> + p++;
> +
> + name = strsep(&p, " \t");
> + if (strlen(name) >= TLOB_MAX_NAME || !is_good_name(name))
> + return -EINVAL;
> +
> + if (!p)
> + return -EINVAL;
> + while (*p == ' ' || *p == '\t')
> + p++;
> + path_token = strsep(&p, " \t");
> + if (!path_token || !*path_token)
> + return -EINVAL;
> +
> + colon = strrchr(path_token, ':');
> + if (!colon || colon - path_token < 2)
> + return -EINVAL;
> + *colon = '\0';
> +
> + if (path_token[0] != '/')
> + return -EINVAL;
> +
> + if (kstrtoll(colon + 1, 0, &start_val))
> + return -EINVAL;
> + if (start_val < 0)
> + return -EINVAL;
> +
> + while (p && (token = strsep(&p, " \t")) != NULL) {
> + if (!*token)
> + continue;
> + if (strncmp(token, "threshold=", 10) == 0) {
> + if (got_thr)
> + return -EINVAL;
> + if (kstrtoull(token + 10, 0, &thr))
> + return -EINVAL;
> + if (thr < TLOB_MIN_THRESHOLD_NS ||
> + thr > TLOB_MAX_THRESHOLD_NS)
> + return -ERANGE;
> + got_thr = true;
> + } else if (!got_stop) {
> + long long sv;
> +
> + if (kstrtoll(token, 0, &sv))
> + return -EINVAL;
> + if (sv < 0)
> + return -EINVAL;
> + stop_val = (unsigned long long)sv;
> + got_stop = true;
> + } else {
> + return -EINVAL;
> + }
> + }
> +
> + if (!got_stop || !got_thr)
> + return -EINVAL;
> + if (start_val == (long long)stop_val)
> + return -EINVAL;
> +
> + *name_out = name;
> + *thr_out = thr;
> + *path_out = path_token;
> + *start_out = (loff_t)start_val;
> + *stop_out = (loff_t)stop_val;
> + return 0;
> +}
> +
> +static int tlob_parse_remove_line(char *buf, char **name_out)
> +{
> + char *name = buf + 2;
> +
> + if (buf[0] != '-' || buf[1] != ':')
> + return -EINVAL;
> + if (strlen(name) >= TLOB_MAX_NAME || !is_good_name(name))
> + return -EINVAL;
> +
> + *name_out = name;
> + return 0;
> +}
> +
> +static int tlob_create_or_delete_uprobe(char *buf)
> +{
> + loff_t offset_start, offset_stop;
> + u64 threshold_ns;
> + char *name, *binpath;
> + int ret;
> +
> + if (buf[0] == '-' && buf[1] == ':') {
> + ret = tlob_parse_remove_line(buf, &name);
> + if (ret)
> + return ret;
> + return tlob_remove_uprobe_by_name(name);
> + }
> + ret = tlob_parse_uprobe_line(buf, &name, &binpath, &offset_start,
> + &offset_stop, &threshold_ns);
> + if (ret)
> + return ret;
> + return tlob_add_uprobe(name, binpath, offset_start, offset_stop,
> + threshold_ns);
> +}
> +
> +static ssize_t tlob_monitor_write(struct file *file,
> + const char __user *ubuf,
> + size_t count, loff_t *ppos)
> +{
> + char buf[TLOB_MAX_PATH + TLOB_MAX_NAME + 128];
> +
> + if (count >= sizeof(buf))
> + return -EINVAL;
> + if (copy_from_user(buf, ubuf, count))
> + return -EFAULT;
> + buf[count] = '\0';
> + if (count > 0 && buf[count - 1] == '\n')
> + buf[count - 1] = '\0';
> + if (!buf[0])
> + return count;
> + return tlob_create_or_delete_uprobe(buf) ?: (ssize_t)count;
> +}
> +
> +static int tlob_monitor_open(struct inode *inode, struct file *file)
> +{
> + int ret;
> +
> + ret = security_locked_down(LOCKDOWN_TRACEFS);
Umh, that's something we probably want also for the other files, I'm not
too familiar with this thing though.
Thanks,
Gabriele
next prev parent reply other threads:[~2026-11-20 16:38 UTC|newest]
Thread overview: 22+ 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-20 16:55 ` Gabriele Monaco
2026-11-05 17:49 ` [PATCH v8 05/14] rv: Add a KUnit test for " wen.yang
2026-11-20 17:02 ` Gabriele Monaco
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
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-20 16:37 ` Gabriele Monaco [this message]
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=df35b9bf6b509a02b96d8aea8224ad538275e356.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
all inboxes | Powered by JetHome®