[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v5 28/28] 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> 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 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 | 9 ++++-- tools/libxl/xl_cmdimpl.c | 2 ++ 11 files changed, 131 insertions(+), 49 deletions(-) diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 index 80e51bb..75d9949 100644 --- a/docs/man/xl.cfg.pod.5 +++ b/docs/man/xl.cfg.pod.5 @@ -1741,6 +1741,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 507b323..b89f8e3 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 3b40ba1..fe11ef9 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)) @@ -516,7 +516,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; @@ -531,18 +531,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 4f2eb24..9fe1c33 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1033,11 +1033,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); @@ -1584,11 +1587,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); @@ -3205,7 +3208,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; @@ -3242,8 +3245,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) { @@ -3292,7 +3310,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 5128160..00fe462 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) { @@ -923,7 +930,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; @@ -1260,6 +1268,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 16ad47a..7ae10d3 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1501,7 +1501,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 4a214e7..b82b938 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -781,21 +781,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); @@ -861,7 +863,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; @@ -876,18 +878,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; } @@ -898,6 +916,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); @@ -915,6 +934,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); @@ -927,6 +947,7 @@ static int libxl__domain_firmware(libxl__gc *gc, return 0; out: + assert(rc != 0); return rc; } @@ -939,10 +960,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"); goto out; @@ -974,8 +998,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; @@ -987,8 +1015,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 294d442..e155987 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -112,6 +112,12 @@ #define TAP_DEVICE_SUFFIX "-emu" #define DOMID_XS_PATH "domid" +/* 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) \ @@ -1173,7 +1179,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 ef346e7..b6e99c4 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 9ecd85d..cf68541 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -7,7 +7,9 @@ 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) xc_config->emulation_flags = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | @@ -488,6 +490,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++) @@ -508,8 +511,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 ebbb9a5..4464aa5 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2172,6 +2172,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 |