mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC] x86/apic: skip cpu slot reservation logic on boot in case of NR_CPUS == 1
@ 2022-09-02 16:42 Yury Norov
  2022-09-02 17:14 ` Dave Hansen
  0 siblings, 1 reply; 3+ messages in thread
From: Yury Norov @ 2022-09-02 16:42 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	linux-kernel
  Cc: Yury Norov, kernel test robot

generic_processor_info() ensures that there's always a room for boot-cpu
in phys_cpu_present_map. This logic is unneeded when there's a single CPU
in the system, and it makes smatch warning when aliasing nr_cpu_ids to
NR_CPUS in this patch:

https://www.spinics.net/lists/kernel/msg4493525.html

smatch warnings:
arch/x86/kernel/apic/apic.c:2437 generic_processor_info() warn: always true condition '(num_processors >= (1) - 1) =>
+(0-u32max >= 0)'

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
This is RFC because I'm not sure that this is not a false positive from
smatch. If NR_CPUS is 1, and the condition is always true, it's simply
optimized out by a compiler, and nothing wrong happens, except maybe a
couple of checks on boot.

 arch/x86/kernel/apic/apic.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 6d303d1d276c..6a43faaea5ac 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -2430,6 +2430,7 @@ int generic_processor_info(int apicid, int version)
 		return -ENODEV;
 	}
 
+#if NR_CPUS > 1
 	/*
 	 * If boot cpu has not been detected yet, then only allow upto
 	 * nr_cpu_ids - 1 processors and keep one slot free for boot cpu
@@ -2445,6 +2446,7 @@ int generic_processor_info(int apicid, int version)
 		disabled_cpus++;
 		return -ENODEV;
 	}
+#endif
 
 	if (num_processors >= nr_cpu_ids) {
 		int thiscpu = max + disabled_cpus;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RFC] x86/apic: skip cpu slot reservation logic on boot in case of NR_CPUS == 1
  2022-09-02 16:42 [PATCH RFC] x86/apic: skip cpu slot reservation logic on boot in case of NR_CPUS == 1 Yury Norov
@ 2022-09-02 17:14 ` Dave Hansen
  2022-09-02 17:35   ` Yury Norov
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Hansen @ 2022-09-02 17:14 UTC (permalink / raw)
  To: Yury Norov, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, linux-kernel
  Cc: kernel test robot

On 9/2/22 09:42, Yury Norov wrote:
> This is RFC because I'm not sure that this is not a false positive from
> smatch. If NR_CPUS is 1, and the condition is always true, it's simply
> optimized out by a compiler, and nothing wrong happens, except maybe a
> couple of checks on boot.

I think it's a reasonable warning, but it's also not something we need
to hack around.  We can surely only land in here with
boot_cpu_detected==true if NR_CPUS==1, so the rest of the expression is
moot.

I don't think it's worth adding the #ifdef.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RFC] x86/apic: skip cpu slot reservation logic on boot in case of NR_CPUS == 1
  2022-09-02 17:14 ` Dave Hansen
@ 2022-09-02 17:35   ` Yury Norov
  0 siblings, 0 replies; 3+ messages in thread
From: Yury Norov @ 2022-09-02 17:35 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	linux-kernel, kernel test robot

On Fri, Sep 02, 2022 at 10:14:51AM -0700, Dave Hansen wrote:
> On 9/2/22 09:42, Yury Norov wrote:
> > This is RFC because I'm not sure that this is not a false positive from
> > smatch. If NR_CPUS is 1, and the condition is always true, it's simply
> > optimized out by a compiler, and nothing wrong happens, except maybe a
> > couple of checks on boot.
> 
> I think it's a reasonable warning, but it's also not something we need
> to hack around.  We can surely only land in here with
> boot_cpu_detected==true if NR_CPUS==1, so the rest of the expression is
> moot.
> 
> I don't think it's worth adding the #ifdef.

Thanks Dave. Then I'll add a comment and move my series as-is.

Thanks,
Yury

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-02 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-02 16:42 [PATCH RFC] x86/apic: skip cpu slot reservation logic on boot in case of NR_CPUS == 1 Yury Norov
2022-09-02 17:14 ` Dave Hansen
2022-09-02 17:35   ` Yury Norov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®