From patchwork Thu Sep 25 01:42:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 37879 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f198.google.com (mail-we0-f198.google.com [74.125.82.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 88AC920063 for ; Thu, 25 Sep 2014 01:44:49 +0000 (UTC) Received: by mail-we0-f198.google.com with SMTP id t60sf4110898wes.1 for ; Wed, 24 Sep 2014 18:44:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=4ESu1oUpJdPxkEZQ36KAkR7PgxonuN/DaG9QG+Jb+zA=; b=lR6rKu4nNsC6CkbLALIL9CDBVudfaLRBtHs1TmAhwU525riAsplDvfIn88NAymgRJr V1ZafOzui+ZKGjUb9k+bVRo6p/rYwIuDg7VpPAOFv6t1ZLKK2PBjyur0VB/LnAM4GM6l EVXY+n0xAuSQKx7Js/3nwTZf9tOWAYa7pfXKwH+7SB/Ijnzmgl/QqFdENw/LI17WxLCQ AJOfpRmHaJ3gXoYtNaF1IznyB8GmxMS6ZvV+Z8CEeaMyYqYswyd5H6HsBN2Phd/LyFBd x8sJOFQkQxUXlDGQw99SeUIHc0chABR/aQmIvAwc+1eGDIoc21RHUY6KW04lCPp04DGO TVgQ== X-Gm-Message-State: ALoCoQk6OA6IHK2b+DDtRtgaGOJnoW/eN+N8FzaZmZgYEJ0TInPl/TFuhCUEf1NBnYW8YosO1xH5 X-Received: by 10.112.145.136 with SMTP id su8mr1113604lbb.9.1411609488749; Wed, 24 Sep 2014 18:44:48 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.97 with SMTP id u1ls187391lae.105.gmail; Wed, 24 Sep 2014 18:44:48 -0700 (PDT) X-Received: by 10.112.198.74 with SMTP id ja10mr9548671lbc.14.1411609488608; Wed, 24 Sep 2014 18:44:48 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by mx.google.com with ESMTPS id ba4si993828lab.45.2014.09.24.18.44.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 24 Sep 2014 18:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id w7so6933564lbi.35 for ; Wed, 24 Sep 2014 18:44:48 -0700 (PDT) X-Received: by 10.112.44.129 with SMTP id e1mr9498786lbm.78.1411609488538; Wed, 24 Sep 2014 18:44:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp678224lbb; Wed, 24 Sep 2014 18:44:47 -0700 (PDT) X-Received: by 10.140.34.42 with SMTP id k39mr13792017qgk.100.1411609487279; Wed, 24 Sep 2014 18:44:47 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id z9si1090721qcn.9.2014.09.24.18.44.46 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 24 Sep 2014 18:44:47 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XWy57-0000xf-1w; Thu, 25 Sep 2014 01:42:53 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XWy56-0000wR-6u for xen-devel@lists.xen.org; Thu, 25 Sep 2014 01:42:52 +0000 Received: from [85.158.139.211:43561] by server-10.bemta-5.messagelabs.com id 3D/E0-19806-B1373245; Thu, 25 Sep 2014 01:42:51 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-11.tower-206.messagelabs.com!1411609369!7767403!1 X-Originating-IP: [209.85.213.170] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15667 invoked from network); 25 Sep 2014 01:42:50 -0000 Received: from mail-ig0-f170.google.com (HELO mail-ig0-f170.google.com) (209.85.213.170) by server-11.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 25 Sep 2014 01:42:50 -0000 Received: by mail-ig0-f170.google.com with SMTP id a13so7857676igq.1 for ; Wed, 24 Sep 2014 18:42:49 -0700 (PDT) X-Received: by 10.42.92.129 with SMTP id t1mr14949399icm.59.1411609369018; Wed, 24 Sep 2014 18:42:49 -0700 (PDT) Received: from rfranz-v430.caveonetworks.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id x9sm5829238igl.10.2014.09.24.18.42.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Sep 2014 18:42:48 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com, keir@xen.org Date: Wed, 24 Sep 2014 18:42:23 -0700 Message-Id: <1411609352-24549-6-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411609352-24549-1-git-send-email-roy.franz@linaro.org> References: <1411609352-24549-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org Subject: [Xen-devel] [PATCH for-4.5 V7 05/14] Add architecture functions for pre/post ExitBootServices X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: The UEFI ExitBootServices function is invoked to transition the system to the 'runtime' mode of operation, and is done right before transitioning from the EFI loader code into Xen proper. x86 does some arch specific memory management (trampoline) before exit boot services, and the code that transitions from the EFI application state to Xen is architecture specific. This patch adds two functions, one pre and one post ExitBootServices to allow each architecture to to handle these cases in a customized manner. Signed-off-by: Roy Franz Acked-by: Jan Beulich --- xen/arch/x86/efi/efi-boot.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 42 ++----------------------------------- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 80b8dfe..254783f 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -198,3 +198,53 @@ static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size) return NULL; return (void *)(long)mbi.mem_upper; } + +static void __init efi_arch_pre_exit_boot(void) +{ + if ( !trampoline_phys ) + { + if ( !cfg.addr ) + blexit(L"No memory for trampoline"); + relocate_trampoline(cfg.addr); + } +} + +static void __init noreturn efi_arch_post_exit_boot(void) +{ + u64 efer; + + efi_arch_relocate_image(__XEN_VIRT_START - xen_phys_start); + memcpy((void *)trampoline_phys, trampoline_start, cfg.size); + + /* Set system registers and transfer control. */ + asm volatile("pushq $0\n\tpopfq"); + rdmsrl(MSR_EFER, efer); + efer |= EFER_SCE; + if ( cpuid_ext_features & (1 << (X86_FEATURE_NX & 0x1f)) ) + efer |= EFER_NX; + wrmsrl(MSR_EFER, efer); + write_cr0(X86_CR0_PE | X86_CR0_MP | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | + X86_CR0_AM | X86_CR0_PG); + asm volatile ( "mov %[cr4], %%cr4\n\t" + "mov %[cr3], %%cr3\n\t" + "movabs $__start_xen, %[rip]\n\t" + "lgdt gdt_descr(%%rip)\n\t" + "mov stack_start(%%rip), %%rsp\n\t" + "mov %[ds], %%ss\n\t" + "mov %[ds], %%ds\n\t" + "mov %[ds], %%es\n\t" + "mov %[ds], %%fs\n\t" + "mov %[ds], %%gs\n\t" + "movl %[cs], 8(%%rsp)\n\t" + "mov %[rip], (%%rsp)\n\t" + "lretq %[stkoff]-16" + : [rip] "=&r" (efer/* any dead 64-bit variable */) + : [cr3] "r" (idle_pg_table), + [cr4] "r" (mmu_cr4_features), + [cs] "ir" (__HYPERVISOR_CS), + [ds] "r" (__HYPERVISOR_DS), + [stkoff] "i" (STACK_SIZE - sizeof(struct cpu_info)), + "D" (&mbi) + : "memory" ); + for( ; ; ); /* not reached */ +} diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 6c7caac..0eee250 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -668,7 +668,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info; EFI_FILE_HANDLE dir_handle; union string section = { NULL }, name; - u64 efer; bool_t base_video = 0; efi_ih = ImageHandle; @@ -1277,12 +1276,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size, efi_mdesc_size, mdesc_ver); - if ( !trampoline_phys ) - { - if ( !cfg.addr ) - blexit(L"No memory for trampoline"); - relocate_trampoline(cfg.addr); - } + efi_arch_pre_exit_boot(); status = efi_bs->ExitBootServices(ImageHandle, map_key); if ( EFI_ERROR(status) ) @@ -1296,39 +1290,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START; efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START; - efi_arch_relocate_image(__XEN_VIRT_START - xen_phys_start); - memcpy((void *)trampoline_phys, trampoline_start, cfg.size); - - /* Set system registers and transfer control. */ - asm volatile("pushq $0\n\tpopfq"); - rdmsrl(MSR_EFER, efer); - efer |= EFER_SCE; - if ( cpuid_ext_features & (1 << (X86_FEATURE_NX & 0x1f)) ) - efer |= EFER_NX; - wrmsrl(MSR_EFER, efer); - write_cr0(X86_CR0_PE | X86_CR0_MP | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | - X86_CR0_AM | X86_CR0_PG); - asm volatile ( "mov %[cr4], %%cr4\n\t" - "mov %[cr3], %%cr3\n\t" - "movabs $__start_xen, %[rip]\n\t" - "lgdt gdt_descr(%%rip)\n\t" - "mov stack_start(%%rip), %%rsp\n\t" - "mov %[ds], %%ss\n\t" - "mov %[ds], %%ds\n\t" - "mov %[ds], %%es\n\t" - "mov %[ds], %%fs\n\t" - "mov %[ds], %%gs\n\t" - "movl %[cs], 8(%%rsp)\n\t" - "mov %[rip], (%%rsp)\n\t" - "lretq %[stkoff]-16" - : [rip] "=&r" (efer/* any dead 64-bit variable */) - : [cr3] "r" (idle_pg_table), - [cr4] "r" (mmu_cr4_features), - [cs] "ir" (__HYPERVISOR_CS), - [ds] "r" (__HYPERVISOR_DS), - [stkoff] "i" (STACK_SIZE - sizeof(struct cpu_info)), - "D" (&mbi) - : "memory" ); + efi_arch_post_exit_boot(); for( ; ; ); /* not reached */ }