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__ 13 14hostprogs := gen-hyprel 15HOST_EXTRACFLAGS += -I$(objtree)/include 16 17lib-objs := clear_page.o copy_page.o memcpy.o memset.o 18lib-objs := $(addprefix ../../../lib/, $(lib-objs)) 19 20obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ 21 hyp-main.o hyp-smp.o psci-relay.o early_alloc.o stub.o page_alloc.o \ 22 cache.o ffa.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o iommu.o 23obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ 24 ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o 25obj-y += $(lib-objs) 26 27obj-$(CONFIG_KVM_S2MPU) += iommu/s2mpu.o 28 29## 30## Build rules for compiling nVHE hyp code 31## Output of this folder is `kvm_nvhe.o`, a partially linked object 32## file containing all nVHE hyp code and data. 33## 34 35hyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y)) 36obj-y := kvm_nvhe.o 37extra-y := $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-reloc.o 38 39# 1) Compile all source files to `.nvhe.o` object files. The file extension 40# avoids file name clashes for files shared with VHE. 41$(obj)/%.nvhe.o: $(src)/%.c FORCE 42 $(call if_changed_rule,cc_o_c) 43$(obj)/%.nvhe.o: $(src)/%.S FORCE 44 $(call if_changed_rule,as_o_S) 45 46# 2) Compile linker script. 47$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE 48 $(call if_changed_dep,cpp_lds_S) 49 50# 3) Partially link all '.nvhe.o' files and apply the linker script. 51# Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'. 52# Note: The following rule assumes that the 'ld' rule puts LDFLAGS before 53# the list of dependencies to form '-T $(obj)/hyp.lds'. This is to 54# keep the dependency on the target while avoiding an error from 55# GNU ld if the linker script is passed to it twice. 56LDFLAGS_kvm_nvhe.tmp.o := -r -T 57$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE 58 $(call if_changed,ld) 59 60# 4) Generate list of hyp code/data positions that need to be relocated at 61# runtime. Because the hypervisor is part of the kernel binary, relocations 62# produce a kernel VA. We enumerate relocations targeting hyp at build time 63# and convert the kernel VAs at those positions to hyp VAs. 64$(obj)/hyp-reloc.S: $(obj)/kvm_nvhe.tmp.o $(obj)/gen-hyprel FORCE 65 $(call if_changed,hyprel) 66 67# 5) Compile hyp-reloc.S and link it into the existing partially linked object. 68# The object file now contains a section with pointers to hyp positions that 69# will contain kernel VAs at runtime. These pointers have relocations on them 70# so that they get updated as the hyp object is linked into `vmlinux`. 71LDFLAGS_kvm_nvhe.rel.o := -r 72$(obj)/kvm_nvhe.rel.o: $(obj)/kvm_nvhe.tmp.o $(obj)/hyp-reloc.o FORCE 73 $(call if_changed,ld) 74 75# 6) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'. 76# Prefixes names of ELF symbols with '__kvm_nvhe_'. 77$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.rel.o FORCE 78 $(call if_changed,hypcopy) 79 80# The HYPREL command calls `gen-hyprel` to generate an assembly file with 81# a list of relocations targeting hyp code/data. 82quiet_cmd_hyprel = HYPREL $@ 83 cmd_hyprel = $(obj)/gen-hyprel $< > $@ 84 85# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names 86# to avoid clashes with VHE code/data. 87quiet_cmd_hypcopy = HYPCOPY $@ 88 cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@ 89 90# Remove ftrace, Shadow Call Stack, and CFI CFLAGS. 91# This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations. 92KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS)) 93# Starting from 13.0.0 llvm emits SHT_REL section '.llvm.call-graph-profile' 94# when profile optimization is applied. gen-hyprel does not support SHT_REL and 95# causes a build failure. Remove profile optimization flags. 96KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS)) 97 98# KVM nVHE code is run at a different exception code with a different map, so 99# compiler instrumentation that inserts callbacks or checks into the code may 100# cause crashes. Just disable it. 101GCOV_PROFILE := n 102KASAN_SANITIZE := n 103UBSAN_SANITIZE := n 104KCOV_INSTRUMENT := n 105 106# Skip objtool checking for this directory because nVHE code is compiled with 107# non-standard build rules. 108OBJECT_FILES_NON_STANDARD := y 109