Re: [PATCH v2] KVM: SVM: Delay restoration of host MSR_TSC_AUX until return to userspace

From: Reiji Watanabe
Date: Thu Apr 22 2021 - 18:39:25 EST


> All in all, I think we want this:
>
> case MSR_TSC_AUX:
> if (!boot_cpu_has(X86_FEATURE_RDTSCP))
> return 1;
>
> if (!msr_info->host_initiated &&
> !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP))
> return 1;
>
> /*
> * TSC_AUX is usually changed only during boot and never read
> * directly. Intercept TSC_AUX instead of exposing it to the
> * guest via direct_access_msrs, and switch it via user return.
> */
> preempt_disable();
> r = kvm_set_user_return_msr(TSC_AUX_URET_SLOT, data, -1ull);
> preempt_enable();
> if (r)
> return 1;
>
> /*
> * Bits 63:32 are dropped by AMD CPUs, but are reserved on
> * Intel CPUs. AMD's APM has incomplete and conflicting info
> * on the architectural behavior; emulate current hardware as
> * doing so ensures migrating from AMD to Intel won't explode.
> */
> svm->tsc_aux = (u32)data;
> break;


Thank you for the explanation.
I understand and the code above looks good to me.
(I would assume we want to check the msr_info->host_initiated and
guest_cpuid_has in svm_get_msr as well)

Thanks,
Reiji