Skip to contentSkip to conversation

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

PATCH Superseded Grygorii Strashko 3 participants 11 messages Nov 27, 2025 – Nov 28, 2025 RISC-V

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

From: Grygorii Strashko <[email protected]>

1) arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro
2) add generic domain_clamp_alloc_bitsize() macro and clean up !x86 arches
3) move d->arch.physaddr_bitsize field handling to pv32 code

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

Grygorii Strashko (3):
arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro xen/mm: add generic domain_clamp_alloc_bitsize() macro xen/x86: move d->arch.physaddr_bitsize field handling to pv32

 xen/arch/arm/include/asm/mm.h     |  3 ---
 xen/arch/ppc/include/asm/mm.h     |  3 ---
 xen/arch/riscv/include/asm/mm.h   |  3 ---
 xen/arch/x86/include/asm/domain.h |  8 +++++---
 xen/arch/x86/include/asm/mm.h     |  7 +++++--
 xen/arch/x86/pv/dom0_build.c      |  6 ++++--
 xen/arch/x86/pv/domain.c          | 23 +++++++++++++++++++++++
 xen/arch/x86/x86_64/mm.c          | 20 --------------------
 xen/include/xen/mm.h              |  4 ++++
 9 files changed, 41 insertions(+), 36 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro

From: Grygorii Strashko <[email protected]>

The domain_set_alloc_bitsize() is x86 PV32 specific and not used by other arch or common code, so remove it.

---
 xen/arch/arm/include/asm/mm.h   | 1 -
 xen/arch/ppc/include/asm/mm.h   | 1 -
 xen/arch/riscv/include/asm/mm.h | 1 -
 3 files changed, 3 deletions(-)
xen/arch/arm/include/asm/mm.h +0 -1
index f702f4a0d676..4c6cc64aa7ba 100644
@@ -313,7 +313,6 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-#define domain_set_alloc_bitsize(d) ((void)0)
 #define domain_clamp_alloc_bitsize(d, b) (b)
 
 unsigned long domain_get_maximum_gpfn(struct domain *d);
xen/arch/ppc/include/asm/mm.h +0 -1
index a33eeec43bd6..e478291fdf55 100644
@@ -96,7 +96,6 @@ static inline struct page_info *virt_to_page(const void *v)
 /* TODO: implement */
 #define mfn_valid(mfn) ({ (void) (mfn); 0; })
 
-#define domain_set_alloc_bitsize(d) ((void)(d))
 #define domain_clamp_alloc_bitsize(d, b) (b)
 
 #define PFN_ORDER(pfn_) ((pfn_)->v.free.order)
xen/arch/riscv/include/asm/mm.h +0 -1
index 9283616c0224..11e9f26bf0a5 100644
@@ -292,7 +292,6 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)
 /* TODO: implement */
 #define mfn_valid(mfn) ({ (void)(mfn); 0; })
 
-#define domain_set_alloc_bitsize(d) ((void)(d))
 #define domain_clamp_alloc_bitsize(d, b) ((void)(d), (b))
 
 #define PFN_ORDER(pg) ((pg)->v.free.order)
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/3 xen/mm: add generic domain_clamp_alloc_bitsize() macro

In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Add generic domain_clamp_alloc_bitsize() macro and clean up arch specific defines.

---
 xen/arch/arm/include/asm/mm.h   | 2 --
 xen/arch/ppc/include/asm/mm.h   | 2 --
 xen/arch/riscv/include/asm/mm.h | 2 --
 xen/arch/x86/include/asm/mm.h   | 1 +
 xen/include/xen/mm.h            | 4 ++++
 5 files changed, 5 insertions(+), 6 deletions(-)
xen/arch/arm/include/asm/mm.h +0 -2
index 4c6cc64aa7ba..ec2d2dc5372a 100644
@@ -313,8 +313,6 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-#define domain_clamp_alloc_bitsize(d, b) (b)
-
 unsigned long domain_get_maximum_gpfn(struct domain *d);
 
 /* Release all __init and __initdata ranges to be reused */
xen/arch/ppc/include/asm/mm.h +0 -2
index e478291fdf55..91c405876bd0 100644
@@ -96,8 +96,6 @@ static inline struct page_info *virt_to_page(const void *v)
 /* TODO: implement */
 #define mfn_valid(mfn) ({ (void) (mfn); 0; })
 
-#define domain_clamp_alloc_bitsize(d, b) (b)
-
 #define PFN_ORDER(pfn_) ((pfn_)->v.free.order)
 
 struct page_info
xen/arch/riscv/include/asm/mm.h +0 -2
index 11e9f26bf0a5..e5ea91fa4d0c 100644
@@ -292,8 +292,6 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)
 /* TODO: implement */
 #define mfn_valid(mfn) ({ (void)(mfn); 0; })
 
-#define domain_clamp_alloc_bitsize(d, b) ((void)(d), (b))
-
 #define PFN_ORDER(pg) ((pg)->v.free.order)
 
 extern unsigned char cpu0_boot_stack[];
xen/arch/x86/include/asm/mm.h +1 -0
index 08153e6d6fa2..17ca6666a34e 100644
@@ -621,6 +621,7 @@ extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
 void domain_set_alloc_bitsize(struct domain *d);
 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)
 
 unsigned long domain_get_maximum_gpfn(struct domain *d);
 
xen/include/xen/mm.h +4 -0
index b968f47b87e0..426362adb2f4 100644
@@ -641,4 +641,8 @@ static inline void put_page_alloc_ref(struct page_info *page)
     }
 }
 
+#ifndef domain_clamp_alloc_bitsize
+#define domain_clamp_alloc_bitsize(d, bits) ((void)(d), (bits))
+#endif
+
 #endif /* __XEN_MM_H__ */
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/3 xen/x86: move d->arch.physaddr_bitsize field handling to 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 domain_set_alloc_bitsize() function into PV32 code
- move domain_clamp_alloc_bitsize() function into PV32 code
- move d->arch.physaddr_bitsize field under PV32 ifdef into struct pv_domain

---
 xen/arch/x86/include/asm/domain.h |  8 +++++---
 xen/arch/x86/include/asm/mm.h     |  6 ++++--
 xen/arch/x86/pv/dom0_build.c      |  6 ++++--
 xen/arch/x86/pv/domain.c          | 23 +++++++++++++++++++++++
 xen/arch/x86/x86_64/mm.c          | 20 --------------------
 5 files changed, 36 insertions(+), 27 deletions(-)
xen/arch/x86/include/asm/domain.h +5 -3
index 5df8c7825333..6cdfdf8b5c26 100644
@@ -276,6 +276,11 @@ struct pv_domain
 
     atomic_t nr_l4_pages;
 
+#ifdef CONFIG_PV32
+    /* Maximum physical-address bitwidth supported by this guest. */
+    unsigned int physaddr_bitsize;
+#endif
+
     /* Is a 32-bit PV guest? */
     bool is_32bit;
     /* XPTI active? */
@@ -316,9 +321,6 @@ struct arch_domain
     unsigned int hv_compat_vstart;
 #endif
 
-    /* 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 +4 -2
index 17ca6666a34e..128115442ecc 100644
@@ -619,9 +619,11 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 
 extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
-void domain_set_alloc_bitsize(struct domain *d);
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
+#ifdef CONFIG_PV32
+unsigned int domain_clamp_alloc_bitsize(const struct domain *d,
+                                        unsigned int bits);
 #define domain_clamp_alloc_bitsize(d, bits) domain_clamp_alloc_bitsize(d, bits)
+#endif
 
 unsigned long domain_get_maximum_gpfn(struct domain *d);
 
xen/arch/x86/pv/dom0_build.c +4 -2
index 21158ce1812e..e4f95d8f2fc8 100644
@@ -626,8 +626,9 @@ 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 +651,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 +23 -0
index 9c4785c187dd..ad40a712ac5f 100644
@@ -230,6 +230,29 @@ unsigned long pv_make_cr4(const struct vcpu *v)
 }
 
 #ifdef CONFIG_PV32
+unsigned int domain_clamp_alloc_bitsize(const struct domain *d,
+                                        unsigned int bits)
+{
+    if ( (d == NULL) || (d->arch.pv.physaddr_bitsize == 0) )
+        return bits;
+
+    return min(d->arch.pv.physaddr_bitsize, bits);
+}
+
+static void domain_set_alloc_bitsize(struct domain *d)
+{
+    if ( !is_pv_32bit_domain(d) ||
+         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||
+         d->arch.pv.physaddr_bitsize > 0 )
+        return;
+
+    d->arch.pv.physaddr_bitsize =
+        /* 2^n entries can be contained in guest's p2m mapping space */
+        fls(MACH2PHYS_COMPAT_NR_ENTRIES(d)) - 1
+        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
+        + PAGE_SHIFT;
+}
+
 int switch_compat(struct domain *d)
 {
     struct vcpu *v;
xen/arch/x86/x86_64/mm.c +0 -20
index d4e6a9c0a2e0..8eadab7933d0 100644
@@ -1119,26 +1119,6 @@ unmap:
     return ret;
 }
 
-void domain_set_alloc_bitsize(struct domain *d)
-{
-    if ( !is_pv_32bit_domain(d) ||
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||
-         d->arch.physaddr_bitsize > 0 )
-        return;
-    d->arch.physaddr_bitsize =
-        /* 2^n entries can be contained in guest's p2m mapping space */
-        fls(MACH2PHYS_COMPAT_NR_ENTRIES(d)) - 1
-        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
-        + PAGE_SHIFT;
-}
-
-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
#4 lore raw

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

Quoted 13 lines · Grygorii Strashko
xen/arch/x86/include/asm/mm.h +3 -2
index 17ca6666a34e..128115442ecc 100644
@@ -619,9 +619,11 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 
 extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
-void domain_set_alloc_bitsize(struct domain *d);
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
+#ifdef CONFIG_PV32
+unsigned int domain_clamp_alloc_bitsize(const struct domain *d,
+                                        unsigned int bits);

Do not convert this, or any other domains/vcpus you see, to const.  I realise you have been given conflicting information on this point, but the maintainers as a whole agreed to not const pointers to complex objects in the general case because of the churn it creates, and the repeated examples of MISRA violations people have inserted to work around the fact it shouldn't have been a const pointer to start with.

That aside, I think clamp wants to be a static inline here.  (Except it can't be, so it needs to be a macro).

It's currently a concrete function call to very simple piece of logic, where the callers have options to eliminate it entirely in the d = NULL case if they could only see in.

#define domain_clamp_alloc_bitsize(d, bits)                             \
    (((d) && (d)->arch.pv.physaddr_bitsize)                             \
     ? min_t(uint32_t, (d)->arch.pv.physaddr_bitsize, bits) : bits)

seems to work.  The min_t() is because all callers pass in bits as a long constant, tripping the typecheck in min().

Quoted 9 lines
xen/arch/x86/include/asm/mm.h +1 -0
+#endif
 
 unsigned long domain_get_maximum_gpfn(struct domain *d);
 
xen/arch/x86/pv/dom0_build.c +0 -0
index 21158ce1812e..e4f95d8f2fc8 100644

xen/arch/x86/pv/dom0_build.c static int __init dom0_construct(const struct boot_domain *bd) · line 630

Quoted 5 lines
xen/arch/x86/pv/dom0_build.c +0 -2
@@ -626,8 +626,9 @@ 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)) )

While you're editing this, blank line here please.

Quoted 34 lines
xen/arch/x86/pv/dom0_build.c +4 -0
+#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 +651,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 +12 -0
index 9c4785c187dd..ad40a712ac5f 100644
@@ -230,6 +230,29 @@ unsigned long pv_make_cr4(const struct vcpu *v)
 }
 
 #ifdef CONFIG_PV32
+unsigned int domain_clamp_alloc_bitsize(const struct domain *d,
+                                        unsigned int bits)
+{
+    if ( (d == NULL) || (d->arch.pv.physaddr_bitsize == 0) )
+        return bits;
+
+    return min(d->arch.pv.physaddr_bitsize, bits);
+}
+
+static void domain_set_alloc_bitsize(struct domain *d)
+{
+    if ( !is_pv_32bit_domain(d) ||

xen/arch/x86/pv/domain.c unsigned long pv_make_cr4(const struct vcpu *v) · line 254

Quoted 10 lines
xen/arch/x86/pv/domain.c +10 -0
+         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||
+         d->arch.pv.physaddr_bitsize > 0 )
+        return;
+
+    d->arch.pv.physaddr_bitsize =
+        /* 2^n entries can be contained in guest's p2m mapping space */
+        fls(MACH2PHYS_COMPAT_NR_ENTRIES(d)) - 1
+        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
+        + PAGE_SHIFT;
+}

The single caller has just set d->arch.pv.is_32bit = true, but the compiler can't eliminate the first condition because of the embedded evaluate_nospec().  Nor the 3rd condition, because it can't reason about the singleton nature of switch_compat().

Thus, it would be better inlined fully, as:

    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page ) 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;

which is rather easier to follow.  Even the comment about PAGE_SHIFT is more noise than help.

In an ideal world it ought to be in its own patch, and in principle I'm happy to draft one with a fuller explanation if you'd prefer, but given the repositioning of physaddr_bitsize into pv domain as wekk, it's probably all better together in this single patch.

~Andrew

#5 lore raw
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Grygorii Strashko
xen/arch/x86/include/asm/mm.h +0 -0
index 17ca6666a34e..128115442ecc 100644
@@ -619,9 +619,11 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 
 extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
Quoted 12 lines

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

Quoted 5 lines
xen/arch/x86/include/asm/mm.h +3 -2
-void domain_set_alloc_bitsize(struct domain *d);
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
+#ifdef CONFIG_PV32
+unsigned int domain_clamp_alloc_bitsize(const struct domain *d,
+                                        unsigned int bits);

Do not convert this, or any other domains/vcpus you see, to const.  I realise you have been given conflicting information on this point, but the maintainers as a whole agreed to not const pointers to complex objects in the general case because of the churn it creates, and the repeated examples of MISRA violations people have inserted to work around the fact it shouldn't have been a const pointer to start with.

While moot here when indeed converted to a macro, as you suggest below, I don't recall "maintainers as a whole agreed" on this. For one there are predicate-like functions where I think even you agreed their parameters can be pointer-to-const. The case here isn't very far from predicate-like, in particular ...

Quoted 10 lines

That aside, I think clamp wants to be a static inline here.  (Except it can't be, so it needs to be a macro).

It's currently a concrete function call to very simple piece of logic, where the callers have options to eliminate it entirely in the d = NULL case if they could only see in.

#define domain_clamp_alloc_bitsize(d, bits)                             \
    (((d) && (d)->arch.pv.physaddr_bitsize)                             \
     ? min_t(uint32_t, (d)->arch.pv.physaddr_bitsize, bits) : bits)

... this representation alone demonstrates that what d points to is only ever read.

Yes, there are cases where the situation is more complex, and where I can see how my pov may not be shared by others. Yet still - can you point me to a written form of the supposed agreement among maintainers? Imo something like this, which has been controversial for a long time, really needs recording in ./CODING_STYLE or docs/process/coding-best-practices.pandoc. And then preferably in a shape acceptable to everyone (i.e. no outright "never").

Jan

#6 lore raw
In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Grygorii Strashko
xen/arch/x86/include/asm/mm.h +0 -0
index 17ca6666a34e..128115442ecc 100644
@@ -619,9 +619,11 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 
  extern int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm);
 
Quoted 12 lines

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

Quoted 5 lines
xen/arch/x86/include/asm/mm.h +3 -2
-void domain_set_alloc_bitsize(struct domain *d);
-unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
+#ifdef CONFIG_PV32
+unsigned int domain_clamp_alloc_bitsize(const struct domain *d,
+                                        unsigned int bits);

Do not convert this, or any other domains/vcpus you see, to const.  I realise you have been given conflicting information on this point, but the maintainers as a whole agreed to not const pointers to complex objects in the general case because of the churn it creates, and the repeated examples of MISRA violations people have inserted to work around the fact it shouldn't have been a const pointer to start with.

It's pure and simple RO function that's why I added const.

Quoted 3 lines

That aside, I think clamp wants to be a static inline here.  (Except it can't be, so it needs to be a macro).

Sorry, why "can't be" static inline?

Quoted 82 lines

It's currently a concrete function call to very simple piece of logic, where the callers have options to eliminate it entirely in the d = NULL case if they could only see in.

#define domain_clamp_alloc_bitsize(d, bits)                             \
    (((d) && (d)->arch.pv.physaddr_bitsize)                             \
     ? min_t(uint32_t, (d)->arch.pv.physaddr_bitsize, bits) : bits)

seems to work.  The min_t() is because all callers pass in bits as a long constant, tripping the typecheck in min().

Quoted 9 lines
xen/arch/x86/include/asm/mm.h +1 -0
+#endif
 
  unsigned long domain_get_maximum_gpfn(struct domain *d);
 
xen/arch/x86/pv/dom0_build.c +0 -0
index 21158ce1812e..e4f95d8f2fc8 100644

xen/arch/x86/pv/dom0_build.c static int __init dom0_construct(const struct boot_domain *bd) · line 630

Quoted 5 lines
xen/arch/x86/pv/dom0_build.c +0 -2
@@ -626,8 +626,9 @@ 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)) )

While you're editing this, blank line here please.

Quoted 34 lines
xen/arch/x86/pv/dom0_build.c +4 -0
+#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 +651,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 +12 -0
index 9c4785c187dd..ad40a712ac5f 100644
@@ -230,6 +230,29 @@ unsigned long pv_make_cr4(const struct vcpu *v)
  }
 
  #ifdef CONFIG_PV32
+unsigned int domain_clamp_alloc_bitsize(const struct domain *d,
+                                        unsigned int bits)
+{
+    if ( (d == NULL) || (d->arch.pv.physaddr_bitsize == 0) )
+        return bits;
+
+    return min(d->arch.pv.physaddr_bitsize, bits);
+}
+
+static void domain_set_alloc_bitsize(struct domain *d)
+{
+    if ( !is_pv_32bit_domain(d) ||

xen/arch/x86/pv/domain.c unsigned long pv_make_cr4(const struct vcpu *v) · line 254

Quoted 10 lines
xen/arch/x86/pv/domain.c +10 -0
+         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||
+         d->arch.pv.physaddr_bitsize > 0 )
+        return;
+
+    d->arch.pv.physaddr_bitsize =
+        /* 2^n entries can be contained in guest's p2m mapping space */
+        fls(MACH2PHYS_COMPAT_NR_ENTRIES(d)) - 1
+        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
+        + PAGE_SHIFT;
+}

The single caller has just set d->arch.pv.is_32bit = true, but the compiler can't eliminate the first condition because of the embedded evaluate_nospec().  Nor the 3rd condition, because it can't reason about the singleton nature of switch_compat().

Thus, it would be better inlined fully, as:

Quoted 8 lines

    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page ) 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;

which is rather easier to follow.  Even the comment about PAGE_SHIFT is more noise than help.

To clarify my understanding - you wanna drop domain_set_alloc_bitsize and inline code in switch_compat(), right?

Quoted 7 lines

In an ideal world it ought to be in its own patch, and in principle I'm happy to draft one with a fuller explanation if you'd prefer, but given the repositioning of physaddr_bitsize into pv domain as wekk, it's probably all better together in this single patch.

~Andrew

Signature · 2 lines
Best regards,
-grygorii
#7 lore raw
In reply to Grygorii Strashko
Quoted 6 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

1) arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro
2) add generic domain_clamp_alloc_bitsize() macro and clean up !x86 arches
3) move d->arch.physaddr_bitsize field handling to pv32 code

Quoted 8 lines

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

Grygorii Strashko (3):
arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro xen/mm: add generic domain_clamp_alloc_bitsize() macro

These two should be merged.  You also need to CC the ARM/PPC/RISC-V maintainers.

~Andrew

#8 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

1) arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro
2) add generic domain_clamp_alloc_bitsize() macro and clean up !x86 arches
3) move d->arch.physaddr_bitsize field handling to pv32 code

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

Quoted 5 lines
Quoted 3 lines

Grygorii Strashko (3):
arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro xen/mm: add generic domain_clamp_alloc_bitsize() macro

These two should be merged.

Why? They're dealing with two separate macros / functions ("set" vs "clamp").

Jan

#9 lore raw
In reply to Andrew Cooper
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

1) arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro
2) add generic domain_clamp_alloc_bitsize() macro and clean up !x86 arches
3) move d->arch.physaddr_bitsize field handling to pv32 code

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

Quoted 6 lines
Quoted 3 lines

Grygorii Strashko (3):
arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro xen/mm: add generic domain_clamp_alloc_bitsize() macro

These two should be merged.  You also need to CC the ARM/PPC/RISC-V maintainers.

Omg. missed to drop supress-cc=all :( will resend with patch 3 updated.

Signature · 2 lines
Best regards,
-grygorii
Acked-by on the v2 series
#10 lore raw
In reply to Grygorii Strashko
Quoted 6 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

1) arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro
2) add generic domain_clamp_alloc_bitsize() macro and clean up !x86 arches
3) move d->arch.physaddr_bitsize field handling to pv32 code

Quoted 8 lines

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

Grygorii Strashko (3):
arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro xen/mm: add generic domain_clamp_alloc_bitsize() macro

As I'm happy with these two being separate:

But of course Andrew's objection needs dealing with before they can go in. And as he said, at least Arm maintainers need Cc-ing for them to actually be aware that their ack is going to be needed.

Jan

Quoted 13 lines

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

 xen/arch/arm/include/asm/mm.h     |  3 ---
 xen/arch/ppc/include/asm/mm.h     |  3 ---
 xen/arch/riscv/include/asm/mm.h   |  3 ---
 xen/arch/x86/include/asm/domain.h |  8 +++++---
 xen/arch/x86/include/asm/mm.h     |  7 +++++--
 xen/arch/x86/pv/dom0_build.c      |  6 ++++--
 xen/arch/x86/pv/domain.c          | 23 +++++++++++++++++++++++
 xen/arch/x86/x86_64/mm.c          | 20 --------------------
 xen/include/xen/mm.h              |  4 ++++
 9 files changed, 41 insertions(+), 36 deletions(-)