Skip to contentSkip to conversation

kmemcheck: add opcode self-testing at boot

PATCH New Vegard Nossum 1 participant 1 message Feb 27, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kmemcheck: add opcode self-testing at boot

Quoted 1 line

From 01fb811b6c25ecb113af9230b7297ac45ed91519 Mon Sep 17 00:00:00 2001

From: Vegard Nossum <[email protected]>
Date: Fri, 27 Feb 2009 11:35:55 +0100
Subject: [PATCH] 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!

---
 arch/x86/mm/kmemcheck/Makefile    |    2 +-
 arch/x86/mm/kmemcheck/kmemcheck.c |   38 ++++++++++++--------
 arch/x86/mm/kmemcheck/selftest.c  |   69 +++++++++++++++++++++++++++++++++++++
 arch/x86/mm/kmemcheck/selftest.h  |    6 +++
 4 files changed, 99 insertions(+), 16 deletions(-)
 create mode 100644 arch/x86/mm/kmemcheck/selftest.c
 create mode 100644 arch/x86/mm/kmemcheck/selftest.h
arch/x86/mm/kmemcheck/Makefile +1 -1
index 4666b7a..520b3bc 100644
@@ -1 +1 @@
-obj-y := error.o kmemcheck.o opcode.o pte.o shadow.o
+obj-y := error.o kmemcheck.o opcode.o pte.o selftest.o shadow.o
arch/x86/mm/kmemcheck/kmemcheck.c +23 -15
index 9349565..2b5ca65 100644
@@ -29,12 +29,26 @@
 #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
+
+#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;
+
 void __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
@@ -46,21 +60,15 @@ void __init kmemcheck_init(void)
 		setup_max_cpus = 1;
 	}
 #endif
-}
 
-#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
+	if (!kmemcheck_selftest()) {
+		printk(KERN_INFO "kmemcheck: self-tests failed; disabling\n");
+		kmemcheck_enabled = 0;
+		return;
+	}
 
-int kmemcheck_enabled = KMEMCHECK_ENABLED;
+	printk(KERN_INFO "kmemcheck: Initialized\n");
+}
 
 /*
  * We need to parse the kmemcheck= option before any memory is allocated.
arch/x86/mm/kmemcheck/selftest.c new file +69 -0

69 lines not on this page · raw message

arch/x86/mm/kmemcheck/selftest.h new file +6 -0
new file mode 100644
index 0000000..8fed4fe
@@ -0,0 +1,6 @@
+#ifndef ARCH_X86_MM_KMEMCHECK_SELFTEST_H
+#define ARCH_X86_MM_KMEMCHECK_SELFTEST_H
+
+bool kmemcheck_selftest(void);
+
+#endif
Signature · 1 line
1.6.0.6