176217129SDavid Brazdil# SPDX-License-Identifier: GPL-2.0 276217129SDavid Brazdil# 376217129SDavid Brazdil# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part 476217129SDavid Brazdil# 576217129SDavid Brazdil 676217129SDavid Brazdilasflags-y := -D__KVM_NVHE_HYPERVISOR__ 776217129SDavid Brazdilccflags-y := -D__KVM_NVHE_HYPERVISOR__ 876217129SDavid Brazdil 9c04dd455SDavid Brazdilobj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o 10c04dd455SDavid Brazdilobj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ 11c04dd455SDavid Brazdil ../fpsimd.o ../hyp-entry.o 1276217129SDavid Brazdil 1376217129SDavid Brazdilobj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) 1476217129SDavid Brazdilextra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y)) 1576217129SDavid Brazdil 1676217129SDavid Brazdil$(obj)/%.hyp.tmp.o: $(src)/%.c FORCE 1776217129SDavid Brazdil $(call if_changed_rule,cc_o_c) 1876217129SDavid Brazdil$(obj)/%.hyp.tmp.o: $(src)/%.S FORCE 1976217129SDavid Brazdil $(call if_changed_rule,as_o_S) 2076217129SDavid Brazdil$(obj)/%.hyp.o: $(obj)/%.hyp.tmp.o FORCE 2176217129SDavid Brazdil $(call if_changed,hypcopy) 2276217129SDavid Brazdil 23*bdbc0c7aSDavid Brazdil# Disable reordering functions by GCC (enabled at -O2). 24*bdbc0c7aSDavid Brazdil# This pass puts functions into '.text.*' sections to aid the linker 25*bdbc0c7aSDavid Brazdil# in optimizing ELF layout. See HYPCOPY comment below for more info. 26*bdbc0c7aSDavid Brazdilccflags-y += $(call cc-option,-fno-reorder-functions) 27*bdbc0c7aSDavid Brazdil 28*bdbc0c7aSDavid Brazdil# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names 29*bdbc0c7aSDavid Brazdil# and relevant ELF section names to avoid clashes with VHE code/data. 30*bdbc0c7aSDavid Brazdil# 31*bdbc0c7aSDavid Brazdil# Hyp code is assumed to be in the '.text' section of the input object 32*bdbc0c7aSDavid Brazdil# files (with the exception of specialized sections such as 33*bdbc0c7aSDavid Brazdil# '.hyp.idmap.text'). This assumption may be broken by a compiler that 34*bdbc0c7aSDavid Brazdil# divides code into sections like '.text.unlikely' so as to optimize 35*bdbc0c7aSDavid Brazdil# ELF layout. HYPCOPY checks that no such sections exist in the input 36*bdbc0c7aSDavid Brazdil# using `objdump`, otherwise they would be linked together with other 37*bdbc0c7aSDavid Brazdil# kernel code and not memory-mapped correctly at runtime. 3876217129SDavid Brazdilquiet_cmd_hypcopy = HYPCOPY $@ 39*bdbc0c7aSDavid Brazdil cmd_hypcopy = \ 40*bdbc0c7aSDavid Brazdil if $(OBJDUMP) -h $< | grep -F '.text.'; then \ 41*bdbc0c7aSDavid Brazdil echo "$@: function reordering not supported in nVHE hyp code" >&2; \ 42*bdbc0c7aSDavid Brazdil /bin/false; \ 43*bdbc0c7aSDavid Brazdil fi; \ 44*bdbc0c7aSDavid Brazdil $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ \ 45c50cb043SDavid Brazdil --rename-section=.text=.hyp.text \ 46c50cb043SDavid Brazdil $< $@ 47c50cb043SDavid Brazdil 48c50cb043SDavid Brazdil# Remove ftrace and Shadow Call Stack CFLAGS. 49c50cb043SDavid Brazdil# This is equivalent to the 'notrace' and '__noscs' annotations. 50c50cb043SDavid BrazdilKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS)) 5176217129SDavid Brazdil 5276217129SDavid Brazdil# KVM nVHE code is run at a different exception code with a different map, so 5376217129SDavid Brazdil# compiler instrumentation that inserts callbacks or checks into the code may 5476217129SDavid Brazdil# cause crashes. Just disable it. 5576217129SDavid BrazdilGCOV_PROFILE := n 5676217129SDavid BrazdilKASAN_SANITIZE := n 5776217129SDavid BrazdilUBSAN_SANITIZE := n 5876217129SDavid BrazdilKCOV_INSTRUMENT := n 5976217129SDavid Brazdil 6076217129SDavid Brazdil# Skip objtool checking for this directory because nVHE code is compiled with 6176217129SDavid Brazdil# non-standard build rules. 6276217129SDavid BrazdilOBJECT_FILES_NON_STANDARD := y 63