From: Gabriele Monaco <gmonaco@redhat.com>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
bpf@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>,
Gabriele Monaco <gmonaco@redhat.com>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
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: [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs
Date: Thu, 26 Nov 2026 13:59:51 +0100 [thread overview]
Message-ID: <20261126130004.127155-6-gmonaco@redhat.com> (raw)
In-Reply-To: <20261126130004.127155-1-gmonaco@redhat.com>
Add event_monitor and error_monitor tracepoints, carrying a monitor
name and a single formatted message. These tracepoints aim to replace
the per-monitor tracepoints for a set of monitors (now BPF only) and are
generic enough to allow reporting from different monitor classes.
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).
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
kernel/trace/rv/Makefile | 1 +
kernel/trace/rv/rv_bpf.c | 76 ++++++++++++++++++++++++++++++++++++++
kernel/trace/rv/rv_trace.h | 37 +++++++++++++++++++
3 files changed, 114 insertions(+)
create mode 100644 kernel/trace/rv/rv_bpf.c
diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
index c895d81dfdad..588250ce3fa9 100644
--- a/kernel/trace/rv/Makefile
+++ b/kernel/trace/rv/Makefile
@@ -3,6 +3,7 @@
ccflags-y += -I $(src) # needed for trace events
obj-$(CONFIG_RV) += rv.o
+obj-$(CONFIG_RV) += rv_bpf.o
obj-$(CONFIG_RV_MON_WIP) += monitors/wip/wip.o
obj-$(CONFIG_RV_MON_WWNR) += monitors/wwnr/wwnr.o
obj-$(CONFIG_RV_MON_SCHED) += monitors/sched/sched.o
diff --git a/kernel/trace/rv/rv_bpf.c b/kernel/trace/rv/rv_bpf.c
new file mode 100644
index 000000000000..f39f33335c71
--- /dev/null
+++ b/kernel/trace/rv/rv_bpf.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * BPF kfuncs for Runtime Verification (RV)
+ */
+
+#include <linux/init.h>
+#include <linux/bpf.h>
+#include <linux/btf.h>
+#include <linux/btf_ids.h>
+#include <rv_trace.h>
+
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_rv_event_monitor - emit an RV monitor event tracepoint
+ *
+ * @msg must be NULL-terminated, drop the event if it isn't. This happens by
+ * construction if using snprintf-like functions and passing the right @msg__sz
+ * to both.
+ *
+ * @mon__str: name of the monitor
+ * @msg: message string
+ * @msg__sz: message string size
+ *
+ * Return -EINVAL if @msg is not NULL-terminated, 0 otherwise.
+ */
+__bpf_kfunc int bpf_rv_event_monitor(const char *mon__str, const int *id__nullable,
+ const char *msg, u32 msg__sz)
+{
+ if (strnlen(msg, msg__sz) == msg__sz)
+ return -EINVAL;
+
+ trace_event_monitor(mon__str, id__nullable, msg);
+ return 0;
+}
+
+/**
+ * bpf_rv_error_monitor - emit an RV monitor error tracepoint
+ *
+ * @msg must be NULL-terminated, drop the event if it isn't. This happens by
+ * construction if using snprintf-like functions and passing the right @msg__sz
+ * to both.
+ *
+ * @mon__str: name of the monitor
+ * @msg: message string
+ * @msg__sz: message string size
+ *
+ * Return -EINVAL if @msg is not NULL-terminated, 0 otherwise.
+ */
+__bpf_kfunc int bpf_rv_error_monitor(const char *mon__str, const int *id__nullable,
+ const char *msg, u32 msg__sz)
+{
+ if (strnlen(msg, msg__sz) == msg__sz)
+ return -EINVAL;
+
+ trace_error_monitor(mon__str, id__nullable, msg);
+ return 0;
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(bpf_rv_kfunc_ids)
+BTF_ID_FLAGS(func, bpf_rv_event_monitor)
+BTF_ID_FLAGS(func, bpf_rv_error_monitor)
+BTF_KFUNCS_END(bpf_rv_kfunc_ids)
+
+static const struct btf_kfunc_id_set bpf_rv_kfunc_set = {
+ .owner = THIS_MODULE,
+ .set = &bpf_rv_kfunc_ids,
+};
+
+static int __init bpf_rv_kfunc_init(void)
+{
+ return register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &bpf_rv_kfunc_set);
+}
+late_initcall(bpf_rv_kfunc_init);
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index 24d4b94a54a5..9fa9e1230e84 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -292,6 +292,43 @@ DECLARE_EVENT_CLASS(error_ltl_monitor_id,
// Add new monitors based on CONFIG_LTL_MON_EVENTS_ID here
#endif /* CONFIG_LTL_MON_EVENTS_ID */
+DECLARE_EVENT_CLASS(event_template_monitor,
+
+ TP_PROTO(const char *mon, const int *id, const char *msg),
+
+ TP_ARGS(mon, id, msg),
+
+ TP_STRUCT__entry(
+ __string( mon, mon )
+ __field( u8, has_id )
+ __field( int, id )
+ __string( msg, msg )
+ ),
+
+ TP_fast_assign(
+ __assign_str(mon);
+ __entry->has_id = !!id;
+ __entry->id = id ? *id : 0;
+ __assign_str(msg);
+ ),
+
+ /*
+ * The id is used only for filters, if it is of interest in the format,
+ * callers should pass it to the msg too.
+ */
+ TP_printk("%s: %s",
+ __get_str(mon),
+ __get_str(msg))
+);
+
+DEFINE_EVENT(event_template_monitor, event_monitor,
+ TP_PROTO(const char *mon, const int *id, const char *msg),
+ TP_ARGS(mon, id, msg));
+
+DEFINE_EVENT(event_template_monitor, error_monitor,
+ TP_PROTO(const char *mon, const int *id, const char *msg),
+ TP_ARGS(mon, id, msg));
+
#ifdef CONFIG_RV_MON_MAINTENANCE_EVENTS
/* Tracepoint useful for monitors development, currenly only used in DA */
TRACE_EVENT(rv_retries_error,
--
2.56.1
next prev parent reply other threads:[~2026-11-26 13:00 UTC|newest]
Thread overview: 20+ 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 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 ` Gabriele Monaco [this message]
2026-11-26 22:09 ` [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs 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 12:59 ` [PATCH v3 10/18] tools/rv: Implement BPF monitor loading and tracing Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 11/18] tools/rv: Rework tracing to support generic events Gabriele Monaco
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: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: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=20261126130004.127155-6-gmonaco@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
all inboxes | Powered by JetHome®