From patchwork Tue Nov 6 19:14:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150347 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274063ljp; Tue, 6 Nov 2018 11:17:23 -0800 (PST) X-Google-Smtp-Source: AJdET5ehG9DbtMLiWbcGXqcBJIivALbo2Jsy2AkojthbE5ahpUhi+pvds/5KQyUq/PShS39dziK7 X-Received: by 2002:a81:2156:: with SMTP id h83-v6mr6435535ywh.9.1541531843250; Tue, 06 Nov 2018 11:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531843; cv=none; d=google.com; s=arc-20160816; b=nc0LevNL19kBJMYhaaBWgnutXPBcXKVbZTvyfBqz1b5adCwfm64ETygGsgE/lMEUaF eT/RDol6zbLQeriAEfk4pE9VP17EIPl40OabXXcm+W5Azjg4tPegbI2nfgxfc5k99A6f djew9TnTZU/++E2nO6L0TitpoxeQ/lqjtXhOGvnx0CpE2hqWKpfudZeh46gcwR95x2Fi nLQYIzagUrWsgMesm7XB51m7+XVtR1uFoFf/01yUIMsR8k5UHYLBv4EAxYz7cGdfltXe I7J+GwzvoGqTavwoa47mc3MsltnKLVAVb9JxhMn6fAue75qTbckE2L8+ch3c43RnIZAq eoZg== 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=8e4iTU1+5oTWBMUdWKQNQBTRkQ9xWyAy/unG3YCog40=; b=vql660/tT036FAYaHlxpWg6hIpCKly2Ayj3f/sIU9moiuEps+BFYtmqll+KzQ/E9OZ rXXATcYyO8ijAnna5px523xmJcNez4AIDHiSVs7AmWlt5yA2byUqltVHH6ftIyl9NG9u Mp5YWacW6DfZOjSc08KlKYssVjEhlCQFfOxIde4TutBH7gpw+vBtRCzOKN2MG+BY3YwX k33CZo/7JFl8VD+fnRWFFFheY69nxT6HVt3V5eZivgRVmNkSMK6mtkb/w9MCdMdO/BNA vRAo/hbZVVzTfvb1fi/3RpcWWvyUbh0mlBOcOcUjesi+RVDjqLhZQaVZr8YaRoDSv+Xu fR5Q== 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 g16-v6si21108365ybh.28.2018.11.06.11.17.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:23 -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 1gK6oe-0003bq-91; Tue, 06 Nov 2018 19:15:08 +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 1gK6oc-0003bb-SC for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:06 +0000 X-Inumbo-ID: 44f1f0aa-e1f8-11e8-9fee-12d6303a7972 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 44f1f0aa-e1f8-11e8-9fee-12d6303a7972; 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 8B4911596; Tue, 6 Nov 2018 11:15:05 -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 9D7813F718; Tue, 6 Nov 2018 11:15:03 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:47 +0000 Message-Id: <20181106191454.22143-2-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 1/8] xen/page_alloc: Move get_pg_owner()/put_pg_owner() from x86 to common code 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: Wei Liu , Benjamin Sanda , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Benjamin Sanda get_pg_owner() and put_pg_owner() will be necessary in a follow-up commit to support xentrace on Arm. So move the helper to common code. Note that put_pg_owner() has been turned to a macro rather than static inline because of inter-dependency between includes. Signed-off-by: Benjamin Sanda [julien: Rework commit title / turn put_pg_owner to a macro] Signed-off-by: Julien Grall --- xen/arch/x86/mm.c | 42 ------------------------------------------ xen/common/page_alloc.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 3 +++ 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index f043e43ac7..9363e9bd96 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3100,48 +3100,6 @@ static int vcpumask_to_pcpumask( } } -static struct domain *get_pg_owner(domid_t domid) -{ - struct domain *pg_owner = NULL, *curr = current->domain; - - if ( likely(domid == DOMID_SELF) ) - { - pg_owner = rcu_lock_current_domain(); - goto out; - } - - if ( unlikely(domid == curr->domain_id) ) - { - gdprintk(XENLOG_WARNING, "Cannot specify itself as foreign domain\n"); - goto out; - } - - switch ( domid ) - { - case DOMID_IO: - pg_owner = rcu_lock_domain(dom_io); - break; - case DOMID_XEN: - pg_owner = rcu_lock_domain(dom_xen); - break; - default: - if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL ) - { - gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid); - break; - } - break; - } - - out: - return pg_owner; -} - -static void put_pg_owner(struct domain *pg_owner) -{ - rcu_unlock_domain(pg_owner); -} - long do_mmuext_op( XEN_GUEST_HANDLE_PARAM(mmuext_op_t) uops, unsigned int count, diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 16e1b0c357..ef1b4f596a 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -146,6 +146,7 @@ #include #include #include /* for highmem_start only */ +#include #else #define p2m_pod_offline_or_broken_hit(pg) 0 #define p2m_pod_offline_or_broken_replace(pg) BUG_ON(pg != NULL) @@ -2447,6 +2448,43 @@ static __init int register_heap_trigger(void) } __initcall(register_heap_trigger); +struct domain *get_pg_owner(domid_t domid) +{ + struct domain *pg_owner = NULL, *curr = current->domain; + + if ( likely(domid == DOMID_SELF) ) + { + pg_owner = rcu_lock_current_domain(); + goto out; + } + + if ( unlikely(domid == curr->domain_id) ) + { + gdprintk(XENLOG_WARNING, "Cannot specify itself as foreign domain\n"); + goto out; + } + + switch ( domid ) + { + case DOMID_IO: + pg_owner = rcu_lock_domain(dom_io); + break; + case DOMID_XEN: + pg_owner = rcu_lock_domain(dom_xen); + break; + default: + if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL ) + { + gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid); + break; + } + break; + } + + out: + return pg_owner; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 054d02e6c0..dd4d990ae3 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -589,6 +589,9 @@ int xenmem_add_to_physmap_one(struct domain *d, unsigned int space, int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp, unsigned int start); +struct domain *get_pg_owner(domid_t domid); +#define put_pg_owner(pg_owner) rcu_unlock_domain(pg_owner) + /* Return 0 on success, or negative on error. */ int __must_check guest_remove_page(struct domain *d, unsigned long gmfn); int __must_check steal_page(struct domain *d, struct page_info *page, 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); From patchwork Tue Nov 6 19:14:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150349 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274097ljp; Tue, 6 Nov 2018 11:17:24 -0800 (PST) X-Google-Smtp-Source: AJdET5dAa3JnUSmA/YtaY94GZ/rA+cf0Kn7WcXFZoK97wlHKuO2ka3PhQODvPjKZDRBSB6aLRVcf X-Received: by 2002:a25:4a05:: with SMTP id x5-v6mr9002485yba.267.1541531844802; Tue, 06 Nov 2018 11:17:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531844; cv=none; d=google.com; s=arc-20160816; b=CmTEJbJzinqsX/wB1d8JKbzc2L6XPldJllryCvlr3XgCmdYB8V5XnXjC3cujzHZSqT N2bfw46t5eK6mh6I7zGdbINELPgrJG7fLlF2JLg1g4RqPo7Bx6L00BkuWIoUmBKhHbo2 tx0+DR9rTgaO5u7nd+GnfIcDxYoJyohUgC9VKRB40bL1GBi6rJucUo5nKZOAzRzXvZLT tnnJMz0L0RggA+8jUw28ihDGT46p6wC5Ggv9YS6mDUpzhc27rFrIDRa+LTP0Xns5u+QA TC6plbqNDePjUbECoAJj88CbPWZqhsLypztayFjIkIfun872jIo+svUuKoMzRfyjZeDT qTUA== 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=8laReRPUdNuxZNAmnUHpp4NVYoEAVOouLOQXJVmEXrw=; b=U4qFwLDv4pWXhg/VDabkQbUpWtSnB2oWL0T5/QS+35++IWz2Reqg5k7YuPal8SScxK h3QtpA26c8EJ/DpXzgXbx/tjrFSq2CGUMj2dZ9lLWKmqfkO5NcYxD0D27lAdgqTQz862 Qr3e5JkeU8gUZGGUbBNpPJhcJ9FlxO3vThZzurCtb4NrjBSqwayOtvG4Ldopc5LHKZ47 31Z8bhCNSXY5C/+AZwyNtfPeR9+fjtm/o5SR92VU7CBW/zueB+4nsRgfIQQnkYzvShOB 8wDv7JCay2t8qIe+1CwBw8wdD44v4MMMisiwCyek6oCqSPmvk8dpMoFTZGBmqvPpwUaQ /qpg== 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 r64-v6si3763901ywf.68.2018.11.06.11.17.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:24 -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-0003cI-Su; 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 1gK6of-0003c1-8K for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:09 +0000 X-Inumbo-ID: 46317124-e1f8-11e8-9a16-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 46317124-e1f8-11e8-9a16-bc764e045a96; Tue, 06 Nov 2018 19:15:08 +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 95C151650; Tue, 6 Nov 2018 11:15:07 -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 CE23D3F718; Tue, 6 Nov 2018 11:15:06 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:49 +0000 Message-Id: <20181106191454.22143-4-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 3/8] xen/arm: Rename p2m_map_foreign to p2m_map_foreign_rw 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" A follow-up patch will introduce another type of foreign mapping. Rename the type to make clear it is only used for read-write mapping. No functional changes intended. Signed-off-by: Julien Grall --- xen/arch/arm/mm.c | 2 +- xen/arch/arm/p2m.c | 2 +- xen/include/asm-arm/p2m.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7a06a33e21..cec821c3a3 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1283,7 +1283,7 @@ int xenmem_add_to_physmap_one( } mfn = page_to_mfn(page); - t = p2m_map_foreign; + t = p2m_map_foreign_rw; rcu_unlock_domain(od); break; diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 04c8718e9f..b32b16cd94 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -440,7 +440,7 @@ static void p2m_set_permission(lpae_t *e, p2m_type_t t, p2m_access_t a) break; case p2m_iommu_map_rw: - case p2m_map_foreign: + case p2m_map_foreign_rw: case p2m_grant_map_rw: case p2m_mmio_direct_dev: case p2m_mmio_direct_nc: diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index a5914136e3..5f7f31186d 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -117,7 +117,7 @@ enum p2m_type { p2m_mmio_direct_dev,/* Read/write mapping of genuine Device MMIO area */ p2m_mmio_direct_nc, /* Read/write mapping of genuine MMIO area non-cacheable */ p2m_mmio_direct_c, /* Read/write mapping of genuine MMIO area cacheable */ - p2m_map_foreign, /* Ram pages from foreign domain */ + p2m_map_foreign_rw, /* Read/write RAM pages from foreign domain */ p2m_grant_map_rw, /* Read/write grant mapping */ p2m_grant_map_ro, /* Read-only grant mapping */ /* The types below are only used to decide the page attribute in the P2M */ @@ -139,10 +139,10 @@ enum p2m_type { /* Useful predicates */ #define p2m_is_ram(_t) (p2m_to_mask(_t) & P2M_RAM_TYPES) -#define p2m_is_foreign(_t) (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign)) +#define p2m_is_foreign(_t) (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign_rw)) #define p2m_is_any_ram(_t) (p2m_to_mask(_t) & \ (P2M_RAM_TYPES | P2M_GRANT_TYPES | \ - p2m_to_mask(p2m_map_foreign))) + p2m_to_mask(p2m_map_foreign_rw))) static inline void p2m_altp2m_check(struct vcpu *v, uint16_t idx) From patchwork Tue Nov 6 19:14:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150344 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274037ljp; Tue, 6 Nov 2018 11:17:21 -0800 (PST) X-Google-Smtp-Source: AJdET5f/EmZW2NmlrpIbmrxza83ZYX63kci/+n45+ws4aZe+LyIrmd99MX3u5gJl68WTJ4LKj5QK X-Received: by 2002:a25:428b:: with SMTP id p133-v6mr27541773yba.178.1541531841509; Tue, 06 Nov 2018 11:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531841; cv=none; d=google.com; s=arc-20160816; b=Cz1JV8NP8facdUiyRwYMbpkCFcH43InHppbuNb0x6pmBkKRm/YWUzUlvLVbPdAr/CI 8ax1nT+eY3s9VujsJakq6JDd7o45rqWqx5tlrh2Tsx7ysgdPwJr2DYpbDQygTICRPiHI oIxL1qebCctzk+lN02tcqjO7uXflsB4Kur04sDojrdQjpqLn4yXdrt2Z19T/bdLoi/Dd 8HwoCWew3iOFVnCye2BgJWgDMLMa/G6SOcvqXljWHPV2h5vfVHxkenXS/3RDBoPxjdOR yTVCIMUO6hYFKV1Df5ido9JNeOrFDNNk/mJAR0KahpWq5+1rnF+TfsAUmdgoj+60791y xVyA== 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=QGaEn9afeWabg2ZcJ1pIGpEc10OaZ9Pi4iAvSOGtXro=; b=WcFfj/7gpEvsV0Y+7rme1nEPgEXxC8rvI1Hcpkn+bFfz4em9UQ0HnpxxqEqepmEaZy K9VEFewcSlsy8XSLzhsWb8Mk2JS8d6iXBe7IRCsbJMRBopnuX6qeHtO6R6BTEA7vyZ3Q 5oXWlTNZdVIvLc07akAkDiijU1o02MeTYol5dkM5sfQHJHy4XSTggASrlZSEH18BLU2G il+paOQ0Tvw28dY8UJdpRVWXTygtgT3tXPs5pqlhMUvGwO6Y8F3PgAeRlPIJ9y0e0jnF d056r74L1G/SAn8eOpD8SGr6GGh/XhYgPchyilojPR5oSv2pCiz7O05+EzWn3T66NSe7 Xt7w== 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 y197-v6si27953741ywa.431.2018.11.06.11.17.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:21 -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 1gK6oh-0003ca-7Z; Tue, 06 Nov 2018 19:15:11 +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 1gK6og-0003cO-3I for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:10 +0000 X-Inumbo-ID: 46a3b91a-e1f8-11e8-a1ec-12d6303a7972 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 46a3b91a-e1f8-11e8-a1ec-12d6303a7972; Tue, 06 Nov 2018 19:15:08 +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 9A7D11596; Tue, 6 Nov 2018 11:15:08 -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 D2D843F718; Tue, 6 Nov 2018 11:15:07 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:50 +0000 Message-Id: <20181106191454.22143-5-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 4/8] xen/arm: Add support for read-only foreign mappings 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" Current, foreign mappings can only be read-write. A follow-up patch will extend foreign mapping for Xen backend memory (via XEN_DOMID), some of that memory should only be read accessible for the mapping domain. Introduce a new p2m_type to cater read-only foreign mappings. For now, the decision between the two foreign mapping type is based on the type of the guest page mapped. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 2 +- xen/arch/arm/p2m.c | 1 + xen/include/asm-arm/p2m.h | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index cec821c3a3..e31b47a394 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1283,7 +1283,7 @@ int xenmem_add_to_physmap_one( } mfn = page_to_mfn(page); - t = p2m_map_foreign_rw; + t = (p2mt == p2m_ram_rw) ? p2m_map_foreign_rw : p2m_map_foreign_ro; rcu_unlock_domain(od); break; diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index b32b16cd94..0941be9e41 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -450,6 +450,7 @@ static void p2m_set_permission(lpae_t *e, p2m_type_t t, p2m_access_t a) break; case p2m_iommu_map_ro: + case p2m_map_foreign_ro: case p2m_grant_map_ro: case p2m_invalid: e->p2m.xn = 1; diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 5f7f31186d..7c67806056 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -118,6 +118,7 @@ enum p2m_type { p2m_mmio_direct_nc, /* Read/write mapping of genuine MMIO area non-cacheable */ p2m_mmio_direct_c, /* Read/write mapping of genuine MMIO area cacheable */ p2m_map_foreign_rw, /* Read/write RAM pages from foreign domain */ + p2m_map_foreign_ro, /* Read-only RAM pages from foreign domain */ p2m_grant_map_rw, /* Read/write grant mapping */ p2m_grant_map_ro, /* Read-only grant mapping */ /* The types below are only used to decide the page attribute in the P2M */ @@ -137,12 +138,16 @@ enum p2m_type { #define P2M_GRANT_TYPES (p2m_to_mask(p2m_grant_map_rw) | \ p2m_to_mask(p2m_grant_map_ro)) +/* Foreign mappings types */ +#define P2M_FOREIGN_TYPES (p2m_to_mask(p2m_map_foreign_rw) | \ + p2m_to_mask(p2m_map_foreign_ro)) + /* Useful predicates */ #define p2m_is_ram(_t) (p2m_to_mask(_t) & P2M_RAM_TYPES) -#define p2m_is_foreign(_t) (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign_rw)) +#define p2m_is_foreign(_t) (p2m_to_mask(_t) & P2M_FOREIGN_TYPES) #define p2m_is_any_ram(_t) (p2m_to_mask(_t) & \ (P2M_RAM_TYPES | P2M_GRANT_TYPES | \ - p2m_to_mask(p2m_map_foreign_rw))) + P2M_FOREIGN_TYPES)) static inline void p2m_altp2m_check(struct vcpu *v, uint16_t idx) @@ -275,7 +280,38 @@ struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn, static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { - return p2m_get_page_from_gfn(d, _gfn(gfn), t); + mfn_t mfn; + p2m_type_t _t; + struct page_info *page; + + /* + * Special case for DOMID_XEN as it is the only domain so far that is + * not auto-translated. + */ + if ( unlikely(d != dom_xen) ) + return p2m_get_page_from_gfn(d, _gfn(gfn), t); + + if ( !t ) + t = &_t; + + *t = p2m_invalid; + + /* + * DOMID_XEN see 1-1 RAM. The p2m_type is based on the type of the + * page. + */ + mfn = _mfn(gfn); + page = mfn_to_page(mfn); + + if ( !mfn_valid(mfn) || !get_page(page, d) ) + return NULL; + + if ( page->u.inuse.type_info & PGT_writable_page ) + *t = p2m_ram_rw; + else + *t = p2m_ram_ro; + + return page; } int get_page_type(struct page_info *page, unsigned long type); From patchwork Tue Nov 6 19:14:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150345 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274053ljp; Tue, 6 Nov 2018 11:17:22 -0800 (PST) X-Google-Smtp-Source: AJdET5eY+swI6ZNOWogmXiNrEvbnQgx+ebX8E0PmnVmiUgN6ZEs9xK2uqWVJU83mKV5OBBANFcGc X-Received: by 2002:a81:441e:: with SMTP id r30-v6mr26249501ywa.48.1541531842207; Tue, 06 Nov 2018 11:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531842; cv=none; d=google.com; s=arc-20160816; b=AI2b9bMyT/2PdVGbi/4Fa18PnRT2FPwS3l1LdbWR+h9pM+YWlV/VxyNLdRFGofSUdx /sk/MWQ9+XbEUr5QvbtSchTU7x/g63pe+x6kThVg8rFn2sPwevliGgqZ3mcd7ll095t5 JFvMB2Q7xfSmgunOp+Vf+lptr1gsiyPFKA93QXqGOKo39b5uDisPJ9pSLAP2e9muouwy 1BfNqgCz1w82vorzz+gejDxoT4Tn1Hw/Skl3UI4fYeDzp3d6JsYkSZVUIA1UNmu/3ssb xWwhQGPqgTcA+T30xen6NvseDpSilSAMbo2xGcfv+kUanFKkTW1Ezy43gs4lBAvxBxDb DhtQ== 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=5KBQRzf5WvRCGVMJlo/WgFDMYU7atSxiPnLtxslgGP0=; b=MZ/1dLZV2jkfV2wOVY8ISSXBvj90MWRcTNlTUIAX+2MFLG+ANI4lc2ed2QsZ7t+Es6 081YC+7cGZo1aUpUpBWGIctQh2ZOuX6zBMImUeN9oCo33gwAXilYUszcI2Bv3pI6cSWa +Npxdr857sHVJanakV0XbC1TDXw2VQ1oOIdZ8+GUK8FsF95YzTc3nJ8jgVWUkEunuofP pwJlQjuN63XLNJONgqVRK/wkw97PDDTvat46ZIl6Xf6pxeow6Y0EugyEdc3XoBlS5maD TmhqPhSGcvzjxVyPPZzzrU24zwbSaUb2liCi93465r7+A+OmnfXSrRlkUhT4Jw5h2U6h ibVg== 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 z6-v6si4387312ybg.136.2018.11.06.11.17.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:22 -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 1gK6oi-0003cv-HL; Tue, 06 Nov 2018 19:15:12 +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 1gK6oh-0003cb-9q for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:11 +0000 X-Inumbo-ID: 475798a4-e1f8-11e8-b36e-12d6303a7972 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 475798a4-e1f8-11e8-b36e-12d6303a7972; Tue, 06 Nov 2018 19:15:10 +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 A8DA5EBD; Tue, 6 Nov 2018 11:15:09 -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 D7E9C3F718; Tue, 6 Nov 2018 11:15:08 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:51 +0000 Message-Id: <20181106191454.22143-6-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 5/8] xen/arm: Allow a privileged domain to map foreign page from DOMID_XEN 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" For auto-translated domain, the only way to map page to itself is the using foreign map API. The current code does not allow mapping page from special page (such as DOMID_XEN). As xentrace buffer are shared using DOMID_XEN, it is not possible to use tracing for Arm. This could be solved by using the helper get_pg_owner(). This helper will be able to get a reference on DOMID_XEN and therefore allow mapping for privileged domain. This patch replace the call to rcu_lock_domain_by_any_id() with get_pg_owner(). For consistency, all the call to rcu_unlock_domain are replaced by put_pg_owner(). Signed-off-by: Julien grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index e31b47a394..72d0285768 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1249,20 +1249,20 @@ int xenmem_add_to_physmap_one( struct domain *od; p2m_type_t p2mt; - od = rcu_lock_domain_by_any_id(extra.foreign_domid); + od = get_pg_owner(extra.foreign_domid); if ( od == NULL ) return -ESRCH; if ( od == d ) { - rcu_unlock_domain(od); + put_pg_owner(od); return -EINVAL; } rc = xsm_map_gmfn_foreign(XSM_TARGET, d, od); if ( rc ) { - rcu_unlock_domain(od); + put_pg_owner(od); return rc; } @@ -1271,21 +1271,21 @@ int xenmem_add_to_physmap_one( page = get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC); if ( !page ) { - rcu_unlock_domain(od); + put_pg_owner(od); return -EINVAL; } if ( !p2m_is_ram(p2mt) ) { put_page(page); - rcu_unlock_domain(od); + put_pg_owner(od); return -EINVAL; } mfn = page_to_mfn(page); t = (p2mt == p2m_ram_rw) ? p2m_map_foreign_rw : p2m_map_foreign_ro; - rcu_unlock_domain(od); + put_pg_owner(od); break; } case XENMAPSPACE_dev_mmio: From patchwork Tue Nov 6 19:14:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150348 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274086ljp; Tue, 6 Nov 2018 11:17:24 -0800 (PST) X-Google-Smtp-Source: AJdET5c2d3PzLZi3ybWr1f2keJTaDPsJ5bzQwDXflcUqYXFujQrBzd4RS2R+eB16OjQkmxTuUtnL X-Received: by 2002:a25:f80e:: with SMTP id u14-v6mr26567438ybd.161.1541531844303; Tue, 06 Nov 2018 11:17:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531844; cv=none; d=google.com; s=arc-20160816; b=tKPz1u5EYq/Pue46j3qRBXp5pswV5JWk4g74grQhQoMw5rQMYtEfyfPnupwkrZNhYa CJFtRwB/h2qujNNmVu/GYLv5uQfrvxr4Fo2Vgw0dWvD1aRVPNwMPduIfgHizsNj+UTDu r1UER/WE8crpGIawHwIonlkNHhUyOgZQZMzCWmsyDFSWB0WytoQZizgcsFchM7559T7u PeKd3cHs7xm/eAXGe/3wRIFtymcq/cCm31DcLUJpr+Xbhzzd6OFttJIG2imzyJYR0+lV Ybe4xwwA4xNFyhCdj0coGMIDXaeIrUPb9YsuYEwOasv4QEQZ+Elt26ZYeEi8vAdFYTLK xVKw== 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=ppyQLX1uZRa/9Xb2PFbt5cvJ01uS19oNw6/8viRNDBI=; b=t4Unmh+l7l4q6zWh6OtnTBlQLfSx2vgSQF4aUFbiSXp6zzSd1tatz5MDWe1lo1i9Bj 7JeWHKadLnMHJAMfwqwvqE6XZgqKS6JU0QDvi+TzbFL6zUvEbVhe3UCiu4U1XedRT98h +EpOiPoQYx1oba4gef1pFPP4hh0cBodGy9shtoDEPPsd6rkciJxKd98KWuKp9eRof1va 1ew33P+yXudmMU050gNF/O0Sj0RfJ92KFK3t7G724qwPPRzKTpCXXTdXIJQKT6DxrKbC Nb5KaatTGYijOR0pxsUAp/5Qwz+TrrMHJXQLTPK0CUdqwfjVm2oqizcMCe3kONz/ImDK 4h6g== 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 e3-v6si11266114ybi.266.2018.11.06.11.17.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:24 -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 1gK6oj-0003dS-Qb; Tue, 06 Nov 2018 19:15:13 +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 1gK6oi-0003cp-GU for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:12 +0000 X-Inumbo-ID: 48017f4a-e1f8-11e8-9e65-12d6303a7972 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 48017f4a-e1f8-11e8-9e65-12d6303a7972; Tue, 06 Nov 2018 19:15:11 +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 CD9FE1596; Tue, 6 Nov 2018 11:15:10 -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 E26DB3F718; Tue, 6 Nov 2018 11:15:09 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:52 +0000 Message-Id: <20181106191454.22143-7-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 6/8] xen/arm: Initialize trace buffer 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 , Benjamin Sanda MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Benjamin Sanda Now that we allow a privileged domain to map tracing buffer, initialize them so a user can effectively trace Xen. Signed-off-by: Benjamin Sanda [julien: rework commit message] Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/setup.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 80f00286d3..7022904cc3 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -863,6 +864,8 @@ void __init start_xen(unsigned long boot_phys_offset, heap_init_late(); + init_trace_bufs(); + init_constructors(); console_endboot(); From patchwork Tue Nov 6 19:14:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150343 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274042ljp; Tue, 6 Nov 2018 11:17:21 -0800 (PST) X-Google-Smtp-Source: AJdET5euAMUyMtAsaYCz4k51flaGBsHo8qT70CUGbwlQD5hX90P2B+nLldVjj9EO4uJcZiTMiLBJ X-Received: by 2002:a25:ad11:: with SMTP id y17-v6mr26603175ybi.341.1541531841795; Tue, 06 Nov 2018 11:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531841; cv=none; d=google.com; s=arc-20160816; b=AP9VfKSZDWnREStX981blfPbtzrMLPzy2cjHi5FgGlOf8vhPz33emAcGeFh9S0w0mO o80CNq/Pki/NMz6d9Es13qls8qCcAhnTFpW+W0D6cjrdm1524DPygjfV4uOa5lDQr62O UMqcriLjfj/ZCdT4lcjG85pF0lcLeVdch1H1Li/oKJd7d0O67d3fYEazd3WGkRll6Xmn xrtxm9DWF0c3nwlYcmG9Wv5hyTHsK4Y9SzVQgcqJTkGoEvkZhtdOA20aD5oF5XBUhOyp 3upo46MUpTdy3GCoYr5Xfglw44h3XlQ1G4fdAQ/iAHs5Qr8sIrpxOZFEMjbgl+6b/96i SnfQ== 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=G/30Tq4xrfv+Uua0WOf44+PIxeZReDWTsG0SrHflPqk=; b=mRHxtE3xjepeMJVHM4szE6Zt36GVVaGCp3VL2tFFSmJWTyrhn5oeYaZYUFhxb36g/o GlkgokZ20Luw6mTpp1z44m1Gs/eJGJDERoCSp+RzkjziqZRs/7bx0sW3E4uPCAyip9Lp aEMTK/1r6+uwMMxALb89WjZRW0Bo17GYe699EYV1e3IrwxH2HHI9G+MhMocGn1YWyvos a2qkvdkLSCcJXERIXz9xVw9zTOB9uJ5Oa3P4urrKhaJ+GxFDSMFWG/IwB2tKGe9RRGQI doW5mpghfdCcuLlWSG4p5luC/QJaTsfgxPSP6BzYllwiRxR25XQ7ABK+PTv7uZTyTVs9 +Nrg== 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 x66-v6si28287473ybg.132.2018.11.06.11.17.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:21 -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 1gK6ok-0003eS-6B; Tue, 06 Nov 2018 19:15:14 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gK6oj-0003dL-Bp for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:13 +0000 X-Inumbo-ID: 48fce875-e1f8-11e8-9a16-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 48fce875-e1f8-11e8-9a16-bc764e045a96; Tue, 06 Nov 2018 19:15:12 +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 6CB35EBD; Tue, 6 Nov 2018 11:15:12 -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 17AE23F718; Tue, 6 Nov 2018 11:15:10 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:53 +0000 Message-Id: <20181106191454.22143-8-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 7/8] xenalyze: Build for Both ARM and x86 Platforms 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: George Dunlap , Wei Liu , Julien Grall , Ian Jackson , Benjamin Sanda MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Benjamin Sanda Modified to provide building of the xenalyze binary for both ARM and x86 platforms. The xenalyze binary is now built as part of the BIN list for both platforms. Signed-off-by: Benjamin Sanda Signed-off-by: Julien Grall Acked-by: Wei Liu --- tools/xentrace/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/xentrace/Makefile b/tools/xentrace/Makefile index 0bad942bdf..9fb7fc96e7 100644 --- a/tools/xentrace/Makefile +++ b/tools/xentrace/Makefile @@ -9,8 +9,7 @@ LDLIBS += $(LDLIBS_libxenevtchn) LDLIBS += $(LDLIBS_libxenctrl) LDLIBS += $(ARGP_LDFLAGS) -BIN-$(CONFIG_X86) = xenalyze -BIN = $(BIN-y) +BIN = xenalyze SBIN = xentrace xentrace_setsize LIBBIN = xenctx SCRIPTS = xentrace_format From patchwork Tue Nov 6 19:14:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150350 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274138ljp; Tue, 6 Nov 2018 11:17:27 -0800 (PST) X-Google-Smtp-Source: AJdET5f1fnUsld1wbiWv7hITFdADHCG098p8OJalT2KxKQXsASA8XgId1rfjLHhxwSKIOU/huxDN X-Received: by 2002:a25:628f:: with SMTP id w137-v6mr13590498ybb.322.1541531847263; Tue, 06 Nov 2018 11:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531847; cv=none; d=google.com; s=arc-20160816; b=sWI/zUbRImH8lkTd99tu3F/se9fB2Tq9v2S3w8bXGNf7u6DP3HW9YfRu5wLwreoKp5 wE1MH0XDH43XgHTbsRCwoaE44XGLJb0NZdm64vKUg3lyDP+U+UFrFhJqmrGw27+nxoMN 0vHzmlMWj25TxYG+xUhoNIDZ//H4D8sK7QoJVCOiSEmHTZXwImWqnyhzElsDZGbr1MUZ m3S5Ka9g2yIEJ7l2VjKGqO59B9u47L8y5JE0l/71pmONFgKhtlPehSdziPs11LYdePjd yu2K+zAEtkEIASkcivCS8xHp2jIJT0OBnaBwlPF8BBHALCKXltoY4OOC+8mHCqYGpDTM JBjA== 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=qrWBUQTt3fu+ohN6fSbQk+p5Hdu9+PbCwz2OSA7Lv4Y=; b=qvTJHdx1qu4UVN5w4FHG+20iCdAg1zEOpkxW4kmxirEbi3uek0kbnfzhNChAdP7H5b in0y/6MaMOjj6lq8puo2cmPXOQfidAUVND310wXIeYku6/jwwR8eVGS6IxCVEFprNqof 8CqVU6tIkJ2aI/gN3YTWnvNa4wEuDoH7vuEim4dznHU8FyPv+/hv+e2KYdvJEstyn2l/ b0gb05wpBzZ+jI6k6FI60Q9PIMQ/ejFC8dw507NGmU3PqQ1FBUMQbT0CGGXeV5yJK0lu U5QXkU/v91Jmam+jb8uLlB50PFNY28P7g83CEu5TBugXhdsR8ACCgG0ASKNEOc7IH91e IXOQ== 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 n9-v6si28951638ybp.250.2018.11.06.11.17.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:27 -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 1gK6on-0003hY-Q4; Tue, 06 Nov 2018 19:15:17 +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 1gK6om-0003gn-NT for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:16 +0000 X-Inumbo-ID: 4adfea58-e1f8-11e8-973d-12d6303a7972 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 4adfea58-e1f8-11e8-973d-12d6303a7972; Tue, 06 Nov 2018 19:15:16 +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 9E40BEBD; Tue, 6 Nov 2018 11:15:15 -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 ABCED3F718; Tue, 6 Nov 2018 11:15:12 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:54 +0000 Message-Id: <20181106191454.22143-9-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 8/8] xen: Swich parameter in get_page_from_gfn to use typesafe 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: Jun Nakajima , Kevin Tian , Wei Liu , Suravee Suthikulpanit , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Julien Grall , Paul Durrant , Jan Beulich , Boris Ostrovsky , Brian Woods MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional change intended. Only reasonable clean-ups are done in this patch. The rest will use _gfn for the time being. Signed-off-by: Julien Grall Signed-off-by: Julien Grall <julie.grall@arm.com>
--- xen/arch/arm/guestcopy.c | 2 +- xen/arch/arm/mm.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/domain.c | 12 ++++++------ xen/arch/x86/domctl.c | 6 +++--- xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/domain.c | 2 +- xen/arch/x86/hvm/hvm.c | 9 +++++---- xen/arch/x86/hvm/svm/svm.c | 8 ++++---- xen/arch/x86/hvm/viridian/viridian.c | 24 ++++++++++++------------ xen/arch/x86/hvm/vmx/vmx.c | 4 ++-- xen/arch/x86/hvm/vmx/vvmx.c | 12 ++++++------ xen/arch/x86/mm.c | 24 ++++++++++++++---------- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/mm/shadow/hvm.c | 6 +++--- xen/arch/x86/physdev.c | 3 ++- xen/arch/x86/pv/descriptor-tables.c | 5 ++--- xen/arch/x86/pv/emul-priv-op.c | 6 +++--- xen/arch/x86/pv/mm.c | 2 +- xen/arch/x86/traps.c | 11 ++++++----- xen/common/domain.c | 2 +- xen/common/event_fifo.c | 12 ++++++------ xen/common/memory.c | 4 ++-- xen/common/tmem_xen.c | 2 +- xen/include/asm-arm/p2m.h | 6 +++--- xen/include/asm-x86/p2m.h | 11 +++++++---- 26 files changed, 95 insertions(+), 86 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 7a0f3e9d5f..55892062bb 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -37,7 +37,7 @@ static struct page_info *translate_get_page(copy_info_t info, uint64_t addr, return get_page_from_gva(info.gva.v, addr, write ? GV2M_WRITE : GV2M_READ); - page = get_page_from_gfn(info.gpa.d, paddr_to_pfn(addr), &p2mt, P2M_ALLOC); + page = get_page_from_gfn(info.gpa.d, gaddr_to_gfn(addr), &p2mt, P2M_ALLOC); if ( !page ) return NULL; diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 72d0285768..88711096ef 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1268,7 +1268,7 @@ int xenmem_add_to_physmap_one( /* Take reference to the foreign domain page. * Reference will be released in XENMEM_remove_from_physmap */ - page = get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC); + page = get_page_from_gfn(od, _gfn(idx), &p2mt, P2M_ALLOC); if ( !page ) { put_pg_owner(od); diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c index 8a4f753eae..4d8f153031 100644 --- a/xen/arch/x86/cpu/vpmu.c +++ b/xen/arch/x86/cpu/vpmu.c @@ -607,7 +607,7 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params) struct vcpu *v; struct vpmu_struct *vpmu; struct page_info *page; - uint64_t gfn = params->val; + gfn_t gfn = _gfn(params->val); if ( (params->vcpu >= d->max_vcpus) || (d->vcpu[params->vcpu] == NULL) ) return -EINVAL; diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index f6fe954313..c5cce4b38d 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -797,7 +797,7 @@ int arch_set_info_guest( unsigned long flags; bool compat; #ifdef CONFIG_PV - unsigned long cr3_gfn; + gfn_t cr3_gfn; struct page_info *cr3_page; unsigned long cr4; int rc = 0; @@ -1061,9 +1061,9 @@ int arch_set_info_guest( set_bit(_VPF_in_reset, &v->pause_flags); if ( !compat ) - cr3_gfn = xen_cr3_to_pfn(c.nat->ctrlreg[3]); + cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat->ctrlreg[3])); else - cr3_gfn = compat_cr3_to_pfn(c.cmp->ctrlreg[3]); + cr3_gfn = _gfn(compat_cr3_to_pfn(c.cmp->ctrlreg[3])); cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC); if ( !cr3_page ) @@ -1092,7 +1092,7 @@ int arch_set_info_guest( case 0: if ( !compat && !VM_ASSIST(d, m2p_strict) && !paging_mode_refcounts(d) ) - fill_ro_mpt(_mfn(cr3_gfn)); + fill_ro_mpt(_mfn(gfn_x(cr3_gfn))); break; default: if ( cr3_page == current->arch.old_guest_table ) @@ -1107,7 +1107,7 @@ int arch_set_info_guest( v->arch.guest_table = pagetable_from_page(cr3_page); if ( c.nat->ctrlreg[1] ) { - cr3_gfn = xen_cr3_to_pfn(c.nat->ctrlreg[1]); + cr3_gfn = _gfn(xen_cr3_to_pfn(c.nat->ctrlreg[1])); cr3_page = get_page_from_gfn(d, cr3_gfn, NULL, P2M_ALLOC); if ( !cr3_page ) @@ -1132,7 +1132,7 @@ int arch_set_info_guest( break; case 0: if ( VM_ASSIST(d, m2p_strict) ) - zap_ro_mpt(_mfn(cr3_gfn)); + zap_ro_mpt(_mfn(gfn_x(cr3_gfn))); break; } } diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 33f9a869c0..6b0d8075cd 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -448,7 +448,7 @@ long arch_do_domctl( break; } - page = get_page_from_gfn(d, gfn, &t, P2M_ALLOC); + page = get_page_from_gfn(d, _gfn(gfn), &t, P2M_ALLOC); if ( unlikely(!page) || unlikely(is_xen_heap_page(page)) ) @@ -498,11 +498,11 @@ long arch_do_domctl( case XEN_DOMCTL_hypercall_init: { - unsigned long gmfn = domctl->u.hypercall_init.gmfn; + gfn_t gfn = _gfn(domctl->u.hypercall_init.gmfn); struct page_info *page; void *hypercall_page; - page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); if ( !page || !get_page_type(page, PGT_writable_page) ) { diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c index d6d0e8be89..3b3ad27938 100644 --- a/xen/arch/x86/hvm/dm.c +++ b/xen/arch/x86/hvm/dm.c @@ -186,7 +186,7 @@ static int modified_memory(struct domain *d, { struct page_info *page; - page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE); + page = get_page_from_gfn(d, _gfn(pfn), NULL, P2M_UNSHARE); if ( page ) { paging_mark_pfn_dirty(d, _pfn(pfn)); diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c index 5d5a746a25..73d2da8441 100644 --- a/xen/arch/x86/hvm/domain.c +++ b/xen/arch/x86/hvm/domain.c @@ -297,7 +297,7 @@ int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx) { /* Shadow-mode CR3 change. Check PDBR and update refcounts. */ struct page_info *page = get_page_from_gfn(v->domain, - v->arch.hvm.guest_cr[3] >> PAGE_SHIFT, + gaddr_to_gfn(v->arch.hvm.guest_cr[3]), NULL, P2M_ALLOC); if ( !page ) { diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 7be9cf4454..be262e5a1d 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2146,7 +2146,7 @@ int hvm_set_cr0(unsigned long value, bool may_defer) { struct vcpu *v = current; struct domain *d = v->domain; - unsigned long gfn, old_value = v->arch.hvm.guest_cr[0]; + unsigned long old_value = v->arch.hvm.guest_cr[0]; struct page_info *page; HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR0 value = %lx", value); @@ -2201,7 +2201,8 @@ int hvm_set_cr0(unsigned long value, bool may_defer) if ( !paging_mode_hap(d) ) { /* The guest CR3 must be pointing to the guest physical. */ - gfn = v->arch.hvm.guest_cr[3] >> PAGE_SHIFT; + gfn_t gfn = gaddr_to_gfn(v->arch.hvm.guest_cr[3]); + page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); if ( !page ) { @@ -2293,7 +2294,7 @@ int hvm_set_cr3(unsigned long value, bool may_defer) { /* Shadow-mode CR3 change. Check PDBR and update refcounts. */ HVM_DBG_LOG(DBG_LEVEL_VMMU, "CR3 value = %lx", value); - page = get_page_from_gfn(v->domain, value >> PAGE_SHIFT, + page = get_page_from_gfn(v->domain, gaddr_to_gfn(value), NULL, P2M_ALLOC); if ( !page ) goto bad_cr3; @@ -3120,7 +3121,7 @@ enum hvm_translation_result hvm_translate_get_page( && hvm_mmio_internal(gfn_to_gaddr(gfn)) ) return HVMTRANS_bad_gfn_to_mfn; - page = get_page_from_gfn(v->domain, gfn_x(gfn), &p2mt, P2M_UNSHARE); + page = get_page_from_gfn(v->domain, gfn, &p2mt, P2M_UNSHARE); if ( !page ) return HVMTRANS_bad_gfn_to_mfn; diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 5d00256aaa..a7419bd444 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -317,7 +317,7 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c) { if ( c->cr0 & X86_CR0_PG ) { - page = get_page_from_gfn(v->domain, c->cr3 >> PAGE_SHIFT, + page = get_page_from_gfn(v->domain, gaddr_to_gfn(c->cr3), NULL, P2M_ALLOC); if ( !page ) { @@ -2412,9 +2412,9 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t vmcbaddr) return NULL; /* Need to translate L1-GPA to MPA */ - page = get_page_from_gfn(v->domain, - nv->nv_vvmcxaddr >> PAGE_SHIFT, - &p2mt, P2M_ALLOC | P2M_UNSHARE); + page = get_page_from_gfn(v->domain, + gaddr_to_gfn(nv->nv_vvmcxaddr >> PAGE_SHIFT), + &p2mt, P2M_ALLOC | P2M_UNSHARE); if ( !page ) return NULL; diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 2dc86dd0f3..1d3be156db 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -332,16 +332,16 @@ static void dump_reference_tsc(const struct domain *d) static void enable_hypercall_page(struct domain *d) { - unsigned long gmfn = d->arch.hvm.viridian.hypercall_gpa.fields.pfn; - struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + gfn_t gfn = _gfn(d->arch.hvm.viridian.hypercall_gpa.fields.pfn); + struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); uint8_t *p; if ( !page || !get_page_type(page, PGT_writable_page) ) { if ( page ) put_page(page); - gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", - gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); + gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", + gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); return; } @@ -367,8 +367,8 @@ static void enable_hypercall_page(struct domain *d) static void initialize_vp_assist(struct vcpu *v) { struct domain *d = v->domain; - unsigned long gmfn = v->arch.hvm.viridian.vp_assist.msr.fields.pfn; - struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + gfn_t gfn = _gfn(v->arch.hvm.viridian.vp_assist.msr.fields.pfn); + struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); void *va; ASSERT(!v->arch.hvm.viridian.vp_assist.va); @@ -395,8 +395,8 @@ static void initialize_vp_assist(struct vcpu *v) return; fail: - gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", - gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); + gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", + gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); } static void teardown_vp_assist(struct vcpu *v) @@ -465,16 +465,16 @@ void viridian_apic_assist_clear(struct vcpu *v) static void update_reference_tsc(struct domain *d, bool_t initialize) { - unsigned long gmfn = d->arch.hvm.viridian.reference_tsc.fields.pfn; - struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + gfn_t gfn = _gfn(d->arch.hvm.viridian.reference_tsc.fields.pfn); + struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); HV_REFERENCE_TSC_PAGE *p; if ( !page || !get_page_type(page, PGT_writable_page) ) { if ( page ) put_page(page); - gdprintk(XENLOG_WARNING, "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", - gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); + gdprintk(XENLOG_WARNING, "Bad GFN %#"PRI_gfn" (MFN %#"PRI_mfn")\n", + gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN)); return; } diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index e065f8bbdb..2070e78358 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -674,7 +674,7 @@ static int vmx_restore_cr0_cr3( { if ( cr0 & X86_CR0_PG ) { - page = get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT, + page = get_page_from_gfn(v->domain, gaddr_to_gfn(cr3), NULL, P2M_ALLOC); if ( !page ) { @@ -1373,7 +1373,7 @@ static void vmx_load_pdptrs(struct vcpu *v) if ( (cr3 & 0x1fUL) && !hvm_pcid_enabled(v) ) goto crash; - page = get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT, &p2mt, P2M_UNSHARE); + page = get_page_from_gfn(v->domain, gaddr_to_gfn(cr3), &p2mt, P2M_UNSHARE); if ( !page ) { /* Ideally you don't want to crash but rather go into a wait diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index dfd08e2d0a..2953d05a17 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -649,11 +649,11 @@ static void nvmx_update_apic_access_address(struct vcpu *v) if ( ctrl & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES ) { p2m_type_t p2mt; - unsigned long apic_gpfn; + gfn_t apic_gfn; struct page_info *apic_pg; - apic_gpfn = get_vvmcs(v, APIC_ACCESS_ADDR) >> PAGE_SHIFT; - apic_pg = get_page_from_gfn(v->domain, apic_gpfn, &p2mt, P2M_ALLOC); + apic_gfn = gaddr_to_gfn(get_vvmcs(v, APIC_ACCESS_ADDR)); + apic_pg = get_page_from_gfn(v->domain, apic_gfn, &p2mt, P2M_ALLOC); ASSERT(apic_pg && !p2m_is_paging(p2mt)); __vmwrite(APIC_ACCESS_ADDR, page_to_maddr(apic_pg)); put_page(apic_pg); @@ -670,11 +670,11 @@ static void nvmx_update_virtual_apic_address(struct vcpu *v) if ( ctrl & CPU_BASED_TPR_SHADOW ) { p2m_type_t p2mt; - unsigned long vapic_gpfn; + gfn_t vapic_gfn; struct page_info *vapic_pg; - vapic_gpfn = get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR) >> PAGE_SHIFT; - vapic_pg = get_page_from_gfn(v->domain, vapic_gpfn, &p2mt, P2M_ALLOC); + vapic_gfn = gaddr_to_gfn(get_vvmcs(v, VIRTUAL_APIC_PAGE_ADDR)); + vapic_pg = get_page_from_gfn(v->domain, vapic_gfn, &p2mt, P2M_ALLOC); ASSERT(vapic_pg && !p2m_is_paging(p2mt)); __vmwrite(VIRTUAL_APIC_PAGE_ADDR, page_to_maddr(vapic_pg)); put_page(vapic_pg); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 9363e9bd96..e3462f8a77 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2052,7 +2052,7 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, p2m_query_t q = l1e_get_flags(nl1e) & _PAGE_RW ? P2M_ALLOC | P2M_UNSHARE : P2M_ALLOC; - page = get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), &p2mt, q); + page = get_page_from_gfn(pg_dom, _gfn(l1e_get_pfn(nl1e)), &p2mt, q); if ( p2m_is_paged(p2mt) ) { @@ -3223,7 +3223,8 @@ long do_mmuext_op( if ( paging_mode_refcounts(pg_owner) ) break; - page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL, + P2M_ALLOC); if ( unlikely(!page) ) { rc = -EINVAL; @@ -3288,7 +3289,8 @@ long do_mmuext_op( if ( paging_mode_refcounts(pg_owner) ) break; - page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), NULL, + P2M_ALLOC); if ( unlikely(!page) ) { gdprintk(XENLOG_WARNING, @@ -3504,7 +3506,8 @@ long do_mmuext_op( } case MMUEXT_CLEAR_PAGE: - page = get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt, P2M_ALLOC); + page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &p2mt, + P2M_ALLOC); if ( unlikely(p2mt != p2m_ram_rw) && page ) { put_page(page); @@ -3532,7 +3535,7 @@ long do_mmuext_op( { struct page_info *src_page, *dst_page; - src_page = get_page_from_gfn(pg_owner, op.arg2.src_mfn, &p2mt, + src_page = get_page_from_gfn(pg_owner, _gfn(op.arg2.src_mfn), &p2mt, P2M_ALLOC); if ( unlikely(p2mt != p2m_ram_rw) && src_page ) { @@ -3548,7 +3551,7 @@ long do_mmuext_op( break; } - dst_page = get_page_from_gfn(pg_owner, op.arg1.mfn, &p2mt, + dst_page = get_page_from_gfn(pg_owner, _gfn(op.arg1.mfn), &p2mt, P2M_ALLOC); if ( unlikely(p2mt != p2m_ram_rw) && dst_page ) { @@ -3636,7 +3639,8 @@ long do_mmu_update( { struct mmu_update req; void *va = NULL; - unsigned long gpfn, gmfn, mfn; + unsigned long gpfn, mfn; + gfn_t gfn; struct page_info *page; unsigned int cmd, i = 0, done = 0, pt_dom; struct vcpu *curr = current, *v = curr; @@ -3749,8 +3753,8 @@ long do_mmu_update( rc = -EINVAL; req.ptr -= cmd; - gmfn = req.ptr >> PAGE_SHIFT; - page = get_page_from_gfn(pt_owner, gmfn, &p2mt, P2M_ALLOC); + gfn = gaddr_to_gfn(req.ptr); + page = get_page_from_gfn(pt_owner, gfn, &p2mt, P2M_ALLOC); if ( unlikely(!page) || p2mt != p2m_ram_rw ) { @@ -3758,7 +3762,7 @@ long do_mmu_update( put_page(page); if ( p2m_is_paged(p2mt) ) { - p2m_mem_paging_populate(pt_owner, gmfn); + p2m_mem_paging_populate(pt_owner, gfn_x(gfn)); rc = -ENOENT; } else diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index a00a3c1bff..3b2aac8804 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2718,7 +2718,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, * Take a refcnt on the mfn. NB: following supported for foreign mapping: * ram_rw | ram_logdirty | ram_ro | paging_out. */ - page = get_page_from_gfn(fdom, fgfn, &p2mt, P2M_ALLOC); + page = get_page_from_gfn(fdom, _gfn(fgfn), &p2mt, P2M_ALLOC); if ( !page || !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) ) { diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c index 4cc75916b8..9275ba476c 100644 --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -313,15 +313,15 @@ const struct x86_emulate_ops hvm_shadow_emulator_ops = { static mfn_t emulate_gva_to_mfn(struct vcpu *v, unsigned long vaddr, struct sh_emulate_ctxt *sh_ctxt) { - unsigned long gfn; + gfn_t gfn; struct page_info *page; mfn_t mfn; p2m_type_t p2mt; uint32_t pfec = PFEC_page_present | PFEC_write_access; /* Translate the VA to a GFN. */ - gfn = paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec); - if ( gfn == gfn_x(INVALID_GFN) ) + gfn = _gfn(paging_get_hostmode(v)->gva_to_gfn(v, NULL, vaddr, &pfec)); + if ( gfn_eq(gfn, INVALID_GFN) ) { x86_emul_pagefault(pfec, vaddr, &sh_ctxt->ctxt); diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 3a3c15890b..4f3f438614 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -229,7 +229,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) break; ret = -EINVAL; - page = get_page_from_gfn(current->domain, info.gmfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(current->domain, _gfn(info.gmfn), + NULL, P2M_ALLOC); if ( !page ) break; if ( !get_page_type(page, PGT_writable_page) ) diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descriptor-tables.c index 8b2d55fc2e..7e8f41d3fd 100644 --- a/xen/arch/x86/pv/descriptor-tables.c +++ b/xen/arch/x86/pv/descriptor-tables.c @@ -112,7 +112,7 @@ long pv_set_gdt(struct vcpu *v, unsigned long *frames, unsigned int entries) { struct page_info *page; - page = get_page_from_gfn(d, frames[i], NULL, P2M_ALLOC); + page = get_page_from_gfn(d, _gfn(frames[i]), NULL, P2M_ALLOC); if ( !page ) goto fail; if ( !get_page_type(page, PGT_seg_desc_page) ) @@ -209,7 +209,6 @@ int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint) frame_list, long do_update_descriptor(uint64_t pa, uint64_t desc) { struct domain *currd = current->domain; - unsigned long gmfn = pa >> PAGE_SHIFT; unsigned long mfn; unsigned int offset; struct desc_struct *gdt_pent, d; @@ -220,7 +219,7 @@ long do_update_descriptor(uint64_t pa, uint64_t desc) *(uint64_t *)&d = desc; - page = get_page_from_gfn(currd, gmfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(currd, gaddr_to_gfn(pa), NULL, P2M_ALLOC); if ( (((unsigned int)pa % sizeof(struct desc_struct)) != 0) || !page || !check_descriptor(currd, &d) ) diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index f73ea4a163..a529ebcc3f 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -760,12 +760,12 @@ static int write_cr(unsigned int reg, unsigned long val, case 3: /* Write CR3 */ { struct domain *currd = curr->domain; - unsigned long gfn; + gfn_t gfn; struct page_info *page; int rc; - gfn = !is_pv_32bit_domain(currd) - ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val); + gfn = _gfn(!is_pv_32bit_domain(currd) + ? xen_cr3_to_pfn(val) : compat_cr3_to_pfn(val)); page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC); if ( !page ) break; diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c index f5ea00ca4e..c9ad1152b4 100644 --- a/xen/arch/x86/pv/mm.c +++ b/xen/arch/x86/pv/mm.c @@ -106,7 +106,7 @@ bool pv_map_ldt_shadow_page(unsigned int offset) if ( unlikely(!(l1e_get_flags(gl1e) & _PAGE_PRESENT)) ) return false; - page = get_page_from_gfn(currd, l1e_get_pfn(gl1e), NULL, P2M_ALLOC); + page = get_page_from_gfn(currd, _gfn(l1e_get_pfn(gl1e)), NULL, P2M_ALLOC); if ( unlikely(!page) ) return false; diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 9471d89022..d967e49432 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -795,7 +795,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val) case 0: /* Write hypercall page */ { void *hypercall_page; - unsigned long gmfn = val >> PAGE_SHIFT; + gfn_t gfn = gaddr_to_gfn(val); unsigned int page_index = val & (PAGE_SIZE - 1); struct page_info *page; p2m_type_t t; @@ -808,7 +808,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val) return X86EMUL_EXCEPTION; } - page = get_page_from_gfn(d, gmfn, &t, P2M_ALLOC); + page = get_page_from_gfn(d, gfn, &t, P2M_ALLOC); if ( !page || !get_page_type(page, PGT_writable_page) ) { @@ -817,13 +817,14 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val) if ( p2m_is_paging(t) ) { - p2m_mem_paging_populate(d, gmfn); + p2m_mem_paging_populate(d, gfn_x(gfn)); return X86EMUL_RETRY; } gdprintk(XENLOG_WARNING, - "Bad GMFN %lx (MFN %#"PRI_mfn") to MSR %08x\n", - gmfn, mfn_x(page ? page_to_mfn(page) : INVALID_MFN), base); + "Bad GMFN %#"PRI_gfn" (MFN %#"PRI_mfn") to MSR %08x\n", + gfn_x(gfn), mfn_x(page ? page_to_mfn(page) : INVALID_MFN), + base); return X86EMUL_EXCEPTION; } diff --git a/xen/common/domain.c b/xen/common/domain.c index d6650f0656..5e3c05b96c 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1250,7 +1250,7 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset) if ( (v != current) && !(v->pause_flags & VPF_down) ) return -EINVAL; - page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(d, _gfn(gfn), NULL, P2M_ALLOC); if ( !page ) return -EINVAL; diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c index c49f446754..71a6f673b2 100644 --- a/xen/common/event_fifo.c +++ b/xen/common/event_fifo.c @@ -358,7 +358,7 @@ static const struct evtchn_port_ops evtchn_port_ops_fifo = .print_state = evtchn_fifo_print_state, }; -static int map_guest_page(struct domain *d, uint64_t gfn, void **virt) +static int map_guest_page(struct domain *d, gfn_t gfn, void **virt) { struct page_info *p; @@ -419,7 +419,7 @@ static int setup_control_block(struct vcpu *v) return 0; } -static int map_control_block(struct vcpu *v, uint64_t gfn, uint32_t offset) +static int map_control_block(struct vcpu *v, gfn_t gfn, uint32_t offset) { void *virt; unsigned int i; @@ -505,7 +505,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control) { struct domain *d = current->domain; uint32_t vcpu_id; - uint64_t gfn; + gfn_t gfn; uint32_t offset; struct vcpu *v; int rc; @@ -513,7 +513,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control) init_control->link_bits = EVTCHN_FIFO_LINK_BITS; vcpu_id = init_control->vcpu; - gfn = init_control->control_gfn; + gfn = _gfn(init_control->control_gfn); offset = init_control->offset; if ( vcpu_id >= d->max_vcpus || !d->vcpu[vcpu_id] ) @@ -569,7 +569,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control) return rc; } -static int add_page_to_event_array(struct domain *d, unsigned long gfn) +static int add_page_to_event_array(struct domain *d, gfn_t gfn) { void *virt; unsigned int slot; @@ -619,7 +619,7 @@ int evtchn_fifo_expand_array(const struct evtchn_expand_array *expand_array) return -EOPNOTSUPP; spin_lock(&d->event_lock); - rc = add_page_to_event_array(d, expand_array->array_gfn); + rc = add_page_to_event_array(d, _gfn(expand_array->array_gfn)); spin_unlock(&d->event_lock); return rc; diff --git a/xen/common/memory.c b/xen/common/memory.c index 987395fbb3..e02733dba0 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1365,7 +1365,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) return rc; } - page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(d, _gfn(xrfp.gpfn), NULL, P2M_ALLOC); if ( page ) { rc = guest_physmap_remove_page(d, _gfn(xrfp.gpfn), @@ -1636,7 +1636,7 @@ int check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly, p2m_type_t p2mt; struct page_info *page; - page = get_page_from_gfn(d, gfn_x(gfn), &p2mt, q); + page = get_page_from_gfn(d, gfn, &p2mt, q); #ifdef CONFIG_HAS_MEM_PAGING if ( p2m_is_paging(p2mt) ) diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c index bf7b14f79a..72cba7f10c 100644 --- a/xen/common/tmem_xen.c +++ b/xen/common/tmem_xen.c @@ -52,7 +52,7 @@ static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t *pcli_mfn, p2m_type_t t; struct page_info *page; - page = get_page_from_gfn(current->domain, cmfn, &t, P2M_ALLOC); + page = get_page_from_gfn(current->domain, _gfn(cmfn), &t, P2M_ALLOC); if ( !page || t != p2m_ram_rw ) { if ( page ) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 7c67806056..5e598a0b37 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -278,7 +278,7 @@ 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 domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q) { mfn_t mfn; p2m_type_t _t; @@ -289,7 +289,7 @@ static inline struct page_info *get_page_from_gfn( * not auto-translated. */ if ( unlikely(d != dom_xen) ) - return p2m_get_page_from_gfn(d, _gfn(gfn), t); + return p2m_get_page_from_gfn(d, gfn, t); if ( !t ) t = &_t; @@ -300,7 +300,7 @@ static inline struct page_info *get_page_from_gfn( * DOMID_XEN see 1-1 RAM. The p2m_type is based on the type of the * page. */ - mfn = _mfn(gfn); + mfn = _mfn(gfn_x(gfn)); page = mfn_to_page(mfn); if ( !mfn_valid(mfn) || !get_page(page, d) ) diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index d08c595887..db1ec37610 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -489,18 +489,21 @@ struct page_info *p2m_get_page_from_gfn(struct p2m_domain *p2m, gfn_t gfn, p2m_query_t q); static inline struct page_info *get_page_from_gfn( - struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) + struct domain *d, gfn_t gfn, p2m_type_t *t, p2m_query_t q) { struct page_info *page; + mfn_t mfn; if ( paging_mode_translate(d) ) - return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t, NULL, q); + return p2m_get_page_from_gfn(p2m_get_hostp2m(d), gfn, t, NULL, q); /* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ if ( t ) *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct; - page = mfn_to_page(_mfn(gfn)); - return mfn_valid(_mfn(gfn)) && get_page(page, d) ? page : NULL; + + mfn = _mfn(gfn_x(gfn)); + page = mfn_to_page(mfn); + return mfn_valid(mfn) && get_page(page, d) ? page : NULL; } /* General conversion function from mfn to gfn */