Skip to contentSkip to conversation

xen/x86: move d->arch.physaddr_bitsize field handling to pv32

PATCH In review Grygorii Strashko 3 participants 6 messages Dec 16, 2025 – Dec 17, 2025

lore
Share & tools
lore
#0 lore raw

v4 cover xen/x86: move d->arch.physaddr_bitsize field handling to pv32

From: Grygorii Strashko <[email protected]>

The d->arch.physaddr_bitsize field is used only by PV32 code so as the domain_clamp_alloc_bitsize() function.
So move them into PV32 code.

changes in v4:
- rebase
- split patch 3 on two:
move domain_clamp_alloc_bitsize()
move d->arch.physaddr_bitsize

changes in v3:
- added tags
- changed patch 3

changes in v2:
- split on 3 patches
- move physaddr_bitsize in struct pv_domain
- make minimal style adjustments as requested

v3: https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/
v2: https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/

Grygorii Strashko (2):
xen/x86: move domain_clamp_alloc_bitsize() into pv32 code xen/x86: move d->arch.physaddr_bitsize field handling into pv32

 xen/arch/x86/include/asm/domain.h |  6 +++---
 xen/arch/x86/include/asm/mm.h     | 12 ++++++++++--
 xen/arch/x86/pv/dom0_build.c      |  7 +++++--
 xen/arch/x86/pv/domain.c          |  2 +-
 xen/arch/x86/x86_64/mm.c          |  7 -------
 5 files changed, 19 insertions(+), 15 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/2 xen/x86: move domain_clamp_alloc_bitsize() into pv32 code

From: Grygorii Strashko <[email protected]>

The d->arch.physaddr_bitsize field is used only by PV32 code so as the domain_clamp_alloc_bitsize() function.

Hence move domain_clamp_alloc_bitsize() function into PV32 code and convert it to macro.

---
changes in v4:
- rebase
- split out moving d->arch.physaddr_bitsize in separate patch
- fix comments for domain_clamp_alloc_bitsize() macro

 xen/arch/x86/include/asm/mm.h | 12 ++++++++++--
 xen/arch/x86/x86_64/mm.c      |  7 -------
 2 files changed, 10 insertions(+), 9 deletions(-)
xen/arch/x86/include/asm/mm.h +10 -2
index 9438f5ea0119..89e8940c3316 100644
@@ -619,8 +619,16 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 
 extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
-#define domain_clamp_alloc_bitsize(d, bits) domain_clamp_alloc_bitsize(d, bits)
+#ifdef CONFIG_PV32
+#define domain_clamp_alloc_bitsize(d, bits) ({                                 \
+    struct domain *_d = (d);                                                   \
+                                                                               \
+    ((_d &&                                                                    \
+      _d->arch.physaddr_bitsize)                                               \
+         ? min_t(unsigned int, _d->arch.physaddr_bitsize, bits)                \
+         : bits);                                                              \
+})
+#endif
 
 unsigned long domain_get_maximum_gpfn(struct domain *d);
 
xen/arch/x86/x86_64/mm.c +0 -7
index 42fd4fe4e9b5..8eadab7933d0 100644
@@ -1119,13 +1119,6 @@ unmap:
     return ret;
 }
 
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits)
-{
-    if ( (d == NULL) || (d->arch.physaddr_bitsize == 0) )
-        return bits;
-    return min(d->arch.physaddr_bitsize, bits);
-}
-
 static int transfer_pages_to_heap(struct mem_hotadd_info *info)
 {
     unsigned long i;
Signature · 1 line
2.34.1
Reviewed-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] xen/x86: move domain_clamp_alloc_bitsize() into pv32 code

xen/arch/x86/include/asm/mm.h void __iomem *ioremap_wc(paddr_t pa, size_t len); · line 624

Quoted 11 lines · Grygorii Strashko
xen/arch/x86/include/asm/mm.h +3 -2
@@ -619,8 +619,16 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 
 extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
-#define domain_clamp_alloc_bitsize(d, bits) domain_clamp_alloc_bitsize(d, bits)
+#ifdef CONFIG_PV32
+#define domain_clamp_alloc_bitsize(d, bits) ({                                 \
+    struct domain *_d = (d);                                                   \

This imo wants to be pointer-to-const. Question is whether then I'm upsetting you again, Andrew?

xen/arch/x86/include/asm/mm.h void __iomem *ioremap_wc(paddr_t pa, size_t len); · line 629

Quoted 4 lines
xen/arch/x86/include/asm/mm.h +4 -0
+    ((_d &&                                                                    \
+      _d->arch.physaddr_bitsize)                                               \
+         ? min_t(unsigned int, _d->arch.physaddr_bitsize, bits)                \
+         : bits);                                                              \

This imo wants to look more like

    ((_d && _d->arch.physaddr_bitsize)                      \
     ? min_t(unsigned int, _d->arch.physaddr_bitsize, bits) \
     : (bits));                                             \

The parenthesization of the latter use of "bits" is a must.

With the adjustments (happy to carry out while committing, so long as there's agreement):

Albeit, as indicated before, I'm not quite happy with the use of min_t(). Maybe another macro-local variable _bits should be introduced?

Jan

#3 lore raw

Re: [PATCH v4 1/2] xen/x86: move domain_clamp_alloc_bitsize() into pv32 code

Quoted 21 lines · Jan Beulich

xen/arch/x86/include/asm/mm.h void __iomem *ioremap_wc(paddr_t pa, size_t len); · line 624

Quoted 11 lines · Grygorii Strashko
xen/arch/x86/include/asm/mm.h +3 -2
@@ -619,8 +619,16 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 
  extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
-#define domain_clamp_alloc_bitsize(d, bits) domain_clamp_alloc_bitsize(d, bits)
+#ifdef CONFIG_PV32
+#define domain_clamp_alloc_bitsize(d, bits) ({                                 \
+    struct domain *_d = (d);                                                   \

This imo wants to be pointer-to-const. Question is whether then I'm upsetting you again, Andrew?

xen/arch/x86/include/asm/mm.h void __iomem *ioremap_wc(paddr_t pa, size_t len); · line 629

Quoted 4 lines
xen/arch/x86/include/asm/mm.h +4 -0
+    ((_d &&                                                                    \
+      _d->arch.physaddr_bitsize)                                               \
+         ? min_t(unsigned int, _d->arch.physaddr_bitsize, bits)                \
+         : bits);                                                              \
Quoted 8 lines

This imo wants to look more like

     ((_d && _d->arch.physaddr_bitsize)                      \
      ? min_t(unsigned int, _d->arch.physaddr_bitsize, bits) \
      : (bits));                                             \

The parenthesization of the latter use of "bits" is a must.

I'm ok with above adjustments, thank you.

Quoted 8 lines

With the adjustments (happy to carry out while committing, so long as there's agreement):

Albeit, as indicated before, I'm not quite happy with the use of min_t(). Maybe another macro-local variable _bits should be introduced?

Signature · 2 lines
Best regards,
-grygorii
#4 lore raw

PATCH v4 2/2 xen/x86: move d->arch.physaddr_bitsize field handling into pv32

In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>

The d->arch.physaddr_bitsize field is used only by PV32 code, so move d->arch.physaddr_bitsize field under PV32 ifdef into struct pv_domain.

---
changes in v4:
- rebase
- new patch

 xen/arch/x86/include/asm/domain.h | 6 +++---
 xen/arch/x86/include/asm/mm.h     | 4 ++--
 xen/arch/x86/pv/dom0_build.c      | 7 +++++--
 xen/arch/x86/pv/domain.c          | 2 +-
 4 files changed, 11 insertions(+), 8 deletions(-)
xen/arch/x86/include/asm/domain.h +3 -3
index 7e5cbd11a464..16cd45cc32c0 100644
@@ -290,6 +290,9 @@ struct pv_domain
 
 #ifdef CONFIG_PV32
     unsigned int hv_compat_vstart;
+
+    /* Maximum physical-address bitwidth supported by this guest. */
+    unsigned int physaddr_bitsize;
 #endif
 
     /* map_domain_page() mapping cache. */
@@ -319,9 +322,6 @@ struct arch_domain
 {
     struct page_info *perdomain_l3_pg;
 
-    /* Maximum physical-address bitwidth supported by this guest. */
-    unsigned int physaddr_bitsize;
-
     /* I/O-port admin-specified access capabilities. */
     struct rangeset *ioport_caps;
     uint32_t pci_cf8;
xen/arch/x86/include/asm/mm.h +2 -2
index 89e8940c3316..734e6b3af1d6 100644
@@ -624,8 +624,8 @@ extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
     struct domain *_d = (d);                                                   \
                                                                                \
     ((_d &&                                                                    \
-      _d->arch.physaddr_bitsize)                                               \
-         ? min_t(unsigned int, _d->arch.physaddr_bitsize, bits)                \
+      _d->arch.pv.physaddr_bitsize)                                            \
+         ? min_t(unsigned int, _d->arch.pv.physaddr_bitsize, bits)             \
          : bits);                                                              \
 })
 #endif
xen/arch/x86/pv/dom0_build.c +5 -2
index 418b453ba8bf..9a11a0a16b4e 100644
@@ -626,8 +626,10 @@ static int __init dom0_construct(const struct boot_domain *bd)
         initrd_mfn = paddr_to_pfn(initrd->start);
         mfn = initrd_mfn;
         count = PFN_UP(initrd_len);
-        if ( d->arch.physaddr_bitsize &&
-             ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)) )
+
+#ifdef CONFIG_PV32
+        if ( d->arch.pv.physaddr_bitsize &&
+             ((mfn + count - 1) >> (d->arch.pv.physaddr_bitsize - PAGE_SHIFT)) )
         {
             order = get_order_from_pages(count);
             page = alloc_domheap_pages(d, order, MEMF_no_scrub);
@@ -650,6 +652,7 @@ static int __init dom0_construct(const struct boot_domain *bd)
             initrd->start = pfn_to_paddr(initrd_mfn);
         }
         else
+#endif
         {
             while ( count-- )
                 if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) )
xen/arch/x86/pv/domain.c +1 -1
index ca5f6920516e..01499582d2d6 100644
@@ -257,7 +257,7 @@ int switch_compat(struct domain *d)
     d->arch.pv.hv_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START;
 
     if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )
-        d->arch.physaddr_bitsize =
+        d->arch.pv.physaddr_bitsize =
             /* 2^n entries can be contained in guest's p2m mapping space */
             fls(MACH2PHYS_COMPAT_NR_ENTRIES(d)) - 1 + PAGE_SHIFT;
 
Signature · 1 line
2.34.1