[PATCH] slab: silence sparse warning with type-based partitioning

0 views
Skip to first unread message

Marco Elver

unread,
Jul 21, 2026, 5:20:14 AMJul 21
to el...@google.com, Vlastimil Babka, Andrew Morton, Harry Yoo, Hao Li, Christoph Lameter, David Rientjes, Roman Gushchin, linu...@kvack.org, linux-...@vger.kernel.org, kasa...@googlegroups.com, kernel test robot
Sparse does not know __builtin_infer_alloc_token() and complains:

sparse: sparse: undefined identifier '__builtin_infer_alloc_token'

Fix it by using a dummy variant of __kmalloc_token() if __CHECKER__ is
defined.

Fixes: feb662d9168b ("slab: support for compiler-assisted type-based slab cache partitioning")
Reported-by: kernel test robot <l...@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202607110912...@intel.com/
Signed-off-by: Marco Elver <el...@google.com>
---
include/linux/slab.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 51f03f18c9a7..7ffe152ce483 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -505,8 +505,12 @@ typedef struct { unsigned long v; } kmalloc_token_t;
extern unsigned long random_kmalloc_seed;
#define __kmalloc_token(...) ((kmalloc_token_t){ .v = _CODE_LOCATION_ })
#elif defined(CONFIG_KMALLOC_PARTITION_TYPED)
+#ifdef __CHECKER__
+#define __kmalloc_token(...) ((kmalloc_token_t){ .v = 0 })
+#else /* !__CHECKER__ */
#define __kmalloc_token(...) ((kmalloc_token_t){ .v = __builtin_infer_alloc_token(__VA_ARGS__) })
-#endif
+#endif /* __CHECKER__ */
+#endif /* CONFIG_KMALLOC_PARTITION_TYPED */
#define DECL_TOKEN_PARAM(_token) , kmalloc_token_t (_token)
#define _PASS_TOKEN_PARAM(_token) , (_token)
#define PASS_TOKEN_PARAM(_token) (_token)
--
2.55.0.229.g6434b31f56-goog

Vlastimil Babka (SUSE)

unread,
Jul 21, 2026, 5:30:19 AMJul 21
to Marco Elver, Andrew Morton, Chris Li, Harry Yoo, Hao Li, Christoph Lameter, David Rientjes, Roman Gushchin, linu...@kvack.org, linux-...@vger.kernel.org, kasa...@googlegroups.com, kernel test robot, linux-...@vger.kernel.org
On 7/21/26 11:19, Marco Elver wrote:
> Sparse does not know __builtin_infer_alloc_token() and complains:
>
> sparse: sparse: undefined identifier '__builtin_infer_alloc_token'
>
> Fix it by using a dummy variant of __kmalloc_token() if __CHECKER__ is
> defined.
>
> Fixes: feb662d9168b ("slab: support for compiler-assisted type-based slab cache partitioning")
> Reported-by: kernel test robot <l...@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202607110912...@intel.com/
> Signed-off-by: Marco Elver <el...@google.com>

Added to slab/for-next-fixes, thanks!

Harry Yoo

unread,
Jul 22, 2026, 3:08:18 AMJul 22
to Marco Elver, Vlastimil Babka, Andrew Morton, Hao Li, Christoph Lameter, David Rientjes, Roman Gushchin, linu...@kvack.org, linux-...@vger.kernel.org, kasa...@googlegroups.com, kernel test robot


On 7/21/26 6:19 PM, Marco Elver wrote:
> Sparse does not know __builtin_infer_alloc_token() and complains:
>
> sparse: sparse: undefined identifier '__builtin_infer_alloc_token'
>
> Fix it by using a dummy variant of __kmalloc_token() if __CHECKER__ is
> defined.
>
> Fixes: feb662d9168b ("slab: support for compiler-assisted type-based slab cache partitioning")
> Reported-by: kernel test robot <l...@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202607110912...@intel.com/
> Signed-off-by: Marco Elver <el...@google.com>
> ---

FWIW,
Acked-by: Harry Yoo (Oracle) <ha...@kernel.org>

> include/linux/slab.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 51f03f18c9a7..7ffe152ce483 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -505,8 +505,12 @@ typedef struct { unsigned long v; } kmalloc_token_t;
> extern unsigned long random_kmalloc_seed;
> #define __kmalloc_token(...) ((kmalloc_token_t){ .v = _CODE_LOCATION_ })
> #elif defined(CONFIG_KMALLOC_PARTITION_TYPED)
> +#ifdef __CHECKER__
> +#define __kmalloc_token(...) ((kmalloc_token_t){ .v = 0 })
> +#else /* !__CHECKER__ */
> #define __kmalloc_token(...) ((kmalloc_token_t){ .v = __builtin_infer_alloc_token(__VA_ARGS__) })
> -#endif
> +#endif /* __CHECKER__ */
> +#endif /* CONFIG_KMALLOC_PARTITION_TYPED */
> #define DECL_TOKEN_PARAM(_token) , kmalloc_token_t (_token)
> #define _PASS_TOKEN_PARAM(_token) , (_token)
> #define PASS_TOKEN_PARAM(_token) (_token)

--
Cheers,
Harry / Hyeonggon
OpenPGP_signature.asc
Reply all
Reply to author
Forward
0 new messages