Skip to content

Commit

Permalink
Linux 5.8 __vmalloc compat
Browse files Browse the repository at this point in the history
The pgprot argument has been removed from __vmalloc in Linux 5.8 [1],
being `PAGE_KERNEL` always now.

Detect this during configure to use the right function call in spl.

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

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>
  • Loading branch information
BrainSlayer and c0d3z3r0 committed Jun 8, 2020
1 parent c9e319f commit 9fb9eaf
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
26 changes: 26 additions & 0 deletions config/kernel-kmem.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
])
-
2 changes: 2 additions & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion include/os/linux/kernel/linux/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ KERNEL_H = \
$(top_srcdir)/include/os/linux/kernel/linux/simd_powerpc.h \
$(top_srcdir)/include/os/linux/kernel/linux/mod_compat.h \
$(top_srcdir)/include/os/linux/kernel/linux/page_compat.h \
$(top_srcdir)/include/os/linux/kernel/linux/compiler_compat.h
$(top_srcdir)/include/os/linux/kernel/linux/compiler_compat.h \
$(top_srcdir)/include/os/linux/kernel/linux/vmalloc_compat.h

USER_H =

Expand Down
41 changes: 41 additions & 0 deletions include/os/linux/kernel/linux/vmalloc_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2020, Sebastian Gottschall / NewMedia-NET GmbH. All rights reserved.
* Copyright (c) 2020, Michael Niewöhner. All rights reserved.
*/

#ifndef _ZFS_VMALLOC_H
#define _ZFS_VMALLOC_H

#include <linux/vmalloc.h>

/*
* 5.8 API change
*/

#ifdef HAVE_VMALLOC_PAGE_KERNEL
#define __vmalloc(size, gfp_flags) \
__vmalloc(size, gfp_flags, PAGE_KERNEL)
#endif /* HAVE_VMALLOC_PAGE_KERNEL */

#endif /* _ZFS_VMALLOC_H */
1 change: 1 addition & 0 deletions include/os/linux/spl/sys/vmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ extern size_t vmem_size(vmem_t *vmp, int typemask);
* allocations (8MB in size or smaller) and map vmem_{alloc,zalloc,free}()
* to them.
*/
#include <linux/vmalloc_compat.h>

#define vmem_alloc(sz, fl) spl_vmem_alloc((sz), (fl), __func__, __LINE__)
#define vmem_zalloc(sz, fl) spl_vmem_zalloc((sz), (fl), __func__, __LINE__)
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/spl/spl-kmem-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = __vmalloc(size, lflags | __GFP_HIGHMEM);
}

/* Resulting allocated memory will be page aligned */
Expand Down
5 changes: 2 additions & 3 deletions module/os/linux/spl/spl-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ spl_kvmalloc(size_t size, gfp_t lflags)
return (ptr);
}

return (__vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL));
return (__vmalloc(size, lflags | __GFP_HIGHMEM));
}

/*
Expand Down Expand Up @@ -251,8 +251,7 @@ spl_kmem_alloc_impl(size_t size, int flags, int node)
*/
if (size > spl_kmem_alloc_max) {
if (flags & KM_VMEM) {
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM,
PAGE_KERNEL);
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM);
} else {
return (NULL);
}
Expand Down

0 comments on commit 9fb9eaf

Please sign in to comment.