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