* [PATCH 0/2] x86/cpu: RDPID+MSR_TSC_AUX fix and a cleanup @ 2021-05-04 22:56 Sean Christopherson 2021-05-04 22:56 ` [PATCH 1/2] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported Sean Christopherson 2021-05-04 22:56 ` [PATCH 2/2] x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers Sean Christopherson 0 siblings, 2 replies; 5+ messages in thread From: Sean Christopherson @ 2021-05-04 22:56 UTC (permalink / raw) To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86 Cc: H. Peter Anvin, linux-kernel, Reiji Watanabe, Jim Mattson, Andy Lutomirski, Sean Christopherson Fix a bug where MSR_TSC_AUX is left uninitialized in the theoretically possible scenario where RDPID is supported by RDTSCP is not. AFAIK, no such CPUs exits, but both Intel and AMD architecturally allow RDPID and MSR_TSC_AUX to exist without RDTSCP. Found by inspection when cleaning up a similar mess in KVM. Confirmed the bug and verified the fix by running the problematic CPU model under KVM (once KVM's even bigger trainwreck was fixed). Sean Christopherson (2): x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers arch/x86/include/asm/msr.h | 4 ---- arch/x86/kernel/cpu/common.c | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) -- 2.31.1.527.g47e6f16901-goog ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported 2021-05-04 22:56 [PATCH 0/2] x86/cpu: RDPID+MSR_TSC_AUX fix and a cleanup Sean Christopherson @ 2021-05-04 22:56 ` Sean Christopherson 2021-05-06 12:14 ` [tip: x86/urgent] " tip-bot2 for Sean Christopherson 2021-05-04 22:56 ` [PATCH 2/2] x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers Sean Christopherson 1 sibling, 1 reply; 5+ messages in thread From: Sean Christopherson @ 2021-05-04 22:56 UTC (permalink / raw) To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86 Cc: H. Peter Anvin, linux-kernel, Reiji Watanabe, Jim Mattson, Andy Lutomirski, Sean Christopherson 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") Cc: stable@vger.kernel.org Cc: Reiji Watanabe <reijiw@google.com> Cc: Jim Mattson <jmattson@google.com> Cc: Andy Lutomirski <luto@kernel.org> Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/x86/kernel/cpu/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index ab640abe26b6..1e576cc831c1 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1850,7 +1850,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. */ -- 2.31.1.527.g47e6f16901-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip: x86/urgent] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported 2021-05-04 22:56 ` [PATCH 1/2] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported Sean Christopherson @ 2021-05-06 12:14 ` tip-bot2 for Sean Christopherson 0 siblings, 0 replies; 5+ messages in thread From: tip-bot2 for Sean Christopherson @ 2021-05-06 12:14 UTC (permalink / raw) To: linux-tip-commits Cc: Sean Christopherson, Thomas Gleixner, stable, x86, linux-kernel 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(-) 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. */ ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers 2021-05-04 22:56 [PATCH 0/2] x86/cpu: RDPID+MSR_TSC_AUX fix and a cleanup Sean Christopherson 2021-05-04 22:56 ` [PATCH 1/2] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported Sean Christopherson @ 2021-05-04 22:56 ` Sean Christopherson 2021-05-06 12:14 ` [tip: x86/urgent] " tip-bot2 for Sean Christopherson 1 sibling, 1 reply; 5+ messages in thread From: Sean Christopherson @ 2021-05-04 22:56 UTC (permalink / raw) To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86 Cc: H. Peter Anvin, linux-kernel, Reiji Watanabe, Jim Mattson, Andy Lutomirski, Sean Christopherson Drop write_tsc() and write_rdtscp_aux(); the former has no users, and the latter has only a single user and is slightly misleading since the only in-kernel consumer of MSR_TSC_AUX is RDPID, not RDTSCP. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/x86/include/asm/msr.h | 4 ---- arch/x86/kernel/cpu/common.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index e16cccdd0420..a3f87f1015d3 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -324,10 +324,6 @@ static inline int wrmsrl_safe(u32 msr, u64 val) return wrmsr_safe(msr, (u32)val, (u32)(val >> 32)); } -#define write_tsc(low, high) wrmsr(MSR_IA32_TSC, (low), (high)) - -#define write_rdtscp_aux(val) wrmsr(MSR_TSC_AUX, (val), 0) - struct msr *msrs_alloc(void); void msrs_free(struct msr *msrs); int msr_set_bit(u32 msr, u8 bit); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 1e576cc831c1..0fc80c5ba5ae 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) struct desc_struct d = { }; if (boot_cpu_has(X86_FEATURE_RDTSCP) || boot_cpu_has(X86_FEATURE_RDPID)) - write_rdtscp_aux(cpudata); + wrmsr(MSR_TSC_AUX, cpudata, 0); /* Store CPU and node number in limit. */ d.limit0 = cpudata; -- 2.31.1.527.g47e6f16901-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip: x86/urgent] x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers 2021-05-04 22:56 ` [PATCH 2/2] x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers Sean Christopherson @ 2021-05-06 12:14 ` tip-bot2 for Sean Christopherson 0 siblings, 0 replies; 5+ messages in thread From: tip-bot2 for Sean Christopherson @ 2021-05-06 12:14 UTC (permalink / raw) To: linux-tip-commits; +Cc: Sean Christopherson, Thomas Gleixner, x86, linux-kernel The following commit has been merged into the x86/urgent branch of tip: Commit-ID: fc48a6d1faadbf08b7a840d58a5a6eb85bd1a79a Gitweb: https://git.kernel.org/tip/fc48a6d1faadbf08b7a840d58a5a6eb85bd1a79a Author: Sean Christopherson <seanjc@google.com> AuthorDate: Tue, 04 May 2021 15:56:32 -07:00 Committer: Thomas Gleixner <tglx@linutronix.de> CommitterDate: Wed, 05 May 2021 21:50:14 +02:00 x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers Drop write_tsc() and write_rdtscp_aux(); the former has no users, and the latter has only a single user and is slightly misleading since the only in-kernel consumer of MSR_TSC_AUX is RDPID, not RDTSCP. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20210504225632.1532621-3-seanjc@google.com --- arch/x86/include/asm/msr.h | 4 ---- arch/x86/kernel/cpu/common.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index e16cccd..a3f87f1 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -324,10 +324,6 @@ static inline int wrmsrl_safe(u32 msr, u64 val) return wrmsr_safe(msr, (u32)val, (u32)(val >> 32)); } -#define write_tsc(low, high) wrmsr(MSR_IA32_TSC, (low), (high)) - -#define write_rdtscp_aux(val) wrmsr(MSR_TSC_AUX, (val), 0) - struct msr *msrs_alloc(void); void msrs_free(struct msr *msrs); int msr_set_bit(u32 msr, u8 bit); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 490bed0..a1b756c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1852,7 +1852,7 @@ static inline void setup_getcpu(int cpu) struct desc_struct d = { }; if (boot_cpu_has(X86_FEATURE_RDTSCP) || boot_cpu_has(X86_FEATURE_RDPID)) - write_rdtscp_aux(cpudata); + wrmsr(MSR_TSC_AUX, cpudata, 0); /* Store CPU and node number in limit. */ d.limit0 = cpudata; ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-06 12:15 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-05-04 22:56 [PATCH 0/2] x86/cpu: RDPID+MSR_TSC_AUX fix and a cleanup Sean Christopherson 2021-05-04 22:56 ` [PATCH 1/2] x86/cpu: Initialize MSR_TSC_AUX if RDTSCP *or* RDPID is supported Sean Christopherson 2021-05-06 12:14 ` [tip: x86/urgent] " tip-bot2 for Sean Christopherson 2021-05-04 22:56 ` [PATCH 2/2] x86/cpu: Remove write_tsc() and write_rdtscp_aux() wrappers Sean Christopherson 2021-05-06 12:14 ` [tip: x86/urgent] " tip-bot2 for Sean Christopherson
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.