From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Reiji Watanabe <reijiw@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Tom Lendacky <thomas.lendacky@amd.com>
Subject: Re: [PATCH v2] KVM: SVM: Delay restoration of host MSR_TSC_AUX until return to userspace
Date: Fri, 23 Apr 2021 14:12:32 +0000 [thread overview]
Message-ID: <YILV0KrBUaESfTiY@google.com> (raw)
In-Reply-To: <8cc2bb9a-167e-598c-6a9e-c23e943b1248@redhat.com>
On Fri, Apr 23, 2021, Paolo Bonzini wrote:
> On 22/04/21 22:12, Sean Christopherson wrote:
> > 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;
> >
>
> Ok, squashed in the following:
Too fast! The below won't compile (s/msr_info/msr and 'r' needs to be defined),
and the get_msr() path needs the guest_cpuid_has() check. I'll spin a v3.
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 14ff7f0963e9..00e9680969a2 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -2875,16 +2875,28 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
> 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.
> */
> - svm->tsc_aux = data;
> -
> preempt_disable();
> - kvm_set_user_return_msr(TSC_AUX_URET_SLOT, data, -1ull);
> + 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;
> case MSR_IA32_DEBUGCTLMSR:
> if (!boot_cpu_has(X86_FEATURE_LBRV)) {
>
> Paolo
>
next prev parent reply other threads:[~2021-04-23 14:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-22 0:17 [PATCH v2] KVM: SVM: Delay restoration of host MSR_TSC_AUX until return to userspace Sean Christopherson
2021-04-22 6:45 ` Paolo Bonzini
2021-04-22 19:02 ` Reiji Watanabe
2021-04-22 20:12 ` Sean Christopherson
2021-04-22 22:39 ` Reiji Watanabe
2021-04-23 6:13 ` Paolo Bonzini
2021-04-23 14:12 ` Sean Christopherson [this message]
2021-04-23 14:18 ` Paolo Bonzini
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=YILV0KrBUaESfTiY@google.com \
--to=seanjc@google.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=reijiw@google.com \
--cc=thomas.lendacky@amd.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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.