LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH resend] x86/proc: fix /proc/cpuinfo cpu offline bug
@ 2008-10-27  6:11 Lai Jiangshan
  2008-10-27  9:54 ` Ingo Molnar
  0 siblings, 1 reply; 2+ messages in thread
From: Lai Jiangshan @ 2008-10-27  6:11 UTC (permalink / raw)
  To: Ingo Molnar, Andrew Morton; +Cc: Alexey Dobriyan, Linux Kernel Mailing List

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 file,
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 uses next_cpu_nr(*pos - 1, cpu_online_map) to
search the next unshown cpu.

the way to reproduce this bug:
(cpu#0 cpu#1 cpu#2 must be online before test)

step 1) offline cpu#1
step 2) dd ibs=2 if=/proc/cpuinfo

now, only cpu#0 's cpuinfo is shown.
cpu#2 and cpu#3 .... cannot be shown in /proc/cpuinfo
it's a 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);
 }
 


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

* Re: [PATCH resend] x86/proc: fix /proc/cpuinfo cpu offline bug
  2008-10-27  6:11 [PATCH resend] x86/proc: fix /proc/cpuinfo cpu offline bug Lai Jiangshan
@ 2008-10-27  9:54 ` Ingo Molnar
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Molnar @ 2008-10-27  9:54 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: Andrew Morton, Alexey Dobriyan, Linux Kernel Mailing List


* Lai Jiangshan <laijs@cn.fujitsu.com> wrote:

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

fix is already upstream - see below.

	Ingo

-------------------->
Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=bc8bcc79ea4203c7d04309f1307ab88c86f0b0cf
Commit:     bc8bcc79ea4203c7d04309f1307ab88c86f0b0cf
Parent:     35af28219e684a36cc8b1ff456c370ce22be157d
Author:     Lai Jiangshan <laijs@cn.fujitsu.com>
AuthorDate: Wed Oct 22 12:42:30 2008 +0800
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed Oct 22 14:29:37 2008 +0200

    x86/proc: fix /proc/cpuinfo cpu offline bug
    
    Impact: fix missing CPUs in /proc/cpuinfo after CPU hotunplug/hotreplug
    
    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>
    Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/cpu/proc.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

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);
 }
 

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

end of thread, other threads:[~2008-10-27  9:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-27  6:11 [PATCH resend] x86/proc: fix /proc/cpuinfo cpu offline bug Lai Jiangshan
2008-10-27  9:54 ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).