aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2015-07-27 12:32:09 -0400
committerIngo Molnar <mingo@kernel.org>2015-08-03 05:34:16 -0400
commit1987c947d905baa05bee430178e8eef882f36bd4 (patch)
tree3e1bf8a1224c9c929b5546b5be98569d508c80e4
parent11276d5306b8e5b438a36bbff855fe792d7eaa61 (diff)
locking/static_keys: Add selftest
Add a little selftest that validates all combinations. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/Kconfig6
-rw-r--r--kernel/jump_label.c39
2 files changed, 44 insertions, 1 deletions
diff --git a/arch/Kconfig b/arch/Kconfig
index 8a8ea7110de8..a71cdbe2a04d 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -71,6 +71,12 @@ config JUMP_LABEL
71 ( On 32-bit x86, the necessary options added to the compiler 71 ( On 32-bit x86, the necessary options added to the compiler
72 flags may increase the size of the kernel slightly. ) 72 flags may increase the size of the kernel slightly. )
73 73
74config STATIC_KEYS_SELFTEST
75 bool "Static key selftest"
76 depends on JUMP_LABEL
77 help
78 Boot time self-test of the branch patching code.
79
74config OPTPROBES 80config OPTPROBES
75 def_bool y 81 def_bool y
76 depends on KPROBES && HAVE_OPTPROBES 82 depends on KPROBES && HAVE_OPTPROBES
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 8fd00d892286..f7dd15d537f9 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -482,4 +482,41 @@ static void jump_label_update(struct static_key *key)
482 __jump_label_update(key, entry, stop); 482 __jump_label_update(key, entry, stop);
483} 483}
484 484
485#endif 485#ifdef CONFIG_STATIC_KEYS_SELFTEST
486static DEFINE_STATIC_KEY_TRUE(sk_true);
487static DEFINE_STATIC_KEY_FALSE(sk_false);
488
489static __init int jump_label_test(void)
490{
491 int i;
492
493 for (i = 0; i < 2; i++) {
494 WARN_ON(static_key_enabled(&sk_true.key) != true);
495 WARN_ON(static_key_enabled(&sk_false.key) != false);
496
497 WARN_ON(!static_branch_likely(&sk_true));
498 WARN_ON(!static_branch_unlikely(&sk_true));
499 WARN_ON(static_branch_likely(&sk_false));
500 WARN_ON(static_branch_unlikely(&sk_false));
501
502 static_branch_disable(&sk_true);
503 static_branch_enable(&sk_false);
504
505 WARN_ON(static_key_enabled(&sk_true.key) == true);
506 WARN_ON(static_key_enabled(&sk_false.key) == false);
507
508 WARN_ON(static_branch_likely(&sk_true));
509 WARN_ON(static_branch_unlikely(&sk_true));
510 WARN_ON(!static_branch_likely(&sk_false));
511 WARN_ON(!static_branch_unlikely(&sk_false));
512
513 static_branch_enable(&sk_true);
514 static_branch_disable(&sk_false);
515 }
516
517 return 0;
518}
519late_initcall(jump_label_test);
520#endif /* STATIC_KEYS_SELFTEST */
521
522#endif /* HAVE_JUMP_LABEL */