From patchwork Thu Dec 20 19:23:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154359 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp50553ljp; Thu, 20 Dec 2018 11:26:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/X76SwdSNiQVG8SPfjZGUNfSC0xRAlMpRaJ9+IzOtiRLaplyFo24zziDenaroqmKuvu52hX X-Received: by 2002:a25:5d02:: with SMTP id r2-v6mr26014121ybb.88.1545333961945; Thu, 20 Dec 2018 11:26:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545333961; cv=none; d=google.com; s=arc-20160816; b=AS2GGHMKBJvsy4bGVYfwVplaeHLSiehc+arxnf4XnylVmZxpqSjPQMDgiJTmaag0OU I2wt1D8r2gtzv4ayPXnhTuBMl69WwKYqZWTrRhlTKzElmjIp/SF6ZyoJ8Ao0HEERrcqH V2zrAMzRLdr78hGAx8G7Q3N/MU26ncrM6E6bNAgeNOsIR9SwEoQL0wlqg768YQPGq0Su ckHflqMHeaH3vPj8/wzVsI+rLuRmwqyZ5tpbOqRcRHFxNhYmjuI6xpsjscA6nGqcEFDh uJ1L5IweBCe7rmA5BzVgtqSiLjG5gJVsnFSKB5Z3chy+sjBNerQwIqJN+cU6Wld5/j2l M28w== 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=YhjDQu2OKUegIQ9jZgAQ4UCKJ40WEXmA282w8iVRck4=; b=QjBEkQrm0BuQAb/kq830rOE+CT6M0TZF8tPuLHghH+CyLtjNkHsX3FIf8URtYEbSTs TBxCRG0yU7LqDgZZldaX88PasMNS3eEanXj+Ub3g+Tzav37XoA9/CW3ms0IA3q4l9AFN iRkgDvE+oDUNXy7njQjd51Ok4yqCfheqPJQjYLaahTYUhXPq/hGguSaCAbUE5R938WIj yIgSW3VpfHhlL+EbxZrqZafqvRDp9rJ6ojtBAP5V8qv5MaubtEvAV1DTcWLP634IVt2h ZIMc074VSR2sf92oeeYFtsE/qKtJCO331t0U68mlQZv/XCfesnRmnoGIQvYNcOtm2Mhc apSQ== 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 s32si13463306ybe.386.2018.12.20.11.26.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Dec 2018 11:26:01 -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 1ga3vF-0001x4-D3; Thu, 20 Dec 2018 19:23:53 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ga3vD-0001wi-Nt for xen-devel@lists.xenproject.org; Thu, 20 Dec 2018 19:23:51 +0000 X-Inumbo-ID: c7c4a770-048c-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id c7c4a770-048c-11e9-8e1d-bc764e045a96; Thu, 20 Dec 2018 19:23:50 +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 5C54615AD; Thu, 20 Dec 2018 11:23:50 -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 6E02B3F575; Thu, 20 Dec 2018 11:23:49 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 20 Dec 2018 19:23:32 +0000 Message-Id: <20181220192338.17526-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181220192338.17526-1-julien.grall@arm.com> References: <20181220192338.17526-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 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 , sstabellini@kernel.org, Andrii Anisov 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 Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- 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 2b5e43f50a..cd34149d13 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -406,6 +406,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 01cd3ee4b5..4db8e8709d 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -289,38 +289,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);