From 9fb9eaff451238457d28d523c5f0692a40bbe830 Mon Sep 17 00:00:00 2001 From: Sebastian Gottschall Date: Sat, 6 Jun 2020 15:57:13 +0400 Subject: [PATCH] Linux 5.8 __vmalloc compat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Michael Niewöhner Signed-off-by: Sebastian Gottschall Signed-off-by: Michael Niewöhner --- config/kernel-kmem.m4 | 26 ++++++++++++ config/kernel.m4 | 2 + include/os/linux/kernel/linux/Makefile.am | 3 +- .../os/linux/kernel/linux/vmalloc_compat.h | 41 +++++++++++++++++++ include/os/linux/spl/sys/vmem.h | 1 + module/os/linux/spl/spl-kmem-cache.c | 2 +- module/os/linux/spl/spl-kmem.c | 5 +-- 7 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 include/os/linux/kernel/linux/vmalloc_compat.h diff --git a/config/kernel-kmem.m4 b/config/kernel-kmem.m4 index 2862299168c1..43f9e72f88d8 100644 --- a/config/kernel-kmem.m4 +++ b/config/kernel-kmem.m4 @@ -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 + #include + ],[ + 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 diff --git a/config/kernel.m4 b/config/kernel.m4 index 8cbf4aee9899..78b0ce4d3aa9 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -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 diff --git a/include/os/linux/kernel/linux/Makefile.am b/include/os/linux/kernel/linux/Makefile.am index 6b9b2a30ce38..3de053dcd46a 100644 --- a/include/os/linux/kernel/linux/Makefile.am +++ b/include/os/linux/kernel/linux/Makefile.am @@ -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 = diff --git a/include/os/linux/kernel/linux/vmalloc_compat.h b/include/os/linux/kernel/linux/vmalloc_compat.h new file mode 100644 index 000000000000..5b8dbf63917b --- /dev/null +++ b/include/os/linux/kernel/linux/vmalloc_compat.h @@ -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 + +/* + * 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 */ diff --git a/include/os/linux/spl/sys/vmem.h b/include/os/linux/spl/sys/vmem.h index a9b12eeb9619..27a94744b210 100644 --- a/include/os/linux/spl/sys/vmem.h +++ b/include/os/linux/spl/sys/vmem.h @@ -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 #define vmem_alloc(sz, fl) spl_vmem_alloc((sz), (fl), __func__, __LINE__) #define vmem_zalloc(sz, fl) spl_vmem_zalloc((sz), (fl), __func__, __LINE__) diff --git a/module/os/linux/spl/spl-kmem-cache.c b/module/os/linux/spl/spl-kmem-cache.c index 2ebbb43d18b7..c578fb55abc9 100644 --- a/module/os/linux/spl/spl-kmem-cache.c +++ b/module/os/linux/spl/spl-kmem-cache.c @@ -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 */ diff --git a/module/os/linux/spl/spl-kmem.c b/module/os/linux/spl/spl-kmem.c index b51e203edfe2..ca147d6c931c 100644 --- a/module/os/linux/spl/spl-kmem.c +++ b/module/os/linux/spl/spl-kmem.c @@ -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)); } /* @@ -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); }