aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Norris <[email protected]>2024-07-31 21:39:31 +1000
committerBrian Behlendorf <[email protected]>2024-08-13 17:47:22 -0700
commit2633075e0905bbe4989a469c7d5892f2cf1108be (patch)
tree18fc0f146be9b15384277a8f3bd6f322fe05313b
parent3abffc8781ddd8a49434ec6cadf10c68bb699533 (diff)
Linux 6.11: avoid passing "end" sentinel to register_sysctl()
Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Sponsored-by: https://despairlabs.com/sponsor/ Closes #16400
-rw-r--r--config/kernel-register_sysctl_table.m426
-rw-r--r--config/kernel.m42
-rw-r--r--module/os/linux/spl/spl-proc.c41
3 files changed, 66 insertions, 3 deletions
diff --git a/config/kernel-register_sysctl_table.m4 b/config/kernel-register_sysctl_table.m4
index b8a0e0b17..12ffe9d95 100644
--- a/config/kernel-register_sysctl_table.m4
+++ b/config/kernel-register_sysctl_table.m4
@@ -27,6 +27,32 @@ AC_DEFUN([ZFS_AC_KERNEL_REGISTER_SYSCTL_TABLE], [
])
dnl #
+dnl # Linux 6.11 register_sysctl() enforces that sysctl tables no longer
+dnl # supply a sentinel end-of-table element. 6.6 introduces
+dnl # register_sysctl_sz() to enable callers to choose, so we use it if
+dnl # available for backward compatibility.
+dnl #
+AC_DEFUN([ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_SZ], [
+ ZFS_LINUX_TEST_SRC([has_register_sysctl_sz], [
+ #include <linux/sysctl.h>
+ ],[
+ struct ctl_table test_table[] __attribute__((unused)) = {0};
+ register_sysctl_sz("", test_table, 0);
+ ])
+])
+
+AC_DEFUN([ZFS_AC_KERNEL_REGISTER_SYSCTL_SZ], [
+ AC_MSG_CHECKING([whether register_sysctl_sz exists])
+ ZFS_LINUX_TEST_RESULT([has_register_sysctl_sz], [
+ AC_MSG_RESULT([yes])
+ AC_DEFINE(HAVE_REGISTER_SYSCTL_SZ, 1,
+ [register_sysctl_sz exists])
+ ],[
+ AC_MSG_RESULT([no])
+ ])
+])
+
+dnl #
dnl # Linux 6.11 makes const the ctl_table arg of proc_handler
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_PROC_HANDLER_CTL_TABLE_CONST], [
diff --git a/config/kernel.m4 b/config/kernel.m4
index d6ea34532..4d471358d 100644
--- a/config/kernel.m4
+++ b/config/kernel.m4
@@ -167,6 +167,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
ZFS_AC_KERNEL_SRC_WRITEPAGE_T
ZFS_AC_KERNEL_SRC_RECLAIMED
ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_TABLE
+ ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_SZ
ZFS_AC_KERNEL_SRC_PROC_HANDLER_CTL_TABLE_CONST
ZFS_AC_KERNEL_SRC_COPY_SPLICE_READ
ZFS_AC_KERNEL_SRC_SYNC_BDEV
@@ -321,6 +322,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
ZFS_AC_KERNEL_WRITEPAGE_T
ZFS_AC_KERNEL_RECLAIMED
ZFS_AC_KERNEL_REGISTER_SYSCTL_TABLE
+ ZFS_AC_KERNEL_REGISTER_SYSCTL_SZ
ZFS_AC_KERNEL_PROC_HANDLER_CTL_TABLE_CONST
ZFS_AC_KERNEL_COPY_SPLICE_READ
ZFS_AC_KERNEL_SYNC_BDEV
diff --git a/module/os/linux/spl/spl-proc.c b/module/os/linux/spl/spl-proc.c
index 22f587934..2c0cdd9fe 100644
--- a/module/os/linux/spl/spl-proc.c
+++ b/module/os/linux/spl/spl-proc.c
@@ -22,6 +22,9 @@
*
* Solaris Porting Layer (SPL) Proc Implementation.
*/
+/*
+ * Copyright (c) 2024, Rob Norris <[email protected]>
+ */
#include <sys/systeminfo.h>
#include <sys/kstat.h>
@@ -694,6 +697,37 @@ static void spl_proc_cleanup(void)
}
}
+#ifndef HAVE_REGISTER_SYSCTL_TABLE
+
+/*
+ * Traditionally, struct ctl_table arrays have been terminated by an "empty"
+ * sentinel element (specifically, one with .procname == NULL).
+ *
+ * Linux 6.6 began migrating away from this, adding register_sysctl_sz() so
+ * that callers could provide the size directly, and redefining
+ * register_sysctl() to just call register_sysctl_sz() with the array size. It
+ * retained support for the terminating element so that existing callers would
+ * continue to work.
+ *
+ * Linux 6.11 removed support for the terminating element, instead interpreting
+ * it as a real malformed element, and rejecting it.
+ *
+ * In order to continue support older kernels, we retain the terminating
+ * sentinel element for our sysctl tables, but instead detect availability of
+ * register_sysctl_sz(). If it exists, we pass it the array size -1, stopping
+ * the kernel from trying to process the terminator. For pre-6.6 kernels that
+ * don't have register_sysctl_sz(), we just use register_sysctl(), which can
+ * handle the terminating element as it always has.
+ */
+#ifdef HAVE_REGISTER_SYSCTL_SZ
+#define spl_proc_register_sysctl(p, t) \
+ register_sysctl_sz(p, t, ARRAY_SIZE(t)-1)
+#else
+#define spl_proc_register_sysctl(p, t) \
+ register_sysctl(p, t)
+#endif
+#endif
+
int
spl_proc_init(void)
{
@@ -704,16 +738,17 @@ spl_proc_init(void)
if (spl_header == NULL)
return (-EUNATCH);
#else
- spl_header = register_sysctl("kernel/spl", spl_table);
+ spl_header = spl_proc_register_sysctl("kernel/spl", spl_table);
if (spl_header == NULL)
return (-EUNATCH);
- spl_kmem = register_sysctl("kernel/spl/kmem", spl_kmem_table);
+ spl_kmem = spl_proc_register_sysctl("kernel/spl/kmem", spl_kmem_table);
if (spl_kmem == NULL) {
rc = -EUNATCH;
goto out;
}
- spl_kstat = register_sysctl("kernel/spl/kstat", spl_kstat_table);
+ spl_kstat = spl_proc_register_sysctl("kernel/spl/kstat",
+ spl_kstat_table);
if (spl_kstat == NULL) {
rc = -EUNATCH;
goto out;