[tip:,x86/urgent] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported
diff mbox series

Message ID 162030324711.29796.18380824416576531617.tip-bot2@tip-bot2
State Accepted
Commit b6b4fbd90b155a0025223df2c137af8a701d53b3
Headers show
Series
  • [tip:,x86/urgent] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported
Related show

Commit Message

tip-bot2 for Cassio Neri May 6, 2021, 12:14 p.m. UTC
The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     b6b4fbd90b155a0025223df2c137af8a701d53b3
Gitweb:        https://git.kernel.org/tip/b6b4fbd90b155a0025223df2c137af8a701d53b3
Author:        Sean Christopherson <seanjc@google.com>
AuthorDate:    Tue, 04 May 2021 15:56:31 -07:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 05 May 2021 21:50:14 +02:00

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

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.

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/kernel/cpu/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 6bdb69a..490bed0 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1851,7 +1851,7 @@  static inline void setup_getcpu(int cpu)
 	unsigned long cpudata = vdso_encode_cpunode(cpu, early_cpu_to_node(cpu));
 	struct desc_struct d = { };
 
-	if (boot_cpu_has(X86_FEATURE_RDTSCP))
+	if (boot_cpu_has(X86_FEATURE_RDTSCP) || boot_cpu_has(X86_FEATURE_RDPID))
 		write_rdtscp_aux(cpudata);
 
 	/* Store CPU and node number in limit. */