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 13/15] powerpc: Add a panic test
Date: Wed, 12 Jun 2024 15:23:18 +1000	[thread overview]
Message-ID: <20240612052322.218726-14-npiggin@gmail.com> (raw)
In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com>

This adds a simple panic test for pseries and powernv that works with
TCG (unlike the s390x panic tests), making it easier to test this part
of the harness code.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 lib/powerpc/asm/rtas.h |  1 +
 lib/powerpc/rtas.c     | 16 ++++++++++++++++
 powerpc/run            |  2 +-
 powerpc/selftest.c     | 18 ++++++++++++++++--
 powerpc/unittests.cfg  |  5 +++++
 5 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/lib/powerpc/asm/rtas.h b/lib/powerpc/asm/rtas.h
index 364bf9355..2dcb2f1b3 100644
--- a/lib/powerpc/asm/rtas.h
+++ b/lib/powerpc/asm/rtas.h
@@ -26,6 +26,7 @@ extern int rtas_call(int token, int nargs, int nret, int *outputs, ...);
 extern int rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, int *outputs, ...);
 
 extern void rtas_power_off(void);
+extern void rtas_os_panic(void);
 extern void rtas_stop_self(void);
 #endif /* __ASSEMBLY__ */
 
diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c
index 9c1e0affc..98eee24f4 100644
--- a/lib/powerpc/rtas.c
+++ b/lib/powerpc/rtas.c
@@ -182,3 +182,19 @@ void rtas_power_off(void)
 	ret = rtas_call_unlocked(&args, token, 2, 1, NULL, -1, -1);
 	printf("RTAS power-off returned %d\n", ret);
 }
+
+void rtas_os_panic(void)
+{
+	struct rtas_args args;
+	uint32_t token;
+	int ret;
+
+	ret = rtas_token("ibm,os-term", &token);
+	if (ret) {
+		puts("RTAS ibm,os-term not available\n");
+		return;
+	}
+
+	ret = rtas_call_unlocked(&args, token, 1, 1, NULL, "rtas_os_panic");
+	printf("RTAS ibm,os-term returned %d\n", ret);
+}
diff --git a/powerpc/run b/powerpc/run
index 27abf1ef6..4cdc7d16c 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -56,7 +56,7 @@ fi
 
 command="$qemu -nodefaults $A $M $B $D"
 command+=" -display none -serial stdio -kernel"
-command="$(migration_cmd) $(timeout_cmd) $command"
+command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command"
 
 # powerpc tests currently exit with rtas-poweroff, which exits with 0.
 # run_qemu treats that as a failure exit and returns 1, so we need
diff --git a/powerpc/selftest.c b/powerpc/selftest.c
index 8d1a2c767..101cfcdef 100644
--- a/powerpc/selftest.c
+++ b/powerpc/selftest.c
@@ -7,6 +7,7 @@
  */
 #include <libcflat.h>
 #include <util.h>
+#include <asm/rtas.h>
 #include <asm/setup.h>
 #include <asm/smp.h>
 
@@ -47,6 +48,17 @@ static void check_setup(int argc, char **argv)
 		report_abort("missing input");
 }
 
+static void do_panic(void)
+{
+	if (machine_is_pseries()) {
+		rtas_os_panic();
+	} else {
+		/* Cause a checkstop with MSR[ME] disabled */
+		*((char *)0x10000000000) = 0;
+	}
+	report_fail("survived panic");
+}
+
 int main(int argc, char **argv)
 {
 	report_prefix_push("selftest");
@@ -57,9 +69,11 @@ int main(int argc, char **argv)
 	report_prefix_push(argv[1]);
 
 	if (strcmp(argv[1], "setup") == 0) {
-
 		check_setup(argc-2, &argv[2]);
-
+	} else if (strcmp(argv[1], "panic") == 0) {
+		do_panic();
+	} else {
+		report_abort("unknown test %s", argv[1]);
 	}
 
 	return report_summary();
diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg
index 89455b618..9e7df22f4 100644
--- a/powerpc/unittests.cfg
+++ b/powerpc/unittests.cfg
@@ -18,6 +18,11 @@ smp = 2
 extra_params = -m 1g -append 'setup smp=2 mem=1024'
 groups = selftest gitlab-ci
 
+[selftest-panic]
+file = selftest.elf
+extra_params = -append 'panic'
+groups = selftest panic gitlab-ci
+
 [selftest-migration]
 file = selftest-migration.elf
 machine = pseries
-- 
2.45.1


  parent reply	other threads:[~2024-06-12  5:33 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 ` [kvm-unit-tests PATCH v10 05/15] common/sieve: Support machines without MMU Nicholas Piggin
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 ` Nicholas Piggin [this message]
2024-06-19  7:42   ` [kvm-unit-tests PATCH v10 13/15] powerpc: Add a panic test 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-14-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).