The p2m_freelist is used to allocate pages for the P2M, but to initialize
this list, domain_p2m_set_allocation() might be called.
This function is invoked in construct_domU() within the common Dom0less
code, and providing an implementation of domain_p2m_set_allocation() when
CONFIG_ARCH_PAGING_MEMPOOL=y is appropriate for RISC-V.
Additionally, implement arch_{set,get}_paging_mempool_size().
They are not used directly for now, but are required to support the
XEN_DOMCTL_{get,set}_paging_mempool_size() hypercalls.
Remove 'struct paging_domain' from RISC-V's 'struct arch_domain' when
the field is not required.
Signed-off-by: Oleksii Kurochko <[email protected]>
---
xen/arch/riscv/Kconfig | 1 +
xen/arch/riscv/Makefile | 2 +-
xen/arch/riscv/include/asm/domain.h | 2 ++
xen/arch/riscv/p2m.c | 31 +++++++++++++++++++++++++++++
4 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig
index 12b337365f1f..091510380949 100644
--- a/xen/arch/riscv/Kconfig
+++ b/xen/arch/riscv/Kconfig
@@ -1,5 +1,6 @@
config RISCV
def_bool y
+ select ARCH_PAGING_MEMPOOL
select DOMAIN_BUILD_HELPERS
select FUNCTION_ALIGNMENT_16B
select GENERIC_BUG_FRAME
diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile
index 48957104e0b5..b1514f1514a2 100644
--- a/xen/arch/riscv/Makefile
+++ b/xen/arch/riscv/Makefile
@@ -10,7 +10,7 @@ obj-y += irq.o
obj-y += kernel.o
obj-y += mm.o
obj-y += p2m.o
-obj-y += paging.o
+obj-$(CONFIG_ARCH_PAGING_MEMPOOL) += paging.o
obj-y += pt.o
obj-$(CONFIG_RISCV_64) += riscv64/
obj-y += sbi.o
diff --git a/xen/arch/riscv/include/asm/domain.h
b/xen/arch/riscv/include/asm/domain.h
index 6c48bf13111d..0caacf92b5a2 100644
--- a/xen/arch/riscv/include/asm/domain.h
+++ b/xen/arch/riscv/include/asm/domain.h
@@ -92,7 +92,9 @@ struct arch_domain {
/* Virtual MMU */
struct p2m_domain p2m;
+#ifdef CONFIG_ARCH_PAGING_MEMPOOL
struct paging_domain paging;
+#endif
};
#include <xen/sched.h>
diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c
index fba93bce24d9..886e06196ba2 100644
--- a/xen/arch/riscv/p2m.c
+++ b/xen/arch/riscv/p2m.c
@@ -1568,3 +1568,34 @@ struct page_info *get_page_from_gfn(struct domain *d,
unsigned long gfn,
return page;
}
+
+#ifdef CONFIG_ARCH_PAGING_MEMPOOL
+
+int arch_set_paging_mempool_size(struct domain *d, uint64_t size)
+{
+ unsigned long pages = PFN_DOWN(size);
+ bool preempted = false;
+ int rc;
+
+ if ( (size & ~PAGE_MASK) || /* Non page-sized request? */
+ pages != PFN_DOWN(size) ) /* 32-bit overflow? */
+ return -EINVAL;
+
+ spin_lock(&d->arch.paging.lock);
+ rc = p2m_set_allocation(d, pages, &preempted);
+ spin_unlock(&d->arch.paging.lock);
+
+ ASSERT(preempted == (rc == -ERESTART));
+
+ return rc;
+}
+
+/* Return the size of the pool, in bytes. */
+int arch_get_paging_mempool_size(struct domain *d, uint64_t *size)
+{
+ *size = (uint64_t)ACCESS_ONCE(d->arch.paging.total_pages) << PAGE_SHIFT;
+
+ return 0;
+}
+
+#endif /* CONFIG_ARCH_PAGING_MEMPOOL */
--
2.53.0