* [tip:x86/sgx 2/2] arch/x86/kernel/cpu/sgx/main.c:496:7: warning: variable 'nid' is used uninitialized whenever 'if' condition is false
@ 2021-03-18 21:03 kernel test robot
2021-03-18 21:49 ` [PATCH] x86/sgx: fix uninitialized 'nid' variable Dave Hansen
0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2021-03-18 21:03 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: kbuild-all, clang-built-linux, linux-kernel, x86, Borislav Petkov
[-- Attachment #1: Type: text/plain, Size: 6248 bytes --]
tree: 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
Reported-by: kernel test robot <lkp@intel.com>
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;
^
= 0
2 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 <jarkko@kernel.org>
:::::: CC: Borislav Petkov <bp@suse.de>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 27364 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] x86/sgx: fix uninitialized 'nid' variable
2021-03-18 21:03 [tip:x86/sgx 2/2] arch/x86/kernel/cpu/sgx/main.c:496:7: warning: variable 'nid' is used uninitialized whenever 'if' condition is false kernel test robot
@ 2021-03-18 21:49 ` Dave Hansen
2021-03-19 5:38 ` Jarkko Sakkinen
2021-03-19 8:57 ` [tip: x86/sgx] x86/sgx: Fix " tip-bot2 for Dave Hansen
0 siblings, 2 replies; 4+ messages in thread
From: Dave Hansen @ 2021-03-18 21:49 UTC (permalink / raw)
To: linux-kernel
Cc: Dave Hansen, Dave Hansen, Jarkko Sakkinen, Borislav Petkov, x86,
linux-sgx
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.
Fixes: 5b8719504e3a ("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Cc: linux-sgx@vger.kernel.org
---
arch/x86/kernel/cpu/sgx/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 2a0031e4a4dc..1b4d8a0e0915 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -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);
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/sgx: fix uninitialized 'nid' variable
2021-03-18 21:49 ` [PATCH] x86/sgx: fix uninitialized 'nid' variable Dave Hansen
@ 2021-03-19 5:38 ` Jarkko Sakkinen
2021-03-19 8:57 ` [tip: x86/sgx] x86/sgx: Fix " tip-bot2 for Dave Hansen
1 sibling, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2021-03-19 5:38 UTC (permalink / raw)
To: Dave Hansen; +Cc: linux-kernel, Dave Hansen, Borislav Petkov, x86, linux-sgx
On Thu, Mar 18, 2021 at 02:49:33PM -0700, Dave Hansen wrote:
> 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.
>
> Fixes: 5b8719504e3a ("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: x86@kernel.org
> Cc: linux-sgx@vger.kernel.org
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
> ---
> arch/x86/kernel/cpu/sgx/main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> index 2a0031e4a4dc..1b4d8a0e0915 100644
> --- a/arch/x86/kernel/cpu/sgx/main.c
> +++ b/arch/x86/kernel/cpu/sgx/main.c
> @@ -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);
> --
> 2.19.1
>
>
/Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
* [tip: x86/sgx] x86/sgx: Fix uninitialized 'nid' variable
2021-03-18 21:49 ` [PATCH] x86/sgx: fix uninitialized 'nid' variable Dave Hansen
2021-03-19 5:38 ` Jarkko Sakkinen
@ 2021-03-19 8:57 ` tip-bot2 for Dave Hansen
1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Dave Hansen @ 2021-03-19 8:57 UTC (permalink / raw)
To: linux-tip-commits
Cc: kernel test robot, Dave Hansen, Borislav Petkov, Jarkko Sakkinen,
x86, linux-kernel
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 <dave.hansen@intel.com>
AuthorDate: Thu, 18 Mar 2021 14:49:33 -07:00
Committer: Borislav Petkov <bp@suse.de>
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.
Fixes: 5b8719504e3a ("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lkml.kernel.org/r/20210318214933.29341-1-dave.hansen@intel.com
---
arch/x86/kernel/cpu/sgx/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 5c9c5e5..13a7599 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -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);
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-19 8:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 21:03 [tip:x86/sgx 2/2] arch/x86/kernel/cpu/sgx/main.c:496:7: warning: variable 'nid' is used uninitialized whenever 'if' condition is false kernel test robot
2021-03-18 21:49 ` [PATCH] x86/sgx: fix uninitialized 'nid' variable Dave Hansen
2021-03-19 5:38 ` Jarkko Sakkinen
2021-03-19 8:57 ` [tip: x86/sgx] x86/sgx: Fix " tip-bot2 for Dave Hansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).