From: Sean Christopherson <seanjc@google.com>
To: Tom Lendacky <thomas.lendacky@amd.com>
Cc: "Nikunj A. Dadhania" <nikunj@amd.com>,
pbonzini@redhat.com, kvm@vger.kernel.org,
santosh.shukla@amd.com, bp@alien8.de, isaku.yamahata@intel.com
Subject: Re: [PATCH v4 5/5] KVM: SVM: Enable Secure TSC for SNP guests
Date: Tue, 11 Mar 2025 07:52:02 -0700 [thread overview]
Message-ID: <Z9BOEtM6bm-ng68c@google.com> (raw)
In-Reply-To: <0d121f41-a31d-1c0b-22cb-9533dd983b8a@amd.com>
On Tue, Mar 11, 2025, Tom Lendacky wrote:
> On 3/11/25 06:05, Nikunj A. Dadhania wrote:
> > On 3/11/2025 2:41 PM, Nikunj A. Dadhania wrote:
> >> On 3/10/2025 9:09 PM, Tom Lendacky wrote:
> >>> On 3/10/25 01:45, Nikunj A Dadhania wrote:
> >>
> >>>> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> >>>> index 50263b473f95..b61d6bd75b37 100644
> >>>> --- a/arch/x86/kvm/svm/sev.c
> >>>> +++ b/arch/x86/kvm/svm/sev.c
> >>>> @@ -2205,6 +2205,20 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp)
> >>>>
> >>>> start.gctx_paddr = __psp_pa(sev->snp_context);
> >>>> start.policy = params.policy;
> >>>> +
> >>>> + if (snp_secure_tsc_enabled(kvm)) {
> >>>> + u32 user_tsc_khz = params.desired_tsc_khz;
> >>>> +
> >>>> + /* Use tsc_khz if the VMM has not provided the TSC frequency */
> >>>> + if (!user_tsc_khz)
> >>>> + user_tsc_khz = tsc_khz;
> >>>> +
> >>>> + start.desired_tsc_khz = user_tsc_khz;
The code just below this clobbers kvm->arch.default_tsc_khz, which could already
have been set by userspace. Why? Either require params.desired_tsc_khz to match
kvm->arch.default_tsc_khz, or have KVM's ABI be that KVM stuffs desired_tsc_khz
based on kvm->arch.default_tsc_khz. I don't see any reason to add yet another
way to control TSC.
> >>> Do we need to perform any sanity checking against this value?
> >>
> >> On the higher side, sev-snp-guest.stsc-freq is u32, a Secure TSC guest boots fine with
> >> TSC frequency set to the highest value (stsc-freq=0xFFFFFFFF).
> >>
> >> On the lower side as MSR_AMD64_GUEST_TSC_FREQ is in MHz, TSC clock should at least be 1Mhz.
> >
> > Something like this ?
> >
> > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> > index b61d6bd75b37..c46b6afa969d 100644
> > --- a/arch/x86/kvm/svm/sev.c
> > +++ b/arch/x86/kvm/svm/sev.c
> > @@ -2213,6 +2213,14 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp)
> > if (!user_tsc_khz)
> > user_tsc_khz = tsc_khz;
> >
> > + /*
> > + * The minimum granularity for reporting Secure TSC frequency is
> > + * 1MHz. Return an error if the user specifies a TSC frequency
> > + * less than 1MHz.
> > + */
> > + if (user_tsc_khz < 1000)
> > + return -EINVAL;
>
> Seems reasonable to me. I'll let Sean or Paolo weigh in on it. I don't
> think we need a message, there should be a check in the VMM, too, which
> would be able to provide information to the end user?
Why bother? Userspace can DoS the guest anytime it wants. A TSC frequency of
1MHz on a modern CPU is absolutely absurd. Making that the minimum is is likely
going to do nothing but sow confusion.
next prev parent reply other threads:[~2025-03-11 14:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 6:39 [PATCH v4 0/5] Enable Secure TSC for SEV-SNP Nikunj A Dadhania
2025-03-10 6:43 ` [PATCH v4 1/5] x86/cpufeatures: Add SNP Secure TSC Nikunj A Dadhania
2025-03-10 15:03 ` Tom Lendacky
2025-03-13 15:15 ` Vaishali Thakkar
2025-03-13 15:38 ` Borislav Petkov
2025-03-10 6:45 ` [PATCH v4 2/5] KVM: SVM: Add missing member in SNP_LAUNCH_START command structure Nikunj A Dadhania
2025-03-10 6:45 ` [PATCH v4 3/5] KVM: SVM: Add GUEST_TSC_FREQ MSR for Secure TSC enabled guests Nikunj A Dadhania
2025-03-10 15:09 ` Tom Lendacky
2025-03-10 6:45 ` [PATCH v4 4/5] KVM: SVM: Prevent writes to TSC MSR when Secure TSC is enabled Nikunj A Dadhania
2025-03-10 15:23 ` Tom Lendacky
2025-03-11 6:49 ` Nikunj A. Dadhania
2025-03-10 6:45 ` [PATCH v4 5/5] KVM: SVM: Enable Secure TSC for SNP guests Nikunj A Dadhania
2025-03-10 15:39 ` Tom Lendacky
2025-03-11 9:11 ` Nikunj A. Dadhania
2025-03-11 11:05 ` Nikunj A. Dadhania
2025-03-11 14:33 ` Tom Lendacky
2025-03-11 14:52 ` Sean Christopherson [this message]
2025-03-11 15:33 ` Nikunj A. Dadhania
2025-03-11 15:53 ` Sean Christopherson
2025-03-11 16:02 ` 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=Z9BOEtM6bm-ng68c@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=isaku.yamahata@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 \
/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