mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: kan.liang@intel.com, peterz@infradead.org
Cc: andi@firstfloor.org, alexander.shishkin@linux.intel.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] x86 msr: msr goto extension support
Date: Thu, 31 Jul 2014 14:05:48 -0700	[thread overview]
Message-ID: <53DAAFAC.9000502@amacapital.net> (raw)
In-Reply-To: <1406799663-18192-1-git-send-email-kan.liang@intel.com>

On 07/31/2014 02:41 AM, kan.liang@intel.com wrote:
> From: Kan Liang <kan.liang@intel.com>
> 
> Currently, {rd,wr}msrl_safe can handle the exception which caused by accessing
> specific MSR.
> However, it will introduce extra conditional branch for testing errors. That
> will impact the "fast" path's performance.
> The newly implemented {rd,wr}msrl_goto function can not only handle the
> exception which caused by accessing specific MSR,
> but also takes advantage of the asm goto extension to eliminate the impact of
> performance.
> 
> The asm goto extension is supported by GCC 4.5 and later versions. If the
> compiler doesn't support goto extension, _safe will be used to replace _goto.
> 
> Signed-off-by: Kan Liang <kan.liang@intel.com>
> ---
>  arch/x86/include/asm/msr.h      | 60 +++++++++++++++++++++++++++++++++++++++++
>  arch/x86/include/asm/paravirt.h | 18 +++++++++++++
>  2 files changed, 78 insertions(+)
> 
> diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
> index de36f22..55438da 100644
> --- a/arch/x86/include/asm/msr.h
> +++ b/arch/x86/include/asm/msr.h
> @@ -203,6 +203,66 @@ do {                                                            \
>  
>  #define rdtscpll(val, aux) (val) = native_read_tscp(&(aux))
>  
> +#ifdef CC_HAVE_ASM_GOTO
> +
> +/*
> + * The _goto version is rdmsrl/wrmsrl with exception handling
> + * The advantage (than _safe) is that it can directly jump in the
> + * exception handling code, and never test in the "fast" path.
> + *
> + * Since _goto doesn't support output, try to protect the output
> + * registers by clobbers, and process the registers immediately.
> + */
> +#define rdmsrl_goto(msr, result, fail_label)			\
> +do {								\
> +	DECLARE_ARGS(val, low, high);				\
> +	asm_volatile_goto("2: rdmsr\n"				\
> +			"1:\n\t"				\
> +			_ASM_EXTABLE(2b, %l[fail_label])	\
> +			: /* No outputs. */			\
> +			: "c" (msr)				\
> +			: "%rax", "%rdx"			\
> +			: fail_label);				\
> +	asm volatile (""					\
> +			: EAX_EDX_RET(val, low, high)		\
> +			: );					\

This is scary -- the compiler is free to optimize this incorrectly, and
it doesn't even seem very farfetched to me.

> +	result = EAX_EDX_VAL(val, low, high);			\
> +} while (0)
> +
> +#define wrmsrl_goto(msr, val, fail_label)			\
> +do {								\
> +	unsigned low, high;					\
> +	low = (u32)val;						\
> +	high = (u32)(val >> 32);				\
> +	asm_volatile_goto("2: wrmsr\n"				\
> +			"1:\n\t"				\
> +			_ASM_EXTABLE(2b, %l[fail_label])	\
> +			: /* No outputs. */			\
> +			: "c" (msr), "a" (low), "d" (high)	\
> +			: "memory"				\
> +			: fail_label);				\
> +} while (0)

I like this one.

--Andy

  parent reply	other threads:[~2014-07-31 21:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-31  9:41 kan.liang
2014-07-31  9:41 ` [PATCH 2/3] x86 perf: Protect LBR msrs accessing against potential #GP kan.liang
2014-08-01  7:38   ` Peter Zijlstra
2014-08-01  7:44     ` Peter Zijlstra
2014-08-01 13:21       ` Andi Kleen
2014-08-01 18:50         ` Peter Zijlstra
2014-08-02  5:27           ` Ingo Molnar
2014-07-31  9:41 ` [PATCH 3/3] x86 perf: Protect LBR and BTS enabling kan.liang
2014-07-31 21:05 ` Andy Lutomirski [this message]
2014-08-01  8:05   ` [PATCH 1/3] x86 msr: msr goto extension support Peter Zijlstra

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=53DAAFAC.9000502@amacapital.net \
    --to=luto@amacapital.net \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.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

Powered by JetHome