xref: /linux/arch/arm64/kvm/hyp/nvhe/Makefile (revision d07b43284ab356daf7ec5ae1858a16c1c7b6adab)
176217129SDavid Brazdil# SPDX-License-Identifier: GPL-2.0
276217129SDavid Brazdil#
376217129SDavid Brazdil# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
476217129SDavid Brazdil#
576217129SDavid Brazdil
6bbc075e0SQuentin Perretasflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
7451f2f1cSSai Prakash Ranjan
8451f2f1cSSai Prakash Ranjan# Tracepoint and MMIO logging symbols should not be visible at nVHE KVM as
9451f2f1cSSai Prakash Ranjan# there is no way to execute them and any such MMIO access from nVHE KVM
10451f2f1cSSai Prakash Ranjan# will explode instantly (Words of Marc Zyngier). So introduce a generic flag
11451f2f1cSSai Prakash Ranjan# __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM.
12451f2f1cSSai Prakash Ranjanccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
13837d632aSVincent Donnefortccflags-y += -fno-stack-protector	\
14837d632aSVincent Donnefort	     -DDISABLE_BRANCH_PROFILING	\
15837d632aSVincent Donnefort	     $(DISABLE_STACKLEAK_PLUGIN)
1676217129SDavid Brazdil
178c49b5d4SDavid Brazdilhostprogs := gen-hyprel
18bc93763fSMarc ZyngierHOST_EXTRACFLAGS += -I$(objtree)/include
198c49b5d4SDavid Brazdil
207b4a7b5eSWill Deaconlib-objs := clear_page.o copy_page.o memcpy.o memset.o
217b4a7b5eSWill Deaconlib-objs := $(addprefix ../../../lib/, $(lib-objs))
227b4a7b5eSWill Deacon
23*963a08e5SSebastian OttCFLAGS_switch.nvhe.o += -Wno-override-init
24*963a08e5SSebastian Ott
253d5697f9SMasahiro Yamadahyp-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
264c68d6c0SKeir Fraser	 hyp-main.o hyp-smp.o psci-relay.o early_alloc.o page_alloc.o \
27048be5feSWill Deacon	 cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o ffa.o
283d5697f9SMasahiro Yamadahyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
29f320bc74SQuentin Perret	 ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o
30aebc7b0dSMarco Elverhyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o
313d5697f9SMasahiro Yamadahyp-obj-y += $(lib-objs)
3276217129SDavid Brazdil
33ab25464bSDavid Brazdil##
34ab25464bSDavid Brazdil## Build rules for compiling nVHE hyp code
35ab25464bSDavid Brazdil## Output of this folder is `kvm_nvhe.o`, a partially linked object
36ab25464bSDavid Brazdil## file containing all nVHE hyp code and data.
37ab25464bSDavid Brazdil##
3876217129SDavid Brazdil
393d5697f9SMasahiro Yamadahyp-obj := $(patsubst %.o,%.nvhe.o,$(hyp-obj-y))
40ab25464bSDavid Brazdilobj-y := kvm_nvhe.o
4140c56bd8SMasahiro Yamadatargets += $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-reloc.o
42ab25464bSDavid Brazdil
43ab25464bSDavid Brazdil# 1) Compile all source files to `.nvhe.o` object files. The file extension
44ab25464bSDavid Brazdil#    avoids file name clashes for files shared with VHE.
45ab25464bSDavid Brazdil$(obj)/%.nvhe.o: $(src)/%.c FORCE
4676217129SDavid Brazdil	$(call if_changed_rule,cc_o_c)
47ab25464bSDavid Brazdil$(obj)/%.nvhe.o: $(src)/%.S FORCE
4876217129SDavid Brazdil	$(call if_changed_rule,as_o_S)
49ab25464bSDavid Brazdil
50ab25464bSDavid Brazdil# 2) Compile linker script.
51ab25464bSDavid Brazdil$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
52ab25464bSDavid Brazdil	$(call if_changed_dep,cpp_lds_S)
53ab25464bSDavid Brazdil
54ab25464bSDavid Brazdil# 3) Partially link all '.nvhe.o' files and apply the linker script.
55ab25464bSDavid Brazdil#    Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
56ab25464bSDavid Brazdil#    Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
57ab25464bSDavid Brazdil#          the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
58ab25464bSDavid Brazdil#          keep the dependency on the target while avoiding an error from
59ab25464bSDavid Brazdil#          GNU ld if the linker script is passed to it twice.
60ab25464bSDavid BrazdilLDFLAGS_kvm_nvhe.tmp.o := -r -T
61ab25464bSDavid Brazdil$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
62ab25464bSDavid Brazdil	$(call if_changed,ld)
63ab25464bSDavid Brazdil
648c49b5d4SDavid Brazdil# 4) Generate list of hyp code/data positions that need to be relocated at
658c49b5d4SDavid Brazdil#    runtime. Because the hypervisor is part of the kernel binary, relocations
668c49b5d4SDavid Brazdil#    produce a kernel VA. We enumerate relocations targeting hyp at build time
678c49b5d4SDavid Brazdil#    and convert the kernel VAs at those positions to hyp VAs.
68a49b50a3SZenghui Yu$(obj)/hyp-reloc.S: $(obj)/kvm_nvhe.tmp.o $(obj)/gen-hyprel FORCE
698c49b5d4SDavid Brazdil	$(call if_changed,hyprel)
708c49b5d4SDavid Brazdil
718c49b5d4SDavid Brazdil# 5) Compile hyp-reloc.S and link it into the existing partially linked object.
728c49b5d4SDavid Brazdil#    The object file now contains a section with pointers to hyp positions that
738c49b5d4SDavid Brazdil#    will contain kernel VAs at runtime. These pointers have relocations on them
748c49b5d4SDavid Brazdil#    so that they get updated as the hyp object is linked into `vmlinux`.
758c49b5d4SDavid BrazdilLDFLAGS_kvm_nvhe.rel.o := -r
768c49b5d4SDavid Brazdil$(obj)/kvm_nvhe.rel.o: $(obj)/kvm_nvhe.tmp.o $(obj)/hyp-reloc.o FORCE
778c49b5d4SDavid Brazdil	$(call if_changed,ld)
788c49b5d4SDavid Brazdil
798c49b5d4SDavid Brazdil# 6) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
80ab25464bSDavid Brazdil#    Prefixes names of ELF symbols with '__kvm_nvhe_'.
818c49b5d4SDavid Brazdil$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.rel.o FORCE
8276217129SDavid Brazdil	$(call if_changed,hypcopy)
8376217129SDavid Brazdil
848c49b5d4SDavid Brazdil# The HYPREL command calls `gen-hyprel` to generate an assembly file with
858c49b5d4SDavid Brazdil# a list of relocations targeting hyp code/data.
868c49b5d4SDavid Brazdilquiet_cmd_hyprel = HYPREL  $@
878c49b5d4SDavid Brazdil      cmd_hyprel = $(obj)/gen-hyprel $< > $@
888c49b5d4SDavid Brazdil
89bdbc0c7aSDavid Brazdil# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
90ab25464bSDavid Brazdil# to avoid clashes with VHE code/data.
9176217129SDavid Brazdilquiet_cmd_hypcopy = HYPCOPY $@
92ab25464bSDavid Brazdil      cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
93c50cb043SDavid Brazdil
94eca4ba5bSPierre-Clément Tosi# Remove ftrace and Shadow Call Stack CFLAGS.
95eca4ba5bSPierre-Clément Tosi# This is equivalent to the 'notrace' and '__noscs' annotations.
96eca4ba5bSPierre-Clément TosiKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS))
97bde971a8SDenis Nikitin# Starting from 13.0.0 llvm emits SHT_REL section '.llvm.call-graph-profile'
98bde971a8SDenis Nikitin# when profile optimization is applied. gen-hyprel does not support SHT_REL and
99bde971a8SDenis Nikitin# causes a build failure. Remove profile optimization flags.
100bde971a8SDenis NikitinKBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS))
10168c76ad4SArd BiesheuvelKBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
102