1 # SPDX-License-Identifier: GPL-2.0
2 # Makefile for vm selftests
4 LOCAL_HDRS += $(selfdir)/vm/local_config.h $(top_srcdir)/mm/gup_test.h
6 include local_config.mk
8 uname_M := $(shell uname -m 2>/dev/null || echo not)
9 MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/ppc64/')
11 # Without this, failed build products remain, with up-to-date timestamps,
12 # thus tricking Make (and you!) into believing that All Is Well, in subsequent
16 # Avoid accidental wrong builds, due to built-in rules working just a little
17 # bit too well--but not quite as well as required for our situation here.
19 # In other words, "make userfaultfd" is supposed to fail to build at all,
20 # because this Makefile only supports either "make" (all), or "make /full/path".
21 # However, the built-in rules, if not suppressed, will pick up CFLAGS and the
22 # initial LDLIBS (but not the target-specific LDLIBS, because those are only
23 # set for the full path target!). This causes it to get pretty far into building
24 # things despite using incorrect values such as an *occasionally* incomplete
26 MAKEFLAGS += --no-builtin-rules
28 CFLAGS = -Wall -I $(top_srcdir) -I $(top_srcdir)/usr/include $(EXTRA_CFLAGS) $(KHDR_INCLUDES)
29 LDLIBS = -lrt -lpthread
30 TEST_GEN_FILES = compaction_test
31 TEST_GEN_FILES += gup_test
32 TEST_GEN_FILES += hmm-tests
33 TEST_GEN_FILES += hugetlb-madvise
34 TEST_GEN_FILES += hugepage-mmap
35 TEST_GEN_FILES += hugepage-mremap
36 TEST_GEN_FILES += hugepage-shm
37 TEST_GEN_FILES += hugepage-vmemmap
38 TEST_GEN_FILES += khugepaged
39 TEST_GEN_PROGS = madv_populate
40 TEST_GEN_FILES += map_fixed_noreplace
41 TEST_GEN_FILES += map_hugetlb
42 TEST_GEN_FILES += map_populate
43 TEST_GEN_FILES += memfd_secret
44 TEST_GEN_FILES += migration
45 TEST_GEN_FILES += mlock-random-test
46 TEST_GEN_FILES += mlock2-tests
47 TEST_GEN_FILES += mrelease_test
48 TEST_GEN_FILES += mremap_dontunmap
49 TEST_GEN_FILES += mremap_test
50 TEST_GEN_FILES += on-fault-limit
51 TEST_GEN_FILES += thuge-gen
52 TEST_GEN_FILES += transhuge-stress
53 TEST_GEN_FILES += userfaultfd
54 TEST_GEN_PROGS += soft-dirty
55 TEST_GEN_PROGS += split_huge_page_test
56 TEST_GEN_FILES += ksm_tests
58 ifeq ($(MACHINE),x86_64)
59 CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32)
60 CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c)
61 CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
63 VMTARGETS := protection_keys
64 BINARIES_32 := $(VMTARGETS:%=%_32)
65 BINARIES_64 := $(VMTARGETS:%=%_64)
67 ifeq ($(CAN_BUILD_WITH_NOPIE),1)
71 ifeq ($(CAN_BUILD_I386),1)
72 TEST_GEN_FILES += $(BINARIES_32)
75 ifeq ($(CAN_BUILD_X86_64),1)
76 TEST_GEN_FILES += $(BINARIES_64)
80 ifneq (,$(findstring $(MACHINE),ppc64))
81 TEST_GEN_FILES += protection_keys
86 ifneq (,$(filter $(MACHINE),arm64 ia64 mips64 parisc64 ppc64 riscv64 s390x sh64 sparc64 x86_64))
87 TEST_GEN_FILES += va_128TBswitch
88 TEST_GEN_FILES += virtual_address_range
89 TEST_GEN_FILES += write_to_hugetlbfs
92 TEST_PROGS := run_vmtests.sh
94 TEST_FILES := test_vmalloc.sh
95 TEST_FILES += test_hmm.sh
96 TEST_FILES += va_128TBswitch.sh
100 $(OUTPUT)/madv_populate: vm_util.c
101 $(OUTPUT)/soft-dirty: vm_util.c
102 $(OUTPUT)/split_huge_page_test: vm_util.c
104 ifeq ($(MACHINE),x86_64)
105 BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
106 BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
108 define gen-target-rule-32
109 $(1) $(1)_32: $(OUTPUT)/$(1)_32
113 define gen-target-rule-64
114 $(1) $(1)_64: $(OUTPUT)/$(1)_64
118 ifeq ($(CAN_BUILD_I386),1)
119 $(BINARIES_32): CFLAGS += -m32 -mxsave
120 $(BINARIES_32): LDLIBS += -lrt -ldl -lm
121 $(BINARIES_32): $(OUTPUT)/%_32: %.c
122 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
123 $(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t))))
126 ifeq ($(CAN_BUILD_X86_64),1)
127 $(BINARIES_64): CFLAGS += -m64 -mxsave
128 $(BINARIES_64): LDLIBS += -lrt -ldl
129 $(BINARIES_64): $(OUTPUT)/%_64: %.c
130 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
131 $(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t))))
134 # x86_64 users should be encouraged to install 32-bit libraries
135 ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
136 all: warn_32bit_failure
139 @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \
140 echo "environment. This will reduce test coverage of 64-bit" 2>&1; \
141 echo "kernels. If you are using a Debian-like distribution," 2>&1; \
144 echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
146 echo "If you are using a Fedora-like distribution, try:"; \
148 echo " yum install glibc-devel.*i686"; \
153 $(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap
155 # HMM_EXTRA_LIBS may get set in local_config.mk, or it may be left empty.
156 $(OUTPUT)/hmm-tests: LDLIBS += $(HMM_EXTRA_LIBS)
158 $(OUTPUT)/ksm_tests: LDLIBS += -lnuma
160 $(OUTPUT)/migration: LDLIBS += -lnuma
162 local_config.mk local_config.h: check_config.sh
163 /bin/sh ./check_config.sh $(CC)
165 EXTRA_CLEAN += local_config.mk local_config.h
167 ifeq ($(HMM_EXTRA_LIBS),)
168 all: warn_missing_hugelibs
170 warn_missing_hugelibs:
172 echo "Warning: missing libhugetlbfs support. Some HMM tests will be skipped." ; \