From patchwork Thu Jul 28 10:50:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 9251097 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 266506075F for ; Thu, 28 Jul 2016 10:54:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1791026785 for ; Thu, 28 Jul 2016 10:54:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C22326B4A; Thu, 28 Jul 2016 10:54:36 +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 952FB26785 for ; Thu, 28 Jul 2016 10:54:35 +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 1bSitd-0007D8-9C; Thu, 28 Jul 2016 10:50:33 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSitc-0007Av-4z for xen-devel@lists.xen.org; Thu, 28 Jul 2016 10:50:32 +0000 Received: from [193.109.254.147] by server-10.bemta-14.messagelabs.com id 38/B4-03469-773E9975; Thu, 28 Jul 2016 10:50:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHSDvW7Z45n hBieOm1os+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnb+x0LlmhXNF7pYW9gvKTYxcjJISHgL3Hy zklWEJtNwEBixfSrjCC2iICsxOquOexdjFwczAJHGCVu3fwJlhAWsJTYde85O4jNIqAqcattM 5jNK2AnsXHpNnaIoXISDefvM4PYnAL2EisP3weLCwHVHNq4kBnCVpO4sXAZC0SvoMTJmU/AbG YBCYmDL14wQ8zhlrh9eirzBEa+WUjKZiEpW8DItIpRozi1qCy1SNfQQi+pKDM9oyQ3MTNH19D QRC83tbg4MT01JzGpWC85P3cTIzCo6hkYGHcwHtnueYhRkoNJSZQ3LHRmuBBfUn5KZUZicUZ8 UWlOavEhRhkODiUJ3sxHQDnBotT01Iq0zBxgeMOkJTh4lER4K0DSvMUFibnFmekQqVOMilLiv CYgCQGQREZpHlwbLKYuMcpKCfMyMjAwCPEUpBblZpagyr9iFOdgVBLmnQkyhSczrwRu+iugxU xAi4tjZ4AsLklESEk1MMpLnJ6lmcu94oSic2+fw8QbjycnbveoN4+72vt93lK5dzPVV+t/idk ufiG9976zhsf8o1vNVz1+fPRM53knwXaHPQUi5bttK6NnXbZyn/C7MaCwt0XeM0r6dj+Ho8pa 20Vmf20jf74ufDT/aPQEpn5//witRbuVP3PrTNv5soF17nlOs/33ryqxFGckGmoxFxUnAgCJ7 UAepAIAAA== X-Env-Sender: prvs=0100a76d6=anthony.perard@citrix.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1469703029!56167039!1 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.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12653 invoked from network); 28 Jul 2016 10:50:30 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jul 2016 10:50:30 -0000 X-IronPort-AV: E=Sophos;i="5.28,433,1464652800"; d="scan'208";a="375969525" From: Anthony PERARD To: Date: Thu, 28 Jul 2016 11:50:06 +0100 Message-ID: <20160728105013.22310-9-anthony.perard@citrix.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160728105013.22310-1-anthony.perard@citrix.com> References: <20160728105013.22310-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Anthony PERARD , Andrew Cooper , Ian Jackson , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v7 08/15] hvmloader: Locate the BIOS blob 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 BIOS blob can be found an entry called "firmware" of the modlist of the hvm_start_info struct. The found BIOS blob is not loaded by this patch, but only passed as argument to bios_load() function. Signed-off-by: Anthony PERARD --- Changes in V6: - cast addresses to uintptr_t instead of uint32_t. - use UINTPTR_MAX for the upper boundary checks. - Do a full check of every things that are used, check that modlist, cmdlines, modules lives below 4GB and does not cross the boundary. Changes in V5: - don't BUG() on module's paddr having value 0, and just skip. - fix some coding style - rename module name to "firmware" (was "bios") - less use of BUG_ON in get_module_entry() and skip entries instead. Only BUG() if the module which match name is not accessible. Changes in V4: - add more BUG_ON into get_module_entry(). Check that modules paddr and size are 32bits. Changes in V3: - fix some codying style - use module.cmdline to look for a module name instead of the main cmdline from hvm_start_info. --- tools/firmware/hvmloader/config.h | 2 +- tools/firmware/hvmloader/hvmloader.c | 60 ++++++++++++++++++++++++++++++++++-- tools/firmware/hvmloader/ovmf.c | 3 +- tools/firmware/hvmloader/rombios.c | 3 +- 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h index b838cf9..4c6d8ad 100644 --- a/tools/firmware/hvmloader/config.h +++ b/tools/firmware/hvmloader/config.h @@ -22,7 +22,7 @@ struct bios_config { /* ROMS */ void (*load_roms)(void); - void (*bios_load)(const struct bios_config *config); + void (*bios_load)(const struct bios_config *config, void *addr, uint32_t size); void (*bios_info_setup)(void); void (*bios_info_finish)(void); diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c index 77c70e0..5c57ab3 100644 --- a/tools/firmware/hvmloader/hvmloader.c +++ b/tools/firmware/hvmloader/hvmloader.c @@ -254,10 +254,57 @@ static void acpi_enable_sci(void) BUG_ON(!(pm1a_cnt_val & ACPI_PM1C_SCI_EN)); } +const struct hvm_modlist_entry *get_module_entry( + const struct hvm_start_info *info, + const char *name) +{ + const struct hvm_modlist_entry *modlist = + (struct hvm_modlist_entry *)(uintptr_t)info->modlist_paddr; + unsigned int i; + + if ( !modlist || + info->modlist_paddr > UINTPTR_MAX || + (info->modlist_paddr + info->nr_modules * sizeof(*modlist) - 1) + > UINTPTR_MAX + ) + return NULL; + + for ( i = 0; i < info->nr_modules; i++ ) + { + char *module_name = (char*)(uintptr_t)modlist[i].cmdline_paddr; + + /* Skip if the module or its cmdline is missing. */ + if ( !module_name || !modlist[i].paddr ) + continue; + + /* Skip if the cmdline can not be read. */ + if ( modlist[i].cmdline_paddr > UINTPTR_MAX || + (modlist[i].cmdline_paddr + strlen(name)) > UINTPTR_MAX ) + continue; + + if ( !strcmp(name, module_name) ) + { + if ( modlist[i].paddr > UINTPTR_MAX || + modlist[i].size > UINTPTR_MAX || + (modlist[i].paddr + modlist[i].size - 1) > UINTPTR_MAX ) + { + printf("Can not load \"%s\" from 0x"PRIllx" (0x"PRIllx")\n", + name, PRIllx_arg(modlist[i].paddr), + PRIllx_arg(modlist[i].size)); + BUG(); + } + return &modlist[i]; + } + } + + return NULL; +} + int main(void) { const struct bios_config *bios; int acpi_enabled; + const struct hvm_modlist_entry *bios_module; /* Initialise hypercall stubs with RET, rendering them no-ops. */ memset((void *)HYPERCALL_PHYSICAL_ADDRESS, 0xc3 /* RET */, PAGE_SIZE); @@ -293,8 +340,17 @@ int main(void) } printf("Loading %s ...\n", bios->name); - if ( bios->bios_load ) - bios->bios_load(bios); + bios_module = get_module_entry(hvm_start_info, "firmware"); + if ( bios_module && bios->bios_load ) + { + uint32_t paddr = bios_module->paddr; + + bios->bios_load(bios, (void*)paddr, bios_module->size); + } + else if ( bios->bios_load ) + { + bios->bios_load(bios, NULL, 0); + } else { BUG_ON(bios->bios_address + bios->image_size > diff --git a/tools/firmware/hvmloader/ovmf.c b/tools/firmware/hvmloader/ovmf.c index db9fa7a..858a2d4 100644 --- a/tools/firmware/hvmloader/ovmf.c +++ b/tools/firmware/hvmloader/ovmf.c @@ -93,7 +93,8 @@ static void ovmf_finish_bios_info(void) info->checksum = -checksum; } -static void ovmf_load(const struct bios_config *config) +static void ovmf_load(const struct bios_config *config, + void *bios_addr, uint32_t bios_length) { xen_pfn_t mfn; uint64_t addr = OVMF_BEGIN; diff --git a/tools/firmware/hvmloader/rombios.c b/tools/firmware/hvmloader/rombios.c index 1f15b94..2ded844 100644 --- a/tools/firmware/hvmloader/rombios.c +++ b/tools/firmware/hvmloader/rombios.c @@ -121,7 +121,8 @@ static void rombios_load_roms(void) option_rom_phys_addr + option_rom_sz - 1); } -static void rombios_load(const struct bios_config *config) +static void rombios_load(const struct bios_config *config, + void *unused_addr, uint32_t unused_size) { uint32_t bioshigh; struct rombios_info *info;