From patchwork Fri Dec 21 16:26:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154408 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117807ljp; Fri, 21 Dec 2018 08:29:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/X50mbYu4eR+MP0BAkL2mIcQWQF7tFPpmnRau9GgBEdhfJHc/INBkW6qNl14PZU8aQp64gz X-Received: by 2002:a0d:ca84:: with SMTP id m126mr3238606ywd.59.1545409743255; Fri, 21 Dec 2018 08:29:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545409743; cv=none; d=google.com; s=arc-20160816; b=alBdccpxE9mL7cTVauk8JMCVeQve/ELjbiguMEYKFo8ug/jwBD59uCNmMjXHTELqQt QSgFsRpqrjNvnZ4GX5R8ELirtU3m/C8rJ9viTs1aBmGnYCeTGhSOoLO6OX1pl1FBMwo2 G6ApHYXEFqgAQsK4y4hUctWS3Vv14E4PJg3r6BPJ9sOqxLmZhQe/rK821DU+u2/jnHzr 6+QLJNcN8FVZdpbGMhC4S4VCrL9Ak7Qr7vOnHXfsQgDpFUsZi0WxqcNs4SmK16yhwMc9 6ea3IVeTZSXl4+G1uQSBA25HuqK3gWHYrFDld+HZH4eMlp0ap5XmIA/deY78fiDVtpkU oKnQ== 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=UoNJhs7xcVE2eIo1CRko2o/rCLb+F4g2Ywx6N04oTtI=; b=z6s+4IwZo6DBp75KspP2RtuBSc55nfddd05gIKk92fllunQJ5iAuhe0s+lE51SBzZa pDIKQwOwJjFJpZTSMiX1UjA+Cn8jHGrSabJTe72rmtD5ycFWBzeBzuJdP7qY/fAeUj1G WRwGTBhfsSvks7+n75IlAjRbYgMwmc9kgd/jwkCdm2fx29+fYJlAdwDq/NQ799/e4XLg xSkryLLARVEwfAOukeU16QsXtMVekyYoDihk0jsFqEafafWtcpkCmJohwwkI2Kxsk8bR GoMpjkBNGRTwDPLHjyRH6B9mNZEGBt/XeIUrwPKe7wyA//0KJJ53lV4yLrEh9Zwy7bOC XVng== 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 s186si15961502ywf.144.2018.12.21.08.29.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 08:29:03 -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 1gaNdg-00067Z-1Q; Fri, 21 Dec 2018 16:27:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gaNde-00067N-O6 for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:02 +0000 X-Inumbo-ID: 3ec14e20-053d-11e9-b9f0-4fe8a0a963b7 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3ec14e20-053d-11e9-b9f0-4fe8a0a963b7; Fri, 21 Dec 2018 16:27:01 +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 307831596; Fri, 21 Dec 2018 08:27:01 -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 4172B3F5C0; Fri, 21 Dec 2018 08:27:00 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:43 +0000 Message-Id: <20181221162650.11515-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181221162650.11515-1-julien.grall@arm.com> References: <20181221162650.11515-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v3 1/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 patch, 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 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 v3: - Fix typeos - Add Stefano's reviewed-by - Fix coding style Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/p2m.c | 33 +++++++++++++++++++++++++++++++++ xen/include/asm-arm/p2m.h | 33 ++++----------------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 2b5e43f50a..7ae5b29699 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -406,6 +406,39 @@ 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);