From patchwork Wed Apr 24 16:59: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: 162791 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895674jan; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGvD1q5qjogDw3vHMhu0EjsvoX4lbu/1YeCNaVRp95hL1aFemjvZJOXx/hKE8sKDzHOIa+ X-Received: by 2002:a25:6f83:: with SMTP id k125mr27758995ybc.106.1556125313400; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125313; cv=none; d=google.com; s=arc-20160816; b=vivkTaH3Qjr8y2Lb8tXxam3sxiI1BGnlRqZCi7IFq6tQuk/JHNQ1rgXNPYJ2eHobWW k4g/gxXGR6Fat6sC/ItGCIkG+lRJVI307fw3wt1LZoaI/RP1ZiyHkBYbwYL2CHSPOu2C TItyvq4jOqPySv0CTcY3nL5cgqQoQj8jl9lptlGaerNWDhp38zm7jT0WETVzXCBR7Wr0 6NJyWFFYdvVNCqQopEr02enHy1Esvc813rH9SmJZ4mUBCU/dWySSVNwYxXq7LqRxz6Ld t5JP3zWlGgqdxVBtSaNeeeO9kfDQOBzGcNHKcZKoXQVHgzxEEiz7WesI6UlYHrpAgf1o Idzg== 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=CVOwkPIQIV7WD0PjnnuTpAx04DTIUnAjo6Z3+BVP+34=; b=qEjFRNyiCgwWvyiCc6DSFWkUXGJIxULLsIJn91m6hqbt8YvDFyiEFhcc94HEM7Zl03 y8I8mBh7fUt3FhWJallsD5nl/5cnmuVzIb3wrJ31QPpIlsjZRNOpqFgSGgxmOd64Lzfy ZcJiKtbm22hit6JpnFXGhcobqi/7ajq5dFEixQ/bNalbGZUzfsyTniS5e6YmT7hjzqCI rBqrxZQS7CgBppkJHRNGMIHnqI6GOBsc266r68CzUPhXfJBTiG4r3wI9zycfF7n1yMcE bRH2VjHQS3k4aeI3vYQY4Y38gaISlgBPIVuLV+KqNUcKhTc5+AmDq6YFAl+RjWykiUCp ajng== 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 d9si7146576ywa.58.2019.04.24.10.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01: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 1hJLFr-0007pc-Mo; Wed, 24 Apr 2019 17:00:19 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFq-0007ou-7w for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:18 +0000 X-Inumbo-ID: 6f5498a0-66b2-11e9-92d7-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6f5498a0-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:17 +0000 (UTC) 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 D40E7374; Wed, 24 Apr 2019 10:00:16 -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 B99843F557; Wed, 24 Apr 2019 10:00:15 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:52 +0100 Message-Id: <20190424165955.23718-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 09/12] xen/arm: mm: Use {, un}map_domain_page() to map/unmap Xen 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, the virtual address of the 3rd level page-tables is obtained using mfn_to_virt(). On Arm32, mfn_to_virt can only work on xenheap page. While in practice all the page-tables updated will reside in xenheap, in practive the page-tables covering Xen memory (e.g xen_mapping) is part of Xen binary. Furthermore, a follow-up change will update xen_pt_update_entry() to walk all the levels and therefore be more generic. Some of the page-tables will also part of Xen memory and therefore will not be reachable using mfn_to_virt(). The easiest way to reach those pages is to use {, un}map_domain_page(). While on arm32 this means an extra mapping in the normal cases, this is not very important as xen page-tables are not updated often. In order to allow future change in the way Xen page-tables are mapped, two new helpers are introduced to map/unmap the page-tables. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 97e876d866..115e8340f1 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -969,6 +969,16 @@ static int create_xen_table(lpae_t *entry) return 0; } +static lpae_t *xen_map_table(mfn_t mfn) +{ + return map_domain_page(mfn); +} + +static void xen_unmap_table(const lpae_t *table) +{ + unmap_domain_page(table); +} + /* Sanity check of the entry */ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) { @@ -1031,6 +1041,7 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, unsigned int flags) { + int rc; lpae_t pte, *entry; lpae_t *third = NULL; @@ -1049,15 +1060,17 @@ static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, BUG_ON(!lpae_is_valid(*entry)); - third = mfn_to_virt(lpae_get_mfn(*entry)); + third = xen_map_table(lpae_get_mfn(*entry)); entry = &third[third_table_offset(addr)]; + rc = -EINVAL; if ( !xen_pt_check_entry(*entry, mfn, flags) ) - return -EINVAL; + goto out; /* If we are only populating page-table, then we are done. */ + rc = 0; if ( flags & _PAGE_POPULATE ) - return 0; + goto out; /* We are removing the page */ if ( !(flags & _PAGE_PRESENT) ) @@ -1082,7 +1095,12 @@ static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, write_pte(entry, pte); - return 0; + rc = 0; + +out: + xen_unmap_table(third); + + return rc; } static DEFINE_SPINLOCK(xen_pt_lock);