blob: e6fba18d0b2c801259f31953829aecffc5133517 [file] [log] [blame]
Thomas Gleixnerec8f24b2019-05-19 13:07:45 +01001# SPDX-License-Identifier: GPL-2.0-only
Masahiro Yamadab61442d2021-04-16 22:00:51 +09002include ../../../build/Build.include
Paolo Bonzinic2390f12019-04-11 15:51:19 +02003
Paolo Bonzini783e9e52018-03-27 11:49:19 +02004all:
5
Andrew Jonescc687652018-09-18 19:54:26 +02006top_srcdir = ../../../..
Shuah Khan211929f2018-12-12 20:25:14 -07007KSFT_KHDR_INSTALL := 1
Shuah Khan66d69e02020-04-27 18:11:07 -06008
9# For cross-builds to work, UNAME_M has to map to ARCH and arch specific
10# directories and targets in this Makefile. "uname -m" doesn't map to
11# arch specific sub-directory names.
12#
13# UNAME_M variable to used to run the compiles pointing to the right arch
14# directories and build the right targets for these supported architectures.
15#
16# TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable.
17# LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable.
18#
19# x86_64 targets are named to include x86_64 as a suffix and directories
20# for includes are in x86_64 sub-directory. s390x and aarch64 follow the
21# same convention. "uname -m" doesn't result in the correct mapping for
22# s390x and aarch64.
23#
24# No change necessary for x86_64
Paolo Bonzini783e9e52018-03-27 11:49:19 +020025UNAME_M := $(shell uname -m)
26
Shuah Khan66d69e02020-04-27 18:11:07 -060027# Set UNAME_M for arm64 compile/install to work
28ifeq ($(ARCH),arm64)
29 UNAME_M := aarch64
30endif
31# Set UNAME_M s390x compile/install to work
32ifeq ($(ARCH),s390)
33 UNAME_M := s390x
34endif
35
Maciej S. Szmigiero22721a52021-04-13 16:08:27 +020036LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/rbtree.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c
Jim Mattson4c63c922021-06-04 10:26:08 -070037LIBKVM_x86_64 = lib/x86_64/apic.c 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
Ricardo Kollere3db7572021-06-10 18:10:19 -070038LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S
Collin Wallingefaa83a2020-12-07 10:41:25 -050039LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c
Paolo Bonzini783e9e52018-03-27 11:49:19 +020040
Aaron Lewis61cfcd52019-05-21 17:13:58 +000041TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
Emanuele Giuseppe Esposito77a3aa22021-03-18 15:56:29 +010042TEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features
Vitaly Kuznetsov18178ff2018-10-16 18:50:11 +020043TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
Aaron Lewis39bbcc32021-05-10 07:48:34 -070044TEST_GEN_PROGS_x86_64 += x86_64/emulator_error_test
Vitaly Kuznetsovfb18d052021-01-29 17:18:21 +010045TEST_GEN_PROGS_x86_64 += x86_64/get_cpuid_test
Vitaly Kuznetsov2c7f76b2021-03-18 15:09:49 +010046TEST_GEN_PROGS_x86_64 += x86_64/hyperv_clock
Vitaly Kuznetsov7edcb732018-12-10 18:21:59 +010047TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
Vitaly Kuznetsove2e1cc12021-05-21 11:52:04 +020048TEST_GEN_PROGS_x86_64 += x86_64/hyperv_features
Oliver Uptonac4a4d62020-10-27 16:10:44 -070049TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test
Aaron Lewis9dba9882019-05-31 14:14:52 +000050TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
Sean Christophersonef6a74b2021-06-22 13:05:29 -070051TEST_GEN_PROGS_x86_64 += x86_64/mmu_role_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000052TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
Emanuele Giuseppe Esposito3df22522021-03-18 16:16:24 +010053TEST_GEN_PROGS_x86_64 += x86_64/set_boot_cpu_id
Aaron Lewis61cfcd52019-05-21 17:13:58 +000054TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
55TEST_GEN_PROGS_x86_64 += x86_64/smm_test
56TEST_GEN_PROGS_x86_64 += x86_64/state_test
Makarand Sonare8d7fbf02020-05-26 14:51:07 -070057TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010058TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test
Maxim Levitsky1ad32102021-09-14 18:48:13 +030059TEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000060TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
Aaron Lewis3cea1892020-10-12 12:47:16 -070061TEST_GEN_PROGS_x86_64 += x86_64/userspace_msr_exit_test
Jim Mattson97a71a52020-10-26 11:09:22 -070062TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000063TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
Paolo Bonzini09444422019-09-26 15:01:15 +020064TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
Aaron Lewisda1e3072019-05-02 11:31:41 -070065TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000066TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
Ilias Stamatisefe58542021-05-26 19:44:18 +010067TEST_GEN_PROGS_x86_64 += x86_64/vmx_nested_tsc_scaling_test
Peter Shier678e90a2020-11-05 14:38:23 -080068TEST_GEN_PROGS_x86_64 += x86_64/xapic_ipi_test
Aaron Lewisc90992b2019-10-21 16:30:28 -070069TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
Peter Xu449aa902020-05-05 16:50:00 -040070TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
Paolo Bonzini0c899c22020-09-24 14:45:27 +020071TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
Like Xuf88d4f22021-02-01 13:10:39 +080072TEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_msrs_test
David Woodhouse8d4e7e82020-12-04 01:02:04 +000073TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test
Joao Martins23200b72018-06-13 09:55:44 -040074TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
David Matlackc33e05d2021-07-13 22:09:57 +000075TEST_GEN_PROGS_x86_64 += access_tracking_perf_test
Ben Gardon025eed72020-01-23 10:04:27 -080076TEST_GEN_PROGS_x86_64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010077TEST_GEN_PROGS_x86_64 += dirty_log_test
Ben Gardon4fd94ec2020-10-27 16:37:33 -070078TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
Ignacio Alvarado1838b062021-02-13 00:14:52 +000079TEST_GEN_PROGS_x86_64 += hardware_disable_test
Paolo Bonzinifd4198bf2019-07-15 12:50:46 +020080TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +080081TEST_GEN_PROGS_x86_64 += kvm_page_table_test
Ben Gardonf73a3442021-01-12 13:42:53 -080082TEST_GEN_PROGS_x86_64 += memslot_modification_stress_test
Maciej S. Szmigierocad347f2021-04-13 16:08:28 +020083TEST_GEN_PROGS_x86_64 += memslot_perf_test
Sean Christopherson61e52f12021-09-01 13:30:29 -070084TEST_GEN_PROGS_x86_64 += rseq_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -070085TEST_GEN_PROGS_x86_64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010086TEST_GEN_PROGS_x86_64 += steal_time
Jing Zhang0b45d582021-06-18 22:27:08 +000087TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
Andrew Jonesfff8dcd2018-09-18 19:54:32 +020088
Ricardo Koller4f052232021-06-10 18:10:20 -070089TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
Andrew Jonesfd020292020-10-29 21:17:01 +010090TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
Oliver Uptoncb97cf92021-08-18 20:21:33 +000091TEST_GEN_PROGS_aarch64 += aarch64/psci_cpu_on_test
Eric Augerdc0e0582021-04-05 18:39:41 +020092TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
Ben Gardon025eed72020-01-23 10:04:27 -080093TEST_GEN_PROGS_aarch64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010094TEST_GEN_PROGS_aarch64 += dirty_log_test
Andrew Jones87c5f352020-11-11 13:26:34 +010095TEST_GEN_PROGS_aarch64 += dirty_log_perf_test
Thomas Huth49fe9a52019-05-23 18:43:09 +020096TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +080097TEST_GEN_PROGS_aarch64 += kvm_page_table_test
Ricardo Koller358928f2021-09-07 11:09:57 -070098TEST_GEN_PROGS_aarch64 += memslot_modification_stress_test
99TEST_GEN_PROGS_aarch64 += memslot_perf_test
Sean Christopherson61e52f12021-09-01 13:30:29 -0700100TEST_GEN_PROGS_aarch64 += rseq_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -0700101TEST_GEN_PROGS_aarch64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +0100102TEST_GEN_PROGS_aarch64 += steal_time
Jing Zhang0b45d582021-06-18 22:27:08 +0000103TEST_GEN_PROGS_aarch64 += kvm_binary_stats_test
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200104
Thomas Huthbe6f55a2019-08-29 15:07:32 +0200105TEST_GEN_PROGS_s390x = s390x/memop
Janosch Frankb25d4cb2020-01-31 05:02:04 -0500106TEST_GEN_PROGS_s390x += s390x/resets
Andrew Jones94c4b76b2020-03-13 16:56:44 +0100107TEST_GEN_PROGS_s390x += s390x/sync_regs_test
Ben Gardon025eed72020-01-23 10:04:27 -0800108TEST_GEN_PROGS_s390x += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +0100109TEST_GEN_PROGS_s390x += dirty_log_test
Thomas Huth49fe9a52019-05-23 18:43:09 +0200110TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +0800111TEST_GEN_PROGS_s390x += kvm_page_table_test
Sean Christopherson61e52f12021-09-01 13:30:29 -0700112TEST_GEN_PROGS_s390x += rseq_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -0700113TEST_GEN_PROGS_s390x += set_memory_region_test
Jing Zhang0b45d582021-06-18 22:27:08 +0000114TEST_GEN_PROGS_s390x += kvm_binary_stats_test
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200115
116TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
117LIBKVM += $(LIBKVM_$(UNAME_M))
118
119INSTALL_HDR_PATH = $(top_srcdir)/usr
120LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
Andrew Jonescc687652018-09-18 19:54:26 +0200121LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +0200122ifeq ($(ARCH),x86_64)
123LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include
124else
Shuah Khan66d69e02020-04-27 18:11:07 -0600125LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +0200126endif
Thomas Huth319f6f92019-05-17 11:04:45 +0200127CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
128 -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
Sean Christophersona5543d32019-12-20 20:44:56 -0800129 -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
130 -I$(<D) -Iinclude/$(UNAME_M) -I..
Paolo Bonzinic2390f12019-04-11 15:51:19 +0200131
132no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
Shuah Khan6e069832019-10-02 17:14:30 -0600133 $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
Paolo Bonzinic2390f12019-04-11 15:51:19 +0200134
Christian Borntraeger8343ba22019-05-24 12:27:01 +0200135# On s390, build the testcases KVM-enabled
136pgste-option = $(call try-run, echo 'int main() { return 0; }' | \
137 $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste)
138
139
140LDFLAGS += -pthread $(no-pie-option) $(pgste-option)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200141
142# After inclusion, $(OUTPUT) is defined and
143# $(TEST_GEN_PROGS) starts with $(OUTPUT)/
144include ../lib.mk
145
146STATIC_LIBS := $(OUTPUT)/libkvm.a
Aaron Lewis29faeb92020-10-12 12:47:15 -0700147LIBKVM_C := $(filter %.c,$(LIBKVM))
148LIBKVM_S := $(filter %.S,$(LIBKVM))
149LIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C))
150LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S))
151EXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.*
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200152
Aaron Lewis29faeb92020-10-12 12:47:15 -0700153x := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
154$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200155 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
156
Aaron Lewis29faeb92020-10-12 12:47:15 -0700157$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S
158 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
159
160LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)
161$(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200162 $(AR) crs $@ $^
163
Shuah Khan66d69e02020-04-27 18:11:07 -0600164x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
Anders Roxellb2d35fa2018-09-04 12:47:21 +0200165all: $(STATIC_LIBS)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200166$(TEST_GEN_PROGS): $(STATIC_LIBS)
Andrew Joneseea192b2018-09-18 19:54:27 +0200167
168cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
169cscope:
170 $(RM) cscope.*
171 (find $(include_paths) -name '*.h' \
172 -exec realpath --relative-base=$(PWD) {} \;; \
173 find . -name '*.c' \
174 -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files
175 cscope -b