Skip to contentSkip to conversation

x86: Fix /proc/cpuinfo cpumask warning

PATCH In review Andrew Jones 3 participants 5 messages Oct 11, 2022 – Oct 12, 2022 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Fix /proc/cpuinfo cpumask warning

Upcoming cpumask changes will start issuing warnings[*] when cpu indices equal to nr_cpu_ids are passed to cpumask_next* functions. Ensure we don't generate a warning when reading /proc/cpuinfo by validating the cpu index before calling cpumask_next().

[*] Warnings will only appear with DEBUG_PER_CPU_MAPS enabled.

---
 arch/x86/kernel/cpu/proc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/proc.c +6 -3
index 099b6f0d96bd..584ae6cb5b87 100644
@@ -153,9 +153,12 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 
 static void *c_start(struct seq_file *m, loff_t *pos)
 {
-	*pos = cpumask_next(*pos - 1, cpu_online_mask);
-	if ((*pos) < nr_cpu_ids)
-		return &cpu_data(*pos);
+	if (*pos < nr_cpu_ids) {
+		*pos = cpumask_next(*pos - 1, cpu_online_mask);
+		if (*pos < nr_cpu_ids)
+			return &cpu_data(*pos);
+	}
+
 	return NULL;
 }
 
Signature · 1 line
2.37.3
maintainer
#1 lore raw
Quoted 1 line · Andrew Jones

Upcoming cpumask changes will start issuing warnings[*] when cpu

What upcoming changes?

This needs a concrete pointer to a commit or so.

Quoted 1 line

indices equal to nr_cpu_ids are passed to cpumask_next* functions.

How do those indices get passed here? I think you need to explain how exactly this happens.

Quoted 1 line

Ensure we don't generate a warning when reading /proc/cpuinfo by

Please use passive voice in your commit message: no "we" or "I", etc, and describe your changes in imperative mood.

Quoted 1 line

validating the cpu index before calling cpumask_next().

s/cpu/CPU/g

Quoted 14 lines

[*] Warnings will only appear with DEBUG_PER_CPU_MAPS enabled.

---
 arch/x86/kernel/cpu/proc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/proc.c +0 -0
index 099b6f0d96bd..584ae6cb5b87 100644
@@ -153,9 +153,12 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 

arch/x86/kernel/cpu/proc.c static int show_cpuinfo(struct seq_file *m, void *v) · line 160

Quoted 10 lines
arch/x86/kernel/cpu/proc.c +5 -3
 static void *c_start(struct seq_file *m, loff_t *pos)
 {
-	*pos = cpumask_next(*pos - 1, cpu_online_mask);
-	if ((*pos) < nr_cpu_ids)
-		return &cpu_data(*pos);
+	if (*pos < nr_cpu_ids) {
+		*pos = cpumask_next(*pos - 1, cpu_online_mask);
+		if (*pos < nr_cpu_ids)
+			return &cpu_data(*pos);
+	}

Simpler: on function entry:

	if (*pos >= nr_cpu_ids)
		return NULL;

	 /* the rest remains unchanged */
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#2 lore raw
Quoted 6 lines · Borislav Petkov
Quoted 1 line · Andrew Jones

Upcoming cpumask changes will start issuing warnings[*] when cpu

What upcoming changes?

This needs a concrete pointer to a commit or so.

Hi Boris,

Sorry, I should have pointed this out. The upcoming change is

linux-next/master commit a314123c8bdb ("cpumask: fix checking valid cpu range")

And also an ongoing discussion here
https://lore.kernel.org/lkml/20221011170949.upxk3tcfcwnkytwm@kamzik/

I'm hoping that Yury will pick these patches up and integrate them at the front of his series when introducing the warnings. I wasn't sure how to call that out other than with the generic "upcoming change".

Quoted 5 lines
Quoted 2 lines

indices equal to nr_cpu_ids are passed to cpumask_next* functions.

How do those indices get passed here? I think you need to explain how exactly this happens.

I took a stab at explaining it in the discussion thread[1] just now and I can bring that explanation into the commit message for v2.

[1] https://lore.kernel.org/lkml/20221011180442.cwjtcvjioias3qt6@kamzik/

Quoted 5 lines
Quoted 2 lines

Ensure we don't generate a warning when reading /proc/cpuinfo by

Please use passive voice in your commit message: no "we" or "I", etc, and describe your changes in imperative mood.

I'll change to "Ensure no warning is generated ..."

Quoted 32 lines
Quoted 2 lines

validating the cpu index before calling cpumask_next().

s/cpu/CPU/g

Quoted 14 lines

[*] Warnings will only appear with DEBUG_PER_CPU_MAPS enabled.

---
 arch/x86/kernel/cpu/proc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/proc.c +0 -0
index 099b6f0d96bd..584ae6cb5b87 100644
@@ -153,9 +153,12 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 

arch/x86/kernel/cpu/proc.c static int show_cpuinfo(struct seq_file *m, void *v) · line 160

Quoted 10 lines
arch/x86/kernel/cpu/proc.c +5 -3
 static void *c_start(struct seq_file *m, loff_t *pos)
 {
-	*pos = cpumask_next(*pos - 1, cpu_online_mask);
-	if ((*pos) < nr_cpu_ids)
-		return &cpu_data(*pos);
+	if (*pos < nr_cpu_ids) {
+		*pos = cpumask_next(*pos - 1, cpu_online_mask);
+		if (*pos < nr_cpu_ids)
+			return &cpu_data(*pos);
+	}

Simpler: on function entry:

Quoted 4 lines
	if (*pos >= nr_cpu_ids)
		return NULL;

	 /* the rest remains unchanged */

Will do for v2.

Thanks,
drew

#3 lore raw
Quoted 16 lines · Andrew Jones
Quoted 6 lines · Borislav Petkov
Quoted 1 line · Andrew Jones

Upcoming cpumask changes will start issuing warnings[*] when cpu

What upcoming changes?

This needs a concrete pointer to a commit or so.

Hi Boris,

Sorry, I should have pointed this out. The upcoming change is

linux-next/master commit a314123c8bdb ("cpumask: fix checking valid cpu range")

Quoted 13 lines

And also an ongoing discussion here
https://lore.kernel.org/lkml/20221011170949.upxk3tcfcwnkytwm@kamzik/

I'm hoping that Yury will pick these patches up and integrate them at the front of his series when introducing the warnings. I wasn't sure how to call that out other than with the generic "upcoming change".

Quoted 5 lines
Quoted 2 lines

indices equal to nr_cpu_ids are passed to cpumask_next* functions.

How do those indices get passed here? I think you need to explain how exactly this happens.

The cpumask_check() fix is already in master. Because of some mess in cpumask, cpumask_check() was broken for quite a long time, and didn't bark when passed with an out-of-range CPU.

I fixed some false-positives and sent those fixes together with a314123c8bdb. Now, I expect that people will see warnings generated by correct cpumask_check().
This is actually the first sign.

Andrew, can you please answer Borislav's question:

Quoted 2 lines
Quoted 2 lines

How do those indices get passed here? I think you need to explain how exactly this happens.

It might be either an expected behaviour, and then there should be a great explanation on how and why things work in the subsystem.

Or it might be an error in the caller. In that case, the caller must be fixed.

Thanks,
Yury

#4 lore raw
Quoted 26 lines · Yury Norov
Quoted 25 lines · Andrew Jones
Quoted 6 lines · Borislav Petkov
Quoted 1 line · Andrew Jones

Upcoming cpumask changes will start issuing warnings[*] when cpu

What upcoming changes?

This needs a concrete pointer to a commit or so.

Hi Boris,

Sorry, I should have pointed this out. The upcoming change is

linux-next/master commit a314123c8bdb ("cpumask: fix checking valid cpu range")

And also an ongoing discussion here
https://lore.kernel.org/lkml/20221011170949.upxk3tcfcwnkytwm@kamzik/

I'm hoping that Yury will pick these patches up and integrate them at the front of his series when introducing the warnings. I wasn't sure how to call that out other than with the generic "upcoming change".

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

indices equal to nr_cpu_ids are passed to cpumask_next* functions.

How do those indices get passed here? I think you need to explain how exactly this happens.

The cpumask_check() fix is already in master. Because of some mess in

Ah, it's already in master. I should have checked that...

Quoted 9 lines

cpumask, cpumask_check() was broken for quite a long time, and didn't bark when passed with an out-of-range CPU.

I fixed some false-positives and sent those fixes together with a314123c8bdb. Now, I expect that people will see warnings generated by correct cpumask_check().
This is actually the first sign.

Andrew, can you please answer Borislav's question:

I answered in the discussion[1], but I'll send a v2 of this patch, properly based on master, with a proper pointer to commit 78e5a3399421 ("cpumask: fix checking valid cpu range"), and also with a condensed analysis for justification in the commit message.

Thanks,
drew

Quoted 11 lines
Quoted 3 lines
Quoted 3 lines

How do those indices get passed here? I think you need to explain how exactly this happens.

It might be either an expected behaviour, and then there should be a great explanation on how and why things work in the subsystem.

Or it might be an error in the caller. In that case, the caller must be fixed.

Thanks,
Yury