Skip to contentSkip to conversation

kernel/cpu.c: fix init_cpu_online

PATCH In review Yury Norov 2 participants 3 messages Jan 31, 2022 – Feb 1, 2022 CPU hotplug

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

PATCH 1/1 kernel/cpu.c: fix init_cpu_online

cpu_online_mask has an associate counter of online cpus, which must be initialized in init_cpu_online().

Fixes 0c09ab96fc82010 (cpu/hotplug: Cache number of online CPUs)
---
 kernel/cpu.c | 1 +
 1 file changed, 1 insertion(+)
kernel/cpu.c +1 -0
index 407a2568f35e..cd7605204d4d 100644
@@ -2616,6 +2616,7 @@ void init_cpu_possible(const struct cpumask *src)
 void init_cpu_online(const struct cpumask *src)
 {
 	cpumask_copy(&__cpu_online_mask, src);
+	atomic_set(&__num_online_cpus, cpumask_weight(cpu_online_mask));
 }
 
 void set_cpu_online(unsigned int cpu, bool online)
Signature · 1 line
2.30.2
#1 lore raw

Hi Yury,

Quoted 4 lines · Yury Norov

cpu_online_mask has an associate counter of online cpus, which must be initialized in init_cpu_online().

Fixes 0c09ab96fc82010 (cpu/hotplug: Cache number of online CPUs)

Aren't the increments/decrements from set_cpu_online() enough?

I guess we could argue that this isn't a private function and the num_online_cpus should be updated here. But unless I missed something, init_cpu_online() is only called in ia64 arch, in the !SMP case. Is this the problem you're trying to tackle? If not, I'm not sure that warrants a "Fixes:" tag

Quoted 20 lines
---
 kernel/cpu.c | 1 +
 1 file changed, 1 insertion(+)
kernel/cpu.c +1 -0
index 407a2568f35e..cd7605204d4d 100644
@@ -2616,6 +2616,7 @@ void init_cpu_possible(const struct cpumask *src)
 void init_cpu_online(const struct cpumask *src)
 {
 	cpumask_copy(&__cpu_online_mask, src);
+	atomic_set(&__num_online_cpus, cpumask_weight(cpu_online_mask));
 }
 
 void set_cpu_online(unsigned int cpu, bool online)
Signature · 1 line
2.30.2
author
#2 lore raw
Quoted 10 lines · Vincent Donnefort

Hi Yury,

Quoted 4 lines · Yury Norov

cpu_online_mask has an associate counter of online cpus, which must be initialized in init_cpu_online().

Fixes 0c09ab96fc82010 (cpu/hotplug: Cache number of online CPUs)

Aren't the increments/decrements from set_cpu_online() enough?

It will only count cpus onlined by this function . Those onlined before will never be counted.

Quoted 3 lines

I guess we could argue that this isn't a private function and the num_online_cpus should be updated here. But unless I missed something, init_cpu_online() is only called in ia64 arch, in the !SMP case.

Yes, this looks weird. In !SMP case this counter and function are not needed at all, and this is the only case when the function is used.

In SMP case, things work just because the cpu_online_mask and num_online_cpus are both initialized to 0. If this is the intentional behavior, and it would be like this forever, then the init_cpu_online() must be dropped, otherwise it needs to be fixed. Isn't?

Quoted 1 line

Is this the problem you're trying to tackle?

It was initially a part of a bigger series that added 3 more counters like this:

https://lkml.org/lkml/2021/12/18/253

But now it's postponed.

Quoted 1 line

If not, I'm not sure that warrants a "Fixes:" tag

The patch 0c09ab96fc82010 adds the counter but does not initialize it properly. For me it sounds like a fix.

Quoted 20 lines
Quoted 20 lines
---
 kernel/cpu.c | 1 +
 1 file changed, 1 insertion(+)
kernel/cpu.c +1 -1
index 407a2568f35e..cd7605204d4d 100644
@@ -2616,6 +2616,7 @@ void init_cpu_possible(const struct cpumask *src)
 void init_cpu_online(const struct cpumask *src)
 {
      cpumask_copy(&__cpu_online_mask, src);
+     atomic_set(&__num_online_cpus, cpumask_weight(cpu_online_mask));
 }
 
 void set_cpu_online(unsigned int cpu, bool online)
--

2.30.2