linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: Thomas Huth <thuth@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>,
	linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org,
	Nicholas Piggin <npiggin@gmail.com>,
	Andrew Jones <andrew.jones@linux.dev>
Subject: [kvm-unit-tests PATCH v10 05/15] common/sieve: Support machines without MMU
Date: Wed, 12 Jun 2024 15:23:10 +1000	[thread overview]
Message-ID: <20240612052322.218726-6-npiggin@gmail.com> (raw)
In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com>

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@redhat.com>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Nicholas Piggin <npiggin@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


  parent reply	other threads:[~2024-06-12  5:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12  5:23 [kvm-unit-tests PATCH v10 00/15] powerpc improvements Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 01/15] powerpc: Add facility to query TCG or KVM host Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 02/15] powerpc: Add atomics tests Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 03/15] powerpc: Add timebase tests Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 04/15] powerpc: Add MMU support Nicholas Piggin
2024-06-12  5:23 ` Nicholas Piggin [this message]
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 06/15] powerpc: Add sieve.c common test Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 07/15] powerpc: add usermode support Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 08/15] powerpc: add pmu tests Nicholas Piggin
2024-06-18 15:20   ` Thomas Huth
2024-06-18 18:39   ` Thomas Huth
2024-06-25  1:56     ` Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 09/15] configure: Make arch_libdir a first-class entity Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 10/15] powerpc: Remove remnants of ppc64 directory and build structure Nicholas Piggin
2024-06-19  7:36   ` Thomas Huth
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 11/15] powerpc: gitlab CI update Nicholas Piggin
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 12/15] scripts/arch-run.bash: Fix run_panic() success exit status Nicholas Piggin
2024-06-12  7:26   ` Andrew Jones
2024-06-14  0:56     ` Nicholas Piggin
2024-06-17 14:12       ` Andrew Jones
2024-06-17 14:13   ` Andrew Jones
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 13/15] powerpc: Add a panic test Nicholas Piggin
2024-06-19  7:42   ` Thomas Huth
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 14/15] powerpc/gitlab-ci: Upgrade powerpc to Fedora 40 Nicholas Piggin
2024-06-19  7:35   ` Thomas Huth
2024-06-12  5:23 ` [kvm-unit-tests PATCH v10 15/15] powerpc/gitlab-ci: Enable more tests with " Nicholas Piggin
2024-06-19  7:44   ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240612052322.218726-6-npiggin@gmail.com \
    --to=npiggin@gmail.com \
    --cc=andrew.jones@linux.dev \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lvivier@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).