From eafa39fbc3dbbadeda320a9bf418eaab75a88e41 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Fri, 29 May 2026 16:40:14 +0000 Subject: [PATCH] build: add ZFS_DEBUG Kconfig for copy-builtin ... so we can toggle ZFS debug assertions from the Linux kernel build without having to regenerate the ZFS patch. Update the qemu test script to also set this kernel config. Reviewed-by: Tony Hutter Reviewed-by: Brian Behlendorf Signed-off-by: Timothy Day Co-authored-by: Timothy Day Closes #18595 --- .github/workflows/scripts/qemu-6-tests.sh | 1 + config/zfs-build.m4 | 12 ++++++++++++ copy-builtin | 11 +++++++++++ module/Kbuild.in | 11 +++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/qemu-6-tests.sh b/.github/workflows/scripts/qemu-6-tests.sh index c261cbfca06..41c34511357 100755 --- a/.github/workflows/scripts/qemu-6-tests.sh +++ b/.github/workflows/scripts/qemu-6-tests.sh @@ -79,6 +79,7 @@ function do_builtin_build() { cd $HOME/linux-$fullver ./scripts/config --enable ZFS + ./scripts/config --enable ZFS_DEBUG yes "" | make oldconfig make -j `nproc` ) &> /var/tmp/builtin.txt || rc=$? diff --git a/config/zfs-build.m4 b/config/zfs-build.m4 index 1e1485c4cf4..7aabad3868b 100644 --- a/config/zfs-build.m4 +++ b/config/zfs-build.m4 @@ -39,6 +39,18 @@ dnl # (If INVARIANTS is detected, we need to force DEBUG, or strange panics dnl # can ensue.) dnl # AC_DEFUN([ZFS_AC_DEBUG], [ + dnl # + dnl # In the Linux kernel copy-builtin build, assertion/debug support + dnl # is selected by CONFIG_ZFS_DEBUG (Kconfig). + dnl # + AH_BOTTOM([ +#ifdef CONFIG_ZFS +#undef ZFS_DEBUG +#ifdef CONFIG_ZFS_DEBUG +#define ZFS_DEBUG 1 +#endif +#endif]) + AC_MSG_CHECKING([whether assertion support will be enabled]) AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], diff --git a/copy-builtin b/copy-builtin index 9a430bfb289..d412437f556 100755 --- a/copy-builtin +++ b/copy-builtin @@ -43,6 +43,17 @@ config ZFS To compile this file system support as a module, choose M here. + If unsure, say N. + +config ZFS_DEBUG + bool "ZFS debugging" + depends on ZFS + help + Enable ZFS debugging. This turns on all ASSERT() assertions, + enables additional debug-only code paths, and promotes + compiler warnings to errors. This should only be enabled for + development or troubleshooting. + If unsure, say N. EOF diff --git a/module/Kbuild.in b/module/Kbuild.in index ff2c96b85ae..fa4085c84b0 100644 --- a/module/Kbuild.in +++ b/module/Kbuild.in @@ -4,9 +4,11 @@ ZFS_MODULE_CFLAGS += -std=gnu11 -Wno-declaration-after-statement ZFS_MODULE_CFLAGS += -Wmissing-prototypes -ZFS_MODULE_CFLAGS += @KERNEL_DEBUG_CFLAGS@ @KERNEL_NO_FORMAT_ZERO_LENGTH@ +ZFS_MODULE_CFLAGS += @KERNEL_NO_FORMAT_ZERO_LENGTH@ ifneq ($(KBUILD_EXTMOD),) +ZFS_MODULE_CFLAGS += @KERNEL_DEBUG_CFLAGS@ +ZFS_MODULE_CPPFLAGS += @KERNEL_DEBUG_CPPFLAGS@ zfs_include = @abs_top_srcdir@/include icp_include = @abs_srcdir@/icp/include zstd_include = @abs_srcdir@/zstd/include @@ -16,6 +18,12 @@ ZFS_MODULE_CFLAGS += -I@abs_top_builddir@/include src = @abs_srcdir@ obj = @abs_builddir@ else +ifeq ($(CONFIG_ZFS_DEBUG),y) +ZFS_MODULE_CFLAGS += -Werror +ZFS_MODULE_CPPFLAGS += -DDEBUG -UNDEBUG -DZFS_DEBUG +else +ZFS_MODULE_CPPFLAGS += -UDEBUG -DNDEBUG +endif zfs_include = $(srctree)/include/zfs icp_include = $(src)/icp/include zstd_include = $(src)/zstd/include @@ -28,7 +36,6 @@ ZFS_MODULE_CFLAGS += -I$(zfs_include)/os/linux/spl ZFS_MODULE_CFLAGS += -I$(zfs_include)/os/linux/zfs ZFS_MODULE_CFLAGS += -I$(zfs_include) ZFS_MODULE_CPPFLAGS += -D_KERNEL -ZFS_MODULE_CPPFLAGS += @KERNEL_DEBUG_CPPFLAGS@ # KASAN enables -Werror=frame-larger-than=1024, which # breaks oh so many parts of our build.