x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
PATCH 1/1 x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
When comparing 'model name' fields in /proc/cpuinfo it was noticed that a simple test comparing the model name fields was failing. After some simple investigation it was noticed that, in fact, the model name fields are different for each processor. Processor 0's model name field had white space removed, while the other processors did not.
Another way of seeing this behaviour is to convert spaces into underscores in the output of /proc/cpuinfo,
[thetango@prarit ~]# grep "^model name" /proc/cpuinfo | uniq -c | sed 's/\ /_/g'______1_model_name :_AMD_Opteron(TM)_Processor_6272_____63_model_name :_AMD_Opteron(TM)_Processor_6272_________________
which shows two different model name fields even though they should be the same.
This occurs because the kernel calls strim() on cpu 0's x86_model_id field to output a pretty message to the console in print_cpu_info(), and as a result truncates the whitespace at the end of the x86_model_id field.
The x86_model_id field should be the same for the same processors. This patch adds a local copy of the x86_model_id field and modifies the value there so that the output in dmesg still looks like
smpboot: CPU0: AMD Opteron(TM) Processor 6272 (fam: 15, model: 01, stepping: 02)
and the x86_model_id field is correct across all processors:
[thetango@prarit ~]# grep "^model name" /proc/cpuinfo | uniq -c | sed 's/\ /_/g'_____64_model_name :_AMD_Opteron(TM)_Processor_6272_________________
--- arch/x86/kernel/cpu/common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/common.c +5 -3
@@ -1110,6 +1110,7 @@ __setup("noclflush", setup_noclflush);void print_cpu_info (struct cpuinfo_x86 *c) {const char *vendor =NULL ; +char x86_model_id[64 ];if (c->x86_vendor <X86_VENDOR_NUM ) { vendor = this_cpu->c_vendor;
@@ -1121,9 +1122,10 @@ void print_cpu_info(struct cpuinfo_x86 *c)if (vendor && !strstr (c->x86_model_id, vendor))printk (KERN_CONT "%s " , vendor); -if (c->x86_model_id[0 ]) -printk (KERN_CONT "%s" ,strim (c->x86_model_id)); -else +if (c->x86_model_id[0 ]) { +strcpy (x86_model_id, c->x86_model_id); +printk (KERN_CONT "%s" ,strim (x86_model_id)); + }else printk (KERN_CONT "%d86" , c->x86);printk (KERN_CONT " (fam: %02x, model: %02x" , c->x86, c->x86_model);
Signature · 1 line
1.7.9.3
Borislav Petkov
maintainerQuoted 9 lines · Prarit Bhargava
When comparing 'model name' fields in
/proc/cpuinfoit was noticed that a simple test comparing the model name fields was failing. After some simple investigation it was noticed that, in fact, the model name fields are different for each processor. Processor 0's model name field had white space removed, while the other processors did not.Another way of seeing this behaviour is to convert spaces into underscores in the output of
/proc/cpuinfo,
Quoted 8 lines
[thetango@prarit ~]# grep "^model name"
/proc/cpuinfo| uniq -c | sed 's/\ /_/g'______1_model_name:_AMD_Opteron(TM)_Processor_6272_____63_model_name:_AMD_Opteron(TM)_Processor_6272_________________which shows two different model name fields even though they should be the same.
This occurs because the kernel calls
strim()on cpu 0'sx86_model_idfield
I'd actually prefer this much simpler patch:
---
arch/x86/kernel/cpu/proc.c +1 -1
@@ -67,7 +67,7 @@ static int show_cpuinfo(struct seq_file *m, void *v) c->x86_vendor_id[0 ] ? c->x86_vendor_id :"unknown" , c->x86, c->x86_model, - c->x86_model_id[0] ? c->x86_model_id : "unknown"); + c->x86_model_id[0] ? strim(c->x86_model_id) : "unknown");if (c->x86_mask || c->cpuid_level >=0 )seq_printf (m,"stepping\t: %d\n" , c->x86_mask);
---
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Quoted 27 lines · Borislav Petkov
Quoted 9 lines · Prarit Bhargava
When comparing 'model name' fields in
/proc/cpuinfoit was noticed that a simple test comparing the model name fields was failing. After some simple investigation it was noticed that, in fact, the model name fields are different for each processor. Processor 0's model name field had white space removed, while the other processors did not.Another way of seeing this behaviour is to convert spaces into underscores in the output of
/proc/cpuinfo,Quoted 8 lines
[thetango@prarit ~]# grep "^model name"
/proc/cpuinfo| uniq -c | sed 's/\ /_/g'______1_model_name:_AMD_Opteron(TM)_Processor_6272_____63_model_name:_AMD_Opteron(TM)_Processor_6272_________________which shows two different model name fields even though they should be the same.
This occurs because the kernel calls
strim()on cpu 0'sx86_model_idfieldI'd actually prefer this much simpler patch:
---
arch/x86/kernel/cpu/proc.c +0
-0
arch/x86/kernel/cpu/proc.c static int show_cpuinfo(struct seq_file *m, void *v) · line 73
Quoted 8 lines
arch/x86/kernel/cpu/proc.c +1
-1@@ -67,7 +67,7 @@ static int show_cpuinfo(struct seq_file *m, void *v) c->x86_vendor_id[0 ] ? c->x86_vendor_id :"unknown" , c->x86, c->x86_model, - c->x86_model_id[0] ? c->x86_model_id : "unknown"); + c->x86_model_id[0] ? strim(c->x86_model_id) : "unknown");if (c->x86_mask || c->cpuid_level >=0 )seq_printf (m,"stepping\t: %d\n" , c->x86_mask);
The problem here is that strim() modifies the string in place, replacing the first trailing space with a null. I think the best solution is to do the trimming in get_model_name(). It already trims leading spaces for Intel.
--
Brian Gerst
Borislav Petkov
maintainerQuoted 4 lines · Brian Gerst
The problem here is that
strim()modifies the string in place, replacing the first trailing space with a null. I think the best solution is to do the trimming inget_model_name(). It already trims leading spaces for Intel.
Sounds good - start from the 48th position forward to the first non \s char. Yeah.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--H. Peter Anvin
reviewerQuoted 9 lines · Borislav Petkov
Quoted 4 lines · Brian Gerst
The problem here is that
strim()modifies the string in place, replacing the first trailing space with a null. I think the best solution is to do the trimming inget_model_name(). It already trims leading spaces for Intel.Sounds good - start from the 48th position forward to the first non \s char. Yeah.
Yes, we should trim both leading and trailing spaces.
-hpa
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Borislav Petkov
Quoted 4 lines · Brian Gerst
The problem here is that
strim()modifies the string in place, replacing the first trailing space with a null. I think the best solution is to do the trimming inget_model_name(). It already trims leading spaces for Intel.
Quoted 5 lines
Quoted 3 lines
Sounds good - start from the 48th position forward to the first non \s char. Yeah.
Yes, we should trim both leading and trailing spaces.
Oh sorry, I missed this as it just landed in my mailbox. So a backward search for the first non \s char.
I can do that and I'll nack my new patch.
P.
Quoted 3 lines
-hpa