summaryrefslogtreecommitdiffstats
path: root/arch/x86/mm/kmemcheck/kmemcheck.c
diff options
context:
space:
mode:
authorVegard Nossum2009-02-27 11:35:55 +0100
committerVegard Nossum2009-06-15 15:49:22 +0200
commitac61a7579625ddfca3b2e0aa298879a94d15884d (patch)
treeadb11c2513bfdb4825e1ac213f8116d7280ac4a9 /arch/x86/mm/kmemcheck/kmemcheck.c
parentx86: unify pte_hidden (diff)
downloadkernel-qcow2-linux-ac61a7579625ddfca3b2e0aa298879a94d15884d.tar.gz
kernel-qcow2-linux-ac61a7579625ddfca3b2e0aa298879a94d15884d.tar.xz
kernel-qcow2-linux-ac61a7579625ddfca3b2e0aa298879a94d15884d.zip
kmemcheck: add opcode self-testing at boot
We've had some troubles in the past with weird instructions. This patch adds a self-test framework which can be used to verify that a certain set of opcodes are decoded correctly. Of course, the opcodes which are not tested can still give the wrong results. In short, this is just a safeguard to catch unintentional changes in the opcode decoder. It does not mean that errors can't still occur! [rebased for mainline inclusion] Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
Diffstat (limited to 'arch/x86/mm/kmemcheck/kmemcheck.c')
-rw-r--r--arch/x86/mm/kmemcheck/kmemcheck.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
index 6931e5115bcd..2c55ed098654 100644
--- a/arch/x86/mm/kmemcheck/kmemcheck.c
+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
@@ -29,8 +29,10 @@
#include "error.h"
#include "opcode.h"
#include "pte.h"
+#include "selftest.h"
#include "shadow.h"
+
#ifdef CONFIG_KMEMCHECK_DISABLED_BY_DEFAULT
# define KMEMCHECK_ENABLED 0
#endif
@@ -47,8 +49,6 @@ int kmemcheck_enabled = KMEMCHECK_ENABLED;
int __init kmemcheck_init(void)
{
- printk(KERN_INFO "kmemcheck: Initialized\n");
-
#ifdef CONFIG_SMP
/*
* Limit SMP to use a single CPU. We rely on the fact that this code
@@ -61,25 +61,18 @@ int __init kmemcheck_init(void)
}
#endif
+ if (!kmemcheck_selftest()) {
+ printk(KERN_INFO "kmemcheck: self-tests failed; disabling\n");
+ kmemcheck_enabled = 0;
+ return -EINVAL;
+ }
+
+ printk(KERN_INFO "kmemcheck: Initialized\n");
return 0;
}
early_initcall(kmemcheck_init);
-#ifdef CONFIG_KMEMCHECK_DISABLED_BY_DEFAULT
-# define KMEMCHECK_ENABLED 0
-#endif
-
-#ifdef CONFIG_KMEMCHECK_ENABLED_BY_DEFAULT
-# define KMEMCHECK_ENABLED 1
-#endif
-
-#ifdef CONFIG_KMEMCHECK_ONESHOT_BY_DEFAULT
-# define KMEMCHECK_ENABLED 2
-#endif
-
-int kmemcheck_enabled = KMEMCHECK_ENABLED;
-
/*
* We need to parse the kmemcheck= option before any memory is allocated.
*/