Skip to contentSkip to conversation

mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32

PATCH In review Jianqun Xu 3 participants 3 messages Mar 12, 2021

Subsystems (3)
lore
Share & tools
lore

Jianqun Xu

author
#0 lore raw

PATCH 1/1 mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32

The flag GFP_DMA32 only effect in kmalloc_large currently.

This patch will create caches with GFP_DMA32 to support kmalloc with size under KMALLOC_MAX_CACHE_SIZE.

---
 include/linux/slab.h |  7 +++++++
 mm/slab_common.c     | 14 ++++++++++++++
 2 files changed, 21 insertions(+)
include/linux/slab.h +7 -0
index be4ba5867ac5..f4317663d148 100644
@@ -307,6 +307,9 @@ enum kmalloc_cache_type {
 	KMALLOC_RECLAIM,
 #ifdef CONFIG_ZONE_DMA
 	KMALLOC_DMA,
+#endif
+#ifdef CONFIG_ZONE_DMA32
+	KMALLOC_DMA32,
 #endif
 	NR_KMALLOC_TYPES
 };
@@ -331,6 +334,10 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
 	 */
 	return flags & __GFP_DMA ? KMALLOC_DMA : KMALLOC_RECLAIM;
 #else
+#ifdef CONFIG_ZONE_DMA32
+	if (unlikely(flags & __GFP_DMA32))
+		return KMALLOC_DMA32;
+#endif
 	return flags & __GFP_RECLAIMABLE ? KMALLOC_RECLAIM : KMALLOC_NORMAL;
 #endif
 }
mm/slab_common.c +14 -0
index e981c80d216c..2a04736fe8f5 100644
@@ -805,6 +805,20 @@ void __init create_kmalloc_caches(slab_flags_t flags)
 		}
 	}
 #endif
+#ifdef CONFIG_ZONE_DMA32
+	for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
+		struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
+
+		if (s) {
+			unsigned int size = kmalloc_size(i);
+			const char *n = kmalloc_cache_name("dma32-kmalloc", size);
+
+			BUG_ON(!n);
+			kmalloc_caches[KMALLOC_DMA32][i] = create_kmalloc_cache(
+				n, size, SLAB_CACHE_DMA32 | flags, 0, 0);
+		}
+	}
+#endif
 }
 #endif /* !CONFIG_SLOB */
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Jianqun Xu

The flag GFP_DMA32 only effect in kmalloc_large currently.

This patch will create caches with GFP_DMA32 to support kmalloc with size under KMALLOC_MAX_CACHE_SIZE.

No. No new code should use GFP_DMA32, never mind through slab. Please use the proper DMA APIs for your addressing needs.

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#2 lore raw
In reply to Jianqun Xu
Thank you for the patch! Yet something to improve:

Hi Jianqun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on hnaz-linux-mm/master]

url:    https://github.com/0day-ci/linux/commits/Jianqun-Xu/mm-slab-kmalloc-with-GFP_DMA32-allocate-from-SLAB_CACHE_DMA32/20210312-160426
base:   https://github.com/hnaz/linux-mm master
config: x86_64-randconfig-a006-20210312 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 7b153b43d3a14d76975039408c4b922beb576735)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/93abfa9fa97332c9d5c1727fcf76b604b6da33de
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jianqun-Xu/mm-slab-kmalloc-with-GFP_DMA32-allocate-from-SLAB_CACHE_DMA32/20210312-160426 git checkout 93abfa9fa97332c9d5c1727fcf76b604b6da33de
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

>> mm/slab_common.c:812:24: error: implicit declaration of function 'kmalloc_size' [-Werror,-Wimplicit-function-declaration]
                           unsigned int size = kmalloc_size(i);
                                               ^
>> mm/slab_common.c:813:20: error: implicit declaration of function 'kmalloc_cache_name' [-Werror,-Wimplicit-function-declaration]
                           const char *n = kmalloc_cache_name("dma32-kmalloc", size);
                                           ^
>> mm/slab_common.c:813:16: warning: incompatible integer to pointer conversion initializing 'const char *' with an expression of type 'int' [-Wint-conversion]
                           const char *n = kmalloc_cache_name("dma32-kmalloc", size);
                                       ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 warning and 2 errors generated.

vim +/kmalloc_size +812 mm/slab_common.c

761
762 /*
763 * Create the kmalloc array. Some of the regular kmalloc arrays
764 * may already have been created because they were needed to
765 * enable allocations for slab creation.
766 */
767 void __init create_kmalloc_caches(slab_flags_t flags)
768 {
769 int i;
770 enum kmalloc_cache_type type;
771
772 for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) {
773 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
774 if (!kmalloc_caches[type][i])
775 new_kmalloc_cache(i, type, flags);
776
777 /*
778 * Caches that are not of the two-to-the-power-of size.
779 * These have to be created immediately after the
780 * earlier power of two caches
781 */
782 if (KMALLOC_MIN_SIZE <= 32 && i == 6 &&
783 !kmalloc_caches[type][1])
784 new_kmalloc_cache(1, type, flags);
785 if (KMALLOC_MIN_SIZE <= 64 && i == 7 &&
786 !kmalloc_caches[type][2])
787 new_kmalloc_cache(2, type, flags);
788 }
789 }
790
791 /* Kmalloc array is now usable */
792 slab_state = UP;
793
794 #ifdef CONFIG_ZONE_DMA
795 for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
796 struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
797
798 if (s) {
799 kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(
800 kmalloc_info[i].name[KMALLOC_DMA],
801 kmalloc_info[i].size,
802 SLAB_CACHE_DMA | flags, 0,
803 kmalloc_info[i].size);
804 }
805 }
806 #endif
807 #ifdef CONFIG_ZONE_DMA32
808 for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
809 struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
810
811 if (s) {

 > 812				unsigned int size = kmalloc_size(i);
 > 813				const char *n = kmalloc_cache_name("dma32-kmalloc", size);

814
815 BUG_ON(!n);
816 kmalloc_caches[KMALLOC_DMA32][i] = create_kmalloc_cache(
817 n, size, SLAB_CACHE_DMA32 | flags, 0, 0);
818 }
819 }
820 #endif
821 }
822 #endif /* !CONFIG_SLOB */
823

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org