From patchwork Thu Sep 7 11:26:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Patchwork-Id: 13376360 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0AC16EB8FB0 for ; Thu, 7 Sep 2023 11:28:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeDAJ-0004OO-PD; Thu, 07 Sep 2023 07:27:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeDA5-0004HD-7N for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:02 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeD9z-00063p-FZ for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:00 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-401d10e3e54so8914595e9.2 for ; Thu, 07 Sep 2023 04:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694086012; x=1694690812; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kk4BYECTK9VZ3/Su8VFwEGn9G5CRlLBreIRbOvNSXRI=; b=ake7k+3jlq9Mxja2rILsu+Kq+R1BAvqZkdOe9QtDy2Zx/PDZWGKhcv/35NhT1rcAI8 jGbV7ymu9dymGurJ6hme55u4EPHkRAQ3RLZg2IPJzLXOGDEsHZRFAnmvMkmKBMsXka3e DEw6q0r7KqTQQ4Ykq9h4dkD3EgHVeJ4khBnD+6+SEa3U1UX1Fqli4P3cLFUQYn4aTqUY AsevXPwhSPP1uK5UletTHmy8LiFiAdDThdcLYZFaTiXLp0gSHICt5BRcV57GIw7xBRDE ZLxxzZ+W2Gz8xd98rb6EsZ2h646Jn+BoVpEGtfz97i+sr/lLBltjpWgC+dUxEwZVS+F7 SfgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694086012; x=1694690812; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kk4BYECTK9VZ3/Su8VFwEGn9G5CRlLBreIRbOvNSXRI=; b=RpA4lCPr+RoR7Ko+j9ix+a3+rJ6wBAOpgumECN9ybwxRpPTY2okecKa9jPGabfrAkB Fb7siqQn/59f0/gdeicyCOVai07uJ2q5kqzbe9rouGMvQ+u0jJaH46JqJDM/adVTyBSK P+c66QrvtJ31t5U4HlRFBqtR5a0bugxKC39X2UNwxI5wR6DEUuIEDtr1GWW0ejDsZGzE I9aykbHGVtou8JoCWoBTiey9MBVGXBhW4yMQan4kk3Fet3KqjjOQ/Y5nJbJocLLw0P1i LeHNDLjGu45gt9VcMOdX18PWAkdqvnKrgIgOE9c8bRkMufK38J+B12c1Jo12LDW7NXnN XYtw== X-Gm-Message-State: AOJu0Yz86fGYvcSdORuslGyrdNzZxnu6vfs4J1Wo2VkNoV4kJh7mT10N Nr5eOVzaZKcnYjoqNzNkPPDTy9P1hYKYcEWA95Y= X-Google-Smtp-Source: AGHT+IF4z9Slhz4+0IAQf1x4pT9fsld634wp+vlskJqzFSGrXWlIgawZhfT1sZVyivqZWEUagWCc+Q== X-Received: by 2002:adf:f38e:0:b0:315:8a13:ef17 with SMTP id m14-20020adff38e000000b003158a13ef17mr4726117wro.65.1694086012429; Thu, 07 Sep 2023 04:26:52 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:c2c3:52c5:8306:a161]) by smtp.gmail.com with ESMTPSA id y3-20020adfe6c3000000b00317909f9985sm22998755wrm.113.2023.09.07.04.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 04:26:52 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, peter.maydell@linaro.org, alistair23@gmail.com, =?utf-8?q?Cl=C3=A9ment_Chigot?= Subject: [PATCH v3 1/5] softmmu: add means to pass an exit code when requesting a shutdown Date: Thu, 7 Sep 2023 13:26:36 +0200 Message-Id: <20230907112640.292104-2-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230907112640.292104-1-chigot@adacore.com> References: <20230907112640.292104-1-chigot@adacore.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=chigot@adacore.com; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As of now, the exit code was either EXIT_FAILURE when a panic shutdown was requested or EXIT_SUCCESS otherwise. However, some hardware could want to pass more complex exit codes. Thus, introduce a new shutdown request function allowing that. Signed-off-by: Clément Chigot Reviewed-by: Alistair Francis --- include/sysemu/runstate.h | 2 ++ softmmu/runstate.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 7beb29c2e2..1e59e0b12b 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -61,6 +61,8 @@ void qemu_system_wakeup_request(WakeupReason reason, Error **errp); void qemu_system_wakeup_enable(WakeupReason reason, bool enabled); void qemu_register_wakeup_notifier(Notifier *notifier); void qemu_register_wakeup_support(void); +void qemu_system_shutdown_request_with_code(ShutdownCause reason, + int exit_code); void qemu_system_shutdown_request(ShutdownCause reason); void qemu_system_powerdown_request(void); void qemu_register_powerdown_notifier(Notifier *notifier); diff --git a/softmmu/runstate.c b/softmmu/runstate.c index f3bd862818..ee27e26048 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -345,6 +345,7 @@ void vm_state_notify(bool running, RunState state) static ShutdownCause reset_requested; static ShutdownCause shutdown_requested; +static int shutdown_exit_code = EXIT_SUCCESS; static int shutdown_signal; static pid_t shutdown_pid; static int powerdown_requested; @@ -624,6 +625,13 @@ void qemu_system_killed(int signal, pid_t pid) qemu_notify_event(); } +void qemu_system_shutdown_request_with_code(ShutdownCause reason, + int exit_code) +{ + shutdown_exit_code = exit_code; + qemu_system_shutdown_request(reason); +} + void qemu_system_shutdown_request(ShutdownCause reason) { trace_qemu_system_shutdown_request(reason); @@ -685,7 +693,9 @@ static bool main_loop_should_exit(int *status) if (shutdown_action == SHUTDOWN_ACTION_PAUSE) { vm_stop(RUN_STATE_SHUTDOWN); } else { - if (request == SHUTDOWN_CAUSE_GUEST_PANIC && + if (shutdown_exit_code != EXIT_SUCCESS) { + *status = shutdown_exit_code; + } else if (request == SHUTDOWN_CAUSE_GUEST_PANIC && panic_action == PANIC_ACTION_EXIT_FAILURE) { *status = EXIT_FAILURE; } From patchwork Thu Sep 7 11:26:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Patchwork-Id: 13376358 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91953CA0FF6 for ; Thu, 7 Sep 2023 11:27:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeDAF-0004LP-RV; Thu, 07 Sep 2023 07:27:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeDA5-0004HC-6s for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:02 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeD9z-00063z-GB for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:00 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31dd10c2b8bso807488f8f.3 for ; Thu, 07 Sep 2023 04:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694086013; x=1694690813; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CLRBFV9EhtGpydKvDDv3lCKaLKWsHuB0nFrWrdJFf/M=; b=gjYIo4dmNxRsY33Los0VHGldmJM7RHfgkpvsbzayEaMApL+Jt+JHQSk7pCif2VqjJn ZNmyVMeb5pHP5pHA+mczqC+88zFRe855RmjwslsHyGnqVJSvGRbHGNhG2oMZ926gRjAv 8JbQob0GtjpDHgk8u3KAF9ZELrY7god+/8JSlyR1yMbmhOL87k8p90w990N2FAS3wgrk 04cOduLd0NaM/BzP5LDYWNTRvsj+wgVnFjmieC9kFu1B43Rt/7G4k46ncj+uxxA98N6Y N7dE1poXiiYY71lOvCaoGPTRYAMwfK/6uUu31xRqQv0tS99CIb37iMuUQ1Y6Y5LiNcZ/ 0Qdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694086013; x=1694690813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CLRBFV9EhtGpydKvDDv3lCKaLKWsHuB0nFrWrdJFf/M=; b=Ph8tAmd/h7LYV2T6wHT3OjyAlYpGkbqrxFmPvMnG2X2E9WG0pcsRB7YLuXBZM4DLuX SkjEYehap6M7Dl0URTGHBTMxEpVQkrfC944zORO9Ap7D7JIyqS/c/AYYqdYO8nS8VuU2 IyGi4JmvrgW0Kw4Qxpq1G8PD6B/jalcp1wGi5GgfDY1/M2yr+jlaqxfniwMXevqZWZ9v P3glmqmmyidjongnvErk8KNgO3ectU0V2SmbaxB1z9H8N1Njt+utQPS2uBeEZ9LPWOgN xtGYVX1SbWWgYxWWFBLVx4y7Rgky6KsMWT2gcx2CR8zV9A1IGE5ZBrqykhChCY61UFLJ 1FOg== X-Gm-Message-State: AOJu0YyI8TZxFl/Ae5onQMAtcxNENevjJPWo/dANqlzoO36+Qb7PQnkP D+RmM4J5Z5txN8W9j34+ySbVaNX82kUo8F2cO/k= X-Google-Smtp-Source: AGHT+IEztf6EtQFwUzx1VOehChxj09HS/eRrmL5GSot+V2tkobbzRXz7kzDkbjv9flx3YedwIrUpjQ== X-Received: by 2002:adf:f249:0:b0:317:690e:7b39 with SMTP id b9-20020adff249000000b00317690e7b39mr4641657wrp.12.1694086013364; Thu, 07 Sep 2023 04:26:53 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:c2c3:52c5:8306:a161]) by smtp.gmail.com with ESMTPSA id y3-20020adfe6c3000000b00317909f9985sm22998755wrm.113.2023.09.07.04.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 04:26:52 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, peter.maydell@linaro.org, alistair23@gmail.com, =?utf-8?q?Cl=C3=A9ment_Chigot?= Subject: [PATCH v3 2/5] softmmu: pass the main loop status to gdb "Wxx" packet Date: Thu, 7 Sep 2023 13:26:37 +0200 Message-Id: <20230907112640.292104-3-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230907112640.292104-1-chigot@adacore.com> References: <20230907112640.292104-1-chigot@adacore.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=chigot@adacore.com; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org gdb_exit function aims to close gdb sessions and sends the exit code of the current execution. It's being called by qemu_cleanup once the main loop is over. Until now, the exit code sent was always 0. Now that hardware can shutdown this main loop with custom exit codes, these codes must be transfered to gdb as well. Signed-off-by: Clément Chigot Reviewed-by: Alistair Francis --- include/sysemu/sysemu.h | 2 +- softmmu/main.c | 2 +- softmmu/runstate.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 25be2a692e..73a37949c2 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -101,7 +101,7 @@ bool defaults_enabled(void); void qemu_init(int argc, char **argv); int qemu_main_loop(void); -void qemu_cleanup(void); +void qemu_cleanup(int); extern QemuOptsList qemu_legacy_drive_opts; extern QemuOptsList qemu_common_drive_opts; diff --git a/softmmu/main.c b/softmmu/main.c index 694388bd7f..9b91d21ea8 100644 --- a/softmmu/main.c +++ b/softmmu/main.c @@ -35,7 +35,7 @@ int qemu_default_main(void) int status; status = qemu_main_loop(); - qemu_cleanup(); + qemu_cleanup(status); return status; } diff --git a/softmmu/runstate.c b/softmmu/runstate.c index ee27e26048..d4e2e59e45 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -794,9 +794,9 @@ void qemu_init_subsystems(void) } -void qemu_cleanup(void) +void qemu_cleanup(int status) { - gdb_exit(0); + gdb_exit(status); /* * cleaning up the migration object cancels any existing migration From patchwork Thu Sep 7 11:26:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Patchwork-Id: 13376363 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 991F5EB8FB0 for ; Thu, 7 Sep 2023 11:28:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeDAM-0004SF-6C; Thu, 07 Sep 2023 07:27:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeDA8-0004IO-JS for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:05 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeD9z-00064E-Ob for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:04 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31c4d5bd69cso873376f8f.3 for ; Thu, 07 Sep 2023 04:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694086014; x=1694690814; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8OEPSyw+MdZfz0ReAADR42z8ORf1HBCMspHfxG1kMUI=; b=ADyCv4nJXVyYqAu5qgrjaLVUAdLAbXU+4Cv8I3zo7iKK2oXiRBU4x777MvtJfoquFB G7LisxH6sa1Eq+ZHGcvABY/qXTZRYtvaF+wT9VvCdaCab9gS4dCfiIrn1AApgIQ8zTh+ kUN9DhRHnUwunGCtR7bzXQNdJlrSpEI/UFiELVtuYbEP6W2k1qwaznLueXc+gv4QunOo TENDxeL84XEZXkuP8P2e2qEin3OdVQFbJ83I8kkCTK7mXiBoJ7+RWdJclLym7PXpa+Lu VojFoLpMrTx+eC/p5sz6yENWc4B2MZpJgeb7+bOFHvbdvLvWYoTsYGsyVkCJyWl9/Mgf RJ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694086014; x=1694690814; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8OEPSyw+MdZfz0ReAADR42z8ORf1HBCMspHfxG1kMUI=; b=DbFzCVCJdvUlhifOTmbAsFeNHqjn0a+M11mUqz+5plhN7rmRZmbp0gtrrpJ5MOiEFc Dk44eSMoND0AoyIGrXci8gPGqIAT+cX6kO9ITS1bX98E96/JLuId2q7Dn4MIWDAHJDbd ksBsGYQKM/YL1oiiazj28zikmDUtyJKrm1f7nkAphoRSo1Yj4Vz+ZLyVXvaNnH9GgblV V81gfAKb2+j1irxcFMQrGgQ5EIFyE1XORgrx3kxbFwztiEPvj7UPPnuriTvf8nFuBjMc FKPxUFWnaANrV1vOExQUZWgPq9D5RXeOmOoXFk0oof4UKvLZ+PjnoZbqQS9M51lREbwu DlIA== X-Gm-Message-State: AOJu0YwVM3E/tiit7U0uVBGwWBQ9KDk6Vb1VQb8kfjgpq0qrqYz7EAQZ y3xBL+45WUFP1Oe1KY7tfqbjuXqAUaJMBnx923E= X-Google-Smtp-Source: AGHT+IF0s/Sa0+JYH9lv9ACp+DwmE8jk7UcN8qOn3TQyWxt3XdQzkPMmvcEzGI1UqeW7nno48ozk4w== X-Received: by 2002:a5d:6550:0:b0:314:3fc0:ba82 with SMTP id z16-20020a5d6550000000b003143fc0ba82mr4063607wrv.37.1694086014159; Thu, 07 Sep 2023 04:26:54 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:c2c3:52c5:8306:a161]) by smtp.gmail.com with ESMTPSA id y3-20020adfe6c3000000b00317909f9985sm22998755wrm.113.2023.09.07.04.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 04:26:53 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, peter.maydell@linaro.org, alistair23@gmail.com, =?utf-8?q?Cl=C3=A9ment_Chigot?= Subject: [PATCH v3 3/5] hw/misc/sifive_test.c: replace exit calls with proper shutdown Date: Thu, 7 Sep 2023 13:26:38 +0200 Message-Id: <20230907112640.292104-4-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230907112640.292104-1-chigot@adacore.com> References: <20230907112640.292104-1-chigot@adacore.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=chigot@adacore.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This replaces the exit calls by shutdown requests, ensuring a proper cleanup of Qemu. Otherwise, some connections like gdb could be broken before its final packet ("Wxx") is being sent. This part, being done inside qemu_cleanup function, can be reached only when the main loop exits after a shutdown request. Signed-off-by: Clément Chigot Reviewed-by: Alistair Francis --- hw/misc/sifive_test.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/misc/sifive_test.c b/hw/misc/sifive_test.c index 56df45bfe5..ad688079c4 100644 --- a/hw/misc/sifive_test.c +++ b/hw/misc/sifive_test.c @@ -25,6 +25,7 @@ #include "qemu/module.h" #include "sysemu/runstate.h" #include "hw/misc/sifive_test.h" +#include "sysemu/sysemu.h" static uint64_t sifive_test_read(void *opaque, hwaddr addr, unsigned int size) { @@ -39,9 +40,13 @@ static void sifive_test_write(void *opaque, hwaddr addr, int code = (val64 >> 16) & 0xffff; switch (status) { case FINISHER_FAIL: - exit(code); + qemu_system_shutdown_request_with_code( + SHUTDOWN_CAUSE_GUEST_PANIC, code); + return; case FINISHER_PASS: - exit(0); + qemu_system_shutdown_request_with_code( + SHUTDOWN_CAUSE_GUEST_SHUTDOWN, code); + return; case FINISHER_RESET: qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); return; From patchwork Thu Sep 7 11:26:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Patchwork-Id: 13376359 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1B78CA0FF6 for ; Thu, 7 Sep 2023 11:28:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeDAP-0004bC-6t; Thu, 07 Sep 2023 07:27:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeDA8-0004IR-RS for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:05 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeDA0-00064V-Pj for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:04 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-307d20548adso847786f8f.0 for ; Thu, 07 Sep 2023 04:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694086015; x=1694690815; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Onk5iX5pAqOQQ8Z64rzCsuwWRpswOiPiPW0vWDB6iYs=; b=aEdnT2mucqGZPkpxkqcNH/diU7wS3Ykg3yvMzrPWYb839Ws3jxlxQDtlP7htzFaBh9 RzaNZAj9SyJozG1SZia5fu7XhpGFow41Twz0jPLK/mkUT9y6tZOMC+5m0C6Gt04UBaq5 mMDwkzeWASEoT2dalgP05AcC8RhzI0wUJhb/lQyds95yB8ysSOyOno9+5i5h4rHjPck3 7+7ibOnAokpn4QgKfCPSDEfGlyPJvkJZJ/KTlzxL2j0927me+UdkexaeDC3X+HtU2HOR K/4o3vr79GyIIhsM9g4kMS5He7Apq6PiMK98oh1gcWk0aeWorU3CsHeNfwTy8p5fc3Rk S6Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694086015; x=1694690815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Onk5iX5pAqOQQ8Z64rzCsuwWRpswOiPiPW0vWDB6iYs=; b=H5uyzNvlmdxFRnTpr5iOZFelw3GBDppi1AAaAedhz3xW6bafL3BlgpoG4VD+ucU1+u pnzdl6ZysNlKc/MjxSyueiBgEjX4UGW4CGnK+vov9EG+TgnTbiof7xvJ9HH/C0dZNSNR ZhYvZxb1b5h751dmyAitKd10Jvh9yCnjs+dRh7DFC2z4ahDT0Iaj3+wNPFNV3Jgjon/h 4WC8pPIHBg82645OEK5KLYjw5ZnIQndSI/K5rt1JYnJxjUwDN8mpnH33P3Gmlu8u+4br FzOkwfZ3G+Nwiz/CC/wQOt3jFF9TvkhSMaZca6Y9Kn4xKpKUpHRld2T22Jkf/3sZmxxP dVeg== X-Gm-Message-State: AOJu0YxYaliU6Daf4MUA30A2QhyMVRgPzRbPVJRq+WgHpMRwd6wcsu2u rafAKLTADxvZlQa9baGRxlEJTd9kUSoEXpzjR5Q= X-Google-Smtp-Source: AGHT+IHxHbDj6g0qxNfIf6qtXstbjqXuscneLTUuoI6CckEdLjo1l/WzKqygOYx2T+mFTDvjgaMYgQ== X-Received: by 2002:a5d:4442:0:b0:319:7b6f:4a5d with SMTP id x2-20020a5d4442000000b003197b6f4a5dmr4857309wrr.52.1694086015012; Thu, 07 Sep 2023 04:26:55 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:c2c3:52c5:8306:a161]) by smtp.gmail.com with ESMTPSA id y3-20020adfe6c3000000b00317909f9985sm22998755wrm.113.2023.09.07.04.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 04:26:54 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, peter.maydell@linaro.org, alistair23@gmail.com, =?utf-8?q?Cl=C3=A9ment_Chigot?= Subject: [PATCH v3 4/5] hw/char: riscv_htif: replace exit calls with proper shutdown Date: Thu, 7 Sep 2023 13:26:39 +0200 Message-Id: <20230907112640.292104-5-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230907112640.292104-1-chigot@adacore.com> References: <20230907112640.292104-1-chigot@adacore.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=chigot@adacore.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This replaces the exit calls by shutdown requests, ensuring a proper cleanup of Qemu. Otherwise, some connections like gdb could be broken before its final packet ("Wxx") is being sent. This part, being done inside qemu_cleanup function, can be reached only when the main loop exits after a shutdown request. Signed-off-by: Clément Chigot Reviewed-by: Alistair Francis --- hw/char/riscv_htif.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 37d3ccc76b..7e9b6fcc98 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -31,6 +31,7 @@ #include "qemu/error-report.h" #include "exec/address-spaces.h" #include "sysemu/dma.h" +#include "sysemu/runstate.h" #define RISCV_DEBUG_HTIF 0 #define HTIF_DEBUG(fmt, ...) \ @@ -205,7 +206,9 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) g_free(sig_data); } - exit(exit_code); + qemu_system_shutdown_request_with_code( + SHUTDOWN_CAUSE_GUEST_SHUTDOWN, exit_code); + return; } else { uint64_t syscall[8]; cpu_physical_memory_read(payload, syscall, sizeof(syscall)); From patchwork Thu Sep 7 11:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Patchwork-Id: 13376361 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C6BCEB8FB0 for ; Thu, 7 Sep 2023 11:28:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeDAO-0004YT-Et; Thu, 07 Sep 2023 07:27:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeDAA-0004Ig-Rc for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:08 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeDA1-00064i-Kj for qemu-devel@nongnu.org; Thu, 07 Sep 2023 07:27:06 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-31ae6bf91a9so821627f8f.2 for ; Thu, 07 Sep 2023 04:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694086016; x=1694690816; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fu41ZOpFY0zs51s8MJh4JeufHQBx0Nq8Vnk2TTW6oVM=; b=ZkY8u4wv0NdM/JrrgmPLhF7D8kA6FgyYvRMOS4YH0c8guMueWye5bfte+yOchQBPsz b9oqIBXFtmIbBs77co3hBWjX8W0XMxGcc42hNFSdUytsqW1lPLXrDe7wVMCYQFpkebK8 DBY4mcbEo0oUtnV5mlAOM3sYtP3rmaFfYzygx4MUeQAFxtSIHeWZI0VAC7CmI3TT7G2T O3eWQnE9PRgUITi4rsukhgw08bPXthHYcx47ksm8Cafjzrp2NBigWMNNLA4PoAtKK1OQ 9SuBoJIq+/CBgk+VAw7sdd6q735LgyRmGVYIN6baKD5H08GoxyC5xoCifvoke7Ksad09 j2ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694086016; x=1694690816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fu41ZOpFY0zs51s8MJh4JeufHQBx0Nq8Vnk2TTW6oVM=; b=k1gwEOtQ5oRcKBKgF6Fnwj2FCxyn7oetv8FPIpMy4TFOcvfAZM7DOba2biR7i+btkG vqrYuN9HrYSccbqaBk03/JOz7WD/9QlpfOTEnENyglZq9ftkBuSMUfalNry+qpmASkHl ESJ3cCaiFl/zVvmAtp/EPvhNy1JS2qmkKZ8feX5rA7gL53k6eKPlDAN/s7/meS5EBuQy hFgHbsu8sve08HCcO2zmvjjCfUKEx6HfB3ILnUp3le926iEAZyKZLLno7rrWcozfZ02T nk8vPMew/FadIXl1hAvoS7I//lO9ykw1KjwvAqSetc2hUieAO30MIoRABe3oMR1IFvOx W4DA== X-Gm-Message-State: AOJu0Yyi2UbudWcyHkHy+ns3NOqmbNPJDSMET4u8NnJhqiR2CK/dclqM +6Il2TlJq5iF3bzbQfywKCDYQfi59yQFgdLL1gY= X-Google-Smtp-Source: AGHT+IEJqRXiB+k5LX7rlKRtwSCHUX4SNWWixyVPROKKppXlICbCoai53J7FiVh8rmQ/91WufF0uLA== X-Received: by 2002:a5d:42d2:0:b0:318:e4c4:4981 with SMTP id t18-20020a5d42d2000000b00318e4c44981mr3923446wrr.20.1694086016044; Thu, 07 Sep 2023 04:26:56 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:c2c3:52c5:8306:a161]) by smtp.gmail.com with ESMTPSA id y3-20020adfe6c3000000b00317909f9985sm22998755wrm.113.2023.09.07.04.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 04:26:55 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, peter.maydell@linaro.org, alistair23@gmail.com, =?utf-8?q?Cl=C3=A9ment_Chigot?= Subject: [PATCH v3 5/5] gdbstub: replace exit calls with proper shutdown for softmmu Date: Thu, 7 Sep 2023 13:26:40 +0200 Message-Id: <20230907112640.292104-6-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230907112640.292104-1-chigot@adacore.com> References: <20230907112640.292104-1-chigot@adacore.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=chigot@adacore.com; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This replaces the exit calls by shutdown requests, ensuring a proper cleanup of Qemu. Features like net/vhost-vdpa.c are expecting qemu_cleanup to be called to remove their last residuals. Signed-off-by: Clément Chigot Reviewed-by: Alistair Francis --- gdbstub/gdbstub.c | 5 +++-- gdbstub/softmmu.c | 6 ++++++ gdbstub/user.c | 6 ++++++ include/gdbstub/syscalls.h | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 349d348c7b..1cb6d65306 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1327,7 +1327,7 @@ static void handle_v_kill(GArray *params, void *user_ctx) gdb_put_packet("OK"); error_report("QEMU: Terminated via GDBstub"); gdb_exit(0); - exit(0); + gdb_qemu_exit(0); } static const GdbCmdParseEntry gdb_v_commands_table[] = { @@ -1846,7 +1846,8 @@ static int gdb_handle_packet(const char *line_buf) /* Kill the target */ error_report("QEMU: Terminated via GDBstub"); gdb_exit(0); - exit(0); + gdb_qemu_exit(0); + break; case 'D': { static const GdbCmdParseEntry detach_cmd_desc = { diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index 9f0b8b5497..a5d6e04c79 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -435,6 +435,12 @@ void gdb_exit(int code) qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); } +void gdb_qemu_exit(int code) +{ + qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN, + code); +} + /* * Memory access */ diff --git a/gdbstub/user.c b/gdbstub/user.c index 7ab6e5d975..dbe1d9b887 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -113,6 +113,12 @@ void gdb_exit(int code) gdb_put_packet(buf); gdbserver_state.allow_stop_reply = false; } + +} + +void gdb_qemu_exit(int code) +{ + exit(code); } int gdb_handlesig(CPUState *cpu, int sig) diff --git a/include/gdbstub/syscalls.h b/include/gdbstub/syscalls.h index 243eaf8ce4..54ff7245a1 100644 --- a/include/gdbstub/syscalls.h +++ b/include/gdbstub/syscalls.h @@ -110,4 +110,13 @@ int use_gdb_syscalls(void); */ void gdb_exit(int code); +/** + * gdb_qemu_exit: ask qemu to exit + * @code: exit code reported + * + * This requests qemu to exit. This function is allowed to return as + * the exit request might be processed asynchronously by qemu backend. + */ +void gdb_qemu_exit(int code); + #endif /* _SYSCALLS_H_ */