From: Gabriele Monaco <gmonaco@redhat.com>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Gabriele Monaco <gmonaco@redhat.com>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Nam Cao <namcao@linutronix.de>,
Thomas Weissschuh <thomas.weissschuh@linutronix.de>,
Tomas Glozar <tglozar@redhat.com>, John Kacur <jkacur@redhat.com>,
Wen Yang <wen.yang@linux.dev>
Subject: [PATCH v2 13/14] rv: Prevent unintentional tracepoints during KUnit tests
Date: Thu, 14 May 2026 17:20:54 +0200 [thread overview]
Message-ID: <20260514152055.229162-14-gmonaco@redhat.com> (raw)
In-Reply-To: <20260514152055.229162-1-gmonaco@redhat.com>
Monitor initialisation also called during KUnit tests may register some
tracepoints, this can lead to issues since we don't expect real monitor
events running during KUnit tests.
Prevent tracepoint registration if an RV KUnit test is running.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
include/rv/instrumentation.h | 5 +++++
include/rv/kunit.h | 2 ++
kernel/trace/rv/rv_monitors_test.c | 10 ++++++++++
3 files changed, 17 insertions(+)
diff --git a/include/rv/instrumentation.h b/include/rv/instrumentation.h
index d4e7a02ede1a..761f8f147dac 100644
--- a/include/rv/instrumentation.h
+++ b/include/rv/instrumentation.h
@@ -9,12 +9,15 @@
*/
#include <linux/ftrace.h>
+#include <rv/kunit.h>
/*
* rv_attach_trace_probe - check and attach a handler function to a tracepoint
*/
#define rv_attach_trace_probe(monitor, tp, rv_handler) \
do { \
+ if (rv_mon_test_is_running()) \
+ break; \
check_trace_callback_type_##tp(rv_handler); \
WARN_ONCE(register_trace_##tp(rv_handler, NULL), \
"fail attaching " #monitor " " #tp "handler"); \
@@ -25,5 +28,7 @@
*/
#define rv_detach_trace_probe(monitor, tp, rv_handler) \
do { \
+ if (rv_mon_test_is_running()) \
+ break; \
unregister_trace_##tp(rv_handler, NULL); \
} while (0)
diff --git a/include/rv/kunit.h b/include/rv/kunit.h
index 3ef83d337880..9daaebacfc7e 100644
--- a/include/rv/kunit.h
+++ b/include/rv/kunit.h
@@ -19,6 +19,7 @@
struct task_struct *rv_get_current(void);
int rv_current_cpu(void);
+bool rv_mon_test_is_running(void);
struct rv_kunit_ctx {
int reactions, expected;
@@ -52,6 +53,7 @@ struct rv_kunit_ctx {
#define rv_get_current() current
#define rv_current_cpu() smp_processor_id()
+#define rv_mon_test_is_running() false
#endif /* CONFIG_RV_MONITORS_KUNIT_TEST */
#endif /* _RV_KUNIT_H */
diff --git a/kernel/trace/rv/rv_monitors_test.c b/kernel/trace/rv/rv_monitors_test.c
index 3dbe562f00c1..01cbee9ac6c0 100644
--- a/kernel/trace/rv/rv_monitors_test.c
+++ b/kernel/trace/rv/rv_monitors_test.c
@@ -14,6 +14,8 @@
#include <linux/rv.h>
#include "rv.h"
+static bool rv_mon_test_running;
+
__printf(2, 3)
static void stub_rv_react(struct rv_monitor *monitor, const char *msg, ...)
{
@@ -55,6 +57,11 @@ static int stub_rv_current_cpu(void)
return ctx->cpu;
}
+bool rv_mon_test_is_running(void)
+{
+ return rv_mon_test_running;
+}
+
static int rv_mon_test_init(struct kunit *test)
{
struct rv_kunit_ctx *ctx;
@@ -94,6 +101,8 @@ static int rv_set_testing(struct kunit_suite *suite)
mutex_lock(&rv_interface_lock);
+ rv_mon_test_running = true;
+
list_for_each_entry(mon, &rv_monitors_list, list) {
if (mon->enabled) {
mutex_unlock(&rv_interface_lock);
@@ -111,6 +120,7 @@ static int rv_set_testing(struct kunit_suite *suite)
*/
static void rv_clear_testing(struct kunit_suite *suite)
{
+ rv_mon_test_running = false;
mutex_unlock(&rv_interface_lock);
}
--
2.54.0
next prev parent reply other threads:[~2026-05-14 15:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 15:20 [PATCH v2 00/14] rv: Add selftests to tools and KUnit tests Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 01/14] tools/rv: Fix substring match bug in monitor name search Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 02/14] tools/rv: Fix substring match when listing container monitors Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 03/14] tools/rv: Fix exit status when monitor execution fails Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 04/14] tools/rv: Fix cleanup after failed trace setup Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 05/14] tools/rv: Add selftests Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 06/14] verification/rvgen: Fix options shared among commands Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 07/14] verification/rvgen: Fix ltl2k writing True as a literal Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 08/14] verification/rvgen: Add golden and spec folders for tests Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 09/14] verification/rvgen: Add selftests Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 10/14] rv: Add KUnit stub to rv_react() and rv_*_task_monitor_slot() Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 11/14] rv: Add KUnit tests for some DA/HA monitors Gabriele Monaco
2026-05-14 15:20 ` [PATCH v2 12/14] rv: Add KUnit stubs for current and smp_processor_id() Gabriele Monaco
2026-05-14 15:20 ` Gabriele Monaco [this message]
2026-05-14 15:20 ` [PATCH v2 14/14] rv: Add KUnit tests for some LTL monitors 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=20260514152055.229162-14-gmonaco@redhat.com \
--to=gmonaco@redhat.com \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=namcao@linutronix.de \
--cc=rostedt@goodmis.org \
--cc=tglozar@redhat.com \
--cc=thomas.weissschuh@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