Skip to content

Commit 080102a

Browse files
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 <[email protected]> Co-authored-by: Sebastian Gottschall <[email protected]> Co-authored-by: Michael Niewöhner <[email protected]> Signed-off-by: Sebastian Gottschall <[email protected]> Signed-off-by: Michael Niewöhner <[email protected]> Closes #10422
1 parent 529246d commit 080102a

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

config/kernel-kmem.m4

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,29 @@ AC_DEFUN([ZFS_AC_KERNEL_KVMALLOC], [
8080
AC_MSG_RESULT(no)
8181
])
8282
])
83+
84+
dnl #
85+
dnl # 5.8 API,
86+
dnl # __vmalloc PAGE_KERNEL removal
87+
dnl #
88+
AC_DEFUN([ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL], [
89+
ZFS_LINUX_TEST_SRC([__vmalloc], [
90+
#include <linux/mm.h>
91+
#include <linux/vmalloc.h>
92+
],[
93+
void *p __attribute__ ((unused));
94+
95+
p = __vmalloc(0, GFP_KERNEL, PAGE_KERNEL);
96+
])
97+
])
98+
99+
AC_DEFUN([ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL], [
100+
AC_MSG_CHECKING([whether __vmalloc(ptr, flags, pageflags) is available])
101+
ZFS_LINUX_TEST_RESULT([__vmalloc], [
102+
AC_MSG_RESULT(yes)
103+
AC_DEFINE(HAVE_VMALLOC_PAGE_KERNEL, 1, [__vmalloc page flags exists])
104+
],[
105+
AC_MSG_RESULT(no)
106+
])
107+
])
108+
-

config/kernel.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
4747
ZFS_AC_KERNEL_SRC_USLEEP_RANGE
4848
ZFS_AC_KERNEL_SRC_KMEM_CACHE
4949
ZFS_AC_KERNEL_SRC_KVMALLOC
50+
ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
5051
ZFS_AC_KERNEL_SRC_WAIT
5152
ZFS_AC_KERNEL_SRC_INODE_TIMES
5253
ZFS_AC_KERNEL_SRC_INODE_LOCK
@@ -141,6 +142,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
141142
ZFS_AC_KERNEL_USLEEP_RANGE
142143
ZFS_AC_KERNEL_KMEM_CACHE
143144
ZFS_AC_KERNEL_KVMALLOC
145+
ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
144146
ZFS_AC_KERNEL_WAIT
145147
ZFS_AC_KERNEL_INODE_TIMES
146148
ZFS_AC_KERNEL_INODE_LOCK

include/os/linux/spl/sys/kmem.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ extern void *spl_kmem_alloc(size_t sz, int fl, const char *func, int line);
172172
extern void *spl_kmem_zalloc(size_t sz, int fl, const char *func, int line);
173173
extern void spl_kmem_free(const void *ptr, size_t sz);
174174

175+
/*
176+
* 5.8 API change, pgprot_t argument removed.
177+
*/
178+
#ifdef HAVE_VMALLOC_PAGE_KERNEL
179+
#define spl_vmalloc(size, flags) __vmalloc(size, flags, PAGE_KERNEL)
180+
#else
181+
#define spl_vmalloc(size, flags) __vmalloc(size, flags)
182+
#endif
183+
175184
/*
176185
* The following functions are only available for internal use.
177186
*/

module/os/linux/spl/spl-kmem-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ kv_alloc(spl_kmem_cache_t *skc, int size, int flags)
203203
ASSERT(ISP2(size));
204204
ptr = (void *)__get_free_pages(lflags, get_order(size));
205205
} else {
206-
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL);
206+
ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
207207
}
208208

209209
/* Resulting allocated memory will be page aligned */
@@ -1251,7 +1251,7 @@ spl_cache_grow(spl_kmem_cache_t *skc, int flags, void **obj)
12511251
* allocation.
12521252
*
12531253
* However, this can't be applied to KVM_VMEM due to a bug that
1254-
* __vmalloc() doesn't honor gfp flags in page table allocation.
1254+
* spl_vmalloc() doesn't honor gfp flags in page table allocation.
12551255
*/
12561256
if (!(skc->skc_flags & KMC_VMEM) && !(skc->skc_flags & KMC_KVMEM)) {
12571257
rc = __spl_cache_grow(skc, flags | KM_NOSLEEP);

module/os/linux/spl/spl-kmem.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <sys/sysmacros.h>
2727
#include <sys/kmem.h>
2828
#include <sys/vmem.h>
29-
#include <linux/mm.h>
3029

3130
/*
3231
* As a general rule kmem_alloc() allocations should be small, preferably
@@ -188,12 +187,12 @@ spl_kvmalloc(size_t size, gfp_t lflags)
188187

189188
/*
190189
* We first try kmalloc - even for big sizes - and fall back to
191-
* __vmalloc if that fails.
190+
* spl_vmalloc if that fails.
192191
*
193192
* For non-__GFP-RECLAIM allocations we always stick to
194193
* kmalloc_node, and fail when kmalloc is not successful (returns
195194
* NULL).
196-
* We cannot fall back to __vmalloc in this case because __vmalloc
195+
* We cannot fall back to spl_vmalloc in this case because spl_vmalloc
197196
* internally uses GPF_KERNEL allocations.
198197
*/
199198
void *ptr = kmalloc_node(size, kmalloc_lflags, NUMA_NO_NODE);
@@ -202,7 +201,7 @@ spl_kvmalloc(size_t size, gfp_t lflags)
202201
return (ptr);
203202
}
204203

205-
return (__vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL));
204+
return (spl_vmalloc(size, lflags | __GFP_HIGHMEM));
206205
}
207206

208207
/*
@@ -243,16 +242,15 @@ spl_kmem_alloc_impl(size_t size, int flags, int node)
243242
* kmem_zalloc() callers.
244243
*
245244
* For vmem_alloc() and vmem_zalloc() callers it is permissible
246-
* to use __vmalloc(). However, in general use of __vmalloc()
247-
* is strongly discouraged because a global lock must be
248-
* acquired. Contention on this lock can significantly
245+
* to use spl_vmalloc(). However, in general use of
246+
* spl_vmalloc() is strongly discouraged because a global lock
247+
* must be acquired. Contention on this lock can significantly
249248
* impact performance so frequently manipulating the virtual
250249
* address space is strongly discouraged.
251250
*/
252251
if (size > spl_kmem_alloc_max) {
253252
if (flags & KM_VMEM) {
254-
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM,
255-
PAGE_KERNEL);
253+
ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
256254
} else {
257255
return (NULL);
258256
}

0 commit comments

Comments
 (0)