[Intel-gfx] [PATCH igt] lib: Check and report if a subtest triggers a new kernel taint

Chris Wilson chris at chris-wilson.co.uk
Wed Nov 29 12:30:23 UTC 2017


Checking for a tainted kernel is a convenient way to see if the test
generated a critical error such as a oops, or machine check.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Cc: Radoslaw Szwichtenberg <radoslaw.szwichtenberg at intel.com>
---
 lib/Makefile.sources   |  2 ++
 lib/igt_core.c         | 19 +++++++++-
 lib/igt_kernel_taint.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kernel_taint.h | 34 ++++++++++++++++++
 4 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 lib/igt_kernel_taint.c
 create mode 100644 lib/igt_kernel_taint.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 6e968d9f..15215390 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -22,6 +22,8 @@ lib_source_list =	 	\
 	igt_gt.h		\
 	igt_gvt.c		\
 	igt_gvt.h		\
+	igt_kernel_taint.c	\
+	igt_kernel_taint.h	\
 	igt_primes.c		\
 	igt_primes.h		\
 	igt_rand.c		\
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 6ce83bec..7e656323 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -63,6 +63,7 @@
 #include "intel_chipset.h"
 #include "intel_io.h"
 #include "igt_debugfs.h"
+#include "igt_kernel_taint.h"
 #include "version.h"
 #include "config.h"
 
@@ -258,6 +259,7 @@ static bool list_subtests = false;
 static char *run_single_subtest = NULL;
 static bool run_single_subtest_found = false;
 static const char *in_subtest = NULL;
+static unsigned long saved_kernel_taint;
 static struct timespec subtest_time;
 static clockid_t igt_clock = (clockid_t)-1;
 static bool in_fixture = false;
@@ -1002,6 +1004,8 @@ bool __igt_run_subtest(const char *subtest_name)
 		return false;
 	}
 
+	saved_kernel_taint = igt_read_kernel_taint();
+
 	kmsg(KERN_INFO "[IGT] %s: starting subtest %s\n", command_str, subtest_name);
 	igt_debug("Starting subtest: %s\n", subtest_name);
 
@@ -1148,8 +1152,21 @@ void __igt_skip_check(const char *file, const int line,
 void igt_success(void)
 {
 	succeeded_one = true;
-	if (in_subtest)
+	if (in_subtest) {
+		unsigned long new_kernel_taints =
+			igt_read_kernel_taint() & ~saved_kernel_taint;
+		unsigned int tainted = igt_kernel_tainted(new_kernel_taints);
+
+		if (tainted) {
+			igt_kernel_taint_print(new_kernel_taints);
+			if (tainted & TAINT_ERROR)
+				exit_subtest("FAIL");
+			else
+				exit_subtest("WARN");
+		}
+
 		exit_subtest("SUCCESS");
+	}
 }
 
 /**
diff --git a/lib/igt_kernel_taint.c b/lib/igt_kernel_taint.c
new file mode 100644
index 00000000..86d9cd20
--- /dev/null
+++ b/lib/igt_kernel_taint.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "igt.h"
+#include "igt_kernel_taint.h"
+#include "igt_sysfs.h"
+
+#define BIT(x) (1ul << (x))
+
+static const struct kernel_taint {
+	const char *msg;
+	unsigned int flags;
+} taints[] = {
+	{ "Non-GPL module loaded" },
+	{ "Forced module load" },
+	{ "Unsafe SMP processor" },
+	{ "Forced module unload" },
+	{ "Machine Check Exception", TAINT_WARN },
+	{ "Bad page detected", TAINT_ERROR },
+	{ "Tainted by user request", TAINT_WARN },
+	{ "System is on fire", TAINT_ERROR },
+	{ "ACPI DSDT has been overridden by user" },
+	{ "OOPS", TAINT_ERROR },
+	{ "Staging driver loaded; are you mad?" },
+	{ "Severe firmware bug workaround active", TAINT_WARN },
+	{ "Out-of-tree module loaded" },
+	{ "Unsigned module loaded" },
+	{ "Soft-lockup detected", TAINT_WARN },
+	{ "Kernel has been live patched" },
+};
+
+unsigned long igt_read_kernel_taint(void)
+{
+	unsigned long taint = 0;
+	int dir;
+
+	dir = open("/proc/sys/kernel", O_RDONLY);
+	if (dir != -1) {
+		igt_sysfs_scanf(dir, "tainted", "%lu", &taint);
+		close(dir);
+	}
+
+	return taint;
+}
+
+void igt_kernel_taint_print(unsigned long taint)
+{
+	igt_info("Kernel taint: %08lx\n", taint);
+	for (long bit = 0; bit < ARRAY_SIZE(taints); bit++) {
+		if (!(taint & BIT(bit)))
+			continue;
+
+		if (taints[bit].flags & (TAINT_WARN | TAINT_ERROR))
+			igt_warn("\t%08lx - %s\n", BIT(bit), taints[bit].msg);
+		else
+			igt_info("\t%08lx - %s \n", BIT(bit), taints[bit].msg);
+	}
+}
+
+unsigned int igt_kernel_tainted(unsigned long taint)
+{
+	unsigned int result = 0;
+
+	for (long bit = 0; bit < ARRAY_SIZE(taints); bit++) {
+		if (!(taint & BIT(bit)))
+			continue;
+
+		result |= taints[bit].flags & (TAINT_WARN | TAINT_ERROR);
+	}
+
+	return result;
+}
diff --git a/lib/igt_kernel_taint.h b/lib/igt_kernel_taint.h
new file mode 100644
index 00000000..2240fe79
--- /dev/null
+++ b/lib/igt_kernel_taint.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef IGT_KERNEL_TAINT_H
+#define IGT_KERNEL_TAINT_H
+
+#define TAINT_WARN 0x1
+#define TAINT_ERROR 0x2
+
+unsigned long igt_read_kernel_taint(void);
+void igt_kernel_taint_print(unsigned long taint);
+unsigned int igt_kernel_tainted(unsigned long taint);
+
+#endif /* IGT_KERNEL_TAINT_H */
-- 
2.15.0



More information about the Intel-gfx mailing list