• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2# Makefile for vm selftests
3
4LOCAL_HDRS += $(selfdir)/vm/local_config.h $(top_srcdir)/mm/gup_test.h
5
6include local_config.mk
7
8uname_M := $(shell uname -m 2>/dev/null || echo not)
9MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/ppc64/')
10
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
13# make invocations:
14.DELETE_ON_ERROR:
15
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.
18#
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
25# LDLIBS.
26MAKEFLAGS += --no-builtin-rules
27
28CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS)
29LDLIBS = -lrt -lpthread
30TEST_GEN_FILES = compaction_test
31TEST_GEN_FILES += gup_test
32TEST_GEN_FILES += hmm-tests
33TEST_GEN_FILES += hugepage-mmap
34TEST_GEN_FILES += hugepage-shm
35TEST_GEN_FILES += khugepaged
36TEST_GEN_FILES += madv_populate
37TEST_GEN_FILES += map_fixed_noreplace
38TEST_GEN_FILES += map_hugetlb
39TEST_GEN_FILES += map_populate
40TEST_GEN_FILES += memfd_secret
41TEST_GEN_FILES += mlock-random-test
42TEST_GEN_FILES += mlock2-tests
43TEST_GEN_FILES += mremap_dontunmap
44TEST_GEN_FILES += mremap_test
45TEST_GEN_FILES += on-fault-limit
46TEST_GEN_FILES += thuge-gen
47TEST_GEN_FILES += transhuge-stress
48TEST_GEN_FILES += userfaultfd
49TEST_GEN_FILES += split_huge_page_test
50TEST_GEN_FILES += ksm_tests
51
52ifeq ($(MACHINE),x86_64)
53CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32)
54CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c)
55CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
56
57VMTARGETS := protection_keys
58BINARIES_32 := $(VMTARGETS:%=%_32)
59BINARIES_64 := $(VMTARGETS:%=%_64)
60
61ifeq ($(CAN_BUILD_WITH_NOPIE),1)
62CFLAGS += -no-pie
63endif
64
65ifeq ($(CAN_BUILD_I386),1)
66TEST_GEN_FILES += $(BINARIES_32)
67endif
68
69ifeq ($(CAN_BUILD_X86_64),1)
70TEST_GEN_FILES += $(BINARIES_64)
71endif
72else
73
74ifneq (,$(findstring $(MACHINE),ppc64))
75TEST_GEN_FILES += protection_keys
76endif
77
78endif
79
80ifneq (,$(filter $(MACHINE),arm64 ia64 mips64 parisc64 ppc64 riscv64 s390x sh64 sparc64 x86_64))
81TEST_GEN_FILES += va_128TBswitch
82TEST_GEN_FILES += virtual_address_range
83TEST_GEN_FILES += write_to_hugetlbfs
84endif
85
86TEST_PROGS := run_vmtests.sh
87
88TEST_FILES := test_vmalloc.sh
89
90KSFT_KHDR_INSTALL := 1
91include ../lib.mk
92
93ifeq ($(MACHINE),x86_64)
94BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
95BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
96
97define gen-target-rule-32
98$(1) $(1)_32: $(OUTPUT)/$(1)_32
99.PHONY: $(1) $(1)_32
100endef
101
102define gen-target-rule-64
103$(1) $(1)_64: $(OUTPUT)/$(1)_64
104.PHONY: $(1) $(1)_64
105endef
106
107ifeq ($(CAN_BUILD_I386),1)
108$(BINARIES_32): CFLAGS += -m32 -mxsave
109$(BINARIES_32): LDLIBS += -lrt -ldl -lm
110$(BINARIES_32): $(OUTPUT)/%_32: %.c
111	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
112$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t))))
113endif
114
115ifeq ($(CAN_BUILD_X86_64),1)
116$(BINARIES_64): CFLAGS += -m64 -mxsave
117$(BINARIES_64): LDLIBS += -lrt -ldl
118$(BINARIES_64): $(OUTPUT)/%_64: %.c
119	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
120$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t))))
121endif
122
123# x86_64 users should be encouraged to install 32-bit libraries
124ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
125all: warn_32bit_failure
126
127warn_32bit_failure:
128	@echo "Warning: you seem to have a broken 32-bit build" 2>&1;		\
129	echo  "environment. This will reduce test coverage of 64-bit" 2>&1;	\
130	echo  "kernels. If you are using a Debian-like distribution," 2>&1;	\
131	echo  "try:"; 2>&1;							\
132	echo  "";								\
133	echo  "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386";	\
134	echo  "";								\
135	echo  "If you are using a Fedora-like distribution, try:";		\
136	echo  "";								\
137	echo  "  yum install glibc-devel.*i686";				\
138	exit 0;
139endif
140endif
141
142$(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap
143
144# HMM_EXTRA_LIBS may get set in local_config.mk, or it may be left empty.
145$(OUTPUT)/hmm-tests: LDLIBS += $(HMM_EXTRA_LIBS)
146
147$(OUTPUT)/ksm_tests: LDLIBS += -lnuma
148
149local_config.mk local_config.h: check_config.sh
150	/bin/sh ./check_config.sh $(CC)
151
152EXTRA_CLEAN += local_config.mk local_config.h
153
154ifeq ($(HMM_EXTRA_LIBS),)
155all: warn_missing_hugelibs
156
157warn_missing_hugelibs:
158	@echo ; \
159	echo "Warning: missing libhugetlbfs support. Some HMM tests will be skipped." ; \
160	echo
161endif
162