From: Siddh Raman Pant via Linux-kernel-mentees <linux-kernel-mentees@lists.linuxfoundation.org> To: x86@kernel.org, Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com> Cc: linux-kernel-mentees <linux-kernel-mentees@lists.linuxfoundation.org>, linux-kernel <linux-kernel@vger.kernel.org> Subject: [PATCH] x86/numa: Use cpumask_available instead of hardcoded NULL check Date: Sun, 31 Jul 2022 21:39:13 +0530 [thread overview] Message-ID: <20220731160913.632092-1-code@siddh.me> (raw) node_to_cpumask_map is of type cpumask_var_t[]. When CONFIG_CPUMASK_OFFSTACK is set, cpumask_var_t is typedef'd to a pointer for dynamic allocation, else to an array of one element. The "wicked game" can be checked on line 700 of include/linux/cpumask.h. The lines changed in this commit were probably written by the original authors with CONFIG_CPUMASK_OFFSTACK=y (i.e. dynamic allocation) in mind, checking if the cpumask was available via a direct NULL check. When CONFIG_CPUMASK_OFFSTACK is not set, GCC gives the below given warning while compiling the kernel. Fix that by using cpumask_available(), which does the NULL check when CONFIG_CPUMASK_OFFSTACK is set, otherwise returns true. Use it wherever such checks are made. Conditional definitions of cpumask_available() can be found along with the definition of cpumask_var_t. Check the cpumask.h reference mentioned above. GCC warning log: =========================================================================== arch/x86/mm/numa.c: In function ‘cpumask_of_node’: arch/x86/mm/numa.c:916:39: warning: the comparison will always evaluate as ‘false’ for the address of ‘node_to_cpumask_map’ will never be NULL [-Waddress] 916 | if (node_to_cpumask_map[node] == NULL) { | ^~ In file included from ./include/linux/linkage.h:7, from ./include/linux/kernel.h:17, from ./arch/x86/include/asm/percpu.h:27, from ./arch/x86/include/asm/current.h:6, from ./include/linux/mutex.h:14, from ./include/linux/kernfs.h:11, from ./include/linux/sysfs.h:16, from ./include/linux/kobject.h:20, from ./include/linux/of.h:17, from ./include/linux/irqdomain.h:35, from ./include/linux/acpi.h:13, from arch/x86/mm/numa.c:3: arch/x86/mm/numa.c:67:15: note: ‘node_to_cpumask_map’ declared here 67 | EXPORT_SYMBOL(node_to_cpumask_map); | ^~~~~~~~~~~~~~~~~~~ ./include/linux/export.h:87:28: note: in definition of macro ‘___EXPORT_SYMBOL’ 87 | extern typeof(sym) sym; \ | ^~~ ./include/linux/export.h:147:41: note: in expansion of macro ‘__EXPORT_SYMBOL’ 147 | #define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "") | ^~~~~~~~~~~~~~~ ./include/linux/export.h:150:41: note: in expansion of macro ‘_EXPORT_SYMBOL’ 150 | #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "") | ^~~~~~~~~~~~~~ arch/x86/mm/numa.c:67:1: note: in expansion of macro ‘EXPORT_SYMBOL’ 67 | EXPORT_SYMBOL(node_to_cpumask_map); | ^~~~~~~~~~~~~ =========================================================================== Fixes: c032ef60d1aa ("cpumask: convert node_to_cpumask_map[] to cpumask_var_t") Fixes: de2d9445f162 ("x86: Unify node_to_cpumask_map handling between 32 and 64bit") Signed-off-by: Siddh Raman Pant <code@siddh.me> --- arch/x86/mm/numa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index e8b061557887..2aadb2019b4f 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -867,7 +867,7 @@ void debug_cpumask_set_cpu(int cpu, int node, bool enable) return; } mask = node_to_cpumask_map[node]; - if (!mask) { + if (!cpumask_available(mask)) { pr_err("node_to_cpumask_map[%i] NULL\n", node); dump_stack(); return; @@ -913,7 +913,7 @@ const struct cpumask *cpumask_of_node(int node) dump_stack(); return cpu_none_mask; } - if (node_to_cpumask_map[node] == NULL) { + if (!cpumask_available(node_to_cpumask_map[node])) { printk(KERN_WARNING "cpumask_of_node(%d): no node_to_cpumask_map!\n", node); -- 2.35.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
WARNING: multiple messages have this Message-ID (diff)
From: Siddh Raman Pant <code@siddh.me> To: x86@kernel.org, Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com> Cc: linux-kernel <linux-kernel@vger.kernel.org>, linux-kernel-mentees <linux-kernel-mentees@lists.linuxfoundation.org> Subject: [PATCH] x86/numa: Use cpumask_available instead of hardcoded NULL check Date: Sun, 31 Jul 2022 21:39:13 +0530 [thread overview] Message-ID: <20220731160913.632092-1-code@siddh.me> (raw) node_to_cpumask_map is of type cpumask_var_t[]. When CONFIG_CPUMASK_OFFSTACK is set, cpumask_var_t is typedef'd to a pointer for dynamic allocation, else to an array of one element. The "wicked game" can be checked on line 700 of include/linux/cpumask.h. The lines changed in this commit were probably written by the original authors with CONFIG_CPUMASK_OFFSTACK=y (i.e. dynamic allocation) in mind, checking if the cpumask was available via a direct NULL check. When CONFIG_CPUMASK_OFFSTACK is not set, GCC gives the below given warning while compiling the kernel. Fix that by using cpumask_available(), which does the NULL check when CONFIG_CPUMASK_OFFSTACK is set, otherwise returns true. Use it wherever such checks are made. Conditional definitions of cpumask_available() can be found along with the definition of cpumask_var_t. Check the cpumask.h reference mentioned above. GCC warning log: =========================================================================== arch/x86/mm/numa.c: In function ‘cpumask_of_node’: arch/x86/mm/numa.c:916:39: warning: the comparison will always evaluate as ‘false’ for the address of ‘node_to_cpumask_map’ will never be NULL [-Waddress] 916 | if (node_to_cpumask_map[node] == NULL) { | ^~ In file included from ./include/linux/linkage.h:7, from ./include/linux/kernel.h:17, from ./arch/x86/include/asm/percpu.h:27, from ./arch/x86/include/asm/current.h:6, from ./include/linux/mutex.h:14, from ./include/linux/kernfs.h:11, from ./include/linux/sysfs.h:16, from ./include/linux/kobject.h:20, from ./include/linux/of.h:17, from ./include/linux/irqdomain.h:35, from ./include/linux/acpi.h:13, from arch/x86/mm/numa.c:3: arch/x86/mm/numa.c:67:15: note: ‘node_to_cpumask_map’ declared here 67 | EXPORT_SYMBOL(node_to_cpumask_map); | ^~~~~~~~~~~~~~~~~~~ ./include/linux/export.h:87:28: note: in definition of macro ‘___EXPORT_SYMBOL’ 87 | extern typeof(sym) sym; \ | ^~~ ./include/linux/export.h:147:41: note: in expansion of macro ‘__EXPORT_SYMBOL’ 147 | #define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "") | ^~~~~~~~~~~~~~~ ./include/linux/export.h:150:41: note: in expansion of macro ‘_EXPORT_SYMBOL’ 150 | #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "") | ^~~~~~~~~~~~~~ arch/x86/mm/numa.c:67:1: note: in expansion of macro ‘EXPORT_SYMBOL’ 67 | EXPORT_SYMBOL(node_to_cpumask_map); | ^~~~~~~~~~~~~ =========================================================================== Fixes: c032ef60d1aa ("cpumask: convert node_to_cpumask_map[] to cpumask_var_t") Fixes: de2d9445f162 ("x86: Unify node_to_cpumask_map handling between 32 and 64bit") Signed-off-by: Siddh Raman Pant <code@siddh.me> --- arch/x86/mm/numa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index e8b061557887..2aadb2019b4f 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -867,7 +867,7 @@ void debug_cpumask_set_cpu(int cpu, int node, bool enable) return; } mask = node_to_cpumask_map[node]; - if (!mask) { + if (!cpumask_available(mask)) { pr_err("node_to_cpumask_map[%i] NULL\n", node); dump_stack(); return; @@ -913,7 +913,7 @@ const struct cpumask *cpumask_of_node(int node) dump_stack(); return cpu_none_mask; } - if (node_to_cpumask_map[node] == NULL) { + if (!cpumask_available(node_to_cpumask_map[node])) { printk(KERN_WARNING "cpumask_of_node(%d): no node_to_cpumask_map!\n", node); -- 2.35.1
next reply other threads:[~2022-07-31 16:10 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-31 16:09 Siddh Raman Pant via Linux-kernel-mentees [this message] 2022-07-31 16:09 ` [PATCH] x86/numa: Use cpumask_available instead of hardcoded NULL check Siddh Raman Pant 2022-08-02 11:07 ` Ingo Molnar 2022-08-02 11:07 ` Ingo Molnar 2022-08-02 16:29 ` Siddh Raman Pant via Linux-kernel-mentees 2022-08-02 16:29 ` Siddh Raman Pant 2022-08-03 8:48 ` Ingo Molnar 2022-08-03 8:48 ` Ingo Molnar 2022-08-03 8:58 ` Siddh Raman Pant via Linux-kernel-mentees 2022-08-03 8:58 ` Siddh Raman Pant 2022-08-03 9:08 ` Ingo Molnar 2022-08-03 9:08 ` Ingo Molnar 2022-08-03 9:21 ` Siddh Raman Pant 2022-08-03 9:21 ` Siddh Raman Pant via Linux-kernel-mentees 2022-08-03 9:42 ` Ingo Molnar 2022-08-03 9:42 ` Ingo Molnar 2022-08-03 9:46 ` Siddh Raman Pant via Linux-kernel-mentees 2022-08-03 9:46 ` Siddh Raman Pant 2022-08-03 15:41 ` [tip: x86/urgent] " tip-bot2 for Siddh Raman Pant
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=20220731160913.632092-1-code@siddh.me \ --to=linux-kernel-mentees@lists.linuxfoundation.org \ --cc=bp@alien8.de \ --cc=code@siddh.me \ --cc=dave.hansen@linux.intel.com \ --cc=hpa@zytor.com \ --cc=linux-kernel@vger.kernel.org \ --cc=luto@kernel.org \ --cc=mingo@redhat.com \ --cc=peterz@infradead.org \ --cc=tglx@linutronix.de \ --cc=x86@kernel.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.