From: David Woodhouse 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 Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525 Signed-off-by: David Woodhouse --- 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