Skip to contentSkip to conversation

KVM: PPC: Book3S HV: Free the queue pages in error path

PATCH Superseded Gautam Menghani 2 participants 3 messages Sep 16 – Sep 17

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: PPC: Book3S HV: Free the queue pages in error path

If the xive_native_configure_queue() call fails, the qpage allocated is not freed, which results in wasted memory. Fix this by freeing the qpage in the error path.

Fixes 5af50993850a ("KVM: PPC: Book3S HV: Native usage of the XIVE interrupt controller")
---
 arch/powerpc/kvm/book3s_xive.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_xive.c +3 -1
index 1d67237783b7..6f8648d9302b 100644
@@ -961,9 +961,11 @@ static int xive_provision_queue(struct kvm_vcpu *vcpu, u8 prio)
 	 */
 	rc = xive_native_configure_queue(xc->vp_id, q, prio, qpage,
 					 xive->q_order, true);
-	if (rc)
+	if (rc) {
+		free_pages((unsigned long)qpage, xive->q_page_order);
 		pr_err("Failed to configure queue %d for VCPU %d\n",
 		       prio, xc->server_num);
+	}
 	return rc;
 }
 
Signature · 1 line
2.50.1 (Apple Git-155)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Gautam Menghani

If the xive_native_configure_queue() call fails, the qpage allocated is not freed, which results in wasted memory. Fix this by freeing the qpage in the error path.

Fixes 5af50993850a ("KVM: PPC: Book3S HV: Native usage of the XIVE interrupt controller")
---
 arch/powerpc/kvm/book3s_xive.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_xive.c +0 -0
index 1d67237783b7..6f8648d9302b 100644

arch/powerpc/kvm/book3s_xive.c static int xive_provision_queue(struct kvm_vcpu *vcpu, u8 prio) · line 967

Quoted 8 lines
arch/powerpc/kvm/book3s_xive.c +2 -1
@@ -961,9 +961,11 @@ static int xive_provision_queue(struct kvm_vcpu *vcpu, u8 prio)
 	 */
 	rc = xive_native_configure_queue(xc->vp_id, q, prio, qpage,
 					 xive->q_order, true);
-	if (rc)
+	if (rc) {
+		free_pages((unsigned long)qpage, xive->q_page_order);
 		pr_err("Failed to configure queue %d for VCPU %d\n",
 		       prio, xc->server_num);

Fix looks correct. xive_native_configure_queue() only sets q->qpage on success, so without this fix the cleanup path in kvmppc_xive_cleanup_vcpu() would never reclaim the pages. The use of q_page_order for freeing is consistent with the rest of the file.

One nit: I would prefer emitting the error log first and then perform cleanup which I think looks more consistent:

	if (rc) {
		pr_err("Failed to configure queue %d for VCPU %d\n",
		       prio, xc->server_num);
		free_pages((unsigned long)qpage, xive->q_page_order);
	}

Not a blocker though.

Thanks,
Amit

#2 lore raw
Quoted 30 lines · Amit Machhiwal
Quoted 15 lines · Gautam Menghani

If the xive_native_configure_queue() call fails, the qpage allocated is not freed, which results in wasted memory. Fix this by freeing the qpage in the error path.

Fixes 5af50993850a ("KVM: PPC: Book3S HV: Native usage of the XIVE interrupt controller")
---
 arch/powerpc/kvm/book3s_xive.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_xive.c +0 -0
index 1d67237783b7..6f8648d9302b 100644

arch/powerpc/kvm/book3s_xive.c static int xive_provision_queue(struct kvm_vcpu *vcpu, u8 prio) · line 967

Quoted 8 lines
arch/powerpc/kvm/book3s_xive.c +2 -1
@@ -961,9 +961,11 @@ static int xive_provision_queue(struct kvm_vcpu *vcpu, u8 prio)
 	 */
 	rc = xive_native_configure_queue(xc->vp_id, q, prio, qpage,
 					 xive->q_order, true);
-	if (rc)
+	if (rc) {
+		free_pages((unsigned long)qpage, xive->q_page_order);
 		pr_err("Failed to configure queue %d for VCPU %d\n",
 		       prio, xc->server_num);

Fix looks correct. xive_native_configure_queue() only sets q->qpage on success, so without this fix the cleanup path in kvmppc_xive_cleanup_vcpu() would never reclaim the pages. The use of q_page_order for freeing is consistent with the rest of the file.

Quoted 2 lines

One nit: I would prefer emitting the error log first and then perform cleanup which I think looks more consistent:

Yes agreed, will send a v2.

Thanks,
Gautam