public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Andi Kleen <andi@firstfloor.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH 1/3] x86, intel: Output microcode revision
Date: Wed, 25 May 2011 08:54:51 +0200	[thread overview]
Message-ID: <20110525065451.GC429@elte.hu> (raw)
In-Reply-To: <1306278210-18285-1-git-send-email-andi@firstfloor.org>


* Andi Kleen <andi@firstfloor.org> wrote:

> From: Andi Kleen <ak@linux.intel.com>
> 
> I got a request to make it easier to determine the microcode update level
> on Intel CPUs. This patch adds a new "cpu update" field to /proc/cpuinfo,
> which I added at the end to minimize impact on parsers.

Agreed, that is a good idea, adding this to cpuinfo makes sense.

Your patch is rather messy though:

> The update level is also outputed on fatal machine checks together
> with the other CPUID model information.
> 
> I removed the respective code from the microcode update driver, it
> just reads the field from cpu_data. Also when the microcode is updated
> it fills in the new values too.
> 
> I had to add a memory barrier to native_cpuid to prevent it being
> optimized away when the result is not used.
> 
> This turns out to clean up further code which already got this
> information manually. This is done in followon patches.
>
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>  arch/x86/include/asm/processor.h  |    5 ++++-
>  arch/x86/kernel/cpu/intel.c       |   10 ++++++++++
>  arch/x86/kernel/cpu/mcheck/mce.c  |    5 +++--
>  arch/x86/kernel/cpu/proc.c        |    6 +++++-
>  arch/x86/kernel/microcode_intel.c |    9 +++------
>  5 files changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
> index 4c25ab4..23b7e26 100644
> --- a/arch/x86/include/asm/processor.h
> +++ b/arch/x86/include/asm/processor.h
> @@ -111,6 +111,8 @@ struct cpuinfo_x86 {
>  	/* Index into per_cpu list: */
>  	u16			cpu_index;
>  #endif
> +	/* CPU update signature */
> +	u32			x86_cpu_update;

This should be cpu_microcode_version instead. We already know its x86 so the 
x86_ prefix is superfluous. 'cpu_update' is also rather ambigious and does not 
describe much.

> diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
> index 1edf5ba..150623a 100644
> --- a/arch/x86/kernel/cpu/intel.c
> +++ b/arch/x86/kernel/cpu/intel.c
> @@ -364,6 +364,16 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c)
>  
>  	early_init_intel(c);
>  
> +	/* Determine CPU update level */
> +	if (c->x86 >= 6 && !(cpu_has(c, X86_FEATURE_IA64))) {	
> +		unsigned lo;
> +
> +		wrmsr(MSR_IA32_UCODE_REV, 0, 0);
> +		/* The CPUID 1 fills in the MSR */
> +		cpuid_eax(1);
> +		rdmsr(MSR_IA32_UCODE_REV, lo, c->x86_cpu_update);
> +	}


So, during the course of developing this, did it occur to you that other x86 
CPUs should fill in this information as well?

If yes, did it occur to you to do the obvious git log 
arch/x86/kernel/microcode*.c command to figure out who else might be interested 
in this, and add them to the Cc: instead of forcing the maintainer to do that?

Also, and this is a repeat pattern from you Andi, you've silently made code worse
while moving it. You've changed this:

> -	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
> -	/* see notes above for revision 1.07.  Apparent chip bug */
> -	sync_core();
> -	/* get the current revision from MSR 0x8B */
> -	rdmsr(MSR_IA32_UCODE_REV, val[0], csig->rev);
> -

To:

> +		unsigned lo;
> +
> +		wrmsr(MSR_IA32_UCODE_REV, 0, 0);
> +		/* The CPUID 1 fills in the MSR */
> +		cpuid_eax(1);
> +		rdmsr(MSR_IA32_UCODE_REV, lo, c->x86_cpu_update);

Firstly, name 'lo' appropriately - 'lo' in itself says nothing and keeps the 
reader wondering about what recreational drugs the writer of this code was on.

Obviously Secondly you've removed the reference to this chip bug:

> -	/* see notes above for revision 1.07.  Apparent chip bug */

Why? If you think it's not a bug (but got documented meanwhile as the official 
way of updating the microcode and reading out the version) then update the 
comments in a *separate* patch, and update the *other* reference to it as well.

You are repeating the same mistakes again and again.

>  	intel_workarounds(c);
>  
>  	/*
> diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
> index ff1ae9b..e93c41f 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce.c
> @@ -220,8 +220,9 @@ static void print_mce(struct mce *m)
>  		pr_cont("MISC %llx ", m->misc);
>  
>  	pr_cont("\n");
> -	pr_emerg(HW_ERR "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
> -		m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid);
> +	pr_emerg(HW_ERR "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x CPU-UPDATE %u\n",
> +		m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid, 
> +		cpu_data(m->extcpu).x86_cpu_update);

This text too should be microcode-version or so. Also, while at it please fix 
that printk() to not shout at users needlessly.

> diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
> index 62ac8cb..cefcc27 100644
> --- a/arch/x86/kernel/cpu/proc.c
> +++ b/arch/x86/kernel/cpu/proc.c
> @@ -132,8 +132,12 @@ static int show_cpuinfo(struct seq_file *m, void *v)
>  				seq_printf(m, " [%d]", i);
>  		}
>  	}
> +	seq_printf(m, "\n");
>  
> -	seq_printf(m, "\n\n");
> +	if (c->x86_cpu_update)
> +		seq_printf(m, "cpu update\t: %u\n", c->x86_cpu_update);
> +
> +	seq_printf(m, "\n");

This too should say microcode version.

Also, please move the field to the logical place, next to "stepping:". The 
argument about parsers is bogus - anyone parsing /proc/cpuinfo is not in a 
fastpath, full stop.

Also, the above sequence is rather suboptimal to begin with - we can and only 
want to execute a *single* seq_printf() there.

> --- a/arch/x86/kernel/microcode_intel.c
> +++ b/arch/x86/kernel/microcode_intel.c
> @@ -161,12 +161,7 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
>  		csig->pf = 1 << ((val[1] >> 18) & 7);
>  	}
>  
> -	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
> -	/* see notes above for revision 1.07.  Apparent chip bug */
> -	sync_core();
> -	/* get the current revision from MSR 0x8B */
> -	rdmsr(MSR_IA32_UCODE_REV, val[0], csig->rev);
> -
> +	csig->rev = c->x86_cpu_update;
>  	pr_info("CPU%d sig=0x%x, pf=0x%x, revision=0x%x\n",
>  		cpu_num, csig->sig, csig->pf, csig->rev);
>
>  
> @@ -300,6 +295,7 @@ static int apply_microcode(int cpu)
>  	struct ucode_cpu_info *uci;
>  	unsigned int val[2];
>  	int cpu_num;
> +	struct cpuinfo_x86 *c = &cpu_data(cpu_num);
>  
>  	cpu_num = raw_smp_processor_id();
>  	uci = ucode_cpu_info + cpu;
> @@ -335,6 +331,7 @@ static int apply_microcode(int cpu)
>  		(mc_intel->hdr.date >> 16) & 0xff);
>  
>  	uci->cpu_sig.rev = val[1];
> +	c->x86_cpu_update = val[1];
>  
>  	return 0;

Please factor out the reading of the microcode version - you have now created 
two duplicated open-coded versions of it in cpu.c and microcode_intel.c, with 
mismatching comments - not good.

Also, in this branch:

        if (val[1] != mc_intel->hdr.rev) {
                pr_err("CPU%d update to revision 0x%x failed\n",
                       cpu_num, mc_intel->hdr.rev);
                return -1;
        }

it would be nice to put a check:

		WARN_ON_ONCE(val[1] != c->x86_cpu_update);

To make sure that our notion of the version is still in sync with what the 
hardware's notion is. (it should be)

Thanks,

	Ingo

  parent reply	other threads:[~2011-05-25  6:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-24 23:03 [PATCH 1/3] x86, intel: Output microcode revision Andi Kleen
2011-05-24 23:03 ` [PATCH 2/3] x86, intel: Use cpu_update for Atom errata check Andi Kleen
2011-05-25  6:59   ` Ingo Molnar
2011-05-24 23:03 ` [PATCH 3/3] coretemp: Get microcode revision from cpu_data Andi Kleen
2011-05-24 23:58   ` Yu, Fenghua
2011-05-25  0:39   ` [PATCH 1/3] x86, intel: Output microcode revision Fenghua Yu
     [not found] ` <BANLkTikoa494-bRWtbbXuE6eqLuH0ZPUTg@mail.gmail.com>
     [not found]   ` <493994B35A117E4F832F97C4719C4C04011E214EC2@orsmsx505.amr.corp.intel.com>
2011-05-25  0:47     ` Andi Kleen
2011-05-25  6:54 ` Ingo Molnar [this message]
2011-05-25  8:00   ` Borislav Petkov
2011-05-25  9:05     ` Ingo Molnar
2011-05-25 10:50       ` Borislav Petkov
2011-05-25 11:28         ` Ingo Molnar
2011-05-25 21:08           ` Borislav Petkov
2011-05-25 11:30         ` Ingo Molnar
2011-05-25 16:54   ` Andi Kleen
2011-05-25 18:59     ` Ingo Molnar
2011-05-25 19:13       ` Andi Kleen
2011-05-25  7:06 ` Ingo Molnar
2011-05-25 16:06   ` Henrique de Moraes Holschuh
2011-05-25 16:58     ` Andi Kleen
2011-05-25 18:24       ` Ingo Molnar
2011-05-25 19:04         ` Henrique de Moraes Holschuh
2011-05-25 19:36           ` Ingo Molnar
2011-05-25 19:05         ` Andi Kleen
2011-05-25 19:45           ` Ingo Molnar
2011-05-29 10:21 ` Jan Ceuleers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110525065451.GC429@elte.hu \
    --to=mingo@elte.hu \
    --cc=ak@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox