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> 9*ff348355SMichael 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 { 23*ff348355SMichael Ellerman bool thread_priv; 24*ff348355SMichael Ellerman 25*ff348355SMichael Ellerman thread_priv = security_ftr_enabled(SEC_FTR_L1D_THREAD_PRIV); 26*ff348355SMichael Ellerman 27*ff348355SMichael Ellerman if (rfi_flush || thread_priv) { 28*ff348355SMichael Ellerman struct seq_buf s; 29*ff348355SMichael Ellerman seq_buf_init(&s, buf, PAGE_SIZE - 1); 30*ff348355SMichael Ellerman 31*ff348355SMichael Ellerman seq_buf_printf(&s, "Mitigation: "); 32*ff348355SMichael Ellerman 338ad33041SMichael Ellerman if (rfi_flush) 34*ff348355SMichael Ellerman seq_buf_printf(&s, "RFI Flush"); 35*ff348355SMichael Ellerman 36*ff348355SMichael Ellerman if (rfi_flush && thread_priv) 37*ff348355SMichael Ellerman seq_buf_printf(&s, ", "); 38*ff348355SMichael Ellerman 39*ff348355SMichael Ellerman if (thread_priv) 40*ff348355SMichael Ellerman seq_buf_printf(&s, "L1D private per thread"); 41*ff348355SMichael Ellerman 42*ff348355SMichael Ellerman seq_buf_printf(&s, "\n"); 43*ff348355SMichael Ellerman 44*ff348355SMichael Ellerman return s.len; 45*ff348355SMichael Ellerman } 46*ff348355SMichael Ellerman 47*ff348355SMichael Ellerman if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) && 48*ff348355SMichael Ellerman !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR)) 49*ff348355SMichael Ellerman return sprintf(buf, "Not affected\n"); 508ad33041SMichael Ellerman 518ad33041SMichael Ellerman return sprintf(buf, "Vulnerable\n"); 528ad33041SMichael Ellerman } 53