Skip to contentSkip to conversation

KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter

PATCH In review Paolo Bonzini 2 participants 3 messages Feb 25, 2020

Subsystems (3)
lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter

Even if APICv is disabled at startup, the backing page and ir_list need to be initialized in case they are needed later. The only case in which this can be skipped is for userspace irqchip, and that must be done because avic_init_backing_page dereferences vcpu->arch.apic (which is NULL for userspace irqchip).

---
 arch/x86/kvm/svm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/svm.c +2 -1
index ad3f5b178a03..bd02526300ab 100644
@@ -2194,8 +2194,9 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 static int avic_init_vcpu(struct vcpu_svm *svm)
 {
 	int ret;
+	struct kvm_vcpu *vcpu = &svm->vcpu;
 
-	if (!kvm_vcpu_apicv_active(&svm->vcpu))
+	if (!avic || !irqchip_in_kernel(vcpu->kvm))
 		return 0;
 
 	ret = avic_init_backing_page(&svm->vcpu);
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Paolo Bonzini

Even if APICv is disabled at startup, the backing page and ir_list need to be initialized in case they are needed later. The only case in which this can be skipped is for userspace irqchip, and that must be done because avic_init_backing_page dereferences vcpu->arch.apic (which is NULL for userspace irqchip).

---
 arch/x86/kvm/svm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/svm.c +0 -0
index ad3f5b178a03..bd02526300ab 100644

arch/x86/kvm/svm.c static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) · line 2202

Quoted 10 lines
arch/x86/kvm/svm.c +2 -1
@@ -2194,8 +2194,9 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 static int avic_init_vcpu(struct vcpu_svm *svm)
 {
 	int ret;
+	struct kvm_vcpu *vcpu = &svm->vcpu;
 
-	if (!kvm_vcpu_apicv_active(&svm->vcpu))
+	if (!avic || !irqchip_in_kernel(vcpu->kvm))
 		return 0;
 
 	ret = avic_init_backing_page(&svm->vcpu);

Out of pure curiosity,

when irqchip_in_kernel() is false, can we still get to .update_pi_irte() (svm_update_pi_irte()) -> get_pi_vcpu_info() -> "vcpu_info->pi_desc_addr = __sme_set(page_to_phys((*svm)->avic_backing_page));" -> crash! or is there anything which make this impossible?

The patch is an improvement anyway, so

Signature · 1 line
Vitaly
author maintainer
#2 lore raw
Quoted 7 lines · Vitaly Kuznetsov
Quoted 7 lines
arch/x86/kvm/svm.c +2 -1
 	int ret;
+	struct kvm_vcpu *vcpu = &svm->vcpu;
 
-	if (!kvm_vcpu_apicv_active(&svm->vcpu))
+	if (!avic || !irqchip_in_kernel(vcpu->kvm))
 		return 0;
Quoted 7 lines
Quoted 1 line

ret = avic_init_backing_page(&svm->vcpu);

Out of pure curiosity,

when irqchip_in_kernel() is false, can we still get to .update_pi_irte() (svm_update_pi_irte()) -> get_pi_vcpu_info() -> "vcpu_info->pi_desc_addr = __sme_set(page_to_phys((*svm)->avic_backing_page));" -> crash! or is there anything which make this impossible?

No, because kvm_arch_irqfd_allowed returns false so you cannot create any irqfd (svm_update_pi_irte is called when virt/lib/irqbypass.c finds a match between two eventfds in KVM and VFIO).

Paolo