[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220719214449.2520-11-w@1wt.eu>
Date: Tue, 19 Jul 2022 23:44:41 +0200
From: Willy Tarreau <w@....eu>
To: "Paul E . McKenney" <paulmck@...nel.org>
Cc: Pranith Kumar <bobby.prani@...il.com>,
Alviro Iskandar Setiawan <alviro.iskandar@...weeb.org>,
Ammar Faizi <ammarfaizi2@...weeb.org>,
David Laight <David.Laight@...LAB.COM>,
Mark Brown <broonie@...nel.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Shuah Khan <shuah@...nel.org>, linux-kselftest@...r.kernel.org,
linux-kernel@...r.kernel.org, Willy Tarreau <w@....eu>
Subject: [PATCH 09/17] selftests/nolibc: on x86, support exiting with isa-debug-exit
QEMU, when started with "-device isa-debug-exit -no-reboot" will exit
with status code 2N+1 when N is written to 0x501. This is particularly
convenient for automated tests but this is not portable. As such we
only enable this on x86_64 when pid==1. In addition, this requires an
ioperm() call but in order not to have to define arch-specific syscalls
we just perform the syscall by hand there.
Signed-off-by: Willy Tarreau <w@....eu>
---
tools/testing/selftests/nolibc/nolibc-test.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 5f2173610d03..45793b6f2244 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -638,6 +638,15 @@ int main(int argc, char **argv, char **envp)
printf("Leaving init with final status: %d\n", !!ret);
if (ret == 0)
reboot(LINUX_REBOOT_CMD_POWER_OFF);
+#if defined(__x86_64__)
+ /* QEMU started with "-device isa-debug-exit -no-reboot" will
+ * exit with status code 2N+1 when N is written to 0x501. We
+ * hard-code the syscall here as it's arch-dependent.
+ */
+ else if (my_syscall3(__NR_ioperm, 0x501, 1, 1) == 0)
+ asm volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0));
+ /* if it does nothing, fall back to the regular panic */
+#endif
}
printf("Exiting with status %d\n", !!ret);
--
2.17.5
Powered by blists - more mailing lists