From nobody Tue Feb 10 00:39:51 2026 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