Split off nVHE hyp code
v2 cover Split off nVHE hyp code
Refactor files in arch/arm64/kvm/hyp to compile all code which runs in EL2 under nVHE into separate object files from the rest of KVM. This is done in preparation for being able to unmap hyp code from EL1 and kernel code/data from EL2 but has other benefits too, notably:
* safe use of KASAN/UBSAN/GCOV instrumentation on VHE code,
* cleaner HVC API,
* no need for __hyp_text annotations.
nVHE-specific code is moved to hyp/nvhe and compiled with custom build rules similar to those used by EFI stub. Shared source files are compiled under both VHE and nVHE build rules. Where a source file contained both VHE and nVHE code, it is split into a shared header file and two C source files. This is done one file per commit to make review easier.
All nVHE symbols are prefixed with "__kvm_nvhe_" to avoid collisions with VHE variants (also inspired by EFI stub). Since this prefixes unresolved symbols too, image-vars.h contains a list of kernel symbol aliases where nVHE code still refers to kernel proper. The list grows fairly large as the patch series progresses and code is moved around, but at the end contains 17 symbols. These remaining dependencies on kernel proper will be further reduced in the future.
No functional changes are intended but code was simplified whenever the refactoring made it possible.
Tested by running kvm-unit-tests on QEMU 5.0 with VHE/nVHE and GIC v2/v3.
Dual compilation of code shared by VHE/nVHE increase the size of the kernel. Bloat-o-meter vmlinux diff shows an increase of 21 KB on the ELF symbol level. Size of Image.gz is up by 10 KB; size of Image is unchanged, presumably due to ELF section alignment.
This is based off Fuad Tabba's patch series "KVM: arm64: Tidy up arch Kconfig and Makefiles". Available in branch 'topic/el2-obj-v2' of git repo:
https://android-kvm.googlesource.com/linux
Changes v1 -> v2:
* change nVHE symbol prefix from __hyp_text_ to __kvm_nvhe_
* rename __HYPERVISOR__ macro to __KVM_NVHE_HYPERVISOR__
* use hcall jump table instead of array of function pointers
* drop patch to unify HVC callers
* move __smccc_workaround_1_smc to own file
* header guards for hyp/*.h
* improve helpers for handling VHE/nVHE hyp syms in kernel proper
* improve commit messages, cover letter
-David
David Brazdil (14):
arm64: kvm: Fix symbol dependency in __hyp_call_panic_nvhe
arm64: kvm: Move __smccc_workaround_1_smc to .rodata
arm64: kvm: Formalize hypcall ABI
arm64: kvm: Add build rules for separate nVHE object files
arm64: kvm: Build hyp-entry.S separately for VHE/nVHE
arm64: kvm: Split hyp/tlb.c to VHE/nVHE
arm64: kvm: Split hyp/switch.c to VHE/nVHE
arm64: kvm: Split hyp/debug-sr.c to VHE/nVHE
arm64: kvm: Split hyp/sysreg-sr.c to VHE/nVHE
arm64: kvm: Split hyp/timer-sr.c to VHE/nVHE
arm64: kvm: Compile remaining hyp/ files for both VHE/nVHE
arm64: kvm: Add comments around __kvm_nvhe_ symbol aliases
arm64: kvm: Remove __hyp_text macro, use build rules instead
arm64: kvm: Lift instrumentation restrictions on VHE
arch/arm64/include/asm/kvm_asm.h | 29 +- arch/arm64/include/asm/kvm_emulate.h | 2 +- arch/arm64/include/asm/kvm_host.h | 12 +- arch/arm64/include/asm/kvm_host_hypercalls.h | 59 ++ arch/arm64/include/asm/kvm_hyp.h | 15 +- arch/arm64/include/asm/kvm_mmu.h | 16 +- arch/arm64/include/asm/mmu.h | 7 - arch/arm64/kernel/cpu_errata.c | 4 +- arch/arm64/kernel/image-vars.h | 43 ++ arch/arm64/kvm/arm.c | 6 +- arch/arm64/kvm/hyp.S | 18 +- arch/arm64/kvm/hyp/Makefile | 13 +- arch/arm64/kvm/hyp/aarch32.c | 6 +- arch/arm64/kvm/hyp/debug-sr.c | 214 +----- arch/arm64/kvm/hyp/debug-sr.h | 170 +++++ arch/arm64/kvm/hyp/entry.S | 1 - arch/arm64/kvm/hyp/fpsimd.S | 1 - arch/arm64/kvm/hyp/hyp-entry.S | 77 +-- arch/arm64/kvm/hyp/nvhe/Makefile | 42 ++ arch/arm64/kvm/hyp/nvhe/debug-sr.c | 77 +++ arch/arm64/kvm/hyp/nvhe/switch.c | 271 ++++++++ arch/arm64/kvm/hyp/nvhe/sysreg-sr.c | 56 ++ arch/arm64/kvm/hyp/nvhe/timer-sr.c | 43 ++ arch/arm64/kvm/hyp/nvhe/tlb.c | 67 ++ arch/arm64/kvm/hyp/smccc_wa.S | 30 + arch/arm64/kvm/hyp/switch.c | 688 +------------------ arch/arm64/kvm/hyp/switch.h | 443 ++++++++++++ arch/arm64/kvm/hyp/sysreg-sr.c | 233 +------ arch/arm64/kvm/hyp/sysreg-sr.h | 216 ++++++ arch/arm64/kvm/hyp/timer-sr.c | 38 +- arch/arm64/kvm/hyp/tlb.c | 168 +---- arch/arm64/kvm/hyp/tlb.h | 131 ++++ arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 4 +- arch/arm64/kvm/hyp/vgic-v3-sr.c | 130 ++-- arch/arm64/kvm/va_layout.c | 2 +- scripts/kallsyms.c | 1 + 36 files changed, 1867 insertions(+), 1466 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_host_hypercalls.h create mode 100644 arch/arm64/kvm/hyp/debug-sr.h create mode 100644 arch/arm64/kvm/hyp/nvhe/Makefile create mode 100644 arch/arm64/kvm/hyp/nvhe/debug-sr.c create mode 100644 arch/arm64/kvm/hyp/nvhe/switch.c create mode 100644 arch/arm64/kvm/hyp/nvhe/sysreg-sr.c create mode 100644 arch/arm64/kvm/hyp/nvhe/timer-sr.c create mode 100644 arch/arm64/kvm/hyp/nvhe/tlb.c create mode 100644 arch/arm64/kvm/hyp/smccc_wa.S create mode 100644 arch/arm64/kvm/hyp/switch.h create mode 100644 arch/arm64/kvm/hyp/sysreg-sr.h create mode 100644 arch/arm64/kvm/hyp/tlb.h
Signature · 1 line
2.26.2
PATCH v2 1/14 arm64: kvm: Fix symbol dependency in __hyp_call_panic_nvhe
__hyp_call_panic_nvhe contains inline assembly which did not declare its dependency on the __hyp_panic_string symbol.
The static-declared string has previously been kept alive because of a use in __hyp_call_panic_vhe. Fix this in preparation for separating the source files between VHE and nVHE when the two users land in two different compilation units. The static variable otherwise gets dropped when compiling the nVHE source file, causing an undefined symbol linker error later.
--- arch/arm64/kvm/hyp/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp/switch.c +1 -1
@@ -836,7 +836,7 @@ static void __hyp_text __hyp_call_panic_nvhe(u64 spsr, u64 elr, u64 par,* making sure it is a kernel address and not a PC-relative * reference. */ - asmvolatile ("ldr %0, =__hyp_panic_string" :"=r" (str_va)); + asmvolatile ("ldr %0, =%1" :"=r" (str_va) :"S" (__hyp_panic_string)); __hyp_do_panic(str_va, spsr, elr,
Signature · 6 lines
2.26.2 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v2 2/14 arm64: kvm: Move __smccc_workaround_1_smc to .rodata
In reply to David BrazdilThis snippet of assembly is used by cpu_errata.c to overwrite parts of KVM hyp vector. Move it to its own source file and change its ELF section to .rodata.
--- arch/arm64/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/hyp-entry.S | 16 ---------------- arch/arm64/kvm/hyp/smccc_wa.S | 30 ++++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 arch/arm64/kvm/hyp/smccc_wa.S
arch/arm64/kvm/hyp/Makefile +1 -0
@@ -7,6 +7,7 @@ ccflags-y += -fno-stack-protector -DDISABLE_BRANCH_PROFILING \ $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_KVM) += hyp.o +obj-$(CONFIG_KVM_INDIRECT_VECTORS) += smccc_wa.o hyp-y := vgic-v3-sr.o timer-sr.o aarch32.o vgic-v2-cpuif-proxy.o sysreg-sr.o \ debug-sr.o entry.o switch.o fpsimd.o tlb.o hyp-entry.o
arch/arm64/kvm/hyp/hyp-entry.S +0 -16
@@ -319,20 +319,4 @@ SYM_CODE_START(__bp_harden_hyp_vecs) 1: .org __bp_harden_hyp_vecs + __BP_HARDEN_HYP_VECS_SZ .org 1b SYM_CODE_END(__bp_harden_hyp_vecs) - - .popsection - -SYM_CODE_START(__smccc_workaround_1_smc) - esb - sub sp, sp, #(8 * 4) - stp x2, x3, [sp, #(8 * 0)] - stp x0, x1, [sp, #(8 * 2)] - mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1 - smc #0 - ldp x2, x3, [sp, #(8 * 0)] - ldp x0, x1, [sp, #(8 * 2)] - add sp, sp, #(8 * 4) -1: .org __smccc_workaround_1_smc + __SMCCC_WORKAROUND_1_SMC_SZ - .org 1b -SYM_CODE_END(__smccc_workaround_1_smc) #endif
arch/arm64/kvm/hyp/smccc_wa.S new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2015-2018 - ARM Ltd + * Author: Marc Zyngier <[email protected]> + */ + +#include <linux/arm-smccc.h> + +#include <asm/kvm_asm.h> +#include <asm/kvm_mmu.h> + + /* + * This is not executed directly and is instead copied into the vectors + * by install_bp_hardening_cb(). + */ + .data + .pushsection .rodata + .global __smccc_workaround_1_smc +__smccc_workaround_1_smc: + esb + sub sp, sp, #(8 * 4) + stp x2, x3, [sp, #(8 * 0)] + stp x0, x1, [sp, #(8 * 2)] + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1 + smc #0 + ldp x2, x3, [sp, #(8 * 0)] + ldp x0, x1, [sp, #(8 * 2)] + add sp, sp, #(8 * 4) +1: .org __smccc_workaround_1_smc + __SMCCC_WORKAROUND_1_SMC_SZ + .org 1b
Signature · 1 line
2.26.2
PATCH v2 3/14 arm64: kvm: Formalize hypcall ABI
In reply to David BrazdilIn preparation for unmapping .hyp.text from kernel memory mappings, convert the current EL1 - EL2 KVM ABI to use hypercall numbers in lieu of direct function pointers. While this in itself does not provide any isolation, it is a first step towards having a well-defined EL2 ABI.
The implementation is based on a jump table to known host HVC handlers indexed by the hypercall ID. Relative-offset branches were chosen over
a sys_call_table-like array of function pointers to avoid the need for re-computing the addresses under hyp memory mappings.
Hypcall IDs start at 0x1000 because comments in hyp.S state that lower IDs are allocated for hyp stub operations. This was not originally honored by hyp-entry.S, only the actually used IDs would be recognized and all other values would be treated as function pointers. This is cleaned up and all IDs lower than 0x1000 are routed to __kvm_handle_stub_hvc.
--- arch/arm64/include/asm/kvm_host.h | 10 ++-- arch/arm64/include/asm/kvm_host_hypercalls.h | 59 ++++++++++++++++++++ arch/arm64/kvm/hyp.S | 18 +++--- arch/arm64/kvm/hyp/hyp-entry.S | 56 +++++++++++-------- 4 files changed, 107 insertions(+), 36 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_host_hypercalls.h
arch/arm64/include/asm/kvm_host.h +6 -4
@@ -24,6 +24,7 @@#include <asm/fpsimd.h> #include <asm/kvm.h> #include <asm/kvm_asm.h> +#include <asm/kvm_host_hypercalls.h> #include <asm/thread_info.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED
@@ -446,7 +447,7 @@ int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);void kvm_arm_halt_guest (struct kvm *kvm);void kvm_arm_resume_guest (struct kvm *kvm); -u64 __kvm_call_hyp (void *hypfn, ...); +u64 __kvm_call_hyp (unsigned long hcall_id, ...);/* * The couple of isb() below are there to guarantee the same behaviour
@@ -459,7 +460,8 @@ u64 __kvm_call_hyp(void *hypfn, ...);f (__VA_ARGS__); \isb (); \ }else { \ - __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__); \ +__kvm_call_hyp (KVM_HOST_HCALL_ID (f), \ + ##__VA_ARGS__); \ } \ }while (0 )
@@ -471,7 +473,7 @@ u64 __kvm_call_hyp(void *hypfn, ...); ret =f (__VA_ARGS__); \isb (); \ }else { \ - ret =__kvm_call_hyp (kvm_ksym_ref (f), \ + ret =__kvm_call_hyp (KVM_HOST_HCALL_ID (f), \ ##__VA_ARGS__); \ } \ \
@@ -551,7 +553,7 @@ static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,* cpus_have_const_cap() wrapper. */ BUG_ON (!system_capabilities_finalized ()); -__kvm_call_hyp ((void *)pgd_ptr, hyp_stack_ptr, vector_ptr, tpidr_el2); +__kvm_call_hyp ((unsigned long )pgd_ptr, hyp_stack_ptr, vector_ptr, tpidr_el2);/* * Disabling SSBD on a non-VHE system requires us to enable SSBS
arch/arm64/include/asm/kvm_host_hypercalls.h new file +59 -0
59 lines not on this page · raw message
arch/arm64/kvm/hyp.S +8 -10
@@ -11,22 +11,20 @@ #include <asm/cpufeature.h> /* - * u64 __kvm_call_hyp(void *hypfn, ...); + * u64 __kvm_call_hyp(unsigned long hcall_id, ...); * * This is not really a variadic function in the classic C-way and care must * be taken when calling this to ensure parameters are passed in registers * only, since the stack will change between the caller and the callee. * - * Call the function with the first argument containing a pointer to the - * function you wish to call in Hyp mode, and subsequent arguments will be - * passed as x0, x1, and x2 (a maximum of 3 arguments in addition to the - * function pointer can be passed). The function being called must be mapped - * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are - * passed in x0. + * Call the function with the first argument containing ID of the function + * you wish to call in Hyp mode, as defined in kvm_host_hypercalls.h, and + * subsequent arguments will be passed as x0, x1, and x2 (a maximum of + * 3 arguments in addition to the hypcall ID can be passed). Return values + * are passed in x0. * - * A function pointer with a value less than 0xfff has a special meaning, - * and is used to implement hyp stubs in the same way as in - * arch/arm64/kernel/hyp_stub.S. + * Hypcalls with ID less than 0x1000 are propagated to operations implemented + * in arch/arm64/kernel/hyp_stub.S. */ SYM_FUNC_START(__kvm_call_hyp) hvc #0
arch/arm64/kvm/hyp/hyp-entry.S +34 -22
81 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 4/14 arm64: kvm: Add build rules for separate nVHE object files
In reply to David BrazdilAdd new folder arch/arm64/kvm/hyp/nvhe and a Makefile for building code that runs in EL2 under nVHE KVM.
Compile each source file into a .hyp.tmp.o object first, then prefix all its symbols with "__kvm_nvhe_" using objcopy and produce a .hyp.o. Suffixes were chosen so that it would be possible for VHE and nVHE to share some source files, but compiled with different CFLAGS. nVHE build rules add -D__KVM_NVHE_HYPERVISOR__.
The nVHE ELF symbol prefix is added to kallsyms.c as ignored. EL2-only symbols will never appear in EL1 stack traces.
--- arch/arm64/kernel/image-vars.h | 12 +++++++++++ arch/arm64/kvm/hyp/Makefile | 4 ++-- arch/arm64/kvm/hyp/nvhe/Makefile | 35 ++++++++++++++++++++++++++++++++ scripts/kallsyms.c | 1 + 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/Makefile
arch/arm64/kernel/image-vars.h +12 -0
@@ -51,4 +51,16 @@ __efistub__ctype = _ctype;#endif +#ifdef CONFIG_KVM + +/* +* KVM nVHE code has its own symbol namespace prefixed by __hyp_text_, to +* isolate it from the kernel proper. The following symbols are legally +* accessed by it, therefore provide aliases to make them linkable. +* Do not include symbols which may not be safely accessed under hypervisor +* memory mappings. +*/ + +#endif /* CONFIG_KVM */ +#endif /* __ARM64_KERNEL_IMAGE_VARS_H */
arch/arm64/kvm/hyp/Makefile +2 -2
@@ -6,10 +6,10 @@ ccflags-y += -fno-stack-protector -DDISABLE_BRANCH_PROFILING \ $(DISABLE_STACKLEAK_PLUGIN) -obj-$(CONFIG_KVM) += hyp.o +obj-$(CONFIG_KVM) += vhe.o nvhe/ obj-$(CONFIG_KVM_INDIRECT_VECTORS) += smccc_wa.o -hyp-y := vgic-v3-sr.o timer-sr.o aarch32.o vgic-v2-cpuif-proxy.o sysreg-sr.o \ +vhe-y := vgic-v3-sr.o timer-sr.o aarch32.o vgic-v2-cpuif-proxy.o sysreg-sr.o \ debug-sr.o entry.o switch.o fpsimd.o tlb.o hyp-entry.o # KVM code is run at a different exception code with a different map, so
arch/arm64/kvm/hyp/nvhe/Makefile new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part +# + +asflags-y := -D__KVM_NVHE_HYPERVISOR__ +ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ + -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) + +obj-y := + +obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) +extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y)) + +$(obj)/%.hyp.tmp.o: $(src)/%.c FORCE + $(call if_changed_rule,cc_o_c) +$(obj)/%.hyp.tmp.o: $(src)/%.S FORCE + $(call if_changed_rule,as_o_S) +$(obj)/%.hyp.o: $(obj)/%.hyp.tmp.o FORCE + $(call if_changed,hypcopy) + +quiet_cmd_hypcopy = HYPCOPY $@ + cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@ + +# KVM nVHE code is run at a different exception code with a different map, so +# compiler instrumentation that inserts callbacks or checks into the code may +# cause crashes. Just disable it. +GCOV_PROFILE := n +KASAN_SANITIZE := n +UBSAN_SANITIZE := n +KCOV_INSTRUMENT := n + +# Skip objtool checking for this directory because nVHE code is compiled with +# non-standard build rules. +OBJECT_FILES_NON_STANDARD := y
scripts/kallsyms.c +1 -0
@@ -109,6 +109,7 @@ static bool is_ignored_symbol(const char *name, char type)".LASANPC" ,/* s390 kasan local symbols */ "__crc_" ,/* modversions */ "__efistub_" ,/* arm64 EFI stub namespace */ +"__kvm_nvhe_" ,/* arm64 non-VHE KVM namespace */ NULL };
Signature · 1 line
2.26.2
Re: [PATCH v2 04/14] arm64: kvm: Add build rules for separate nVHE object files
Quoted 7 lines · David Brazdil
arch/arm64/kernel/image-vars.h +0
-0@@ -51,4 +51,16 @@ __efistub__ctype = _ctype;#endif
arch/arm64/kernel/image-vars.h __efistub__ctype = _ctype; · line 62
Quoted 10 lines
arch/arm64/kernel/image-vars.h +9
-0+#ifdef CONFIG_KVM + +/* +* KVM nVHE code has its own symbol namespace prefixed by __hyp_text_, to +* isolate it from the kernel proper. The following symbols are legally +* accessed by it, therefore provide aliases to make them linkable. +* Do not include symbols which may not be safely accessed under hypervisor +* memory mappings. +*/
nit: the prefix is not '__kvm_nvhe_' rather than '__hyp_text_'
Re: [PATCH v2 04/14] arm64: kvm: Add build rules for separate nVHE object files
Quoted 9 lines · Andrew Scull
Quoted 8 lines · David Brazdil
arch/arm64/kernel/image-vars.h +0
-0@@ -51,4 +51,16 @@ __efistub__ctype = _ctype;#endif
Quoted 11 lines
arch/arm64/kernel/image-vars.h __efistub__ctype = _ctype; · line 62
Quoted 9 lines
arch/arm64/kernel/image-vars.h +9
-0+#ifdef CONFIG_KVM + +/* +* KVM nVHE code has its own symbol namespace prefixed by __hyp_text_, to +* isolate it from the kernel proper. The following symbols are legally +* accessed by it, therefore provide aliases to make them linkable. +* Do not include symbols which may not be safely accessed under hypervisor +* memory mappings. +*/ nit: the prefix is not '
__kvm_nvhe_' rather than '__hyp_text_'
Thanks, will fix in v3.
PATCH v2 5/14 arm64: kvm: Build hyp-entry.S separately for VHE/nVHE
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
hyp-entry.S contains implementation of KVM hyp vectors. This code is mostly shared between VHE/nVHE, therefore compile it under both VHE and nVHE build rules. nVHE-specific host HVC handler is hidden behind __KVM_NVHE_HYPERVISOR__.
Adjust code which selects which KVM hyp vecs to install to choose the correct VHE/nVHE symbol.
--- arch/arm64/include/asm/kvm_asm.h | 25 ++++++++++++++++++++++++- arch/arm64/include/asm/kvm_mmu.h | 16 ++++++++++------ arch/arm64/include/asm/mmu.h | 7 ------- arch/arm64/kernel/cpu_errata.c | 4 +++- arch/arm64/kernel/image-vars.h | 29 ++++++++++++++++++++++++++++- arch/arm64/kvm/hyp/hyp-entry.S | 2 ++ arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/va_layout.c | 2 +- 8 files changed, 69 insertions(+), 18 deletions(-)
arch/arm64/include/asm/kvm_asm.h +24 -1
@@ -42,6 +42,22 @@#include <linux/mm.h> +/* +* Translate name of a symbol defined in VHE/nVHE hyp implementations +* to the name seen by kernel proper. All nVHE symbols are prefixed by +* the build system to avoid clashes with the VHE variants. +*/ +#define __kvm_vhe_sym (sym) sym +#define __kvm_nvhe_sym (sym) __kvm_nvhe_##sym + +/* +* Define a pair of symbols sharing the same name but one defined in +* VHE and the other in nVHE hyp implementations. +*/ +#define DECLARE_KVM_HYP_SYM (sym) \ + extern char __kvm_vhe_sym(sym)[]; \ + extern char __kvm_nvhe_sym(sym)[] +/* Translate a kernel address of @sym into its equivalent linear mapping */ #define kvm_ksym_ref (sym) \ ({ \
@@ -50,6 +66,8 @@ val =lm_alias (&sym); \ val; \ }) +#define kvm_ksym_ref_vhe (sym) kvm_ksym_ref(__kvm_vhe_sym(sym)) +#define kvm_ksym_ref_nvhe (sym) kvm_ksym_ref(__kvm_nvhe_sym(sym))struct kvm ;struct kvm_vcpu ;
@@ -57,7 +75,12 @@ struct kvm_vcpu;extern char __kvm_hyp_init[];extern char __kvm_hyp_init_end[]; -extern char __kvm_hyp_vector[]; +DECLARE_KVM_HYP_SYM (__kvm_hyp_vector); + +#ifdef CONFIG_KVM_INDIRECT_VECTORS +DECLARE_KVM_HYP_SYM (__bp_harden_hyp_vecs); +extern atomic_t arm64_el2_vector_last_slot; +#endif extern void __kvm_flush_vm_context (void );extern void __kvm_tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa);
arch/arm64/include/asm/kvm_mmu.h +10 -6
@@ -477,11 +477,15 @@ extern int __kvm_harden_el2_vector_slot;static inline void *kvm_get_hyp_vector (void ) {struct bp_hardening_data *data =arm64_get_bp_hardening_data (); -void *vect =kern_hyp_va (kvm_ksym_ref (__kvm_hyp_vector));int slot =-1 ; +void *vect =kern_hyp_va (has_vhe () + ?kvm_ksym_ref_vhe (__kvm_hyp_vector) + :kvm_ksym_ref_nvhe (__kvm_hyp_vector));if (cpus_have_const_cap (ARM64_HARDEN_BRANCH_PREDICTOR ) && data->fn) { - vect =kern_hyp_va (kvm_ksym_ref (__bp_harden_hyp_vecs)); + vect =kern_hyp_va (has_vhe () + ?kvm_ksym_ref_vhe (__bp_harden_hyp_vecs) + :kvm_ksym_ref_nvhe (__bp_harden_hyp_vecs)); slot = data->hyp_vectors_slot; }
@@ -510,12 +514,11 @@ static inline int kvm_map_vectors(void)* HBP + HEL2 -> use hardened vertors and use exec mapping */ if (cpus_have_const_cap (ARM64_HARDEN_BRANCH_PREDICTOR )) { - __kvm_bp_vect_base =kvm_ksym_ref (__bp_harden_hyp_vecs); - __kvm_bp_vect_base =kern_hyp_va (__kvm_bp_vect_base); + __kvm_bp_vect_base =kern_hyp_va (kvm_ksym_ref_nvhe (__bp_harden_hyp_vecs)); }if (cpus_have_const_cap (ARM64_HARDEN_EL2_VECTORS )) { -phys_addr_t vect_pa =__pa_symbol (__bp_harden_hyp_vecs); +phys_addr_t vect_pa =__pa_symbol (__kvm_nvhe_sym (__bp_harden_hyp_vecs));unsigned long size = __BP_HARDEN_HYP_VECS_SZ;/*
@@ -534,7 +537,8 @@ static inline int kvm_map_vectors(void)#else static inline void *kvm_get_hyp_vector (void ) { -return kern_hyp_va (kvm_ksym_ref (__kvm_hyp_vector)); +return kern_hyp_va (has_vhe () ?kvm_ksym_ref_vhe (__kvm_hyp_vector) + :kvm_ksym_ref_nvhe (__kvm_hyp_vector)); }static inline int kvm_map_vectors (void )
arch/arm64/include/asm/mmu.h +0 -7
@@ -42,13 +42,6 @@ struct bp_hardening_data {bp_hardening_cb_t fn; }; -#if (defined(CONFIG_HARDEN_BRANCH_PREDICTOR ) || \ - defined(CONFIG_HARDEN_EL2_VECTORS )) - -extern char __bp_harden_hyp_vecs[]; -extern atomic_t arm64_el2_vector_last_slot; -#endif /* CONFIG_HARDEN_BRANCH_PREDICTOR || CONFIG_HARDEN_EL2_VECTORS */ -#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
arch/arm64/kernel/cpu_errata.c +3 -1
@@ -117,7 +117,9 @@ DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);static void __copy_hyp_vect_bpi (int slot,const char *hyp_vecs_start,const char *hyp_vecs_end) { -void *dst =lm_alias (__bp_harden_hyp_vecs + slot *SZ_2K ); +char *vec =has_vhe () ?__kvm_vhe_sym (__bp_harden_hyp_vecs) + :__kvm_nvhe_sym (__bp_harden_hyp_vecs); +void *dst =lm_alias (vec + slot *SZ_2K );int i;for (i =0 ; i <SZ_2K ; i +=0x80 )
arch/arm64/kernel/image-vars.h +28 -1
@@ -54,13 +54,40 @@ __efistub__ctype = _ctype;#ifdef CONFIG_KVM /* -* KVM nVHE code has its own symbol namespace prefixed by __hyp_text_, to +* KVM nVHE code has its own symbol namespace prefixed by __kvm_nvhe_, to * isolate it from the kernel proper. The following symbols are legally * accessed by it, therefore provide aliases to make them linkable. * Do not include symbols which may not be safely accessed under hypervisor * memory mappings. */ +__kvm_nvhe___guest_exit = __guest_exit; +__kvm_nvhe___kvm_enable_ssbs = __kvm_enable_ssbs; +__kvm_nvhe___kvm_flush_vm_context = __kvm_flush_vm_context; +__kvm_nvhe___kvm_get_mdcr_el2 = __kvm_get_mdcr_el2; +__kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; +__kvm_nvhe___kvm_timer_set_cntvoff = __kvm_timer_set_cntvoff; +__kvm_nvhe___kvm_tlb_flush_local_vmid = __kvm_tlb_flush_local_vmid; +__kvm_nvhe___kvm_tlb_flush_vmid = __kvm_tlb_flush_vmid; +__kvm_nvhe___kvm_tlb_flush_vmid_ipa = __kvm_tlb_flush_vmid_ipa; +__kvm_nvhe___kvm_vcpu_run_nvhe = __kvm_vcpu_run_nvhe; +__kvm_nvhe___vgic_v3_get_ich_vtr_el2 = __vgic_v3_get_ich_vtr_el2; +__kvm_nvhe___vgic_v3_init_lrs = __vgic_v3_init_lrs; +__kvm_nvhe___vgic_v3_read_vmcr = __vgic_v3_read_vmcr; +__kvm_nvhe___vgic_v3_restore_aprs = __vgic_v3_restore_aprs; +__kvm_nvhe___vgic_v3_save_aprs = __vgic_v3_save_aprs; +__kvm_nvhe___vgic_v3_write_vmcr = __vgic_v3_write_vmcr; +__kvm_nvhe_abort_guest_exit_end = abort_guest_exit_end; +__kvm_nvhe_abort_guest_exit_start = abort_guest_exit_start; +__kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; +__kvm_nvhe_arm64_ssbd_callback_required = arm64_ssbd_callback_required; +__kvm_nvhe_hyp_panic = hyp_panic; +__kvm_nvhe_kimage_voffset = kimage_voffset; +__kvm_nvhe_kvm_host_data = kvm_host_data; +__kvm_nvhe_kvm_patch_vector_branch = kvm_patch_vector_branch; +__kvm_nvhe_kvm_update_va_mask = kvm_update_va_mask; +__kvm_nvhe_panic = panic; +#endif /* CONFIG_KVM */ #endif /* __ARM64_KERNEL_IMAGE_VARS_H */
arch/arm64/kvm/hyp/hyp-entry.S +2 -0
@@ -27,6 +27,7 @@ el1_sync: // Guest trapped into EL2 ccmp x0, #ESR_ELx_EC_HVC32, #4, ne b.ne el1_trap +#ifdef __KVM_NVHE_HYPERVISOR__ mrs x1, vttbr_el2 // If vttbr is valid, the guest cbnz x1, el1_hvc_guest // called HVC
@@ -86,6 +87,7 @@ el1_host_invalid_hvc: mov x0, -ENOSYS eret sb +#endif /* __KVM_NVHE_HYPERVISOR__ */ el1_hvc_guest: /*
arch/arm64/kvm/hyp/nvhe/Makefile +1 -1
@@ -7,7 +7,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) -obj-y := +obj-y := ../hyp-entry.o obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
arch/arm64/kvm/va_layout.c +1 -1
@@ -150,7 +150,7 @@ void kvm_patch_vector_branch(struct alt_instr *alt,/* * Compute HYP VA by using the same computation as kern_hyp_va() */ - addr = (uintptr_t )kvm_ksym_ref (__kvm_hyp_vector); + addr = (uintptr_t )kvm_ksym_ref_nvhe (__kvm_hyp_vector); addr &= va_mask; addr |= tag_val << tag_lsb;
Signature · 1 line
2.26.2
PATCH v2 6/14 arm64: kvm: Split hyp/tlb.c to VHE/nVHE
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
tlb.c contains code for flushing the TLB, with parts shared between VHE/nVHE. These common routines are moved into a header file tlb.h, VHE-specific code remains in tlb.c and nVHE-specific code is moved to nvhe/tlb.c.
The header file expects its users to implement two helper functions declared at the top of the file.
--- arch/arm64/kernel/image-vars.h | 8 +- arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/tlb.c | 69 +++++++++++++ arch/arm64/kvm/hyp/tlb.c | 170 +++---------------------------- arch/arm64/kvm/hyp/tlb.h | 134 ++++++++++++++++++++++++ 5 files changed, 221 insertions(+), 162 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/tlb.c create mode 100644 arch/arm64/kvm/hyp/tlb.h
arch/arm64/kernel/image-vars.h +4 -4
@@ -62,14 +62,11 @@ __efistub__ctype = _ctype;*/ __kvm_nvhe___guest_exit = __guest_exit; +__kvm_nvhe___icache_flags = __icache_flags; __kvm_nvhe___kvm_enable_ssbs = __kvm_enable_ssbs; -__kvm_nvhe___kvm_flush_vm_context = __kvm_flush_vm_context; __kvm_nvhe___kvm_get_mdcr_el2 = __kvm_get_mdcr_el2; __kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; __kvm_nvhe___kvm_timer_set_cntvoff = __kvm_timer_set_cntvoff; -__kvm_nvhe___kvm_tlb_flush_local_vmid = __kvm_tlb_flush_local_vmid; -__kvm_nvhe___kvm_tlb_flush_vmid = __kvm_tlb_flush_vmid; -__kvm_nvhe___kvm_tlb_flush_vmid_ipa = __kvm_tlb_flush_vmid_ipa; __kvm_nvhe___kvm_vcpu_run_nvhe = __kvm_vcpu_run_nvhe; __kvm_nvhe___vgic_v3_get_ich_vtr_el2 = __vgic_v3_get_ich_vtr_el2; __kvm_nvhe___vgic_v3_init_lrs = __vgic_v3_init_lrs;
@@ -79,8 +76,11 @@ __kvm_nvhe___vgic_v3_save_aprs = __vgic_v3_save_aprs; __kvm_nvhe___vgic_v3_write_vmcr = __vgic_v3_write_vmcr; __kvm_nvhe_abort_guest_exit_end = abort_guest_exit_end; __kvm_nvhe_abort_guest_exit_start = abort_guest_exit_start; +__kvm_nvhe_arm64_const_caps_ready = arm64_const_caps_ready; __kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; __kvm_nvhe_arm64_ssbd_callback_required = arm64_ssbd_callback_required; +__kvm_nvhe_cpu_hwcap_keys = cpu_hwcap_keys; +__kvm_nvhe_cpu_hwcaps = cpu_hwcaps; __kvm_nvhe_hyp_panic = hyp_panic; __kvm_nvhe_kimage_voffset = kimage_voffset; __kvm_nvhe_kvm_host_data = kvm_host_data;
arch/arm64/kvm/hyp/nvhe/Makefile +1 -1
@@ -7,7 +7,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) -obj-y := ../hyp-entry.o +obj-y := tlb.o ../hyp-entry.o obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
arch/arm64/kvm/hyp/nvhe/tlb.c new file +69 -0
69 lines not on this page · raw message
arch/arm64/kvm/hyp/tlb.c +13 -157
197 lines not on this page · raw message
arch/arm64/kvm/hyp/tlb.h new file +134 -0
134 lines not on this page · raw message
Signature · 6 lines
2.26.2 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v2 7/14 arm64: kvm: Split hyp/switch.c to VHE/nVHE
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
switch.c implements context-switching for KVM, with large parts shared between VHE/nVHE. These common routines are moved to switch.h, VHE-specific code is left in switch.c and nVHE-specific code is moved to nvhe/switch.c.
Previously __kvm_vcpu_run needed a different symbol name for VHE/nVHE. This is cleaned up and the caller in arm.c simplified.
--- arch/arm64/include/asm/kvm_asm.h | 4 +- arch/arm64/include/asm/kvm_host_hypercalls.h | 4 +- arch/arm64/include/asm/kvm_hyp.h | 5 + arch/arm64/kernel/image-vars.h | 25 +- arch/arm64/kvm/arm.c | 6 +- arch/arm64/kvm/hyp/hyp-entry.S | 2 + arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/switch.c | 271 ++++++++ arch/arm64/kvm/hyp/switch.c | 688 +------------------ arch/arm64/kvm/hyp/switch.h | 446 ++++++++++++ arch/arm64/kvm/hyp/sysreg-sr.c | 4 +- 11 files changed, 769 insertions(+), 688 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/switch.c create mode 100644 arch/arm64/kvm/hyp/switch.h
arch/arm64/include/asm/kvm_asm.h +1 -3
@@ -89,9 +89,7 @@ extern void __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu);extern void __kvm_timer_set_cntvoff (u32 cntvoff_low,u32 cntvoff_high); -extern int kvm_vcpu_run_vhe (struct kvm_vcpu *vcpu); - -extern int __kvm_vcpu_run_nvhe (struct kvm_vcpu *vcpu); +extern int __kvm_vcpu_run (struct kvm_vcpu *vcpu);extern u64 __vgic_v3_get_ich_vtr_el2 (void );extern u64 __vgic_v3_read_vmcr (void );
arch/arm64/include/asm/kvm_host_hypercalls.h +2 -2
@@ -22,8 +22,8 @@ __KVM_HOST_HCALL(__kvm_tlb_flush_local_vmid)#define __KVM_HOST_HCALL_ID___kvm_flush_vm_context 4 __KVM_HOST_HCALL(__kvm_flush_vm_context) -#define __KVM_HOST_HCALL_ID___kvm_vcpu_run_nvhe 5 -__KVM_HOST_HCALL(__kvm_vcpu_run_nvhe) +#define __KVM_HOST_HCALL_ID___kvm_vcpu_run 5 +__KVM_HOST_HCALL(__kvm_vcpu_run)#define __KVM_HOST_HCALL_ID___kvm_tlb_flush_vmid 6__KVM_HOST_HCALL (__kvm_tlb_flush_vmid)
arch/arm64/include/asm/kvm_hyp.h +5 -0
@@ -82,11 +82,16 @@ void __debug_switch_to_host(struct kvm_vcpu *vcpu);void __fpsimd_save_state (struct user_fpsimd_state *fp_regs);void __fpsimd_restore_state (struct user_fpsimd_state *fp_regs); +#ifndef __KVM_NVHE_HYPERVISOR__void activate_traps_vhe_load (struct kvm_vcpu *vcpu);void deactivate_traps_vhe_put (void ); +#endif u64 __guest_enter (struct kvm_vcpu *vcpu,struct kvm_cpu_context *host_ctxt); + +#ifdef __KVM_NVHE_HYPERVISOR__void __noreturn __hyp_do_panic (unsigned long , ...); +#endif /* * Must be called from hyp code running at EL2 with an updated VTTBR
arch/arm64/kernel/image-vars.h +23 -2
@@ -61,18 +61,34 @@ __efistub__ctype = _ctype;* memory mappings. */ +__kvm_nvhe___debug_switch_to_guest = __debug_switch_to_guest; +__kvm_nvhe___debug_switch_to_host = __debug_switch_to_host; +__kvm_nvhe___fpsimd_restore_state = __fpsimd_restore_state; +__kvm_nvhe___fpsimd_save_state = __fpsimd_save_state; +__kvm_nvhe___guest_enter = __guest_enter; __kvm_nvhe___guest_exit = __guest_exit; __kvm_nvhe___icache_flags = __icache_flags; __kvm_nvhe___kvm_enable_ssbs = __kvm_enable_ssbs; __kvm_nvhe___kvm_get_mdcr_el2 = __kvm_get_mdcr_el2; __kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; __kvm_nvhe___kvm_timer_set_cntvoff = __kvm_timer_set_cntvoff; -__kvm_nvhe___kvm_vcpu_run_nvhe = __kvm_vcpu_run_nvhe; +__kvm_nvhe___sysreg32_restore_state = __sysreg32_restore_state; +__kvm_nvhe___sysreg32_save_state = __sysreg32_save_state; +__kvm_nvhe___sysreg_restore_state_nvhe = __sysreg_restore_state_nvhe; +__kvm_nvhe___sysreg_save_state_nvhe = __sysreg_save_state_nvhe; +__kvm_nvhe___timer_disable_traps = __timer_disable_traps; +__kvm_nvhe___timer_enable_traps = __timer_enable_traps; +__kvm_nvhe___vgic_v2_perform_cpuif_access = __vgic_v2_perform_cpuif_access; +__kvm_nvhe___vgic_v3_activate_traps = __vgic_v3_activate_traps; +__kvm_nvhe___vgic_v3_deactivate_traps = __vgic_v3_deactivate_traps; __kvm_nvhe___vgic_v3_get_ich_vtr_el2 = __vgic_v3_get_ich_vtr_el2; __kvm_nvhe___vgic_v3_init_lrs = __vgic_v3_init_lrs; +__kvm_nvhe___vgic_v3_perform_cpuif_access = __vgic_v3_perform_cpuif_access; __kvm_nvhe___vgic_v3_read_vmcr = __vgic_v3_read_vmcr; __kvm_nvhe___vgic_v3_restore_aprs = __vgic_v3_restore_aprs; +__kvm_nvhe___vgic_v3_restore_state = __vgic_v3_restore_state; __kvm_nvhe___vgic_v3_save_aprs = __vgic_v3_save_aprs; +__kvm_nvhe___vgic_v3_save_state = __vgic_v3_save_state; __kvm_nvhe___vgic_v3_write_vmcr = __vgic_v3_write_vmcr; __kvm_nvhe_abort_guest_exit_end = abort_guest_exit_end; __kvm_nvhe_abort_guest_exit_start = abort_guest_exit_start;
@@ -81,12 +97,17 @@ __kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; __kvm_nvhe_arm64_ssbd_callback_required = arm64_ssbd_callback_required; __kvm_nvhe_cpu_hwcap_keys = cpu_hwcap_keys; __kvm_nvhe_cpu_hwcaps = cpu_hwcaps; -__kvm_nvhe_hyp_panic = hyp_panic; __kvm_nvhe_kimage_voffset = kimage_voffset; __kvm_nvhe_kvm_host_data = kvm_host_data; __kvm_nvhe_kvm_patch_vector_branch = kvm_patch_vector_branch; +__kvm_nvhe_kvm_skip_instr32 = kvm_skip_instr32; __kvm_nvhe_kvm_update_va_mask = kvm_update_va_mask; +__kvm_nvhe_kvm_vgic_global_state = kvm_vgic_global_state; __kvm_nvhe_panic = panic; +__kvm_nvhe_sve_load_state = sve_load_state; +__kvm_nvhe_sve_save_state = sve_save_state; +__kvm_nvhe_vgic_v2_cpuif_trap = vgic_v2_cpuif_trap; +__kvm_nvhe_vgic_v3_cpuif_trap = vgic_v3_cpuif_trap;#endif /* CONFIG_KVM */
arch/arm64/kvm/arm.c +1 -5
@@ -749,11 +749,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)trace_kvm_entry (*vcpu_pc (vcpu));guest_enter_irqoff (); -if (has_vhe ()) { - ret =kvm_vcpu_run_vhe (vcpu); - }else { - ret =kvm_call_hyp_ret (__kvm_vcpu_run_nvhe, vcpu); - } + ret =kvm_call_hyp_ret (__kvm_vcpu_run, vcpu); vcpu->mode =OUTSIDE_GUEST_MODE ; vcpu->stat.exits++;
arch/arm64/kvm/hyp/hyp-entry.S +2 -0
@@ -194,6 +194,7 @@ el2_error: eret sb +#ifdef __KVM_NVHE_HYPERVISOR__ SYM_FUNC_START(__hyp_do_panic) mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ PSR_MODE_EL1h)
@@ -203,6 +204,7 @@ SYM_FUNC_START(__hyp_do_panic) eret sb SYM_FUNC_END(__hyp_do_panic) +#endif SYM_CODE_START(__hyp_panic) get_host_ctxt x0, x1
arch/arm64/kvm/hyp/nvhe/Makefile +1 -1
@@ -7,7 +7,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) -obj-y := tlb.o ../hyp-entry.o +obj-y := switch.o tlb.o ../hyp-entry.o obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
arch/arm64/kvm/hyp/nvhe/switch.c new file +271 -0
271 lines not on this page · raw message
arch/arm64/kvm/hyp/switch.c +15 -673
743 lines not on this page · raw message
arch/arm64/kvm/hyp/switch.h new file +446 -0
446 lines not on this page · raw message
arch/arm64/kvm/hyp/sysreg-sr.c +2 -2
@@ -125,7 +125,7 @@ static void __hyp_text __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)/* * Must only be done for guest registers, hence the context * test. We're coming from the host, so SCTLR.M is already -* set. Pairs with __activate_traps_nvhe(). +* set. Pairs with nVHE's __activate_traps(). */ write_sysreg_el1((ctxt->sys_regs[TCR_EL1] | TCR_EPD1_MASK | TCR_EPD0_MASK),
@@ -153,7 +153,7 @@ static void __hyp_text __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt) ctxt->__hyp_running_vcpu) {/* * Must only be done for host registers, hence the context -* test. Pairs with __deactivate_traps_nvhe(). +* test. Pairs with nVHE's __deactivate_traps(). */ isb ();/*
Signature · 1 line
2.26.2
Re: [PATCH v2 07/14] arm64: kvm: Split hyp/switch.c to VHE/nVHE
arch/arm64/kernel/image-vars.h __kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; · line 108
Quoted 2 lines · David Brazdil
arch/arm64/kernel/image-vars.h +2
-0+__kvm_nvhe_sve_load_state = sve_load_state; +__kvm_nvhe_sve_save_state = sve_save_state;
Building without CONFIG_ARM64_VHE leads to a linker error due to the SVE functions being referenced in this list. This is caused by CONFIG_ARM64_VHE disabling CONFIG_ARM64_SVE and, in turn, preventing the generation of those symbols. There aren't any references from code, just this file.
It can be resolved by having the SVE symbol aliases depend on CONFIG_ARM64_SVE.
Re: [PATCH v2 07/14] arm64: kvm: Split hyp/switch.c to VHE/nVHE
Quoted 10 lines · Andrew Scull
arch/arm64/kernel/image-vars.h __kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; · line 108
Quoted 2 lines · David Brazdil
arch/arm64/kernel/image-vars.h +2
-0+__kvm_nvhe_sve_load_state = sve_load_state; +__kvm_nvhe_sve_save_state = sve_save_state;Building without
CONFIG_ARM64_VHEleads to a linker error due to the SVE functions being referenced in this list. This is caused byCONFIG_ARM64_VHEdisablingCONFIG_ARM64_SVEand, in turn, preventing the generation of those symbols. There aren't any references from code, just this file.
Quoted 2 lines
It can be resolved by having the SVE symbol aliases depend on
CONFIG_ARM64_SVE.
Thanks, will fix the linker script in v3.
PATCH v2 8/14 arm64: kvm: Split hyp/debug-sr.c to VHE/nVHE
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
debug-sr.c contains KVM's code for context-switching debug registers, with some parts shared between VHE/nVHE. These common routines are moved to debug-sr.h, VHE-specific code is left in debug-sr.c and nVHE-specific code is moved to nvhe/debug-sr.c.
Functions are slightly refactored to move code hidden behind has_vhe() checks to the corresponding .c files.
--- arch/arm64/kernel/image-vars.h | 3 - arch/arm64/kvm/hyp/debug-sr.c | 214 +---------------------------- arch/arm64/kvm/hyp/debug-sr.h | 172 +++++++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/debug-sr.c | 77 +++++++++++ 5 files changed, 256 insertions(+), 212 deletions(-) create mode 100644 arch/arm64/kvm/hyp/debug-sr.h create mode 100644 arch/arm64/kvm/hyp/nvhe/debug-sr.c
arch/arm64/kernel/image-vars.h +0 -3
@@ -61,15 +61,12 @@ __efistub__ctype = _ctype;* memory mappings. */ -__kvm_nvhe___debug_switch_to_guest = __debug_switch_to_guest; -__kvm_nvhe___debug_switch_to_host = __debug_switch_to_host; __kvm_nvhe___fpsimd_restore_state = __fpsimd_restore_state; __kvm_nvhe___fpsimd_save_state = __fpsimd_save_state; __kvm_nvhe___guest_enter = __guest_enter; __kvm_nvhe___guest_exit = __guest_exit; __kvm_nvhe___icache_flags = __icache_flags; __kvm_nvhe___kvm_enable_ssbs = __kvm_enable_ssbs; -__kvm_nvhe___kvm_get_mdcr_el2 = __kvm_get_mdcr_el2; __kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; __kvm_nvhe___kvm_timer_set_cntvoff = __kvm_timer_set_cntvoff; __kvm_nvhe___sysreg32_restore_state = __sysreg32_restore_state;
arch/arm64/kvm/hyp/debug-sr.c +6 -208
227 lines not on this page · raw message
arch/arm64/kvm/hyp/debug-sr.h new file +172 -0
172 lines not on this page · raw message
arch/arm64/kvm/hyp/nvhe/Makefile +1 -1
@@ -7,7 +7,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) -obj-y := switch.o tlb.o ../hyp-entry.o +obj-y := debug-sr.o switch.o tlb.o ../hyp-entry.o obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
arch/arm64/kvm/hyp/nvhe/debug-sr.c new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 9/14 arm64: kvm: Split hyp/sysreg-sr.c to VHE/nVHE
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
sysreg-sr.c contains KVM's code for saving/restoring system registers, with some parts shared between VHE/nVHE. These common routines are moved to sysreg-sr.h, VHE-specific code is left in sysreg-sr.c and nVHE-specific code is moved to nvhe/sysreg-sr.c.
--- arch/arm64/include/asm/kvm_asm.h | 2 + arch/arm64/include/asm/kvm_host.h | 2 - arch/arm64/include/asm/kvm_hyp.h | 4 + arch/arm64/kernel/image-vars.h | 5 - arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/sysreg-sr.c | 56 +++++++ arch/arm64/kvm/hyp/sysreg-sr.c | 233 ++-------------------------- arch/arm64/kvm/hyp/sysreg-sr.h | 223 ++++++++++++++++++++++++++ 8 files changed, 299 insertions(+), 228 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/sysreg-sr.c create mode 100644 arch/arm64/kvm/hyp/sysreg-sr.h
arch/arm64/include/asm/kvm_asm.h +2 -0
@@ -91,6 +91,8 @@ extern void __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high);extern int __kvm_vcpu_run (struct kvm_vcpu *vcpu); +extern void __kvm_enable_ssbs (void ); +extern u64 __vgic_v3_get_ich_vtr_el2 (void );extern u64 __vgic_v3_read_vmcr (void );extern void __vgic_v3_write_vmcr (u32 vmcr);
arch/arm64/include/asm/kvm_host.h +0 -2
@@ -532,8 +532,6 @@ static inline void kvm_init_host_cpu_context(struct kvm_cpu_context *cpu_ctxt) cpu_ctxt->sys_regs[MPIDR_EL1 ] =read_cpuid_mpidr (); } -void __kvm_enable_ssbs (void ); -static inline void __cpu_init_hyp_mode (phys_addr_t pgd_ptr,unsigned long hyp_stack_ptr,unsigned long vector_ptr)
arch/arm64/include/asm/kvm_hyp.h +4 -0
@@ -67,12 +67,16 @@ int __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu);void __timer_enable_traps (struct kvm_vcpu *vcpu);void __timer_disable_traps (struct kvm_vcpu *vcpu); +#ifdef __KVM_NVHE_HYPERVISOR__void __sysreg_save_state_nvhe (struct kvm_cpu_context *ctxt);void __sysreg_restore_state_nvhe (struct kvm_cpu_context *ctxt); +#else void sysreg_save_host_state_vhe (struct kvm_cpu_context *ctxt);void sysreg_restore_host_state_vhe (struct kvm_cpu_context *ctxt);void sysreg_save_guest_state_vhe (struct kvm_cpu_context *ctxt);void sysreg_restore_guest_state_vhe (struct kvm_cpu_context *ctxt); +#endif +void __sysreg32_save_state (struct kvm_vcpu *vcpu);void __sysreg32_restore_state (struct kvm_vcpu *vcpu);
arch/arm64/kernel/image-vars.h +0 -5
@@ -66,13 +66,8 @@ __kvm_nvhe___fpsimd_save_state = __fpsimd_save_state; __kvm_nvhe___guest_enter = __guest_enter; __kvm_nvhe___guest_exit = __guest_exit; __kvm_nvhe___icache_flags = __icache_flags; -__kvm_nvhe___kvm_enable_ssbs = __kvm_enable_ssbs; __kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; __kvm_nvhe___kvm_timer_set_cntvoff = __kvm_timer_set_cntvoff; -__kvm_nvhe___sysreg32_restore_state = __sysreg32_restore_state; -__kvm_nvhe___sysreg32_save_state = __sysreg32_save_state; -__kvm_nvhe___sysreg_restore_state_nvhe = __sysreg_restore_state_nvhe; -__kvm_nvhe___sysreg_save_state_nvhe = __sysreg_save_state_nvhe; __kvm_nvhe___timer_disable_traps = __timer_disable_traps; __kvm_nvhe___timer_enable_traps = __timer_enable_traps; __kvm_nvhe___vgic_v2_perform_cpuif_access = __vgic_v2_perform_cpuif_access;
arch/arm64/kvm/hyp/nvhe/Makefile +1 -1
@@ -7,7 +7,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) -obj-y := debug-sr.o switch.o tlb.o ../hyp-entry.o +obj-y := sysreg-sr.o debug-sr.o switch.o tlb.o ../hyp-entry.o obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
arch/arm64/kvm/hyp/nvhe/sysreg-sr.c new file +56 -0
56 lines not on this page · raw message
arch/arm64/kvm/hyp/sysreg-sr.c +13 -220
266 lines not on this page · raw message
arch/arm64/kvm/hyp/sysreg-sr.h new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 10/14 arm64: kvm: Split hyp/timer-sr.c to VHE/nVHE
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
timer-sr.c contains a HVC handler for setting CNTVOFF_EL2 and two helper functions for controlling access to physical counter. The former is shared between VHE/nVHE and is kept in timer-sr.c but compiled under both configs. The latter are nVHE-specific and are moved to nvhe/timer-sr.c.
--- arch/arm64/include/asm/kvm_hyp.h | 2 ++ arch/arm64/kernel/image-vars.h | 3 --- arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++- arch/arm64/kvm/hyp/nvhe/timer-sr.c | 43 ++++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/timer-sr.c | 36 ------------------------- 5 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/timer-sr.c
arch/arm64/include/asm/kvm_hyp.h +2 -0
@@ -64,8 +64,10 @@ void __vgic_v3_save_aprs(struct kvm_vcpu *vcpu);void __vgic_v3_restore_aprs (struct kvm_vcpu *vcpu);int __vgic_v3_perform_cpuif_access (struct kvm_vcpu *vcpu); +#ifdef __KVM_NVHE_HYPERVISOR__void __timer_enable_traps (struct kvm_vcpu *vcpu);void __timer_disable_traps (struct kvm_vcpu *vcpu); +#endif #ifdef __KVM_NVHE_HYPERVISOR__void __sysreg_save_state_nvhe (struct kvm_cpu_context *ctxt);
arch/arm64/kernel/image-vars.h +0 -3
@@ -67,9 +67,6 @@ __kvm_nvhe___guest_enter = __guest_enter; __kvm_nvhe___guest_exit = __guest_exit; __kvm_nvhe___icache_flags = __icache_flags; __kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; -__kvm_nvhe___kvm_timer_set_cntvoff = __kvm_timer_set_cntvoff; -__kvm_nvhe___timer_disable_traps = __timer_disable_traps; -__kvm_nvhe___timer_enable_traps = __timer_enable_traps; __kvm_nvhe___vgic_v2_perform_cpuif_access = __vgic_v2_perform_cpuif_access; __kvm_nvhe___vgic_v3_activate_traps = __vgic_v3_activate_traps; __kvm_nvhe___vgic_v3_deactivate_traps = __vgic_v3_deactivate_traps;
arch/arm64/kvm/hyp/nvhe/Makefile +2 -1
@@ -7,7 +7,8 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) -obj-y := sysreg-sr.o debug-sr.o switch.o tlb.o ../hyp-entry.o +obj-y := ../timer-sr.o timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o \ + ../hyp-entry.o obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
arch/arm64/kvm/hyp/nvhe/timer-sr.c new file +43 -0
43 lines not on this page · raw message
arch/arm64/kvm/hyp/timer-sr.c +0 -36
@@ -4,10 +4,6 @@* Author: Marc Zyngier <[email protected]> */ -#include <clocksource/arm_arch_timer.h> -#include <linux/compiler.h> -#include <linux/kvm_host.h> -#include <asm/kvm_hyp.h> void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high)
@@ -15,35 +11,3 @@ void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high)u64 cntvoff = (u64 )cntvoff_high <<32 | cntvoff_low;write_sysreg (cntvoff, cntvoff_el2); } - -/* -* Should only be called on non-VHE systems. -* VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe(). -*/ -void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu) -{ -u64 val; - -/* Allow physical timer/counter access for the host */ - val =read_sysreg (cnthctl_el2); - val |=CNTHCTL_EL1PCTEN |CNTHCTL_EL1PCEN ; -write_sysreg (val, cnthctl_el2); -} - -/* -* Should only be called on non-VHE systems. -* VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe(). -*/ -void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu) -{ -u64 val; - -/* -* Disallow physical timer access for the guest -* Physical counter access is allowed -*/ - val =read_sysreg (cnthctl_el2); - val &= ~CNTHCTL_EL1PCEN ; - val |=CNTHCTL_EL1PCTEN ; -write_sysreg (val, cnthctl_el2); -}
Signature · 1 line
2.26.2
PATCH v2 11/14 arm64: kvm: Compile remaining hyp/ files for both VHE/nVHE
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
The following files in hyp/ contain only code shared by VHE/nVHE:
vgic-v3-sr.c, aarch32.c, vgic-v2-cpuif-proxy.c, entry.S, fpsimd.S
Compile them under both configurations. Deletions in image-vars.h reflect eliminated dependencies of nVHE code on the rest of the kernel.
--- arch/arm64/kernel/image-vars.h | 19 ------------------- arch/arm64/kvm/hyp/nvhe/Makefile | 5 +++-- 2 files changed, 3 insertions(+), 21 deletions(-)
arch/arm64/kernel/image-vars.h +0 -19
@@ -61,26 +61,8 @@ __efistub__ctype = _ctype;* memory mappings. */ -__kvm_nvhe___fpsimd_restore_state = __fpsimd_restore_state; -__kvm_nvhe___fpsimd_save_state = __fpsimd_save_state; -__kvm_nvhe___guest_enter = __guest_enter; -__kvm_nvhe___guest_exit = __guest_exit; __kvm_nvhe___icache_flags = __icache_flags; __kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; -__kvm_nvhe___vgic_v2_perform_cpuif_access = __vgic_v2_perform_cpuif_access; -__kvm_nvhe___vgic_v3_activate_traps = __vgic_v3_activate_traps; -__kvm_nvhe___vgic_v3_deactivate_traps = __vgic_v3_deactivate_traps; -__kvm_nvhe___vgic_v3_get_ich_vtr_el2 = __vgic_v3_get_ich_vtr_el2; -__kvm_nvhe___vgic_v3_init_lrs = __vgic_v3_init_lrs; -__kvm_nvhe___vgic_v3_perform_cpuif_access = __vgic_v3_perform_cpuif_access; -__kvm_nvhe___vgic_v3_read_vmcr = __vgic_v3_read_vmcr; -__kvm_nvhe___vgic_v3_restore_aprs = __vgic_v3_restore_aprs; -__kvm_nvhe___vgic_v3_restore_state = __vgic_v3_restore_state; -__kvm_nvhe___vgic_v3_save_aprs = __vgic_v3_save_aprs; -__kvm_nvhe___vgic_v3_save_state = __vgic_v3_save_state; -__kvm_nvhe___vgic_v3_write_vmcr = __vgic_v3_write_vmcr; -__kvm_nvhe_abort_guest_exit_end = abort_guest_exit_end; -__kvm_nvhe_abort_guest_exit_start = abort_guest_exit_start; __kvm_nvhe_arm64_const_caps_ready = arm64_const_caps_ready; __kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; __kvm_nvhe_arm64_ssbd_callback_required = arm64_ssbd_callback_required;
@@ -89,7 +71,6 @@ __kvm_nvhe_cpu_hwcaps = cpu_hwcaps; __kvm_nvhe_kimage_voffset = kimage_voffset; __kvm_nvhe_kvm_host_data = kvm_host_data; __kvm_nvhe_kvm_patch_vector_branch = kvm_patch_vector_branch; -__kvm_nvhe_kvm_skip_instr32 = kvm_skip_instr32; __kvm_nvhe_kvm_update_va_mask = kvm_update_va_mask; __kvm_nvhe_kvm_vgic_global_state = kvm_vgic_global_state; __kvm_nvhe_panic = panic;
arch/arm64/kvm/hyp/nvhe/Makefile +3 -2
@@ -7,8 +7,9 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) -obj-y := ../timer-sr.o timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o \ - ../hyp-entry.o +obj-y := ../vgic-v3-sr.o ../timer-sr.o timer-sr.o ../aarch32.o \ + ../vgic-v2-cpuif-proxy.o sysreg-sr.o debug-sr.o ../entry.o switch.o \ + ../fpsimd.o tlb.o ../hyp-entry.o obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
Signature · 1 line
2.26.2
PATCH v2 12/14 arm64: kvm: Add comments around __kvm_nvhe_ symbol aliases
In reply to David BrazdilThis patch is part of a series which builds KVM's non-VHE hyp code separately from VHE and the rest of the kernel.
With all source files split between VHE/nVHE, add comments around the list of symbols where nVHE code still links against kernel proper. Split them into groups and explain how each group is currently used.
Some of these dependencies will be removed in the future.
--- arch/arm64/kernel/image-vars.h | 47 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-)
arch/arm64/kernel/image-vars.h +30 -17
@@ -61,23 +61,36 @@ __efistub__ctype = _ctype;* memory mappings. */ -__kvm_nvhe___icache_flags = __icache_flags; -__kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; -__kvm_nvhe_arm64_const_caps_ready = arm64_const_caps_ready; -__kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; -__kvm_nvhe_arm64_ssbd_callback_required = arm64_ssbd_callback_required; -__kvm_nvhe_cpu_hwcap_keys = cpu_hwcap_keys; -__kvm_nvhe_cpu_hwcaps = cpu_hwcaps; -__kvm_nvhe_kimage_voffset = kimage_voffset; -__kvm_nvhe_kvm_host_data = kvm_host_data; -__kvm_nvhe_kvm_patch_vector_branch = kvm_patch_vector_branch; -__kvm_nvhe_kvm_update_va_mask = kvm_update_va_mask; -__kvm_nvhe_kvm_vgic_global_state = kvm_vgic_global_state; -__kvm_nvhe_panic = panic; -__kvm_nvhe_sve_load_state = sve_load_state; -__kvm_nvhe_sve_save_state = sve_save_state; -__kvm_nvhe_vgic_v2_cpuif_trap = vgic_v2_cpuif_trap; -__kvm_nvhe_vgic_v3_cpuif_trap = vgic_v3_cpuif_trap; +/* If nVHE code panics, it ERETs into panic() in EL1. */ +__kvm_nvhe_panic = panic; + +/* Stub HVC IDs are routed to a handler in .hyp.idmap.text. Executed in EL2. */ +__kvm_nvhe___kvm_handle_stub_hvc = __kvm_handle_stub_hvc; + +/* Alternative callbacks, referenced in .altinstructions. Executed in EL1. */ +__kvm_nvhe_arm64_enable_wa2_handling = arm64_enable_wa2_handling; +__kvm_nvhe_kvm_patch_vector_branch = kvm_patch_vector_branch; +__kvm_nvhe_kvm_update_va_mask = kvm_update_va_mask; + +/* Values used to convert between memory mappings, read-only after init. */ +__kvm_nvhe_kimage_voffset = kimage_voffset; + +/* Data shared with the kernel. */ +__kvm_nvhe_cpu_hwcaps = cpu_hwcaps; +__kvm_nvhe_cpu_hwcap_keys = cpu_hwcap_keys; +__kvm_nvhe___icache_flags = __icache_flags; +__kvm_nvhe_kvm_vgic_global_state = kvm_vgic_global_state; +__kvm_nvhe_arm64_ssbd_callback_required = arm64_ssbd_callback_required; +__kvm_nvhe_kvm_host_data = kvm_host_data; + +/* Static keys shared with the kernel. */ +__kvm_nvhe_arm64_const_caps_ready = arm64_const_caps_ready; +__kvm_nvhe_vgic_v2_cpuif_trap = vgic_v2_cpuif_trap; +__kvm_nvhe_vgic_v3_cpuif_trap = vgic_v3_cpuif_trap; + +/* SVE support, currently unused by nVHE. */ +__kvm_nvhe_sve_save_state = sve_save_state; +__kvm_nvhe_sve_load_state = sve_load_state;#endif /* CONFIG_KVM */
Signature · 1 line
2.26.2
PATCH v2 13/14 arm64: kvm: Remove __hyp_text macro, use build rules instead
In reply to David BrazdilWith nVHE code now fully separated from the rest of the kernel, the effects of the __hyp_text macro (which had to be applied on all nVHE code) can be achieved with build rules instead. The macro used to:
(a) move code to .hyp.text ELF section, now done by renaming .text using objcopy, and
(b) notrace would negate effects of CC_FLAGS_FTRACE, now those flags are erased from KBUILD_CFLAGS (same way as in EFI stub).
Note that by removing __hyp_text from code shared with VHE, all VHE code is now compiled into .text and without notrace.
Use of '.pushsection .hyp.text' removed from assembly files as this is now also covered by the build rules.
For MAINTAINERS: if needed to re-run, uses of macro were removed with the following command. Formatting was fixed up manually.
find arch/arm64/kvm/hyp -type f -name '*.c' -o -name '*.h' \
-exec sed -i 's/ __hyp_text//g' {} +--- arch/arm64/include/asm/kvm_emulate.h | 2 +- arch/arm64/include/asm/kvm_hyp.h | 4 +- arch/arm64/kvm/hyp/aarch32.c | 6 +- arch/arm64/kvm/hyp/debug-sr.h | 18 ++-- arch/arm64/kvm/hyp/entry.S | 1 - arch/arm64/kvm/hyp/fpsimd.S | 1 - arch/arm64/kvm/hyp/hyp-entry.S | 1 - arch/arm64/kvm/hyp/nvhe/Makefile | 7 +- arch/arm64/kvm/hyp/nvhe/debug-sr.c | 10 +- arch/arm64/kvm/hyp/nvhe/switch.c | 18 ++-- arch/arm64/kvm/hyp/nvhe/sysreg-sr.c | 10 +- arch/arm64/kvm/hyp/nvhe/timer-sr.c | 4 +- arch/arm64/kvm/hyp/nvhe/tlb.c | 14 ++- arch/arm64/kvm/hyp/switch.h | 35 +++--- arch/arm64/kvm/hyp/sysreg-sr.h | 27 ++--- arch/arm64/kvm/hyp/timer-sr.c | 2 +- arch/arm64/kvm/hyp/tlb.c | 6 +- arch/arm64/kvm/hyp/tlb.h | 15 ++- arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 4 +- arch/arm64/kvm/hyp/vgic-v3-sr.c | 130 ++++++++++------------- 20 files changed, 141 insertions(+), 174 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +1 -1
@@ -520,7 +520,7 @@ static __always_inline void kvm_skip_instr(struct kvm_vcpu *vcpu, bool is_wide_i* Skip an instruction which has been emulated at hyp while most guest sysregs * are live. */ -static __always_inline void __hyp_text __kvm_skip_instr(struct kvm_vcpu *vcpu) +static __always_inline void __kvm_skip_instr(struct kvm_vcpu *vcpu) { *vcpu_pc (vcpu) =read_sysreg_el2 (SYS_ELR ); vcpu->arch.ctxt.gp_regs.regs.pstate =read_sysreg_el2 (SYS_SPSR );
arch/arm64/include/asm/kvm_hyp.h +1 -3
@@ -13,8 +13,6 @@#include <asm/kvm_mmu.h> #include <asm/sysreg.h> -#define __hyp_text __section(.hyp.text) notrace -#define read_sysreg_elx (r,nvh,vh) \ ({ \ u64 reg; \
@@ -103,7 +101,7 @@ void __noreturn __hyp_do_panic(unsigned long, ...);* Must be called from hyp code running at EL2 with an updated VTTBR * and interrupts disabled. */ -static __always_inline void __hyp_text __load_guest_stage2(struct kvm *kvm) +static __always_inline void __load_guest_stage2(struct kvm *kvm) {write_sysreg (kvm->arch.vtcr, vtcr_el2);write_sysreg (kvm_get_vttbr (kvm), vttbr_el2);
arch/arm64/kvm/hyp/aarch32.c +3 -3
@@ -44,7 +44,7 @@ static const unsigned short cc_map[16] = {/* * Check if a trapped instruction should have been executed or not. */ -bool __hyp_text kvm_condition_valid32(const struct kvm_vcpu *vcpu) +bool kvm_condition_valid32 (const struct kvm_vcpu *vcpu) {unsigned long cpsr;u32 cpsr_cond;
@@ -93,7 +93,7 @@ bool __hyp_text kvm_condition_valid32(const struct kvm_vcpu *vcpu)* * IT[7:0] -> CPSR[26:25],CPSR[15:10] */ -static void __hyp_text kvm_adjust_itstate(struct kvm_vcpu *vcpu) +static void kvm_adjust_itstate (struct kvm_vcpu *vcpu) {unsigned long itbits, cond;unsigned long cpsr = *vcpu_cpsr (vcpu);
@@ -123,7 +123,7 @@ static void __hyp_text kvm_adjust_itstate(struct kvm_vcpu *vcpu)* kvm_skip_instr - skip a trapped instruction and proceed to the next * @vcpu: The vcpu pointer */ -void __hyp_text kvm_skip_instr32(struct kvm_vcpu *vcpu, bool is_wide_instr) +void kvm_skip_instr32 (struct kvm_vcpu *vcpu,bool is_wide_instr) {bool is_thumb;
arch/arm64/kvm/hyp/debug-sr.h +8 -10
@@ -88,9 +88,9 @@default :write_debug (ptr[0 ], reg,0 ); \ } -static inline void __hyp_text -__debug_save_state (struct kvm_vcpu *vcpu,struct kvm_guest_debug_arch *dbg, -struct kvm_cpu_context *ctxt) +static inline void __debug_save_state (struct kvm_vcpu *vcpu, +struct kvm_guest_debug_arch *dbg, +struct kvm_cpu_context *ctxt) {u64 aa64dfr0;int brps, wrps;
@@ -107,9 +107,9 @@ __debug_save_state(struct kvm_vcpu *vcpu, struct kvm_guest_debug_arch *dbg, ctxt->sys_regs[MDCCINT_EL1 ] =read_sysreg (mdccint_el1); } -static inline void __hyp_text -__debug_restore_state (struct kvm_vcpu *vcpu,struct kvm_guest_debug_arch *dbg, -struct kvm_cpu_context *ctxt) +static inline void __debug_restore_state (struct kvm_vcpu *vcpu, +struct kvm_guest_debug_arch *dbg, +struct kvm_cpu_context *ctxt) {u64 aa64dfr0;int brps, wrps;
@@ -127,8 +127,7 @@ __debug_restore_state(struct kvm_vcpu *vcpu, struct kvm_guest_debug_arch *dbg,write_sysreg (ctxt->sys_regs[MDCCINT_EL1 ], mdccint_el1); } -static inline void __hyp_text -__debug_switch_to_guest_common (struct kvm_vcpu *vcpu) +static inline void __debug_switch_to_guest_common (struct kvm_vcpu *vcpu) {struct kvm_cpu_context *host_ctxt;struct kvm_cpu_context *guest_ctxt;
@@ -147,8 +146,7 @@ __debug_switch_to_guest_common(struct kvm_vcpu *vcpu)__debug_restore_state (vcpu, guest_dbg, guest_ctxt); } -static inline void __hyp_text -__debug_switch_to_host_common (struct kvm_vcpu *vcpu) +static inline void __debug_switch_to_host_common (struct kvm_vcpu *vcpu) {struct kvm_cpu_context *host_ctxt;struct kvm_cpu_context *guest_ctxt;
arch/arm64/kvm/hyp/entry.S +0 -1
@@ -20,7 +20,6 @@ #define CPU_XREG_OFFSET(x) CPU_GP_REG_OFFSET(CPU_USER_PT_REGS + 8*x) .text - .pushsection .hyp.text, "ax" /* * We treat x18 as callee-saved as the host may use it as a platform
arch/arm64/kvm/hyp/fpsimd.S +0 -1
@@ -9,7 +9,6 @@ #include <asm/fpsimdmacros.h> .text - .pushsection .hyp.text, "ax" SYM_FUNC_START(__fpsimd_save_state) fpsimd_save x0, 1
arch/arm64/kvm/hyp/hyp-entry.S +0 -1
@@ -17,7 +17,6 @@ #include <asm/mmu.h> .text - .pushsection .hyp.text, "ax" el1_sync: // Guest trapped into EL2
arch/arm64/kvm/hyp/nvhe/Makefile +6 -1
@@ -22,7 +22,12 @@ $(obj)/%.hyp.o: $(obj)/%.hyp.tmp.o FORCE $(call if_changed,hypcopy) quiet_cmd_hypcopy = HYPCOPY $@ - cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@ + cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ \ + --rename-section=.text=.hyp.text \ + $< $@ + +# Remove ftrace CFLAGS, this is equivalent to the 'notrace' annotation. +KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) # KVM nVHE code is run at a different exception code with a different map, so # compiler instrumentation that inserts callbacks or checks into the code may
arch/arm64/kvm/hyp/nvhe/debug-sr.c +5 -5
@@ -14,7 +14,7 @@#include "../debug-sr.h" -static void __hyp_text __debug_save_spe(u64 *pmscr_el1) +static void __debug_save_spe (u64 *pmscr_el1) {u64 reg;
@@ -46,7 +46,7 @@ static void __hyp_text __debug_save_spe(u64 *pmscr_el1)dsb (nsh); } -static void __hyp_text __debug_restore_spe(u64 pmscr_el1) +static void __debug_restore_spe (u64 pmscr_el1) {if (!pmscr_el1)return ;
@@ -58,20 +58,20 @@ static void __hyp_text __debug_restore_spe(u64 pmscr_el1)write_sysreg_s (pmscr_el1,SYS_PMSCR_EL1 ); } -void __hyp_text __debug_switch_to_guest(struct kvm_vcpu *vcpu) +void __debug_switch_to_guest (struct kvm_vcpu *vcpu) {/* Disable and flush SPE data generation */ __debug_save_spe (&vcpu->arch.host_debug_state.pmscr_el1);__debug_switch_to_guest_common (vcpu); } -void __hyp_text __debug_switch_to_host(struct kvm_vcpu *vcpu) +void __debug_switch_to_host (struct kvm_vcpu *vcpu) {__debug_restore_spe (vcpu->arch.host_debug_state.pmscr_el1);__debug_switch_to_host_common (vcpu); } -u32 __hyp_text __kvm_get_mdcr_el2(void) +u32 __kvm_get_mdcr_el2 (void ) {return read_sysreg (mdcr_el2); }
arch/arm64/kvm/hyp/nvhe/switch.c +9 -9
@@ -26,7 +26,7 @@#include "../switch.h" -static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) +static void __activate_traps (struct kvm_vcpu *vcpu) {u64 val;
@@ -57,7 +57,7 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) } } -static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) +static void __deactivate_traps (struct kvm_vcpu *vcpu) {u64 mdcr_el2;
@@ -92,13 +92,13 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu)write_sysreg (CPTR_EL2_DEFAULT , cptr_el2); } -static void __hyp_text __deactivate_vm(struct kvm_vcpu *vcpu) +static void __deactivate_vm (struct kvm_vcpu *vcpu) {write_sysreg (0 , vttbr_el2); }/* Save VGICv3 state on non-VHE systems */ -static void __hyp_text __hyp_vgic_save_state(struct kvm_vcpu *vcpu) +static void __hyp_vgic_save_state (struct kvm_vcpu *vcpu) {if (static_branch_unlikely (&kvm_vgic_global_state.gicv3_cpuif)) {__vgic_v3_save_state (vcpu);
@@ -107,7 +107,7 @@ static void __hyp_text __hyp_vgic_save_state(struct kvm_vcpu *vcpu) }/* Restore VGICv3 state on non_VEH systems */ -static void __hyp_text __hyp_vgic_restore_state(struct kvm_vcpu *vcpu) +static void __hyp_vgic_restore_state (struct kvm_vcpu *vcpu) {if (static_branch_unlikely (&kvm_vgic_global_state.gicv3_cpuif)) {__vgic_v3_activate_traps (vcpu);
@@ -118,7 +118,7 @@ static void __hyp_text __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)/** * Disable host events, enable guest events */ -static bool __hyp_text __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt) +static bool __pmu_switch_to_guest (struct kvm_cpu_context *host_ctxt) {struct kvm_host_data *host;struct kvm_pmu_events *pmu;
@@ -138,7 +138,7 @@ static bool __hyp_text __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt)/** * Disable guest events, enable host events */ -static void __hyp_text __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt) +static void __pmu_switch_to_host (struct kvm_cpu_context *host_ctxt) {struct kvm_host_data *host;struct kvm_pmu_events *pmu;
@@ -154,7 +154,7 @@ static void __hyp_text __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt) }/* Switch to the guest for legacy non-VHE systems */ -int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) +int __kvm_vcpu_run (struct kvm_vcpu *vcpu) {struct kvm_cpu_context *host_ctxt;struct kvm_cpu_context *guest_ctxt;
@@ -241,7 +241,7 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)return exit_code; } -void __hyp_text __noreturn hyp_panic(struct kvm_cpu_context *host_ctxt) +void __noreturn hyp_panic (struct kvm_cpu_context *host_ctxt) {u64 spsr =read_sysreg_el2 (SYS_SPSR );u64 elr =read_sysreg_el2 (SYS_ELR );
arch/arm64/kvm/hyp/nvhe/sysreg-sr.c +5 -5
@@ -18,7 +18,7 @@* Non-VHE: Both host and guest must save everything. */ -void __hyp_text __sysreg_save_state_nvhe(struct kvm_cpu_context *ctxt) +void __sysreg_save_state_nvhe (struct kvm_cpu_context *ctxt) {__sysreg_save_el1_state (ctxt);__sysreg_save_common_state (ctxt);
@@ -26,7 +26,7 @@ void __hyp_text __sysreg_save_state_nvhe(struct kvm_cpu_context *ctxt)__sysreg_save_el2_return_state (ctxt); } -void __hyp_text __sysreg_restore_state_nvhe(struct kvm_cpu_context *ctxt) +void __sysreg_restore_state_nvhe (struct kvm_cpu_context *ctxt) {__sysreg_restore_el1_state (ctxt);__sysreg_restore_common_state (ctxt);
@@ -34,17 +34,17 @@ void __hyp_text __sysreg_restore_state_nvhe(struct kvm_cpu_context *ctxt)__sysreg_restore_el2_return_state (ctxt); } -void __hyp_text __sysreg32_save_state(struct kvm_vcpu *vcpu) +void __sysreg32_save_state (struct kvm_vcpu *vcpu) {___sysreg32_save_state (vcpu); } -void __hyp_text __sysreg32_restore_state(struct kvm_vcpu *vcpu) +void __sysreg32_restore_state (struct kvm_vcpu *vcpu) {___sysreg32_restore_state (vcpu); } -void __hyp_text __kvm_enable_ssbs(void) +void __kvm_enable_ssbs (void ) {u64 tmp;
arch/arm64/kvm/hyp/nvhe/timer-sr.c +2 -2
@@ -14,7 +14,7 @@* Should only be called on non-VHE systems. * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe(). */ -void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu) +void __timer_disable_traps (struct kvm_vcpu *vcpu) {u64 val;
@@ -28,7 +28,7 @@ void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu)* Should only be called on non-VHE systems. * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe(). */ -void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu) +void __timer_enable_traps (struct kvm_vcpu *vcpu) {u64 val;
arch/arm64/kvm/hyp/nvhe/tlb.c +6 -8
@@ -12,8 +12,7 @@#include "../tlb.h" -static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm, -struct tlb_inv_context *cxt) +static void __tlb_switch_to_guest (struct kvm *kvm,struct tlb_inv_context *cxt) {if (cpus_have_final_cap (ARM64_WORKAROUND_SPECULATIVE_AT_NVHE )) {u64 val;
@@ -35,8 +34,7 @@ static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm,isb (); } -static void __hyp_text __tlb_switch_to_host(struct kvm *kvm, -struct tlb_inv_context *cxt) +static void __tlb_switch_to_host (struct kvm *kvm,struct tlb_inv_context *cxt) {write_sysreg (0 , vttbr_el2);
@@ -48,22 +46,22 @@ static void __hyp_text __tlb_switch_to_host(struct kvm *kvm, } } -void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) +void __kvm_tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa) {__tlb_flush_vmid_ipa (kvm, ipa); } -void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm) +void __kvm_tlb_flush_vmid (struct kvm *kvm) {__tlb_flush_vmid (kvm); } -void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu) +void __kvm_tlb_flush_local_vmid (struct kvm_vcpu *vcpu) {__tlb_flush_local_vmid (vcpu); } -void __hyp_text __kvm_flush_vm_context(void) +void __kvm_flush_vm_context (void ) {__tlb_flush_vm_context (); }
arch/arm64/kvm/hyp/switch.h +16 -19
@@ -30,7 +30,7 @@static const char __hyp_panic_string[] ="HYP panic:\nPS:%08llx PC:%016llx ESR:%08llx\nFAR:%016llx HPFAR:%016llx PAR:%016llx\nVCPU:%p\n" ;/* Check whether the FP regs were dirtied while in the host-side run loop: */ -static inline bool __hyp_text update_fp_enabled(struct kvm_vcpu *vcpu) +static inline bool update_fp_enabled (struct kvm_vcpu *vcpu) {/* * When the system doesn't support FP/SIMD, we cannot rely on
@@ -48,7 +48,7 @@ static inline bool __hyp_text update_fp_enabled(struct kvm_vcpu *vcpu) }/* Save the 32-bit only FPSIMD system register state */ -static inline void __hyp_text __fpsimd_save_fpexc32(struct kvm_vcpu *vcpu) +static inline void __fpsimd_save_fpexc32 (struct kvm_vcpu *vcpu) {if (!vcpu_el1_is_32bit (vcpu))return ;
@@ -56,7 +56,7 @@ static inline void __hyp_text __fpsimd_save_fpexc32(struct kvm_vcpu *vcpu) vcpu->arch.ctxt.sys_regs[FPEXC32_EL2 ] =read_sysreg (fpexc32_el2); } -static inline void __hyp_text __activate_traps_fpsimd32(struct kvm_vcpu *vcpu) +static inline void __activate_traps_fpsimd32 (struct kvm_vcpu *vcpu) {/* * We are about to set CPTR_EL2.TFP to trap all floating point
@@ -73,7 +73,7 @@ static inline void __hyp_text __activate_traps_fpsimd32(struct kvm_vcpu *vcpu) } } -static inline void __hyp_text __activate_traps_common(struct kvm_vcpu *vcpu) +static inline void __activate_traps_common (struct kvm_vcpu *vcpu) {/* Trap on AArch32 cp15 c15 (impdef sysregs) accesses (EL1 or EL0) */ write_sysreg (1 <<15 , hstr_el2);
@@ -89,13 +89,13 @@ static inline void __hyp_text __activate_traps_common(struct kvm_vcpu *vcpu)write_sysreg (vcpu->arch.mdcr_el2, mdcr_el2); } -static inline void __hyp_text __deactivate_traps_common(void) +static inline void __deactivate_traps_common (void ) {write_sysreg (0 , hstr_el2);write_sysreg (0 , pmuserenr_el0); } -static inline void __hyp_text ___activate_traps(struct kvm_vcpu *vcpu) +static inline void ___activate_traps (struct kvm_vcpu *vcpu) {u64 hcr = vcpu->arch.hcr_el2;
@@ -108,7 +108,7 @@ static inline void __hyp_text ___activate_traps(struct kvm_vcpu *vcpu)write_sysreg_s (vcpu->arch.vsesr_el2,SYS_VSESR_EL2 ); } -static inline void __hyp_text ___deactivate_traps(struct kvm_vcpu *vcpu) +static inline void ___deactivate_traps (struct kvm_vcpu *vcpu) {/* * If we pended a virtual abort, preserve it until it gets
@@ -122,12 +122,12 @@ static inline void __hyp_text ___deactivate_traps(struct kvm_vcpu *vcpu) } } -static inline void __hyp_text __activate_vm(struct kvm *kvm) +static inline void __activate_vm (struct kvm *kvm) {__load_guest_stage2 (kvm); } -static inline bool __hyp_text __translate_far_to_hpfar(u64 far, u64 *hpfar) +static inline bool __translate_far_to_hpfar (u64 far,u64 *hpfar) {u64 par, tmp;
@@ -156,7 +156,7 @@ static inline bool __hyp_text __translate_far_to_hpfar(u64 far, u64 *hpfar)return true; } -static inline bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu) +static inline bool __populate_fault_info (struct kvm_vcpu *vcpu) {u8 ec;u64 esr;
@@ -196,7 +196,7 @@ static inline bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu) }/* Check for an FPSIMD/SVE trap and handle as appropriate */ -static inline bool __hyp_text __hyp_handle_fpsimd(struct kvm_vcpu *vcpu) +static inline bool __hyp_handle_fpsimd (struct kvm_vcpu *vcpu) {bool vhe, sve_guest, sve_host;u8 hsr_ec;
@@ -278,7 +278,7 @@ static inline bool __hyp_text __hyp_handle_fpsimd(struct kvm_vcpu *vcpu)return true; } -static inline bool __hyp_text handle_tx2_tvm(struct kvm_vcpu *vcpu) +static inline bool handle_tx2_tvm (struct kvm_vcpu *vcpu) {u32 sysreg =esr_sys64_to_sysreg (kvm_vcpu_get_hsr (vcpu));int rt =kvm_vcpu_sys_get_rt (vcpu);
@@ -338,8 +338,7 @@ static inline bool __hyp_text handle_tx2_tvm(struct kvm_vcpu *vcpu)* the guest, false when we should restore the host state and return to the * main run loop. */ -static inline bool __hyp_text -fixup_guest_exit (struct kvm_vcpu *vcpu,u64 *exit_code) +static inline bool fixup_guest_exit (struct kvm_vcpu *vcpu,u64 *exit_code) {if (ARM_EXCEPTION_CODE (*exit_code) !=ARM_EXCEPTION_IRQ ) vcpu->arch.fault.esr_el2 =read_sysreg_el2 (SYS_ESR );
@@ -408,7 +407,7 @@ fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)return false; } -static inline bool __hyp_text __needs_ssbd_off(struct kvm_vcpu *vcpu) +static inline bool __needs_ssbd_off (struct kvm_vcpu *vcpu) {if (!cpus_have_final_cap (ARM64_SSBD ))return false;
@@ -416,8 +415,7 @@ static inline bool __hyp_text __needs_ssbd_off(struct kvm_vcpu *vcpu)return !(vcpu->arch.workaround_flags &VCPU_WORKAROUND_2_FLAG ); } -static inline void __hyp_text -__set_guest_arch_workaround_state (struct kvm_vcpu *vcpu) +static inline void __set_guest_arch_workaround_state (struct kvm_vcpu *vcpu) {#ifdef CONFIG_ARM64_SSBD /*
@@ -430,8 +428,7 @@ __set_guest_arch_workaround_state(struct kvm_vcpu *vcpu)#endif } -static inline void __hyp_text -__set_host_arch_workaround_state (struct kvm_vcpu *vcpu) +static inline void __set_host_arch_workaround_state (struct kvm_vcpu *vcpu) {#ifdef CONFIG_ARM64_SSBD /*
arch/arm64/kvm/hyp/sysreg-sr.h +10 -17
@@ -15,8 +15,7 @@#include <asm/kvm_emulate.h> #include <asm/kvm_hyp.h> -static inline void __hyp_text -__sysreg_save_common_state (struct kvm_cpu_context *ctxt) +static inline void __sysreg_save_common_state (struct kvm_cpu_context *ctxt) { ctxt->sys_regs[MDSCR_EL1 ] =read_sysreg (mdscr_el1);
@@ -27,15 +26,13 @@ __sysreg_save_common_state(struct kvm_cpu_context *ctxt) ctxt->gp_regs.regs.sp =read_sysreg (sp_el0); } -static inline void __hyp_text -__sysreg_save_user_state (struct kvm_cpu_context *ctxt) +static inline void __sysreg_save_user_state (struct kvm_cpu_context *ctxt) { ctxt->sys_regs[TPIDR_EL0 ] =read_sysreg (tpidr_el0); ctxt->sys_regs[TPIDRRO_EL0 ] =read_sysreg (tpidrro_el0); } -static inline void __hyp_text -__sysreg_save_el1_state (struct kvm_cpu_context *ctxt) +static inline void __sysreg_save_el1_state (struct kvm_cpu_context *ctxt) { ctxt->sys_regs[CSSELR_EL1 ] =read_sysreg (csselr_el1); ctxt->sys_regs[SCTLR_EL1 ] =read_sysreg_el1 (SYS_SCTLR );
@@ -61,8 +58,7 @@ __sysreg_save_el1_state(struct kvm_cpu_context *ctxt) ctxt->gp_regs.spsr[KVM_SPSR_EL1 ]=read_sysreg_el1 (SYS_SPSR ); } -static inline void __hyp_text -__sysreg_save_el2_return_state (struct kvm_cpu_context *ctxt) +static inline void __sysreg_save_el2_return_state (struct kvm_cpu_context *ctxt) { ctxt->gp_regs.regs.pc =read_sysreg_el2 (SYS_ELR ); ctxt->gp_regs.regs.pstate =read_sysreg_el2 (SYS_SPSR );
@@ -71,8 +67,7 @@ __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt) ctxt->sys_regs[DISR_EL1 ] =read_sysreg_s (SYS_VDISR_EL2 ); } -static inline void __hyp_text -__sysreg_restore_common_state (struct kvm_cpu_context *ctxt) +static inline void __sysreg_restore_common_state (struct kvm_cpu_context *ctxt) {write_sysreg (ctxt->sys_regs[MDSCR_EL1 ], mdscr_el1);
@@ -83,15 +78,13 @@ __sysreg_restore_common_state(struct kvm_cpu_context *ctxt)write_sysreg (ctxt->gp_regs.regs.sp, sp_el0); } -static inline void __hyp_text -__sysreg_restore_user_state (struct kvm_cpu_context *ctxt) +static inline void __sysreg_restore_user_state (struct kvm_cpu_context *ctxt) {write_sysreg (ctxt->sys_regs[TPIDR_EL0 ], tpidr_el0);write_sysreg (ctxt->sys_regs[TPIDRRO_EL0 ], tpidrro_el0); } -static inline void __hyp_text -__sysreg_restore_el1_state (struct kvm_cpu_context *ctxt) +static inline void __sysreg_restore_el1_state (struct kvm_cpu_context *ctxt) {write_sysreg (ctxt->sys_regs[MPIDR_EL1 ], vmpidr_el2);write_sysreg (ctxt->sys_regs[CSSELR_EL1 ], csselr_el1);
@@ -149,7 +142,7 @@ __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)write_sysreg_el1 (ctxt->gp_regs.spsr[KVM_SPSR_EL1 ],SYS_SPSR ); } -static inline void __hyp_text +static inline void __sysreg_restore_el2_return_state (struct kvm_cpu_context *ctxt) {u64 pstate = ctxt->gp_regs.regs.pstate;
@@ -176,7 +169,7 @@ __sysreg_restore_el2_return_state(struct kvm_cpu_context *ctxt)write_sysreg_s (ctxt->sys_regs[DISR_EL1 ],SYS_VDISR_EL2 ); } -static inline void __hyp_text ___sysreg32_save_state(struct kvm_vcpu *vcpu) +static inline void ___sysreg32_save_state (struct kvm_vcpu *vcpu) {u64 *spsr, *sysreg;
@@ -198,7 +191,7 @@ static inline void __hyp_text ___sysreg32_save_state(struct kvm_vcpu *vcpu) sysreg[DBGVCR32_EL2 ] =read_sysreg (dbgvcr32_el2); } -static inline void __hyp_text ___sysreg32_restore_state(struct kvm_vcpu *vcpu) +static inline void ___sysreg32_restore_state (struct kvm_vcpu *vcpu) {u64 *spsr, *sysreg;
arch/arm64/kvm/hyp/timer-sr.c +1 -1
@@ -6,7 +6,7 @@#include <asm/kvm_hyp.h> -void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high) +void __kvm_timer_set_cntvoff (u32 cntvoff_low,u32 cntvoff_high) {u64 cntvoff = (u64 )cntvoff_high <<32 | cntvoff_low;write_sysreg (cntvoff, cntvoff_el2);
arch/arm64/kvm/hyp/tlb.c +2 -4
@@ -12,8 +12,7 @@#include "tlb.h" -static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm, -struct tlb_inv_context *cxt) +static void __tlb_switch_to_guest (struct kvm *kvm,struct tlb_inv_context *cxt) {u64 val;
@@ -56,8 +55,7 @@ static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm,isb (); } -static void __hyp_text __tlb_switch_to_host(struct kvm *kvm, -struct tlb_inv_context *cxt) +static void __tlb_switch_to_host (struct kvm *kvm,struct tlb_inv_context *cxt) {/* * We're done with the TLB operation, let's restore the host's
arch/arm64/kvm/hyp/tlb.h +6 -9
@@ -19,13 +19,10 @@ struct tlb_inv_context {u64 sctlr; }; -static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm, -struct tlb_inv_context *cxt); -static void __hyp_text __tlb_switch_to_host(struct kvm *kvm, -struct tlb_inv_context *cxt); +static void __tlb_switch_to_guest (struct kvm *kvm,struct tlb_inv_context *cxt); +static void __tlb_switch_to_host (struct kvm *kvm,struct tlb_inv_context *cxt); -static inline void __hyp_text -__tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa) +static inline void __tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa) {struct tlb_inv_context cxt;
@@ -79,7 +76,7 @@ __tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)__tlb_switch_to_host (kvm, &cxt); } -static inline void __hyp_text __tlb_flush_vmid(struct kvm *kvm) +static inline void __tlb_flush_vmid (struct kvm *kvm) {struct tlb_inv_context cxt;
@@ -96,7 +93,7 @@ static inline void __hyp_text __tlb_flush_vmid(struct kvm *kvm)__tlb_switch_to_host (kvm, &cxt); } -static inline void __hyp_text __tlb_flush_local_vmid(struct kvm_vcpu *vcpu) +static inline void __tlb_flush_local_vmid (struct kvm_vcpu *vcpu) {struct kvm *kvm =kern_hyp_va (kern_hyp_va (vcpu)->kvm);struct tlb_inv_context cxt;
@@ -111,7 +108,7 @@ static inline void __hyp_text __tlb_flush_local_vmid(struct kvm_vcpu *vcpu)__tlb_switch_to_host (kvm, &cxt); } -static inline void __hyp_text __tlb_flush_vm_context(void) +static inline void __tlb_flush_vm_context (void ) {dsb (ishst);__tlbi (alle1is);
arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c +2 -2
@@ -13,7 +13,7 @@#include <asm/kvm_hyp.h> #include <asm/kvm_mmu.h> -static bool __hyp_text __is_be(struct kvm_vcpu *vcpu) +static bool __is_be (struct kvm_vcpu *vcpu) {if (vcpu_mode_is_32bit (vcpu))return !!(read_sysreg_el2 (SYS_SPSR ) &PSR_AA32_E_BIT );
@@ -32,7 +32,7 @@ static bool __hyp_text __is_be(struct kvm_vcpu *vcpu)* 0: Not a GICV access * -1: Illegal GICV access successfully performed */ -int __hyp_text __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu) +int __vgic_v2_perform_cpuif_access (struct kvm_vcpu *vcpu) {struct kvm *kvm =kern_hyp_va (vcpu->kvm);struct vgic_dist *vgic = &kvm->arch.vgic;
arch/arm64/kvm/hyp/vgic-v3-sr.c +58 -72
434 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 14/14 arm64: kvm: Lift instrumentation restrictions on VHE
In reply to David BrazdilWith VHE and nVHE executable code completely separated, remove build config that disabled GCOV/KASAN/UBSAN/KCOV instrumentation for VHE as these now execute under the same memory mappings as the rest of the kernel.
No violations are currently being reported by either KASAN or UBSAN.
--- arch/arm64/kvm/hyp/Makefile | 8 -------- 1 file changed, 8 deletions(-)
arch/arm64/kvm/hyp/Makefile +0 -8
@@ -11,11 +11,3 @@ obj-$(CONFIG_KVM_INDIRECT_VECTORS) += smccc_wa.o vhe-y := vgic-v3-sr.o timer-sr.o aarch32.o vgic-v2-cpuif-proxy.o sysreg-sr.o \ debug-sr.o entry.o switch.o fpsimd.o tlb.o hyp-entry.o - -# KVM code is run at a different exception code with a different map, so -# compiler instrumentation that inserts callbacks or checks into the code may -# cause crashes. Just disable it. -GCOV_PROFILE := n -KASAN_SANITIZE := n -UBSAN_SANITIZE := n -KCOV_INSTRUMENT := n
Signature · 1 line
2.26.2