[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/riscv: don't decrement total_pages on failed paging_alloc_page()



paging_alloc_page() unconditionally decrements d->arch.paging.total_pages,
even when the freelist is empty and page_list_remove_head() returns NULL.
In that case the counter underflows, so arch_get_paging_mempool_size()
reports a bogus pool size and subsequent paging_freelist_adjust() calls
operate on a wrong page count.

Only decrement the counter when a page was actually taken from the
freelist.

Fixes: af87a609c79d ("xen/riscv: implement p2m_next_level()")
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
---
 xen/arch/riscv/paging.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xen/arch/riscv/paging.c b/xen/arch/riscv/paging.c
index 35f572689a7c..6464c7ce68a6 100644
--- a/xen/arch/riscv/paging.c
+++ b/xen/arch/riscv/paging.c
@@ -120,7 +120,8 @@ struct page_info *paging_alloc_page(struct domain *d)
 
     spin_lock(&d->arch.paging.lock);
     pg = page_list_remove_head(&d->arch.paging.freelist);
-    d->arch.paging.total_pages--;
+    if ( pg )
+        d->arch.paging.total_pages--;
     spin_unlock(&d->arch.paging.lock);
 
     return pg;
-- 
2.56.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.