public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: X86-ML <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Andreas Herrmann <andreas.herrmann3@amd.com>,
	Henrique de Moraes Holschuh <hmh@hmh.eng.br>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH -v2 1/2] x86, microcode: Sanitize per-cpu microcode reloading interface
Date: Wed, 27 Jun 2012 07:20:02 +0200	[thread overview]
Message-ID: <20120627052002.GA32654@aftab.osrc.amd.com> (raw)
In-Reply-To: <1340747178.21991.105.camel@twins>

On Tue, Jun 26, 2012 at 11:46:18PM +0200, Peter Zijlstra wrote:
> On Tue, 2012-06-26 at 21:40 +0200, Borislav Petkov wrote:
> >  
> > > +void perf_check_microcode(void)
> > > +{
> > > +	if (x86_pmu.check_microcode)
> > > +		x86_pmu.check_microcode();
> > > +}
> > > +EXPORT_SYMBOL_GPL(perf_check_microcode);
> > 
> > Maybe we should call the after-ucode-has-been-updated callback something
> > like arch_verify_microcode_revision or something similar and move it to
> > generic x86 code so that other stuff can use it too, in the future...
> > 
> > Although I'm not aware of any other users right about now.
> 
> Like that notifier list I had earlier? Yeah we can do that if more users
> show up.

Yeah, ok.

> > > @@ -373,7 +375,7 @@ struct x86_pmu {
> > >  	 * Intel DebugStore bits
> > >  	 */
> > >  	int		bts, pebs;
> > > -	int		bts_active, pebs_active;
> > > +	int		bts_active, pebs_active, pebs_broken;
> > 
> > I know you don't like bool's here but maybe make it a bitfield like the
> > one in perf_event_attr?
> 
> I added another patch doing just that:
> 
> ---
> Subject: perf, x86: Save a few bytes in struct x86_pmu
> From: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Date: Tue Jun 26 23:38:39 CEST 2012
> 
> All these are basically boolean flags, use a bitfield to save a few
> bytes.
> 
> Suggested-by: Borislav Petkov <bp@amd64.org>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> ---
>  arch/x86/kernel/cpu/perf_event.h |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> --- a/arch/x86/kernel/cpu/perf_event.h
> +++ b/arch/x86/kernel/cpu/perf_event.h
> @@ -374,8 +374,11 @@ struct x86_pmu {
>  	/*
>  	 * Intel DebugStore bits
>  	 */
> -	int		bts, pebs;
> -	int		bts_active, pebs_active, pebs_broken;
> +	int		bts		:1,
> +			bts_active	:1,
> +			pebs		:1,
> +			pebs_active	:1,
> +			pebs_broken	:1;
>  	int		pebs_record_size;
>  	void		(*drain_pebs)(struct pt_regs *regs);
>  	struct event_constraint *pebs_constraints;
> ---

Yep.

> 
> 
> > >  	int		pebs_record_size;
> > >  	void		(*drain_pebs)(struct pt_regs *regs);
> > >  	struct event_constraint *pebs_constraints;
> > > --- a/arch/x86/kernel/cpu/perf_event_intel.c
> > > +++ b/arch/x86/kernel/cpu/perf_event_intel.c
> > > @@ -1714,11 +1714,54 @@ static __init void intel_clovertown_quir
> > >  	x86_pmu.pebs_constraints = NULL;
> > >  }
> > >  
> > > +static int intel_snb_pebs_broken(int cpu)
> > > +{
> > > +	u32 rev = UINT_MAX; /* default to broken for unknown models */
> > > +
> > > +	switch (cpu_data(cpu).x86_model) {
> > 
> > cpu_data(cpu) does a per_cpu access three times in this function, maybe
> > declare a local ptr which saves us the next two derefs... (if the
> > compiler is not optimizing those, anyway, that is).
> 
> I was hoping for CSE optimization to do that for me.. its not really a
> performance critical path anyway. I could change it if people think it
> reads better with regular: struct cpuinfo_x86 *c = &cpu_data(cpu);

Right, we maybe will do this a couple of times tops during system
lifetime, ok.

> > > +	get_online_cpus();
> > > +	for_each_online_cpu(cpu)
> > > +		pebs_broken |= intel_snb_pebs_broken(cpu);
> > 
> > if pebs_broken gets set here not on the last cpu, you could break out of
> > the loop early instead of iterating to the last cpu.
> 
> Right you are.. 
> 
> 
> ---
> Subject: perf, x86: Add a microcode revision check for SNB-PEBS
> From: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Date: Fri Jun 08 14:50:50 CEST 2012
> 
> Recent Intel microcode resolved the SNB-PEBS issues, so conditionally
> enable PEBS on SNB hardware depending on the microcode revision.
> 
> Thanks to Stephane for figuring out the various microcode revisions.
> 
> Cc: Stephane Eranian <eranian@google.com>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>

Right, looks ok to me.

If it is of any use:

Acked-by: Borislav Petkov <borislav.petkov@amd.com>

Thanks.

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551

  reply	other threads:[~2012-06-27  5:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-21 12:07 [PATCH -v2 0/2] x86, microcode: Reload ucode only per-system Borislav Petkov
2012-06-21 12:07 ` [PATCH -v2 1/2] x86, microcode: Sanitize per-cpu microcode reloading interface Borislav Petkov
2012-06-21 12:12   ` Peter Zijlstra
2012-06-22 15:46   ` Peter Zijlstra
2012-06-26 19:40     ` Borislav Petkov
2012-06-26 19:51       ` Borislav Petkov
2012-06-26 21:46       ` Peter Zijlstra
2012-06-27  5:20         ` Borislav Petkov [this message]
2012-07-03  4:37         ` Borislav Petkov
2012-07-03  9:26           ` Peter Zijlstra
2012-07-03 10:41             ` Borislav Petkov
2012-07-01 19:35   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
2012-06-21 12:07 ` [PATCH -v2 2/2] x86, microcode: Make reload interface per system Borislav Petkov
2012-06-21 12:12   ` Peter Zijlstra
2012-07-01 19:35   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
2012-06-30 17:45 ` [PATCH -v2 0/2] x86, microcode: Reload ucode only per-system Borislav Petkov
2012-07-02  9:53   ` Peter Zijlstra
2012-07-02 13:05     ` H. Peter Anvin
2012-07-03 10:52       ` Borislav Petkov

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=20120627052002.GA32654@aftab.osrc.amd.com \
    --to=bp@amd64.org \
    --cc=andreas.herrmann3@amd.com \
    --cc=eranian@google.com \
    --cc=hmh@hmh.eng.br \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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