blob: 4a166588d99f2df2be12056723433d43fcaa1c6c [file] [log] [blame]
Thomas Gleixnerec8f24b2019-05-19 13:07:45 +01001# SPDX-License-Identifier: GPL-2.0-only
Paolo Bonzinic2390f12019-04-11 15:51:19 +02002include ../../../../scripts/Kbuild.include
3
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
Ben Gardonaf99e1a2020-01-23 10:04:30 -080036LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c
Eric Auger20ba2622020-02-06 11:47:09 +010037LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c
Thomas Huth2040f412019-07-31 17:15:23 +020038LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
Thomas Huthf90f57b2019-07-31 17:15:24 +020039LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.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
Vitaly Kuznetsov18178ff2018-10-16 18:50:11 +020042TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
Vitaly Kuznetsov7edcb732018-12-10 18:21:59 +010043TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
Aaron Lewis9dba9882019-05-31 14:14:52 +000044TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000045TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
46TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
47TEST_GEN_PROGS_x86_64 += x86_64/smm_test
48TEST_GEN_PROGS_x86_64 += x86_64/state_test
Makarand Sonare8d7fbf02020-05-26 14:51:07 -070049TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010050TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000051TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
52TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
Paolo Bonzini09444422019-09-26 15:01:15 +020053TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
Aaron Lewisda1e3072019-05-02 11:31:41 -070054TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
Aaron Lewis61cfcd52019-05-21 17:13:58 +000055TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
Aaron Lewisc90992b2019-10-21 16:30:28 -070056TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
Peter Xu449aa902020-05-05 16:50:00 -040057TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +020058TEST_GEN_PROGS_x86_64 += clear_dirty_log_test
Ben Gardon025eed72020-01-23 10:04:27 -080059TEST_GEN_PROGS_x86_64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010060TEST_GEN_PROGS_x86_64 += dirty_log_test
Paolo Bonzinifd4198bf2019-07-15 12:50:46 +020061TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
Sean Christopherson5b4f7582020-04-10 16:17:06 -070062TEST_GEN_PROGS_x86_64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010063TEST_GEN_PROGS_x86_64 += steal_time
Andrew Jonesfff8dcd2018-09-18 19:54:32 +020064
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +020065TEST_GEN_PROGS_aarch64 += clear_dirty_log_test
Ben Gardon025eed72020-01-23 10:04:27 -080066TEST_GEN_PROGS_aarch64 += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010067TEST_GEN_PROGS_aarch64 += dirty_log_test
Thomas Huth49fe9a52019-05-23 18:43:09 +020068TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
Sean Christopherson5b4f7582020-04-10 16:17:06 -070069TEST_GEN_PROGS_aarch64 += set_memory_region_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010070TEST_GEN_PROGS_aarch64 += steal_time
Paolo Bonzini783e9e52018-03-27 11:49:19 +020071
Thomas Huthbe6f55a2019-08-29 15:07:32 +020072TEST_GEN_PROGS_s390x = s390x/memop
Janosch Frankb25d4cb2020-01-31 05:02:04 -050073TEST_GEN_PROGS_s390x += s390x/resets
Andrew Jones94c4b76b2020-03-13 16:56:44 +010074TEST_GEN_PROGS_s390x += s390x/sync_regs_test
Ben Gardon025eed72020-01-23 10:04:27 -080075TEST_GEN_PROGS_s390x += demand_paging_test
Andrew Jones94c4b76b2020-03-13 16:56:44 +010076TEST_GEN_PROGS_s390x += dirty_log_test
Thomas Huth49fe9a52019-05-23 18:43:09 +020077TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
Sean Christopherson5b4f7582020-04-10 16:17:06 -070078TEST_GEN_PROGS_s390x += set_memory_region_test
Paolo Bonzini783e9e52018-03-27 11:49:19 +020079
80TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
81LIBKVM += $(LIBKVM_$(UNAME_M))
82
83INSTALL_HDR_PATH = $(top_srcdir)/usr
84LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
Andrew Jonescc687652018-09-18 19:54:26 +020085LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +020086ifeq ($(ARCH),x86_64)
87LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include
88else
Shuah Khan66d69e02020-04-27 18:11:07 -060089LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
Vitaly Kuznetsovb80db732020-06-05 16:20:28 +020090endif
Thomas Huth319f6f92019-05-17 11:04:45 +020091CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
92 -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
Sean Christophersona5543d32019-12-20 20:44:56 -080093 -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
94 -I$(<D) -Iinclude/$(UNAME_M) -I..
Paolo Bonzinic2390f12019-04-11 15:51:19 +020095
96no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
Shuah Khan6e069832019-10-02 17:14:30 -060097 $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
Paolo Bonzinic2390f12019-04-11 15:51:19 +020098
Christian Borntraeger8343ba22019-05-24 12:27:01 +020099# On s390, build the testcases KVM-enabled
100pgste-option = $(call try-run, echo 'int main() { return 0; }' | \
101 $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste)
102
103
104LDFLAGS += -pthread $(no-pie-option) $(pgste-option)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200105
106# After inclusion, $(OUTPUT) is defined and
107# $(TEST_GEN_PROGS) starts with $(OUTPUT)/
108include ../lib.mk
109
110STATIC_LIBS := $(OUTPUT)/libkvm.a
111LIBKVM_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM))
Andrew Joneseea192b2018-09-18 19:54:27 +0200112EXTRA_CLEAN += $(LIBKVM_OBJ) $(STATIC_LIBS) cscope.*
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200113
114x := $(shell mkdir -p $(sort $(dir $(LIBKVM_OBJ))))
115$(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c
116 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
117
118$(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
119 $(AR) crs $@ $^
120
Shuah Khan66d69e02020-04-27 18:11:07 -0600121x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
Anders Roxellb2d35fa2018-09-04 12:47:21 +0200122all: $(STATIC_LIBS)
Paolo Bonzini783e9e52018-03-27 11:49:19 +0200123$(TEST_GEN_PROGS): $(STATIC_LIBS)
Andrew Joneseea192b2018-09-18 19:54:27 +0200124
125cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
126cscope:
127 $(RM) cscope.*
128 (find $(include_paths) -name '*.h' \
129 -exec realpath --relative-base=$(PWD) {} \;; \
130 find . -name '*.c' \
131 -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files
132 cscope -b