Skip to content

Commit 9a868f6

Browse files
committed
powerpc: Add security feature flags for Spectre/Meltdown
This commit adds security feature flags to reflect the settings we receive from firmware regarding Spectre/Meltdown mitigations. The feature names reflect the names we are given by firmware on bare metal machines. See the hostboot source for details. Arguably these could be firmware features, but that then requires them to be read early in boot so they're available prior to asm feature patching, but we don't actually want to use them for patching. We may also want to dynamically update them in future, which would be incompatible with the way firmware features work (at the moment at least). So for now just make them separate flags. Signed-off-by: Michael Ellerman <[email protected]>
1 parent c4bc366 commit 9a868f6

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
/*
3+
* Security related feature bit definitions.
4+
*
5+
* Copyright 2018, Michael Ellerman, IBM Corporation.
6+
*/
7+
8+
#ifndef _ASM_POWERPC_SECURITY_FEATURES_H
9+
#define _ASM_POWERPC_SECURITY_FEATURES_H
10+
11+
12+
extern unsigned long powerpc_security_features;
13+
14+
static inline void security_ftr_set(unsigned long feature)
15+
{
16+
powerpc_security_features |= feature;
17+
}
18+
19+
static inline void security_ftr_clear(unsigned long feature)
20+
{
21+
powerpc_security_features &= ~feature;
22+
}
23+
24+
static inline bool security_ftr_enabled(unsigned long feature)
25+
{
26+
return !!(powerpc_security_features & feature);
27+
}
28+
29+
30+
// Features indicating support for Spectre/Meltdown mitigations
31+
32+
// The L1-D cache can be flushed with ori r30,r30,0
33+
#define SEC_FTR_L1D_FLUSH_ORI30 0x0000000000000001ull
34+
35+
// The L1-D cache can be flushed with mtspr 882,r0 (aka SPRN_TRIG2)
36+
#define SEC_FTR_L1D_FLUSH_TRIG2 0x0000000000000002ull
37+
38+
// ori r31,r31,0 acts as a speculation barrier
39+
#define SEC_FTR_SPEC_BAR_ORI31 0x0000000000000004ull
40+
41+
// Speculation past bctr is disabled
42+
#define SEC_FTR_BCCTRL_SERIALISED 0x0000000000000008ull
43+
44+
// Entries in L1-D are private to a SMT thread
45+
#define SEC_FTR_L1D_THREAD_PRIV 0x0000000000000010ull
46+
47+
// Indirect branch prediction cache disabled
48+
#define SEC_FTR_COUNT_CACHE_DISABLED 0x0000000000000020ull
49+
50+
51+
// Features indicating need for Spectre/Meltdown mitigations
52+
53+
// The L1-D cache should be flushed on MSR[HV] 1->0 transition (hypervisor to guest)
54+
#define SEC_FTR_L1D_FLUSH_HV 0x0000000000000040ull
55+
56+
// The L1-D cache should be flushed on MSR[PR] 0->1 transition (kernel to userspace)
57+
#define SEC_FTR_L1D_FLUSH_PR 0x0000000000000080ull
58+
59+
// A speculation barrier should be used for bounds checks (Spectre variant 1)
60+
#define SEC_FTR_BNDS_CHK_SPEC_BAR 0x0000000000000100ull
61+
62+
// Firmware configuration indicates user favours security over performance
63+
#define SEC_FTR_FAVOUR_SECURITY 0x0000000000000200ull
64+
65+
#endif /* _ASM_POWERPC_SECURITY_FEATURES_H */

arch/powerpc/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ obj-$(CONFIG_VDSO32) += vdso32/
4242
obj-$(CONFIG_PPC_WATCHDOG) += watchdog.o
4343
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
4444
obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o
45-
obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_power.o
45+
obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_power.o security.o
4646
obj-$(CONFIG_PPC_BOOK3S_64) += mce.o mce_power.o
4747
obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o
4848
obj-$(CONFIG_PPC64) += vdso64/

arch/powerpc/kernel/security.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// 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>
8+
#include <asm/security_features.h>
9+
10+
11+
unsigned long powerpc_security_features __read_mostly = \
12+
SEC_FTR_L1D_FLUSH_HV | \
13+
SEC_FTR_L1D_FLUSH_PR | \
14+
SEC_FTR_BNDS_CHK_SPEC_BAR | \
15+
SEC_FTR_FAVOUR_SECURITY;

0 commit comments

Comments
 (0)