From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752730AbbE0ORs (ORCPT ); Wed, 27 May 2015 10:17:48 -0400 Received: from terminus.zytor.com ([198.137.202.10]:35996 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752324AbbE0ORp (ORCPT ); Wed, 27 May 2015 10:17:45 -0400 Date: Wed, 27 May 2015 07:16:42 -0700 From: tip-bot for Prarit Bhargava Message-ID: Cc: peterz@infradead.org, imammedo@redhat.com, torvalds@linux-foundation.org, dvlasenk@redhat.com, mingo@kernel.org, brgerst@gmail.com, luto@amacapital.net, bp@alien8.de, tglx@linutronix.de, bp@suse.de, prarit@redhat.com, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, hpa@zytor.com, fenghua.yu@intel.com Reply-To: luto@amacapital.net, bp@alien8.de, peterz@infradead.org, dvlasenk@redhat.com, torvalds@linux-foundation.org, imammedo@redhat.com, brgerst@gmail.com, mingo@kernel.org, prarit@redhat.com, dave.hansen@linux.intel.com, fenghua.yu@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@suse.de In-Reply-To: <1432628901-18044-15-git-send-email-bp@alien8.de> References: <1432050210-32036-1-git-send-email-prarit@redhat.com> <1432628901-18044-15-git-send-email-bp@alien8.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cpu] x86/cpu: Strip any /proc/ cpuinfo model name field whitespace Git-Commit-ID: adafb98da6a7af5e45362933a7dae6ab0e5076bf X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: adafb98da6a7af5e45362933a7dae6ab0e5076bf Gitweb: http://git.kernel.org/tip/adafb98da6a7af5e45362933a7dae6ab0e5076bf Author: Prarit Bhargava AuthorDate: Tue, 26 May 2015 10:28:17 +0200 Committer: Ingo Molnar CommitDate: Wed, 27 May 2015 14:38:24 +0200 x86/cpu: Strip any /proc/cpuinfo model name field whitespace When comparing the 'model name' field of each core in /proc/cpuinfo it was noticed that there is a whitespace difference between the cores' model names. After some quick investigation it was noticed that the model name fields were actually different -- processor 0's model name field had trailing whitespace 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 the discrepancy. 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 strips the whitespace at the end of the ->x86_model_id field. But, the ->x86_model_id field should be the same for the all identical CPUs in the box. Thus, we need to remove both leading and trailing whitespace. As a result, the print_cpu_info() output looks like smpboot: CPU0: AMD Opteron(TM) Processor 6272 (fam: 15, model: 01, stepping: 02) and the x86_model_id field is correct on all processors on AMD platforms: _____64_model_name :_AMD_Opteron(TM)_Processor_6272 Output is still correct on an Intel box: ____144_model_name :_Intel(R)_Xeon(R)_CPU_E7-8890_v3_@_2.50GHz Signed-off-by: Prarit Bhargava Signed-off-by: Borislav Petkov Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Igor Mammedov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1432050210-32036-1-git-send-email-prarit@redhat.com Link: http://lkml.kernel.org/r/1432628901-18044-15-git-send-email-bp@alien8.de Signed-off-by: Ingo Molnar --- arch/x86/kernel/cpu/common.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index a62cf04..41a8e9c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -419,7 +419,6 @@ static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {}; static void get_model_name(struct cpuinfo_x86 *c) { unsigned int *v; - char *p, *q; if (c->extended_cpuid_level < 0x80000004) return; @@ -431,18 +430,10 @@ static void get_model_name(struct cpuinfo_x86 *c) c->x86_model_id[48] = 0; /* - * Intel chips right-justify this string for some dumb reason; - * undo that brain damage: + * Remove leading whitespace on Intel processors and trailing + * whitespace on AMD processors. */ - p = q = &c->x86_model_id[0]; - while (*p == ' ') - p++; - if (p != q) { - while (*p) - *q++ = *p++; - while (q <= &c->x86_model_id[48]) - *q++ = '\0'; /* Zero-pad the rest */ - } + memmove(c->x86_model_id, strim(c->x86_model_id), 48); } void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) @@ -1122,7 +1113,7 @@ void print_cpu_info(struct cpuinfo_x86 *c) printk(KERN_CONT "%s ", vendor); if (c->x86_model_id[0]) - printk(KERN_CONT "%s", strim(c->x86_model_id)); + printk(KERN_CONT "%s", c->x86_model_id); else printk(KERN_CONT "%d86", c->x86);