Makefile.nvhe 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
  4. #
  5. asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
  6. # Tracepoint and MMIO logging symbols should not be visible at nVHE KVM as
  7. # there is no way to execute them and any such MMIO access from nVHE KVM
  8. # will explode instantly (Words of Marc Zyngier). So introduce a generic flag
  9. # __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM.
  10. ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
  11. ccflags-y += -fno-stack-protector \
  12. -DDISABLE_BRANCH_PROFILING \
  13. $(DISABLE_STACKLEAK_PLUGIN)
  14. HYPREL := arch/arm64/tools/gen-hyprel
  15. ##
  16. ## Build rules for compiling nVHE hyp code
  17. ## Output of this folder is `kvm_nvhe.o`, a partially linked object
  18. ## file containing all nVHE hyp code and data.
  19. ##
  20. hyp-obj := $(patsubst %.o,%.nvhe.o,$(hyp-obj-y))
  21. targets += $(hyp-obj) kvm_nvhe.tmp.o kvm_nvhe.rel.o hyp.lds hyp-reloc.S hyp-reloc.o
  22. # 1) Compile all source files to `.nvhe.o` object files. The file extension
  23. # avoids file name clashes for files shared with VHE.
  24. $(obj)/%.nvhe.o: $(src)/%.c FORCE
  25. $(call if_changed_rule,cc_o_c)
  26. $(obj)/%.nvhe.o: $(src)/%.S FORCE
  27. $(call if_changed_rule,as_o_S)
  28. # 2) Partially link all '.nvhe.o' files and apply the linker script.
  29. # Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
  30. # Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
  31. # the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
  32. # keep the dependency on the target while avoiding an error from
  33. # GNU ld if the linker script is passed to it twice.
  34. LDFLAGS_kvm_nvhe.tmp.o := -r -T
  35. $(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
  36. $(call if_changed,ld)
  37. # 3) Generate list of hyp code/data positions that need to be relocated at
  38. # runtime. Because the hypervisor is part of the kernel binary, relocations
  39. # produce a kernel VA. We enumerate relocations targeting hyp at build time
  40. # and convert the kernel VAs at those positions to hyp VAs.
  41. $(obj)/hyp-reloc.S: $(obj)/kvm_nvhe.tmp.o FORCE
  42. $(call if_changed,hyprel)
  43. # 4) Compile hyp-reloc.S and link it into the existing partially linked object.
  44. # The object file now contains a section with pointers to hyp positions that
  45. # will contain kernel VAs at runtime. These pointers have relocations on them
  46. # so that they get updated as the hyp object is linked into `vmlinux`.
  47. LDFLAGS_kvm_nvhe.rel.o := -r
  48. $(obj)/kvm_nvhe.rel.o: $(obj)/kvm_nvhe.tmp.o $(obj)/hyp-reloc.o FORCE
  49. $(call if_changed,ld)
  50. # 5) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
  51. # Prefixes names of ELF symbols with '__kvm_nvhe_'.
  52. $(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.rel.o FORCE
  53. $(call if_changed,hypcopy)
  54. # The HYPREL command calls `gen-hyprel` to generate an assembly file with
  55. # a list of relocations targeting hyp code/data.
  56. quiet_cmd_hyprel = HYPREL $@
  57. cmd_hyprel = $(HYPREL) $< > $@
  58. # The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
  59. # to avoid clashes with VHE code/data.
  60. quiet_cmd_hypcopy = HYPCOPY $@
  61. cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
  62. # Remove ftrace, Shadow Call Stack, and CFI CFLAGS.
  63. # This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations.
  64. KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
  65. # Starting from 13.0.0 llvm emits SHT_REL section '.llvm.call-graph-profile'
  66. # when profile optimization is applied. gen-hyprel does not support SHT_REL and
  67. # causes a build failure. Remove profile optimization flags.
  68. KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS))
  69. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
  70. # KVM nVHE code is run at a different exception code with a different map, so
  71. # compiler instrumentation that inserts callbacks or checks into the code may
  72. # cause crashes. Just disable it.
  73. GCOV_PROFILE := n
  74. KASAN_SANITIZE := n
  75. KCSAN_SANITIZE := n
  76. UBSAN_SANITIZE := n
  77. KCOV_INSTRUMENT := n
  78. # Skip objtool checking for this directory because nVHE code is compiled with
  79. # non-standard build rules.
  80. OBJECT_FILES_NON_STANDARD := y