[PATCH v2] KVM: PPC: Book3S HV: Free the queue pages in error path

Gautam Menghani posted 1 patch 1 week ago
arch/powerpc/kvm/book3s_xive.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH v2] KVM: PPC: Book3S HV: Free the queue pages in error path
Posted by Gautam Menghani 1 week ago
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")
Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
---
v2:
1. Move call to free_pages() after error message. (Amit)

 arch/powerpc/kvm/book3s_xive.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c
index 89a1b8c21ab4..0f8f851a3f8f 100644
--- a/arch/powerpc/kvm/book3s_xive.c
+++ b/arch/powerpc/kvm/book3s_xive.c
@@ -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) {
 		pr_err("Failed to configure queue %d for VCPU %d\n",
 		       prio, xc->server_num);
+		free_pages((unsigned long)qpage, xive->q_page_order);
+	}
 	return rc;
 }
 
-- 
2.55.0