From nobody Tue Apr 7 03:50:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88296ECAAD1 for ; Wed, 31 Aug 2022 18:26:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbiHaS0i (ORCPT ); Wed, 31 Aug 2022 14:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232855AbiHaSZi (ORCPT ); Wed, 31 Aug 2022 14:25:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26E15FC30B for ; Wed, 31 Aug 2022 11:21:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 93ADA61CE3 for ; Wed, 31 Aug 2022 18:21:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89F5FC4314A; Wed, 31 Aug 2022 18:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661970110; bh=ji7Ed4q5NuKbjIkgjEFzkBepKawEfl7hcBFRLDYPOOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jH5dGoI7dwzUvb9xbHnxXkdaEdEXKojiLHWsoVR+4UKLEFsutoqcSf/aLlBTn1RAb XZOagUdC7E/VQz6YnquoLWV/D2+MlmKScQrKDqT3qjrQ/FH2KttbbUby/gUxS03P6e eTXw/oVMp4c8QrnBabSALBpCIxcbU0InjC4PTZRUrmhHAY9hHtdmAzBuLaWzmOjUHE 8BlFqmVmbRcTDFBm4f/kGBc4PdN2sVebVp74GBXYgxhi1cjwIdCi6vzsouqO8HONle 4hcGt+cwtSCcrjXVe19CN8J2Rrcqwn0bV1YUTPCnchrTq2zuqsCxrJh/nEIMFf0faX CPPrAxV66jDDw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E24F55C0AAE; Wed, 31 Aug 2022 11:21:49 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@fb.com, w@lwt.eu, Willy Tarreau , "Paul E . McKenney" Subject: [PATCH nolibc 09/18] selftests/nolibc: on x86, support exiting with isa-debug-exit Date: Wed, 31 Aug 2022 11:21:39 -0700 Message-Id: <20220831182148.2698489-11-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20220831182113.GA2697286@paulmck-ThinkPad-P17-Gen-1> References: <20220831182113.GA2697286@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Willy Tarreau 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=3D=3D1. 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 Signed-off-by: Paul E. McKenney --- 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/s= elftests/nolibc/nolibc-test.c index 291d96bfd7c12..eeb254749239c 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 =3D=3D 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) =3D=3D 0) + asm volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0)); + /* if it does nothing, fall back to the regular panic */ +#endif } =20 printf("Exiting with status %d\n", !!ret); --=20 2.31.1.189.g2e36527f23