Linux 5.8 compat: __vmalloc()

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

(cherry picked from commit 080102a1b6)
- apply to 0.8.4 before certain files were moved around
- config/kernel-kmem.m4 exists in git but not release tarballs because
  it is unused; introduce it in a new file to prevent conflicts
- linux/mm.h is included in git master via sys/kmem.h; do not remove it
  here or the build will error due to undefined is_vmalloc_addr()

Original-patch-by: Michael Niewöhner <c0d3z3r0@users.noreply.github.com>
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
This commit is contained in:
Eli Schwartz 2020-08-17 18:40:53 -04:00 committed by Tony Hutter
parent 04837c8dcb
commit 638edf1d42
5 changed files with 41 additions and 7 deletions

View File

@ -0,0 +1,24 @@
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)
])
])

View File

@ -45,6 +45,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
ZFS_AC_KERNEL_SRC_SCHED ZFS_AC_KERNEL_SRC_SCHED
ZFS_AC_KERNEL_SRC_USLEEP_RANGE ZFS_AC_KERNEL_SRC_USLEEP_RANGE
ZFS_AC_KERNEL_SRC_KMEM_CACHE ZFS_AC_KERNEL_SRC_KMEM_CACHE
ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
ZFS_AC_KERNEL_SRC_WAIT ZFS_AC_KERNEL_SRC_WAIT
ZFS_AC_KERNEL_SRC_INODE_TIMES ZFS_AC_KERNEL_SRC_INODE_TIMES
ZFS_AC_KERNEL_SRC_INODE_LOCK ZFS_AC_KERNEL_SRC_INODE_LOCK
@ -163,6 +164,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
ZFS_AC_KERNEL_SCHED ZFS_AC_KERNEL_SCHED
ZFS_AC_KERNEL_USLEEP_RANGE ZFS_AC_KERNEL_USLEEP_RANGE
ZFS_AC_KERNEL_KMEM_CACHE ZFS_AC_KERNEL_KMEM_CACHE
ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
ZFS_AC_KERNEL_WAIT ZFS_AC_KERNEL_WAIT
ZFS_AC_KERNEL_INODE_TIMES ZFS_AC_KERNEL_INODE_TIMES
ZFS_AC_KERNEL_INODE_LOCK ZFS_AC_KERNEL_INODE_LOCK

View File

@ -169,6 +169,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_zalloc(size_t sz, int fl, const char *func, int line);
extern void spl_kmem_free(const void *ptr, size_t sz); 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. * The following functions are only available for internal use.
*/ */

View File

@ -203,7 +203,7 @@ kv_alloc(spl_kmem_cache_t *skc, int size, int flags)
ASSERT(ISP2(size)); ASSERT(ISP2(size));
ptr = (void *)__get_free_pages(lflags, get_order(size)); ptr = (void *)__get_free_pages(lflags, get_order(size));
} else { } else {
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL); ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
} }
/* Resulting allocated memory will be page aligned */ /* Resulting allocated memory will be page aligned */
@ -1242,7 +1242,7 @@ spl_cache_grow(spl_kmem_cache_t *skc, int flags, void **obj)
* allocation. * allocation.
* *
* However, this can't be applied to KVM_VMEM due to a bug that * 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)) { if (!(skc->skc_flags & KMC_VMEM)) {
rc = __spl_cache_grow(skc, flags | KM_NOSLEEP); rc = __spl_cache_grow(skc, flags | KM_NOSLEEP);

View File

@ -172,16 +172,15 @@ spl_kmem_alloc_impl(size_t size, int flags, int node)
* kmem_zalloc() callers. * kmem_zalloc() callers.
* *
* For vmem_alloc() and vmem_zalloc() callers it is permissible * For vmem_alloc() and vmem_zalloc() callers it is permissible
* to use __vmalloc(). However, in general use of __vmalloc() * to use spl_vmalloc(). However, in general use of
* is strongly discouraged because a global lock must be * spl_vmalloc() is strongly discouraged because a global lock
* acquired. Contention on this lock can significantly * must be acquired. Contention on this lock can significantly
* impact performance so frequently manipulating the virtual * impact performance so frequently manipulating the virtual
* address space is strongly discouraged. * address space is strongly discouraged.
*/ */
if ((size > spl_kmem_alloc_max) || use_vmem) { if ((size > spl_kmem_alloc_max) || use_vmem) {
if (flags & KM_VMEM) { if (flags & KM_VMEM) {
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM, ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
PAGE_KERNEL);
} else { } else {
return (NULL); return (NULL);
} }