xen/riscv: don't decrement total_pages on failed paging_alloc_page()
PATCH 1/1 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.
--- xen/arch/riscv/paging.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/riscv/paging.c +2 -1
@@ -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;
Signature · 1 line
2.56.1
Quoted 11 lines · Oleksii Kurochko
paging_alloc_page()unconditionally decrementsd->arch.paging.total_pages, even when the freelist is empty andpage_list_remove_head()returns NULL. In that case the counter underflows, soarch_get_paging_mempool_size()reports a bogus pool size and subsequentpaging_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 <[email protected]>
Quoted 29 lines · Oleksii Kurochko
paging_alloc_page()unconditionally decrementsd->arch.paging.total_pages, even when the freelist is empty andpage_list_remove_head()returns NULL. In that case the counter underflows, soarch_get_paging_mempool_size()reports a bogus pool size and subsequentpaging_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 <[email protected]>--- xen/arch/riscv/paging.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)xen/arch/riscv/paging.c +2
-1@@ -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;