From patchwork Fri Jun 14 17:51:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166867 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351225ilk; Fri, 14 Jun 2019 10:53:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTJrm/ArQ+yYmobBvRXLzPdFl+AehNddpME/Mb0CAeUgG5gGV6rV7gbHl7ynxE4NGkX1CP X-Received: by 2002:a6b:4107:: with SMTP id n7mr4232696ioa.12.1560534810614; Fri, 14 Jun 2019 10:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534810; cv=none; d=google.com; s=arc-20160816; b=T6HV9i9+c4QjBua48dF9HSzshCba/XLd8OVJOSHTGfJ5a8gWyn8J6pfrYlxAmmvXIV zJkbYC/apTTrtaB4mgAuB0SnPKKeePUK4VLb/migPq6J8b2JF5KLz42HtRwHnO9KIVHb BaAUMmIatuQLbm0XaVQ7B2aVWTkM9yWyQb8V/JQ1/Mzge0ByXSULOM+j9vzs1W4dnOOR Ph15ifsFlhMOSlulXzjyDpdAByXFzPtKGSMYBCbXBz87yCPduW5QskXdgBjOrT9GgJLp qaQxtbIRPyHbdt+s6ICfvi9H6YBywD2pnP05GmKE9xR11hwnuymmYnpjqp0GNS8s/UVc E//A== 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=6I6oLvgAH33N4xLc0KBuDXtK8crW9qnBmFRQ96NfwLI=; b=OrlvqdvfGfVssjzOTEb1fDvgCVA0OM+lipDg5hHEQwWJPLx5WhJIQn7SBm7M0TkeQC dPN09mWoJucKBjixKOB8uT8Gd52gpkq0SwlbO0MTrgVVgd2Dajuc0jsGDWk8zVFrYPLM jWesOj7/+gAT6W1hKAIq/ERI7JMd9sQkiYkbQ+nea4b6w/Cv5LePHK5D0pfMQ+ZZxWe6 VACe0skv9JLtFzyvPR/xbcPEJ46kYvOEl4AziE0IA6ePwvYf/o9/zvZDTqtD4t6utyBz RjS/K27Qt21BG3CJt6dyUAL6d+Y9GClkkg+JGNqav8RhuT5toNmY48UXZBE1WXBv2Dy3 pqxQ== 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 b79si4055304iof.13.2019.06.14.10.53.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:30 -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 1hbqMr-0001ps-Up; Fri, 14 Jun 2019 17:52:01 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbqMp-0001ob-Oj for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:51:59 +0000 X-Inumbo-ID: 1b4d369a-8ecd-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 1b4d369a-8ecd-11e9-8980-bc764e045a96; Fri, 14 Jun 2019 17:51:58 +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 CC1D0346; Fri, 14 Jun 2019 10:51:58 -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 E41BF3F718; Fri, 14 Jun 2019 10:51:57 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:41 +0100 Message-Id: <20190614175144.20046-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 6/9] 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 , Stefano Stabellini , Andrii Anisov 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 theory all the page-tables updated will reside in xenheap, in practice 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 Acked-by: Stefano Stabellini --- Changes in v3: - Fix typo in the commit message - Add Stefano's acked-by Changes in v2: - Add Andrii's reviewed-by --- 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 3f6d0e29d5..c3dd2c08ba 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -947,6 +947,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) { @@ -1016,6 +1026,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; @@ -1034,15 +1045,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) ) @@ -1067,7 +1080,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);