David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # |
| 3 | # Makefile for Kernel-based Virtual Machine module, HYP/nVHE part |
| 4 | # |
| 5 | |
Quentin Perret | bbc075e | 2021-02-03 14:19:31 +0000 | [diff] [blame] | 6 | asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS |
Sai Prakash Ranjan | 451f2f1 | 2022-05-18 22:14:15 +0530 | [diff] [blame] | 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. |
| 12 | ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__ |
Vincent Donnefort | 837d632 | 2022-10-04 16:42:16 +0100 | [diff] [blame] | 13 | ccflags-y += -fno-stack-protector \ |
| 14 | -DDISABLE_BRANCH_PROFILING \ |
| 15 | $(DISABLE_STACKLEAK_PLUGIN) |
David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 16 | |
David Brazdil | 8c49b5d | 2021-01-05 18:05:37 +0000 | [diff] [blame] | 17 | hostprogs := gen-hyprel |
Marc Zyngier | bc93763 | 2021-01-30 13:07:51 +0000 | [diff] [blame] | 18 | HOST_EXTRACFLAGS += -I$(objtree)/include |
David Brazdil | 8c49b5d | 2021-01-05 18:05:37 +0000 | [diff] [blame] | 19 | |
Will Deacon | 7b4a7b5 | 2021-03-19 10:01:10 +0000 | [diff] [blame] | 20 | lib-objs := clear_page.o copy_page.o memcpy.o memset.o |
| 21 | lib-objs := $(addprefix ../../../lib/, $(lib-objs)) |
| 22 | |
Masahiro Yamada | 3d5697f | 2022-06-13 18:20:25 +0900 | [diff] [blame] | 23 | hyp-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ |
Keir Fraser | 4c68d6c | 2022-01-31 12:40:53 +0000 | [diff] [blame] | 24 | hyp-main.o hyp-smp.o psci-relay.o early_alloc.o page_alloc.o \ |
Will Deacon | 048be5f | 2023-05-23 11:18:18 +0100 | [diff] [blame] | 25 | cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o ffa.o |
Masahiro Yamada | 3d5697f | 2022-06-13 18:20:25 +0900 | [diff] [blame] | 26 | hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ |
Quentin Perret | f320bc7 | 2021-03-19 10:01:25 +0000 | [diff] [blame] | 27 | ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o |
Marco Elver | aebc7b0 | 2023-08-11 17:18:40 +0200 | [diff] [blame] | 28 | hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o |
Masahiro Yamada | 3d5697f | 2022-06-13 18:20:25 +0900 | [diff] [blame] | 29 | hyp-obj-y += $(lib-objs) |
David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 30 | |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 31 | ## |
| 32 | ## Build rules for compiling nVHE hyp code |
| 33 | ## Output of this folder is `kvm_nvhe.o`, a partially linked object |
| 34 | ## file containing all nVHE hyp code and data. |
| 35 | ## |
David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 36 | |
Masahiro Yamada | 3d5697f | 2022-06-13 18:20:25 +0900 | [diff] [blame] | 37 | hyp-obj := $(patsubst %.o,%.nvhe.o,$(hyp-obj-y)) |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 38 | obj-y := kvm_nvhe.o |
Masahiro Yamada | 40c56bd | 2022-06-13 18:20:26 +0900 | [diff] [blame] | 39 | targets += $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-reloc.o |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 40 | |
| 41 | # 1) Compile all source files to `.nvhe.o` object files. The file extension |
| 42 | # avoids file name clashes for files shared with VHE. |
| 43 | $(obj)/%.nvhe.o: $(src)/%.c FORCE |
David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 44 | $(call if_changed_rule,cc_o_c) |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 45 | $(obj)/%.nvhe.o: $(src)/%.S FORCE |
David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 46 | $(call if_changed_rule,as_o_S) |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 47 | |
| 48 | # 2) Compile linker script. |
| 49 | $(obj)/hyp.lds: $(src)/hyp.lds.S FORCE |
| 50 | $(call if_changed_dep,cpp_lds_S) |
| 51 | |
| 52 | # 3) Partially link all '.nvhe.o' files and apply the linker script. |
| 53 | # Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'. |
| 54 | # Note: The following rule assumes that the 'ld' rule puts LDFLAGS before |
| 55 | # the list of dependencies to form '-T $(obj)/hyp.lds'. This is to |
| 56 | # keep the dependency on the target while avoiding an error from |
| 57 | # GNU ld if the linker script is passed to it twice. |
| 58 | LDFLAGS_kvm_nvhe.tmp.o := -r -T |
| 59 | $(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE |
| 60 | $(call if_changed,ld) |
| 61 | |
David Brazdil | 8c49b5d | 2021-01-05 18:05:37 +0000 | [diff] [blame] | 62 | # 4) Generate list of hyp code/data positions that need to be relocated at |
| 63 | # runtime. Because the hypervisor is part of the kernel binary, relocations |
| 64 | # produce a kernel VA. We enumerate relocations targeting hyp at build time |
| 65 | # and convert the kernel VAs at those positions to hyp VAs. |
Zenghui Yu | a49b50a | 2021-09-07 13:21:37 +0800 | [diff] [blame] | 66 | $(obj)/hyp-reloc.S: $(obj)/kvm_nvhe.tmp.o $(obj)/gen-hyprel FORCE |
David Brazdil | 8c49b5d | 2021-01-05 18:05:37 +0000 | [diff] [blame] | 67 | $(call if_changed,hyprel) |
| 68 | |
| 69 | # 5) Compile hyp-reloc.S and link it into the existing partially linked object. |
| 70 | # The object file now contains a section with pointers to hyp positions that |
| 71 | # will contain kernel VAs at runtime. These pointers have relocations on them |
| 72 | # so that they get updated as the hyp object is linked into `vmlinux`. |
| 73 | LDFLAGS_kvm_nvhe.rel.o := -r |
| 74 | $(obj)/kvm_nvhe.rel.o: $(obj)/kvm_nvhe.tmp.o $(obj)/hyp-reloc.o FORCE |
| 75 | $(call if_changed,ld) |
| 76 | |
| 77 | # 6) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'. |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 78 | # Prefixes names of ELF symbols with '__kvm_nvhe_'. |
David Brazdil | 8c49b5d | 2021-01-05 18:05:37 +0000 | [diff] [blame] | 79 | $(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.rel.o FORCE |
David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 80 | $(call if_changed,hypcopy) |
| 81 | |
David Brazdil | 8c49b5d | 2021-01-05 18:05:37 +0000 | [diff] [blame] | 82 | # The HYPREL command calls `gen-hyprel` to generate an assembly file with |
| 83 | # a list of relocations targeting hyp code/data. |
| 84 | quiet_cmd_hyprel = HYPREL $@ |
| 85 | cmd_hyprel = $(obj)/gen-hyprel $< > $@ |
| 86 | |
David Brazdil | bdbc0c7 | 2020-07-30 14:25:19 +0100 | [diff] [blame] | 87 | # The HYPCOPY command uses `objcopy` to prefix all ELF symbol names |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 88 | # to avoid clashes with VHE code/data. |
David Brazdil | 7621712 | 2020-06-25 14:14:08 +0100 | [diff] [blame] | 89 | quiet_cmd_hypcopy = HYPCOPY $@ |
David Brazdil | ab25464 | 2020-09-22 21:49:01 +0100 | [diff] [blame] | 90 | cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@ |
David Brazdil | c50cb04 | 2020-06-25 14:14:19 +0100 | [diff] [blame] | 91 | |
Pierre-Clément Tosi | eca4ba5 | 2024-06-10 07:32:37 +0100 | [diff] [blame] | 92 | # Remove ftrace and Shadow Call Stack CFLAGS. |
| 93 | # This is equivalent to the 'notrace' and '__noscs' annotations. |
| 94 | KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS)) |
Denis Nikitin | bde971a | 2022-10-14 11:45:32 -0700 | [diff] [blame] | 95 | # Starting from 13.0.0 llvm emits SHT_REL section '.llvm.call-graph-profile' |
| 96 | # when profile optimization is applied. gen-hyprel does not support SHT_REL and |
| 97 | # causes a build failure. Remove profile optimization flags. |
| 98 | KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS)) |
Ard Biesheuvel | 68c76ad | 2022-10-27 17:59:06 +0200 | [diff] [blame] | 99 | KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables |