HVM firmware passthrough libxl support
PATCH v3 1/1 HVM firmware passthrough libxl support
This patch series is a follow-up to the earlier HVM firmware passthrough patch set. It introduces support in libxl for specifying and loading the ACPI and SMBIOS firmware blobs that are passed to libxc.
There are 3 patches in the series:
01 - Switch xl to use the new xc_hvm_build() libxc API.
02 - Xen xl toolstack changes to load ACPI and SMBIOS firmware files.
Doc changes to the man page for xl.cfg describing the new params.
03 - Cleanup, use LOG* and GCSPRINTF macro in libxl_dom.c
This version cleans up some of the logging and error handling in the new firmware passthrough code.
(Based on xen-4.3 staging/unstable cs 26527)
PATCH v3 1/1 HVM firmware passthrough libxl support
Switch libxl to use the new xc_hvm_build() libxc API.
tools/libxl/libxl_dom.c +13 -6
@@ -542,17 +542,24 @@ int libxl__build_hvm(libxl__gc *gc, uint libxl__domain_build_state *state) {libxl_ctx *ctx =libxl__gc_owner (gc); +struct xc_hvm_build_args args = {};int ret, rc =ERROR_FAIL ;const char *firmware =libxl__domain_firmware (gc, info);if (!firmware) goto out; - ret =xc_hvm_build_target_mem ( - ctx->xch, - domid, - (info->max_memkb - info->video_memkb) /1024 , - (info->target_memkb - info->video_memkb) /1024 , - firmware); + +memset (&args,0 ,sizeof (struct xc_hvm_build_args )); +/* The params from the configuration file are in Mb, which are then +* multiplied by 1 Kb. This was then divided off when calling +* the old xc_hvm_build_target_mem() which then turned them to bytes. +* Do all this in one step here... +*/ + args.mem_size = (uint64_t )(info->max_memkb - info->video_memkb) <<10 ; + args.mem_target = (uint64_t )(info->target_memkb - info->video_memkb) <<10 ; + args.image_file_name = firmware; + + ret =xc_hvm_build (ctx->xch, domid, &args);if (ret) {LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , ret,"hvm building failed" ); goto out;
PATCH v3 1/1 HVM firmware passthrough libxl support
In reply to Ross PhilipsonThis patch introduces support for two new parameters in libxl:
smbios_firmware=<path_to_smbios_structures_file>
acpi_firmware=<path_to_acpi_tables_file>
The changes are primarily in the domain building code where the firmware files are read and passed to libxc for loading into the new guest. After the domain building call to libxc, the addresses for the loaded blobs are returned and written to xenstore.
LIBXL_HAVE_FIRMWARE_PASSTHROUGH is defined in libxl.h to allow users to determine if the feature is present.
This patch also updates the xl.cfg man page with descriptions of the two new parameters for firmware passthrough.
docs/man/xl.cfg.pod.5 +19 -0
@@ -829,6 +829,25 @@ libxl: 'host,tm=0,sse3=0' More info about the CPUID instruction can be found in the processor manuals, and in Wikipedia: L<http://en.wikipedia.org/wiki/CPUID> +=item B<acpi_firmware="STRING"> + +Specify a path to a file that contains extra ACPI firmware tables to pass in to +a guest. The file can contain several tables in their binary AML form +concatenated together. Each table self describes its length so no additional +information is needed. These tables will be added to the ACPI table set in the +guest. Note that existing tables cannot be overridden by this feature. For +example this cannot be used to override tables like DSDT, FADT, etc. + +=item B<smbios_firmware="STRING"> + +Specify a path to a file that contains extra SMBIOS firmware structures to pass +in to a guest. The file can contain a set DMTF predefined structures which will +override the internal defaults. Not all predefined structures can be overridden, +only the following types: 0, 1, 2, 3, 11, 22, 39. The file can also contain any +number of vendor defined SMBIOS structures (type 128 - 255). Since SMBIOS +structures do not present their overall size, each entry in the file must be +preceded by a 32b integer indicating the size of the next structure. + =back =head3 Guest Virtual Time Controls
tools/libxl/libxl.h +7 -0
@@ -68,6 +68,13 @@*/ /* +* LIBXL_HAVE_FIRMWARE_PASSTHROUGH indicates the feature for +* passing in SMBIOS and ACPI firmware to HVM guests is present +* in the library. +*/ +#define LIBXL_HAVE_FIRMWARE_PASSTHROUGH 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_dom.c +115 -17
198 lines not on this page · raw message
tools/libxl/libxl_types.idl +2 -0
@@ -308,6 +308,8 @@ libxl_domain_build_info = Struct("domain ("vpt_align", libxl_defbool), ("timer_mode", libxl_timer_mode), ("nested_hvm", libxl_defbool), + ("smbios_firmware", string), + ("acpi_firmware", string), ("nographic", libxl_defbool), ("vga", libxl_vga_interface_info), ("vnc", libxl_vnc_info),
tools/libxl/xl_cmdimpl.c +5 -0
@@ -882,6 +882,11 @@ static void parse_config_data(const char }xlu_cfg_get_defbool (config,"nestedhvm" , &b_info->u.hvm.nested_hvm,0 ); + +xlu_cfg_replace_string (config,"smbios_firmware" , + &b_info->u.hvm.smbios_firmware,0 ); +xlu_cfg_replace_string (config,"acpi_firmware" , + &b_info->u.hvm.acpi_firmware,0 );break ;case LIBXL_DOMAIN_TYPE_PV : {
PATCH v3 1/1 HVM firmware passthrough libxl support
In reply to Ross PhilipsonCleanup, use LOG* and GCSPRINTF macro in libxl_dom.c
tools/libxl/libxl_dom.c +39 -58
@@ -31,8 +31,7 @@ libxl_domain_type libxl__domain_type(lib ret =xc_domain_getinfolist (ctx->xch, domid,1 , &info);if (ret !=1 || info.domain != domid) { -LIBXL__LOG (CTX ,LIBXL__LOG_ERROR , -"unable to get domain type for domid=%" PRIu32, domid); +LOG (ERROR ,"unable to get domain type for domid=%" PRIu32, domid);return LIBXL_DOMAIN_TYPE_INVALID ; }if (info.flags & XEN_DOMINF_hvm_guest)
@@ -313,20 +312,19 @@ int libxl__build_post(libxl__gc *gc, uin ents =libxl__calloc (gc,12 + (info->max_vcpus *2 ) +2 ,sizeof (char *)); ents[0 ] ="memory/static-max" ; - ents[1 ] =libxl__sprintf (gc,"%" PRId64, info->max_memkb); + ents[1 ] =GCSPRINTF ("%" PRId64, info->max_memkb); ents[2 ] ="memory/target" ; - ents[3 ] =libxl__sprintf (gc,"%" PRId64, - info->target_memkb - info->video_memkb); + ents[3 ] =GCSPRINTF ("%" PRId64, info->target_memkb - info->video_memkb); ents[4 ] ="memory/videoram" ; - ents[5 ] =libxl__sprintf (gc,"%" PRId64, info->video_memkb); + ents[5 ] =GCSPRINTF ("%" PRId64, info->video_memkb); ents[6 ] ="domid" ; - ents[7 ] =libxl__sprintf (gc,"%d" , domid); + ents[7 ] =GCSPRINTF ("%d" , domid); ents[8 ] ="store/port" ; - ents[9 ] =libxl__sprintf (gc,"%" PRIu32, state->store_port); + ents[9 ] =GCSPRINTF ("%" PRIu32, state->store_port); ents[10 ] ="store/ring-ref" ; - ents[11 ] =libxl__sprintf (gc,"%lu" , state->store_mfn); + ents[11 ] =GCSPRINTF ("%lu" , state->store_mfn);for (i =0 ; i < info->max_vcpus; i++) { - ents[12 +(i*2 )] =libxl__sprintf (gc,"cpu/%d/availability" , i); + ents[12 +(i*2 )] =GCSPRINTF ("cpu/%d/availability" , i); ents[12 +(i*2 )+1 ] =libxl_bitmap_test (&info->avail_vcpus, i) ?"online" :"offline" ; }
@@ -335,7 +333,7 @@ int libxl__build_post(libxl__gc *gc, uinif (info->type ==LIBXL_DOMAIN_TYPE_HVM ) { hvm_ents =libxl__calloc (gc,3 ,sizeof (char *)); hvm_ents[0 ] ="hvmloader/generation-id-address" ; - hvm_ents[1 ] =libxl__sprintf (gc,"0x%lx" , state->vm_generationid_addr); + hvm_ents[1 ] =GCSPRINTF ("0x%lx" , state->vm_generationid_addr); } dom_path =libxl__xs_get_dompath (gc, domid);
@@ -343,7 +341,7 @@ int libxl__build_post(libxl__gc *gc, uinreturn ERROR_FAIL ; } - vm_path =xs_read (ctx->xsh,XBT_NULL ,libxl__sprintf (gc,"%s/vm" , dom_path),NULL ); + vm_path =xs_read (ctx->xsh,XBT_NULL ,GCSPRINTF ("%s/vm" , dom_path),NULL ); retry_transaction: t =xs_transaction_start (ctx->xsh);
@@ -374,7 +372,7 @@ int libxl__build_pv(libxl__gc *gc, uint3 dom =xc_dom_allocate (ctx->xch, state->pv_cmdline, info->u.pv.features);if (!dom) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_allocate failed" ); +LOGE (ERROR ,"xc_dom_allocate failed" );return ERROR_FAIL ; }
@@ -384,13 +382,13 @@ int libxl__build_pv(libxl__gc *gc, uint3 state->pv_kernel.data, state->pv_kernel.size);if ( ret !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_kernel_mem failed" ); +LOGE (ERROR ,"xc_dom_kernel_mem failed" ); goto out; } }else { ret =xc_dom_kernel_file (dom, state->pv_kernel.path);if ( ret !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_kernel_file failed" ); +LOGE (ERROR ,"xc_dom_kernel_file failed" ); goto out; } }
@@ -398,12 +396,12 @@ int libxl__build_pv(libxl__gc *gc, uint3if ( state->pv_ramdisk.path &&strlen (state->pv_ramdisk.path) ) {if (state->pv_ramdisk.mapped) {if ( (ret =xc_dom_ramdisk_mem (dom, state->pv_ramdisk.data, state->pv_ramdisk.size)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_ramdisk_mem failed" ); +LOGE (ERROR ,"xc_dom_ramdisk_mem failed" ); goto out; } }else {if ( (ret =xc_dom_ramdisk_file (dom, state->pv_ramdisk.path)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_ramdisk_file failed" ); +LOGE (ERROR ,"xc_dom_ramdisk_file failed" ); goto out; } }
@@ -416,31 +414,31 @@ int libxl__build_pv(libxl__gc *gc, uint3 dom->xenstore_domid = state->store_domid;if ( (ret =xc_dom_boot_xen_init (dom, ctx->xch, domid)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_boot_xen_init failed" ); +LOGE (ERROR ,"xc_dom_boot_xen_init failed" ); goto out; }if ( (ret =xc_dom_parse_image (dom)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_parse_image failed" ); +LOGE (ERROR ,"xc_dom_parse_image failed" ); goto out; }if ( (ret =xc_dom_mem_init (dom, info->target_memkb /1024 )) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_mem_init failed" ); +LOGE (ERROR ,"xc_dom_mem_init failed" ); goto out; }if ( (ret =xc_dom_boot_mem_init (dom)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_boot_mem_init failed" ); +LOGE (ERROR ,"xc_dom_boot_mem_init failed" ); goto out; }if ( (ret =xc_dom_build_image (dom)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_build_image failed" ); +LOGE (ERROR ,"xc_dom_build_image failed" ); goto out; }if ( (ret =xc_dom_boot_image (dom)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_boot_image failed" ); +LOGE (ERROR ,"xc_dom_boot_image failed" ); goto out; }if ( (ret =xc_dom_gnttab_init (dom)) !=0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_dom_gnttab_init failed" ); +LOGE (ERROR ,"xc_dom_gnttab_init failed" ); goto out; }
@@ -679,8 +677,7 @@ int libxl__qemu_traditional_cmd(libxl__g const char *cmd) {char *path =NULL ; - path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , - domid); + path =GCSPRINTF ("/local/domain/0/device-model/%d/command" , domid);return libxl__xs_write (gc,XBT_NULL , path,"%s" , cmd); }
@@ -697,8 +694,7 @@ struct libxl__physmap_info {static inline char *restore_helper (libxl__gc *gc,uint32_t domid,uint64_t phys_offset,char *node) { -return libxl__sprintf (gc, -"/local/domain/0/device-model/%d/physmap/%" PRIx64"/%s" , +return GCSPRINTF ("/local/domain/0/device-model/%d/physmap/%" PRIx64"/%s" , domid, phys_offset, node); }
@@ -708,7 +704,6 @@ int libxl__toolstack_restore(uint32_t dolibxl__save_helper_state *shs = user;libxl__domain_create_state *dcs =CONTAINER_OF (shs, *dcs, shs);STATE_AO_GC (dcs->ao); -libxl_ctx *ctx =CTX ;int i, ret;const uint8_t *ptr = buf;uint32_t count =0 , version =0 ;
@@ -718,7 +713,7 @@ int libxl__toolstack_restore(uint32_t doLOG (DEBUG ,"domain=%" PRIu32" toolstack data size=%" PRIu32, domid, size);if (size <sizeof (version) +sizeof (count)) { -LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"wrong size" ); +LOG (ERROR ,"wrong size" );return -1 ; }
@@ -726,7 +721,7 @@ int libxl__toolstack_restore(uint32_t do ptr +=sizeof (version);if (version !=TOOLSTACK_SAVE_VERSION ) { -LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"wrong version" ); +LOG (ERROR ,"wrong version" );return -1 ; }
@@ -735,7 +730,7 @@ int libxl__toolstack_restore(uint32_t doif (size <sizeof (version) +sizeof (count) + count * (sizeof (struct libxl__physmap_info ))) { -LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"wrong size" ); +LOG (ERROR ,"wrong size" );return -1 ; }
@@ -984,15 +979,13 @@ static void switch_logdirty_done(libxl__int libxl__domain_suspend_device_model (libxl__gc *gc,libxl__domain_suspend_state *dss) { -libxl_ctx *ctx =libxl__gc_owner (gc);int ret =0 ;uint32_t const domid = dss->domid;const char *const filename = dss->dm_savefile;switch (libxl__device_model_version_running (gc, domid)) {case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : { -LIBXL__LOG (ctx,LIBXL__LOG_DEBUG , -"Saving device model state to %s" , filename); +LOG (DEBUG ,"Saving device model state to %s" , filename);libxl__qemu_traditional_cmd (gc, domid,"save" );libxl__wait_for_device_model (gc, domid,"paused" ,NULL ,NULL ,NULL );break ;
@@ -1168,8 +1161,7 @@ int libxl__domain_suspend_common_callbacstatic inline char *physmap_path (libxl__gc *gc,uint32_t domid,char *phys_offset,char *node) { -return libxl__sprintf (gc, -"/local/domain/0/device-model/%d/physmap/%s/%s" , +return GCSPRINTF ("/local/domain/0/device-model/%d/physmap/%s/%s" , domid, phys_offset, node); }
@@ -1186,7 +1178,7 @@ int libxl__toolstack_save(uint32_t domidchar **entries =NULL ;struct libxl__physmap_info *pi; - entries =libxl__xs_directory (gc,0 ,libxl__sprintf (gc, + entries =libxl__xs_directory (gc,0 ,GCSPRINTF ("/local/domain/0/device-model/%d/physmap" , domid), &num); count = num;
@@ -1327,7 +1319,7 @@ void libxl__domain_suspend(libxl__egc *echar *path;char *addr; - path =libxl__sprintf (gc,"%s/hvmloader/generation-id-address" , + path =GCSPRINTF ("%s/hvmloader/generation-id-address" ,libxl__xs_get_dompath (gc, domid)); addr =libxl__xs_read (gc,XBT_NULL , path);
@@ -1541,10 +1533,7 @@ static void domain_suspend_done(libxl__echar *libxl__uuid2string (libxl__gc *gc,const libxl_uuid uuid) { -char *s =libxl__sprintf (gc,LIBXL_UUID_FMT ,LIBXL_UUID_BYTES (uuid)); -if (!s) -LIBXL__LOG (libxl__gc_owner (gc),LIBXL__LOG_ERROR ,"cannot allocate for uuid" ); -return s; +return GCSPRINTF (LIBXL_UUID_FMT ,LIBXL_UUID_BYTES (uuid)); } static const char *userdata_path(libxl__gc *gc, uint32_t domid,
@@ -1552,34 +1541,27 @@ static const char *userdata_path(libxl__ const char *wh) {libxl_ctx *ctx =libxl__gc_owner (gc); -char *path, *uuid_string; +char *uuid_string;libxl_dominfo info;int rc; rc =libxl_domain_info (ctx, &info, domid);if (rc) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"unable to find domain info" -" for domain %" PRIu32, domid); +LOGE (ERROR ,"unable to find domain info for domain %" PRIu32, domid);return NULL ; } - uuid_string =libxl__sprintf (gc,LIBXL_UUID_FMT ,LIBXL_UUID_BYTES (info.uuid)); + uuid_string =GCSPRINTF (LIBXL_UUID_FMT ,LIBXL_UUID_BYTES (info.uuid)); - path =libxl__sprintf (gc,"/var/lib/xen/" -"userdata-%s.%u.%s.%s" , - wh, domid, uuid_string, userdata_userid); -if (!path) -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"unable to allocate for" -" userdata path" ); -return path; +return GCSPRINTF ("/var/lib/xen/userdata-%s.%u.%s.%s" , + wh, domid, uuid_string, userdata_userid); }static int userdata_delete (libxl__gc *gc,const char *path) { -libxl_ctx *ctx =libxl__gc_owner (gc);int r; r =unlink (path);if (r) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"remove failed for %s" , path); +LOGE (ERROR ,"remove failed for %s" , path);return errno; }return 0 ;
@@ -1587,7 +1569,6 @@ static int userdata_delete(libxl__gc *gcvoid libxl__userdata_destroyall (libxl__gc *gc,uint32_t domid) { -libxl_ctx *ctx =libxl__gc_owner (gc);const char *pattern;glob_t gl;int r, i;
@@ -1603,7 +1584,7 @@ void libxl__userdata_destroyall(libxl__gif (r ==GLOB_NOMATCH ) goto out;if (r) -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"glob failed for %s" , pattern); +LOGE (ERROR ,"glob failed for %s" , pattern);for (i=0 ; i<gl.gl_pathc; i++) {userdata_delete (gc, gl.gl_pathv[i]);
Quoted 10 lines · Ross Philipson
This patch series is a follow-up to the earlier HVM firmware passthrough patch set. It introduces support in libxl for specifying and loading the ACPI and SMBIOS firmware blobs that are passed to libxc.
There are 3 patches in the series:
01 - Switch xl to use the newxc_hvm_build()libxc API.
02 - Xen xl toolstack changes to load ACPI and SMBIOS firmware files.
Doc changes to the man page for xl.cfg describing the new params.
03 - Cleanup, use LOG* and GCSPRINTF macro inlibxl_dom.c
Quoted 4 lines
This version cleans up some of the logging and error handling in the new firmware passthrough code.
Signed-off-by Ross Philipson <[email protected]>
Acked + applied. All three patches had the same title here, please give patches unique and descriptive titles in the future. I retitled them as:
libxl: switch to using the new xc_hvm_build() libxc API.
libxl: HVM firmware passthrough support
libxl: Cleanup, use LOG* and GCSPRINTF macro in libxl_dom.c
Wilco, thank you.
Quoted 34 lines
-----Original Message-----
From: Ian Campbell
Sent: Friday, February 15, 2013 8:39 AM
To: Ross Philipson
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH 0 of 3] [v3] HVM firmware passthrough libxl supportQuoted 1 line · Ross Philipson
This patch series is a follow-up to the earlier HVM firmware
passthrough
Quoted 1 line
patch set. It introduces support in libxl for specifying and loading
the
Quoted 8 lines
ACPI and SMBIOS firmware blobs that are passed to libxc.
There are 3 patches in the series:
01 - Switch xl to use the newxc_hvm_build()libxc API.
02 - Xen xl toolstack changes to load ACPI and SMBIOS firmware files.
Doc changes to the man page for xl.cfg describing the new params.
03 - Cleanup, use LOG* and GCSPRINTF macro inlibxl_dom.cQuoted 4 lines
This version cleans up some of the logging and error handling in the new firmware passthrough code.
Signed-off-by Ross Philipson <[email protected]>Acked + applied. All three patches had the same title here, please give patches unique and descriptive titles in the future. I retitled them as:
libxl: switch to using the new
xc_hvm_build()libxc API.
libxl: HVM firmware passthrough support
libxl: Cleanup, use LOG* and GCSPRINTF macro inlibxl_dom.c