Skip to contentSkip to conversation

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

PATCH Superseded Grygorii Strashko 6 participants 17 messages Nov 28, 2025 – Dec 9, 2025 RISC-V

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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 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

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     |  8 ++++++--
 xen/arch/x86/pv/dom0_build.c      |  7 +++++--
 xen/arch/x86/pv/domain.c          |  6 +++++-
 xen/arch/x86/x86_64/mm.c          | 20 --------------------
 xen/include/xen/mm.h              |  4 ++++
 9 files changed, 25 insertions(+), 37 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 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.

---
v3: no changes, added tag

 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
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro

Hi Grygorii,

Quoted 7 lines · Grygorii Strashko

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.

Quoted 6 lines

---
v3: no changes, added tag

xen/arch/arm/include/asm/mm.h | 1 -

Looks good to me:

Cheers,
Luca

Reviewed-by on v3 1/3
#3 lore raw

Re: [PATCH v3 1/3] arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro

In reply to Grygorii Strashko
Quoted 44 lines · Grygorii Strashko

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.

---
v3: no changes, added tag

  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 -0
index 9283616c0224..11e9f26bf0a5 100644

xen/arch/riscv/include/asm/mm.h static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr) · line 297

Quoted 7 lines
xen/arch/riscv/include/asm/mm.h +0 -1
@@ -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)

LGTM:

Thanks.

~ Oleksii

Acked-by on v3 1/3
#4 lore raw

Re: [PATCH v3 1/3] arm/ppc/riscv: drop unused domain_set_alloc_bitsize() macro

In reply to Grygorii Strashko
Quoted 7 lines · Grygorii Strashko

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.

~Michal

#5 lore raw

PATCH v3 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.

---
v3: no changes, added tag

 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
Reviewed-by on v3 2/3
#6 lore raw

Re: [PATCH v3 2/3] xen/mm: add generic domain_clamp_alloc_bitsize() macro

Hi Grygorii,

Quoted 7 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

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

Quoted 6 lines

---
v3: no changes, added tag

xen/arch/arm/include/asm/mm.h | 2 --

Looks ok to me:

Cheers,
Luca

Reviewed-by on v3 2/3
#7 lore raw

Re: [PATCH v3 2/3] xen/mm: add generic domain_clamp_alloc_bitsize() macro

In reply to Grygorii Strashko
Quoted 73 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

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

---
v3: no changes, added tag

  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 +0 -0
index b968f47b87e0..426362adb2f4 100644

xen/include/xen/mm.h static inline void put_page_alloc_ref(struct page_info *page) · line 648

Quoted 8 lines
xen/include/xen/mm.h +4 -0
@@ -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__ */

LGTM:

Thanks.

~ Oleksii

#9 lore raw

PATCH v3 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 and inline it into switch_compat()
- move domain_clamp_alloc_bitsize() function into PV32 code and convert to macro
- move d->arch.physaddr_bitsize field under PV32 ifdef into struct pv_domain

---
changes in v3:
- domain_set_alloc_bitsize() inlined.
Note change of condition to "(MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page)"
- domain_clamp_alloc_bitsize() convert to macro

 xen/arch/x86/include/asm/domain.h |  8 +++++---
 xen/arch/x86/include/asm/mm.h     |  9 ++++++---
 xen/arch/x86/pv/dom0_build.c      |  7 +++++--
 xen/arch/x86/pv/domain.c          |  6 +++++-
 xen/arch/x86/x86_64/mm.c          | 20 --------------------
 5 files changed, 21 insertions(+), 29 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 +6 -3
index 17ca6666a34e..a308a98df2a4 100644
@@ -619,9 +619,12 @@ 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);
-#define domain_clamp_alloc_bitsize(d, bits) domain_clamp_alloc_bitsize(d, bits)
+#ifdef CONFIG_PV32
+#define domain_clamp_alloc_bitsize(d, bits)                                    \
+    (((d) && (d)->arch.pv.physaddr_bitsize)                                    \
+         ? min_t(uint32_t, (d)->arch.pv.physaddr_bitsize, (bits))              \
+         : (bits))
+#endif
 
 unsigned long domain_get_maximum_gpfn(struct domain *d);
 
xen/arch/x86/pv/dom0_build.c +5 -2
index 21158ce1812e..94f7976e819f 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 +5 -1
index 9c4785c187dd..d58e4e213e5c 100644
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
             goto undo_and_fail;
     }
 
-    domain_set_alloc_bitsize(d);
+    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;
+
     recalculate_cpuid_policy(d);
 
     d->arch.x87_fip_width = 4;
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
#10 lore raw
Quoted 4 lines · Grygorii Strashko
xen/arch/x86/include/asm/mm.h +0 -0
@@ -619,9 +619,12 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 

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

Quoted 10 lines
xen/arch/x86/include/asm/mm.h +5 -3
 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)
+#ifdef CONFIG_PV32
+#define domain_clamp_alloc_bitsize(d, bits)                                    \
+    (((d) && (d)->arch.pv.physaddr_bitsize)                                    \
+         ? min_t(uint32_t, (d)->arch.pv.physaddr_bitsize, (bits))              \
+         : (bits))

I'm not quite sure if converting to a macro was a good idea. But now that it's done this way, so be it. Just that a couple of issues may want / need sorting:
- d is now evaluated up to 3 times,
- indentation is wrong,
- the use of uint32_t is against ./CODING_STYLE (I dislike the use of min_t() anyway, but what do you do when a macro was asked for; of course we could [easily] arrange for BITS_PER_LONG to be of type "unsigned int"),
- the use of "bits" in min_t() doesn't really need parentheses.

xen/arch/x86/pv/domain.c int switch_compat(struct domain *d) · line 257

Quoted 8 lines
xen/arch/x86/pv/domain.c +1 -1
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
             goto undo_and_fail;
     }
 
-    domain_set_alloc_bitsize(d);
+    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )

You mention the change in condition in the revlog (but not in the description), and I'm having trouble to follow why ...

xen/arch/x86/x86_64/mm.c unmap: · line 1126

Quoted 11 lines
xen/arch/x86/x86_64/mm.c +0 -5
@@ -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 )

... this 3rd part is going away.

Jan

#11 lore raw
Quoted 16 lines · Jan Beulich
Quoted 4 lines · Grygorii Strashko
xen/arch/x86/include/asm/mm.h +0 -0
@@ -619,9 +619,12 @@ void __iomem *ioremap_wc(paddr_t pa, size_t len);
 

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

Quoted 10 lines
xen/arch/x86/include/asm/mm.h +5 -3
  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)
+#ifdef CONFIG_PV32
+#define domain_clamp_alloc_bitsize(d, bits)                                    \
+    (((d) && (d)->arch.pv.physaddr_bitsize)                                    \
+         ? min_t(uint32_t, (d)->arch.pv.physaddr_bitsize, (bits))              \
+         : (bits))
Quoted 9 lines

I'm not quite sure if converting to a macro was a good idea. But now that it's done this way, so be it. Just that a couple of issues may want / need sorting:
- d is now evaluated up to 3 times,
- indentation is wrong,
- the use of uint32_t is against ./CODING_STYLE (I dislike the use of min_t() anyway, but what do you do when a macro was asked for; of course we could [easily] arrange for BITS_PER_LONG to be of type "unsigned int"),
- the use of "bits" in min_t() doesn't really need parentheses.

I'll update it.

Quoted 10 lines

xen/arch/x86/pv/domain.c int switch_compat(struct domain *d) · line 257

Quoted 8 lines
xen/arch/x86/pv/domain.c +1 -1
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
              goto undo_and_fail;
      }
 
-    domain_set_alloc_bitsize(d);
+    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )

You mention the change in condition in the revlog (but not in the description),

The updated chunk was based on snippet from Andrew [1], which used incorrect condition - I've changed it and noted in change log

[1] https://patchwork.kernel.org/comment/26680551/

Quoted 10 lines

and I'm having trouble to follow why ...

xen/arch/x86/x86_64/mm.c unmap: · line 1123

Quoted 8 lines
xen/arch/x86/x86_64/mm.c +0 -2
@@ -1119,26 +1119,6 @@ unmap:
      return ret;
  }
 
-void domain_set_alloc_bitsize(struct domain *d)
-{

The domain_set_alloc_bitsize() inlined in switch_compat() and x86 PV domain always created as 64bit domain.

At the beginning of switch_compat() there is:

( is_pv_32bit_domain(d) )

        return 0;

[2]
above ensures that switch_compat() can be actually called only once (at least it can reach point [2] only once, because there is no way to reset PV domain state 32bit->64bit

this is original condition which says:

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1124

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-    if ( !is_pv_32bit_domain(d) ||

do nothing if !is_pv_32bit_domain(d)
- for inlined code is_pv_32bit_domain(d) == true, so is_pv_32bit_domain(d) can be ignored

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1125

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||

do nothing if (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page)
- inlinded code should proceed if this condition is opposite (MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page)

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1126

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         d->arch.physaddr_bitsize > 0 )

do nothing if d->arch.physaddr_bitsize > 0 (already set)
- inlined code will be executed only once, so (d->arch.physaddr_bitsize ==/!= 0) can be ignored

Quoted 2 lines

... this 3rd part is going away.

Another observation: MACH2PHYS_COMPAT_NR_ENTRIES(d) is looks like a const, as (d)->arch.hv_compat_vstart is always 0.

grep -rw hv_compat_vstart ./*
./arch/x86/include/asm/config.h:#define HYPERVISOR_COMPAT_VIRT_START(d) ((d)->arch.hv_compat_vstart)
./arch/x86/include/asm/domain.h: unsigned int hv_compat_vstart;

Signature · 2 lines
Best regards,
-grygorii
#12 lore raw
Quoted 52 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich

xen/arch/x86/pv/domain.c int switch_compat(struct domain *d) · line 257

Quoted 8 lines · Grygorii Strashko
xen/arch/x86/pv/domain.c +1 -1
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
              goto undo_and_fail;
      }
 
-    domain_set_alloc_bitsize(d);
+    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )

You mention the change in condition in the revlog (but not in the description),

The updated chunk was based on snippet from Andrew [1], which used incorrect condition - I've changed it and noted in change log

[1] https://patchwork.kernel.org/comment/26680551/

Quoted 10 lines

and I'm having trouble to follow why ...

xen/arch/x86/x86_64/mm.c unmap: · line 1123

Quoted 8 lines
xen/arch/x86/x86_64/mm.c +0 -2
@@ -1119,26 +1119,6 @@ unmap:
      return ret;
  }
 
-void domain_set_alloc_bitsize(struct domain *d)
-{

The domain_set_alloc_bitsize() inlined in switch_compat() and x86 PV domain always created as 64bit domain.

At the beginning of switch_compat() there is:

( is_pv_32bit_domain(d) )

         return 0;

[2]
above ensures that switch_compat() can be actually called only once (at least it can reach point [2] only once, because there is no way to reset PV domain state 32bit->64bit

this is original condition which says:

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1124

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-    if ( !is_pv_32bit_domain(d) ||

do nothing if !is_pv_32bit_domain(d)
- for inlined code is_pv_32bit_domain(d) == true, so is_pv_32bit_domain(d) can be ignored

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1125

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||

do nothing if (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page)
- inlinded code should proceed if this condition is opposite (MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page)

Quoted 5 lines
Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1126

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         d->arch.physaddr_bitsize > 0 )

do nothing if d->arch.physaddr_bitsize > 0 (already set)
- inlined code will be executed only once, so (d->arch.physaddr_bitsize ==/!= 0) can be ignored

This is the crucial point: It being executed only once isn't spelled out anywhere in the description, and it's not entirely obvious why that would be. Yes, nowadays it is. Originally (iirc) one could switch the guest back to 64-bit mode, then again to 32-bit.

Quoted 8 lines
Quoted 1 line

... this 3rd part is going away.

Another observation: MACH2PHYS_COMPAT_NR_ENTRIES(d) is looks like a const, as (d)->arch.hv_compat_vstart is always 0.

grep -rw hv_compat_vstart ./*
./arch/x86/include/asm/config.h:#define HYPERVISOR_COMPAT_VIRT_START(d) ((d)->arch.hv_compat_vstart)
./arch/x86/include/asm/domain.h: unsigned int hv_compat_vstart;

This observation isn't directly related here, is it?

Jan

#13 lore raw
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich

xen/arch/x86/pv/domain.c int switch_compat(struct domain *d) · line 257

Quoted 8 lines · Grygorii Strashko
xen/arch/x86/pv/domain.c +1 -1
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
               goto undo_and_fail;
       }
 
-    domain_set_alloc_bitsize(d);
+    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )

You mention the change in condition in the revlog (but not in the description),

The updated chunk was based on snippet from Andrew [1], which used incorrect condition - I've changed it and noted in change log

[1] https://patchwork.kernel.org/comment/26680551/

Quoted 10 lines

and I'm having trouble to follow why ...

xen/arch/x86/x86_64/mm.c unmap: · line 1123

Quoted 8 lines
xen/arch/x86/x86_64/mm.c +0 -2
@@ -1119,26 +1119,6 @@ unmap:
       return ret;
   }
 
-void domain_set_alloc_bitsize(struct domain *d)
-{

The domain_set_alloc_bitsize() inlined in switch_compat() and x86 PV domain always created as 64bit domain.

At the beginning of switch_compat() there is:

   ( is_pv_32bit_domain(d) )
          return 0;

[2]
above ensures that switch_compat() can be actually called only once (at least it can reach point [2] only once, because there is no way to reset PV domain state 32bit->64bit

this is original condition which says:

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1124

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-    if ( !is_pv_32bit_domain(d) ||

do nothing if !is_pv_32bit_domain(d)
- for inlined code is_pv_32bit_domain(d) == true, so is_pv_32bit_domain(d) can be ignored

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1125

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||

do nothing if (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page)
- inlinded code should proceed if this condition is opposite (MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page)

Quoted 1 line
Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         d->arch.physaddr_bitsize > 0 )
Quoted 8 lines
Quoted 3 lines

do nothing if d->arch.physaddr_bitsize > 0 (already set)
- inlined code will be executed only once, so (d->arch.physaddr_bitsize ==/!= 0) can be ignored

This is the crucial point: It being executed only once isn't spelled out anywhere in the description, and it's not entirely obvious why that would be. Yes, nowadays it is. Originally (iirc) one could switch the guest back to 64-bit mode, then again to 32-bit.

I'll update description.

Or can add it back as !d->arch.physaddr_bitsize to be safe and avoid confusions?

Quoted 11 lines
Quoted 9 lines
Quoted 2 lines

... this 3rd part is going away.

Another observation: MACH2PHYS_COMPAT_NR_ENTRIES(d) is looks like a const, as (d)->arch.hv_compat_vstart is always 0.

grep -rw hv_compat_vstart ./*
./arch/x86/include/asm/config.h:#define HYPERVISOR_COMPAT_VIRT_START(d) ((d)->arch.hv_compat_vstart)
./arch/x86/include/asm/domain.h: unsigned int hv_compat_vstart;

This observation isn't directly related here, is it?

Yep. Just found it while investigated.

Signature · 2 lines
Best regards,
-grygorii
#14 lore raw
Quoted 66 lines · Grygorii Strashko
Quoted 63 lines · Jan Beulich
Quoted 61 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich

xen/arch/x86/pv/domain.c int switch_compat(struct domain *d) · line 257

Quoted 7 lines · Grygorii Strashko
xen/arch/x86/pv/domain.c +1 -0
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
                goto undo_and_fail;
        }
    -    domain_set_alloc_bitsize(d);
+    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )

You mention the change in condition in the revlog (but not in the description),

The updated chunk was based on snippet from Andrew [1], which used incorrect condition - I've changed it and noted in change log

[1] https://patchwork.kernel.org/comment/26680551/

Quoted 9 lines

and I'm having trouble to follow why ...

xen/arch/x86/x86_64/mm.c unmap: · line 1122

Quoted 7 lines
xen/arch/x86/x86_64/mm.c +0 -1
@@ -1119,26 +1119,6 @@ unmap:
        return ret;
    }
    -void domain_set_alloc_bitsize(struct domain *d)
-{

The domain_set_alloc_bitsize() inlined in  switch_compat() and x86 PV domain
always created as 64bit domain.

At the beginning of switch_compat() there is:

   ( is_pv_32bit_domain(d) )
          return 0;
[2]
above ensures that switch_compat() can be actually called only once (at least it can reach
point [2] only once, because there is no way to reset PV domain state 32bit->64bit

this is original condition which says:

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1124

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-    if ( !is_pv_32bit_domain(d) ||

do nothing if !is_pv_32bit_domain(d)
   - for inlined code is_pv_32bit_domain(d) == true, so is_pv_32bit_domain(d) can be ignored

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1125

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||

do nothing if (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page)
    - inlinded code should proceed if this condition is opposite (MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page)

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1126

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         d->arch.physaddr_bitsize > 0 )

do nothing if d->arch.physaddr_bitsize > 0 (already set)
    - inlined code will be executed only once, so (d->arch.physaddr_bitsize ==/!= 0)
      can be ignored

Quoted 6 lines
Quoted 6 lines

This is the crucial point: It being executed only once isn't spelled out anywhere in the description, and it's not entirely obvious why that would
be. Yes, nowadays it is. Originally (iirc) one could switch the guest back
to 64-bit mode, then again to 32-bit.

I changed it in 02e78311cdc6

Quoted 5 lines

I'll update description.

Or can add it back as !d->arch.physaddr_bitsize to be safe and avoid confusions?

Please update the description.  The function really is singleshot now.

I'd expect MC/DC coverage to complain at leaving the conditional in place, not that this particular codepath is going to be on the top of the list for coverage.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

... this 3rd part is going away.

Another observation: MACH2PHYS_COMPAT_NR_ENTRIES(d) is looks like a const, as
(d)->arch.hv_compat_vstart is always 0.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

grep -rw hv_compat_vstart ./* ./arch/x86/include/asm/config.h:#define HYPERVISOR_COMPAT_VIRT_START(d) ((d)->arch.hv_compat_vstart) ./arch/x86/include/asm/domain.h:    unsigned int hv_compat_vstart;

This observation isn't directly related here, is it?

Yep. Just found it while investigated.

Don't be deceived by that.  pv's dom0_construct() has

    HYPERVISOR_COMPAT_VIRT_START(d) = max_t(unsigned int, m2p_compat_vstart, value);

which hides the write.  I've been meaning to fix this for ages.

In fact, I could also submit the inlining of domain_set_alloc_bitsize() too with relevant history if you'd prefer.

~Andrew

#15 lore raw
Quoted 75 lines · Andrew Cooper
Quoted 64 lines · Grygorii Strashko
Quoted 63 lines · Jan Beulich
Quoted 61 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich

xen/arch/x86/pv/domain.c int switch_compat(struct domain *d) · line 257

Quoted 7 lines · Grygorii Strashko
xen/arch/x86/pv/domain.c +1 -0
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
                goto undo_and_fail;
        }
    -    domain_set_alloc_bitsize(d);
+    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )

You mention the change in condition in the revlog (but not in the description),

The updated chunk was based on snippet from Andrew [1], which used incorrect condition - I've changed it and noted in change log

[1] https://patchwork.kernel.org/comment/26680551/

Quoted 9 lines

and I'm having trouble to follow why ...

xen/arch/x86/x86_64/mm.c unmap: · line 1122

Quoted 7 lines
xen/arch/x86/x86_64/mm.c +0 -1
@@ -1119,26 +1119,6 @@ unmap:
        return ret;
    }
    -void domain_set_alloc_bitsize(struct domain *d)
-{

The domain_set_alloc_bitsize() inlined in  switch_compat() and x86 PV domain
always created as 64bit domain.

At the beginning of switch_compat() there is:

   ( is_pv_32bit_domain(d) )
          return 0;
[2]
above ensures that switch_compat() can be actually called only once (at least it can reach
point [2] only once, because there is no way to reset PV domain state 32bit->64bit

this is original condition which says:

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1124

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-    if ( !is_pv_32bit_domain(d) ||

do nothing if !is_pv_32bit_domain(d)
   - for inlined code is_pv_32bit_domain(d) == true, so is_pv_32bit_domain(d) can be ignored

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1125

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||

do nothing if (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page)
    - inlinded code should proceed if this condition is opposite (MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page)

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1126

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         d->arch.physaddr_bitsize > 0 )

do nothing if d->arch.physaddr_bitsize > 0 (already set)
    - inlined code will be executed only once, so (d->arch.physaddr_bitsize ==/!= 0)
      can be ignored

Quoted 6 lines
Quoted 6 lines

This is the crucial point: It being executed only once isn't spelled out anywhere in the description, and it's not entirely obvious why that would
be. Yes, nowadays it is. Originally (iirc) one could switch the guest back
to 64-bit mode, then again to 32-bit.

I changed it in 02e78311cdc6

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

I'll update description.

Or can add it back as !d->arch.physaddr_bitsize to be safe and avoid confusions?

Please update the description.  The function really is singleshot now.

+1

Jan

#16 lore raw
In reply to Andrew Cooper
Quoted 108 lines · Andrew Cooper
Quoted 66 lines · Grygorii Strashko
Quoted 63 lines · Jan Beulich
Quoted 61 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich

xen/arch/x86/pv/domain.c int switch_compat(struct domain *d) · line 257

Quoted 7 lines · Grygorii Strashko
xen/arch/x86/pv/domain.c +1 -0
@@ -254,7 +254,11 @@ int switch_compat(struct domain *d)
                goto undo_and_fail;
        }
    -    domain_set_alloc_bitsize(d);
+    if ( MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page )

You mention the change in condition in the revlog (but not in the description),

The updated chunk was based on snippet from Andrew [1], which used incorrect condition - I've changed it and noted in change log

[1] https://patchwork.kernel.org/comment/26680551/

Quoted 9 lines

and I'm having trouble to follow why ...

xen/arch/x86/x86_64/mm.c unmap: · line 1122

Quoted 7 lines
xen/arch/x86/x86_64/mm.c +0 -1
@@ -1119,26 +1119,6 @@ unmap:
        return ret;
    }
    -void domain_set_alloc_bitsize(struct domain *d)
-{

The domain_set_alloc_bitsize() inlined in  switch_compat() and x86 PV domain
always created as 64bit domain.

At the beginning of switch_compat() there is:

   ( is_pv_32bit_domain(d) )
          return 0;
[2]
above ensures that switch_compat() can be actually called only once (at least it can reach
point [2] only once, because there is no way to reset PV domain state 32bit->64bit

this is original condition which says:

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1124

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-    if ( !is_pv_32bit_domain(d) ||

do nothing if !is_pv_32bit_domain(d)
   - for inlined code is_pv_32bit_domain(d) == true, so
is_pv_32bit_domain(d) can be ignored

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1125

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||

do nothing if (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page)
    - inlinded code should proceed if this condition is opposite (MACH2PHYS_COMPAT_NR_ENTRIES(d) < max_page)

Quoted 1 line

xen/arch/x86/x86_64/mm.c unmap: · line 1126

Quoted 1 line
xen/arch/x86/x86_64/mm.c +0 -1
-         d->arch.physaddr_bitsize > 0 )

do nothing if d->arch.physaddr_bitsize > 0 (already set)
    - inlined code will be executed only once, so
(d->arch.physaddr_bitsize ==/!= 0)
      can be ignored

Quoted 6 lines
Quoted 6 lines

This is the crucial point: It being executed only once isn't spelled out anywhere in the description, and it's not entirely obvious why that would
be. Yes, nowadays it is. Originally (iirc) one could switch the guest back
to 64-bit mode, then again to 32-bit.

I changed it in 02e78311cdc6

Quoted 5 lines

I'll update description.

Or can add it back as !d->arch.physaddr_bitsize to be safe and avoid confusions?

Please update the description.  The function really is singleshot now.

I'd expect MC/DC coverage to complain at leaving the conditional in place, not that this particular codepath is going to be on the top of the list for coverage.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

... this 3rd part is going away.

Another observation: MACH2PHYS_COMPAT_NR_ENTRIES(d) is looks like a const, as
(d)->arch.hv_compat_vstart is always 0.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

grep -rw hv_compat_vstart ./* ./arch/x86/include/asm/config.h:#define HYPERVISOR_COMPAT_VIRT_START(d) ((d)->arch.hv_compat_vstart) ./arch/x86/include/asm/domain.h:    unsigned int hv_compat_vstart;

This observation isn't directly related here, is it?

Yep. Just found it while investigated.

Don't be deceived by that.  pv's dom0_construct() has

Quoted 7 lines

    HYPERVISOR_COMPAT_VIRT_START(d) = max_t(unsigned int, m2p_compat_vstart, value);

which hides the write.  I've been meaning to fix this for ages.

In fact, I could also submit the inlining of domain_set_alloc_bitsize() too with relevant history if you'd prefer.

Sorry, didn't get it - you wanna take ownership of the whole patch or part of it?

In general, I'm ok.
In the later case I'll need to handle only domain_clamp_alloc_bitsize(), right?

Signature · 2 lines
Best regards,
-grygorii