mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
runtime verifier updates for v7.4:
- Improve lockdep annotation for reactors Reactors are not supposed to take locks, so they fit the LD_WAIT_FREE lockdep class. However, reactors may run in preemptible context and if the preempting code (tick or simply the scheduler) takes locks, we see a lockdep splat. Switch to LD_WAIT_SPIN to avoid the splat while documenting that reactors should still not take locks. - Add KUnit tests for reactors Add KUnit test cases to validate registration and reaction, this requires exporting some symbols and other minor fixes. - Use the right rv_this variable in the wakeup monitor LTL monitors were updated to use the generic rv_this static variable but this change wasn't propagated to the newly introduced wakeup monitor. This broke reactors for the monitor: update the it. -----BEGIN PGP SIGNATURE----- iIoEABYKADIWIQRRSw7ePDh/lE+zeZMp5XQQmuv6qgUCateHQxQccm9zdGVkdEBn b29kbWlzLm9yZwAKCRAp5XQQmuv6qi1NAP9fv++iAElk3/btNOOQqSv6vEj9xCpE 0sRiGRPoWupqUAEA0tGOB5JQNQM97HYeJoC0VzXZok3ZyDpO/afev576yw0= =X6hG -----END PGP SIGNATURE----- Merge tag 'trace-rv-v7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace Pull runtime verifier updates from Steven Rostedt: - Improve lockdep annotation for reactors Reactors are not supposed to take locks, so they fit the LD_WAIT_FREE lockdep class. However, reactors may run in preemptible context and if the preempting code (tick or simply the scheduler) takes locks, we see a lockdep splat. Switch to LD_WAIT_SPIN to avoid the splat while documenting that reactors should still not take locks. - Add KUnit tests for reactors Add KUnit test cases to validate registration and reaction, this requires exporting some symbols and other minor fixes. - Use the right rv_this variable in the wakeup monitor LTL monitors were updated to use the generic rv_this static variable but this change wasn't propagated to the newly introduced wakeup monitor. This broke reactors for the monitor: update the it. * tag 'trace-rv-v7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: rv/rtapp/wakeup: Use "rv_this" the rv_monitor variable rv: Add KUnit tests for reactor registration and dispatch rv: Export rv_register_reactor() and rv_unregister_reactor() rv: Propagate rv_register_reactor() error from reactor init rv: Use LD_WAIT_SPIN as the reactor lockdep wait type
This commit is contained in:
commit
ff5b1cefb4
|
|
@ -113,6 +113,18 @@ config RV_REACT_PANIC
|
|||
Enables the panic reactor. The panic reactor emits a printk()
|
||||
message if an exception is found and panic()s the system.
|
||||
|
||||
config RV_REACTORS_KUNIT
|
||||
tristate "KUnit tests for RV reactors" if !KUNIT_ALL_TESTS
|
||||
depends on KUNIT
|
||||
depends on RV_REACTORS
|
||||
default KUNIT_ALL_TESTS
|
||||
help
|
||||
Enable KUnit tests for RV reactor registration and dispatch.
|
||||
These tests verify the register/unregister lifecycle, duplicate
|
||||
rejection, and that rv_react() correctly invokes callbacks.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config RV_MONITORS_KUNIT_TEST
|
||||
tristate "KUnit tests for RV monitors" if !KUNIT_ALL_TESTS
|
||||
depends on KUNIT && RV && RV_REACTORS
|
||||
|
|
|
|||
|
|
@ -25,4 +25,5 @@ obj-$(CONFIG_RV_MON_WAKEUP) += monitors/wakeup/wakeup.o
|
|||
obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
|
||||
obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
|
||||
obj-$(CONFIG_RV_REACT_PANIC) += reactor_panic.o
|
||||
obj-$(CONFIG_RV_REACTORS_KUNIT) += rv_reactors_kunit.o
|
||||
obj-$(CONFIG_RV_MONITORS_KUNIT_TEST) += rv_monitors_test.o
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ static void disable_wakeup(void)
|
|||
ltl_monitor_destroy();
|
||||
}
|
||||
|
||||
static struct rv_monitor rv_wakeup = {
|
||||
static struct rv_monitor rv_this = {
|
||||
.name = "wakeup",
|
||||
.description = "Monitor that real-time tasks are not woken by lower-priority tasks",
|
||||
.enable = enable_wakeup,
|
||||
|
|
@ -137,12 +137,12 @@ static struct rv_monitor rv_wakeup = {
|
|||
|
||||
static int __init register_wakeup(void)
|
||||
{
|
||||
return rv_register_monitor(&rv_wakeup, &rv_rtapp);
|
||||
return rv_register_monitor(&rv_this, &rv_rtapp);
|
||||
}
|
||||
|
||||
static void __exit unregister_wakeup(void)
|
||||
{
|
||||
rv_unregister_monitor(&rv_wakeup);
|
||||
rv_unregister_monitor(&rv_this);
|
||||
}
|
||||
|
||||
module_init(register_wakeup);
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ static struct rv_reactor rv_panic = {
|
|||
|
||||
static int __init register_react_panic(void)
|
||||
{
|
||||
rv_register_reactor(&rv_panic);
|
||||
return 0;
|
||||
return rv_register_reactor(&rv_panic);
|
||||
}
|
||||
|
||||
static void __exit unregister_react_panic(void)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ static struct rv_reactor rv_printk = {
|
|||
|
||||
static int __init register_react_printk(void)
|
||||
{
|
||||
rv_register_reactor(&rv_printk);
|
||||
return 0;
|
||||
return rv_register_reactor(&rv_printk);
|
||||
}
|
||||
|
||||
static void __exit unregister_react_printk(void)
|
||||
|
|
|
|||
|
|
@ -314,6 +314,7 @@ int rv_register_reactor(struct rv_reactor *reactor)
|
|||
guard(mutex)(&rv_interface_lock);
|
||||
return __rv_register_reactor(reactor);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rv_register_reactor);
|
||||
|
||||
/**
|
||||
* rv_unregister_reactor - unregister a rv reactor.
|
||||
|
|
@ -327,6 +328,7 @@ int rv_unregister_reactor(struct rv_reactor *reactor)
|
|||
list_del(&reactor->list);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rv_unregister_reactor);
|
||||
|
||||
/*
|
||||
* reacting_on interface.
|
||||
|
|
@ -465,7 +467,15 @@ int init_rv_reactors(struct dentry *root_dir)
|
|||
|
||||
void rv_react(struct rv_monitor *monitor, const char *msg, ...)
|
||||
{
|
||||
static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_FREE);
|
||||
/*
|
||||
* Reactors must not explicitly take locks, so they should be
|
||||
* LD_WAIT_FREE. However, reactor callbacks can run with preemption
|
||||
* enabled, meaning the preempting code (e.g. the scheduler taking
|
||||
* rq->__lock at LD_WAIT_SPIN) may violate that constraint. Use
|
||||
* LD_WAIT_SPIN to avoid false-positive lockdep reports.
|
||||
* But you should still NOT be using locks in reactors.
|
||||
*/
|
||||
static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_SPIN);
|
||||
va_list args;
|
||||
|
||||
if (!rv_reacting_on() || !monitor->react)
|
||||
|
|
|
|||
111
kernel/trace/rv/rv_reactors_kunit.c
Normal file
111
kernel/trace/rv/rv_reactors_kunit.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* KUnit tests for RV reactor registration and dispatch.
|
||||
*
|
||||
* The dispatch tests rely on reacting_on being enabled, since rv_react()
|
||||
* returns early when it is off. It is on by default when the suites run
|
||||
* built-in; as a module, re-enable it if disabled via
|
||||
* /sys/kernel/tracing/rv/reacting_on.
|
||||
*/
|
||||
|
||||
#include <kunit/test.h>
|
||||
#include <linux/build_bug.h>
|
||||
#include <linux/rv.h>
|
||||
#include <linux/delay.h>
|
||||
#include "rv.h"
|
||||
|
||||
static struct rv_reactor test_reactor = {
|
||||
.name = "kunit_test_reactor",
|
||||
.description = "KUnit test reactor",
|
||||
};
|
||||
|
||||
static void reactor_teardown(void *arg)
|
||||
{
|
||||
rv_unregister_reactor(&test_reactor);
|
||||
}
|
||||
|
||||
static void register_test_reactor(struct kunit *test)
|
||||
{
|
||||
KUNIT_ASSERT_EQ(test, rv_register_reactor(&test_reactor), 0);
|
||||
KUNIT_ASSERT_EQ(test,
|
||||
kunit_add_action_or_reset(test, reactor_teardown, NULL), 0);
|
||||
}
|
||||
|
||||
static void test_double_register(struct kunit *test)
|
||||
{
|
||||
register_test_reactor(test);
|
||||
KUNIT_EXPECT_EQ(test, rv_register_reactor(&test_reactor), -EINVAL);
|
||||
}
|
||||
|
||||
static const char long_reactor_name[] = "kunit_reactor_name_too_long_xxx_";
|
||||
static_assert(sizeof(long_reactor_name) - 1 >= MAX_RV_REACTOR_NAME_SIZE,
|
||||
"long_reactor_name must be at least MAX_RV_REACTOR_NAME_SIZE chars");
|
||||
|
||||
static void test_name_too_long(struct kunit *test)
|
||||
{
|
||||
static struct rv_reactor long_reactor = {
|
||||
.name = long_reactor_name,
|
||||
};
|
||||
|
||||
KUNIT_EXPECT_EQ(test, rv_register_reactor(&long_reactor), -EINVAL);
|
||||
}
|
||||
|
||||
static struct kunit_case rv_reactor_registration_cases[] = {
|
||||
KUNIT_CASE(test_double_register),
|
||||
KUNIT_CASE(test_name_too_long),
|
||||
{}
|
||||
};
|
||||
|
||||
static struct kunit_suite rv_reactor_registration_suite = {
|
||||
.name = "rv_reactor_registration",
|
||||
.test_cases = rv_reactor_registration_cases,
|
||||
};
|
||||
|
||||
static int react_call_count;
|
||||
|
||||
__printf(1, 0) static void mock_react(const char *msg, va_list args)
|
||||
{
|
||||
react_call_count++;
|
||||
/* Busy-wait so a timer interrupt fires inside rv_react(). */
|
||||
mdelay(20);
|
||||
}
|
||||
|
||||
static void test_react_no_callback(struct kunit *test)
|
||||
{
|
||||
struct rv_monitor monitor = {
|
||||
.name = "kunit_null_react",
|
||||
};
|
||||
|
||||
react_call_count = 0;
|
||||
rv_react(&monitor, "no callback");
|
||||
|
||||
KUNIT_EXPECT_EQ(test, react_call_count, 0);
|
||||
}
|
||||
|
||||
static void test_react_callback_invoked(struct kunit *test)
|
||||
{
|
||||
struct rv_monitor monitor = {
|
||||
.name = "kunit_dispatch_monitor",
|
||||
.react = mock_react,
|
||||
};
|
||||
|
||||
react_call_count = 0;
|
||||
rv_react(&monitor, "callback invocation test");
|
||||
KUNIT_EXPECT_EQ(test, react_call_count, 1);
|
||||
}
|
||||
|
||||
static struct kunit_case rv_react_dispatch_cases[] = {
|
||||
KUNIT_CASE(test_react_no_callback),
|
||||
KUNIT_CASE(test_react_callback_invoked),
|
||||
{}
|
||||
};
|
||||
|
||||
static struct kunit_suite rv_react_dispatch_suite = {
|
||||
.name = "rv_react_dispatch",
|
||||
.test_cases = rv_react_dispatch_cases,
|
||||
};
|
||||
|
||||
kunit_test_suites(&rv_reactor_registration_suite, &rv_react_dispatch_suite);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("KUnit tests for RV reactor registration and dispatch");
|
||||
Loading…
Reference in New Issue
Block a user