From patchwork Thu Jan 19 03:52:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Goldstein X-Patchwork-Id: 9525137 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 88EFB60437 for ; Thu, 19 Jan 2017 03:55:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66BDA2854A for ; Thu, 19 Jan 2017 03:55:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B89828648; Thu, 19 Jan 2017 03:55:17 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID 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 C33732854A for ; Thu, 19 Jan 2017 03:55:16 +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 1cU3mc-00056V-C1; Thu, 19 Jan 2017 03:53:06 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU3ma-00054x-Fv for xen-devel@lists.xen.org; Thu, 19 Jan 2017 03:53:04 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 06/E3-12836-F1830885; Thu, 19 Jan 2017 03:53:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRWlGSWpSXmKPExsVyMXThIV05i4Y Ig/6DJhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8abm1OZCmYZV1z/2c3cwHhTrYuRi0NIYAKj xM55l5lAHBaB/cwSN9bPYAFxJASWsUq0Xp3A3sXICeTESFz/do8Jwq6W2Hi8CcwWElCQ+D3hE BPEqJVMEl1TlrKBJNgENCSe/JoBZosISEtc+3yZEaSIWeAqk8TGGzfBuoUF/CRmvGplAbFZBF QlrmxYDtbAKxAnsX32REaIbfISC88fAavnFEiV6GvtY4HYnCKxccdtdlziExiFFjAyrGJUL04 tKkst0jXSSyrKTM8oyU3MzNE1NDDVy00tLk5MT81JTCrWS87P3cQIDEYGINjB+P2P0yFGSQ4m JVHec/oNEUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkePnMgXKCRanpqRVpmTnAuIBJS3DwKInws oGkeYsLEnOLM9MhUqcYjTl6uk6/ZOLYs+vySyYhlrz8vFQpcV4WkFIBkNKM0jy4QbB4vcQoKy XMywh0mhBPQWpRbmYJqvwrRnEORiVhXjeQKTyZeSVw+14BncIEdIqVcj3IKSWJCCmpBkb/B1N /Ny98O11y/4K9wgsYnyyq0Qjr15zC0iE9O6pI5Znog7Kaz/pm6y13hYk/bd+z/svmYJep8n1z 99acu7ZVxehn1oHA67/YbpfV2M2KeXQ02P17nbu65IX3ZstLG89VWMw2uzVZom9/5vkFe8sE6 pPuRPnIhsmrXqtc61bjVtAZ/jhuqbESS3FGoqEWc1FxIgCVzuA60gIAAA== X-Env-Sender: cardoe@cardoe.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1484797981!80498002!1 X-Originating-IP: [209.85.161.194] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30597 invoked from network); 19 Jan 2017 03:53:02 -0000 Received: from mail-yw0-f194.google.com (HELO mail-yw0-f194.google.com) (209.85.161.194) by server-7.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 19 Jan 2017 03:53:02 -0000 Received: by mail-yw0-f194.google.com with SMTP id 17so2863739ywk.2 for ; Wed, 18 Jan 2017 19:53:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cardoe.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=DtL8KaRzEN0zdOQRRwsP4D3fh+kjOirGxmli2/6wDPU=; b=S3jr5RVWr3Qr8ovWEgjjYTXG7k34rUaytg1mvg2SC6HBD+RNUvv2uz1AKjFziYsIJj CTcOTnfJutyo4tM/RIN6rkj6Jd6NLuRqPyoHHPL4pzqMX32ULUWgldJw1hBa1FESwjqZ eZPezSVFK3Q5QVTbbjDll21zrmD2nq4DCpbrc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=DtL8KaRzEN0zdOQRRwsP4D3fh+kjOirGxmli2/6wDPU=; b=OtPtyTHPyz6mqsiIufc13T0PyvYzCpM+ukvQWPo8omvoSy8ytQihATkyPH+pvG/nAG 2DdhkUr6pZlYdWQtfS5vIxQEavbRbKLdaztRp6QmHXYM1G3beM8M7AcVkIyqkmF139HC e0zfUBuZwDQtc/T0wYPmCpfBTs61vNIcGFIUjXzaJ3uYdVbGwYtIsg4v23UPgEpWlmym KtVsAcBq9aWflG2XHnAKwgPdyOUStjjSV8H3xMoKhjaP/EMagphe9wl39v6bPaEpV63i JNx2RwOGp+8UvopR2Ynjeah3aoNy90fRcLRVdOP4R9gHdiQfgc4eUfKF5QnxvcwalAnI VC1A== X-Gm-Message-State: AIkVDXKpr3fcWJp0pX5B/KENAF7kJ6GL7lfmLgq0n1BhNLpBH8b77OaHgOVGJe76xFB1lA== X-Received: by 10.129.57.134 with SMTP id g128mr5750143ywa.247.1484797981390; Wed, 18 Jan 2017 19:53:01 -0800 (PST) Received: from swanson.attlocal.net (104-179-196-18.lightspeed.brhmal.sbcglobal.net. [104.179.196.18]) by smtp.gmail.com with ESMTPSA id g133sm1203373ywe.19.2017.01.18.19.53.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 19:53:00 -0800 (PST) From: Doug Goldstein To: xen-devel@lists.xen.org Date: Wed, 18 Jan 2017 21:52:45 -0600 Message-Id: <3672c19ed736d17efec961b84988d169390da2b3.1484797961.git-series.cardoe@cardoe.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: References: In-Reply-To: References: Cc: jgross@suse.com, sstabellini@kernel.org, konrad.wilk@oracle.com, Andrew Cooper , daniel.kiper@oracle.com, Doug Goldstein , pgnet.dev@gmail.com, ning.sun@intel.com, julien.grall@arm.com, Jan Beulich , qiaowei.ren@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v5 5/5] fix: add multiboot2 protocol support for EFI platforms 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This should be squashed into the 4/4 patch 'x86: add multiboot2 protocol support for EFI platforms'. - fix incorrect assembly (identified by Andrew Cooper) - fix issue where the trampoline size was left as 0 and the way the memory is allocated for the trampolines we would go to the end of an available section and then subtract off the size to decide where to place it. The end result was that we would always copy the trampolines and the 32-bit stack into some form of reserved memory after the conventional region we wanted to put things into. On some systems this did not manifest as a crash while on others it did. Reworked the changes to always reserve 64kb for both the stack and the size of the trampolines. Added a build time assert to make sure we have enough room always. Signed-off-by: Doug Goldstein Reviewed-by: Jan Beulich --- Doug v5 - change comment style in xen.lds.S as requested by Jan Beulich. - fix comment around ExitBootServices() (suggested by Andrew Cooper) - change multiboot2 efi entry point name to __mb2_efi64_start (suggested by Andrew Cooper) Doug v4 - change wording around "stack base" (found by Jan Beulich) - added build time assert as suggested by Jan Beulich - added a KB() macro to make our sizes consistent with MB() and GB(). Doug v3 - drop ASSERTs since they are runtime only without any output. This should be completely mitigated by using max() and ensuring we have a sane value. (found by Jan Beulich) - removed extra_mem variable that was incorrectly left behind. (found by Jan Beulich) - fix comment around the "start of stack" (found by Jan Beulich) Doug v2 - new in this version to help show what's changed --- --- xen/arch/x86/boot/head.S | 7 ++++--- xen/arch/x86/efi/efi-boot.h | 8 ++++---- xen/arch/x86/efi/stub.c | 2 +- xen/arch/x86/xen.lds.S | 8 ++++++++ xen/include/xen/config.h | 1 + 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index ac93df0..f2e8cc9 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -89,12 +89,12 @@ multiboot2_header_start: 0, /* Number of the lines - no preference. */ \ 0 /* Number of bits per pixel - no preference. */ - /* Inhibit bootloader from calling ExitBootServices(). */ + /* Request that ExitBootServices() not be called. */ mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL) /* EFI64 entry point. */ mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \ - sym_phys(__efi64_start) + sym_phys(__mb2_efi64_start) /* Multiboot2 header end tag. */ mb2ht_init MB2_HT(END), MB2_HT(REQUIRED) @@ -169,7 +169,7 @@ not_multiboot: .code64 -__efi64_start: +__mb2_efi64_start: cld /* VGA is not available on EFI platforms. */ @@ -519,6 +519,7 @@ trampoline_setup: 1: /* Switch to low-memory stack. */ mov sym_phys(trampoline_phys),%edi + /* The stack ends 64kb after the location of trampoline_phys */ lea 0x10000(%edi),%esp lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax pushl $BOOT_CS32 diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index dc857d8..d2ebf21 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -146,8 +146,6 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable, { struct e820entry *e; unsigned int i; - /* Check for extra mem for mbi data if Xen is loaded via multiboot2 protocol. */ - UINTN extra_mem = efi_enabled(EFI_LOADER) ? 0 : (64 << 10); /* Populate E820 table and check trampoline area availability. */ e = e820map - 1; @@ -170,8 +168,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable, /* fall through */ case EfiConventionalMemory: if ( !trampoline_phys && desc->PhysicalStart + len <= 0x100000 && - len >= cfg.size + extra_mem && - desc->PhysicalStart + len > cfg.addr ) + len >= cfg.size && desc->PhysicalStart + len > cfg.addr ) cfg.addr = (desc->PhysicalStart + len - cfg.size) & PAGE_MASK; /* fall through */ case EfiLoaderCode: @@ -686,6 +683,9 @@ paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTa setup_efi_pci(); efi_variables(); + /* This is the maximum size of our trampoline + our low memory stack */ + cfg.size = KB(64); + if ( gop ) efi_set_gop_mode(gop, gop_mode); diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c index 6ea6aa1..b81adc0 100644 --- a/xen/arch/x86/efi/stub.c +++ b/xen/arch/x86/efi/stub.c @@ -33,7 +33,7 @@ paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, * not be directly supported by C compiler. */ asm volatile( - " call %2 \n" + " call *%2 \n" "0: hlt \n" " jmp 0b \n" : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString) diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index e0e2529..025760f 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -333,3 +333,11 @@ ASSERT(IS_ALIGNED(trampoline_start, 4), "trampoline_start misaligned") ASSERT(IS_ALIGNED(trampoline_end, 4), "trampoline_end misaligned") ASSERT(IS_ALIGNED(__bss_start, 8), "__bss_start misaligned") ASSERT(IS_ALIGNED(__bss_end, 8), "__bss_end misaligned") + +/* + * The trampolines and the low memory stack must fit in 64kb. In testing + * the low memory stack never exceeded 1kb so just require that the + * trampolines fit in 63kb, leaving 1kb for the stack. + */ +ASSERT((trampoline_end - trampoline_start) < KB(63), + "not enough room for trampolines and low memory stack") diff --git a/xen/include/xen/config.h b/xen/include/xen/config.h index 473c5e8..04e4da5 100644 --- a/xen/include/xen/config.h +++ b/xen/include/xen/config.h @@ -70,6 +70,7 @@ #define __force #define __bitwise +#define KB(_kb) (_AC(_kb, ULL) << 10) #define MB(_mb) (_AC(_mb, ULL) << 20) #define GB(_gb) (_AC(_gb, ULL) << 30)