1 # SPDX-License-Identifier: GPL-2.0 2 # Makefile for mm selftests 3 4 LOCAL_HDRS += $(selfdir)/mm/local_config.h $(top_srcdir)/mm/gup_test.h 5 LOCAL_HDRS += $(selfdir)/mm/mseal_helpers.h 6 7 include local_config.mk 8 9 ifeq ($(ARCH),) 10 11 ifeq ($(CROSS_COMPILE),) 12 uname_M := $(shell uname -m 2>/dev/null || echo not) 13 else 14 uname_M := $(shell echo $(CROSS_COMPILE) | grep -o '^[a-z0-9]\+') 15 endif 16 ARCH ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/powerpc/') 17 endif 18 19 # Without this, failed build products remain, with up-to-date timestamps, 20 # thus tricking Make (and you!) into believing that All Is Well, in subsequent 21 # make invocations: 22 .DELETE_ON_ERROR: 23 24 # Avoid accidental wrong builds, due to built-in rules working just a little 25 # bit too well--but not quite as well as required for our situation here. 26 # 27 # In other words, "make $SOME_TEST" is supposed to fail to build at all, 28 # because this Makefile only supports either "make" (all), or "make /full/path". 29 # However, the built-in rules, if not suppressed, will pick up CFLAGS and the 30 # initial LDLIBS (but not the target-specific LDLIBS, because those are only 31 # set for the full path target!). This causes it to get pretty far into building 32 # things despite using incorrect values such as an *occasionally* incomplete 33 # LDLIBS. 34 MAKEFLAGS += --no-builtin-rules 35 36 CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES) 37 LDLIBS = -lrt -lpthread -lm 38 39 TEST_GEN_FILES = cow 40 TEST_GEN_FILES += compaction_test 41 TEST_GEN_FILES += gup_longterm 42 TEST_GEN_FILES += gup_test 43 TEST_GEN_FILES += hmm-tests 44 TEST_GEN_FILES += hugetlb-madvise 45 TEST_GEN_FILES += hugetlb-read-hwpoison 46 TEST_GEN_FILES += hugetlb-soft-offline 47 TEST_GEN_FILES += hugepage-mmap 48 TEST_GEN_FILES += hugepage-mremap 49 TEST_GEN_FILES += hugepage-shm 50 TEST_GEN_FILES += hugepage-vmemmap 51 TEST_GEN_FILES += khugepaged 52 TEST_GEN_FILES += madv_populate 53 TEST_GEN_FILES += map_fixed_noreplace 54 TEST_GEN_FILES += map_hugetlb 55 TEST_GEN_FILES += map_populate 56 ifneq (,$(filter $(ARCH),arm64 riscv riscv64 x86 x86_64)) 57 TEST_GEN_FILES += memfd_secret 58 endif 59 TEST_GEN_FILES += migration 60 TEST_GEN_FILES += mkdirty 61 TEST_GEN_FILES += mlock-random-test 62 TEST_GEN_FILES += mlock2-tests 63 TEST_GEN_FILES += mrelease_test 64 TEST_GEN_FILES += mremap_dontunmap 65 TEST_GEN_FILES += mremap_test 66 TEST_GEN_FILES += mseal_test 67 TEST_GEN_FILES += seal_elf 68 TEST_GEN_FILES += on-fault-limit 69 TEST_GEN_FILES += pagemap_ioctl 70 TEST_GEN_FILES += thuge-gen 71 TEST_GEN_FILES += transhuge-stress 72 TEST_GEN_FILES += uffd-stress 73 TEST_GEN_FILES += uffd-unit-tests 74 TEST_GEN_FILES += split_huge_page_test 75 TEST_GEN_FILES += ksm_tests 76 TEST_GEN_FILES += ksm_functional_tests 77 TEST_GEN_FILES += mdwe_test 78 TEST_GEN_FILES += hugetlb_fault_after_madv 79 TEST_GEN_FILES += hugetlb_madv_vs_map 80 TEST_GEN_FILES += hugetlb_dio 81 TEST_GEN_FILES += droppable 82 83 ifneq ($(ARCH),arm64) 84 TEST_GEN_FILES += soft-dirty 85 endif 86 87 ifeq ($(ARCH),x86_64) 88 CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32) 89 CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c) 90 CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie) 91 92 VMTARGETS := protection_keys 93 VMTARGETS += pkey_sighandler_tests 94 BINARIES_32 := $(VMTARGETS:%=%_32) 95 BINARIES_64 := $(VMTARGETS:%=%_64) 96 97 ifeq ($(CAN_BUILD_WITH_NOPIE),1) 98 CFLAGS += -no-pie 99 endif 100 101 ifeq ($(CAN_BUILD_I386),1) 102 TEST_GEN_FILES += $(BINARIES_32) 103 endif 104 105 ifeq ($(CAN_BUILD_X86_64),1) 106 TEST_GEN_FILES += $(BINARIES_64) 107 endif 108 else 109 110 ifneq (,$(filter $(ARCH),arm64 powerpc)) 111 TEST_GEN_FILES += protection_keys 112 endif 113 114 endif 115 116 ifneq (,$(filter $(ARCH),arm64 mips64 parisc64 powerpc riscv64 s390x sparc64 x86_64 s390)) 117 TEST_GEN_FILES += va_high_addr_switch 118 TEST_GEN_FILES += virtual_address_range 119 TEST_GEN_FILES += write_to_hugetlbfs 120 endif 121 122 TEST_PROGS := run_vmtests.sh 123 124 TEST_FILES := test_vmalloc.sh 125 TEST_FILES += test_hmm.sh 126 TEST_FILES += va_high_addr_switch.sh 127 TEST_FILES += charge_reserved_hugetlb.sh 128 TEST_FILES += hugetlb_reparenting_test.sh 129 130 # required by charge_reserved_hugetlb.sh 131 TEST_FILES += write_hugetlb_memory.sh 132 133 include ../lib.mk 134 135 $(TEST_GEN_PROGS): vm_util.c thp_settings.c 136 $(TEST_GEN_FILES): vm_util.c thp_settings.c 137 138 $(OUTPUT)/uffd-stress: uffd-common.c 139 $(OUTPUT)/uffd-unit-tests: uffd-common.c 140 141 ifeq ($(ARCH),x86_64) 142 BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) 143 BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) 144 145 define gen-target-rule-32 146 $(1) $(1)_32: $(OUTPUT)/$(1)_32 147 .PHONY: $(1) $(1)_32 148 endef 149 150 define gen-target-rule-64 151 $(1) $(1)_64: $(OUTPUT)/$(1)_64 152 .PHONY: $(1) $(1)_64 153 endef 154 155 ifeq ($(CAN_BUILD_I386),1) 156 $(BINARIES_32): CFLAGS += -m32 -mxsave 157 $(BINARIES_32): LDLIBS += -lrt -ldl -lm 158 $(BINARIES_32): $(OUTPUT)/%_32: %.c 159 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 160 $(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t)))) 161 endif 162 163 ifeq ($(CAN_BUILD_X86_64),1) 164 $(BINARIES_64): CFLAGS += -m64 -mxsave 165 $(BINARIES_64): LDLIBS += -lrt -ldl 166 $(BINARIES_64): $(OUTPUT)/%_64: %.c 167 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 168 $(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t)))) 169 endif 170 171 # x86_64 users should be encouraged to install 32-bit libraries 172 ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) 173 all: warn_32bit_failure 174 175 warn_32bit_failure: 176 @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ 177 echo "environment. This will reduce test coverage of 64-bit" 2>&1; \ 178 echo "kernels. If you are using a Debian-like distribution," 2>&1; \ 179 echo "try:"; 2>&1; \ 180 echo ""; \ 181 echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ 182 echo ""; \ 183 echo "If you are using a Fedora-like distribution, try:"; \ 184 echo ""; \ 185 echo " yum install glibc-devel.*i686"; \ 186 exit 0; 187 endif 188 endif 189 190 # IOURING_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. 191 $(OUTPUT)/cow: LDLIBS += $(IOURING_EXTRA_LIBS) 192 193 $(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS) 194 195 $(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap 196 197 $(OUTPUT)/ksm_tests: LDLIBS += -lnuma 198 199 $(OUTPUT)/migration: LDLIBS += -lnuma 200 201 local_config.mk local_config.h: check_config.sh 202 /bin/sh ./check_config.sh $(CC) 203 204 EXTRA_CLEAN += local_config.mk local_config.h 205 206 ifeq ($(IOURING_EXTRA_LIBS),) 207 all: warn_missing_liburing 208 209 warn_missing_liburing: 210 @echo ; \ 211 echo "Warning: missing liburing support. Some tests will be skipped." ; \ 212 echo 213 endif
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.