From: David Woodhouse xen_xenstore_reset() and xen_primary_console_reset() open a new gnttab handle without closing the previous one, leaking it and its mappings on each guest soft reset. Close the old handle first; closing unmaps any remaining refs. Fixes: d05864d23b1a ("hw/xen: Map guest XENSTORE_PFN grant in emulated Xenstore") Fixes: a72ccc7fc449 ("hw/xen: add support for Xen primary console in emulated mode") Reported-by: Hui Peng Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525 Signed-off-by: David Woodhouse --- hw/i386/kvm/xen_primary_console.c | 3 +++ hw/i386/kvm/xen_xenstore.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/hw/i386/kvm/xen_primary_console.c b/hw/i386/kvm/xen_primary_console.c index bf61f6235be..0a2a6de3ecb 100644 --- a/hw/i386/kvm/xen_primary_console.c +++ b/hw/i386/kvm/xen_primary_console.c @@ -184,6 +184,9 @@ int xen_primary_console_reset(void) trace_xen_primary_console_reset(s->guest_port); + if (s->gt) { + qemu_xen_gnttab_close(s->gt); + } s->gt = qemu_xen_gnttab_open(); uint32_t xs_gntref = GNTTAB_RESERVED_CONSOLE; s->granted_xs = qemu_xen_gnttab_map_refs(s->gt, 1, xen_domid, &xs_gntref, diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 7d6d6d5cbb7..ff0dfb1bff8 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -1490,6 +1490,9 @@ int xen_xenstore_reset(void) * first place. Map the grant anyway, mostly for cosmetic purposes so * it *looks* like it's in use in the guest-visible grant table. */ + if (s->gt) { + qemu_xen_gnttab_close(s->gt); + } s->gt = qemu_xen_gnttab_open(); uint32_t xs_gntref = GNTTAB_RESERVED_XENSTORE; s->granted_xs = qemu_xen_gnttab_map_refs(s->gt, 1, xen_domid, &xs_gntref, -- 2.43.0