From: Nikunj A Dadhania <nikunj@amd.com>
To: <linux-kernel@vger.kernel.org>, <bp@alien8.de>, <x86@kernel.org>
Cc: <seanjc@google.com>, <tglx@linutronix.de>, <mingo@redhat.com>,
<dave.hansen@linux.intel.com>, <thomas.lendacky@amd.com>,
<santosh.shukla@amd.com>, Nikunj A Dadhania <nikunj@amd.com>
Subject: [PATCH] x86/sev: Improve handling of writes to intercepted GUEST_TSC_FREQ
Date: Fri, 11 Jul 2025 09:42:00 +0530 [thread overview]
Message-ID: <20250711041200.87892-1-nikunj@amd.com> (raw)
From: Sean Christopherson <seanjc@google.com>
For Secure TSC enabled guests, don't panic when a guest writes to
intercepted GUEST_TSC_FREQ MSR. Instead, ignore writes to GUEST_TSC_FREQ,
similar to MSR_IA32_TSC, and log a warning instead.
Only terminate the guest when reading from intercepted GUEST_TSC_FREQ MSR
with Secure TSC enabled, as this indicates an unexpected hypervisor
configuration.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
---
arch/x86/coco/sev/vc-handle.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c
index faf1fce89ed4..581e34083321 100644
--- a/arch/x86/coco/sev/vc-handle.c
+++ b/arch/x86/coco/sev/vc-handle.c
@@ -376,24 +376,21 @@ static enum es_result __vc_handle_secure_tsc_msrs(struct pt_regs *regs, bool wri
u64 tsc;
/*
- * GUEST_TSC_FREQ should not be intercepted when Secure TSC is enabled.
- * Terminate the SNP guest when the interception is enabled.
+ * Writing to MSR_IA32_TSC can cause subsequent reads of the TSC to
+ * return undefined values, and GUEST_TSC_FREQ is read-only. Ignore
+ * all writes, but WARN to log the kernel bug.
*/
- if (regs->cx == MSR_AMD64_GUEST_TSC_FREQ)
- return ES_VMM_ERROR;
+ if (WARN_ON_ONCE(write))
+ return ES_OK;
/*
- * Writes: Writing to MSR_IA32_TSC can cause subsequent reads of the TSC
- * to return undefined values, so ignore all writes.
- *
- * Reads: Reads of MSR_IA32_TSC should return the current TSC value, use
- * the value returned by rdtsc_ordered().
+ * GUEST_TSC_FREQ read should not be intercepted when Secure TSC is
+ * enabled. Terminate the SNP guest when the interception is enabled.
*/
- if (write) {
- WARN_ONCE(1, "TSC MSR writes are verboten!\n");
- return ES_OK;
- }
+ if (regs->cx == MSR_AMD64_GUEST_TSC_FREQ)
+ return ES_VMM_ERROR;
+ /* Reads of MSR_IA32_TSC should return the current TSC value. */
tsc = rdtsc_ordered();
regs->ax = lower_32_bits(tsc);
regs->dx = upper_32_bits(tsc);
--
2.43.0
next reply other threads:[~2025-07-11 4:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 4:12 Nikunj A Dadhania [this message]
2025-07-14 10:44 ` Borislav Petkov
2025-07-14 14:24 ` Sean Christopherson
2025-07-14 14:59 ` Tom Lendacky
2025-07-14 15:17 ` Sean Christopherson
2025-07-14 16:16 ` Borislav Petkov
2025-07-14 16:36 ` Sean Christopherson
2025-07-15 8:37 ` Nikunj A Dadhania
2025-07-15 8:43 ` Borislav Petkov
2025-07-15 8:58 ` Nikunj A Dadhania
2025-07-15 8:38 ` Borislav Petkov
2025-07-15 9:13 ` Nikunj A Dadhania
2025-07-15 9:44 ` Borislav Petkov
2025-07-15 12:47 ` Tom Lendacky
2025-07-16 6:09 ` Nikunj A Dadhania
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=20250711041200.87892-1-nikunj@amd.com \
--to=nikunj@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=santosh.shukla@amd.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--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
all inboxes | Powered by JetHome®