When running selftests from the kernel top-level (e.g. make kselftest-all), sub-makes might still inherit the caller's PWD from the environment. Some selftests use $(PWD) in recursive kbuild invocations, which can then incorrectly resolve to the kernel top directory instead of the current test directory. In that case, kbuild may generate an external-module wrapper Makefile in the wrong location, potentially clobbering the top-level Makefile and causing recursive include failures ("Too many open files"). Export PWD := $(CURDIR) in selftests/lib.mk so $(PWD) always matches the actual current selftest directory. Reported-by: Andrew Morton Signed-off-by: Li Wang --- tools/testing/selftests/lib.mk | 2 ++ tools/testing/selftests/mm/local_config.stamp | 0 2 files changed, 2 insertions(+) create mode 100644 tools/testing/selftests/mm/local_config.stamp diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index f02cc8a2e4ae..2840e98c225c 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -60,6 +60,8 @@ endif selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) top_srcdir = $(selfdir)/../../.. +export PWD := $(CURDIR) + # msg: emit succinct information message describing current building step # $1 - generic step name (e.g., CC, LINK, etc); # $2 - optional "flavor" specifier; if provided, will be emitted as [flavor]; diff --git a/tools/testing/selftests/mm/local_config.stamp b/tools/testing/selftests/mm/local_config.stamp new file mode 100644 index 000000000000..e69de29bb2d1 -- 2.53.0