Thomas Gleixner | ec8f24b | 2019-05-19 13:07:45 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
Masahiro Yamada | b61442d | 2021-04-16 22:00:51 +0900 | [diff] [blame] | 2 | include ../../../build/Build.include |
Paolo Bonzini | c2390f1 | 2019-04-11 15:51:19 +0200 | [diff] [blame] | 3 | |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 4 | all: |
| 5 | |
Andrew Jones | cc68765 | 2018-09-18 19:54:26 +0200 | [diff] [blame] | 6 | top_srcdir = ../../../.. |
Shuah Khan | 211929f | 2018-12-12 20:25:14 -0700 | [diff] [blame] | 7 | KSFT_KHDR_INSTALL := 1 |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 8 | |
| 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 Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 25 | UNAME_M := $(shell uname -m) |
| 26 | |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 27 | # Set UNAME_M for arm64 compile/install to work |
| 28 | ifeq ($(ARCH),arm64) |
| 29 | UNAME_M := aarch64 |
| 30 | endif |
| 31 | # Set UNAME_M s390x compile/install to work |
| 32 | ifeq ($(ARCH),s390) |
| 33 | UNAME_M := s390x |
| 34 | endif |
| 35 | |
Maciej S. Szmigiero | 22721a5 | 2021-04-13 16:08:27 +0200 | [diff] [blame] | 36 | LIBKVM = 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 Mattson | 4c63c92 | 2021-06-04 10:26:08 -0700 | [diff] [blame^] | 37 | LIBKVM_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 Huth | 2040f41 | 2019-07-31 17:15:23 +0200 | [diff] [blame] | 38 | LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c |
Collin Walling | efaa83a | 2020-12-07 10:41:25 -0500 | [diff] [blame] | 39 | LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 40 | |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 41 | TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test |
Emanuele Giuseppe Esposito | 77a3aa2 | 2021-03-18 15:56:29 +0100 | [diff] [blame] | 42 | TEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features |
Vitaly Kuznetsov | 18178ff | 2018-10-16 18:50:11 +0200 | [diff] [blame] | 43 | TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test |
Vitaly Kuznetsov | fb18d05 | 2021-01-29 17:18:21 +0100 | [diff] [blame] | 44 | TEST_GEN_PROGS_x86_64 += x86_64/get_cpuid_test |
Vitaly Kuznetsov | 2c7f76b | 2021-03-18 15:09:49 +0100 | [diff] [blame] | 45 | TEST_GEN_PROGS_x86_64 += x86_64/hyperv_clock |
Vitaly Kuznetsov | 7edcb73 | 2018-12-10 18:21:59 +0100 | [diff] [blame] | 46 | TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid |
Oliver Upton | ac4a4d6 | 2020-10-27 16:10:44 -0700 | [diff] [blame] | 47 | TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test |
Aaron Lewis | 9dba988 | 2019-05-31 14:14:52 +0000 | [diff] [blame] | 48 | TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 49 | TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test |
Emanuele Giuseppe Esposito | 3df2252 | 2021-03-18 16:16:24 +0100 | [diff] [blame] | 50 | TEST_GEN_PROGS_x86_64 += x86_64/set_boot_cpu_id |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 51 | TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test |
| 52 | TEST_GEN_PROGS_x86_64 += x86_64/smm_test |
| 53 | TEST_GEN_PROGS_x86_64 += x86_64/state_test |
Makarand Sonare | 8d7fbf0 | 2020-05-26 14:51:07 -0700 | [diff] [blame] | 54 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 55 | TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 56 | TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test |
Aaron Lewis | 3cea189 | 2020-10-12 12:47:16 -0700 | [diff] [blame] | 57 | TEST_GEN_PROGS_x86_64 += x86_64/userspace_msr_exit_test |
Jim Mattson | 97a71a5 | 2020-10-26 11:09:22 -0700 | [diff] [blame] | 58 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 59 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test |
Paolo Bonzini | 0944442 | 2019-09-26 15:01:15 +0200 | [diff] [blame] | 60 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test |
Aaron Lewis | da1e307 | 2019-05-02 11:31:41 -0700 | [diff] [blame] | 61 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 62 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test |
Ilias Stamatis | efe5854 | 2021-05-26 19:44:18 +0100 | [diff] [blame] | 63 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_nested_tsc_scaling_test |
Peter Shier | 678e90a | 2020-11-05 14:38:23 -0800 | [diff] [blame] | 64 | TEST_GEN_PROGS_x86_64 += x86_64/xapic_ipi_test |
Aaron Lewis | c90992b | 2019-10-21 16:30:28 -0700 | [diff] [blame] | 65 | TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test |
Peter Xu | 449aa90 | 2020-05-05 16:50:00 -0400 | [diff] [blame] | 66 | TEST_GEN_PROGS_x86_64 += x86_64/debug_regs |
Paolo Bonzini | 0c899c2 | 2020-09-24 14:45:27 +0200 | [diff] [blame] | 67 | TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test |
Like Xu | f88d4f2 | 2021-02-01 13:10:39 +0800 | [diff] [blame] | 68 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_msrs_test |
David Woodhouse | 8d4e7e8 | 2020-12-04 01:02:04 +0000 | [diff] [blame] | 69 | TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test |
Joao Martins | 23200b7 | 2018-06-13 09:55:44 -0400 | [diff] [blame] | 70 | TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test |
Ben Gardon | 025eed7 | 2020-01-23 10:04:27 -0800 | [diff] [blame] | 71 | TEST_GEN_PROGS_x86_64 += demand_paging_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 72 | TEST_GEN_PROGS_x86_64 += dirty_log_test |
Ben Gardon | 4fd94ec | 2020-10-27 16:37:33 -0700 | [diff] [blame] | 73 | TEST_GEN_PROGS_x86_64 += dirty_log_perf_test |
Ignacio Alvarado | 1838b06 | 2021-02-13 00:14:52 +0000 | [diff] [blame] | 74 | TEST_GEN_PROGS_x86_64 += hardware_disable_test |
Paolo Bonzini | fd4198bf | 2019-07-15 12:50:46 +0200 | [diff] [blame] | 75 | TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus |
Yanan Wang | b9c2bd5 | 2021-03-30 16:08:56 +0800 | [diff] [blame] | 76 | TEST_GEN_PROGS_x86_64 += kvm_page_table_test |
Ben Gardon | f73a344 | 2021-01-12 13:42:53 -0800 | [diff] [blame] | 77 | TEST_GEN_PROGS_x86_64 += memslot_modification_stress_test |
Maciej S. Szmigiero | cad347f | 2021-04-13 16:08:28 +0200 | [diff] [blame] | 78 | TEST_GEN_PROGS_x86_64 += memslot_perf_test |
Sean Christopherson | 5b4f758 | 2020-04-10 16:17:06 -0700 | [diff] [blame] | 79 | TEST_GEN_PROGS_x86_64 += set_memory_region_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 80 | TEST_GEN_PROGS_x86_64 += steal_time |
Andrew Jones | fff8dcd | 2018-09-18 19:54:32 +0200 | [diff] [blame] | 81 | |
Andrew Jones | fd02029 | 2020-10-29 21:17:01 +0100 | [diff] [blame] | 82 | TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list |
Andrew Jones | 31d2129 | 2020-10-29 21:17:03 +0100 | [diff] [blame] | 83 | TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve |
Eric Auger | dc0e058 | 2021-04-05 18:39:41 +0200 | [diff] [blame] | 84 | TEST_GEN_PROGS_aarch64 += aarch64/vgic_init |
Ben Gardon | 025eed7 | 2020-01-23 10:04:27 -0800 | [diff] [blame] | 85 | TEST_GEN_PROGS_aarch64 += demand_paging_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 86 | TEST_GEN_PROGS_aarch64 += dirty_log_test |
Andrew Jones | 87c5f35 | 2020-11-11 13:26:34 +0100 | [diff] [blame] | 87 | TEST_GEN_PROGS_aarch64 += dirty_log_perf_test |
Thomas Huth | 49fe9a5 | 2019-05-23 18:43:09 +0200 | [diff] [blame] | 88 | TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus |
Yanan Wang | b9c2bd5 | 2021-03-30 16:08:56 +0800 | [diff] [blame] | 89 | TEST_GEN_PROGS_aarch64 += kvm_page_table_test |
Sean Christopherson | 5b4f758 | 2020-04-10 16:17:06 -0700 | [diff] [blame] | 90 | TEST_GEN_PROGS_aarch64 += set_memory_region_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 91 | TEST_GEN_PROGS_aarch64 += steal_time |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 92 | |
Thomas Huth | be6f55a | 2019-08-29 15:07:32 +0200 | [diff] [blame] | 93 | TEST_GEN_PROGS_s390x = s390x/memop |
Janosch Frank | b25d4cb | 2020-01-31 05:02:04 -0500 | [diff] [blame] | 94 | TEST_GEN_PROGS_s390x += s390x/resets |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 95 | TEST_GEN_PROGS_s390x += s390x/sync_regs_test |
Ben Gardon | 025eed7 | 2020-01-23 10:04:27 -0800 | [diff] [blame] | 96 | TEST_GEN_PROGS_s390x += demand_paging_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 97 | TEST_GEN_PROGS_s390x += dirty_log_test |
Thomas Huth | 49fe9a5 | 2019-05-23 18:43:09 +0200 | [diff] [blame] | 98 | TEST_GEN_PROGS_s390x += kvm_create_max_vcpus |
Yanan Wang | b9c2bd5 | 2021-03-30 16:08:56 +0800 | [diff] [blame] | 99 | TEST_GEN_PROGS_s390x += kvm_page_table_test |
Sean Christopherson | 5b4f758 | 2020-04-10 16:17:06 -0700 | [diff] [blame] | 100 | TEST_GEN_PROGS_s390x += set_memory_region_test |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 101 | |
| 102 | TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) |
| 103 | LIBKVM += $(LIBKVM_$(UNAME_M)) |
| 104 | |
| 105 | INSTALL_HDR_PATH = $(top_srcdir)/usr |
| 106 | LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ |
Andrew Jones | cc68765 | 2018-09-18 19:54:26 +0200 | [diff] [blame] | 107 | LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include |
Vitaly Kuznetsov | b80db73 | 2020-06-05 16:20:28 +0200 | [diff] [blame] | 108 | ifeq ($(ARCH),x86_64) |
| 109 | LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include |
| 110 | else |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 111 | LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include |
Vitaly Kuznetsov | b80db73 | 2020-06-05 16:20:28 +0200 | [diff] [blame] | 112 | endif |
Thomas Huth | 319f6f9 | 2019-05-17 11:04:45 +0200 | [diff] [blame] | 113 | CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ |
| 114 | -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ |
Sean Christopherson | a5543d3 | 2019-12-20 20:44:56 -0800 | [diff] [blame] | 115 | -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ |
| 116 | -I$(<D) -Iinclude/$(UNAME_M) -I.. |
Paolo Bonzini | c2390f1 | 2019-04-11 15:51:19 +0200 | [diff] [blame] | 117 | |
| 118 | no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ |
Shuah Khan | 6e06983 | 2019-10-02 17:14:30 -0600 | [diff] [blame] | 119 | $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie) |
Paolo Bonzini | c2390f1 | 2019-04-11 15:51:19 +0200 | [diff] [blame] | 120 | |
Christian Borntraeger | 8343ba2 | 2019-05-24 12:27:01 +0200 | [diff] [blame] | 121 | # On s390, build the testcases KVM-enabled |
| 122 | pgste-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 | |
| 126 | LDFLAGS += -pthread $(no-pie-option) $(pgste-option) |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 127 | |
| 128 | # After inclusion, $(OUTPUT) is defined and |
| 129 | # $(TEST_GEN_PROGS) starts with $(OUTPUT)/ |
| 130 | include ../lib.mk |
| 131 | |
| 132 | STATIC_LIBS := $(OUTPUT)/libkvm.a |
Aaron Lewis | 29faeb9 | 2020-10-12 12:47:15 -0700 | [diff] [blame] | 133 | LIBKVM_C := $(filter %.c,$(LIBKVM)) |
| 134 | LIBKVM_S := $(filter %.S,$(LIBKVM)) |
| 135 | LIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C)) |
| 136 | LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S)) |
| 137 | EXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.* |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 138 | |
Aaron Lewis | 29faeb9 | 2020-10-12 12:47:15 -0700 | [diff] [blame] | 139 | x := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)))) |
| 140 | $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 141 | $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ |
| 142 | |
Aaron Lewis | 29faeb9 | 2020-10-12 12:47:15 -0700 | [diff] [blame] | 143 | $(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S |
| 144 | $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ |
| 145 | |
| 146 | LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) |
| 147 | $(OUTPUT)/libkvm.a: $(LIBKVM_OBJS) |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 148 | $(AR) crs $@ $^ |
| 149 | |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 150 | x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS)))) |
Anders Roxell | b2d35fa | 2018-09-04 12:47:21 +0200 | [diff] [blame] | 151 | all: $(STATIC_LIBS) |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 152 | $(TEST_GEN_PROGS): $(STATIC_LIBS) |
Andrew Jones | eea192b | 2018-09-18 19:54:27 +0200 | [diff] [blame] | 153 | |
| 154 | cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. |
| 155 | cscope: |
| 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 |