All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: kernel test robot <lkp@intel.com>,
	kbuild-all@lists.01.org,
	Linux Memory Management List <linux-mm@kvack.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>
Subject: [PATCH FIX -next] Re: [linux-next:master 7012/7430] include/linux/compiler_types.h:328:38: error: call to '__compiletime_assert_183' declared with attribute error: unexpected size in kmalloc_index()
Date: Mon, 14 Jun 2021 11:26:48 +0200	[thread overview]
Message-ID: <bea97388-01df-8eac-091b-a3c89b4a4a09@suse.cz> (raw)
In-Reply-To: <CAB=+i9SbDgMJSo91Wt4ZfkgWW3+8R49_7Uhn5FCbBXt-SX+osg@mail.gmail.com>


On 6/12/21 2:19 AM, Hyeonggon Yoo wrote:
> On Sat, Jun 12, 2021, 8:59 AM Vlastimil Babka <vbabka@suse.cz
> <mailto:vbabka@suse.cz>> wrote:
> 
> 
>     > But little bit worried :(
>     > The code is getting too complicated...
>     > How do you think?
> 
>     Yeah, I expected that problems like this could occur as we're poking at some
>     rare corner cases of compiler implementations here. But if that leads to fixes
>     in compilers, good for everyone I'd say.
> 
>     So I would try this, even if it becomes complicated.
> 
> 
> Okay, I see the code is okay, but one thing to suggest:
>     The problem already existed in kmalloc_node before the patch And we found it
> by adding BUILD_BUG_ON in kmalloc_index.
> 
>     So I suggest adding the condition in kmalloc_node. How about this?
> 

If we add it to kmalloc_node() it means with CONFIG_PROFILE_ALL_BRANCHES we will
not be using the compile-time optimized kmalloc_index anywhere. But we get the
error only with one file, so in all the other cases the gcc optimizer seems to
work fine even with this config enabled. Placing the condition to
kmalloc_index() thus limits it only to cases where it doesn't work.

As you indicated you would be away starting this week, let me just sent the fix
right now so we stop getting the -next reports:

----8<----
From 56c164dc5c0485c2e133190c0f56e4069844ad62 Mon Sep 17 00:00:00 2001
From: Vlastimil Babka <vbabka@suse.cz>
Date: Mon, 14 Jun 2021 11:16:03 +0200
Subject: [PATCH] 
 mm-slub-change-run-time-assertion-in-kmalloc_index-to-compile-time-fix-3

Kernel test robot reports a false-positive compile-time assert while compiling
kernel/bpf/local_storage.c

   In file included from <command-line>:
   In function 'kmalloc_index',
       inlined from 'kmalloc_node' at include/linux/slab.h:572:20,
       inlined from 'bpf_map_kmalloc_node.isra.0.part.0' at include/linux/bpf.h:1319:9:
>> >> include/linux/compiler_types.h:328:38: error: call to '__compiletime_assert_183' declared with attribute error: unexpected size in kmalloc_index()
     328 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |                                      ^
   include/linux/compiler_types.h:309:4: note: in definition of macro '__compiletime_assert'
     309 |    prefix ## suffix();    \
         |    ^~~~~~
   include/linux/compiler_types.h:328:2: note: in expansion of macro '_compiletime_assert'
     328 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |  ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/slab.h:389:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     389 |  BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
         |  ^~~~~~~~~~~~~~~~

This only happens with CONFIG_PROFILE_ALL_BRANCHES enabled. Informal
conversation with gcc developers suggest that this config pushes the optimizer
to a corner case where in kmalloc_node() the 'size' is considered a
builtin-constant and thus kmalloc_index() is chosen, but later in
kmalloc_index() the notion of compile-time constant is lost and thus the
compiletime assert becomes reachable.

While there's plan to submit a proper gcc bug report with reduced testcase,
for now add CONFIG_PROFILE_ALL_BRANCHES to the list of situations where we
keep using the runtime BUG_ON() instead of compile-time assert.

This is a 3rd fix for mmotm patch
mm-slub-change-run-time-assertion-in-kmalloc_index-to-compile-time.patch

[1] https://lore.kernel.org/linux-mm/202106051442.G1VJubTz-lkp@intel.com/

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 include/linux/slab.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 8d8dd8571261..083f3ce550bc 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -413,7 +413,8 @@ 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 ((IS_ENABLED(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 110000) && size_is_constant)
+	if ((IS_ENABLED(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 110000)
+	    && !IS_ENABLED(CONFIG_PROFILE_ALL_BRANCHES) && size_is_constant)
 		BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
 	else
 		BUG();
-- 
2.32.0



      reply	other threads:[~2021-06-14  9:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-05  6:10 kernel test robot
2021-06-06 11:08 ` Hyeonggon Yoo
2021-06-07 11:40   ` Vlastimil Babka
2021-06-07 12:25     ` Hyeonggon Yoo
2021-06-07 15:27       ` Vlastimil Babka
2021-06-07 15:49         ` Hyeonggon Yoo
2021-06-08  7:57           ` Vlastimil Babka
2021-06-08 17:05             ` Hyeonggon Yoo
2021-06-08 17:27               ` Vlastimil Babka
2021-06-08 18:45                 ` Hyeonggon Yoo
2021-06-08 18:50                   ` Hyeonggon Yoo
2021-06-10  5:17                   ` Some logical errors on my words, but I still wonder Hyeonggon Yoo
2021-06-10 11:43                   ` [linux-next:master 7012/7430] include/linux/compiler_types.h:328:38: error: call to '__compiletime_assert_183' declared with attribute error: unexpected size in kmalloc_index() Vlastimil Babka
     [not found]                     ` <CAB=+i9StdrGQWXXoQHKU5oLK3eKuNcuCAbrd88kPLzM_Yw==Jg@mail.gmail.com>
2021-06-11 16:56                       ` Nathan Chancellor
2021-06-12  0:31                         ` Hyeonggon Yoo
     [not found]                       ` <d89798b1-ac4f-ab3e-27be-b1d40b8d7193@suse.cz>
     [not found]                         ` <CAB=+i9Snmu7ML3Zqrbii1-jtS0BF_KeGEhn-R49Z2bh=uW-rGg@mail.gmail.com>
2021-06-11 23:59                           ` Vlastimil Babka
2021-06-12  0:19                             ` Hyeonggon Yoo
2021-06-14  9:26                               ` Vlastimil Babka [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=bea97388-01df-8eac-091b-a3c89b4a4a09@suse.cz \
    --to=vbabka@suse.cz \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --subject='[PATCH FIX -next] Re: [linux-next:master 7012/7430] include/linux/compiler_types.h:328:38: error: call to '\''__compiletime_assert_183'\'' declared with attribute error: unexpected size in kmalloc_index()' \
    /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

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.