Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 #
0003 # Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
0004 #
0005 
0006 asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
0007 
0008 # Tracepoint and MMIO logging symbols should not be visible at nVHE KVM as
0009 # there is no way to execute them and any such MMIO access from nVHE KVM
0010 # will explode instantly (Words of Marc Zyngier). So introduce a generic flag
0011 # __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM.
0012 ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
0013 
0014 hostprogs := gen-hyprel
0015 HOST_EXTRACFLAGS += -I$(objtree)/include
0016 
0017 lib-objs := clear_page.o copy_page.o memcpy.o memset.o
0018 lib-objs := $(addprefix ../../../lib/, $(lib-objs))
0019 
0020 hyp-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
0021          hyp-main.o hyp-smp.o psci-relay.o early_alloc.o page_alloc.o \
0022          cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o
0023 hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
0024          ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o
0025 hyp-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
0026 hyp-obj-y += $(lib-objs)
0027 
0028 ##
0029 ## Build rules for compiling nVHE hyp code
0030 ## Output of this folder is `kvm_nvhe.o`, a partially linked object
0031 ## file containing all nVHE hyp code and data.
0032 ##
0033 
0034 hyp-obj := $(patsubst %.o,%.nvhe.o,$(hyp-obj-y))
0035 obj-y := kvm_nvhe.o
0036 targets += $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-reloc.o
0037 
0038 # 1) Compile all source files to `.nvhe.o` object files. The file extension
0039 #    avoids file name clashes for files shared with VHE.
0040 $(obj)/%.nvhe.o: $(src)/%.c FORCE
0041         $(call if_changed_rule,cc_o_c)
0042 $(obj)/%.nvhe.o: $(src)/%.S FORCE
0043         $(call if_changed_rule,as_o_S)
0044 
0045 # 2) Compile linker script.
0046 $(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
0047         $(call if_changed_dep,cpp_lds_S)
0048 
0049 # 3) Partially link all '.nvhe.o' files and apply the linker script.
0050 #    Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
0051 #    Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
0052 #          the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
0053 #          keep the dependency on the target while avoiding an error from
0054 #          GNU ld if the linker script is passed to it twice.
0055 LDFLAGS_kvm_nvhe.tmp.o := -r -T
0056 $(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
0057         $(call if_changed,ld)
0058 
0059 # 4) Generate list of hyp code/data positions that need to be relocated at
0060 #    runtime. Because the hypervisor is part of the kernel binary, relocations
0061 #    produce a kernel VA. We enumerate relocations targeting hyp at build time
0062 #    and convert the kernel VAs at those positions to hyp VAs.
0063 $(obj)/hyp-reloc.S: $(obj)/kvm_nvhe.tmp.o $(obj)/gen-hyprel FORCE
0064         $(call if_changed,hyprel)
0065 
0066 # 5) Compile hyp-reloc.S and link it into the existing partially linked object.
0067 #    The object file now contains a section with pointers to hyp positions that
0068 #    will contain kernel VAs at runtime. These pointers have relocations on them
0069 #    so that they get updated as the hyp object is linked into `vmlinux`.
0070 LDFLAGS_kvm_nvhe.rel.o := -r
0071 $(obj)/kvm_nvhe.rel.o: $(obj)/kvm_nvhe.tmp.o $(obj)/hyp-reloc.o FORCE
0072         $(call if_changed,ld)
0073 
0074 # 6) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
0075 #    Prefixes names of ELF symbols with '__kvm_nvhe_'.
0076 $(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.rel.o FORCE
0077         $(call if_changed,hypcopy)
0078 
0079 # The HYPREL command calls `gen-hyprel` to generate an assembly file with
0080 # a list of relocations targeting hyp code/data.
0081 quiet_cmd_hyprel = HYPREL  $@
0082       cmd_hyprel = $(obj)/gen-hyprel $< > $@
0083 
0084 # The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
0085 # to avoid clashes with VHE code/data.
0086 quiet_cmd_hypcopy = HYPCOPY $@
0087       cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
0088 
0089 # Remove ftrace, Shadow Call Stack, and CFI CFLAGS.
0090 # This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations.
0091 KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
0092 
0093 # KVM nVHE code is run at a different exception code with a different map, so
0094 # compiler instrumentation that inserts callbacks or checks into the code may
0095 # cause crashes. Just disable it.
0096 GCOV_PROFILE    := n
0097 KASAN_SANITIZE  := n
0098 KCSAN_SANITIZE  := n
0099 UBSAN_SANITIZE  := n
0100 KCOV_INSTRUMENT := n
0101 
0102 # Skip objtool checking for this directory because nVHE code is compiled with
0103 # non-standard build rules.
0104 OBJECT_FILES_NON_STANDARD := y