[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <159896088487.20229.10616348998847001332.tip-bot2@tip-bot2>
Date: Tue, 01 Sep 2020 11:48:04 -0000
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>, x86 <x86@...nel.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: [tip: core/static_call] static_call: Add simple self-test for static calls
The following commit has been merged into the core/static_call branch of tip:
Commit-ID: f03c412915f5f69f2d17bcd20ecdd69320bcbf7b
Gitweb: https://git.kernel.org/tip/f03c412915f5f69f2d17bcd20ecdd69320bcbf7b
Author: Peter Zijlstra <peterz@...radead.org>
AuthorDate: Tue, 18 Aug 2020 15:57:46 +02:00
Committer: Ingo Molnar <mingo@...nel.org>
CommitterDate: Tue, 01 Sep 2020 09:58:05 +02:00
static_call: Add simple self-test for static calls
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Signed-off-by: Ingo Molnar <mingo@...nel.org>
Link: https://lore.kernel.org/r/20200818135804.922581202@infradead.org
---
arch/Kconfig | 6 ++++++-
kernel/static_call.c | 43 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 49 insertions(+)
diff --git a/arch/Kconfig b/arch/Kconfig
index 2c4936a..76ec339 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -106,6 +106,12 @@ config STATIC_KEYS_SELFTEST
help
Boot time self-test of the branch patching code.
+config STATIC_CALL_SELFTEST
+ bool "Static call selftest"
+ depends on HAVE_STATIC_CALL
+ help
+ Boot time self-test of the call patching code.
+
config OPTPROBES
def_bool y
depends on KPROBES && HAVE_OPTPROBES
diff --git a/kernel/static_call.c b/kernel/static_call.c
index 753b2f1..97142cb 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -369,3 +369,46 @@ static void __init static_call_init(void)
#endif
}
early_initcall(static_call_init);
+
+#ifdef CONFIG_STATIC_CALL_SELFTEST
+
+static int func_a(int x)
+{
+ return x+1;
+}
+
+static int func_b(int x)
+{
+ return x+2;
+}
+
+DEFINE_STATIC_CALL(sc_selftest, func_a);
+
+static struct static_call_data {
+ int (*func)(int);
+ int val;
+ int expect;
+} static_call_data [] __initdata = {
+ { NULL, 2, 3 },
+ { func_b, 2, 4 },
+ { func_a, 2, 3 }
+};
+
+static int __init test_static_call_init(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(static_call_data); i++ ) {
+ struct static_call_data *scd = &static_call_data[i];
+
+ if (scd->func)
+ static_call_update(sc_selftest, scd->func);
+
+ WARN_ON(static_call(sc_selftest)(scd->val) != scd->expect);
+ }
+
+ return 0;
+}
+early_initcall(test_static_call_init);
+
+#endif /* CONFIG_STATIC_CALL_SELFTEST */
Powered by blists - more mailing lists