From: Sean Christopherson <seanjc@google.com>
To: "Nikunj A. Dadhania" <nikunj@amd.com>
Cc: bp@alien8.de, pbonzini@redhat.com, kvm@vger.kernel.org,
thomas.lendacky@amd.com, santosh.shukla@amd.com,
isaku.yamahata@intel.com, vaishali.thakkar@suse.com,
kai.huang@intel.com
Subject: Re: [PATCH v8 2/2] KVM: SVM: Enable Secure TSC for SNP guests
Date: Thu, 10 Jul 2025 16:30:00 -0700 [thread overview]
Message-ID: <aHBM-LfEW7FXOjhO@google.com> (raw)
In-Reply-To: <99ca91cd-4363-42b8-bcac-5710684c6d92@amd.com>
On Thu, Jul 10, 2025, Nikunj A. Dadhania wrote:
> On 7/10/2025 6:50 PM, Sean Christopherson wrote:
> > On Thu, Jul 10, 2025, Nikunj A Dadhania wrote:
> >> Sean Christopherson <seanjc@google.com> writes:
> >>> Because there's zero point in not intercepting writes, and KVM shouldn't do
> >>> things for no reason as doing so tends to confuse readers. E.g. I reacted to
> >>> this because I didn't read the changelog first, and was surprised that the guest
> >>> could adjust its TSC frequency (which it obviously can't, but that's what the
> >>> code implies to me).
> >>>
> >>
> >> Agree to your point that MSR read-only and having a MSR_TYPE_RW
> >> creates a special case. I can change this to MSR_TYPE_R. The only thing
> >> which looks inefficient to me is the path to generate the #GP when the
> >> MSR interception is enabled.
> >>
> >> AFAIU, the GUEST_TSC_FREQ write handling for SEV-SNP guest:
> >>
> >> sev_handle_vmgexit()
> >> -> msr_interception()
> >> -> kvm_set_msr_common()
> >> -> kvm_emulate_wrmsr()
> >> -> kvm_set_msr_with_filter()
> >> -> svm_complete_emulated_msr() will inject the #GP
> >>
> >> With MSR interception disabled: vCPU will directly generate #GP
> >
> > Yes, but no well-behaved guest will ever write the MSR, and if a guest does
> > manage to generate a WRMSR, the guest is beyond hosed if it affects performance.
> >
> >>>> The guest vCPU handles it appropriately when interception is disabled.
> >>>>
> >>>> 2) Guest does not expect GUEST_TSC_FREQ MSR to be intercepted(read or write), guest
> >>>> will terminate if GUEST_TSC_FREQ MSR is intercepted by the hypervisor:
> >>>
> >>> But it's read-only, the guest shouldn't be writing. If the vCPU handles #GPs
> >>> appropriately, then it should have no problem handling #VCs on bad writes.
> >>>
> >>>> 38cc6495cdec x86/sev: Prevent GUEST_TSC_FREQ MSR interception for Secure TSC enabled guests
> >>>
> >>> That's a guest bug, it shouldn't be complaining about the host
> >>> intercepting writes.
> >>
> >> The code was written with a perspective that host should not be
> >> intercepting GUEST_TSC_FREQ, as it is a guest-only MSR.
> >
> > It's fine to panic on a _read_, I'm saying the guest shouldn't panic on a write,
> > because the guest shouldn't be writing in the first place.
>
> Agree, and the with the below change the write to GUEST_TSC_FREQ will be ignored.
>
> Should I send a patch with your authorship/signed-off-by ?
Sure, that'd be wonderful!
Signed-off-by: Sean Christopherson <seanjc@google.com>
> > diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c
> > index 0989d98da130..353647339a79 100644
> > --- a/arch/x86/coco/sev/vc-handle.c
> > +++ b/arch/x86/coco/sev/vc-handle.c
> > @@ -369,24 +369,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 (WARN_ON_ONCE(write))
> > + return ES_OK;
> > +
> > + /*
> > + * GUEST_TSC_FREQ should be not be intercepted when Secure TSC is
> > + * enabled. Terminate the SNP guest when the interception is enabled.
> > */
> > if (regs->cx == MSR_AMD64_GUEST_TSC_FREQ)
> > return ES_VMM_ERROR;
> >
> > - /*
> > - * 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().
> > - */
> > - if (write) {
> > - WARN_ONCE(1, "TSC MSR writes are verboten!\n");
> > - return ES_OK;
> > - }
> > -
> > + /* 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);
>
> Regards,
> Nikunj
prev parent reply other threads:[~2025-07-10 23:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 10:10 [PATCH v8 0/2] Enable Secure TSC for SEV-SNP Nikunj A Dadhania
2025-07-07 10:10 ` [PATCH v8 1/2] x86/cpufeatures: Add SNP Secure TSC Nikunj A Dadhania
2025-07-07 10:10 ` [PATCH v8 2/2] KVM: SVM: Enable Secure TSC for SNP guests Nikunj A Dadhania
2025-07-07 13:34 ` Tom Lendacky
2025-07-08 2:21 ` Huang, Kai
2025-07-08 6:45 ` Nikunj A. Dadhania
2025-07-08 10:48 ` Huang, Kai
2025-07-08 14:34 ` Sean Christopherson
2025-07-08 22:42 ` Huang, Kai
2025-07-09 4:14 ` Nikunj A. Dadhania
2025-07-08 7:16 ` Xiaoyao Li
2025-07-08 10:53 ` Huang, Kai
2025-07-08 14:42 ` Sean Christopherson
2025-07-08 22:56 ` Huang, Kai
2025-07-08 23:08 ` Sean Christopherson
2025-07-09 5:54 ` Huang, Kai
2025-07-08 14:37 ` Sean Christopherson
2025-07-09 4:12 ` Nikunj A. Dadhania
2025-07-09 13:02 ` Sean Christopherson
2025-07-10 10:59 ` Nikunj A Dadhania
2025-07-10 13:20 ` Sean Christopherson
2025-07-10 15:04 ` Nikunj A. Dadhania
2025-07-10 23:30 ` Sean Christopherson [this message]
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=aHBM-LfEW7FXOjhO@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=isaku.yamahata@intel.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=santosh.shukla@amd.com \
--cc=thomas.lendacky@amd.com \
--cc=vaishali.thakkar@suse.com \
/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 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.