]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Linux 5.8 compat: __vmalloc()
authorMichael Niewöhner <c0d3z3r0@users.noreply.github.com>
Mon, 8 Jun 2020 23:32:02 +0000 (01:32 +0200)
committerGitHub <noreply@github.com>
Mon, 8 Jun 2020 23:32:02 +0000 (16:32 -0700)
The `pgprot` argument has been removed from `__vmalloc` in Linux 5.8,
being `PAGE_KERNEL` always now [1].

Detect this during configure and define a wrapper for older kernels.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/mm/vmalloc.c?h=next-20200605&id=88dca4ca5a93d2c09e5bbc6a62fbfc3af83c4fca

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Co-authored-by: Michael Niewöhner <foss@mniewoehner.de>
Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
Closes #10422

config/kernel-kmem.m4
config/kernel.m4
include/os/linux/spl/sys/kmem.h
module/os/linux/spl/spl-kmem-cache.c
module/os/linux/spl/spl-kmem.c

index 2862299168c1fd0a96de978de3f1fca5605d50d3..43f9e72f88d886455343ec94c0b222738b50e0b8 100644 (file)
@@ -80,3 +80,29 @@ AC_DEFUN([ZFS_AC_KERNEL_KVMALLOC], [
                AC_MSG_RESULT(no)
        ])
 ])
+
+dnl #
+dnl # 5.8 API,
+dnl # __vmalloc PAGE_KERNEL removal
+dnl #
+AC_DEFUN([ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL], [
+       ZFS_LINUX_TEST_SRC([__vmalloc], [
+               #include <linux/mm.h>
+               #include <linux/vmalloc.h>
+       ],[
+               void *p __attribute__ ((unused));
+
+               p = __vmalloc(0, GFP_KERNEL, PAGE_KERNEL);
+       ])
+])
+
+AC_DEFUN([ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL], [
+       AC_MSG_CHECKING([whether __vmalloc(ptr, flags, pageflags) is available])
+       ZFS_LINUX_TEST_RESULT([__vmalloc], [
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_VMALLOC_PAGE_KERNEL, 1, [__vmalloc page flags exists])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+])
+-
\ No newline at end of file
index 8cbf4aee9899c6a8ddf06d5f61f746e29a5b9e39..78b0ce4d3aa963b51ee442fbd73f6c8fe36b302b 100644 (file)
@@ -47,6 +47,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
        ZFS_AC_KERNEL_SRC_USLEEP_RANGE
        ZFS_AC_KERNEL_SRC_KMEM_CACHE
        ZFS_AC_KERNEL_SRC_KVMALLOC
+       ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
        ZFS_AC_KERNEL_SRC_WAIT
        ZFS_AC_KERNEL_SRC_INODE_TIMES
        ZFS_AC_KERNEL_SRC_INODE_LOCK
@@ -141,6 +142,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
        ZFS_AC_KERNEL_USLEEP_RANGE
        ZFS_AC_KERNEL_KMEM_CACHE
        ZFS_AC_KERNEL_KVMALLOC
+       ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
        ZFS_AC_KERNEL_WAIT
        ZFS_AC_KERNEL_INODE_TIMES
        ZFS_AC_KERNEL_INODE_LOCK
index 1f51f5d98cdbc52c9f6a190287378cce09fe53aa..176858dc22be555f1ada7c54fbab86a24ff53fa5 100644 (file)
@@ -172,6 +172,15 @@ extern void *spl_kmem_alloc(size_t sz, int fl, const char *func, int line);
 extern void *spl_kmem_zalloc(size_t sz, int fl, const char *func, int line);
 extern void spl_kmem_free(const void *ptr, size_t sz);
 
+/*
+ * 5.8 API change, pgprot_t argument removed.
+ */
+#ifdef HAVE_VMALLOC_PAGE_KERNEL
+#define        spl_vmalloc(size, flags)        __vmalloc(size, flags, PAGE_KERNEL)
+#else
+#define        spl_vmalloc(size, flags)        __vmalloc(size, flags)
+#endif
+
 /*
  * The following functions are only available for internal use.
  */
index 2ebbb43d18b782613986bd5429e9f11691640266..4e8ce90931880ea9ca537ef3b66cd5de49602b8b 100644 (file)
@@ -203,7 +203,7 @@ kv_alloc(spl_kmem_cache_t *skc, int size, int flags)
                ASSERT(ISP2(size));
                ptr = (void *)__get_free_pages(lflags, get_order(size));
        } else {
-               ptr = __vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL);
+               ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
        }
 
        /* Resulting allocated memory will be page aligned */
@@ -1251,7 +1251,7 @@ spl_cache_grow(spl_kmem_cache_t *skc, int flags, void **obj)
         * allocation.
         *
         * However, this can't be applied to KVM_VMEM due to a bug that
-        * __vmalloc() doesn't honor gfp flags in page table allocation.
+        * spl_vmalloc() doesn't honor gfp flags in page table allocation.
         */
        if (!(skc->skc_flags & KMC_VMEM) && !(skc->skc_flags & KMC_KVMEM)) {
                rc = __spl_cache_grow(skc, flags | KM_NOSLEEP);
index b51e203edfe25c5ef88fcb542081ffeb514b0c2d..0bb82ac7af0a3b9e9a80bd3dd108df9306ffffeb 100644 (file)
@@ -26,7 +26,6 @@
 #include <sys/sysmacros.h>
 #include <sys/kmem.h>
 #include <sys/vmem.h>
-#include <linux/mm.h>
 
 /*
  * As a general rule kmem_alloc() allocations should be small, preferably
@@ -188,12 +187,12 @@ spl_kvmalloc(size_t size, gfp_t lflags)
 
        /*
         * We first try kmalloc - even for big sizes - and fall back to
-        * __vmalloc if that fails.
+        * spl_vmalloc if that fails.
         *
         * For non-__GFP-RECLAIM allocations we always stick to
         * kmalloc_node, and fail when kmalloc is not successful (returns
         * NULL).
-        * We cannot fall back to __vmalloc in this case because __vmalloc
+        * We cannot fall back to spl_vmalloc in this case because spl_vmalloc
         * internally uses GPF_KERNEL allocations.
         */
        void *ptr = kmalloc_node(size, kmalloc_lflags, NUMA_NO_NODE);
@@ -202,7 +201,7 @@ spl_kvmalloc(size_t size, gfp_t lflags)
                return (ptr);
        }
 
-       return (__vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL));
+       return (spl_vmalloc(size, lflags | __GFP_HIGHMEM));
 }
 
 /*
@@ -243,16 +242,15 @@ spl_kmem_alloc_impl(size_t size, int flags, int node)
                 * kmem_zalloc() callers.
                 *
                 * For vmem_alloc() and vmem_zalloc() callers it is permissible
-                * to use __vmalloc().  However, in general use of __vmalloc()
-                * is strongly discouraged because a global lock must be
-                * acquired.  Contention on this lock can significantly
+                * to use spl_vmalloc().  However, in general use of
+                * spl_vmalloc() is strongly discouraged because a global lock
+                * must be acquired.  Contention on this lock can significantly
                 * impact performance so frequently manipulating the virtual
                 * address space is strongly discouraged.
                 */
                if (size > spl_kmem_alloc_max) {
                        if (flags & KM_VMEM) {
-                               ptr = __vmalloc(size, lflags | __GFP_HIGHMEM,
-                                   PAGE_KERNEL);
+                               ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
                        } else {
                                return (NULL);
                        }