From patchwork Mon Aug 12 17:29:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171100 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120175ily; Mon, 12 Aug 2019 10:31:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5IngPyvQMyVQQjpsJCAI6w3aK7/KF2CwO6U75pc2AiXvG2RarzsbmBLULt5/TQNQ7EMJq X-Received: by 2002:a6b:8b47:: with SMTP id n68mr23172903iod.191.1565631105088; Mon, 12 Aug 2019 10:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631105; cv=none; d=google.com; s=arc-20160816; b=x872RnCn5C1ZywPDxgLaDsOK2UOPO0X3ehFeUKx1lOyL6i1AbgMFBXvml8mNYxlJBb ifCsu069NchlTJcg4JLtWGjgATGpU8fzQxT15D2kS28vrtXlUV2eri2dXS2O6L80Wf9O OHfMuX5J765GrwFmDysd39iQ9zY0yqTVIhsKG1KJExvardfwYHoI4DnGVRbiPC0FFATY Ln3jN87bQWJsLdLydIdwWrdT1v92Si97l25PzK2G9T116I2GhyUAlhayQrii4otFlzyL RGmfzqX5LsE4DhAPOLM+FkOWyCwNJplUqf1yKZ7h5pgIjVZM+d89X5qoRjF/I9bTMwpq EmEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=Co+eZ6+IVrxeUjZFgkwQfgun+0luZ97DKl/KFIOq9Hc=; b=N2E1VsjFxqxOxwSwMHc20Scex4ywkfNh5Lnpt+YAJZLUSyBTaTvNHmfmyXrD6EQMxa WVTNAKO8QZkcNby4/Qb9O+JofwUZ4lOOyKfGWE7dMcTTwv/Lsb6am+IlQuV/HKi+l0Sf mx4BApzkLKqe6wom2R+ca59+XB6WOzoRAyIzbfMVEifJUUp84bmOQeIWBdVl4+4Yx5gO 5d+1jE72w/PK/uy7Xe/tXcaQ3sbXKv0huyWSqRJ5m7oF6qngL9IaJy/Eo2vUHq335+aO px4DNnGWe32NQsoUMjY7MamBA4qkKC3ezNNxzNEdH8awZYnlK6pvFzvdhCG+JWnWTOxM Ea9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id z26si10742625ioe.90.2019.08.12.10.31.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9O-0006gC-Q6; Mon, 12 Aug 2019 17:30:30 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9N-0006g2-00 for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:29 +0000 X-Inumbo-ID: e065d761-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id e065d761-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:28 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D2FC1715; Mon, 12 Aug 2019 10:30:28 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7B5BE3F706; Mon, 12 Aug 2019 10:30:27 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:52 +0100 Message-Id: <20190812173019.11956-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 01/28] xen/arm: lpae: Allow more LPAE helpers to be used in assembly X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" A follow-up patch will require to use *_table_offset() and *_MASK helpers from assembly. This can be achieved by using _AT() macro to remove the type when called from assembly. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Patch added --- xen/include/asm-arm/lpae.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index c22780f8f3..4797f9cee4 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -245,19 +245,19 @@ TABLE_OFFSET_HELPERS(64); #define THIRD_SHIFT (PAGE_SHIFT) #define THIRD_ORDER (THIRD_SHIFT - PAGE_SHIFT) -#define THIRD_SIZE ((paddr_t)1 << THIRD_SHIFT) +#define THIRD_SIZE (_AT(paddr_t, 1) << THIRD_SHIFT) #define THIRD_MASK (~(THIRD_SIZE - 1)) #define SECOND_SHIFT (THIRD_SHIFT + LPAE_SHIFT) #define SECOND_ORDER (SECOND_SHIFT - PAGE_SHIFT) -#define SECOND_SIZE ((paddr_t)1 << SECOND_SHIFT) +#define SECOND_SIZE (_AT(paddr_t, 1) << SECOND_SHIFT) #define SECOND_MASK (~(SECOND_SIZE - 1)) #define FIRST_SHIFT (SECOND_SHIFT + LPAE_SHIFT) #define FIRST_ORDER (FIRST_SHIFT - PAGE_SHIFT) -#define FIRST_SIZE ((paddr_t)1 << FIRST_SHIFT) +#define FIRST_SIZE (_AT(paddr_t, 1) << FIRST_SHIFT) #define FIRST_MASK (~(FIRST_SIZE - 1)) #define ZEROETH_SHIFT (FIRST_SHIFT + LPAE_SHIFT) #define ZEROETH_ORDER (ZEROETH_SHIFT - PAGE_SHIFT) -#define ZEROETH_SIZE ((paddr_t)1 << ZEROETH_SHIFT) +#define ZEROETH_SIZE (_AT(paddr_t, 1) << ZEROETH_SHIFT) #define ZEROETH_MASK (~(ZEROETH_SIZE - 1)) /* Calculate the offsets into the pagetables for a given VA */ @@ -266,7 +266,7 @@ TABLE_OFFSET_HELPERS(64); #define second_linear_offset(va) ((va) >> SECOND_SHIFT) #define third_linear_offset(va) ((va) >> THIRD_SHIFT) -#define TABLE_OFFSET(offs) ((unsigned int)(offs) & LPAE_ENTRY_MASK) +#define TABLE_OFFSET(offs) (_AT(unsigned int, offs) & LPAE_ENTRY_MASK) #define first_table_offset(va) TABLE_OFFSET(first_linear_offset(va)) #define second_table_offset(va) TABLE_OFFSET(second_linear_offset(va)) #define third_table_offset(va) TABLE_OFFSET(third_linear_offset(va)) From patchwork Mon Aug 12 17:29:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171108 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120222ily; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWFaI+r5aIGh/jxDWNSEdmeiU0gbQ6DUXH8uCcu4Dy7oX0JBjERQUEV9ZcAtYi3906WbS3 X-Received: by 2002:a02:a595:: with SMTP id b21mr39195853jam.28.1565631106620; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631106; cv=none; d=google.com; s=arc-20160816; b=a0NvyRgN6ucnD8Ss5he63eA4reqTKEKyRkCbpcg8meyqLh8dQHB3QCsDDS57bM4Z5/ loVxU9AuMCQebx9S3VhChGwx5/39pUUAd9+fMV2idFGXDggnvqfyx0uRZKWlHMsPm2xb H3RgHQzcPmTTKMqCbi3K2hP5EzvV4ntCRM4QtKwrR6e0vPQM1s0ZBjOS4VTZ50XOU0NR 5T+4sMnRNpZgMazHIpCmdf1+UAvRC2KnPlTQvhQzPo2A+xMZrTbN3kFf2xHeU+G+Fg4H VSefnH/TN0WVXN9JVML914iZdJkOIbkvGSZqpCN3T6rAm+zkupHgulULAukkWIgkwm7W gNXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=W7UhYk79bdW97AZoE67zrxcovVSjbeoJvYykZznlss0=; b=KT23dqavvaW9Y3mLFCDPYnQLgI3rrZ3TbH+PAAOsHbo4tIkWMIRWUyPQpNuSG4iFP4 m7Ld3CvL8GOUhYjOXXdQied50B2mJcti0wWfP4p37CMqaStao+vhk5DgdnmE5ZvnbxYJ RpE4d3r52D6IoUY3KgGlQVFlyDDb46jX1WIZJufI0jmC1y/8pL0cSQ0xuFf0IU6WEt/q JwyMyZ2iUDat3umBit9aK8EshAQeSnkAeFi3ztPm4eToRfvGAA8ncwGIoNZpy625ihqP ssPoRVXxSju+tqgaTiFwyExjz7UbOHjZHBxu4gh0vmqjCXJ9ekttCnXwklobY6mvH9Fm ybOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id m5si14326742ioq.134.2019.08.12.10.31.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9R-0006gX-B9; Mon, 12 Aug 2019 17:30:33 +0000 Received: from [172.99.69.81] (helo=us1-rack-iad1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9Q-0006gO-LZ for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:32 +0000 X-Inumbo-ID: e0f4eee4-bd26-11e9-b94c-33c0d2efa14c Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id e0f4eee4-bd26-11e9-b94c-33c0d2efa14c; Mon, 12 Aug 2019 17:30:29 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 138CA174E; Mon, 12 Aug 2019 10:30:29 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 61EA93F706; Mon, 12 Aug 2019 10:30:28 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:53 +0100 Message-Id: <20190812173019.11956-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 02/28] xen/arm64: head: Remove 1:1 mapping as soon as it is not used X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The 1:1 mapping may clash with other parts of the Xen virtual memory layout. At the moment, Xen is handling the clash by only creating a mapping to the runtime virtual address before enabling the MMU. The rest of the mappings (such as the fixmap) will be mapped after the MMU is enabled. However, the code doing the mapping is not safe as it replace mapping without using the Break-Before-Make sequence. As the 1:1 mapping can be anywhere in the memory, it is easier to remove all the entries added as soon as the 1:1 mapping is not used rather than adding the Break-Before-Make sequence everywhere. It is difficult to track where exactly the 1:1 mapping was created without a full rework of create_page_tables(). Instead, introduce a new function remove_identity_mapping() will look where is the top-level entry for the 1:1 mapping and remove it. The new function is only called for the boot CPU. Secondary CPUs will switch directly to the runtime page-tables so there are no need to remove the 1:1 mapping. Note that this still doesn't make the Secondary CPUs path safe but it is not making it worst. Signed-off-by: Julien Grall --- It is very likely we will need to re-introduce the 1:1 mapping to cater secondary CPUs boot and suspend/resume. For now, the attempt is to make boot CPU path fully Arm Arm compliant. Changes in v3: - Avoid hardcoding slots Changes in v2: - s/ID map/1:1 mapping/ - Rename remove_id_map() to remove_identity_mapping() - Add missing signed-off-by --- xen/arch/arm/arm64/head.S | 94 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 50cff08756..ec138aae3e 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -33,6 +33,11 @@ #define PT_DEV 0xe71 /* nG=1 AF=1 SH=10 AP=01 NS=1 ATTR=100 T=0 P=1 */ #define PT_DEV_L3 0xe73 /* nG=1 AF=1 SH=10 AP=01 NS=1 ATTR=100 T=1 P=1 */ +/* Convenience defines to get slot used by Xen mapping. */ +#define XEN_ZEROETH_SLOT zeroeth_table_offset(XEN_VIRT_START) +#define XEN_FIRST_SLOT first_table_offset(XEN_VIRT_START) +#define XEN_SECOND_SLOT second_table_offset(XEN_VIRT_START) + #define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2) #define __HEAD_FLAG_PHYS_BASE 1 @@ -301,6 +306,13 @@ real_start_efi: ldr x0, =primary_switched br x0 primary_switched: + /* + * The 1:1 map may clash with other parts of the Xen virtual memory + * layout. As it is not used anymore, remove it completely to + * avoid having to worry about replacing existing mapping + * afterwards. + */ + bl remove_identity_mapping bl setup_fixmap #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ @@ -626,10 +638,71 @@ enable_mmu: ret ENDPROC(enable_mmu) +/* + * Remove the 1:1 map for the page-tables. It is not easy to keep track + * where the 1:1 map was mapped, so we will look for the top-level entry + * exclusive to the 1:1 map and remove it. + * + * Inputs: + * x19: paddr(start) + * + * Clobbers x0 - x1 + */ +remove_identity_mapping: + /* + * Find the zeroeth slot used. Remove the entry from zeroeth + * table if the slot is not XEN_ZEROETH_SLOT. For slot + * XEN_ZEROETH_SLOT, the 1:1 mapping was either done in first + * or second table. + */ + lsr x1, x19, #ZEROETH_SHIFT /* x1 := zeroeth slot */ + cmp x1, #XEN_ZEROETH_SLOT + beq 1f + /* It is not in slot XEN_ZEROETH_SLOT, remove the entry. */ + ldr x0, =boot_pgtable /* x0 := root table */ + str xzr, [x0, x1, lsl #3] + b identity_mapping_removed + +1: + /* + * Find the first slot used. Remove the entry for the first + * table if the slot is not XEN_FIRST_SLOT. For slot XEN_FIRST_SLOT, + * the 1:1 mapping was done in the second table. + */ + lsr x1, x19, #FIRST_SHIFT + and x1, x1, #LPAE_ENTRY_MASK /* x1 := first slot */ + cmp x1, #XEN_FIRST_SLOT + beq 1f + /* It is not in slot XEN_FIRST_SLOT, remove the entry. */ + ldr x0, =boot_first /* x0 := first table */ + str xzr, [x0, x1, lsl #3] + b identity_mapping_removed + +1: + /* + * Find the second slot used. Remove the entry for the first + * table if the slot is not XEN_SECOND_SLOT. For slot XEN_SECOND_SLOT, + * it means the 1:1 mapping was not created. + */ + lsr x1, x19, #SECOND_SHIFT + and x1, x1, #LPAE_ENTRY_MASK /* x1 := first slot */ + cmp x1, #XEN_SECOND_SLOT + beq identity_mapping_removed + /* It is not in slot 1, remove the entry */ + ldr x0, =boot_second /* x0 := second table */ + str xzr, [x0, x1, lsl #3] + +identity_mapping_removed: + /* See asm-arm/arm64/flushtlb.h for the explanation of the sequence. */ + dsb nshst + tlbi alle2 + dsb nsh + isb + + ret +ENDPROC(remove_identity_mapping) + setup_fixmap: - /* Now we can install the fixmap and dtb mappings, since we - * don't need the 1:1 map any more */ - dsb sy #if defined(CONFIG_EARLY_PRINTK) /* Fixmap is only used by early printk */ /* Add UART to the fixmap table */ ldr x1, =xen_fixmap /* x1 := vaddr (xen_fixmap) */ @@ -647,19 +720,10 @@ setup_fixmap: ldr x1, =FIXMAP_ADDR(0) lsr x1, x1, #(SECOND_SHIFT - 3) /* x1 := Slot for FIXMAP(0) */ str x2, [x4, x1] /* Map it in the fixmap's slot */ -#endif - /* - * Flush the TLB in case the 1:1 mapping happens to clash with - * the virtual addresses used by the fixmap or DTB. - */ - dsb sy /* Ensure any page table updates made above - * have occurred. */ - - isb - tlbi alle2 - dsb sy /* Ensure completion of TLB flush */ - isb + /* Ensure any page table updates made above have occurred. */ + dsb nshst +#endif ret ENDPROC(setup_fixmap) From patchwork Mon Aug 12 17:29:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171153 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp511537ily; Mon, 12 Aug 2019 23:54:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFi8YDBhHadZ+iwmvY+9SZLXRjzjoWByvQTDU0zUObTzJePWkVSamExhQMk+yd553UhEL9 X-Received: by 2002:a5e:da48:: with SMTP id o8mr26535382iop.252.1565679269366; Mon, 12 Aug 2019 23:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565679269; cv=none; d=google.com; s=arc-20160816; b=XfTOMdUAe66q9dn3oRon0djjFeBnxuPSt00D2wJCoQ2orgMPleH5B9wUSIuXTi3+Fc QhbE3unXR4NsZk18XpGDlb8SgH26Wg8gJx6WQR7ecazTLHuTtCXdRQxG5zaumDgAwT8r plxTfHIPRts35XzdqgZo6EFZpwyuEF+ZJaWjxQ9X/Ac6jRkaW6eq+A+vT1JrxhRd0hl7 aGk7GQk9u4aykmyBeLbYOS00IDeLKgYAnZ2nJY+iVDGFGA+qyATufeQCnyCKfpthxTHj dtwhZJwQOCZNwBa89ZbE0l549myFnrCywDFfQOYEGBl3qluAw/17M0DFdQ/EK3KW3vhM p8Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=NnEO8pGjdWBgR6+OU6qvQov8sBT+IABu4d12Ujs2vBg=; b=C3GVCHt1MGVMpe2wKDbVh2FbsVYg6G3ZP9KuKsLxMzS35//CAH1EI3Yo8+KZRdPU2I F5lbwn99jQfwBm9SsRVE9EYkoChpDHOKk5/0KBP/Y02ZqZHIfAoJW7l3oLEI0IuHZGmh pon9/TfgntNn2zOkDnjWUr3dJmqsoEziVU0mdQViZwRaUPxGS6qRixm6l24LAsWOVa5V sKBTyk2jMK1fq6dkbrAt2Dgc76vpF25QmafrPh6WzkbPk7014Id9q411kpnn7/e3ztT/ 8xXvaKt1iV7Zcwqi0j6puxHqt4ZgCjVaTLT47S4yDMxU79cIUUS3L4Le/AnhfUx7Fg1U /uVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x14si23150822jao.84.2019.08.12.23.54.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:54:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQgl-0002Cg-H3; Tue, 13 Aug 2019 06:53:47 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQgk-0002CC-Ll for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:53:46 +0000 X-Inumbo-ID: e19da1ba-bd26-11e9-a064-c7d14abe968e Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e19da1ba-bd26-11e9-a064-c7d14abe968e; Mon, 12 Aug 2019 17:30:30 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EEF6D1993; Mon, 12 Aug 2019 10:30:29 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 487E93F706; Mon, 12 Aug 2019 10:30:29 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:54 +0100 Message-Id: <20190812173019.11956-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 03/28] xen/arm64: head: Rework and document setup_fixmap() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, the fixmap table is only hooked when earlyprintk is used. This is fine today because in C land, the fixmap is not used by anyone until the the boot CPU is switching to the runtime page-tables. In the future, the boot CPU will not switch between page-tables to avoid TLB incoherency. Thus, the fixmap table will need to be always hooked before any use. Let's start doing it now in setup_fixmap(). Lastly, document the behavior and the main registers usage within the function. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Fix typo in the commit message - Add Stefano's Acked-by Changes in v2: - Update the comment to reflect that we clobbers x1 - x4 and not x0 - x1. - Add the list of input registers - s/ID map/1:1 mapping/ - Reword the commit message --- xen/arch/arm/arm64/head.S | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index ec138aae3e..7b6b820726 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -702,8 +702,21 @@ identity_mapping_removed: ret ENDPROC(remove_identity_mapping) +/* + * Map the UART in the fixmap (when earlyprintk is used) and hook the + * fixmap table in the page tables. + * + * The fixmap cannot be mapped in create_page_tables because it may + * clash with the 1:1 mapping. + * + * Inputs: + * x20: Physical offset + * x23: Early UART base physical address + * + * Clobbers x1 - x4 + */ setup_fixmap: -#if defined(CONFIG_EARLY_PRINTK) /* Fixmap is only used by early printk */ +#ifdef CONFIG_EARLY_PRINTK /* Add UART to the fixmap table */ ldr x1, =xen_fixmap /* x1 := vaddr (xen_fixmap) */ lsr x2, x23, #THIRD_SHIFT @@ -711,6 +724,7 @@ setup_fixmap: mov x3, #PT_DEV_L3 orr x2, x2, x3 /* x2 := 4K dev map including UART */ str x2, [x1, #(FIXMAP_CONSOLE*8)] /* Map it in the first fixmap's slot */ +#endif /* Map fixmap into boot_second */ ldr x4, =boot_second /* x4 := vaddr (boot_second) */ @@ -723,7 +737,7 @@ setup_fixmap: /* Ensure any page table updates made above have occurred. */ dsb nshst -#endif + ret ENDPROC(setup_fixmap) From patchwork Mon Aug 12 17:29:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171111 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120248ily; Mon, 12 Aug 2019 10:31:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwy9n0kR+PdNEj8vUHgGtgHNJ7qDeEj306vEHW0pl3Qi8XFxGJUB5Pem5Bz5qFW+hMa+Cbq X-Received: by 2002:a6b:e90c:: with SMTP id u12mr1212648iof.221.1565631108461; Mon, 12 Aug 2019 10:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631108; cv=none; d=google.com; s=arc-20160816; b=lAHvHOA5ENfb5sVeyiTSpAfxf+h0XXMPFURInIrcB0Su7M5c0t2FLjJh42QZuhivbu Nhcq0HF9+NvRsJEfICJrnlcW//Zu1OtKIjqTCYN+RmhEawV84qyGTgBIG9BJcWIdK+rk +MzNYSunq8Q1NhA6TdpyNzGFzik0VlLzEzuVeXDROoI/P5jaRN/93QOpkynsURitlWpo aoaP7KmFffHzwsuADYdMl73C0A8E00eiLDU0tfNoE33ePgX2EWq72GEFjt3Z/w+n1TeD HZUd6GQY4rWd5F52B99r4wXQIOMFPNmzGlikubtym3MyIWAjrvqdxlO1Dzt6YlMct/cy vWoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=V6QdoZY6mMvtxJVkiaKhbKEcrN57JCAWdTaKQhRrIsY=; b=vn5DCiIgqFBXKTFnE5eRGezroSOzEYJ/T0oTXybjhTX7iKdHEubLMlhJDKePc9ylvN nzMYSMAEXFwcz+T7u36BubvKkrW4xNhJDNX0F2ZdvPGl+0xSum6Th8yy4h3S+ncfN8Ii ijOElPxb1/nKadCRaOIDap0b9qs9KN7UhltV2jEr/Cx31HffLfLygoNbF1CGxsdGTg3b DR8WyntcTsJL01tYQwYf7trgdffDlKA7FVdw7XkXr81a61JyeUk9IYxzvP6odaBdlD5Z kPuB8GU+GDASCuXDI2MbOkTBdW//uv1wUURteqTCSIGhiX/oYTJAWtiB3iAewAsDuRDu BqSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id y8si22200896jap.72.2019.08.12.10.31.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9V-0006hX-B4; Mon, 12 Aug 2019 17:30:37 +0000 Received: from [172.99.69.81] (helo=us1-rack-iad1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9T-0006hC-Lo for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:35 +0000 X-Inumbo-ID: e206497c-bd26-11e9-9c85-8b766f5a9059 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id e206497c-bd26-11e9-9c85-8b766f5a9059; Mon, 12 Aug 2019 17:30:31 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D5A8315AB; Mon, 12 Aug 2019 10:30:30 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2FF9A3F706; Mon, 12 Aug 2019 10:30:30 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:55 +0100 Message-Id: <20190812173019.11956-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 04/28] xen/arm64: head: Rework and document launch() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Boot CPU and secondary CPUs will use different entry point to C code. At the moment, the decision on which entry to use is taken within launch(). In order to avoid a branch for the decision and make the code clearer, launch() is reworked to take in parameters the entry point and its arguments. Lastly, document the behavior and the main registers usage within the function. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Indent all the comments the same way - Add Stefano's reviewed-by Changes in v2: - Use x3 instead of x4 - Add a clobbers section --- xen/arch/arm/arm64/head.S | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 7b6b820726..925fb93e58 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -318,6 +318,11 @@ primary_switched: /* Use a virtual address to access the UART. */ ldr x23, =EARLY_UART_VIRTUAL_ADDRESS #endif + PRINT("- Ready -\r\n") + /* Setup the arguments for start_xen and jump to C world */ + mov x0, x20 /* x0 := Physical offset */ + mov x1, x21 /* x1 := paddr(FDT) */ + ldr x2, =start_xen b launch ENDPROC(real_start) @@ -380,6 +385,9 @@ secondary_switched: /* Use a virtual address to access the UART. */ ldr x23, =EARLY_UART_VIRTUAL_ADDRESS #endif + PRINT("- Ready -\r\n") + /* Jump to C world */ + ldr x2, =start_secondary b launch ENDPROC(init_secondary) @@ -741,23 +749,26 @@ setup_fixmap: ret ENDPROC(setup_fixmap) +/* + * Setup the initial stack and jump to the C world + * + * Inputs: + * x0 : Argument 0 of the C function to call + * x1 : Argument 1 of the C function to call + * x2 : C entry point + * + * Clobbers x3 + */ launch: - PRINT("- Ready -\r\n") - - ldr x0, =init_data - add x0, x0, #INITINFO_stack /* Find the boot-time stack */ - ldr x0, [x0] - add x0, x0, #STACK_SIZE /* (which grows down from the top). */ - sub x0, x0, #CPUINFO_sizeof /* Make room for CPU save record */ - mov sp, x0 - - cbnz x22, 1f - - mov x0, x20 /* Marshal args: - phys_offset */ - mov x1, x21 /* - FDT */ - b start_xen /* and disappear into the land of C */ -1: - b start_secondary /* (to the appropriate entry point) */ + ldr x3, =init_data + add x3, x3, #INITINFO_stack /* Find the boot-time stack */ + ldr x3, [x3] + add x3, x3, #STACK_SIZE /* (which grows down from the top). */ + sub x3, x3, #CPUINFO_sizeof /* Make room for CPU save record */ + mov sp, x3 + + /* Jump to C world */ + br x2 ENDPROC(launch) /* Fail-stop */ From patchwork Mon Aug 12 17:29:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171113 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3121837ily; Mon, 12 Aug 2019 10:33:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqySDIssgLAWEmPNlQsREFr0inTBlyn3FH0LVFzvQ1uiW9cflQRKnm9wsI5RNSTxcaaxih/X X-Received: by 2002:a6b:b214:: with SMTP id b20mr35164739iof.149.1565631110842; Mon, 12 Aug 2019 10:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631110; cv=none; d=google.com; s=arc-20160816; b=FY7xnclGnvLNpIST19ZS0UaJMzwirIs093/Z8BpSs2mNznV1MkKNs2GtQM+ZBBeDK/ 7vilGjXeiqNwB9tDDfE8pO3WSmOEF2HeqVk0+g23aR4+RM/u1+YFWoBGtBmAOsUK2FRe SiDKOo+8AoIE95QoUrN932QHVwE7s/hkBzzs7UjCUacfGKE+22dNH9DTYm1QXXsqcvQb 5B2g8xUtR1MskYUGNQ8zo3lMqYfr4/yJdUSCJl6/CEffF2qG7toGWh40XwRxSe9/tKFL dU8n2L2t1DG3AkSrzMnY4mQcVDau3J3b+q9tXm+wVHepM9O8G487pRyKWzCr6NQo8kRH fjmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=2s0JjyzPVynGpQYpZfr30ZCMgXeoLBrG03+SvMh1AAk=; b=ADnaIlONW0ITaxMLbIJQdfAJwpoeQZETr8zvCR0aCsEXm2th9zJr68hLq7s0271a+h g3wY54psquIKEeNm9dgicQSBuWwnMCfaW2Im5h14ZSi2BOCBvOS2010eu/RpU5wsxfg4 1NoWXrZXna1DyJG8dRYUSp/W0wrXQvg1BXeoBCiBOquAwV3s9DttjkVVxjls9p3DBPeR Y1Ku3Yp1k9Ow46XSbYMya2ikOZV9Eyqm7mdD0hEVXWBRqybz/ZgKcPksBsmDJWpW34Dq 28Fv7Mg49VBwqhtDihC+cIrYWONrtc5W5bpXzHRFQdh8/N9W7a5zE73kWrIESzFlk12U FiQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id o10si37559661jam.75.2019.08.12.10.31.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9S-0006gy-OS; Mon, 12 Aug 2019 17:30:34 +0000 Received: from [172.99.69.81] (helo=us1-rack-iad1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9R-0006ge-KT for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:33 +0000 X-Inumbo-ID: e29140f4-bd26-11e9-8483-13847f7cc42a Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id e29140f4-bd26-11e9-8483-13847f7cc42a; Mon, 12 Aug 2019 17:30:31 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC39E19BF; Mon, 12 Aug 2019 10:30:31 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 16AA23F706; Mon, 12 Aug 2019 10:30:30 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:56 +0100 Message-Id: <20190812173019.11956-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 05/28] xen/arm64: head: Setup TTBR_EL2 in enable_mmu() and add missing isb X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, TTBR_EL2 is setup in create_page_tables(). This is fine as it is called by every CPUs. However, such assumption may not hold in the future. To make change easier, the TTBR_EL2 is not setup in enable_mmu(). Take the opportunity to add the missing isb() to ensure the TTBR_EL2 is seen before the MMU is turned on. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Patch added --- xen/arch/arm/arm64/head.S | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 925fb93e58..9b703e79ce 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -507,9 +507,7 @@ create_page_tables: cmp x19, #XEN_VIRT_START cset x25, eq /* x25 := identity map in place, or not */ - /* Write Xen's PT's paddr into TTBR0_EL2 */ load_paddr x4, boot_pgtable - msr TTBR0_EL2, x4 /* Setup boot_pgtable: */ load_paddr x1, boot_first @@ -637,6 +635,11 @@ enable_mmu: tlbi alle2 /* Flush hypervisor TLBs */ dsb nsh + /* Write Xen's PT's paddr into TTBR0_EL2 */ + load_paddr x0, boot_pgtable + msr TTBR0_EL2, x0 + isb + mrs x0, SCTLR_EL2 orr x0, x0, #SCTLR_Axx_ELx_M /* Enable MMU */ orr x0, x0, #SCTLR_Axx_ELx_C /* Enable D-cache */ From patchwork Mon Aug 12 17:29:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171150 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp509381ily; Mon, 12 Aug 2019 23:51:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcsArc4LRZgHGV56jbJe2TAJ2afje1bBQBlzZRvZu3OWAuwla2UrX0mnhvGUMg4eyi8J4s X-Received: by 2002:a02:b715:: with SMTP id g21mr10556339jam.137.1565679106128; Mon, 12 Aug 2019 23:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565679106; cv=none; d=google.com; s=arc-20160816; b=TBH+Ss9LXma6hgCR3v23NX2MmoFFgTJWUrueeP71BTzR2v+eENtABSGLS4xUGwBviQ opG/2g85oAQCBmgnYjTiYEQJv8/YJ/N7CACMQHKaAXLCUttPmFbuPnihBe7tYHKfzkjw ZLGe/pGKQxb5H8cC2T//T/ovuGsEvaYdYXwChoy6203yxRcFga6P0iNOmYO4hmByDpKP fK1mqh7FPUDX1hzbMavkKIws4dXk4qWa1z7EhqlUyQaKOU+pom3XjO38c7rImxJ3KWq3 9K9wanTIyaV4DR7lcRapOAxQyKxFYO1isa6/9w9WJfhpKdBSOGJ+YflSDBww/tMhhB3A kyyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=NJzD68mVF0YOtqarzMpQ++9R36OqyRysmbIg9IsulfI=; b=ZEGZhFRKPg+iHrTAx1JGBV55QOVzl7uZjDOoDpFSzgT4ttNeHIGo0MLtovX/2ArI6w tabco85uGu8evQo+6azXuV820h95joh+6JL1ouZzT706KvIMryfzk49bM8/OHjvPJDCh vpJR8LW85HLPMW+rH6ckHZ59Bf0fE/mRs70fk+rd6bkg3KRjU7r72borYC3Xn9SMUiqT Y6naNwSZPOHMsUyJEw8/XAw9BUy9xufIGVvFqX9Cg9U4rRpOGvT0FY3GXI2hJ7jemMu4 7Fiebp1NoeT4t1nw9ON3I2YSq6hIUn07XqQVhlm/GaUEB4NPNwLtzqm0jr7vMpC3QFU0 hCQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id s140si14498086ios.146.2019.08.12.23.51.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:51:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQdv-0001PO-Io; Tue, 13 Aug 2019 06:50:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQdt-0001P2-HG for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:50:49 +0000 X-Inumbo-ID: e335e1d6-bd26-11e9-80d0-7b22129d03e0 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e335e1d6-bd26-11e9-80d0-7b22129d03e0; Mon, 12 Aug 2019 17:30:33 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A305A1715; Mon, 12 Aug 2019 10:30:32 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F146E3F706; Mon, 12 Aug 2019 10:30:31 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:57 +0100 Message-Id: <20190812173019.11956-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 06/28] xen/arm64: head: Introduce a macro to get a PC-relative address of a symbol X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Arm64 provides instructions to load a PC-relative address, but with some limitations: - adr is enable to cope with +/-1MB - adrp is enale to cope with +/-4GB but relative to a 4KB page address Because of that, the code requires to use 2 instructions to load any Xen symbol. To make the code more obvious, introducing a new macro adr_l is introduced. The new macro is used to replace a couple of open-coded use in efi_xen_start. The macro is copied from Linux 5.2-rc4. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Fix typo in my e-mail address - Add Stefano's acked-by Changes in v2: - Patch added --- xen/arch/arm/arm64/head.S | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 9b703e79ce..cd03101196 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -117,6 +117,18 @@ #endif /* !CONFIG_EARLY_PRINTK */ +/* + * Pseudo-op for PC relative adr , where is + * within the range +/- 4GB of the PC. + * + * @dst: destination register (64 bit wide) + * @sym: name of the symbol + */ +.macro adr_l, dst, sym + adrp \dst, \sym + add \dst, \dst, :lo12:\sym +.endm + /* Load the physical address of a symbol into xb */ .macro load_paddr xb, sym ldr \xb, =\sym @@ -895,11 +907,9 @@ ENTRY(efi_xen_start) * Flush dcache covering current runtime addresses * of xen text/data. Then flush all of icache. */ - adrp x1, _start - add x1, x1, #:lo12:_start + adr_l x1, _start mov x0, x1 - adrp x2, _end - add x2, x2, #:lo12:_end + adr_l x2, _end sub x1, x2, x1 bl __flush_dcache_area From patchwork Mon Aug 12 17:29:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171154 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp511959ily; Mon, 12 Aug 2019 23:55:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhLAxRGt9PTltL9yC3ROhp1yTfuOi9/gh3Q8FbiuW3Pry8dcAiENqpJwhPF2b8UTZJv8hw X-Received: by 2002:a02:710f:: with SMTP id n15mr41769367jac.119.1565679304708; Mon, 12 Aug 2019 23:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565679304; cv=none; d=google.com; s=arc-20160816; b=xIhPzLMk35s3ojEIueQ8aD2zXSaQpntXtImuuOlaxB51SStO+zvnIXTwvrYm3Aeomn 15RDwmRUm9BWfu7OQQBG9zQ491VGf/Uorjl341bCt4VB+nrhmyLFgmMLlp4fZz7t3+tz AuFVA1lrS59IYTnXyZTCCg34RbX7qwl9GI8UWqLwFOOZCcfLwh7NMGYZW1gCwQrB8Vnx x8zwQc7MnNaGWMlukrORxT2/mfVn6+0yU0P7WtCa7pGN59kvsQxn1SYo6X+g16Wj17NI gpDj80hL6YqPwUimYdtjyjkOf/ppoMOd/cPTCAys8vjUHb+FtALeNeQcTpzboIXoTnjd KJmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=YpxOx2HMhyRl8a9SNJh03K7bN3YZ2CoYODS5M0eOC3Y=; b=y4Wk5gR1XGIdIrGhGRYBII69wpJEc2EtYUSRv0rYAgd19IsMgxtMBaRLclu6dtbgzN o6y/4rgqS5i8azySwTIAjzMy0nEHKNCNSIsbAQ61ZhhXsi9Sf4OL990AlpnEIE/neu+H KhNShvCb2ZaF6r76cFxzntB/+DfdGBkQ6FESp7jXIKfUhnnFfR1N6MDd8jOV0RMZwMdN 47yYzwnPr7Ow7onLbK3OK1mM1+r1IwsjlTvbQy1WgOmWIm38zNi5llF+f+xc0Io0Y5M7 anoewtq+ACgSpumAvP2UeBr4e+ETqKU5mN/j5HDn9s4i7+0IKARD0xrzyS9vjMHBYkJB z8/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b6si120196224ios.81.2019.08.12.23.55.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:55:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQhK-0002i9-8c; Tue, 13 Aug 2019 06:54:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQhI-0002g2-Bb for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:54:20 +0000 X-Inumbo-ID: e3a0e620-bd26-11e9-a3f0-5f35362fd25f Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e3a0e620-bd26-11e9-a3f0-5f35362fd25f; Mon, 12 Aug 2019 17:30:33 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 923E3174E; Mon, 12 Aug 2019 10:30:33 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D75B03F706; Mon, 12 Aug 2019 10:30:32 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:58 +0100 Message-Id: <20190812173019.11956-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 07/28] xen/arm64: head: Fix typo in the documentation on top of init_uart() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Patch added --- xen/arch/arm/arm64/head.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index cd03101196..a6f3aa4ee5 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -825,7 +825,7 @@ ENTRY(switch_ttbr) /* * Initialize the UART. Should only be called on the boot CPU. * - * Ouput: + * Output: * x23: Early UART base physical address * * Clobbers x0 - x1 From patchwork Mon Aug 12 17:29:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171104 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120220ily; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPtpgcBA5ztgFM3cGHvYzYOmJL+0NGyyHIwesBJa29N6cn+/HoaNdYo7kVWUZSyD7qSb79 X-Received: by 2002:a6b:720e:: with SMTP id n14mr37551547ioc.139.1565631106549; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631106; cv=none; d=google.com; s=arc-20160816; b=ppoMaAcOpM64GFaUxJfJuupFc2gUpRW7czovNa8lj4KeYm1kLMGJQoAB3EgWM1LCXv M5lJOO+qbshd75+fv9N1N4r7zh/Wj7J9/5nEn8RUpuUM8+2Bywgxav7vWfiZjoqfF3D2 OmVE2xdH3cwLhzvt8G2WHPPJxPOi8kalyz2FHTgUwfgccEGjIuiiHM8Wj5en7VaxrPJG Lp8+Dyt3P/v9nWhdWh9pJLyrzuhShYLIU0+zp+KfqGo7e59j2sI5pwZoxcAR4C7PajJ3 z/WN9m873GDo3t5PJMYCH9Ja3K0rfHfq1G3AriIRUyKqnNwUwjtLQZIvD3lK5sKaZQPx B9ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=kj7gDaBmW9ApnLebCTiEuDAfZEM4LqTFeRGWXdqnJxk=; b=chBbErb5q1XjknikunR30oKJTi/hBQ30FeWSoj8PR0vS8rrk5i7/b4mLyo/fk0IAEh N50qYCAK/0paf/8Gw+U0ZxJPcFEgXMlRJaRhS2YkbGQQvpamssUIn8h8J0MwrR6W+Aru WNrbKOcStlCvvYouHYVHPCodmQKKKvy6J0A3vIcd4WnzW/8bELnduXbsGL1CVG3v4Npf 0lCL0yE7hY1vqSfFJB7B+u9WS+3b8UYubbQMAsK5gC+QzvT9jVssMbwPcFINDQ3RJST7 BJ0o5DP4yar1lNklwRTI2Ydo20ibrhM3YG973CM8rxBMEBUlnYAw71Its5IXmmBP/FG4 JMtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u21si20754815iob.131.2019.08.12.10.31.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9V-0006hP-21; Mon, 12 Aug 2019 17:30:37 +0000 Received: from [172.99.69.81] (helo=us1-rack-iad1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9T-0006hB-Kf for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:35 +0000 X-Inumbo-ID: e4367596-bd26-11e9-883b-d7d30b8f119f Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id e4367596-bd26-11e9-883b-d7d30b8f119f; Mon, 12 Aug 2019 17:30:34 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 788301993; Mon, 12 Aug 2019 10:30:34 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C6E133F706; Mon, 12 Aug 2019 10:30:33 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:29:59 +0100 Message-Id: <20190812173019.11956-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 08/28] xen/arm32: head: Add a macro to move an immediate constant into a 32-bit register X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The current boot code is using the pattern ldr rX, =... to move an immediate constant into a 32-bit register. This pattern implies to load the immediate constant from a literal pool, meaning a memory access will be performed. The memory access can be avoided by using movw/movt instructions. A new macro is introduced to move an immediate constant into a 32-bit register without a memory load. Follow-up patches will make use of it. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 18ded49a04..99f4af18d8 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -37,6 +37,15 @@ #endif /* + * Move an immediate constant into a 32-bit register using movw/movt + * instructions. + */ +.macro mov_w reg, word + movw \reg, #:lower16:\word + movt \reg, #:upper16:\word +.endm + +/* * Common register usage in this file: * r0 - * r1 - From patchwork Mon Aug 12 17:30:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171157 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp515541ily; Mon, 12 Aug 2019 23:59:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFiMfYuoOmZz8cqBnlDYrHZwdMNRJABoCP0i/Mpf5OikvzbT5Ln1lqvSoQyZqOXWTYdsX3 X-Received: by 2002:a6b:5a12:: with SMTP id o18mr23409542iob.159.1565679563374; Mon, 12 Aug 2019 23:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565679563; cv=none; d=google.com; s=arc-20160816; b=Y5dc6oAncj65bGNIPATojLX16TKFfWi4Jqs/NJBW47H4Pi4fCwjnsY0sDZ916MzKzX BqpP+t8rhsNm9QcOJqDT1nQ5krBNWtSihmHQeKJ7Mc5N1FBL8Sxmlzg2Xizslu3+1Wcj iINUlagD0G4r7PCo4U1yopiPFIjIsiI5bodb0IK2fs5IOM8K39qYZoz77R0yqrhwSbdi NKqZmGDAwE2/V3lV8vy0t5Og/k2a2S18/cDolVXjb7IQTaeHm1bvHjDTOlKdjmxv5fYB AP8r6NNBNbJ2SW/+iV7FcvL/t7hD3t4rnxSpwcU9/0ih8uEI2taheGc7h7wFZHYe/NDc fA9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=wqkpVdEFPLMsdWnOcvve+wxNwuarLGL+AvNGRiUUUvc=; b=0yOa/UufMGQynfM0myqk9vckY8jODJ96zh9ja41Woz1q6dDcsoBIEh+fqjDtxlboN2 TGkN4Dc8F6eJkHrWozIcwqq92LRAk40YwxZLc9a2kM1th67zamxjJHW1OfeYUHys7ncN 6y97ZTW4orV2dKVY+F3DltHZtI/ORnQN3dlLo12obF3D7OaLWaCCC0Gm0GIGwxCtjC+f FBh1t0pS0AYpxBZKpUNlJDkO8bD8uW56OGAL/ebch6CIFYXhFWBfiYUUq8EauNL/sJ48 Xh/fwBIFSyGHPwzrjkWM5ge01CxktFIgFXg2DjJoGaCEmuHdp7zrhO8IqweGBW4Bul/o UPtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id q17si1083251ior.76.2019.08.12.23.59.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:59:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQlJ-0005DV-PV; Tue, 13 Aug 2019 06:58:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQlJ-0005DK-3b for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:58:29 +0000 X-Inumbo-ID: e4c30aec-bd26-11e9-921e-0bdc7fa6004d Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e4c30aec-bd26-11e9-921e-0bdc7fa6004d; Mon, 12 Aug 2019 17:30:35 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A75A15AB; Mon, 12 Aug 2019 10:30:35 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AD6FF3F706; Mon, 12 Aug 2019 10:30:34 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:00 +0100 Message-Id: <20190812173019.11956-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 09/28] xen/arm32: head: Mark the end of subroutines with ENDPROC X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , Stefano Stabellini MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" putn() and puts() are two subroutines. Add ENDPROC for the benefits of static analysis tools and the reader. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 99f4af18d8..8b4c8a4714 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -518,6 +518,7 @@ puts: moveq pc, lr early_uart_transmit r11, r1 b puts +ENDPROC(puts) /* * Print a 32-bit number in hex. Specific to the PL011 UART. @@ -537,6 +538,7 @@ putn: subs r3, r3, #1 bne 1b mov pc, lr +ENDPROC(putn) hex: .ascii "0123456789abcdef" .align 2 From patchwork Mon Aug 12 17:30:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171101 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120187ily; Mon, 12 Aug 2019 10:31:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUGzlKMeFYaU8tF6HiGes4ufBIj8A1VIsYZGt++Ju1lE6gzPK/YfiAM9DOyfjBQ4btyKlo X-Received: by 2002:a02:7f15:: with SMTP id r21mr34641284jac.120.1565631104830; Mon, 12 Aug 2019 10:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631104; cv=none; d=google.com; s=arc-20160816; b=XP69nukrFaAnPP20BwphHGrG1yUYg9eMsksLM7RQwzp++UBYFgRlpiHK4639QbRy9s 2gbFnqF6vijHc1qfbxrKZFJJijo0bvwpEBMW7Ds4XYOu9C4ST782wvUutPSWJS+bKNaM SKbkTzTDqzcURpDX/aVizeAxEiWQTpP734iXuIouvHExX5mXloaq1CgS/hSxeix2S8zO 1fCt0yoU/2DQkMl+IcAY4WLcqCP6pjEhhyHD8XWbcyaRlZYkRfvFILUpbkCsA+fX265C fvK/RYvxJSVx2w3ZCKtc3JM8YARgZp0rgl8SZX52pYr0RhcVPN5y/6FIXO+ZSbITBg81 upKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=/s5EPjYegcOAe62m+pveZEHcZyiV91rrUeU5gXuqjVY=; b=A3NGQNILvgOCpDJL1lDQ178k+tIHKUOicueCbmkOkRpFvxIi+lRIuUTpTgNOW4tgh0 sJJNMy2bLxYafnIn8FpYh3CRRJxE0myznd5CD17Uor9rwrEsOKpvlVWaM7GeI6Em7Ght D9ms8F8SBesL91cBQQRI3HcDVeW4+f4N35hz79Pm/39f2McRZ6+ZE7/hgssltDraO8KP LLPon6CSV2RF8+J2lp1iEuMRQ31pmWnSUGh/LpCnvi2WBRwSEvyC4Zh/5VU6s2Ktdrqa ZOu162ORwGjZkxbtLXMOyK4UJbyxDQUTdFrFkPDfXvk7oDowz2o9Ll2GQkxACvOAvto/ kRLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id y68si11011685iof.27.2019.08.12.10.31.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9W-0006iK-Lg; Mon, 12 Aug 2019 17:30:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9V-0006ha-Ev for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:37 +0000 X-Inumbo-ID: e555a358-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id e555a358-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:36 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 60AA51715; Mon, 12 Aug 2019 10:30:36 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AF5953F706; Mon, 12 Aug 2019 10:30:35 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:01 +0100 Message-Id: <20190812173019.11956-11-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 10/28] xen/arm32: head: Don't clobber r14/lr in the macro PRINT X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The current implementation of the macro PRINT will clobber r14/lr. This means the user should save r14 if it cares about it. Follow-up patches will introduce more use of PRINT in places where lr should be preserved. Rather than requiring all the user to preserve lr, the macro PRINT is modified to save and restore it. While the comment state r3 will be clobbered, this is not the case. So PRINT will use r3 to preserve lr. Lastly, take the opportunity to move the comment on top of PRINT and use PRINT in init_uart. Both changes will be helpful in a follow-up patch. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 8b4c8a4714..b54331c19d 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -64,15 +64,20 @@ * r14 - LR * r15 - PC */ -/* Macro to print a string to the UART, if there is one. - * Clobbers r0-r3. */ #ifdef CONFIG_EARLY_PRINTK -#define PRINT(_s) \ - adr r0, 98f ; \ - bl puts ; \ - b 99f ; \ -98: .asciz _s ; \ - .align 2 ; \ +/* + * Macro to print a string to the UART, if there is one. + * + * Clobbers r0 - r3 + */ +#define PRINT(_s) \ + mov r3, lr ;\ + adr r0, 98f ;\ + bl puts ;\ + mov lr, r3 ;\ + b 99f ;\ +98: .asciz _s ;\ + .align 2 ;\ 99: #else /* CONFIG_EARLY_PRINTK */ #define PRINT(s) @@ -500,10 +505,8 @@ init_uart: #ifdef EARLY_PRINTK_INIT_UART early_uart_init r11, r1, r2 #endif - adr r0, 1f - b puts /* Jump to puts */ -1: .asciz "- UART enabled -\r\n" - .align 4 + PRINT("- UART enabled -\r\n") + mov pc, lr /* * Print early debug messages. From patchwork Mon Aug 12 17:30:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171102 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120214ily; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjXvN4qxP89cfGYu0qsWuxSU9XS06Kj1h/NNd7NctExwfi5hLiB8XbLHrnYBEv1LtP782t X-Received: by 2002:a02:caa8:: with SMTP id e8mr9708826jap.67.1565631106327; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631106; cv=none; d=google.com; s=arc-20160816; b=pdOP0Th8Xy1512DrcDuxc2ek3rxcXMKeP3ZIWRK1mawOAD4YaZrsLPHiBkTJLuVt35 Nty3kG7ifNzxT7ECzW/4yXcfqxPywjNh7/SkHFM4mzp9XGZ3MS6H9wZZ8ZlURETy8kd9 X9qD8JDDrfIeFBZtk7rdtbeIwPd3NUmjByqptEq7u9pxmLtFtC9B3Awj76zCrngON+Ix JSdZi4CgZgN1IjTy6ps/FinsNemORsZbeJ7Wuwu4E1KPf9Lk1R9+7mIkQb4F5v8qKu+1 9bIzNJZmT1JgHkaU2mb3tSmpi0uWuq+0JDGE0/r/Eoe8sL0xU/pI9NHkjR4vPQVRwvYo ATdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=n5YniBj9P6TcPm+1CItPaAM9PItwp8SJYWblTKvsep0=; b=GBQUYK3qA/NCoVKvqRl7tZBIHbr4Y5flwaS5vU+AAyrMPVWOtEWmfnrPP3mJquBvhX cFQtC/VSPfFSZH4myVxlm2phM/HX5lKKS8P4cHq+sfuh2z9po0Xe0uldz5Kw4HZwoZ38 tu9mY9wV82keQALUSp4FBSJvm1ji8gMwFO1yrUzYIEtNOfpn1fkcGmesTiwP1ohRf+QJ 3V0Wsk5FKakwW7ZE1hJsv8vVLnaKbfatYSs1SXlb4UTKc0G2dKqg3MMEZxPy2Y8N2Rcx 4KW+rZdSBvhqr5k+PHCh3jE50fAwafVBLP+jvIaPXpLW6WTDTgyqqAUuO85ZZNHuITQk L/hg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 4si140997888jai.65.2019.08.12.10.31.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9Y-0006jy-0U; Mon, 12 Aug 2019 17:30:40 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9W-0006iJ-M0 for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:38 +0000 X-Inumbo-ID: e5dd18c1-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id e5dd18c1-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:37 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4831119F6; Mon, 12 Aug 2019 10:30:37 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 95C473F706; Mon, 12 Aug 2019 10:30:36 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:02 +0100 Message-Id: <20190812173019.11956-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 11/28] xen/arm32: head: Rework UART initialization on boot CPU X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Anything executed after the label common_start can be executed on all CPUs. However most of the instructions executed between the label common_start and init_uart are not executed on the boot CPU. The only instructions executed are to lookup the CPUID so it can be printed on the console (if earlyprintk is enabled). Printing the CPUID is not entirely useful to have for the boot CPU and requires a conditional branch to bypass unused instructions. Furthermore, the function init_uart is only called for boot CPU requiring another conditional branch. This makes the code a bit tricky to follow. The UART initialization is now moved before the label common_start. This now requires to have a slightly altered print for the boot CPU and set the early UART base address in each the two path (boot CPU and secondary CPUs). This has the nice effect to remove a couple of conditional branch in the code. After this rework, the CPUID is only used at the very beginning of the secondary CPUs boot path. So there is no need to "reserve" x24 for the CPUID. Lastly, take the opportunity to replace load from literal pool with the new macro mov_w. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - s/Ouput/Output/ - Add Stefano's reviewed-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index b54331c19d..fd3a273550 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -54,7 +54,7 @@ * r4 - * r5 - * r6 - identity map in place - * r7 - CPUID + * r7 - * r8 - DTB address (boot CPU only) * r9 - paddr(start) * r10 - phys offset @@ -123,6 +123,12 @@ past_zImage: add r8, r10 /* r8 := paddr(DTB) */ #endif + /* Initialize the UART if earlyprintk has been enabled. */ +#ifdef CONFIG_EARLY_PRINTK + bl init_uart +#endif + PRINT("- Boot CPU booting -\r\n") + mov r12, #0 /* r12 := is_secondary_cpu */ b common_start @@ -137,14 +143,9 @@ GLOBAL(init_secondary) mov r12, #1 /* r12 := is_secondary_cpu */ -common_start: mrc CP32(r1, MPIDR) bic r7, r1, #(~MPIDR_HWID_MASK) /* Mask out flags to get CPU ID */ - /* Non-boot CPUs wait here until __cpu_up is ready for them */ - teq r12, #0 - beq 1f - ldr r0, =smp_up_cpu add r0, r0, r10 /* Apply physical offset */ dsb @@ -156,15 +157,14 @@ common_start: 1: #ifdef CONFIG_EARLY_PRINTK - ldr r11, =EARLY_UART_BASE_ADDRESS /* r11 := UART base address */ - teq r12, #0 /* Boot CPU sets up the UART too */ - bleq init_uart + mov_w r11, EARLY_UART_BASE_ADDRESS /* r11 := UART base address */ PRINT("- CPU ") mov r0, r7 bl putn PRINT(" booting -\r\n") #endif +common_start: /* Check that this CPU has Hyp mode */ mrc CP32(r0, ID_PFR1) and r0, r0, #0xf000 /* Bits 12-15 define virt extensions */ @@ -497,11 +497,15 @@ ENTRY(switch_ttbr) #ifdef CONFIG_EARLY_PRINTK /* - * Bring up the UART. - * r11: Early UART base address - * Clobbers r0-r2 + * Initialize the UART. Should only be called on the boot CPU. + * + * Output: + * r11: Early UART base physical address + * + * Clobbers r0 - r3 */ init_uart: + mov_w r11, EARLY_UART_BASE_ADDRESS #ifdef EARLY_PRINTK_INIT_UART early_uart_init r11, r1, r2 #endif From patchwork Mon Aug 12 17:30:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171109 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120226ily; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqylKnLbuo57lbaYlKYZNxw3xicns334ORzJMJrDC38/rds2+UDa5+XQ8UJB7Eq0Tlzh2qVw X-Received: by 2002:a02:3745:: with SMTP id r66mr13614377jar.23.1565631106926; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631106; cv=none; d=google.com; s=arc-20160816; b=BQiVtXX5N3J7IK5jyfe5yefCa7XtGjT0NvaTyNJOHQWS6fQOF4eaInx+RJIe3QNkkz p7t3hmg/vCDhxBChKr3L/64u5Q8jHleUFzTFIe5yd0aZbnJU0dilXYbV//EPBGXrL9vY w6hRhxl8Vi264n2YDeaAgNiTKK4TGH5sQFFJ215Vb3IVWmikx+gzrH8hJ/Z8Urx5AYQ3 M52XwKOPupaHsS/YqM7MRip00k6G402cIXM4BPov3QClWU+Gy3IxZWQDkYrgJjVRmcl9 7GYJSQh8wcrU0SbtWxXqjgaAr13CDyEhvCvKiInQKvywcahjh6ZR56lJreyj6PFO9FwJ QXGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=GKSyRuIwKG7ddAAnZeH3xqr6moOoK9mkUhIyW2f1kPk=; b=Eh0Ks+QUae335ozVBCVwE2Mk75+vqyX6LRyB3NVP2bPPWjw9Uk03jGdm8o9Zxn3rft SCnWebT0p98fQKHXvzMLwrfQFJYXjGdampknq3Svv/GQuGvepkd7R51nQbTujRd+YVHP bda5YOqaEKbm+DsHJ2TISYuSt20WK2v/1iBTiPF/P4rMP6Qy2p8B44PMpFkthUXT2a+j NP3ijPdw+tKAEAmF+cmHRiXqTE8ntJR9nlYinqXdpxu1ln59QT2lrle6Z1OJEb3AFcLN KVtm6QJUxD7Tiq2h7937M6LvXZrj7BO13mWKUI5FTiQNnnzDuevogKUCf0CPxar64r5a P3JQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id d14si145587329jaq.25.2019.08.12.10.31.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9Y-0006kd-By; Mon, 12 Aug 2019 17:30:40 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9W-0006iQ-TC for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:38 +0000 X-Inumbo-ID: e65def37-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id e65def37-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:38 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2E21C174E; Mon, 12 Aug 2019 10:30:38 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7C38A3F706; Mon, 12 Aug 2019 10:30:37 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:03 +0100 Message-Id: <20190812173019.11956-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 12/28] xen/arm32: head: Introduce print_reg X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, the user should save r14/lr if it cares about it. Follow-up patches will introduce more use of putn in place where lr should be preserved. Furthermore, any user of putn should also move the value to register r0 if it was stored in a different register. For convenience, a new macro is introduced to print a given register. The macro will take care for us to move the value to r0 and also preserve lr. Lastly the new macro is used to replace all the callsite of putn. This will simplify rework/review later on. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index fd3a273550..c4ee06ba93 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -79,8 +79,25 @@ 98: .asciz _s ;\ .align 2 ;\ 99: + +/* + * Macro to print the value of register \rb + * + * Clobbers r0 - r4 + */ +.macro print_reg rb + mov r0, \rb + mov r4, lr + bl putn + mov lr, r4 +.endm + #else /* CONFIG_EARLY_PRINTK */ #define PRINT(s) + +.macro print_reg rb +.endm + #endif /* !CONFIG_EARLY_PRINTK */ .arm @@ -159,8 +176,7 @@ GLOBAL(init_secondary) #ifdef CONFIG_EARLY_PRINTK mov_w r11, EARLY_UART_BASE_ADDRESS /* r11 := UART base address */ PRINT("- CPU ") - mov r0, r7 - bl putn + print_reg r7 PRINT(" booting -\r\n") #endif @@ -211,8 +227,7 @@ skip_bss: bne 1f mov r4, r0 PRINT("- Missing processor info: ") - mov r0, r4 - bl putn + print_reg r4 PRINT(" -\r\n") b fail 1: From patchwork Mon Aug 12 17:30:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171105 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120235ily; Mon, 12 Aug 2019 10:31:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzo4FbNEakH9SAkMny5RVvrC1x+BJ4iHDR+79XSxbC5WkHuF5F2Wmm/BntlGFxqpVy2Ovjp X-Received: by 2002:a5d:9d89:: with SMTP id 9mr19377935ion.212.1565631107371; Mon, 12 Aug 2019 10:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631107; cv=none; d=google.com; s=arc-20160816; b=XcMRKApQqZUsI5p82yI38sk0LwslBXU8PhEh8j3pYsZU3kXMp2mpYzT9h9+/0u9FUh n94nofswF12R8pVs6BefNcJL0YcG83sKZ1/MOwxicHg67HnnkM8z8xnIpFrB6iOc8mAt 6SGYJfPAu6t+EA074PPQID5b2eCR9d29ns6XgugwSfeqZ4oDhOga12QbXSJSOSiI59rG 7iCSq+aWz68vwPP1MgA92XZ3d+ZYnAC8NHyNJPZEIZBN7YB9VzVnBppowSalyNSGldb5 Z8U6cjAzBOH8bikmrOBBmErnPr9IRxCJ8BZOxOaMtEDbjTIhM8X9cI0iqvditIFhWoTk Zj1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=GAqhDTTnX88Fu6DP3MqRSeCdELS4Himqqxj8V/SycJE=; b=WFzQUzo8aRFyXtFb5YNw60k9odeDAwmy5J/Yw7IlF3mhFP99zjllPz+3Z4WkiNHHvS c7xYUOVPXAMpMcSXhQATg+gpjxAGjwmBk4p5SaY9gzIzNc7SzWEdJgGnafH2QV/VQAHP jWZBeYrTj9J6359lIKeI6prQKop9piilcPuo3REEp2f1CW3a8RMio6YOLQYJFV51yyEg exLkVvPPR8fXBYeHKNie+XWCl26aFMb7D1kNLKW53IZEABVv4ejeNeXoUlv8gKpRlrET Ry9yHExZ4IAbKI5JvxqLIITvX/sAttqCV7n/w+oCeYGmWBoMlEW2rxGIHaOlflqEaSO7 Y9rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id n26si44013ioh.135.2019.08.12.10.31.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9Z-0006mC-MO; Mon, 12 Aug 2019 17:30:41 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9Y-0006kA-5h for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:40 +0000 X-Inumbo-ID: e6f4937b-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id e6f4937b-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:39 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 144D115AB; Mon, 12 Aug 2019 10:30:39 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 62A153F706; Mon, 12 Aug 2019 10:30:38 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:04 +0100 Message-Id: <20190812173019.11956-14-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 13/28] xen/arm32: head: Introduce distinct paths for the boot CPU and secondary CPUs X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The boot code is currently quite difficult to go through because of the lack of documentation and a number of indirection to avoid executing some path in either the boot CPU or secondary CPUs. In an attempt to make the boot code easier to follow, each parts of the boot are now in separate functions. Furthermore, the paths for the boot CPU and secondary CPUs are now distinct and for now will call each functions. Follow-ups will remove unnecessary calls and do further improvement (such as adding documentation and reshuffling). Note that the switch from using the ID mapping to the runtime mapping is duplicated for each path. This is because in the future we will need to stay longer in the ID mapping for the boot CPU. Lastly, it is now required to save lr in cpu_init() becauswe the function will call other functions and therefore clobber lr. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Remove hard tab - s/ID map/1:1 mapping/ Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 65 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index c4ee06ba93..4285f76463 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -148,7 +148,19 @@ past_zImage: mov r12, #0 /* r12 := is_secondary_cpu */ - b common_start + bl check_cpu_mode + bl zero_bss + bl cpu_init + bl create_page_tables + bl enable_mmu + + /* We are still in the 1:1 mapping. Jump to the runtime Virtual Address. */ + ldr r0, =primary_switched + mov pc, r0 +primary_switched: + bl setup_fixmap + b launch +ENDPROC(start) GLOBAL(init_secondary) cpsid aif /* Disable all interrupts */ @@ -179,8 +191,22 @@ GLOBAL(init_secondary) print_reg r7 PRINT(" booting -\r\n") #endif - -common_start: + bl check_cpu_mode + bl zero_bss + bl cpu_init + bl create_page_tables + bl enable_mmu + + + /* We are still in the 1:1 mapping. Jump to the runtime Virtual Address. */ + ldr r0, =secondary_switched + mov pc, r0 +secondary_switched: + bl setup_fixmap + b launch +ENDPROC(init_secondary) + +check_cpu_mode: /* Check that this CPU has Hyp mode */ mrc CP32(r0, ID_PFR1) and r0, r0, #0xf000 /* Bits 12-15 define virt extensions */ @@ -202,7 +228,10 @@ common_start: b fail hyp: PRINT("- Xen starting in Hyp mode -\r\n") + mov pc, lr +ENDPROC(check_cpu_mode) +zero_bss: /* Zero BSS On the boot CPU to avoid nasty surprises */ teq r12, #0 bne skip_bss @@ -219,8 +248,14 @@ hyp: PRINT("- Xen starting in Hyp mode -\r\n") blo 1b skip_bss: + mov pc, lr +ENDPROC(zero_bss) + +cpu_init: PRINT("- Setting up control registers -\r\n") + mov r5, lr /* r5 := return address */ + /* Get processor specific proc info into r1 */ bl __lookup_processor_type teq r1, #0 @@ -231,7 +266,6 @@ skip_bss: PRINT(" -\r\n") b fail 1: - /* Jump to cpu_init */ ldr r1, [r1, #PROCINFO_cpu_init] /* r1 := vaddr(init func) */ adr lr, cpu_init_done /* Save return address */ @@ -256,6 +290,10 @@ cpu_init_done: ldr r0, =HSCTLR_SET mcr CP32(r0, HSCTLR) + mov pc, r5 /* Return address is in r5 */ +ENDPROC(cpu_init) + +create_page_tables: /* * Rebuild the boot pagetable's first-level entries. The structure * is described in mm.c. @@ -359,15 +397,16 @@ cpu_init_done: /* boot pagetable setup complete */ cmp r6, #1 /* Did we manage to create an identity mapping ? */ - beq 1f + moveq pc, lr 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") b fail +ENDPROC(create_page_tables) -1: +enable_mmu: PRINT("- Turning on paging -\r\n") /* @@ -377,16 +416,16 @@ virtphys_clash: mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLBs */ dsb nsh - ldr r1, =paging /* Explicit vaddr, not RIP-relative */ mrc CP32(r0, HSCTLR) /* Enable MMU and D-cache */ orr r0, r0, #(SCTLR_Axx_ELx_M|SCTLR_Axx_ELx_C) dsb /* Flush PTE writes and finish reads */ mcr CP32(r0, HSCTLR) /* now paging is enabled */ isb /* Now, flush the icache */ - mov pc, r1 /* Get a proper vaddr into PC */ -paging: + mov pc, lr +ENDPROC(enable_mmu) +setup_fixmap: /* * Now we can install the fixmap and dtb mappings, since we * don't need the 1:1 map any more @@ -436,12 +475,15 @@ paging: mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLB */ dsb /* Ensure completion of TLB flush */ isb + mov pc, lr +ENDPROC(setup_fixmap) +launch: PRINT("- Ready -\r\n") /* The boot CPU should go straight into C now */ teq r12, #0 - beq launch + beq 1f /* * Non-boot CPUs need to move on to the proper pagetables, which were @@ -460,7 +502,7 @@ paging: dsb /* Ensure completion of TLB+BP flush */ isb -launch: +1: ldr r0, =init_data add r0, #INITINFO_stack /* Find the boot-time stack */ ldr sp, [r0] @@ -471,6 +513,7 @@ launch: moveq r1, r8 /* - DTB address */ beq start_xen /* and disappear into the land of C */ b start_secondary /* (to the appropriate entry point) */ +ENDPROC(launch) /* Fail-stop */ fail: PRINT("- Boot failed -\r\n") From patchwork Mon Aug 12 17:30:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171103 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120216ily; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5dls2eW/NE76m74sl8XHxBSgTYRSkXCmvWlX0jIQQCeRaxOiVgH/rXd+YVTrAbzAIxQsV X-Received: by 2002:a05:6638:105:: with SMTP id x5mr12643013jao.43.1565631106361; Mon, 12 Aug 2019 10:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631106; cv=none; d=google.com; s=arc-20160816; b=lmg0IvvYlZDn1c9JevNI2OpJNmhekuBguQItgN7sgG/PLBjvv1X8F5MmAZkdUdRg6L Ez9mx2FqXfTpzaevYtzYNtVkUvZjhUtD1J96UyX0YIGWpVVj4taJZR2RTOIwp1MR+s/S l3ftwNCDvjCEkLfrSPqhnkSvt6AfWzlpeWRRjyUmzpEX6KuxfjvENJHP/H097acWzEDu myPELZA4rPQtsB55xUDYrU5+pbg+iQUCOmQ2q9Zygu9cqj4p6fIWrJP5vcdalgg+rDhR bNsCLRFL3u2kh5vazXpQq9LTAB2rIhvgnI1KudvygsAHTVn2eabRwgFppyNlzHmYGnc5 NQbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=8dHSU4/G6Zygf9l3myCMrCWC87mfAv/spWzDvyaYzwE=; b=LBthvAGd3yquoni1VEea8z2gtr2BBD2+25uQgWtFSqSLKX2Tfstz3ZD/99ArZm5tPh ch0M66k4LRHXP3oiCGMkuPbPPBRhRQJn8IyV5mc6m87HrWhJg80IicL7rh2UMzKgCFnd oMcz3v9vrsTWo9pw859EdOh300ijd4pkGmp8ducF19f4HQ3/jIZd3QNcbI7IIJ6N2XsO wIdec6hTIiuXymnq2zEu8dPQJegLGS1+dyI4counVW4a2EmvWXWCbaaVnjPmnKPbTVNH 7MfEfT+iSKmH+LNwdTKMYULEun2fBIXZ9tJiPcws9HabIACB0XfM3gcW//BHtebeY/Dw PvjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u73si90316jab.120.2019.08.12.10.31.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9a-0006mm-1r; Mon, 12 Aug 2019 17:30:42 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9Y-0006lR-VI for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:40 +0000 X-Inumbo-ID: e767d733-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id e767d733-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:40 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF0B21715; Mon, 12 Aug 2019 10:30:39 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 491D63F706; Mon, 12 Aug 2019 10:30:39 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:05 +0100 Message-Id: <20190812173019.11956-15-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 14/28] xen/arm32: head: Rework and document check_cpu_mode() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" A branch in the success case can be avoided by inverting the branch condition. At the same time, remove a pointless comment as Xen can only run at Hypervisor Mode. Lastly, document the behavior and the main registers usage within the function. Signed-off-by: Julien Grall --- Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 4285f76463..c7b4fe4cd4 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -206,6 +206,16 @@ secondary_switched: b launch ENDPROC(init_secondary) +/* + * Check if the CPU supports virtualization extensions and has been booted + * in Hypervisor mode. + * + * This function will never return when the CPU doesn't support + * virtualization extensions or is booted in another mode than + * Hypervisor mode. + * + * Clobbers r0 - r3 + */ check_cpu_mode: /* Check that this CPU has Hyp mode */ mrc CP32(r0, ID_PFR1) @@ -220,15 +230,12 @@ check_cpu_mode: mrs r0, cpsr and r0, r0, #0x1f /* Mode is in the low 5 bits of CPSR */ teq r0, #0x1a /* Hyp Mode? */ - beq hyp + moveq pc, lr /* Yes, return */ /* OK, we're boned. */ PRINT("- Xen must be entered in NS Hyp mode -\r\n") PRINT("- Please update the bootloader -\r\n") b fail - -hyp: PRINT("- Xen starting in Hyp mode -\r\n") - mov pc, lr ENDPROC(check_cpu_mode) zero_bss: From patchwork Mon Aug 12 17:30:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171148 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp506397ily; Mon, 12 Aug 2019 23:47:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxS4DGofkV/6Nh0dt0GnkpB32RSFJSa/MmR7IPcFn4uWErjF1vPOneJDLWWi1CLyon8gkiD X-Received: by 2002:a02:c992:: with SMTP id b18mr28534587jap.128.1565678866235; Mon, 12 Aug 2019 23:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565678866; cv=none; d=google.com; s=arc-20160816; b=ldLaa5W3nA7BQDo/H35v1LEXeLTCEkt1+nIcyNNZD8X25RejF43UNX10B0j6dN3Zi+ 3gufmgMIszhpRu3hZTYhDw5q+hf8+LjVdyDgXU9lKKXlPaP5iHNCjmnarsmbXHrLQ3SB 5P6pUSP0S35GoiLasK9EP4cIxSGFX7VReQ3mpjkGSDQD3jSOuYHKfEMZjIhsrMJ2nLLG eU2otm7AVOLvUGTqCgGP37hc8DfCZaWx31yXB03lAIx5qPWyoYQ2Sj0tsvwM1qF4VWp4 TjbzLL63m8od4KbwWbQ+9s5+kcgv6Qxgu+jgmjzLWcslmsg3SQ424y/rRot6LxL7NDLE si2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=JLeCiNn5svnzKhZF8NXdx8eNdHs7LpSasB4UiewQO8Q=; b=g9ixUEE1NX2o0AYLmQjveYzIdZCcbNqyf1W4zMFAAyZ9lvTxmdXZZv2xS75RgC110h kyteWZNOQJT30Yikx5kztqriIoZnNy+xe+Fn1JLzQ2rHar75M/sswBga0lrrFOPKAEcy F7IukxtlEKlEixJ1Y+N+l0EraLyfVfPAdHsgz9V7ISrsyPhPtHMF4KNP28xaxLka910H +rVD+KZqflLBY1CoZPFO2JwQonlsenD0EeXLrjz5vp8vXhZcDclJlC6BlNpYQpGomvKy /OOpiBnA5GySPE+tNOVrgaVeF+g2Oil5ykowIeJfWYR7RbwW7guHgSn18v71AmG1g0v8 CTCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p3si143816741iom.77.2019.08.12.23.47.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:47:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQZv-00007O-Sm; Tue, 13 Aug 2019 06:46:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQZu-00007F-UI for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:46:42 +0000 X-Inumbo-ID: e7fe84b6-bd26-11e9-a00c-e78223b30793 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e7fe84b6-bd26-11e9-a00c-e78223b30793; Mon, 12 Aug 2019 17:30:41 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D59531993; Mon, 12 Aug 2019 10:30:40 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2FC9A3F706; Mon, 12 Aug 2019 10:30:40 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:06 +0100 Message-Id: <20190812173019.11956-16-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 15/28] xen/arm32: head: Rework and document zero_bss() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On secondary CPUs, zero_bss() will be a NOP because BSS only need to be zeroed once at boot. So the call in the secondary CPUs path can be removed. Lastly, document the behavior and the main registers usage within the function. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index c7b4fe4cd4..1189ed6c47 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -192,7 +192,6 @@ GLOBAL(init_secondary) PRINT(" booting -\r\n") #endif bl check_cpu_mode - bl zero_bss bl cpu_init bl create_page_tables bl enable_mmu @@ -238,11 +237,15 @@ check_cpu_mode: b fail ENDPROC(check_cpu_mode) +/* + * Zero BSS + * + * Inputs: + * r10: Physical offset + * + * Clobbers r0 - r3 + */ zero_bss: - /* Zero BSS On the boot CPU to avoid nasty surprises */ - teq r12, #0 - bne skip_bss - PRINT("- Zero BSS -\r\n") ldr r0, =__bss_start /* Load start & end of bss */ ldr r1, =__bss_end @@ -254,7 +257,6 @@ zero_bss: cmp r0, r1 blo 1b -skip_bss: mov pc, lr ENDPROC(zero_bss) From patchwork Mon Aug 12 17:30:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171110 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120230ily; Mon, 12 Aug 2019 10:31:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFvx0KMEUdRw1GHBnDJsgrfkkLDU1PAYcrSHl84DGOtVq+D8uCZhF1tdgcFmJw6VhiVRif X-Received: by 2002:a5e:9314:: with SMTP id k20mr2845503iom.235.1565631107101; Mon, 12 Aug 2019 10:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631107; cv=none; d=google.com; s=arc-20160816; b=gCLxG2xU83pwoFH2+XTr1MQcS8757aSg9CFU0nJpwzt9Bc1uVR2q64aomtuKc/fqvq Xi9Slm2dh7zjDJDal4cTcWoCkFjprMtuh0W9mpmOXIrZubJ6axyk/C72GYsR0tvf7whE XScHZ7YbX6+Fegtj8/IACDUPmO0A8qeyI3crAHUBzgeZO1s2JBQguTn8zvZHKo/YnOV2 pkpigphMeWbTxZ0Uo2Kbli6H6YQeeoTi2BWluEz4+4ls/7g+4btiJk5kK87MF2ecJn3z vKaOToULT5XDemJAdIEgnElFHw2eDL2qPrq8w/o9sQLkbVyaF/FSO87DsH4pZie1a9MU PL/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=pitq2vQJhD3+2BaWEic4+RL19L5gGzvW/cF6m0kH14I=; b=qeO108rr+ZOKvERlZo7BkXNnLO2zFqdYtSL3igCRv7H1RmuMY9JvwRw4aguBdlQzNv y9ag0INn5RbQc7JvG/xat2bZTOAsp5S2yysIexMYKEyZpqTqyjGihl4bnTHR5LZfwAE6 KhF67HtZ7hJFHM8rN1dSQ+dWpO501fLGXFuxP7GekUVuTqr6q/O7u2kle2bmgQ2I5q6z j7uuKcJvFC05oJLMFbqXdnimem0Dw5lorCFK3uluvbsnCvDhEgANXzpXF52YMomiYVXc 60qdpzrT8XVEw9qgIUmW0f6M7qa1QBDyBl2n9tMC1i+NwVs6JZmE9da11yS5yfiga5V4 Ly9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id i16si145136076jak.37.2019.08.12.10.31.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9c-0006py-Kc; Mon, 12 Aug 2019 17:30:44 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9b-0006oW-8g for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:43 +0000 X-Inumbo-ID: e88a2bd5-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id e88a2bd5-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:41 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC16C19BF; Mon, 12 Aug 2019 10:30:41 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1655B3F706; Mon, 12 Aug 2019 10:30:40 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:07 +0100 Message-Id: <20190812173019.11956-17-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 16/28] xen/arm32: head: Document create_pages_tables() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Document the behavior and the main registers usage within the function. Note that r6 is now only used within the function, so it does not need to be part of the common register. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 1189ed6c47..83f8774e2a 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -53,7 +53,7 @@ * r3 - * r4 - * r5 - - * r6 - identity map in place + * r6 - * r7 - * r8 - DTB address (boot CPU only) * r9 - paddr(start) @@ -302,18 +302,26 @@ cpu_init_done: mov pc, r5 /* Return address is in r5 */ ENDPROC(cpu_init) +/* + * Rebuild the boot pagetable's first-level entries. The structure + * is described in mm.c. + * + * After the CPU enables paging it will add the fixmap mapping + * to these page tables, however this may clash with the 1:1 + * mapping. So each CPU must rebuild the page tables here with + * the 1:1 in place. + * + * Inputs: + * r9 : paddr(start) + * r10: phys offset + * + * Clobbers r0 - r6 + * + * Register usage within this function: + * r6 : Identity map in place + */ create_page_tables: /* - * Rebuild the boot pagetable's first-level entries. The structure - * is described in mm.c. - * - * After the CPU enables paging it will add the fixmap mapping - * to these page tables, however this may clash with the 1:1 - * 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. From patchwork Mon Aug 12 17:30:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171107 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120359ily; Mon, 12 Aug 2019 10:31:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJez3jQhkT+IE5ZJjonEi8BKgHUP6goPnwztgq2sSZzoN4E+sZQaWjPZEW9A+NJQgM3JV7 X-Received: by 2002:a5e:9e0a:: with SMTP id i10mr35821428ioq.44.1565631114423; Mon, 12 Aug 2019 10:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631114; cv=none; d=google.com; s=arc-20160816; b=mfOtck2jp6lImx6m2XfnnmxnVoBk2SuWpr3tpcC4/ioaClDH7plaHAMMbFCJFw2yft m31MEJYEvdFV6OitN3+MuQ5t8jB/BqUA2ObsqtYFPkEEHg8w/vMOWogeQki6Nr+seEZb QazjNHYLMPMW6mKMfjoFxUT7zLJMxmrVu9rxPPuJvPjHZA04tJe6XQ1+u2G8DyuLMAqA DvwiLCvjslTfYYQfRiIKDGnGBEmP42buKTLlfcjKmna6mo3VWBVP27k5xvyDMbckbxzM McYe0VWNGeZPE4WbVFXAtIZSKjt3LclbjiRTwKpY23zFAyF18o0DpFVvdDlGJF1nY2gN YlNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=NUE/1p5Sow7PaM/gxco4h1fyZ4YFzPuhzqHez7gtG9A=; b=gUdmp8B8Muh2tbtfClOkqd4J/eqjxtNliywEoeFB0S2VZHRG/Fde2JSxKh4qL9Ed/7 dFgdWR5BC2hUTN7RkCe50D7iAKj05dhz1dXzcKRScuEoNb9orb1y8/0wSUgjt1Ktr6eS GZBjcUxdyqnmhta/kCuHtb5IlygzBdtD+SAoqlHQSDeyLoaCqR3h4qi1V9MDi13QBMcP 2KDx9NIprcud3zTT+BVGgDiCWzoq4YJ34dmhL5FqpTc2IahS+mMGnD94DEe9R/36hO0R 0tKKWukmf88DyqRAlHxgezUQuqMqfn5Gecm8QqHsgOJuABBb3tWX2i+RqK7RWW+fXRfp tDYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g6si12583529jar.83.2019.08.12.10.31.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9d-0006qh-1i; Mon, 12 Aug 2019 17:30:45 +0000 Received: from [172.99.69.81] (helo=us1-rack-iad1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9b-0006oz-Lm for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:43 +0000 X-Inumbo-ID: e911ec08-bd26-11e9-984b-bf171714a9dd Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id e911ec08-bd26-11e9-984b-bf171714a9dd; Mon, 12 Aug 2019 17:30:42 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A2A8515AB; Mon, 12 Aug 2019 10:30:42 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F09C13F706; Mon, 12 Aug 2019 10:30:41 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:08 +0100 Message-Id: <20190812173019.11956-18-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 17/28] xen/arm32: head: Document enable_mmu() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Document the behavior and the main registers usage within enable_mmu(). Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 83f8774e2a..f8603051e4 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -423,6 +423,13 @@ virtphys_clash: b fail ENDPROC(create_page_tables) +/* + * Turn on the Data Cache and the MMU. The function will return on the 1:1 + * mapping. In other word, the caller is responsible to switch to the runtime + * mapping. + * + * Clobbers r0 - r3 + */ enable_mmu: PRINT("- Turning on paging -\r\n") From patchwork Mon Aug 12 17:30:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171152 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp511490ily; Mon, 12 Aug 2019 23:54:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxV++gU5n28WOKutmbbloKjKNWqMd5mc5dOTbmdNeb0EKOT7zF5sdjYKiekAJxjUH5kwYZd X-Received: by 2002:a05:6638:627:: with SMTP id h7mr1188716jar.33.1565679265316; Mon, 12 Aug 2019 23:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565679265; cv=none; d=google.com; s=arc-20160816; b=ELDoumW+2USZuSlpya36idPTU0D7jh3Tn43mQ389JP3umb6wINvUuboxMKrL8jkYx4 B8/kTznqKQzeyxatMnThjk989gXt4Wt0kvtnfoYyrO1gwqFw/M+t3Rv4q4rnWP5rgHOU bcbAgfFYbZe00G53GpDftMZSfAspdk9RZxd1MycqlVjROA2EWi7mHBJfB/2k7gCp25rS pgIXe0Ddgexv+p806a/MlujrypwFtDjHdXDaAnZ4nIXB2fTP23sj7TrhGISz0olVc+W4 60tLwjrkldg6V/ICunYcEnDem/bzS+me0G+MJuMozmRg7e/HKeZEJ/GEjX9UOvb4REu+ 5v1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=ARvSkFI7OOOjpaPsrN+aZQd0Z5VfNtsngXzzBvrE56I=; b=dbd2dpqoXTKl5VRK0D7gqVaS5oxCg5MkCPhfabUyR6UBnphRuZ3TEN7scz0ybBv9Z4 qLIoBSJ+puKyj9ZwF153ph8b25ANwsrINI1WuD/T+cptBLstFFjp5FeCcnoJYMvPTqQY H90Z8Pfq/sFBmvq2YEGiVqDAEcWect4MH0X6SimxvX5gipVGxH4GP8lcm8gTa05h0Owe FcjBNdCERmkBBV7LfMvTkEHUKJ4qKqymyNS4aepMez8+8SVN0M7SZgMUR4CjW9oZFUK8 fb4blBp2n+1n9EMRta0z1JGGgKK2ddm0RMrsEHMxAg6Rlos3kWdptadnoZ/uNEemO+5W YKdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id t130si69719125jaa.66.2019.08.12.23.54.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:54:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQgh-00029T-5W; Tue, 13 Aug 2019 06:53:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQgf-00027A-BI for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:53:41 +0000 X-Inumbo-ID: e993ecda-bd26-11e9-8db2-43c97a43d94f Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e993ecda-bd26-11e9-8db2-43c97a43d94f; Mon, 12 Aug 2019 17:30:43 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 88AEA1715; Mon, 12 Aug 2019 10:30:43 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D71353F706; Mon, 12 Aug 2019 10:30:42 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:09 +0100 Message-Id: <20190812173019.11956-19-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 18/28] xen/arm32: head: Move assembly switch to the runtime PT in secondary CPUs path X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The assembly switch to the runtime PT is only necessary for the secondary CPUs. So move the code in the secondary CPUs path. While this is definitely not compliant with the Arm Arm as we are switching between two differents set of page-tables without turning off the MMU. Turning off the MMU is impossible here as the ID map may clash with other mappings in the runtime page-tables. This will require more rework to avoid the problem. So for now add a TODO in the code. Finally, the code is currently assume that r5 will be properly set to 0 before hand. This is done by create_page_tables() which is called quite early in the boot process. There are a risk this may be oversight in the future and therefore breaking secondary CPUs boot. Instead, set r5 to 0 just before using it. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - There is no need to zero r5 Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index f8603051e4..0c95d1c432 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -202,6 +202,25 @@ GLOBAL(init_secondary) mov pc, r0 secondary_switched: bl setup_fixmap + + /* + * Non-boot CPUs need to move on to the proper pagetables, which were + * setup in init_secondary_pagetables. + * + * XXX: This is not compliant with the Arm Arm. + */ + ldr r4, =init_ttbr /* VA of HTTBR value stashed by CPU 0 */ + ldrd r4, r5, [r4] /* Actual value */ + dsb + mcrr CP64(r4, r5, HTTBR) + dsb + isb + mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLB */ + mcr CP32(r0, ICIALLU) /* Flush I-cache */ + mcr CP32(r0, BPIALL) /* Flush branch predictor */ + dsb /* Ensure completion of TLB+BP flush */ + isb + b launch ENDPROC(init_secondary) @@ -505,28 +524,6 @@ ENDPROC(setup_fixmap) launch: PRINT("- Ready -\r\n") - /* The boot CPU should go straight into C now */ - teq r12, #0 - beq 1f - - /* - * Non-boot CPUs need to move on to the proper pagetables, which were - * setup in init_secondary_pagetables. - */ - - ldr r4, =init_ttbr /* VA of HTTBR value stashed by CPU 0 */ - ldrd r4, r5, [r4] /* Actual value */ - dsb - mcrr CP64(r4, r5, HTTBR) - dsb - isb - mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLB */ - mcr CP32(r0, ICIALLU) /* Flush I-cache */ - mcr CP32(r0, BPIALL) /* Flush branch predictor */ - dsb /* Ensure completion of TLB+BP flush */ - isb - -1: ldr r0, =init_data add r0, #INITINFO_stack /* Find the boot-time stack */ ldr sp, [r0] From patchwork Mon Aug 12 17:30:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171156 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp513449ily; Mon, 12 Aug 2019 23:56:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1QecXK2R3scY2TngjhZ9h31sXkOQqev0vUryMBkG7XqXtOBN4SDQAdgSaqFfoNUTqRyDk X-Received: by 2002:a6b:f30b:: with SMTP id m11mr22020193ioh.214.1565679413944; Mon, 12 Aug 2019 23:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565679413; cv=none; d=google.com; s=arc-20160816; b=UgoVTkHZRdCRqe8C5OMTG7n0kRdABR8dxIwVXoiDEXl+GBGn6jB1V4d58aSgkyl+J7 LPVWjkvFYmhe+Vz6FuyMC7e/ndLZdiM1hwXxDKqwR7a18amwZJ/WpjNfVUhKpy3Kcz2k HDSG244Xr4MGJisf0OZ/hKCokPf8xxH+tdXKP0k0+p/LoSjeNFsGCHtPEInUmYkhZh++ KbbTOiCSdy0Ea+6qoL5PULrKqZO5Z2nOOhPi3nYXDODrtY/MsqOH32jEWE63aPeVu+xW 3BSRyf6wsFqbpEQ1r8PYarF/49uIbu8dVOF/AcA/eBi8HoGB9ITn+9LRqFuoXI8cHc4y CnxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=fJRtBSa9M5G/U3wKch+mL1O4lf10buC8DkOiaD2TQL4=; b=mCKfuY7evmzT69J+M1RhLd+uII4kP68Rkb4dKCcZ13mBh49mWCkdmYOswwV9DUPMyg x9ZwLlZr5Nk3MaoI1uBSuS97jXrlAGZ8BUMUo6RLyo8AI8x5LaSbYi0P6psFcSqkdHee 7GSJddvQ4K8eBFQjJHu3OdeFF6CplUVmF6xkEv5LqtWO8Np+osTfCEWf6BZfw1kyBdDu 5YzpAddIKkJth2ZXRVOUhA3dQ2d3/dsuWBmLzeExhcrgxKGUWKxOrbvW/Q9yGwQmymOO BRvvDeDXuKkK2NI5bNvqjt9Nz6a4lrvpDWGh4MggGaMP8h++qWv9/pWnA67ki1741WSM pNkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u12si13708576jap.79.2019.08.12.23.56.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:56:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQj5-00046F-8X; Tue, 13 Aug 2019 06:56:11 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQj4-00045J-9J for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:56:10 +0000 X-Inumbo-ID: ea194f92-bd26-11e9-bd8c-07b407aedc9a Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id ea194f92-bd26-11e9-bd8c-07b407aedc9a; Mon, 12 Aug 2019 17:30:44 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6F22F174E; Mon, 12 Aug 2019 10:30:44 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BD98E3F706; Mon, 12 Aug 2019 10:30:43 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:10 +0100 Message-Id: <20190812173019.11956-20-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 19/28] xen/arm32: head: Don't setup the fixmap on secondary CPUs X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" setup_fixmap() will setup the fixmap in the boot page tables in order to use earlyprintk and also update the register r11 holding the address to the UART. However, secondary CPUs are not using earlyprintk between turning the MMU on and switching to the runtime page table. So setting up the fixmap in the boot pages table is pointless. This means most of setup_fixmap() is not necessary for the secondary CPUs. The update of UART address is now moved out of setup_fixmap() and duplicated in the CPU boot and secondary CPUs boot. Additionally, the call to setup_fixmap() is removed from secondary CPUs boot. Lastly, take the opportunity to replace load from literal pool with the new macro mov_w. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 0c95d1c432..8f945d318a 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -159,6 +159,10 @@ past_zImage: mov pc, r0 primary_switched: bl setup_fixmap +#ifdef CONFIG_EARLY_PRINTK + /* Use a virtual address to access the UART. */ + mov_w r11, EARLY_UART_VIRTUAL_ADDRESS +#endif b launch ENDPROC(start) @@ -201,8 +205,6 @@ GLOBAL(init_secondary) ldr r0, =secondary_switched mov pc, r0 secondary_switched: - bl setup_fixmap - /* * Non-boot CPUs need to move on to the proper pagetables, which were * setup in init_secondary_pagetables. @@ -221,6 +223,10 @@ secondary_switched: dsb /* Ensure completion of TLB+BP flush */ isb +#ifdef CONFIG_EARLY_PRINTK + /* Use a virtual address to access the UART. */ + mov_w r11, EARLY_UART_VIRTUAL_ADDRESS +#endif b launch ENDPROC(init_secondary) @@ -475,13 +481,6 @@ setup_fixmap: */ dsb #if defined(CONFIG_EARLY_PRINTK) /* Fixmap is only used by early printk */ - /* - * Non-boot CPUs don't need to rebuild the fixmap itself, just - * the mapping from boot_second to xen_fixmap - */ - teq r12, #0 - bne 1f - /* Add UART to the fixmap table */ ldr r1, =xen_fixmap /* r1 := vaddr (xen_fixmap) */ lsr r2, r11, #THIRD_SHIFT @@ -502,9 +501,6 @@ setup_fixmap: mov r4, r4, lsr #(SECOND_SHIFT - 3) /* r4 := Slot for FIXMAP(0) */ mov r3, #0x0 strd r2, r3, [r1, r4] /* Map it in the fixmap's slot */ - - /* Use a virtual address to access the UART. */ - ldr r11, =EARLY_UART_VIRTUAL_ADDRESS #endif /* From patchwork Mon Aug 12 17:30:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171097 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120016ily; Mon, 12 Aug 2019 10:31:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOPWHdliztBdzG209/fNIIe6ce5LYu+rnj72TYzOn5IZ3ofNZsmK5YB7a+w6ca7lOb2wYb X-Received: by 2002:a05:6638:113:: with SMTP id x19mr18868032jao.83.1565631097967; Mon, 12 Aug 2019 10:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631097; cv=none; d=google.com; s=arc-20160816; b=fIdL6IMhuKvThPzE8QoDlrXicUH2o9uAyZfm/yUrUoxGB/xAATw8XjB+hanmtc7vOY 9PBxT40ASY0HkzIw5TMCG8LZFLBKq24Bbr+7UfMOwI81sXW3h/43IdzVrYCxIrLHRuxf ytELboNL8HdVPXL+blSxMpv0pjV+KEkTcW8x5CFND1/FqNj7q5bOt3f6VaQafkkTMngr Q907DGVEOu3Cl6Uq6iKR0qzYIbeVHfpkCmvl258rst4oOq8LEjnT2qUiM1NiPdQmc33X BDFvCeb3qb4uef88iboU13tQSI8x61P7XAyqzOkRK5XIfoad1EvAgeOD/D/Owj00pPCv k4SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=key0p2HeXqhGi80mjYVIrqmvSBp0HUbWEpXOsRB2apQ=; b=N/9LPTZjzezCxsQ0tzvCVaePYCjOxXtz6Hdde7YPQtdhTVANiMTjZRYYaLMnIi2Nrp 8TXKY9YZcxwV2d+M4cBbZMKbQ78YTyCDPs40l6islNfTCRKcy5uoIyTY7RagfvlwHv1z y2N10TTl3VGPirilbkc1l92lRhLNOKZTf9vFr9xdjO6LP3khvC2RsNP9LFwrIjgA3dPm 48/Ej6UXpWwbVOBNgKSnEr06uUFLXgb5Zgd/gy4Ce3EKXtoiK62QzBATHfw0NnObSPyj Z2RgJ1wQzii6pC9d8QIOlNIM4x5IiwOaUIa1mwZuudBJu4W7b1ltQZApO91x3O/vS6VC 8DYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id t11si17427704jai.13.2019.08.12.10.31.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9g-0006uN-EE; Mon, 12 Aug 2019 17:30:48 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9e-0006sA-Be for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:46 +0000 X-Inumbo-ID: ea9bd597-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id ea9bd597-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:45 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 55D921993; Mon, 12 Aug 2019 10:30:45 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A3B8F3F706; Mon, 12 Aug 2019 10:30:44 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:11 +0100 Message-Id: <20190812173019.11956-21-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 20/28] xen/arm32: head: Remove 1:1 mapping as soon as it is not used X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The 1:1 mapping may clash with other parts of the Xen virtual memory layout. At the moment, Xen is handling the clash by only creating a mapping to the runtime virtual address before enabling the MMU. The rest of the mappings (such as the fixmap) will be mapped after the MMU is enabled. However, the code doing the mapping is not safe as it replace mapping without using the Break-Before-Make sequence. As the 1:1 mapping can be anywhere in the memory, it is easier to remove all the entries added as soon as the 1:1 mapping is not used rather than adding the Break-Before-Make sequence everywhere. It is difficult to track where exactly the 1:1 mapping was created without a full rework of create_page_tables(). Instead, introduce a new function remove_identity_mapping() will look where is the top-level entry for the 1:1 mapping and remove it. The new function is only called for the boot CPU. Secondary CPUs will switch directly to the runtime page-tables so there are no need to remove the 1:1 mapping. Note that this still doesn't make the Secondary CPUs path safe but it is not making it worst. Signed-off-by: Julien Grall --- It is very likely we will need to re-introduce the 1:1 mapping to cater secondary CPUs boot and suspend/resume. For now, the attempt is to make boot CPU path fully Arm Arm compliant. Changes in v3: - Remove unused label - Avoid harcoding slots Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 86 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 8f945d318a..34fc9ffcee 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -32,6 +32,10 @@ #define PT_UPPER(x) (PT_##x & 0xf00) #define PT_LOWER(x) (PT_##x & 0x0ff) +/* Convenience defines to get slot used by Xen mapping. */ +#define XEN_FIRST_SLOT first_table_offset(XEN_VIRT_START) +#define XEN_SECOND_SLOT second_table_offset(XEN_VIRT_START) + #if (defined (CONFIG_EARLY_PRINTK)) && (defined (EARLY_PRINTK_INC)) #include EARLY_PRINTK_INC #endif @@ -158,6 +162,13 @@ past_zImage: ldr r0, =primary_switched mov pc, r0 primary_switched: + /* + * The 1:1 map may clash with other parts of the Xen virtual memory + * layout. As it is not used anymore, remove it completely to + * avoid having to worry about replacing existing mapping + * afterwards. + */ + bl remove_identity_mapping bl setup_fixmap #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ @@ -474,12 +485,63 @@ enable_mmu: mov pc, lr ENDPROC(enable_mmu) -setup_fixmap: +/* + * Remove the 1:1 map for the page-tables. It is not easy to keep track + * where the 1:1 map was mapped, so we will look for the top-level entry + * exclusive to the 1:1 map and remove it. + * + * Inputs: + * r9 : paddr(start) + * + * Clobbers r0 - r3 + */ +remove_identity_mapping: + /* r2:r3 := invalid page-table entry */ + mov r2, #0x0 + mov r3, #0x0 /* - * Now we can install the fixmap and dtb mappings, since we - * don't need the 1:1 map any more + * Find the first slot used. Remove the entry for the first + * table if the slot is not XEN_FIRST_SLOT. For slot XEN_FIRST_SLOT, + * the 1:1 mapping was done in the second table. */ - dsb + lsr r1, r9, #FIRST_SHIFT + mov_w r0, LPAE_ENTRY_MASK + and r1, r1, r0 /* r1 := first slot */ + cmp r1, #XEN_FIRST_SLOT + beq 1f + /* It is not in slot 0, remove the entry */ + ldr r0, =boot_pgtable /* r0 := root table */ + lsl r1, r1, #3 /* r1 := Slot offset */ + strd r2, r3, [r0, r1] + b identity_mapping_removed + +1: + /* + * Find the second slot used. Remove the entry for the first + * table if the slot is not XEN_SECOND_SLOT. For slot XEN_SECOND_SLOT, + * it means the 1:1 mapping was not created. + */ + lsr r1, r9, #SECOND_SHIFT + mov_w r0, LPAE_ENTRY_MASK + and r1, r1, r0 /* r1 := second slot */ + cmp r1, #XEN_SECOND_SLOT + beq identity_mapping_removed + /* It is not in slot 1, remove the entry */ + ldr r0, =boot_second /* r0 := second table */ + lsl r1, r1, #3 /* r1 := Slot offset */ + strd r2, r3, [r0, r1] + +identity_mapping_removed: + /* See asm-arm/arm32/flushtlb.h for the explanation of the sequence. */ + dsb nshst + mcr CP32(r0, TLBIALLH) + dsb nsh + isb + + mov pc, lr +ENDPROC(remove_identity_mapping) + +setup_fixmap: #if defined(CONFIG_EARLY_PRINTK) /* Fixmap is only used by early printk */ /* Add UART to the fixmap table */ ldr r1, =xen_fixmap /* r1 := vaddr (xen_fixmap) */ @@ -489,7 +551,6 @@ setup_fixmap: orr r2, r2, #PT_LOWER(DEV_L3) /* r2:r3 := 4K dev map including UART */ mov r3, #0x0 strd r2, r3, [r1, #(FIXMAP_CONSOLE*8)] /* Map it in the first fixmap's slot */ -1: /* Map fixmap into boot_second */ ldr r1, =boot_second /* r1 := vaddr (boot_second) */ @@ -501,19 +562,10 @@ setup_fixmap: mov r4, r4, lsr #(SECOND_SHIFT - 3) /* r4 := Slot for FIXMAP(0) */ mov r3, #0x0 strd r2, r3, [r1, r4] /* Map it in the fixmap's slot */ -#endif - - /* - * Flush the TLB in case the 1:1 mapping happens to clash with - * the virtual addresses used by the fixmap or DTB. - */ - dsb /* Ensure any page table updates made above - * have occurred. */ - isb - mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLB */ - dsb /* Ensure completion of TLB flush */ - isb + /* Ensure any page table updates made above have occurred. */ + dsb nshst +#endif mov pc, lr ENDPROC(setup_fixmap) From patchwork Mon Aug 12 17:30:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171114 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3121911ily; Mon, 12 Aug 2019 10:33:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXsT80VVYcYmqsQ1QXljj6c/T8Sby/RBeH0S+iussN5FxC1oKFC865lVG+cfa+DwudKjcS X-Received: by 2002:a02:7f15:: with SMTP id r21mr34641616jac.120.1565631109354; Mon, 12 Aug 2019 10:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631109; cv=none; d=google.com; s=arc-20160816; b=vG0+hyr6G/cbV84W5dspV9GQ2XaHJLjq3BcZFtGp00LnVwRAYS4758R6ku80foCysl 4RYsc0uH3fTLXyRoOMBNqiXEXc7ZMr6OLI4LF2FHUKpkycfyVG7pT8OXbIdIFYBDbz/v P+/pJSk+tuwYrcT7PZNqLh59NHIN7Jtf0s4xMCpFBD8ytoSXxC5NvJiTXQzUX3guar9c NNziMqzP4YAnxti3dEzDO+dWulH10A9UA3KQU5JxODmMTKIJ+vvb/ToA8g/0iNZgIcP5 JAAYm/McE9MLcn1yE2SVj0H9HTeyN32zHrMj7wKUykaKjTbpwpyQBPAwqhhItQfSGlrn zrww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=YQnWtnj+k7l4DQOhSeQaVkrfCTZPJHAFo5iFqugBerk=; b=PyYYONjXV5bVw8FXemMAJWgb2RApBWoAYX3+MJC33mLQFOUIg4dO0mzFUYVPmWByeD qXFSkjQqykPGXTNcFbg5AypjHpewsC1ndS6Y767rw15LqEO1L71GNrI1aw+rjLcY6Hue 5R9XryeFMVn9eN5mIePb788Pwck2A+Ep6ZHE7/Z5jr8yhtl+1aODaLIMo1KXHQwb/oHC YnfvmD/m4RGWQgS6kd/i/GV+63efwNgSYDwMqwlzv4Do7dUBtrCCNh6koTwNMqwVLK+y Jv4ubp37lVPoDIPmbxBA06sGHh7YRtZ2K/vvZQjY7mxRWTz5KuKNikmKJmYxotlkJhQ7 /D1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id l27si1431149jac.34.2019.08.12.10.31.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9g-0006v6-RG; Mon, 12 Aug 2019 17:30:48 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9f-0006tT-Jc for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:47 +0000 X-Inumbo-ID: eb29bb4c-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id eb29bb4c-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:46 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C15915AB; Mon, 12 Aug 2019 10:30:46 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A9343F706; Mon, 12 Aug 2019 10:30:45 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:12 +0100 Message-Id: <20190812173019.11956-22-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 21/28] xen/arm32: head: Rework and document setup_fixmap() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, the fixmap table is only hooked when earlyprintk is used. This is fine today because in C land, the fixmap is not used by anyone until the the boot CPU is switching to the runtime page-tables. In the future, the boot CPU will not switch between page-tables to avoid TLB incoherency. Thus, the fixmap table will need to be always hooked beofre any use. Let's start doing it now in setup_fixmap(). Lastly, document the behavior and the main registers usage within the function. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - The unused label is now removed in the previous patch - Add Stefano's reviewed-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 34fc9ffcee..ee5c3d2af8 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -541,8 +541,21 @@ identity_mapping_removed: mov pc, lr ENDPROC(remove_identity_mapping) +/* + * Map the UART in the fixmap (when earlyprintk is used) and hook the + * fixmap table in the page tables. + * + * The fixmap cannot be mapped in create_page_tables because it may + * clash with the 1:1 mapping. + * + * Inputs: + * r10: Physical offset + * r11: Early UART base physical address + * + * Clobbers r1 - r4 + */ setup_fixmap: -#if defined(CONFIG_EARLY_PRINTK) /* Fixmap is only used by early printk */ +#if defined(CONFIG_EARLY_PRINTK) /* Add UART to the fixmap table */ ldr r1, =xen_fixmap /* r1 := vaddr (xen_fixmap) */ lsr r2, r11, #THIRD_SHIFT @@ -551,6 +564,7 @@ setup_fixmap: orr r2, r2, #PT_LOWER(DEV_L3) /* r2:r3 := 4K dev map including UART */ mov r3, #0x0 strd r2, r3, [r1, #(FIXMAP_CONSOLE*8)] /* Map it in the first fixmap's slot */ +#endif /* Map fixmap into boot_second */ ldr r1, =boot_second /* r1 := vaddr (boot_second) */ @@ -565,7 +579,7 @@ setup_fixmap: /* Ensure any page table updates made above have occurred. */ dsb nshst -#endif + mov pc, lr ENDPROC(setup_fixmap) From patchwork Mon Aug 12 17:30:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171106 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120265ily; Mon, 12 Aug 2019 10:31:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcQdYDjxWgHyQT2uY84F9AwwA05AIgXwXS/HHPdBCxcWt6RiVEstHNoceccH5ABgR6qkqd X-Received: by 2002:a5e:9403:: with SMTP id q3mr15968187ioj.63.1565631109239; Mon, 12 Aug 2019 10:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631109; cv=none; d=google.com; s=arc-20160816; b=ZmeglCLOGDLG+ywb/SrJ+2w8AjADb/UPfAuyUKAYfdfG5FLk8l1Sc2dmnDBDJcDmew lZ003KWlmnO3yQH2C29rKhJqYIwFH7IPNZ8ZUA6GFtHOeKSni5aPlzvokuK5n6zUMpMM 2Rsao4FVP0sYdYxMk8YTQqmubG9eFq+C5y9BIbkc0yRZYIZaYPX/HKCwFosQaI8zBl+B lkg4JEfeC6LIM9hSTJtfgnsIptOC1udcG4ukx7ar2cNiAPBInN1qnwIEONMMkLoRoh9U WqGosq6Nglihf4LUFkTzaYtjjhB8WdyjF+Bf2qagAyQmGRQfJ9aOIdC4OCQUAdPjNam5 Odww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=vPVhfdN+RjUhqrdYR7UDIk3OFs6iLNzvte4HvESXzFo=; b=WA11GqZEtDD3PtXkBdpUok5jOuCMHUV/0nQU3/86VuErayKEeui9nUOTu2lmkey1w9 9spaaQwuDO9d/4VGXlQCQDOZ9dg7PfRDpwfFfKN1JwjYcCAz3JUIFA0ZCXO676AYOawe UR6ADP8c4bzZL8RIRDrkEYbLySNtLXUcYNoYN+/3emljBMpd8NaBDmyF0HI43zhAkOFL 3fBLDPANBDgGfnf6ha5vGYXPMc0IGg2nXXQ+dBTBitFbAm/dsoXKqyseYswm/f2ErX6Q DUlINtVILmvS1+wQ/vshZqfiUEUUjWbYmkp4U6LunJYa196LP7wAIKMNAOuCdpZihcp+ eMNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id k12si19948386jan.9.2019.08.12.10.31.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9h-0006vt-8I; Mon, 12 Aug 2019 17:30:49 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9f-0006tg-RC for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:47 +0000 X-Inumbo-ID: ebaaf76d-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id ebaaf76d-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:47 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 223711715; Mon, 12 Aug 2019 10:30:47 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 70C5A3F706; Mon, 12 Aug 2019 10:30:46 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:13 +0100 Message-Id: <20190812173019.11956-23-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 22/28] xen/arm32: head: Rework and document launch() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Boot CPU and secondary CPUs will use different entry point to C code. At the moment, the decision on which entry to use is taken within launch(). In order to avoid using conditional instruction and make the call clearer, launch() is reworked to take in parameters the entry point and its arguments. Lastly, document the behavior and the main registers usage within the function. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index ee5c3d2af8..3c18037575 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -174,6 +174,11 @@ primary_switched: /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS #endif + PRINT("- Ready -\r\n") + /* Setup the arguments for start_xen and jump to C world */ + mov r0, r10 /* r0 := Physical offset */ + mov r1, r8 /* r1 := paddr(FDT) */ + ldr r2, =start_xen b launch ENDPROC(start) @@ -238,6 +243,9 @@ secondary_switched: /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS #endif + PRINT("- Ready -\r\n") + /* Jump to C world */ + ldr r2, =start_secondary b launch ENDPROC(init_secondary) @@ -583,19 +591,25 @@ setup_fixmap: mov pc, lr ENDPROC(setup_fixmap) +/* + * Setup the initial stack and jump to the C world + * + * Inputs: + * r0 : Argument 0 of the C function to call + * r1 : Argument 1 of the C function to call + * r2 : C entry point + * + * Clobbers r3 + */ launch: - PRINT("- Ready -\r\n") - - ldr r0, =init_data - add r0, #INITINFO_stack /* Find the boot-time stack */ - ldr sp, [r0] + ldr r3, =init_data + add r3, #INITINFO_stack /* Find the boot-time stack */ + ldr sp, [r3] add sp, #STACK_SIZE /* (which grows down from the top). */ sub sp, #CPUINFO_sizeof /* Make room for CPU save record */ - teq r12, #0 - moveq r0, r10 /* Marshal args: - phys_offset */ - moveq r1, r8 /* - DTB address */ - beq start_xen /* and disappear into the land of C */ - b start_secondary /* (to the appropriate entry point) */ + + /* Jump to C world */ + bx r2 ENDPROC(launch) /* Fail-stop */ From patchwork Mon Aug 12 17:30:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171116 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3124264ily; Mon, 12 Aug 2019 10:35:42 -0700 (PDT) X-Received: by 2002:a5e:c918:: with SMTP id z24mr17000698iol.234.1565631102778; Mon, 12 Aug 2019 10:31:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7atj6EU0GfpSvNwCLM1SbqRnpcv3LU+i5R1cF6b/7g4QNFWtoxulJ/VyQC9LZcqKmV6dd X-Received: by 2002:a5e:c918:: with SMTP id z24mr17000635iol.234.1565631101804; Mon, 12 Aug 2019 10:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631101; cv=none; d=google.com; s=arc-20160816; b=WeaQU8M1LFjEWBj2ApcLwVsGaFPijP4FtS9EWoFQDYYaTeAFK0rRoZpz1k3qTvXJMo B+NHLSG2/HNNew3AuxTjHtY9VZgQyaivKe+Auw6Nx91S7yGd3bToxyQItdaS6s4nlqN8 L3UaCkL6cR+W/s8QMZQDqalhViBZW30HntoXR9YJRWv6acE56GSORyK4YV+GfBVMWtGV scsmNTJ0ug1YLHq9U5T778N0ZS+Z0JUQIxynvfo0WbHsyRJs0rC2E5Ck1ctISAYrPDlL R3K4qdI7F0fxzR9NTWJ54k6GqpmVat8k7SheZV3A3fMOZKdNp0/YOHgTTm8sC9RhAXAZ teBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=jAjlCgDnGJiKnR0+9/uphuRtfbp8Lvc2+KF5nkGdnNA=; b=K/vb73i4LVR7Oz+ts5j/ik8XsGBAeic43D2f5zMcqjMz1ZoGnAWCqeN0wZqCVHvJSQ ZiuLITd0fgBGZXeRCIEbWtOtIwo7pSGCHI32/Aht/w8tvrw2EmIouN0BWmKf4C3znYEo +86hwXSKSaGafHe0w57i8qpXkAN2hf+epBfjGS32zVQSSJ4MRgJh8qayg09ugP5kzxi8 C/366VV3uNdRDySEMWDnbvn6EfwP1JTfJmrHb9koVAdksee0rqffTvP4NmU1uxJfRlfQ Du99JQ/9msonmtkAheS0P01QXNv90nsLgI5q9aAuo9ZdsOiJn9gKbNZg+X5WiE0zG+EW AvmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 185si14299865jau.87.2019.08.12.10.31.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9i-0006y6-JX; Mon, 12 Aug 2019 17:30:50 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9h-0006vS-25 for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:49 +0000 X-Inumbo-ID: ec34de73-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id ec34de73-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:48 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 07E48174E; Mon, 12 Aug 2019 10:30:48 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 566DF3F706; Mon, 12 Aug 2019 10:30:47 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:14 +0100 Message-Id: <20190812173019.11956-24-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 23/28] xen/arm32: head: Setup HTTBR in enable_mmu() and add missing isb X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, HTTBR is setup in create_page_tables(). This is fine as it is called by every CPUs. However, such assumption may not hold in the future. To make change easier, the HTTBR is not setup in enable_mmu(). Take the opportunity to add the missing isb() to ensure the HTTBR is seen before the MMU is turned on. Lastly, the only use of r5 in create_page_tables() is now removed. So the register can be removed from the clobber list of the function. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Move the comment in the correct place - r5 is not cloberred anymore Changes in v2: - Patch added --- xen/arch/arm/arm32/head.S | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 3c18037575..2317fb8855 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -359,7 +359,7 @@ ENDPROC(cpu_init) * r9 : paddr(start) * r10: phys offset * - * Clobbers r0 - r6 + * Clobbers r0 - r4, r6 * * Register usage within this function: * r6 : Identity map in place @@ -374,11 +374,8 @@ create_page_tables: 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) */ - mov r5, #0 /* r4:r5 is paddr (boot_pagetable) */ - mcrr CP64(r4, r5, HTTBR) /* Setup boot_pgtable: */ ldr r1, =boot_second @@ -484,6 +481,13 @@ enable_mmu: mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLBs */ dsb nsh + /* Write Xen's PT's paddr into the HTTBR */ + ldr r0, =boot_pgtable + add r0, r0, r10 /* r0 := paddr (boot_pagetable) */ + mov r1, #0 /* r0:r1 is paddr (boot_pagetable) */ + mcrr CP64(r0, r1, HTTBR) + isb + mrc CP32(r0, HSCTLR) /* Enable MMU and D-cache */ orr r0, r0, #(SCTLR_Axx_ELx_M|SCTLR_Axx_ELx_C) From patchwork Mon Aug 12 17:30:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171149 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp507493ily; Mon, 12 Aug 2019 23:49:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxc9w7MIdj9QbHbBxmPY6vd6d0oQnuA69LjZZTXOon+Me3WAwH2ETYdczhGr2ngDs/43WEQ X-Received: by 2002:a6b:790d:: with SMTP id i13mr36828688iop.27.1565678958237; Mon, 12 Aug 2019 23:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565678958; cv=none; d=google.com; s=arc-20160816; b=XahNJNXw8Z9Q2Swj8xsNPT0RoJlkFrCKfNSg/LYt8r+sHYtPhjufdH2yHY9Ergn2hX 4Ldnlg4sP71TzTSM+A7TTFL2l5F3FxW0VO8Zg93/CstwS9keISS4y8FsxCqs6pyeMbDO khkNsOPm342ZMVw91FMB3O4gIq5C+ZFCCCfSV3NEQOy+KlOqMXxk/bWVWYXQ7FiPK49l 34BPyR+t8yT1+9x+0YV094d9azCIjKJiv09MvoOaZThQEwKrWHLCkSsMv9xN3Blucohd PrGW50v8hyf67UDfJJIdpfbkbBvUb4PCnQmRPVOLTWDIb6CfIFBJ5Qi1s8OAk3bINw/Z GjGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=CBYjp1+0JYemoE6+f5tVuiaWXPszHWMLqoR1sPlDpeg=; b=LxYucDzt2jLSoH0Ef1zHf+dqbkfX5zDrkZ7KxjYR6YvI9QUTCQ5FHw78BRxZUndTIW PoINCVXsu5ZtfIhGfSRrMAdrU/gcOuB826f7zNNuVC6W5ag3e0UycbpqqZVCi3SkP63r qLt0JAvIp91u3vBD7vzwyPIKgQVhu1blbP5EXuHf8xYQaraCx6w/9r2Q6w9dX5q9E0dj JqQ0LmwHAV+JFi0DeUOSIxotKEz8cQzAHXk93OTo2AT3r3vhfLgLsWtYdj/yAI6+VsUG Faq7MKk0oP5Cqi63zzpJc1+CWMxC4eULHicTb7t39VbAXVFDFKbGXsbyNx6vumXftwuw px1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u12si13693639jap.79.2019.08.12.23.49.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:49:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQbh-0000O3-WC; Tue, 13 Aug 2019 06:48:33 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQbg-0000Nm-4W for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:48:32 +0000 X-Inumbo-ID: ecc2ce76-bd26-11e9-b9e0-5fdaea4ddd45 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id ecc2ce76-bd26-11e9-b9e0-5fdaea4ddd45; Mon, 12 Aug 2019 17:30:49 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E1FA51993; Mon, 12 Aug 2019 10:30:48 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3C6BB3F706; Mon, 12 Aug 2019 10:30:48 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:15 +0100 Message-Id: <20190812173019.11956-25-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 24/28] xen/arm: Zero BSS after the MMU and D-cache is turned on X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment BSS is zeroed before the MMU and D-Cache is turned on. In other words, the cache will be bypassed when zeroing the BSS section. On Arm64, per the Image protocol [1], the state of the cache for BSS region is not known because it is not part of the "loaded kernel image". On Arm32, the boot protocol [2] does not mention anything about the state of the cache. Therefore, it should be assumed that it is not known for BSS region. This means that the cache will need to be invalidated twice for the BSS region: 1) Before zeroing to remove any dirty cache line. Otherwise they may get evicted while zeroing and therefore overriding the value. 2) After zeroing to remove any cache line that may have been speculated. Otherwise when turning on MMU and D-Cache, the CPU may see old values. At the moment, the only reason to have BSS zeroed early is because the boot page tables are part of it. To avoid the two cache invalidations, it would be better if the boot page tables are part of the "loaded kernel image" and therefore be zeroed when loading the image into memory. A good candidate is the section .data.page_aligned. A new macro DEFINE_BOOT_PAGE_TABLE is introduced to create and mark page-tables used before BSS is zeroed. This includes all boot_* but also xen_fixmap as zero_bss() will print a message when earlyprintk is enabled. [1] linux/Documentation/arm64/booting.txt [2] linux/Documentation/arm/Booting Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Add missing signed-off - Clarify commit message - Add arm32 parts --- xen/arch/arm/arm32/head.S | 11 +++-------- xen/arch/arm/arm64/head.S | 7 +++---- xen/arch/arm/mm.c | 23 +++++++++++++++++------ 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 2317fb8855..e86a9f95e7 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -153,7 +153,6 @@ past_zImage: mov r12, #0 /* r12 := is_secondary_cpu */ bl check_cpu_mode - bl zero_bss bl cpu_init bl create_page_tables bl enable_mmu @@ -174,6 +173,7 @@ primary_switched: /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS #endif + bl zero_bss PRINT("- Ready -\r\n") /* Setup the arguments for start_xen and jump to C world */ mov r0, r10 /* r0 := Physical offset */ @@ -284,17 +284,12 @@ ENDPROC(check_cpu_mode) /* * Zero BSS * - * Inputs: - * r10: Physical offset - * * Clobbers r0 - r3 */ zero_bss: PRINT("- Zero BSS -\r\n") - ldr r0, =__bss_start /* Load start & end of bss */ - ldr r1, =__bss_end - add r0, r0, r10 /* Apply physical offset */ - add r1, r1, r10 + ldr r0, =__bss_start /* r0 := vaddr(__bss_start) */ + ldr r1, =__bss_end /* r1 := vaddr(__bss_start) */ mov r2, #0 1: str r2, [r0], #4 diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index a6f3aa4ee5..f2a0e1d3b0 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -309,7 +309,6 @@ real_start_efi: mov x22, #0 /* x22 := is_secondary_cpu */ bl check_cpu_mode - bl zero_bss bl cpu_init bl create_page_tables bl enable_mmu @@ -330,6 +329,7 @@ primary_switched: /* Use a virtual address to access the UART. */ ldr x23, =EARLY_UART_VIRTUAL_ADDRESS #endif + bl zero_bss PRINT("- Ready -\r\n") /* Setup the arguments for start_xen and jump to C world */ mov x0, x20 /* x0 := Physical offset */ @@ -432,7 +432,6 @@ ENDPROC(check_cpu_mode) * Zero BSS * * Inputs: - * x20: Physical offset * x26: Do we need to zero BSS? * * Clobbers x0 - x3 @@ -442,8 +441,8 @@ zero_bss: cbnz x26, skip_bss PRINT("- Zero BSS -\r\n") - load_paddr x0, __bss_start /* Load paddr of start & end of bss */ - load_paddr x1, __bss_end + ldr x0, =__bss_start /* x0 := vaddr(__bss_start) */ + ldr x1, =__bss_end /* x1 := vaddr(__bss_start) */ 1: str xzr, [x0], #8 cmp x0, x1 diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index e1cdeaaf2f..65552da4ba 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -62,6 +62,17 @@ mm_printk(const char *fmt, ...) {} } while (0); #endif +/* + * Macros to define page-tables: + * - DEFINE_BOOT_PAGE_TABLE is used to define page-table that are used + * in assembly code before BSS is zeroed. + * - DEFINE_PAGE_TABLE{,S} are used to define one or multiple + * page-tables to be used after BSS is zeroed (typically they are only used + * in C). + */ +#define DEFINE_BOOT_PAGE_TABLE(name) \ +lpae_t __aligned(PAGE_SIZE) __section(".data.page_aligned") name[LPAE_ENTRIES] + #define DEFINE_PAGE_TABLES(name, nr) \ lpae_t __aligned(PAGE_SIZE) name[LPAE_ENTRIES * (nr)] @@ -90,13 +101,13 @@ lpae_t __aligned(PAGE_SIZE) name[LPAE_ENTRIES * (nr)] * Finally, if EARLY_PRINTK is enabled then xen_fixmap will be mapped * by the CPU once it has moved off the 1:1 mapping. */ -DEFINE_PAGE_TABLE(boot_pgtable); +DEFINE_BOOT_PAGE_TABLE(boot_pgtable); #ifdef CONFIG_ARM_64 -DEFINE_PAGE_TABLE(boot_first); -DEFINE_PAGE_TABLE(boot_first_id); +DEFINE_BOOT_PAGE_TABLE(boot_first); +DEFINE_BOOT_PAGE_TABLE(boot_first_id); #endif -DEFINE_PAGE_TABLE(boot_second); -DEFINE_PAGE_TABLE(boot_third); +DEFINE_BOOT_PAGE_TABLE(boot_second); +DEFINE_BOOT_PAGE_TABLE(boot_third); /* Main runtime page tables */ @@ -149,7 +160,7 @@ static __initdata int xenheap_first_first_slot = -1; */ static DEFINE_PAGE_TABLES(xen_second, 2); /* First level page table used for fixmap */ -DEFINE_PAGE_TABLE(xen_fixmap); +DEFINE_BOOT_PAGE_TABLE(xen_fixmap); /* First level page table used to map Xen itself with the XN bit set * as appropriate. */ static DEFINE_PAGE_TABLE(xen_xenmap); From patchwork Mon Aug 12 17:30:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171155 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp512521ily; Mon, 12 Aug 2019 23:55:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqApSBs6n4NoLHFhQyUeEbrp8PC5q+LIqlaf4BhvwCT/irniQLFUztr6vj5ovT++NHhOFI X-Received: by 2002:a6b:ea02:: with SMTP id m2mr17480784ioc.155.1565679345574; Mon, 12 Aug 2019 23:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565679345; cv=none; d=google.com; s=arc-20160816; b=dLleHLuES0G+1+7ykLWaC2Pp39seJmlqzYV+hXLZsd1N95lQTI5vKsp61tnxBunMqO bWTWMjosFFZnL4GeNwPED2wLa3I/Isfc7/lfa9txDIEWZ+26GYMytTQTfC5kogZbvWxZ xLLynF0FhSUNm1W5adLa5TnCi3OcRW08YjXvoxrj9sMmSWYqMaXAaZX1UXvh/QplUe+T 8fYe/kFBp+xeezeg150gbcOX5A3YqrIdM0LpGWFnfLlYOkchasSkPZNrNzCqIQhHNfzK mUZVAGRfthefyl2pTC+KfAlKCdI4c0mVTwbLJKsimkxv311KGfiL1bjnzCay4G38/zQb PzRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=puTHP0rFsm4tqD9k5UNMBJbVV1Uu69rFQ3UbpOENxT4=; b=xgcwRcGlY4Yr7uFPbgquR6JbzKzb5iQc2t8NLbzTdqSdXgH4KLd+yb3lXmd74KkwUZ YDPzrn22Ed8gfVC1UJ93MNCqbR7oXWYpVdWO7G651EZWDMNfhWNZM0fGUlJARYeWgOxr ukubm7X/5yfQbGue/pQ3Bd9zfsaWksDZyQSyxqjdw8+ddwiEqfb/tVHkPxUfd6m8Et7U dK2INZp2Fe1llwKigKHlUeBoI8TGYVl4ErE9T1Qu16hdV2vzznY+FIwcPa+IIa9DgAk2 fTItUSVTXNbkvaTMqvbSfeTLlBjAqM1YG1sVG1AtbG+c+Uen7TJyMQLGn430j5YZsCd+ gwJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id j11si30047608ioe.156.2019.08.12.23.55.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 23:55:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQhw-0003Mp-BR; Tue, 13 Aug 2019 06:55:00 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQhv-0003M1-8t for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:54:59 +0000 X-Inumbo-ID: ed4c28b0-bd26-11e9-b33e-57ddb43ce05f Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id ed4c28b0-bd26-11e9-b33e-57ddb43ce05f; Mon, 12 Aug 2019 17:30:49 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C885915AB; Mon, 12 Aug 2019 10:30:49 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 22ED23F706; Mon, 12 Aug 2019 10:30:49 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:16 +0100 Message-Id: <20190812173019.11956-26-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 25/28] xen/arm64: head: Introduce macros to create table and mapping entry X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, any update to the boot-pages are open-coded. This is making more difficult to understand the logic of a function as each update roughly requires 6 instructions. To ease the readability, two new macros are introduced: - create_table_entry: Create a page-table entry in a given table. This can work at any level. - create_mapping_entry: Create a mapping entry in a given table. None of the users will require to map at any other level than 3rd (i.e page granularity). So the macro is supporting support 3rd level mapping. Furthermore, the two macros are capable to work independently of the state of the MMU. Lastly, take the opportunity to replace open-coded version in setup_fixmap() by the two new macros. The ones in create_page_tables() will be replaced in a follow-up patch. Signed-off-by: Julien Grall --- Changes in v3: - Patch added --- xen/arch/arm/arm64/head.S | 83 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index f2a0e1d3b0..f4177dbba1 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -492,6 +492,68 @@ cpu_init: ENDPROC(cpu_init) /* + * Macro to create a page table entry in \ptbl to \tbl + * + * ptbl: table symbol where the entry will be created + * tbl: table symbol to point to + * virt: virtual address + * shift: #imm page table shift + * tmp1: scratch register + * tmp2: scratch register + * tmp3: scratch register + * + * Preserves \virt + * Clobbers \tmp1, \tmp2, \tmp3 + * + * Also use x20 for the phys offset. + * + * Note that all parameters using registers should be distinct. + */ +.macro create_table_entry, ptbl, tbl, virt, shift, tmp1, tmp2, tmp3 + lsr \tmp1, \virt, #\shift + and \tmp1, \tmp1, #LPAE_ENTRY_MASK/* \tmp1 := slot in \tlb */ + + load_paddr \tmp2, \tbl + mov \tmp3, #PT_PT /* \tmp3 := right for linear PT */ + orr \tmp3, \tmp3, \tmp2 /* + \tlb paddr */ + + adr_l \tmp2, \ptbl + + str \tmp3, [\tmp2, \tmp1, lsl #3] +.endm + +/* + * Macro to create a mapping entry in \tbl to \phys. Only mapping in 3rd + * level table (i.e page granularity) is supported. + * + * tbl: table symbol where the entry will be created + * virt: virtual address + * phys: physical address (should be page aligned) + * tmp1: scratch register + * tmp2: scratch register + * tmp3: scratch register + * type: mapping type. If not specified it will be normal memory (PT_MEM_L3) + * + * Preserves \virt, \phys + * Clobbers \tmp1, \tmp2, \tmp3 + * + * Note that all parameters using registers should be distinct. + */ +.macro create_mapping_entry, tbl, virt, phys, tmp1, tmp2, tmp3, type=PT_MEM_L3 + and \tmp3, \phys, #THIRD_MASK /* \tmp3 := PAGE_ALIGNED(phys) */ + + lsr \tmp1, \virt, #THIRD_SHIFT + and \tmp1, \tmp1, #LPAE_ENTRY_MASK/* \tmp1 := slot in \tlb */ + + mov \tmp2, #\type /* \tmp2 := right for section PT */ + orr \tmp2, \tmp2, \tmp3 /* + PAGE_ALIGNED(phys) */ + + adr_l \tmp3, \tbl + + str \tmp2, [\tmp3, \tmp1, lsl #3] +.endm + +/* * Rebuild the boot pagetable's first-level entries. The structure * is described in mm.c. * @@ -735,28 +797,17 @@ ENDPROC(remove_identity_mapping) * x20: Physical offset * x23: Early UART base physical address * - * Clobbers x1 - x4 + * Clobbers x0 - x3 */ setup_fixmap: #ifdef CONFIG_EARLY_PRINTK /* Add UART to the fixmap table */ - ldr x1, =xen_fixmap /* x1 := vaddr (xen_fixmap) */ - lsr x2, x23, #THIRD_SHIFT - lsl x2, x2, #THIRD_SHIFT /* 4K aligned paddr of UART */ - mov x3, #PT_DEV_L3 - orr x2, x2, x3 /* x2 := 4K dev map including UART */ - str x2, [x1, #(FIXMAP_CONSOLE*8)] /* Map it in the first fixmap's slot */ + ldr x0, =EARLY_UART_VIRTUAL_ADDRESS + create_mapping_entry xen_fixmap, x0, x23, x1, x2, x3, type=PT_DEV_L3 #endif - /* Map fixmap into boot_second */ - ldr x4, =boot_second /* x4 := vaddr (boot_second) */ - load_paddr x2, xen_fixmap - mov x3, #PT_PT - orr x2, x2, x3 /* x2 := table map of xen_fixmap */ - ldr x1, =FIXMAP_ADDR(0) - lsr x1, x1, #(SECOND_SHIFT - 3) /* x1 := Slot for FIXMAP(0) */ - str x2, [x4, x1] /* Map it in the fixmap's slot */ - + ldr x0, =FIXMAP_ADDR(0) + create_table_entry boot_second, xen_fixmap, x0, SECOND_SHIFT, x1, x2, x3 /* Ensure any page table updates made above have occurred. */ dsb nshst From patchwork Mon Aug 12 17:30:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171098 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120076ily; Mon, 12 Aug 2019 10:31:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/q28Cb5NyEb9f6TD73Ku3gOw7zVyEf9hOgunnPmWoTNqlJ74TsHL4hKdnaW2vBrve3dn4 X-Received: by 2002:a05:6602:22ce:: with SMTP id e14mr9482046ioe.290.1565631100237; Mon, 12 Aug 2019 10:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631100; cv=none; d=google.com; s=arc-20160816; b=QXB3H51JL16j+KbZDXH5nMM1oKlu4rtLDo15vR5jFrYHYmOZAwEG5TQhsNuOPdfSk3 KkqhqSGV7Xhu+cWuw38nYJZhVwoARIJ5q7p3e3t6783/gXREptwL3xpn4AHPB5SPxxZP csQEUboat1RgwozbPDcQ5ss3txoIqjYv6t+zm8LzzFmCA7C736R+WMMbXh2P34Y0YyPZ pu8/NAtpXC79q/JGBWCMPBEasyvl6EQ/PEkL2JPMUpT0ohZC8inryC5b6Oz2iyQC1kYG FckklJrNuwe+Kasww/Ql/tIkphz64nvern1V+r5gRvdUI8+OMEy13K1oc5tQIfLefk94 s7Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=dDRW0EyOLAQTTxXzzDF82v1k/ldaPcU4iqT9gA+grmQ=; b=TDrfwvIJ4sqExlgln3pZ4XNKVHnRo/qgx2+UWE5i4sEs6oAb22TGu5huBKXKxNgavW csrD8cMyvi5C6AjfEBN96XYbBp+cnFVsVJZcN6YOc/yU3/ya1llWM8+hmR7Qjm/UOGBp rvF2V4oivzRCJG/xRg6Y+6Zcv0e8xbnuq/y3Vm2k6a+Mt05wQhAWWgJLKMA312OfabdD 0qDBkCR/nn1hALllW6UzFWZZn31WYN8hGpfnNv+wCllQ0vuTyQh68E64RrTcDgbiqT5R z2DxMwgix8znzd5lmLjZpfUx3h3PxLwj0sZClb8mRbuFPS42sizdpeODpqRMaGRiWEut MEkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 191si143082350jay.46.2019.08.12.10.31.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9l-00072e-9Z; Mon, 12 Aug 2019 17:30:53 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9k-00070q-CL for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:52 +0000 X-Inumbo-ID: eddeca18-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id eddeca18-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:50 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C94461715; Mon, 12 Aug 2019 10:30:50 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 08ABE3F706; Mon, 12 Aug 2019 10:30:49 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:17 +0100 Message-Id: <20190812173019.11956-27-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 26/28] xen/arm64: head: Use a page mapping for the 1:1 mapping in create_page_tables() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment the function create_page_tables() will use 1GB/2MB mapping for the identity mapping. As we don't know what is present before and after Xen in memory, we may end up to map device/reserved-memory with cacheable memory. This may result to mismatched attributes as other users may access the same region differently. To prevent any issues, we should only map the strict minimum in the 1:1 mapping. A check in xen.lds.S already guarantees anything necessary for turning on the MMU fits in a page (at the moment 4K). As only one page will be mapped for the 1:1 mapping, it is necessary to pre-allocate a page for the 3rd level table. For simplicity, all the tables that may be necessary for setting up the 1:1 mapping are linked together in advance. They will then be linked to the boot page tables at the correct level. Signed-off-by: Julien Grall --- Changes in v3: - Patch added --- xen/arch/arm/arm64/head.S | 176 ++++++++++++++++++++-------------------------- xen/arch/arm/mm.c | 2 + 2 files changed, 78 insertions(+), 100 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index f4177dbba1..1e5b1035b8 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -566,100 +566,17 @@ ENDPROC(cpu_init) * x19: paddr(start) * x20: phys offset * - * Clobbers x0 - x4, x25 - * - * Register usage within this function: - * x25: Identity map in place + * Clobbers x0 - x4 */ create_page_tables: - /* - * 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 */ - - load_paddr x4, boot_pgtable - - /* Setup boot_pgtable: */ - load_paddr x1, boot_first - - /* ... map boot_first in boot_pgtable[0] */ - mov x3, #PT_PT /* x2 := table map of boot_first */ - orr x2, x1, x3 /* + rights for linear PT */ - str x2, [x4, #0] /* Map it in slot 0 */ - - /* ... map of paddr(start) in boot_pgtable+boot_first_id */ - lsr x1, x19, #ZEROETH_SHIFT/* Offset of base paddr in boot_pgtable */ - cbz x1, 1f /* It's in slot 0, map in boot_first - * or boot_second later on */ - - /* - * Level zero does not support superpage mappings, so we have - * to use an extra first level page in which we create a 1GB mapping. - */ - load_paddr x2, boot_first_id - - mov x3, #PT_PT /* x2 := table map of boot_first_id */ - orr x2, x2, x3 /* + rights for linear PT */ - str x2, [x4, x1, lsl #3] - - load_paddr x4, boot_first_id - - lsr x1, x19, #FIRST_SHIFT /* x1 := Offset of base paddr in boot_first_id */ - lsl x2, x1, #FIRST_SHIFT /* x2 := Base address for 1GB mapping */ - mov x3, #PT_MEM /* x2 := Section map */ - orr x2, x2, x3 - and x1, x1, #LPAE_ENTRY_MASK /* x1 := Slot offset */ - str x2, [x4, x1, lsl #3] /* Mapping of paddr(start) */ - mov x25, #1 /* x25 := identity map now in place */ - -1: /* Setup boot_first: */ - load_paddr x4, boot_first /* Next level into boot_first */ - - /* ... map boot_second in boot_first[0] */ - load_paddr x1, boot_second - mov x3, #PT_PT /* x2 := table map of boot_second */ - orr x2, x1, x3 /* + rights for linear PT */ - 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 */ - - lsl x2, x2, #FIRST_SHIFT /* Base address for 1GB mapping */ - mov x3, #PT_MEM /* x2 := Section map */ - orr x2, x2, x3 - str x2, [x4, x1, lsl #3] /* Create mapping of paddr(start)*/ - mov x25, #1 /* x25 := identity map now in place */ - -1: /* Setup boot_second: */ - load_paddr x4, boot_second - - /* ... map boot_third in boot_second[1] */ - load_paddr x1, boot_third - mov x3, #PT_PT /* x2 := table map of boot_third */ - orr x2, x1, x3 /* + rights for linear PT */ - 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 - b.eq virtphys_clash /* It's in slot 1, which we cannot handle */ - - lsl x2, x2, #SECOND_SHIFT /* Base address for 2MB mapping */ - mov x3, #PT_MEM /* x2 := Section map */ - orr x2, x2, x3 - str x2, [x4, x1, lsl #3] /* Create mapping of paddr(start)*/ - mov x25, #1 /* x25 := identity map now in place */ + /* Prepare the page-tables for mapping Xen */ + ldr x0, =XEN_VIRT_START + create_table_entry boot_pgtable, boot_first, x0, ZEROETH_SHIFT, x1, x2, x3 + create_table_entry boot_first, boot_second, x0, FIRST_SHIFT, x1, x2, x3 + create_table_entry boot_second, boot_third, x0, SECOND_SHIFT, x1, x2, x3 -1: /* Setup boot_third: */ - load_paddr x4, boot_third + /* Map Xen */ + adr_l x4, boot_third lsr x2, x19, #THIRD_SHIFT /* Base address for 4K mapping */ lsl x2, x2, #THIRD_SHIFT @@ -674,21 +591,80 @@ create_page_tables: cmp x1, #(LPAE_ENTRIES<<3) /* 512 entries per page */ b.lt 1b - /* Defer fixmap and dtb mapping until after paging enabled, to - * avoid them clashing with the 1:1 mapping. */ + /* + * 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 + bne 1f + ret +1: + /* + * Only the first page of Xen will be part of the 1:1 mapping. + * All the boot_*_id tables are linked together even if they may + * not be all used. They will then be linked to the boot page + * tables at the correct level. + */ + create_table_entry boot_first_id, boot_second_id, x19, FIRST_SHIFT, x0, x1, x2 + create_table_entry boot_second_id, boot_third_id, x19, SECOND_SHIFT, x0, x1, x2 + create_mapping_entry boot_third_id, x19, x19, x0, x1, x2 + + /* + * Find the zeroeth slot used. Link boot_first_id into + * boot_pgtable if the slot is not XEN_ZEROETH_SLOT. For slot + * XEN_ZEROETH_SLOT, the tables associated with the 1:1 mapping + * will need to be linked in boot_first or boot_second. + */ + lsr x0, x19, #ZEROETH_SHIFT /* x0 := zeroeth slot */ + cmp x0, #XEN_ZEROETH_SLOT + beq 1f + /* + * It is not in slot XEN_ZEROETH_SLOT. Link boot_first_id + * into boot_pgtable. + */ + create_table_entry boot_pgtable, boot_first_id, x19, ZEROETH_SHIFT, x0, x1, x2 + ret + +1: + /* + * Find the first slot used. Link boot_second_id into boot_first + * if the slot is not XEN_FIRST_SLOT. For slot XEN_FIRST_SLOT, + * the tables associated with the 1:1 mapping will need to be + * linked in boot_second. + */ + lsr x0, x19, #FIRST_SHIFT + and x0, x0, #LPAE_ENTRY_MASK /* x0 := first slot */ + cmp x0, #XEN_FIRST_SLOT + beq 1f + /* + * It is not in slot XEN_FIRST_SLOT. Link boot_second_id into + * boot_first + */ + create_table_entry boot_first, boot_second_id, x19, FIRST_SHIFT, x0, x1, x2 + ret - /* boot pagetable setup complete */ +1: + /* + * Find the second slot used. Link boot_third_id into boot_second + * if the slot is not XEN_SECOND_SLOT. For slot XEN_SECOND_SLOT, + * Xen is not yet able to handle it. + */ + lsr x0, x19, #SECOND_SHIFT + and x0, x0, #LPAE_ENTRY_MASK /* x0 := first slot */ + cmp x0, #XEN_SECOND_SLOT + beq virtphys_clash + /* + * It is not in slot XEN_SECOND_SLOT. Link boot_third_id into + * boot_second. + */ + create_table_entry boot_second, boot_third_id, x19, SECOND_SHIFT, x0, x1, x2 + ret - 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") b fail - -1: - ret ENDPROC(create_page_tables) /* diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 65552da4ba..72ffea7472 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -105,6 +105,8 @@ DEFINE_BOOT_PAGE_TABLE(boot_pgtable); #ifdef CONFIG_ARM_64 DEFINE_BOOT_PAGE_TABLE(boot_first); DEFINE_BOOT_PAGE_TABLE(boot_first_id); +DEFINE_BOOT_PAGE_TABLE(boot_second_id); +DEFINE_BOOT_PAGE_TABLE(boot_third_id); #endif DEFINE_BOOT_PAGE_TABLE(boot_second); DEFINE_BOOT_PAGE_TABLE(boot_third); From patchwork Mon Aug 12 17:30:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171115 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3124224ily; Mon, 12 Aug 2019 10:35:40 -0700 (PDT) X-Received: by 2002:a5e:d51a:: with SMTP id e26mr14669890iom.71.1565631100654; Mon, 12 Aug 2019 10:31:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzoKDsrIGW/JkiFunfqePc/jGE2Wmr0R5X/7v8aWed319ilFCTbvq1xFtdWlb9y6IOq6LEk X-Received: by 2002:a5e:d51a:: with SMTP id e26mr14669818iom.71.1565631099585; Mon, 12 Aug 2019 10:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631099; cv=none; d=google.com; s=arc-20160816; b=DeEEJJj5S63FZbuUES/MldczJ6qPXrMgbLcvCnSsxWbUACkgeZUANTh2RVLy/YbiCV WeAbpEVtfRxmVVUukq/CMe4wbCsEeouokS/8F4M3nkxSz6d+rzrHbqd5x4OPy4y2uUfX iYq2bljjY1lBTh8IYh+y3fIsizRCdEV+uafoG14nE5CRbFVGEAwEUZlOVfGesvIm0XbK qdLBEmEIxciWMLFuzWbn+yBQL5cS/Gl9+u8ndBMO+bXnGFbZcE5RHu87atgtge1QJ5p2 xC8izczFKXxZzPLnZn1FOqugQhOWyvEZOZwpqoZl1jyQzfCbIBVqyeM2rQ/uphZepWfj 3E2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=stP6R78oOixtoK7B5SGg1AG+0Y85JxxM4tdwrXSjw+A=; b=KlTOxENPMd2pEtU8opaKVVAzr6nOQ//INzi5tdOcAYkjOWkiCpyWLykGAIhLTNmQqs qfK/WBc9Ii+RSYjr/OhzSDN5ZqnFApJYCsGeR0RJgaO92/jUccCGpKQaT64M+MDXEGE5 /c6zXlpJOCV41CJKS4Do3VD30bXVVFb2071+gT3UN77SPABigeEtezm8Axe9FnG4Xbh0 EDTrbju9azHLxLTZDjipWADM9o2oFetxUsuMMp5+Uw26qOGl5BqCWvcDFKb4zp37i8K7 1a1upVe+BT7tbB0ZFSlX8ecsks6XX5zcSWEC2lwF0ZUxvpTvTMLOQZbndMZFjMab++3s QQWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id d28si73400051jaa.64.2019.08.12.10.31.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9m-000759-Ln; Mon, 12 Aug 2019 17:30:54 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9k-00071A-L9 for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:52 +0000 X-Inumbo-ID: ee6c9aa8-bd26-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id ee6c9aa8-bd26-11e9-8980-bc764e045a96; Mon, 12 Aug 2019 17:30:51 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AEA2A174E; Mon, 12 Aug 2019 10:30:51 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 090EA3F706; Mon, 12 Aug 2019 10:30:50 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:18 +0100 Message-Id: <20190812173019.11956-28-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 27/28] xen/arm32: head: Introduce macros to create table and mapping entry X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, any update to the boot-pages are open-coded. This is making more difficult to understand the logic of a function as each update roughly requires 6 instructions. To ease the readability, two new macros are introduced: - create_table_entry: Create a page-table entry in a given table. This can work at any level. - create_mapping_entry: Create a mapping entry in a given table. None of the users will require to map at any other level than 3rd (i.e page granularity). So the macro is supporting support 3rd level mapping. Unlike arm64, there are no easy way to have a PC relative address within the range -/+4GB. In order to have the possibility to use the macro in context with MMU on/off, the user needs to tell the state of the MMU. Lastly, take the opportunity to replace open-coded version in setup_fixmap() by the two new macros. The ones in create_page_tables() will be replaced in a follow-up patch. Signed-off-by: Julien Grall --- The adr_l hack is a bit ugly, but I can't find nicer way to avoid code duplication and improve readability. Changes in v3: - Patch added --- xen/arch/arm/arm32/head.S | 108 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 19 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index e86a9f95e7..6d03fecaf2 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -50,6 +50,20 @@ .endm /* + * There are no easy way to have a PC relative address within the range + * +/- 4GB of the PC. + * + * This macro workaround it by asking the user to tell whether the MMU + * has been turned on or not. + */ +.macro adr_l, dst, sym, mmu + ldr \dst, =\sym + .if \mmu == 0 + add \dst, \dst, r10 + .endif +.endm + +/* * Common register usage in this file: * r0 - * r1 - @@ -342,6 +356,76 @@ cpu_init_done: ENDPROC(cpu_init) /* + * Macro to create a page table entry in \ptbl to \tbl + * + * ptbl: table symbol where the entry will be created + * tbl: table symbol to point to + * virt: virtual address + * shift: #imm page table shift + * mmu: Is the MMU turned on/off. If not specified it will be off + * + * Preserves \virt + * Clobbers r1 - r4 + * + * Also use r10 for the phys offset. + * + * Note that \virt should be in a register other than r1 - r4 + */ +.macro create_table_entry, ptbl, tbl, virt, shift, mmu=0 + lsr r1, \virt, #\shift + mov_w r2, LPAE_ENTRY_MASK + and r1, r1, r2 /* r1 := slot in \tlb */ + lsl r1, r1, #3 /* r1 := slot offset in \tlb */ + + ldr r4, =\tbl + add r4, r4, r10 /* r4 := paddr(\tlb) */ + + mov r2, #PT_PT /* r2:r3 := right for linear PT */ + orr r2, r2, r4 /* + \tlb paddr */ + mov r3, #0 + + adr_l r4, \ptbl, \mmu + + strd r2, r3, [r4, r1] +.endm + +/* + * Macro to create a mapping entry in \tbl to \paddr. Only mapping in 3rd + * level table (i.e page granularity) is supported. + * + * tbl: table symbol where the entry will be created + * virt: virtual address + * phys: physical address + * type: mapping type. If not specified it will be normal memory (PT_MEM_L3) + * mmu: Is the MMU turned on/off. If not specified it will be off + * + * Preserves \virt, \phys + * Clobbers r1 - r4 + * + * * Also use r10 for the phys offset. + * + * Note that \virt and \paddr should be in other registers than r1 - r4 + * and be distinct. + */ +.macro create_mapping_entry, tbl, virt, phys, type=PT_MEM_L3, mmu=0 + lsr r4, \phys, #THIRD_SHIFT + lsl r4, r4, #THIRD_SHIFT /* r4 := PAGE_ALIGNED(phys) */ + + mov_w r2, LPAE_ENTRY_MASK + lsr r1, \virt, #THIRD_SHIFT + and r1, r1, r2 /* r1 := slot in \tlb */ + lsl r1, r1, #3 /* r1 := slot offset in \tlb */ + + mov r2, #\type /* r2:r3 := right for section PT */ + orr r2, r2, r4 /* + PAGE_ALIGNED(phys) */ + mov r3, #0 + + adr_l r4, \tbl, \mmu + + strd r2, r3, [r4, r1] +.endm + +/* * Rebuild the boot pagetable's first-level entries. The structure * is described in mm.c. * @@ -559,31 +643,17 @@ ENDPROC(remove_identity_mapping) * r10: Physical offset * r11: Early UART base physical address * - * Clobbers r1 - r4 + * Clobbers r0 - r4 */ setup_fixmap: #if defined(CONFIG_EARLY_PRINTK) /* Add UART to the fixmap table */ - ldr r1, =xen_fixmap /* r1 := vaddr (xen_fixmap) */ - lsr r2, r11, #THIRD_SHIFT - lsl r2, r2, #THIRD_SHIFT /* 4K aligned paddr of UART */ - orr r2, r2, #PT_UPPER(DEV_L3) - orr r2, r2, #PT_LOWER(DEV_L3) /* r2:r3 := 4K dev map including UART */ - mov r3, #0x0 - strd r2, r3, [r1, #(FIXMAP_CONSOLE*8)] /* Map it in the first fixmap's slot */ + ldr r0, =EARLY_UART_VIRTUAL_ADDRESS + create_mapping_entry xen_fixmap, r0, r11, type=PT_DEV_L3, mmu=1 #endif - /* Map fixmap into boot_second */ - ldr r1, =boot_second /* r1 := vaddr (boot_second) */ - ldr r2, =xen_fixmap - add r2, r2, r10 /* r2 := paddr (xen_fixmap) */ - orr r2, r2, #PT_UPPER(PT) - orr r2, r2, #PT_LOWER(PT) /* r2:r3 := table map of xen_fixmap */ - ldr r4, =FIXMAP_ADDR(0) - mov r4, r4, lsr #(SECOND_SHIFT - 3) /* r4 := Slot for FIXMAP(0) */ - mov r3, #0x0 - strd r2, r3, [r1, r4] /* Map it in the fixmap's slot */ - + mov_w r0, FIXMAP_ADDR(0) + create_table_entry boot_second, xen_fixmap, r0, SECOND_SHIFT, mmu=1 /* Ensure any page table updates made above have occurred. */ dsb nshst From patchwork Mon Aug 12 17:30:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 171099 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3120107ily; Mon, 12 Aug 2019 10:31:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqydCxkTv73+0po96QDtDRzy/ayz8xGSol35TmqocHOzWx9KkNGrCae9+N49lRunQFmIGpUy X-Received: by 2002:a02:1441:: with SMTP id 62mr40231895jag.21.1565631101687; Mon, 12 Aug 2019 10:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631101; cv=none; d=google.com; s=arc-20160816; b=KtIMlcrtZSyVlVpeioZcohc2SOAdTbEwtZ1dryJduw0ISYqfT+6qmq9OgXOiqIVI7C ewgLt6VIqwwJ/wH0WQEEks+GcfhTlmuTU8pK7wg5iTgl1zA2/HcvuJe2QQuscXcrEK/m mVrhT5i9LBgXHGGGrOB+HvgqUNdnKqDIg0rKXQgR92167ejLwfdLoBMyM6fffDPB9KLh eX4KOOhQEu2zQaKzAXE/Af9GmSKAQgMPNUr8YhHMTTC4Si9K+MKs49f220NIr/T70EVN 8lk1TVYkoW/yOnkjCmAhpmUUVhH1KdmPgRhzta4UhIklZjuoBusS0LhZ7s8WFlBGU0du xNuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=tg2jeMcnIiYjRdkTCnMAg2zdOijMnbCG8zj2XWYAX0Y=; b=MJVZXFhFXKzQT6iEXtQAG/P5dONhfT+U4xnKqf36wmGz3+ffHHboeDdxiiWn5b/szz 6dintF7aPiB+FCFsjNshoVmFN6ckv/pENNCDYITjAkszC+Gm6yysRUlYmn+/jLqipbda hORAYLiO+vvg+nuSU7swGi4tg50qdzkPLeJPEBLXFdIaS6IZvfAlpg1NZewDn2LHFqE6 +EyF6Bj5FKRvury360n7V15kub//eko6d3wT1k8YeobJc58o/YWwyyXYpscbpFlyZbhP 6quRGZMta/qHDLeSFH105ghs7ecJBNElLWF+m+EBjzOi7mnLgeiOygtpgYSqn48O5AOQ vHvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u190si12446054jau.68.2019.08.12.10.31.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Aug 2019 10:31:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9o-00077d-5B; Mon, 12 Aug 2019 17:30:56 +0000 Received: from [172.99.69.81] (helo=us1-rack-iad1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxE9m-00075C-NJ for xen-devel@lists.xenproject.org; Mon, 12 Aug 2019 17:30:54 +0000 X-Inumbo-ID: eefcd7f4-bd26-11e9-b59c-4f004b76b6cd Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id eefcd7f4-bd26-11e9-b59c-4f004b76b6cd; Mon, 12 Aug 2019 17:30:52 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9488F15AB; Mon, 12 Aug 2019 10:30:52 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E31253F706; Mon, 12 Aug 2019 10:30:51 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 Aug 2019 18:30:19 +0100 Message-Id: <20190812173019.11956-29-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190812173019.11956-1-julien.grall@arm.com> References: <20190812173019.11956-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 28/28] xen/arm32: head: Use a page mapping for the 1:1 mapping in create_page_tables() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment the function create_page_tables() will use 1GB/2MB mapping for the identity mapping. As we don't know what is present before and after Xen in memory, we may end up to map device/reserved-memory with cacheable memory. This may result to mismatched attributes as other users may access the same region differently. To prevent any issues, we should only map the strict minimum in the 1:1 mapping. A check in xen.lds.S already guarantees anything necessary for turning on the MMU fits in a page (at the moment 4K). As only one page will be mapped for the 1:1 mapping, it is necessary to pre-allocate a page for the 3rd level table. For simplicity, all the tables that may be necessary for setting up the 1:1 mapping are linked together in advance. They will then be linked to the boot page tables at the correct level. Signed-off-by: Julien Grall --- Changes in v3: - Patch added --- xen/arch/arm/arm32/head.S | 119 ++++++++++++++++++---------------------------- xen/arch/arm/mm.c | 2 +- 2 files changed, 48 insertions(+), 73 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 6d03fecaf2..dec6266803 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -444,73 +444,13 @@ ENDPROC(cpu_init) * r6 : Identity map in place */ create_page_tables: - /* - * 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 */ - - ldr r4, =boot_pgtable - add r4, r4, r10 /* r4 := paddr (boot_pagetable) */ - - /* Setup boot_pgtable: */ - ldr r1, =boot_second - add r1, r1, r10 /* r1 := paddr (boot_second) */ - - /* ... map boot_second in boot_pgtable[0] */ - orr r2, r1, #PT_UPPER(PT) /* r2:r3 := table map of boot_second */ - orr r2, r2, #PT_LOWER(PT) /* (+ rights for linear PT) */ - mov r3, #0x0 - strd r2, r3, [r4, #0] /* Map it in slot 0 */ - - /* ... map of paddr(start) in boot_pgtable */ - lsrs r1, r9, #FIRST_SHIFT /* Offset of base paddr in boot_pgtable */ - beq 1f /* If it is in slot 0 then map in boot_second - * later on */ - lsl r2, r1, #FIRST_SHIFT /* Base address for 1GB mapping */ - orr r2, r2, #PT_UPPER(MEM) /* r2:r3 := section map */ - orr r2, r2, #PT_LOWER(MEM) - lsl r1, r1, #3 /* r1 := Slot offset */ - mov r3, #0x0 - 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 - add r4, r4, r10 /* r4 := paddr (boot_second) */ - - ldr r1, =boot_third - add r1, r1, r10 /* r1 := paddr (boot_third) */ - - /* ... map boot_third in boot_second[1] */ - orr r2, r1, #PT_UPPER(PT) /* r2:r3 := table map of boot_third */ - orr r2, r2, #PT_LOWER(PT) /* (+ rights for linear PT) */ - mov r3, #0x0 - 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 - cmp r1, #1 - beq virtphys_clash /* It's in slot 1, which we cannot handle */ - - lsl r2, r2, #SECOND_SHIFT /* Base address for 2MB mapping */ - orr r2, r2, #PT_UPPER(MEM) /* r2:r3 := section map */ - orr r2, r2, #PT_LOWER(MEM) - 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 */ + /* Prepare the page-tables for mapping Xen */ + ldr r0, =XEN_VIRT_START + create_table_entry boot_pgtable, boot_second, r0, FIRST_SHIFT + create_table_entry boot_second, boot_third, r0, SECOND_SHIFT /* Setup boot_third: */ -1: ldr r4, =boot_third - add r4, r4, r10 /* r4 := paddr (boot_third) */ + adr_l r4, boot_third, mmu=0 lsr r2, r9, #THIRD_SHIFT /* Base address for 4K mapping */ lsl r2, r2, #THIRD_SHIFT @@ -527,16 +467,51 @@ create_page_tables: blo 1b /* - * Defer fixmap and dtb mapping until after paging enabled, to - * avoid them clashing with the 1:1 mapping. + * 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 pc, lr - /* boot pagetable setup complete */ +1: + /* + * Only the first page of Xen will be part of the 1:1 mapping. + * All the boot_*_id tables are linked together even if they may + * not be all used. They will then be linked to the boot page + * tables at the correct level. + */ + create_table_entry boot_second_id, boot_third_id, r9, SECOND_SHIFT + create_mapping_entry boot_third_id, r9, r9 + + /* + * Find the first slot used. Link boot_second_id into boot_first + * if the slot is not 0. For slot 0, the tables associated with + * the 1:1 mapping will need to be linked in boot_second. + */ + lsr r0, r9, #FIRST_SHIFT + mov_w r1, LPAE_ENTRY_MASK + ands r0, r0, r1 /* r0 := first slot */ + beq 1f + /* It is not in slot 0, Link boot_second_id into boot_first */ + create_table_entry boot_pgtable, boot_second_id, r9, FIRST_SHIFT + mov pc, lr + +1: + /* + * Find the second slot used. Link boot_third_id into boot_second + * if the slot is not 1 (runtime Xen mapping is 2M - 4M). + * For slot 1, Xen is not yet able to handle it. + */ + lsr r0, r9, #SECOND_SHIFT + mov_w r1, LPAE_ENTRY_MASK + and r0, r0, r1 /* x0 := first slot */ + cmp r0, #1 + beq virtphys_clash + /* It is not in slot 1, link boot_third_id into boot_second */ + create_table_entry boot_second, boot_third_id, r9, SECOND_SHIFT + mov pc, lr - cmp r6, #1 /* Did we manage to create an identity mapping ? */ - moveq pc, lr - 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/mm.c b/xen/arch/arm/mm.c index 72ffea7472..9e0fdc39f9 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -105,9 +105,9 @@ DEFINE_BOOT_PAGE_TABLE(boot_pgtable); #ifdef CONFIG_ARM_64 DEFINE_BOOT_PAGE_TABLE(boot_first); DEFINE_BOOT_PAGE_TABLE(boot_first_id); +#endif DEFINE_BOOT_PAGE_TABLE(boot_second_id); DEFINE_BOOT_PAGE_TABLE(boot_third_id); -#endif DEFINE_BOOT_PAGE_TABLE(boot_second); DEFINE_BOOT_PAGE_TABLE(boot_third);