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