[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <7b30f2b5-5173-4c3b-85ff-dbfeda3c807a@linux.intel.com>
Date: Thu, 6 Nov 2025 09:55:39 +0800
From: Binbin Wu <binbin.wu@...ux.intel.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Jon Kohler <jon@...anix.com>
Subject: Re: [PATCH 3/4] KVM: x86: Load guest/host XCR0 and XSS outside of the
fastpath run loop
On 11/5/2025 10:43 PM, Sean Christopherson wrote:
> On Wed, Nov 05, 2025, Binbin Wu wrote:
>>
>> On 10/31/2025 6:42 AM, Sean Christopherson wrote:
>> [...]
>>> -void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu)
>>> +static void kvm_load_guest_xfeatures(struct kvm_vcpu *vcpu)
>>> {
>>> if (vcpu->arch.guest_state_protected)
>>> return;
>>> if (kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE)) {
>>> -
>>> if (vcpu->arch.xcr0 != kvm_host.xcr0)
>>> xsetbv(XCR_XFEATURE_ENABLED_MASK, vcpu->arch.xcr0);
>>> @@ -1217,6 +1216,27 @@ void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu)
>>> vcpu->arch.ia32_xss != kvm_host.xss)
>>> wrmsrq(MSR_IA32_XSS, vcpu->arch.ia32_xss);
>>> }
>>> +}
>>> +
>>> +static void kvm_load_host_xfeatures(struct kvm_vcpu *vcpu)
>>> +{
>>> + if (vcpu->arch.guest_state_protected)
>>> + return;
>>> +
>>> + if (kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE)) {
>>> + if (vcpu->arch.xcr0 != kvm_host.xcr0)
>>> + xsetbv(XCR_XFEATURE_ENABLED_MASK, kvm_host.xcr0);
>>> +
>>> + if (guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) &&
>>> + vcpu->arch.ia32_xss != kvm_host.xss)
>>> + wrmsrq(MSR_IA32_XSS, kvm_host.xss);
>>> + }
>>> +}
>> kvm_load_guest_xfeatures() and kvm_load_host_xfeatures() are almost the same
>> except for the guest values VS. host values to set.
>> I am wondering if it is worth adding a helper to dedup the code, like:
>>
>> static void kvm_load_xfeatures(struct kvm_vcpu *vcpu, u64 xcr0, u64 xss)
>> {
>> if (vcpu->arch.guest_state_protected)
>> return;
>>
>> if (kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE)) {
>> if (vcpu->arch.xcr0 != kvm_host.xcr0)
>> xsetbv(XCR_XFEATURE_ENABLED_MASK, xcr0);
>>
>> if (guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) &&
>> vcpu->arch.ia32_xss != kvm_host.xss)
>> wrmsrq(MSR_IA32_XSS, xss);
>> }
>> }
> Nice! I like it. Want to send a proper patch (relative to this series)? Or
> I can turn the above into a patch with a Suggested-by. Either way works for me.
>
I can send a patch.
Powered by blists - more mailing lists