[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] libxl: allow the creation of HVM domains without a device model.
commit 5ca88cb7582a19636646c1a39c739fdbcaf3362a Author: Roger Pau Monne <roger.pau@xxxxxxxxxx> AuthorDate: Mon Dec 7 17:48:36 2015 +0100 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Tue Dec 15 13:25:44 2015 +0000 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> --- 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.h | 8 ++++ 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 + 12 files changed, 144 insertions(+), 50 deletions(-) diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 index 3b695bd..8899f75 100644 --- a/docs/man/xl.cfg.pod.5 +++ b/docs/man/xl.cfg.pod.5 @@ -1789,6 +1789,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 efa6c6e..2460818 100644 --- a/tools/libxc/include/xc_dom.h +++ b/tools/libxc/include/xc_dom.h @@ -20,6 +20,8 @@ #include <xenguest.h> #define INVALID_PFN ((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 d058949..3960875 100644 --- a/tools/libxc/xc_dom_x86.c +++ b/tools/libxc/xc_dom_x86.c @@ -58,8 +58,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)) @@ -589,7 +589,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; @@ -604,18 +604,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 bd604ac..9207621 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1065,11 +1065,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); @@ -1616,11 +1619,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, GCSPRINTF("/local/domain/%d/image/device-model-pid", domid)); dm_present = (pid != NULL); @@ -3240,7 +3243,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; @@ -3277,8 +3280,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) { @@ -3327,7 +3345,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.h b/tools/libxl/libxl.h index 981cb84..05606a7 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -859,6 +859,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src); */ #define LIBXL_HAVE_GFX_PASSTHRU_KIND +/* + * LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE + * + * In the case that LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE is set libxl + * allows the creation of HVM guests without a device model. + */ +#define LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE 1 + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index a9cf16a..261816a 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) { @@ -920,7 +927,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; @@ -1261,6 +1269,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 2de0273..0aaefd9 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1606,7 +1606,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 d17ea86..deb3ffa 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -787,21 +787,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); @@ -867,7 +869,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; @@ -882,18 +884,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; } @@ -904,6 +922,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); @@ -921,6 +940,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); @@ -933,6 +953,7 @@ static int libxl__domain_firmware(libxl__gc *gc, return 0; out: + assert(rc != 0); return rc; } @@ -945,10 +966,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; @@ -981,8 +1005,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; @@ -994,8 +1022,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 96842d3..15731a8 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -115,6 +115,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) \ @@ -1190,7 +1196,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 cf3730f..9658356 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 183b6c2..46cfafb 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; } @@ -485,6 +491,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++) @@ -505,8 +512,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 2b6371d..f9933cb 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); -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |