V4.4 backport of arm64 Spectre patches
Subsystems (9)
cover V4.4 backport of arm64 Spectre patches
Hello,
Here is an attempt to backport arm64 spectre patches to v4.4 stable tree.
I have started this backport with Mark Rutland's backport of Spectre to 4.9 [1] and tried applying the upstream version of them over 4.4 and resolved conflicts by checking how they have been resolved in 4.9.
I had to pick few extra upstream patches to avoid unnecessary conflicts (upstream commit ids mentioned):
a842789837c0 arm64: remove duplicate macro __KERNEL__ check 64f8ebaf115b mm/kasan: add API to check memory regions bffe1baff5d5 arm64: kasan: instrument user memory access API 92406f0cc9e3 arm64: cpufeature: Add scope for capability check 9eb8a2cdf65c arm64: cputype info for Broadcom Vulcan 0d90718871fe arm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs 98dd64f34f47 ARM: 8478/2: arm/arm64: add arm-smccc
I had to drop few patches as well as they weren't getting applied properly due to missing files/features (upstream commit id mentioned):
93f339ef4175 arm64: cpufeature: __this_cpu_has_cap() shouldn't stop early 3c31fa5a06b4 arm64: Run enable method for errata work arounds on late CPUs 6840bdd73d07 arm64: KVM: Use per-CPU vector when BP hardening is enabled 90348689d500 arm64: KVM: Make PSCI_VERSION a fast path
Since v4.4 doesn't contain arch/arm/kvm/hyp/switch.c file, changes for it are dropped from some of the patches. The commit log of specific patches are updated with this information.
Also for commit id (from 4.9 stable):
c24c205d2528 arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP hardening support
I have dropped arch/arm64/crypto/sha256-core.S and sha512-core.S files as they weren't part of the upstream commit. Not sure why it was included by Mark as the commit log doesn't provide any reasoning for it.
The patches in this series are pushed here [2].
This is only build/boot tested by me as I don't have access to the required test-suite which can verify spectre mitigations.
@Julien: Can you please help reviewing / testing them ? Thanks.
--
viresh
[1] https://patches.linaro.org/cover/133195/ with top commit in 4.9 stable tree:
a3b292fe0560 arm64: futex: Mask __user pointers prior to dereference
[2] https://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.git stable/v4.4.y/spectre
Andrey Ryabinin (1):
mm/kasan: add API to check memory regions
Catalin Marinas (1):
arm64: Factor out TTBR0_EL1 post-update workaround into a specific asm
macro
Jayachandran C (3):
arm64: cputype info for Broadcom Vulcan
arm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs
arm64: Branch predictor hardening for Cavium ThunderX2
Jens Wiklander (1):
ARM: 8478/2: arm/arm64: add arm-smccc
Laura Abbott (1):
mm: Introduce lm_alias
Marc Zyngier (14):
arm64: Move post_ttbr_update_workaround to C code
arm64: Move BP hardening to check_and_switch_context
arm64: cpu_errata: Allow an erratum to be match for all revisions of a
core
arm64: KVM: Increment PC after handling an SMC trap arm/arm64: KVM: Add PSCI_VERSION helper
arm/arm64: KVM: Add smccc accessors to PSCI code arm/arm64: KVM: Implement PSCI 1.0 support
arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling firmware/psci: Expose PSCI conduit
firmware/psci: Expose SMCCC version through psci_ops arm/arm64: smccc: Make function identifiers an unsigned quantity arm/arm64: smccc: Implement SMCCC v1.1 inline primitive
arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP hardening support
arm64: Kill PSCI_GET_VERSION as a variant-2 workaround
Mark Rutland (4):
arm/arm64: KVM: Consolidate the PSCI include files arm/arm64: KVM: Advertise SMCCC v1.1
arm/arm64: KVM: Turn kvm_psci_version into a static inline
arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support
Robin Murphy (3):
arm64: Implement array_index_mask_nospec()
arm64: Make USER_DS an inclusive limit
arm64: Use pointer masking to limit uaccess speculation
Suzuki K Poulose (1):
arm64: cpufeature: Add scope for capability check
Will Deacon (13):
arm64: barrier: Add CSDB macros to control data-value prediction
arm64: entry: Ensure branch through syscall table is bounded under
speculation
arm64: uaccess: Prevent speculative use of the current addr_limit
arm64: uaccess: Don't bother eliding access_ok checks in __{get,
put}_user
arm64: uaccess: Mask __user pointers for __arch_{clear, copy_*}_user
arm64: cpufeature: Pass capability structure to ->enable callback drivers/firmware: Expose psci_get_version through psci_ops structure
arm64: Add skeleton to harden the branch predictor against aliasing
attacks
arm64: entry: Apply BP hardening for high-priority synchronous
exceptions
arm64: entry: Apply BP hardening for suspicious interrupts from EL0
arm64: cputype: Add missing MIDR values for Cortex-A72 and Cortex-A75
arm64: Implement branch predictor hardening for affected Cortex-A CPUs
arm64: futex: Mask __user pointers prior to dereference
Yang Shi (1):
arm64: kasan: instrument user memory access API
Yury Norov (1):
arm64: move TASK_* definitions to <asm/processor.h>
zijun_hu (1):
arm64: remove duplicate macro __KERNEL__ check
MAINTAINERS | 14 ++ arch/arm/include/asm/kvm_host.h | 6 + arch/arm/include/asm/kvm_psci.h | 27 --- arch/arm/kvm/arm.c | 2 +- arch/arm/kvm/handle_exit.c | 4 +- arch/arm/kvm/psci.c | 143 ++++++++++++--- arch/arm64/Kconfig | 17 ++ arch/arm64/include/asm/assembler.h | 18 ++ arch/arm64/include/asm/barrier.h | 23 +++ arch/arm64/include/asm/cpufeature.h | 12 +- arch/arm64/include/asm/cputype.h | 12 ++ arch/arm64/include/asm/futex.h | 9 +- arch/arm64/include/asm/kvm_host.h | 5 + arch/arm64/include/asm/kvm_psci.h | 27 --- arch/arm64/include/asm/memory.h | 15 -- arch/arm64/include/asm/mmu.h | 39 ++++ arch/arm64/include/asm/processor.h | 26 ++- arch/arm64/include/asm/sysreg.h | 2 + arch/arm64/include/asm/uaccess.h | 175 ++++++++++++------ arch/arm64/kernel/Makefile | 5 + arch/arm64/kernel/arm64ksyms.c | 8 +- arch/arm64/kernel/bpi.S | 75 ++++++++ arch/arm64/kernel/cpu_errata.c | 185 ++++++++++++++++++- arch/arm64/kernel/cpufeature.c | 112 ++++++------ arch/arm64/kernel/entry.S | 26 ++- arch/arm64/kvm/handle_exit.c | 16 +- arch/arm64/kvm/hyp.S | 20 ++- arch/arm64/lib/clear_user.S | 6 +- arch/arm64/lib/copy_from_user.S | 4 +- arch/arm64/lib/copy_in_user.S | 4 +- arch/arm64/lib/copy_to_user.S | 4 +- arch/arm64/mm/context.c | 12 ++ arch/arm64/mm/fault.c | 31 ++++ arch/arm64/mm/proc.S | 12 +- drivers/firmware/Kconfig | 3 + drivers/firmware/psci.c | 58 +++++- include/kvm/arm_psci.h | 51 ++++++ include/linux/arm-smccc.h | 267 ++++++++++++++++++++++++++++ include/linux/kasan-checks.h | 12 ++ include/linux/mm.h | 4 + include/linux/psci.h | 14 ++ include/uapi/linux/psci.h | 3 + mm/kasan/kasan.c | 12 ++ 43 files changed, 1270 insertions(+), 250 deletions(-) delete mode 100644 arch/arm/include/asm/kvm_psci.h delete mode 100644 arch/arm64/include/asm/kvm_psci.h create mode 100644 arch/arm64/kernel/bpi.S create mode 100644 include/kvm/arm_psci.h create mode 100644 include/linux/arm-smccc.h create mode 100644 include/linux/kasan-checks.h
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 1/45 arm64: barrier: Add CSDB macros to control data-value prediction
From: Will Deacon <[email protected]>
commit 669474e772b952b14f4de4845a1558fd4c0414a4 upstream.
For CPUs capable of data value prediction, CSDB waits for any outstanding predictions to architecturally resolve before allowing speculative execution to continue. Provide macros to expose it to the arch code.
--- arch/arm64/include/asm/assembler.h | 7 +++++++ arch/arm64/include/asm/barrier.h | 2 ++ 2 files changed, 9 insertions(+)
arch/arm64/include/asm/assembler.h +7 -0
@@ -95,6 +95,13 @@ dmb \opt .endm +/* + * Value prediction barrier + */ + .macro csdb + hint #20 + .endm + #define USER(l, x...) \ 9999: x; \ .section __ex_table,"a"; \
arch/arm64/include/asm/barrier.h +2 -0
@@ -28,6 +28,8 @@#define dmb (opt) asm volatile("dmb " #opt : : : "memory")#define dsb (opt) asm volatile("dsb " #opt : : : "memory") +#define csdb () asm volatile("hint #20" : : : "memory") +#define mb () dsb(sy)#define rmb () dsb(ld)#define wmb () dsb(st)
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 2/45 arm64: Implement array_index_mask_nospec()
In reply to Viresh KumarFrom: Robin Murphy <[email protected]>
commit 022620eed3d0bc4bf2027326f599f5ad71c2ea3f upstream.
Provide an optimised, assembly implementation of array_index_mask_nospec() for arm64 so that the compiler is not in a position to transform the code in ways which affect its ability to inhibit speculation (e.g. by introducing conditional branches).
This is similar to the sequence used by x86, modulo architectural differences in the carry/borrow flags.
--- arch/arm64/include/asm/barrier.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/arm64/include/asm/barrier.h +21 -0
@@ -37,6 +37,27 @@#define dma_rmb () dmb(oshld)#define dma_wmb () dmb(oshst) +/* +* Generate a mask for array_index__nospec() that is ~0UL when 0 <= idx < sz +* and 0 otherwise. +*/ +#define array_index_mask_nospec array_index_mask_nospec +static inline unsigned long array_index_mask_nospec (unsigned long idx, +unsigned long sz) +{ +unsigned long mask; + + asmvolatile ( +" cmp %1, %2\n" +" sbc %0, xzr, xzr\n" + :"=r" (mask) + :"r" (idx),"Ir" (sz) + :"cc" ); + +csdb (); +return mask; +} +#define smp_mb () dmb(ish)#define smp_rmb () dmb(ishld)#define smp_wmb () dmb(ishst)
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 3/45 arm64: remove duplicate macro __KERNEL__ check
In reply to Viresh KumarFrom: zijun_hu <[email protected]>
commit a842789837c0e3734357c6b4c54d39d60a1d24b1 upstream.
remove duplicate macro __KERNEL__ check
--- arch/arm64/include/asm/processor.h | 2 -- 1 file changed, 2 deletions(-)
arch/arm64/include/asm/processor.h +0 -2
@@ -35,7 +35,6 @@#include <asm/ptrace.h> #include <asm/types.h> -#ifdef __KERNEL__#define STACK_TOP_MAX TASK_SIZE_64#ifdef CONFIG_COMPAT #define AARCH32_VECTORS_BASE 0xffff0000
@@ -47,7 +46,6 @@extern phys_addr_t arm64_dma_phys_limit;#define ARCH_LOW_ADDRESS_LIMIT (arm64_dma_phys_limit - 1) -#endif /* __KERNEL__ */ struct debug_info {/* Have we suspended stepping by a debugger? */
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 4/45 arm64: move TASK_* definitions to <asm/processor.h>
In reply to Viresh KumarFrom: Yury Norov <[email protected]>
commit eef94a3d09aab437c8c254de942d8b1aa76455e2 upstream.
ILP32 series [1] introduces the dependency on <asm/is_compat.h> for TASK_SIZE macro. Which in turn requires <asm/thread_info.h>, and <asm/thread_info.h> include <asm/memory.h>, giving a circular dependency, because TASK_SIZE is currently located in <asm/memory.h>.
In other architectures, TASK_SIZE is defined in <asm/processor.h>, and moving TASK_SIZE there fixes the problem.
Discussion: https://patchwork.kernel.org/patch/9929107/
[1] https://github.com/norov/linux/tree/ilp32-next
--- arch/arm64/include/asm/memory.h | 15 --------------- arch/arm64/include/asm/processor.h | 21 +++++++++++++++++++++ arch/arm64/kernel/entry.S | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-)
arch/arm64/include/asm/memory.h +0 -15
@@ -43,8 +43,6 @@* (VA_BITS - 1)) * VA_BITS - the maximum number of bits for virtual addresses. * VA_START - the first kernel virtual address. -* TASK_SIZE - the maximum size of a user space task. -* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. * The module space lives between the addresses given by TASK_SIZE * and PAGE_OFFSET - it must be within 128MB of the kernel text. */
@@ -58,19 +56,6 @@#define PCI_IO_END (MODULES_VADDR - SZ_2M)#define PCI_IO_START (PCI_IO_END - PCI_IO_SIZE)#define FIXADDR_TOP (PCI_IO_START - SZ_2M) -#define TASK_SIZE_64 (UL(1) << VA_BITS) - -#ifdef CONFIG_COMPAT -#define TASK_SIZE_32 UL(0x100000000) -#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ - TASK_SIZE_32 : TASK_SIZE_64) -#define TASK_SIZE_OF (tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ - TASK_SIZE_32 : TASK_SIZE_64) -#else -#define TASK_SIZE TASK_SIZE_64 -#endif /* CONFIG_COMPAT */ - -#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4))/* * Physical vs virtual RAM address space conversion. These are
arch/arm64/include/asm/processor.h +21 -0
@@ -19,6 +19,10 @@#ifndef __ASM_PROCESSOR_H#define __ASM_PROCESSOR_H +#define TASK_SIZE_64 (UL(1) << VA_BITS) + +#ifndef __ASSEMBLY__ +/* * Default implementation of macro that returns current * instruction pointer ("program counter").
@@ -35,6 +39,22 @@#include <asm/ptrace.h> #include <asm/types.h> +/* +* TASK_SIZE - the maximum size of a user space task. +* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. +*/ +#ifdef CONFIG_COMPAT +#define TASK_SIZE_32 UL(0x100000000) +#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ + TASK_SIZE_32 : TASK_SIZE_64) +#define TASK_SIZE_OF (tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ + TASK_SIZE_32 : TASK_SIZE_64) +#else +#define TASK_SIZE TASK_SIZE_64 +#endif /* CONFIG_COMPAT */ + +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4)) +#define STACK_TOP_MAX TASK_SIZE_64#ifdef CONFIG_COMPAT #define AARCH32_VECTORS_BASE 0xffff0000
@@ -186,4 +206,5 @@ static inline void spin_lock_prefetch(const void *x)int cpu_enable_pan (void *__unused); +#endif /* __ASSEMBLY__ */ #endif /* __ASM_PROCESSOR_H */
arch/arm64/kernel/entry.S +1 -1
@@ -27,7 +27,7 @@ #include <asm/cpufeature.h> #include <asm/errno.h> #include <asm/esr.h> -#include <asm/memory.h> +#include <asm/processor.h> #include <asm/thread_info.h> #include <asm/asm-uaccess.h> #include <asm/unistd.h>
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 5/45 arm64: Make USER_DS an inclusive limit
In reply to Viresh KumarFrom: Robin Murphy <[email protected]>
commit 51369e398d0d33e8f524314e672b07e8cf870e79 upstream.
Currently, USER_DS represents an exclusive limit while KERNEL_DS is inclusive. In order to do some clever trickery for speculation-safe masking, we need them both to behave equivalently - there aren't enough bits to make KERNEL_DS exclusive, so we have precisely one option. This also happens to correct a longstanding false negative for a range ending on the very top byte of kernel memory.
Mark Rutland points out that we've actually got the semantics of addresses vs. segments muddled up in most of the places we need to amend, so shuffle the {USER,KERNEL}_DS definitions around such that we can correct those properly instead of just pasting "-1"s everywhere.
--- arch/arm64/include/asm/processor.h | 3 ++ arch/arm64/include/asm/uaccess.h | 45 +++++++++++++++++------------- arch/arm64/kernel/entry.S | 4 +-- 3 files changed, 31 insertions(+), 21 deletions(-)
arch/arm64/include/asm/processor.h +3 -0
@@ -21,6 +21,9 @@#define TASK_SIZE_64 (UL(1) << VA_BITS) +#define KERNEL_DS UL(-1) +#define USER_DS (TASK_SIZE_64 - 1) +#ifndef __ASSEMBLY__/*
arch/arm64/include/asm/uaccess.h +26 -19
65 lines not on this page · raw message
arch/arm64/kernel/entry.S +2 -2
@@ -96,10 +96,10 @@ .else add x21, sp, #S_FRAME_SIZE get_thread_info tsk - /* Save the task's original addr_limit and set USER_DS (TASK_SIZE_64) */ + /* Save the task's original addr_limit and set USER_DS */ ldr x20, [tsk, #TI_ADDR_LIMIT] str x20, [sp, #S_ORIG_ADDR_LIMIT] - mov x20, #TASK_SIZE_64 + mov x20, #USER_DS str x20, [tsk, #TI_ADDR_LIMIT] .endif /* \el == 0 */ mrs x22, elr_el1
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 6/45 arm64: Use pointer masking to limit uaccess speculation
In reply to Viresh KumarFrom: Robin Murphy <[email protected]>
commit 4d8efc2d5ee4c9ccfeb29ee8afd47a8660d0c0ce upstream.
Similarly to x86, mitigate speculation past an access_ok() check by masking the pointer against the address limit before use.
Even if we don't expect speculative writes per se, it is plausible that a CPU may still speculate at least as far as fetching a cache line for writing, hence we also harden put_user() and clear_user() for peace of mind.
--- arch/arm64/include/asm/uaccess.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
arch/arm64/include/asm/uaccess.h +23 -3
@@ -121,6 +121,26 @@ static inline unsigned long __range_ok(unsigned long addr, unsigned long size)#define access_ok (type, addr, size) __range_ok((unsigned long)(addr), size)#define user_addr_max get_fs +/* +* Sanitise a uaccess pointer such that it becomes NULL if above the +* current addr_limit. +*/ +#define uaccess_mask_ptr (ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) +static inline void __user *__uaccess_mask_ptr (const void __user *ptr) +{ +void __user *safe_ptr; + + asmvolatile ( +" bics xzr, %1, %2\n" +" csel %0, %1, xzr, eq\n" + :"=&r" (safe_ptr) + :"r" (ptr),"r" (current_thread_info ()->addr_limit) + :"cc" ); + +csdb (); +return safe_ptr; +} +/* * The "__xxx" versions of the user access functions do not verify the address * space - it must have been done previously with a separate "access_ok()"
@@ -193,7 +213,7 @@ do { \ __typeof__(*(ptr)) __user *__p = (ptr); \might_fault (); \access_ok (VERIFY_READ , __p,sizeof (*__p)) ? \ -__get_user ((x), __p) : \ + __p =uaccess_mask_ptr (__p),__get_user ((x), __p) : \ ((x) =0 , -EFAULT ); \ })
@@ -259,7 +279,7 @@ do { \ __typeof__(*(ptr)) __user *__p = (ptr); \might_fault (); \access_ok (VERIFY_WRITE , __p,sizeof (*__p)) ? \ -__put_user ((x), __p) : \ + __p =uaccess_mask_ptr (__p),__put_user ((x), __p) : \ -EFAULT ; \ })
@@ -297,7 +317,7 @@ static inline unsigned long __must_check copy_in_user(void __user *to, const voistatic inline unsigned long __must_check clear_user (void __user *to,unsigned long n) {if (access_ok (VERIFY_WRITE , to, n)) - n =__clear_user (to, n); + n =__clear_user (__uaccess_mask_ptr (to), n);return n; }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 7/45 arm64: entry: Ensure branch through syscall table is bounded under speculation
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit 6314d90e64936c584f300a52ef173603fb2461b5 upstream.
In a similar manner to array_index_mask_nospec, this patch introduces an assembly macro (mask_nospec64) which can be used to bound a value under speculation. This macro is then used to ensure that the indirect branch through the syscall table is bounded under speculation, with out-of-range addresses speculating as calls to sys_io_setup (0).
--- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 1 + 2 files changed, 12 insertions(+)
arch/arm64/include/asm/assembler.h +11 -0
@@ -102,6 +102,17 @@ hint #20 .endm +/* +* Sanitise a 64-bit bounded index wrt speculation, returning zero if out +* of bounds. +*/ + .macro mask_nospec64, idx, limit, tmp + sub \tmp, \idx, \limit + bic \tmp, \tmp, \idx + and \idx, \idx, \tmp, asr #63 + csdb + .endm + #define USER(l, x...) \ 9999: x; \ .section __ex_table,"a"; \
arch/arm64/kernel/entry.S +1 -0
@@ -697,6 +697,7 @@ el0_svc_naked: // compat entry point b.ne __sys_trace cmp scno, sc_nr // check upper syscall limit b.hs ni_sys + mask_nospec64 scno, sc_nr, x19 // enforce bounds for syscall number ldr x16, [stbl, scno, lsl #3] // address in the syscall table blr x16 // call sys_* routine b ret_fast_syscall
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 8/45 arm64: uaccess: Prevent speculative use of the current addr_limit
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit c2f0ad4fc089cff81cef6a13d04b399980ecbfcc upstream.
A mispredicted conditional call to set_fs could result in the wrong addr_limit being forwarded under speculation to a subsequent access_ok check, potentially forming part of a spectre-v1 attack using uaccess routines.
This patch prevents this forwarding from taking place, but putting heavy barriers in set_fs after writing the addr_limit.
--- arch/arm64/include/asm/uaccess.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/include/asm/uaccess.h +7 -0
@@ -62,6 +62,13 @@ extern int fixup_exception(struct pt_regs *regs);static inline void set_fs (mm_segment_t fs) {current_thread_info ()->addr_limit = fs; + +/* +* Prevent a mispredicted conditional call to set_fs from forwarding +* the wrong address limit to access_ok under speculation. +*/ +dsb (nsh); +isb (); }#define segment_eq (a, b) ((a) == (b))
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 9/45 arm64: uaccess: Don't bother eliding access_ok checks in __{get, put}_user
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit 84624087dd7e3b482b7b11c170ebc1f329b3a218 upstream.
access_ok isn't an expensive operation once the addr_limit for the current thread has been loaded into the cache. Given that the initial access_ok check preceding a sequence of __{get,put}_user operations will take the brunt of the miss, we can make the __* variants identical to the full-fat versions, which brings with it the benefits of address masking.
The likely cost in these sequences will be from toggling PAN/UAO, which we can address later by implementing the *_unsafe versions.
--- arch/arm64/include/asm/uaccess.h | 62 ++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 26 deletions(-)
arch/arm64/include/asm/uaccess.h +36 -26
@@ -200,30 +200,35 @@ do { \ CONFIG_ARM64_PAN)); \ } while (0) -#define __get_user (x, ptr) \ +#define __get_user_check (x, ptr, err) \ ({ \ - int __gu_err = 0; \ - __get_user_err((x), (ptr), __gu_err); \ - __gu_err; \ + __typeof__(*(ptr)) __user *__p = (ptr); \ + might_fault(); \ + if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \ + __p = uaccess_mask_ptr(__p); \ + __get_user_err((x), __p, (err)); \ + } else { \ + (x) = 0; (err) = -EFAULT; \ + } \ })#define __get_user_error (x, ptr, err) \ ({ \ - __get_user_err((x), (ptr), (err)); \ + __get_user_check((x), (ptr), (err)); \ (void)0; \ }) -#define __get_user_unaligned __get_user - -#define get_user (x, ptr) \ +#define __get_user (x, ptr) \ ({ \ - __typeof__(*(ptr)) __user *__p = (ptr); \ - might_fault(); \ - access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \ - __p = uaccess_mask_ptr(__p), __get_user((x), __p) : \ - ((x) = 0, -EFAULT); \ + int __gu_err = 0; \ + __get_user_check((x), (ptr), __gu_err); \ + __gu_err; \ }) +#define __get_user_unaligned __get_user + +#define get_user __get_user +#define __put_user_asm (instr, reg, x, addr, err) \ asm volatile( \ "1: " instr " " reg "1, [%2]\n" \
@@ -266,30 +271,35 @@ do { \ CONFIG_ARM64_PAN)); \ } while (0) -#define __put_user (x, ptr) \ +#define __put_user_check (x, ptr, err) \ ({ \ - int __pu_err = 0; \ - __put_user_err((x), (ptr), __pu_err); \ - __pu_err; \ + __typeof__(*(ptr)) __user *__p = (ptr); \ + might_fault(); \ + if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \ + __p = uaccess_mask_ptr(__p); \ + __put_user_err((x), __p, (err)); \ + } else { \ + (err) = -EFAULT; \ + } \ })#define __put_user_error (x, ptr, err) \ ({ \ - __put_user_err((x), (ptr), (err)); \ + __put_user_check((x), (ptr), (err)); \ (void)0; \ }) -#define __put_user_unaligned __put_user - -#define put_user (x, ptr) \ +#define __put_user (x, ptr) \ ({ \ - __typeof__(*(ptr)) __user *__p = (ptr); \ - might_fault(); \ - access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \ - __p = uaccess_mask_ptr(__p), __put_user((x), __p) : \ - -EFAULT; \ + int __pu_err = 0; \ + __put_user_check((x), (ptr), __pu_err); \ + __pu_err; \ }) +#define __put_user_unaligned __put_user + +#define put_user __put_user +extern unsigned long __must_check __copy_from_user (void *to,const void __user *from,unsigned long n);extern unsigned long __must_check __copy_to_user (void __user *to,const void *from,unsigned long n);extern unsigned long __must_check __copy_in_user (void __user *to,const void __user *from,unsigned long n);
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 10/45 mm/kasan: add API to check memory regions
In reply to Viresh KumarFrom: Andrey Ryabinin <[email protected]>
commit 64f8ebaf115bcddc4aaa902f981c57ba6506bc42 upstream.
Memory access coded in an assembly won't be seen by KASAN as a compiler can instrument only C code. Add kasan_check_[read,write]() API which is going to be used to check a certain memory range.
--- MAINTAINERS | 14 ++++++++++++++ include/linux/kasan-checks.h | 12 ++++++++++++ mm/kasan/kasan.c | 12 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 include/linux/kasan-checks.h
MAINTAINERS +14 -0
@@ -5982,6 +5982,20 @@ S: Maintained F: Documentation/hwmon/k8temp F: drivers/hwmon/k8temp.c +KASAN +M: Andrey Ryabinin <[email protected]> +R: Alexander Potapenko <[email protected]> +R: Dmitry Vyukov <[email protected]> +L: [email protected] +S: Maintained +F: arch/*/include/asm/kasan.h +F: arch/*/mm/kasan_init* +F: Documentation/kasan.txt +F: include/linux/kasan*.h +F: lib/test_kasan.c +F: mm/kasan/ +F: scripts/Makefile.kasan + KCONFIG M: "Yann E. MORIN" <[email protected]> L: [email protected]
include/linux/kasan-checks.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LINUX_KASAN_CHECKS_H +#define _LINUX_KASAN_CHECKS_H + +#ifdef CONFIG_KASAN +void kasan_check_read (const void *p,unsigned int size); +void kasan_check_write (const void *p,unsigned int size); +#else +static inline void kasan_check_read (const void *p,unsigned int size) { } +static inline void kasan_check_write (const void *p,unsigned int size) { } +#endif + +#endif
mm/kasan/kasan.c +12 -0
@@ -274,6 +274,18 @@ static __always_inline void check_memory_region(unsigned long addr,void __asan_loadN (unsigned long addr,size_t size);void __asan_storeN (unsigned long addr,size_t size); +void kasan_check_read (const void *p,unsigned int size) +{ +check_memory_region ((unsigned long )p, size, false, _RET_IP_); +} +EXPORT_SYMBOL (kasan_check_read); + +void kasan_check_write (const void *p,unsigned int size) +{ +check_memory_region ((unsigned long )p, size, true, _RET_IP_); +} +EXPORT_SYMBOL (kasan_check_write); +#undef memsetvoid *memset (void *addr,int c,size_t len) {
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Re: [PATCH v4.4 10/45] mm/kasan: add API to check memory regions
Hi Viresh,
Quoted 74 lines · Viresh Kumar
From: Andrey Ryabinin <[email protected]>
commit
64f8ebaf115bcddc4aaa902f981c57ba6506bc42upstream.Memory access coded in an assembly won't be seen by KASAN as a compiler can instrument only C code. Add kasan_check_[read,write]() API which is going to be used to check a certain memory range.
Signed-off-by Andrey Ryabinin <[email protected]>Cc Dmitry Vyukov <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>[ v4.4: Fixed MAINTAINERS conflict and added whole kasan entry ]Signed-off-by Viresh Kumar <[email protected]>--- MAINTAINERS | 14 ++++++++++++++ include/linux/kasan-checks.h | 12 ++++++++++++ mm/kasan/kasan.c | 12 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 include/linux/kasan-checks.hMAINTAINERS +14
-0@@ -5982,6 +5982,20 @@ S: Maintained F: Documentation/hwmon/k8temp F: drivers/hwmon/k8temp.c +KASAN +M: Andrey Ryabinin <[email protected]> +R: Alexander Potapenko <[email protected]> +R: Dmitry Vyukov <[email protected]> +L: [email protected] +S: Maintained +F: arch/*/include/asm/kasan.h +F: arch/*/mm/kasan_init* +F: Documentation/kasan.txt +F: include/linux/kasan*.h +F: lib/test_kasan.c +F: mm/kasan/ +F: scripts/Makefile.kasan + KCONFIG M: "Yann E. MORIN" <[email protected]> L: [email protected]include/linux/kasan-checks.h new file +12
-0@@ -0,0 +1,12 @@ +#ifndef _LINUX_KASAN_CHECKS_H +#define _LINUX_KASAN_CHECKS_H + +#ifdef CONFIG_KASAN +void kasan_check_read (const void *p,unsigned int size); +void kasan_check_write (const void *p,unsigned int size); +#else +static inline void kasan_check_read (const void *p,unsigned int size) { } +static inline void kasan_check_write (const void *p,unsigned int size) { } +#endif + +#endif mm/kasan/kasan.c +0
-0
mm/kasan/kasan.c static __always_inline void check_memory_region(unsigned long addr, · line 279
Quoted 6 lines
mm/kasan/kasan.c +3
-0@@ -274,6 +274,18 @@ static __always_inline void check_memory_region(unsigned long addr,void __asan_loadN (unsigned long addr,size_t size);void __asan_storeN (unsigned long addr,size_t size); +void kasan_check_read (const void *p,unsigned int size) +{ +check_memory_region ((unsigned long )p, size, false, _RET_IP_);
I know you have updated the code since then but the issue seems to be also present on your updated branch.
This patch breaks the build when enabling CONFIG_KASAN because in 4.4 check_memory_region() only takes 3 arguments.
mm/kasan/kasan.c static __always_inline void check_memory_region(unsigned long addr, · line 291
Quoted 13 lines
mm/kasan/kasan.c +9
-0+} +EXPORT_SYMBOL (kasan_check_read); + +void kasan_check_write (const void *p,unsigned int size) +{ +check_memory_region ((unsigned long )p, size, true, _RET_IP_); +} +EXPORT_SYMBOL (kasan_check_write); +#undef memsetvoid *memset (void *addr,int c,size_t len) {
Cheers,
Signature · 1 line
Julien Thierry
Re: [PATCH v4.4 10/45] mm/kasan: add API to check memory regions
Quoted 5 lines · Julien Thierry
I know you have updated the code since then but the issue seems to be also present on your updated branch.
This patch breaks the build when enabling
CONFIG_KASANbecause in 4.4check_memory_region()only takes 3 arguments.
Fixed and pushed again. Thanks.
I have also tried enabling all the other ifdefs used in these patches to make sure it doesn't work after enabling them. Looks good now.
Signature · 1 line
viresh
PATCH 11/45 arm64: kasan: instrument user memory access API
In reply to Viresh KumarFrom: Yang Shi <[email protected]>
commit bffe1baff5d57521b0c41b6997c41ff1993e9818 upstream.
The upstream commit 1771c6e1a567ea0ba2cccc0a4ffe68a1419fd8ef ("x86/kasan: instrument user memory access API") added KASAN instrument to x86 user memory access API, so added such instrument to ARM64 too.
Define __copy_to/from_user in C in order to add kasan_check_read/write call, rename assembly implementation to __arch_copy_to/from_user.
Tested by test_kasan module.
--- arch/arm64/include/asm/uaccess.h | 25 +++++++++++++++++++++---- arch/arm64/kernel/arm64ksyms.c | 4 ++-- arch/arm64/lib/copy_from_user.S | 4 ++-- arch/arm64/lib/copy_to_user.S | 4 ++-- 4 files changed, 27 insertions(+), 10 deletions(-)
arch/arm64/include/asm/uaccess.h +21 -4
@@ -22,6 +22,7 @@* User space memory access functions */ #include <linux/bitops.h> +#include <linux/kasan-checks.h> #include <linux/string.h> #include <linux/thread_info.h>
@@ -300,15 +301,29 @@ do { \#define put_user __put_user -extern unsigned long __must_check __copy_from_user (void *to,const void __user *from,unsigned long n); -extern unsigned long __must_check __copy_to_user (void __user *to,const void *from,unsigned long n); +extern unsigned long __must_check __arch_copy_from_user (void *to,const void __user *from,unsigned long n); +extern unsigned long __must_check __arch_copy_to_user (void __user *to,const void *from,unsigned long n);extern unsigned long __must_check __copy_in_user (void __user *to,const void __user *from,unsigned long n);extern unsigned long __must_check __clear_user (void __user *addr,unsigned long n); +static inline unsigned long __must_check __copy_from_user (void *to,const void __user *from,unsigned long n) +{ +kasan_check_write (to, n); +return __arch_copy_from_user (to, from, n); +} + +static inline unsigned long __must_check __copy_to_user (void __user *to,const void *from,unsigned long n) +{ +kasan_check_read (from, n); +return __arch_copy_to_user (to, from, n); +} +static inline unsigned long __must_check copy_from_user (void *to,const void __user *from,unsigned long n) { +kasan_check_write (to, n); +if (access_ok (VERIFY_READ , from, n)) - n =__copy_from_user (to, from, n); + n =__arch_copy_from_user (to, from, n);else /* security hole - plug it */ memset (to,0 , n);return n;
@@ -316,8 +331,10 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __ustatic inline unsigned long __must_check copy_to_user (void __user *to,const void *from,unsigned long n) { +kasan_check_read (from, n); +if (access_ok (VERIFY_WRITE , to, n)) - n =__copy_to_user (to, from, n); + n =__arch_copy_to_user (to, from, n);return n; }
arch/arm64/kernel/arm64ksyms.c +2 -2
@@ -33,8 +33,8 @@ EXPORT_SYMBOL(copy_page);EXPORT_SYMBOL (clear_page);/* user mem (segment) */ -EXPORT_SYMBOL (__copy_from_user); -EXPORT_SYMBOL (__copy_to_user); +EXPORT_SYMBOL (__arch_copy_from_user); +EXPORT_SYMBOL (__arch_copy_to_user);EXPORT_SYMBOL (__clear_user);EXPORT_SYMBOL (__copy_in_user);
arch/arm64/lib/copy_from_user.S +2 -2
@@ -66,7 +66,7 @@ .endm end .req x5 -ENTRY(__copy_from_user) +ENTRY(__arch_copy_from_user) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) add end, x0, x2
@@ -75,7 +75,7 @@ ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) mov x0, #0 // Nothing to copy ret -ENDPROC(__copy_from_user) +ENDPROC(__arch_copy_from_user) .section .fixup,"ax" .align 2
arch/arm64/lib/copy_to_user.S +2 -2
@@ -65,7 +65,7 @@ .endm end .req x5 -ENTRY(__copy_to_user) +ENTRY(__arch_copy_to_user) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) add end, x0, x2
@@ -74,7 +74,7 @@ ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) mov x0, #0 ret -ENDPROC(__copy_to_user) +ENDPROC(__arch_copy_to_user) .section .fixup,"ax" .align 2
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 12/45 arm64: uaccess: Mask __user pointers for __arch_{clear, copy_*}_user
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit f71c2ffcb20dd8626880747557014bb9a61eb90e upstream.
Like we've done for get_user and put_user, ensure that user pointers are masked before invoking the underlying __arch_{clear,copy_*}_user operations.
--- arch/arm64/include/asm/uaccess.h | 20 ++++++++++++-------- arch/arm64/kernel/arm64ksyms.c | 4 ++-- arch/arm64/lib/clear_user.S | 6 +++--- arch/arm64/lib/copy_in_user.S | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-)
arch/arm64/include/asm/uaccess.h +12 -8
@@ -303,19 +303,20 @@ do { \extern unsigned long __must_check __arch_copy_from_user (void *to,const void __user *from,unsigned long n);extern unsigned long __must_check __arch_copy_to_user (void __user *to,const void *from,unsigned long n); -extern unsigned long __must_check __copy_in_user (void __user *to,const void __user *from,unsigned long n); -extern unsigned long __must_check __clear_user (void __user *addr,unsigned long n); +extern unsigned long __must_check __arch_copy_in_user (void __user *to,const void __user *from,unsigned long n);static inline unsigned long __must_check __copy_from_user (void *to,const void __user *from,unsigned long n) {kasan_check_write (to, n); -return __arch_copy_from_user (to, from, n); +return __arch_copy_from_user (to,__uaccess_mask_ptr (from), n); + }static inline unsigned long __must_check __copy_to_user (void __user *to,const void *from,unsigned long n) {kasan_check_read (from, n); -return __arch_copy_to_user (to, from, n); +return __arch_copy_to_user (__uaccess_mask_ptr (to), from, n); + }static inline unsigned long __must_check copy_from_user (void *to,const void __user *from,unsigned long n)
@@ -338,22 +339,25 @@ static inline unsigned long __must_check copy_to_user(void __user *to, const voireturn n; } -static inline unsigned long __must_check copy_in_user (void __user *to,const void __user *from,unsigned long n) +static inline unsigned long __must_check __copy_in_user (void __user *to,const void __user *from,unsigned long n) {if (access_ok (VERIFY_READ , from, n) &&access_ok (VERIFY_WRITE , to, n)) - n =__copy_in_user (to, from, n); + n =__arch_copy_in_user (__uaccess_mask_ptr (to),__uaccess_mask_ptr (from), n);return n; } +#define copy_in_user __copy_in_user#define __copy_to_user_inatomic __copy_to_user#define __copy_from_user_inatomic __copy_from_user -static inline unsigned long __must_check clear_user (void __user *to,unsigned long n) +extern unsigned long __must_check __arch_clear_user (void __user *to,unsigned long n); +static inline unsigned long __must_check __clear_user (void __user *to,unsigned long n) {if (access_ok (VERIFY_WRITE , to, n)) - n =__clear_user (__uaccess_mask_ptr (to), n); + n =__arch_clear_user (__uaccess_mask_ptr (to), n);return n; } +#define clear_user __clear_userextern long strncpy_from_user (char *dest,const char __user *src,long count);
arch/arm64/kernel/arm64ksyms.c +2 -2
@@ -35,8 +35,8 @@ EXPORT_SYMBOL(clear_page);/* user mem (segment) */ EXPORT_SYMBOL (__arch_copy_from_user);EXPORT_SYMBOL (__arch_copy_to_user); -EXPORT_SYMBOL (__clear_user); -EXPORT_SYMBOL (__copy_in_user); +EXPORT_SYMBOL (__arch_clear_user); +EXPORT_SYMBOL (__arch_copy_in_user);/* physical memory */ EXPORT_SYMBOL (memstart_addr);
arch/arm64/lib/clear_user.S +3 -3
@@ -24,7 +24,7 @@ .text -/* Prototype: int __clear_user(void *addr, size_t sz) +/* Prototype: int __arch_clear_user(void *addr, size_t sz) * Purpose : clear some user memory * Params : addr - user memory address to clear * : sz - number of bytes to clear
@@ -32,7 +32,7 @@ * * Alignment fixed up by hardware. */ -ENTRY(__clear_user) +ENTRY(__arch_clear_user) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) mov x2, x1 // save the size for fixup return
@@ -57,7 +57,7 @@ USER(9f, strb wzr, [x0] ) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) ret -ENDPROC(__clear_user) +ENDPROC(__arch_clear_user) .section .fixup,"ax" .align 2
arch/arm64/lib/copy_in_user.S +2 -2
@@ -67,7 +67,7 @@ .endm end .req x5 -ENTRY(__copy_in_user) +ENTRY(__arch_copy_in_user) ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) add end, x0, x2
@@ -76,7 +76,7 @@ ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) mov x0, #0 ret -ENDPROC(__copy_in_user) +ENDPROC(__arch_copy_in_user) .section .fixup,"ax" .align 2
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 13/45 arm64: cpufeature: Pass capability structure to ->enable callback
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit 0a0d111d40fd1dc588cc590fab6b55d86ddc71d3 upstream.
In order to invoke the CPU capability ->matches callback from the ->enable callback for applying local-CPU workarounds, we need a handle on the capability structure.
This patch passes a pointer to the capability structure to the ->enable callback.
--- arch/arm64/kernel/cpufeature.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/cpufeature.c +2 -2
@@ -780,7 +780,7 @@ static void enable_cpu_capabilities(const struct arm64_cpu_capabilities *caps)* uses an IPI, giving us a PSTATE that disappears when * we return. */ -stop_machine (caps[i].enable,NULL , cpu_online_mask); +stop_machine (caps[i].enable, (void *)&caps[i], cpu_online_mask); }#ifdef CONFIG_HOTPLUG_CPU
@@ -894,7 +894,7 @@ void verify_local_cpu_capabilities(void)if (!feature_matches (__raw_read_system_reg (caps[i].sys_reg), &caps[i]))fail_incapable_cpu ("arm64_features" , &caps[i]);if (caps[i].enable) - caps[i].enable (NULL ); + caps[i].enable ((void *)&caps[i]); }for (i =0 , caps = arm64_hwcaps; caps[i].desc; i++) {
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 14/45 drivers/firmware: Expose psci_get_version through psci_ops structure
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit d68e3ba5303f7e1099f51fdcd155f5263da8569b upstream.
Entry into recent versions of ARM Trusted Firmware will invalidate the CPU branch predictor state in order to protect against aliasing attacks.
This patch exposes the PSCI "VERSION" function via psci_ops, so that it can be invoked outside of the PSCI driver where necessary.
--- drivers/firmware/psci.c | 2 ++ include/linux/psci.h | 1 + 2 files changed, 3 insertions(+)
drivers/firmware/psci.c +2 -0
@@ -305,6 +305,8 @@ static void __init psci_init_migrate(void)static void __init psci_0_2_set_functions (void ) {pr_info ("Using standard PSCI v0.2 function IDs\n" ); + psci_ops.get_version = psci_get_version; + psci_function_id[PSCI_FN_CPU_SUSPEND ] = PSCI_FN_NATIVE(0_2, CPU_SUSPEND); psci_ops.cpu_suspend = psci_cpu_suspend;
include/linux/psci.h +1 -0
@@ -25,6 +25,7 @@ bool psci_power_state_loses_context(u32 state);bool psci_power_state_is_valid (u32 state);struct psci_operations { +u32 (*get_version)(void );int (*cpu_suspend)(u32 state,unsigned long entry_point);int (*cpu_off)(u32 state);int (*cpu_on)(unsigned long cpuid,unsigned long entry_point);
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 15/45 arm64: Factor out TTBR0_EL1 post-update workaround into a specific asm macro
In reply to Viresh KumarFrom: Catalin Marinas <[email protected]>
commit f33bcf03e6079668da6bf4eec4a7dcf9289131d0 upstream.
This patch takes the errata workaround code out of cpu_do_switch_mm into a dedicated post_ttbr0_update_workaround macro which will be reused in a subsequent patch.
--- arch/arm64/include/asm/assembler.h | 18 ++++++++++++++++++ arch/arm64/mm/proc.S | 11 +---------- 2 files changed, 19 insertions(+), 10 deletions(-)
arch/arm64/include/asm/assembler.h +18 -0
@@ -23,6 +23,7 @@#ifndef __ASM_ASSEMBLER_H#define __ASM_ASSEMBLER_H +#include <asm/cpufeature.h> #include <asm/cputype.h> #include <asm/ptrace.h> #include <asm/thread_info.h>
@@ -282,4 +283,21 @@ lr .req x30 // link register .Ldone\@: .endm +/* + * Errata workaround post TTBR0_EL1 update. + */ + .macro post_ttbr0_update_workaround +#ifdef CONFIG_CAVIUM_ERRATUM_27456 +alternative_if_not ARM64_WORKAROUND_CAVIUM_27456 + ret + nop + nop + nop +alternative_else + ic iallu + dsb nsh + isb +#endif + .endm + #endif /* __ASM_ASSEMBLER_H */
arch/arm64/mm/proc.S +1 -10
@@ -139,17 +139,8 @@ ENTRY(cpu_do_switch_mm) bfi x0, x1, #48, #16 // set the ASID msr ttbr0_el1, x0 // set TTBR0 isb -alternative_if_not ARM64_WORKAROUND_CAVIUM_27456 + post_ttbr0_update_workaround ret - nop - nop - nop -alternative_else - ic iallu - dsb nsh - isb - ret -alternative_endif ENDPROC(cpu_do_switch_mm) .section ".text.init", #alloc, #execinstr
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 16/45 arm64: Move post_ttbr_update_workaround to C code
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit 95e3de3590e3f2358bb13f013911bc1bfa5d3f53 upstream.
We will soon need to invoke a CPU-specific function pointer after changing page tables, so move post_ttbr_update_workaround out into C code to make this possible.
[ v4.4: Removed cpufeature.h, included alternative.h, dropped entry.S
changes and adapted to drop alternative_if_not ]
--- arch/arm64/include/asm/assembler.h | 18 ------------------ arch/arm64/mm/context.c | 10 ++++++++++ arch/arm64/mm/proc.S | 3 +-- 3 files changed, 11 insertions(+), 20 deletions(-)
arch/arm64/include/asm/assembler.h +0 -18
@@ -23,7 +23,6 @@#ifndef __ASM_ASSEMBLER_H#define __ASM_ASSEMBLER_H -#include <asm/cpufeature.h> #include <asm/cputype.h> #include <asm/ptrace.h> #include <asm/thread_info.h>
@@ -283,21 +282,4 @@ lr .req x30 // link register .Ldone\@: .endm -/* - * Errata workaround post TTBR0_EL1 update. - */ - .macro post_ttbr0_update_workaround -#ifdef CONFIG_CAVIUM_ERRATUM_27456 -alternative_if_not ARM64_WORKAROUND_CAVIUM_27456 - ret - nop - nop - nop -alternative_else - ic iallu - dsb nsh - isb -#endif - .endm -#endif /* __ASM_ASSEMBLER_H */
arch/arm64/mm/context.c +10 -0
@@ -22,6 +22,7 @@#include <linux/slab.h> #include <linux/mm.h> +#include <asm/alternative.h> #include <asm/cpufeature.h> #include <asm/mmu_context.h> #include <asm/tlbflush.h>
@@ -185,6 +186,15 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)cpu_switch_mm (mm->pgd, mm); } +/* Errata workaround post TTBRx_EL1 update. */ +asmlinkage void post_ttbr_update_workaround(void) +{ + asm(ALTERNATIVE("nop; nop; nop", +"ic iallu; dsb nsh; isb" , +ARM64_WORKAROUND_CAVIUM_27456 , + CONFIG_CAVIUM_ERRATUM_27456)); +} +static int asids_init (void ) {int fld =cpuid_feature_extract_field (read_cpuid (ID_AA64MMFR0_EL1 ),4 );
arch/arm64/mm/proc.S +1 -2
@@ -139,8 +139,7 @@ ENTRY(cpu_do_switch_mm) bfi x0, x1, #48, #16 // set the ASID msr ttbr0_el1, x0 // set TTBR0 isb - post_ttbr0_update_workaround - ret + b post_ttbr_update_workaround // Back to C code... ENDPROC(cpu_do_switch_mm) .section ".text.init", #alloc, #execinstr
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 17/45 arm64: cpufeature: Add scope for capability check
In reply to Viresh KumarFrom: Suzuki K Poulose <[email protected]>
commit 92406f0cc9e3d5cc77bf3de6d68c9c2373dcd701 upstream.
Add scope parameter to the arm64_cpu_capabilities::matches(), so that this can be reused for checking the capability on a given CPU vs the system wide. The system uses the default scope associated with the capability for initialising the CPU_HWCAPs and ELF_HWCAPs.
--- arch/arm64/include/asm/cpufeature.h | 9 ++- arch/arm64/kernel/cpu_errata.c | 5 +- arch/arm64/kernel/cpufeature.c | 105 +++++++++++++++------------- 3 files changed, 70 insertions(+), 49 deletions(-)
arch/arm64/include/asm/cpufeature.h +8 -1
@@ -74,10 +74,17 @@ struct arm64_ftr_reg {struct arm64_ftr_bits *ftr_bits; }; +/* scope of capability check */ +enum { +SCOPE_SYSTEM , +SCOPE_LOCAL_CPU , +}; + struct arm64_cpu_capabilities { const char *desc; u16 capability; - bool (*matches)(const struct arm64_cpu_capabilities *); + int def_scope; /* default scope */ + bool (*matches)(const struct arm64_cpu_capabilities *caps, int scope); int (*enable)(void *); /* Called on all active CPUs */ union { struct { /* To be used for erratum handling only */
arch/arm64/kernel/cpu_errata.c +4 -1
@@ -29,10 +29,12 @@ MIDR_ARCHITECTURE_MASK) static bool __maybe_unused -is_affected_midr_range (const struct arm64_cpu_capabilities *entry) +is_affected_midr_range (const struct arm64_cpu_capabilities *entry,int scope) {u32 midr =read_cpuid_id (); +WARN_ON (scope !=SCOPE_LOCAL_CPU ||preemptible ()); +if ((midr &CPU_MODEL_MASK ) != entry->midr_model)return false;
@@ -42,6 +44,7 @@ is_affected_midr_range(const struct arm64_cpu_capabilities *entry) }#define MIDR_RANGE (model, min, max) \ + .def_scope = SCOPE_LOCAL_CPU, \ .matches = is_affected_midr_range, \ .midr_model = model, \ .midr_range_min = min, \
arch/arm64/kernel/cpufeature.c +58 -47
174 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 18/45 arm64: Add skeleton to harden the branch predictor against aliasing attacks
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit 0f15adbb2861ce6f75ccfc5a92b19eae0ef327d0 upstream.
Aliasing attacks against CPU branch predictors can allow an attacker to redirect speculative control flow on some CPUs and potentially divulge information from one context to another.
This patch adds initial skeleton code behind a new Kconfig option to enable implementation-specific mitigations against these attacks for CPUs that are affected.
--- arch/arm64/Kconfig | 17 +++++++ arch/arm64/include/asm/cpufeature.h | 3 +- arch/arm64/include/asm/mmu.h | 39 +++++++++++++++ arch/arm64/include/asm/sysreg.h | 2 + arch/arm64/kernel/Makefile | 5 ++ arch/arm64/kernel/bpi.S | 55 +++++++++++++++++++++ arch/arm64/kernel/cpu_errata.c | 74 +++++++++++++++++++++++++++++ arch/arm64/kernel/cpufeature.c | 3 +- arch/arm64/kernel/entry.S | 8 ++-- arch/arm64/mm/context.c | 2 + arch/arm64/mm/fault.c | 16 +++++++ 11 files changed, 219 insertions(+), 5 deletions(-) create mode 100644 arch/arm64/kernel/bpi.S
arch/arm64/Kconfig +17 -0
@@ -624,6 +624,23 @@ config FORCE_MAX_ZONEORDER However for 4K, we choose a higher default value, 11 as opposed to 10, giving us 4M allocations matching the default size used by generic code. +config HARDEN_BRANCH_PREDICTOR + bool "Harden the branch predictor against aliasing attacks" if EXPERT + default y + help + Speculation attacks against some high-performance processors rely on + being able to manipulate the branch predictor for a victim context by + executing aliasing branches in the attacker context. Such attacks + can be partially mitigated against by clearing internal branch + predictor state and limiting the prediction logic in some situations. + + This config option will take CPU-specific actions to harden the + branch predictor against aliasing attacks and may rely on specific + instruction sequences or control bits being set by the system + firmware. + + If unsure, say Y. + menuconfig ARMV8_DEPRECATED bool "Emulate deprecated/obsolete ARMv8 instructions" depends on COMPAT
arch/arm64/include/asm/cpufeature.h +2 -1
@@ -32,8 +32,9 @@#define ARM64_WORKAROUND_834220 7#define ARM64_WORKAROUND_CAVIUM_27456 8#define ARM64_HAS_32BIT_EL0 9 +#define ARM64_HARDEN_BRANCH_PREDICTOR 10 -#define ARM64_NCAPS 10 +#define ARM64_NCAPS 11#ifndef __ASSEMBLY__
arch/arm64/include/asm/mmu.h +39 -0
@@ -16,6 +16,8 @@ #ifndef __ASM_MMU_H #define __ASM_MMU_H +#include <linux/percpu.h> + typedef struct { atomic64_t id; void *vdso;
@@ -28,6 +30,43 @@ typedef struct {*/ #define ASID (mm) ((mm)->context.id.counter & 0xffff) +typedef void (*bp_hardening_cb_t )(void ); + +struct bp_hardening_data { +int hyp_vectors_slot; +bp_hardening_cb_t fn; +}; + +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +extern char __bp_harden_hyp_vecs_start[], __bp_harden_hyp_vecs_end[]; + +DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); + +static inline struct bp_hardening_data *arm64_get_bp_hardening_data (void ) +{ +return this_cpu_ptr (&bp_hardening_data); +} + +static inline void arm64_apply_bp_hardening (void ) +{ +struct bp_hardening_data *d; + +if (!cpus_have_cap (ARM64_HARDEN_BRANCH_PREDICTOR )) +return ; + + d =arm64_get_bp_hardening_data (); +if (d->fn) + d->fn (); +} +#else +static inline struct bp_hardening_data *arm64_get_bp_hardening_data (void ) +{ +return NULL ; +} + +static inline void arm64_apply_bp_hardening (void ) { } +#endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ +extern void paging_init (void );extern void __iomem *early_io_map (phys_addr_t phys,unsigned long virt);extern void init_mem_pgprot (void );
arch/arm64/include/asm/sysreg.h +2 -0
@@ -95,6 +95,8 @@#define ID_AA64ISAR0_AES_SHIFT 4/* id_aa64pfr0 */ +#define ID_AA64PFR0_CSV2_SHIFT 56 +#define ID_AA64PFR0_SVE_SHIFT 32#define ID_AA64PFR0_GIC_SHIFT 24#define ID_AA64PFR0_ASIMD_SHIFT 20#define ID_AA64PFR0_FP_SHIFT 16
arch/arm64/kernel/Makefile +5 -0
@@ -42,7 +42,12 @@ arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o arm64-obj-$(CONFIG_ACPI) += acpi.o +ifeq ($(CONFIG_KVM),y) +arm64-obj-$(CONFIG_HARDEN_BRANCH_PREDICTOR) += bpi.o +endif + obj-y += $(arm64-obj-y) vdso/ + obj-m += $(arm64-obj-m) head-y := head.o extra-y += $(head-y) vmlinux.lds
arch/arm64/kernel/bpi.S new file +55 -0
55 lines not on this page · raw message
arch/arm64/kernel/cpu_errata.c +74 -0
80 lines not on this page · raw message
arch/arm64/kernel/cpufeature.c +2 -1
@@ -83,7 +83,8 @@ static struct arm64_ftr_bits ftr_id_aa64isar0[] = { };static struct arm64_ftr_bits ftr_id_aa64pfr0[] = { -ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,32 ,32 ,0 ), +ARM64_FTR_BITS (FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_CSV2_SHIFT ,4 ,0 ), +ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,32 ,28 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,28 ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,ID_AA64PFR0_GIC_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64PFR0_ASIMD_SHIFT ,4 ,ID_AA64PFR0_ASIMD_NI ),
arch/arm64/kernel/entry.S +5 -3
@@ -495,13 +495,15 @@ ENDPROC(el1_irq) * Instruction abort handling */ mrs x26, far_el1 - // enable interrupts before calling the main handler - enable_dbg_and_irq + msr daifclr, #(8 | 4 | 1) +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif ct_user_exit mov x0, x26 orr x1, x25, #1 << 24 // use reserved ISS bit for instruction aborts mov x2, sp - bl do_mem_abort + bl do_el0_ia_bp_hardening b ret_to_user el0_fpsimd_acc: /*
arch/arm64/mm/context.c +2 -0
@@ -193,6 +193,8 @@ asmlinkage void post_ttbr_update_workaround(void)"ic iallu; dsb nsh; isb" ,ARM64_WORKAROUND_CAVIUM_27456 , CONFIG_CAVIUM_ERRATUM_27456)); + +arm64_apply_bp_hardening (); }static int asids_init (void )
arch/arm64/mm/fault.c +16 -0
@@ -535,6 +535,22 @@ asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr,arm64_notify_die ("" , regs, &info, esr); } +asmlinkage void __exception do_el0_ia_bp_hardening(unsigned long addr, +unsigned int esr, +struct pt_regs *regs) +{ +/* +* We've taken an instruction abort from userspace and not yet +* re-enabled IRQs. If the address is a kernel address, apply +* BP hardening prior to enabling IRQs and pre-emption. +*/ +if (addr >TASK_SIZE ) +arm64_apply_bp_hardening (); + +local_irq_enable (); +do_mem_abort (addr, esr, regs); +} +/* * Handle stack alignment exceptions. */
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 19/45 arm64: Move BP hardening to check_and_switch_context
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit a8e4c0a919ae310944ed2c9ace11cf3ccd8a609b upstream.
We call arm64_apply_bp_hardening() from post_ttbr_update_workaround, which has the unexpected consequence of being triggered on every exception return to userspace when ARM64_SW_TTBR0_PAN is selected, even if no context switch actually occured.
This is a bit suboptimal, and it would be more logical to only invalidate the branch predictor when we actually switch to a different mm.
In order to solve this, move the call to arm64_apply_bp_hardening() into check_and_switch_context(), where we're guaranteed to pick a different mm context.
--- arch/arm64/mm/context.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/mm/context.c +2 -2
@@ -183,6 +183,8 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)raw_spin_unlock_irqrestore (&cpu_asid_lock, flags); switch_mm_fastpath: +arm64_apply_bp_hardening (); +cpu_switch_mm (mm->pgd, mm); }
@@ -193,8 +195,6 @@ asmlinkage void post_ttbr_update_workaround(void)"ic iallu; dsb nsh; isb" ,ARM64_WORKAROUND_CAVIUM_27456 , CONFIG_CAVIUM_ERRATUM_27456)); - -arm64_apply_bp_hardening (); }static int asids_init (void )
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 20/45 mm: Introduce lm_alias
In reply to Viresh KumarFrom: Laura Abbott <[email protected]>
commit 568c5fe5a54f2654f5a4c599c45b8a62ed9a2013 upstream.
Certain architectures may have the kernel image mapped separately to alias the linear map. Introduce a macro lm_alias to translate a kernel image symbol into its linear alias. This is used in part with work to add CONFIG_DEBUG_VIRTUAL support for arm64.
--- include/linux/mm.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/mm.h +4 -0
@@ -59,6 +59,10 @@ extern int sysctl_legacy_va_layout;#define __pa_symbol (x) __pa(RELOC_HIDE((unsigned long)(x), 0))#endif +#ifndef lm_alias +#define lm_alias (x) __va(__pa_symbol(x)) +#endif +/* * To prevent common memory management code establishing * a zero page mapping on a read fault.
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Re: [PATCH v4.4 20/45] mm: Introduce lm_alias
Hi Viresh,
Quoted 9 lines · Viresh Kumar
From: Laura Abbott <[email protected]>
commit
568c5fe5a54f2654f5a4c599c45b8a62ed9a2013upstream.Certain architectures may have the kernel image mapped separately to alias the linear map. Introduce a macro
lm_aliasto translate a kernel image symbol into its linear alias. This is used in part with work to addCONFIG_DEBUG_VIRTUALsupport for arm64.
I think this commit was backported in 4.9 because one of the commits you dropped (6840bdd73d07 arm64: KVM: Use per-CPU vector when BP hardening is enabled) depended on it. I have yet to check whether that other commit can be just dropped, however on your branch 4.4 branch, lm_alias isn't used anywhere, so we probably don't want to backport this particular patch (unless we need to actually backport the other patch in some way).
Cheers,
Signature · 1 line
Julien Thierry
Re: [PATCH v4.4 20/45] mm: Introduce lm_alias
Quoted 3 lines · Julien Thierry
I think this commit was backported in 4.9 because one of the commits you dropped (
6840bdd73d07arm64: KVM: Use per-CPU vector when BP hardening is enabled) depended on it.
Looks like that. I dropped 6840bdd73d07 patch at a later point of time when the conflicts couldn't get resolved properly any further. I should have dropped $subject one as well :(
Quoted 5 lines
I have yet to check whether that other
commit can be just dropped, however on your branch 4.4 branch,lm_aliasisn't used anywhere, so we probably don't want to backport this particular patch (unless we need to actually backport the other patch in some way).
Right, dropping this doesn't generate any compilation warnings so we should be good without it.
Signature · 1 line
viresh
PATCH 21/45 arm64: entry: Apply BP hardening for high-priority synchronous exceptions
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit 5dfc6ed27710c42cbc15db5c0d4475699991da0a upstream.
Software-step and PC alignment fault exceptions have higher priority than instruction abort exceptions, so apply the BP hardening hooks there too if the user PC appears to reside in kernel space.
--- arch/arm64/kernel/entry.S | 6 ++++-- arch/arm64/mm/fault.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-)
arch/arm64/kernel/entry.S +4 -2
@@ -530,8 +530,10 @@ ENDPROC(el1_irq) * Stack or PC alignment exception handling */ mrs x26, far_el1 - // enable interrupts before calling the main handler - enable_dbg_and_irq + enable_dbg +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif ct_user_exit mov x0, x26 mov x1, x25
arch/arm64/mm/fault.c +9 -0
@@ -561,6 +561,12 @@ asmlinkage void __exception do_sp_pc_abort(unsigned long addr,struct siginfo info;struct task_struct *tsk = current; +if (user_mode (regs)) { +if (instruction_pointer (regs) >TASK_SIZE ) +arm64_apply_bp_hardening (); +local_irq_enable (); + } +if (show_unhandled_signals &&unhandled_signal (tsk,SIGBUS )) pr_info_ratelimited("%s[%d]: %s exception: pc=%p sp=%p\n", tsk->comm, task_pid_nr(tsk),
@@ -621,6 +627,9 @@ asmlinkage int __exception do_debug_exception(unsigned long addr_if_watchpoint,if (interrupts_enabled (regs))trace_hardirqs_off (); +if (user_mode (regs) &&instruction_pointer (regs) >TASK_SIZE ) +arm64_apply_bp_hardening (); +if (!inf->fn (addr_if_watchpoint, esr, regs)) { rv =1 ; }else {
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 22/45 arm64: entry: Apply BP hardening for suspicious interrupts from EL0
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit 30d88c0e3ace625a92eead9ca0ad94093a8f59fe upstream.
It is possible to take an IRQ from EL0 following a branch to a kernel address in such a way that the IRQ is prioritised over the instruction abort. Whilst an attacker would need to get the stars to align here, it might be sufficient with enough calibration so perform BP hardening in the rare case that we see a kernel address in the ELR when handling an IRQ from EL0.
--- arch/arm64/kernel/entry.S | 5 +++++ arch/arm64/mm/fault.c | 6 ++++++ 2 files changed, 11 insertions(+)
arch/arm64/kernel/entry.S +5 -0
@@ -582,6 +582,11 @@ ENDPROC(el0_sync) #endif ct_user_exit +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR + tbz x22, #55, 1f + bl do_el0_irq_bp_hardening +1: +#endif irq_handler #ifdef CONFIG_TRACE_IRQFLAGS
arch/arm64/mm/fault.c +6 -0
@@ -535,6 +535,12 @@ asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr,arm64_notify_die ("" , regs, &info, esr); } +asmlinkage void __exception do_el0_irq_bp_hardening(void) +{ +/* PC has already been checked in entry.S */ +arm64_apply_bp_hardening (); +} + asmlinkage void __exception do_el0_ia_bp_hardening(unsigned long addr,unsigned int esr,struct pt_regs *regs)
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 23/45 arm64: cputype: Add missing MIDR values for Cortex-A72 and Cortex-A75
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit a65d219fe5dc7887fd5ca04c2ac3e9a34feb8dfc upstream.
Hook up MIDR values for the Cortex-A72 and Cortex-A75 CPUs, since they will soon need MIDR matches for hardening the branch predictor.
--- arch/arm64/include/asm/cputype.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm64/include/asm/cputype.h +6 -0
@@ -77,14 +77,20 @@#define ARM_CPU_PART_AEM_V8 0xD0F#define ARM_CPU_PART_FOUNDATION 0xD00#define ARM_CPU_PART_CORTEX_A57 0xD07 +#define ARM_CPU_PART_CORTEX_A72 0xD08#define ARM_CPU_PART_CORTEX_A53 0xD03#define ARM_CPU_PART_CORTEX_A55 0xD05 +#define ARM_CPU_PART_CORTEX_A73 0xD09 +#define ARM_CPU_PART_CORTEX_A75 0xD0A#define APM_CPU_PART_POTENZA 0x000#define CAVIUM_CPU_PART_THUNDERX 0x0A1#define MIDR_CORTEX_A55 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A55) +#define MIDR_CORTEX_A72 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72) +#define MIDR_CORTEX_A73 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73) +#define MIDR_CORTEX_A75 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)#ifndef __ASSEMBLY__
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 24/45 arm64: cpu_errata: Allow an erratum to be match for all revisions of a core
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit 06f1494f837da8997d670a1ba87add7963b08922 upstream.
Some minor erratum may not be fixed in further revisions of a core, leading to a situation where the workaround needs to be updated each time an updated core is released.
Introduce a MIDR_ALL_VERSIONS match helper that will work for all versions of that MIDR, once and for all.
--- arch/arm64/kernel/cpu_errata.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/kernel/cpu_errata.c +7 -0
@@ -124,6 +124,13 @@ static void install_bp_hardening_cb(const struct arm64_cpu_capabilities *entry, .midr_range_min = min, \ .midr_range_max = max +#define MIDR_ALL_VERSIONS (model) \ + .def_scope = SCOPE_LOCAL_CPU, \ + .matches = is_affected_midr_range, \ + .midr_model = model, \ + .midr_range_min = 0, \ + .midr_range_max = (MIDR_VARIANT_MASK | MIDR_REVISION_MASK) + const struct arm64_cpu_capabilities arm64_errata[] = { #if defined(CONFIG_ARM64_ERRATUM_826319) || \ defined(CONFIG_ARM64_ERRATUM_827319) || \
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 25/45 arm64: Implement branch predictor hardening for affected Cortex-A CPUs
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit aa6acde65e03186b5add8151e1ffe36c3c62639b upstream.
Cortex-A57, A72, A73 and A75 are susceptible to branch predictor aliasing and can theoretically be attacked by malicious code.
This patch implements a PSCI-based mitigation for these CPUs when available. The call into firmware will invalidate the branch predictor state, preventing any malicious entries from affecting other victim contexts.
--- arch/arm64/kernel/bpi.S | 24 +++++++++++++++++++ arch/arm64/kernel/cpu_errata.c | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
arch/arm64/kernel/bpi.S +24 -0
@@ -53,3 +53,27 @@ ENTRY(__bp_harden_hyp_vecs_start) vectors __kvm_hyp_vector .endr ENTRY(__bp_harden_hyp_vecs_end) +ENTRY(__psci_hyp_bp_inval_start) + sub sp, sp, #(8 * 18) + stp x16, x17, [sp, #(16 * 0)] + stp x14, x15, [sp, #(16 * 1)] + stp x12, x13, [sp, #(16 * 2)] + stp x10, x11, [sp, #(16 * 3)] + stp x8, x9, [sp, #(16 * 4)] + stp x6, x7, [sp, #(16 * 5)] + stp x4, x5, [sp, #(16 * 6)] + stp x2, x3, [sp, #(16 * 7)] + stp x0, x1, [sp, #(16 * 8)] + mov x0, #0x84000000 + smc #0 + ldp x16, x17, [sp, #(16 * 0)] + ldp x14, x15, [sp, #(16 * 1)] + ldp x12, x13, [sp, #(16 * 2)] + ldp x10, x11, [sp, #(16 * 3)] + ldp x8, x9, [sp, #(16 * 4)] + ldp x6, x7, [sp, #(16 * 5)] + ldp x4, x5, [sp, #(16 * 6)] + ldp x2, x3, [sp, #(16 * 7)] + ldp x0, x1, [sp, #(16 * 8)] + add sp, sp, #(8 * 18) +ENTRY(__psci_hyp_bp_inval_end)
arch/arm64/kernel/cpu_errata.c +42 -0
66 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 26/45 arm64: cputype info for Broadcom Vulcan
In reply to Viresh KumarFrom: Jayachandran C <[email protected]>
commit 9eb8a2cdf65ce47c3aa68f1297c84d8bcf5a7b3a upstream.
Add Broadcom Vulcan implementor ID and part ID in cputype.h. This is to document the values.
--- arch/arm64/include/asm/cputype.h | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/include/asm/cputype.h +3 -0
@@ -73,6 +73,7 @@#define ARM_CPU_IMP_ARM 0x41#define ARM_CPU_IMP_APM 0x50#define ARM_CPU_IMP_CAVIUM 0x43 +#define ARM_CPU_IMP_BRCM 0x42#define ARM_CPU_PART_AEM_V8 0xD0F#define ARM_CPU_PART_FOUNDATION 0xD00
@@ -87,6 +88,8 @@#define CAVIUM_CPU_PART_THUNDERX 0x0A1 +#define BRCM_CPU_PART_VULCAN 0x516 +#define MIDR_CORTEX_A55 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A55)#define MIDR_CORTEX_A72 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72)#define MIDR_CORTEX_A73 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 27/45 arm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs
In reply to Viresh KumarFrom: Jayachandran C <[email protected]>
commit 0d90718871fe80f019b7295ec9d2b23121e396fb upstream.
Add the older Broadcom ID as well as the new Cavium ID for ThunderX2 CPUs.
--- arch/arm64/include/asm/cputype.h | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/include/asm/cputype.h +3 -0
@@ -87,6 +87,7 @@#define APM_CPU_PART_POTENZA 0x000#define CAVIUM_CPU_PART_THUNDERX 0x0A1 +#define CAVIUM_CPU_PART_THUNDERX2 0x0AF#define BRCM_CPU_PART_VULCAN 0x516
@@ -94,6 +95,8 @@#define MIDR_CORTEX_A72 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72)#define MIDR_CORTEX_A73 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)#define MIDR_CORTEX_A75 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75) +#define MIDR_CAVIUM_THUNDERX2 MIDR_CPU_PART(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX2) +#define MIDR_BRCM_VULCAN MIDR_CPU_PART(ARM_CPU_IMP_BRCM, BRCM_CPU_PART_VULCAN)#ifndef __ASSEMBLY__
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 28/45 arm64: Branch predictor hardening for Cavium ThunderX2
In reply to Viresh KumarFrom: Jayachandran C <[email protected]>
commit f3d795d9b360523beca6d13ba64c2c532f601149 upstream.
Use PSCI based mitigation for speculative execution attacks targeting the branch predictor. We use the same mechanism as the one used for Cortex-A CPUs, we expect the PSCI version call to have a side effect of clearing the BTBs.
--- arch/arm64/kernel/cpu_errata.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/kernel/cpu_errata.c +10 -0
@@ -234,6 +234,16 @@ const struct arm64_cpu_capabilities arm64_errata[] = { MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), .enable = enable_psci_bp_hardening, }, + { + .capability =ARM64_HARDEN_BRANCH_PREDICTOR , +MIDR_ALL_VERSIONS (MIDR_BRCM_VULCAN ), + .enable = enable_psci_bp_hardening, + }, + { + .capability =ARM64_HARDEN_BRANCH_PREDICTOR , +MIDR_ALL_VERSIONS (MIDR_CAVIUM_THUNDERX2 ), + .enable = enable_psci_bp_hardening, + }, #endif { }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 29/45 arm64: KVM: Increment PC after handling an SMC trap
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit f5115e8869e1dfafac0e414b4f1664f3a84a4683 upstream.
When handling an SMC trap, the "preferred return address" is set to that of the SMC, and not the next PC (which is a departure from the behaviour of an SMC that isn't trapped).
Increment PC in the handler, as the guest is otherwise forever stuck...
--- arch/arm64/kvm/handle_exit.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm64/kvm/handle_exit.c +9 -0
@@ -51,7 +51,16 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)static int handle_smc (struct kvm_vcpu *vcpu,struct kvm_run *run) { +/* +* "If an SMC instruction executed at Non-secure EL1 is +* trapped to EL2 because HCR_EL2.TSC is 1, the exception is a +* Trap exception, not a Secure Monitor Call exception [...]" +* +* We need to advance the PC after the trap, as it would +* otherwise return to the same address... +*/ vcpu_set_reg (vcpu,0 , ~0UL ); +kvm_skip_instr (vcpu,kvm_vcpu_trap_il_is32bit (vcpu));return 1 ; }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 30/45 arm/arm64: KVM: Consolidate the PSCI include files
In reply to Viresh KumarFrom: Mark Rutland <[email protected]>
commit 1a2fb94e6a771ff94f4afa22497a4695187b820c upstream.
As we're about to update the PSCI support, and because I'm lazy, let's move the PSCI include file to include/kvm so that both ARM architectures can find it.
--- arch/arm/include/asm/kvm_psci.h | 27 ------------------- arch/arm/kvm/arm.c | 2 +- arch/arm/kvm/handle_exit.c | 2 +- arch/arm/kvm/psci.c | 3 ++- arch/arm64/kvm/handle_exit.c | 5 +++- .../asm/kvm_psci.h => include/kvm/arm_psci.h | 6 ++--- 6 files changed, 11 insertions(+), 34 deletions(-) delete mode 100644 arch/arm/include/asm/kvm_psci.h rename arch/arm64/include/asm/kvm_psci.h => include/kvm/arm_psci.h (89%)
arch/arm/include/asm/kvm_psci.h deleted +0 -27
@@ -1,27 +0,0 @@ -/* -* Copyright (C) 2012 - ARM Ltd -* Author: Marc Zyngier <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __ARM_KVM_PSCI_H__ -#define __ARM_KVM_PSCI_H__ - -#define KVM_ARM_PSCI_0_1 1 -#define KVM_ARM_PSCI_0_2 2 - -int kvm_psci_version (struct kvm_vcpu *vcpu); -int kvm_psci_call (struct kvm_vcpu *vcpu); - -#endif /* __ARM_KVM_PSCI_H__ */
arch/arm/kvm/arm.c +1 -1
@@ -28,6 +28,7 @@#include <linux/sched.h> #include <linux/kvm.h> #include <trace/events/kvm.h> +#include <kvm/arm_psci.h> #define CREATE_TRACE_POINTS #include "trace.h"
@@ -43,7 +44,6 @@#include <asm/kvm_mmu.h> #include <asm/kvm_emulate.h> #include <asm/kvm_coproc.h> -#include <asm/kvm_psci.h> #ifdef REQUIRES_VIRT __asm__(".arch_extension virt" );
arch/arm/kvm/handle_exit.c +1 -1
@@ -21,7 +21,7 @@#include <asm/kvm_emulate.h> #include <asm/kvm_coproc.h> #include <asm/kvm_mmu.h> -#include <asm/kvm_psci.h> +#include <kvm/arm_psci.h> #include <trace/events/kvm.h> #include "trace.h"
arch/arm/kvm/psci.c +2 -1
@@ -21,9 +21,10 @@#include <asm/cputype.h> #include <asm/kvm_emulate.h> -#include <asm/kvm_psci.h> #include <asm/kvm_host.h> +#include <kvm/arm_psci.h> +#include <uapi/linux/psci.h> /*
arch/arm64/kvm/handle_exit.c +4 -1
@@ -22,11 +22,14 @@#include <linux/kvm.h> #include <linux/kvm_host.h> +#include <kvm/arm_psci.h> +#include <asm/esr.h> #include <asm/kvm_coproc.h> #include <asm/kvm_emulate.h> #include <asm/kvm_mmu.h> -#include <asm/kvm_psci.h> +#include <asm/debug-monitors.h> +#include <asm/traps.h> #define CREATE_TRACE_POINTS #include "trace.h"
include/kvm/arm_psci.h renamed from arch/arm64/include/asm/kvm_psci.h +3 -3
@@ -15,8 +15,8 @@* along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __ARM64_KVM_PSCI_H__ -#define __ARM64_KVM_PSCI_H__ +#ifndef __KVM_ARM_PSCI_H__ +#define __KVM_ARM_PSCI_H__#define KVM_ARM_PSCI_0_1 1#define KVM_ARM_PSCI_0_2 2
@@ -24,4 +24,4 @@int kvm_psci_version (struct kvm_vcpu *vcpu);int kvm_psci_call (struct kvm_vcpu *vcpu); -#endif /* __ARM64_KVM_PSCI_H__ */ +#endif /* __KVM_ARM_PSCI_H__ */
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 31/45 arm/arm64: KVM: Add PSCI_VERSION helper
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit d0a144f12a7ca8368933eae6583c096c363ec506 upstream.
As we're about to trigger a PSCI version explosion, it doesn't hurt to introduce a PSCI_VERSION helper that is going to be used everywhere.
--- arch/arm/kvm/psci.c | 4 +--- include/kvm/arm_psci.h | 6 ++++-- include/uapi/linux/psci.h | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-)
arch/arm/kvm/psci.c +1 -3
@@ -25,8 +25,6 @@#include <kvm/arm_psci.h> -#include <uapi/linux/psci.h> -/* * This is an implementation of the Power State Coordination Interface * as described in ARM document number ARM DEN 0022A.
@@ -220,7 +218,7 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)* Bits[31:16] = Major Version = 0 * Bits[15:0] = Minor Version = 2 */ - val =2 ; + val =KVM_ARM_PSCI_0_2 ;break ;case PSCI_0_2_FN_CPU_SUSPEND :case PSCI_0_2_FN64_CPU_SUSPEND :
include/kvm/arm_psci.h +4 -2
@@ -18,8 +18,10 @@#ifndef __KVM_ARM_PSCI_H__#define __KVM_ARM_PSCI_H__ -#define KVM_ARM_PSCI_0_1 1 -#define KVM_ARM_PSCI_0_2 2 +#include <uapi/linux/psci.h> + +#define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1) +#define KVM_ARM_PSCI_0_2 PSCI_VERSION(0, 2)int kvm_psci_version (struct kvm_vcpu *vcpu);int kvm_psci_call (struct kvm_vcpu *vcpu);
include/uapi/linux/psci.h +3 -0
@@ -87,6 +87,9 @@ (((ver) & PSCI_VERSION_MAJOR_MASK) >> PSCI_VERSION_MAJOR_SHIFT)#define PSCI_VERSION_MINOR (ver) \ ((ver) & PSCI_VERSION_MINOR_MASK) +#define PSCI_VERSION (maj, min) \ + ((((maj) << PSCI_VERSION_MAJOR_SHIFT) & PSCI_VERSION_MAJOR_MASK) | \ + ((min) & PSCI_VERSION_MINOR_MASK))/* PSCI features decoding (>=1.0) */ #define PSCI_1_0_FEATURES_CPU_SUSPEND_PF_SHIFT 1
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 32/45 arm/arm64: KVM: Add smccc accessors to PSCI code
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit 84684fecd7ea381824a96634a027b7719587fb77 upstream.
Instead of open coding the accesses to the various registers, let's add explicit SMCCC accessors.
--- arch/arm/kvm/psci.c | 52 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 10 deletions(-)
arch/arm/kvm/psci.c +42 -10
@@ -32,6 +32,38 @@#define AFFINITY_MASK (level) ~((0x1UL << ((level) * MPIDR_LEVEL_BITS)) - 1) +static u32 smccc_get_function (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,0 ); +} + +static unsigned long smccc_get_arg1 (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,1 ); +} + +static unsigned long smccc_get_arg2 (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,2 ); +} + +static unsigned long smccc_get_arg3 (struct kvm_vcpu *vcpu) +{ +return vcpu_get_reg (vcpu,3 ); +} + +static void smccc_set_retval (struct kvm_vcpu *vcpu, +unsigned long a0, +unsigned long a1, +unsigned long a2, +unsigned long a3) +{ +vcpu_set_reg (vcpu,0 , a0); +vcpu_set_reg (vcpu,1 , a1); +vcpu_set_reg (vcpu,2 , a2); +vcpu_set_reg (vcpu,3 , a3); +} +static unsigned long psci_affinity_mask (unsigned long affinity_level) {if (affinity_level <=3 )
@@ -74,7 +106,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)unsigned long context_id;phys_addr_t target_pc; - cpu_id =vcpu_get_reg (source_vcpu,1 ) &MPIDR_HWID_BITMASK ; + cpu_id =smccc_get_arg1 (source_vcpu) &MPIDR_HWID_BITMASK ;if (vcpu_mode_is_32bit (source_vcpu)) cpu_id &= ~((u32 )0 );
@@ -93,8 +125,8 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)return PSCI_RET_INVALID_PARAMS ; } - target_pc =vcpu_get_reg (source_vcpu,2 ); - context_id =vcpu_get_reg (source_vcpu,3 ); + target_pc =smccc_get_arg2 (source_vcpu); + context_id =smccc_get_arg3 (source_vcpu);kvm_reset_vcpu (vcpu);
@@ -113,7 +145,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)* NOTE: We always update r0 (or x0) because for PSCI v0.1 * the general puspose registers are undefined upon CPU_ON. */ -vcpu_set_reg (vcpu,0 , context_id); +smccc_set_retval (vcpu, context_id,0 ,0 ,0 ); vcpu->arch.power_off = false;smp_mb ();/* Make sure the above is visible */
@@ -133,8 +165,8 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)struct kvm *kvm = vcpu->kvm;struct kvm_vcpu *tmp; - target_affinity =vcpu_get_reg (vcpu,1 ); - lowest_affinity_level =vcpu_get_reg (vcpu,2 ); + target_affinity =smccc_get_arg1 (vcpu); + lowest_affinity_level =smccc_get_arg2 (vcpu);/* Determine target affinity mask */ target_affinity_mask =psci_affinity_mask (lowest_affinity_level);
@@ -208,7 +240,7 @@ int kvm_psci_version(struct kvm_vcpu *vcpu)static int kvm_psci_0_2_call (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm; -unsigned long psci_fn =vcpu_get_reg (vcpu,0 ) & ~((u32 )0 ); +unsigned long psci_fn =smccc_get_function (vcpu);unsigned long val;int ret =1 ;
@@ -275,14 +307,14 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)break ; } -vcpu_set_reg (vcpu,0 , val); +smccc_set_retval (vcpu, val,0 ,0 ,0 );return ret; }static int kvm_psci_0_1_call (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm; -unsigned long psci_fn =vcpu_get_reg (vcpu,0 ) & ~((u32 )0 ); +unsigned long psci_fn =smccc_get_function (vcpu);unsigned long val;switch (psci_fn) {
@@ -300,7 +332,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)break ; } -vcpu_set_reg (vcpu,0 , val); +smccc_set_retval (vcpu, val,0 ,0 ,0 );return 1 ; }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 33/45 ARM: 8478/2: arm/arm64: add arm-smccc
In reply to Viresh KumarFrom: Jens Wiklander <[email protected]>
commit 98dd64f34f47ce19b388d9015f767f48393a81eb upstream.
Adds helpers to do SMC and HVC based on ARM SMC Calling Convention. CONFIG_HAVE_ARM_SMCCC is enabled for architectures that may support the SMC or HVC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.
This patch doesn't provide an implementation of the declared functions. Later patches will bring in implementations and set CONFIG_HAVE_ARM_SMCCC for ARM and ARM64 respectively.
--- drivers/firmware/Kconfig | 3 ++ include/linux/arm-smccc.h | 107 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 include/linux/arm-smccc.h
drivers/firmware/Kconfig +3 -0
@@ -173,6 +173,9 @@ config QCOM_SCM_64 def_bool y depends on QCOM_SCM && ARM64 +config HAVE_ARM_SMCCC + bool + source "drivers/firmware/broadcom/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig"
include/linux/arm-smccc.h new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 34/45 arm/arm64: KVM: Implement PSCI 1.0 support
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit 58e0b2239a4d997094ba63986ef4de29ddc91d87 upstream.
PSCI 1.0 can be trivially implemented by providing the FEATURES call on top of PSCI 0.2 and returning 1.0 as the PSCI version.
We happily ignore everything else, as they are either optional or are clarifications that do not require any additional change.
PSCI 1.0 is now the default until we decide to add a userspace selection API.
--- arch/arm/kvm/psci.c | 45 +++++++++++++++++++++++++++++++++++++++++- include/kvm/arm_psci.h | 3 +++ 2 files changed, 47 insertions(+), 1 deletion(-)
arch/arm/kvm/psci.c +44 -1
@@ -232,7 +232,7 @@ static void kvm_psci_system_reset(struct kvm_vcpu *vcpu)int kvm_psci_version (struct kvm_vcpu *vcpu) {if (test_bit (KVM_ARM_VCPU_PSCI_0_2 , vcpu->arch.features)) -return KVM_ARM_PSCI_0_2 ; +return KVM_ARM_PSCI_LATEST ;return KVM_ARM_PSCI_0_1 ; }
@@ -311,6 +311,47 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)return ret; } +static int kvm_psci_1_0_call (struct kvm_vcpu *vcpu) +{ +u32 psci_fn =smccc_get_function (vcpu); +u32 feature; +unsigned long val; +int ret =1 ; + +switch (psci_fn) { +case PSCI_0_2_FN_PSCI_VERSION : + val =KVM_ARM_PSCI_1_0 ; +break ; +case PSCI_1_0_FN_PSCI_FEATURES : + feature =smccc_get_arg1 (vcpu); +switch (feature) { +case PSCI_0_2_FN_PSCI_VERSION : +case PSCI_0_2_FN_CPU_SUSPEND : +case PSCI_0_2_FN64_CPU_SUSPEND : +case PSCI_0_2_FN_CPU_OFF : +case PSCI_0_2_FN_CPU_ON : +case PSCI_0_2_FN64_CPU_ON : +case PSCI_0_2_FN_AFFINITY_INFO : +case PSCI_0_2_FN64_AFFINITY_INFO : +case PSCI_0_2_FN_MIGRATE_INFO_TYPE : +case PSCI_0_2_FN_SYSTEM_OFF : +case PSCI_0_2_FN_SYSTEM_RESET : +case PSCI_1_0_FN_PSCI_FEATURES : + val =0 ; +break ; +default : + val =PSCI_RET_NOT_SUPPORTED ; +break ; + } +break ; +default : +return kvm_psci_0_2_call (vcpu); + } + +smccc_set_retval (vcpu, val,0 ,0 ,0 ); +return ret; +} +static int kvm_psci_0_1_call (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
@@ -353,6 +394,8 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)int kvm_psci_call (struct kvm_vcpu *vcpu) {switch (kvm_psci_version (vcpu)) { +case KVM_ARM_PSCI_1_0 : +return kvm_psci_1_0_call (vcpu);case KVM_ARM_PSCI_0_2 :return kvm_psci_0_2_call (vcpu);case KVM_ARM_PSCI_0_1 :
include/kvm/arm_psci.h +3 -0
@@ -22,6 +22,9 @@#define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1)#define KVM_ARM_PSCI_0_2 PSCI_VERSION(0, 2) +#define KVM_ARM_PSCI_1_0 PSCI_VERSION(1, 0) + +#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0int kvm_psci_version (struct kvm_vcpu *vcpu);int kvm_psci_call (struct kvm_vcpu *vcpu);
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 35/45 arm/arm64: KVM: Advertise SMCCC v1.1
In reply to Viresh KumarFrom: Mark Rutland <[email protected]>
commit 09e6be12effdb33bf7210c8867bbd213b66a499e upstream.
The new SMC Calling Convention (v1.1) allows for a reduced overhead when calling into the firmware, and provides a new feature discovery mechanism.
Make it visible to KVM guests.
--- arch/arm/kvm/handle_exit.c | 2 +- arch/arm/kvm/psci.c | 24 +++++++++++++++++++++++- arch/arm64/kvm/handle_exit.c | 2 +- include/kvm/arm_psci.h | 2 +- include/linux/arm-smccc.h | 13 +++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-)
arch/arm/kvm/handle_exit.c +1 -1
@@ -43,7 +43,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)trace_kvm_hvc (*vcpu_pc (vcpu), *vcpu_reg (vcpu,0 ),kvm_vcpu_hvc_get_imm (vcpu)); - ret =kvm_psci_call (vcpu); + ret =kvm_hvc_call_handler (vcpu);if (ret <0 ) {vcpu_set_reg (vcpu,0 , ~0UL );return 1 ;
arch/arm/kvm/psci.c +23 -1
@@ -15,6 +15,7 @@* along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <linux/arm-smccc.h> #include <linux/preempt.h> #include <linux/kvm_host.h> #include <linux/wait.h>
@@ -337,6 +338,7 @@ static int kvm_psci_1_0_call(struct kvm_vcpu *vcpu)case PSCI_0_2_FN_SYSTEM_OFF :case PSCI_0_2_FN_SYSTEM_RESET :case PSCI_1_0_FN_PSCI_FEATURES : +case ARM_SMCCC_VERSION_FUNC_ID : val =0 ;break ;default :
@@ -391,7 +393,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)* Errors: * -EINVAL: Unrecognized PSCI function */ -int kvm_psci_call (struct kvm_vcpu *vcpu) +static int kvm_psci_call (struct kvm_vcpu *vcpu) {switch (kvm_psci_version (vcpu)) {case KVM_ARM_PSCI_1_0 :
@@ -404,3 +406,23 @@ int kvm_psci_call(struct kvm_vcpu *vcpu)return -EINVAL ; }; } + +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu) +{ +u32 func_id =smccc_get_function (vcpu); +u32 val =PSCI_RET_NOT_SUPPORTED ; + +switch (func_id) { +case ARM_SMCCC_VERSION_FUNC_ID : + val =ARM_SMCCC_VERSION_1_1 ; +break ; +case ARM_SMCCC_ARCH_FEATURES_FUNC_ID : +/* Nothing supported yet */ +break ; +default : +return kvm_psci_call (vcpu); + } + +smccc_set_retval (vcpu, val,0 ,0 ,0 ); +return 1 ; +}
arch/arm64/kvm/handle_exit.c +1 -1
@@ -43,7 +43,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)trace_kvm_hvc_arm64 (*vcpu_pc (vcpu),vcpu_get_reg (vcpu,0 ),kvm_vcpu_hvc_get_imm (vcpu)); - ret =kvm_psci_call (vcpu); + ret =kvm_hvc_call_handler (vcpu);if (ret <0 ) {vcpu_set_reg (vcpu,0 , ~0UL );return 1 ;
include/kvm/arm_psci.h +1 -1
@@ -27,6 +27,6 @@#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0int kvm_psci_version (struct kvm_vcpu *vcpu); -int kvm_psci_call (struct kvm_vcpu *vcpu); +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu);#endif /* __KVM_ARM_PSCI_H__ */
include/linux/arm-smccc.h +13 -0
@@ -60,6 +60,19 @@#define ARM_SMCCC_OWNER_TRUSTED_OS 50#define ARM_SMCCC_OWNER_TRUSTED_OS_END 63 +#define ARM_SMCCC_VERSION_1_0 0x10000 +#define ARM_SMCCC_VERSION_1_1 0x10001 + +#define ARM_SMCCC_VERSION_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0) + +#define ARM_SMCCC_ARCH_FEATURES_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 1) +#ifndef __ASSEMBLY__/**
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 36/45 arm/arm64: KVM: Turn kvm_psci_version into a static inline
In reply to Viresh KumarFrom: Mark Rutland <[email protected]>
commit a4097b351118e821841941a79ec77d3ce3f1c5d9 upstream.
We're about to need kvm_psci_version in HYP too. So let's turn it into a static inline, and pass the kvm structure as a second parameter (so that HYP can do a kern_hyp_va on it).
[ v4.4: account for files moved to virt/ upstream and drop switch.c
changes ]
--- arch/arm/kvm/psci.c | 12 ++---------- include/kvm/arm_psci.h | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 11 deletions(-)
arch/arm/kvm/psci.c +2 -10
@@ -120,7 +120,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)if (!vcpu)return PSCI_RET_INVALID_PARAMS ;if (!vcpu->arch.power_off) { -if (kvm_psci_version (source_vcpu) !=KVM_ARM_PSCI_0_1 ) +if (kvm_psci_version (source_vcpu, kvm) !=KVM_ARM_PSCI_0_1 )return PSCI_RET_ALREADY_ON ;else return PSCI_RET_INVALID_PARAMS ;
@@ -230,14 +230,6 @@ static void kvm_psci_system_reset(struct kvm_vcpu *vcpu)kvm_prepare_system_event (vcpu,KVM_SYSTEM_EVENT_RESET ); } -int kvm_psci_version (struct kvm_vcpu *vcpu) -{ -if (test_bit (KVM_ARM_VCPU_PSCI_0_2 , vcpu->arch.features)) -return KVM_ARM_PSCI_LATEST ; - -return KVM_ARM_PSCI_0_1 ; -} -static int kvm_psci_0_2_call (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
@@ -395,7 +387,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)*/ static int kvm_psci_call (struct kvm_vcpu *vcpu) { -switch (kvm_psci_version (vcpu)) { +switch (kvm_psci_version (vcpu, vcpu->kvm)) {case KVM_ARM_PSCI_1_0 :return kvm_psci_1_0_call (vcpu);case KVM_ARM_PSCI_0_2 :
include/kvm/arm_psci.h +20 -1
@@ -18,6 +18,7 @@#ifndef __KVM_ARM_PSCI_H__#define __KVM_ARM_PSCI_H__ +#include <linux/kvm_host.h> #include <uapi/linux/psci.h> #define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1)
@@ -26,7 +27,25 @@#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0 -int kvm_psci_version (struct kvm_vcpu *vcpu); +/* +* We need the KVM pointer independently from the vcpu as we can call +* this from HYP, and need to apply kern_hyp_va on it... +*/ +static inline int kvm_psci_version (struct kvm_vcpu *vcpu,struct kvm *kvm) +{ +/* +* Our PSCI implementation stays the same across versions from +* v0.2 onward, only adding the few mandatory functions (such +* as FEATURES with 1.0) that are required by newer +* revisions. It is thus safe to return the latest. +*/ +if (test_bit (KVM_ARM_VCPU_PSCI_0_2 , vcpu->arch.features)) +return KVM_ARM_PSCI_LATEST ; + +return KVM_ARM_PSCI_0_1 ; +} + +int kvm_hvc_call_handler (struct kvm_vcpu *vcpu);#endif /* __KVM_ARM_PSCI_H__ */
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 37/45 arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support
In reply to Viresh KumarFrom: Mark Rutland <[email protected]>
commit 6167ec5c9145cdf493722dfd80a5d48bafc4a18a upstream.
A new feature of SMCCC 1.1 is that it offers firmware-based CPU workarounds. In particular, SMCCC_ARCH_WORKAROUND_1 provides BP hardening for CVE-2017-5715.
If the host has some mitigation for this issue, report that we deal with it using SMCCC_ARCH_WORKAROUND_1, as we apply the host workaround on every guest exit.
--- arch/arm/include/asm/kvm_host.h | 6 ++++++ arch/arm/kvm/psci.c | 9 ++++++++- arch/arm64/include/asm/kvm_host.h | 5 +++++ include/linux/arm-smccc.h | 5 +++++ 4 files changed, 24 insertions(+), 1 deletion(-)
arch/arm/include/asm/kvm_host.h +6 -0
@@ -237,4 +237,10 @@ static inline void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) {}static inline void kvm_arm_clear_debug (struct kvm_vcpu *vcpu) {}static inline void kvm_arm_reset_debug_ptr (struct kvm_vcpu *vcpu) {} +static inline bool kvm_arm_harden_branch_predictor (void ) +{ +/* No way to detect it yet, pretend it is not there. */ +return false; +} +#endif /* __ARM_KVM_HOST_H__ */
arch/arm/kvm/psci.c +8 -1
@@ -403,13 +403,20 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) {u32 func_id =smccc_get_function (vcpu);u32 val =PSCI_RET_NOT_SUPPORTED ; +u32 feature;switch (func_id) {case ARM_SMCCC_VERSION_FUNC_ID : val =ARM_SMCCC_VERSION_1_1 ;break ;case ARM_SMCCC_ARCH_FEATURES_FUNC_ID : -/* Nothing supported yet */ + feature =smccc_get_arg1 (vcpu); +switch (feature) { +case ARM_SMCCC_ARCH_WORKAROUND_1 : +if (kvm_arm_harden_branch_predictor ()) + val =0 ; +break ; + }break ;default :return kvm_psci_call (vcpu);
arch/arm64/include/asm/kvm_host.h +5 -0
@@ -258,4 +258,9 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu);void kvm_arm_clear_debug (struct kvm_vcpu *vcpu);void kvm_arm_reset_debug_ptr (struct kvm_vcpu *vcpu); +static inline bool kvm_arm_harden_branch_predictor (void ) +{ +return cpus_have_cap (ARM64_HARDEN_BRANCH_PREDICTOR ); +} +#endif /* __ARM64_KVM_HOST_H__ */
include/linux/arm-smccc.h +5 -0
@@ -73,6 +73,11 @@ ARM_SMCCC_SMC_32, \ 0, 1) +#define ARM_SMCCC_ARCH_WORKAROUND_1 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0x8000) +#ifndef __ASSEMBLY__/**
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 38/45 arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit f72af90c3783d924337624659b43e2d36f1b36b4 upstream.
We want SMCCC_ARCH_WORKAROUND_1 to be fast. As fast as possible. So let's intercept it as early as we can by testing for the function call number as soon as we've identified a HVC call coming from the guest.
--- arch/arm64/kvm/hyp.S | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp.S +18 -2
@@ -15,6 +15,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <linux/arm-smccc.h> #include <linux/linkage.h> #include <asm/alternative.h>
@@ -974,10 +975,11 @@ el1_sync: // Guest trapped into EL2 lsr x2, x1, #ESR_ELx_EC_SHIFT cmp x2, #ESR_ELx_EC_HVC64 + ccmp x2, #ESR_ELx_EC_HVC32, #4, ne b.ne el1_trap - mrs x3, vttbr_el2 // If vttbr is valid, the 64bit guest - cbnz x3, el1_trap // called HVC + mrs x3, vttbr_el2 // If vttbr is valid, the guest + cbnz x3, el1_hvc_guest // called HVC /* Here, we're pretty sure the host called HVC. */ pop x2, x3
@@ -1003,6 +1005,20 @@ el1_sync: // Guest trapped into EL2 pop lr, xzr 2: eret +el1_hvc_guest: + /* + * Fastest possible path for ARM_SMCCC_ARCH_WORKAROUND_1. + * The workaround has already been applied on the host, + * so let's quickly get back to the guest. We don't bother + * restoring x1, as it can be clobbered anyway. + */ + ldr x1, [sp] // Guest's x0 + eor w1, w1, #ARM_SMCCC_ARCH_WORKAROUND_1 + cbnz w1, el1_trap + mov x0, x1 + add sp, sp, #16 + eret + el1_trap: /* * x1: ESR
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 39/45 firmware/psci: Expose PSCI conduit
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit 09a8d6d48499f93e2abde691f5800081cd858726 upstream.
In order to call into the firmware to apply workarounds, it is useful to find out whether we're using HVC or SMC. Let's expose this through the psci_ops.
--- drivers/firmware/psci.c | 28 +++++++++++++++++++++++----- include/linux/psci.h | 7 +++++++ 2 files changed, 30 insertions(+), 5 deletions(-)
drivers/firmware/psci.c +23 -5
@@ -54,7 +54,9 @@ bool psci_tos_resident_on(int cpu)return cpu == resident_cpu; } -struct psci_operations psci_ops; +struct psci_operations psci_ops = { + .conduit =PSCI_CONDUIT_NONE , +};typedef unsigned long (psci_fn )(unsigned long ,unsigned long ,unsigned long ,unsigned long );
@@ -187,6 +189,22 @@ static unsigned long psci_migrate_info_up_cpu(void) 0, 0, 0); } +static void set_conduit (enum psci_conduit conduit) +{ +switch (conduit) { +case PSCI_CONDUIT_HVC : + invoke_psci_fn = __invoke_psci_fn_hvc; +break ; +case PSCI_CONDUIT_SMC : + invoke_psci_fn = __invoke_psci_fn_smc; +break ; +default : +WARN (1 ,"Unexpected PSCI conduit %d\n" , conduit); + } + + psci_ops.conduit = conduit; +} +static int get_set_conduit_method (struct device_node *np) {const char *method;
@@ -199,9 +217,9 @@ static int get_set_conduit_method(struct device_node *np) }if (!strcmp ("hvc" , method)) { - invoke_psci_fn = __invoke_psci_fn_hvc; +set_conduit (PSCI_CONDUIT_HVC ); }else if (!strcmp ("smc" , method)) { - invoke_psci_fn = __invoke_psci_fn_smc; +set_conduit (PSCI_CONDUIT_SMC ); }else {pr_warn ("invalid \"method\" property: %s\n" , method);return -EINVAL ;
@@ -463,9 +481,9 @@ int __init psci_acpi_init(void)pr_info ("probing for conduit method from ACPI.\n" );if (acpi_psci_use_hvc ()) - invoke_psci_fn = __invoke_psci_fn_hvc; +set_conduit (PSCI_CONDUIT_HVC );else - invoke_psci_fn = __invoke_psci_fn_smc; +set_conduit (PSCI_CONDUIT_SMC );return psci_probe (); }
include/linux/psci.h +7 -0
@@ -24,6 +24,12 @@ bool psci_tos_resident_on(int cpu);bool psci_power_state_loses_context (u32 state);bool psci_power_state_is_valid (u32 state); +enum psci_conduit { +PSCI_CONDUIT_NONE , +PSCI_CONDUIT_SMC , +PSCI_CONDUIT_HVC , +}; +struct psci_operations {u32 (*get_version)(void );int (*cpu_suspend)(u32 state,unsigned long entry_point);
@@ -33,6 +39,7 @@ struct psci_operations {int (*affinity_info)(unsigned long target_affinity,unsigned long lowest_affinity_level);int (*migrate_info_type)(void ); +enum psci_conduit conduit; };extern struct psci_operations psci_ops;
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 40/45 firmware/psci: Expose SMCCC version through psci_ops
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit e78eef554a912ef6c1e0bbf97619dafbeae3339f upstream.
Since PSCI 1.0 allows the SMCCC version to be (indirectly) probed, let's do that at boot time, and expose the version of the calling convention as part of the psci_ops structure.
--- drivers/firmware/psci.c | 28 ++++++++++++++++++++++++++++ include/linux/psci.h | 6 ++++++ 2 files changed, 34 insertions(+)
drivers/firmware/psci.c +28 -0
@@ -13,6 +13,7 @@#define pr_fmt (fmt) "psci: " fmt +#include <linux/arm-smccc.h> #include <linux/errno.h> #include <linux/linkage.h> #include <linux/of.h>
@@ -56,6 +57,7 @@ bool psci_tos_resident_on(int cpu)struct psci_operations psci_ops = { .conduit =PSCI_CONDUIT_NONE , + .smccc_version =SMCCC_VERSION_1_0 , }; typedef unsigned long (psci_fn)(unsigned long, unsigned long,
@@ -320,6 +322,31 @@ static void __init psci_init_migrate(void)pr_info ("Trusted OS resident on physical CPU 0x%lx\n" , cpuid); } +static void __init psci_init_smccc (void ) +{ +u32 ver =ARM_SMCCC_VERSION_1_0 ; +int feature; + + feature =psci_features (ARM_SMCCC_VERSION_FUNC_ID ); + +if (feature !=PSCI_RET_NOT_SUPPORTED ) { +u32 ret; + ret =invoke_psci_fn (ARM_SMCCC_VERSION_FUNC_ID ,0 ,0 ,0 ); +if (ret ==ARM_SMCCC_VERSION_1_1 ) { + psci_ops.smccc_version =SMCCC_VERSION_1_1 ; + ver = ret; + } + } + +/* +* Conveniently, the SMCCC and PSCI versions are encoded the +* same way. No, this isn't accidental. +*/ +pr_info ("SMC Calling Convention v%d.%d\n" , +PSCI_VERSION_MAJOR (ver),PSCI_VERSION_MINOR (ver)); + +} +static void __init psci_0_2_set_functions (void ) {pr_info ("Using standard PSCI v0.2 function IDs\n" );
@@ -368,6 +395,7 @@ static int __init psci_probe(void)psci_init_migrate ();if (PSCI_VERSION_MAJOR (ver) >=1 ) { +psci_init_smccc ();psci_init_cpu_suspend ();psci_init_system_suspend (); }
include/linux/psci.h +6 -0
@@ -30,6 +30,11 @@ enum psci_conduit { PSCI_CONDUIT_HVC, }; +enum smccc_version { +SMCCC_VERSION_1_0 , +SMCCC_VERSION_1_1 , +}; +struct psci_operations {u32 (*get_version)(void );int (*cpu_suspend)(u32 state,unsigned long entry_point);
@@ -40,6 +45,7 @@ struct psci_operations { unsigned long lowest_affinity_level);int (*migrate_info_type)(void );enum psci_conduit conduit; +enum smccc_version smccc_version; };extern struct psci_operations psci_ops;
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 41/45 arm/arm64: smccc: Make function identifiers an unsigned quantity
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit ded4c39e93f3b72968fdb79baba27f3b83dad34c upstream.
Function identifiers are a 32bit, unsigned quantity. But we never tell so to the compiler, resulting in the following:
4ac: b26187e0 mov x0, #0xffffffff80000001
We thus rely on the firmware narrowing it for us, which is not always a reasonable expectation.
--- include/linux/arm-smccc.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/arm-smccc.h +3 -2
@@ -16,6 +16,7 @@#include <linux/linkage.h> #include <linux/types.h> +#include <uapi/linux/const.h> /* * This file provides common defines for ARM SMC Calling Convention as
@@ -23,8 +24,8 @@* http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html */ -#define ARM_SMCCC_STD_CALL 0 -#define ARM_SMCCC_FAST_CALL 1 +#define ARM_SMCCC_STD_CALL _AC(0,U) +#define ARM_SMCCC_FAST_CALL _AC(1,U)#define ARM_SMCCC_TYPE_SHIFT 31#define ARM_SMCCC_SMC_32 0
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 42/45 arm/arm64: smccc: Implement SMCCC v1.1 inline primitive
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit f2d3b2e8759a5833df6f022e42df2d581e6d843c upstream.
One of the major improvement of SMCCC v1.1 is that it only clobbers the first 4 registers, both on 32 and 64bit. This means that it becomes very easy to provide an inline version of the SMC call primitive, and avoid performing a function call to stash the registers that would otherwise be clobbered by SMCCC v1.0.
--- include/linux/arm-smccc.h | 141 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+)
include/linux/arm-smccc.h +141 -0
@@ -122,5 +122,146 @@ asmlinkage void arm_smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a5, unsigned long a6, unsigned long a7, struct arm_smccc_res *res); +/* SMCCC v1.1 implementation madness follows */ +#ifdef CONFIG_ARM64 + +#define SMCCC_SMC_INST "smc #0" +#define SMCCC_HVC_INST "hvc #0" + +#elif defined(CONFIG_ARM ) +#include <asm/opcodes-sec.h> +#include <asm/opcodes-virt.h> + +#define SMCCC_SMC_INST __SMC(0) +#define SMCCC_HVC_INST __HVC(0) + +#endif + +#define ___count_args (_0, _1, _2, _3, _4, _5, _6, _7, _8, x, ...) x + +#define __count_args (...) \ + ___count_args(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0) + +#define __constraint_write_0 \ + "+r" (r0), "=&r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_1 \ + "+r" (r0), "+r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_2 \ + "+r" (r0), "+r" (r1), "+r" (r2), "=&r" (r3) +#define __constraint_write_3 \ + "+r" (r0), "+r" (r1), "+r" (r2), "+r" (r3) +#define __constraint_write_4 __constraint_write_3 +#define __constraint_write_5 __constraint_write_4 +#define __constraint_write_6 __constraint_write_5 +#define __constraint_write_7 __constraint_write_6 + +#define __constraint_read_0 +#define __constraint_read_1 +#define __constraint_read_2 +#define __constraint_read_3 +#define __constraint_read_4 "r" (r4) +#define __constraint_read_5 __constraint_read_4, "r" (r5) +#define __constraint_read_6 __constraint_read_5, "r" (r6) +#define __constraint_read_7 __constraint_read_6, "r" (r7) + +#define __declare_arg_0 (a0, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register unsigned long r1 asm("r1"); \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_1 (a0, a1, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_2 (a0, a1, a2, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register unsigned long r3 asm("r3") + +#define __declare_arg_3 (a0, a1, a2, a3, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register typeof(a3) r3 asm("r3") = a3 + +#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \ + __declare_arg_3(a0, a1, a2, a3, res); \ + register typeof(a4) r4 asm("r4") = a4 + +#define __declare_arg_5 (a0, a1, a2, a3, a4, a5, res) \ + __declare_arg_4(a0, a1, a2, a3, a4, res); \ + register typeof(a5) r5 asm("r5") = a5 + +#define __declare_arg_6 (a0, a1, a2, a3, a4, a5, a6, res) \ + __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ + register typeof(a6) r6 asm("r6") = a6 + +#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ + __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ + register typeof(a7) r7 asm("r7") = a7 + +#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__) +#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__) + +#define ___constraints (count) \ + : __constraint_write_ ## count \ + : __constraint_read_ ## count \ + : "memory" +#define __constraints (count) ___constraints(count) + +/* +* We have an output list that is not necessarily used, and GCC feels +* entitled to optimise the whole sequence away. "volatile" is what +* makes it stick. +*/ +#define __arm_smccc_1_1 (inst, ...) \ + do { \ + __declare_args(__count_args(__VA_ARGS__), __VA_ARGS__); \ + asm volatile(inst "\n" \ + __constraints(__count_args(__VA_ARGS__))); \ + if (___res) \ + *___res = (typeof(*___res)){r0, r1, r2, r3}; \ + } while (0) + +/* +* arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call +* +* This is a variadic macro taking one to eight source arguments, and +* an optional return structure. +* +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 3 +* +* This macro is used to make SMC calls following SMC Calling Convention v1.1. +* The content of the supplied param are copied to registers 0 to 7 prior +* to the SMC instruction. The return values are updated with the content +* from register 0 to 3 on return from the SMC instruction if not NULL. +*/ +#define arm_smccc_1_1_smc (...) __arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__) + +/* +* arm_smccc_1_1_hvc() - make an SMCCC v1.1 compliant HVC call +* +* This is a variadic macro taking one to eight source arguments, and +* an optional return structure. +* +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 3 +* +* This macro is used to make HVC calls following SMC Calling Convention v1.1. +* The content of the supplied param are copied to registers 0 to 7 prior +* to the HVC instruction. The return values are updated with the content +* from register 0 to 3 on return from the HVC instruction if not NULL. +*/ +#define arm_smccc_1_1_hvc (...) __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__) +#endif /*__ASSEMBLY__*/ #endif /*__LINUX_ARM_SMCCC_H*/
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 43/45 arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP hardening support
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit b092201e0020614127f495c092e0a12d26a2116e upstream.
Add the detection and runtime code for ARM_SMCCC_ARCH_WORKAROUND_1. It is lovely. Really.
--- arch/arm64/kernel/bpi.S | 20 ++++++++++ arch/arm64/kernel/cpu_errata.c | 68 +++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-)
arch/arm64/kernel/bpi.S +20 -0
@@ -17,6 +17,7 @@ */ #include <linux/linkage.h> +#include <linux/arm-smccc.h> .macro ventry target .rept 31
@@ -77,3 +78,22 @@ ENTRY(__psci_hyp_bp_inval_start) ldp x0, x1, [sp, #(16 * 8)] add sp, sp, #(8 * 18) ENTRY(__psci_hyp_bp_inval_end) + +.macro smccc_workaround_1 inst + sub sp, sp, #(8 * 4) + stp x2, x3, [sp, #(8 * 0)] + stp x0, x1, [sp, #(8 * 2)] + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1 + \inst #0 + ldp x2, x3, [sp, #(8 * 0)] + ldp x0, x1, [sp, #(8 * 2)] + add sp, sp, #(8 * 4) +.endm + +ENTRY(__smccc_workaround_1_smc_start) + smccc_workaround_1 smc +ENTRY(__smccc_workaround_1_smc_end) + +ENTRY(__smccc_workaround_1_hvc_start) + smccc_workaround_1 hvc +ENTRY(__smccc_workaround_1_hvc_end)
arch/arm64/kernel/cpu_errata.c +67 -1
96 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 44/45 arm64: Kill PSCI_GET_VERSION as a variant-2 workaround
In reply to Viresh KumarFrom: Marc Zyngier <[email protected]>
commit 3a0a397ff5ff8b56ca9f7908b75dee6bf0b5fabb upstream.
Now that we've standardised on SMCCC v1.1 to perform the branch prediction invalidation, let's drop the previous band-aid. If vendors haven't updated their firmware to do SMCCC 1.1, they haven't updated PSCI either, so we don't loose anything.
--- arch/arm64/kernel/bpi.S | 24 ------------------ arch/arm64/kernel/cpu_errata.c | 45 ++++++++++------------------------ 2 files changed, 13 insertions(+), 56 deletions(-)
arch/arm64/kernel/bpi.S +0 -24
@@ -54,30 +54,6 @@ ENTRY(__bp_harden_hyp_vecs_start) vectors __kvm_hyp_vector .endr ENTRY(__bp_harden_hyp_vecs_end) -ENTRY(__psci_hyp_bp_inval_start) - sub sp, sp, #(8 * 18) - stp x16, x17, [sp, #(16 * 0)] - stp x14, x15, [sp, #(16 * 1)] - stp x12, x13, [sp, #(16 * 2)] - stp x10, x11, [sp, #(16 * 3)] - stp x8, x9, [sp, #(16 * 4)] - stp x6, x7, [sp, #(16 * 5)] - stp x4, x5, [sp, #(16 * 6)] - stp x2, x3, [sp, #(16 * 7)] - stp x0, x1, [sp, #(16 * 8)] - mov x0, #0x84000000 - smc #0 - ldp x16, x17, [sp, #(16 * 0)] - ldp x14, x15, [sp, #(16 * 1)] - ldp x12, x13, [sp, #(16 * 2)] - ldp x10, x11, [sp, #(16 * 3)] - ldp x8, x9, [sp, #(16 * 4)] - ldp x6, x7, [sp, #(16 * 5)] - ldp x4, x5, [sp, #(16 * 6)] - ldp x2, x3, [sp, #(16 * 7)] - ldp x0, x1, [sp, #(16 * 8)] - add sp, sp, #(8 * 18) -ENTRY(__psci_hyp_bp_inval_end) .macro smccc_workaround_1 inst sub sp, sp, #(8 * 4)
arch/arm64/kernel/cpu_errata.c +13 -32
119 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 45/45 arm64: futex: Mask __user pointers prior to dereference
In reply to Viresh KumarFrom: Will Deacon <[email protected]>
commit 91b2d3442f6a44dce875670d702af22737ad5eff upstream.
The arm64 futex code has some explicit dereferencing of user pointers where performing atomic operations in response to a futex command. This patch uses masking to limit any speculative futex operations to within the user address space.
--- arch/arm64/include/asm/futex.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm64/include/asm/futex.h +6 -3
@@ -53,9 +53,10 @@ : "memory")static inline int -arch_futex_atomic_op_inuser (int op,int oparg,int *oval,u32 __user *uaddr) +arch_futex_atomic_op_inuser (int op,int oparg,int *oval,u32 __user *_uaddr) {int oldval =0 , ret, tmp; +u32 __user *uaddr =__uaccess_mask_ptr (_uaddr);pagefault_disable ();
@@ -93,15 +94,17 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr) }static inline int -futex_atomic_cmpxchg_inatomic (u32 *uval,u32 __user *uaddr, +futex_atomic_cmpxchg_inatomic (u32 *uval,u32 __user *_uaddr,u32 oldval,u32 newval) {int ret =0 ;u32 val, tmp; +u32 __user *uaddr; -if (!access_ok (VERIFY_WRITE , uaddr,sizeof (u32))) +if (!access_ok (VERIFY_WRITE , _uaddr,sizeof (u32)))return -EFAULT ; + uaddr =__uaccess_mask_ptr (_uaddr); asmvolatile ("// futex_atomic_cmpxchg_inatomic\n" ALTERNATIVE("nop", SET_PSTATE_PAN(0), ARM64_HAS_PAN, CONFIG_ARM64_PAN)" prfm pstl1strm, %2\n"
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Greg KH
maintainerQuoted 37 lines · Viresh Kumar
Hello,
Here is an attempt to backport arm64 spectre patches to v4.4 stable tree.
I have started this backport with Mark Rutland's backport of Spectre to 4.9 [1] and tried applying the upstream version of them over 4.4 and resolved conflicts by checking how they have been resolved in 4.9.
I had to pick few extra upstream patches to avoid unnecessary conflicts (upstream commit ids mentioned):
a842789837c0arm64: remove duplicate macro__KERNEL__check64f8ebaf115bmm/kasan: add API to check memory regionsbffe1baff5d5arm64: kasan: instrument user memory access API92406f0cc9e3arm64: cpufeature: Add scope for capability check9eb8a2cdf65carm64: cputype info for Broadcom Vulcan0d90718871fearm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs98dd64f34f47ARM: 8478/2: arm/arm64: add arm-smcccI had to drop few patches as well as they weren't getting applied properly due to missing files/features (upstream commit id mentioned):
93f339ef4175arm64: cpufeature:__this_cpu_has_cap()shouldn't stop early3c31fa5a06b4arm64: Run enable method for errata work arounds on late CPUs6840bdd73d07arm64: KVM: Use per-CPU vector when BP hardening is enabled90348689d500arm64: KVM: MakePSCI_VERSIONa fast pathSince v4.4 doesn't contain
arch/arm/kvm/hyp/switch.cfile, changes for it are dropped from some of the patches. The commit log of specific patches are updated with this information.Also for commit id (from 4.9 stable):
c24c205d2528arm64: AddARM_SMCCC_ARCH_WORKAROUND_1BP hardening support
Quoted 8 lines
I have dropped
arch/arm64/crypto/sha256-core.Sandsha512-core.Sfiles as they weren't part of the upstream commit. Not sure why it was included by Mark as the commit log doesn't provide any reasoning for it.The patches in this series are pushed here [2].
This is only build/boot tested by me as I don't have access to the required test-suite which can verify spectre mitigations.
Thanks for doing this work.
Quoted 1 line
@Julien: Can you please help reviewing / testing them ? Thanks.
Julien, I need yours, or someone from ARM to sign off on these patches as working properly before I can accept them.
thanks,
greg k-h
Hi Viresh,
Thanks for doing that work and having provided a detailed description for the backport process.
I haven't finished reviewing/testing the whole series yet, but I have some concerns (do let me know in case I'm missing something and that it turns out these aren't really issues).
Please see comments below.
Quoted 5 lines · Viresh Kumar
Hello,
Here is an attempt to backport arm64 spectre patches to v4.4 stable tree.
Quoted 8 lines
I have started this backport with Mark Rutland's backport of Spectre to 4.9 [1] and tried applying the upstream version of them over 4.4 and resolved conflicts by checking how they have been resolved in 4.9.
I had to pick few extra upstream patches to avoid unnecessary conflicts (upstream commit ids mentioned):
a842789837c0arm64: remove duplicate macro__KERNEL__check
I'm a bit unfamiliar with what gets or doesn't get backported. My understanding is that we try to backport only what's necessary to reduce the noise and potential introduction of issues in stable releases.
This commit is just a cleanup and (while valid) doesn't really seem necessary (and potential conflicts from its absence would easily be resolved IMO). So I'm just concerned that this doesn't constitute a candidate for back porting (someone can correct me if I'm wrong).
Quoted 8 lines
64f8ebaf115bmm/kasan: add API to check memory regionsbffe1baff5d5arm64: kasan: instrument user memory access API92406f0cc9e3arm64: cpufeature: Add scope for capability check9eb8a2cdf65carm64: cputype info for Broadcom Vulcan0d90718871fearm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs98dd64f34f47ARM: 8478/2: arm/arm64: add arm-smccc
Quoted 5 lines
I had to drop few patches as well as they weren't getting applied properly due to missing files/features (upstream commit id mentioned):
93f339ef4175arm64: cpufeature:__this_cpu_has_cap()shouldn't stop early3c31fa5a06b4arm64: Run enable method for errata work arounds on late CPUs
Looking at this and at the patches that implement the BP callbacks, we need that patch or an equivalent, otherwise we won't be using the correct vectors for late CPUs...
I appreciate the code has changed, but it might be worth considering 6a6efbb45b7d95c84840010095367eb06a64f342 as a needed dependency for BP hardening.
Quoted 1 line
6840bdd73d07arm64: KVM: Use per-CPU vector when BP hardening is enabled
I don't believe we can do without this patch. Otherwise we're only using the vector that has no mitigation for kvm guests.
In v4.4, it looks like the contents of virt/kvm/arm/arm.c were contained in arch/arm/kvm/arm.c (yes, even for amr64). Are there other reasons this patch was not applying?
Thanks,
Signature · 1 line
Julien Thierry
Quoted 15 lines · Julien Thierry
Quoted 5 lines · Viresh Kumar
Hello,
Here is an attempt to backport arm64 spectre patches to v4.4 stable tree.
Quoted 8 lines
I have started this backport with Mark Rutland's backport of Spectre to 4.9 [1] and tried applying the upstream version of them over 4.4 and resolved conflicts by checking how they have been resolved in 4.9.
I had to pick few extra upstream patches to avoid unnecessary conflicts (upstream commit ids mentioned):
a842789837c0arm64: remove duplicate macro__KERNEL__check
Quoted 8 lines
I'm a bit unfamiliar with what gets or doesn't get backported. My understanding is that we try to backport only what's necessary to reduce the noise and potential introduction of issues in stable releases.
This commit is just a cleanup and (while valid) doesn't really seem necessary (and potential conflicts from its absence would easily be resolved IMO). So I'm just concerned that this doesn't constitute a candidate for back porting (someone can correct me if I'm wrong).
Dropped now.
Quoted 14 lines
Quoted 8 lines
64f8ebaf115bmm/kasan: add API to check memory regionsbffe1baff5d5arm64: kasan: instrument user memory access API92406f0cc9e3arm64: cpufeature: Add scope for capability check9eb8a2cdf65carm64: cputype info for Broadcom Vulcan0d90718871fearm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs98dd64f34f47ARM: 8478/2: arm/arm64: add arm-smcccQuoted 5 lines
I had to drop few patches as well as they weren't getting applied properly due to missing files/features (upstream commit id mentioned):
93f339ef4175arm64: cpufeature:__this_cpu_has_cap()shouldn't stop early3c31fa5a06b4arm64: Run enable method for errata work arounds on late CPUs
Quoted 7 lines
Looking at this and at the patches that implement the BP callbacks, we need that patch or an equivalent, otherwise we won't be using the correct vectors for late CPUs...
I appreciate the code has changed, but it might be worth considering
6a6efbb45b7d95c84840010095367eb06a64f342as a needed dependency for BP hardening.
Okay, I had to pick two more patches for a clean rebase.
d4a7e845dab5 arm64: Introduce cpu_die_early7242dbf2e4da arm64: Move cpu_die_early to smp.c545fe20330c3 arm64: Verify CPU errata work arounds on hotplugged CPU 0365babc6c1f arm64: Run enable method for errata work arounds on late CPUs
(You can fetch my tree again to get these commit ids)
Quoted 8 lines
Quoted 1 line
6840bdd73d07arm64: KVM: Use per-CPU vector when BP hardening is enabledI don't believe we can do without this patch. Otherwise we're only using the vector that has no mitigation for kvm guests.
In v4.4, it looks like the contents of
virt/kvm/arm/arm.cwere contained inarch/arm/kvm/arm.c(yes, even for amr64). Are there other reasons this patch was not applying?
It was something other than this I believe, I have already used these paths for many other patches.
Anyway, KVM stuff is mostly dropped now, just that I had to keep the changes to arm-smccc.h from those patches.
I have updated the stable/v4.4.y/spectre branch with all the changes you suggested and pushed the earlier version to stable/v4.4.y/spectre-v1 branch.
Will it be possible for you to have a look at stable/v4.4.y/spectre branch to see if it is okay, so I can send the v2 version ? Don't want to spam list unnecessary with so many patches :)
Thanks for your help Julien, really appreciate it.
Signature · 1 line
viresh
Hi Viresh,
Quoted 2 lines · Viresh Kumar
Quoted 1 line · Julien Thierry
On 14/06/2019 04:07, Viresh Kumar wrote:
[...]
Quoted 7 lines
I have updated the stable/v4.4.y/spectre branch with all the changes you suggested and pushed the earlier version to stable/v4.4.y/spectre-v1 branch.
Will it be possible for you to have a look at stable/v4.4.y/spectre branch to see if it is okay, so I can send the v2 version ? Don't want to spam list unnecessary with so many patches :)
I've given a run for your new version and it looks like the BP hardening is not taking place.
I believe the culprit is update_cpu_capabilities(), which in 4.4 tests for capability.desc to know where to stop (and requires all valid capabilities to have a description).
Since commit 644c2ae19 "arm64: cpufeature: Test 'matches' pointer to find the end of the list", the restriction was lifted. Unfortunately for you, the errata workarounds using BP hardening were introduced after that commit and were not given a description. So they do not get applied and also, in the current state, would prevent following entries in the errata table from getting applied.
So either 644c2ae19 needs to be backported, or the workarounds need to be given descriptions.
I'll let you know if I find anything else.
Cheers,
Signature · 1 line
Julien Thierry
Quoted 14 lines · Julien Thierry
I've given a run for your new version and it looks like the BP hardening is not taking place.
I believe the culprit is
update_cpu_capabilities(), which in 4.4 tests for capability.desc to know where to stop (and requires all valid capabilities to have a description).Since commit
644c2ae19"arm64: cpufeature: Test 'matches' pointer to find the end of the list", the restriction was lifted. Unfortunately for you, the errata workarounds using BP hardening were introduced after that commit and were not given a description. So they do not get applied and also, in the current state, would prevent following entries in the errata table from getting applied.
Quoted 2 lines
So either
644c2ae19needs to be backported, or the workarounds need to be given descriptions.
Okay, I have backported it and pushed it to my branch now. Thanks.
Signature · 1 line
viresh
Hi Viresh,
After discussing it internally, we think it would be better to drop the patches related to KVM for now. In 4.4 KVM Arm not very mature and has changed a lot since then.
If someone wants to backport the mitigations for KVM in 4.4, it should be done as a separate series. The series is big enough as it is. For now, the main point is to focus on the kernel itself.
Sorry you already went through some trouble to backport those. But dropping will simply review and testing, and as mentioned, 4.4 KVM on Arm is probably not worth the hassle.
Cheers,
Signature · 1 line
Julien Thierry
Hi Viresh,
Quoted 41 lines · Viresh Kumar
Hello,
Here is an attempt to backport arm64 spectre patches to v4.4 stable tree.
I have started this backport with Mark Rutland's backport of Spectre to 4.9 [1] and tried applying the upstream version of them over 4.4 and resolved conflicts by checking how they have been resolved in 4.9.
I had to pick few extra upstream patches to avoid unnecessary conflicts (upstream commit ids mentioned):
a842789837c0arm64: remove duplicate macro__KERNEL__check64f8ebaf115bmm/kasan: add API to check memory regionsbffe1baff5d5arm64: kasan: instrument user memory access API92406f0cc9e3arm64: cpufeature: Add scope for capability check9eb8a2cdf65carm64: cputype info for Broadcom Vulcan0d90718871fearm64: cputype: Add MIDR values for Cavium ThunderX2 CPUs98dd64f34f47ARM: 8478/2: arm/arm64: add arm-smcccI had to drop few patches as well as they weren't getting applied properly due to missing files/features (upstream commit id mentioned):
93f339ef4175arm64: cpufeature:__this_cpu_has_cap()shouldn't stop early3c31fa5a06b4arm64: Run enable method for errata work arounds on late CPUs6840bdd73d07arm64: KVM: Use per-CPU vector when BP hardening is enabled90348689d500arm64: KVM: MakePSCI_VERSIONa fast pathSince v4.4 doesn't contain
arch/arm/kvm/hyp/switch.cfile, changes for it are dropped from some of the patches. The commit log of specific patches are updated with this information.Also for commit id (from 4.9 stable):
c24c205d2528arm64: AddARM_SMCCC_ARCH_WORKAROUND_1BP hardening supportI have dropped
arch/arm64/crypto/sha256-core.Sandsha512-core.Sfiles as they weren't part of the upstream commit. Not sure why it was included by Mark as the commit log doesn't provide any reasoning for it.
Quoted 7 lines
The patches in this series are pushed here [2].
This is only build/boot tested by me as I don't have access to the required test-suite which can verify spectre mitigations.
@Julien: Can you please help reviewing / testing them ? Thanks.
Since there were seems to be a lot of changes between the current branch and the patch series you posted, it would probably be good to post a new version on the mailing list once you believe you have them in a good shape.
Testing the branch is fine, but reviewing is definitely something that should happen on patches posted on the mailing list.
Thanks,
Signature · 1 line
Julien Thierry