From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577913; cv=none; d=zoho.com; s=zohoarc; b=kbOdOIf1gynq9LQL8WjEglfGI68TWOgjVJc6F1B2Gp2iaRpNH+J2gOCdRH3904Kkt1GfZ8HqCJGBXitzJnj/YWSV91Dqod5XjkEyg5rQhWc0koOGPtgj4XINU9uIUoaEWwptFqIccjTzpJchLaX6mKzGUWFzX8XgzlNHT7ou8pQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577913; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=I7IwnujisgWYWSOzFmKuY09E9KpX+s5A70so7G62MNY=; b=VFkuEnU7RhuPeqH5IejWKb39Wl/7hGi5LOSzOQGDK/Jn9XCxyzeDBVIT/YAuJghuD8wwOGirmBSYtnHi9sRfpbTnUPDdaCLLDJHQN4yw+f3DHTJhgKSOJcD2L9EEyXe+wQE+M2OXGlK89ULqidnGAiSZPhfAlvEDUFQllSXrFf4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 155957791323962.14668613710535; Mon, 3 Jun 2019 09:05:13 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRL-0001tO-Kd; Mon, 03 Jun 2019 16:04:03 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRK-0001tE-Cx for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:02 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 336ebb00-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04:00 +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 6274715AB; Mon, 3 Jun 2019 09:04:00 -0700 (PDT) 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 DC5D33F246; Mon, 3 Jun 2019 09:03:58 -0700 (PDT) X-Inumbo-ID: 336ebb00-8619-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:37 +0100 Message-Id: <20190603160350.29806-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 01/14] xen/x86: Make mfn_to_gfn typesafe 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 , George Dunlap , Andrew Cooper , Tim Deegan , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional changes intended. Signed-off-by: Julien Grall Acked-by: George Dunlap Reviewed-by: Jan Beulich --- Changes in v3: - Remove gfn_x(...) for gfn used in parameter of __trace_var(...). Changes in v2: - Patch added --- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/mm/shadow/common.c | 31 ++++++++++++++++++------------- xen/arch/x86/mm/shadow/multi.c | 4 ++-- xen/include/asm-x86/p2m.h | 6 +++--- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 4c9954867c..279278715e 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -951,7 +951,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mf= n_t mfn, } if ( page_get_owner(mfn_to_page(mfn_add(mfn, i))) !=3D d ) continue; - ogfn =3D _gfn(mfn_to_gfn(d, mfn_add(mfn, i))); + ogfn =3D mfn_to_gfn(d, mfn_add(mfn, i)); if ( !gfn_eq(ogfn, _gfn(INVALID_M2P_ENTRY)) && !gfn_eq(ogfn, gfn_add(gfn, i)) ) { diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/commo= n.c index 795201dc82..1e67bd072a 100644 --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn) if ( tb_init_done ) { /* Convert gmfn to gfn */ - unsigned long gfn =3D mfn_to_gfn(current->domain, gmfn); + gfn_t gfn =3D mfn_to_gfn(current->domain, gmfn); + __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn); } } @@ -985,7 +986,8 @@ static inline void trace_shadow_prealloc_unpin(struct d= omain *d, mfn_t smfn) if ( tb_init_done ) { /* Convert smfn to gfn */ - unsigned long gfn; + gfn_t gfn; + ASSERT(mfn_valid(smfn)); gfn =3D mfn_to_gfn(d, backpointer(mfn_to_page(smfn))); __trace_var(TRC_SHADOW_PREALLOC_UNPIN, 0/*!tsc*/, sizeof(gfn), &gf= n); @@ -1861,7 +1863,8 @@ static inline void trace_shadow_wrmap_bf(mfn_t gmfn) if ( tb_init_done ) { /* Convert gmfn to gfn */ - unsigned long gfn =3D mfn_to_gfn(current->domain, gmfn); + gfn_t gfn =3D mfn_to_gfn(current->domain, gmfn); + __trace_var(TRC_SHADOW_WRMAP_BF, 0/*!tsc*/, sizeof(gfn), &gfn); } } @@ -1946,7 +1949,7 @@ int sh_remove_write_access(struct domain *d, mfn_t gm= fn, #if SHADOW_OPTIMIZATIONS & SHOPT_WRITABLE_HEURISTIC if ( curr->domain =3D=3D d ) { - unsigned long gfn; + gfn_t gfn; /* Heuristic: there is likely to be only one writeable mapping, * and that mapping is likely to be in the current pagetable, * in the guest's linear map (on non-HIGHPTE linux and windows)*/ @@ -1969,8 +1972,9 @@ int sh_remove_write_access(struct domain *d, mfn_t gm= fn, GUESS(0xC0000000UL + (fault_addr >> 10), 1); =20 /* Linux lowmem: first 896MB is mapped 1-to-1 above 0xC0000000= */ - if ((gfn =3D mfn_to_gfn(d, gmfn)) < 0x38000 ) - GUESS(0xC0000000UL + (gfn << PAGE_SHIFT), 4); + gfn =3D mfn_to_gfn(d, gmfn); + if ( gfn_x(gfn) < 0x38000 ) + GUESS(0xC0000000UL + gfn_to_gaddr(gfn), 4); =20 /* FreeBSD: Linear map at 0xBFC00000 */ if ( level =3D=3D 1 ) @@ -1987,8 +1991,9 @@ int sh_remove_write_access(struct domain *d, mfn_t gm= fn, } =20 /* Linux lowmem: first 896MB is mapped 1-to-1 above 0xC0000000= */ - if ((gfn =3D mfn_to_gfn(d, gmfn)) < 0x38000 ) - GUESS(0xC0000000UL + (gfn << PAGE_SHIFT), 4); + gfn =3D mfn_to_gfn(d, gmfn); + if ( gfn_x(gfn) < 0x38000 ) + GUESS(0xC0000000UL + gfn_to_gaddr(gfn), 4); =20 /* FreeBSD PAE: Linear map at 0xBF800000 */ switch ( level ) @@ -2016,15 +2021,15 @@ int sh_remove_write_access(struct domain *d, mfn_t = gmfn, * had it at 0xffff810000000000, and older kernels yet had it * at 0x0000010000000000UL */ gfn =3D mfn_to_gfn(d, gmfn); - GUESS(0xffff880000000000UL + (gfn << PAGE_SHIFT), 4); - GUESS(0xffff810000000000UL + (gfn << PAGE_SHIFT), 4); - GUESS(0x0000010000000000UL + (gfn << PAGE_SHIFT), 4); + GUESS(0xffff880000000000UL + gfn_to_gaddr(gfn), 4); + GUESS(0xffff810000000000UL + gfn_to_gaddr(gfn), 4); + GUESS(0x0000010000000000UL + gfn_to_gaddr(gfn), 4); =20 /* * 64bit Solaris kernel page map at * kpm_vbase; 0xfffffe0000000000UL */ - GUESS(0xfffffe0000000000UL + (gfn << PAGE_SHIFT), 4); + GUESS(0xfffffe0000000000UL + gfn_to_gaddr(gfn), 4); =20 /* FreeBSD 64bit: linear map 0xffff800000000000 */ switch ( level ) @@ -2037,7 +2042,7 @@ int sh_remove_write_access(struct domain *d, mfn_t gm= fn, + ((fault_addr & VADDR_MASK) >> 27), 6); break; } /* FreeBSD 64bit: direct map at 0xffffff0000000000 */ - GUESS(0xffffff0000000000 + (gfn << PAGE_SHIFT), 6); + GUESS(0xffffff0000000000 + gfn_to_gaddr(gfn), 6); } =20 #undef GUESS diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index 5f8a745de2..74681ba85c 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -1076,7 +1076,7 @@ static inline void shadow_vram_get_l1e(shadow_l1e_t n= ew_sl1e, || !mfn_valid(mfn) ) /* mfn can be invalid in mmio_direct */ return; =20 - gfn =3D mfn_to_gfn(d, mfn); + gfn =3D gfn_x(mfn_to_gfn(d, mfn)); /* Page sharing not supported on shadow PTs */ BUG_ON(SHARED_M2P(gfn)); =20 @@ -1107,7 +1107,7 @@ static inline void shadow_vram_put_l1e(shadow_l1e_t o= ld_sl1e, || !mfn_valid(mfn) ) /* mfn can be invalid in mmio_direct */ return; =20 - gfn =3D mfn_to_gfn(d, mfn); + gfn =3D gfn_x(mfn_to_gfn(d, mfn)); /* Page sharing not supported on shadow PTs */ BUG_ON(SHARED_M2P(gfn)); =20 diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 09ef7e02fd..1a075547e2 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -506,12 +506,12 @@ static inline struct page_info *get_page_from_gfn( } =20 /* General conversion function from mfn to gfn */ -static inline unsigned long mfn_to_gfn(const struct domain *d, mfn_t mfn) +static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn) { if ( paging_mode_translate(d) ) - return get_gpfn_from_mfn(mfn_x(mfn)); + return _gfn(get_gpfn_from_mfn(mfn_x(mfn))); else - return mfn_x(mfn); + return _gfn(mfn_x(mfn)); } =20 #ifdef CONFIG_HVM --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577907; cv=none; d=zoho.com; s=zohoarc; b=WV7xcj0yQcB+bWR8OfM0xa7dgzzbKSOWAF68tk4MZpSrSQssJJu1wZToLkaK9jL6BfBqVld5xa4GxVoBARXBPCSGO93jaUiLvUcG8WQM66ndLuAhhuyeFZ+AWL1H5P33rhTQjffF+hzSJ5bIxbM2wxsfWBp/pA7R+3GhcVyEzoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577907; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=N11UoGuk6+T2schottcahn0oFtGnqfSGlkL2B9oPHe8=; b=cuePx43ahVRNEp3xP5ggwGAxL5+GtsbwWiaiWC73+48ZfpyGCM42b/bUxQU+1IodgYM2ybU7EtXf8jl4ILMDNFz/v+GamcwjKO8Hg4cphquungxuqBo1Gl2qRLuQVyH8IsN5aTFwvGwqyZgXW+sJUX9aOYCT/hVXkxt41KQyTBc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577907837153.49398723250658; Mon, 3 Jun 2019 09:05:07 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRN-0001uE-4b; Mon, 03 Jun 2019 16:04:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRL-0001tP-O2 for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:03 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 344ce139-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04: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 D3D6D80D; Mon, 3 Jun 2019 09:04:01 -0700 (PDT) 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 A099C3F246; Mon, 3 Jun 2019 09:04:00 -0700 (PDT) X-Inumbo-ID: 344ce139-8619-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:38 +0100 Message-Id: <20190603160350.29806-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 02/14] xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn 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: Andrew Cooper , Julien Grall , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" mfn_to_gfn and mfn_to_gmfn are doing exactly the same except the former is using mfn_t and gfn_t (return type). Furthermore, the naming of the former is more consistent with the current naming scheme (GFN/MFN). So replace mfn_to_gmfn with mfn_to_gfn in x86 code. Take the opportunity to convert some of the callers to use typesafe GFN and format the message correctly. No functional changes. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich -- Changes in v3: - The hunk in x86/mm.c is not necessary anymore - Update printk message to use GFN rather than frame when suitable - Update commit message with some NITs - Add Jan's reviewed-by Changes in v2: - mfn_to_gfn now returns a gfn_t - Use %pd and PRI_gfn when possible in the message - Don't split format string to help grep/ack. --- xen/arch/x86/domain.c | 34 +++++++++++++++++++--------------- xen/arch/x86/pv/emul-priv-op.c | 4 ++-- xen/drivers/passthrough/x86/iommu.c | 16 +++++++++------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 9485a17ddd..6553adc5c0 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -700,7 +700,7 @@ int arch_domain_soft_reset(struct domain *d) int ret =3D 0; struct domain *owner; mfn_t mfn; - unsigned long gfn; + gfn_t gfn; p2m_type_t p2mt; unsigned int i; =20 @@ -734,19 +734,20 @@ int arch_domain_soft_reset(struct domain *d) ASSERT( owner =3D=3D d ); =20 mfn =3D page_to_mfn(page); - gfn =3D mfn_to_gmfn(d, mfn_x(mfn)); + gfn =3D mfn_to_gfn(d, mfn); =20 /* * gfn =3D=3D INVALID_GFN indicates that the shared_info page was neve= r mapped * to the domain's address space and there is nothing to replace. */ - if ( gfn =3D=3D gfn_x(INVALID_GFN) ) + if ( gfn_eq(gfn, INVALID_GFN) ) goto exit_put_page; =20 - if ( !mfn_eq(get_gfn_query(d, gfn, &p2mt), mfn) ) + if ( !mfn_eq(get_gfn_query(d, gfn_x(gfn), &p2mt), mfn) ) { - printk(XENLOG_G_ERR "Failed to get Dom%d's shared_info GFN (%lx)\n= ", - d->domain_id, gfn); + printk(XENLOG_G_ERR + "Failed to get %pd's shared_info GFN (%"PRI_gfn")\n", + d, gfn_x(gfn)); ret =3D -EINVAL; goto exit_put_gfn; } @@ -754,31 +755,34 @@ int arch_domain_soft_reset(struct domain *d) new_page =3D alloc_domheap_page(d, 0); if ( !new_page ) { - printk(XENLOG_G_ERR "Failed to alloc a page to replace" - " Dom%d's shared_info frame %lx\n", d->domain_id, gfn); + printk(XENLOG_G_ERR + "Failed to alloc a page to replace %pd's shared_info GFN %"= PRI_gfn"\n", + d, gfn_x(gfn)); ret =3D -ENOMEM; goto exit_put_gfn; } =20 - ret =3D guest_physmap_remove_page(d, _gfn(gfn), mfn, PAGE_ORDER_4K); + ret =3D guest_physmap_remove_page(d, gfn, mfn, PAGE_ORDER_4K); if ( ret ) { - printk(XENLOG_G_ERR "Failed to remove Dom%d's shared_info frame %l= x\n", - d->domain_id, gfn); + printk(XENLOG_G_ERR + "Failed to remove %pd's shared_info GFN %"PRI_gfn"\n", + d, gfn_x(gfn)); free_domheap_page(new_page); goto exit_put_gfn; } =20 - ret =3D guest_physmap_add_page(d, _gfn(gfn), page_to_mfn(new_page), + ret =3D guest_physmap_add_page(d, gfn, page_to_mfn(new_page), PAGE_ORDER_4K); if ( ret ) { - printk(XENLOG_G_ERR "Failed to add a page to replace" - " Dom%d's shared_info frame %lx\n", d->domain_id, gfn); + printk(XENLOG_G_ERR + "Failed to add a page to replace %pd's shared_info frame %"= PRI_gfn"\n", + d, gfn_x(gfn)); free_domheap_page(new_page); } exit_put_gfn: - put_gfn(d, gfn); + put_gfn(d, gfn_x(gfn)); exit_put_page: put_page(page); =20 diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index b20d79c7a3..ab4c8a7ec4 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -712,7 +712,7 @@ static int read_cr(unsigned int reg, unsigned long *val, if ( !is_pv_32bit_domain(currd) ) { mfn =3D pagetable_get_mfn(curr->arch.guest_table); - *val =3D xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn))); + *val =3D xen_pfn_to_cr3(gfn_x(mfn_to_gfn(currd, mfn))); } else { @@ -721,7 +721,7 @@ static int read_cr(unsigned int reg, unsigned long *val, =20 mfn =3D l4e_get_mfn(*pl4e); unmap_domain_page(pl4e); - *val =3D compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn))); + *val =3D compat_pfn_to_cr3(gfn_x(mfn_to_gfn(currd, mfn))); } /* PTs should not be shared */ BUG_ON(page_get_owner(mfn_to_page(mfn)) =3D=3D dom_cow); diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index 0fa6dcc3fd..35c2b3297c 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -90,15 +90,17 @@ int arch_iommu_populate_page_table(struct domain *d) if ( is_hvm_domain(d) || (page->u.inuse.type_info & PGT_type_mask) =3D=3D PGT_writable_= page ) { - unsigned long mfn =3D mfn_x(page_to_mfn(page)); - unsigned long gfn =3D mfn_to_gmfn(d, mfn); + mfn_t mfn =3D page_to_mfn(page); + gfn_t gfn =3D mfn_to_gfn(d, mfn); unsigned int flush_flags =3D 0; =20 - if ( gfn !=3D gfn_x(INVALID_GFN) ) + if ( !gfn_eq(gfn, INVALID_GFN) ) { - ASSERT(!(gfn >> DEFAULT_DOMAIN_ADDRESS_WIDTH)); - BUG_ON(SHARED_M2P(gfn)); - rc =3D iommu_map(d, _dfn(gfn), _mfn(mfn), PAGE_ORDER_4K, + dfn_t dfn =3D _dfn(gfn_x(gfn)); + + ASSERT(!(gfn_x(gfn) >> DEFAULT_DOMAIN_ADDRESS_WIDTH)); + BUG_ON(SHARED_M2P(gfn_x(gfn))); + rc =3D iommu_map(d, dfn, mfn, PAGE_ORDER_4K, IOMMUF_readable | IOMMUF_writable, &flush_flags); =20 @@ -116,7 +118,7 @@ int arch_iommu_populate_page_table(struct domain *d) ((page->u.inuse.type_info & PGT_type_mask) !=3D PGT_writable_page) ) { - rc =3D iommu_unmap(d, _dfn(gfn), PAGE_ORDER_4K, &flush= _flags); + rc =3D iommu_unmap(d, dfn, PAGE_ORDER_4K, &flush_flags= ); /* If the type changed yet again, simply force a retry= . */ if ( !rc && ((page->u.inuse.type_info & PGT_type_mask)= =3D=3D PGT_writable_page) ) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577909; cv=none; d=zoho.com; s=zohoarc; b=Q5OPw7rsvnCtmg2Hm1GPY3Jny1rXXBzF36EKvmFb7d7oYDzNbJcvIOUZgXtd6rUwQC6L8fCFKUL6HfK5Ou/GatSVHVHWAjgd26Xcnh/RNeMbVLnalnMufsz/QDWwF8YOioBghW5tZ+xOzaR1OQm9eAhTujNm3Qy27dU0CRkdYtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577909; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ljZ+6jvUCRsDrx2GtEVxurJyTEoJcf/yB+y50iIMU4M=; b=LGi6b6bq0JCXmLouBSW7k8Adr3RgblI6cragkYYaun7ASfn4tXB4gFMxDzQnj8lNI7c1fnNwJF3z2lH8ySKMBpZVsjbm4dl3hriU8qlS1hvpG0x+Bt4ipkZimKL5ltLd5n0Rd03Jvx5pQcki2j30jfMq2kyhfqH/wighYxzBAuY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577909686985.6627289850148; Mon, 3 Jun 2019 09:05:09 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRO-0001v1-G8; Mon, 03 Jun 2019 16:04:06 +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 1hXpRN-0001uG-9I for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:05 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 35a05018-8619-11e9-b34d-a759a37a7fc6; Mon, 03 Jun 2019 16:04: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 0FD4AA78; Mon, 3 Jun 2019 09:04:04 -0700 (PDT) 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 1F4AB3F246; Mon, 3 Jun 2019 09:04:01 -0700 (PDT) X-Inumbo-ID: 35a05018-8619-11e9-b34d-a759a37a7fc6 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:39 +0100 Message-Id: <20190603160350.29806-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 03/14] xen/grant-table: Make arch specific macros typesafe 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 , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch rework all the arch specific macros in grant_table.h to use the typesafe MFN/GFN. At the same time, some functions are renamed s/gmfn/gfn/ to match the current naming scheme (see include/mm.h). No functional changes intended. Signed-off-by: Julien Grall Acked-by: Jan Beulich Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Update commit message to explain the changes made - Fix indentation - Adapt the code to match the new prototype of mfn_to_gfn - Add Jan's acked-by for non-ARM parts --- xen/common/grant_table.c | 4 ++-- xen/include/asm-arm/grant_table.h | 12 ++++++------ xen/include/asm-x86/grant_table.h | 19 +++++++------------ 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index dd8a9d9046..7680241851 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1960,7 +1960,7 @@ gnttab_setup_table( op.status =3D GNTST_okay; for ( i =3D 0; i < op.nr_frames; i++ ) { - xen_pfn_t gmfn =3D gnttab_shared_gmfn(d, gt, i); + xen_pfn_t gmfn =3D gfn_x(gnttab_shared_gfn(d, gt, i)); =20 /* Grant tables cannot be shared */ BUG_ON(SHARED_M2P(gmfn)); @@ -3174,7 +3174,7 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gntta= b_get_status_frames_t) uop, =20 for ( i =3D 0; i < op.nr_frames; i++ ) { - gmfn =3D gnttab_status_gmfn(d, gt, i); + gmfn =3D gfn_x(gnttab_status_gfn(d, gt, i)); if ( copy_to_guest_offset(op.frame_list, i, &gmfn, 1) ) op.status =3D GNTST_bad_virt_addr; } diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_= table.h index 051db1362b..750536184e 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -65,15 +65,15 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn); } while ( 0 ) =20 #define gnttab_get_frame_gfn(gt, st, idx) ({ \ - _gfn((st) ? gnttab_status_gmfn(NULL, gt, idx) \ - : gnttab_shared_gmfn(NULL, gt, idx)); \ + (st) ? gnttab_status_gfn(NULL, gt, idx) \ + : gnttab_shared_gfn(NULL, gt, idx); \ }) =20 -#define gnttab_shared_gmfn(d, t, i) \ - gfn_x(((i) >=3D nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_g= fn[i]) +#define gnttab_shared_gfn(d, t, i) \ + (((i) >=3D nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i]) =20 -#define gnttab_status_gmfn(d, t, i) \ - gfn_x(((i) >=3D nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_= gfn[i]) +#define gnttab_status_gfn(d, t, i) \ + (((i) >=3D nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i= ]) =20 #define gnttab_need_iommu_mapping(d) \ (is_domain_direct_mapped(d) && need_iommu_pt_sync(d)) diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_= table.h index 8b604ed51f..661228dd39 100644 --- a/xen/include/asm-x86/grant_table.h +++ b/xen/include/asm-x86/grant_table.h @@ -39,24 +39,19 @@ static inline int replace_grant_host_mapping(uint64_t a= ddr, mfn_t frame, #define gnttab_destroy_arch(gt) do {} while ( 0 ) #define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 ) #define gnttab_get_frame_gfn(gt, st, idx) ({ \ - unsigned long mfn_ =3D (st) ? gnttab_status_mfn(gt, idx) = \ - : gnttab_shared_mfn(gt, idx); \ - unsigned long gpfn_ =3D get_gpfn_from_mfn(mfn_); = \ + mfn_t mfn_ =3D (st) ? gnttab_status_mfn(gt, idx) = \ + : gnttab_shared_mfn(gt, idx); \ + unsigned long gpfn_ =3D get_gpfn_from_mfn(mfn_x(mfn_)); = \ VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN; \ }) =20 -#define gnttab_shared_mfn(t, i) \ - ((virt_to_maddr((t)->shared_raw[i]) >> PAGE_SHIFT)) +#define gnttab_shared_mfn(t, i) _mfn(__virt_to_mfn((t)->shared_raw[i])) =20 -#define gnttab_shared_gmfn(d, t, i) \ - (mfn_to_gmfn(d, gnttab_shared_mfn(t, i))) +#define gnttab_shared_gfn(d, t, i) mfn_to_gfn(d, gnttab_shared_mfn(t, i)) =20 +#define gnttab_status_mfn(t, i) _mfn(__virt_to_mfn((t)->status[i])) =20 -#define gnttab_status_mfn(t, i) \ - ((virt_to_maddr((t)->status[i]) >> PAGE_SHIFT)) - -#define gnttab_status_gmfn(d, t, i) \ - (mfn_to_gmfn(d, gnttab_status_mfn(t, i))) +#define gnttab_status_gfn(d, t, i) mfn_to_gfn(d, gnttab_status_mfn(t, i)) =20 #define gnttab_mark_dirty(d, f) paging_mark_dirty(d, f) =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577915; cv=none; d=zoho.com; s=zohoarc; b=Q9v92Agh8++zPs6dEgtCh+5mdAZxAz8C7Q3D4aEG/plzRDqe/Sk2b1fxMN3xjyyoQI0Rl1fUA3qjN9mok71UQk4GugDl9JlfwNh+GYUYl4ND7MdZXJ4L1Pyg5KnkfcsvNDyssqsUvjasRVGlNpAMQjfZX30mfC1ZYE39Rl/8Hzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577915; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=A2SfxWTw5izmYCBs789HZzlm5vUf/hsbYJw4CxykJ24=; b=AqmqSTo27+G1NMo3IHaIoopulEEmzMmm86enoMiRJdHfnKYhxJH6rmb710uYq7DRjPyFgpx6u/GJQIrgqK5QNQarSfUrDt3emtT18Ozhs2rVc9tV0QhAjPTAKv9DBPQ/1yajCrzaPVgncXqmAk1A2twtZw0bK0anFZ9ng2PRcuc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577915342383.713826402102; Mon, 3 Jun 2019 09:05:15 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRR-0001wP-Sr; Mon, 03 Jun 2019 16:04: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 1hXpRQ-0001vx-Ev for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:08 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3712eb4c-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04: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 6331880D; Mon, 3 Jun 2019 09:04:06 -0700 (PDT) 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 4F5553F246; Mon, 3 Jun 2019 09:04:04 -0700 (PDT) X-Inumbo-ID: 3712eb4c-8619-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:40 +0100 Message-Id: <20190603160350.29806-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 04/14] xen: Convert hotplug page function to use typesafe MFN 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 , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Convert online_page, offline_page and query_page_offline to use typesafe MFN. At the same time, the typesafe is propagated as far as possible without major modifications. Note, for clarity, the words have been re-ordered in the error message updated by this patch. No functional changes. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- Changes in v3: - Mention in the commit message that the typesafe is propagated Changes in v2: - Update error message - Add Jan's acked-by --- xen/arch/x86/cpu/mcheck/mcaction.c | 18 ++++++++++-------- xen/common/page_alloc.c | 24 ++++++++++++------------ xen/common/sysctl.c | 14 +++++++------- xen/include/xen/mm.h | 6 +++--- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/cpu/mcheck/mcaction.c b/xen/arch/x86/cpu/mcheck/m= caction.c index e42267414e..69332fb84d 100644 --- a/xen/arch/x86/cpu/mcheck/mcaction.c +++ b/xen/arch/x86/cpu/mcheck/mcaction.c @@ -6,7 +6,7 @@ =20 static struct mcinfo_recovery * mci_action_add_pageoffline(int bank, struct mc_info *mi, - uint64_t mfn, uint32_t status) + mfn_t mfn, uint32_t status) { struct mcinfo_recovery *rec; =20 @@ -22,7 +22,7 @@ mci_action_add_pageoffline(int bank, struct mc_info *mi, =20 rec->mc_bank =3D bank; rec->action_types =3D MC_ACTION_PAGE_OFFLINE; - rec->action_info.page_retire.mfn =3D mfn; + rec->action_info.page_retire.mfn =3D mfn_x(mfn); rec->action_info.page_retire.status =3D status; return rec; } @@ -42,7 +42,8 @@ mc_memerr_dhandler(struct mca_binfo *binfo, struct mcinfo_bank *bank =3D binfo->mib; struct mcinfo_global *global =3D binfo->mig; struct domain *d; - unsigned long mfn, gfn; + mfn_t mfn; + unsigned long gfn; uint32_t status; int vmce_vcpuid; unsigned int mc_vcpuid; @@ -54,11 +55,12 @@ mc_memerr_dhandler(struct mca_binfo *binfo, return; } =20 - mfn =3D bank->mc_addr >> PAGE_SHIFT; + mfn =3D maddr_to_mfn(bank->mc_addr); if ( offline_page(mfn, 1, &status) ) { dprintk(XENLOG_WARNING, - "Failed to offline page %lx for MCE error\n", mfn); + "Failed to offline page %"PRI_mfn" for MCE error\n", + mfn_x(mfn)); return; } =20 @@ -89,10 +91,10 @@ mc_memerr_dhandler(struct mca_binfo *binfo, ASSERT(d); gfn =3D get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT); =20 - if ( unmmap_broken_page(d, _mfn(mfn), gfn) ) + if ( unmmap_broken_page(d, mfn, gfn) ) { - printk("Unmap broken memory %lx for DOM%d failed\n", - mfn, d->domain_id); + printk("Unmap broken memory %"PRI_mfn" for DOM%d faile= d\n", + mfn_x(mfn), d->domain_id); goto vmce_failed; } =20 diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 7825fd8c42..7075e084b4 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1556,23 +1556,23 @@ static int reserve_heap_page(struct page_info *pg) =20 } =20 -int offline_page(unsigned long mfn, int broken, uint32_t *status) +int offline_page(mfn_t mfn, int broken, uint32_t *status) { unsigned long old_info =3D 0; struct domain *owner; struct page_info *pg; =20 - if ( !mfn_valid(_mfn(mfn)) ) + if ( !mfn_valid(mfn) ) { dprintk(XENLOG_WARNING, - "try to offline page out of range %lx\n", mfn); + "try to offline out of range page %"PRI_mfn"\n", mfn_x(mfn= )); return -EINVAL; } =20 *status =3D 0; - pg =3D mfn_to_page(_mfn(mfn)); + pg =3D mfn_to_page(mfn); =20 - if ( is_xen_fixed_mfn(mfn) ) + if ( is_xen_fixed_mfn(mfn_x(mfn)) ) { *status =3D PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED | (DOMID_XEN << PG_OFFLINE_OWNER_SHIFT); @@ -1583,7 +1583,7 @@ int offline_page(unsigned long mfn, int broken, uint3= 2_t *status) * N.B. xen's txt in x86_64 is marked reserved and handled already. * Also kexec range is reserved. */ - if ( !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) ) + if ( !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) ) { *status =3D PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM; return -EINVAL; @@ -1665,19 +1665,19 @@ int offline_page(unsigned long mfn, int broken, uin= t32_t *status) * The caller should make sure end_pfn <=3D max_page, * if not, expand_pages() should be called prior to online_page(). */ -unsigned int online_page(unsigned long mfn, uint32_t *status) +unsigned int online_page(mfn_t mfn, uint32_t *status) { unsigned long x, nx, y; struct page_info *pg; int ret; =20 - if ( !mfn_valid(_mfn(mfn)) ) + if ( !mfn_valid(mfn) ) { dprintk(XENLOG_WARNING, "call expand_pages() first\n"); return -EINVAL; } =20 - pg =3D mfn_to_page(_mfn(mfn)); + pg =3D mfn_to_page(mfn); =20 spin_lock(&heap_lock); =20 @@ -1718,11 +1718,11 @@ unsigned int online_page(unsigned long mfn, uint32_= t *status) return ret; } =20 -int query_page_offline(unsigned long mfn, uint32_t *status) +int query_page_offline(mfn_t mfn, uint32_t *status) { struct page_info *pg; =20 - if ( !mfn_valid(_mfn(mfn)) || !page_is_ram_type(mfn, RAM_TYPE_CONVENTI= ONAL) ) + if ( !mfn_valid(mfn) || !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENT= IONAL) ) { dprintk(XENLOG_WARNING, "call expand_pages() first\n"); return -EINVAL; @@ -1731,7 +1731,7 @@ int query_page_offline(unsigned long mfn, uint32_t *s= tatus) *status =3D 0; spin_lock(&heap_lock); =20 - pg =3D mfn_to_page(_mfn(mfn)); + pg =3D mfn_to_page(mfn); =20 if ( page_state_is(pg, offlining) ) *status |=3D PG_OFFLINE_STATUS_OFFLINE_PENDING; diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index 765effde8d..fcf2d2fd7c 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -185,7 +185,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_s= ysctl) case XEN_SYSCTL_page_offline_op: { uint32_t *status, *ptr; - unsigned long pfn; + mfn_t mfn; =20 ret =3D xsm_page_offline(XSM_HOOK, op->u.page_offline.cmd); if ( ret ) @@ -204,21 +204,21 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u= _sysctl) memset(status, PG_OFFLINE_INVALID, sizeof(uint32_t) * (op->u.page_offline.end - op->u.page_offline.start += 1)); =20 - for ( pfn =3D op->u.page_offline.start; - pfn <=3D op->u.page_offline.end; - pfn ++ ) + for ( mfn =3D _mfn(op->u.page_offline.start); + mfn_x(mfn) <=3D op->u.page_offline.end; + mfn =3D mfn_add(mfn, 1) ) { switch ( op->u.page_offline.cmd ) { /* Shall revert her if failed, or leave caller do it? */ case sysctl_page_offline: - ret =3D offline_page(pfn, 0, ptr++); + ret =3D offline_page(mfn, 0, ptr++); break; case sysctl_page_online: - ret =3D online_page(pfn, ptr++); + ret =3D online_page(mfn, ptr++); break; case sysctl_query_page_offline: - ret =3D query_page_offline(pfn, ptr++); + ret =3D query_page_offline(mfn, ptr++); break; default: ret =3D -EINVAL; diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 7fc3039593..196ce9fcda 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -206,9 +206,9 @@ unsigned long avail_domheap_pages(void); unsigned long avail_node_heap_pages(unsigned int); #define alloc_domheap_page(d,f) (alloc_domheap_pages(d,0,f)) #define free_domheap_page(p) (free_domheap_pages(p,0)) -unsigned int online_page(unsigned long mfn, uint32_t *status); -int offline_page(unsigned long mfn, int broken, uint32_t *status); -int query_page_offline(unsigned long mfn, uint32_t *status); +unsigned int online_page(mfn_t mfn, uint32_t *status); +int offline_page(mfn_t mfn, int broken, uint32_t *status); +int query_page_offline(mfn_t mfn, uint32_t *status); =20 void heap_init_late(void); =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577917; cv=none; d=zoho.com; s=zohoarc; b=UM++2N3h/iWA7WxkNZH0nPjOm/a/XS6WvcnJkptpl6YXYTtpcZQlBvCwWFnQdgEaH8IJvqogNJl7ExPriZLCaSP0yz6sijlcoNsHs1TVq9l1xlXEphma+u8Y1sic4coWwKJU4AqGrWJ7zP67aYRRy4jYCNh9C0w7ZyKwZCzZpiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577917; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9I6SG1Dz3HCvviVDoowGPpTpX8L5XhdKvTHABn47KpA=; b=dIoelhHuG4+uoYBNIYbCO7ppMQZo+2pQTUoIFyYuaPJ0ocl8wNjZq3GZOOC41nH2doYu+3sqf6jnUH4V8M9kfA3DHRv86Jyc+vS6KmmqgP0rSTkTTAJsYWx80o1bQpgZ/pvwqYPX9NQ+2cpWDhOErvOfVq50irAObynxUBcNFL0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577917529166.88586732135468; Mon, 3 Jun 2019 09:05:17 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRT-0001xO-91; Mon, 03 Jun 2019 16:04: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 1hXpRS-0001wq-D7 for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:10 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3886b10a-8619-11e9-892c-875838fe41ea; Mon, 03 Jun 2019 16:04:09 +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 0929515AB; Mon, 3 Jun 2019 09:04:09 -0700 (PDT) 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 A268F3F246; Mon, 3 Jun 2019 09:04:06 -0700 (PDT) X-Inumbo-ID: 3886b10a-8619-11e9-892c-875838fe41ea From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:41 +0100 Message-Id: <20190603160350.29806-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 05/14] xen: Convert is_xen_fixed_mfn to use typesafe MFN 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 , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Shane Wang , Ian Jackson , George Dunlap , Tim Deegan , Julien Grall , Jan Beulich , Andrew Cooper , Gang Wei , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional changes. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich Acked-by: Stefano Stabellini Reviewed-by: George Dunlap --- Changes in v3: - Add George's reviewed-by Changes in v2: - Add Jan's reviewed-by - Add Stefano's acked-by --- xen/arch/x86/tboot.c | 2 +- xen/common/page_alloc.c | 2 +- xen/include/asm-arm/mm.h | 4 ++-- xen/include/asm-x86/mm.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index f3fdee4d39..30d159cc62 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -280,7 +280,7 @@ static void tboot_gen_xenheap_integrity(const uint8_t k= ey[TB_KEY_SIZE], =20 if ( !mfn_valid(_mfn(mfn)) ) continue; - if ( is_xen_fixed_mfn(mfn) ) + if ( is_xen_fixed_mfn(_mfn(mfn)) ) continue; /* skip Xen */ if ( (mfn >=3D PFN_DOWN(g_tboot_shared->tboot_base - 3 * PAGE_SIZE= )) && (mfn < PFN_UP(g_tboot_shared->tboot_base diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 7075e084b4..71e24dbb2d 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1572,7 +1572,7 @@ int offline_page(mfn_t mfn, int broken, uint32_t *sta= tus) *status =3D 0; pg =3D mfn_to_page(mfn); =20 - if ( is_xen_fixed_mfn(mfn_x(mfn)) ) + if ( is_xen_fixed_mfn(mfn) ) { *status =3D PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED | (DOMID_XEN << PG_OFFLINE_OWNER_SHIFT); diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 7b6aaf5e3f..b56018aace 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -151,8 +151,8 @@ extern vaddr_t xenheap_virt_start; #endif =20 #define is_xen_fixed_mfn(mfn) \ - ((pfn_to_paddr(mfn) >=3D virt_to_maddr(&_start)) && \ - (pfn_to_paddr(mfn) <=3D virt_to_maddr(&_end))) + ((mfn_to_maddr(mfn) >=3D virt_to_maddr(&_start)) && \ + (mfn_to_maddr(mfn) <=3D virt_to_maddr(&_end))) =20 #define page_get_owner(_p) (_p)->v.inuse.domain #define page_set_owner(_p,_d) ((_p)->v.inuse.domain =3D (_d)) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index c72e329506..0d954e1bd8 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -280,8 +280,8 @@ struct page_info #define is_xen_heap_mfn(mfn) \ (__mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(_mfn(mfn)))) #define is_xen_fixed_mfn(mfn) \ - ((((mfn) << PAGE_SHIFT) >=3D __pa(&_stext)) && \ - (((mfn) << PAGE_SHIFT) <=3D __pa(&__2M_rwdata_end))) + (((mfn_to_maddr(mfn)) >=3D __pa(&_stext)) && \ + ((mfn_to_maddr(mfn)) <=3D __pa(&__2M_rwdata_end))) =20 #define PRtype_info "016lx"/* should only be used for printk's */ =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577919; cv=none; d=zoho.com; s=zohoarc; b=ffu1GU+0UxJWJcQNBFWbJ+AgcQD1W87s1behcGorxBD5Ycl7QYuO8j2J63KZ9TizCZgIYScoNRxk1zy3UXdaZef2KFsXlB0I6ee3yrwJGsGnGbvqOR9zoMHvH+QzVfTr9foQNtVbES46s8dKGq3JkHDecWEaEAnTuBw9S/54jSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577919; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FqW0tXfX40NoB53FUeOU+i8GYSkLn5dqY/2768yw0JU=; b=eqmh8iRrGqjE3s/eOWvEf2Yn6sreavv4fZZSEAr4hElyq3UKRudSBUz86zvo37+zzvAWNcgEooYVRcJrN9YnkvBXki5nBFRURhW1KvxiMQs76RhbySfgzlQWzoOh1XOa+PORvvfk1G46tOMdifeImUwQZCpv3oP/hZ7TTCq1S6U= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577919124656.6220514904048; Mon, 3 Jun 2019 09:05:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRU-0001zI-Rt; Mon, 03 Jun 2019 16:04: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 1hXpRU-0001yr-GW for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:12 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 39df92f4-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04: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 5C8A7A78; Mon, 3 Jun 2019 09:04:11 -0700 (PDT) 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 48CED3F246; Mon, 3 Jun 2019 09:04:09 -0700 (PDT) X-Inumbo-ID: 39df92f4-8619-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:42 +0100 Message-Id: <20190603160350.29806-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 06/14] xen: Convert is_xen_heap_mfn to use typesafe MFN 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 , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , George Dunlap , Tim Deegan , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional changes. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich Acked-by: Stefano Stabellini Reviewed-by: George Dunlap --- Changes in v3: - Add George's reviewed-by Changes in v2: - Fix coding style - Merge the declaration for gpfn and old_gpfn - Don't open-code mfn_valid - Add Jan's reviewed-by - Use mfn_add(mfn, -1) - Add Stefano's acked-by for ARM parts --- xen/arch/x86/mm.c | 10 +++++----- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/mm/shadow/multi.c | 2 +- xen/common/page_alloc.c | 4 ++-- xen/include/asm-arm/mm.h | 8 ++++---- xen/include/asm-x86/mm.h | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 2f620d9aeb..3d3d8bd7a8 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4458,8 +4458,8 @@ int xenmem_add_to_physmap_one( gfn_t gpfn) { struct page_info *page =3D NULL; - unsigned long gfn =3D 0; /* gcc ... */ - unsigned long prev_mfn, old_gpfn; + unsigned long gfn =3D 0 /* gcc ... */, old_gpfn; + mfn_t prev_mfn; int rc =3D 0; mfn_t mfn =3D INVALID_MFN; p2m_type_t p2mt; @@ -4505,12 +4505,12 @@ int xenmem_add_to_physmap_one( } =20 /* Remove previously mapped page if it was present. */ - prev_mfn =3D mfn_x(get_gfn(d, gfn_x(gpfn), &p2mt)); - if ( mfn_valid(_mfn(prev_mfn)) ) + prev_mfn =3D get_gfn(d, gfn_x(gpfn), &p2mt); + if ( mfn_valid(prev_mfn) ) { if ( is_xen_heap_mfn(prev_mfn) ) /* Xen heap frames are simply unhooked from this phys slot. */ - rc =3D guest_physmap_remove_page(d, gpfn, _mfn(prev_mfn), PAGE= _ORDER_4K); + rc =3D guest_physmap_remove_page(d, gpfn, prev_mfn, PAGE_ORDER= _4K); else /* Normal domain memory is freed, to avoid leaking memory. */ rc =3D guest_remove_page(d, gfn_x(gpfn)); diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 279278715e..e03f0ae630 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2970,7 +2970,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned lon= g fgfn, prev_mfn =3D get_gfn(tdom, gpfn, &p2mt_prev); if ( mfn_valid(prev_mfn) ) { - if ( is_xen_heap_mfn(mfn_x(prev_mfn)) ) + if ( is_xen_heap_mfn(prev_mfn) ) /* Xen heap frames are simply unhooked from this phys slot */ rc =3D guest_physmap_remove_page(tdom, _gfn(gpfn), prev_mfn, 0= ); else diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index 74681ba85c..26798b317c 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -559,7 +559,7 @@ _sh_propagate(struct vcpu *v, * caching attributes in the shadows to match what was asked for. */ if ( (level =3D=3D 1) && is_hvm_domain(d) && - !is_xen_heap_mfn(mfn_x(target_mfn)) ) + !is_xen_heap_mfn(target_mfn) ) { int type; =20 diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 71e24dbb2d..04c9dc0c65 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2104,9 +2104,9 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) * Yuk! Ensure there is a one-page buffer between Xen and Dom zones, to * prevent merging of power-of-two blocks across the zone boundary. */ - if ( ps && !is_xen_heap_mfn(paddr_to_pfn(ps)-1) ) + if ( ps && !is_xen_heap_mfn(mfn_add(maddr_to_mfn(ps), -1)) ) ps +=3D PAGE_SIZE; - if ( !is_xen_heap_mfn(paddr_to_pfn(pe)) ) + if ( !is_xen_heap_mfn(maddr_to_mfn(pe)) ) pe -=3D PAGE_SIZE; =20 memguard_guard_range(maddr_to_virt(ps), pe - ps); diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index b56018aace..a9c8352b94 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -138,16 +138,16 @@ extern vaddr_t xenheap_virt_start; #endif =20 #ifdef CONFIG_ARM_32 -#define is_xen_heap_page(page) is_xen_heap_mfn(mfn_x(page_to_mfn(page))) +#define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page)) #define is_xen_heap_mfn(mfn) ({ \ - unsigned long mfn_ =3D (mfn); \ + unsigned long mfn_ =3D mfn_x(mfn); \ (mfn_ >=3D mfn_x(xenheap_mfn_start) && \ mfn_ < mfn_x(xenheap_mfn_end)); \ }) #else #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap) #define is_xen_heap_mfn(mfn) \ - (mfn_valid(_mfn(mfn)) && is_xen_heap_page(mfn_to_page(_mfn(mfn)))) + (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn))) #endif =20 #define is_xen_fixed_mfn(mfn) \ @@ -246,7 +246,7 @@ static inline paddr_t __virt_to_maddr(vaddr_t va) #ifdef CONFIG_ARM_32 static inline void *maddr_to_virt(paddr_t ma) { - ASSERT(is_xen_heap_mfn(ma >> PAGE_SHIFT)); + ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma))); ma -=3D mfn_to_maddr(xenheap_mfn_start); return (void *)(unsigned long) ma + XENHEAP_VIRT_START; } diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 0d954e1bd8..e420d88137 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -278,7 +278,7 @@ struct page_info =20 #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap) #define is_xen_heap_mfn(mfn) \ - (__mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(_mfn(mfn)))) + (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn))) #define is_xen_fixed_mfn(mfn) \ (((mfn_to_maddr(mfn)) >=3D __pa(&_stext)) && \ ((mfn_to_maddr(mfn)) <=3D __pa(&__2M_rwdata_end))) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577925; cv=none; d=zoho.com; s=zohoarc; b=Ii3cwfEcYUs1H77Y8NwEhh6BBxdCCMPxlns6E2aUjISmRpMeFrbxpxuQ9zg10jiiho9XPWFEtuvjOD1uS0XGj9SbITGHO/KqsgAZtAmulAoTKq5ZPDTl+9Gd+IDifqe/LPfUc6FEcgC1b/yzk2nsrYU0M39+ypHtGdkC0jWiu5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577925; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WWBMozpCwcyQBKfLr9eAsodk8t8PhuTb6fE303dfXdU=; b=jj2bT8wzScesfXUx6Spko0lvlQPQ5Ab5R1LiLUuvcahUanxDtnyFhUEuy07MORIn3qJ0P/P4HJnzi8HtX+4xyvLeZwC0rt5krrX5M4u0ufoCa92KSBufqLYcYvX3ReaQiZBYpM88+xTIQRjelqvrBICwKkBRloqhH+O0bs19aME= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577925725388.8222918520481; Mon, 3 Jun 2019 09:05:25 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRZ-00022i-6T; Mon, 03 Jun 2019 16:04: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 1hXpRX-00021c-LF for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:15 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3b6717de-8619-11e9-8860-e3f31b8f3fad; Mon, 03 Jun 2019 16:04:14 +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 D36C680D; Mon, 3 Jun 2019 09:04:13 -0700 (PDT) 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 9C0A73F246; Mon, 3 Jun 2019 09:04:11 -0700 (PDT) X-Inumbo-ID: 3b6717de-8619-11e9-8860-e3f31b8f3fad From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:43 +0100 Message-Id: <20190603160350.29806-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 07/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call 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 , andrii_anisov@epam.com, Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , oleksandr_tyshchenko@epam.com, Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" While Arm never had a M2P, the implementation of mfn_to_gmfn is pretty bogus as we directly return the MFN passed in parameter. Thankfully, the use of mfn_to_gmfn is pretty limited on Arm today. There are only 3 callers: - iommu_hwdom_init: mfn_to_gmfn is used for creating IOMMU page-tables when the P2M is not shared with the IOMMU. No issues so far as Arm does not yet support non-shared P2M case. - memory_exchange: Arm cannot not use it because steal_page is not implemented. - getdomaininfo: Toolstack may map the shared page. It looks like this is mostly used for mapping the P2M of PV guest. Therefore the issue might be minor. Implementing the M2P on Arm is not planned. The M2P would require significa= nt amount of VA address (very tough on 32-bit) that can hardly be justified wi= th the current use of mfn_to_gmfn. - iommu_hwdom_init: mfn_to_gmfn is used because the creating of the IOMMU page-tables is delayed until the first device is assigned. In the embedded case, we will known in most of the times what devices are assigned during the domain creation. So it is possible to take to enable the IOMMU from start. See [1] for the patch. - memory_exchange: This does not work and I haven't seen any request for it so far. - getdomaininfo: The structure on Arm does not seem to contain a lot of useful information on Arm. It is unclear whether we want to allow the toolstack mapping it on Arm. This patch introduces a config option HAS_M2P to tell whether an architecture implements the M2P. - iommu_hwdom_init: For now, we require the M2P support when the IOMMU is not sharing the P2M. - memory_exchange: The hypercall is marked as not supported when the M2P does not exist. - getdomaininfo: A new helper is introduced to wrap the call to mfn_to_gfn/mfn_to_gmfn. For Arm, a fixed value will be provided that wi= ll fail on mapping if used. [1] https://patchwork.kernel.org/patch/9719913/ Signed-off-by Julien Grall --- Cc: oleksandr_tyshchenko@epam.com Cc: andrii_anisov@epam.com Changes in v3: - Move the BUG_ON() in domain_shared_info_gfn() - Use a fixed value when the field shared_info_frame is not supported. - Add an ASSERT_UNREACHABLE in iommu_hwdom_init + move printk within the #ifdef. Changes in v2: - Add a warning in public headers - Constify local variable in domain_shared_info_gfn - Invert the naming (_d / d) in domain_shared_info_gfn - Use -EOPNOTSUPP rather than -ENOSYS - Rework how the memory_exchange hypercall is removed from Arm --- xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 +++ xen/common/domctl.c | 9 +++++++-- xen/common/memory.c | 4 ++++ xen/drivers/passthrough/iommu.c | 8 +++++++- xen/include/asm-arm/domain.h | 5 +++++ xen/include/public/domctl.h | 6 ++++++ xen/include/xen/domain.h | 12 ++++++++++++ 8 files changed, 45 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index f502d765ba..c78eaf820a 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -17,6 +17,7 @@ config X86 select HAS_IOPORTS select HAS_KEXEC select MEM_ACCESS_ALWAYS_ON + select HAS_M2P select HAS_MEM_PAGING select HAS_MEM_SHARING select HAS_NS16550 diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 10a759b31f..aae4c93002 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -66,6 +66,9 @@ config HAS_GDBSX config HAS_IOPORTS bool =20 +config HAS_M2P + bool + config NEEDS_LIBELF bool =20 diff --git a/xen/common/domctl.c b/xen/common/domctl.c index bade9a63b1..5746daeb80 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -154,6 +154,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_= getdomaininfo *info) u64 cpu_time =3D 0; int flags =3D XEN_DOMINF_blocked; struct vcpu_runstate_info runstate; + gfn_t shared_info_frame; =20 info->domain =3D d->domain_id; info->max_vcpu_id =3D XEN_INVALID_MAX_VCPU_ID; @@ -205,8 +206,12 @@ void getdomaininfo(struct domain *d, struct xen_domctl= _getdomaininfo *info) info->outstanding_pages =3D d->outstanding_pages; info->shr_pages =3D atomic_read(&d->shr_pages); info->paged_pages =3D atomic_read(&d->paged_pages); - info->shared_info_frame =3D mfn_to_gmfn(d, virt_to_mfn(d->shared_info)= ); - BUG_ON(SHARED_M2P(info->shared_info_frame)); + + shared_info_frame =3D domain_shared_info_gfn(d); + if ( gfn_eq(shared_info_frame, INVALID_GFN) ) + info->shared_info_frame =3D XEN_INVALID_SHARED_INFO_FRAME; + else + info->shared_info_frame =3D gfn_x(shared_info_frame); =20 info->cpupool =3D d->cpupool ? d->cpupool->cpupool_id : CPUPOOLID_NONE; =20 diff --git a/xen/common/memory.c b/xen/common/memory.c index 520d6f4803..7a94250e50 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -504,6 +504,7 @@ static bool propagate_node(unsigned int xmf, unsigned i= nt *memflags) =20 static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) = arg) { +#ifdef CONFIG_M2P struct xen_memory_exchange exch; PAGE_LIST_HEAD(in_chunk_list); PAGE_LIST_HEAD(out_chunk_list); @@ -794,6 +795,9 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_= memory_exchange_t) arg) if ( __copy_field_to_guest(arg, &exch, nr_exchanged) ) rc =3D -EFAULT; return rc; +#else /* !CONFIG_M2P */ + return -EOPNOTSUPP; +#endif } =20 int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xat= p, diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 79ec6719f5..43174176c2 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) hd->need_sync =3D iommu_hwdom_strict && !iommu_use_hap_pt(d); if ( need_iommu_pt_sync(d) ) { + int rc =3D 0; +#ifdef CONFIG_HAS_M2P struct page_info *page; unsigned int i =3D 0, flush_flags =3D 0; - int rc =3D 0; =20 page_list_for_each ( page, &d->page_list ) { @@ -221,6 +222,11 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) if ( rc ) printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n", d->domain_id, rc); +#else + ASSERT_UNREACHABLE(); + rc =3D -EOPNOTSUPP; +#endif + } =20 hd->platform_ops->hwdom_init(d); diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 312fec8932..d61b0188da 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -267,6 +267,11 @@ static inline void free_vcpu_guest_context(struct vcpu= _guest_context *vgc) =20 static inline void arch_vcpu_block(struct vcpu *v) {} =20 +static inline gfn_t domain_shared_info_gfn(struct domain *d) +{ + return INVALID_GFN; +} + #endif /* __ASM_DOMAIN_H__ */ =20 /* diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 19486d5e32..9e9d28a8da 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -118,6 +118,12 @@ struct xen_domctl_getdomaininfo { uint64_aligned_t outstanding_pages; uint64_aligned_t shr_pages; uint64_aligned_t paged_pages; +#define XEN_INVALID_SHARED_INFO_FRAME (~(uint64_t)0) + /* + * GFN of shared_info struct. Some architectures (e.g Arm) may not + * provide a mappable address in the field. In that case, the field + * will be set to XEN_INVALID_SHARED_INFO_FRAME. + */ uint64_aligned_t shared_info_frame; /* GMFN of shared_info struct */ uint64_aligned_t cpu_time; uint32_t nr_online_vcpus; /* Number of VCPUs currently online. */ diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index d1bfc82f57..f5b9f3ef2a 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -118,4 +118,16 @@ struct vnuma_info { =20 void vnuma_destroy(struct vnuma_info *vnuma); =20 +#ifdef CONFIG_HAS_M2P +#define domain_shared_info_gfn(d) ({ \ + const struct domain *d_ =3D (d); \ + gfn_t gfn_; \ + \ + gfn_ =3D mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));\ + BUG_ON(SHARED_M2P(gfn_x(gfn_))); \ + \ + gfn_; \ +}) +#endif + #endif /* __XEN_DOMAIN_H__ */ --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577919; cv=none; d=zoho.com; s=zohoarc; b=PD5RK8JQnfg7F+ipixOdF1aZhk110zmIun7UwpYcRzUWmsg+s4tRUA94TJOyyAl9U27d8bC3v9doZ+flUhph9aVJS6MHJM2JzZ0H1jyPwdQpFVe1xXhfJhbmPJdH9i1aDZZJJB3PhGIE+IkKq8l/Nn/+nSnT2VH/n5uYKm0yMy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577919; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=W8dVUen859rvTnW85eLoUyZ3y5qV9X78UsQLAtY/K0g=; b=NUK21VKXRoeEBwIMI8P1+dXNqyjv4i2lPwZVcgrdgeZSCRXIIV/EnjbX/kaIwSyvKVbzUVzrTw/Biz/wCjEgYKDDBZTOd/VgoxUL09AGRtIi6eQC9daLCdhrZvFZrgM8f0Z7Qg/UDaVKgk9waG2IuXlgHcQ/rqywNF26Xy7cGLQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577919728919.82055251246; Mon, 3 Jun 2019 09:05:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRa-00024D-HX; Mon, 03 Jun 2019 16:04:18 +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 1hXpRY-00022Q-TZ for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:16 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3c5c76b6-8619-11e9-beeb-03b514b6ce83; Mon, 03 Jun 2019 16:04:15 +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 74798A78; Mon, 3 Jun 2019 09:04:15 -0700 (PDT) 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 1DDA33F246; Mon, 3 Jun 2019 09:04:13 -0700 (PDT) X-Inumbo-ID: 3c5c76b6-8619-11e9-beeb-03b514b6ce83 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:44 +0100 Message-Id: <20190603160350.29806-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 08/14] xen: Remove mfn_to_gmfn macro 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 , Wei Liu , Andrew Cooper , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On x86, mfn_to_gmfn can be replaced with mfn_to_gfn. On Arm, there are no more call to mfn_to_gmfn, so the helper can be dropped. At the same time rework a comment in Arm code that does not make sense. Signed-off-by: Julien Grall Acked-by: Jan Beulich Acked-by: Stefano Stabellini --- Changes in v2: - Add Jan's and Stefano's acked-by --- xen/drivers/passthrough/iommu.c | 7 +++---- xen/include/asm-arm/mm.h | 4 +--- xen/include/asm-x86/mm.h | 5 ----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 43174176c2..ad4309fde5 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -195,8 +195,8 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) =20 page_list_for_each ( page, &d->page_list ) { - unsigned long mfn =3D mfn_x(page_to_mfn(page)); - unsigned long dfn =3D mfn_to_gmfn(d, mfn); + mfn_t mfn =3D page_to_mfn(page); + dfn_t dfn =3D _dfn(gfn_x(mfn_to_gfn(d, mfn))); unsigned int mapping =3D IOMMUF_readable; int ret; =20 @@ -205,8 +205,7 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) =3D=3D PGT_writable_page) ) mapping |=3D IOMMUF_writable; =20 - ret =3D iommu_map(d, _dfn(dfn), _mfn(mfn), 0, mapping, - &flush_flags); + ret =3D iommu_map(d, dfn, mfn, 0, mapping, &flush_flags); =20 if ( !rc ) rc =3D ret; diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index a9c8352b94..a9cb98a6c7 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -321,10 +321,8 @@ struct page_info *get_page_from_gva(struct vcpu *v, va= ddr_t va, #define SHARED_M2P_ENTRY (~0UL - 1UL) #define SHARED_M2P(_e) ((_e) =3D=3D SHARED_M2P_ENTRY) =20 -/* Xen always owns P2M on ARM */ +/* We don't have a M2P on Arm */ #define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } whil= e (0) -#define mfn_to_gmfn(_d, mfn) (mfn) - =20 /* Arch-specific portion of memory_op hypercall. */ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg); diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index e420d88137..bf90916077 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -506,11 +506,6 @@ extern struct rangeset *mmio_ro_ranges; =20 #define get_gpfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)]) =20 -#define mfn_to_gmfn(_d, mfn) \ - ( (paging_mode_translate(_d)) \ - ? get_gpfn_from_mfn(mfn) \ - : (mfn) ) - #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn)= >> 20)) #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3)= << 20)) =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577924; cv=none; d=zoho.com; s=zohoarc; b=bGDGC463UOCnbddMk2i+sjjwHUQTHQ/qfn16pE+t33YX/DP7sSiyTqaNuhHIRxaT+AegA4txSK57I7jELgPTIxmtRVdIm2hGBekphaSo1ycm7YCODfrYIylamxSBgFtMetlsGp8XRkQGLQsRyPWbpbbq5iGju1DQ37vRz/5Xtac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577924; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=x66YXEVOIcYvY2UITycn9C0LDz/k+UOiu+j3wTMr+jY=; b=QWOg7LqhQQyG10ZTJt2FRc87SZvSaloDc84VGy9RcGKjrr4aXov0rsHnR97p7t9zhopuM/xmAiA+Ls5/4s17W5RTmxZwh+ZDc0KGBuP2l3xtPDO4/MaXPmdbAVGJs0AhXsM1cMBLeCzmuoinriCJVzsg1sHL+XftClAV//2vPaY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577924321730.0306932841853; Mon, 3 Jun 2019 09:05:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRb-00025f-SM; Mon, 03 Jun 2019 16:04:19 +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 1hXpRa-00023a-6c for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:18 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3d3ae388-8619-11e9-8d3d-37e54aa2a50d; Mon, 03 Jun 2019 16:04:17 +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 E47A015AB; Mon, 3 Jun 2019 09:04:16 -0700 (PDT) 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 B187C3F246; Mon, 3 Jun 2019 09:04:15 -0700 (PDT) X-Inumbo-ID: 3d3ae388-8619-11e9-8d3d-37e54aa2a50d From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:45 +0100 Message-Id: <20190603160350.29806-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 09/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function 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: Andrew Cooper , Julien Grall , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" set_gpfn_from_mfn() is currently implement in a 2 part macros. The second macro is only called within the first macro, so they can be folded together. Furthermore, this is now converted to a static inline making the code more readable and safer. As set_gpfn_from_mfn is now a static inline function, the extern variable dom_cow should be defined earlier on. For convenience, the definition of all dom_* variables are moved earlier on. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich --- Changes in v3: - Add missing blank - Fix condition Changes in v2: - Patch added --- xen/include/asm-x86/mm.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index bf90916077..dcae558764 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -442,6 +442,8 @@ int check_descriptor(const struct domain *d, seg_desc_t= *desc); =20 extern paddr_t mem_hotplug; =20 +extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ + /*************************************************************************= ***** * With shadow pagetables, the different kinds of address start * to get get confusing. @@ -483,24 +485,25 @@ extern paddr_t mem_hotplug; #define SHARED_M2P(_e) ((_e) =3D=3D SHARED_M2P_ENTRY) =20 #define compat_machine_to_phys_mapping ((unsigned int *)RDWR_COMPAT_MPT_VI= RT_START) -#define _set_gpfn_from_mfn(mfn, pfn) ({ \ - struct domain *d =3D page_get_owner(mfn_to_page(_mfn(mfn))); \ - unsigned long entry =3D (d && (d =3D=3D dom_cow)) ? \ - SHARED_M2P_ENTRY : (pfn); \ - ((void)((mfn) >=3D (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_ST= ART) / 4 || \ - (compat_machine_to_phys_mapping[(mfn)] =3D (unsigned int)(entr= y))), \ - machine_to_phys_mapping[(mfn)] =3D (entry)); \ - }) =20 /* * Disable some users of set_gpfn_from_mfn() (e.g., free_heap_pages()) unt= il * the machine_to_phys_mapping is actually set up. */ extern bool machine_to_phys_mapping_valid; -#define set_gpfn_from_mfn(mfn, pfn) do { \ - if ( machine_to_phys_mapping_valid ) \ - _set_gpfn_from_mfn(mfn, pfn); \ -} while (0) + +static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) +{ + struct domain *d =3D page_get_owner(mfn_to_page(_mfn(mfn))); + unsigned long entry =3D (d && (d =3D=3D dom_cow)) ? SHARED_M2P_ENTRY := pfn; + + if ( !machine_to_phys_mapping_valid ) + return; + + if ( mfn < (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4= ) + compat_machine_to_phys_mapping[mfn] =3D entry; + machine_to_phys_mapping[mfn] =3D entry; +} =20 extern struct rangeset *mmio_ro_ranges; =20 @@ -590,8 +593,6 @@ unsigned int domain_clamp_alloc_bitsize(struct domain *= d, unsigned int bits); =20 unsigned long domain_get_maximum_gpfn(struct domain *d); =20 -extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ - /* Definition of an mm lock: spinlock with extra fields for debugging */ typedef struct mm_lock { spinlock_t lock; --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577925; cv=none; d=zoho.com; s=zohoarc; b=lIR0boJ2hGyb1S/NyB/q16KDyPQ9THKAVJ1ukWal52UiMWe1olTxWkwK7hEQ/wRKIHEVwW4NHXNLwIxI1PaIGlQUH/+4nRT6jGpVP0WN4QTMkhRXOAfShK+H1Scb93hb9uF+ol3JOjWkUWdjVS5Ozo6I1A94NfAOrljQT2LktIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577925; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=JHh0TRZTbaRDkM+j3b1WC/h0J7CbxPGU+cSRuQlSb8Y=; b=APDbgKjPo0W/+qLIHKrRXXCBlWuP2+AhJvYd0ETqbTot5RCJwDpN7Gy95nbaayq6nJe5Hv7YLvdSHocqIoyeU9IAdCH+VIl7VdJnpmV2d9JOnceIc3DB0v+EfmaPC9Tj9J8//jGGnHl+8NLePCttATh94oRMZ+mFxIoMCRKaS/c= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577925497196.2374380946511; Mon, 3 Jun 2019 09:05:25 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRc-00026W-DX; Mon, 03 Jun 2019 16:04:20 +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 1hXpRb-000257-EX for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:19 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3e13eb24-8619-11e9-aa0b-8bfb69120422; Mon, 03 Jun 2019 16:04:18 +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 60C2A80D; Mon, 3 Jun 2019 09:04:18 -0700 (PDT) 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 2DE553F246; Mon, 3 Jun 2019 09:04:17 -0700 (PDT) X-Inumbo-ID: 3e13eb24-8619-11e9-aa0b-8bfb69120422 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:46 +0100 Message-Id: <20190603160350.29806-11-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 10/14] xen/x86: pv: Convert update_intpte() to use typesafe MFN 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: Andrew Cooper , Julien Grall , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The third parameter of update_intpte() is a MFN, so it can be switched to use the typesafe. At the same time, the typesafe is propagated as far as possible without major modifications. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich --- Changes in v3: - Remove stray change in mod_l1_entry() - Remove stray parentheses in do_mmu_update() - Re-flow update_intpte() prototype - Add Jan's reviewed-by Changes in v2: - Patch added --- xen/arch/x86/mm.c | 80 ++++++++++++++++++++-----------------= ---- xen/arch/x86/pv/grant_table.c | 6 ++-- xen/arch/x86/pv/mm.h | 7 ++-- xen/arch/x86/pv/ro-page-fault.c | 2 +- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 3d3d8bd7a8..3bb12782a1 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2078,7 +2078,7 @@ void page_unlock(struct page_info *page) =20 /* Update the L1 entry at pl1e to new value nl1e. */ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, - unsigned long gl1mfn, unsigned int cmd, + mfn_t gl1mfn, unsigned int cmd, struct vcpu *pt_vcpu, struct domain *pg_dom) { bool preserve_ad =3D (cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD); @@ -2186,16 +2186,16 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgen= try_t nl1e, } =20 =20 -/* Update the L2 entry at pl2e to new value nl2e. pl2e is within frame pfn= . */ +/* Update the L2 entry at pl2e to new value nl2e. pl2e is within frame mfn= . */ static int mod_l2_entry(l2_pgentry_t *pl2e, l2_pgentry_t nl2e, - unsigned long pfn, + mfn_t mfn, int preserve_ad, struct vcpu *vcpu) { l2_pgentry_t ol2e; struct domain *d =3D vcpu->domain; - struct page_info *l2pg =3D mfn_to_page(_mfn(pfn)); + struct page_info *l2pg =3D mfn_to_page(mfn); unsigned long type =3D l2pg->u.inuse.type_info; int rc =3D 0; =20 @@ -2222,16 +2222,16 @@ static int mod_l2_entry(l2_pgentry_t *pl2e, if ( !l2e_has_changed(ol2e, nl2e, ~FASTPATH_FLAG_WHITELIST) ) { nl2e =3D adjust_guest_l2e(nl2e, d); - if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, preserve_ad= ) ) + if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu, preserve_ad= ) ) return 0; return -EBUSY; } =20 - if ( unlikely((rc =3D get_page_from_l2e(nl2e, pfn, d, 0)) < 0) ) + if ( unlikely((rc =3D get_page_from_l2e(nl2e, mfn_x(mfn), d, 0)) <= 0) ) return rc; =20 nl2e =3D adjust_guest_l2e(nl2e, d); - if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, + if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu, preserve_ad)) ) { ol2e =3D nl2e; @@ -2240,21 +2240,21 @@ static int mod_l2_entry(l2_pgentry_t *pl2e, } else if ( pv_l1tf_check_l2e(d, nl2e) ) return -ERESTART; - else if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, + else if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu, preserve_ad)) ) { return -EBUSY; } =20 - put_page_from_l2e(ol2e, pfn, 0, true); + put_page_from_l2e(ol2e, mfn_x(mfn), 0, true); =20 return rc; } =20 -/* Update the L3 entry at pl3e to new value nl3e. pl3e is within frame pfn= . */ +/* Update the L3 entry at pl3e to new value nl3e. pl3e is within frame mfn= . */ static int mod_l3_entry(l3_pgentry_t *pl3e, l3_pgentry_t nl3e, - unsigned long pfn, + mfn_t mfn, int preserve_ad, struct vcpu *vcpu) { @@ -2285,17 +2285,17 @@ static int mod_l3_entry(l3_pgentry_t *pl3e, if ( !l3e_has_changed(ol3e, nl3e, ~FASTPATH_FLAG_WHITELIST) ) { nl3e =3D adjust_guest_l3e(nl3e, d); - rc =3D UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu, preserve_= ad); + rc =3D UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu, preserve_= ad); return rc ? 0 : -EFAULT; } =20 - rc =3D get_page_from_l3e(nl3e, pfn, d, 0); + rc =3D get_page_from_l3e(nl3e, mfn_x(mfn), d, 0); if ( unlikely(rc < 0) ) return rc; rc =3D 0; =20 nl3e =3D adjust_guest_l3e(nl3e, d); - if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu, + if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu, preserve_ad)) ) { ol3e =3D nl3e; @@ -2304,7 +2304,7 @@ static int mod_l3_entry(l3_pgentry_t *pl3e, } else if ( pv_l1tf_check_l3e(d, nl3e) ) return -ERESTART; - else if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu, + else if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu, preserve_ad)) ) { return -EFAULT; @@ -2314,14 +2314,14 @@ static int mod_l3_entry(l3_pgentry_t *pl3e, if ( !create_pae_xen_mappings(d, pl3e) ) BUG(); =20 - put_page_from_l3e(ol3e, pfn, 0, 1); + put_page_from_l3e(ol3e, mfn_x(mfn), 0, 1); return rc; } =20 -/* Update the L4 entry at pl4e to new value nl4e. pl4e is within frame pfn= . */ +/* Update the L4 entry at pl4e to new value nl4e. pl4e is within frame mfn= . */ static int mod_l4_entry(l4_pgentry_t *pl4e, l4_pgentry_t nl4e, - unsigned long pfn, + mfn_t mfn, int preserve_ad, struct vcpu *vcpu) { @@ -2352,17 +2352,17 @@ static int mod_l4_entry(l4_pgentry_t *pl4e, if ( !l4e_has_changed(ol4e, nl4e, ~FASTPATH_FLAG_WHITELIST) ) { nl4e =3D adjust_guest_l4e(nl4e, d); - rc =3D UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu, preserve_= ad); + rc =3D UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu, preserve_= ad); return rc ? 0 : -EFAULT; } =20 - rc =3D get_page_from_l4e(nl4e, pfn, d, 0); + rc =3D get_page_from_l4e(nl4e, mfn_x(mfn), d, 0); if ( unlikely(rc < 0) ) return rc; rc =3D 0; =20 nl4e =3D adjust_guest_l4e(nl4e, d); - if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu, + if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu, preserve_ad)) ) { ol4e =3D nl4e; @@ -2371,13 +2371,13 @@ static int mod_l4_entry(l4_pgentry_t *pl4e, } else if ( pv_l1tf_check_l4e(d, nl4e) ) return -ERESTART; - else if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu, + else if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu, preserve_ad)) ) { return -EFAULT; } =20 - put_page_from_l4e(ol4e, pfn, 0, 1); + put_page_from_l4e(ol4e, mfn_x(mfn), 0, 1); return rc; } #endif /* CONFIG_PV */ @@ -3079,7 +3079,7 @@ int new_guest_cr3(mfn_t mfn) l4e_from_mfn(mfn, (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)), - mfn_x(gt_mfn), 0, curr); + gt_mfn, 0, curr); unmap_domain_page(pl4e); switch ( rc ) { @@ -3748,12 +3748,12 @@ long do_mmu_update( { struct mmu_update req; void *va =3D NULL; - unsigned long gpfn, gmfn, mfn; + unsigned long gpfn, gmfn; struct page_info *page; unsigned int cmd, i =3D 0, done =3D 0, pt_dom; struct vcpu *curr =3D current, *v =3D curr; struct domain *d =3D v->domain, *pt_owner =3D d, *pg_owner; - mfn_t map_mfn =3D INVALID_MFN; + mfn_t map_mfn =3D INVALID_MFN, mfn; bool sync_guest =3D false; uint32_t xsm_needed =3D 0; uint32_t xsm_checked =3D 0; @@ -3879,14 +3879,14 @@ long do_mmu_update( break; } =20 - mfn =3D mfn_x(page_to_mfn(page)); + mfn =3D page_to_mfn(page); =20 - if ( !mfn_eq(_mfn(mfn), map_mfn) ) + if ( !mfn_eq(mfn, map_mfn) ) { if ( va ) unmap_domain_page(va); - va =3D map_domain_page(_mfn(mfn)); - map_mfn =3D _mfn(mfn); + va =3D map_domain_page(mfn); + map_mfn =3D mfn; } va =3D _p(((unsigned long)va & PAGE_MASK) + (req.ptr & ~PAGE_M= ASK)); =20 @@ -3922,7 +3922,8 @@ long do_mmu_update( { bool local_in_use =3D false; =20 - if ( pagetable_get_pfn(curr->arch.guest_table) =3D= =3D mfn ) + if ( mfn_eq(pagetable_get_mfn(curr->arch.guest_tab= le), + mfn) ) { local_in_use =3D true; get_cpu_info()->root_pgt_changed =3D true; @@ -3935,15 +3936,15 @@ long do_mmu_update( */ if ( (page->u.inuse.type_info & PGT_count_mask) > (1 + !!(page->u.inuse.type_info & PGT_pinned)= + - (pagetable_get_pfn(curr->arch.guest_table_us= er) =3D=3D - mfn) + local_in_use) ) + mfn_eq(pagetable_get_mfn(curr->arch.guest_ta= ble_user), + mfn) + local_in_use) ) sync_guest =3D true; } break; =20 case PGT_writable_page: perfc_incr(writable_mmu_updates); - if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn= )) ) + if ( paging_write_guest_entry(v, va, req.val, mfn) ) rc =3D 0; break; } @@ -3954,7 +3955,7 @@ long do_mmu_update( else if ( get_page_type(page, PGT_writable_page) ) { perfc_incr(writable_mmu_updates); - if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn)) ) + if ( paging_write_guest_entry(v, va, req.val, mfn) ) rc =3D 0; put_page_type(page); } @@ -3976,7 +3977,7 @@ long do_mmu_update( break; } =20 - mfn =3D req.ptr >> PAGE_SHIFT; + mfn =3D maddr_to_mfn(req.ptr); gpfn =3D req.val; =20 xsm_needed |=3D XSM_MMU_MACHPHYS_UPDATE; @@ -3988,7 +3989,7 @@ long do_mmu_update( xsm_checked =3D xsm_needed; } =20 - page =3D get_page_from_mfn(_mfn(mfn), pg_owner); + page =3D get_page_from_mfn(mfn, pg_owner); if ( unlikely(!page) ) { gdprintk(XENLOG_WARNING, @@ -3997,7 +3998,7 @@ long do_mmu_update( break; } =20 - set_gpfn_from_mfn(mfn, gpfn); + set_gpfn_from_mfn(mfn_x(mfn), gpfn); paging_mark_pfn_dirty(pg_owner, _pfn(gpfn)); =20 put_page(page); @@ -4253,8 +4254,7 @@ static int __do_update_va_mapping( goto out; } =20 - rc =3D mod_l1_entry(pl1e, val, mfn_x(gl1mfn), MMU_NORMAL_PT_UPDATE, v, - pg_owner); + rc =3D mod_l1_entry(pl1e, val, gl1mfn, MMU_NORMAL_PT_UPDATE, v, pg_own= er); =20 page_unlock(gl1pg); put_page(gl1pg); diff --git a/xen/arch/x86/pv/grant_table.c b/xen/arch/x86/pv/grant_table.c index 5180334f42..0325618c98 100644 --- a/xen/arch/x86/pv/grant_table.c +++ b/xen/arch/x86/pv/grant_table.c @@ -108,7 +108,7 @@ int create_grant_pv_mapping(uint64_t addr, mfn_t frame, goto out_unlock; =20 ol1e =3D *pl1e; - if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(gl1mfn), curr, 0) ) + if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, curr, 0) ) rc =3D GNTST_okay; =20 out_unlock: @@ -165,7 +165,7 @@ static bool steal_linear_address(unsigned long linear, = l1_pgentry_t *out) goto out_unlock; =20 ol1e =3D *pl1e; - okay =3D UPDATE_ENTRY(l1, pl1e, ol1e, l1e_empty(), mfn_x(gl1mfn), curr= , 0); + okay =3D UPDATE_ENTRY(l1, pl1e, ol1e, l1e_empty(), gl1mfn, curr, 0); =20 if ( okay ) *out =3D ol1e; @@ -293,7 +293,7 @@ int replace_grant_pv_mapping(uint64_t addr, mfn_t frame, "PTE flags %x for %"PRIx64" don't match grant (%x)\n", l1e_get_flags(ol1e), addr, grant_pte_flags); =20 - if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(gl1mfn), curr, 0) ) + if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, curr, 0) ) rc =3D GNTST_okay; =20 out_unlock: diff --git a/xen/arch/x86/pv/mm.h b/xen/arch/x86/pv/mm.h index 976209ba4c..2d427b418d 100644 --- a/xen/arch/x86/pv/mm.h +++ b/xen/arch/x86/pv/mm.h @@ -37,15 +37,14 @@ static inline l1_pgentry_t guest_get_eff_l1e(unsigned l= ong linear) * Returns false for failure (pointer not valid), true for success. */ static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new, - unsigned long mfn, struct vcpu *v, - bool preserve_ad) + mfn_t mfn, struct vcpu *v, bool preserve_= ad) { bool rv =3D true; =20 #ifndef PTE_UPDATE_WITH_CMPXCHG if ( !preserve_ad ) { - rv =3D paging_write_guest_entry(v, p, new, _mfn(mfn)); + rv =3D paging_write_guest_entry(v, p, new, mfn); } else #endif @@ -59,7 +58,7 @@ static inline bool update_intpte(intpte_t *p, intpte_t ol= d, intpte_t new, if ( preserve_ad ) _new |=3D old & (_PAGE_ACCESSED | _PAGE_DIRTY); =20 - rv =3D paging_cmpxchg_guest_entry(v, p, &t, _new, _mfn(mfn)); + rv =3D paging_cmpxchg_guest_entry(v, p, &t, _new, mfn); if ( unlikely(rv =3D=3D 0) ) { gdprintk(XENLOG_WARNING, diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-faul= t.c index fa358a62e7..a920fb5e15 100644 --- a/xen/arch/x86/pv/ro-page-fault.c +++ b/xen/arch/x86/pv/ro-page-fault.c @@ -197,7 +197,7 @@ static int ptwr_emulated_update(unsigned long addr, int= pte_t *p_old, else { ol1e =3D *pl1e; - if ( !UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(mfn), v, 0) ) + if ( !UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn, v, 0) ) BUG(); } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577919; cv=none; d=zoho.com; s=zohoarc; b=To3lJ2dKshC0/aZYTWJ+m+2XbxyfTtJdOyXOIe2twL8K5d4/kHZxJqkNF0YZYoD1AVNVuttXSWfvGVmmQizaH0tGrHKFdrDo5630JThn/lM1ly/SHRyvI45F1fEAPUZCddiyH48whoXCvS82vzqQPaqigj/9mp2Ufgg9TEpTRtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577919; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=msWBYayx3x8aN1jrN1e+Vjbza5UY1Xdfts352ZyLccw=; b=dNepHGmZhyY58fJ6ockSGRzspJFK6TwXSKOEgntrTAX6FIhBt2A28i7Ohnw0/s2OQ6/FEfitqvVDnz1o5tYYmwlU3bZbHJ7FstTgmTU+gIU2Daaf8Mdq1H5wgVjMaky+TdUmkSc7Ag3ocYq6QPAw0D74fgV4uNmN48cyzhTPWjE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577919703479.0762165747701; Mon, 3 Jun 2019 09:05:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRe-00028z-77; Mon, 03 Jun 2019 16:04:22 +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 1hXpRd-00028P-MD for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:21 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3f1a3a0a-8619-11e9-8e8e-7fb61b469f17; Mon, 03 Jun 2019 16:04:20 +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 021F6A78; Mon, 3 Jun 2019 09:04:20 -0700 (PDT) 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 9E0273F246; Mon, 3 Jun 2019 09:04:18 -0700 (PDT) X-Inumbo-ID: 3f1a3a0a-8619-11e9-8e8e-7fb61b469f17 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:47 +0100 Message-Id: <20190603160350.29806-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 11/14] xen/x86: p2m: Remove duplicate error message in p2m_pt_audit_p2m() 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 , George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" p2m_pt_audit_p2m() has one place where the same message may be printed twice via printk and P2M_PRINTK. Remove the one printed using printk to stay consistent with the rest of the code. Take the opportunity to reflow the format of P2M_PRINTK. Signed-off-by: Julien Grall --- Changes in v3: - Patch added --- xen/arch/x86/mm/p2m-pt.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index cafc9f299b..84ddc1834b 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -1041,9 +1041,8 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m) if ( m2pfn !=3D (gfn + i2) ) { pmbad++; - P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx" - " -> gfn %#lx\n", gfn+i2, mfn+i2, - m2pfn); + P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx -> = gfn %#lx\n", + gfn + i2, mfn + i2, m2pfn); BUG(); } gfn +=3D 1 << (L3_PAGETABLE_SHIFT - PAGE_SHIFT); @@ -1108,8 +1107,6 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m) !p2m_is_shared(type) ) { pmbad++; - printk("mismatch: gfn %#lx -> mfn %#lx" - " -> gfn %#lx\n", gfn, mfn, m2pfn); P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx" " -> gfn %#lx\n", gfn, mfn, m2pfn); BUG(); --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577938; cv=none; d=zoho.com; s=zohoarc; b=dR89FLXgYclkTInImpTvvnovgYHMsCed+r5TimFnrw5sOBaUQL0nZ5AufDzUlheVIxmVrcgHXPQhrlDs/wRO1yzFX59Y4/rXwOOEfPxwJQ6HdMX+nOpnZWSgtbm33qS1klQS0nGVbU9Iqyh8saevGYZWbEjENd7f3eKuGKdhkj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577938; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=UbgWjUOcZRkbUW+pWRGSAFnc4ffbKls3VPptBlWvyPE=; b=mhLutcUi6ZQ43S52kStVIGGffHxoOVINUobssQoCKc0kfgxp41H0N0uvlHg06hMS4x9R9r7iuna/OgSQ9fqchf3VtslRGrKDEEP7MOyIvrKUUNjaxc2LPJdNXaPvHZhF5zhltD1P2QRsyqS11xmuhluxnsImHJjQy4YBgqfusg0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577938307679.2745083667991; Mon, 3 Jun 2019 09:05:38 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRg-0002Bk-J3; Mon, 03 Jun 2019 16:04:24 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRf-0002A3-0D for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:23 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3ffb4560-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04:21 +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 9476380D; Mon, 3 Jun 2019 09:04:21 -0700 (PDT) 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 3DF273F246; Mon, 3 Jun 2019 09:04:20 -0700 (PDT) X-Inumbo-ID: 3ffb4560-8619-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:48 +0100 Message-Id: <20190603160350.29806-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 12/14] xen/x86: p2m: Rework printk format in audit_p2m() 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 , George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" One of the printk format in audit_p2m() may be difficult to read as it is not clear what is the first number. Furthermore, the format can now take advantage of %pd. Signed-off-by: Julien Grall --- Changes in v3: - Patch added --- xen/arch/x86/mm/p2m.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index e03f0ae630..208c196667 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2838,8 +2838,7 @@ void audit_p2m(struct domain *d, =20 if ( od !=3D d ) { - P2M_PRINTK("wrong owner %#lx -> %p(%u) !=3D %p(%u)\n", - mfn, od, (od?od->domain_id:-1), d, d->domain_id); + P2M_PRINTK("mfn %"PRI_mfn" owner %pd !=3D %pd\n", mfn, od, d); continue; } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577948; cv=none; d=zoho.com; s=zohoarc; b=XCnejbN3gmvXIrUGcUiECnvH4MxANpWLCC+wuPV5+Y/SiEuh3KB5k/tUIPYp44zD941oiVA8Y64fLoOJwdlBR+e8PcA5iphyda0AVOk7oAcMkSPlK1dxzj2hgOWRTAt6mhlp1IkUb+Mb1T6H+Ty0XVzYwAVHstqzgjfVShCgZqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577948; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=l89rvGfuQbIfL4U8/ss0hPMlsH+1TRIAH+Ny6Fk/IfQ=; b=C04KYnDefyfV9F5oOVi0sl53YAshkK/um1GIG0KFyZ3ItGduMqXN6ovDpLq7c8nnjNcVuVxPkJoUllEWi11J7/b+j2s9PGFbjSir29tDw6UPG3Nzm4t/mVOHgtsiS1AmSh6ei31geyae+Q0A1idqBsnt7xmKR0Y6JQ0IBSkNYPc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559577948467761.5954191296486; Mon, 3 Jun 2019 09:05:48 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRj-0002FT-V4; Mon, 03 Jun 2019 16:04:27 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRi-0002Dj-HD for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:26 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 4172eec2-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04:24 +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 16852A78; Mon, 3 Jun 2019 09:04:24 -0700 (PDT) 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 D344E3F246; Mon, 3 Jun 2019 09:04:21 -0700 (PDT) X-Inumbo-ID: 4172eec2-8619-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:49 +0100 Message-Id: <20190603160350.29806-14-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN 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 , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Tamas K Lengyel , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The first parameter of {s,g}et_gpfn_from_mfn() is an MFN, so it can be switched to use the typesafe. At the same time, replace gpfn with pfn in the helpers as they all deal with PFN and also turn the macros to static inline. Note that the return of the getter and the 2nd parameter of the setter have not been converted to use typesafe PFN because it was requiring more changes than expected. Signed-off-by: Julien Grall Acked-by: Tamas K Lengyel Acked-by: Stefano Stabellini --- Changes in v3: - Add Tamas's acked-by for mem_sharing bits - Add Stefano's acked-by - Fix coding style in the declaration of mem_sharing_lookup() --- xen/arch/x86/cpu/mcheck/mcaction.c | 2 +- xen/arch/x86/mm.c | 14 ++++---- xen/arch/x86/mm/mem_sharing.c | 19 +++++------ xen/arch/x86/mm/p2m-pod.c | 4 +-- xen/arch/x86/mm/p2m-pt.c | 34 +++++++++++--------- xen/arch/x86/mm/p2m.c | 66 +++++++++++++++++++---------------= ---- xen/arch/x86/mm/paging.c | 4 +-- xen/arch/x86/pv/dom0_build.c | 6 ++-- xen/arch/x86/x86_64/traps.c | 41 +++++++++++------------ xen/common/page_alloc.c | 2 +- xen/include/asm-arm/mm.h | 2 +- xen/include/asm-x86/grant_table.h | 2 +- xen/include/asm-x86/mm.h | 16 +++++---- xen/include/asm-x86/p2m.h | 2 +- 14 files changed, 111 insertions(+), 103 deletions(-) diff --git a/xen/arch/x86/cpu/mcheck/mcaction.c b/xen/arch/x86/cpu/mcheck/m= caction.c index 69332fb84d..5e78fb7703 100644 --- a/xen/arch/x86/cpu/mcheck/mcaction.c +++ b/xen/arch/x86/cpu/mcheck/mcaction.c @@ -89,7 +89,7 @@ mc_memerr_dhandler(struct mca_binfo *binfo, { d =3D get_domain_by_id(bank->mc_domid); ASSERT(d); - gfn =3D get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT); + gfn =3D get_pfn_from_mfn(maddr_to_mfn(bank->mc_addr)); =20 if ( unmmap_broken_page(d, mfn, gfn) ) { diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 3bb12782a1..83e0f0fb6b 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -500,7 +500,7 @@ void share_xen_page_with_guest(struct page_info *page, = struct domain *d, if ( page_get_owner(page) =3D=3D d ) return; =20 - set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), INVALID_M2P_ENTRY); + set_pfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY); =20 spin_lock(&d->page_alloc_lock); =20 @@ -1075,7 +1075,7 @@ get_page_from_l1e( =20 gdprintk(XENLOG_WARNING, "Error updating mappings for mfn %" P= RI_mfn " (pfn %" PRI_pfn ", from L1 entry %" PRIpte ") for d= %d\n", - mfn, get_gpfn_from_mfn(mfn), + mfn, get_pfn_from_mfn(_mfn(mfn)), l1e_get_intpte(l1e), l1e_owner->domain_id); return err; } @@ -1086,7 +1086,7 @@ get_page_from_l1e( could_not_pin: gdprintk(XENLOG_WARNING, "Error getting mfn %" PRI_mfn " (pfn %" PRI_p= fn ") from L1 entry %" PRIpte " for l1e_owner d%d, pg_owner d%d\= n", - mfn, get_gpfn_from_mfn(mfn), + mfn, get_pfn_from_mfn(_mfn(mfn)), l1e_get_intpte(l1e), l1e_owner->domain_id, pg_owner->domain_i= d); if ( real_pg_owner !=3D NULL ) put_page(page); @@ -2602,7 +2602,7 @@ static int alloc_page_type(struct page_info *page, un= signed long type, " (pfn %" PRI_pfn ") for type %" PRtype_info ": caf=3D%08lx taf=3D%" PRtype_info "\n", mfn_x(page_to_mfn(page)), - get_gpfn_from_mfn(mfn_x(page_to_mfn(page))), + get_pfn_from_mfn(page_to_mfn(page)), type, page->count_info, page->u.inuse.type_info); if ( page !=3D current->arch.old_guest_table ) page->u.inuse.type_info =3D 0; @@ -2886,7 +2886,7 @@ static int _get_page_type(struct page_info *page, uns= igned long type, "Bad type (saw %" PRtype_info " !=3D exp %" PRtype_in= fo ") " "for mfn %" PRI_mfn " (pfn %" PRI_pfn ")\n", x, type, mfn_x(page_to_mfn(page)), - get_gpfn_from_mfn(mfn_x(page_to_mfn(page)))); + get_pfn_from_mfn(page_to_mfn(page))); return -EINVAL; } else if ( unlikely(!(x & PGT_validated)) ) @@ -3998,7 +3998,7 @@ long do_mmu_update( break; } =20 - set_gpfn_from_mfn(mfn_x(mfn), gpfn); + set_pfn_from_mfn(mfn, gpfn); paging_mark_pfn_dirty(pg_owner, _pfn(gpfn)); =20 put_page(page); @@ -4522,7 +4522,7 @@ int xenmem_add_to_physmap_one( goto put_both; =20 /* Unmap from old location, if any. */ - old_gpfn =3D get_gpfn_from_mfn(mfn_x(mfn)); + old_gpfn =3D get_pfn_from_mfn(mfn); ASSERT(!SHARED_M2P(old_gpfn)); if ( space =3D=3D XENMAPSPACE_gmfn && old_gpfn !=3D gfn ) { diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index f16a3f5324..fc1fb6fe89 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -391,11 +391,12 @@ static inline void mem_sharing_gfn_destroy(struct pag= e_info *page, xfree(gfn_info); } =20 -static struct page_info* mem_sharing_lookup(unsigned long mfn) +static struct page_info *mem_sharing_lookup(mfn_t mfn) { - if ( mfn_valid(_mfn(mfn)) ) + if ( mfn_valid(mfn) ) { - struct page_info* page =3D mfn_to_page(_mfn(mfn)); + struct page_info* page =3D mfn_to_page(mfn); + if ( page_get_owner(page) =3D=3D dom_cow ) { /* Count has to be at least two, because we're called @@ -404,7 +405,7 @@ static struct page_info* mem_sharing_lookup(unsigned lo= ng mfn) unsigned long t =3D read_atomic(&page->u.inuse.type_info); ASSERT((t & PGT_type_mask) =3D=3D PGT_shared_page); ASSERT((t & PGT_count_mask) >=3D 2); - ASSERT(SHARED_M2P(get_gpfn_from_mfn(mfn))); + ASSERT(SHARED_M2P(get_pfn_from_mfn(mfn))); return page; } } @@ -464,10 +465,10 @@ static int audit(void) } =20 /* Check the m2p entry */ - if ( !SHARED_M2P(get_gpfn_from_mfn(mfn_x(mfn))) ) + if ( !SHARED_M2P(get_pfn_from_mfn(mfn)) ) { MEM_SHARING_DEBUG("mfn %lx shared, but wrong m2p entry (%lx)!\n= ", - mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn))); + mfn_x(mfn), get_pfn_from_mfn(mfn)); errors++; } =20 @@ -693,7 +694,7 @@ static inline struct page_info *__grab_shared_page(mfn_= t mfn) if ( !mem_sharing_page_lock(pg) ) return NULL; =20 - if ( mem_sharing_lookup(mfn_x(mfn)) =3D=3D NULL ) + if ( mem_sharing_lookup(mfn) =3D=3D NULL ) { mem_sharing_page_unlock(pg); return NULL; @@ -877,7 +878,7 @@ static int nominate_page(struct domain *d, gfn_t gfn, atomic_inc(&nr_shared_mfns); =20 /* Update m2p entry to SHARED_M2P_ENTRY */ - set_gpfn_from_mfn(mfn_x(mfn), SHARED_M2P_ENTRY); + set_pfn_from_mfn(mfn, SHARED_M2P_ENTRY); =20 *phandle =3D page->sharing->handle; audit_add_list(page); @@ -1222,7 +1223,7 @@ private_page_found: } =20 /* Update m2p entry */ - set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), gfn); + set_pfn_from_mfn(page_to_mfn(page), gfn); =20 /* Now that the gfn<->mfn map is properly established, * marking dirty is feasible */ diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 4313863066..9e001738f4 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -652,7 +652,7 @@ p2m_pod_decrease_reservation(struct domain *d, gfn_t gf= n, unsigned int order) } p2m_tlb_flush_sync(p2m); for ( j =3D 0; j < n; ++j ) - set_gpfn_from_mfn(mfn_x(mfn), INVALID_M2P_ENTRY); + set_pfn_from_mfn(mfn, INVALID_M2P_ENTRY); p2m_pod_cache_add(p2m, page, cur_order); =20 steal_for_cache =3D ( p2m->pod.entry_count > p2m->pod.count ); @@ -1203,7 +1203,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, gfn_t= gfn, =20 for( i =3D 0; i < (1UL << order); i++ ) { - set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn_aligned) + i); + set_pfn_from_mfn(mfn_add(mfn, i), gfn_x(gfn_aligned) + i); paging_mark_pfn_dirty(d, _pfn(gfn_x(gfn_aligned) + i)); } =20 diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index 84ddc1834b..a9d9ada4a0 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -991,7 +991,8 @@ static int p2m_pt_change_entry_type_range(struct p2m_do= main *p2m, long p2m_pt_audit_p2m(struct p2m_domain *p2m) { unsigned long entry_count =3D 0, pmbad =3D 0; - unsigned long mfn, gfn, m2pfn; + unsigned long gfn, m2pfn; + mfn_t mfn; =20 ASSERT(p2m_locked_by_me(p2m)); ASSERT(pod_locked_by_me(p2m)); @@ -1030,19 +1031,20 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m) /* check for 1GB super page */ if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE ) { - mfn =3D l3e_get_pfn(l3e[i3]); - ASSERT(mfn_valid(_mfn(mfn))); + mfn =3D l3e_get_mfn(l3e[i3]); + ASSERT(mfn_valid(mfn)); /* we have to cover 512x512 4K pages */ for ( i2 =3D 0;=20 i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIE= S); i2++) { - m2pfn =3D get_gpfn_from_mfn(mfn+i2); + m2pfn =3D get_pfn_from_mfn(mfn_add(mfn, i2)); if ( m2pfn !=3D (gfn + i2) ) { pmbad++; - P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx -> = gfn %#lx\n", - gfn + i2, mfn + i2, m2pfn); + P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mf= n" gfn %#lx\n", + gfn + i2, mfn_x(mfn_add(mfn, i2)), + m2pfn); BUG(); } gfn +=3D 1 << (L3_PAGETABLE_SHIFT - PAGE_SHIFT); @@ -1066,17 +1068,17 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m) /* check for super page */ if ( l2e_get_flags(l2e[i2]) & _PAGE_PSE ) { - mfn =3D l2e_get_pfn(l2e[i2]); - ASSERT(mfn_valid(_mfn(mfn))); + mfn =3D l2e_get_mfn(l2e[i2]); + ASSERT(mfn_valid(mfn)); for ( i1 =3D 0; i1 < L1_PAGETABLE_ENTRIES; i1++) { - m2pfn =3D get_gpfn_from_mfn(mfn+i1); + m2pfn =3D get_pfn_from_mfn(mfn_add(mfn, i1)); /* Allow shared M2Ps */ if ( (m2pfn !=3D (gfn + i1)) && !SHARED_M2P(m2= pfn) ) { pmbad++; - P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx" - " -> gfn %#lx\n", gfn+i1, mfn+i= 1, + P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PR= I_mfn" -> gfn %#lx\n", + gfn + i1, mfn_x(mfn_add(mfn, i1= )), m2pfn); BUG(); } @@ -1098,17 +1100,17 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m) entry_count++; continue; } - mfn =3D l1e_get_pfn(l1e[i1]); - ASSERT(mfn_valid(_mfn(mfn))); - m2pfn =3D get_gpfn_from_mfn(mfn); + mfn =3D l1e_get_mfn(l1e[i1]); + ASSERT(mfn_valid(mfn)); + m2pfn =3D get_pfn_from_mfn(mfn); if ( m2pfn !=3D gfn && type !=3D p2m_mmio_direct && !p2m_is_grant(type) && !p2m_is_shared(type) ) { pmbad++; - P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx" - " -> gfn %#lx\n", gfn, mfn, m2pfn); + P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mf= n" -> gfn %#lx\n", + gfn, mfn_x(mfn), m2pfn); BUG(); } } diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 208c196667..d2a876c769 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -769,7 +769,7 @@ void p2m_final_teardown(struct domain *d) =20 =20 static int -p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, unsigned long= mfn, +p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, mfn_t mfn, unsigned int page_order) { unsigned long i; @@ -783,17 +783,17 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long= gfn_l, unsigned long mfn, return 0; =20 ASSERT(gfn_locked_by_me(p2m, gfn)); - P2M_DEBUG("removing gfn=3D%#lx mfn=3D%#lx\n", gfn_l, mfn); + P2M_DEBUG("removing gfn=3D%#lx mfn=3D%"PRI_mfn"\n", gfn_l, mfn_x(mfn)); =20 - if ( mfn_valid(_mfn(mfn)) ) + if ( mfn_valid(mfn) ) { for ( i =3D 0; i < (1UL << page_order); i++ ) { mfn_return =3D p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0, NULL, NULL); if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(= t) ) - set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY); - ASSERT( !p2m_is_valid(t) || mfn + i =3D=3D mfn_x(mfn_return) ); + set_pfn_from_mfn(mfn_add(mfn, i), INVALID_M2P_ENTRY); + ASSERT( !p2m_is_valid(t) || mfn_eq(mfn_add(mfn, i), mfn_return= ) ); } } return p2m_set_entry(p2m, gfn, INVALID_MFN, page_order, p2m_invalid, @@ -807,7 +807,7 @@ guest_physmap_remove_page(struct domain *d, gfn_t gfn, struct p2m_domain *p2m =3D p2m_get_hostp2m(d); int rc; gfn_lock(p2m, gfn, page_order); - rc =3D p2m_remove_page(p2m, gfn_x(gfn), mfn_x(mfn), page_order); + rc =3D p2m_remove_page(p2m, gfn_x(gfn), mfn, page_order); gfn_unlock(p2m, gfn, page_order); return rc; } @@ -842,7 +842,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn= _t mfn, else return -EINVAL; =20 - set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn) + i); + set_pfn_from_mfn(mfn_add(mfn, i), gfn_x(gfn) + i); } =20 return 0; @@ -924,7 +924,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mf= n_t mfn, else if ( p2m_is_ram(ot) && !p2m_is_paged(ot) ) { ASSERT(mfn_valid(omfn)); - set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY); + set_pfn_from_mfn(omfn, INVALID_M2P_ENTRY); } else if ( ot =3D=3D p2m_populate_on_demand ) { @@ -967,7 +967,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mf= n_t mfn, P2M_DEBUG("old gfn=3D%#lx -> mfn %#lx\n", gfn_x(ogfn) , mfn_x(omfn)); if ( mfn_eq(omfn, mfn_add(mfn, i)) ) - p2m_remove_page(p2m, gfn_x(ogfn), mfn_x(mfn_add(mfn, i= )), + p2m_remove_page(p2m, gfn_x(ogfn), mfn_add(mfn, i), 0); } } @@ -984,8 +984,8 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mf= n_t mfn, if ( !p2m_is_grant(t) ) { for ( i =3D 0; i < (1UL << page_order); i++ ) - set_gpfn_from_mfn(mfn_x(mfn_add(mfn, i)), - gfn_x(gfn_add(gfn, i))); + set_pfn_from_mfn(mfn_add(mfn, i), + gfn_x(gfn_add(gfn, i))); } } else @@ -1286,7 +1286,7 @@ static int set_typed_p2m_entry(struct domain *d, unsi= gned long gfn_l, for ( i =3D 0; i < (1UL << order); ++i ) { ASSERT(mfn_valid(mfn_add(omfn, i))); - set_gpfn_from_mfn(mfn_x(omfn) + i, INVALID_M2P_ENTRY); + set_pfn_from_mfn(mfn_add(omfn, i), INVALID_M2P_ENTRY); } } =20 @@ -1481,7 +1481,7 @@ int set_shared_p2m_entry(struct domain *d, unsigned l= ong gfn_l, mfn_t mfn) pg_type =3D read_atomic(&(mfn_to_page(omfn)->u.inuse.type_info)); if ( (pg_type & PGT_count_mask) =3D=3D 0 || (pg_type & PGT_type_mask) !=3D PGT_shared_page ) - set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY); + set_pfn_from_mfn(omfn, INVALID_M2P_ENTRY); =20 P2M_DEBUG("set shared %lx %lx\n", gfn_l, mfn_x(mfn)); rc =3D p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, p2m_ram_shared, @@ -1836,7 +1836,7 @@ int p2m_mem_paging_prep(struct domain *d, unsigned lo= ng gfn_l, uint64_t buffer) ret =3D p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, paging_mode_log_dirty(d) ? p2m_ram_logdirty : p2m_ram_rw, a); - set_gpfn_from_mfn(mfn_x(mfn), gfn_l); + set_pfn_from_mfn(mfn, gfn_l); =20 if ( !page_extant ) atomic_dec(&d->paged_pages); @@ -1887,7 +1887,7 @@ void p2m_mem_paging_resume(struct domain *d, vm_event= _response_t *rsp) p2m_ram_rw, a); =20 if ( !rc ) - set_gpfn_from_mfn(mfn_x(mfn), gfn_x(gfn)); + set_pfn_from_mfn(mfn, gfn_x(gfn)); } gfn_unlock(p2m, gfn, 0); } @@ -2693,7 +2693,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned = int idx, { mfn =3D ap2m->get_entry(ap2m, old_gfn, &t, &a, 0, NULL, NULL); if ( mfn_valid(mfn) ) - p2m_remove_page(ap2m, gfn_x(old_gfn), mfn_x(mfn), PAGE_ORDER_4= K); + p2m_remove_page(ap2m, gfn_x(old_gfn), mfn, PAGE_ORDER_4K); rc =3D 0; goto out; } @@ -2807,8 +2807,8 @@ void audit_p2m(struct domain *d, { struct page_info *page; struct domain *od; - unsigned long mfn, gfn; - mfn_t p2mfn; + unsigned long gfn; + mfn_t p2mfn, mfn; unsigned long orphans_count =3D 0, mpbad =3D 0, pmbad =3D 0; p2m_access_t p2ma; p2m_type_t type; @@ -2830,53 +2830,53 @@ void audit_p2m(struct domain *d, spin_lock(&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { - mfn =3D mfn_x(page_to_mfn(page)); + mfn =3D page_to_mfn(page); =20 - P2M_PRINTK("auditing guest page, mfn=3D%#lx\n", mfn); + P2M_PRINTK("auditing guest page, mfn=3D%"PRI_mfn"\n", mfn_x(mfn)); =20 od =3D page_get_owner(page); =20 if ( od !=3D d ) { - P2M_PRINTK("mfn %"PRI_mfn" owner %pd !=3D %pd\n", mfn, od, d); + P2M_PRINTK("mfn %"PRI_mfn" owner %pd !=3D %pd\n", mfn_x(mfn), = od, d); continue; } =20 - gfn =3D get_gpfn_from_mfn(mfn); + gfn =3D get_pfn_from_mfn(mfn); if ( gfn =3D=3D INVALID_M2P_ENTRY ) { orphans_count++; - P2M_PRINTK("orphaned guest page: mfn=3D%#lx has invalid gfn\n", - mfn); + P2M_PRINTK("orphaned guest page: mfn=3D%"PRI_mfn" has invalid = gfn\n", + mfn_x(mfn)); continue; } =20 if ( SHARED_M2P(gfn) ) { - P2M_PRINTK("shared mfn (%lx) on domain page list!\n", - mfn); + P2M_PRINTK("shared mfn (%"PRI_mfn") on domain page list!\n", + mfn_x(mfn)); continue; } =20 p2mfn =3D get_gfn_type_access(p2m, gfn, &type, &p2ma, 0, NULL); - if ( mfn_x(p2mfn) !=3D mfn ) + if ( !mfn_eq(p2mfn, mfn) ) { mpbad++; - P2M_PRINTK("map mismatch mfn %#lx -> gfn %#lx -> mfn %#lx" + P2M_PRINTK("map mismatch mfn %"PRI_mfn" -> gfn %#lx -> mfn %"P= RI_mfn"" " (-> gfn %#lx)\n", - mfn, gfn, mfn_x(p2mfn), + mfn_x(mfn), gfn, mfn_x(p2mfn), (mfn_valid(p2mfn) - ? get_gpfn_from_mfn(mfn_x(p2mfn)) + ? get_pfn_from_mfn(p2mfn) : -1u)); /* This m2p entry is stale: the domain has another frame in * this physical slot. No great disaster, but for neatness, * blow away the m2p entry. */ - set_gpfn_from_mfn(mfn, INVALID_M2P_ENTRY); + set_pfn_from_mfn(mfn, INVALID_M2P_ENTRY); } __put_gfn(p2m, gfn); =20 - P2M_PRINTK("OK: mfn=3D%#lx, gfn=3D%#lx, p2mfn=3D%#lx\n", - mfn, gfn, mfn_x(p2mfn)); + P2M_PRINTK("OK: mfn=3D%"PRI_mfn", gfn=3D%#lx, p2mfn=3D%"PRI_mfn"\n= ", + mfn_x(mfn), gfn, mfn_x(p2mfn)); } spin_unlock(&d->page_alloc_lock); =20 diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index 011089368a..1ef77e1182 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -344,7 +344,7 @@ void paging_mark_dirty(struct domain *d, mfn_t gmfn) return; =20 /* We /really/ mean PFN here, even for non-translated guests. */ - pfn =3D _pfn(get_gpfn_from_mfn(mfn_x(gmfn))); + pfn =3D _pfn(get_pfn_from_mfn(gmfn)); =20 paging_mark_pfn_dirty(d, pfn); } @@ -362,7 +362,7 @@ int paging_mfn_is_dirty(struct domain *d, mfn_t gmfn) ASSERT(paging_mode_log_dirty(d)); =20 /* We /really/ mean PFN here, even for non-translated guests. */ - pfn =3D _pfn(get_gpfn_from_mfn(mfn_x(gmfn))); + pfn =3D _pfn(get_pfn_from_mfn(gmfn)); /* Invalid pages can't be dirty. */ if ( unlikely(!VALID_M2P(pfn_x(pfn))) ) return 0; diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 1bd53e9c08..00f6946ca7 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -39,7 +39,7 @@ void __init dom0_update_physmap(struct domain *d, unsigne= d long pfn, else ((unsigned int *)vphysmap_s)[pfn] =3D mfn; =20 - set_gpfn_from_mfn(mfn, pfn); + set_pfn_from_mfn(_mfn(mfn), pfn); } =20 static __init void mark_pv_pt_pages_rdonly(struct domain *d, @@ -798,8 +798,8 @@ int __init dom0_construct_pv(struct domain *d, page_list_for_each ( page, &d->page_list ) { mfn =3D mfn_x(page_to_mfn(page)); - BUG_ON(SHARED_M2P(get_gpfn_from_mfn(mfn))); - if ( get_gpfn_from_mfn(mfn) >=3D count ) + BUG_ON(SHARED_M2P(get_pfn_from_mfn(_mfn(mfn)))); + if ( get_pfn_from_mfn(_mfn(mfn)) >=3D count ) { BUG_ON(is_pv_32bit_domain(d)); if ( !page->u.inuse.type_info && diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c index 23d9357657..dbc1255476 100644 --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -184,7 +184,8 @@ void vcpu_show_registers(const struct vcpu *v) =20 void show_page_walk(unsigned long addr) { - unsigned long pfn, mfn =3D read_cr3() >> PAGE_SHIFT; + unsigned long pfn; + mfn_t mfn =3D maddr_to_mfn(read_cr3()); l4_pgentry_t l4e, *l4t; l3_pgentry_t l3e, *l3t; l2_pgentry_t l2e, *l2t; @@ -194,52 +195,52 @@ void show_page_walk(unsigned long addr) if ( !is_canonical_address(addr) ) return; =20 - l4t =3D map_domain_page(_mfn(mfn)); + l4t =3D map_domain_page(mfn); l4e =3D l4t[l4_table_offset(addr)]; unmap_domain_page(l4t); - mfn =3D l4e_get_pfn(l4e); - pfn =3D mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ? - get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY; + mfn =3D l4e_get_mfn(l4e); + pfn =3D mfn_valid(mfn) && machine_to_phys_mapping_valid ? + get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY; printk(" L4[0x%03lx] =3D %"PRIpte" %016lx\n", l4_table_offset(addr), l4e_get_intpte(l4e), pfn); if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) || - !mfn_valid(_mfn(mfn)) ) + !mfn_valid(mfn) ) return; =20 - l3t =3D map_domain_page(_mfn(mfn)); + l3t =3D map_domain_page(mfn); l3e =3D l3t[l3_table_offset(addr)]; unmap_domain_page(l3t); - mfn =3D l3e_get_pfn(l3e); - pfn =3D mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ? - get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY; + mfn =3D l3e_get_mfn(l3e); + pfn =3D mfn_valid(mfn) && machine_to_phys_mapping_valid ? + get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY; printk(" L3[0x%03lx] =3D %"PRIpte" %016lx%s\n", l3_table_offset(addr), l3e_get_intpte(l3e), pfn, (l3e_get_flags(l3e) & _PAGE_PSE) ? " (PSE)" : ""); if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) || (l3e_get_flags(l3e) & _PAGE_PSE) || - !mfn_valid(_mfn(mfn)) ) + !mfn_valid(mfn) ) return; =20 - l2t =3D map_domain_page(_mfn(mfn)); + l2t =3D map_domain_page(mfn); l2e =3D l2t[l2_table_offset(addr)]; unmap_domain_page(l2t); - mfn =3D l2e_get_pfn(l2e); - pfn =3D mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ? - get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY; + mfn =3D l2e_get_mfn(l2e); + pfn =3D mfn_valid(mfn) && machine_to_phys_mapping_valid ? + get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY; printk(" L2[0x%03lx] =3D %"PRIpte" %016lx%s\n", l2_table_offset(addr), l2e_get_intpte(l2e), pfn, (l2e_get_flags(l2e) & _PAGE_PSE) ? " (PSE)" : ""); if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) || (l2e_get_flags(l2e) & _PAGE_PSE) || - !mfn_valid(_mfn(mfn)) ) + !mfn_valid(mfn) ) return; =20 - l1t =3D map_domain_page(_mfn(mfn)); + l1t =3D map_domain_page(mfn); l1e =3D l1t[l1_table_offset(addr)]; unmap_domain_page(l1t); - mfn =3D l1e_get_pfn(l1e); - pfn =3D mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ? - get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY; + mfn =3D l1e_get_mfn(l1e); + pfn =3D mfn_valid(mfn) && machine_to_phys_mapping_valid ? + get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY; printk(" L1[0x%03lx] =3D %"PRIpte" %016lx\n", l1_table_offset(addr), l1e_get_intpte(l1e), pfn); } diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 04c9dc0c65..400fa9838c 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1416,7 +1416,7 @@ static void free_heap_pages( =20 /* This page is not a guest frame any more. */ page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner= */ - set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY); + set_pfn_from_mfn(mfn_add(mfn, + i), INVALID_M2P_ENTRY); =20 if ( need_scrub ) { diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index a9cb98a6c7..3c03be3bca 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -322,7 +322,7 @@ struct page_info *get_page_from_gva(struct vcpu *v, vad= dr_t va, #define SHARED_M2P(_e) ((_e) =3D=3D SHARED_M2P_ENTRY) =20 /* We don't have a M2P on Arm */ -#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } whil= e (0) +static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {} =20 /* Arch-specific portion of memory_op hypercall. */ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg); diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_= table.h index 661228dd39..d731b9e49f 100644 --- a/xen/include/asm-x86/grant_table.h +++ b/xen/include/asm-x86/grant_table.h @@ -41,7 +41,7 @@ static inline int replace_grant_host_mapping(uint64_t add= r, mfn_t frame, #define gnttab_get_frame_gfn(gt, st, idx) ({ \ mfn_t mfn_ =3D (st) ? gnttab_status_mfn(gt, idx) = \ : gnttab_shared_mfn(gt, idx); \ - unsigned long gpfn_ =3D get_gpfn_from_mfn(mfn_x(mfn_)); = \ + unsigned long gpfn_ =3D get_pfn_from_mfn(mfn_); = \ VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN; \ }) =20 diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index dcae558764..4f7ead5ecc 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -492,22 +492,26 @@ extern struct domain *dom_xen, *dom_io, *dom_cow; /* = for vmcoreinfo */ */ extern bool machine_to_phys_mapping_valid; =20 -static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) +static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) { - struct domain *d =3D page_get_owner(mfn_to_page(_mfn(mfn))); + const unsigned long mfn_ =3D mfn_x(mfn); + struct domain *d =3D page_get_owner(mfn_to_page(mfn)); unsigned long entry =3D (d && (d =3D=3D dom_cow)) ? SHARED_M2P_ENTRY := pfn; =20 if ( !machine_to_phys_mapping_valid ) return; =20 - if ( mfn < (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4= ) - compat_machine_to_phys_mapping[mfn] =3D entry; - machine_to_phys_mapping[mfn] =3D entry; + if ( mfn_ < (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / = 4 ) + compat_machine_to_phys_mapping[mfn_] =3D entry; + machine_to_phys_mapping[mfn_] =3D entry; } =20 extern struct rangeset *mmio_ro_ranges; =20 -#define get_gpfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)]) +static inline unsigned long get_pfn_from_mfn(mfn_t mfn) +{ + return machine_to_phys_mapping[mfn_x(mfn)]; +} =20 #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn)= >> 20)) #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3)= << 20)) diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 1a075547e2..4c6e582a67 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -509,7 +509,7 @@ static inline struct page_info *get_page_from_gfn( static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn) { if ( paging_mode_translate(d) ) - return _gfn(get_gpfn_from_mfn(mfn_x(mfn))); + return _gfn(get_pfn_from_mfn(mfn)); else return _gfn(mfn_x(mfn)); } --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 19 21:06:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559577930; cv=none; d=zoho.com; s=zohoarc; b=LZZE7FFrACWfQaBD4L5xSAf5JcX3/Ep0Rf/HDfS5aU/vgozJZfbbIM8APti5bwSyLZMZYF+ozH7uCtTtMLxtZTQ7xWpws0JtFH7C0dhCaHg9hVJMzvTw3jqaEVew7Wm27lkArugN2Shc8/lAjzsHRvifk9qDeox4SnQOWX5ophM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559577930; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2H6zg9h09xX8OJxhTNWdzaI3ssiklzJpUKhh7iqnGKU=; b=HsX+CdiMRbdjKdrHvc+u1KqXrUOYgxp9hjaxMZ7n3VTmlP+/JZOCm+WS2tfyWV04ArZi/5m4YTS2c2OJdKu7bUorfXtUABOsyCI3QpqU1SGAb3pPlWWfLjh8QmP8Vd5bOkCOqfh29r0rLe21LBTiTC/icHMSOQxG03z1RlI7nLs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 155957793070194.91543332489994; Mon, 3 Jun 2019 09:05:30 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRk-0002HC-UQ; Mon, 03 Jun 2019 16:04:28 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRk-0002FS-02 for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:28 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 42cbcab1-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04:26 +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 460761682; Mon, 3 Jun 2019 09:04:26 -0700 (PDT) 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 557A73F246; Mon, 3 Jun 2019 09:04:24 -0700 (PDT) X-Inumbo-ID: 42cbcab1-8619-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:50 +0100 Message-Id: <20190603160350.29806-15-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P 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 , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , George Dunlap , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, Arm is providing a dummy implementation for the M2P helpers used in common code. However, they are quite isolated and could be used by other architecture in the future. So move all the helpers in xen/mm.h. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini Acked-by: George Dunlap --- Changes in v3: - Add Stefano's reviewed-by - Add George's acked-by Changes in v2: - Patch added --- xen/include/asm-arm/mm.h | 11 ----------- xen/include/xen/mm.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 3c03be3bca..d68d1794e5 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -313,17 +313,6 @@ static inline void *page_to_virt(const struct page_inf= o *pg) struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, unsigned long flags); =20 -/* - * Arm does not have an M2P, but common code expects a handful of - * M2P-related defines and functions. Provide dummy versions of these. - */ -#define INVALID_M2P_ENTRY (~0UL) -#define SHARED_M2P_ENTRY (~0UL - 1UL) -#define SHARED_M2P(_e) ((_e) =3D=3D SHARED_M2P_ENTRY) - -/* We don't have a M2P on Arm */ -static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {} - /* Arch-specific portion of memory_op hypercall. */ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg); =20 diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 196ce9fcda..477d24d52f 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -655,4 +655,18 @@ static inline void share_xen_page_with_privileged_gues= ts( share_xen_page_with_guest(page, dom_xen, flags); } =20 +/* + * Dummy implementation of M2P-related helpers for common code when + * the architecture doesn't have an M2P. + */ +#ifndef CONFIG_HAS_M2P + +#define INVALID_M2P_ENTRY (~0UL) +#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define SHARED_M2P(_e) ((_e) =3D=3D SHARED_M2P_ENTRY) + +static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {} + +#endif + #endif /* __XEN_MM_H__ */ --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel