Skip to contentSkip to conversation

constrain page_is_ram_type() to x86

PATCH In review Jan Beulich 5 participants 9 messages Aug 18, 2025 – Aug 25, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover constrain page_is_ram_type() to x86

Re-worked the plain dropping of an assertion to a function rename, and then isolating of the original function to just x86.

1: Arm: drop assertion from page_is_ram_type()
2: common: make page_{is,get}_ram_type() x86-only

Jan

#1 lore raw

PATCH v2 1/2 Arm: drop assertion from page_is_ram_type()

Its uses in offline_page() and query_page_offline() make it reachable on Arm, as long as XEN_SYSCTL_page_offline_op doesn't have any Arm-specific code added. It being reachable was even mentioned in the commit introducing it, claiming it "clearly shouldn't be called on ARM just yet".

However, dropping the assertion from a function of this name is deemed problematic. Rename it to better reflect its sole purpose outside of x86-specific code.

Fixes 214c4cd94a80 ("xen: arm: stub page_is_ram_type")

---
v2: Rename the function used in common code.
---
The new name is chosen such that, down the road, offlining of non-RAM could in principle also become possible.

xen/arch/arm/mm.c +2 -3
@@ -64,10 +64,9 @@ int steal_page(
     return -EOPNOTSUPP;
 }
 
-int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
+bool page_is_offlinable(mfn_t mfn)
 {
-    ASSERT_UNREACHABLE();
-    return 0;
+    return false;
 }
 
 unsigned long domain_get_maximum_gpfn(struct domain *d)
xen/arch/x86/mm.c +5 -0
@@ -425,6 +425,11 @@ int page_is_ram_type(unsigned long mfn,
     return 0;
 }
 
+bool page_is_offlinable(mfn_t mfn)
+{
+    return page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL);
+}
+
 unsigned int page_get_ram_type(mfn_t mfn)
 {
     uint64_t last = 0, maddr = mfn_to_maddr(mfn);
xen/common/page_alloc.c +3 -3
@@ -1635,7 +1635,7 @@ static unsigned long mark_page_offline(s
 {
     unsigned long nx, x, y = pg->count_info;
 
-    ASSERT(page_is_ram_type(mfn_x(page_to_mfn(pg)), RAM_TYPE_CONVENTIONAL));
+    ASSERT(page_is_offlinable(page_to_mfn(pg)));
     ASSERT(spin_is_locked(&heap_lock));
 
     do {
@@ -1711,7 +1711,7 @@ int offline_page(mfn_t mfn, int broken,
      * N.B. xen's txt in x86_64 is marked reserved and handled already.
      * Also kexec range is reserved.
      */
-    if ( !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
+    if ( !page_is_offlinable(mfn) )
     {
         *status = PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM;
         return -EINVAL;
@@ -1851,7 +1851,7 @@ int query_page_offline(mfn_t mfn, uint32
 {
     struct page_info *pg;
 
-    if ( !mfn_valid(mfn) || !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
+    if ( !mfn_valid(mfn) || !page_is_offlinable(mfn) )
     {
         dprintk(XENLOG_WARNING, "call expand_pages() first\n");
         return -EINVAL;
xen/include/xen/mm.h +2 -0
@@ -144,9 +144,11 @@ unsigned long avail_domheap_pages_region
 unsigned long avail_node_heap_pages(unsigned int nodeid);
 #define alloc_domheap_page(d,f) (alloc_domheap_pages(d,0,f))
 #define free_domheap_page(p)  (free_domheap_pages(p,0))
+
 int online_page(mfn_t mfn, uint32_t *status);
 int offline_page(mfn_t mfn, int broken, uint32_t *status);
 int query_page_offline(mfn_t mfn, uint32_t *status);
+bool page_is_offlinable(mfn_t mfn);
 
 void heap_init_late(void);
 
#2 lore raw

Re: [PATCH v2 1/2] Arm: drop assertion from page_is_ram_type()

Quoted 10 lines · Jan Beulich

Its uses in offline_page() and query_page_offline() make it reachable on Arm, as long as XEN_SYSCTL_page_offline_op doesn't have any Arm-specific code added. It being reachable was even mentioned in the commit introducing it, claiming it "clearly shouldn't be called on ARM just yet".

However, dropping the assertion from a function of this name is deemed problematic. Rename it to better reflect its sole purpose outside of x86-specific code.

Quoted 7 lines
Fixes 214c4cd94a80 ("xen: arm: stub page_is_ram_type")

---
v2: Rename the function used in common code.
---
The new name is chosen such that, down the road, offlining of non-RAM could in principle also become possible.

I think it could be useful to put in commit message.

LGTM: Reviewed-by: Oleksii Kurochko<[email protected]>

~ Oleksii

Quoted 74 lines
xen/arch/arm/mm.c +2 -3
@@ -64,10 +64,9 @@ int steal_page(
      return -EOPNOTSUPP;
  }
 
-int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
+bool page_is_offlinable(mfn_t mfn)
  {
-    ASSERT_UNREACHABLE();
-    return 0;
+    return false;
  }
 
  unsigned long domain_get_maximum_gpfn(struct domain *d)
xen/arch/x86/mm.c +5 -0
@@ -425,6 +425,11 @@ int page_is_ram_type(unsigned long mfn,
      return 0;
  }
 
+bool page_is_offlinable(mfn_t mfn)
+{
+    return page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL);
+}
+
  unsigned int page_get_ram_type(mfn_t mfn)
  {
      uint64_t last = 0, maddr = mfn_to_maddr(mfn);
xen/common/page_alloc.c +3 -3
@@ -1635,7 +1635,7 @@ static unsigned long mark_page_offline(s
  {
      unsigned long nx, x, y = pg->count_info;
 
-    ASSERT(page_is_ram_type(mfn_x(page_to_mfn(pg)), RAM_TYPE_CONVENTIONAL));
+    ASSERT(page_is_offlinable(page_to_mfn(pg)));
      ASSERT(spin_is_locked(&heap_lock));
 
      do {
@@ -1711,7 +1711,7 @@ int offline_page(mfn_t mfn, int broken,
       * N.B. xen's txt in x86_64 is marked reserved and handled already.
       * Also kexec range is reserved.
       */
-    if ( !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
+    if ( !page_is_offlinable(mfn) )
      {
          *status = PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM;
          return -EINVAL;
@@ -1851,7 +1851,7 @@ int query_page_offline(mfn_t mfn, uint32
  {
      struct page_info *pg;
 
-    if ( !mfn_valid(mfn) || !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
+    if ( !mfn_valid(mfn) || !page_is_offlinable(mfn) )
      {
          dprintk(XENLOG_WARNING, "call expand_pages() first\n");
          return -EINVAL;
xen/include/xen/mm.h +2 -0
@@ -144,9 +144,11 @@ unsigned long avail_domheap_pages_region
  unsigned long avail_node_heap_pages(unsigned int nodeid);
  #define alloc_domheap_page(d,f) (alloc_domheap_pages(d,0,f))
  #define free_domheap_page(p)  (free_domheap_pages(p,0))
+
  int online_page(mfn_t mfn, uint32_t *status);
  int offline_page(mfn_t mfn, int broken, uint32_t *status);
  int query_page_offline(mfn_t mfn, uint32_t *status);
+bool page_is_offlinable(mfn_t mfn);
 
  void heap_init_late(void);
 
Reviewed-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] Arm: drop assertion from page_is_ram_type()

In reply to Jan Beulich
Quoted 6 lines · Jan Beulich

Its uses in offline_page() and query_page_offline() make it reachable on Arm, as long as XEN_SYSCTL_page_offline_op doesn't have any Arm-specific code added. It being reachable was even mentioned in the commit introducing it, claiming it "clearly shouldn't be called on ARM just yet".

Quoted 6 lines

However, dropping the assertion from a function of this name is deemed problematic. Rename it to better reflect its sole purpose outside of x86-specific code.

Fixes 214c4cd94a80 ("xen: arm: stub page_is_ram_type")
Acked-by on v2 1/2
#4 lore raw

Re: [PATCH v2 1/2] Arm: drop assertion from page_is_ram_type()

In reply to Jan Beulich
Quoted 6 lines · Jan Beulich

Its uses in offline_page() and query_page_offline() make it reachable on Arm, as long as XEN_SYSCTL_page_offline_op doesn't have any Arm-specific code added. It being reachable was even mentioned in the commit introducing it, claiming it "clearly shouldn't be called on ARM just yet".

Quoted 6 lines

However, dropping the assertion from a function of this name is deemed problematic. Rename it to better reflect its sole purpose outside of x86-specific code.

Fixes 214c4cd94a80 ("xen: arm: stub page_is_ram_type")

~Michal

#5 lore raw

PATCH v2 2/2 common: make page_{is,get}_ram_type() x86-only

In reply to Jan Beulich

The classification is pretty E820-centric anyway, and all uses of the function are now in x86-only code.

Switch the boolean return type to properly use bool while at it.

---
v2: New.

xen/arch/x86/include/asm/mm.h +10 -0
@@ -464,6 +464,16 @@ extern bool opt_pv_linear_pt;
     ASSERT(((_p)->count_info & PGC_count_mask) != 0);          \
     ASSERT(page_get_owner(_p) == (_d))
 
+#define RAM_TYPE_CONVENTIONAL 0x00000001
+#define RAM_TYPE_RESERVED     0x00000002
+#define RAM_TYPE_UNUSABLE     0x00000004
+#define RAM_TYPE_ACPI         0x00000008
+#define RAM_TYPE_UNKNOWN      0x00000010
+/* TRUE if the whole page at @mfn is of the requested RAM type(s) above. */
+bool page_is_ram_type(unsigned long mfn, unsigned long mem_type);
+/* Returns the page type(s). */
+unsigned int page_get_ram_type(mfn_t mfn);
+
 /******************************************************************************
  * With shadow pagetables, the different kinds of address start
  * to get get confusing.
xen/arch/x86/mm.c +3 -3
@@ -385,7 +385,7 @@ void __init arch_init_memory(void)
     ASM_CONSTANT(FIXADDR_X_SIZE, FIXADDR_X_SIZE);
 }
 
-int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
+bool page_is_ram_type(unsigned long mfn, unsigned long mem_type)
 {
     uint64_t maddr = pfn_to_paddr(mfn);
     int i;
@@ -419,10 +419,10 @@ int page_is_ram_type(unsigned long mfn,
         /* Test the range. */
         if ( (e820.map[i].addr <= maddr) &&
              ((e820.map[i].addr + e820.map[i].size) >= (maddr + PAGE_SIZE)) )
-            return 1;
+            return true;
     }
 
-    return 0;
+    return false;
 }
 
 bool page_is_offlinable(mfn_t mfn)
xen/include/xen/mm.h +0 -9
@@ -565,15 +565,6 @@ int __must_check guest_remove_page(struc
 int __must_check steal_page(struct domain *d, struct page_info *page,
                             unsigned int memflags);
 
-#define RAM_TYPE_CONVENTIONAL 0x00000001
-#define RAM_TYPE_RESERVED     0x00000002
-#define RAM_TYPE_UNUSABLE     0x00000004
-#define RAM_TYPE_ACPI         0x00000008
-#define RAM_TYPE_UNKNOWN      0x00000010
-/* TRUE if the whole page at @mfn is of the requested RAM type(s) above. */
-int page_is_ram_type(unsigned long mfn, unsigned long mem_type);
-/* Returns the page type(s). */
-unsigned int page_get_ram_type(mfn_t mfn);
 /* Check if a range falls into a hole in the memory map. */
 bool is_memory_hole(mfn_t start, mfn_t end);
 
#7 lore raw

Re: [PATCH v2 2/2] common: make page_{is,get}_ram_type() x86-only

In reply to Jan Beulich

xen/arch/x86/include/asm/mm.h extern bool opt_pv_linear_pt; · line 473

Quoted 13 lines · Jan Beulich
xen/arch/x86/include/asm/mm.h +7 -0
@@ -464,6 +464,16 @@ extern bool opt_pv_linear_pt;
     ASSERT(((_p)->count_info & PGC_count_mask) != 0);          \
     ASSERT(page_get_owner(_p) == (_d))
 
+#define RAM_TYPE_CONVENTIONAL 0x00000001
+#define RAM_TYPE_RESERVED     0x00000002
+#define RAM_TYPE_UNUSABLE     0x00000004
+#define RAM_TYPE_ACPI         0x00000008
+#define RAM_TYPE_UNKNOWN      0x00000010
+/* TRUE if the whole page at @mfn is of the requested RAM type(s) above. */
+bool page_is_ram_type(unsigned long mfn, unsigned long mem_type);

Making it x86-only is fine, but if you're changing the return type, mem_type can become shorter too.

Also, I'm struggling to convince myself that page_is_ram_type() is correct.  Even if it is correct, it is horribly inefficient, and we run this algorithm lots on boot.

Checking the type before the range is the backwards way of doing this, and it can be a binary search because we go out of our way to fix unsorted e820 maps.

Finally, acpi_memory_banned() shows that this really isn't the greatest API in the first place.  It's explicitly designed to take multiple inputs, but does the wrong thing for its' single caller wanting that behaviour.  I can't help but feel we'd be in a better position by removing this entirely and using plain E820 queries.

~Andrew

#8 lore raw

Re: [PATCH v2 2/2] common: make page_{is,get}_ram_type() x86-only

Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
xen/arch/x86/include/asm/mm.h +0 -0
@@ -464,6 +464,16 @@ extern bool opt_pv_linear_pt;
     ASSERT(((_p)->count_info & PGC_count_mask) != 0);          \
     ASSERT(page_get_owner(_p) == (_d))
 
Quoted 10 lines

xen/arch/x86/include/asm/mm.h extern bool opt_pv_linear_pt; · line 473

Quoted 7 lines
xen/arch/x86/include/asm/mm.h +7 -0
+#define RAM_TYPE_CONVENTIONAL 0x00000001
+#define RAM_TYPE_RESERVED     0x00000002
+#define RAM_TYPE_UNUSABLE     0x00000004
+#define RAM_TYPE_ACPI         0x00000008
+#define RAM_TYPE_UNKNOWN      0x00000010
+/* TRUE if the whole page at @mfn is of the requested RAM type(s) above. */
+bool page_is_ram_type(unsigned long mfn, unsigned long mem_type);

Making it x86-only is fine, but if you're changing the return type, mem_type can become shorter too.

Oh, indeed - done. Won't re-post just for this, though.

Quoted 8 lines

Also, I'm struggling to convince myself that page_is_ram_type() is correct.  Even if it is correct, it is horribly inefficient, and we run this algorithm lots on boot.

Checking the type before the range is the backwards way of doing this, and it can be a binary search because we go out of our way to fix unsorted e820 maps.

Quoted 5 lines

Finally, acpi_memory_banned() shows that this really isn't the greatest API in the first place.  It's explicitly designed to take multiple inputs, but does the wrong thing for its' single caller wanting that behaviour.  I can't help but feel we'd be in a better position by removing this entirely and using plain E820 queries.

All valid remarks, but all to be taken care of separately imo.

Jan