[PATCH v3 17/20] xen/riscv: implement put_page()

Oleksii Kurochko posted 20 patches 3 months ago
There is a newer version of this series
[PATCH v3 17/20] xen/riscv: implement put_page()
Posted by Oleksii Kurochko 3 months ago
Implement put_page(), as it will be used by p2m_put_code().

Although CONFIG_STATIC_MEMORY has not yet been introduced for RISC-V,
a stub for PGC_static is added to avoid cluttering the code of
put_page_nr() with #ifdefs.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
 xen/arch/riscv/include/asm/mm.h |  7 +++++++
 xen/arch/riscv/mm.c             | 25 ++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h
index 7950d132c1..b914813e52 100644
--- a/xen/arch/riscv/include/asm/mm.h
+++ b/xen/arch/riscv/include/asm/mm.h
@@ -273,6 +273,13 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)
 /* Page is Xen heap? */
 #define _PGC_xen_heap     PG_shift(2)
 #define PGC_xen_heap      PG_mask(1, 2)
+#ifdef CONFIG_STATIC_MEMORY
+/* Page is static memory */
+#define _PGC_static       PG_shift(3)
+#define PGC_static        PG_mask(1, 3)
+#else
+#define PGC_static     0
+#endif
 /* Page is broken? */
 #define _PGC_broken       PG_shift(7)
 #define PGC_broken        PG_mask(1, 7)
diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c
index 1ef015f179..3cac16f1b7 100644
--- a/xen/arch/riscv/mm.c
+++ b/xen/arch/riscv/mm.c
@@ -362,11 +362,6 @@ unsigned long __init calc_phys_offset(void)
     return phys_offset;
 }
 
-void put_page(struct page_info *page)
-{
-    BUG_ON("unimplemented");
-}
-
 void arch_dump_shared_mem_info(void)
 {
     BUG_ON("unimplemented");
@@ -627,3 +622,23 @@ void flush_page_to_ram(unsigned long mfn, bool sync_icache)
     if ( sync_icache )
         invalidate_icache();
 }
+
+void put_page(struct page_info *page)
+{
+    unsigned long nx, x, y = page->count_info;
+
+    do {
+        ASSERT((y & PGC_count_mask) >= 1);
+        x  = y;
+        nx = x - 1;
+    }
+    while ( unlikely((y = cmpxchg(&page->count_info, x, nx)) != x) );
+
+    if ( unlikely((nx & PGC_count_mask) == 0) )
+    {
+        if ( unlikely(nx & PGC_static) )
+            free_domstatic_page(page);
+        else
+            free_domheap_page(page);
+    }
+}
-- 
2.50.1
Re: [PATCH v3 17/20] xen/riscv: implement put_page()
Posted by Jan Beulich 2 months, 2 weeks ago
On 31.07.2025 17:58, Oleksii Kurochko wrote:
> Implement put_page(), as it will be used by p2m_put_code().

I would have ack-ed the code change, but the description is irritating:
Who or what is p2m_put_code() (going to be)?

> Although CONFIG_STATIC_MEMORY has not yet been introduced for RISC-V,
> a stub for PGC_static is added to avoid cluttering the code of
> put_page_nr() with #ifdefs.

There isn't any put_page_nr() being introduced (anymore), though.

Jan
Re: [PATCH v3 17/20] xen/riscv: implement put_page()
Posted by Oleksii Kurochko 2 months, 2 weeks ago
On 8/11/25 2:43 PM, Jan Beulich wrote:
> On 31.07.2025 17:58, Oleksii Kurochko wrote:
>> Implement put_page(), as it will be used by p2m_put_code().
> I would have ack-ed the code change, but the description is irritating:
> Who or what is p2m_put_code() (going to be)?

It should be p2m_put_*-related code.

>
>> Although CONFIG_STATIC_MEMORY has not yet been introduced for RISC-V,
>> a stub for PGC_static is added to avoid cluttering the code of
>> put_page_nr() with #ifdefs.
> There isn't any put_page_nr() being introduced (anymore), though.

I'll correct the commit message, it should be put_page() here.

Thanks.

~ Oleksii