18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci# Makefile for vm selftests 38c2ecf20Sopenharmony_ciuname_M := $(shell uname -m 2>/dev/null || echo not) 48c2ecf20Sopenharmony_ciMACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/ppc64/') 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci# Without this, failed build products remain, with up-to-date timestamps, 78c2ecf20Sopenharmony_ci# thus tricking Make (and you!) into believing that All Is Well, in subsequent 88c2ecf20Sopenharmony_ci# make invocations: 98c2ecf20Sopenharmony_ci.DELETE_ON_ERROR: 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci# Avoid accidental wrong builds, due to built-in rules working just a little 128c2ecf20Sopenharmony_ci# bit too well--but not quite as well as required for our situation here. 138c2ecf20Sopenharmony_ci# 148c2ecf20Sopenharmony_ci# In other words, "make userfaultfd" is supposed to fail to build at all, 158c2ecf20Sopenharmony_ci# because this Makefile only supports either "make" (all), or "make /full/path". 168c2ecf20Sopenharmony_ci# However, the built-in rules, if not suppressed, will pick up CFLAGS and the 178c2ecf20Sopenharmony_ci# initial LDLIBS (but not the target-specific LDLIBS, because those are only 188c2ecf20Sopenharmony_ci# set for the full path target!). This causes it to get pretty far into building 198c2ecf20Sopenharmony_ci# things despite using incorrect values such as an *occasionally* incomplete 208c2ecf20Sopenharmony_ci# LDLIBS. 218c2ecf20Sopenharmony_ciMAKEFLAGS += --no-builtin-rules 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciCFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) 248c2ecf20Sopenharmony_ciLDLIBS = -lrt 258c2ecf20Sopenharmony_ciTEST_GEN_FILES = compaction_test 268c2ecf20Sopenharmony_ciTEST_GEN_FILES += gup_benchmark 278c2ecf20Sopenharmony_ciTEST_GEN_FILES += hmm-tests 288c2ecf20Sopenharmony_ciTEST_GEN_FILES += hugepage-mmap 298c2ecf20Sopenharmony_ciTEST_GEN_FILES += hugepage-shm 308c2ecf20Sopenharmony_ciTEST_GEN_FILES += map_hugetlb 318c2ecf20Sopenharmony_ciTEST_GEN_FILES += map_fixed_noreplace 328c2ecf20Sopenharmony_ciTEST_GEN_FILES += map_populate 338c2ecf20Sopenharmony_ciTEST_GEN_FILES += mlock-random-test 348c2ecf20Sopenharmony_ciTEST_GEN_FILES += mlock2-tests 358c2ecf20Sopenharmony_ciTEST_GEN_FILES += mremap_dontunmap 368c2ecf20Sopenharmony_ciTEST_GEN_FILES += on-fault-limit 378c2ecf20Sopenharmony_ciTEST_GEN_FILES += thuge-gen 388c2ecf20Sopenharmony_ciTEST_GEN_FILES += transhuge-stress 398c2ecf20Sopenharmony_ciTEST_GEN_FILES += userfaultfd 408c2ecf20Sopenharmony_ciTEST_GEN_FILES += khugepaged 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciifeq ($(MACHINE),x86_64) 438c2ecf20Sopenharmony_ciCAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32) 448c2ecf20Sopenharmony_ciCAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c) 458c2ecf20Sopenharmony_ciCAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciVMTARGETS := protection_keys 488c2ecf20Sopenharmony_ciBINARIES_32 := $(VMTARGETS:%=%_32) 498c2ecf20Sopenharmony_ciBINARIES_64 := $(VMTARGETS:%=%_64) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_WITH_NOPIE),1) 528c2ecf20Sopenharmony_ciCFLAGS += -no-pie 538c2ecf20Sopenharmony_ciendif 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_I386),1) 568c2ecf20Sopenharmony_ciTEST_GEN_FILES += $(BINARIES_32) 578c2ecf20Sopenharmony_ciendif 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_X86_64),1) 608c2ecf20Sopenharmony_ciTEST_GEN_FILES += $(BINARIES_64) 618c2ecf20Sopenharmony_ciendif 628c2ecf20Sopenharmony_cielse 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciifneq (,$(findstring $(MACHINE),ppc64)) 658c2ecf20Sopenharmony_ciTEST_GEN_FILES += protection_keys 668c2ecf20Sopenharmony_ciendif 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciendif 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ciifneq (,$(filter $(MACHINE),arm64 ia64 mips64 parisc64 ppc64 riscv64 s390x sh64 sparc64 x86_64)) 718c2ecf20Sopenharmony_ciTEST_GEN_FILES += va_128TBswitch 728c2ecf20Sopenharmony_ciTEST_GEN_FILES += virtual_address_range 738c2ecf20Sopenharmony_ciTEST_GEN_FILES += write_to_hugetlbfs 748c2ecf20Sopenharmony_ciendif 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ciTEST_PROGS := run_vmtests 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciTEST_FILES := test_vmalloc.sh 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciKSFT_KHDR_INSTALL := 1 818c2ecf20Sopenharmony_ciinclude ../lib.mk 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci$(OUTPUT)/hmm-tests: LDLIBS += -lhugetlbfs -lpthread 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciifeq ($(MACHINE),x86_64) 868c2ecf20Sopenharmony_ciBINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) 878c2ecf20Sopenharmony_ciBINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cidefine gen-target-rule-32 908c2ecf20Sopenharmony_ci$(1) $(1)_32: $(OUTPUT)/$(1)_32 918c2ecf20Sopenharmony_ci.PHONY: $(1) $(1)_32 928c2ecf20Sopenharmony_ciendef 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_cidefine gen-target-rule-64 958c2ecf20Sopenharmony_ci$(1) $(1)_64: $(OUTPUT)/$(1)_64 968c2ecf20Sopenharmony_ci.PHONY: $(1) $(1)_64 978c2ecf20Sopenharmony_ciendef 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_I386),1) 1008c2ecf20Sopenharmony_ci$(BINARIES_32): CFLAGS += -m32 1018c2ecf20Sopenharmony_ci$(BINARIES_32): LDLIBS += -lrt -ldl -lm 1028c2ecf20Sopenharmony_ci$(BINARIES_32): $(OUTPUT)/%_32: %.c 1038c2ecf20Sopenharmony_ci $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 1048c2ecf20Sopenharmony_ci$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t)))) 1058c2ecf20Sopenharmony_ciendif 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_X86_64),1) 1088c2ecf20Sopenharmony_ci$(BINARIES_64): CFLAGS += -m64 1098c2ecf20Sopenharmony_ci$(BINARIES_64): LDLIBS += -lrt -ldl 1108c2ecf20Sopenharmony_ci$(BINARIES_64): $(OUTPUT)/%_64: %.c 1118c2ecf20Sopenharmony_ci $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 1128c2ecf20Sopenharmony_ci$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t)))) 1138c2ecf20Sopenharmony_ciendif 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci# x86_64 users should be encouraged to install 32-bit libraries 1168c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) 1178c2ecf20Sopenharmony_ciall: warn_32bit_failure 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciwarn_32bit_failure: 1208c2ecf20Sopenharmony_ci @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ 1218c2ecf20Sopenharmony_ci echo "environment. This will reduce test coverage of 64-bit" 2>&1; \ 1228c2ecf20Sopenharmony_ci echo "kernels. If you are using a Debian-like distribution," 2>&1; \ 1238c2ecf20Sopenharmony_ci echo "try:"; 2>&1; \ 1248c2ecf20Sopenharmony_ci echo ""; \ 1258c2ecf20Sopenharmony_ci echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ 1268c2ecf20Sopenharmony_ci echo ""; \ 1278c2ecf20Sopenharmony_ci echo "If you are using a Fedora-like distribution, try:"; \ 1288c2ecf20Sopenharmony_ci echo ""; \ 1298c2ecf20Sopenharmony_ci echo " yum install glibc-devel.*i686"; \ 1308c2ecf20Sopenharmony_ci exit 0; 1318c2ecf20Sopenharmony_ciendif 1328c2ecf20Sopenharmony_ciendif 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci$(OUTPUT)/userfaultfd: LDLIBS += -lpthread 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci$(OUTPUT)/mlock-random-test: LDLIBS += -lcap 137