From: Konstantin Khorenko <khorenko@virtuozzo.com>
Subject: [Devel] [PATCH RHEL10 COMMIT] selftests: build test modules against the kernel tree
Date: Fri, 14 Aug 2026 13:11:20 +0200 [thread overview]
Message-ID: <202608141111.67EBBK2U251346@f0.sw.ru> (raw)
In-Reply-To: <20260813175806.236084-3-khorenko@virtuozzo.com>
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)
prev parent reply other threads:[~2026-08-14 11:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 9:49 [Devel] [PATCH vz10 v2] " 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 ` Konstantin Khorenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202608141111.67EBBK2U251346@f0.sw.ru \
--to=khorenko@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.