All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm, slub: Fix support for clang 10
@ 2021-05-18 18:12 Hyeonggon Yoo
  2021-05-18 18:16 ` Hyeonggon Yoo
  2021-05-18 20:30   ` Nick Desaulniers
  0 siblings, 2 replies; 5+ messages in thread
From: Hyeonggon Yoo @ 2021-05-18 18:12 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Nathan Chancellor,
	Nick Desaulniers, Stephen Rothwell
  Cc: linux-mm, linux-kernel, clang-built-linux, Naresh Kamboju

Previously in 'commit ff3daafe3fd3 ("mm, slub: change run-time assertion
in kmalloc_index() to compile-time")', changed kmalloc_index's run-time
assertion to compile-time assertion.

But clang 10 has a bug misevaluating __builtin_constant_p() as true,
making it unable to compile. This bug was fixed in clang 11.

To support clang 10, introduce a macro to do run-time assertion if clang
version is less than 11, even if the size is constant. Might revert this
commit later if we choose not to support clang 10.

Fixes: ff3daafe3fd3 ("mm, slub: change run-time assertion in kmalloc_index() to compile-time")
Link: https://lore.kernel.org/r/CA+G9fYvYxqVhUTkertjZjcrUq8LWPnO7qC==Wum3gYCwWF9D6Q@mail.gmail.com/
Link: https://lkml.org/lkml/2021/5/11/872
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
---
 include/linux/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 9d316aac0aba..8d8dd8571261 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -413,7 +413,7 @@ static __always_inline unsigned int __kmalloc_index(size_t size,
 	if (size <=  16 * 1024 * 1024) return 24;
 	if (size <=  32 * 1024 * 1024) return 25;
 
-	if (size_is_constant)
+	if ((IS_ENABLED(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 110000) && size_is_constant)
 		BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
 	else
 		BUG();
-- 
2.25.1


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

* Re: [PATCH] mm, slub: Fix support for clang 10
  2021-05-18 18:12 [PATCH] mm, slub: Fix support for clang 10 Hyeonggon Yoo
@ 2021-05-18 18:16 ` Hyeonggon Yoo
  2021-05-18 18:21   ` Hyeonggon Yoo
  2021-05-18 20:30   ` Nick Desaulniers
  1 sibling, 1 reply; 5+ messages in thread
From: Hyeonggon Yoo @ 2021-05-18 18:16 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Nathan Chancellor,
	Nick Desaulniers, Stephen Rothwell
  Cc: linux-mm, linux-kernel, clang-built-linux, Naresh Kamboju

Nathan, Thank you for suggesting the idea and allowing me to write the patch.

it compiled and booted without problem when compiled with gcc-10.2.0,
clang-10.0.1, clang-11.0.0 with x86_64 default config.

Thanks,
Hyeonggon

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

* Re: [PATCH] mm, slub: Fix support for clang 10
  2021-05-18 18:16 ` Hyeonggon Yoo
@ 2021-05-18 18:21   ` Hyeonggon Yoo
  0 siblings, 0 replies; 5+ messages in thread
From: Hyeonggon Yoo @ 2021-05-18 18:21 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Nathan Chancellor,
	Nick Desaulniers, Stephen Rothwell
  Cc: linux-mm, linux-kernel, clang-built-linux, Naresh Kamboju

And Naresh, Thank you for reporting the problem!

If there's any problem with it or I can improve anything,
any feedback will be welcomed. and I'll reply soon.

Thanks,
Hyeonggon

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

* Re: [PATCH] mm, slub: Fix support for clang 10
  2021-05-18 18:12 [PATCH] mm, slub: Fix support for clang 10 Hyeonggon Yoo
@ 2021-05-18 20:30   ` Nick Desaulniers
  2021-05-18 20:30   ` Nick Desaulniers
  1 sibling, 0 replies; 5+ messages in thread
From: Nick Desaulniers @ 2021-05-18 20:30 UTC (permalink / raw)
  To: Hyeonggon Yoo
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Nathan Chancellor,
	Stephen Rothwell, Linux Memory Management List, LKML,
	clang-built-linux, Naresh Kamboju

On Tue, May 18, 2021 at 11:12 AM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote:
>
> Previously in 'commit ff3daafe3fd3 ("mm, slub: change run-time assertion
> in kmalloc_index() to compile-time")', changed kmalloc_index's run-time
> assertion to compile-time assertion.
>
> But clang 10 has a bug misevaluating __builtin_constant_p() as true,
> making it unable to compile. This bug was fixed in clang 11.
>
> To support clang 10, introduce a macro to do run-time assertion if clang
> version is less than 11, even if the size is constant. Might revert this
> commit later if we choose not to support clang 10.
>
> Fixes: ff3daafe3fd3 ("mm, slub: change run-time assertion in kmalloc_index() to compile-time")
> Link: https://lore.kernel.org/r/CA+G9fYvYxqVhUTkertjZjcrUq8LWPnO7qC==Wum3gYCwWF9D6Q@mail.gmail.com/
> Link: https://lkml.org/lkml/2021/5/11/872
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>

Thanks for the patch; hopefully this isn't too much burden in order to
help us support clang-10 a little bit longer.  We will rip it out when
dropping clang-10 someday; grepping for CLANG_VERSION should turn this
up easily.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  include/linux/slab.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 9d316aac0aba..8d8dd8571261 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -413,7 +413,7 @@ static __always_inline unsigned int __kmalloc_index(size_t size,
>         if (size <=  16 * 1024 * 1024) return 24;
>         if (size <=  32 * 1024 * 1024) return 25;
>
> -       if (size_is_constant)
> +       if ((IS_ENABLED(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 110000) && size_is_constant)
>                 BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
>         else
>                 BUG();
> --
> 2.25.1
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] mm, slub: Fix support for clang 10
@ 2021-05-18 20:30   ` Nick Desaulniers
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Desaulniers @ 2021-05-18 20:30 UTC (permalink / raw)
  To: Hyeonggon Yoo
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Nathan Chancellor,
	Stephen Rothwell, Linux Memory Management List, LKML,
	clang-built-linux, Naresh Kamboju

On Tue, May 18, 2021 at 11:12 AM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote:
>
> Previously in 'commit ff3daafe3fd3 ("mm, slub: change run-time assertion
> in kmalloc_index() to compile-time")', changed kmalloc_index's run-time
> assertion to compile-time assertion.
>
> But clang 10 has a bug misevaluating __builtin_constant_p() as true,
> making it unable to compile. This bug was fixed in clang 11.
>
> To support clang 10, introduce a macro to do run-time assertion if clang
> version is less than 11, even if the size is constant. Might revert this
> commit later if we choose not to support clang 10.
>
> Fixes: ff3daafe3fd3 ("mm, slub: change run-time assertion in kmalloc_index() to compile-time")
> Link: https://lore.kernel.org/r/CA+G9fYvYxqVhUTkertjZjcrUq8LWPnO7qC==Wum3gYCwWF9D6Q@mail.gmail.com/
> Link: https://lkml.org/lkml/2021/5/11/872
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>

Thanks for the patch; hopefully this isn't too much burden in order to
help us support clang-10 a little bit longer.  We will rip it out when
dropping clang-10 someday; grepping for CLANG_VERSION should turn this
up easily.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  include/linux/slab.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 9d316aac0aba..8d8dd8571261 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -413,7 +413,7 @@ static __always_inline unsigned int __kmalloc_index(size_t size,
>         if (size <=  16 * 1024 * 1024) return 24;
>         if (size <=  32 * 1024 * 1024) return 25;
>
> -       if (size_is_constant)
> +       if ((IS_ENABLED(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 110000) && size_is_constant)
>                 BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
>         else
>                 BUG();
> --
> 2.25.1
>


-- 
Thanks,
~Nick Desaulniers


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

end of thread, other threads:[~2021-05-18 20:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 18:12 [PATCH] mm, slub: Fix support for clang 10 Hyeonggon Yoo
2021-05-18 18:16 ` Hyeonggon Yoo
2021-05-18 18:21   ` Hyeonggon Yoo
2021-05-18 20:30 ` Nick Desaulniers
2021-05-18 20:30   ` Nick Desaulniers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.