Re: [PATCH] x86/proc: fix /proc/cpuinfo cpu offline bug

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Lai Jiangshan
Date: Tuesday, October 21, 2008 - 9:42 pm

Lai Jiangshan wrote:


In my test, I found that if a cpu has been offline,
the next cpus may not be shown in the /proc/cpuinfo.

if one read() cannot consume the whole /proc/cpuinfo,
c_start() will be called again in the next read() calls.
And *pos has been increased by 1 by the caller(seq_read()).
if this time the cpu#*pos is offline, c_start() will return
NULL, and the next cpus can not be shown.

this fix use next_cpu_nr(*pos - 1, cpu_online_map) to
search the next unshown cpu.

the most easy way to reproduce this bug:
1) offline cpu#1             (cpu#0 is online)
2) dd ibs=2 if=/proc/cpuinfo
   the result is that only cpu#0 is shown.
   cpu#2 and cpu#3 .... cannot be shown in /proc/cpuinfo
   it's bug.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index a26c480..01b1244 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -160,14 +160,16 @@ static void *c_start(struct seq_file *m, loff_t *pos)
 {
 	if (*pos == 0)	/* just in case, cpu 0 is not the first */
 		*pos = first_cpu(cpu_online_map);
-	if ((*pos) < nr_cpu_ids && cpu_online(*pos))
+	else
+		*pos = next_cpu_nr(*pos - 1, cpu_online_map);
+	if ((*pos) < nr_cpu_ids)
 		return &cpu_data(*pos);
 	return NULL;
 }
 
 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
 {
-	*pos = next_cpu(*pos, cpu_online_map);
+	(*pos)++;
 	return c_start(m, pos);
 }
 



--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] x86/proc: fix /proc/cpuinfo cpu offline bug, Lai Jiangshan, (Fri Oct 17, 1:55 am)
Re: [PATCH] x86/proc: fix /proc/cpuinfo cpu offline bug, Alexey Dobriyan, (Fri Oct 17, 4:41 am)
Re: [PATCH] x86/proc: fix /proc/cpuinfo cpu offline bug, Lai Jiangshan, (Fri Oct 17, 5:44 am)
Re: [PATCH] x86/proc: fix /proc/cpuinfo cpu offline bug, Lai Jiangshan, (Tue Oct 21, 9:39 pm)
Re: [PATCH] x86/proc: fix /proc/cpuinfo cpu offline bug, Lai Jiangshan, (Tue Oct 21, 9:42 pm)