Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp860236rwe; Wed, 31 Aug 2022 12:20:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR4A/ul4hw/vI5w4aoHh13pkNJGppi9wC2Wn8uDuLlfiWyY+RfXCiqZgUKrmI+rVtp1aXsLk X-Received: by 2002:a63:6b87:0:b0:41c:2fb4:24f1 with SMTP id g129-20020a636b87000000b0041c2fb424f1mr23596530pgc.452.1661973619404; Wed, 31 Aug 2022 12:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661973619; cv=none; d=google.com; s=arc-20160816; b=mWgTGaX/DdNNBf5+iydtbPhFHGp+5AI0dsinHonBthT7y5oiPxjP42gpgVje28j8tM LaCseoQQ5pAHN/F1RKQYzBxOiunokHdL4O7JXKbO75SjgApVKcK4kg2HAXg+JfrvwbNW o7RFp//b1yYzHbyzsUkQ8BreNUhYdBFij+Kl5TpD+lY+eXE/+oIoUuGqGp9IVltJHvUq QOV8+/3mLmhUn1xr0+zVCCDjk1PpRizJXgIY2Or39KgM4WfFuLc9ftBjJCfQFYNLQzU5 4qAK9+qErKAIwQOCsxTmBBTIA0yxs9XHK81tl0GJPc0V9VSe9xdWAvqODDCLaLgQrT4z YPug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yyPEt9xHiwtdAdqcYZKAGyNrTmx4Pni6+V8PJ7eIvAE=; b=aN4u+m1q2wf4BeAUnvPsrZ2sII4o7DVf1CLI91OZRjInRed/i/1Ok0rNmiu7+92Dzv u+wT12eQXXW84SqOYpxKDuWZSERGyeVeC/+a2Xkmk5PWk+bIuSLCdUhf6NE+YzRrkqkU RZI2cecIiPHm9KoB+S71cbbnbQvroPWZywpJM8jgr/HFgHdXap4BiON3LhoBQLUBCdJ6 BYpAtwpvO17gUPygCWGMjQ192JgWo5dl/e7TYASMPz108oVFWR/RrzvgkDn7O3bABZ7v wxKlMR50utAdGPX7pIC3tih8PH5TdslafpSJiDYHG3o0lrIEk3TPb/3DhUIz700h752h XLeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jH5dGoI7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t28-20020a63445c000000b0042b8b0284cfsi5278386pgk.509.2022.08.31.12.20.06; Wed, 31 Aug 2022 12:20:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jH5dGoI7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232941AbiHaS0g (ORCPT + 99 others); Wed, 31 Aug 2022 14:26:36 -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: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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==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 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/selftests/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 == 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.31.1.189.g2e36527f23