[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 3/3] xen/arm: fix mfn_to_gfn() usage in memory_exchange()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <alejandro.garciavallejo@xxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Fri, 27 Mar 2026 15:50:25 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=l83BYNp+aMnzNw6sbx4zGflMnyM8f979yRPcRxeM/Wc=; b=CLhB4GCjRCB3cnQjZ6SL81WyE0IJezNKN5f867ZxoyOUmUHOCjyhVrax0RW4MF1nKZKZEQiCRM2xjHAOcaGupEONkIRou1qrHk55rzICrtdMp+w6GBVDWTen6/f1K4vjpDH7Qp/MVPUjkXnpgoTxPi1xzDMcJ745OMfKOS2sCkKD7XReiotBBRVJ9NE13KNObbwnHCp45b1VESJfCcmwgb+0icSR+iVhkWrf8g3X2IyYqdxrrCXjv6GTQVlAmru8zSD9LIjFKg0dCkWtcABRdEklKAGoWAgrdOsMbpPBcPsD4SLDpjzN6R7beT/3fFP//GcC9c94E57kta4hb1G6Jw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=blHN6y9jzhIuJGYzhqPjqNlrZAPN/fD+ljVWlyYBeQKvySE1ePd9STgaggr/qq/GZBzNpJS4LFHa1B0rIQIZS/Zw+k2pmgUA43XVCAMPGfRn+qqjIVvIlckbPHsqqZ6OT3sEprIlNcoCHWbCsrmj9gakT0SzPT4LBhSFHzeZwa109lPmPCsTr1agYMdoD01AanoJXGnH3Db7VuU/LvTwDM8EUemti+Gg/PrrusS+ysYrMyxCFMM56LaM2+jax6P0a+L9OtMoH0xyqpg3nzFGMJNHGpa7A7cQI1qXExe96JrWQP33id75fXtpwrhzfNajBKPHpO0vlLs08x2qwdFvCw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: <ray.huang@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, "Volodymyr Babchuk" <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, "Jan Beulich" <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>
  • Delivery-date: Fri, 27 Mar 2026 07:56:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On ARM, the only callsite of mfn_to_gfn() is in memory_exchange(). Although
memory_exchange() is actually not reachable on ARM because steal_page() always
returns -EOPNOTSUPP. We still need to fix it here to ensure correctness once
steal_page() is implemented for ARM in the future, and avoid propagating
broken usage.

Fixing it with the following steps:
- Recording the GFN into the page's type_info via page_set_gfn() at stolen time
- Retrieving it via page_get_gfn() at consume time instead of mfn_to_gfn().

With the only call site removed in ARM, mfn_to_gfn() macro is no longer
referenced and could be removed in ARM.

Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
---
 xen/arch/arm/include/asm/mm.h |  1 -
 xen/common/memory.c           | 11 +++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index 8d61b74e4f..14cb3c3dfa 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -307,7 +307,6 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t 
va,
 
 /* Xen always owns P2M on ARM */
 #define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
-#define mfn_to_gfn(d, mfn) ((void)(d), _gfn(mfn_x(mfn)))
 #define shared_info_to_gfn(d) \
     page_get_xenheap_gfn(virt_to_page((d)->shared_info))
 
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 918510f287..5c462c302d 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -814,6 +814,13 @@ static long 
memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
                     goto fail;
                 }
 
+#ifndef CONFIG_X86
+                /*
+                 * Record the GFN in the page's type_info,
+                 * so that we can retrieve it later when consuming the page.
+                 */
+                page_set_gfn(page, _gfn(gmfn + k));
+#endif
                 page_list_add(page, &in_chunk_list);
 #ifdef CONFIG_X86
                 put_gfn(d, gmfn + k);
@@ -849,7 +856,11 @@ static long 
memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
             gfn_t gfn;
 
             mfn = page_to_mfn(page);
+#ifdef CONFIG_X86
             gfn = mfn_to_gfn(d, mfn);
+#else
+            gfn = page_get_gfn(page);
+#endif
             /* Pages were unshared above */
             BUG_ON(SHARED_M2P(gfn_x(gfn)));
             if ( guest_physmap_remove_page(d, gfn, mfn, 0) )
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.