Files
xen/tools/libxc/xc_dom_compat_linux.c
T
Andrew Cooper 87b0ae7e82 tools/dombuilder: Fix asymmetry when setting up console and xenstore rings
libxl always uses xc_dom_gnttab_init(), which internally calls
xc_dom_gnttab{_hvm,}_seed() to set up the grants point at the console and
xenstore rings.  For HVM guests, libxl then asks Xen for the information set
up previously, and calls xc_dom_gnttab_hvm_seed() a second time, which is
wasteful.  ARM construction expects libxl to have set up
dom->{console,xenstore}_evtchn earlier, so only actually functions because of
this second call.

Rationalise everything and make it consistent for all guests.

 1) Users of the domain builder are expected to provide
    dom->{console,xenstore}_{evtchn,domid} unconditionally.  This is checked
    by setting invalid values in xc_dom_allocate(), and checking in
    xc_dom_boot_image().

 2) For x86 HVM and ARM guests, the event channels are given to Xen at the
    same time as the ring gfns.  ARM already did this, but x86 is updated to
    match.  x86 PV already provides this information in the start_info page.

 3) Libxl is updated to drop all relevant functionality from
    hvm_build_set_params(), and behave consistently with PV guests when it
    comes to the handling of dom->{console,xenstore}_{evtchn,domid,gfn}.

This removes several redundant hypercalls (including a foreign mapping) from
the x86 HVM and ARM construction paths.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Tested-by: Julien Grall <julien.grall@arm.com>
Release-acked-by: Julien Grall <julien.grall@linaro.org>
2017-11-02 17:07:23 +00:00

100 lines
2.8 KiB
C

/*
* Xen domain builder -- compatibility code.
*
* Replacements for xc_linux_build & friends,
* as example code and to make the new builder
* usable as drop-in replacement.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; If not, see <http://www.gnu.org/licenses/>.
*
* written 2006 by Gerd Hoffmann <kraxel@suse.de>.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <zlib.h>
#include "xenctrl.h"
#include "xg_private.h"
#include "xc_dom.h"
/* ------------------------------------------------------------------------ */
int xc_linux_build(xc_interface *xch, uint32_t domid,
unsigned int mem_mb,
const char *image_name,
const char *initrd_name,
const char *cmdline,
const char *features,
unsigned long flags,
unsigned int store_evtchn,
unsigned long *store_mfn,
unsigned int console_evtchn,
unsigned long *console_mfn)
{
struct xc_dom_image *dom;
int rc;
xc_dom_loginit(xch);
dom = xc_dom_allocate(xch, cmdline, features);
if (dom == NULL)
return -1;
if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
goto out;
if ( initrd_name && strlen(initrd_name) &&
((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
goto out;
dom->flags |= flags;
dom->console_evtchn = console_evtchn;
dom->console_domid = 0;
dom->xenstore_evtchn = store_evtchn;
dom->xenstore_domid = 0;
if ( (rc = xc_dom_boot_xen_init(dom, xch, domid)) != 0 )
goto out;
if ( (rc = xc_dom_parse_image(dom)) != 0 )
goto out;
if ( (rc = xc_dom_mem_init(dom, mem_mb)) != 0 )
goto out;
if ( (rc = xc_dom_boot_mem_init(dom)) != 0 )
goto out;
if ( (rc = xc_dom_build_image(dom)) != 0 )
goto out;
if ( (rc = xc_dom_boot_image(dom)) != 0 )
goto out;
if ( (rc = xc_dom_gnttab_init(dom)) != 0)
goto out;
*console_mfn = dom->console_gfn;
*store_mfn = dom->xenstore_gfn;
out:
xc_dom_release(dom);
return rc;
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/