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

Petri Latvala petri.latvala at intel.com
Tue Dec 5 12:32:36 UTC 2017


On Tue, Dec 05, 2017 at 12:24:53PM +0000, Chris Wilson wrote:
> 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.
> 
> v2: Docs?
> 
> 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>
> Reviewed-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
> ---
>  lib/Makefile.sources   |   2 +
>  lib/igt_core.c         |  19 +++++++-
>  lib/igt_kernel_taint.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_kernel_taint.h |  34 ++++++++++++++
>  4 files changed, 174 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 6e968d9f7..152153908 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 03fa6e4e8..486c5989d 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"
>  
> @@ -261,6 +262,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;
> @@ -937,6 +939,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);
>  
> @@ -1083,8 +1087,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");
> +	}
>  }


If you change the result to FAIL or WARN here, succeeded_one should not be changed.

What of tests that don't have subtests?


-- 
Petri Latvala



>  
>  /**
> diff --git a/lib/igt_kernel_taint.c b/lib/igt_kernel_taint.c
> new file mode 100644
> index 000000000..7f105ead7
> --- /dev/null
> +++ b/lib/igt_kernel_taint.c
> @@ -0,0 +1,120 @@
> +/*
> + * 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 (e.g. modparam_unsafe)" },
> +	{ "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" },
> +};
> +
> +/**
> + * igt_read_kernel_taint: Reads the kernel's taint status
> + *
> + * The kernel maintains a bitmask of taints (permanent errors) it has
> + * seen since boot. Each taint means that the kernel is subsequently
> + * unreliable, but some taints are more important than others.
> + */
> +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;
> +}
> +
> +/**
> + * igt_kernel_taint_print: Print the meaning of a taint bitmask
> + * @taint: The taint bitmask to decode
> + *
> + * Decodes a bitmask into error messages and displays them using
> + * igt_info() for normal errors, and igt_warn() for critical errors.
> + */
> +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);
> +	}
> +}
> +
> +/**
> + * igt_kernel_tainted: Checks the tainted bitmask for crtical errors
> + * @taint: The taint bitmask to decode
> + *
> + * Some kernel taints are more important than others. Some tell us about
> + * user operations that are risky, others tell us when the system is on fire.
> + * igt_kernel_tainted() decodes the taint bitmask into whether we can
> + * safely ignore the taint or should flag an error.
> + *
> + * Returns: a bitmask of TAINT_WARN | TAINT_ERROR.
> + */
> +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 000000000..2240fe791
> --- /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.1
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx


More information about the Intel-gfx mailing list