linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
Cc: SeongJae Park <sj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>, Kees Cook <kees@kernel.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Matthew Wilcox <willy@infradead.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] tools/testing: fix testing/vma and testing/radix-tree build
Date: Wed, 25 Feb 2026 16:39:43 -0800	[thread overview]
Message-ID: <20260226003945.7145-1-sj@kernel.org> (raw)
In-Reply-To: <20260225233111.2760752-1-rppt@kernel.org>

On Thu, 26 Feb 2026 01:31:11 +0200 Mike Rapoport <rppt@kernel.org> wrote:

> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> 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.

Thank you for fixing this!
> 
> Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Tested-by: SeongJae Park <sj@kernel.org>

> ---
>  tools/include/linux/gfp.h      |  4 ++++
>  tools/include/linux/overflow.h | 19 +++++++++++++++++++
>  tools/include/linux/slab.h     |  9 +++++++++
>  3 files changed, 32 insertions(+)
> 
> diff --git a/tools/include/linux/gfp.h b/tools/include/linux/gfp.h
> index 6a10ff5f5be9..9e957b57b694 100644
> --- a/tools/include/linux/gfp.h
> +++ b/tools/include/linux/gfp.h
> @@ -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);
> diff --git a/tools/include/linux/overflow.h b/tools/include/linux/overflow.h
> index dcb0c1bf6866..3427d7880326 100644
> --- a/tools/include/linux/overflow.h
> +++ b/tools/include/linux/overflow.h
> @@ -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.
>   *
> diff --git a/tools/include/linux/slab.h b/tools/include/linux/slab.h
> index 94937a699402..6d8e9413d5a4 100644
> --- a/tools/include/linux/slab.h
> +++ b/tools/include/linux/slab.h
> @@ -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)
> +

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

[...]


      reply	other threads:[~2026-02-26  0:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 23:31 Mike Rapoport
2026-02-26  0:39 ` SeongJae Park [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260226003945.7145-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=rppt@kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox