From patchwork Tue May 7 15:14:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 163539 Delivered-To: patch@linaro.org Received: by 2002:ac9:2a84:0:0:0:0:0 with SMTP id p4csp3883139oca; Tue, 7 May 2019 08:16:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxP9aM0/fTdtOZwRT5vZJKMe3uAJETggdH/96v85Wju/GWhSXJVECsfCbr32Fu17mjxyJAO X-Received: by 2002:a24:c183:: with SMTP id e125mr22953159itg.95.1557242209638; Tue, 07 May 2019 08:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557242209; cv=none; d=google.com; s=arc-20160816; b=jz94/zjWUmYa2mJ6fdTRheIgHvPOxQUbkuC+Lk6X28EuNaNlab2/qMgw+xYbD3nOTW I1UzlB68M4/xkhN+4YmRbI47jyF18fXrFN/+fErbjakiw1CctvbfPUn+bXqH2Wl22e/Q GTzM4KvPl8c1Ek45geD5VTHhzM2WvAwRt8bPU6xQD6nIc4P8oJacCyB3jLbg3+PPWYmP em1qiRlTQojIg9ITD4M4c3HXG4Ssuy70ir8sAyI36BCcYEGjaTxsuC1tJ4QQmrCpP0sZ RvMPo/7sEUHqqelEOjEMkaIWeWUDaYyO/WP+7eu1dlcAlQpo3EPpcWt8duKYootOZbQy uPEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=sPD6AkqDlyYWNcwjAwQLHM9uGqFhj5oCSgj/X8d3A9A=; b=sfXph3+ppEmObkPMPwzNwY4cdFi/47PTjljfQKiSI4hj/Y/A+vtC4ylxKNeKh/gmMb J018g8BHu5almM2xshSj6pnH30Aw8zWxFh3xMk0SPywCxcP4gJbATUa2uvc+yatUtHIe iTRaunUIuJimtNoLw3NgtLp0bG6cVF8mFE7rSNNFvJznUbNCc7ztxmcWG1zTr5CoJOlJ kOHU2EDVlkb2Ao7vvLUGGywYA6JMaQsko0sdBsa1Iy+DaUfvtBuO3eva/u0Q9ehUxzcb B+QTWhh2Sppmcqg9HyhOvC5hqUQ6usHZd6WGH+TZjtxXSKGdT9Bx4npOvp2n1q2h07r3 NuHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id a199si10289780ita.35.2019.05.07.08.16.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 May 2019 08:16:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hO1oL-0007KJ-Vc; Tue, 07 May 2019 15:15:17 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hO1oL-0007K1-7N for xen-devel@lists.xenproject.org; Tue, 07 May 2019 15:15:17 +0000 X-Inumbo-ID: eb6aafdc-70da-11e9-914b-9744845dd15d Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id eb6aafdc-70da-11e9-914b-9744845dd15d; Tue, 07 May 2019 15:15:16 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D0011684; Tue, 7 May 2019 08:15: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 29CF43F5AF; Tue, 7 May 2019 08:15:15 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 7 May 2019 16:14:48 +0100 Message-Id: <20190507151458.29350-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190507151458.29350-1-julien.grall@arm.com> References: <20190507151458.29350-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 04/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_Pau_Monn=C3=A9?= MIME-Version: 1.0 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. Furthermore, the naming of the former is more consistent with the current naming scheme (GFN/MFN). So use 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 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/mm.c | 9 +++++---- xen/arch/x86/pv/emul-priv-op.c | 4 ++-- xen/drivers/passthrough/x86/iommu.c | 16 +++++++++------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 9eaa978ce5..8d29dfeecc 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -679,7 +679,7 @@ int arch_domain_soft_reset(struct domain *d) int ret = 0; struct domain *owner; mfn_t mfn; - unsigned long gfn; + gfn_t gfn; p2m_type_t p2mt; unsigned int i; @@ -713,19 +713,20 @@ int arch_domain_soft_reset(struct domain *d) ASSERT( owner == d ); mfn = page_to_mfn(page); - gfn = mfn_to_gmfn(d, mfn_x(mfn)); + gfn = mfn_to_gfn(d, mfn); /* * gfn == INVALID_GFN indicates that the shared_info page was never mapped * to the domain's address space and there is nothing to replace. */ - if ( gfn == gfn_x(INVALID_GFN) ) + if ( gfn_eq(gfn, INVALID_GFN) ) goto exit_put_page; - 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 = -EINVAL; goto exit_put_gfn; } @@ -733,31 +734,34 @@ int arch_domain_soft_reset(struct domain *d) new_page = 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 frame %"PRI_gfn"\n", + d, gfn_x(gfn)); ret = -ENOMEM; goto exit_put_gfn; } - ret = guest_physmap_remove_page(d, _gfn(gfn), mfn, PAGE_ORDER_4K); + ret = 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 %lx\n", - d->domain_id, gfn); + printk(XENLOG_G_ERR + "Failed to remove %pd's shared_info frame %"PRI_gfn"\n", + d, gfn_x(gfn)); free_domheap_page(new_page); goto exit_put_gfn; } - ret = guest_physmap_add_page(d, _gfn(gfn), page_to_mfn(new_page), + ret = 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); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 45fadbab61..9878453eb0 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2632,19 +2632,20 @@ int free_page_type(struct page_info *page, unsigned long type, { #ifdef CONFIG_PV struct domain *owner = page_get_owner(page); - unsigned long gmfn; int rc; if ( likely(owner != NULL) && unlikely(paging_mode_enabled(owner)) ) { + gfn_t gfn; + /* A page table is dirtied when its type count becomes zero. */ paging_mark_dirty(owner, page_to_mfn(page)); ASSERT(!shadow_mode_refcounts(owner)); - gmfn = mfn_to_gmfn(owner, mfn_x(page_to_mfn(page))); - if ( VALID_M2P(gmfn) ) - shadow_remove_all_shadows(owner, _mfn(gmfn)); + gfn = mfn_to_gfn(owner, page_to_mfn(page)); + if ( VALID_M2P(gfn_x(gfn)) ) + shadow_remove_all_shadows(owner, _mfn(gfn_x(gfn))); } if ( !(type & PGT_partial) ) diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index af74f50dc8..e976ff9898 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 = pagetable_get_mfn(curr->arch.guest_table); - *val = xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn))); + *val = 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, mfn = l4e_get_mfn(*pl4e); unmap_domain_page(pl4e); - *val = compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn))); + *val = 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)) == dom_cow); diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index 034ac903dd..7a756ef19e 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -92,15 +92,17 @@ int arch_iommu_populate_page_table(struct domain *d) if ( is_hvm_domain(d) || (page->u.inuse.type_info & PGT_type_mask) == PGT_writable_page ) { - unsigned long mfn = mfn_x(page_to_mfn(page)); - unsigned long gfn = mfn_to_gmfn(d, mfn); + mfn_t mfn = page_to_mfn(page); + gfn_t gfn = mfn_to_gfn(d, mfn); unsigned int flush_flags = 0; - if ( gfn != gfn_x(INVALID_GFN) ) + if ( !gfn_eq(gfn, INVALID_GFN) ) { - ASSERT(!(gfn >> DEFAULT_DOMAIN_ADDRESS_WIDTH)); - BUG_ON(SHARED_M2P(gfn)); - rc = iommu_map(d, _dfn(gfn), _mfn(mfn), PAGE_ORDER_4K, + dfn_t dfn = _dfn(gfn_x(gfn)); + + ASSERT(!(gfn_x(gfn) >> DEFAULT_DOMAIN_ADDRESS_WIDTH)); + BUG_ON(SHARED_M2P(gfn_x(gfn))); + rc = iommu_map(d, dfn, mfn, PAGE_ORDER_4K, IOMMUF_readable | IOMMUF_writable, &flush_flags); @@ -118,7 +120,7 @@ int arch_iommu_populate_page_table(struct domain *d) ((page->u.inuse.type_info & PGT_type_mask) != PGT_writable_page) ) { - rc = iommu_unmap(d, _dfn(gfn), PAGE_ORDER_4K, &flush_flags); + rc = 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) == PGT_writable_page) )