tools/testing: fix testing/vma and testing/radix-tree build
Subsystems (2)
PATCH 1/1 tools/testing: fix testing/vma and testing/radix-tree build
From: "Mike Rapoport (Microsoft)" <[email protected]>
Build of VMA and radix-tree tests is unhappy after the conversion of kzalloc() to kzalloc_obj() in lib/idr.c:
cc -I../shared -I. -I../../include -I../../arch/x86/include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined -DNUM_VMA_FLAG_BITS=128 -DNUM_MM_FLAG_BITS=128 -c -o idr.o idr.c
idr.c: In function ‘ida_alloc_range’:
idr.c:420:34: error: implicit declaration of function ‘kzalloc_obj’; did you mean ‘kzalloc_node’? [-Wimplicit-function-declaration]
420 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT);
| ^~~~~~~~~~~
| kzalloc_node
idr.c:420:32: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
420 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT);
| ^
idr.c:447:40: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
447 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT);
| ^
idr.c:468:15: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
468 | alloc = kzalloc_obj(*bitmap, gfp);
| ^make: *** [<builtin>: idr.o] Error 1
Import necessary macros from include/linux to tools/include/linux to fix the compilation.
--- tools/include/linux/gfp.h | 4 ++++ tools/include/linux/overflow.h | 19 +++++++++++++++++++ tools/include/linux/slab.h | 9 +++++++++ 3 files changed, 32 insertions(+)
tools/include/linux/gfp.h +4 -0
@@ -5,6 +5,10 @@#include <linux/types.h> #include <linux/gfp_types.h> +/* Helper macro to avoid gfp flags if they are the default one */ +#define __default_gfp (a,...) a +#define default_gfp (...) __default_gfp(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL) +static inline bool gfpflags_allow_blocking (const gfp_t gfp_flags) {return !!(gfp_flags & __GFP_DIRECT_RECLAIM);
tools/include/linux/overflow.h +19 -0
@@ -68,6 +68,25 @@__builtin_mul_overflow (__a, __b, __d); \ }) +/** +* size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX +* @factor1: first factor +* @factor2: second factor +* +* Returns: calculate @factor1 * @factor2, both promoted to size_t, +* with any overflow causing the return value to be SIZE_MAX. The +* lvalue must be size_t to avoid implicit type conversion. +*/ +static inline size_t __must_check size_mul (size_t factor1,size_t factor2) +{ +size_t bytes; + +if (check_mul_overflow (factor1, factor2, &bytes)) +return SIZE_MAX ; + +return bytes; +} +/** * array_size() - Calculate size of 2-dimensional array. *
tools/include/linux/slab.h +9 -0
@@ -202,4 +202,13 @@ static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf) return sheaf->size; } +#define __alloc_objs (KMALLOC ,GFP ,TYPE ,COUNT ) \ +({ \ + const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \ + (TYPE *)KMALLOC(__obj_size, GFP); \ +}) + +#define kzalloc_obj (P , ...) \ + __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1) +#endif /* _TOOLS_SLAB_H */
Signature · 1 line
2.51.0
Quoted 20 lines · On Thu, 26 Feb 2026 01:31:11 +0200 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Build of VMA and radix-tree tests is unhappy after the conversion of
kzalloc()tokzalloc_obj()inlib/idr.c:cc -I../shared -I. -I../../include -I../../arch/x86/include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined -DNUM_VMA_FLAG_BITS=128 -DNUM_MM_FLAG_BITS=128 -c -o idr.o
idr.c
idr.c: In function ‘ida_alloc_range’:
idr.c:420:34: error: implicit declaration of function ‘kzalloc_obj’; did you mean ‘kzalloc_node’? [-Wimplicit-function-declaration]420 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT); | ^~~~~~~~~~~ | kzalloc_node idr.c:420:32: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 420 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT); | ^ idr.c:447:40: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 447 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT); | ^ idr.c:468:15: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 468 | alloc = kzalloc_obj(*bitmap, gfp); | ^
Quoted 4 lines
make: *** [<builtin>: idr.o] Error 1
Import necessary macros from
include/linuxtotools/include/linuxto fix the compilation.
Thank you for fixing this!
Quoted 3 lines
Fixes 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Quoted 58 lines
--- tools/include/linux/gfp.h | 4 ++++ tools/include/linux/overflow.h | 19 +++++++++++++++++++ tools/include/linux/slab.h | 9 +++++++++ 3 files changed, 32 insertions(+)tools/include/linux/gfp.h +4
-0@@ -5,6 +5,10 @@#include <linux/types.h> #include <linux/gfp_types.h> +/* Helper macro to avoid gfp flags if they are the default one */ +#define __default_gfp (a,...) a +#define default_gfp (...) __default_gfp(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL) +static inline bool gfpflags_allow_blocking (const gfp_t gfp_flags) {return !!(gfp_flags & __GFP_DIRECT_RECLAIM);tools/include/linux/overflow.h +19
-0@@ -68,6 +68,25 @@__builtin_mul_overflow (__a, __b, __d); \ }) +/** +* size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX +* @factor1: first factor +* @factor2: second factor +* +* Returns: calculate @factor1 * @factor2, both promoted to size_t, +* with any overflow causing the return value to be SIZE_MAX. The +* lvalue must be size_t to avoid implicit type conversion. +*/ +static inline size_t __must_check size_mul (size_t factor1,size_t factor2) +{ +size_t bytes; + +if (check_mul_overflow (factor1, factor2, &bytes)) +return SIZE_MAX ; + +return bytes; +} +/** * array_size() - Calculate size of 2-dimensional array. * tools/include/linux/slab.h +0
-0@@ -202,4 +202,13 @@ static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf)return sheaf->size; }
tools/include/linux/slab.h static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf) · line 213
Quoted 10 lines
tools/include/linux/slab.h +9
-0+#define __alloc_objs (KMALLOC ,GFP ,TYPE ,COUNT ) \ +({ \ + const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \ + (TYPE *)KMALLOC(__obj_size, GFP); \ +}) + +#define kzalloc_obj (P , ...) \ + __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1) +
Just out of curiosity. Is there a reason to not copy the comments from the original (include/linux/...) for the above two macros, unlike the others on this patch?
Thanks,
SJ
[...]
Quoted 7 lines · SeongJae Park
tools/include/linux/slab.h static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf) · line 213
Quoted 3 lines
tools/include/linux/slab.h +3
-0+#define kzalloc_obj (P , ...) \ + __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1) +Just out of curiosity. Is there a reason to not copy the comments from the original (
include/linux/...) for the above two macros, unlike the others on this patch?
I mean it doesn't matter too much, but I think for tools/include we do _try_ to keep these as close to the original as possible.
But again I don't think this really matters here tbh.
Quoted 6 lines
Thanks,
SJ[...]
Cheers, Lorenzo
Quoted 20 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Build of VMA and radix-tree tests is unhappy after the conversion of
kzalloc()tokzalloc_obj()inlib/idr.c:cc -I../shared -I. -I../../include -I../../arch/x86/include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined -DNUM_VMA_FLAG_BITS=128 -DNUM_MM_FLAG_BITS=128 -c -o idr.o
idr.c
idr.c: In function ‘ida_alloc_range’:
idr.c:420:34: error: implicit declaration of function ‘kzalloc_obj’; did you mean ‘kzalloc_node’? [-Wimplicit-function-declaration]420 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT); | ^~~~~~~~~~~ | kzalloc_node idr.c:420:32: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 420 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT); | ^ idr.c:447:40: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 447 | bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT); | ^ idr.c:468:15: error: assignment to ‘struct ida_bitmap *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 468 | alloc = kzalloc_obj(*bitmap, gfp); | ^
Quoted 7 lines
make: *** [<builtin>: idr.o] Error 1
Import necessary macros from
include/linuxtotools/include/linuxto fix the compilation.Fixes 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Thanks, saves me having to do this :)
Quoted 72 lines
--- tools/include/linux/gfp.h | 4 ++++ tools/include/linux/overflow.h | 19 +++++++++++++++++++ tools/include/linux/slab.h | 9 +++++++++ 3 files changed, 32 insertions(+)tools/include/linux/gfp.h +4
-0@@ -5,6 +5,10 @@#include <linux/types.h> #include <linux/gfp_types.h> +/* Helper macro to avoid gfp flags if they are the default one */ +#define __default_gfp (a,...) a +#define default_gfp (...) __default_gfp(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL) +static inline bool gfpflags_allow_blocking (const gfp_t gfp_flags) {return !!(gfp_flags & __GFP_DIRECT_RECLAIM);tools/include/linux/overflow.h +19
-0@@ -68,6 +68,25 @@__builtin_mul_overflow (__a, __b, __d); \ }) +/** +* size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX +* @factor1: first factor +* @factor2: second factor +* +* Returns: calculate @factor1 * @factor2, both promoted to size_t, +* with any overflow causing the return value to be SIZE_MAX. The +* lvalue must be size_t to avoid implicit type conversion. +*/ +static inline size_t __must_check size_mul (size_t factor1,size_t factor2) +{ +size_t bytes; + +if (check_mul_overflow (factor1, factor2, &bytes)) +return SIZE_MAX ; + +return bytes; +} +/** * array_size() - Calculate size of 2-dimensional array. * tools/include/linux/slab.h +9
-1@@ -202,4 +202,13 @@ static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf) return sheaf->size; } +#define __alloc_objs (KMALLOC ,GFP ,TYPE ,COUNT ) \ +({ \ + const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \ + (TYPE *)KMALLOC(__obj_size, GFP); \ +}) + +#define kzalloc_obj (P , ...) \ + __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1) +#endif /* _TOOLS_SLAB_H */ --2.51.0