From patchwork Tue Nov 6 19:14:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150342 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274028ljp; Tue, 6 Nov 2018 11:17:20 -0800 (PST) X-Google-Smtp-Source: AJdET5evU5LulyAHH9X7uJnDtDUjfkcGW/Wvx02vD/FYgRWGJxNGt8f9LKmzYy1q1cuAGTrE9jq/ X-Received: by 2002:a81:28d1:: with SMTP id o200-v6mr26416280ywo.74.1541531840666; Tue, 06 Nov 2018 11:17:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531840; cv=none; d=google.com; s=arc-20160816; b=Gg5xaqtnwfYDfiQ19FiZZveKgh1uP2IQaGmH7qih1Gy6A5k45h81pWmsMvkwMb8ECM g5A+FRgZS016cz1IXm9Ga4lr5scD4J3z9qdxKgTIZhUKDc2zi3pobnrJ90uCE7X0Fkr/ pX8XB8Q0uZqxmTzfnSL5jJMJN+mfsSHheNpB+cb4blwgxURODRFuaXRmbDPOi2/EUDdd W6gBrKXDQj/W2FFy01QbpjsTJ6lhZqcjbzwy4ggi9b9sdqmtXIYGLjm/rbAWwGo8lF7Z bGEmuyHY/9ZzKvhIKaKLNzAVC1AMmxLbQKNu4q1qqo0yo/Izwib3xktUgBQaHwVIjlrX xIaA== 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=katsBz+yU7/TRr1UmNHZIldNWOZT/bMKTUa34v0pxaI=; b=LOJMCXXTsq1kxH+xNE657Mw8K8ydHLfZ13r6aelRkpOh7xC2+D1hGJO5PybcZwk9vD sG8nZ39S0puosg3cz7BbPmsLPPz5usA6XAcfZEuU7ThaHgvBQXaQ1EH0AtQzje3yPwpQ 2U8/yfIVfu8YTUu99//chltMJiIF5+QRHeV5OI+pR5mE/3UgqDD+NaOrSXtAalgrQ49i r+Mo+k/ZzoRlylPFvjwZ6oSPXO7BGfU/oRRJdb9aC3CkSw43zj7PoGLElXcaPB2O6xQ2 Ca3MhFLZdaBMp3QZJHCYvx/BHPEvWUfKUa3ywjRsy7PvfB9sx7StqQFG9L1GLvA5iOvw xtJQ== 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 s65-v6si1289197ywe.177.2018.11.06.11.17.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:20 -0800 (PST) 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 1gK6of-0003cA-Ik; Tue, 06 Nov 2018 19:15:09 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gK6od-0003bj-KJ for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:07 +0000 X-Inumbo-ID: 45700ad8-e1f8-11e8-9a16-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 45700ad8-e1f8-11e8-9a16-bc764e045a96; Tue, 06 Nov 2018 19:15:06 +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 90A3915BF; Tue, 6 Nov 2018 11:15:06 -0800 (PST) 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 C896B3F718; Tue, 6 Nov 2018 11:15:05 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:48 +0000 Message-Id: <20181106191454.22143-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181106191454.22143-1-julien.grall@arm.com> References: <20181106191454.22143-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 2/8] xen/arm: p2m: Introduce p2m_get_page_from_gfn 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: Julien Grall MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In a follow-up patches, we will need to handle get_page_from_gfn differently for DOMID_XEN. To keep the code simple move the current content in a new separate helper p2m_get_page_from_gfn. Note the new helper is a not anymore a static inline function as the helper is quite complex. Finally, take the opportunity to use typesafe gfn as the change is minor. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/p2m.c | 32 ++++++++++++++++++++++++++++++++ xen/include/asm-arm/p2m.h | 33 ++++----------------------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 30cfb01498..04c8718e9f 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -379,6 +379,38 @@ mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) return mfn; } +struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn, + p2m_type_t *t) +{ + struct page_info *page; + p2m_type_t p2mt; + mfn_t mfn = p2m_lookup(d, gfn, &p2mt); + + if (t) + *t = p2mt; + + if ( !p2m_is_any_ram(p2mt) ) + return NULL; + + if ( !mfn_valid(mfn) ) + return NULL; + page = mfn_to_page(mfn); + + /* + * get_page won't work on foreign mapping because the page doesn't + * belong to the current domain. + */ + if ( p2m_is_foreign(p2mt) ) + { + struct domain *fdom = page_get_owner_and_reference(page); + ASSERT(fdom != NULL); + ASSERT(fdom != d); + return page; + } + + return (get_page(page, d) ? page: NULL); +} + int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn, unsigned int order) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index c03557544a..a5914136e3 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -269,38 +269,13 @@ typedef unsigned int p2m_query_t; #define P2M_ALLOC (1u<<0) /* Populate PoD and paged-out entries */ #define P2M_UNSHARE (1u<<1) /* Break CoW sharing */ +struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn, + p2m_type_t *t); + static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { - struct page_info *page; - p2m_type_t p2mt; - mfn_t mfn = p2m_lookup(d, _gfn(gfn), &p2mt); - - if (t) - *t = p2mt; - - if ( !p2m_is_any_ram(p2mt) ) - return NULL; - - if ( !mfn_valid(mfn) ) - return NULL; - page = mfn_to_page(mfn); - - /* - * get_page won't work on foreign mapping because the page doesn't - * belong to the current domain. - */ - if ( p2m_is_foreign(p2mt) ) - { - struct domain *fdom = page_get_owner_and_reference(page); - ASSERT(fdom != NULL); - ASSERT(fdom != d); - return page; - } - - if ( !get_page(page, d) ) - return NULL; - return page; + return p2m_get_page_from_gfn(d, _gfn(gfn), t); } int get_page_type(struct page_info *page, unsigned long type);