From nobody Tue May 7 11:22:06 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1570730040; cv=none; d=zoho.com; s=zohoarc; b=GyZy8Vgl516XKaVB2wN3JYeTi/UrVFAb7ODStuP8ZwlvuKLfJV25USmWE3m99jxBeQNaNML+Uzcdx/P3s9CAw6Jnl3n9RoRNJLAM458jwyUD3ZsFoFGHwGRtBADOBMnQriJfLMnVia0daIJQuK265E76Ifv6hiYER8103zUEQe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570730040; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=jJkOWuazp51Dh2Kz7rI3cjYRhKYj3MrfJ/7KnVw2Ij0=; b=F5qBbO4NRCqvpzZB2G4f7HSCBLompTaNtDKBMvvyLFBpw+tav+sGxfO8MjwtGVk7fupv/YiU6xMutR0MUGvdNbUtRKLg/fSxU0oLItgiUeWEKogIjSTJMxhP7v+Sp84mvUikLx1LvaCkdLpQbDsHmT88/YcOotpmLDqshmg7OqU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1570730040832338.78513371922463; Thu, 10 Oct 2019 10:54:00 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIccI-0006GW-Jg; Thu, 10 Oct 2019 17:52:46 +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 1iIccG-0006GR-Ns for xen-devel@lists.xenproject.org; Thu, 10 Oct 2019 17:52:44 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id c26c1a36-eb86-11e9-9320-12813bfff9fa; Thu, 10 Oct 2019 17:52: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 D5E2F28; Thu, 10 Oct 2019 10:52: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 EC86D3F71A; Thu, 10 Oct 2019 10:52:41 -0700 (PDT) X-Inumbo-ID: c26c1a36-eb86-11e9-9320-12813bfff9fa From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 10 Oct 2019 18:52:38 +0100 Message-Id: <20191010175238.4769-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH for-4.13] xen/arm: mm: Allow generic xen page-tables helpers to be called early 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: jgross@suse.com, Volodymyr Babchuk , Julien Grall , Stefano Stabellini , Julien Grall MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The current implementations of xen_{map, unmap}_table() expect {map, unmap}_domain_page() to be usable. Those helpers are used to map/unmap page tables while update Xen page-tables. Since commit 022387ee1a "xen/arm: mm: Don't open-code Xen PT update in {set, clear}_fixmap()", setup_fixmap() will make use of the helpers mentioned above. When booting Xen using GRUB, setup_fixmap() may be used before map_domain_page() can be called. This will result to data abort: (XEN) Data Abort Trap. Syndrome=3D0x5 (XEN) CPU0: Unexpected Trap: Data Abort [...] (XEN) Xen call trace: (XEN) [<000000000025ab6c>] mm.c#xen_pt_update+0x2b4/0x59c (PC) (XEN) [<000000000025ab20>] mm.c#xen_pt_update+0x268/0x59c (LR) (XEN) [<000000000025ae70>] set_fixmap+0x1c/0x2c (XEN) [<00000000002a9c98>] copy_from_paddr+0x7c/0xdc (XEN) [<00000000002a4ae0>] has_xsm_magic+0x18/0x34 (XEN) [<00000000002a5b5c>] bootfdt.c#early_scan_node+0x398/0x560 (XEN) [<00000000002a5de0>] device_tree_for_each_node+0xbc/0x144 (XEN) [<00000000002a5ed4>] boot_fdt_info+0x6c/0x260 (XEN) [<00000000002ac0d0>] start_xen+0x108/0xc74 (XEN) [<000000000020044c>] arm64/head.o#paging+0x60/0x88 During early boot, the page tables are either statically allocated in Xen binary or allocated via alloc_boot_pages(). For statically allocated page-tables, they will already be mapped as part of Xen binary. So we can easily find the virtual address. For dynamically allocated page-tables, we need to rely map_domain_page() to be functionally working. For arm32, the call will be usable much before page can be dynamically allocated (see setup_pagetables()). For arm64, the call will be usable after setup_xenheap_mappings(). In both cases, memory are given to the boot allocator afterwards. So we can rely on map_domain_page() for mapping page tables allocated dynamically. The helpers xen_{map, unmap}_table() are now updated to take into account the case where page-tables are part of Xen binary. Fixes: 022387ee1a ('xen/arm: mm: Don't open-code Xen PT update in {set, cle= ar}_fixmap()') Signed-off-by: Julien Grall Release-acked-by: Juergen Gross --- Changes in v2: - Add RaB Juergen - Rework the check to avoid truncation --- xen/arch/arm/mm.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index be23acfe26..a6637ce347 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -964,11 +964,40 @@ static int create_xen_table(lpae_t *entry) =20 static lpae_t *xen_map_table(mfn_t mfn) { + /* + * We may require to map the page table before map_domain_page() is + * useable. The requirements here is it must be useable as soon as + * page-tables are allocated dynamically via alloc_boot_pages(). + * + * We need to do the check on physical address rather than virtual + * address to avoid truncation on Arm32. Therefore is_kernel() cannot + * be used. + */ + if ( system_state =3D=3D SYS_STATE_early_boot ) + { + const mfn_t mstart =3D virt_to_mfn(_start); + const mfn_t mend =3D virt_to_mfn(_end); + + if ( (mfn_x(mstart) <=3D mfn_x(mfn)) && (mfn_x(mfn) < mfn_x(mend))= ) + { + vaddr_t offset =3D mfn_to_maddr(mfn) - mfn_to_maddr(mstart); + + return (lpae_t *)(XEN_VIRT_START + offset); + } + } + return map_domain_page(mfn); } =20 static void xen_unmap_table(const lpae_t *table) { + /* + * During early boot, xen_map_table() will not use map_domain_page() + * for page-tables residing in Xen binary. So skip the unmap part. + */ + if ( system_state =3D=3D SYS_STATE_early_boot && is_kernel(table) ) + return; + unmap_domain_page(table); } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel