Skip to contentSkip to conversation

KVM: arm: fix missing free_percpu_irq in kvm_timer_hyp_init()

PATCH Superseded linmiaohe 2 participants 2 messages Nov 23, 2019 – Dec 6, 2019

Subsystems (2)
lore
Share & tools
lore

linmiaohe

author
#0 lore raw

PATCH 1/1 KVM: arm: fix missing free_percpu_irq in kvm_timer_hyp_init()

From: Miaohe Lin <[email protected]>

When host_ptimer_irq request irq resource failed, we forget to release the host_vtimer_irq resource already requested. Fix this missing irq release and other similar scenario.

Fixes 9e01dc76be6a ("KVM: arm/arm64: arch_timer: Assign the phys timer on VHE systems")
---
 virt/kvm/arm/arch_timer.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
virt/kvm/arm/arch_timer.c +12 -5
index f182b2380345..73867f97040c 100644
@@ -935,7 +935,7 @@ int kvm_timer_hyp_init(bool has_gic)
 					    kvm_get_running_vcpus());
 		if (err) {
 			kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
-			goto out_free_irq;
+			goto out_free_vtimer_irq;
 		}
 
 		static_branch_enable(&has_gic_active_state);
@@ -960,7 +960,7 @@ int kvm_timer_hyp_init(bool has_gic)
 		if (err) {
 			kvm_err("kvm_arch_timer: can't request ptimer interrupt %d (%d)\n",
 				host_ptimer_irq, err);
-			return err;
+			goto out_disable_gic_state;
 		}
 
 		if (has_gic) {
@@ -968,7 +968,7 @@ int kvm_timer_hyp_init(bool has_gic)
 						    kvm_get_running_vcpus());
 			if (err) {
 				kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
-				goto out_free_irq;
+				goto out_free_ptimer_irq;
 			}
 		}
 
@@ -977,15 +977,22 @@ int kvm_timer_hyp_init(bool has_gic)
 		kvm_err("kvm_arch_timer: invalid physical timer IRQ: %d\n",
 			info->physical_irq);
 		err = -ENODEV;
-		goto out_free_irq;
+		goto out_disable_gic_state;
 	}
 
 	cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING,
 			  "kvm/arm/timer:starting", kvm_timer_starting_cpu,
 			  kvm_timer_dying_cpu);
 	return 0;
-out_free_irq:
+
+out_free_ptimer_irq:
+	free_percpu_irq(host_ptimer_irq, kvm_get_running_vcpus());
+out_disable_gic_state:
+	if (has_gic)
+		static_branch_disable(&has_gic_active_state);
+out_free_vtimer_irq:
 	free_percpu_irq(host_vtimer_irq, kvm_get_running_vcpus());
+
 	return err;
 }
 
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 5 lines · linmiaohe

From: Miaohe Lin <[email protected]>

When host_ptimer_irq request irq resource failed, we forget to release the host_vtimer_irq resource already requested. Fix this missing irq release and other similar scenario.

That's really not a big deal, as nothing but KVM can use the timers anyway, but I guess it doesn't hurt to be correct.

Quoted 49 lines
Fixes 9e01dc76be6a ("KVM: arm/arm64: arch_timer: Assign the phys

timer on VHE systems")

---
 virt/kvm/arm/arch_timer.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
virt/kvm/arm/arch_timer.c +2 -2
index f182b2380345..73867f97040c 100644
@@ -935,7 +935,7 @@ int kvm_timer_hyp_init(bool has_gic)
 					    kvm_get_running_vcpus());
 		if (err) {
 			kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
-			goto out_free_irq;
+			goto out_free_vtimer_irq;
 		}
 
 		static_branch_enable(&has_gic_active_state);
@@ -960,7 +960,7 @@ int kvm_timer_hyp_init(bool has_gic)
 		if (err) {
 			kvm_err("kvm_arch_timer: can't request ptimer interrupt %d 
 (%d)\n",
 				host_ptimer_irq, err);
-			return err;
+			goto out_disable_gic_state;
 		}
 
virt/kvm/arm/arch_timer.c +2 -2
 		if (has_gic) {
@@ -968,7 +968,7 @@ int kvm_timer_hyp_init(bool has_gic)
 						    kvm_get_running_vcpus());
 			if (err) {
 				kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
-				goto out_free_irq;
+				goto out_free_ptimer_irq;
 			}
 		}
 
@@ -977,15 +977,22 @@ int kvm_timer_hyp_init(bool has_gic)
 		kvm_err("kvm_arch_timer: invalid physical timer IRQ: %d\n",
 			info->physical_irq);
 		err = -ENODEV;
-		goto out_free_irq;
+		goto out_disable_gic_state;
 	}
 
 	cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING,

virt/kvm/arm/arch_timer.c int kvm_timer_hyp_init(bool has_gic) · line 992

Quoted 10 lines
virt/kvm/arm/arch_timer.c +6 -1
 			  "kvm/arm/timer:starting", kvm_timer_starting_cpu,
 			  kvm_timer_dying_cpu);
 	return 0;
-out_free_irq:
+
+out_free_ptimer_irq:
+	free_percpu_irq(host_ptimer_irq, kvm_get_running_vcpus());
+out_disable_gic_state:
+	if (has_gic)
+		static_branch_disable(&has_gic_active_state);

Given that we're failing the init of KVM, this is totally superfluous. Also, this state is still valid, no matter what happens (the GIC is not going away from under our feet).

virt/kvm/arm/arch_timer.c int kvm_timer_hyp_init(bool has_gic) · line 997

Quoted 5 lines
virt/kvm/arm/arch_timer.c +2 -0
+out_free_vtimer_irq:
 	free_percpu_irq(host_vtimer_irq, kvm_get_running_vcpus());
+
 	return err;
 }

Thanks,

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...