19a868f63SMichael Ellerman // SPDX-License-Identifier: GPL-2.0+ 29a868f63SMichael Ellerman // 39a868f63SMichael Ellerman // Security related flags and so on. 49a868f63SMichael Ellerman // 59a868f63SMichael Ellerman // Copyright 2018, Michael Ellerman, IBM Corporation. 69a868f63SMichael Ellerman 79a868f63SMichael Ellerman #include <linux/kernel.h> 88ad33041SMichael Ellerman #include <linux/device.h> 9ff348355SMichael Ellerman #include <linux/seq_buf.h> 108ad33041SMichael Ellerman 119a868f63SMichael Ellerman #include <asm/security_features.h> 129a868f63SMichael Ellerman 139a868f63SMichael Ellerman 149a868f63SMichael Ellerman unsigned long powerpc_security_features __read_mostly = \ 159a868f63SMichael Ellerman SEC_FTR_L1D_FLUSH_HV | \ 169a868f63SMichael Ellerman SEC_FTR_L1D_FLUSH_PR | \ 179a868f63SMichael Ellerman SEC_FTR_BNDS_CHK_SPEC_BAR | \ 189a868f63SMichael Ellerman SEC_FTR_FAVOUR_SECURITY; 198ad33041SMichael Ellerman 208ad33041SMichael Ellerman 218ad33041SMichael Ellerman ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) 228ad33041SMichael Ellerman { 23ff348355SMichael Ellerman bool thread_priv; 24ff348355SMichael Ellerman 25ff348355SMichael Ellerman thread_priv = security_ftr_enabled(SEC_FTR_L1D_THREAD_PRIV); 26ff348355SMichael Ellerman 27ff348355SMichael Ellerman if (rfi_flush || thread_priv) { 28ff348355SMichael Ellerman struct seq_buf s; 29ff348355SMichael Ellerman seq_buf_init(&s, buf, PAGE_SIZE - 1); 30ff348355SMichael Ellerman 31ff348355SMichael Ellerman seq_buf_printf(&s, "Mitigation: "); 32ff348355SMichael Ellerman 338ad33041SMichael Ellerman if (rfi_flush) 34ff348355SMichael Ellerman seq_buf_printf(&s, "RFI Flush"); 35ff348355SMichael Ellerman 36ff348355SMichael Ellerman if (rfi_flush && thread_priv) 37ff348355SMichael Ellerman seq_buf_printf(&s, ", "); 38ff348355SMichael Ellerman 39ff348355SMichael Ellerman if (thread_priv) 40ff348355SMichael Ellerman seq_buf_printf(&s, "L1D private per thread"); 41ff348355SMichael Ellerman 42ff348355SMichael Ellerman seq_buf_printf(&s, "\n"); 43ff348355SMichael Ellerman 44ff348355SMichael Ellerman return s.len; 45ff348355SMichael Ellerman } 46ff348355SMichael Ellerman 47ff348355SMichael Ellerman if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) && 48ff348355SMichael Ellerman !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR)) 49ff348355SMichael Ellerman return sprintf(buf, "Not affected\n"); 508ad33041SMichael Ellerman 518ad33041SMichael Ellerman return sprintf(buf, "Vulnerable\n"); 528ad33041SMichael Ellerman } 53*56986016SMichael Ellerman 54*56986016SMichael Ellerman ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf) 55*56986016SMichael Ellerman { 56*56986016SMichael Ellerman if (!security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR)) 57*56986016SMichael Ellerman return sprintf(buf, "Not affected\n"); 58*56986016SMichael Ellerman 59*56986016SMichael Ellerman return sprintf(buf, "Vulnerable\n"); 60*56986016SMichael Ellerman } 61