xref: /openbmc/linux/arch/arm/kernel/spectre.c (revision 57654884)
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/cpu.h>
3 #include <linux/device.h>
4 
5 #include <asm/spectre.h>
6 
7 ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
8 			    char *buf)
9 {
10 	return sprintf(buf, "Mitigation: __user pointer sanitization\n");
11 }
12 
13 static unsigned int spectre_v2_state;
14 static unsigned int spectre_v2_methods;
15 
16 void spectre_v2_update_state(unsigned int state, unsigned int method)
17 {
18 	if (state > spectre_v2_state)
19 		spectre_v2_state = state;
20 	spectre_v2_methods |= method;
21 }
22 
23 ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
24 			    char *buf)
25 {
26 	const char *method;
27 
28 	if (spectre_v2_state == SPECTRE_UNAFFECTED)
29 		return sprintf(buf, "%s\n", "Not affected");
30 
31 	if (spectre_v2_state != SPECTRE_MITIGATED)
32 		return sprintf(buf, "%s\n", "Vulnerable");
33 
34 	switch (spectre_v2_methods) {
35 	case SPECTRE_V2_METHOD_BPIALL:
36 		method = "Branch predictor hardening";
37 		break;
38 
39 	case SPECTRE_V2_METHOD_ICIALLU:
40 		method = "I-cache invalidation";
41 		break;
42 
43 	case SPECTRE_V2_METHOD_SMC:
44 	case SPECTRE_V2_METHOD_HVC:
45 		method = "Firmware call";
46 		break;
47 
48 	case SPECTRE_V2_METHOD_LOOP8:
49 		method = "History overwrite";
50 		break;
51 
52 	default:
53 		method = "Multiple mitigations";
54 		break;
55 	}
56 
57 	return sprintf(buf, "Mitigation: %s\n", method);
58 }
59