|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [RFC][PATCH 10/13] tools: extend XENMEM_set_memory_map
On Fri, Apr 10, 2015 at 05:22:01PM +0800, Tiejun Chen wrote:
> Here we'll construct a basic guest e820 table via
> XENMEM_set_memory_map. This table includes lowmem, highmem
> and RDMs if they exist. And hvmloader would need this info
> later.
>
> Signed-off-by: Tiejun Chen <tiejun.chen@xxxxxxxxx>
> ---
> tools/libxl/libxl_dom.c | 72
> +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 72 insertions(+)
>
> diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
> index ee67282..82468be 100644
> --- a/tools/libxl/libxl_dom.c
> +++ b/tools/libxl/libxl_dom.c
> @@ -787,6 +787,70 @@ out:
> return rc;
> }
>
> +static int libxl__domain_construct_memmap(libxl_ctx *ctx,
Internal function should take libxl__gc *gc.
> + libxl_domain_config *d_config,
> + uint32_t domid,
> + struct xc_hvm_build_args *args,
> + int num_pcidevs,
> + libxl_device_pci *pcidevs)
I think domid, num_pcidevs and pcidevs should be in d_config by the
time you call this function? At least num_pcidevs and pcidevs should be
available.
That said, I don't see pci stuff being used anywhere in the function, so
please just delete them.
> +{
> + unsigned int nr = 0, i;
> + /* We always own at least one lowmem entry. */
> + unsigned int e820_entries = 1;
> + uint64_t highmem_end = 0, highmem_size = args->mem_size -
> args->lowmem_size;
FWIW there are some new output fields called lowmem_end, highmem_end and
mmio_start in xc_hvm_build_args. Those might be useful as well?
Note that they are only available *after* calling xc_hvm_build, which
seems to *not* be the case for you.
So if you somehow find those fields useful you might want to consider
moving the callsite a bit later.
> + struct e820entry *e820 = NULL;
> +
> + /* Add all rdm entries. */
> + e820_entries += d_config->num_rdms;
> +
> + /* If we should have a highmem range. */
> + if (highmem_size)
> + {
> + highmem_end = (1ull<<32) + highmem_size;
> + e820_entries++;
> + }
> +
> + e820 = malloc(sizeof(struct e820entry) * e820_entries);
You can use libxl__malloc(gc, ...).
> + if (!e820) {
> + return -1;
> + }
No need to check if you use libxl__malloc.
> +
> + /* Low memory */
> + e820[nr].addr = 0x100000;
Hardcoded value?
> + e820[nr].size = args->lowmem_size - 0x100000;
> + e820[nr].type = E820_RAM;
> + nr++;
> +
> + /* RDM mapping */
> + for (i = 0; i < d_config->num_rdms; i++) {
> + /*
> + * We should drop this kind of rdm entry.
> + */
> + if (d_config->rdms[i].flag == LIBXL_RDM_RESERVE_FLAG_INVALID)
> + continue;
> +
> + e820[nr].addr = d_config->rdms[i].start;
> + e820[nr].size = d_config->rdms[i].size;
> + e820[nr].type = E820_RESERVED;
> + nr++;
> + }
> +
> + /* High memory */
> + if (highmem_size) {
> + e820[nr].addr = ((uint64_t)1 << 32);
> + e820[nr].size = highmem_size;
> + e820[nr].type = E820_RAM;
> + }
> +
> + if (xc_domain_set_memory_map(ctx->xch, domid, e820, e820_entries) != 0) {
> + free(e820);
No need to free if you use libxl__malloc(gc, ...).
> + return -1;
> + }
> +
> + free(e820);
Ditto.
Wei.
> + return 0;
> +}
> +
> int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
> libxl_domain_config *d_config,
> libxl__domain_build_state *state)
> @@ -836,6 +900,14 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
> goto out;
> }
>
> + if (libxl__domain_construct_memmap(ctx, d_config, domid,
> + &args,
> + d_config->num_pcidevs,
> + d_config->pcidevs)) {
> + LOG(ERROR, "setting domain rdm memory map failed");
> + goto out;
> + }
> +
> if (libxl__domain_firmware(gc, info, &args)) {
> LOG(ERROR, "initializing domain firmware failed");
> goto out;
> --
> 1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |