Skip to content

Commit 7621712

Browse files
David BrazdilMarc Zyngier
authored andcommitted
KVM: arm64: Add build rules for separate VHE/nVHE object files
Add new folders arch/arm64/kvm/hyp/{vhe,nvhe} and Makefiles for building code that runs in EL2 under VHE/nVHE KVM, repsectivelly. Add an include folder for hyp-specific header files which will include code common to VHE/nVHE. Build nVHE code with -D__KVM_NVHE_HYPERVISOR__, VHE code with -D__KVM_VHE_HYPERVISOR__. Under nVHE 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. The nVHE ELF symbol prefix is added to kallsyms.c as ignored. EL2-only symbols will never appear in EL1 stack traces. Due to symbol prefixing, add a section in image-vars.h for aliases of symbols that are defined in nVHE EL2 and accessed by kernel in EL1 or vice versa. Signed-off-by: David Brazdil <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7b2399e commit 7621712

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

arch/arm64/kernel/image-vars.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,18 @@ __efistub__ctype = _ctype;
5151

5252
#endif
5353

54+
#ifdef CONFIG_KVM
55+
56+
/*
57+
* KVM nVHE code has its own symbol namespace prefixed with __kvm_nvhe_, to
58+
* separate it from the kernel proper. The following symbols are legally
59+
* accessed by it, therefore provide aliases to make them linkable.
60+
* Do not include symbols which may not be safely accessed under hypervisor
61+
* memory mappings.
62+
*/
63+
64+
#define KVM_NVHE_ALIAS(sym) __kvm_nvhe_##sym = sym;
65+
66+
#endif /* CONFIG_KVM */
67+
5468
#endif /* __ARM64_KERNEL_IMAGE_VARS_H */

arch/arm64/kvm/hyp/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
# Makefile for Kernel-based Virtual Machine module, HYP part
44
#
55

6-
ccflags-y += -fno-stack-protector -DDISABLE_BRANCH_PROFILING \
7-
$(DISABLE_STACKLEAK_PLUGIN)
6+
incdir := $(srctree)/$(src)/include
7+
subdir-asflags-y := -I$(incdir)
8+
subdir-ccflags-y := -I$(incdir) \
9+
-fno-stack-protector \
10+
-DDISABLE_BRANCH_PROFILING \
11+
$(DISABLE_STACKLEAK_PLUGIN)
812

9-
obj-$(CONFIG_KVM) += hyp.o
13+
obj-$(CONFIG_KVM) += hyp.o nvhe/
1014
obj-$(CONFIG_KVM_INDIRECT_VECTORS) += smccc_wa.o
1115

1216
hyp-y := vgic-v3-sr.o timer-sr.o aarch32.o vgic-v2-cpuif-proxy.o sysreg-sr.o \

arch/arm64/kvm/hyp/nvhe/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
4+
#
5+
6+
asflags-y := -D__KVM_NVHE_HYPERVISOR__
7+
ccflags-y := -D__KVM_NVHE_HYPERVISOR__
8+
9+
obj-y :=
10+
11+
obj-y := $(patsubst %.o,%.hyp.o,$(obj-y))
12+
extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
13+
14+
$(obj)/%.hyp.tmp.o: $(src)/%.c FORCE
15+
$(call if_changed_rule,cc_o_c)
16+
$(obj)/%.hyp.tmp.o: $(src)/%.S FORCE
17+
$(call if_changed_rule,as_o_S)
18+
$(obj)/%.hyp.o: $(obj)/%.hyp.tmp.o FORCE
19+
$(call if_changed,hypcopy)
20+
21+
quiet_cmd_hypcopy = HYPCOPY $@
22+
cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
23+
24+
# KVM nVHE code is run at a different exception code with a different map, so
25+
# compiler instrumentation that inserts callbacks or checks into the code may
26+
# cause crashes. Just disable it.
27+
GCOV_PROFILE := n
28+
KASAN_SANITIZE := n
29+
UBSAN_SANITIZE := n
30+
KCOV_INSTRUMENT := n
31+
32+
# Skip objtool checking for this directory because nVHE code is compiled with
33+
# non-standard build rules.
34+
OBJECT_FILES_NON_STANDARD := y

arch/arm64/kvm/hyp/vhe/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
4+
#
5+
6+
asflags-y := -D__KVM_VHE_HYPERVISOR__
7+
ccflags-y := -D__KVM_VHE_HYPERVISOR__
8+
9+
obj-y :=
10+
11+
# KVM code is run at a different exception code with a different map, so
12+
# compiler instrumentation that inserts callbacks or checks into the code may
13+
# cause crashes. Just disable it.
14+
GCOV_PROFILE := n
15+
KASAN_SANITIZE := n
16+
UBSAN_SANITIZE := n
17+
KCOV_INSTRUMENT := n

scripts/kallsyms.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static bool is_ignored_symbol(const char *name, char type)
109109
".LASANPC", /* s390 kasan local symbols */
110110
"__crc_", /* modversions */
111111
"__efistub_", /* arm64 EFI stub namespace */
112+
"__kvm_nvhe_", /* arm64 non-VHE KVM namespace */
112113
NULL
113114
};
114115

0 commit comments

Comments
 (0)