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