All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [igt-dev] [PATCH i-g-t 2/2] lib/kmod: Check for kernel taints before/after selftests
@ 2021-01-13  2:38 Dixit, Ashutosh
  0 siblings, 0 replies; 3+ messages in thread
From: Dixit, Ashutosh @ 2021-01-13  2:38 UTC (permalink / raw)
  To: igt-dev, Chris Wilson; +Cc: cq.tang, Petri Latvala

On Thu, Jan 07, 2021 at 10:43:28AM +0000, Chris Wilson wrote:
> If the kernel generates a bad taint during the selftest (e.g. a
> warning), declare the selftest to be a failure.

People are reporting selftests skipping if the kernel was previously
tainted due to an unrelated reason as a result of this commit (mostly in
personal testing). Is there any way to clear the kernel taint to avoid this
issue (without reverting this commit)? I have looked but haven't found
anything. Thanks.

> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  lib/igt_kmod.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
> index ebeacd6fc..2ae45a1a1 100644
> --- a/lib/igt_kmod.c
> +++ b/lib/igt_kmod.c
> @@ -29,6 +29,7 @@
>  #include "igt_core.h"
>  #include "igt_kmod.h"
>  #include "igt_sysfs.h"
> +#include "igt_taints.h"
>
>  /**
>   * SECTION:igt_kmod
> @@ -582,9 +583,12 @@ int igt_kselftest_execute(struct igt_kselftest *tst,
>			  const char *options,
>			  const char *result)
>  {
> +	unsigned long taints;
>	char buf[1024];
>	int err;
>
> +	igt_skip_on(igt_kernel_tainted(&taints));
> +
>	lseek(tst->kmsg, 0, SEEK_END);
>
>	snprintf(buf, sizeof(buf), "%s=1 %s", tl->param, options ?: "");
> @@ -607,6 +611,8 @@ int igt_kselftest_execute(struct igt_kselftest *tst,
>		     "kselftest \"%s %s\" failed: %s [%d]\n",
>		     tst->module_name, buf, strerror(-err), -err);
>
> +	igt_assert_eq(igt_kernel_tainted(&taints), 0);
> +
>	return err;
>  }
>
> --
> 2.30.0
>
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [igt-dev] [PATCH i-g-t 1/2] lib: Process kernel taints
@ 2021-01-07 10:43 Chris Wilson
  2021-01-07 10:43 ` [igt-dev] [PATCH i-g-t 2/2] lib/kmod: Check for kernel taints before/after selftests Chris Wilson
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Wilson @ 2021-01-07 10:43 UTC (permalink / raw)
  To: igt-dev; +Cc: petri.latvala, Chris Wilson

A small library routine to read '/proc/sys/kernel/taints' and check for
a fatal condition. This is currently used by the runner, but is also
useful for some tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/Makefile.sources |  2 ++
 lib/igt_taints.c     | 65 +++++++++++++++++++++++++++++++++++++++
 lib/igt_taints.h     | 19 ++++++++++++
 lib/meson.build      |  1 +
 runner/executor.c    | 73 +++++++++-----------------------------------
 5 files changed, 101 insertions(+), 59 deletions(-)
 create mode 100644 lib/igt_taints.c
 create mode 100644 lib/igt_taints.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 67b386457..7102f95e7 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -64,6 +64,8 @@ lib_source_list =	 	\
 	igt_sysfs.h		\
 	igt_sysrq.c		\
 	igt_sysrq.h		\
+	igt_taints.c		\
+	igt_taints.h		\
 	igt_thread.c		\
 	igt_thread.h		\
 	igt_x86.h		\
diff --git a/lib/igt_taints.c b/lib/igt_taints.c
new file mode 100644
index 000000000..f9b32d106
--- /dev/null
+++ b/lib/igt_taints.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2021 Intel Corporation
+ */
+
+#include <stdio.h>
+
+#include "igt_taints.h"
+
+/* see Linux's include/linux/kernel.h */
+static const struct {
+	int bit;
+	int bad;
+	const char *explanation;
+} abort_taints[] = {
+  { 5, 1, "TAINT_BAD_PAGE: Bad page reference or an unexpected page flags." },
+  { 7, 1, "TAINT_DIE: Kernel has died - BUG/OOPS." },
+  { 9, 1, "TAINT_WARN: WARN_ON has happened." },
+  { -1 }
+};
+
+const char *igt_explain_taints(unsigned long *taints)
+{
+	for (typeof(*abort_taints) *taint = abort_taints;
+	     taint->bit >= 0;
+	     taint++) {
+		if (*taints & (1ul << taint->bit)) {
+			*taints &= ~(1ul << taint->bit);
+			return taint->explanation;
+		}
+	}
+
+	return NULL;
+}
+
+unsigned long igt_bad_taints(void)
+{
+	static unsigned long bad_taints;
+
+	if (!bad_taints) {
+		for (typeof(*abort_taints) *taint = abort_taints;
+		     taint->bit >= 0;
+		     taint++) {
+			if (taint->bad)
+				bad_taints |= 1ul << taint->bit;
+		}
+	}
+
+	return bad_taints;
+}
+
+unsigned long igt_kernel_tainted(unsigned long *taints)
+{
+	FILE *f;
+
+	*taints = 0;
+
+	f = fopen("/proc/sys/kernel/tainted", "r");
+	if (f) {
+		fscanf(f, "%lu", taints);
+		fclose(f);
+	}
+
+	return is_tainted(*taints);
+}
diff --git a/lib/igt_taints.h b/lib/igt_taints.h
new file mode 100644
index 000000000..be4195c5a
--- /dev/null
+++ b/lib/igt_taints.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2021 Intel Corporation
+ */
+
+#ifndef __IGT_TAINTS_H__
+#define __IGT_TAINTS_H__
+
+unsigned long igt_kernel_tainted(unsigned long *taints);
+const char *igt_explain_taints(unsigned long *taints);
+
+unsigned long igt_bad_taints(void);
+
+static inline unsigned long is_tainted(unsigned long taints)
+{
+	return taints & igt_bad_taints();
+}
+
+#endif /* __IGT_TAINTS_H__ */
diff --git a/lib/meson.build b/lib/meson.build
index 540facb24..3abc42cb3 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -27,6 +27,7 @@ lib_sources = [
 	'igt_syncobj.c',
 	'igt_sysfs.c',
 	'igt_sysrq.c',
+	'igt_taints.c',
 	'igt_thread.c',
 	'igt_vec.c',
 	'igt_vgem.c',
diff --git a/runner/executor.c b/runner/executor.c
index faf272d85..93db8bb36 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -24,6 +24,7 @@
 
 #include "igt_aux.h"
 #include "igt_core.h"
+#include "igt_taints.h"
 #include "executor.h"
 #include "output_strings.h"
 
@@ -307,70 +308,23 @@ static char *handle_lockdep(void)
 	return NULL;
 }
 
-/* see Linux's include/linux/kernel.h */
-static const struct {
-	unsigned long bit;
-	const char *explanation;
-} abort_taints[] = {
-  {(1 << 5), "TAINT_BAD_PAGE: Bad page reference or an unexpected page flags."},
-  {(1 << 7), "TAINT_DIE: Kernel has died - BUG/OOPS."},
-  {(1 << 9), "TAINT_WARN: WARN_ON has happened."},
-  {0, 0}};
-
-static unsigned long bad_taints(void)
-{
-	static unsigned long __bad_taints;
-
-	if (!__bad_taints) {
-		for (typeof(*abort_taints) *taint = abort_taints;
-		     taint->bit;
-		     taint++)
-			__bad_taints |= taint->bit;
-	}
-
-	return __bad_taints;
-}
-
-static unsigned long is_tainted(unsigned long taints)
-{
-	return taints & bad_taints();
-}
-
-static unsigned long tainted(unsigned long *taints)
-{
-	FILE *f;
-
-	*taints = 0;
-
-	f = fopen("/proc/sys/kernel/tainted", "r");
-	if (f) {
-		fscanf(f, "%lu", taints);
-		fclose(f);
-	}
-
-	return is_tainted(*taints);
-}
-
 static char *handle_taint(void)
 {
-	unsigned long taints;
+	unsigned long taints, bad;
+	char *explain;
 	char *reason;
 
-	if (!tainted(&taints))
+	bad = igt_kernel_tainted(&taints);
+	if (!bad)
 		return NULL;
 
-	asprintf(&reason, "Kernel badly tainted (%#lx) (check dmesg for details):\n",
-		 taints);
-
-	for (typeof(*abort_taints) *taint = abort_taints; taint->bit; taint++) {
-		if (taint->bit & taints) {
-			char *old_reason = reason;
-			asprintf(&reason, "%s\t(%#lx) %s\n",
-					old_reason,
-					taint->bit,
-					taint->explanation);
-			free(old_reason);
-		}
+	asprintf(&reason, "Kernel badly tainted (%#lx, %#lx) (check dmesg for details):\n",
+		 taints, bad);
+
+	while ((explain = igt_explain_taints(&bad))) {
+		char *old_reason = reason;
+		asprintf(&reason, "%s\t%s\n", old_reason, explain);
+		free(old_reason);
 	}
 
 	return reason;
@@ -1142,7 +1096,8 @@ static int monitor_output(pid_t child,
 			sigfd = -1; /* we are dying, no signal handling for now */
 		}
 
-		timeout_reason = need_to_timeout(settings, killed, tainted(&taints),
+		timeout_reason = need_to_timeout(settings, killed,
+						 igt_kernel_tainted(&taints),
 						 igt_time_elapsed(&time_last_activity, &time_now),
 						 igt_time_elapsed(&time_last_subtest, &time_now),
 						 igt_time_elapsed(&time_killed, &time_now),
-- 
2.30.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-13  2:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13  2:38 [igt-dev] [PATCH i-g-t 2/2] lib/kmod: Check for kernel taints before/after selftests Dixit, Ashutosh
  -- strict thread matches above, loose matches on Subject: below --
2021-01-07 10:43 [igt-dev] [PATCH i-g-t 1/2] lib: Process kernel taints Chris Wilson
2021-01-07 10:43 ` [igt-dev] [PATCH i-g-t 2/2] lib/kmod: Check for kernel taints before/after selftests Chris Wilson
2021-01-08 12:28   ` Petri Latvala

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.