KVM: SVM: Check vCPU ID against max x2AVIC ID if and only if x2AVIC is enabled
Sean Christopherson
maintainerPATCH 1/1 KVM: SVM: Check vCPU ID against max x2AVIC ID if and only if x2AVIC is enabled
When allocating the AVIC backing page, only check one of the max AVIC vs. x2AVIC ID based on whether or not x2AVIC is enabled. Doing so fixes a bug where KVM incorrectly inhibits AVIC if x2AVIC is _disabled_ and any vCPU with a non-zero APIC ID is created, as x2avic_max_physical_id is left '0' when x2AVIC is disabled.
--- arch/x86/kvm/svm/avic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/avic.c +2 -2
@@ -376,6 +376,7 @@ void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb)static int avic_init_backing_page (struct kvm_vcpu *vcpu) { +u32 max_id = x2avic_enabled ? x2avic_max_physical_id :AVIC_MAX_PHYSICAL_ID ;struct kvm_svm *kvm_svm =to_kvm_svm (vcpu->kvm);struct vcpu_svm *svm =to_svm (vcpu);u32 id = vcpu->vcpu_id;
@@ -388,8 +389,7 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu)* avic_vcpu_load() expects to be called if and only if the vCPU has * fully initialized AVIC. */ -if ((!x2avic_enabled && id >AVIC_MAX_PHYSICAL_ID ) || - (id > x2avic_max_physical_id)) { +if (id > max_id) {kvm_set_apicv_inhibit (vcpu->kvm,APICV_INHIBIT_REASON_PHYSICAL_ID_TOO_BIG ); vcpu->arch.apic->apicv_active = false;return 0 ;
base-commit: 9448598b22c50c8a5bb77a9103e2d49f134c9578
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Quoted 6 lines · Sean Christopherson
When allocating the AVIC backing page, only check one of the max AVIC vs. x2AVIC ID based on whether or not x2AVIC is enabled. Doing so fixes a bug where KVM incorrectly inhibits AVIC if x2AVIC is _disabled_ and any vCPU with a non-zero APIC ID is created, as
x2avic_max_physical_idis left '0' when x2AVIC is disabled.
Quoted 8 lines
Fixes 940fc47cfb0d ("KVM: SVM: Add AVIC support for 4k vCPUs in x2AVIC mode")Cc Naveen N Rao (AMD) <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/svm/avic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
I think the bad commit is:f628a34a9d52 ("KVM: SVM: Replace "avic_mode" enum with "x2avic_enabled" boolean")
... which introduced x2avic_enabled.
Other than that:
Thanks,
Naveen
Sean Christopherson
maintainerQuoted 16 lines · Naveen N Rao
Quoted 6 lines · Sean Christopherson
When allocating the AVIC backing page, only check one of the max AVIC vs. x2AVIC ID based on whether or not x2AVIC is enabled. Doing so fixes a bug where KVM incorrectly inhibits AVIC if x2AVIC is _disabled_ and any vCPU with a non-zero APIC ID is created, as
x2avic_max_physical_idis left '0' when x2AVIC is disabled.Quoted 8 lines
Fixes 940fc47cfb0d ("KVM: SVM: Add AVIC support for 4k vCPUs in x2AVIC mode")Cc Naveen N Rao (AMD) <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/svm/avic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 4 lines
I think the bad commit is:
f628a34a9d52("KVM: SVM: Replace "avic_mode" enum with "x2avic_enabled" boolean")... which introduced
x2avic_enabled.
No. That commit definitely set a trap for 4k vCPUs support, but there was no functional bug as of that commit. KVM would unnecessarily check @id against X2AVIC_MAX_PHYSICAL_ID, but it's a non-issue because X2AVIC_MAX_PHYSICAL_ID is a constant and greater than AVIC_MAX_PHYSICAL_ID.
if ((!x2avic_enabled && id > AVIC_MAX_PHYSICAL_ID) ||
(id > X2AVIC_MAX_PHYSICAL_ID))
return -EINVAL;So from a "what LTS commits need this fix" perspective, it's just the ones with 940fc47cfb0d.
Quoted 8 lines · Sean Christopherson
When allocating the AVIC backing page, only check one of the max AVIC vs. x2AVIC ID based on whether or not x2AVIC is enabled. Doing so fixes a bug where KVM incorrectly inhibits AVIC if x2AVIC is _disabled_ and any vCPU with a non-zero APIC ID is created, as
x2avic_max_physical_idis left '0' when x2AVIC is disabled.[...]
Applied to kvm-x86 fixes, thanks!
[1/1] KVM: SVM: Check vCPU ID against max x2AVIC ID if and only if x2AVIC is enabled
https://github.com/kvm-x86/linux/commit/cfbe371194d1