From patchwork Thu Sep 18 22:49:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 37612 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E72602054E for ; Thu, 18 Sep 2014 22:52:17 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id d17sf119720eek.0 for ; Thu, 18 Sep 2014 15:52:17 -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=YI3Osg5Q0h+z5GgQSzsuYlgkAC4LOMoMl+UZ/uGYBHo=; b=Nq57BxWMIQw73GsiY4ssCbuYpKbgr+a3Qa1QupolkRv8tAvC7K+bRSF0dUuH3MRje2 DSoBbxgkSjMjoDXW5OcQrlIkCGmBtLpJ6Z+46tnduTd+W3FXD4PXRD65UY2lG+j22Uw1 WZmE7O+P6XE2XOsOe79Nq8xQmwL6NiSjxH4J4SzymqorSu/pFbCpvZpMOayPTR6CJGQD H6qBZQRprvUWdgOyuog9/KttpoLqBg/Ufs+GABDPzGjBDygwhay3+iUktXdRTMqhiNkW A8x5BVDaQ2Q7C0cycFztxYU5jYoE4zVq9AM9gybYBhzBsXG+pYtNV8T+IDKKaKa3Sj3b sFkA== X-Gm-Message-State: ALoCoQljb6d0jVZu4pAnJj9Ajw1TWhUqmp8dHzGcnM3tZqYgbHkZgjrF/b54Spj1skKs9R+u2SLg X-Received: by 10.180.198.172 with SMTP id jd12mr199796wic.6.1411080737107; Thu, 18 Sep 2014 15:52:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.200 with SMTP id le8ls170123lab.101.gmail; Thu, 18 Sep 2014 15:52:16 -0700 (PDT) X-Received: by 10.152.179.226 with SMTP id dj2mr2860343lac.40.1411080736912; Thu, 18 Sep 2014 15:52:16 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com [209.85.215.45]) by mx.google.com with ESMTPS id xw9si81634lbb.119.2014.09.18.15.52.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Sep 2014 15:52:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id b17so2100175lan.32 for ; Thu, 18 Sep 2014 15:52:16 -0700 (PDT) X-Received: by 10.152.246.6 with SMTP id xs6mr2817241lac.56.1411080736807; Thu, 18 Sep 2014 15:52:16 -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 of9csp843127lbb; Thu, 18 Sep 2014 15:52:16 -0700 (PDT) X-Received: by 10.52.246.198 with SMTP id xy6mr1464595vdc.7.1411080735281; Thu, 18 Sep 2014 15:52:15 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id dr6si57254vcb.67.2014.09.18.15.52.14 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 18 Sep 2014 15:52:15 -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 1XUkWw-0006Jm-6y; Thu, 18 Sep 2014 22:50:26 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XUkWu-0006J5-8Z for xen-devel@lists.xen.org; Thu, 18 Sep 2014 22:50:24 +0000 Received: from [193.109.254.147:17807] by server-16.bemta-14.messagelabs.com id 49/EB-16990-FA16B145; Thu, 18 Sep 2014 22:50:23 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-7.tower-27.messagelabs.com!1411080620!16435158!1 X-Originating-IP: [209.85.192.169] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21963 invoked from network); 18 Sep 2014 22:50:22 -0000 Received: from mail-pd0-f169.google.com (HELO mail-pd0-f169.google.com) (209.85.192.169) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 18 Sep 2014 22:50:22 -0000 Received: by mail-pd0-f169.google.com with SMTP id fp1so2328133pdb.28 for ; Thu, 18 Sep 2014 15:50:20 -0700 (PDT) X-Received: by 10.70.36.33 with SMTP id n1mr11830885pdj.26.1411080620018; Thu, 18 Sep 2014 15:50:20 -0700 (PDT) Received: from rfranz-t520.swisscom.com (70-35-38-154.static.wiline.com. [70.35.38.154]) by mx.google.com with ESMTPSA id ig4sm66332pbb.55.2014.09.18.15.50.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Sep 2014 15:50:19 -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: Thu, 18 Sep 2014 15:49:55 -0700 Message-Id: <1411080607-32365-5-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411080607-32365-1-git-send-email-roy.franz@linaro.org> References: <1411080607-32365-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org Subject: [Xen-devel] [PATCH V5 04/15] 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.215.45 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/common/efi/boot.c | 42 ++--------------------------------- xen/include/asm-x86/efi-boot.h | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 307740b..f4662b4 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -662,7 +662,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; UINT32 mmap_desc_ver = 0; UINTN mmap_size, mmap_desc_size, mmap_key = 0; @@ -1274,12 +1273,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_process_memory_map(SystemTable, mmap, mmap_size, mmap_desc_size, mmap_desc_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, mmap_key); if ( EFI_ERROR(status) ) @@ -1293,39 +1287,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 */ } diff --git a/xen/include/asm-x86/efi-boot.h b/xen/include/asm-x86/efi-boot.h index 8832b21..7aba173 100644 --- a/xen/include/asm-x86/efi-boot.h +++ b/xen/include/asm-x86/efi-boot.h @@ -209,3 +209,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 */ +}