arch/x86/kernel/cpu/sgx/main.c:496:7: warning: variable 'nid' is used uninitialized whenever 'if' condition is false
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/sgx head: 5b8719504e3adf47646273781591ad439b3c3c7a commit: 5b8719504e3adf47646273781591ad439b3c3c7a [2/2] x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page() config: x86_64-randconfig-r004-20210318 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 6db3ab2903f42712f44000afb5aa467efbd25f35)
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://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=5b8719504e3adf47646273781591ad439b3c3c7a
git remote add tip https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
git fetch --no-tags tip x86/sgx
git checkout 5b8719504e3adf47646273781591ad439b3c3c7a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> arch/x86/kernel/cpu/sgx/main.c:496:7: warning: variable 'nid' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (page)
^~~~
arch/x86/kernel/cpu/sgx/main.c:502:22: note: uninitialized use occurs here
nid = next_node_in(nid, sgx_numa_mask);
^~~
include/linux/nodemask.h:278:46: note: expanded from macro 'next_node_in'
#define next_node_in(n, src) __next_node_in((n), &(src))
^
arch/x86/kernel/cpu/sgx/main.c:496:3: note: remove the 'if' if its condition is always true
if (page)
^~~~~~~~~
arch/x86/kernel/cpu/sgx/main.c:494:6: warning: variable 'nid' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (node_isset(nid_of_current, sgx_numa_mask)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/nodemask.h:152:36: note: expanded from macro 'node_isset'
#define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/cpu/sgx/main.c:502:22: note: uninitialized use occurs here
nid = next_node_in(nid, sgx_numa_mask);
^~~
include/linux/nodemask.h:278:46: note: expanded from macro 'next_node_in'
#define next_node_in(n, src) __next_node_in((n), &(src))
^
arch/x86/kernel/cpu/sgx/main.c:494:2: note: remove the 'if' if its condition is always true
if (node_isset(nid_of_current, sgx_numa_mask)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/cpu/sgx/main.c:492:9: note: initialize the variable 'nid' to silence this warning
int nid;
^
= 02 warnings generated.
vim +496 arch/x86/kernel/cpu/sgx/main.c
d2285493bef310 Jarkko Sakkinen 2020-11-13 477
d2285493bef310 Jarkko Sakkinen 2020-11-13 478 /**
d2285493bef310 Jarkko Sakkinen 2020-11-13 479 * __sgx_alloc_epc_page() - Allocate an EPC page
d2285493bef310 Jarkko Sakkinen 2020-11-13 480 *
5b8719504e3adf Jarkko Sakkinen 2021-03-18 481 * Iterate through NUMA nodes and reserve ia free EPC page to the caller. Start
5b8719504e3adf Jarkko Sakkinen 2021-03-18 482 * from the NUMA node, where the caller is executing.
d2285493bef310 Jarkko Sakkinen 2020-11-13 483 *
d2285493bef310 Jarkko Sakkinen 2020-11-13 484 * Return:
5b8719504e3adf Jarkko Sakkinen 2021-03-18 485 * - an EPC page: A borrowed EPC pages were available.
5b8719504e3adf Jarkko Sakkinen 2021-03-18 486 * - NULL: Out of EPC pages.
d2285493bef310 Jarkko Sakkinen 2020-11-13 487 */
d2285493bef310 Jarkko Sakkinen 2020-11-13 488 struct sgx_epc_page *__sgx_alloc_epc_page(void)
d2285493bef310 Jarkko Sakkinen 2020-11-13 489 {
d2285493bef310 Jarkko Sakkinen 2020-11-13 490 struct sgx_epc_page *page;
5b8719504e3adf Jarkko Sakkinen 2021-03-18 491 int nid_of_current = numa_node_id();
5b8719504e3adf Jarkko Sakkinen 2021-03-18 492 int nid;
d2285493bef310 Jarkko Sakkinen 2020-11-13 493
5b8719504e3adf Jarkko Sakkinen 2021-03-18 494 if (node_isset(nid_of_current, sgx_numa_mask)) {
5b8719504e3adf Jarkko Sakkinen 2021-03-18 495 page = __sgx_alloc_epc_page_from_node(nid_of_current);
d2285493bef310 Jarkko Sakkinen 2020-11-13 @496 if (page)
d2285493bef310 Jarkko Sakkinen 2020-11-13 497 return page;
d2285493bef310 Jarkko Sakkinen 2020-11-13 498 }
d2285493bef310 Jarkko Sakkinen 2020-11-13 499
5b8719504e3adf Jarkko Sakkinen 2021-03-18 500 /* Fall back to the non-local NUMA nodes: */
5b8719504e3adf Jarkko Sakkinen 2021-03-18 501 while (true) {
5b8719504e3adf Jarkko Sakkinen 2021-03-18 502 nid = next_node_in(nid, sgx_numa_mask);
5b8719504e3adf Jarkko Sakkinen 2021-03-18 503 if (nid == nid_of_current)
5b8719504e3adf Jarkko Sakkinen 2021-03-18 504 break;
5b8719504e3adf Jarkko Sakkinen 2021-03-18 505
5b8719504e3adf Jarkko Sakkinen 2021-03-18 506 page = __sgx_alloc_epc_page_from_node(nid);
5b8719504e3adf Jarkko Sakkinen 2021-03-18 507 if (page)
5b8719504e3adf Jarkko Sakkinen 2021-03-18 508 break;
5b8719504e3adf Jarkko Sakkinen 2021-03-18 509 }
5b8719504e3adf Jarkko Sakkinen 2021-03-18 510
5b8719504e3adf Jarkko Sakkinen 2021-03-18 511 return page;
d2285493bef310 Jarkko Sakkinen 2020-11-13 512 }
d2285493bef310 Jarkko Sakkinen 2020-11-13 513 :::::: The code at line 496 was first introduced by commit
:::::: d2285493bef310b66b56dfe4eb75c1e2f431ea5c x86/sgx: Add SGX page allocator functions
:::::: TO: Jarkko Sakkinen <[email protected]>
:::::: CC: Borislav Petkov <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 1/1 x86/sgx: fix uninitialized 'nid' variable
The NUMA fallback in __sgx_alloc_epc_page() recently grew an additional 'nid' variable to prevent extra trips through the fallback loop in case where the thread is migrated around.
But, the new copy is not properly initialized. Fix it.
This was found by some fancy clang that 0day runs. My gcc does not detect it.
--- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/main.c +1 -1
@@ -489,7 +489,7 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) {struct sgx_epc_page *page;int nid_of_current =numa_node_id (); -int nid; +int nid = nid_of_current;if (node_isset (nid_of_current, sgx_numa_mask)) { page =__sgx_alloc_epc_page_from_node (nid_of_current);
Signature · 1 line
2.19.1
Re: [PATCH] x86/sgx: fix uninitialized 'nid' variable
Quoted 9 lines · Dave Hansen
The NUMA fallback in
__sgx_alloc_epc_page()recently grew an additional 'nid' variable to prevent extra trips through the fallback loop in case where the thread is migrated around.But, the new copy is not properly initialized. Fix it.
This was found by some fancy clang that 0day runs. My gcc does not detect it.
Quoted 7 lines
Fixes 5b8719504e3a ("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()")Reported-by kernel test robot <[email protected]>Signed-off-by Dave Hansen <[email protected]>Cc Jarkko Sakkinen <[email protected]>Cc Borislav Petkov <[email protected]>
Quoted 21 lines
--- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/sgx/main.c +1
-1@@ -489,7 +489,7 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) {struct sgx_epc_page *page;int nid_of_current =numa_node_id (); -int nid; +int nid = nid_of_current;if (node_isset (nid_of_current, sgx_numa_mask)) { page =__sgx_alloc_epc_page_from_node (nid_of_current);Signature · 1 line
2.19.1
/Jarkko
[tip: x86/sgx] x86/sgx: Fix uninitialized 'nid' variable
In reply to Dave HansenThe following commit has been merged into the x86/sgx branch of tip:
The following commit has been merged into the x86/sgx branch of tip:
Commit-ID: 262e88b63f55e3d2bacdf629874a0af486775572 Gitweb: https://git.kernel.org/tip/262e88b63f55e3d2bacdf629874a0af486775572 Author: Dave Hansen <[email protected]> AuthorDate: Thu, 18 Mar 2021 14:49:33 -07:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Fri, 19 Mar 2021 09:51:55 +01:00
x86/sgx: Fix uninitialized 'nid' variable
The NUMA fallback in __sgx_alloc_epc_page() recently grew an additional 'nid' variable to prevent extra trips through the fallback loop in case where the thread is migrated around.
But, the new copy is not properly initialized. Fix it.
This was found by some fancy clang that 0day runs. My gcc does not detect it.
--- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/main.c +1 -1
@@ -489,7 +489,7 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) {struct sgx_epc_page *page;int nid_of_current =numa_node_id (); -int nid; +int nid = nid_of_current;if (node_isset (nid_of_current, sgx_numa_mask)) { page =__sgx_alloc_epc_page_from_node (nid_of_current);