Skip to contentSkip to conversation

Two PVH dom0 series fixes

PATCH In review Wei Liu 3 participants 6 messages Feb 26, 2017 – Feb 27, 2017

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover Two PVH dom0 series fixes

Wei Liu (2):
x86: fix memory leak in pvh_setup_acpi_madt
x86: fix memory leak in pvh_setup_acpi_xsdt

 xen/arch/x86/domain_build.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH 1/2 x86: fix memory leak in pvh_setup_acpi_madt

Switch to use goto style error handling to avoid leaking madt.

Coverity-ID: 1401534

---
 xen/arch/x86/domain_build.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
xen/arch/x86/domain_build.c +12 -5
index 0534838c8e..1f18f9283f 100644
@@ -2290,7 +2290,8 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr)
     if ( !madt )
     {
         printk("Unable to allocate memory for MADT table\n");
-        return -ENOMEM;
+        rc = -ENOMEM;
+        goto out;
     }
 
     /* Copy the native MADT table header. */
@@ -2298,7 +2299,8 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr)
     if ( !ACPI_SUCCESS(status) )
     {
         printk("Failed to get MADT ACPI table, aborting.\n");
-        return -EINVAL;
+        rc = -EINVAL;
+        goto out;
     }
     madt->header = *table;
     madt->address = APIC_DEFAULT_PHYS_BASE;
@@ -2358,7 +2360,8 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr)
     if ( pvh_steal_ram(d, size, 0, GB(4), addr) )
     {
         printk("Unable to find allocate guest RAM for MADT\n");
-        return -ENOMEM;
+        rc = -ENOMEM;
+        goto out;
     }
 
     /* Mark this region as E820_ACPI. */
@@ -2369,11 +2372,15 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr)
     if ( rc )
     {
         printk("Unable to copy MADT into guest memory\n");
-        return rc;
+        goto out;
     }
+
+    rc = 0;
+
+ out:
     xfree(madt);
 
-    return 0;
+    return rc;
 }
 
 static bool __init acpi_memory_banned(unsigned long address,
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#3 lore raw

PATCH 2/2 x86: fix memory leak in pvh_setup_acpi_xsdt

In reply to Wei Liu

Switch to use goto style error handling to avoid leaking xsdt.

Coverity-ID: 1401535

---
 xen/arch/x86/domain_build.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
xen/arch/x86/domain_build.c +14 -6
index 1f18f9283f..d74296509a 100644
@@ -2459,7 +2459,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr,
     if ( !xsdt )
     {
         printk("Unable to allocate memory for XSDT table\n");
-        return -ENOMEM;
+        rc = -ENOMEM;
+        goto out;
     }
 
     /* Copy the native XSDT table header. */
@@ -2467,7 +2468,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr,
     if ( !rsdp )
     {
         printk("Unable to map RSDP\n");
-        return -EINVAL;
+        rc = -EINVAL;
+        goto out;
     }
     xsdt_paddr = rsdp->xsdt_physical_address;
     acpi_os_unmap_memory(rsdp, sizeof(*rsdp));
@@ -2475,7 +2477,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr,
     if ( !table )
     {
         printk("Unable to map XSDT\n");
-        return -EINVAL;
+        rc = -EINVAL;
+        goto out;
     }
     xsdt->header = *table;
     acpi_os_unmap_memory(table, sizeof(*table));
@@ -2505,7 +2508,8 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr,
     if ( pvh_steal_ram(d, size, 0, GB(4), addr) )
     {
         printk("Unable to find guest RAM for XSDT\n");
-        return -ENOMEM;
+        rc = -ENOMEM;
+        goto out;
     }
 
     /* Mark this region as E820_ACPI. */
@@ -2516,11 +2520,15 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr,
     if ( rc )
     {
         printk("Unable to copy XSDT into guest memory\n");
-        return rc;
+        goto out;
     }
+
+    rc = 0;
+
+ out:
     xfree(xsdt);
 
-    return 0;
+    return rc;
 }
 
 static int __init pvh_setup_acpi(struct domain *d, paddr_t start_info)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] x86: fix memory leak in pvh_setup_acpi_madt

In reply to Wei Liu
Quoted 1 line · Wei Liu

Switch to use goto style error handling to avoid leaking madt.

Thanks, I guess it's fine to don't leak memory here, but in any case this is doomed to fail, no further progress is going to be made if Dom0 build fails, hence that's why memory leaks here are not really meaningful.

Quoted 3 lines

Coverity-ID: 1401534

Quoted 9 lines
---
 xen/arch/x86/domain_build.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
xen/arch/x86/domain_build.c +0 -0
index 0534838c8e..1f18f9283f 100644

xen/arch/x86/domain_build.c static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr) · line 2294

Quoted 6 lines
xen/arch/x86/domain_build.c +2 -1
@@ -2290,7 +2290,8 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr)
     if ( !madt )
     {
         printk("Unable to allocate memory for MADT table\n");
-        return -ENOMEM;
+        rc = -ENOMEM;
+        goto out;

This one doesn't need the goto, there's nothing leaked here (although there's also no problem in doing in that way).

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] x86: fix memory leak in pvh_setup_acpi_xsdt

In reply to Wei Liu
Quoted 5 lines · Wei Liu

Switch to use goto style error handling to avoid leaking xsdt.

Coverity-ID: 1401535

Thanks! Same comments as the ones in the previous patch, and the first goto is not really needed.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
In reply to Wei Liu
Quoted 7 lines · Wei Liu

Wei Liu (2):
x86: fix memory leak in pvh_setup_acpi_madt
x86: fix memory leak in pvh_setup_acpi_xsdt

 xen/arch/x86/domain_build.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

Reviewed and committed. Thanks,

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel