From patchwork Tue Aug 13 20:23:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 818848 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp430398wrm; Tue, 13 Aug 2024 13:25:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWrEX1X67opLjKXplzJNR56zAuPpO0zUvbEVZC5TGjBTkJ+twJonjt5FJa4xbTk7A4y5LCSWwDrSL3c6Hg/EEJ8 X-Google-Smtp-Source: AGHT+IEGqDyAPC0MSi3ya8YxqFuFXPTbEJTkmnYDpDIOud8dbdTou+UUyads2NWQDdwC0PY/BGL0 X-Received: by 2002:a05:620a:17ab:b0:79f:aa9:b3a0 with SMTP id af79cd13be357-7a4e37b26c6mr775042985a.13.1723580716200; Tue, 13 Aug 2024 13:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723580716; cv=none; d=google.com; s=arc-20160816; b=kDMt+dJeKWKEFRFFu5zrW81aCeZT8v6YLmouAC5zUYCt7UNAyJmlYJPmahTKNw+0Hr ZKbnjVBuWAiUsqUdwZIfCoXEGvph4/matDRiFZQ2MMHNSIKBB4cV6yfLbt/ZGWnnuQW8 sxMPQHeC14fPhlgov5hHAQzUGIKJGJUnNUpssruqqf+7JqEyR5xjzey+Ttu/83mUW7wj 7s4LvwwTmkIrahuIer9jL/LHrKTO9Fg74nFjrUSGC31K7KaiFgaMxBUb1XpxvKtu2TkH NDY11vDig6d9hYwJKQQdujCHF1eVps1YPFnjlXBcgBVDOiIS+4yOc3K+6cJqzq1e+aec x90Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gKnLVSpjxmewuCirNFwcFUTWuBBv0LU3PKhxtt5azvQ=; fh=CA3M1ELZq0B3Vsyopbo2wbvGRMyzgjLkXtCvvSx9Tl4=; b=LWFEXN1TAGMqKeXZDyVeqgyaN2SzCgMH8JorIrCf8eMfSvSLXZ2M2KdHaV4fwD2p50 NZ7x2XUM55mZObhPnLFc+AYSdiYk22L1ImV0bD0GhPvgh4Q5c836A/mnNRhoTMA44dh8 j4VQLDVyxuZouGn1ppqBQOoDPTwSa1tbr9icenI2TpeyrxcnGuqXD/kb2IczMbcXWH5a GkRCxVO0Ber01Q+Cq6lO+g0hVBsJRw5I6b5g9I9o/No8R3CHhmc4hnTDZFKBufH0xPZJ C86uzlwSdSPoH0Xvrcd6fwNtNhJJ0IOHViV3ISDVNMvAYw6+I6x2jFDLM5T3S+dunLyZ dU5A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUVma06k; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4531c266b1asi93930001cf.249.2024.08.13.13.25.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Aug 2024 13:25:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUVma06k; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sdy43-0006pa-9v; Tue, 13 Aug 2024 16:24: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 1sdy3r-0005vo-EX for qemu-devel@nongnu.org; Tue, 13 Aug 2024 16:24:08 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sdy3R-0006EM-Tf for qemu-devel@nongnu.org; Tue, 13 Aug 2024 16:24:04 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2eeb1ba0481so79078591fa.2 for ; Tue, 13 Aug 2024 13:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723580620; x=1724185420; 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=gKnLVSpjxmewuCirNFwcFUTWuBBv0LU3PKhxtt5azvQ=; b=AUVma06k0D8LMAdpY2jTxZD4+BGXaRJgh52JGrvItXso7Lp47bgkyyT7EYRSGDy7+h hOfz/j//uHvnYMqrYnUy4GYCIe75u0vfXYmlSKlH/CXhBJTGr0oBUN0J/r/trrg5oTvL StuM26nUzdGUNELGrVR4va3pzAJZcx4hIpPbH9vj4QPGmel/ksuzzH/eX6KMi/Jio8mB 8jNxuswa6YlDQ2UQkeqcS/2aY+N2Aq8CI9zpcrXLDjwsEl3lwB0YbGeg7r+UpnMI166b rzkwI86Wg7MopZZo1+2OVQK1FOZfuoDVdjJdt+1xlCtQNJ6NSWPFMLWdM7beOxxumh3/ H9pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723580620; x=1724185420; 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=gKnLVSpjxmewuCirNFwcFUTWuBBv0LU3PKhxtt5azvQ=; b=buvlBkOVThyCywVx4838wxU1QGMHfCsiaGafa2ei8NyiDXD/0e8OeHWyrEdwi40XZ0 ZWv9b8F5RxKcJEaXDq8GzKf8VvNm+qF48aQKUHVRt8iHdKQ4eWCYWpG7dGVXGtdYRD0C kPEOun6c33ryXyUv0yytNG2SRcPmrJEHcRNe4LzhNOOJd1M1QZpHm6v6I8utpUHVYBnM NukjU+zONDtQbOOMyNQuGpbbLkpe7QGMwDMzsBUGiEhmPvqb2jzXpVglJt3Rb5KA/qzP m/3s+uk5OeMCxRmjhkAPPX7CBn/cFgLlIpu4/KGLd1YYe4qESmRZC+hErkWY+wHeatDn S6NA== X-Gm-Message-State: AOJu0YxoP2n2R7dPymSNjwx7x8CoXYqxUTk9WLNbIv7YIXccWObNbPMx v/zAWaFi8eILkU8lVjhed5nDnL9QHsG59uA0lBxusZMDK8LIomIHdIzasZkw05w= X-Received: by 2002:a05:651c:19ac:b0:2f0:25dc:1894 with SMTP id 38308e7fff4ca-2f3aa1d9de7mr3336041fa.2.1723580619507; Tue, 13 Aug 2024 13:23:39 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429deb4a4aesm893215e9.14.2024.08.13.13.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 13:23:38 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8B99B5FCF1; Tue, 13 Aug 2024 21:23:30 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Michael Roth , Palmer Dabbelt , Mahmoud Mandour , Pavel Dovgalyuk , Yoshinori Sato , Weiwei Li , Eduardo Habkost , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Markus Armbruster , David Hildenbrand , Beraldo Leal , Liu Zhiwei , Eric Auger , Song Gao , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, Peter Xu , Jiri Pirko , Eric Blake , Fabiano Rosas , qemu-s390x@nongnu.org, Peter Maydell , "Michael S. Tsirkin" , Daniel Henrique Barboza , John Snow , Alexandre Iooss , Konstantin Kostiuk , Pierrick Bouvier , Cleber Rosa , Ilya Leoshkevich , qemu-riscv@nongnu.org, Thomas Huth , Paolo Bonzini , Richard Henderson , Jason Wang , Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Nicholas Piggin , Pavel Dovgalyuk Subject: [PATCH v2 12/21] replay: allow runstate shutdown->running when replaying trace Date: Tue, 13 Aug 2024 21:23:20 +0100 Message-Id: <20240813202329.1237572-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240813202329.1237572-1-alex.bennee@linaro.org> References: <20240813202329.1237572-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=alex.bennee@linaro.org; helo=mail-lj1-x22c.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, T_SCC_BODY_TEXT_LINE=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Nicholas Piggin When replaying a trace, it is possible to go from shutdown to running with a reverse-debugging step. This can be useful if the problem being debugged triggers a reset or shutdown. This can be tested by making a recording of a machine that shuts down, then using -action shutdown=pause when replaying it. Continuing to the end of the trace then reverse-stepping in gdb crashes due to invalid runstate transition. Just permitting the transition seems to be all that's necessary for reverse-debugging to work well in such a state. Reviewed-by: Alex Bennée Reviewed-by: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin Message-Id: <20240813050638.446172-5-npiggin@gmail.com> Signed-off-by: Alex Bennée --- include/sysemu/runstate.h | 1 + replay/replay.c | 2 ++ system/runstate.c | 31 ++++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index e210a37abf..11c7ff3ffb 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -9,6 +9,7 @@ void runstate_set(RunState new_state); RunState runstate_get(void); bool runstate_is_running(void); bool runstate_needs_reset(void); +void runstate_replay_enable(void); typedef void VMChangeStateHandler(void *opaque, bool running, RunState state); diff --git a/replay/replay.c b/replay/replay.c index a2c576c16e..b8564a4813 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -385,6 +385,8 @@ static void replay_enable(const char *fname, int mode) replay_fetch_data_kind(); } + runstate_replay_enable(); + replay_init_events(); } diff --git a/system/runstate.c b/system/runstate.c index c833316f6d..a0e2a5fd22 100644 --- a/system/runstate.c +++ b/system/runstate.c @@ -181,6 +181,12 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE__MAX, RUN_STATE__MAX }, }; +static const RunStateTransition replay_play_runstate_transitions_def[] = { + { RUN_STATE_SHUTDOWN, RUN_STATE_RUNNING}, + + { RUN_STATE__MAX, RUN_STATE__MAX }, +}; + static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX]; bool runstate_check(RunState state) @@ -188,14 +194,33 @@ bool runstate_check(RunState state) return current_run_state == state; } -static void runstate_init(void) +static void transitions_set_valid(const RunStateTransition *rst) { const RunStateTransition *p; - memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); - for (p = &runstate_transitions_def[0]; p->from != RUN_STATE__MAX; p++) { + for (p = rst; p->from != RUN_STATE__MAX; p++) { runstate_valid_transitions[p->from][p->to] = true; } +} + +void runstate_replay_enable(void) +{ + assert(replay_mode != REPLAY_MODE_NONE); + + if (replay_mode == REPLAY_MODE_PLAY) { + /* + * When reverse-debugging, it is possible to move state from + * shutdown to running. + */ + transitions_set_valid(&replay_play_runstate_transitions_def[0]); + } +} + +static void runstate_init(void) +{ + memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); + + transitions_set_valid(&runstate_transitions_def[0]); qemu_mutex_init(&vmstop_lock); }