• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2018 Michael Moese <mmoese@suse.de>
4  */
5 
6 /* Usage example
7  *
8  * ...
9  * #include "tst_test.h"
10  * ..
11  * static struct tst_test test = {
12  *	...
13  *	.taint_check = TST_TAINT_W | TST_TAINT_D,
14  *	...
15  * };
16  *
17  * void run(void)
18  * {
19  *	...
20  *	. test code here
21  *	...
22  *	if (tst_taint_check() != 0)
23  *		tst_res(TFAIL, "kernel has issues");
24  *	else
25  *		tst_res(TPASS, "kernel seems to be fine");
26  * }
27  *
28  *
29  *
30  * The above code checks whether the kernel issued a warning (TST_TAINT_W)
31  * or even died (TST_TAINT_D) during test execution.
32  * If these are set after running a test case, we most likely
33  * triggered a kernel bug.
34  *
35  * You do not need to use tst_taint_check() explicitly because it'll be called
36  * automatically at the end of testing by the LTP library if
37  * tst_test.taint_check in non-zero.
38  */
39 
40 #ifndef TST_TAINTED_H__
41 #define TST_TAINTED_H__
42 
43 /*
44  * This are all 17 flags that are present in kernel 4.15
45  * see kernel/panic.c in kernel sources
46  *
47  * Not all of them are valid in all kernel versions.
48  */
49 #define TST_TAINT_G     (1 <<  0) /* a module with non-GPL license loaded */
50 #define TST_TAINT_F     (1 <<  1) /* a module was force-loaded */
51 #define TST_TAINT_S     (1 <<  2) /* SMP with Non-SMP kernel */
52 #define TST_TAINT_R     (1 <<  3) /* module force unloaded */
53 #define TST_TAINT_M     (1 <<  4) /* machine check error occurred */
54 #define TST_TAINT_B     (1 <<  5) /* page-release function found bad page */
55 #define TST_TAINT_U     (1 <<  6) /* user requested taint flag */
56 #define TST_TAINT_D     (1 <<  7) /* kernel died recently - OOPS or BUG */
57 #define TST_TAINT_A     (1 <<  8) /* ACPI table has been overwritten */
58 #define TST_TAINT_W     (1 <<  9) /* a warning has been issued by kernel */
59 #define TST_TAINT_C     (1 << 10) /* driver from drivers/staging was loaded */
60 #define TST_TAINT_I     (1 << 11) /* working around BIOS/Firmware bug */
61 #define TST_TAINT_O     (1 << 12) /* out of tree module loaded */
62 #define TST_TAINT_E     (1 << 13) /* unsigned module was loaded */
63 #define TST_TAINT_L     (1 << 14) /* A soft lock-up has previously occurred */
64 #define TST_TAINT_K     (1 << 15) /* kernel has been live-patched */
65 #define TST_TAINT_X     (1 << 16) /* auxiliary taint, for distro's use */
66 #define TST_TAINT_T     (1 << 17) /* kernel was built with the struct randomization plugin */
67 
68 /*
69  * Initialize and prepare support for checking tainted kernel. Called
70  * automatically by LTP library during test setup if tst_test.taint_check
71  * is non-zero. The value of tst_test.taint_check will be passed as the mask
72  * argument.
73  *
74  * supply the mask of TAINT-flags you want to check, for example
75  * (TST_TAINT_W | TST_TAINT_D) when you want to check if the kernel issued
76  * a warning or even reported it died.
77  *
78  * This function tests if the requested flags are supported on the
79  * locally running kernel. In case the tainted-flags are already set by
80  * the kernel, there is no reason to continue and TBROK is generated.
81  *
82  * The mask must not be zero.
83  */
84 void tst_taint_init(unsigned int mask);
85 
86 
87 /*
88  * check if the tainted flags handed to tst_taint_init() are still not set
89  * during or after running the test.
90  * Calling this function is only allowed after tst_taint_init() was called,
91  * otherwise TBROK will be generated.
92  *
93  * returns 0 or a bitmask of the flags that currently tainted the kernel.
94  */
95 unsigned int tst_taint_check(void);
96 
97 
98 #endif /* TST_TAINTED_H__ */
99