From patchwork Thu Apr 20 15:12:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 97826 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp846179qgf; Thu, 20 Apr 2017 08:14:39 -0700 (PDT) X-Received: by 10.202.98.194 with SMTP id w185mr4273561oib.172.1492701279172; Thu, 20 Apr 2017 08:14:39 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id q84si3473452oia.275.2017.04.20.08.14.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 08:14:39 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlC-00053c-Sa; Thu, 20 Apr 2017 15:12:42 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlC-000530-C8 for xen-devel@lists.xen.org; Thu, 20 Apr 2017 15:12:42 +0000 Received: from [85.158.139.211] by server-15.bemta-5.messagelabs.com id BD/61-01730-9EFC8F85; Thu, 20 Apr 2017 15:12:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTffZ+R8 RBs3LmS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oxNy9tZCjo4KnovdTI3ML5i62Lk4hAS2Mwo 8fH4chYI5zSjxI5FF1i7GDk52AQ0Je58/sQEYosISEtc+3yZEcRmFnCQePPxHguILSwQKvF8Y QNYDYuAqsTbH1/BenkFLCWWTuwGsyUE5CV2tV0EszkFrCR67kDMFAKq6Zu2mWkCI/cCRoZVjO rFqUVlqUW65npJRZnpGSW5iZk5uoYGpnq5qcXFiempOYlJxXrJ+bmbGIH+ZQCCHYzHJjsfYpT kYFIS5VWb+yNCiC8pP6UyI7E4I76oNCe1+BCjDAeHkgTvi3NAOcGi1PTUirTMHGCgwaQlOHiU RHhPg6R5iwsSc4sz0yFSpxgVpcR5i0ESAiCJjNI8uDZYcF9ilJUS5mUEOkSIpyC1KDezBFX+F aM4B6OSMK8UMFaEeDLzSuCmvwJazAS0+Kwf2OKSRISUVAMje9wVuTsWTTPZt1i/LS5d2jbhBw N/55xXf/Jup/KcC2Y5vles9cGdk9VrU+MUsrZ+uTZf+sj9JLXipMYJe/f94LBQ1Nd3v5p9Mvf oN71Nv1v78mI9Stg+cqtnpTrNbfpnbWG2bc3sJXzObNbuexUUirn3fLbhDu1I/seb49+p5l9e MWveqmAlluKMREMt5qLiRAAAoMYAaQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1492701157!78778486!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests=UPPERCASE_25_50 X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 39298 invoked from network); 20 Apr 2017 15:12:37 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-13.tower-206.messagelabs.com with SMTP; 20 Apr 2017 15:12:37 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4357215A2; Thu, 20 Apr 2017 08:12:37 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A38C43F4FF; Thu, 20 Apr 2017 08:12:36 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 20 Apr 2017 16:12:24 +0100 Message-Id: <20170420151228.19158-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170420151228.19158-1-julien.grall@arm.com> References: <20170420151228.19158-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 for-4.9 1/5] xen/arm: Add BOOT_FDT_VIRT_END and BOOT_FDT_SLOT_SIZE X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" The 2 new defines will help to avoid hardcoding the size and the end of the slot in the code. The newlines are added for clarity. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/include/asm-arm/config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h index b2edf95f72..9c14a385e7 100644 --- a/xen/include/asm-arm/config.h +++ b/xen/include/asm-arm/config.h @@ -111,7 +111,11 @@ #define XEN_VIRT_START _AT(vaddr_t,0x00200000) #define FIXMAP_ADDR(n) (_AT(vaddr_t,0x00400000) + (n) * PAGE_SIZE) + #define BOOT_FDT_VIRT_START _AT(vaddr_t,0x00600000) +#define BOOT_FDT_SLOT_SIZE MB(2) +#define BOOT_FDT_VIRT_END (BOOT_FDT_VIRT_START + BOOT_FDT_SLOT_SIZE) + #define BOOT_RELOC_VIRT_START _AT(vaddr_t,0x00800000) #ifdef CONFIG_LIVEPATCH #define LIVEPATCH_VMAP_START _AT(vaddr_t,0x00800000) From patchwork Thu Apr 20 15:12:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 97829 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp846198qgf; Thu, 20 Apr 2017 08:14:42 -0700 (PDT) X-Received: by 10.157.10.198 with SMTP id 64mr4312816otq.107.1492701282094; Thu, 20 Apr 2017 08:14:42 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id s7si3474531ota.129.2017.04.20.08.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 08:14:42 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlB-00052Z-7M; Thu, 20 Apr 2017 15:12:41 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlA-000523-6q for xen-devel@lists.xen.org; Thu, 20 Apr 2017 15:12:40 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 42/2E-03587-7EFC8F85; Thu, 20 Apr 2017 15:12:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsVysyfVTff5+R8 RBluOM1os+biYxYHR4+ju30wBjFGsmXlJ+RUJrBmTfx1lLpgnW/Fn7XHGBsb3ol2MXBxCApsZ JVbMOMII4ZxmlFi//TJ7FyMnB5uApsSdz5+YQGwRAWmJa58vM4LYzAIOEm8+3mMBsYUF4iS6F nazdTFycLAIqEo8nQ5WzitgKbGycxIriC0hIC+xq+0imM0pYCXRcwdipBBQTd+0zUwTGLkXMD KsYlQvTi0qSy3StdRLKspMzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZLzs/dxAj0LgMQ7GC8uyn gEKMkB5OSKK/a3B8RQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4884B5QSLUtNTK9Iyc4BhBpOW 4OBREuE9DZLmLS5IzC3OTIdInWJUlBLnLQZJCIAkMkrz4NpgoX2JUVZKmJcR6BAhnoLUotzME lT5V4ziHIxKwryLQabwZOaVwE1/BbSYCWjxWT+wxSWJCCmpBsY67vYSJ3XxbM07LVXaczK+sG eE1K9bXpl9rGE9y4uTKmcFWHqVMvqL1snlfrPn7ph+eEXaZfHKUg7jZWcahYM9J2xzX/qa/+P 004rSp78m5kWV8uRkvJFlVqxTOM15W+PW3RKbMiGFdcunZS46XOlz/mKax9PLn4rcPOMDLRWf L/xoN3XnASWW4oxEQy3mouJEAGnLcD5oAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1492701158!45321922!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55892 invoked from network); 20 Apr 2017 15:12:38 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-15.tower-27.messagelabs.com with SMTP; 20 Apr 2017 15:12:38 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 23F561684; Thu, 20 Apr 2017 08:12:38 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7EA533F4FF; Thu, 20 Apr 2017 08:12:37 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 20 Apr 2017 16:12:25 +0100 Message-Id: <20170420151228.19158-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170420151228.19158-1-julien.grall@arm.com> References: <20170420151228.19158-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 for-4.9 2/5] xen/arm: mm: Move create_mappings function earlier in the file X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" This function will be called by other function later one. This will avoid forward declaration and keep the new function close to sibling ones. This was moved just after *_fixmap helpers as they are page table handling functions too. Signed-off-by: Julien Grall --- Changes in v2: - Patch added --- xen/arch/arm/mm.c | 68 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f0a2eddaaf..bc65c0e432 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -269,6 +269,40 @@ void clear_fixmap(unsigned map) flush_xen_data_tlb_range_va(FIXMAP_ADDR(map), PAGE_SIZE); } +/* Create Xen's mappings of memory. + * Mapping_size must be either 2MB or 32MB. + * Base and virt must be mapping_size aligned. + * Size must be a multiple of mapping_size. + * second must be a contiguous set of second level page tables + * covering the region starting at virt_offset. */ +static void __init create_mappings(lpae_t *second, + unsigned long virt_offset, + unsigned long base_mfn, + unsigned long nr_mfns, + unsigned int mapping_size) +{ + unsigned long i, count; + const unsigned long granularity = mapping_size >> PAGE_SHIFT; + lpae_t pte, *p; + + ASSERT((mapping_size == MB(2)) || (mapping_size == MB(32))); + ASSERT(!((virt_offset >> PAGE_SHIFT) % granularity)); + ASSERT(!(base_mfn % granularity)); + ASSERT(!(nr_mfns % granularity)); + + count = nr_mfns / LPAE_ENTRIES; + p = second + second_linear_offset(virt_offset); + pte = mfn_to_xen_entry(base_mfn, WRITEALLOC); + if ( granularity == 16 * LPAE_ENTRIES ) + pte.pt.contig = 1; /* These maps are in 16-entry contiguous chunks. */ + for ( i = 0; i < count; i++ ) + { + write_pte(p + i, pte); + pte.pt.base += 1 << LPAE_SHIFT; + } + flush_xen_data_tlb_local(); +} + #ifdef CONFIG_DOMAIN_PAGE void *map_domain_page_global(mfn_t mfn) { @@ -633,40 +667,6 @@ void mmu_init_secondary_cpu(void) flush_xen_text_tlb_local(); } -/* Create Xen's mappings of memory. - * Mapping_size must be either 2MB or 32MB. - * Base and virt must be mapping_size aligned. - * Size must be a multiple of mapping_size. - * second must be a contiguous set of second level page tables - * covering the region starting at virt_offset. */ -static void __init create_mappings(lpae_t *second, - unsigned long virt_offset, - unsigned long base_mfn, - unsigned long nr_mfns, - unsigned int mapping_size) -{ - unsigned long i, count; - const unsigned long granularity = mapping_size >> PAGE_SHIFT; - lpae_t pte, *p; - - ASSERT((mapping_size == MB(2)) || (mapping_size == MB(32))); - ASSERT(!((virt_offset >> PAGE_SHIFT) % granularity)); - ASSERT(!(base_mfn % granularity)); - ASSERT(!(nr_mfns % granularity)); - - count = nr_mfns / LPAE_ENTRIES; - p = second + second_linear_offset(virt_offset); - pte = mfn_to_xen_entry(base_mfn, WRITEALLOC); - if ( granularity == 16 * LPAE_ENTRIES ) - pte.pt.contig = 1; /* These maps are in 16-entry contiguous chunks. */ - for ( i = 0; i < count; i++ ) - { - write_pte(p + i, pte); - pte.pt.base += 1 << LPAE_SHIFT; - } - flush_xen_data_tlb_local(); -} - #ifdef CONFIG_ARM_32 /* Set up the xenheap: up to 1GB of contiguous, always-mapped memory. */ void __init setup_xenheap_mappings(unsigned long base_mfn, From patchwork Thu Apr 20 15:12:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 97831 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp846271qgf; Thu, 20 Apr 2017 08:14:51 -0700 (PDT) X-Received: by 10.202.54.87 with SMTP id d84mr2958542oia.129.1492701290954; Thu, 20 Apr 2017 08:14:50 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id l32si2826059otd.116.2017.04.20.08.14.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 08:14:50 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlC-000535-ED; Thu, 20 Apr 2017 15:12:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlB-00052K-7q for xen-devel@lists.xen.org; Thu, 20 Apr 2017 15:12:41 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id E7/57-03696-8EFC8F85; Thu, 20 Apr 2017 15:12:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrILMWRWlGSWpSXmKPExsVysyfVTff5+R8 RBstnW1ss+biYxYHR4+ju30wBjFGsmXlJ+RUJrBndffYFG9QqOr7uYmxg3CbbxcjFISSwiVHi Qu9eZgjnNKPE22U3GLsYOTnYBDQl7nz+xARiiwhIS1z7fBkszizgIPHm4z0WEFtYIF3i+4xtz CA2i4CqxKn/3awgNq+ApcT5zc1gNRIC8hK72i6CxTkFrCR67kDMFAKq6Zu2mWkCI/cCRoZVjO rFqUVlqUW6xnpJRZnpGSW5iZk5uoYGZnq5qcXFiempOYlJxXrJ+bmbGIHeZQCCHYwd/5wOMUp yMCmJ8qrN/REhxJeUn1KZkVicEV9UmpNafIhRhoNDSYL3xTmgnGBRanpqRVpmDjDMYNISHDxK IrynQdK8xQWJucWZ6RCpU4y6HIee/3zPJMSSl5+XKiXO+wSkSACkKKM0D24ELOQvMcpKCfMyA h0lxFOQWpSbWYIq/4pRnINRSZj3IcgUnsy8ErhNr4COYAI64qwf2BEliQgpKWAcMXHZGGp3N/ r88M5Qjb4mKFkScXpfwSah96tndWga1c1cpM31+tcPhe9/Tn3yaoj5p7k56Owig7Uuacmz+Ts +1b713aXCuCNskcKCzeGdQjcvrN5ZvuBMSubV9SEJu4x1oq8ca5dSknt8KLzCT8XuhJfgtw+b /WexxvPybN5dGNMutv/ZrR9KLMUZiYZazEXFiQDZDbt6dAIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1492701159!64545712!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 971 invoked from network); 20 Apr 2017 15:12:39 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-12.tower-21.messagelabs.com with SMTP; 20 Apr 2017 15:12:39 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F37F0CFC; Thu, 20 Apr 2017 08:12:38 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 610603F4FF; Thu, 20 Apr 2017 08:12:38 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 20 Apr 2017 16:12:26 +0100 Message-Id: <20170420151228.19158-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170420151228.19158-1-julien.grall@arm.com> References: <20170420151228.19158-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 for-4.9 3/5] xen/arm: Move the code to map FDT in the boot tables from assembly to C X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" The FDT will not be accessed before start_xen (begining of C code) is called and it will be easier to maintain as the code could be common between AArch32 and AArch64. A new function early_fdt_map is introduced to map the FDT in the boot page table. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Remove the forward declaration for create_mappins as it has been moved earlier. - Remove spurious newline. - Add Stefano's reviewed. I keep it because the change is minor. --- xen/arch/arm/arm32/head.S | 14 -------------- xen/arch/arm/arm64/head.S | 13 ------------- xen/arch/arm/mm.c | 13 +++++++++++++ xen/arch/arm/setup.c | 4 +--- xen/include/asm-arm/mm.h | 2 ++ 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index ec63ba4c04..4090f4a744 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -389,20 +389,6 @@ paging: /* Use a virtual address to access the UART. */ ldr r11, =EARLY_UART_VIRTUAL_ADDRESS #endif - /* Map the DTB in the boot misc slot */ - teq r12, #0 /* Only on boot CPU */ - bne 1f - - ldr r1, =boot_second - mov r3, #0x0 - lsr r2, r8, #SECOND_SHIFT - lsl r2, r2, #SECOND_SHIFT /* r2: 2MB-aligned paddr of DTB */ - orr r2, r2, #PT_UPPER(MEM) - orr r2, r2, #PT_LOWER(MEM) /* r2:r3 := 2MB RAM incl. DTB */ - ldr r4, =BOOT_FDT_VIRT_START - mov r4, r4, lsr #(SECOND_SHIFT - 3) /* Slot for BOOT_FDT_VIRT_START */ - strd r2, r3, [r1, r4] /* Map it in the early fdt slot */ -1: /* * Flush the TLB in case the 1:1 mapping happens to clash with diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 72ea4e0233..78292f4396 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -550,19 +550,6 @@ paging: ldr x23, =EARLY_UART_VIRTUAL_ADDRESS #endif - /* Map the DTB in the boot misc slot */ - cbnz x22, 1f /* Only on boot CPU */ - - ldr x4, =boot_second /* x4 := vaddr (boot_second) */ - lsr x2, x21, #SECOND_SHIFT - lsl x2, x2, #SECOND_SHIFT /* x2 := 2MB-aligned paddr of DTB */ - mov x3, #PT_MEM /* x2 := 2MB RAM incl. DTB */ - orr x2, x2, x3 - ldr x1, =BOOT_FDT_VIRT_START - lsr x1, x1, #(SECOND_SHIFT - 3) /* x4 := Slot for BOOT_FDT_VIRT_START */ - str x2, [x4, x1] /* Map it in the early fdt slot */ -1: - /* * Flush the TLB in case the 1:1 mapping happens to clash with * the virtual addresses used by the fixmap or DTB. diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index bc65c0e432..97b3209286 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -38,6 +38,7 @@ #include #include #include +#include struct domain *dom_xen, *dom_io, *dom_cow; @@ -468,6 +469,18 @@ static inline lpae_t pte_of_xenaddr(vaddr_t va) return mfn_to_xen_entry(mfn, WRITEALLOC); } +/* Map the FDT in the early boot page table */ +void * __init early_fdt_map(paddr_t fdt_paddr) +{ + /* We are using 2MB superpage for mapping the FDT */ + paddr_t base_paddr = fdt_paddr & SECOND_MASK; + + create_mappings(boot_second, BOOT_FDT_VIRT_START, paddr_to_pfn(base_paddr), + SZ_2M >> PAGE_SHIFT, SZ_2M); + + return (void *)BOOT_FDT_VIRT_START + (fdt_paddr % SECOND_SIZE); +} + void __init remove_early_mappings(void) { lpae_t pte = {0}; diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 92a2de6b70..986398970f 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -724,9 +724,7 @@ void __init start_xen(unsigned long boot_phys_offset, smp_clear_cpu_maps(); - /* This is mapped by head.S */ - device_tree_flattened = (void *)BOOT_FDT_VIRT_START - + (fdt_paddr & ((1 << SECOND_SHIFT) - 1)); + device_tree_flattened = early_fdt_map(fdt_paddr); fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr); cmdline = boot_fdt_cmdline(device_tree_flattened); diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 0fef612f42..f6915ad882 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -160,6 +160,8 @@ extern unsigned long total_pages; /* Boot-time pagetable setup */ extern void setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr); +/* Map FDT in boot pagetable */ +extern void *early_fdt_map(paddr_t fdt_paddr); /* Remove early mappings */ extern void remove_early_mappings(void); /* Allocate and initialise pagetables for a secondary CPU. Sets init_ttbr to the From patchwork Thu Apr 20 15:12:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 97828 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp846195qgf; Thu, 20 Apr 2017 08:14:41 -0700 (PDT) X-Received: by 10.202.229.6 with SMTP id c6mr4686172oih.45.1492701281703; Thu, 20 Apr 2017 08:14:41 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id m54si1196071otd.313.2017.04.20.08.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 08:14:41 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlC-00053M-LH; Thu, 20 Apr 2017 15:12:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlB-00052c-Lu for xen-devel@lists.xen.org; Thu, 20 Apr 2017 15:12:41 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 34/28-03371-9EFC8F85; Thu, 20 Apr 2017 15:12:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTffF+R8 RBnc3SVos+biYxYHR4+ju30wBjFGsmXlJ+RUJrBldWxexF3yTq7iy8ihbA+NpiS5GLg4hgc2M EhfunGGCcE4zStxf1cTSxcjJwSagKXHn8ycmEFtEQFri2ufLjCA2s4CDxJuP98BqhAWiJY5Pm g5WwyKgKjH53x9WEJtXwFLiwOQ7YDUSAvISu9ougsU5Bawkeu5AzBQCqumbtplpAiP3AkaGVY zqxalFZalFupZ6SUWZ6RkluYmZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiB/mUAgh2MdzcFHGK U5GBSEuVVm/sjQogvKT+lMiOxOCO+qDQntfgQowwHh5IEb945oJxgUWp6akVaZg4w0GDSEhw8 SiK8p0HSvMUFibnFmekQqVOMilLivMUgCQGQREZpHlwbLLgvMcpKCfMyAh0ixFOQWpSbWYIq/ 4pRnINRSZh3McgUnsy8Erjpr4AWMwEtPusHtrgkESEl1cA4ZbGJZADPzBVPrPK9Hxneirz9Kr /ttxOnvozhA/tj1a0LPgRnTA+7rnhGY9YWPR+9I22vHK+saeh5WHIpWu9DUMLmzQIpJ1Imrks 1vbTTfk9b+ZFmdsk8C63of+amByvnf1EOEUyz760LdNJdZRB1eGFQQFbQRhtRr1/n5AvXmax8 k1hnaKvEUpyRaKjFXFScCAClerI1aQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1492701158!45321922!2 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56344 invoked from network); 20 Apr 2017 15:12:40 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-15.tower-27.messagelabs.com with SMTP; 20 Apr 2017 15:12:40 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D1612169F; Thu, 20 Apr 2017 08:12:39 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3AC4C3F4FF; Thu, 20 Apr 2017 08:12:39 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 20 Apr 2017 16:12:27 +0100 Message-Id: <20170420151228.19158-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170420151228.19158-1-julien.grall@arm.com> References: <20170420151228.19158-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 for-4.9 4/5] xen/arm: Check if the FDT passed by the bootloader is valid X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" There is currently no sanity check on the FDT passed by the bootloader. Whilst they are stricly not necessary, it will avoid us to spend hours to try to find out why it does not work. >From the booting documentation for AArch32 [1] and AArch64 [2] must : - be placed on 8-byte boundary - not exceed 2MB (only on AArch64) Even if AArch32 does not seem to limit the size, Xen is not currently able to support more the 2MB FDT. It is better to crash rather with a nice error message than claiming we are supporting any size of FDT. The checks are mostly borrowed from the Linux code (see fixmap_remap_fdt in arch/arm64/mm/mmu.c). [1] Section 2 in linux/Documentation/arm64/booting.txt [2] Section 4b in linux/Documentation/arm/Booting Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Move the \n from the begining of the last line to the end of the first line. The 2 \n are here for clarity - Add missing "." - Add Stefano's reviewed-by --- xen/arch/arm/mm.c | 29 ++++++++++++++++++++++++++++- xen/arch/arm/setup.c | 6 ++++++ xen/include/asm-arm/setup.h | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 97b3209286..f598396994 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include struct domain *dom_xen, *dom_io, *dom_cow; @@ -474,11 +476,36 @@ void * __init early_fdt_map(paddr_t fdt_paddr) { /* We are using 2MB superpage for mapping the FDT */ paddr_t base_paddr = fdt_paddr & SECOND_MASK; + paddr_t offset; + void *fdt_virt; + + /* + * Check whether the physical FDT address is set and meets the minimum + * alignment requirement. Since we are relying on MIN_FDT_ALIGN to be at + * least 8 bytes so that we always access the magic and size fields + * of the FDT header after mapping the first chunk, double check if + * that is indeed the case. + */ + BUILD_BUG_ON(MIN_FDT_ALIGN < 8); + if ( !fdt_paddr || fdt_paddr % MIN_FDT_ALIGN ) + return NULL; + + /* The FDT is mapped using 2MB superpage */ + BUILD_BUG_ON(BOOT_FDT_VIRT_START % SZ_2M); create_mappings(boot_second, BOOT_FDT_VIRT_START, paddr_to_pfn(base_paddr), SZ_2M >> PAGE_SHIFT, SZ_2M); - return (void *)BOOT_FDT_VIRT_START + (fdt_paddr % SECOND_SIZE); + offset = fdt_paddr % SECOND_SIZE; + fdt_virt = (void *)BOOT_FDT_VIRT_START + offset; + + if ( fdt_magic(fdt_virt) != FDT_MAGIC ) + return NULL; + + if ( fdt_totalsize(fdt_virt) > MAX_FDT_SIZE ) + return NULL; + + return fdt_virt; } void __init remove_early_mappings(void) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 986398970f..e2cda1f134 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -725,6 +725,12 @@ void __init start_xen(unsigned long boot_phys_offset, smp_clear_cpu_maps(); device_tree_flattened = early_fdt_map(fdt_paddr); + if ( !device_tree_flattened ) + panic("Invalid device tree blob at physical address %#lx.\n" + "The DTB must be 8-byte aligned and must not exceed 2 MB in size.\n\n" + "Please check your bootloader.", + fdt_paddr); + fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr); cmdline = boot_fdt_cmdline(device_tree_flattened); diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index 7c761851d2..7ff2c34dab 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -3,6 +3,9 @@ #include +#define MIN_FDT_ALIGN 8 +#define MAX_FDT_SIZE SZ_2M + #define NR_MEM_BANKS 64 #define MAX_MODULES 5 /* Current maximum useful modules */ From patchwork Thu Apr 20 15:12:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 97827 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp846193qgf; Thu, 20 Apr 2017 08:14:41 -0700 (PDT) X-Received: by 10.157.36.4 with SMTP id p4mr4891545ota.267.1492701281450; Thu, 20 Apr 2017 08:14:41 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id y11si3467486otd.309.2017.04.20.08.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 08:14:41 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlE-00053x-3U; Thu, 20 Apr 2017 15:12:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DlD-00053H-30 for xen-devel@lists.xen.org; Thu, 20 Apr 2017 15:12:43 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 6B/55-01870-AEFC8F85; Thu, 20 Apr 2017 15:12:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsVysyfVTffl+R8 RBp/nqlss+biYxYHR4+ju30wBjFGsmXlJ+RUJrBknvn1gKfjmWnFrdh9zA+NEqy5GLg4hgc2M Eu/fzmKCcE4zSsy4u5i1i5GTg01AU+LO509MILaIgLTEtc+XGUFsZgEHiTcf77GA2MICIRI3G 2aA1bAIqEpsvviTGcTmFbCU2DZhHliNhIC8xK62i2AzOQWsJHruQMwUAqrpm7aZaQIj9wJGhl WM6sWpRWWpRboWeklFmekZJbmJmTm6hgbGermpxcWJ6ak5iUnFesn5uZsYgf5lAIIdjBfanQ8 xSnIwKYnyqs39ESHEl5SfUpmRWJwRX1Sak1p8iFGGg0NJgvfFOaCcYFFqempFWmYOMNBg0hIc PEoivKdB0rzFBYm5xZnpEKlTjLoc7zb/fs8kxJKXn5cqJc77BKRIAKQoozQPbgQs6C8xykoJ8 zICHSXEU5BalJtZgir/ilGcg1FJmFcKGENCPJl5JXCbXgEdwQR0xFk/sCNKEhFSUg2Mx8Pqck 7Z1fZyptdU//fu952d8fbumca3sZzbpTfyzHqd8TKrxvMxb/Sy+TlTBVuXX1I3P9x7THflizu fV29Zz9SjZXj9E//vawvXv/xTarG678K5HXfcRfL5axvOiPlE1M0KfHJfVnuV3MdZJ7bKyM/Y Vf201E9BX6dnj9mZU5EBNY2Bn7WvKrEUZyQaajEXFScCAH+9IaB1AgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1492701160!93368592!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15566 invoked from network); 20 Apr 2017 15:12:41 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-5.tower-31.messagelabs.com with SMTP; 20 Apr 2017 15:12:41 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A8B1415A2; Thu, 20 Apr 2017 08:12:40 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 15B0A3F4FF; Thu, 20 Apr 2017 08:12:39 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 20 Apr 2017 16:12:28 +0100 Message-Id: <20170420151228.19158-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170420151228.19158-1-julien.grall@arm.com> References: <20170420151228.19158-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 for-4.9 5/5] xen/arm: Properly map the FDT in the boot page table X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" Currently, Xen is assuming the FDT will always fit in a 2MB section. Recently, I noticed an early crash on Xen when using GRUB with the following call trace: (XEN) Hypervisor Trap. HSR=0x96000006 EC=0x25 IL=1 Syndrome=0x6 (XEN) CPU0: Unexpected Trap: Hypervisor (XEN) ----[ Xen-4.9-unstable arm64 debug=y Not tainted ]---- (XEN) CPU: 0 (XEN) PC: 0000000000264140 strlen+0x10/0x84 (XEN) LR: 00000000002401c0 (XEN) SP: 00000000002cfc20 (XEN) CPSR: 400003c9 MODE:64-bit EL2h (Hypervisor, handler) (XEN) X0: 0000000000801230 X1: 0000000000801230 X2: 0000000000005230 (XEN) X3: 0000000000000030 X4: 0000000000000030 X5: 0000000000000038 (XEN) X6: 0000000000000034 X7: 0000000000000000 X8: 7f7f7f7f7f7f7f7f (XEN) X9: 64622c6479687222 X10: 7f7f7f7f7f7f7f7f X11: 0101010101010101 (XEN) X12: 0000000000000030 X13: ffffff00ff000000 X14: 0800000003000000 (XEN) X15: ffffffffffffffff X16: 00000000fefff610 X17: 00000000000000f0 (XEN) X18: 0000000000000004 X19: 0000000000000008 X20: 00000000007fc040 (XEN) X21: 00000000007fc000 X22: 000000000000000e X23: 0000000000000000 (XEN) X24: 00000000002a9f58 X25: 0000000000801230 X26: 00000000002a9f68 (XEN) X27: 00000000002a9f58 X28: 0000000000298910 FP: 00000000002cfc20 (XEN) (XEN) VTCR_EL2: 80010c40 (XEN) VTTBR_EL2: 0000082800203000 (XEN) (XEN) SCTLR_EL2: 30c5183d (XEN) HCR_EL2: 000000000038663f (XEN) TTBR0_EL2: 00000000f4912000 (XEN) (XEN) ESR_EL2: 96000006 (XEN) HPFAR_EL2: 00000000e8071000 (XEN) FAR_EL2: 0000000000801230 (XEN) (XEN) Xen stack trace from sp=00000000002cfc20: (XEN) 00000000002cfc70 0000000000240254 00000000002a9f58 00000000007fc000 (XEN) 0000000000000000 0000000000000000 0000000000000000 00000000007fc03c (XEN) 00000000002cfd78 0000000000000000 00000000002cfca0 00000000002986fc (XEN) 0000000000000000 00000000007fc000 0000000000000000 0000000000000000 (XEN) 00000000002cfcc0 0000000000298f1c 0000000000000000 00000000007fc000 (XEN) 00000000002cfdc0 000000000029904c 00000000f47fc000 00000000f4604000 (XEN) 00000000f47fc000 00000000007fc000 0000000000400000 0000000000000100 (XEN) 00000000f4604000 0000000000000001 0000000000000001 8000000000000002 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 00000000002cfdc0 0000000000299038 (XEN) 00000000f47fc000 00000000f4604000 00000000f47fc000 0000000000000000 (XEN) 00000000002cfe20 000000000029c420 00000000002d8000 00000000f4604000 (XEN) 00000000f47fc000 0000000000000000 0000000000400000 0000000000000100 (XEN) 00000000f4604000 0000000000000001 00000000f47fc000 000000000029c404 (XEN) 00000000fefff510 0000000000200624 00000000f4804000 00000000f4604000 (XEN) 00000000f47fc000 0000000000000000 0000000000400000 0000000000000100 (XEN) 0000000000000001 0000000000000001 0000000000000001 8000000000000002 (XEN) 00000000f47fc000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 0000000000000000 0000000000000000 (XEN) Xen call trace: (XEN) [<0000000000264140>] strlen+0x10/0x84 (PC) (XEN) [<00000000002401c0>] fdt_get_property_namelen+0x9c/0xf0 (LR) (XEN) [<0000000000240254>] fdt_get_property+0x40/0x50 (XEN) [<00000000002986fc>] bootfdt.c#device_tree_get_u32+0x18/0x5c (XEN) [<0000000000298f1c>] device_tree_for_each_node+0x84/0x144 (XEN) [<000000000029904c>] boot_fdt_info+0x70/0x23c (XEN) [<000000000029c420>] start_xen+0x9c/0xd30 (XEN) [<0000000000200624>] arm64/head.o#paging+0x84/0xbc (XEN) (XEN) (XEN) **************************************** (XEN) Panic on CPU 0: (XEN) CPU0: Unexpected Trap: Hypervisor (XEN) (XEN) **************************************** Indeed, the booting documentation for AArch32 and AArch64 only requires the FDT to be placed on a 8-byte boundary. This means the Device-Tree can cross a 2MB boundary. Given that Xen limits the size of the FDT to 2MB, it will always fit in a 4MB slot. So extend the fixmap slot for FDT from 2MB to 4MB. The second 2MB superpage will only be mapped if the FDT is cross the 2MB boundary. Signed-off-by: Julien Grall --- Changes in v2: - Remove correctly the second early mapings --- xen/arch/arm/mm.c | 17 +++++++++++++++-- xen/include/asm-arm/config.h | 14 +++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f598396994..48f74f6e65 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -478,6 +478,7 @@ void * __init early_fdt_map(paddr_t fdt_paddr) paddr_t base_paddr = fdt_paddr & SECOND_MASK; paddr_t offset; void *fdt_virt; + uint32_t size; /* * Check whether the physical FDT address is set and meets the minimum @@ -502,9 +503,17 @@ void * __init early_fdt_map(paddr_t fdt_paddr) if ( fdt_magic(fdt_virt) != FDT_MAGIC ) return NULL; - if ( fdt_totalsize(fdt_virt) > MAX_FDT_SIZE ) + size = fdt_totalsize(fdt_virt); + if ( size > MAX_FDT_SIZE ) return NULL; + if ( (offset + size) > SZ_2M ) + { + create_mappings(boot_second, BOOT_FDT_VIRT_START + SZ_2M, + paddr_to_pfn(base_paddr + SZ_2M), + SZ_2M >> PAGE_SHIFT, SZ_2M); + } + return fdt_virt; } @@ -512,7 +521,9 @@ void __init remove_early_mappings(void) { lpae_t pte = {0}; write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START), pte); - flush_xen_data_tlb_range_va(BOOT_FDT_VIRT_START, SECOND_SIZE); + write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START + SZ_2M), + pte); + flush_xen_data_tlb_range_va(BOOT_FDT_VIRT_START, BOOT_FDT_SLOT_SIZE); } extern void relocate_xen(uint64_t ttbr, void *src, void *dst, size_t len); @@ -571,6 +582,8 @@ void __init setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr) /* ... DTB */ pte = boot_second[second_table_offset(BOOT_FDT_VIRT_START)]; xen_second[second_table_offset(BOOT_FDT_VIRT_START)] = pte; + pte = boot_second[second_table_offset(BOOT_FDT_VIRT_START + SZ_2M)]; + xen_second[second_table_offset(BOOT_FDT_VIRT_START + SZ_2M)] = pte; /* ... Boot Misc area for xen relocation */ dest_va = BOOT_RELOC_VIRT_START; diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h index 9c14a385e7..5b6f3c985d 100644 --- a/xen/include/asm-arm/config.h +++ b/xen/include/asm-arm/config.h @@ -77,12 +77,12 @@ * 0 - 2M Unmapped * 2M - 4M Xen text, data, bss * 4M - 6M Fixmap: special-purpose 4K mapping slots - * 6M - 8M Early boot mapping of FDT - * 8M - 10M Early relocation address (used when relocating Xen) + * 6M - 10M Early boot mapping of FDT + * 10M - 12M Early relocation address (used when relocating Xen) * and later for livepatch vmap (if compiled in) * * ARM32 layout: - * 0 - 10M + * 0 - 12M * * 32M - 128M Frametable: 24 bytes per page for 16GB of RAM * 256M - 1G VMAP: ioremap and early_ioremap use this virtual address @@ -93,7 +93,7 @@ * * ARM64 layout: * 0x0000000000000000 - 0x0000007fffffffff (512GB, L0 slot [0]) - * 0 - 10M + * 0 - 12M * * 1G - 2G VMAP: ioremap and early_ioremap * @@ -113,12 +113,12 @@ #define FIXMAP_ADDR(n) (_AT(vaddr_t,0x00400000) + (n) * PAGE_SIZE) #define BOOT_FDT_VIRT_START _AT(vaddr_t,0x00600000) -#define BOOT_FDT_SLOT_SIZE MB(2) +#define BOOT_FDT_SLOT_SIZE MB(4) #define BOOT_FDT_VIRT_END (BOOT_FDT_VIRT_START + BOOT_FDT_SLOT_SIZE) -#define BOOT_RELOC_VIRT_START _AT(vaddr_t,0x00800000) +#define BOOT_RELOC_VIRT_START _AT(vaddr_t,0x00a00000) #ifdef CONFIG_LIVEPATCH -#define LIVEPATCH_VMAP_START _AT(vaddr_t,0x00800000) +#define LIVEPATCH_VMAP_START _AT(vaddr_t,0x00a00000) #define LIVEPATCH_VMAP_END (LIVEPATCH_VMAP_START + MB(2)) #endif