162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Security related feature bit definitions. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright 2018, Michael Ellerman, IBM Corporation. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef _ASM_POWERPC_SECURITY_FEATURES_H 962306a36Sopenharmony_ci#define _ASM_POWERPC_SECURITY_FEATURES_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciextern u64 powerpc_security_features; 1362306a36Sopenharmony_ciextern bool rfi_flush; 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* These are bit flags */ 1662306a36Sopenharmony_cienum stf_barrier_type { 1762306a36Sopenharmony_ci STF_BARRIER_NONE = 0x1, 1862306a36Sopenharmony_ci STF_BARRIER_FALLBACK = 0x2, 1962306a36Sopenharmony_ci STF_BARRIER_EIEIO = 0x4, 2062306a36Sopenharmony_ci STF_BARRIER_SYNC_ORI = 0x8, 2162306a36Sopenharmony_ci}; 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_civoid setup_stf_barrier(void); 2462306a36Sopenharmony_civoid do_stf_barrier_fixups(enum stf_barrier_type types); 2562306a36Sopenharmony_civoid setup_count_cache_flush(void); 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_cistatic inline void security_ftr_set(u64 feature) 2862306a36Sopenharmony_ci{ 2962306a36Sopenharmony_ci powerpc_security_features |= feature; 3062306a36Sopenharmony_ci} 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cistatic inline void security_ftr_clear(u64 feature) 3362306a36Sopenharmony_ci{ 3462306a36Sopenharmony_ci powerpc_security_features &= ~feature; 3562306a36Sopenharmony_ci} 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_cistatic inline bool security_ftr_enabled(u64 feature) 3862306a36Sopenharmony_ci{ 3962306a36Sopenharmony_ci return !!(powerpc_security_features & feature); 4062306a36Sopenharmony_ci} 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 4362306a36Sopenharmony_cienum stf_barrier_type stf_barrier_type_get(void); 4462306a36Sopenharmony_ci#else 4562306a36Sopenharmony_cistatic inline enum stf_barrier_type stf_barrier_type_get(void) { return STF_BARRIER_NONE; } 4662306a36Sopenharmony_ci#endif 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci// Features indicating support for Spectre/Meltdown mitigations 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci// The L1-D cache can be flushed with ori r30,r30,0 5162306a36Sopenharmony_ci#define SEC_FTR_L1D_FLUSH_ORI30 0x0000000000000001ull 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci// The L1-D cache can be flushed with mtspr 882,r0 (aka SPRN_TRIG2) 5462306a36Sopenharmony_ci#define SEC_FTR_L1D_FLUSH_TRIG2 0x0000000000000002ull 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci// ori r31,r31,0 acts as a speculation barrier 5762306a36Sopenharmony_ci#define SEC_FTR_SPEC_BAR_ORI31 0x0000000000000004ull 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci// Speculation past bctr is disabled 6062306a36Sopenharmony_ci#define SEC_FTR_BCCTRL_SERIALISED 0x0000000000000008ull 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci// Entries in L1-D are private to a SMT thread 6362306a36Sopenharmony_ci#define SEC_FTR_L1D_THREAD_PRIV 0x0000000000000010ull 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci// Indirect branch prediction cache disabled 6662306a36Sopenharmony_ci#define SEC_FTR_COUNT_CACHE_DISABLED 0x0000000000000020ull 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci// bcctr 2,0,0 triggers a hardware assisted count cache flush 6962306a36Sopenharmony_ci#define SEC_FTR_BCCTR_FLUSH_ASSIST 0x0000000000000800ull 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci// bcctr 2,0,0 triggers a hardware assisted link stack flush 7262306a36Sopenharmony_ci#define SEC_FTR_BCCTR_LINK_FLUSH_ASSIST 0x0000000000002000ull 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci// Features indicating need for Spectre/Meltdown mitigations 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci// The L1-D cache should be flushed on MSR[HV] 1->0 transition (hypervisor to guest) 7762306a36Sopenharmony_ci#define SEC_FTR_L1D_FLUSH_HV 0x0000000000000040ull 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci// The L1-D cache should be flushed on MSR[PR] 0->1 transition (kernel to userspace) 8062306a36Sopenharmony_ci#define SEC_FTR_L1D_FLUSH_PR 0x0000000000000080ull 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci// A speculation barrier should be used for bounds checks (Spectre variant 1) 8362306a36Sopenharmony_ci#define SEC_FTR_BNDS_CHK_SPEC_BAR 0x0000000000000100ull 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci// Firmware configuration indicates user favours security over performance 8662306a36Sopenharmony_ci#define SEC_FTR_FAVOUR_SECURITY 0x0000000000000200ull 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci// Software required to flush count cache on context switch 8962306a36Sopenharmony_ci#define SEC_FTR_FLUSH_COUNT_CACHE 0x0000000000000400ull 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci// Software required to flush link stack on context switch 9262306a36Sopenharmony_ci#define SEC_FTR_FLUSH_LINK_STACK 0x0000000000001000ull 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci// The L1-D cache should be flushed when entering the kernel 9562306a36Sopenharmony_ci#define SEC_FTR_L1D_FLUSH_ENTRY 0x0000000000004000ull 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci// The L1-D cache should be flushed after user accesses from the kernel 9862306a36Sopenharmony_ci#define SEC_FTR_L1D_FLUSH_UACCESS 0x0000000000008000ull 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci// The STF flush should be executed on privilege state switch 10162306a36Sopenharmony_ci#define SEC_FTR_STF_BARRIER 0x0000000000010000ull 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci// Features enabled by default 10462306a36Sopenharmony_ci#define SEC_FTR_DEFAULT \ 10562306a36Sopenharmony_ci (SEC_FTR_L1D_FLUSH_HV | \ 10662306a36Sopenharmony_ci SEC_FTR_L1D_FLUSH_PR | \ 10762306a36Sopenharmony_ci SEC_FTR_BNDS_CHK_SPEC_BAR | \ 10862306a36Sopenharmony_ci SEC_FTR_L1D_FLUSH_ENTRY | \ 10962306a36Sopenharmony_ci SEC_FTR_L1D_FLUSH_UACCESS | \ 11062306a36Sopenharmony_ci SEC_FTR_STF_BARRIER | \ 11162306a36Sopenharmony_ci SEC_FTR_FAVOUR_SECURITY) 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci#endif /* _ASM_POWERPC_SECURITY_FEATURES_H */ 114