diff mbox series

x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported

Message ID 875yzofenz.ffs@nanos.tec.linutronix.de
State New
Headers show
Series x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported | expand

Commit Message

Thomas Gleixner May 12, 2021, 10:08 a.m. UTC
From: Sean Christopherson <seanjc@google.com>

commit b6b4fbd90b155a0025223df2c137af8a701d53b3 upstream

Initialize MSR_TSC_AUX with CPU node information if RDTSCP or RDPID is
supported.  This fixes a bug where vdso_read_cpunode() will read garbage
via RDPID if RDPID is supported but RDTSCP is not.  While no known CPU
supports RDPID but not RDTSCP, both Intel's SDM and AMD's APM allow for
RDPID to exist without RDTSCP, e.g. it's technically a legal CPU model
for a virtual machine.

Note, technically MSR_TSC_AUX could be initialized if and only if RDPID
is supported since RDTSCP is currently not used to retrieve the CPU node.
But, the cost of the superfluous WRMSR is negigible, whereas leaving
MSR_TSC_AUX uninitialized is just asking for future breakage if someone
decides to utilize RDTSCP.

[ tglx: Backport for 4.14/4.19 ]

Fixes: a582c540ac1b ("x86/vdso: Use RDPID in preference to LSL when available")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20210504225632.1532621-2-seanjc@google.com
---
 arch/x86/entry/vdso/vma.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---

Comments

Greg KH May 12, 2021, 10:10 a.m. UTC | #1
On Wed, May 12, 2021 at 12:08:00PM +0200, Thomas Gleixner wrote:
> From: Sean Christopherson <seanjc@google.com>
> 
> commit b6b4fbd90b155a0025223df2c137af8a701d53b3 upstream
> 
> Initialize MSR_TSC_AUX with CPU node information if RDTSCP or RDPID is
> supported.  This fixes a bug where vdso_read_cpunode() will read garbage
> via RDPID if RDPID is supported but RDTSCP is not.  While no known CPU
> supports RDPID but not RDTSCP, both Intel's SDM and AMD's APM allow for
> RDPID to exist without RDTSCP, e.g. it's technically a legal CPU model
> for a virtual machine.
> 
> Note, technically MSR_TSC_AUX could be initialized if and only if RDPID
> is supported since RDTSCP is currently not used to retrieve the CPU node.
> But, the cost of the superfluous WRMSR is negigible, whereas leaving
> MSR_TSC_AUX uninitialized is just asking for future breakage if someone
> decides to utilize RDTSCP.
> 
> [ tglx: Backport for 4.14/4.19 ]

Now queued up, thanks!

greg k-h
diff mbox series

Patch

--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -342,7 +342,7 @@  static void vgetcpu_cpu_init(void *arg)
 #ifdef CONFIG_NUMA
 	node = cpu_to_node(cpu);
 #endif
-	if (static_cpu_has(X86_FEATURE_RDTSCP))
+	if (boot_cpu_has(X86_FEATURE_RDTSCP) || boot_cpu_has(X86_FEATURE_RDPID))
 		write_rdtscp_aux((node << 12) | cpu);
 
 	/*