[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v7 31/32] libxl: allow the creation of HVM domains without a device model.
Replace the firmware loaded into HVM guests with an OS kernel. Since the HVM builder now uses the PV xc_dom_* set of functions this kernel will be parsed and loaded inside the guest like on PV, but the container is a pure HVM guest. Also, if device_model_version is set to none or a device model for the specified domain is not present unconditinally set the nic type to LIBXL_NIC_TYPE_VIF. Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx> Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> --- Changes since v5: - Add Wei Liu Acked-by. Changes since v4: - Set dom->mmio_size to match the size of the special pages if there's no device model for the guest. This implies moving NR_SPECIAL_PAGES and X86_HVM_END_SPECIAL_REGION to a public header so they can be known by libxl when creating the memory map. - Reword the xl.cfg man page description of the "none" device model option. - Use libxl__device_model_version_running instead of creating a new function. Changes since v3: - Add explicit /* fall through */ comments. - Expand libxl__device_nic_setdefault so that it sets the right nic type for HVMlite guests. - Remove stray space in hvm_build_set_params. - Fix the error paths of libxl__domain_firmware. --- docs/man/xl.cfg.pod.5 | 5 +++ tools/libxc/include/xc_dom.h | 2 ++ tools/libxc/xc_dom_x86.c | 15 ++++----- tools/libxl/libxl.c | 44 ++++++++++++++++++-------- tools/libxl/libxl_create.c | 16 +++++++++- tools/libxl/libxl_dm.c | 3 +- tools/libxl/libxl_dom.c | 74 ++++++++++++++++++++++++++++++-------------- tools/libxl/libxl_internal.h | 9 +++++- tools/libxl/libxl_types.idl | 1 + tools/libxl/libxl_x86.c | 15 ++++++--- tools/libxl/xl_cmdimpl.c | 2 ++ 11 files changed, 136 insertions(+), 50 deletions(-) diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 index f8fa48f..f627ac6 100644 --- a/docs/man/xl.cfg.pod.5 +++ b/docs/man/xl.cfg.pod.5 @@ -1781,6 +1781,11 @@ This device-model is the default for Linux dom0. Use the device-model based upon the historical Xen fork of Qemu. This device-model is still the default for NetBSD dom0. +=item B<none> + +Don't use any device model. This requires a kernel capable of booting +without emulated devices. + =back It is recommended to accept the default value for new guests. If diff --git a/tools/libxc/include/xc_dom.h b/tools/libxc/include/xc_dom.h index 720b218..4939f76 100644 --- a/tools/libxc/include/xc_dom.h +++ b/tools/libxc/include/xc_dom.h @@ -17,6 +17,8 @@ #include <xenguest.h> #define INVALID_P2M_ENTRY ((xen_pfn_t)-1) +#define X86_HVM_NR_SPECIAL_PAGES 8 +#define X86_HVM_END_SPECIAL_REGION 0xff000u /* --- typedefs and structs ---------------------------------------- */ diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c index 20a39b7..c3bb7a3 100644 --- a/tools/libxc/xc_dom_x86.c +++ b/tools/libxc/xc_dom_x86.c @@ -57,8 +57,8 @@ #define SPECIALPAGE_IOREQ 5 #define SPECIALPAGE_IDENT_PT 6 #define SPECIALPAGE_CONSOLE 7 -#define NR_SPECIAL_PAGES 8 -#define special_pfn(x) (0xff000u - NR_SPECIAL_PAGES + (x)) +#define special_pfn(x) \ + (X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES + (x)) #define NR_IOREQ_SERVER_PAGES 8 #define ioreq_server_pfn(x) (special_pfn(0) - NR_IOREQ_SERVER_PAGES + (x)) @@ -517,7 +517,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom) void *hvm_info_page; uint32_t *ident_pt, domid = dom->guest_domid; int rc; - xen_pfn_t special_array[NR_SPECIAL_PAGES]; + xen_pfn_t special_array[X86_HVM_NR_SPECIAL_PAGES]; xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES]; xc_interface *xch = dom->xch; @@ -532,18 +532,19 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom) } /* Allocate and clear special pages. */ - for ( i = 0; i < NR_SPECIAL_PAGES; i++ ) + for ( i = 0; i < X86_HVM_NR_SPECIAL_PAGES; i++ ) special_array[i] = special_pfn(i); - rc = xc_domain_populate_physmap_exact(xch, domid, NR_SPECIAL_PAGES, 0, 0, - special_array); + rc = xc_domain_populate_physmap_exact(xch, domid, X86_HVM_NR_SPECIAL_PAGES, + 0, 0, special_array); if ( rc != 0 ) { DOMPRINTF("Could not allocate special pages."); goto error_out; } - if ( xc_clear_domain_pages(xch, domid, special_pfn(0), NR_SPECIAL_PAGES) ) + if ( xc_clear_domain_pages(xch, domid, special_pfn(0), + X86_HVM_NR_SPECIAL_PAGES) ) goto error_out; xc_hvm_param_set(xch, domid, HVM_PARAM_STORE_PFN, diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index e4ea476..0948b9d 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1044,11 +1044,14 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid) } if (type == LIBXL_DOMAIN_TYPE_HVM) { - rc = libxl__domain_resume_device_model(gc, domid); - if (rc < 0) { - LOG(ERROR, "failed to unpause device model for domain %u:%d", - domid, rc); - goto out; + if (libxl__device_model_version_running(gc, domid) != + LIBXL_DEVICE_MODEL_VERSION_NONE) { + rc = libxl__domain_resume_device_model(gc, domid); + if (rc < 0) { + LOG(ERROR, "failed to unpause device model for domain %u:%d", + domid, rc); + goto out; + } } } ret = xc_domain_unpause(ctx->xch, domid); @@ -1597,11 +1600,11 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) switch (libxl__domain_type(gc, domid)) { case LIBXL_DOMAIN_TYPE_HVM: - if (!libxl_get_stubdom_id(CTX, domid)) - dm_present = 1; - else + if (libxl_get_stubdom_id(CTX, domid)) { dm_present = 0; - break; + break; + } + /* fall through */ case LIBXL_DOMAIN_TYPE_PV: pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid)); dm_present = (pid != NULL); @@ -3230,7 +3233,7 @@ out: /******************************************************************************/ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic, - uint32_t domid) + uint32_t domid, libxl_domain_build_info *info) { int rc; @@ -3267,8 +3270,23 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic, switch (libxl__domain_type(gc, domid)) { case LIBXL_DOMAIN_TYPE_HVM: - if (!nic->nictype) - nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU; + if (!nic->nictype) { + if (info != NULL) { + /* Path taken at creation time. */ + if (info->device_model_version == + LIBXL_DEVICE_MODEL_VERSION_NONE) + nic->nictype = LIBXL_NIC_TYPE_VIF; + else + nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU; + } else { + /* Path taken when hot-adding a nic. */ + if (libxl__device_model_version_running(gc, domid) == + LIBXL_DEVICE_MODEL_VERSION_NONE) + nic->nictype = LIBXL_NIC_TYPE_VIF; + else + nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU; + } + } break; case LIBXL_DOMAIN_TYPE_PV: if (nic->nictype == LIBXL_NIC_TYPE_VIF_IOEMU) { @@ -3317,7 +3335,7 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, libxl_device_nic_init(&nic_saved); libxl_device_nic_copy(CTX, &nic_saved, nic); - rc = libxl__device_nic_setdefault(gc, nic, domid); + rc = libxl__device_nic_setdefault(gc, nic, domid, NULL); if (rc) goto out; front = flexarray_make(gc, 16, 1); diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index bf2099b..675eb4f 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -119,6 +119,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, b_info->u.hvm.bios = LIBXL_BIOS_TYPE_ROMBIOS; break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: b_info->u.hvm.bios = LIBXL_BIOS_TYPE_SEABIOS; break; + case LIBXL_DEVICE_MODEL_VERSION_NONE: + break; default:return ERROR_INVAL; } @@ -132,6 +134,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, if (b_info->u.hvm.bios == LIBXL_BIOS_TYPE_ROMBIOS) return ERROR_INVAL; break; + case LIBXL_DEVICE_MODEL_VERSION_NONE: + break; default:abort(); } @@ -236,6 +240,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, break; } break; + case LIBXL_DEVICE_MODEL_VERSION_NONE: + b_info->video_memkb = 0; + break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: default: switch (b_info->u.hvm.vga.kind) { @@ -924,7 +931,8 @@ static void initiate_domain_create(libxl__egc *egc, * called libxl_device_nic_add when domcreate_launch_dm gets called, * but qemu needs the nic information to be complete. */ - ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid); + ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid, + &d_config->b_info); if (ret) { LOG(ERROR, "Unable to set nic defaults for nic %d", i); goto error_out; @@ -1266,6 +1274,12 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev, libxl__device_console_add(gc, domid, &console, state, &device); libxl__device_console_dispose(&console); + if (d_config->b_info.device_model_version == + LIBXL_DEVICE_MODEL_VERSION_NONE) { + domcreate_devmodel_started(egc, &dcs->dmss.dm, 0); + return; + } + libxl_device_vkb_init(&vkb); libxl__device_vkb_add(gc, domid, &vkb); libxl_device_vkb_dispose(&vkb); diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 8e337de..601a30c 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1544,7 +1544,8 @@ static void spawn_stub_launch_dm(libxl__egc *egc, * called libxl_device_nic_add at this point, but qemu needs * the nic information to be complete. */ - ret = libxl__device_nic_setdefault(gc, &dm_config->nics[i], dm_domid); + ret = libxl__device_nic_setdefault(gc, &dm_config->nics[i], dm_domid, + &dm_config->b_info); if (ret) goto out; } diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index b3ac44e..7e8ae14 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -782,21 +782,23 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid, uint64_t str_mfn, cons_mfn; int i; - va_map = xc_map_foreign_range(handle, domid, - XC_PAGE_SIZE, PROT_READ | PROT_WRITE, - HVM_INFO_PFN); - if (va_map == NULL) - return ERROR_FAIL; + if (info->device_model_version != LIBXL_DEVICE_MODEL_VERSION_NONE) { + va_map = xc_map_foreign_range(handle, domid, + XC_PAGE_SIZE, PROT_READ | PROT_WRITE, + HVM_INFO_PFN); + if (va_map == NULL) + return ERROR_FAIL; - va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET); - va_hvm->apic_mode = libxl_defbool_val(info->u.hvm.apic); - va_hvm->nr_vcpus = info->max_vcpus; - memset(va_hvm->vcpu_online, 0, sizeof(va_hvm->vcpu_online)); - memcpy(va_hvm->vcpu_online, info->avail_vcpus.map, info->avail_vcpus.size); - for (i = 0, sum = 0; i < va_hvm->length; i++) - sum += ((uint8_t *) va_hvm)[i]; - va_hvm->checksum -= sum; - munmap(va_map, XC_PAGE_SIZE); + va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET); + va_hvm->apic_mode = libxl_defbool_val(info->u.hvm.apic); + va_hvm->nr_vcpus = info->max_vcpus; + memset(va_hvm->vcpu_online, 0, sizeof(va_hvm->vcpu_online)); + memcpy(va_hvm->vcpu_online, info->avail_vcpus.map, info->avail_vcpus.size); + for (i = 0, sum = 0; i < va_hvm->length; i++) + sum += ((uint8_t *) va_hvm)[i]; + va_hvm->checksum -= sum; + munmap(va_map, XC_PAGE_SIZE); + } xc_hvm_param_get(handle, domid, HVM_PARAM_STORE_PFN, &str_mfn); xc_hvm_param_get(handle, domid, HVM_PARAM_CONSOLE_PFN, &cons_mfn); @@ -862,7 +864,7 @@ static int libxl__domain_firmware(libxl__gc *gc, { libxl_ctx *ctx = libxl__gc_owner(gc); const char *firmware; - int e, rc = ERROR_FAIL; + int e, rc; int datalen = 0; void *data; @@ -877,18 +879,34 @@ static int libxl__domain_firmware(libxl__gc *gc, case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: firmware = "hvmloader"; break; + case LIBXL_DEVICE_MODEL_VERSION_NONE: + if (info->kernel == NULL) { + LOG(ERROR, "no device model requested without a kernel"); + rc = ERROR_FAIL; + goto out; + } + break; default: LOG(ERROR, "invalid device model version %d", info->device_model_version); - return ERROR_FAIL; - break; + rc = ERROR_FAIL; + goto out; } } - rc = xc_dom_kernel_file(dom, libxl__abs_path(gc, firmware, + if (info->kernel != NULL && + info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_NONE) { + /* Try to load a kernel instead of the firmware. */ + rc = xc_dom_kernel_file(dom, info->kernel); + if (rc == 0 && info->ramdisk != NULL) + rc = xc_dom_ramdisk_file(dom, info->ramdisk); + } else { + rc = xc_dom_kernel_file(dom, libxl__abs_path(gc, firmware, libxl__xenfirmwaredir_path())); + } + if (rc != 0) { - LOGE(ERROR, "xc_dom_kernel_file failed"); + LOGE(ERROR, "xc_dom_{kernel_file/ramdisk_file} failed"); goto out; } @@ -899,6 +917,7 @@ static int libxl__domain_firmware(libxl__gc *gc, if (e) { LOGEV(ERROR, e, "failed to read SMBIOS firmware file %s", info->u.hvm.smbios_firmware); + rc = ERROR_FAIL; goto out; } libxl__ptr_add(gc, data); @@ -916,6 +935,7 @@ static int libxl__domain_firmware(libxl__gc *gc, if (e) { LOGEV(ERROR, e, "failed to read ACPI firmware file %s", info->u.hvm.acpi_firmware); + rc = ERROR_FAIL; goto out; } libxl__ptr_add(gc, data); @@ -928,6 +948,7 @@ static int libxl__domain_firmware(libxl__gc *gc, return 0; out: + assert(rc != 0); return rc; } @@ -940,10 +961,13 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, uint64_t mmio_start, lowmem_end, highmem_end, mem_size; libxl_domain_build_info *const info = &d_config->b_info; struct xc_dom_image *dom = NULL; + bool device_model = + info->device_model_version != LIBXL_DEVICE_MODEL_VERSION_NONE ? + true : false; xc_dom_loginit(ctx->xch); - dom = xc_dom_allocate(ctx->xch, NULL, NULL); + dom = xc_dom_allocate(ctx->xch, info->cmdline, NULL); if (!dom) { LOGE(ERROR, "xc_dom_allocate failed"); rc = ERROR_NOMEM; @@ -976,8 +1000,12 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, if (dom->target_pages == 0) dom->target_pages = mem_size >> XC_PAGE_SHIFT; - if (dom->mmio_size == 0) + if (dom->mmio_size == 0 && device_model) dom->mmio_size = HVM_BELOW_4G_MMIO_LENGTH; + else if (dom->mmio_size == 0 && !device_model) + dom->mmio_size = GB(4) - + ((X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES) + << XC_PAGE_SHIFT); lowmem_end = mem_size; highmem_end = 0; mmio_start = (1ull << 32) - dom->mmio_size; @@ -989,8 +1017,8 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, dom->lowmem_end = lowmem_end; dom->highmem_end = highmem_end; dom->mmio_start = mmio_start; - dom->vga_hole_size = LIBXL_VGA_HOLE_SIZE; - dom->device_model = true; + dom->vga_hole_size = device_model ? LIBXL_VGA_HOLE_SIZE : 0; + dom->device_model = device_model; rc = libxl__domain_device_construct_rdm(gc, d_config, info->u.hvm.rdm_mem_boundary_memkb*1024, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 25ace27..f6018a9 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -114,6 +114,12 @@ #define DOMID_XS_PATH "domid" #define INVALID_DOMID ~0 +/* Size macros. */ +#define __AC(X,Y) (X##Y) +#define _AC(X,Y) __AC(X,Y) +#define MB(_mb) (_AC(_mb, ULL) << 20) +#define GB(_gb) (_AC(_gb, ULL) << 30) + #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ROUNDUP(_val, _order) \ @@ -1186,7 +1192,8 @@ _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc, _hidden int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk); _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic, - uint32_t domid); + uint32_t domid, + libxl_domain_build_info *info); _hidden int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm); _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb); _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb); diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index d6ef9a2..082fed8 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -98,6 +98,7 @@ libxl_device_model_version = Enumeration("device_model_version", [ (0, "UNKNOWN"), (1, "QEMU_XEN_TRADITIONAL"), # Historical qemu-xen device model (qemu-dm) (2, "QEMU_XEN"), # Upstream based qemu-xen device model + (3, "NONE"), # No device model ]) libxl_console_type = Enumeration("console_type", [ diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index e71f80e..fb38e70 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -7,10 +7,16 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, xc_domain_configuration_t *xc_config) { - if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM) + + if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM && + d_config->b_info.device_model_version != + LIBXL_DEVICE_MODEL_VERSION_NONE) { + /* HVM domains with a device model. */ xc_config->emulation_flags = XEN_X86_EMU_ALL; - else + } else { + /* PV or HVM domains without a device model. */ xc_config->emulation_flags = 0; + } return 0; } @@ -487,6 +493,7 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc, struct e820entry *e820 = NULL; uint64_t highmem_size = dom->highmem_end ? dom->highmem_end - (1ull << 32) : 0; + uint32_t lowmem_start = dom->device_model ? GUEST_LOW_MEM_START_DEFAULT : 0; /* Add all rdm entries. */ for (i = 0; i < d_config->num_rdms; i++) @@ -507,8 +514,8 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc, e820 = libxl__malloc(gc, sizeof(struct e820entry) * e820_entries); /* Low memory */ - e820[nr].addr = GUEST_LOW_MEM_START_DEFAULT; - e820[nr].size = dom->lowmem_end - GUEST_LOW_MEM_START_DEFAULT; + e820[nr].addr = lowmem_start; + e820[nr].size = dom->lowmem_end - lowmem_start; e820[nr].type = E820_RAM; nr++; diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 365798b..840d73f 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2186,6 +2186,8 @@ skip_vfb: } else if (!strcmp(buf, "qemu-xen")) { b_info->device_model_version = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; + } else if (!strcmp(buf, "none")) { + b_info->device_model_version = LIBXL_DEVICE_MODEL_VERSION_NONE; } else { fprintf(stderr, "Unknown device_model_version \"%s\" specified\n", buf); -- 1.9.5 (Apple Git-50.3) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |