smp: fix smp_call_function_single_async prototype
PATCH 1/1 smp: fix smp_call_function_single_async prototype
From: Arnd Bergmann <[email protected]>
As of commit 966a967116e6 ("smp: Avoid using two cache lines for struct call_single_data"), the smp code prefers 32-byte aligned call_single_data objects for performance reasons, but the block layer includes an instance of this structure in the main 'struct request' that is more senstive to size than to performance here, see 4ccafe032005 ("block: unalign call_single_data in struct request").
The result is a violation of the calling conventions that clang correctly points out:
block/blk-mq.c:630:39: warning: passing 8-byte aligned argument to 32-byte aligned parameter 2 of 'smp_call_function_single_async' may result in an unaligned pointer access [-Walign-mismatch]
smp_call_function_single_async(cpu, &rq->csd);
It does seem that the usage of the call_single_data without cache line alignment should still be allowed by the smp code, so just change the function prototype so it accepts both, but leave the default alignment unchanged for the other users. This seems better to me than adding a local hack to shut up an otherwise correct warning in the caller.
--- include/linux/smp.h | 2 +- kernel/smp.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/smp.h +1 -1
@@ -53,7 +53,7 @@ int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,void on_each_cpu_cond_mask (smp_cond_func_t cond_func,smp_call_func_t func,void *info,bool wait,const struct cpumask *mask); -int smp_call_function_single_async (int cpu,call_single_data_t *csd); +int smp_call_function_single_async (int cpu,struct __call_single_data *csd);/* * Cpus stopping functions in panic. All have default weak definitions.
kernel/smp.c +3 -3
@@ -401,7 +401,7 @@ static void __csd_lock_wait(call_single_data_t *csd)smp_acquire__after_ctrl_dep (); } -static __always_inline void csd_lock_wait(call_single_data_t *csd) +static __always_inline void csd_lock_wait(struct __call_single_data *csd) {if (static_branch_unlikely (&csdlock_debug_enabled)) {__csd_lock_wait (csd);
@@ -501,7 +501,7 @@ void __smp_call_single_queue(int cpu, struct llist_node *node)* for execution on the given CPU. data must already have * ->func, ->info, and ->flags set. */ -static int generic_exec_single (int cpu,call_single_data_t *csd) +static int generic_exec_single (int cpu,struct __call_single_data *csd) {if (cpu ==smp_processor_id ()) {smp_call_func_t func = csd->func;
@@ -784,7 +784,7 @@ EXPORT_SYMBOL(smp_call_function_single);* NOTE: Be careful, there is unfortunately no current debugging facility to * validate the correctness of this serialization. */ -int smp_call_function_single_async (int cpu,call_single_data_t *csd) +int smp_call_function_single_async (int cpu,struct __call_single_data *csd) {int err =0 ;
Signature · 1 line
2.29.2
Quoted 12 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
As of commit
966a967116e6("smp: Avoid using two cache lines for structcall_single_data"), the smp code prefers 32-byte alignedcall_single_dataobjects for performance reasons, but the block layer includes an instance of this structure in the main 'struct request' that is more senstive to size than to performance here, see4ccafe032005("block: unaligncall_single_datain struct request").The result is a violation of the calling conventions that clang correctly points out:
Quoted 8 lines
block/blk-mq.c:630:39: warning: passing 8-byte aligned argument to 32-byte aligned parameter 2 of 'smp_call_function_single_async' may result in an unaligned pointer access [-Walign-mismatch]smp_call_function_single_async(cpu, &rq->csd);It does seem that the usage of the
call_single_datawithout cache line alignment should still be allowed by the smp code, so just change the function prototype so it accepts both, but leave the default alignment unchanged for the other users. This seems better to me than adding a local hack to shut up an otherwise correct warning in the caller.
I think that's the right approach, rather than work-around it in eg blk-mq.
Signature · 1 line
Jens Axboe
(replying manually to
https://lore.kernel.org/lkml/[email protected]/)
Thanks for the patch; with this applied I observe the following new warnings though (for x86_64 defconfig; make LLVM=1 LLVM_IAS=1 -j72)
kernel/smp.c:515:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_lock_record' may result in an unaligned pointer access [-Walign-mismatch]
csd_lock_record(csd);
^
kernel/smp.c:516:14: warning: passing 8-byte aligned argument to 32-byte
aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access
[-Walign-mismatch]
csd_unlock(csd);
^
kernel/smp.c:525:14: warning: passing 8-byte aligned argument to 32-byte
aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access
[-Walign-mismatch]
csd_unlock(csd);
^Quoted 10 lines · Nick Desaulniers
(replying manually to
https://lore.kernel.org/lkml/[email protected]/)Thanks for the patch; with this applied I observe the following new warnings though (for
x86_64defconfig; make LLVM=1 LLVM_IAS=1 -j72)
kernel/smp.c:515:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_lock_record' may result in an unaligned pointer access [-Walign-mismatch]
Quoted 12 lines
csd_lock_record(csd);
^
kernel/smp.c:516:14: warning: passing 8-byte aligned argument to 32-byte
aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access
[-Walign-mismatch]
csd_unlock(csd);
^
kernel/smp.c:525:14: warning: passing 8-byte aligned argument to 32-byte
aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access
[-Walign-mismatch]
csd_unlock(csd);
^Perhaps roll this into a v2?
kernel/smp.c +1 -1
@@ -226,7 +226,7 @@ static void __csd_lock_record(call_single_data_t *csd)/* Or before unlock, as the case may be. */ } -static __always_inline void csd_lock_record(call_single_data_t *csd) +static __always_inline void csd_lock_record(struct __call_single_data *csd) {if (static_branch_unlikely (&csdlock_debug_enabled))__csd_lock_record (csd);
@@ -431,7 +431,7 @@ static void __smp_call_single_queue_debug(int cpu,
struct llist_node *node)
#else
#define cfd_seq_store(var, src, dst, type)
-static void csd_lock_record(call_single_data_t *csd) +static void csd_lock_record(struct __call_single_data *csd)
{
}
@@ -454,7 +454,7 @@ static __always_inline voidcsd_lock(call_single_data_t *csd)
smp_wmb();
}
-static __always_inline void csd_unlock(call_single_data_t *csd) +static __always_inline void csd_unlock(struct __call_single_data *csd)
{
WARN_ON(!(csd->node.u_flags & CSD_FLAG_LOCK));Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 26 lines · Nick Desaulniers' via Clang Built Linux
Quoted 10 lines · Nick Desaulniers
(replying manually to
https://lore.kernel.org/lkml/[email protected]/)Thanks for the patch; with this applied I observe the following new warnings though (for
x86_64defconfig; make LLVM=1 LLVM_IAS=1 -j72)
kernel/smp.c:515:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_lock_record' may result in an unaligned pointer access [-Walign-mismatch]Quoted 12 lines
csd_lock_record(csd); ^ kernel/smp.c:516:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch] csd_unlock(csd); ^ kernel/smp.c:525:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch] csd_unlock(csd); ^
Quoted 2 lines
Perhaps roll this into a v2?
Right, I just did the same thing. I wonder if I failed to hit those because of differences in configuration or because I tested the wrong way.
Either way, I'll give it some more time on the randconfig build machine before I send out v2.
Arnd
Quoted 3 lines · Arnd Bergmann
Either way, I'll give it some more time on the randconfig build machine before I send out v2.
SGTM and thanks for the fix. Perhaps worth a note that this isn't just "a violation of the calling conventions" but straight up undefined behavior, full stop.
UBSAN folks are working on adding a catch for this as well:
https://reviews.llvm.org/D100037, see the relevant citations from the standard.
Signature · 2 lines
Thanks, ~Nick Desaulniers
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Arnd,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20210429]
[cannot apply to linux/master soc/for-next linus/master v5.12 v5.12-rc8 v5.12-rc7 v5.12] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/smp-fix-smp_call_function_single_async-prototype/20210429-231235 base: 9e5cff2a1315fec1da1f497714395670366506b6 config: x86_64-randconfig-a013-20210429 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9131a078901b00e68248a27a4f8c4b11bb1db1ae)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/be40015a8e0990182fa440f75adecf40cf5d0062
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arnd-Bergmann/smp-fix-smp_call_function_single_async-prototype/20210429-231235 git checkout be40015a8e0990182fa440f75adecf40cf5d0062
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/smp.c:515:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_lock_record' may result in an unaligned pointer access [-Walign-mismatch]
csd_lock_record(csd);
^
>> kernel/smp.c:516:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch]
csd_unlock(csd);
^
kernel/smp.c:525:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch]
csd_unlock(csd);
^
kernel/smp.c:684:6: warning: no previous prototype for function 'flush_smp_call_function_from_idle' [-Wmissing-prototypes]
void flush_smp_call_function_from_idle(void)
^ kernel/smp.c:684:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void flush_smp_call_function_from_idle(void)
^
static
4 warnings generated.
vim +/csd_lock_record +515 kernel/smp.c
4b44a21dd640b6 Peter Zijlstra 2020-05-26 498
3d4422332711ef Jens Axboe 2008-06-26 499 /*
966a967116e699 Ying Huang 2017-08-08 500 * Insert a previously allocated call_single_data_t element
0b13fda1e0936b Ingo Molnar 2009-02-25 501 * for execution on the given CPU. data must already have
0b13fda1e0936b Ingo Molnar 2009-02-25 502 * ->func, ->info, and ->flags set.
3d4422332711ef Jens Axboe 2008-06-26 503 */
be40015a8e0990 Arnd Bergmann 2021-04-29 504 static int generic_exec_single(int cpu, struct __call_single_data *csd)
3d4422332711ef Jens Axboe 2008-06-26 505 {
8053871d0f7f67 Linus Torvalds 2015-02-11 506 if (cpu == smp_processor_id()) {
4b44a21dd640b6 Peter Zijlstra 2020-05-26 507 smp_call_func_t func = csd->func;
4b44a21dd640b6 Peter Zijlstra 2020-05-26 508 void *info = csd->info;
8b28499a71d343 Frederic Weisbecker 2014-02-24 509 unsigned long flags;
8b28499a71d343 Frederic Weisbecker 2014-02-24 510
8053871d0f7f67 Linus Torvalds 2015-02-11 511 /*
8053871d0f7f67 Linus Torvalds 2015-02-11 512 * We can unlock early even for the synchronous on-stack case,
8053871d0f7f67 Linus Torvalds 2015-02-11 513 * since we're doing this from the same CPU..
8053871d0f7f67 Linus Torvalds 2015-02-11 514 */
35feb60474bf4f Paul E. McKenney 2020-06-30 @515 csd_lock_record(csd);
8053871d0f7f67 Linus Torvalds 2015-02-11 @516 csd_unlock(csd);
8b28499a71d343 Frederic Weisbecker 2014-02-24 517 local_irq_save(flags);
8b28499a71d343 Frederic Weisbecker 2014-02-24 518 func(info);
35feb60474bf4f Paul E. McKenney 2020-06-30 519 csd_lock_record(NULL);
8b28499a71d343 Frederic Weisbecker 2014-02-24 520 local_irq_restore(flags);
8b28499a71d343 Frederic Weisbecker 2014-02-24 521 return 0;
8b28499a71d343 Frederic Weisbecker 2014-02-24 522 }
8b28499a71d343 Frederic Weisbecker 2014-02-24 523
5224b9613b91d9 Linus Torvalds 2015-04-19 524 if ((unsigned)cpu >= nr_cpu_ids || !cpu_online(cpu)) {
5224b9613b91d9 Linus Torvalds 2015-04-19 525 csd_unlock(csd);
8b28499a71d343 Frederic Weisbecker 2014-02-24 526 return -ENXIO;
5224b9613b91d9 Linus Torvalds 2015-04-19 527 }
8b28499a71d343 Frederic Weisbecker 2014-02-24 528
545b8c8df41f9e Peter Zijlstra 2020-06-15 529 __smp_call_single_queue(cpu, &csd->node.llist);
3d4422332711ef Jens Axboe 2008-06-26 530
8b28499a71d343 Frederic Weisbecker 2014-02-24 531 return 0;
3d4422332711ef Jens Axboe 2008-06-26 532 }
3d4422332711ef Jens Axboe 2008-06-26 533 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Arnd,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20210429]
[cannot apply to linux/master soc/for-next linus/master v5.12 v5.12-rc8 v5.12-rc7 v5.12] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/smp-fix-smp_call_function_single_async-prototype/20210429-231235 base: 9e5cff2a1315fec1da1f497714395670366506b6 config: arm64-randconfig-r022-20210429 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9131a078901b00e68248a27a4f8c4b11bb1db1ae)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/be40015a8e0990182fa440f75adecf40cf5d0062
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arnd-Bergmann/smp-fix-smp_call_function_single_async-prototype/20210429-231235 git checkout be40015a8e0990182fa440f75adecf40cf5d0062
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/smp.c:407:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of '__csd_lock_wait' may result in an unaligned pointer access [-Walign-mismatch]
__csd_lock_wait(csd);
^
kernel/smp.c:515:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_lock_record' may result in an unaligned pointer access [-Walign-mismatch]
csd_lock_record(csd);
^
kernel/smp.c:516:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch]
csd_unlock(csd);
^
kernel/smp.c:525:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch]
csd_unlock(csd);
^
kernel/smp.c:684:6: warning: no previous prototype for function 'flush_smp_call_function_from_idle' [-Wmissing-prototypes]
void flush_smp_call_function_from_idle(void)
^ kernel/smp.c:684:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void flush_smp_call_function_from_idle(void)
^
static
5 warnings generated.
vim +/__csd_lock_wait +407 kernel/smp.c
35feb60474bf4f Paul E. McKenney 2020-06-30 403
be40015a8e0990 Arnd Bergmann 2021-04-29 404 static __always_inline void csd_lock_wait(struct __call_single_data *csd)
8d0968cc6b8ffd Juergen Gross 2021-03-01 405 {
8d0968cc6b8ffd Juergen Gross 2021-03-01 406 if (static_branch_unlikely(&csdlock_debug_enabled)) {
8d0968cc6b8ffd Juergen Gross 2021-03-01 @407 __csd_lock_wait(csd);
8d0968cc6b8ffd Juergen Gross 2021-03-01 408 return;
8d0968cc6b8ffd Juergen Gross 2021-03-01 409 }
8d0968cc6b8ffd Juergen Gross 2021-03-01 410
8d0968cc6b8ffd Juergen Gross 2021-03-01 411 smp_cond_load_acquire(&csd->node.u_flags, !(VAL & CSD_FLAG_LOCK));
8d0968cc6b8ffd Juergen Gross 2021-03-01 412 }
a5aabace5fb8ab Juergen Gross 2021-03-01 413 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Thanks for the patch! Some of the stable kernels also have this warning, but they don't seem to have the dependencies (4.14, 4,19, 5.4). Do we plan to fix those branches as well?
Quoted 71 lines · kernel test robot
Hi Arnd,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20210429]
[cannot apply to linux/master soc/for-next linus/master v5.12 v5.12-rc8 v5.12-rc7 v5.12] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/smp-fix-smp_call_function_single_async-prototype/20210429-231235 base: 9e5cff2a1315fec1da1f497714395670366506b6 config: arm64-randconfig-r022-20210429 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9131a078901b00e68248a27a4f8c4b11bb1db1ae)reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/be40015a8e0990182fa440f75adecf40cf5d0062
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arnd-Bergmann/smp-fix-smp_call_function_single_async-prototype/20210429-231235 git checkoutbe40015a8e0990182fa440f75adecf40cf5d0062
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=arm64If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
kernel/smp.c:407:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of '__csd_lock_wait' may result in an unaligned pointer access [-Walign-mismatch]__csd_lock_wait(csd); ^ kernel/smp.c:515:19: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_lock_record' may result in an unaligned pointer access [-Walign-mismatch] csd_lock_record(csd); ^ kernel/smp.c:516:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch] csd_unlock(csd); ^ kernel/smp.c:525:14: warning: passing 8-byte aligned argument to 32-byte aligned parameter 1 of 'csd_unlock' may result in an unaligned pointer access [-Walign-mismatch] csd_unlock(csd); ^ kernel/smp.c:684:6: warning: no previous prototype for function 'flush_smp_call_function_from_idle' [-Wmissing-prototypes] void flush_smp_call_function_from_idle(void) ^
kernel/smp.c:684:1: note: declare 'static' if the function is not intended to be used outside of this translation unit voidflush_smp_call_function_from_idle(void)
^
static
5 warnings generated.vim +/__csd_lock_wait +407
kernel/smp.c35feb60474bf4f Paul E. McKenney 2020-06-30 403 be40015a8e0990 Arnd Bergmann 2021-04-29 404 static __always_inline void csd_lock_wait(struct __call_single_data *csd) 8d0968cc6b8ffd Juergen Gross 2021-03-01 405 { 8d0968cc6b8ffd Juergen Gross 2021-03-01 406 if (static_branch_unlikely(&csdlock_debug_enabled)) { 8d0968cc6b8ffd Juergen Gross 2021-03-01 @407 __csd_lock_wait(csd); 8d0968cc6b8ffd Juergen Gross 2021-03-01 408 return; 8d0968cc6b8ffd Juergen Gross 2021-03-01 409 } 8d0968cc6b8ffd Juergen Gross 2021-03-01 410 8d0968cc6b8ffd Juergen Gross 2021-03-01 411 smp_cond_load_acquire(&csd->node.u_flags, !(VAL & CSD_FLAG_LOCK)); 8d0968cc6b8ffd Juergen Gross 2021-03-01 412 } a5aabace5fb8ab Juergen Gross 2021-03-01 413---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org