From patchwork Mon Jul 21 12:59:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 33953 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 312C920492 for ; Mon, 21 Jul 2014 13:01:33 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id d1sf2491226wiv.3 for ; Mon, 21 Jul 2014 06:01:32 -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:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=CJfmd0482stFor+KeDb0UJtHpI8pLFUsO0bZQlmfcEs=; b=g5rpL4i2G622zVOYvELr2XpdLAyjWdXQbewHJTSUhxvqI2mowIbjxnUs0uog5gjMvl SIaTsZ/qYKCwjFSZ/1X1nsjxg5RZdFOTp6eT66fI2no06onEvIWLSJTOKnnez5jSjiuS nELpViPnKHGQMNRXmy4FF35K3/z8fYvnZlAfUi1hbvjupZWbSlJCUWy8fysOsL4dvszW +/56arfUL0pVlHFKYdzNLVIVDIlfQiFt3uxs7njXmgjS2McE/HOIErDzaZzsJXfxWAfJ X+BtxJ/3zuNVqg6c331Heolg6akicv2wG5ZiRT1E/uNjEtnAq/UdWLwC9MoUpVt0Fw/8 As+w== X-Gm-Message-State: ALoCoQkBb3hjGcO38riExnBJRP/tudHHDCc9cToeQmS23BL9KSmY0AxS5zeqjQHvGmJS8K0FgUQF X-Received: by 10.112.0.162 with SMTP id 2mr1936609lbf.3.1405947691786; Mon, 21 Jul 2014 06:01:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.226 with SMTP id r89ls1090229qgd.44.gmail; Mon, 21 Jul 2014 06:01:31 -0700 (PDT) X-Received: by 10.221.41.135 with SMTP id tu7mr1880722vcb.70.1405947691506; Mon, 21 Jul 2014 06:01:31 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id jp10si11238864vdb.9.2014.07.21.06.01.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 06:01:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so12190731vcb.3 for ; Mon, 21 Jul 2014 06:01:31 -0700 (PDT) X-Received: by 10.221.47.9 with SMTP id uq9mr11662246vcb.48.1405947691379; Mon, 21 Jul 2014 06:01:31 -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.221.37.5 with SMTP id tc5csp110206vcb; Mon, 21 Jul 2014 06:01:31 -0700 (PDT) X-Received: by 10.52.241.76 with SMTP id wg12mr24413848vdc.5.1405947690971; Mon, 21 Jul 2014 06:01:30 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id oc9si11239404vcb.105.2014.07.21.06.01.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 21 Jul 2014 06:01:29 -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 1X9DCN-0001Lf-C4; Mon, 21 Jul 2014 13:00:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X9DCL-0001Jd-8o for xen-devel@lists.xen.org; Mon, 21 Jul 2014 13:00:09 +0000 Received: from [85.158.137.68:44863] by server-13.bemta-3.messagelabs.com id 45/EA-09942-8DE0DC35; Mon, 21 Jul 2014 13:00:08 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1405947605!17110420!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29527 invoked from network); 21 Jul 2014 13:00:07 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 21 Jul 2014 13:00:07 -0000 X-IronPort-AV: E=Sophos;i="5.01,701,1400025600"; d="scan'208";a="154196109" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 21 Jul 2014 13:00:05 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Mon, 21 Jul 2014 09:00:04 -0400 Received: from drall.uk.xensource.com ([10.80.16.71]) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1X9DCF-0004Ob-D0; Mon, 21 Jul 2014 14:00:04 +0100 Received: by drall.uk.xensource.com (sSMTP sendmail emulation); Mon, 21 Jul 2014 14:00:03 +0100 From: Ian Campbell To: Date: Mon, 21 Jul 2014 13:59:58 +0100 Message-ID: <1405947600-26047-4-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1405947600-26047-1-git-send-email-ian.campbell@citrix.com> References: <1405947513.25022.59.camel@kazak.uk.xensource.com> <1405947600-26047-1-git-send-email-ian.campbell@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: julien.grall@linaro.org, tim@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH v3 4/6] xen: arm: avoid unnecessary additional mappings in boot page tables. 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: , 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: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 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: If the identity map is created at one level then avoid creating entries further down the boot page tables, since these will be aliases at strange virtual address. For example consider an arm32 system (for simplicity) with Xen loaded at address 0x40402000. As a virtual address this corresponds to walking offsets 1, 2 and 2 at the first, second and third levels respectively. When creating the identity map we will therefore create a 1GB super mapping at 0x40000000 for the identity map, which is the one we want to use. However when considering the second level we will see the offset 2 and create a 2MB mapping in slot 2 of boot_second. Since boot_second is mapped in slot 0 of boot_first this corresponds to an unwanted mapping from virtual address 0x00400000 to physical address 0x40400000. We still do not handle the case where the load address is within the 2MB range starting just after XEN_VIRT_START. This is not a regression but this patch tries to provide a more useful diagnostic message. We do handle loading at exactly XEN_VIRT_START. Signed-off-by: Ian Campbell Acked-by: Julien Grall --- v2: Expanded on commit message. Handle/accept being loaded at exactly 2M --- xen/arch/arm/arm32/head.S | 20 +++++++++++++++++--- xen/arch/arm/arm64/head.S | 19 ++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 9bc893f..afb4c6d 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -45,7 +45,7 @@ * r3 - * r4 - * r5 - - * r6 - + * r6 - identity map in place * r7 - CPUID * r8 - DTB address (boot CPU only) * r9 - paddr(start) @@ -250,6 +250,14 @@ cpu_init_done: * mapping. So each CPU must rebuild the page tables here with * the 1:1 in place. */ + /* If Xen is loaded at exactly XEN_VIRT_START then we don't + * need an additional 1:1 mapping, the virtual mapping will + * suffice. + */ + cmp r9, #XEN_VIRT_START + moveq r6, #1 /* r6 := identity map now in place */ + movne r6, #0 /* r6 := identity map not yet in place */ + /* Write Xen's PT's paddr into the HTTBR */ ldr r4, =boot_pgtable add r4, r4, r10 /* r4 := paddr (boot_pagetable) */ @@ -275,6 +283,7 @@ cpu_init_done: orr r2, r2, #PT_LOWER(MEM) lsl r1, r1, #3 /* r1 := Slot offset */ strd r2, r3, [r4, r1] /* Mapping of paddr(start) */ + mov r6, #1 /* r6 := identity map now in place */ 1: /* Setup boot_second: */ ldr r4, =boot_second @@ -290,6 +299,8 @@ cpu_init_done: strd r2, r3, [r4, #8] /* Map it in slot 1 */ /* ... map of paddr(start) in boot_second */ + cmp r6, #1 /* r6 is set if already created */ + beq 1f lsr r2, r9, #SECOND_SHIFT /* Offset of base paddr in boot_second */ ldr r3, =LPAE_ENTRY_MASK and r1, r2, r3 @@ -302,6 +313,7 @@ cpu_init_done: mov r3, #0x0 lsl r1, r1, #3 /* r1 := Slot offset */ strd r2, r3, [r4, r1] /* Mapping of paddr(start) */ + mov r6, #1 /* r6 := identity map now in place */ /* Setup boot_third: */ 1: ldr r4, =boot_third @@ -326,8 +338,10 @@ cpu_init_done: /* boot pagetable setup complete */ - b 1f - + cmp r6, #1 /* Did we manage to create an identity mapping ? */ + beq 1f + PRINT("Unable to build boot page tables - Failed to identity map Xen.\r\n") + b fail virtphys_clash: /* Identity map clashes with boot_third, which we cannot handle yet */ PRINT("Unable to build boot page tables - virt and phys addresses clash.\r\n") diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 2412fe8..4e22374 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -62,7 +62,7 @@ * x22 - is_secondary_cpu * x23 - UART address * x24 - cpuid - * x25 - + * x25 - identity map in place * x26 - * x27 - * x28 - @@ -253,6 +253,13 @@ skip_bss: * mapping. So each CPU must rebuild the page tables here with * the 1:1 in place. */ + /* If Xen is loaded at exactly XEN_VIRT_START then we don't + * need an additional 1:1 mapping, the virtual mapping will + * suffice. + */ + cmp x19, #XEN_VIRT_START + cset x25, eq /* x25 := identity map in place, or not */ + /* Write Xen's PT's paddr into TTBR0_EL2 */ ldr x4, =boot_pgtable add x4, x4, x20 /* x4 := paddr (boot_pagetable) */ @@ -293,6 +300,7 @@ skip_bss: and x1, x1, #LPAE_ENTRY_MASK /* x1 := Slot offset */ lsl x1, x1, #3 str x2, [x4, x1] /* Mapping of paddr(start) */ + mov x25, #1 /* x25 := identity map now in place */ 1: /* Setup boot_first: */ ldr x4, =boot_first /* Next level into boot_first */ @@ -306,6 +314,7 @@ skip_bss: str x2, [x4, #0] /* Map it in slot 0 */ /* ... map of paddr(start) in boot_first */ + cbnz x25, 1f /* x25 is set if already created */ lsr x2, x19, #FIRST_SHIFT /* x2 := Offset of base paddr in boot_first */ and x1, x2, #LPAE_ENTRY_MASK /* x1 := Slot to use */ cbz x1, 1f /* It's in slot 0, map in boot_second */ @@ -315,6 +324,7 @@ skip_bss: orr x2, x2, x3 lsl x1, x1, #3 /* x1 := Slot offset */ str x2, [x4, x1] /* Create mapping of paddr(start)*/ + mov x25, #1 /* x25 := identity map now in place */ 1: /* Setup boot_second: */ ldr x4, =boot_second /* Next level into boot_second */ @@ -328,6 +338,7 @@ skip_bss: str x2, [x4, #8] /* Map it in slot 1 */ /* ... map of paddr(start) in boot_second */ + cbnz x25, 1f /* x25 is set if already created */ lsr x2, x19, #SECOND_SHIFT /* x2 := Offset of base paddr in boot_second */ and x1, x2, #LPAE_ENTRY_MASK /* x1 := Slot to use */ cmp x1, #1 @@ -338,6 +349,7 @@ skip_bss: orr x2, x2, x3 lsl x1, x1, #3 /* x1 := Slot offset */ str x2, [x4, x1] /* Create mapping of paddr(start)*/ + mov x25, #1 /* x25 := identity map now in place */ 1: /* Setup boot_third: */ ldr x4, =boot_third @@ -361,8 +373,9 @@ skip_bss: /* boot pagetable setup complete */ - b 1f - + cbnz x25, 1f /* Did we manage to create an identity mapping ? */ + PRINT("Unable to build boot page tables - Failed to identity map Xen.\r\n") + b fail virtphys_clash: /* Identity map clashes with boot_third, which we cannot handle yet */ PRINT("Unable to build boot page tables - virt and phys addresses clash.\r\n")