1# SPDX-License-Identifier: GPL-2.0 2# Makefile for mm selftests 3 4LOCAL_HDRS += $(selfdir)/mm/local_config.h $(top_srcdir)/mm/gup_test.h 5LOCAL_HDRS += $(selfdir)/mm/mseal_helpers.h 6 7include local_config.mk 8 9ifeq ($(ARCH),) 10 11ifeq ($(CROSS_COMPILE),) 12uname_M := $(shell uname -m 2>/dev/null || echo not) 13else 14uname_M := $(shell echo $(CROSS_COMPILE) | grep -o '^[a-z0-9]\+') 15endif 16ARCH ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/powerpc/') 17endif 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. 34MAKEFLAGS += --no-builtin-rules 35 36CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES) 37LDLIBS = -lrt -lpthread -lm 38 39TEST_GEN_FILES = cow 40TEST_GEN_FILES += compaction_test 41TEST_GEN_FILES += gup_longterm 42TEST_GEN_FILES += gup_test 43TEST_GEN_FILES += hmm-tests 44TEST_GEN_FILES += hugetlb-madvise 45TEST_GEN_FILES += hugetlb-read-hwpoison 46TEST_GEN_FILES += hugetlb-soft-offline 47TEST_GEN_FILES += hugepage-mmap 48TEST_GEN_FILES += hugepage-mremap 49TEST_GEN_FILES += hugepage-shm 50TEST_GEN_FILES += hugepage-vmemmap 51TEST_GEN_FILES += khugepaged 52TEST_GEN_FILES += madv_populate 53TEST_GEN_FILES += map_fixed_noreplace 54TEST_GEN_FILES += map_hugetlb 55TEST_GEN_FILES += map_populate 56ifneq (,$(filter $(ARCH),arm64 riscv riscv64 x86 x86_64)) 57TEST_GEN_FILES += memfd_secret 58endif 59TEST_GEN_FILES += migration 60TEST_GEN_FILES += mkdirty 61TEST_GEN_FILES += mlock-random-test 62TEST_GEN_FILES += mlock2-tests 63TEST_GEN_FILES += mrelease_test 64TEST_GEN_FILES += mremap_dontunmap 65TEST_GEN_FILES += mremap_test 66TEST_GEN_FILES += mseal_test 67TEST_GEN_FILES += seal_elf 68TEST_GEN_FILES += on-fault-limit 69TEST_GEN_FILES += pagemap_ioctl 70TEST_GEN_FILES += thuge-gen 71TEST_GEN_FILES += transhuge-stress 72TEST_GEN_FILES += uffd-stress 73TEST_GEN_FILES += uffd-unit-tests 74TEST_GEN_FILES += split_huge_page_test 75TEST_GEN_FILES += ksm_tests 76TEST_GEN_FILES += ksm_functional_tests 77TEST_GEN_FILES += mdwe_test 78TEST_GEN_FILES += hugetlb_fault_after_madv 79TEST_GEN_FILES += hugetlb_madv_vs_map 80TEST_GEN_FILES += hugetlb_dio 81TEST_GEN_FILES += droppable 82 83ifneq ($(ARCH),arm64) 84TEST_GEN_FILES += soft-dirty 85endif 86 87ifeq ($(ARCH),x86_64) 88CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32) 89CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c) 90CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie) 91 92VMTARGETS := protection_keys 93VMTARGETS += pkey_sighandler_tests 94BINARIES_32 := $(VMTARGETS:%=%_32) 95BINARIES_64 := $(VMTARGETS:%=%_64) 96 97ifeq ($(CAN_BUILD_WITH_NOPIE),1) 98CFLAGS += -no-pie 99endif 100 101ifeq ($(CAN_BUILD_I386),1) 102TEST_GEN_FILES += $(BINARIES_32) 103endif 104 105ifeq ($(CAN_BUILD_X86_64),1) 106TEST_GEN_FILES += $(BINARIES_64) 107endif 108else 109 110ifneq (,$(filter $(ARCH),arm64 powerpc)) 111TEST_GEN_FILES += protection_keys 112endif 113 114endif 115 116ifneq (,$(filter $(ARCH),arm64 mips64 parisc64 powerpc riscv64 s390x sparc64 x86_64 s390)) 117TEST_GEN_FILES += va_high_addr_switch 118TEST_GEN_FILES += virtual_address_range 119TEST_GEN_FILES += write_to_hugetlbfs 120endif 121 122TEST_PROGS := run_vmtests.sh 123 124TEST_FILES := test_vmalloc.sh 125TEST_FILES += test_hmm.sh 126TEST_FILES += va_high_addr_switch.sh 127TEST_FILES += charge_reserved_hugetlb.sh 128TEST_FILES += hugetlb_reparenting_test.sh 129 130# required by charge_reserved_hugetlb.sh 131TEST_FILES += write_hugetlb_memory.sh 132 133include ../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 141ifeq ($(ARCH),x86_64) 142BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) 143BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) 144 145define gen-target-rule-32 146$(1) $(1)_32: $(OUTPUT)/$(1)_32 147.PHONY: $(1) $(1)_32 148endef 149 150define gen-target-rule-64 151$(1) $(1)_64: $(OUTPUT)/$(1)_64 152.PHONY: $(1) $(1)_64 153endef 154 155ifeq ($(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)))) 161endif 162 163ifeq ($(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)))) 169endif 170 171# x86_64 users should be encouraged to install 32-bit libraries 172ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) 173all: warn_32bit_failure 174 175warn_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; 187endif 188endif 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 201local_config.mk local_config.h: check_config.sh 202 /bin/sh ./check_config.sh $(CC) 203 204EXTRA_CLEAN += local_config.mk local_config.h 205 206ifeq ($(IOURING_EXTRA_LIBS),) 207all: warn_missing_liburing 208 209warn_missing_liburing: 210 @echo ; \ 211 echo "Warning: missing liburing support. Some tests will be skipped." ; \ 212 echo 213endif 214