• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
4#
5
6asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
7
8# Tracepoint and MMIO logging symbols should not be visible at nVHE KVM as
9# there is no way to execute them and any such MMIO access from nVHE KVM
10# will explode instantly (Words of Marc Zyngier). So introduce a generic flag
11# __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM.
12ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
13ccflags-y += -fno-stack-protector	\
14	     -DDISABLE_BRANCH_PROFILING	\
15	     $(DISABLE_STACKLEAK_PLUGIN)
16
17HYPREL := arch/arm64/tools/gen-hyprel
18
19##
20## Build rules for compiling nVHE hyp code
21## Output of this folder is `kvm_nvhe.o`, a partially linked object
22## file containing all nVHE hyp code and data.
23##
24
25hyp-obj := $(patsubst %.o,%.nvhe.o,$(hyp-obj-y))
26targets += $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-reloc.o
27
28# 1) Compile all source files to `.nvhe.o` object files. The file extension
29#    avoids file name clashes for files shared with VHE.
30$(obj)/%.nvhe.o: $(src)/%.c FORCE
31	$(call if_changed_rule,cc_o_c)
32$(obj)/%.nvhe.o: $(src)/%.S FORCE
33	$(call if_changed_rule,as_o_S)
34
35# 2) Partially link all '.nvhe.o' files and apply the linker script.
36#    Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
37#    Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
38#          the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
39#          keep the dependency on the target while avoiding an error from
40#          GNU ld if the linker script is passed to it twice.
41LDFLAGS_kvm_nvhe.tmp.o := -r -T
42$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
43	$(call if_changed,ld)
44
45# 3) Generate list of hyp code/data positions that need to be relocated at
46#    runtime. Because the hypervisor is part of the kernel binary, relocations
47#    produce a kernel VA. We enumerate relocations targeting hyp at build time
48#    and convert the kernel VAs at those positions to hyp VAs.
49$(obj)/hyp-reloc.S: $(obj)/kvm_nvhe.tmp.o FORCE
50	$(call if_changed,hyprel)
51
52# 4) Compile hyp-reloc.S and link it into the existing partially linked object.
53#    The object file now contains a section with pointers to hyp positions that
54#    will contain kernel VAs at runtime. These pointers have relocations on them
55#    so that they get updated as the hyp object is linked into `vmlinux`.
56LDFLAGS_kvm_nvhe.rel.o := -r
57$(obj)/kvm_nvhe.rel.o: $(obj)/kvm_nvhe.tmp.o $(obj)/hyp-reloc.o FORCE
58	$(call if_changed,ld)
59
60# 5) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
61#    Prefixes names of ELF symbols with '__kvm_nvhe_'.
62$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.rel.o FORCE
63	$(call if_changed,hypcopy)
64
65# The HYPREL command calls `gen-hyprel` to generate an assembly file with
66# a list of relocations targeting hyp code/data.
67quiet_cmd_hyprel = HYPREL  $@
68      cmd_hyprel = $(HYPREL) $< > $@
69
70# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
71# to avoid clashes with VHE code/data.
72quiet_cmd_hypcopy = HYPCOPY $@
73      cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
74
75# Remove ftrace, Shadow Call Stack, and CFI CFLAGS.
76# This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations.
77KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
78# Starting from 13.0.0 llvm emits SHT_REL section '.llvm.call-graph-profile'
79# when profile optimization is applied. gen-hyprel does not support SHT_REL and
80# causes a build failure. Remove profile optimization flags.
81KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS))
82KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
83
84# KVM nVHE code is run at a different exception code with a different map, so
85# compiler instrumentation that inserts callbacks or checks into the code may
86# cause crashes. Just disable it.
87GCOV_PROFILE	:= n
88KASAN_SANITIZE	:= n
89UBSAN_SANITIZE	:= n
90KCOV_INSTRUMENT	:= n
91
92# Skip objtool checking for this directory because nVHE code is compiled with
93# non-standard build rules.
94OBJECT_FILES_NON_STANDARD := y
95