Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1383821

[PATCH v2] x86/vdso: Use RDPID in preference to LSL when available

From Andy Lutomirski <luto@kernel.org>
Newsgroups linux.kernel
Subject [PATCH v2] x86/vdso: Use RDPID in preference to LSL when available
Date 2016-04-21 03:20 +0200
Message-ID <rqbrI-EU-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


RDPID is a new instruction that reads MSR_TSC_AUX quickly.  This
should be considerably faster than reading the GDT.  Add a
cpufeature for it and use it from __vdso_getcpu when available.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---

I don't have a Cannonlake CPU (or whatever CPU I'd need for this).
Could someone who has such a beast give this a try?

Boris, could you double-check me?  You're a lot more familiar with
CPUID stuff and the instruction tables than I am, and I can't fall
back to a real disassembler because the instruction is too new.

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.

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 */
+			X86_FEATURE_RDPID,
+			[p] "=a" (p), [seg] "r" (__PER_CPU_SEG));
 
 	return p;
 }
-- 
2.5.5

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH v2] x86/vdso: Use RDPID in preference to LSL when available Andy Lutomirski <luto@kernel.org> - 2016-04-21 03:20 +0200
  Re: [PATCH v2] x86/vdso: Use RDPID in preference to LSL when  available Borislav Petkov <bp@alien8.de> - 2016-04-21 14:20 +0200
    Re: [PATCH v2] x86/vdso: Use RDPID in preference to LSL when available Andy Lutomirski <luto@amacapital.net> - 2016-04-21 17:30 +0200
      Re: [PATCH v2] x86/vdso: Use RDPID in preference to LSL when  available Borislav Petkov <bp@alien8.de> - 2016-04-21 18:30 +0200

csiph-web