• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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__
7ccflags-y := -D__KVM_NVHE_HYPERVISOR__
8
9lib-objs := clear_page.o copy_page.o memcpy.o memset.o
10lib-objs := $(addprefix ../../../lib/, $(lib-objs))
11
12obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o
13obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
14	 ../fpsimd.o ../hyp-entry.o
15obj-y += $(lib-objs)
16
17##
18## Build rules for compiling nVHE hyp code
19## Output of this folder is `kvm_nvhe.o`, a partially linked object
20## file containing all nVHE hyp code and data.
21##
22
23hyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y))
24obj-y := kvm_nvhe.o
25extra-y := $(hyp-obj) kvm_nvhe.tmp.o hyp.lds
26
27# 1) Compile all source files to `.nvhe.o` object files. The file extension
28#    avoids file name clashes for files shared with VHE.
29$(obj)/%.nvhe.o: $(src)/%.c FORCE
30	$(call if_changed_rule,cc_o_c)
31$(obj)/%.nvhe.o: $(src)/%.S FORCE
32	$(call if_changed_rule,as_o_S)
33
34# 2) Compile linker script.
35$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
36	$(call if_changed_dep,cpp_lds_S)
37
38# 3) Partially link all '.nvhe.o' files and apply the linker script.
39#    Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
40#    Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
41#          the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
42#          keep the dependency on the target while avoiding an error from
43#          GNU ld if the linker script is passed to it twice.
44LDFLAGS_kvm_nvhe.tmp.o := -r -T
45$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
46	$(call if_changed,ld)
47
48# 4) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
49#    Prefixes names of ELF symbols with '__kvm_nvhe_'.
50$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.tmp.o FORCE
51	$(call if_changed,hypcopy)
52
53# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
54# to avoid clashes with VHE code/data.
55quiet_cmd_hypcopy = HYPCOPY $@
56      cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
57
58# Remove ftrace, Shadow Call Stack, and CFI CFLAGS.
59# This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations.
60KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
61
62# KVM nVHE code is run at a different exception code with a different map, so
63# compiler instrumentation that inserts callbacks or checks into the code may
64# cause crashes. Just disable it.
65GCOV_PROFILE	:= n
66KASAN_SANITIZE	:= n
67UBSAN_SANITIZE	:= n
68KCOV_INSTRUMENT	:= n
69
70# Skip objtool checking for this directory because nVHE code is compiled with
71# non-standard build rules.
72OBJECT_FILES_NON_STANDARD := y
73