1 // SPDX-License-Identifier: GPL-2.0+
3 // Security related flags and so on.
5 // Copyright 2018, Michael Ellerman, IBM Corporation.
7 #include <linux/kernel.h>
8 #include <linux/device.h>
9 #include <linux/seq_buf.h>
11 #include <asm/debugfs.h>
12 #include <asm/security_features.h>
15 unsigned long powerpc_security_features __read_mostly
= \
16 SEC_FTR_L1D_FLUSH_HV
| \
17 SEC_FTR_L1D_FLUSH_PR
| \
18 SEC_FTR_BNDS_CHK_SPEC_BAR
| \
19 SEC_FTR_FAVOUR_SECURITY
;
22 ssize_t
cpu_show_meltdown(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
26 thread_priv
= security_ftr_enabled(SEC_FTR_L1D_THREAD_PRIV
);
28 if (rfi_flush
|| thread_priv
) {
30 seq_buf_init(&s
, buf
, PAGE_SIZE
- 1);
32 seq_buf_printf(&s
, "Mitigation: ");
35 seq_buf_printf(&s
, "RFI Flush");
37 if (rfi_flush
&& thread_priv
)
38 seq_buf_printf(&s
, ", ");
41 seq_buf_printf(&s
, "L1D private per thread");
43 seq_buf_printf(&s
, "\n");
48 if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV
) &&
49 !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR
))
50 return sprintf(buf
, "Not affected\n");
52 return sprintf(buf
, "Vulnerable\n");
55 ssize_t
cpu_show_spectre_v1(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
57 if (!security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR
))
58 return sprintf(buf
, "Not affected\n");
60 return sprintf(buf
, "Vulnerable\n");
63 ssize_t
cpu_show_spectre_v2(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
68 seq_buf_init(&s
, buf
, PAGE_SIZE
- 1);
70 bcs
= security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED
);
71 ccd
= security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED
);
72 ori
= security_ftr_enabled(SEC_FTR_SPEC_BAR_ORI31
);
75 seq_buf_printf(&s
, "Mitigation: ");
78 seq_buf_printf(&s
, "Indirect branch serialisation (kernel only)");
81 seq_buf_printf(&s
, ", ");
84 seq_buf_printf(&s
, "Indirect branch cache disabled");
86 seq_buf_printf(&s
, "Vulnerable");
89 seq_buf_printf(&s
, ", ori31 speculation barrier enabled");
91 seq_buf_printf(&s
, "\n");
97 * Store-forwarding barrier support.
100 static enum stf_barrier_type stf_enabled_flush_types
;
101 static bool no_stf_barrier
;
104 static int __init
handle_no_stf_barrier(char *p
)
106 pr_info("stf-barrier: disabled on command line.");
107 no_stf_barrier
= true;
111 early_param("no_stf_barrier", handle_no_stf_barrier
);
113 /* This is the generic flag used by other architectures */
114 static int __init
handle_ssbd(char *p
)
116 if (!p
|| strncmp(p
, "auto", 5) == 0 || strncmp(p
, "on", 2) == 0 ) {
117 /* Until firmware tells us, we have the barrier with auto */
119 } else if (strncmp(p
, "off", 3) == 0) {
120 handle_no_stf_barrier(NULL
);
127 early_param("spec_store_bypass_disable", handle_ssbd
);
129 /* This is the generic flag used by other architectures */
130 static int __init
handle_no_ssbd(char *p
)
132 handle_no_stf_barrier(NULL
);
135 early_param("nospec_store_bypass_disable", handle_no_ssbd
);
137 static void stf_barrier_enable(bool enable
)
140 do_stf_barrier_fixups(stf_enabled_flush_types
);
142 do_stf_barrier_fixups(STF_BARRIER_NONE
);
144 stf_barrier
= enable
;
147 void setup_stf_barrier(void)
149 enum stf_barrier_type type
;
152 hv
= cpu_has_feature(CPU_FTR_HVMODE
);
154 /* Default to fallback in case fw-features are not available */
155 if (cpu_has_feature(CPU_FTR_ARCH_300
))
156 type
= STF_BARRIER_EIEIO
;
157 else if (cpu_has_feature(CPU_FTR_ARCH_207S
))
158 type
= STF_BARRIER_SYNC_ORI
;
159 else if (cpu_has_feature(CPU_FTR_ARCH_206
))
160 type
= STF_BARRIER_FALLBACK
;
162 type
= STF_BARRIER_NONE
;
164 enable
= security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY
) &&
165 (security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR
) ||
166 (security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV
) && hv
));
168 if (type
== STF_BARRIER_FALLBACK
) {
169 pr_info("stf-barrier: fallback barrier available\n");
170 } else if (type
== STF_BARRIER_SYNC_ORI
) {
171 pr_info("stf-barrier: hwsync barrier available\n");
172 } else if (type
== STF_BARRIER_EIEIO
) {
173 pr_info("stf-barrier: eieio barrier available\n");
176 stf_enabled_flush_types
= type
;
179 stf_barrier_enable(enable
);
182 ssize_t
cpu_show_spec_store_bypass(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
184 if (stf_barrier
&& stf_enabled_flush_types
!= STF_BARRIER_NONE
) {
186 switch (stf_enabled_flush_types
) {
187 case STF_BARRIER_EIEIO
:
190 case STF_BARRIER_SYNC_ORI
:
193 case STF_BARRIER_FALLBACK
:
199 return sprintf(buf
, "Mitigation: Kernel entry/exit barrier (%s)\n", type
);
202 if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV
) &&
203 !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR
))
204 return sprintf(buf
, "Not affected\n");
206 return sprintf(buf
, "Vulnerable\n");
209 #ifdef CONFIG_DEBUG_FS
210 static int stf_barrier_set(void *data
, u64 val
)
221 /* Only do anything if we're changing state */
222 if (enable
!= stf_barrier
)
223 stf_barrier_enable(enable
);
228 static int stf_barrier_get(void *data
, u64
*val
)
230 *val
= stf_barrier
? 1 : 0;
234 DEFINE_SIMPLE_ATTRIBUTE(fops_stf_barrier
, stf_barrier_get
, stf_barrier_set
, "%llu\n");
236 static __init
int stf_barrier_debugfs_init(void)
238 debugfs_create_file("stf_barrier", 0600, powerpc_debugfs_root
, NULL
, &fops_stf_barrier
);
241 device_initcall(stf_barrier_debugfs_init
);
242 #endif /* CONFIG_DEBUG_FS */