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); From patchwork Fri Dec 21 16:26:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154410 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117810ljp; Fri, 21 Dec 2018 08:29:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN4kJkFHL0BAXeIUeUt4ryOV2JR4OWQnCBvcbjIwwUew5PNLauuuT05F4twiZvRotDCcl2Qp X-Received: by 2002:a25:8446:: with SMTP id r6mr3142091ybm.474.1545409743313; 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=SjHyRLANOIsOoSkKjjCkYX6YBl3J2NPJd2niszYhVTCsn5i9M5YW+JFSMB4/kL4TBn eOE3X6FsO/jQ0k6CF+uU31Evh81sBL+fenLN46eux+vFqHyPbPS3hX/oOvBuElN+31zG 7Rw4h9ZNedMM0puGYspa4s9QhWyLzc5foCaYiMAqpcFWzos7dLIUT9H4f0RR7VW7vJRT iOpyFov0wlrCVzDMRj/4EPn4QHPztvAApCerPwT3gifZ6LIpehBaUQQ1PMqJ5YvWS34b GYYMWEIRw2UobRG+fKPtHrEXrk9ytcYTmRRc22o4SuuFdGzAcR5lrv18BTW9C+VsdwBg oMAQ== 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=BhWeaRccV4Z2s570Bwwf97a4pt1D1JKLCMEDve4dTWI=; b=eWdbfPzP0rXG+egAK7b3jHZCWyuwdMKN2nr6L0Gg92N9qguz1RlWBIpUx1kSnYAur8 B4bmGjy6nqb3QZStAx6EOh7HOYd3QctaO/8fhS76u28xZxng0BFp/ikeWt3gMqNRqGy0 1FNqLb7OlFtk0XZuO/RUhmrsAoel0s1YqlH+1BDF5G/d+v/fYWWa2917aYCn/UoMvY7N 2nSXi6VO8RC2W5ymXYN7B1Lnx7Z8ECp9vJkCIP45JJo+8tMKcQ93jcasYgrVpDS3Nxal 8BK4CVgLS9H3ddKAcVLzvS4WfHrar+JOp88Oi4gztmlKjXQUGWwAY78Lhwpxec+0uSNq tR9Q== 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 l200si14619535ywb.58.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 1gaNdh-00067p-AC; Fri, 21 Dec 2018 16:27:05 +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 1gaNdg-00067Y-2s for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:04 +0000 X-Inumbo-ID: 3f780c00-053d-11e9-9ffd-cbe38b3e3cb3 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3f780c00-053d-11e9-9ffd-cbe38b3e3cb3; Fri, 21 Dec 2018 16:27:02 +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 5A258EBD; Fri, 21 Dec 2018 08:27:02 -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 6B3CD3F5C0; Fri, 21 Dec 2018 08:27:01 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:44 +0000 Message-Id: <20181221162650.11515-3-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 2/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 , sstabellini@kernel.org, Andrii Anisov 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 Reviewed-by: Andrii Anisov Acked-by: Stefano Stabellini --- Changes in v3 - Add Stefano's acked-by Changes in v2: - Add Andrii's reviewed-by --- 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 d96a6655ee..7193d83b44 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1267,7 +1267,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 7ae5b29699..89279fb590 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -468,7 +468,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 4db8e8709d..a1aef7b793 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -115,7 +115,7 @@ typedef enum { 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 */ @@ -137,10 +137,10 @@ typedef enum { /* 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))) /* All common type definitions should live ahead of this inclusion. */ #ifdef _XEN_P2M_COMMON_H From patchwork Fri Dec 21 16:26:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154409 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117811ljp; Fri, 21 Dec 2018 08:29:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/UpKT6LYmUgqRMXYeNXpeKTIybKjtVN22Yo8U0OdaEKxc6wkfyOM8wM+y0Dx/agBGJnFwBW X-Received: by 2002:a81:9ad8:: with SMTP id r207mr3166591ywg.72.1545409743348; 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=XuWwZLgqZBvN36fr3s+AqJAftn7rR6GR1LPoi/8feqqQeb8e3AEM8P2D+menWN8Co0 jxyCS8mTClWAwhK3z3MthpvljhEXgb75Mmxej2YeQv9t1DlMOz0uLq6YbZXrPgzR2rGa sV23m/Z+HHXKr2tXyhdifJCR9CjUo3LvDDz/hY140evnyce1i0UTUQacrpE5kmiP7NXD yM2QNtA+GqwCRhqv8ll/AKnAB9RBqfPjn1ik1JYIQz7Inpe/zIp9RP86RNBGtFE0YVtT FPXTjCuq1hG7dyynMBQQqriGf0Os8j1fKSI6Y3KlR8z5ARyk1OB1VCY/5ZW0W6ePwA4N fo2A== 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=eKTQazmZgBYbnOMXWN4g4k3Pu5fsm19lFtLQvVdmaCI=; b=ThpXsAj5en5aknHjjlc6RbdAxXbSQfuXAI5X7YNyLjoN9nprIniPeHITgW+W75eYNk 3NqEKQP3G3MV47KQEgH/b83Ou5KFQZSeYQdhh3M5jOAcIQzLZGohutf37osnfVGkGHTo Bo8tH3b3rJW0IFN82+h8/I3Gav31iGSBZXaML9NPCq/xMTLavgDhos0wv3J2jJZogryp PqoAGg/xwTAfugtVFENAxD57HG9Y4SMQ4osDHcd8o+C27wGENp6Z/x3eZRf0awN7s+E5 XleVBGBfsWQxJfeNAZElo8GF5F2u2sjah72iTfkUidln5k9nenR8Fgt1jFyXQ44P+rTg bDPg== 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 a123si15117869ywg.39.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 1gaNdi-00068L-Jo; Fri, 21 Dec 2018 16:27:06 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gaNdh-00067n-Bk for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:05 +0000 X-Inumbo-ID: 3fffc36e-053d-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3fffc36e-053d-11e9-8e1d-bc764e045a96; Fri, 21 Dec 2018 16:27:03 +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 83DF415AD; Fri, 21 Dec 2018 08:27:03 -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 9522C3F5C0; Fri, 21 Dec 2018 08:27:02 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:45 +0000 Message-Id: <20181221162650.11515-4-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 3/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 , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, 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 --- Cc: Andrii Anisov Changes in v3: - Remove Andrii's reviewed-by - Move out the XEN_DOMID code in a separate patch - Make the new addition future-proof Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 5 +++-- xen/arch/arm/p2m.c | 1 + xen/include/asm-arm/p2m.h | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7193d83b44..3bf11eec4f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1259,7 +1259,9 @@ int xenmem_add_to_physmap_one( return -EINVAL; } - if ( !p2m_is_ram(p2mt) ) + if ( p2m_is_ram(p2mt) ) + t = (p2mt == p2m_ram_rw) ? p2m_map_foreign_rw : p2m_map_foreign_ro; + else { put_page(page); rcu_unlock_domain(od); @@ -1267,7 +1269,6 @@ int xenmem_add_to_physmap_one( } mfn = page_to_mfn(page); - 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 89279fb590..1e7c91e39a 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -478,6 +478,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 a1aef7b793..a03a033a05 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -116,6 +116,7 @@ typedef enum { 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 */ @@ -135,12 +136,16 @@ typedef enum { #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)) /* All common type definitions should live ahead of this inclusion. */ #ifdef _XEN_P2M_COMMON_H From patchwork Fri Dec 21 16:26:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154405 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117741ljp; Fri, 21 Dec 2018 08:28:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/WJtmH7U22qBOCQHg/yH8zJsaIQQMP1+Nm899gbfEoAPTiYMM5FAGP7gFlFLvMfes3Xbprj X-Received: by 2002:a81:6e43:: with SMTP id j64mr3192072ywc.171.1545409739214; Fri, 21 Dec 2018 08:28:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545409739; cv=none; d=google.com; s=arc-20160816; b=v+km4ILbRu5n2zNoHqSoqnzHl0Gm6e7sNHWe5zq2DI+f7xUoka0iEooPiBmdr68P7I yhj3cpDgmYpTSBDWUGLpvaR0cMKbdM9BTYlAxv507kEJw+7+P8SZgyk+zHuT5LHSnK2n nsK6lzaGkx7QdHNg9T4EqagE4fVClbwglLJD2sxAOn4TiAu9UzVGeZEYmMydwRAINMNg E5nYbxIQjgx3h07yNFI/CAPMSrZok27Lgvq0PufL9p4tsK3vvUZsu8riz9K7+3UUJxfW Bf0Oe4Kt5ciiBIcRiaQ7YRWHR6gO2zF0/J3AOhgk2ollCzdYrsqZsFiENTN+C4eVLwOw AwrQ== 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=yan0dKRAF8JVh7bjSZQPU5BTd04hlkvCc3n1yzE7rAk=; b=c0iWqw3SaH53955T1g2xQ4SnBtuJBb58MTJuYJQA7C8ABkT59d9WJtJcVyxvD85oNh pSg6UnFBPBa52B7Mbx7dF/xpBue4udu2C0YLOJrGpTr5pvy2jYdybH/Yyr0byA6Myj+2 SKfIYoxByJJg1I9YuPudsJmCXh4IxpabWD5QQW0FBzHVQ00wavmzqARoK/cjUfq+k5/Y XHTUtXI0php5M9T6zlFPpYKRtMn/uN3aW7gKyjEWjl+c7KUm/lhp8adegm5BvhPxIvko sMnER4HsKopz0NwBK8xoJDVEZb/k+G41lpj9mpsxQpjiuW7NEtItI/jOOfz04oDW/9ws CWFg== 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 a17si14903208ybq.294.2018.12.21.08.28.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 08:28:59 -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 1gaNdi-00068W-Rj; Fri, 21 Dec 2018 16:27:06 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gaNdh-00067o-CM for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:05 +0000 X-Inumbo-ID: 40a32dd0-053d-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 40a32dd0-053d-11e9-8e1d-bc764e045a96; Fri, 21 Dec 2018 16:27:04 +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 8A00D1596; Fri, 21 Dec 2018 08:27:04 -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 BE9DB3F5C0; Fri, 21 Dec 2018 08:27:03 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:46 +0000 Message-Id: <20181221162650.11515-5-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 4/8] xen/arm: Make get_page_from_gfn working with 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 , sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" DOMID_XEN is used to share pages beloging to the hypervisor (e.g trace buffers). Unlike other domains, DOMID_XEN is a non-auto translated domain and therefore does not have a P2M. This patch adds a special case for DOMID_XEN in get_page_from_gfn. We may want to provide "non-auto translated helpers" in the future if we see more case. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- Changes in v3: - Split from "xen/arm: Add support for read-only foreign mappings" - Use likely rather than unlikely - Fix typoes --- xen/include/asm-arm/p2m.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index a03a033a05..041dea827c 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -300,7 +300,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 ( likely(d != dom_xen) ) + return p2m_get_page_from_gfn(d, _gfn(gfn), t); + + if ( !t ) + t = &_t; + + *t = p2m_invalid; + + /* + * DOMID_XEN sees 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 Fri Dec 21 16:26: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: 154411 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117851ljp; Fri, 21 Dec 2018 08:29:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wc7yagJ26H/pjmtvLUqRS1eUekHivuufQ2AVyT6LRvQ0A6yjoqIq9tWAuChE6Ci3BkWbOz X-Received: by 2002:a25:dcf:: with SMTP id 198mr3121732ybn.518.1545409745189; Fri, 21 Dec 2018 08:29:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545409745; cv=none; d=google.com; s=arc-20160816; b=vY7SZlpP56aN0aW8pUVkrSqS7yaX+20FP4M9mnb08DMy0y2HnZJl9A56BnAD2eQPQs x8Lq5sVHgcJ4b7wLKwVJ5EdLYjodet0LLeudIHfohZsgpyneIR/Kuh7taDb5NsyMPwaE f2c7djG5hU5xma4zbw5k56+k5I6O7zGZGUZatbP9o4epApEBUZtVk8XknoKeWJVN+Fi2 y3w9F7GqGKLFTjIHL6OZmcCKRuBG6thfdVu+MNTK2XSj0w1qipvClo3iG4c/VFDNbx0Y iQRXAdIt7dQTp+qz86wFuwJnPFIOuWrhi2JZnsy+qdxT0AklpFIWgaK2W54mey/xZKZ3 9o0w== 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=+vobpsGgNlJjXShc4jKD2JEJiqQxv/2g6acEBJYP75k=; b=PTy3y9qvjckEdSX6PdsbQfB4CnNyWsF/kV6C/z3P66mqpVjFMoy6h/N4ZOhwuO2uzs 1ZMu7Y8ZiYGK6TfM53x6UsaFdWGEkS9+Xu7cYnUynjgdARbP/6X7qs/tLXKPumUBzPsp XxFEVLx62KZJ8fwLwpMt9sL2kVIDV/GDUnntvLQm5J9pJpVBYbDxUI6oYEU3VlSmcGcf ZuMkqc+Jp1s2yaxUbax56LA5VYLK9T52YT/cAx1dVDRbT9GFkQmGdgb5kXxRwGfWRsDg hdL1xNULyxG4ceerUwS8YC5VtBtjqAdsz3EDeE0YM03fL6NWSHm/lKBTzmUTByY97/Cy oSGQ== 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 d20si12798755ybc.113.2018.12.21.08.29.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 08:29:05 -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 1gaNdj-00069C-4K; Fri, 21 Dec 2018 16:27:07 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gaNdi-00068O-PJ for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:06 +0000 X-Inumbo-ID: 415d5816-053d-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 415d5816-053d-11e9-8e1d-bc764e045a96; Fri, 21 Dec 2018 16:27: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 B3957EBD; Fri, 21 Dec 2018 08:27: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 C4D5F3F5C0; Fri, 21 Dec 2018 08:27:04 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:47 +0000 Message-Id: <20181221162650.11515-6-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 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 , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" For auto-translated domain, the only way to map a page to itself is the using the foreign map API. The current code does not allow mapping page from special page (such as DOMID_XEN). As xentrace buffers 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 Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by - Fix typoes Changes in v2: - Add Andrii's reviewed-by --- 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 3bf11eec4f..01ae2cccc0 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1233,20 +1233,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; } @@ -1255,7 +1255,7 @@ 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; } @@ -1264,13 +1264,13 @@ int xenmem_add_to_physmap_one( else { put_page(page); - rcu_unlock_domain(od); + put_pg_owner(od); return -EINVAL; } mfn = page_to_mfn(page); - rcu_unlock_domain(od); + put_pg_owner(od); break; } case XENMAPSPACE_dev_mmio: From patchwork Fri Dec 21 16:26: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: 154406 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117745ljp; Fri, 21 Dec 2018 08:28:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ujl17QbJeSXVgXGS+bu3CyuE7N2rtBmGHYOMXdK4BX4hfWiofQbsiIiqTeOq/Y3du+so6R X-Received: by 2002:a81:6c51:: with SMTP id h78mr3180871ywc.116.1545409739590; Fri, 21 Dec 2018 08:28:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545409739; cv=none; d=google.com; s=arc-20160816; b=vA/wOIyX7wZDUkN1GtoS0tpJEJnICF0rRFFjmkYjfRGS1h7sIr9w2KMliPc+rfMqti MP7OsulO7lC5DTShN16vZSIOQhUYVKZIiLyKtANpQl+kKQykh+dHk17ps5MPQkdL67cg mHhPkzuIrWn+rEsm9AEc+w8XytnxHn2jAh69Ut+9StESUS0IXeKoBsTDOBWQktHnpXJz 696iNE8XzSm+KUWrX97uODQF/ou4k29fw4oqsOPxI8XpZj09LI2JBj0jfBYuPEY8SWqn impJlPZ2IeGdGZlA0x8EMde/L2R4fWCKghtGNo5vfF7DQqkesqaAtqUuCSzcm+Q3BQtA Ad5A== 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=CKGuHRA5eaOwOgZ/DwEbGqTsbsulJPrnHBHPn8plLso=; b=nUj5SguQPdulW4Hoj3q6hA1Ug4j+KqZ2CS/Irf2IkPFNEIU4rmO0w50kZnzOG41apk 81HhPvd3p0enq4QvB/qQUEicfcZbKqlZihG0crscpJ69h5dtn0puqofidN9aCbeWuRWN WAYNRhkm16ivfV4SFshDM/qqaLQ6mKB/5YW7FdzgAo7UNj9m6WLSvIcUQGJzWdEQHBN1 Lb3EZgaDPaRStt3X9+VjI78BN+ktucWXb8JPUytF2OAHf3M3Sao1Dn0migTutd8LDoEg H00g9vp1hS9E8Hs8XlkMrWfrSnBqNUNsRQNtN6gaA2RpNYYxhqnkpFp/v2ur0n/ZixO6 J1YQ== 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 p68si14597423ywg.370.2018.12.21.08.28.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 08:28:59 -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 1gaNdl-0006Au-FT; Fri, 21 Dec 2018 16:27: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 1gaNdk-00069x-1D for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:08 +0000 X-Inumbo-ID: 421ce33d-053d-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 421ce33d-053d-11e9-8e1d-bc764e045a96; Fri, 21 Dec 2018 16:27:07 +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 0D91B1596; Fri, 21 Dec 2018 08:27: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 EEE053F5C0; Fri, 21 Dec 2018 08:27:05 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:48 +0000 Message-Id: <20181221162650.11515-7-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 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 , sstabellini@kernel.org, Andrii Anisov , 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 Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Add Andrii's reviewed-by --- 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 fb923cdf67..444857a967 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -899,6 +900,8 @@ void __init start_xen(unsigned long boot_phys_offset, heap_init_late(); + init_trace_bufs(); + init_constructors(); console_endboot(); From patchwork Fri Dec 21 16:26: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: 154407 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117762ljp; Fri, 21 Dec 2018 08:29:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/XzITGVLKaSZUzQbQppD62f8+csVzF4IiIZuqTK2SzNatiUPBIzmH7ZmrUpMSb3E6YQPHAp X-Received: by 2002:a81:c90d:: with SMTP id o13mr3338806ywi.348.1545409741015; Fri, 21 Dec 2018 08:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545409741; cv=none; d=google.com; s=arc-20160816; b=rQFSRXxqyo85kYiFyus/hnE7vcrMDFWHjyHvvDwKJyMwa2ZDL4QlBzTsYN72hLmrMX j1UUpPVZRyz+cy7K4HcShgeRE7Uexm4j5cCBG3ucIn5N3oFTYbb8AKKb2Fb700chl1OY DOce3I1sxPhqn9eCNCb0QVoJPqFwjWzpaiB/DiIfeZxwC8Dr3Ev7FQUvabcEkkm6hL0F 4MfhuQfpfGz2X+8a2dgFLmQXF4YHaN2fP+z1qwv8niNAqfx4IUsPhrM137Ag6HLbFBH5 9eKuN5b5EE0qsHBjKXKxaCOuJFZ9/2XjHQsWph9JfTbGfyyhTvNVe4qUvXTGlrmIMtAc FCCg== 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=e/PaYR0Nqe8jfYsdCZzruH9YME/P0nB/xQOwJJ+dCrk=; b=NZx6HYdb5Rles3iHM8/cVDfSIxiV3HPKS9h8SF+NKC0tnajjjZW//FwY+tPozG3Lfz lSFXf+K3D82iweg8NIK1S5EEltgMHr7FUbeMjSrU6vWhenJ0uSPm+dJosPY6nbCQk1pO 3CnZm4Rgr8z+hswXJ7VEL535Gq86MX9JJQojHCqFqRKlbHeMSZzqdXjeWsV8ecgg7at/ klZ4LMqK6RSkKpYtBl73ynNN+QnWIVsuD17xFHuhEObgraKp0kTxNLa/s8+6sLJyWMbV NQJf9w3JMJuVCa8Zad0kwED3daP4CXq0CYCzuC31PufqcDevumWTKVR4W4DaPeY6Jo98 kIIw== 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 o186si15314524ywb.31.2018.12.21.08.29.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 08:29: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 1gaNdm-0006C6-UK; Fri, 21 Dec 2018 16:27:10 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gaNdl-0006Af-8l for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:09 +0000 X-Inumbo-ID: 43074e26-053d-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 43074e26-053d-11e9-8e1d-bc764e045a96; Fri, 21 Dec 2018 16:27: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 7EE1CEBD; Fri, 21 Dec 2018 08:27: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 494543F5C0; Fri, 21 Dec 2018 08:27:07 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:49 +0000 Message-Id: <20181221162650.11515-8-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 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: Stefano Stabellini , Julien Grall , sstabellini@kernel.org, Wei Liu , 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 Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - Add Wei's acked-by --- 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 Fri Dec 21 16:26: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: 154412 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117928ljp; Fri, 21 Dec 2018 08:29:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/U+A24Gh2H3TKNqBdgFFAGKcxTUqWJR35fk4jVtSFsOTkYKhZNlVlCqdMTW6KDQLCv78Czg X-Received: by 2002:a81:b306:: with SMTP id r6mr3305745ywh.512.1545409750363; Fri, 21 Dec 2018 08:29:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545409750; cv=none; d=google.com; s=arc-20160816; b=cHLq8k+QfyJ8rR0q0o+9QtP2MvJdeCUI+PKBoaLqTWgbU4IwVHTW20aJXuQkdDiGO6 Qv1Bs7F64s8ZTZH2BU+wh0Iu6tMEFeb6mWc/QOiobZRWdEXZQ4l/ENp72kIDulwh4A5B yELLSeN482vO+mpbXeKuQTGJ20T1ZFkWkDvhwIV81raqlc9Dj0QQDcZiykzokX9q8XV3 DlG6nZ2e2LfGgV5PylQj1m0lzul439qLdl1vNmM/tmo7MYkxAcXxHono43UYRGfB4OcK Yrdg2362oFipm+LXhljdWMQ0mQwPZ9etLEgrotj0U7EvJO3VnaHVVGPUtYuWMbOiufZr 4hTQ== 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=/nVBlgLXYPTz1WVmV+3DdCgVoTPZoop4Mlq0eFe7eBo=; b=sf+SyM6n5mYjPsVyatQOs0szzSb/ghS77sogeWtjVR4YJZkME7NWeSBZ9P8QQ8DYye /P2/3wd5w9WtNs/iiiLV0lCBU4d1vw2DUXXmtzxIip7dpm6cj9BvptuNNVmxD5YmRhjz abIWvs6YGnxzuJ5V2M8dkQa2iz/SWJdg/w04J6MrP72Zw3uyv+2TsWHP5oAx4Jo6vjTR a7FK1NlqHvzuy0NO7WKAkJFYw6imeQ3fCvBG51nPIefBpezF0UAwFftCi/4b1SeMGZEO 2iXE+BTgN3yYyX5SL9/Izj033cGtRA2+nGLKK3IO41RP3k2K36IEcz51nqrmz5EvveGK h08Q== 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 g124si12179803ywa.179.2018.12.21.08.29.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 08:29:10 -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 1gaNdo-0006Dh-9j; Fri, 21 Dec 2018 16:27:12 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gaNdn-0006CG-55 for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:11 +0000 X-Inumbo-ID: 43cb020d-053d-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 43cb020d-053d-11e9-8e1d-bc764e045a96; Fri, 21 Dec 2018 16:27: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 CD4011596; Fri, 21 Dec 2018 08:27: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 B9C9E3F5C0; Fri, 21 Dec 2018 08:27:08 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:50 +0000 Message-Id: <20181221162650.11515-9-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 8/8] xen: Switch 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: Julien Grall , sstabellini@kernel.org, Jan Beulich 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 Acked-by: Jan Beulich Reviewed-by: Kevin Tian --- Changes in v3: - Add Jan's acked-by Changes in v2: - Remove >> PAGE_SHIFT in svm code - Fix typo in the e-mail address - Small NITs --- 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/time.c | 8 ++++---- xen/arch/x86/hvm/viridian/viridian.c | 16 ++++++++-------- 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 | 4 ++-- 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 +++++++---- 27 files changed, 95 insertions(+), 85 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 01ae2cccc0..340a1d1548 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1252,7 +1252,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 32dc4253ff..b462a8513b 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -827,7 +827,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; @@ -1091,9 +1091,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 ) @@ -1122,7 +1122,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 ) @@ -1137,7 +1137,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 ) @@ -1162,7 +1162,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 9bf2d0820f..812a435069 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 d14ddcb527..0109bf6a75 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2168,7 +2168,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); @@ -2223,7 +2223,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 ) { @@ -2315,7 +2316,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; @@ -3143,7 +3144,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 954822c960..29777cd1b8 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 ) { @@ -2351,9 +2351,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), + &p2mt, P2M_ALLOC | P2M_UNSHARE); if ( !page ) return NULL; diff --git a/xen/arch/x86/hvm/viridian/time.c b/xen/arch/x86/hvm/viridian/time.c index 840a82b457..a718434456 100644 --- a/xen/arch/x86/hvm/viridian/time.c +++ b/xen/arch/x86/hvm/viridian/time.c @@ -38,16 +38,16 @@ static void dump_reference_tsc(const struct domain *d) static void update_reference_tsc(struct domain *d, bool 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/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index c78b2918d9..2c4e8bdcc6 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -247,16 +247,16 @@ static void dump_hypercall(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; } @@ -601,13 +601,13 @@ void viridian_dump_guest_page(const struct vcpu *v, const char *name, void viridian_map_guest_page(struct vcpu *v, struct viridian_page *vp) { struct domain *d = v->domain; - unsigned long gmfn = vp->msr.fields.pfn; + gfn_t gfn = _gfn(vp->msr.fields.pfn); struct page_info *page; if ( vp->ptr ) return; - page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); + page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); if ( !page ) goto fail; @@ -628,8 +628,8 @@ void viridian_map_guest_page(struct vcpu *v, struct viridian_page *vp) 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)); } void viridian_unmap_guest_page(struct viridian_page *vp) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 64af8bf943..088b708d3c 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 9f6ea5c1f7..bae8aa2360 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -642,11 +642,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); @@ -663,11 +663,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 08f34722c2..6d4c3a9e35 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2049,7 +2049,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) ) { @@ -3212,7 +3212,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; @@ -3277,7 +3278,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, @@ -3493,7 +3495,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); @@ -3521,7 +3524,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 ) { @@ -3537,7 +3540,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 ) { @@ -3625,7 +3628,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; @@ -3738,8 +3742,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 ) { @@ -3747,7 +3751,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 fea4497910..9d4c4cb27b 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2696,7 +2696,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 8994cb9f87..196c00d63d 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 940804b18a..7b3fb2806a 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) ) @@ -219,7 +219,7 @@ long do_update_descriptor(uint64_t gaddr, seg_desc_t d) if ( !IS_ALIGNED(gaddr, sizeof(d)) || !check_descriptor(currd, &d) ) return -EINVAL; - page = get_page_from_gfn(currd, gfn_x(gfn), NULL, P2M_ALLOC); + page = get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC); if ( !page ) return -EINVAL; diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index 942ece2ca0..13b13bdc40 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -756,12 +756,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 05ddc39bfe..ac2516a709 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 GFN %#"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 c623daec56..9d9731db17 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 5f7d081c61..5be8b8b68d 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1386,7 +1386,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), @@ -1657,7 +1657,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 041dea827c..c0aa7fa167 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -298,7 +298,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; @@ -309,7 +309,7 @@ static inline struct page_info *get_page_from_gfn( * not auto-translated. */ if ( likely(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; @@ -320,7 +320,7 @@ static inline struct page_info *get_page_from_gfn( * DOMID_XEN sees 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 3304921991..1efbc071c5 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -491,18 +491,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 */