Re: [PATCH v11 8/8] KVM: SVM: Enable Secure TSC for SNP guests
From: Sean Christopherson
Date: Wed Aug 20 2025 - 09:03:17 EST
On Wed, Aug 20, 2025, Nikunj A. Dadhania wrote:
>
>
> On 8/20/2025 5:18 AM, Sean Christopherson wrote:
> > From: Nikunj A Dadhania <nikunj@xxxxxxx>
> >
> > @@ -2195,6 +2206,12 @@ 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_is_secure_tsc_enabled(kvm)) {
> > + WARN_ON_ONCE(!kvm->arch.default_tsc_khz);
>
> Any particular reason to drop the the following change:
>
> + if (WARN_ON(!kvm->arch.default_tsc_khz)) {
> + rc = -EINVAL;
> + goto e_free_context;
> + }
Based on this conversation[*], both Kai and I expected KVM to let firmware deal
with the should-be-impossible situation.
On Tue, Jul 8, 2025 at 9:15 PM Nikunj A. Dadhania <nikunj@xxxxxxx> wrote:
> On 7/8/2025 8:04 PM, Sean Christopherson wrote:
> > On Tue, Jul 08, 2025, Kai Huang wrote:
> >>>> Even some bug results in the default_tsc_khz being 0, will the
> >>>> SNP_LAUNCH_START command catch this and return error?
> >>>
> >>> No, that is an invalid configuration, desired_tsc_khz is set to 0 when
> >>> SecureTSC is disabled. If SecureTSC is enabled, desired_tsc_khz should
> >>> have correct value.
> >>
> >> So it's an invalid configuration that when Secure TSC is enabled and
> >> desired_tsc_khz is 0. Assuming the SNP_LAUNCH_START will return an error
> >> if such configuration is used, wouldn't it be simpler if you remove the
> >> above check and depend on the SNP_LAUNCH_START command to catch the
> >> invalid configuration?
> >
> > Support for secure TSC should depend on tsc_khz being non-zero. That way it'll
> > be impossible for arch.default_tsc_khz to be zero at runtime. Then KVM can WARN
> > on arch.default_tsc_khz being zero during SNP_LAUNCH_START.
>
> Sure.
https://lore.kernel.org/all/c327df02-c2eb-41e7-9402-5a16aa211265@xxxxxxx
>
> As this is an unsupported configuration as per the SEV SNP Firmware ABI Specification:
Right, but what happens if KVM manages to pass in '0' for the frequency? Does
SNP_LAUNCH_START fail? If so, bailing from KVM doesn't seem to add any value.
>
> 8.16 SNP_LAUNCH_START
>
> DESIRED_TSC_FREQ
> Hypervisor-desired mean TSC frequency in KHz of the guest. This field has no
> effect if guests do not enable Secure TSC in the VMSA. The hypervisor should
> set this field to 0h if it *does not support Secure TSC* for this guest.
>
> > + start.desired_tsc_khz = kvm->arch.default_tsc_khz;
> > + }
> > +
> Regards,Nikunj