From patchwork Wed Aug 23 07:06:56 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: 1824514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=GydaORqq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVy3G5dYRz1yg8 for ; Wed, 23 Aug 2023 17:07:54 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYhxI-0006Vq-AT; Wed, 23 Aug 2023 03:07:04 -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 1qYhxG-0006VY-Lb for qemu-devel@nongnu.org; Wed, 23 Aug 2023 03:07:02 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYhxE-00043z-SQ for qemu-devel@nongnu.org; Wed, 23 Aug 2023 03:07:02 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-31768ce2e81so4708571f8f.1 for ; Wed, 23 Aug 2023 00:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1692774419; x=1693379219; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JvqFLjsjUTfJaLVSyxitLTq0Nr1RR6VPuAyEzznU0UI=; b=GydaORqqhoj+sAjFy7p8afEBY+demOKM3Cg/wBbBrITF3g4jqHB2pRGFBK9J9xVKBK MAPpGYIUOmWWZ7MwafXKd69OaQjSwgH64aUTvCGuNdJpXE7EhQi/1uoCe4i7b68f2DRj TJ3BWHJKd2LRnVqzB0DTMJvEplDDXafvmggo3XZcDGz8gWJcR2smvVVeA/+jqOOAifst 98tEHQ4XhbRqR6qpxFk+xD0w8dJ1v6RoqE8t4pysSMdsOnc7yBUT3Z1JMwK+zxZfeTZz uhepJJN894hKnGHpOcaYrIR+IWQ1FyoTVNWtaWwv5XpqzQGuPO27YerT8jgo2ViSwjKT /E2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692774419; x=1693379219; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JvqFLjsjUTfJaLVSyxitLTq0Nr1RR6VPuAyEzznU0UI=; b=OpwCo3nV5tNOB+9DAOSLb5UEnFS29JAJOpRpsqfyajntZU6tvcHjhrXKFPc9jo1551 vDL4CbdhRyNtoVsSnb1LTB7G3rC8NPSfvZPOB7vwtV5XxxJmHHveSNOtd7aW5m4bQuOi eZ+1oAn+hKk2oOTK/QhWI/hAWNP3M4pE3v//Kp5xuY+XuS+ErCiFE6/g9djBVzbvklqg BYIPWjtT5u+wjSSBamClxl/895Ds4G18TRr31QAVeRbBMkpPYGSVa/YgDVkmHcr6PZCb svABcDXyl3Kl6RV2a5M+a6ywnUK/nR1s/ue4TmHETMTOrEPSsalvqtJ2SL6M56FbQ5PQ aDPw== X-Gm-Message-State: AOJu0Yy7bmkZJL8fVQfFUuj2qno2cSbAev5VfaLgW5SSeNiTF50I3y+0 Z413xH+08ZL6Imvdk8o59ph8FP9+WWsDusAQu9E= X-Google-Smtp-Source: AGHT+IG7x4XgWfcWuMVrSB1O5RNZFrF7vvbwlnQ/jgAIu/HiHoOhMGAuzVIgpvqnpFrQe14/0ZAIqA== X-Received: by 2002:adf:fb87:0:b0:314:1b4d:bb27 with SMTP id a7-20020adffb87000000b003141b4dbb27mr7272910wrr.64.1692774419059; Wed, 23 Aug 2023 00:06:59 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:d434:6b1d:751:97d0]) by smtp.gmail.com with ESMTPSA id c3-20020adfe703000000b0031433443265sm17924811wrm.53.2023.08.23.00.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 00:06:58 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Cl=C3=A9ment_Chigot?= , Alistair Francis Subject: [PATCH v2 1/3] hw/misc/sifive_test.c: replace exit(0) with proper shutdown Date: Wed, 23 Aug 2023 09:06:56 +0200 Message-Id: <20230823070656.363032-1-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=chigot@adacore.com; helo=mail-wr1-x42d.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This replaces the exit(0) call by a shutdown request, ensuring a proper cleanup of Qemu. Otherwise, some connections like gdb could be broken without being correctly flushed. Signed-off-by: Clément Chigot Reviewed-by: Alistair Francis --- hw/misc/sifive_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/misc/sifive_test.c b/hw/misc/sifive_test.c index 56df45bfe5..ab0674f8fe 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) { @@ -41,7 +42,8 @@ static void sifive_test_write(void *opaque, hwaddr addr, case FINISHER_FAIL: exit(code); case FINISHER_PASS: - exit(0); + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + return; case FINISHER_RESET: qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); return; From patchwork Wed Aug 23 07:07:04 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: 1824513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=QkeCfdMV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVy3D4Htwz1yg8 for ; Wed, 23 Aug 2023 17:07:52 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYhxQ-0006XK-Lj; Wed, 23 Aug 2023 03:07:12 -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 1qYhxO-0006X3-PC for qemu-devel@nongnu.org; Wed, 23 Aug 2023 03:07:10 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYhxN-00044M-1h for qemu-devel@nongnu.org; Wed, 23 Aug 2023 03:07:10 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31969580797so4716060f8f.3 for ; Wed, 23 Aug 2023 00:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1692774427; x=1693379227; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XhD97iO9Cr9UC31aJ5SoAXRsEoQS/yz+IXBL36dUT+0=; b=QkeCfdMVbNKGr09S+IC/2GgrzcZ/sL4AkI1PX7gmq146WTu91SExg51vLQo7S9pp78 x6N/rNfc+xfhFnBgT3uLnl9X63A29EFYBWjc+eezcUA0FO8mWnD5MXB3CPoVBc1m6XPH us3/LSUKi0ETSFXRlggh0Spaqig6xmZi5xD3O6V3O9C1m3td7A3p+Z3gTWH7bFswUctb ZAEnDRZF6wfNBJfPYehuHOE0Hs+5v2cG0zTNsysBP8ZuZKNNZDLhvwss1zBDmY4fsFQq RcYHeukIyyDsfG1eSOLPnmlGkC9vWTR/S46wFPrOO6K7lfYtEc/t1HBNOAuxiy8QpDib Wbuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692774427; x=1693379227; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XhD97iO9Cr9UC31aJ5SoAXRsEoQS/yz+IXBL36dUT+0=; b=U2NXwBRXz1s8/eb0o+XoEomjyp7XCula4AOFg1TjRu/pctnIB5oJF4jTaZUrEMbfV6 FbQ8UCDcBnT0Vttli7PFjRqfCjWD54RGfLQnSp/t1GFcoo1TGdkBMByWByEp2KETv4Rl B+F2SiSDcGETLrd0rvw7EuFz8MJGDAyIA93nzlo+pC+pgQgd6k+4mAM5WKD2SvoSjkAR 3Ew8FLGkwBUUeLpnhbqpAeD/JxXqAK4lGz6L3KZiSM1xaQpC8WKko7MH8XyoOedU8pKw BBSdhJiuVe21fORIRrDrF7mPdMWYQmRHGPJlCKUmh09qPAD4xPWai7M8+8b7PwJr30Im 8e8w== X-Gm-Message-State: AOJu0YzglLpXKwObo5jgR2sVvnlPhT+knZiUxlMi56oqKhb58Sxp8PWV AAnJ1oGtu6fpBwEGAlJ7QdKzh4ap5OsekMA4imo= X-Google-Smtp-Source: AGHT+IFkgUUI8BS2Ce2Cpm9VkzCGS4qcldZ1sZgkQXpFMBofifVVcTX+vINuY6E6VyA3eHHQmb2siA== X-Received: by 2002:adf:f64c:0:b0:319:77dd:61f9 with SMTP id x12-20020adff64c000000b0031977dd61f9mr8845679wrp.35.1692774427389; Wed, 23 Aug 2023 00:07:07 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:d434:6b1d:751:97d0]) by smtp.gmail.com with ESMTPSA id o1-20020a5d58c1000000b003180155493esm17750970wrf.67.2023.08.23.00.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 00:07:06 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, =?utf-8?q?Cl=C3=A9ment_Chigot?= , Alistair Francis Subject: [PATCH v2 2/3] hw/char: riscv_htif: replace exit(0) with proper shutdown Date: Wed, 23 Aug 2023 09:07:04 +0200 Message-Id: <20230823070704.363098-1-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=chigot@adacore.com; helo=mail-wr1-x432.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This replaces the exit(0) call by a shutdown request, ensuring a proper cleanup of Qemu. Otherwise, some connections like gdb could be broken without being correctly flushed. Signed-off-by: Clément Chigot Reviewed-by: Alistair Francis --- hw/char/riscv_htif.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 37d3ccc76b..c49d20a221 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,16 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) g_free(sig_data); } - exit(exit_code); + /* + * Shutdown request is a clean way to stop the QEMU, compared + * to a direct call to exit(). But we can't pass the exit code + * through it so avoid doing that when it can matter. + */ + if (exit_code) { + exit(exit_code); + } else { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } } else { uint64_t syscall[8]; cpu_physical_memory_read(payload, syscall, sizeof(syscall)); From patchwork Wed Aug 23 07:07:35 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: 1824516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=STnq6cNw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVy3x386Sz1yg8 for ; Wed, 23 Aug 2023 17:08:29 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYhy2-0006uR-NJ; Wed, 23 Aug 2023 03:07:50 -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 1qYhxw-0006l1-NJ for qemu-devel@nongnu.org; Wed, 23 Aug 2023 03:07:44 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYhxu-0004BH-6U for qemu-devel@nongnu.org; Wed, 23 Aug 2023 03:07:43 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fee769fcc3so34554465e9.2 for ; Wed, 23 Aug 2023 00:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1692774460; x=1693379260; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yyn+AiDtQ3Hy+Ma8ZvsngF4jC5rWKanopYp2FMK3k0Y=; b=STnq6cNw7gxT/JEGsvDJxFtZxL5rxe8odq5CFnI2B9AwyK9lT6XqThSxqVvlTar84s wacGLkZ1sjvQLwjfhGT67HOtkTfipH7fD9USG/TuE82uzkPTc+kfwcj8F+KR9RJhuMh5 JdOxCUVkOKoItgiGAOsjvqbgnh9Aozkny7xJr4MdYY+FtRJD2y2M4O2gwle8MmaLSsfj Lmk4vxYsB5zsqfR5fzrxoRlfYAM6HufE/VSIzncoWl+fMxhoxVfIK70G9Y6Y2qk1zAAt CJ2rvzT95GjIz7A0GquYVWkLt4H+oR08bWU96xgGqT/oDPaPPBp3Lu66JN8XPBRb8L51 +xDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692774460; x=1693379260; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yyn+AiDtQ3Hy+Ma8ZvsngF4jC5rWKanopYp2FMK3k0Y=; b=T4+WBbMXGJqMMWbBXqaQ5f6tDr4hQ/u64LetcThyO4Yr1zPC7n1pN/vAQbBRgE+z0q xtzWLCH6rHDyH1bC7hFCnwLpPgOpctteC0/ViafuljRk3W7+V82opfWHwxHmoA87ha3W E/9dJYwiJ360d9mugPL4Uxi9uHxWBGdjoc2a7z2RI/JLkwUZHhsS6O+klHPOaN5sCyqn 6tVO+g0ABEOxzT3daSJ++BvdL//jgC6FzwAJUC0tEFfegQxQHyKeQunZT3rgeRsIxw3k y1jAhnYVTu/Ez/culsHorF5fnq2f07NXE9a0FvkBQ5eC0z6CQ+BbQH90k9oQpY6I0LFW vkMQ== X-Gm-Message-State: AOJu0YyABPet+p8yx6CG+TFBmoRrPMFUiOM1cUyHy9L6BHWPLHStLP8K OCt5ClzZBj1SQr5qRuzkvJYquRSquEQ/jdWsARc= X-Google-Smtp-Source: AGHT+IEodKnO8s5kjTfbhns2xVuRnYu8jqBl4hnnmLBIa//LVPsMBU6atS7OpUmXBbqczJYeV4wWRA== X-Received: by 2002:a05:600c:b42:b0:3fe:d780:4f7a with SMTP id k2-20020a05600c0b4200b003fed7804f7amr9109813wmr.3.1692774459979; Wed, 23 Aug 2023 00:07:39 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:d434:6b1d:751:97d0]) by smtp.gmail.com with ESMTPSA id 15-20020a05600c028f00b003fee8793911sm11887739wmk.44.2023.08.23.00.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 00:07:39 -0700 (PDT) From: =?utf-8?q?Cl=C3=A9ment_Chigot?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, peter.maydell@linaro.org, =?utf-8?q?Cl=C3=A9ment_?= =?utf-8?q?Chigot?= Subject: [PATCH v2 3/3] gdbstub: replace exit(0) with proper shutdown Date: Wed, 23 Aug 2023 09:07:35 +0200 Message-Id: <20230823070735.363197-1-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=chigot@adacore.com; helo=mail-wm1-x32f.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This replaces the exit(0) call by a shutdown request, ensuring a proper cleanup of Qemu. Otherwise, some connections could be broken without being correctly flushed. Signed-off-by: Clément Chigot Acked-by: Alistair Francis --- gdbstub/gdbstub.c | 3 +-- gdbstub/softmmu.c | 13 +++++++++++++ gdbstub/user.c | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 5f28d5cf57..358eed1935 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1298,7 +1298,6 @@ 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); } static const GdbCmdParseEntry gdb_v_commands_table[] = { @@ -1818,7 +1817,7 @@ static int gdb_handle_packet(const char *line_buf) /* Kill the target */ error_report("QEMU: Terminated via GDBstub"); gdb_exit(0); - exit(0); + break; case 'D': { static const GdbCmdParseEntry detach_cmd_desc = { diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index f509b7285d..fa9b09537d 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -434,6 +434,19 @@ void gdb_exit(int code) } qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); + + /* + * Shutdown request is a clean way to stop the QEMU, compared + * to a direct call to exit(). But we can't pass the exit code + * through it so avoid doing that when it can matter. + * As this function is also called during the cleanup process, + * avoid sending the request if one is already set. + */ + if (code) { + exit(code); + } else if (!qemu_shutdown_requested_get()) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } } /* diff --git a/gdbstub/user.c b/gdbstub/user.c index 5b375be1d9..f3d97d621f 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -113,6 +113,8 @@ void gdb_exit(int code) gdb_put_packet(buf); gdbserver_state.allow_stop_reply = false; } + + exit(code); } int gdb_handlesig(CPUState *cpu, int sig)