mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] slab: silence sparse warning with type-based partitioning
@ 2026-07-21  9:19 Marco Elver
  2026-07-21  9:30 ` Vlastimil Babka (SUSE)
  2026-07-22  7:08 ` Harry Yoo
  0 siblings, 2 replies; 3+ messages in thread
From: Marco Elver @ 2026-07-21  9:19 UTC (permalink / raw)
  To: elver, Vlastimil Babka, Andrew Morton
  Cc: Harry Yoo, Hao Li, Christoph Lameter, David Rientjes,
	Roman Gushchin, linux-mm, linux-kernel, kasan-dev,
	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 <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202607110912.nZTqfCrH-lkp@intel.com/
Signed-off-by: Marco Elver <elver@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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] slab: silence sparse warning with type-based partitioning
  2026-07-21  9:19 [PATCH] slab: silence sparse warning with type-based partitioning Marco Elver
@ 2026-07-21  9:30 ` Vlastimil Babka (SUSE)
  2026-07-22  7:08 ` Harry Yoo
  1 sibling, 0 replies; 3+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-07-21  9:30 UTC (permalink / raw)
  To: Marco Elver, Andrew Morton, Chris Li
  Cc: Harry Yoo, Hao Li, Christoph Lameter, David Rientjes,
	Roman Gushchin, linux-mm, linux-kernel, kasan-dev,
	kernel test robot, linux-sparse

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 <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202607110912.nZTqfCrH-lkp@intel.com/
> Signed-off-by: Marco Elver <elver@google.com>

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

> ---
>  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)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] slab: silence sparse warning with type-based partitioning
  2026-07-21  9:19 [PATCH] slab: silence sparse warning with type-based partitioning Marco Elver
  2026-07-21  9:30 ` Vlastimil Babka (SUSE)
@ 2026-07-22  7:08 ` Harry Yoo
  1 sibling, 0 replies; 3+ messages in thread
From: Harry Yoo @ 2026-07-22  7:08 UTC (permalink / raw)
  To: Marco Elver, Vlastimil Babka, Andrew Morton
  Cc: Hao Li, Christoph Lameter, David Rientjes, Roman Gushchin,
	linux-mm, linux-kernel, kasan-dev, kernel test robot


[-- Attachment #1.1: Type: text/plain, Size: 1635 bytes --]



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 <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202607110912.nZTqfCrH-lkp@intel.com/
> Signed-off-by: Marco Elver <elver@google.com>
> ---

FWIW,
Acked-by: Harry Yoo (Oracle) <harry@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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-22  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-21  9:19 [PATCH] slab: silence sparse warning with type-based partitioning Marco Elver
2026-07-21  9:30 ` Vlastimil Babka (SUSE)
2026-07-22  7:08 ` Harry Yoo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®