linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
@ 2015-05-18 18:21 Prarit Bhargava
  2015-05-18 19:45 ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Prarit Bhargava @ 2015-05-18 18:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: Prarit Bhargava, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86, Andy Lutomirski, Borislav Petkov, Denys Vlasenko,
	Dave Hansen, Peter P Waskiewicz Jr, Igor Mammedov, Fenghua Yu

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_________________

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
---
 arch/x86/kernel/cpu/common.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a62cf04..61ac5c3 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -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);
-- 
1.7.9.3


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

* Re: [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
  2015-05-18 18:21 [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation Prarit Bhargava
@ 2015-05-18 19:45 ` Borislav Petkov
  2015-05-18 20:27   ` Brian Gerst
  0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2015-05-18 19:45 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Andy Lutomirski, Denys Vlasenko, Dave Hansen,
	Peter P Waskiewicz Jr, Igor Mammedov, Fenghua Yu

On Mon, May 18, 2015 at 02:21:00PM -0400, Prarit Bhargava wrote:
> 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

I'd actually prefer this much simpler patch:

---
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index e7d8c7608471..d215e9b26567 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -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);
---

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

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

* Re: [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
  2015-05-18 19:45 ` Borislav Petkov
@ 2015-05-18 20:27   ` Brian Gerst
  2015-05-18 20:36     ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Gerst @ 2015-05-18 20:27 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Prarit Bhargava, Linux Kernel Mailing List, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, the arch/x86 maintainers,
	Andy Lutomirski, Denys Vlasenko, Dave Hansen,
	Peter P Waskiewicz Jr, Igor Mammedov, Fenghua Yu

On Mon, May 18, 2015 at 3:45 PM, Borislav Petkov <bp@alien8.de> wrote:
> On Mon, May 18, 2015 at 02:21:00PM -0400, Prarit Bhargava wrote:
>> 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
>
> I'd actually prefer this much simpler patch:
>
> ---
> diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
> index e7d8c7608471..d215e9b26567 100644
> --- a/arch/x86/kernel/cpu/proc.c
> +++ b/arch/x86/kernel/cpu/proc.c
> @@ -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

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

* Re: [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
  2015-05-18 20:27   ` Brian Gerst
@ 2015-05-18 20:36     ` Borislav Petkov
  2015-05-18 20:53       ` H. Peter Anvin
  0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2015-05-18 20:36 UTC (permalink / raw)
  To: Brian Gerst
  Cc: Prarit Bhargava, Linux Kernel Mailing List, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, the arch/x86 maintainers,
	Andy Lutomirski, Denys Vlasenko, Dave Hansen,
	Peter P Waskiewicz Jr, Igor Mammedov, Fenghua Yu

On Mon, May 18, 2015 at 04:27:02PM -0400, Brian Gerst wrote:
> 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.

Sounds good - start from the 48th position forward to the first non \s
char. Yeah.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

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

* Re: [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
  2015-05-18 20:36     ` Borislav Petkov
@ 2015-05-18 20:53       ` H. Peter Anvin
  2015-05-18 22:04         ` Prarit Bhargava
  0 siblings, 1 reply; 6+ messages in thread
From: H. Peter Anvin @ 2015-05-18 20:53 UTC (permalink / raw)
  To: Borislav Petkov, Brian Gerst
  Cc: Prarit Bhargava, Linux Kernel Mailing List, Thomas Gleixner,
	Ingo Molnar, the arch/x86 maintainers, Andy Lutomirski,
	Denys Vlasenko, Dave Hansen, Peter P Waskiewicz Jr,
	Igor Mammedov, Fenghua Yu

On 05/18/2015 01:36 PM, Borislav Petkov wrote:
> On Mon, May 18, 2015 at 04:27:02PM -0400, Brian Gerst wrote:
>> 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.
> 
> 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


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

* Re: [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation
  2015-05-18 20:53       ` H. Peter Anvin
@ 2015-05-18 22:04         ` Prarit Bhargava
  0 siblings, 0 replies; 6+ messages in thread
From: Prarit Bhargava @ 2015-05-18 22:04 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Borislav Petkov, Brian Gerst, Linux Kernel Mailing List,
	Thomas Gleixner, Ingo Molnar, the arch/x86 maintainers,
	Andy Lutomirski, Denys Vlasenko, Dave Hansen,
	Peter P Waskiewicz Jr, Igor Mammedov, Fenghua Yu



On 05/18/2015 04:53 PM, H. Peter Anvin wrote:
> On 05/18/2015 01:36 PM, Borislav Petkov wrote:
>> On Mon, May 18, 2015 at 04:27:02PM -0400, Brian Gerst wrote:
>>> 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.
>>
>> 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.

> 
> 	-hpa
> 

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

end of thread, other threads:[~2015-05-18 22:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-18 18:21 [PATCH] x86, cpuinfo fix cpu_data(0) x86_model_id field truncation Prarit Bhargava
2015-05-18 19:45 ` Borislav Petkov
2015-05-18 20:27   ` Brian Gerst
2015-05-18 20:36     ` Borislav Petkov
2015-05-18 20:53       ` H. Peter Anvin
2015-05-18 22:04         ` Prarit Bhargava

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).