^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) include ../../../../scripts/Kbuild.include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) top_srcdir = ../../../..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) KSFT_KHDR_INSTALL := 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # For cross-builds to work, UNAME_M has to map to ARCH and arch specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # directories and targets in this Makefile. "uname -m" doesn't map to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # arch specific sub-directory names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) # UNAME_M variable to used to run the compiles pointing to the right arch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # directories and build the right targets for these supported architectures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) # TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) # LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) # x86_64 targets are named to include x86_64 as a suffix and directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) # for includes are in x86_64 sub-directory. s390x and aarch64 follow the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) # same convention. "uname -m" doesn't result in the correct mapping for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) # s390x and aarch64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # No change necessary for x86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) UNAME_M := $(shell uname -m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) # Set UNAME_M for arm64 compile/install to work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) ifeq ($(ARCH),arm64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) UNAME_M := aarch64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) # Set UNAME_M s390x compile/install to work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ifeq ($(ARCH),s390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) UNAME_M := s390x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) TEST_GEN_PROGS_x86_64 += x86_64/smm_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) TEST_GEN_PROGS_x86_64 += x86_64/state_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) TEST_GEN_PROGS_x86_64 += x86_64/user_msr_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) TEST_GEN_PROGS_x86_64 += demand_paging_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) TEST_GEN_PROGS_x86_64 += dirty_log_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) TEST_GEN_PROGS_x86_64 += set_memory_region_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) TEST_GEN_PROGS_x86_64 += steal_time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) TEST_GEN_PROGS_aarch64 += demand_paging_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) TEST_GEN_PROGS_aarch64 += dirty_log_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) TEST_GEN_PROGS_aarch64 += set_memory_region_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) TEST_GEN_PROGS_aarch64 += steal_time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) TEST_GEN_PROGS_s390x = s390x/memop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) TEST_GEN_PROGS_s390x += s390x/resets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) TEST_GEN_PROGS_s390x += s390x/sync_regs_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) TEST_GEN_PROGS_s390x += demand_paging_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) TEST_GEN_PROGS_s390x += dirty_log_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) TEST_GEN_PROGS_s390x += set_memory_region_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) LIBKVM += $(LIBKVM_$(UNAME_M))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) INSTALL_HDR_PATH = $(top_srcdir)/usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ifeq ($(ARCH),x86_64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) -I$(<D) -Iinclude/$(UNAME_M) -I..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) # On s390, build the testcases KVM-enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) pgste-option = $(call try-run, echo 'int main() { return 0; }' | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) LDFLAGS += -pthread $(no-pie-option) $(pgste-option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) # After inclusion, $(OUTPUT) is defined and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) # $(TEST_GEN_PROGS) starts with $(OUTPUT)/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) include ../lib.mk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) STATIC_LIBS := $(OUTPUT)/libkvm.a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) LIBKVM_C := $(filter %.c,$(LIBKVM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) LIBKVM_S := $(filter %.S,$(LIBKVM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) LIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) EXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) x := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) $(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) $(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) $(AR) crs $@ $^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) all: $(STATIC_LIBS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) $(TEST_GEN_PROGS): $(STATIC_LIBS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) cscope:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) $(RM) cscope.*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) (find $(include_paths) -name '*.h' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) -exec realpath --relative-base=$(PWD) {} \;; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) find . -name '*.c' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) cscope -b