From patchwork Thu Feb 25 14:56:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 8424171 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB8F49F314 for ; Thu, 25 Feb 2016 14:59:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20D1F2026F for ; Thu, 25 Feb 2016 14:59:15 +0000 (UTC) Received: from lists.xen.org (unknown [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B4BD20204 for ; Thu, 25 Feb 2016 14:59:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aYxLx-0001Yf-JG; Thu, 25 Feb 2016 14:57:17 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aYxLw-0001T5-4F for xen-devel@lists.xen.org; Thu, 25 Feb 2016 14:57:16 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id AD/31-03651-B461FC65; Thu, 25 Feb 2016 14:57:15 +0000 X-Env-Sender: prvs=85652c963=anthony.perard@citrix.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1456412233!25029451!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1812 invoked from network); 25 Feb 2016 14:57:14 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 25 Feb 2016 14:57:14 -0000 X-IronPort-AV: E=Sophos;i="5.22,498,1449532800"; d="scan'208";a="334491065" From: Anthony PERARD To: Date: Thu, 25 Feb 2016 14:56:03 +0000 Message-ID: <1456412174-20162-6-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456412174-20162-1-git-send-email-anthony.perard@citrix.com> References: <1456412174-20162-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Anthony PERARD , Wei Liu , Ian Jackson , Stefano Stabellini Subject: [Xen-devel] [PATCH v3 05/16] 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-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The path to the BIOS blob can be override by the xl's bios_override option, or provided by u.hvm.bios_firmware in the domain_build_info struct by other libxl user. Signed-off-by: Anthony PERARD --- Change 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 --- 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 ++++++--- 6 files changed, 86 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index fa87f53..d223c35 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -876,6 +876,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src); */ #define LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE 1 +/* + * LIBXL_HAVE_BUILDINFO_HVM_BIOS_FIRMWARE + * + * libxl_domain_build_info has u.hvm.bios_firmware field which can be use + * to provide a different bios blob (like SeaBIOS or OVMF). + */ +#define LIBXL_HAVE_BUILDINFO_HVM_BIOS_FIRMWARE + 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_dom.c b/tools/libxl/libxl_dom.c index 2269998..50abfbc 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -863,6 +863,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 e; + + LOG(DEBUG, "Loading %s: %s", what, filename); + e = libxl_read_file_contents(CTX, filename, &data, &datalen); + if (e) { + /* + * Print a message only on ENOENT, other error are logged by the + * function libxl_read_file_contents(). + */ + if (e == ENOENT) + LOGEV(ERROR, e, "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_FAIL; + } + return 0; +} + static int libxl__domain_firmware(libxl__gc *gc, libxl_domain_build_info *info, struct xc_dom_image *dom) @@ -872,6 +904,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; @@ -915,6 +948,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.bios_firmware) { + bios_filename = info->u.hvm.bios_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->bios_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 650a958..0dbff27 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2265,6 +2265,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 9ad7eba..95bacd2 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -487,6 +487,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("timer_mode", libxl_timer_mode), ("nested_hvm", libxl_defbool), ("altp2m", libxl_defbool), + ("bios_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 f40af51..201cff6 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1500,12 +1500,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_override", + &b_info->u.hvm.bios_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.bios_firmware) + fprintf(stderr, "WARNING: " + "bios_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);