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 676217129SDavid Brazdilasflags-y := -D__KVM_NVHE_HYPERVISOR__ 776217129SDavid Brazdilccflags-y := -D__KVM_NVHE_HYPERVISOR__ 876217129SDavid Brazdil 9*8c49b5d4SDavid Brazdilhostprogs := gen-hyprel 10*8c49b5d4SDavid Brazdil 11687413d3SDavid Brazdilobj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ 12eeeee719SDavid Brazdil hyp-main.o hyp-smp.o psci-relay.o 13c04dd455SDavid Brazdilobj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ 14e650b64fSMarc Zyngier ../fpsimd.o ../hyp-entry.o ../exception.o 1576217129SDavid Brazdil 16ab25464bSDavid Brazdil## 17ab25464bSDavid Brazdil## Build rules for compiling nVHE hyp code 18ab25464bSDavid Brazdil## Output of this folder is `kvm_nvhe.o`, a partially linked object 19ab25464bSDavid Brazdil## file containing all nVHE hyp code and data. 20ab25464bSDavid Brazdil## 2176217129SDavid Brazdil 22ab25464bSDavid Brazdilhyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y)) 23ab25464bSDavid Brazdilobj-y := kvm_nvhe.o 24*8c49b5d4SDavid Brazdilextra-y := $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-reloc.o 25ab25464bSDavid Brazdil 26ab25464bSDavid Brazdil# 1) Compile all source files to `.nvhe.o` object files. The file extension 27ab25464bSDavid Brazdil# avoids file name clashes for files shared with VHE. 28ab25464bSDavid Brazdil$(obj)/%.nvhe.o: $(src)/%.c FORCE 2976217129SDavid Brazdil $(call if_changed_rule,cc_o_c) 30ab25464bSDavid Brazdil$(obj)/%.nvhe.o: $(src)/%.S FORCE 3176217129SDavid Brazdil $(call if_changed_rule,as_o_S) 32ab25464bSDavid Brazdil 33ab25464bSDavid Brazdil# 2) Compile linker script. 34ab25464bSDavid Brazdil$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE 35ab25464bSDavid Brazdil $(call if_changed_dep,cpp_lds_S) 36ab25464bSDavid Brazdil 37ab25464bSDavid Brazdil# 3) Partially link all '.nvhe.o' files and apply the linker script. 38ab25464bSDavid Brazdil# Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'. 39ab25464bSDavid Brazdil# Note: The following rule assumes that the 'ld' rule puts LDFLAGS before 40ab25464bSDavid Brazdil# the list of dependencies to form '-T $(obj)/hyp.lds'. This is to 41ab25464bSDavid Brazdil# keep the dependency on the target while avoiding an error from 42ab25464bSDavid Brazdil# GNU ld if the linker script is passed to it twice. 43ab25464bSDavid BrazdilLDFLAGS_kvm_nvhe.tmp.o := -r -T 44ab25464bSDavid Brazdil$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE 45ab25464bSDavid Brazdil $(call if_changed,ld) 46ab25464bSDavid Brazdil 47*8c49b5d4SDavid Brazdil# 4) Generate list of hyp code/data positions that need to be relocated at 48*8c49b5d4SDavid Brazdil# runtime. Because the hypervisor is part of the kernel binary, relocations 49*8c49b5d4SDavid Brazdil# produce a kernel VA. We enumerate relocations targeting hyp at build time 50*8c49b5d4SDavid Brazdil# and convert the kernel VAs at those positions to hyp VAs. 51*8c49b5d4SDavid Brazdil$(obj)/hyp-reloc.S: $(obj)/kvm_nvhe.tmp.o $(obj)/gen-hyprel 52*8c49b5d4SDavid Brazdil $(call if_changed,hyprel) 53*8c49b5d4SDavid Brazdil 54*8c49b5d4SDavid Brazdil# 5) Compile hyp-reloc.S and link it into the existing partially linked object. 55*8c49b5d4SDavid Brazdil# The object file now contains a section with pointers to hyp positions that 56*8c49b5d4SDavid Brazdil# will contain kernel VAs at runtime. These pointers have relocations on them 57*8c49b5d4SDavid Brazdil# so that they get updated as the hyp object is linked into `vmlinux`. 58*8c49b5d4SDavid BrazdilLDFLAGS_kvm_nvhe.rel.o := -r 59*8c49b5d4SDavid Brazdil$(obj)/kvm_nvhe.rel.o: $(obj)/kvm_nvhe.tmp.o $(obj)/hyp-reloc.o FORCE 60*8c49b5d4SDavid Brazdil $(call if_changed,ld) 61*8c49b5d4SDavid Brazdil 62*8c49b5d4SDavid Brazdil# 6) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'. 63ab25464bSDavid Brazdil# Prefixes names of ELF symbols with '__kvm_nvhe_'. 64*8c49b5d4SDavid Brazdil$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.rel.o FORCE 6576217129SDavid Brazdil $(call if_changed,hypcopy) 6676217129SDavid Brazdil 67*8c49b5d4SDavid Brazdil# The HYPREL command calls `gen-hyprel` to generate an assembly file with 68*8c49b5d4SDavid Brazdil# a list of relocations targeting hyp code/data. 69*8c49b5d4SDavid Brazdilquiet_cmd_hyprel = HYPREL $@ 70*8c49b5d4SDavid Brazdil cmd_hyprel = $(obj)/gen-hyprel $< > $@ 71*8c49b5d4SDavid Brazdil 72bdbc0c7aSDavid Brazdil# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names 73ab25464bSDavid Brazdil# to avoid clashes with VHE code/data. 7476217129SDavid Brazdilquiet_cmd_hypcopy = HYPCOPY $@ 75ab25464bSDavid Brazdil cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@ 76c50cb043SDavid Brazdil 77c50cb043SDavid Brazdil# Remove ftrace and Shadow Call Stack CFLAGS. 78c50cb043SDavid Brazdil# This is equivalent to the 'notrace' and '__noscs' annotations. 79c50cb043SDavid BrazdilKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS)) 8076217129SDavid Brazdil 8176217129SDavid Brazdil# KVM nVHE code is run at a different exception code with a different map, so 8276217129SDavid Brazdil# compiler instrumentation that inserts callbacks or checks into the code may 8376217129SDavid Brazdil# cause crashes. Just disable it. 8476217129SDavid BrazdilGCOV_PROFILE := n 8576217129SDavid BrazdilKASAN_SANITIZE := n 8676217129SDavid BrazdilUBSAN_SANITIZE := n 8776217129SDavid BrazdilKCOV_INSTRUMENT := n 8876217129SDavid Brazdil 8976217129SDavid Brazdil# Skip objtool checking for this directory because nVHE code is compiled with 9076217129SDavid Brazdil# non-standard build rules. 9176217129SDavid BrazdilOBJECT_FILES_NON_STANDARD := y 92