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 56TEST_GEN_FILES += memfd_secret 57TEST_GEN_FILES += migration 58TEST_GEN_FILES += mkdirty 59TEST_GEN_FILES += mlock-random-test 60TEST_GEN_FILES += mlock2-tests 61TEST_GEN_FILES += mrelease_test 62TEST_GEN_FILES += mremap_dontunmap 63TEST_GEN_FILES += mremap_test 64TEST_GEN_FILES += mseal_test 65TEST_GEN_FILES += seal_elf 66TEST_GEN_FILES += on-fault-limit 67TEST_GEN_FILES += pagemap_ioctl 68TEST_GEN_FILES += thuge-gen 69TEST_GEN_FILES += transhuge-stress 70TEST_GEN_FILES += uffd-stress 71TEST_GEN_FILES += uffd-unit-tests 72TEST_GEN_FILES += split_huge_page_test 73TEST_GEN_FILES += ksm_tests 74TEST_GEN_FILES += ksm_functional_tests 75TEST_GEN_FILES += mdwe_test 76TEST_GEN_FILES += hugetlb_fault_after_madv 77TEST_GEN_FILES += hugetlb_madv_vs_map 78TEST_GEN_FILES += hugetlb_dio 79TEST_GEN_FILES += droppable 80 81ifneq ($(ARCH),arm64) 82TEST_GEN_FILES += soft-dirty 83endif 84 85ifeq ($(ARCH),x86_64) 86CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32) 87CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c) 88CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie) 89 90VMTARGETS := protection_keys 91BINARIES_32 := $(VMTARGETS:%=%_32) 92BINARIES_64 := $(VMTARGETS:%=%_64) 93 94ifeq ($(CAN_BUILD_WITH_NOPIE),1) 95CFLAGS += -no-pie 96endif 97 98ifeq ($(CAN_BUILD_I386),1) 99TEST_GEN_FILES += $(BINARIES_32) 100endif 101 102ifeq ($(CAN_BUILD_X86_64),1) 103TEST_GEN_FILES += $(BINARIES_64) 104endif 105else 106 107ifneq (,$(findstring $(ARCH),powerpc)) 108TEST_GEN_FILES += protection_keys 109endif 110 111endif 112 113ifneq (,$(filter $(ARCH),arm64 ia64 mips64 parisc64 powerpc riscv64 s390x sparc64 x86_64)) 114TEST_GEN_FILES += va_high_addr_switch 115TEST_GEN_FILES += virtual_address_range 116TEST_GEN_FILES += write_to_hugetlbfs 117endif 118 119TEST_PROGS := run_vmtests.sh 120 121TEST_FILES := test_vmalloc.sh 122TEST_FILES += test_hmm.sh 123TEST_FILES += va_high_addr_switch.sh 124TEST_FILES += charge_reserved_hugetlb.sh 125TEST_FILES += hugetlb_reparenting_test.sh 126 127# required by charge_reserved_hugetlb.sh 128TEST_FILES += write_hugetlb_memory.sh 129 130include ../lib.mk 131 132$(TEST_GEN_PROGS): vm_util.c thp_settings.c 133$(TEST_GEN_FILES): vm_util.c thp_settings.c 134 135$(OUTPUT)/uffd-stress: uffd-common.c 136$(OUTPUT)/uffd-unit-tests: uffd-common.c 137 138ifeq ($(ARCH),x86_64) 139BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) 140BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) 141 142define gen-target-rule-32 143$(1) $(1)_32: $(OUTPUT)/$(1)_32 144.PHONY: $(1) $(1)_32 145endef 146 147define gen-target-rule-64 148$(1) $(1)_64: $(OUTPUT)/$(1)_64 149.PHONY: $(1) $(1)_64 150endef 151 152ifeq ($(CAN_BUILD_I386),1) 153$(BINARIES_32): CFLAGS += -m32 -mxsave 154$(BINARIES_32): LDLIBS += -lrt -ldl -lm 155$(BINARIES_32): $(OUTPUT)/%_32: %.c 156 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 157$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t)))) 158endif 159 160ifeq ($(CAN_BUILD_X86_64),1) 161$(BINARIES_64): CFLAGS += -m64 -mxsave 162$(BINARIES_64): LDLIBS += -lrt -ldl 163$(BINARIES_64): $(OUTPUT)/%_64: %.c 164 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 165$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t)))) 166endif 167 168# x86_64 users should be encouraged to install 32-bit libraries 169ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) 170all: warn_32bit_failure 171 172warn_32bit_failure: 173 @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ 174 echo "environment. This will reduce test coverage of 64-bit" 2>&1; \ 175 echo "kernels. If you are using a Debian-like distribution," 2>&1; \ 176 echo "try:"; 2>&1; \ 177 echo ""; \ 178 echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ 179 echo ""; \ 180 echo "If you are using a Fedora-like distribution, try:"; \ 181 echo ""; \ 182 echo " yum install glibc-devel.*i686"; \ 183 exit 0; 184endif 185endif 186 187# IOURING_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. 188$(OUTPUT)/cow: LDLIBS += $(IOURING_EXTRA_LIBS) 189 190$(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS) 191 192$(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap 193 194$(OUTPUT)/ksm_tests: LDLIBS += -lnuma 195 196$(OUTPUT)/migration: LDLIBS += -lnuma 197 198local_config.mk local_config.h: check_config.sh 199 /bin/sh ./check_config.sh $(CC) 200 201EXTRA_CLEAN += local_config.mk local_config.h 202 203ifeq ($(IOURING_EXTRA_LIBS),) 204all: warn_missing_liburing 205 206warn_missing_liburing: 207 @echo ; \ 208 echo "Warning: missing liburing support. Some tests will be skipped." ; \ 209 echo 210endif 211