• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018 Michael Moese <mmoese@suse.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /* Usage example
19  *
20  * ...
21  * #include "tst_test.h"
22  * #include "tst_taint.h"
23  * ..
24  * void setup(void)
25  * {
26  *	...
27  *	tst_taint_init(TST_TAINT_W | TST_TAINT_D));
28  *	...
29  * }
30  *
31  * void run(void)
32  * {
33  *	...
34  *	. test code here
35  *	...
36  *	if (tst_taint_check() != 0)
37  *		tst_res(TFAIL, "kernel has issues");
38  *	else
39  *		tst_res(TPASS, "kernel seems to be fine");
40  * }
41  *
42  *
43  *
44  * The above code checks, if the kernel issued a warning (TST_TAINT_W)
45  * or even died (TST_TAINT_D) during test execution.
46  * If these are set after running a test case, we most likely
47  * triggered a kernel bug.
48  */
49 
50 #ifndef TST_TAINTED_H__
51 #define TST_TAINTED_H__
52 
53 /*
54  * This are all 17 flags that are present in kernel 4.15
55  * see kernel/panic.c in kernel sources
56  *
57  * Not all of them are valid in all kernel versions.
58  */
59 #define TST_TAINT_G     (1 <<  0) /* a module with non-GPL license loaded */
60 #define TST_TAINT_F     (1 <<  1) /* a module was force-loaded */
61 #define TST_TAINT_S     (1 <<  2) /* SMP with Non-SMP kernel */
62 #define TST_TAINT_R     (1 <<  3) /* module force unloaded */
63 #define TST_TAINT_M     (1 <<  4) /* machine check error occurred */
64 #define TST_TAINT_B     (1 <<  5) /* page-release function found bad page */
65 #define TST_TAINT_U     (1 <<  6) /* user requested taint flag */
66 #define TST_TAINT_D     (1 <<  7) /* kernel died recently - OOPS or BUG */
67 #define TST_TAINT_A     (1 <<  8) /* ACPI table has been overwritten */
68 #define TST_TAINT_W     (1 <<  9) /* a warning has been issued by kernel */
69 #define TST_TAINT_C     (1 << 10) /* driver from drivers/staging was loaded */
70 #define TST_TAINT_I     (1 << 11) /* working around BIOS/Firmware bug */
71 #define TST_TAINT_O     (1 << 12) /* out of tree module loaded */
72 #define TST_TAINT_E     (1 << 13) /* unsigned module was loaded */
73 #define TST_TAINT_L     (1 << 14) /* A soft lock-up has previously occurred */
74 #define TST_TAINT_K     (1 << 15) /* kernel has been live-patched */
75 #define TST_TAINT_X	(1 << 16) /* auxiliary taint, for distro's use */
76 
77 /*
78  * Initialize and prepare support for checking tainted kernel.
79  *
80  * supply the mask of TAINT-flags you want to check, for example
81  * (TST_TAINT_W | TST_TAINT_D) when you want to check if the kernel issued
82  * a warning or even reported it died.
83  *
84  * This function tests if the requested flags are supported on the
85  * locally running kernel. In case the tainted-flags are already set by
86  * the kernel, there is no reason to continue and TCONF is generated.
87  *
88  * The mask must not be zero.
89  */
90 void tst_taint_init(unsigned int mask);
91 
92 
93 /*
94  * check if the tainted flags handed to tst_taint_init() are still not set
95  * during or after running the test.
96  * Calling this function is only allowed after tst_taint_init() was called,
97  * otherwise TBROK will be generated.
98  *
99  * returns 0 or a bitmask of the flags that currently tainted the kernel.
100  */
101 unsigned int tst_taint_check(void);
102 
103 
104 #endif /* TST_TAINTED_H__ */
105