1
0

BACKPORT-Linux-5.8-compat-__vmalloc.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. From 6cc95288ccea12ad7b67b2b5b3997dfad8e5b5c9 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Michael=20Niew=C3=B6hner?=
  3. <[email protected]>
  4. Date: Tue, 9 Jun 2020 01:32:02 +0200
  5. Subject: [PATCH] BACKPORT: Linux 5.8 compat: __vmalloc()
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. The `pgprot` argument has been removed from `__vmalloc` in Linux 5.8,
  10. being `PAGE_KERNEL` always now [1].
  11. Detect this during configure and define a wrapper for older kernels.
  12. [1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/mm/vmalloc.c?h=next-20200605&id=88dca4ca5a93d2c09e5bbc6a62fbfc3af83c4fca
  13. Reviewed-by: Brian Behlendorf <[email protected]>
  14. Co-authored-by: Sebastian Gottschall <[email protected]>
  15. Co-authored-by: Michael Niewöhner <[email protected]>
  16. Signed-off-by: Sebastian Gottschall <[email protected]>
  17. Signed-off-by: Michael Niewöhner <[email protected]>
  18. Closes #10422
  19. ---
  20. config/kernel-kmem.m4 | 26 ++++++++++++++++++++++++++
  21. config/kernel.m4 | 2 ++
  22. include/spl/sys/kmem.h | 9 +++++++++
  23. module/spl/spl-kmem-cache.c | 4 ++--
  24. module/spl/spl-kmem.c | 9 ++++-----
  25. 5 files changed, 43 insertions(+), 7 deletions(-)
  26. diff --git a/config/kernel-kmem.m4 b/config/kernel-kmem.m4
  27. index cc055e530..f1c0d2412 100644
  28. --- a/config/kernel-kmem.m4
  29. +++ b/config/kernel-kmem.m4
  30. @@ -56,3 +56,29 @@ AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
  31. AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
  32. AC_MSG_RESULT([$enable_debug_kmem_tracking])
  33. ])
  34. +
  35. +dnl #
  36. +dnl # 5.8 API,
  37. +dnl # __vmalloc PAGE_KERNEL removal
  38. +dnl #
  39. +AC_DEFUN([ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL], [
  40. + ZFS_LINUX_TEST_SRC([__vmalloc], [
  41. + #include <linux/mm.h>
  42. + #include <linux/vmalloc.h>
  43. + ],[
  44. + void *p __attribute__ ((unused));
  45. +
  46. + p = __vmalloc(0, GFP_KERNEL, PAGE_KERNEL);
  47. + ])
  48. +])
  49. +
  50. +AC_DEFUN([ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL], [
  51. + AC_MSG_CHECKING([whether __vmalloc(ptr, flags, pageflags) is available])
  52. + ZFS_LINUX_TEST_RESULT([__vmalloc], [
  53. + AC_MSG_RESULT(yes)
  54. + AC_DEFINE(HAVE_VMALLOC_PAGE_KERNEL, 1, [__vmalloc page flags exists])
  55. + ],[
  56. + AC_MSG_RESULT(no)
  57. + ])
  58. +])
  59. +-
  60. diff --git a/config/kernel.m4 b/config/kernel.m4
  61. index b67fcef8c..23edfdcd8 100644
  62. --- a/config/kernel.m4
  63. +++ b/config/kernel.m4
  64. @@ -45,6 +45,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
  65. ZFS_AC_KERNEL_SRC_SCHED
  66. ZFS_AC_KERNEL_SRC_USLEEP_RANGE
  67. ZFS_AC_KERNEL_SRC_KMEM_CACHE
  68. + ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
  69. ZFS_AC_KERNEL_SRC_WAIT
  70. ZFS_AC_KERNEL_SRC_INODE_TIMES
  71. ZFS_AC_KERNEL_SRC_INODE_LOCK
  72. @@ -163,6 +164,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
  73. ZFS_AC_KERNEL_SCHED
  74. ZFS_AC_KERNEL_USLEEP_RANGE
  75. ZFS_AC_KERNEL_KMEM_CACHE
  76. + ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
  77. ZFS_AC_KERNEL_WAIT
  78. ZFS_AC_KERNEL_INODE_TIMES
  79. ZFS_AC_KERNEL_INODE_LOCK
  80. diff --git a/include/spl/sys/kmem.h b/include/spl/sys/kmem.h
  81. index 72d3a7765..ca15bfe7f 100644
  82. --- a/include/spl/sys/kmem.h
  83. +++ b/include/spl/sys/kmem.h
  84. @@ -169,6 +169,15 @@ extern void *spl_kmem_alloc(size_t sz, int fl, const char *func, int line);
  85. extern void *spl_kmem_zalloc(size_t sz, int fl, const char *func, int line);
  86. extern void spl_kmem_free(const void *ptr, size_t sz);
  87. +/*
  88. + * 5.8 API change, pgprot_t argument removed.
  89. + */
  90. +#ifdef HAVE_VMALLOC_PAGE_KERNEL
  91. +#define spl_vmalloc(size, flags) __vmalloc(size, flags, PAGE_KERNEL)
  92. +#else
  93. +#define spl_vmalloc(size, flags) __vmalloc(size, flags)
  94. +#endif
  95. +
  96. /*
  97. * The following functions are only available for internal use.
  98. */
  99. diff --git a/module/spl/spl-kmem-cache.c b/module/spl/spl-kmem-cache.c
  100. index d71b4b348..4866b2993 100644
  101. --- a/module/spl/spl-kmem-cache.c
  102. +++ b/module/spl/spl-kmem-cache.c
  103. @@ -203,7 +203,7 @@ kv_alloc(spl_kmem_cache_t *skc, int size, int flags)
  104. ASSERT(ISP2(size));
  105. ptr = (void *)__get_free_pages(lflags, get_order(size));
  106. } else {
  107. - ptr = __vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL);
  108. + ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
  109. }
  110. /* Resulting allocated memory will be page aligned */
  111. @@ -1242,7 +1242,7 @@ spl_cache_grow(spl_kmem_cache_t *skc, int flags, void **obj)
  112. * allocation.
  113. *
  114. * However, this can't be applied to KVM_VMEM due to a bug that
  115. - * __vmalloc() doesn't honor gfp flags in page table allocation.
  116. + * spl_vmalloc() doesn't honor gfp flags in page table allocation.
  117. */
  118. if (!(skc->skc_flags & KMC_VMEM)) {
  119. rc = __spl_cache_grow(skc, flags | KM_NOSLEEP);
  120. diff --git a/module/spl/spl-kmem.c b/module/spl/spl-kmem.c
  121. index cee69ad43..ca1fc145f 100644
  122. --- a/module/spl/spl-kmem.c
  123. +++ b/module/spl/spl-kmem.c
  124. @@ -172,16 +172,15 @@ spl_kmem_alloc_impl(size_t size, int flags, int node)
  125. * kmem_zalloc() callers.
  126. *
  127. * For vmem_alloc() and vmem_zalloc() callers it is permissible
  128. - * to use __vmalloc(). However, in general use of __vmalloc()
  129. - * is strongly discouraged because a global lock must be
  130. - * acquired. Contention on this lock can significantly
  131. + * to use spl_vmalloc(). However, in general use of
  132. + * spl_vmalloc() is strongly discouraged because a global lock
  133. + * must be acquired. Contention on this lock can significantly
  134. * impact performance so frequently manipulating the virtual
  135. * address space is strongly discouraged.
  136. */
  137. if ((size > spl_kmem_alloc_max) || use_vmem) {
  138. if (flags & KM_VMEM) {
  139. - ptr = __vmalloc(size, lflags | __GFP_HIGHMEM,
  140. - PAGE_KERNEL);
  141. + ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);
  142. } else {
  143. return (NULL);
  144. }
  145. --
  146. 2.25.1