[RFC PATCH 09/12] rv: Add KUnit stub to rv_react() and rv_*_task_monitor_slot()

Gabriele Monaco
2026-04-27T15:12:42Z

Add KUNIT_STATIC_STUB_REDIRECT to allow those functions to be stubbed in
a KUnit test. This is useful to catch reaction without creating a custom
reactor and going through the effort of setting it from a test.
rv_{get/put}_task_monitor_slot() rely on a lock, but this isn't
necessary during a unit test, so simply skip the calls.

Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
kernel/trace/rv/rv.c | 5 +++++
kernel/trace/rv/rv_reactors.c | 3 +++
2 files changed, 8 insertions(+)

diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c
index ee4e68102f17..f59385a24fa1 100644
--- a/kernel/trace/rv/rv.c
+++ b/kernel/trace/rv/rv.c
@@ -142,6 +142,7 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
+#include <kunit/static_stub.h>

#ifdef CONFIG_RV_MON_EVENTS
#define CREATE_TRACE_POINTS
@@ -171,6 +172,8 @@ int rv_get_task_monitor_slot(void)
{
int i;

+ KUNIT_STATIC_STUB_REDIRECT(rv_get_task_monitor_slot);
+
lockdep_assert_held(&rv_interface_lock);

if (task_monitor_count == CONFIG_RV_PER_TASK_MONITORS)
@@ -192,6 +195,8 @@ int rv_get_task_monitor_slot(void)

void rv_put_task_monitor_slot(int slot)
{
+ KUNIT_STATIC_STUB_REDIRECT(rv_put_task_monitor_slot, slot);
+
lockdep_assert_held(&rv_interface_lock);

if (slot < 0 || slot >= CONFIG_RV_PER_TASK_MONITORS) {
diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c
index 460af07f7aba..f9b6a034c022 100644
--- a/kernel/trace/rv/rv_reactors.c
+++ b/kernel/trace/rv/rv_reactors.c
@@ -63,6 +63,7 @@

#include <linux/lockdep.h>
#include <linux/slab.h>
+#include <kunit/static_stub.h>

#include "rv.h"

@@ -468,6 +469,8 @@ void rv_react(struct rv_monitor *monitor, const char *msg, ...)
static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_FREE);
va_list args;

+ KUNIT_STATIC_STUB_REDIRECT(rv_react, monitor, msg);
+
if (!rv_reacting_on() || !monitor->react)
return;

--
2.53.0