[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 10/21] hw/i386/kvm/xen_evtchn: Reuse existing backend port in find_be_port()



From: David Woodhouse <dwmw@xxxxxxxxxxxx>

After a guest soft reset, close_port() clears only the guest side of an
interdomain port; the backend handle still owns its be_handles[] slot.
Binding again then allocated a fresh slot each time, leaking the old
one — and leaving a dangling entry if the handle is later closed. Reuse
the slot the handle already owns.

Fixes: 794fba23a53a ("hw/xen: Add backend implementation of interdomain event 
channel support")
Reported-by: Hui Peng <benquike@xxxxxxxxx>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
 hw/i386/kvm/xen_evtchn.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index 7fd8c3f3182..e2803cad0a8 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -2052,6 +2052,16 @@ static int find_be_port(XenEvtchnState *s, struct 
xenevtchn_handle *xc)
 {
     int i;
 
+    /*
+     * A handle may still own a backend port from before a guest soft reset;
+     * close_port() clears only the guest side. Reuse it rather than leaking
+     * the old slot and allocating a second one.
+     */
+    if (xc->be_port && xc->be_port < EVTCHN_2L_NR_CHANNELS &&
+        s->be_handles[xc->be_port] == xc) {
+        return xc->be_port;
+    }
+
     for (i = 1; i < EVTCHN_2L_NR_CHANNELS; i++) {
         if (!s->be_handles[i]) {
             s->be_handles[i] = xc;
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.