blob: 0eace3cac818e25dd13a7d4be6efc86997049390 [file] [log] [blame]
Michael Ellerman9a868f62018-03-27 23:01:44 +11001// SPDX-License-Identifier: GPL-2.0+
2//
3// Security related flags and so on.
4//
5// Copyright 2018, Michael Ellerman, IBM Corporation.
6
7#include <linux/kernel.h>
Michael Ellerman8ad33042018-03-27 23:01:48 +11008#include <linux/device.h>
Michael Ellermanff348352018-03-27 23:01:49 +11009#include <linux/seq_buf.h>
Michael Ellerman8ad33042018-03-27 23:01:48 +110010
Michael Ellerman9a868f62018-03-27 23:01:44 +110011#include <asm/security_features.h>
12
13
14unsigned long powerpc_security_features __read_mostly = \
15 SEC_FTR_L1D_FLUSH_HV | \
16 SEC_FTR_L1D_FLUSH_PR | \
17 SEC_FTR_BNDS_CHK_SPEC_BAR | \
18 SEC_FTR_FAVOUR_SECURITY;
Michael Ellerman8ad33042018-03-27 23:01:48 +110019
20
21ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
22{
Michael Ellermanff348352018-03-27 23:01:49 +110023 bool thread_priv;
24
25 thread_priv = security_ftr_enabled(SEC_FTR_L1D_THREAD_PRIV);
26
27 if (rfi_flush || thread_priv) {
28 struct seq_buf s;
29 seq_buf_init(&s, buf, PAGE_SIZE - 1);
30
31 seq_buf_printf(&s, "Mitigation: ");
32
33 if (rfi_flush)
34 seq_buf_printf(&s, "RFI Flush");
35
36 if (rfi_flush && thread_priv)
37 seq_buf_printf(&s, ", ");
38
39 if (thread_priv)
40 seq_buf_printf(&s, "L1D private per thread");
41
42 seq_buf_printf(&s, "\n");
43
44 return s.len;
45 }
46
47 if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
48 !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR))
49 return sprintf(buf, "Not affected\n");
Michael Ellerman8ad33042018-03-27 23:01:48 +110050
51 return sprintf(buf, "Vulnerable\n");
52}
Michael Ellerman56986012018-03-27 23:01:52 +110053
54ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf)
55{
56 if (!security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR))
57 return sprintf(buf, "Not affected\n");
58
59 return sprintf(buf, "Vulnerable\n");
60}