From: Gabriele Monaco <gmonaco@redhat.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Nam Cao <namcao@linutronix.de>, Wen Yang <wen.yang@linux.dev>,
Tobias Schaffner <tobias.schaffner@siemens.com>,
Viktor Malik <vmalik@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
John Ogness <john.ogness@linutronix.de>
Subject: Re: [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs
Date: Mon, 30 Nov 2026 11:56:29 +0100 [thread overview]
Message-ID: <091bc888a43c8b690df49bdc2292dbbd967bdd91.camel@redhat.com> (raw)
In-Reply-To: <DN6DWMLNI044.39KJNBB9RWCQY@gmail.com>
On Fri, 2026-11-27 at 23:33 +0000, Alexei Starovoitov wrote:
> On Thu, Nov 26, 2026 at 04:59 AM Gabriele Monaco <gmonaco@redhat.com> wrote:
> > Add also bpf_rv_event_monitor() / bpf_rv_error_monitor() kfuncs wrapping
> > them, so BPF monitors can emit similar events to in-kernel monitors.
> >
> > Userspace callers need now to use ftrace filters to get the right events
> > but events and errors are separate channels to ease the most common
> > filtering and account for dramatically different volume (errors are
> > rare).
>
> I thought we agreed that plain bpf_printk() works with glob filtering on top.
> Why do you need these new kfuncs?
> See below diff that illustrates the point.
Thanks for the diff.
I tried this alternative as it offers separate channels for events, errors and
standard bpf_printk users.
Especially the events channel has the potential to flood other bpf_printk
readers, I'm not sure whether that's acceptable.
We can apply filters for rv, but then any other user interested in bpf_printk
would need to filter rv out.
Other ergonomics advantages are actually minor, though.
I would have liked structured fields but it gets unnecessarily complicated.
If the amount of messages isn't an issue on the standard bpf_printk, we can just
use that, users are going to need to parse strings either ways.
Thanks,
Gabriele
>
> > + if (strnlen(msg, msg__sz) == msg__sz)
> > + return -EINVAL;
> > +
> > + trace_event_monitor(mon__str, id__nullable, msg);
>
> This will read out of bounds. msg can point to a map value.
> Take a BPF_F_MMAPABLE array with one page size value. NUL is the last byte:
>
> prog user space
> strnlen(msg, msg__sz) finds the NUL
> writes 'x' over the NUL
> __string(msg, msg) -> strlen(msg)
> runs into the vmalloc guard page
>
> There is no limit on msg__sz either.
> When perf is on the event, a msg above 8192 bytes hits WARN_ONCE() in
> perf_trace_buf_alloc().
>
>
> diff --git a/tools/verification/rv/bpf_monitors/da_monitor_bpf.h
> b/tools/verification/rv/bpf_monitors/da_monitor_bpf.h
> index e9e673c..6996c01 100644
> --- a/tools/verification/rv/bpf_monitors/da_monitor_bpf.h
> +++ b/tools/verification/rv/bpf_monitors/da_monitor_bpf.h
> @@ -24,8 +24,6 @@
> #define da_implicit_guard()
> #define IS_ENABLED(conf) 0
>
> -#define DA_TRACE_MSG_MAX 128
> -
> /*
> * Also used to filter out events higher values imply lower ones.
> * Userspace will parse this enum but expects EVENT to imply ERROR(s) and
> ERROR
> @@ -328,10 +326,9 @@ static inline void da_reset_bpf(da_id_type id,
> monitor_target_bpf target)
>
> #endif /* RV_MON_TYPE */
>
> -extern int bpf_rv_event_monitor(const char *mon, const int *id__nullable,
> - const char *msg, u32 msg__sz) __ksym;
> -extern int bpf_rv_error_monitor(const char *mon, const int *id__nullable,
> - const char *msg, u32 msg__sz) __ksym;
> +/* "rv: <type>: <monitor>: <text>" in bpf_trace:bpf_trace_printk */
> +#define rv_printk(type, fmt, ...) \
> + bpf_printk("rv: " type ": " __stringify(MONITOR_NAME) ": " fmt,
> __VA_ARGS__)
>
> #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
> /*
> @@ -345,28 +342,22 @@ static inline void da_trace_event(struct da_monitor
> *da_mon,
> const char *next_state, bool is_final,
> da_id_type id)
> {
> - char msg[DA_TRACE_MSG_MAX];
> -
> if (trace_level < RV_TRACE_EVENT)
> return;
>
> - BPF_SNPRINTF(msg, sizeof(msg), "%s x %s -> %s%s",
> - curr_state, event, next_state, is_final ? " (final)" : "");
> - bpf_rv_event_monitor(__stringify(MONITOR_NAME), NULL, msg,
> sizeof(msg));
> + rv_printk("event", "%s x %s -> %s%s",
> + curr_state, event, next_state, is_final ? " (final)" : "");
> }
>
> static inline void da_trace_error(struct da_monitor *da_mon,
> const char *curr_state, const char *event,
> da_id_type id)
> {
> - char msg[DA_TRACE_MSG_MAX];
> -
> if (trace_level < RV_TRACE_ERROR)
> return;
>
> - BPF_SNPRINTF(msg, sizeof(msg), "event %s not expected in the state
> %s",
> - event, curr_state);
> - bpf_rv_error_monitor(__stringify(MONITOR_NAME), NULL, msg,
> sizeof(msg));
> + rv_printk("error", "event %s not expected in the state %s",
> + event, curr_state);
> }
>
> #elif RV_MON_TYPE == RV_MON_PER_TASK || RV_MON_TYPE == RV_MON_PER_OBJ
> @@ -379,28 +370,22 @@ static inline void da_trace_event(struct da_monitor
> *da_mon,
> const char *next_state, bool is_final,
> da_id_type id)
> {
> - char msg[DA_TRACE_MSG_MAX];
> -
> if (trace_level < RV_TRACE_EVENT)
> return;
>
> - BPF_SNPRINTF(msg, sizeof(msg), "%d: %s x %s -> %s%s", id,
> - curr_state, event, next_state, is_final ? " (final)" : "");
> - bpf_rv_event_monitor(__stringify(MONITOR_NAME), &id, msg,
> sizeof(msg));
> + rv_printk("event", "%d: %s x %s -> %s%s", id,
> + curr_state, event, next_state, is_final ? " (final)" : "");
> }
>
> static inline void da_trace_error(struct da_monitor *da_mon,
> const char *curr_state, const char *event,
> da_id_type id)
> {
> - char msg[DA_TRACE_MSG_MAX];
> -
> if (trace_level < RV_TRACE_ERROR)
> return;
>
> - BPF_SNPRINTF(msg, sizeof(msg), "%d: event %s not expected in the
> state %s",
> - id, event, curr_state);
> - bpf_rv_error_monitor(__stringify(MONITOR_NAME), &id, msg,
> sizeof(msg));
> + rv_printk("error", "%d: event %s not expected in the state %s",
> + id, event, curr_state);
> }
> #endif /* RV_MON_TYPE */
>
> diff --git a/tools/verification/rv/src/trace.c
> b/tools/verification/rv/src/trace.c
> index 629b4f6..91f86bf 100644
> --- a/tools/verification/rv/src/trace.c
> +++ b/tools/verification/rv/src/trace.c
> @@ -15,7 +15,7 @@
> #include <trace.h>
> #include <utils.h>
>
> -#define FILTER_MAX 128
> +#define FILTER_MAX 256
>
> /**
> * collect_registered_events - print an event collected from the trace buffer
> @@ -176,20 +176,25 @@ static int enable_specific_event(struct trace_instance
> *inst, const char *event_
> }
>
> /*
> - * enable_generic_event - enable a generic event with filters
> + * enable_bpf_events - collect the messages of a BPF monitor
> + *
> + * BPF monitors report via bpf_printk("rv: <event|error>: <monitor>: ...").
> + *
> + * Returns 0 on success, -1 otherwise.
> */
> -static int enable_generic_event(struct trace_instance *inst, const char
> *event_name, char *name)
> +static int enable_bpf_events(struct trace_instance *inst, char *name)
> {
> - struct tep_event *tevent = tep_find_event_by_name(inst->tep, "rv",
> event_name);
> + struct tep_event *tevent;
> char filter[FILTER_MAX] = "";
> size_t len;
>
> + tevent = tep_find_event_by_name(inst->tep, "bpf_trace",
> "bpf_trace_printk");
> if (!tevent) {
> - err_msg("trace: fail finding the rv:%s event\n", event_name);
> + err_msg("trace: fail finding the bpf_trace_printk event\n");
> return -1;
> }
>
> - len = snprintf(filter, sizeof(filter), "mon == \"%s\"", name);
> + len = snprintf(filter, sizeof(filter), "bpf_string ~ \"rv: *: %s:
> *\"", name);
> if (len >= sizeof(filter)) {
> err_msg("trace: monitor name %s too long\n", name);
> return -1;
> @@ -197,31 +202,12 @@ static int enable_generic_event(struct trace_instance
> *inst, const char *event_n
>
> if (config.my_pid > 0)
> snprintf(filter + len, sizeof(filter) - len,
> - " && common_pid != %d && !(has_id == 1 && id ==
> %d)",
> - config.my_pid, config.my_pid);
> + " && common_pid != %d && !(bpf_string ~ \"rv: *: %s:
> %d: *\")",
> + config.my_pid, name, config.my_pid);
>
> return apply_filter_enable(inst, tevent, filter);
> }
>
> -/*
> - * enable_bpf_events - enable rv:event_monitor and rv:error_monitor for a
> monitor
> - *
> - * BPF monitors report via generic rv:event_monitor and rv:error_monitor
> events.
> - * Enable the events and filter them to only collect the messages of the
> given monitor.
> - *
> - * Returns 0 on success, -1 otherwise.
> - */
> -static int enable_bpf_events(struct trace_instance *inst, char *name)
> -{
> - if (!config.trace_errors_only && enable_generic_event(inst,
> "event_monitor", name))
> - return -1;
> -
> - if (enable_generic_event(inst, "error_monitor", name))
> - return -1;
> -
> - return 0;
> -}
> -
> /**
> * trace_enable_monitor_events - enable a monitor's events in a trace
> instance
> *
> diff --git a/tools/verification/rv/tests/rv_mon.t
> b/tools/verification/rv/tests/rv_mon.t
> index 30d1dda..f51f194 100644
> --- a/tools/verification/rv/tests/rv_mon.t
> +++ b/tools/verification/rv/tests/rv_mon.t
> @@ -104,16 +104,16 @@ cpu="\[[0-9]\{3\}\][[:space:]]\+"
> state="[a-z_]\+ "
> id="[0-9]\+"
> selfid="\$pid"
> -# BPF monitors report via the common rv:event_monitor/rv:error_monitor
> -# events, which add a "<mon>: " prefix to the message.
> +# BPF monitors report via bpf_printk()
> +type_bpf="bpf_trace_printk: rv: \(event\|error\)"
> trace_task="${genpid}${cpu}${type}: ${id}: ${state}"
> trace_task_self="${genpid}${cpu}${type}: ${selfid}: ${state}"
> trace_cpu="${genpid}${cpu}${type}: ${state}"
> trace_cpu_self="${selfpid}${cpu}${type}: ${state}"
> -trace_task_bpf="${genpid}${cpu}${type}: ${mon}: ${id}: ${state}"
> -trace_task_bpf_self="${genpid}${cpu}${type}: ${mon}: ${selfid}: ${state}"
> -trace_cpu_bpf="${genpid}${cpu}${type}: ${mon}: ${state}"
> -trace_cpu_bpf_self="${selfpid}${cpu}${type}: ${mon}: ${state}"
> +trace_task_bpf="${genpid}${cpu}${type_bpf}: ${mon}: ${id}: ${state}"
> +trace_task_bpf_self="${genpid}${cpu}${type_bpf}: ${mon}: ${selfid}: ${state}"
> +trace_cpu_bpf="${genpid}${cpu}${type_bpf}: ${mon}: ${state}"
> +trace_cpu_bpf_self="${selfpid}${cpu}${type_bpf}: ${mon}: ${state}"
>
> check_if_exists "run per-task monitor with tracing" \
> "$RV mon sssw -t" "$RVDIR/monitors/sched/sssw" \
> @@ -154,10 +154,10 @@ check_if_exists "run per-task monitor tracing only
> errors" \
>
> check_if_exists "run per-task BPF monitor tracing only errors" \
> "$RV mon tqueue -t -E" "$RVTOOL/bpf_monitors/tqueue.o" \
> - "$header" "event_monitor"
> + "$header" "rv: event"
>
> check_if_exists "run per-cpu BPF monitor tracing only errors" \
> "$RV mon nohz -t -E" "$RVTOOL/bpf_monitors/nohz.o" \
> - "error_monitor" "event_monitor"
> + "rv: error" "rv: event"
>
> test_end
>
next prev parent reply other threads:[~2026-11-30 10:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 01/18] sched: Add task enqueue/dequeue trace points Gabriele Monaco
2026-11-26 13:13 ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 02/18] tools/rv: Skip empty pid error in selftest if command failed Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 03/18] rv: Add wrapper macros for monitor tracepoint definitions Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 04/18] rv: Propagate const to model strings and tracepoints Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs Gabriele Monaco
2026-11-26 13:24 ` sashiko-bot
2026-11-26 22:09 ` kernel test robot
2026-11-27 23:33 ` Alexei Starovoitov
2026-11-30 10:56 ` Gabriele Monaco [this message]
2026-11-29 15:15 ` kernel test robot
2026-11-30 7:03 ` kernel test robot
2026-11-26 12:59 ` [PATCH v3 06/18] tools/build: Add a feature test for bpftool-btf Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 07/18] tools/rv: Move argument parsing from in_kernel to utils Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 08/18] tools/rv: Move monitor trace handling to trace.c Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 09/18] tools/rv: Implement BPF monitor discovery and listing Gabriele Monaco
2026-11-26 13:17 ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 10/18] tools/rv: Implement BPF monitor loading and tracing Gabriele Monaco
2026-11-26 13:14 ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 11/18] tools/rv: Rework tracing to support generic events Gabriele Monaco
2026-11-26 13:13 ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 12/18] tools/rv: Copy stripped bpf_atomic.h from libarena Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 13/18] tools/rv: Add BPF monitors Gabriele Monaco
2026-11-26 13:24 ` sashiko-bot
2026-11-26 13:00 ` [PATCH v3 14/18] tools/rv: Define CONFIG_X86_64 statically for " Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 15/18] tools/rv: Add -E/--errors-only option Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 16/18] verification/rvgen: Add support for BPF monitors Gabriele Monaco
2026-11-26 13:14 ` sashiko-bot
2026-11-26 13:00 ` [PATCH v3 17/18] tools/rv: Add selftest for rv bpf monitors Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 18/18] verification/rvgen: Add selftest for rvgen -b 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=091bc888a43c8b690df49bdc2292dbbd967bdd91.camel@redhat.com \
--to=gmonaco@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=namcao@linutronix.de \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tobias.schaffner@siemens.com \
--cc=vmalik@redhat.com \
--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