* [PATCH 1/3] KVM: x86: Keep MSR_IA32_XSS unchanged for INIT
2022-01-26 17:22 [PATCH 0/3] KVM: x86: XSS and XCR0 fixes Sean Christopherson
@ 2022-01-26 17:22 ` Sean Christopherson
2022-01-26 17:22 ` [PATCH 2/3] KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS Sean Christopherson
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Sean Christopherson @ 2022-01-26 17:22 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel, Xiaoyao Li, Like Xu
From: Xiaoyao Li <xiaoyao.li@intel.com>
It has been corrected from SDM version 075 that MSR_IA32_XSS is reset to
zero on Power up and Reset but keeps unchanged on INIT.
Fixes: a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")
Cc: stable@vger.kernel.org
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/x86.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 55518b7d3b96..c0727939684e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11257,6 +11257,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
vcpu->arch.msr_misc_features_enables = 0;
vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+ vcpu->arch.ia32_xss = 0;
}
/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
@@ -11273,8 +11274,6 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
cpuid_0x1 = kvm_find_cpuid_entry(vcpu, 1, 0);
kvm_rdx_write(vcpu, cpuid_0x1 ? cpuid_0x1->eax : 0x600);
- vcpu->arch.ia32_xss = 0;
-
static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
kvm_set_rflags(vcpu, X86_EFLAGS_FIXED);
--
2.35.0.rc0.227.g00780c9af4-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
2022-01-26 17:22 [PATCH 0/3] KVM: x86: XSS and XCR0 fixes Sean Christopherson
2022-01-26 17:22 ` [PATCH 1/3] KVM: x86: Keep MSR_IA32_XSS unchanged for INIT Sean Christopherson
@ 2022-01-26 17:22 ` Sean Christopherson
2022-01-26 17:22 ` [PATCH 3/3] KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time Sean Christopherson
2022-01-26 17:43 ` [PATCH 0/3] KVM: x86: XSS and XCR0 fixes Paolo Bonzini
3 siblings, 0 replies; 8+ messages in thread
From: Sean Christopherson @ 2022-01-26 17:22 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel, Xiaoyao Li, Like Xu
From: Like Xu <likexu@tencent.com>
Do a runtime CPUID update for a vCPU if MSR_IA32_XSS is written, as the
size in bytes of the XSAVE area is affected by the states enabled in XSS.
Fixes: 203000993de5 ("kvm: vmx: add MSR logic for XSAVES")
Cc: stable@vger.kernel.org
Signed-off-by: Like Xu <likexu@tencent.com>
[sean: split out as a separate patch, adjust Fixes tag]
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/x86.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c0727939684e..13793582f26d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3535,6 +3535,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
if (data & ~supported_xss)
return 1;
vcpu->arch.ia32_xss = data;
+ kvm_update_cpuid_runtime(vcpu);
break;
case MSR_SMI_COUNT:
if (!msr_info->host_initiated)
--
2.35.0.rc0.227.g00780c9af4-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time
2022-01-26 17:22 [PATCH 0/3] KVM: x86: XSS and XCR0 fixes Sean Christopherson
2022-01-26 17:22 ` [PATCH 1/3] KVM: x86: Keep MSR_IA32_XSS unchanged for INIT Sean Christopherson
2022-01-26 17:22 ` [PATCH 2/3] KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS Sean Christopherson
@ 2022-01-26 17:22 ` Sean Christopherson
2022-01-26 17:43 ` [PATCH 0/3] KVM: x86: XSS and XCR0 fixes Paolo Bonzini
3 siblings, 0 replies; 8+ messages in thread
From: Sean Christopherson @ 2022-01-26 17:22 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel, Xiaoyao Li, Like Xu
From: Like Xu <likexu@tencent.com>
XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by
both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS
also needs to update kvm_update_cpuid_runtime(). In the above cases, the
size in bytes of the XSAVE area containing all states enabled by XCR0 or
(XCRO | IA32_XSS) needs to be updated.
For simplicity and consistency, existing helpers are used to write values
and call kvm_update_cpuid_runtime(), and it's not exactly a fast path.
Fixes: a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")
Cc: stable@vger.kernel.org
Signed-off-by: Like Xu <likexu@tencent.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/x86.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 13793582f26d..2e8a8fb42269 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11257,8 +11257,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
vcpu->arch.msr_misc_features_enables = 0;
- vcpu->arch.xcr0 = XFEATURE_MASK_FP;
- vcpu->arch.ia32_xss = 0;
+ __kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
+ __kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);
}
/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
--
2.35.0.rc0.227.g00780c9af4-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] KVM: x86: XSS and XCR0 fixes
2022-01-26 17:22 [PATCH 0/3] KVM: x86: XSS and XCR0 fixes Sean Christopherson
` (2 preceding siblings ...)
2022-01-26 17:22 ` [PATCH 3/3] KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time Sean Christopherson
@ 2022-01-26 17:43 ` Paolo Bonzini
2022-01-26 17:48 ` Sean Christopherson
3 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2022-01-26 17:43 UTC (permalink / raw)
To: Sean Christopherson
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel, Xiaoyao Li, Like Xu
On 1/26/22 18:22, Sean Christopherson wrote:
> For convenience, Like's patch split up and applied on top of Xiaoyao.
> Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's
> patch tagged too?
>
> Like Xu (2):
> KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
> KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time
>
> Xiaoyao Li (1):
> KVM: x86: Keep MSR_IA32_XSS unchanged for INIT
>
> arch/x86/kvm/x86.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>
> base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4
Queued, though I'll note that I kinda disagree with the stable@ marking
of patch 1 (and therefore with the patch order) as it has no effect in
practice.
Paolo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] KVM: x86: XSS and XCR0 fixes
2022-01-26 17:43 ` [PATCH 0/3] KVM: x86: XSS and XCR0 fixes Paolo Bonzini
@ 2022-01-26 17:48 ` Sean Christopherson
2022-01-27 12:09 ` Paolo Bonzini
0 siblings, 1 reply; 8+ messages in thread
From: Sean Christopherson @ 2022-01-26 17:48 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel, Xiaoyao Li, Like Xu
On Wed, Jan 26, 2022, Paolo Bonzini wrote:
> On 1/26/22 18:22, Sean Christopherson wrote:
> > For convenience, Like's patch split up and applied on top of Xiaoyao.
> > Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's
> > patch tagged too?
> > Like Xu (2):
> > KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
> > KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time
> >
> > Xiaoyao Li (1):
> > KVM: x86: Keep MSR_IA32_XSS unchanged for INIT
> >
> > arch/x86/kvm/x86.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> >
> > base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4
>
> Queued, though I'll note that I kinda disagree with the stable@ marking of
> patch 1 (and therefore with the patch order) as it has no effect in
> practice.
Hmm, that's not a given, is it? E.g. the guest can configure XSS early on and
then expect the configured value to live across INIT-SIPI-SIPI. I agree it's
highly unlikely for any guest to actually do that, but I don't like assuming all
guests will behave a certain way.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] KVM: x86: XSS and XCR0 fixes
2022-01-26 17:48 ` Sean Christopherson
@ 2022-01-27 12:09 ` Paolo Bonzini
2022-01-27 15:03 ` Sean Christopherson
0 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2022-01-27 12:09 UTC (permalink / raw)
To: Sean Christopherson
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel, Xiaoyao Li, Like Xu
On 1/26/22 18:48, Sean Christopherson wrote:
> On Wed, Jan 26, 2022, Paolo Bonzini wrote:
>> On 1/26/22 18:22, Sean Christopherson wrote:
>>> For convenience, Like's patch split up and applied on top of Xiaoyao.
>>> Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's
>>> patch tagged too?
>>> Like Xu (2):
>>> KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
>>> KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time
>>>
>>> Xiaoyao Li (1):
>>> KVM: x86: Keep MSR_IA32_XSS unchanged for INIT
>>>
>>> arch/x86/kvm/x86.c | 6 +++---
>>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>>
>>> base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4
>>
>> Queued, though I'll note that I kinda disagree with the stable@ marking of
>> patch 1 (and therefore with the patch order) as it has no effect in
>> practice.
>
> Hmm, that's not a given, is it? E.g. the guest can configure XSS early on and
> then expect the configured value to live across INIT-SIPI-SIPI. I agree it's
> highly unlikely for any guest to actually do that, but I don't like assuming all
> guests will behave a certain way.
No, I meant in the sense that supported_xss is always zero right now,
and therefore so is MSR_IA32_XSS.
Paolo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] KVM: x86: XSS and XCR0 fixes
2022-01-27 12:09 ` Paolo Bonzini
@ 2022-01-27 15:03 ` Sean Christopherson
0 siblings, 0 replies; 8+ messages in thread
From: Sean Christopherson @ 2022-01-27 15:03 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel, Xiaoyao Li, Like Xu
On Thu, Jan 27, 2022, Paolo Bonzini wrote:
> On 1/26/22 18:48, Sean Christopherson wrote:
> > On Wed, Jan 26, 2022, Paolo Bonzini wrote:
> > > On 1/26/22 18:22, Sean Christopherson wrote:
> > > > For convenience, Like's patch split up and applied on top of Xiaoyao.
> > > > Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's
> > > > patch tagged too?
> > > > Like Xu (2):
> > > > KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
> > > > KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time
> > > >
> > > > Xiaoyao Li (1):
> > > > KVM: x86: Keep MSR_IA32_XSS unchanged for INIT
> > > >
> > > > arch/x86/kvm/x86.c | 6 +++---
> > > > 1 file changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > >
> > > > base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4
> > >
> > > Queued, though I'll note that I kinda disagree with the stable@ marking of
> > > patch 1 (and therefore with the patch order) as it has no effect in
> > > practice.
> >
> > Hmm, that's not a given, is it? E.g. the guest can configure XSS early on and
> > then expect the configured value to live across INIT-SIPI-SIPI. I agree it's
> > highly unlikely for any guest to actually do that, but I don't like assuming all
> > guests will behave a certain way.
>
> No, I meant in the sense that supported_xss is always zero right now, and
> therefore so is MSR_IA32_XSS.
Oh, duh.
^ permalink raw reply [flat|nested] 8+ messages in thread