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

[PATCH v2 1/2] xen/pdx: account for frametable_base_pdx in generic pdx_to_page/page_to_pdx


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Thu, 30 Apr 2026 14:51:02 +0200
  • 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=2YCO5UKjNJP5UOoj3rYV3rGfJdTy+pPmVxC0pvAcvis=; b=bKDKuRGVwq9uZTJgwk/ZfUpFj5dFhmUbnHAS7gckEag9RsBYijr+dDh+8jJgH6sZvHMZfcvMBkHkY/HJEaDGaHx0rgzsuBgdASNCiaP1uiUsi6FDFfeUbs7jjJWBoNxV7FFPhPeqKt8KHxdfxUDHC0Ar2K+iZeUO0WRKAh5qTEYzEZ3Pi+NSGUI/mBP8b1WCXD1hrbJkNvvihp5hTkPI8YFzIX/PgEO0Db60k2G9DB3zLnnRrXeDVx35FV25tz+VXjztHK3SlrICmGH16TjdfqgFqDHbAOCI8ZNluyrutRejJ3tMGWEBFYgC3EslZs/n95o/2/4UrnnWZlE9mw3B9g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bvaBVywlwhfPpI88zUPtEDCNhtZxj7qTDOsozYydv2P+bONz2xwjZfWwdLk2EoGew7V6oK/4lxtZdQxQ4Dp0eAFDujBa68UhdaBsS1yvsY7kz5nr4RuHP5eKwOLIFriKizeV7x5tYos0VJ4SCBr3fls+1LSOjk1yuUVmRXtssBO+dvVUzLzsK4CCJHmsYRKqc/cDB/icnNMmnZUe7C85zFyJW27IhoScL9QBRt5/iKivfqS4KaXsm+FCXqLtPL9vHUye32MgkhMvc0QM9ZykTCBivt4TZgqBAGw6et7i6roUFdFoFZVN6t2Qjn1prsQbbfyPnIFS6p24M7gH2I3L+g==
  • 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: Michal Orzel <michal.orzel@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@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>, Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Thu, 30 Apr 2026 12:51:55 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The generic pdx_to_page() and page_to_pdx() macros in xen/pdx.h assume
the frame table starts at PDX 0, which is only true on x86. ARM
uses a non-zero frametable_base_pdx to offset into the frame table (PPC also
defines it).

Fix the generic macros to subtract/add frametable_base_pdx, defaulting
to 0 when the arch does not define it. This makes the generic macros
correct for all architectures, even though they are only used on x86
today.

While at it, consolidate the arch-specific PDX definitions
(frametable_base_pdx and PDX_GROUP_SHIFT) from the arch mm.h headers
into new asm/pdx.h headers for ARM and PPC. The asm/pdx.h is included
earlier in xen/pdx.h via __has_include, making these definitions available
before they are needed.

Also decouple the __has_include(<asm/pdx.h>) check from the PFN-to-PDX
translation override mechanism. Previously, the existence of asm/pdx.h
was taken to mean the arch provides custom pdx_to_pfn / pfn_to_pdx
implementations. This conflation would prevent ARM and PPC from having
asm/pdx.h (for frametable_base_pdx) without also being forced to define
the translation helpers. Replace the __has_include gate with an explicit
ARCH_DEFINES_PDX_XLATE sentinel that only x86 defines.

No functional change.

Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
---
Changes in v2:
 - new patch
---
 xen/arch/arm/include/asm/mm.h  |  5 -----
 xen/arch/arm/include/asm/pdx.h | 21 +++++++++++++++++++++
 xen/arch/arm/mm.c              |  1 +
 xen/arch/ppc/include/asm/mm.h  |  5 -----
 xen/arch/ppc/include/asm/pdx.h | 12 ++++++++++++
 xen/arch/ppc/mm-radix.c        |  1 +
 xen/arch/x86/include/asm/pdx.h |  6 ++++++
 xen/include/xen/pdx.h          | 17 ++++++++++++-----
 8 files changed, 53 insertions(+), 15 deletions(-)
 create mode 100644 xen/arch/arm/include/asm/pdx.h
 create mode 100644 xen/arch/ppc/include/asm/pdx.h

diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index 72a692862420..8180b1e12baf 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -181,11 +181,6 @@ struct page_info
 
 #define maddr_get_owner(ma)   (page_get_owner(maddr_to_page((ma))))
 
-/* PDX of the first page in the frame table. */
-extern unsigned long frametable_base_pdx;
-
-#define PDX_GROUP_SHIFT SECOND_SHIFT
-
 /* Boot-time pagetable setup */
 extern void setup_pagetables(void);
 /* Check that the mapping flag has no W and X together */
diff --git a/xen/arch/arm/include/asm/pdx.h b/xen/arch/arm/include/asm/pdx.h
new file mode 100644
index 000000000000..651df4b210dc
--- /dev/null
+++ b/xen/arch/arm/include/asm/pdx.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef ARM_PDX_H
+#define ARM_PDX_H
+
+#include <asm/lpae.h>
+
+#define PDX_GROUP_SHIFT SECOND_SHIFT
+
+#define ARCH_HAS_FRAMETABLE_BASE_PDX
+extern unsigned long frametable_base_pdx;
+
+#endif /* ARM_PDX_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 6eddbcf912ee..faef0efb327c 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -16,6 +16,7 @@
 #include <xen/static-shmem.h>
 #include <xen/vmap.h>
 
+#include <asm/pdx.h>
 #include <asm/setup.h>
 
 #include <xsm/xsm.h>
diff --git a/xen/arch/ppc/include/asm/mm.h b/xen/arch/ppc/include/asm/mm.h
index 402d06bdaa9f..d55393ff2aa4 100644
--- a/xen/arch/ppc/include/asm/mm.h
+++ b/xen/arch/ppc/include/asm/mm.h
@@ -163,9 +163,6 @@ struct page_info
 #define FRAMETABLE_VIRT_START  (XEN_VIRT_START + GB(32))
 #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
 
-/* PDX of the first page in the frame table. */
-extern unsigned long frametable_base_pdx;
-
 /* Convert between machine frame numbers and page-info structures. */
 #define mfn_to_page(mfn)                                            \
     (frame_table + (mfn_to_pdx(mfn) - frametable_base_pdx))
@@ -220,8 +217,6 @@ static inline void put_page_and_type(struct page_info *page)
 #define set_gpfn_from_mfn(mfn, pfn) BUG_ON("unimplemented")
 #define mfn_to_gfn(d, mfn) ({ BUG_ON("unimplemented"); _gfn(0); })
 
-#define PDX_GROUP_SHIFT XEN_PT_SHIFT_LVL_3
-
 static inline unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
     BUG_ON("unimplemented");
diff --git a/xen/arch/ppc/include/asm/pdx.h b/xen/arch/ppc/include/asm/pdx.h
new file mode 100644
index 000000000000..4290c7bc9c36
--- /dev/null
+++ b/xen/arch/ppc/include/asm/pdx.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef PPC_PDX_H
+#define PPC_PDX_H
+
+#include <asm/page.h>
+
+#define PDX_GROUP_SHIFT XEN_PT_SHIFT_LVL_3
+
+#define ARCH_HAS_FRAMETABLE_BASE_PDX
+extern unsigned long frametable_base_pdx;
+
+#endif /* PPC_PDX_H */
diff --git a/xen/arch/ppc/mm-radix.c b/xen/arch/ppc/mm-radix.c
index d5385ec9dd4b..2eddd86822e0 100644
--- a/xen/arch/ppc/mm-radix.c
+++ b/xen/arch/ppc/mm-radix.c
@@ -10,6 +10,7 @@
 
 #include <asm/early_printk.h>
 #include <asm/page.h>
+#include <asm/pdx.h>
 #include <asm/processor.h>
 #include <asm/regs.h>
 #include <asm/msr.h>
diff --git a/xen/arch/x86/include/asm/pdx.h b/xen/arch/x86/include/asm/pdx.h
index 6be7e1185eb1..5e660be17e39 100644
--- a/xen/arch/x86/include/asm/pdx.h
+++ b/xen/arch/x86/include/asm/pdx.h
@@ -3,8 +3,12 @@
 #ifndef X86_PDX_H
 #define X86_PDX_H
 
+#ifndef CONFIG_PDX_NONE
+
 #include <asm/alternative.h>
 
+#define ARCH_DEFINES_PDX_XLATE
+
 /*
  * Introduce a macro to avoid repeating the same asm goto block in each helper.
  * Note the macro is strictly tied to the code in the helpers.
@@ -59,6 +63,8 @@ static inline paddr_t directmapoff_to_maddr(unsigned long 
offset)
 
 #undef PDX_ASM_GOTO_SKIP
 
+#endif /* !CONFIG_PDX_NONE */
+
 #endif /* X86_PDX_H */
 
 /*
diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h
index 856fc3e8a0e6..59c257651953 100644
--- a/xen/include/xen/pdx.h
+++ b/xen/include/xen/pdx.h
@@ -132,8 +132,9 @@ void set_pdx_range(unsigned long smfn, unsigned long emfn);
  */
 bool __mfn_valid(unsigned long mfn);
 
-#define page_to_pdx(pg)  ((pg) - frame_table)
-#define pdx_to_page(pdx) gcc11_wrap(frame_table + (pdx))
+#define page_to_pdx(pg) \
+    ((unsigned long)((pg) - frame_table) + frametable_base_pdx)
+#define pdx_to_page(pdx) gcc11_wrap(frame_table + ((pdx) - 
frametable_base_pdx))
 
 #define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn))
 #define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx))
@@ -244,6 +245,14 @@ static inline paddr_t directmapoff_to_maddr_xlate(unsigned 
long offset)
 
 #endif /* CONFIG_PDX_OFFSET_COMPRESSION */
 
+#if __has_include(<asm/pdx.h>)
+# include <asm/pdx.h>
+#endif
+
+#ifndef ARCH_HAS_FRAMETABLE_BASE_PDX
+#define frametable_base_pdx 0
+#endif
+
 #ifdef CONFIG_PDX_NONE
 
 /* Without PDX compression we can skip some computations */
@@ -283,9 +292,7 @@ static inline void pfn_pdx_compression_reset(void)
  *
  * Do not use _xlate suffixed functions, always use the non _xlate variants.
  */
-#if __has_include(<asm/pdx.h>)
-# include <asm/pdx.h>
-#else
+#ifndef ARCH_DEFINES_PDX_XLATE
 # define pdx_to_pfn pdx_to_pfn_xlate
 # define pfn_to_pdx pfn_to_pdx_xlate
 # define maddr_to_directmapoff maddr_to_directmapoff_xlate
-- 
2.43.0




 


Rackspace

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