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

[PULL 11/21] hw/i386/kvm/xen: Don't leak gnttab handle on reset



From: David Woodhouse <dwmw@xxxxxxxxxxxx>

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 <benquike@xxxxxxxxx>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Reviewed-by: Paul Durrant <paul@xxxxxxx>
Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
 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 bf61f6235b..0a2a6de3ec 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 7d6d6d5cbb..ff0dfb1bff 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.55.0




 


Rackspace

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