* [Devel] [PATCH vz10 v2] selftests: build test modules against the kernel tree
@ 2026-08-12 9:49 Eva Kurchatova
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 0/2] selftests: build test modules for the packaged kernel Konstantin Khorenko
0 siblings, 1 reply; 6+ messages in thread
From: Eva Kurchatova @ 2026-08-12 9:49 UTC (permalink / raw)
Selftests livepatch, cgroup and mm/page_frag build out-of-tree kernel
modules and default KDIR to /lib/modules/$(uname -r)/build, which is
the running kernel build tree on the currently building host.
That is wrong whenever the selftests are built as part of a kernel
package: `uname -r` is not the kernel being packaged, so the modules
either are not built at all (no source tree for the builders kernel)
or come out with the wrong vermagic and symbol layout.
Either way no usable test modules end up in the packaged test suite,
and a testing host may not have the kernel build tree to compile them
either, so the tests will fail.
Default KDIR to the kernel tree the tests are built from, or to its O=
build directory, whenever that tree is configured and built.
This is exactly what bpf/test_kmods has been already doing all along,
and its modules are built and packaged that way today. Pick the build
directory up from O= or KBUILD_OUTPUT, and resolve a relative one
against the source tree, the way kbuild resolves it as well.
Testing for include/config/auto.conf and Module.symvers keeps the previous
behaviour for a bare source checkout, and for a source tree that was
mrpropered after the kernel had been built (packaging copies
Module.symvers back into such a tree), so nothing that builds today
starts failing.
Also test for $(KDIR)/Makefile rather than for $(KDIR) itself before
descending into the kernel tree: /lib/modules/$(uname -r)/build is
commonly a dangling symlink, which the previous test accepted before
failing in make -C. The same protection is applied to bpf/test_kmods
and mm/page_frag, which had no such check at all.
Give bpf/test_kmods the same treatment while at it, so that every
in-tree test module picks KDIR the same way: it hardcoded the source
tree with no regard for O=, and failed outright instead of falling
back when that tree was not configured.
In an O= build KDIR is the build directory, which carries the generated
configuration but not the source headers. mm/Makefile decides whether
to build page_frag_test.ko by looking for include/linux/page_frag_cache.h
below KDIR, so look for that header through the "source" symlink that
outputmakefile leaves in the build directory as well, otherwise an O=
build skips the module and blames a too old kernel for it. Split
kernel-devel packages that keep sources and build artifacts apart carry
the same symlink.
With this, `make kselftest TARGETS=livepatch` in a built kernel tree
builds the modules for that kernel and `make install` ships them, so an
installed testsuite runs against pre-built modules and needs no kernel
build tree at all.
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
https://virtuozzo.atlassian.net/browse/VSTOR-139647
Feature: fix selftests
---
Changes since v1:
- Look for page_frag_cache.h through the "source" symlink as well.
v1 tested $(KDIR)/include/linux/page_frag_cache.h only, but in an O=
build KDIR is the build directory, which carries the generated
configuration and no source headers at all.
mm/Makefile therefore left TEST_GEN_MODS_DIR unset, lib.mk never
descended into page_frag/, page_frag_test.ko was neither built nor
installed, and the build blamed a too old kernel for it.
Before v1 that case built the module against
/lib/modules/$(uname -r)/build, where the header is present, so v1
did regress it.
- Resolve a relative O= against the source tree.
v1 fed O= to $(abspath ...), which resolves against the directory of
the Makefile being read, so make -C <suite> O=../../../../out placed
the build directory several levels off and silently fell back to
/lib/modules/$(uname -r)/build. Going through the top level
selftests Makefile was unaffected, it hands an absolute path down.
- Honour KBUILD_OUTPUT, not only O=, since kbuild treats the two the
same and a suite Makefile invoked directly never sees the O= that
the top level selftests Makefile derives from it.
- Apply the same KDIR selection and the $(KDIR)/Makefile test to
bpf/test_kmods, so that all in-tree test modules pick their kernel
build tree the same way. It hardcoded the source tree, ignoring O=,
and failed the build instead of falling back when that tree was not
configured.
- Derive the source tree in mm/Makefile from MAKEFILE_LIST rather than
from $(CURDIR), to match the other four Makefiles and to not depend
on make having been entered with -C.
.../testing/selftests/bpf/test_kmods/Makefile | 30 ++++++++++++++++-
.../selftests/cgroup/test_modules/Makefile | 33 ++++++++++++++++---
.../selftests/livepatch/test_modules/Makefile | 33 ++++++++++++++++---
tools/testing/selftests/mm/Makefile | 33 ++++++++++++++++++-
tools/testing/selftests/mm/page_frag/Makefile | 30 +++++++++++++++++
5 files changed, 149 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_kmods/Makefile b/tools/testing/selftests/bpf/test_kmods/Makefile
index d4e50c4509c9..2353140505d6 100644
--- a/tools/testing/selftests/bpf/test_kmods/Makefile
+++ b/tools/testing/selftests/bpf/test_kmods/Makefile
@@ -1,5 +1,25 @@
TEST_KMOD_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
-KDIR ?= $(abspath $(TEST_KMOD_DIR)/../../../../..)
+
+# Kernel build tree to compile the test modules against. This already
+# defaulted to the kernel tree these tests are part of; also honour its
+# O= or KBUILD_OUTPUT build directory, and fall back to the running
+# kernel's build tree when the tree is not configured and built, so that
+# all in-tree test modules pick KDIR the same way.
+KSRC_TREE := $(abspath $(TEST_KMOD_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
+KDIR ?= /lib/modules/$(shell uname -r)/build
ifeq ($(V),1)
Q =
@@ -14,8 +34,16 @@ $(foreach m,$(MODULES),$(eval obj-m += $(m:.ko=.o)))
CFLAGS_bpf_testmod.o = -I$(src)
+# Ensure that KDIR is a kernel build tree, otherwise skip the compilation.
+# Testing for the Makefile rather than for the directory itself also covers
+# a dangling /lib/modules/$(uname -r)/build symlink.
all:
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
$(Q)$(MAKE) -C $(KDIR) M=$(TEST_KMOD_DIR) modules
+endif
+# Ensure that KDIR is a kernel build tree, otherwise skip the clean target
clean:
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
$(Q)$(MAKE) -C $(KDIR) M=$(TEST_KMOD_DIR) clean
+endif
diff --git a/tools/testing/selftests/cgroup/test_modules/Makefile b/tools/testing/selftests/cgroup/test_modules/Makefile
index 3f39eeda3a92..1dc531589b15 100644
--- a/tools/testing/selftests/cgroup/test_modules/Makefile
+++ b/tools/testing/selftests/cgroup/test_modules/Makefile
@@ -1,17 +1,42 @@
TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Kernel build tree to compile the test modules against. Prefer the
+# kernel tree these tests are part of (or its O= build directory) when it
+# is configured and built, like bpf/test_kmods already does: When the
+# selftests are built as part of a kernel package, uname -r is the build
+# host's kernel and not the kernel being packaged, so the resulting
+# modules would carry the wrong vermagic and symbol layout. Fall back to
+# the running kernel's build tree for standalone builds.
+KSRC_TREE := $(abspath $(TESTMODS_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += cg_freezer_hang.o \
cg_freezer_kthread.o
-# Ensure that KDIR exists, otherwise skip the compilation
+# Ensure that KDIR is a kernel build tree, otherwise skip the compilation.
+# Testing for the Makefile rather than for the directory itself also covers
+# a dangling /lib/modules/$(uname -r)/build symlink, and an installed
+# testsuite, which ships pre-built modules and has no kernel tree above it.
modules:
-ifneq ("$(wildcard $(KDIR))", "")
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
-# Ensure that KDIR exists, otherwise skip the clean target
+# Ensure that KDIR is a kernel build tree, otherwise skip the clean target
clean:
-ifneq ("$(wildcard $(KDIR))", "")
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
$(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index 939230e571f5..66dcbd842f71 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -1,4 +1,26 @@
TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Kernel build tree to compile the test modules against. Prefer the
+# kernel tree these tests are part of (or its O= build directory) when it
+# is configured and built, like bpf/test_kmods already does: when the
+# selftests are built as part of a kernel package, uname -r is the build
+# host's kernel and not the kernel being packaged, so the resulting
+# modules would carry the wrong vermagic and symbol CRCs. Fall back to
+# the running kernel's build tree for standalone builds.
+KSRC_TREE := $(abspath $(TESTMODS_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += test_klp_atomic_replace.o \
@@ -14,14 +36,17 @@ obj-m += test_klp_atomic_replace.o \
test_klp_state3.o \
test_klp_syscall.o
-# Ensure that KDIR exists, otherwise skip the compilation
+# Ensure that KDIR is a kernel build tree, otherwise skip the compilation.
+# Testing for the Makefile rather than for the directory itself also covers
+# a dangling /lib/modules/$(uname -r)/build symlink, and an installed
+# testsuite, which ships pre-built modules and has no kernel tree above it.
modules:
-ifneq ("$(wildcard $(KDIR))", "")
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
-# Ensure that KDIR exists, otherwise skip the clean target
+# Ensure that KDIR is a kernel build tree, otherwise skip the clean target
clean:
-ifneq ("$(wildcard $(KDIR))", "")
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
$(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index 3de23ea4663f..1d6bb5cf9e08 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -36,9 +36,40 @@ MAKEFLAGS += --no-builtin-rules
CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
LDLIBS = -lrt -lpthread -lm
+# Kernel build tree to compile page_frag_test.ko against. Prefer the
+# kernel tree these tests are part of (or its O= build directory) when it
+# is configured and built, like bpf/test_kmods already does: when the
+# selftests are built as part of a kernel package, uname -r is the build
+# host's kernel and not the kernel being packaged, so the resulting module
+# would carry the wrong vermagic and symbol CRCs. Fall back to the
+# running kernel's build tree for standalone builds. Keep this in sync
+# with page_frag/Makefile, which is invoked separately by lib.mk.
+KSRC_TREE := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
+
+# A build directory holds the generated configuration but no source
+# headers, so look for the header through the "source" symlink that
+# outputmakefile leaves in an O= build directory as well. Split
+# kernel-devel packages carry the same symlink.
+PAGE_FRAG_HDR := $(firstword $(wildcard \
+ $(KDIR)/include/linux/page_frag_cache.h \
+ $(KDIR)/source/include/linux/page_frag_cache.h))
+
ifneq (,$(wildcard $(KDIR)/Module.symvers))
-ifneq (,$(wildcard $(KDIR)/include/linux/page_frag_cache.h))
+ifneq (,$(PAGE_FRAG_HDR))
TEST_GEN_MODS_DIR := page_frag
else
PAGE_FRAG_WARNING = "missing page_frag_cache.h, please use a newer kernel"
diff --git a/tools/testing/selftests/mm/page_frag/Makefile b/tools/testing/selftests/mm/page_frag/Makefile
index 8c8bb39ffa28..f7bc03f5d914 100644
--- a/tools/testing/selftests/mm/page_frag/Makefile
+++ b/tools/testing/selftests/mm/page_frag/Makefile
@@ -1,4 +1,26 @@
PAGE_FRAG_TEST_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Kernel build tree to compile the test module against. Prefer the kernel
+# tree this test is part of (or its O= build directory) when it is
+# configured and built, like bpf/test_kmods already does: when the
+# selftests are built as part of a kernel package, uname -r is the build
+# host's kernel and not the kernel being packaged, so the resulting module
+# would carry the wrong vermagic and symbol CRCs. Fall back to the
+# running kernel's build tree for standalone builds.
+KSRC_TREE := $(abspath $(PAGE_FRAG_TEST_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
ifeq ($(V),1)
@@ -11,8 +33,16 @@ MODULES = page_frag_test.ko
obj-m += page_frag_test.o
+# Ensure that KDIR is a kernel build tree, otherwise skip the compilation.
+# Testing for the Makefile rather than for the directory itself also covers
+# a dangling /lib/modules/$(uname -r)/build symlink, and an installed
+# testsuite, which ships a pre-built module and has no kernel tree above it.
all:
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
+$(Q)make -C $(KDIR) M=$(PAGE_FRAG_TEST_DIR) modules
+endif
clean:
+ifneq ("$(wildcard $(KDIR)/Makefile)", "")
+$(Q)make -C $(KDIR) M=$(PAGE_FRAG_TEST_DIR) clean
+endif
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Devel] [PATCH vz10 v3 0/2] selftests: build test modules for the packaged kernel
2026-08-12 9:49 [Devel] [PATCH vz10 v2] selftests: build test modules against the kernel tree Eva Kurchatova
@ 2026-08-13 17:58 ` Konstantin Khorenko
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 1/2] selftests: do not hide a missing kernel build tree Konstantin Khorenko
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 2/2] selftests: build test modules against the kernel tree Konstantin Khorenko
0 siblings, 2 replies; 6+ messages in thread
From: Konstantin Khorenko @ 2026-08-13 17:58 UTC (permalink / raw)
The in-tree test modules of the selftests are built against the wrong
kernel, or not built at all, when the selftests are built as part of a
kernel package.
The livepatch, cgroup and mm/page_frag test module Makefiles default
KDIR to /lib/modules/$(uname -r)/build, which is the build tree of the
kernel running on the build host, not of the kernel being packaged. The
result is visible in the kernel-selftests rpm we ship today: of all
in-tree test modules only the bpf ones are there, and bpf/test_kmods is
exactly the one which already defaults KDIR to the kernel tree it
belongs to. Patch 2 makes the others do the same, and lets KDIR follow
an O= or KBUILD_OUTPUT build directory as well.
Patch 1 drops the KDIR existence checks around the recipes instead of
fixing them, which is the main change since v2. My reasoning:
- A silent skip is the worst possible outcome for a packaged testsuite.
The modules are simply absent from the rpm, the build log says nothing
about it, and the failure surfaces much later on a test node as a test
which cannot find its module, far away from the cause. A build failure
is strictly better: it happens where the kernel tree is, and it says
what is missing.
- The check did not even do what it promised. $(wildcard) reports the
name of a symlink without resolving it, so for the default KDIR of
/lib/modules/$(uname -r)/build, which commonly is a dangling symlink
left behind by an uninstalled kernel-devel package, the check passed
and the build failed in make -C anyway.
- Nothing is lost by dropping it. The selftests framework already
implements the "do not fail everything because of one target" policy,
and it does so honestly, leaving the error of the failing target in
the build log:
all:
@ret=1; \
for TARGET in $(TARGETS); do \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
O=$(abs_objtree) \
$(if $(FORCE_TARGETS),|| exit); \
ret=$$((ret * $$?)); \
done; exit $$ret;
The exit status is the product of the per-target statuses seeded with
1, so one failing target does not abort the run and is masked by any
later successful one, while FORCE_TARGETS=1 makes the loop strict.
Choosing between the two belongs to whoever runs the build, and a
Makefile which reports success no matter what takes that choice away:
kernel packaging passes FORCE_TARGETS=1 exactly because it wants to
know whether every test module has been built. Dropping the checks
also makes the tree consistent, bpf/test_kmods and mm/page_frag never
had one and simply fail.
One warning based skip is left alone on purpose. mm/Makefile decides
whether to build page_frag_test.ko by looking for
include/linux/page_frag_cache.h, and an older kernel legitimately does
not have that API; that check prints a warning and the test skips at
runtime with the kselftest skip code. Its neighbouring "missing
Module.symvers" branch is not feature detection though, and is a
candidate for the same treatment later.
Changes since v2:
- Split into two patches, so that dropping the KDIR checks is a separate
change with its own reasoning.
- Drop the checks instead of fixing them to test $(KDIR)/Makefile.
- Trim the commit message and the in-code comments, which repeated the
same rationale in four Makefiles.
Eva Kurchatova (1):
selftests: build test modules against the kernel tree
Konstantin Khorenko (1):
selftests: do not hide a missing kernel build tree
.../testing/selftests/bpf/test_kmods/Makefile | 20 +++++++++++++-
.../selftests/cgroup/test_modules/Makefile | 24 ++++++++++++-----
.../selftests/livepatch/test_modules/Makefile | 24 ++++++++++++-----
tools/testing/selftests/mm/Makefile | 27 ++++++++++++++++++-
tools/testing/selftests/mm/page_frag/Makefile | 18 +++++++++++++
5 files changed, 99 insertions(+), 14 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Devel] [PATCH vz10 v3 1/2] selftests: do not hide a missing kernel build tree
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 0/2] selftests: build test modules for the packaged kernel Konstantin Khorenko
@ 2026-08-13 17:58 ` Konstantin Khorenko
2026-08-14 11:11 ` [Devel] [PATCH RHEL10 COMMIT] " Konstantin Khorenko
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 2/2] selftests: build test modules against the kernel tree Konstantin Khorenko
1 sibling, 1 reply; 6+ messages in thread
From: Konstantin Khorenko @ 2026-08-13 17:58 UTC (permalink / raw)
The livepatch and cgroup test module Makefiles wrap their recipes into a
KDIR existence test:
# Ensure that KDIR exists, otherwise skip the compilation
modules:
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
so the test modules are silently not built when KDIR is not there: the
target simply loses its recipe and make reports success. The test comes
from commit 54ee3526796f ("selftests: livepatch: Avoid running the tests
if kernel-devel is missing"), which was a reaction to a kernel test robot
build failure report, and the cgroup Makefile copied the pattern later.
bpf/test_kmods and mm/page_frag never had such a test and simply fail, so
the tree is not consistent about it either.
A silent skip is the worst possible outcome for a packaged testsuite: the
test modules are missing from the rpm, the build log says nothing about
it, and the failure only surfaces on a test node as a test which cannot
find its module, far away from the cause.
Nothing is lost by dropping it, because the selftests framework already
implements the "do not fail everything because of one target" policy and
kernel packaging passes FORCE_TARGETS=1 exactly because it wants to know
whether every test module has been built:
all:
@ret=1; \
for TARGET in $(TARGETS); do \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
O=$(abs_objtree) \
$(if $(FORCE_TARGETS),|| exit); \
ret=$$((ret * $$?)); \
done; exit $$ret;
So drop the tests and let make -C fail and say why. This also puts the
two Makefiles back in line with bpf/test_kmods and mm/page_frag.
https://virtuozzo.atlassian.net/browse/VSTOR-139647
Feature: fix selftests
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
tools/testing/selftests/cgroup/test_modules/Makefile | 6 ------
tools/testing/selftests/livepatch/test_modules/Makefile | 6 ------
2 files changed, 12 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_modules/Makefile b/tools/testing/selftests/cgroup/test_modules/Makefile
index 3f39eeda3a92b..38121d783d921 100644
--- a/tools/testing/selftests/cgroup/test_modules/Makefile
+++ b/tools/testing/selftests/cgroup/test_modules/Makefile
@@ -4,14 +4,8 @@ KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += cg_freezer_hang.o \
cg_freezer_kthread.o
-# Ensure that KDIR exists, otherwise skip the compilation
modules:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
-# Ensure that KDIR exists, otherwise skip the clean target
clean:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index 939230e571f5d..34e2f76fb4cec 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -14,14 +14,8 @@ obj-m += test_klp_atomic_replace.o \
test_klp_state3.o \
test_klp_syscall.o
-# Ensure that KDIR exists, otherwise skip the compilation
modules:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
-# Ensure that KDIR exists, otherwise skip the clean target
clean:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Devel] [PATCH vz10 v3 2/2] selftests: build test modules against the kernel tree
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 0/2] selftests: build test modules for the packaged kernel Konstantin Khorenko
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 1/2] selftests: do not hide a missing kernel build tree Konstantin Khorenko
@ 2026-08-13 17:58 ` Konstantin Khorenko
2026-08-14 11:11 ` [Devel] [PATCH RHEL10 COMMIT] " Konstantin Khorenko
1 sibling, 1 reply; 6+ messages in thread
From: Konstantin Khorenko @ 2026-08-13 17:58 UTC (permalink / raw)
From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Default KDIR to the kernel tree being packaged everywhere, or to its O=
/ KBUILD_OUTPUT build directory, when it is configured and built, that
is when include/config/auto.conf and Module.symvers are in place.
Otherwise keep the old default /lib/modules/$(uname -r)/build, so a bare
source checkout still builds against the running kernel.
This avoids building kselftests kernel modules against running kernel
during keernel packaging.
An O= build directory carries the generated configuration but no source
headers, so mm/Makefile, which decides whether to build page_frag_test.ko
by looking for include/linux/page_frag_cache.h below KDIR, has to look
through the "source" symlink of the build directory as well. Otherwise an
O= build skips the module and blames a too old kernel for it.
https://virtuozzo.atlassian.net/browse/VSTOR-139647
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
.../testing/selftests/bpf/test_kmods/Makefile | 20 +++++++++++++-
.../selftests/cgroup/test_modules/Makefile | 18 +++++++++++++
.../selftests/livepatch/test_modules/Makefile | 18 +++++++++++++
tools/testing/selftests/mm/Makefile | 27 ++++++++++++++++++-
tools/testing/selftests/mm/page_frag/Makefile | 18 +++++++++++++
5 files changed, 99 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_kmods/Makefile b/tools/testing/selftests/bpf/test_kmods/Makefile
index d4e50c4509c93..65547f8570577 100644
--- a/tools/testing/selftests/bpf/test_kmods/Makefile
+++ b/tools/testing/selftests/bpf/test_kmods/Makefile
@@ -1,5 +1,23 @@
TEST_KMOD_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
-KDIR ?= $(abspath $(TEST_KMOD_DIR)/../../../../..)
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(TEST_KMOD_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
+KDIR ?= /lib/modules/$(shell uname -r)/build
ifeq ($(V),1)
Q =
diff --git a/tools/testing/selftests/cgroup/test_modules/Makefile b/tools/testing/selftests/cgroup/test_modules/Makefile
index 38121d783d921..6d6ce08335737 100644
--- a/tools/testing/selftests/cgroup/test_modules/Makefile
+++ b/tools/testing/selftests/cgroup/test_modules/Makefile
@@ -1,4 +1,22 @@
TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(TESTMODS_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += cg_freezer_hang.o \
diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index 34e2f76fb4cec..2820d4e444c61 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -1,4 +1,22 @@
TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(TESTMODS_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += test_klp_atomic_replace.o \
diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index 3de23ea4663f7..c837b0549c892 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -36,9 +36,34 @@ MAKEFLAGS += --no-builtin-rules
CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
LDLIBS = -lrt -lpthread -lm
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+# Keep in sync with page_frag/Makefile, which lib.mk invokes separately.
+KSRC_TREE := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
+
+# In an O= build the headers stay in the source tree, which
+# outputmakefile links as $(objtree)/source.
+PAGE_FRAG_HDR := $(firstword $(wildcard \
+ $(KDIR)/include/linux/page_frag_cache.h \
+ $(KDIR)/source/include/linux/page_frag_cache.h))
+
ifneq (,$(wildcard $(KDIR)/Module.symvers))
-ifneq (,$(wildcard $(KDIR)/include/linux/page_frag_cache.h))
+ifneq (,$(PAGE_FRAG_HDR))
TEST_GEN_MODS_DIR := page_frag
else
PAGE_FRAG_WARNING = "missing page_frag_cache.h, please use a newer kernel"
diff --git a/tools/testing/selftests/mm/page_frag/Makefile b/tools/testing/selftests/mm/page_frag/Makefile
index 8c8bb39ffa282..43a2189a2c9f9 100644
--- a/tools/testing/selftests/mm/page_frag/Makefile
+++ b/tools/testing/selftests/mm/page_frag/Makefile
@@ -1,4 +1,22 @@
PAGE_FRAG_TEST_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(PAGE_FRAG_TEST_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
ifeq ($(V),1)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Devel] [PATCH RHEL10 COMMIT] selftests: do not hide a missing kernel build tree
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 1/2] selftests: do not hide a missing kernel build tree Konstantin Khorenko
@ 2026-08-14 11:11 ` Konstantin Khorenko
0 siblings, 0 replies; 6+ messages in thread
From: Konstantin Khorenko @ 2026-08-14 11:11 UTC (permalink / raw)
The commit is pushed to "branch-rh10-6.12.0-211.39.1.16.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-211.39.1.16.4.vz10
------>
commit c07a6860abc51ad6a6f2ac2f2b64d444be88de54
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date: Thu Aug 13 19:20:09 2026 +0200
selftests: do not hide a missing kernel build tree
The livepatch and cgroup test module Makefiles wrap their recipes into a
KDIR existence test:
# Ensure that KDIR exists, otherwise skip the compilation
modules:
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
so the test modules are silently not built when KDIR is not there: the
target simply loses its recipe and make reports success. The test comes
from commit 54ee3526796f ("selftests: livepatch: Avoid running the tests
if kernel-devel is missing"), which was a reaction to a kernel test robot
build failure report, and the cgroup Makefile copied the pattern later.
bpf/test_kmods and mm/page_frag never had such a test and simply fail, so
the tree is not consistent about it either.
A silent skip is the worst possible outcome for a packaged testsuite: the
test modules are missing from the rpm, the build log says nothing about
it, and the failure only surfaces on a test node as a test which cannot
find its module, far away from the cause.
Nothing is lost by dropping it, because the selftests framework already
implements the "do not fail everything because of one target" policy and
kernel packaging passes FORCE_TARGETS=1 exactly because it wants to know
whether every test module has been built:
all:
@ret=1; \
for TARGET in $(TARGETS); do \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
O=$(abs_objtree) \
$(if $(FORCE_TARGETS),|| exit); \
ret=$$((ret * $$?)); \
done; exit $$ret;
So drop the tests and let make -C fail and say why. This also puts the
two Makefiles back in line with bpf/test_kmods and mm/page_frag.
https://virtuozzo.atlassian.net/browse/VSTOR-139647
Feature: fix selftests
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
tools/testing/selftests/cgroup/test_modules/Makefile | 6 ------
tools/testing/selftests/livepatch/test_modules/Makefile | 6 ------
2 files changed, 12 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_modules/Makefile b/tools/testing/selftests/cgroup/test_modules/Makefile
index 3f39eeda3a92b..38121d783d921 100644
--- a/tools/testing/selftests/cgroup/test_modules/Makefile
+++ b/tools/testing/selftests/cgroup/test_modules/Makefile
@@ -4,14 +4,8 @@ KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += cg_freezer_hang.o \
cg_freezer_kthread.o
-# Ensure that KDIR exists, otherwise skip the compilation
modules:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
-# Ensure that KDIR exists, otherwise skip the clean target
clean:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index 939230e571f5d..34e2f76fb4cec 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -14,14 +14,8 @@ obj-m += test_klp_atomic_replace.o \
test_klp_state3.o \
test_klp_syscall.o
-# Ensure that KDIR exists, otherwise skip the compilation
modules:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
-# Ensure that KDIR exists, otherwise skip the clean target
clean:
-ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
-endif
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Devel] [PATCH RHEL10 COMMIT] selftests: build test modules against the kernel tree
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 2/2] selftests: build test modules against the kernel tree Konstantin Khorenko
@ 2026-08-14 11:11 ` Konstantin Khorenko
0 siblings, 0 replies; 6+ messages in thread
From: Konstantin Khorenko @ 2026-08-14 11:11 UTC (permalink / raw)
The commit is pushed to "branch-rh10-6.12.0-211.39.1.16.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-211.39.1.16.4.vz10
------>
commit 5afeb70f3c754dce8263b0ccd9aa460c33619354
Author: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Date: Wed Aug 12 12:49:17 2026 +0300
selftests: build test modules against the kernel tree
Default KDIR to the kernel tree being packaged everywhere, or to its O=
/ KBUILD_OUTPUT build directory, when it is configured and built, that
is when include/config/auto.conf and Module.symvers are in place.
Otherwise keep the old default /lib/modules/$(uname -r)/build, so a bare
source checkout still builds against the running kernel.
This avoids building kselftests kernel modules against running kernel
during keernel packaging.
An O= build directory carries the generated configuration but no source
headers, so mm/Makefile, which decides whether to build page_frag_test.ko
by looking for include/linux/page_frag_cache.h below KDIR, has to look
through the "source" symlink of the build directory as well. Otherwise an
O= build skips the module and blames a too old kernel for it.
https://virtuozzo.atlassian.net/browse/VSTOR-139647
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/testing/selftests/bpf/test_kmods/Makefile | 20 +++++++++++++++-
.../testing/selftests/cgroup/test_modules/Makefile | 18 +++++++++++++++
.../selftests/livepatch/test_modules/Makefile | 18 +++++++++++++++
tools/testing/selftests/mm/Makefile | 27 +++++++++++++++++++++-
tools/testing/selftests/mm/page_frag/Makefile | 18 +++++++++++++++
5 files changed, 99 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_kmods/Makefile b/tools/testing/selftests/bpf/test_kmods/Makefile
index d4e50c4509c93..65547f8570577 100644
--- a/tools/testing/selftests/bpf/test_kmods/Makefile
+++ b/tools/testing/selftests/bpf/test_kmods/Makefile
@@ -1,5 +1,23 @@
TEST_KMOD_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
-KDIR ?= $(abspath $(TEST_KMOD_DIR)/../../../../..)
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(TEST_KMOD_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
+KDIR ?= /lib/modules/$(shell uname -r)/build
ifeq ($(V),1)
Q =
diff --git a/tools/testing/selftests/cgroup/test_modules/Makefile b/tools/testing/selftests/cgroup/test_modules/Makefile
index 38121d783d921..6d6ce08335737 100644
--- a/tools/testing/selftests/cgroup/test_modules/Makefile
+++ b/tools/testing/selftests/cgroup/test_modules/Makefile
@@ -1,4 +1,22 @@
TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(TESTMODS_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += cg_freezer_hang.o \
diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index 34e2f76fb4cec..2820d4e444c61 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -1,4 +1,22 @@
TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(TESTMODS_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
obj-m += test_klp_atomic_replace.o \
diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index 3de23ea4663f7..c837b0549c892 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -36,9 +36,34 @@ MAKEFLAGS += --no-builtin-rules
CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
LDLIBS = -lrt -lpthread -lm
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+# Keep in sync with page_frag/Makefile, which lib.mk invokes separately.
+KSRC_TREE := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
+
+# In an O= build the headers stay in the source tree, which
+# outputmakefile links as $(objtree)/source.
+PAGE_FRAG_HDR := $(firstword $(wildcard \
+ $(KDIR)/include/linux/page_frag_cache.h \
+ $(KDIR)/source/include/linux/page_frag_cache.h))
+
ifneq (,$(wildcard $(KDIR)/Module.symvers))
-ifneq (,$(wildcard $(KDIR)/include/linux/page_frag_cache.h))
+ifneq (,$(PAGE_FRAG_HDR))
TEST_GEN_MODS_DIR := page_frag
else
PAGE_FRAG_WARNING = "missing page_frag_cache.h, please use a newer kernel"
diff --git a/tools/testing/selftests/mm/page_frag/Makefile b/tools/testing/selftests/mm/page_frag/Makefile
index 8c8bb39ffa282..43a2189a2c9f9 100644
--- a/tools/testing/selftests/mm/page_frag/Makefile
+++ b/tools/testing/selftests/mm/page_frag/Makefile
@@ -1,4 +1,22 @@
PAGE_FRAG_TEST_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
+# Build the modules against the kernel tree these tests are part of, or
+# its O= build directory, when that tree is configured and built; fall
+# back to the running kernel's build tree.
+KSRC_TREE := $(abspath $(PAGE_FRAG_TEST_DIR)/../../../../..)
+KOUT := $(or $(O),$(KBUILD_OUTPUT))
+ifeq ($(KOUT),)
+KDIR_TREE := $(KSRC_TREE)
+else ifneq (,$(filter /%,$(KOUT)))
+KDIR_TREE := $(abspath $(KOUT))
+else
+KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
+endif
+ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
+ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
+KDIR ?= $(KDIR_TREE)
+endif
+endif
KDIR ?= /lib/modules/$(shell uname -r)/build
ifeq ($(V),1)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-08-14 11:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-12 9:49 [Devel] [PATCH vz10 v2] selftests: build test modules against the kernel tree Eva Kurchatova
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 0/2] selftests: build test modules for the packaged kernel Konstantin Khorenko
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 1/2] selftests: do not hide a missing kernel build tree Konstantin Khorenko
2026-08-14 11:11 ` [Devel] [PATCH RHEL10 COMMIT] " Konstantin Khorenko
2026-08-13 17:58 ` [Devel] [PATCH vz10 v3 2/2] selftests: build test modules against the kernel tree Konstantin Khorenko
2026-08-14 11:11 ` [Devel] [PATCH RHEL10 COMMIT] " Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox