From patchwork Tue Oct 15 19:16: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: 176399 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6333138ill; Tue, 15 Oct 2019 12:18:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4Oz02r7ZB3HL8QkF7VDocGt7ZeGlzURq2kbcivUqQT3NUsVbHYj4ES/1CcffA9AjHCSZD X-Received: by 2002:a6b:7f01:: with SMTP id l1mr2166103ioq.90.1571167080632; Tue, 15 Oct 2019 12:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571167080; cv=none; d=google.com; s=arc-20160816; b=qp6S8usy7GgzhfRYkwIv873ht20m8fRmp/CtQPD+Rj3XzM0i+5Av0VT0c3WlIlqdn4 WQg9fOdUjtjHZgsnsYVZoJnoNjFSTPSrlWnx67kwFDjgpJCm7QSmPv8nrF+19a/Dedtg KaKJBL/dDEoz4LBfqdYGHM4bgzlF7J9bTIm946Jip7ZB96WPiELscETIvp9QcES1DuUM CGIPmfjIiBFlJIRHKhhajusjxUZ4jv8PaP1eT1j0BpxHvgCqnFqRTWILyybEiRRYR/JH kzmuTrleQmRnDN/VkQIZ2Ne9SxNTWo7TeM8Bx3CzfLt7nplVI19THxnAvxAVZ5EQfdce 5ffQ== 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:message-id:date:to:from; bh=0rXXl5N1OJtm8q6f9HLpXGr0xQpZc9PCifvUIS/jrVA=; b=ZmuNvaTtVNJbrr73k/AK6ivRVRFVBqGO6jyt5Rjmwh9IONd5uzLCe0XszRousKtdLs NvrOYXxjVJQIvEf99B8Pmdz4WxTD9GO6OoPCHLBx5U8NhemaiiJt2RjvlTWeXlpoiPhv 7bFctHgDwMLLdEcf7hNbI1QeV6G7Y6W+zRD98QDF8kBE+Ko0/FOwIjdJVBmt2WtZi3jb P0GJ8/bftfAUhmat0SXndt1PJM+CAhbYGRDkf9yAubej2EHYWSRk7cXH1Zfy5LNoVLCZ 4rDjCMYGASw8c+X0/wrhW3tRY22lqh5+OPgJ3G5gTuXnVovSKsDdIFuiZIa59niSaZfM VAfQ== 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 j64si8349770ili.89.2019.10.15.12.18.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Oct 2019 12:18:00 -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 1iKSIv-0003k7-1f; Tue, 15 Oct 2019 19:16:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iKSIt-0003k2-5K for xen-devel@lists.xenproject.org; Tue, 15 Oct 2019 19:16:19 +0000 X-Inumbo-ID: 41ddcc86-ef80-11e9-a531-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 41ddcc86-ef80-11e9-a531-bc764e2007e4; Tue, 15 Oct 2019 19:16:15 +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 BD29E28; Tue, 15 Oct 2019 12:16:14 -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 D289B3F718; Tue, 15 Oct 2019 12:16:13 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 15 Oct 2019 20:16:10 +0100 Message-Id: <20191015191610.28680-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH for-4.13 v3] 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 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=0x5 (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, clear}_fixmap()') Signed-off-by: Julien Grall Release-acked-by: Juergen Gross Reviewed-by: Stefano Stabellini --- Changes in v3: - Use is_xen_fixed_mfn - Add a comment about demoting the type. Changes in v2: - Add RaB Juergen - Rework the check to avoid truncation Note this patch relies on is_xen_fixed_mfn to be correct (see [1]). [1] https://lists.xen.org/archives/html/xen-devel/2019-10/msg01138.html --- xen/arch/arm/mm.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index be23acfe26..4514bc6bb0 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -964,11 +964,41 @@ static int create_xen_table(lpae_t *entry) 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 == SYS_STATE_early_boot ) + { + if ( is_xen_fixed_mfn(mfn) ) + { + /* + * It is fine to demote the type because the size of Xen + * will always fit in vaddr_t. + */ + vaddr_t offset = mfn_to_maddr(mfn) - virt_to_maddr(&_start); + + return (lpae_t *)(XEN_VIRT_START + offset); + } + } + return map_domain_page(mfn); } 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 == SYS_STATE_early_boot && is_kernel(table) ) + return; + unmap_domain_page(table); }