From: Borislav Petkov <bp@alien8.de>
To: Andy Lutomirski <luto@kernel.org>
Cc: x86@kernel.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] x86/vdso: Use RDPID in preference to LSL when available
Date: Thu, 21 Apr 2016 14:16:40 +0200 [thread overview]
Message-ID: <20160421121640.GC28821@pd.tnic> (raw)
In-Reply-To: <2452e4bba35cf473d975a90d90533cf580a012f3.1461201316.git.luto@kernel.org>
On Wed, Apr 20, 2016 at 06:16:01PM -0700, Andy Lutomirski wrote:
> Also, it's time for someone to do UMIP. I'll see if I can convince
> someone in KVM land to emulate it to make it easier to test.
That'll be fun - we can simply set that bit in CR4 and see who screams
:-P
> Changes from v1:
> - Remove rdpid() from special_instructions.h. (Was a leftover -- sorry.)
>
> arch/x86/include/asm/cpufeatures.h | 1 +
> arch/x86/include/asm/vgtod.h | 7 ++++++-
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
> index 7bfb6b70c745..beaf2fb601ee 100644
> --- a/arch/x86/include/asm/cpufeatures.h
> +++ b/arch/x86/include/asm/cpufeatures.h
> @@ -279,6 +279,7 @@
> /* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 16 */
> #define X86_FEATURE_PKU (16*32+ 3) /* Protection Keys for Userspace */
> #define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */
> +#define X86_FEATURE_RDPID (16*32+ 22) /* RDPID instruction */
>
> /*
> * BUG word(s)
> diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
> index e728699db774..3a01996db58f 100644
> --- a/arch/x86/include/asm/vgtod.h
> +++ b/arch/x86/include/asm/vgtod.h
> @@ -89,8 +89,13 @@ static inline unsigned int __getcpu(void)
> * works on all CPUs. This is volatile so that it orders
> * correctly wrt barrier() and to keep gcc from cleverly
> * hoisting it out of the calling function.
> + *
> + * If RDPID is available, use it.
> */
> - asm volatile ("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
> + alternative_io ("lsl %[p],%[seg]",
> + ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
AFAICT, 0xf8 is correct, if I'm reading the SDM right:
bits [7:6] must be 11b for opcode group 9 and RDPID is in the 11b row,
bits [5:3] are ModRM.reg and they need to be 111b for RDPID (0x7 column)
and the last three [2:0] select the register and they must be 000b for
rAX.
HOWEVER, you need to make the asm output register constraint "=a"
because you're specifying rAX as a destination register for RDPID.
Also, I'm wondering: should we supply that alternative in a separate
inline function in special_instructions.h for wider use? I.e., something
like read_cpu_num() or so...
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
next prev parent reply other threads:[~2016-04-21 12:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-21 1:16 [PATCH v2] x86/vdso: Use RDPID in preference to LSL when available Andy Lutomirski
2016-04-21 12:16 ` Borislav Petkov [this message]
2016-04-21 15:25 ` Andy Lutomirski
2016-04-21 16:26 ` 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=20160421121640.GC28821@pd.tnic \
--to=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--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