From: Konrad Rzeszutek Wilk Subject: [PATCH v2 08/13] libxc: Check xc_domain_maximum_gpfn for negative return values Date: Wed, 18 Mar 2015 20:24:14 -0400 Message-ID: <1426724659-23999-9-git-send-email-konrad.wilk@oracle.com> References: <1426724659-23999-1-git-send-email-konrad.wilk@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYOGE-0006uq-2x for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 00:24:30 +0000 In-Reply-To: <1426724659-23999-1-git-send-email-konrad.wilk@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org, ian.campbell@citrix.com, ian.jackson@eu.citrix.com Cc: Konrad Rzeszutek Wilk List-Id: xen-devel@lists.xenproject.org Instead of assuming everything is always OK. We stash the gpfns value as an parameter. Signed-off-by: Konrad Rzeszutek Wilk --- tools/libxc/xc_core_arm.c | 17 ++++++++++++++--- tools/libxc/xc_core_x86.c | 24 ++++++++++++++++++++---- tools/libxc/xc_domain_save.c | 8 +++++++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/tools/libxc/xc_core_arm.c b/tools/libxc/xc_core_arm.c index 16508e7..26cec04 100644 --- a/tools/libxc/xc_core_arm.c +++ b/tools/libxc/xc_core_arm.c @@ -31,9 +31,16 @@ xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt, } -static int nr_gpfns(xc_interface *xch, domid_t domid) +static int nr_gpfns(xc_interface *xch, domid_t domid, unsigned long *gpfns) { - return xc_domain_maximum_gpfn(xch, domid) + 1; + int rc = xc_domain_maximum_gpfn(xch, domid); + + if ( rc >= 0 ) + { + *gpfns = rc + 1; + rc = 0; + } + return rc; } int @@ -48,9 +55,13 @@ xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context *unus xc_core_memory_map_t **mapp, unsigned int *nr_entries) { - unsigned long p2m_size = nr_gpfns(xch, info->domid); + unsigned long p2m_size = 0; + int rc = nr_gpfns(xch, info->domid, &p2m_size); xc_core_memory_map_t *map; + if ( rc < 0 ) + return -1; + map = malloc(sizeof(*map)); if ( map == NULL ) { diff --git a/tools/libxc/xc_core_x86.c b/tools/libxc/xc_core_x86.c index d8846f1..02377e8 100644 --- a/tools/libxc/xc_core_x86.c +++ b/tools/libxc/xc_core_x86.c @@ -36,9 +36,16 @@ xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt, } -static int nr_gpfns(xc_interface *xch, domid_t domid) +static int nr_gpfns(xc_interface *xch, domid_t domid, unsigned long *gpfns) { - return xc_domain_maximum_gpfn(xch, domid) + 1; + int rc = xc_domain_maximum_gpfn(xch, domid); + + if ( rc >= 0 ) + { + *gpfns = rc + 1; + rc = 0; + } + return rc; } int @@ -53,9 +60,13 @@ xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context *unus xc_core_memory_map_t **mapp, unsigned int *nr_entries) { - unsigned long p2m_size = nr_gpfns(xch, info->domid); + unsigned long p2m_size = 0; + int rc = nr_gpfns(xch, info->domid, &p2m_size); xc_core_memory_map_t *map; + if ( rc < 0 ) + return -1; + map = malloc(sizeof(*map)); if ( map == NULL ) { @@ -88,7 +99,12 @@ xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *dinfo, xc int err; int i; - dinfo->p2m_size = nr_gpfns(xch, info->domid); + err = nr_gpfns(xch, info->domid, &dinfo->p2m_size); + if ( err < 0 ) + { + ERROR("nr_gpfns returns errno: %d.", errno); + goto out; + } if ( dinfo->p2m_size < info->nr_pages ) { ERROR("p2m_size < nr_pages -1 (%lx < %lx", dinfo->p2m_size, info->nr_pages - 1); diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c index 254fdb3..6346c12 100644 --- a/tools/libxc/xc_domain_save.c +++ b/tools/libxc/xc_domain_save.c @@ -939,7 +939,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter } /* Get the size of the P2M table */ - dinfo->p2m_size = xc_domain_maximum_gpfn(xch, dom) + 1; + rc = xc_domain_maximum_gpfn(xch, dom); + if ( rc < 0 ) + { + ERROR("Could not get maximum GPFN!"); + goto out; + } + dinfo->p2m_size = rc + 1; if ( dinfo->p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) { -- 2.1.0