From patchwork Wed Jun 22 17:15:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 9193383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D881A601C0 for ; Wed, 22 Jun 2016 17:18:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C41802840A for ; Wed, 22 Jun 2016 17:18:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B931E28415; Wed, 22 Jun 2016 17:18:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 233242840A for ; Wed, 22 Jun 2016 17:18:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFlld-0004p5-O0; Wed, 22 Jun 2016 17:16:45 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFllc-0004nm-PD for xen-devel@lists.xen.org; Wed, 22 Jun 2016 17:16:44 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id C6/5B-11548-CF7CA675; Wed, 22 Jun 2016 17:16:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphkeJIrShJLcpLzFFi42JxWrrBXvf38ax wg81/1SyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ow3X6UKbjlV9D/cwNrAeMewi5GTQ0LAX2Lt 2052EJtNwEBixfSrjCC2iICsxOquOUBxDg5mgXKJo8d0QcLCAlYSmzc8YAUJswioSvT8KQEJ8 wrYSny6Po0VYqKcRMP5+8wgNqeAncSyVz1sILYQUM3tBQsYIWw1iRsLl7FA9ApKnJz5BMxmFp CQOPjiBTPIeAkBbom/3fYTGPlmIamahaRqASPTKkb14tSistQiXUO9pKLM9IyS3MTMHF1DAzO 93NTi4sT01JzEpGK95PzcTYzAUGIAgh2MO587HWKU5GBSEuVl3JYVLsSXlJ9SmZFYnBFfVJqT WnyIUYaDQ0mCN/4YUE6wKDU9tSItMwcY1DBpCQ4eJRHe8yBp3uKCxNzizHSI1ClGRSlx3giQh ABIIqM0D64NFkmXGGWlhHkZgQ4R4ilILcrNLEGVf8UozsGoJMw7F2QKT2ZeCdz0V0CLmYAWL+ tPB1lckoiQkmpgbP386pio5YsNVQrba0R0vJ+0/m1qbb5f+VPR5/3trcYaS2+Icd+TXMdi8Lp DwyEjWeSueKH4wUPzmj1q/9X79ms1uhnqrXTLOGqziNHuh/5j0enG/95Xx/K4f8tu2GPHMvv0 M/lNjk6vvxT/qTGdLbx8yUPGG/P0XUslEn/tdNm9YI13+EZtJZbijERDLeai4kQAjis8vp8CA AA= X-Env-Sender: prvs=9742ee4c2=anthony.perard@citrix.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1466615799!19762275!4 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28380 invoked from network); 22 Jun 2016 17:16:43 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-3.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 22 Jun 2016 17:16:43 -0000 X-IronPort-AV: E=Sophos;i="5.26,509,1459814400"; d="scan'208";a="369016603" From: Anthony PERARD To: Date: Wed, 22 Jun 2016 18:15:36 +0100 Message-ID: <20160622171545.5304-6-anthony.perard@citrix.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160622171545.5304-1-anthony.perard@citrix.com> References: <20160622171545.5304-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Anthony PERARD , Wei Liu , Ian Jackson Subject: [Xen-devel] [PATCH v5 05/14] libxl: Load guest BIOS from file X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The path to the BIOS blob can be overriden by the xl's bios_path_override option, or provided by u.hvm.bios_firmware in the domain_build_info struct by other libxl user. Signed-off-by: Anthony PERARD --- Changes in V5: - man page, use B<> to highlight config option in description. - rename config option from `bios_override` to `bios_path_override` - store libxl_read_file_contents() return value into r instead of e (just renamed the variable) - rename domain_build_info.u.hvm.bios_firmware to system_firmware Changes in V4: - updating man page to have bios_override described. - return ERROR_INVAL in libxl__load_hvm_firmware_module when the file is empty. Changes in V3: - move seabios_path and ovmf_path to libxl_path.c (with renaming) - fix some coding style - warn for empty file - remove rombios stuff (will still be built-in hvmloader) - rename field bios_filename in domain_build_info to bios_firmware to follow naming of acpi and smbios. - log an error after libxl_read_file_contents() only when it return ENOENT - return an error on empty file. - added #define LIBXL_HAVE_BUILDINFO_HVM_BIOS_FIRMWARE --- docs/man/xl.cfg.pod.5.in | 9 +++++++ tools/libxl/libxl.h | 8 +++++++ tools/libxl/libxl_dom.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_paths.c | 10 ++++++++ tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 11 ++++++--- 7 files changed, 95 insertions(+), 3 deletions(-) diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in index 3bb27d0..a685b83 100644 --- a/docs/man/xl.cfg.pod.5.in +++ b/docs/man/xl.cfg.pod.5.in @@ -1212,6 +1212,15 @@ Requires device_model_version=qemu-xen. =back +=item B + +Override the path to the blob to be used as BIOS. The blob provided here MUST +be consistent with the B which you have specified. You should not +normally need to specify this option. + +This options does not have any effect if using B or +B. + =item B Hide or expose the IA32 Physical Address Extensions. These extensions diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 2c0f868..2b1f678 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -928,6 +928,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src); #define LIBXL_HAVE_CHECKPOINTED_STREAM 1 /* + * LIBXL_HAVE_BUILDINFO_HVM_SYSTEM_FIRMWARE + * + * libxl_domain_build_info has u.hvm.system_firmware field which can be use + * to provide a different firmware blob (like SeaBIOS or OVMF). + */ +#define LIBXL_HAVE_BUILDINFO_HVM_SYSTEM_FIRMWARE + +/* * ERROR_REMUS_XXX error code only exists from Xen 4.5, Xen 4.6 and it * is changed to ERROR_CHECKPOINT_XXX in Xen 4.7 */ diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index ec29060..c341a29 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -862,6 +862,38 @@ err: return ret; } +static int libxl__load_hvm_firmware_module(libxl__gc *gc, + const char *filename, + const char *what, + struct xc_hvm_firmware_module *m) +{ + int datalen = 0; + void *data = NULL; + int r; + + LOG(DEBUG, "Loading %s: %s", what, filename); + r = libxl_read_file_contents(CTX, filename, &data, &datalen); + if (r) { + /* + * Print a message only on ENOENT, other errors are logged by the + * function libxl_read_file_contents(). + */ + if (r == ENOENT) + LOGEV(ERROR, r, "failed to read %s file", what); + return ERROR_FAIL; + } + libxl__ptr_add(gc, data); + if (datalen) { + /* Only accept non-empty files */ + m->data = data; + m->length = datalen; + } else { + LOG(ERROR, "file %s for %s is empty", filename, what); + return ERROR_INVAL; + } + return 0; +} + static int libxl__domain_firmware(libxl__gc *gc, libxl_domain_build_info *info, struct xc_dom_image *dom) @@ -871,6 +903,7 @@ static int libxl__domain_firmware(libxl__gc *gc, int e, rc; int datalen = 0; void *data; + const char *bios_filename = NULL; if (info->u.hvm.firmware) firmware = info->u.hvm.firmware; @@ -914,6 +947,30 @@ static int libxl__domain_firmware(libxl__gc *gc, goto out; } + if (info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { + if (info->u.hvm.system_firmware) { + bios_filename = info->u.hvm.system_firmware; + } else { + switch (info->u.hvm.bios) { + case LIBXL_BIOS_TYPE_SEABIOS: + bios_filename = libxl__seabios_path(); + break; + case LIBXL_BIOS_TYPE_OVMF: + bios_filename = libxl__ovmf_path(); + break; + case LIBXL_BIOS_TYPE_ROMBIOS: + default: + abort(); + } + } + } + + if (bios_filename) { + rc = libxl__load_hvm_firmware_module(gc, bios_filename, "BIOS", + &dom->system_firmware_module); + if (rc) goto out; + } + if (info->u.hvm.smbios_firmware) { data = NULL; e = libxl_read_file_contents(ctx, info->u.hvm.smbios_firmware, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index e7ab85d..e6a199b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2317,6 +2317,8 @@ _hidden const char *libxl__xen_config_dir_path(void); _hidden const char *libxl__xen_script_dir_path(void); _hidden const char *libxl__lock_dir_path(void); _hidden const char *libxl__run_dir_path(void); +_hidden const char *libxl__seabios_path(void); +_hidden const char *libxl__ovmf_path(void); /*----- subprocess execution with timeout -----*/ diff --git a/tools/libxl/libxl_paths.c b/tools/libxl/libxl_paths.c index 9b7b0d5..6972b90 100644 --- a/tools/libxl/libxl_paths.c +++ b/tools/libxl/libxl_paths.c @@ -35,6 +35,16 @@ const char *libxl__run_dir_path(void) return XEN_RUN_DIR; } +const char *libxl__seabios_path(void) +{ + return SEABIOS_PATH; +} + +const char *libxl__ovmf_path(void) +{ + return OVMF_PATH; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index ef614be..98bfc3a 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -513,6 +513,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("timer_mode", libxl_timer_mode), ("nested_hvm", libxl_defbool), ("altp2m", libxl_defbool), + ("system_firmware", string), ("smbios_firmware", string), ("acpi_firmware", string), ("hdtype", libxl_hdtype), diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 6459eec..18da7ab 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1562,12 +1562,17 @@ static void parse_config_data(const char *config_source, xlu_cfg_replace_string (config, "firmware_override", &b_info->u.hvm.firmware, 0); - if (!xlu_cfg_get_string(config, "bios", &buf, 0) && - libxl_bios_type_from_string(buf, &b_info->u.hvm.bios)) { + xlu_cfg_replace_string (config, "bios_path_override", + &b_info->u.hvm.system_firmware, 0); + if (!xlu_cfg_get_string(config, "bios", &buf, 0)) { + if (libxl_bios_type_from_string(buf, &b_info->u.hvm.bios)) { fprintf(stderr, "ERROR: invalid value \"%s\" for \"bios\"\n", buf); exit (1); - } + } + } else if (b_info->u.hvm.system_firmware) + fprintf(stderr, "WARNING: " + "bios_path_override given without specific bios name\n"); xlu_cfg_get_defbool(config, "pae", &b_info->u.hvm.pae, 0); xlu_cfg_get_defbool(config, "apic", &b_info->u.hvm.apic, 0);