From: Ian Campbell Subject: Re: [PATCH v3 4/5] tools, libxl: parse optional start gfn from the iomem config option Date: Fri, 21 Mar 2014 10:54:06 +0000 Message-ID: <1395399246.27358.34.camel@kazak.uk.xensource.com> References: <1394914286-29713-1-git-send-email-avanzini.arianna@gmail.com> <1394914286-29713-5-git-send-email-avanzini.arianna@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1394914286-29713-5-git-send-email-avanzini.arianna@gmail.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: Arianna Avanzini Cc: paolo.valente@unimore.it, keir@xen.org, stefano.stabellini@eu.citrix.com, Ian.Jackson@eu.citrix.com, dario.faggioli@citrix.com, tim@xen.org, xen-devel@lists.xen.org, julien.grall@citrix.com, etrudeau@broadcom.com, JBeulich@suse.com, viktor.kleinik@globallogic.com List-Id: xen-devel@lists.xenproject.org On Sat, 2014-03-15 at 21:11 +0100, Arianna Avanzini wrote: > Currently the "iomem" domU config option allows to specify a machine > address range to be mapped to the domU. However, there is no way to > specify the guest address range used for the mapping. This commit > extends the iomem config option code to parse an additional, optional > parameter: this parameter, if given, specifies the start guest address > used for the mapping; if no start guest address is given, a 1:1 mapping > is performed as default. > > Signed-off-by: Arianna Avanzini > Cc: Dario Faggioli > Cc: Paolo Valente > Cc: Stefano Stabellini > Cc: Julien Grall > Cc: Ian Campbell > Cc: Jan Beulich > Cc: Keir Fraser > Cc: Tim Deegan > Cc: Ian Jackson > Cc: Eric Trudeau > Cc: Viktor Kleinik > --- > docs/man/xl.cfg.pod.5 | 7 ++++--- > tools/libxl/libxl_types.idl | 1 + > tools/libxl/xl_cmdimpl.c | 22 +++++++++++++++------- > 3 files changed, 20 insertions(+), 10 deletions(-) > > diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 > index a6663b9..d9684f2 100644 > --- a/docs/man/xl.cfg.pod.5 > +++ b/docs/man/xl.cfg.pod.5 > @@ -602,12 +602,13 @@ is given in hexadecimal and may either a span e.g. C<2f8-2ff> > It is recommended to use this option only for trusted VMs under > administrator control. > > -=item B > +=item B > > Allow guest to access specific hardware I/O memory pages. B > is a physical page number. B is the number > -of pages beginning with B to allow access. Both values > -must be given in hexadecimal. > +of pages beginning with B to allow access. B specifies > +the guest frame number where the mapping will start in the domU's > +address space. All of these values must be given in hexadecimal. > > It is recommended to use this option only for trusted VMs under > administrator control. > diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl > index 612645c..f0bdb09 100644 > --- a/tools/libxl/libxl_types.idl > +++ b/tools/libxl/libxl_types.idl > @@ -172,6 +172,7 @@ libxl_ioport_range = Struct("ioport_range", [ > libxl_iomem_range = Struct("iomem_range", [ > ("start", uint64), > ("number", uint64), > + ("gfn", uint64), The existing name "start" is unfortunate since it doesn't really indicate what it is the start of. Can you please add comments to "gfn" and "start" (python syntax so # comment after each is fine) to clarify that one is the host address and the other is the guest address. > ]) > > libxl_vga_interface_info = Struct("vga_interface_info", [ > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c > index 6b1ebfa..cf8d71f 100644 > --- a/tools/libxl/xl_cmdimpl.c > +++ b/tools/libxl/xl_cmdimpl.c > @@ -1220,13 +1220,21 @@ static void parse_config_data(const char *config_source, > "xl: Unable to get element %d in iomem list\n", i); > exit(1); > } > - if(sscanf(buf, "%" SCNx64",%" SCNx64, > - &b_info->iomem[i].start, > - &b_info->iomem[i].number) > - != 2) { > - fprintf(stderr, > - "xl: Invalid argument parsing iomem: %s\n", buf); > - exit(1); > + if(sscanf(buf, "%" SCNx64",%" SCNx64"@%" SCNx64, > + &b_info->iomem[i].start, > + &b_info->iomem[i].number, > + &b_info->iomem[i].gfn) > + != 3) { > + if(sscanf(buf, "%" SCNx64",%" SCNx64, > + &b_info->iomem[i].start, > + &b_info->iomem[i].number) > + != 2) { > + fprintf(stderr, > + "xl: Invalid argument parsing iomem: %s\n", buf); > + exit(1); sscanf returns the number of entries it successfully matched and assigned, so sscanf(buf, "%" SCNx64",%" SCNx64"@%" SCNx64, will return 2 or 3 depending on what it found. So I think you can simplify this by switching on the return value of sscanf rather than reparsing it. swtich (sscanf(...)) { case 3: break; case 2: ...[i].gfn = ...[i].start; break; default: fpritnf(); exit } (you get the idea) Ian.