From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH v3 07/19] libxl: x86: factor out e820_host_sanitize Date: Tue, 13 Jan 2015 21:00:49 +0000 Message-ID: <54B58781.5030904@citrix.com> References: <1421151107-20842-1-git-send-email-wei.liu2@citrix.com> <1421151107-20842-8-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1421151107-20842-8-git-send-email-wei.liu2@citrix.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: Wei Liu , xen-devel@lists.xen.org Cc: Elena Ufimtseva , dario.faggioli@citrix.com, Ian Jackson , Ian Campbell , jbeulich@suse.com List-Id: xen-devel@lists.xenproject.org On 13/01/15 12:11, Wei Liu wrote: > This function gets the machine E820 map and sanitize it according to PV > guest configuration. > > This will be used in later patch. No functional change introduced in > this patch. > > Signed-off-by: Wei Liu > Cc: Ian Campbell > Cc: Ian Jackson > Cc: Dario Faggioli > Cc: Elena Ufimtseva > --- > tools/libxl/libxl_x86.c | 31 ++++++++++++++++++++++--------- > 1 file changed, 22 insertions(+), 9 deletions(-) > > diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c > index 9ceb373..e959e37 100644 > --- a/tools/libxl/libxl_x86.c > +++ b/tools/libxl/libxl_x86.c > @@ -207,6 +207,27 @@ static int e820_sanitize(libxl_ctx *ctx, struct e820entry src[], > return 0; > } > > +static int e820_host_sanitize(libxl__gc *gc, > + libxl_domain_build_info *b_info, > + struct e820entry map[], > + uint32_t *nr) > +{ > + int rc; > + > + rc = xc_get_machine_memory_map(CTX->xch, map, E820MAX); This function should not assume that map[] is E820MAX entries long. The code you copied was passing a local variable whereas here you are passing someone else's pointer. You should pass the length in *nr like e820_sanitize() does. ~Andrew > + if (rc < 0) { > + errno = rc; > + return ERROR_FAIL; > + } > + > + *nr = rc; > + > + rc = e820_sanitize(CTX, map, nr, b_info->target_memkb, > + (b_info->max_memkb - b_info->target_memkb) + > + b_info->u.pv.slack_memkb); > + return rc; > +} > + > static int libxl__e820_alloc(libxl__gc *gc, uint32_t domid, > libxl_domain_config *d_config) > { > @@ -223,15 +244,7 @@ static int libxl__e820_alloc(libxl__gc *gc, uint32_t domid, > if (!libxl_defbool_val(b_info->u.pv.e820_host)) > return ERROR_INVAL; > > - rc = xc_get_machine_memory_map(ctx->xch, map, E820MAX); > - if (rc < 0) { > - errno = rc; > - return ERROR_FAIL; > - } > - nr = rc; > - rc = e820_sanitize(ctx, map, &nr, b_info->target_memkb, > - (b_info->max_memkb - b_info->target_memkb) + > - b_info->u.pv.slack_memkb); > + rc = e820_host_sanitize(gc, b_info, map, &nr); > if (rc) > return ERROR_FAIL; >