[kvm-unit-tests PATCH v10 05/15] common/sieve: Support machines without MMU
Nicholas Piggin
npiggin at gmail.com
Wed Jun 12 15:23:10 AEST 2024
Not all powerpc CPUs provide MMU support. Define vm_available() that is
true by default but archs can override it. Use this to run VM tests.
Reviewed-by: Thomas Huth <thuth at redhat.com>
Reviewed-by: Andrew Jones <andrew.jones at linux.dev>
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
common/sieve.c | 14 ++++++++------
lib/ppc64/asm/mmu.h | 1 -
lib/ppc64/mmu.c | 2 +-
lib/vmalloc.c | 7 +++++++
lib/vmalloc.h | 2 ++
5 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/common/sieve.c b/common/sieve.c
index 8fe05ef13..db084691a 100644
--- a/common/sieve.c
+++ b/common/sieve.c
@@ -40,12 +40,14 @@ int main(void)
printf("starting sieve\n");
test_sieve("static", static_data, STATIC_SIZE);
- setup_vm();
- test_sieve("mapped", static_data, STATIC_SIZE);
- for (i = 0; i < 3; ++i) {
- v = malloc(VSIZE);
- test_sieve("virtual", v, VSIZE);
- free(v);
+ if (vm_available()) {
+ setup_vm();
+ test_sieve("mapped", static_data, STATIC_SIZE);
+ for (i = 0; i < 3; ++i) {
+ v = malloc(VSIZE);
+ test_sieve("virtual", v, VSIZE);
+ free(v);
+ }
}
return 0;
diff --git a/lib/ppc64/asm/mmu.h b/lib/ppc64/asm/mmu.h
index 32f1abab6..2bf94e498 100644
--- a/lib/ppc64/asm/mmu.h
+++ b/lib/ppc64/asm/mmu.h
@@ -4,7 +4,6 @@
#include <asm/pgtable.h>
-bool vm_available(void);
bool mmu_enabled(void);
void mmu_enable(pgd_t *pgtable);
void mmu_disable(void);
diff --git a/lib/ppc64/mmu.c b/lib/ppc64/mmu.c
index 9e62cc800..6f9f4130f 100644
--- a/lib/ppc64/mmu.c
+++ b/lib/ppc64/mmu.c
@@ -23,7 +23,7 @@
static pgd_t *identity_pgd;
-bool vm_available(void)
+bool vm_available(void) /* weak override */
{
return cpu_has_radix;
}
diff --git a/lib/vmalloc.c b/lib/vmalloc.c
index 572682576..cf2ef7a70 100644
--- a/lib/vmalloc.c
+++ b/lib/vmalloc.c
@@ -206,10 +206,17 @@ void init_alloc_vpage(void *top)
spin_unlock(&lock);
}
+bool __attribute__((__weak__)) vm_available(void)
+{
+ return true;
+}
+
void __setup_vm(void *opaque)
{
phys_addr_t base, top;
+ assert_msg(vm_available(), "Virtual memory not available. Must check vm_available() before calling setup_vm()");
+
if (alloc_ops == &vmalloc_ops)
return;
diff --git a/lib/vmalloc.h b/lib/vmalloc.h
index 0269fdde9..e81be39f4 100644
--- a/lib/vmalloc.h
+++ b/lib/vmalloc.h
@@ -17,6 +17,8 @@ extern void setup_vm(void);
/* As above, plus passes an opaque value to setup_mmu(). */
extern void __setup_vm(void *opaque);
+/* common/ tests must check availability before calling setup_vm() */
+extern bool vm_available(void);
/* Set up paging */
extern void *setup_mmu(phys_addr_t top, void *opaque);
/* Walk the page table and resolve the virtual address to a physical address */
--
2.45.1
More information about the Linuxppc-dev
mailing list