blob: 1c750910c27b150016b9f45a5fde89126cd67c7c [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
Thomas Huth2040f412019-07-31 17:15:23 +020038LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
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
Vitaly Kuznetsovfb18d052021-01-29 17:18:21 +010044TEST_GEN_PROGS_x86_64 += x86_64/get_cpuid_test
Vitaly Kuznetsov2c7f76b2021-03-18 15:09:49 +010045TEST_GEN_PROGS_x86_64 += x86_64/hyperv_clock
Vitaly Kuznetsov7edcb732018-12-10 18:21:59 +010046TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
Oliver Uptonac4a4d62020-10-27 16:10:44 -070047TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test
Aaron Lewis9dba9882019-05-31 14:14:52 +000048TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000049TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
Emanuele Giuseppe Esposito3df22522021-03-18 16:16:24 +010050TEST_GEN_PROGS_x86_64 += x86_64/set_boot_cpu_id
Aaron Lewis61cfcd52019-05-21 17:13:58 +000051TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
52TEST_GEN_PROGS_x86_64 += x86_64/smm_test
53TEST_GEN_PROGS_x86_64 += x86_64/state_test
Makarand Sonare8d7fbf02020-05-26 14:51:07 -070054TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010055TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000056TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
Aaron Lewis3cea1892020-10-12 12:47:16 -070057TEST_GEN_PROGS_x86_64 += x86_64/userspace_msr_exit_test
Jim Mattson97a71a52020-10-26 11:09:22 -070058TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000059TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
Paolo Bonzini09444422019-09-26 15:01:15 +020060TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
Aaron Lewisda1e3072019-05-02 11:31:41 -070061TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000062TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
Ilias Stamatisefe58542021-05-26 19:44:18 +010063TEST_GEN_PROGS_x86_64 += x86_64/vmx_nested_tsc_scaling_test
Peter Shier678e90a2020-11-05 14:38:23 -080064TEST_GEN_PROGS_x86_64 += x86_64/xapic_ipi_test
Aaron Lewisc90992b2019-10-21 16:30:28 -070065TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
Peter Xu449aa902020-05-05 16:50:00 -040066TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
Paolo Bonzini0c899c22020-09-24 14:45:27 +020067TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
Like Xuf88d4f22021-02-01 13:10:39 +080068TEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_msrs_test
David Woodhouse8d4e7e82020-12-04 01:02:04 +000069TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test
Joao Martins23200b72018-06-13 09:55:44 -040070TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
Ben Gardon025eed72020-01-23 10:04:27 -080071TEST_GEN_PROGS_x86_64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010072TEST_GEN_PROGS_x86_64 += dirty_log_test
Ben Gardon4fd94ec2020-10-27 16:37:33 -070073TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
Ignacio Alvarado1838b062021-02-13 00:14:52 +000074TEST_GEN_PROGS_x86_64 += hardware_disable_test
Paolo Bonzinifd4198bf2019-07-15 12:50:46 +020075TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +080076TEST_GEN_PROGS_x86_64 += kvm_page_table_test
Ben Gardonf73a3442021-01-12 13:42:53 -080077TEST_GEN_PROGS_x86_64 += memslot_modification_stress_test
Maciej S. Szmigierocad347f2021-04-13 16:08:28 +020078TEST_GEN_PROGS_x86_64 += memslot_perf_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -070079TEST_GEN_PROGS_x86_64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010080TEST_GEN_PROGS_x86_64 += steal_time
Andrew Jonesfff8dcd2018-09-18 19:54:32 +020081
Andrew Jonesfd020292020-10-29 21:17:01 +010082TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
Andrew Jones31d21292020-10-29 21:17:03 +010083TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve
Eric Augerdc0e0582021-04-05 18:39:41 +020084TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
Ben Gardon025eed72020-01-23 10:04:27 -080085TEST_GEN_PROGS_aarch64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010086TEST_GEN_PROGS_aarch64 += dirty_log_test
Andrew Jones87c5f352020-11-11 13:26:34 +010087TEST_GEN_PROGS_aarch64 += dirty_log_perf_test
Thomas Huth49fe9a52019-05-23 18:43:09 +020088TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +080089TEST_GEN_PROGS_aarch64 += kvm_page_table_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -070090TEST_GEN_PROGS_aarch64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010091TEST_GEN_PROGS_aarch64 += steal_time
Paolo Bonzini783e9e52018-03-27 11:49:19 +020092
Thomas Huthbe6f55a2019-08-29 15:07:32 +020093TEST_GEN_PROGS_s390x = s390x/memop
Janosch Frankb25d4cb2020-01-31 05:02:04 -050094TEST_GEN_PROGS_s390x += s390x/resets
Andrew Jones94c4b76b2020-03-13 16:56:44 +010095TEST_GEN_PROGS_s390x += s390x/sync_regs_test
Ben Gardon025eed72020-01-23 10:04:27 -080096TEST_GEN_PROGS_s390x += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010097TEST_GEN_PROGS_s390x += dirty_log_test
Thomas Huth49fe9a52019-05-23 18:43:09 +020098TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +080099TEST_GEN_PROGS_s390x += kvm_page_table_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -0700100TEST_GEN_PROGS_s390x += set_memory_region_test
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200101
102TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
103LIBKVM += $(LIBKVM_$(UNAME_M))
104
105INSTALL_HDR_PATH = $(top_srcdir)/usr
106LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
Andrew Jonescc687652018-09-18 19:54:26 +0200107LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +0200108ifeq ($(ARCH),x86_64)
109LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include
110else
Shuah Khan66d69e02020-04-27 18:11:07 -0600111LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +0200112endif
Thomas Huth319f6f92019-05-17 11:04:45 +0200113CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
114 -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
Sean Christophersona5543d32019-12-20 20:44:56 -0800115 -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
116 -I$(<D) -Iinclude/$(UNAME_M) -I..
Paolo Bonzinic2390f12019-04-11 15:51:19 +0200117
118no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
Shuah Khan6e069832019-10-02 17:14:30 -0600119 $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
Paolo Bonzinic2390f12019-04-11 15:51:19 +0200120
Christian Borntraeger8343ba22019-05-24 12:27:01 +0200121# On s390, build the testcases KVM-enabled
122pgste-option = $(call try-run, echo 'int main() { return 0; }' | \
123 $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste)
124
125
126LDFLAGS += -pthread $(no-pie-option) $(pgste-option)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200127
128# After inclusion, $(OUTPUT) is defined and
129# $(TEST_GEN_PROGS) starts with $(OUTPUT)/
130include ../lib.mk
131
132STATIC_LIBS := $(OUTPUT)/libkvm.a
Aaron Lewis29faeb92020-10-12 12:47:15 -0700133LIBKVM_C := $(filter %.c,$(LIBKVM))
134LIBKVM_S := $(filter %.S,$(LIBKVM))
135LIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C))
136LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S))
137EXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.*
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200138
Aaron Lewis29faeb92020-10-12 12:47:15 -0700139x := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
140$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200141 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
142
Aaron Lewis29faeb92020-10-12 12:47:15 -0700143$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S
144 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
145
146LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)
147$(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200148 $(AR) crs $@ $^
149
Shuah Khan66d69e02020-04-27 18:11:07 -0600150x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
Anders Roxellb2d35fa2018-09-04 12:47:21 +0200151all: $(STATIC_LIBS)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200152$(TEST_GEN_PROGS): $(STATIC_LIBS)
Andrew Joneseea192b2018-09-18 19:54:27 +0200153
154cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
155cscope:
156 $(RM) cscope.*
157 (find $(include_paths) -name '*.h' \
158 -exec realpath --relative-base=$(PWD) {} \;; \
159 find . -name '*.c' \
160 -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files
161 cscope -b