blob: 81ebf99d6ff07a2c6bd819b759d7d22f7fb7a498 [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
Anup Patel3e06cdf2021-10-05 18:09:56 +053035# Set UNAME_M riscv compile/install to work
36ifeq ($(ARCH),riscv)
37 UNAME_M := riscv
38endif
Shuah Khan66d69e02020-04-27 18:11:07 -060039
Maciej S. Szmigiero22721a52021-04-13 16:08:27 +020040LIBKVM = 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 -070041LIBKVM_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
Raghavendra Rao Ananta250b8d62021-10-07 23:34:37 +000042LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S lib/aarch64/spinlock.c lib/aarch64/gic.c lib/aarch64/gic_v3.c lib/aarch64/vgic.c
Collin Wallingefaa83a2020-12-07 10:41:25 -050043LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c
Anup Patel3e06cdf2021-10-05 18:09:56 +053044LIBKVM_riscv = lib/riscv/processor.c lib/riscv/ucall.c
Paolo Bonzini783e9e52018-03-27 11:49:19 +020045
Vitaly Kuznetsov9e6d4842022-01-17 16:05:41 +010046TEST_GEN_PROGS_x86_64 = x86_64/cpuid_test
47TEST_GEN_PROGS_x86_64 += x86_64/cr4_cpuid_sync_test
Emanuele Giuseppe Esposito77a3aa22021-03-18 15:56:29 +010048TEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features
Vitaly Kuznetsov18178ff2018-10-16 18:50:11 +020049TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
Aaron Lewis39bbcc32021-05-10 07:48:34 -070050TEST_GEN_PROGS_x86_64 += x86_64/emulator_error_test
Vitaly Kuznetsov2c7f76b2021-03-18 15:09:49 +010051TEST_GEN_PROGS_x86_64 += x86_64/hyperv_clock
Vitaly Kuznetsov7edcb732018-12-10 18:21:59 +010052TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
Vitaly Kuznetsove2e1cc12021-05-21 11:52:04 +020053TEST_GEN_PROGS_x86_64 += x86_64/hyperv_features
Oliver Upton61fb1c52021-09-16 18:15:48 +000054TEST_GEN_PROGS_x86_64 += x86_64/kvm_clock_test
Oliver Uptonac4a4d62020-10-27 16:10:44 -070055TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test
Aaron Lewis9dba9882019-05-31 14:14:52 +000056TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
Sean Christophersonef6a74b2021-06-22 13:05:29 -070057TEST_GEN_PROGS_x86_64 += x86_64/mmu_role_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000058TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
Jim Mattsonbef9a702022-01-14 21:24:31 -080059TEST_GEN_PROGS_x86_64 += x86_64/pmu_event_filter_test
Emanuele Giuseppe Esposito3df22522021-03-18 16:16:24 +010060TEST_GEN_PROGS_x86_64 += x86_64/set_boot_cpu_id
Aaron Lewis61cfcd52019-05-21 17:13:58 +000061TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
62TEST_GEN_PROGS_x86_64 += x86_64/smm_test
63TEST_GEN_PROGS_x86_64 += x86_64/state_test
Makarand Sonare8d7fbf02020-05-26 14:51:07 -070064TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010065TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test
Maxim Levitsky1ad32102021-09-14 18:48:13 +030066TEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000067TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
Sean Christopherson10e7a092021-10-25 13:13:11 -070068TEST_GEN_PROGS_x86_64 += x86_64/userspace_io_test
Aaron Lewis3cea1892020-10-12 12:47:16 -070069TEST_GEN_PROGS_x86_64 += x86_64/userspace_msr_exit_test
Jim Mattson97a71a52020-10-26 11:09:22 -070070TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000071TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
Paolo Bonzini09444422019-09-26 15:01:15 +020072TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
Sean Christophersone337f7e2021-12-28 23:24:37 +000073TEST_GEN_PROGS_x86_64 += x86_64/vmx_exception_with_invalid_guest_state
Sean Christophersonab1ef342021-12-07 19:30:06 +000074TEST_GEN_PROGS_x86_64 += x86_64/vmx_invalid_nested_guest_state
Aaron Lewisda1e3072019-05-02 11:31:41 -070075TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000076TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
Ilias Stamatisefe58542021-05-26 19:44:18 +010077TEST_GEN_PROGS_x86_64 += x86_64/vmx_nested_tsc_scaling_test
Peter Shier678e90a2020-11-05 14:38:23 -080078TEST_GEN_PROGS_x86_64 += x86_64/xapic_ipi_test
Aaron Lewisc90992b2019-10-21 16:30:28 -070079TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
Peter Xu449aa902020-05-05 16:50:00 -040080TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
Paolo Bonzini0c899c22020-09-24 14:45:27 +020081TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
Like Xuf88d4f22021-02-01 13:10:39 +080082TEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_msrs_test
David Woodhouse8d4e7e82020-12-04 01:02:04 +000083TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test
Joao Martins23200b72018-06-13 09:55:44 -040084TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
Peter Gonda6a581502021-10-21 10:43:03 -070085TEST_GEN_PROGS_x86_64 += x86_64/vmx_pi_mmio_test
86TEST_GEN_PROGS_x86_64 += x86_64/sev_migrate_tests
Yang Zhongbf706362021-12-23 09:53:22 -050087TEST_GEN_PROGS_x86_64 += x86_64/amx_test
Ben Gardon025eed72020-01-23 10:04:27 -080088TEST_GEN_PROGS_x86_64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010089TEST_GEN_PROGS_x86_64 += dirty_log_test
Ben Gardon4fd94ec2020-10-27 16:37:33 -070090TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
Ignacio Alvarado1838b062021-02-13 00:14:52 +000091TEST_GEN_PROGS_x86_64 += hardware_disable_test
Paolo Bonzinifd4198bf2019-07-15 12:50:46 +020092TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +080093TEST_GEN_PROGS_x86_64 += kvm_page_table_test
Ben Gardonf73a3442021-01-12 13:42:53 -080094TEST_GEN_PROGS_x86_64 += memslot_modification_stress_test
Maciej S. Szmigierocad347f2021-04-13 16:08:28 +020095TEST_GEN_PROGS_x86_64 += memslot_perf_test
Sean Christopherson61e52f12021-09-01 13:30:29 -070096TEST_GEN_PROGS_x86_64 += rseq_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -070097TEST_GEN_PROGS_x86_64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010098TEST_GEN_PROGS_x86_64 += steal_time
Jing Zhang0b45d582021-06-18 22:27:08 +000099TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
Oliver Upton3f9808c2021-09-16 18:15:51 +0000100TEST_GEN_PROGS_x86_64 += system_counter_offset_test
Andrew Jonesfff8dcd2018-09-18 19:54:32 +0200101
Raghavendra Rao Ananta4959d862021-10-07 23:34:38 +0000102TEST_GEN_PROGS_aarch64 += aarch64/arch_timer
Ricardo Koller4f052232021-06-10 18:10:20 -0700103TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
Andrew Jonesfd020292020-10-29 21:17:01 +0100104TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
Oliver Uptoncb97cf92021-08-18 20:21:33 +0000105TEST_GEN_PROGS_aarch64 += aarch64/psci_cpu_on_test
Eric Augerdc0e0582021-04-05 18:39:41 +0200106TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
Ricardo Koller50b020c2021-11-08 18:38:55 -0800107TEST_GEN_PROGS_aarch64 += aarch64/vgic_irq
Ben Gardon025eed72020-01-23 10:04:27 -0800108TEST_GEN_PROGS_aarch64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +0100109TEST_GEN_PROGS_aarch64 += dirty_log_test
Andrew Jones87c5f352020-11-11 13:26:34 +0100110TEST_GEN_PROGS_aarch64 += dirty_log_perf_test
Thomas Huth49fe9a52019-05-23 18:43:09 +0200111TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +0800112TEST_GEN_PROGS_aarch64 += kvm_page_table_test
Ricardo Koller358928f2021-09-07 11:09:57 -0700113TEST_GEN_PROGS_aarch64 += memslot_modification_stress_test
114TEST_GEN_PROGS_aarch64 += memslot_perf_test
Sean Christopherson61e52f12021-09-01 13:30:29 -0700115TEST_GEN_PROGS_aarch64 += rseq_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -0700116TEST_GEN_PROGS_aarch64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +0100117TEST_GEN_PROGS_aarch64 += steal_time
Jing Zhang0b45d582021-06-18 22:27:08 +0000118TEST_GEN_PROGS_aarch64 += kvm_binary_stats_test
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200119
Thomas Huthbe6f55a2019-08-29 15:07:32 +0200120TEST_GEN_PROGS_s390x = s390x/memop
Janosch Frankb25d4cb2020-01-31 05:02:04 -0500121TEST_GEN_PROGS_s390x += s390x/resets
Andrew Jones94c4b76b2020-03-13 16:56:44 +0100122TEST_GEN_PROGS_s390x += s390x/sync_regs_test
Ben Gardon025eed72020-01-23 10:04:27 -0800123TEST_GEN_PROGS_s390x += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +0100124TEST_GEN_PROGS_s390x += dirty_log_test
Thomas Huth49fe9a52019-05-23 18:43:09 +0200125TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
Yanan Wangb9c2bd52021-03-30 16:08:56 +0800126TEST_GEN_PROGS_s390x += kvm_page_table_test
Sean Christopherson61e52f12021-09-01 13:30:29 -0700127TEST_GEN_PROGS_s390x += rseq_test
Sean Christopherson5b4f7582020-04-10 16:17:06 -0700128TEST_GEN_PROGS_s390x += set_memory_region_test
Jing Zhang0b45d582021-06-18 22:27:08 +0000129TEST_GEN_PROGS_s390x += kvm_binary_stats_test
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200130
Anup Patel3e06cdf2021-10-05 18:09:56 +0530131TEST_GEN_PROGS_riscv += demand_paging_test
132TEST_GEN_PROGS_riscv += dirty_log_test
133TEST_GEN_PROGS_riscv += kvm_create_max_vcpus
134TEST_GEN_PROGS_riscv += kvm_page_table_test
135TEST_GEN_PROGS_riscv += set_memory_region_test
136TEST_GEN_PROGS_riscv += kvm_binary_stats_test
137
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200138TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
139LIBKVM += $(LIBKVM_$(UNAME_M))
140
141INSTALL_HDR_PATH = $(top_srcdir)/usr
142LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
Andrew Jonescc687652018-09-18 19:54:26 +0200143LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +0200144ifeq ($(ARCH),x86_64)
145LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include
146else
Shuah Khan66d69e02020-04-27 18:11:07 -0600147LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +0200148endif
Thomas Huth319f6f92019-05-17 11:04:45 +0200149CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
150 -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
Sean Christophersona5543d32019-12-20 20:44:56 -0800151 -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
Anup Patel788490e2021-11-26 18:33:45 +0530152 -I$(<D) -Iinclude/$(UNAME_M) -I.. $(EXTRA_CFLAGS)
Paolo Bonzinic2390f12019-04-11 15:51:19 +0200153
154no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
Shuah Khan6e069832019-10-02 17:14:30 -0600155 $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
Paolo Bonzinic2390f12019-04-11 15:51:19 +0200156
Christian Borntraeger8343ba22019-05-24 12:27:01 +0200157# On s390, build the testcases KVM-enabled
158pgste-option = $(call try-run, echo 'int main() { return 0; }' | \
159 $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste)
160
161
162LDFLAGS += -pthread $(no-pie-option) $(pgste-option)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200163
164# After inclusion, $(OUTPUT) is defined and
165# $(TEST_GEN_PROGS) starts with $(OUTPUT)/
166include ../lib.mk
167
168STATIC_LIBS := $(OUTPUT)/libkvm.a
Aaron Lewis29faeb92020-10-12 12:47:15 -0700169LIBKVM_C := $(filter %.c,$(LIBKVM))
170LIBKVM_S := $(filter %.S,$(LIBKVM))
171LIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C))
172LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S))
173EXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.*
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200174
Aaron Lewis29faeb92020-10-12 12:47:15 -0700175x := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
176$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200177 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
178
Aaron Lewis29faeb92020-10-12 12:47:15 -0700179$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S
180 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
181
182LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)
183$(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200184 $(AR) crs $@ $^
185
Shuah Khan66d69e02020-04-27 18:11:07 -0600186x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
Anders Roxellb2d35fa2018-09-04 12:47:21 +0200187all: $(STATIC_LIBS)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200188$(TEST_GEN_PROGS): $(STATIC_LIBS)
Andrew Joneseea192b2018-09-18 19:54:27 +0200189
190cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
191cscope:
192 $(RM) cscope.*
193 (find $(include_paths) -name '*.h' \
194 -exec realpath --relative-base=$(PWD) {} \;; \
195 find . -name '*.c' \
196 -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files
197 cscope -b