From: elena.ufimtseva@oracle.com
To: xen-devel@lists.xen.org
Cc: Elena Ufimtseva <elena.ufimtseva@oracle.com>,
kevin.tian@intel.com, tim@xen.org, jbeulich@suse.com,
yang.z.zhang@intel.com, boris.ostrovsky@oracle.com
Subject: [PATCH v10 1/5] dmar: device scope mem leak fix
Date: Mon, 13 Jul 2015 14:17:58 -0400 [thread overview]
Message-ID: <1436811482-16113-2-git-send-email-elena.ufimtseva@oracle.com> (raw)
In-Reply-To: <1436811482-16113-1-git-send-email-elena.ufimtseva@oracle.com>
From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Release memory allocated for scope.devices dmar units on various
failure paths and when disabling dmar. Set device count after
sucessfull memory allocation, not before, in device scope parsing function.
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
Changes in v10:
- mark patch v6 as v10 and include into the series of patches which add RMRR
comman line option for Xen;
Changes in v6:
- eliminated unrelated code move;
- fix introduces in v5 memory leak;
Changes in v5;
- xencope_devices_free actually safe;
Changes in v4:
- make scope_devices_free safe to call with NULL scope pointer;
- since scope_devices_free is safe to call, use it in failure path
in acpi_parse_one_drhd;
Changes in v3:
- make freeing memory for scope devices and zeroing device counter
as a function;
- make sure parse_one_rmrr has memory leak fix in this patch;
- make sure ret values are not lost acpi_parse_one_drhd;
Changes in v2:
- release memory for devices scope on error paths in acpi_parse_one_drhd
and acpi_parse_one_atsr and set the count to zero;
drivers/passthrough/vtd/dmar.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c
index 2b07be9..8ed1e24 100644
--- a/xen/drivers/passthrough/vtd/dmar.c
+++ b/xen/drivers/passthrough/vtd/dmar.c
@@ -81,6 +81,15 @@ static int __init acpi_register_rmrr_unit(struct acpi_rmrr_unit *rmrr)
return 0;
}
+static void scope_devices_free(struct dmar_scope *scope)
+{
+ if ( !scope )
+ return;
+
+ scope->devices_cnt = 0;
+ xfree(scope->devices);
+}
+
static void __init disable_all_dmar_units(void)
{
struct acpi_drhd_unit *drhd, *_drhd;
@@ -90,16 +99,19 @@ static void __init disable_all_dmar_units(void)
list_for_each_entry_safe ( drhd, _drhd, &acpi_drhd_units, list )
{
list_del(&drhd->list);
+ scope_devices_free(&drhd->scope);
xfree(drhd);
}
list_for_each_entry_safe ( rmrr, _rmrr, &acpi_rmrr_units, list )
{
list_del(&rmrr->list);
+ scope_devices_free(&rmrr->scope);
xfree(rmrr);
}
list_for_each_entry_safe ( atsr, _atsr, &acpi_atsr_units, list )
{
list_del(&atsr->list);
+ scope_devices_free(&atsr->scope);
xfree(atsr);
}
}
@@ -318,13 +330,13 @@ static int __init acpi_parse_dev_scope(
if ( (cnt = scope_device_count(start, end)) < 0 )
return cnt;
- scope->devices_cnt = cnt;
if ( cnt > 0 )
{
scope->devices = xzalloc_array(u16, cnt);
if ( !scope->devices )
return -ENOMEM;
}
+ scope->devices_cnt = cnt;
while ( start < end )
{
@@ -427,7 +439,7 @@ static int __init acpi_parse_dev_scope(
out:
if ( ret )
- xfree(scope->devices);
+ scope_devices_free(scope);
return ret;
}
@@ -542,6 +554,7 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)
" Workaround BIOS bug: ignore the DRHD due to all "
"devices under its scope are not PCI discoverable!\n");
+ scope_devices_free(&dmaru->scope);
iommu_free(dmaru);
xfree(dmaru);
}
@@ -562,9 +575,11 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)
out:
if ( ret )
{
+ scope_devices_free(&dmaru->scope);
iommu_free(dmaru);
xfree(dmaru);
}
+
return ret;
}
@@ -658,6 +673,7 @@ acpi_parse_one_rmrr(struct acpi_dmar_header *header)
" Ignore the RMRR (%"PRIx64", %"PRIx64") due to "
"devices under its scope are not PCI discoverable!\n",
rmrru->base_address, rmrru->end_address);
+ scope_devices_free(&rmrru->scope);
xfree(rmrru);
}
else if ( base_addr > end_addr )
@@ -665,6 +681,7 @@ acpi_parse_one_rmrr(struct acpi_dmar_header *header)
dprintk(XENLOG_WARNING VTDPREFIX,
" The RMRR (%"PRIx64", %"PRIx64") is incorrect!\n",
rmrru->base_address, rmrru->end_address);
+ scope_devices_free(&rmrru->scope);
xfree(rmrru);
ret = -EFAULT;
}
@@ -727,7 +744,10 @@ acpi_parse_one_atsr(struct acpi_dmar_header *header)
}
if ( ret )
+ {
+ scope_devices_free(&atsru->scope);
xfree(atsru);
+ }
else
acpi_register_atsr_unit(atsru);
return ret;
--
2.1.3
next prev parent reply other threads:[~2015-07-13 18:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-13 18:17 [PATCH v10 0/5] iommu: add rmrr Xen command line option elena.ufimtseva
2015-07-13 18:17 ` elena.ufimtseva [this message]
2015-07-13 18:17 ` [PATCH v10 2/5] iommu VT-d: separate rmrr addition function elena.ufimtseva
2015-07-13 18:18 ` [PATCH v10 3/5] pci: add wrapper for parse_pci elena.ufimtseva
2015-07-13 18:18 ` [PATCH v10 4/5] pci: add PCI_SBDF and PCI_SEG macros elena.ufimtseva
2015-07-13 18:18 ` [PATCH v10 5/5] iommu: add rmrr Xen command line option for extra rmrrs elena.ufimtseva
2015-07-14 10:43 ` Jan Beulich
2015-07-15 7:25 ` Jan Beulich
2015-07-15 15:27 ` Elena Ufimtseva
2015-07-15 16:08 ` Jan Beulich
2015-07-14 10:18 ` [PATCH v10 0/5] iommu: add rmrr Xen command line option Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1436811482-16113-2-git-send-email-elena.ufimtseva@oracle.com \
--to=elena.ufimtseva@oracle.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jbeulich@suse.com \
--cc=kevin.tian@intel.com \
--cc=tim@xen.org \
--cc=xen-devel@lists.xen.org \
--cc=yang.z.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).