From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919134023886.9642639251447; Sat, 28 Apr 2018 05:38:54 -0700 (PDT) Received: from localhost ([::1]:52006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7j-0002tP-MP for importer@patchew.org; Sat, 28 Apr 2018 08:38:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP5p-0001vF-P9 for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP5m-0003tM-Vg for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:45 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55850) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP5m-0003sh-My for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:42 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id A5FB854008C; Sat, 28 Apr 2018 15:36:41 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:36:34 +0300 Message-ID: <20180428123634.12445.90565.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 01/19] block: implement bdrv_snapshot_goto for blkreplay X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch enables making snapshots with blkreplay used in block devices. This function is required to make bdrv_snapshot_goto without calling .bdrv_open which is not implemented. Signed-off-by: Pavel Dovgalyuk --- block/blkreplay.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/blkreplay.c b/block/blkreplay.c index fe5a9b4..ec0aa82 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -127,6 +127,12 @@ static int coroutine_fn blkreplay_co_flush(BlockDriver= State *bs) return ret; } =20 +static int blkreplay_snapshot_goto(BlockDriverState *bs, + const char *snapshot_id) +{ + return bdrv_snapshot_goto(bs->file->bs, snapshot_id, NULL); +} + static BlockDriver bdrv_blkreplay =3D { .format_name =3D "blkreplay", .instance_size =3D 0, @@ -142,6 +148,8 @@ static BlockDriver bdrv_blkreplay =3D { .bdrv_co_pwrite_zeroes =3D blkreplay_co_pwrite_zeroes, .bdrv_co_pdiscard =3D blkreplay_co_pdiscard, .bdrv_co_flush =3D blkreplay_co_flush, + + .bdrv_snapshot_goto =3D blkreplay_snapshot_goto, }; =20 static void bdrv_blkreplay_init(void) From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919131120153.2588299988139; Sat, 28 Apr 2018 05:38:51 -0700 (PDT) Received: from localhost ([::1]:52008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7q-00030l-2u for importer@patchew.org; Sat, 28 Apr 2018 08:38:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP5t-0001wZ-Lm for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP5s-00041Y-NB for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:49 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP5s-00041I-Es for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:48 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 600D654008C; Sat, 28 Apr 2018 15:36:47 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:36:40 +0300 Message-ID: <20180428123640.12445.67155.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 02/19] replay: disable default snapshot for record/replay X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch disables setting '-snapshot' option on by default in record/replay mode. This is needed for creating vmstates in record and replay modes. Signed-off-by: Pavel Dovgalyuk --- vl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vl.c b/vl.c index 7487535..39fc03a 100644 --- a/vl.c +++ b/vl.c @@ -3243,7 +3243,13 @@ int main(int argc, char **argv, char **envp) drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); break; case QEMU_OPTION_snapshot: - snapshot =3D 1; + { + Error *blocker =3D NULL; + snapshot =3D 1; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, + "-snapshot"); + replay_add_blocker(blocker); + } break; case QEMU_OPTION_numa: opts =3D qemu_opts_parse_noisily(qemu_find_opts("numa"), @@ -4546,7 +4552,7 @@ int main(int argc, char **argv, char **envp) qapi_free_BlockdevOptions(bdo->bdo); g_free(bdo); } - if (snapshot || replay_mode !=3D REPLAY_MODE_NONE) { + if (snapshot) { qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, NULL); } From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919300930468.8976153696801; Sat, 28 Apr 2018 05:41:40 -0700 (PDT) Received: from localhost ([::1]:52024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPAa-0005TM-1y for importer@patchew.org; Sat, 28 Apr 2018 08:41:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP66-00028A-4K for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP61-00047P-7q for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:02 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55900) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP5y-00045X-3z for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:54 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 212FF54008C; Sat, 28 Apr 2018 15:36:53 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:36:45 +0300 Message-ID: <20180428123645.12445.18399.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 03/19] replay: update docs for record/replay with block devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch updates the description of the command lines for using record/replay with attached block devices. Signed-off-by: Pavel Dovgalyuk --- docs/replay.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/replay.txt b/docs/replay.txt index 2e21e9c..f7def53 100644 --- a/docs/replay.txt +++ b/docs/replay.txt @@ -27,7 +27,7 @@ Usage of the record/replay: * First, record the execution with the following command line: qemu-system-i386 \ -icount shift=3D7,rr=3Drecord,rrfile=3Dreplay.bin \ - -drive file=3Ddisk.qcow2,if=3Dnone,id=3Dimg-direct \ + -drive file=3Ddisk.qcow2,if=3Dnone,snapshot,id=3Dimg-direct \ -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkre= play \ -device ide-hd,drive=3Dimg-blkreplay \ -netdev user,id=3Dnet1 -device rtl8139,netdev=3Dnet1 \ @@ -35,7 +35,7 @@ Usage of the record/replay: * After recording, you can replay it by using another command line: qemu-system-i386 \ -icount shift=3D7,rr=3Dreplay,rrfile=3Dreplay.bin \ - -drive file=3Ddisk.qcow2,if=3Dnone,id=3Dimg-direct \ + -drive file=3Ddisk.qcow2,if=3Dnone,snapshot,id=3Dimg-direct \ -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkre= play \ -device ide-hd,drive=3Dimg-blkreplay \ -netdev user,id=3Dnet1 -device rtl8139,netdev=3Dnet1 \ @@ -223,7 +223,7 @@ Block devices record/replay module intercepts calls of bdrv coroutine functions at the top of block drivers stack. To record and replay block operations the drive must be configured as following: - -drive file=3Ddisk.qcow2,if=3Dnone,id=3Dimg-direct + -drive file=3Ddisk.qcow2,if=3Dnone,snapshot,id=3Dimg-direct -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkreplay -device ide-hd,drive=3Dimg-blkreplay =20 @@ -252,6 +252,12 @@ This snapshot is created at start of recording and res= tored at start of replaying. It also can be loaded while replaying to roll back the execution. =20 +'snapshot' flag of the disk image must be removed to save the snapshots +in the overlay (or original image) instead of using the temporary overlay. + -drive file=3Ddisk.ovl,if=3Dnone,id=3Dimg-direct + -drive driver=3Dblkreplay,if=3Dnone,image=3Dimg-direct,id=3Dimg-blkreplay + -device ide-hd,drive=3Dimg-blkreplay + Use QEMU monitor to create additional snapshots. 'savevm ' command created the snapshot and 'loadvm ' restores it. To prevent corruption of the original disk image, use overlay files linked to the original image= s. From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919295560848.8405944828542; Sat, 28 Apr 2018 05:41:35 -0700 (PDT) Received: from localhost ([::1]:52023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPAU-0005Pi-N2 for importer@patchew.org; Sat, 28 Apr 2018 08:41:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP66-00028B-4t for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP64-00049c-0g for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:02 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55934) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP63-000494-OB for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:36:59 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id BE5F354008C; Sat, 28 Apr 2018 15:36:58 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:36:51 +0300 Message-ID: <20180428123651.12445.90766.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 04/19] replay: don't drain/flush bdrv queue while RR is working X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 In record/replay mode bdrv queue is controlled by replay mechanism. It does not allow saving or loading the snapshots when bdrv queue is not empty. Stopping the VM is not blocked by nonempty queue, but flushing the queue is still impossible there, because it may cause deadlocks in replay mode. This patch disables bdrv_drain_all and bdrv_flush_all in record/replay mode. Signed-off-by: Pavel Dovgalyuk --- block/io.c | 22 ++++++++++++++++++++++ cpus.c | 2 -- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index bd9a19a..1ceefbc 100644 --- a/block/io.c +++ b/block/io.c @@ -32,6 +32,7 @@ #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/error-report.h" +#include "sysemu/replay.h" =20 #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progr= ess */ =20 @@ -407,6 +408,13 @@ void bdrv_drain_all_begin(void) BdrvNextIterator it; GSList *aio_ctxs =3D NULL, *ctx; =20 + /* bdrv queue is managed by record/replay, + waiting for finishing the I/O requests may + be infinite */ + if (replay_events_enabled()) { + return; + } + /* BDRV_POLL_WHILE() for a node can only be called from its own I/O th= read * or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on * nodes in several different AioContexts, so make sure we're in the m= ain @@ -458,6 +466,13 @@ void bdrv_drain_all_end(void) BlockDriverState *bs; BdrvNextIterator it; =20 + /* bdrv queue is managed by record/replay, + waiting for finishing the I/O requests may + be endless */ + if (replay_events_enabled()) { + return; + } + for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 @@ -1832,6 +1847,13 @@ int bdrv_flush_all(void) BlockDriverState *bs =3D NULL; int result =3D 0; =20 + /* bdrv queue is managed by record/replay, + creating new flush request for stopping + the VM may break the determinism */ + if (replay_events_enabled()) { + return result; + } + for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *aio_context =3D bdrv_get_aio_context(bs); int ret; diff --git a/cpus.c b/cpus.c index 38eba8b..140cc4f 100644 --- a/cpus.c +++ b/cpus.c @@ -1016,7 +1016,6 @@ static int do_vm_stop(RunState state, bool send_stop) } =20 bdrv_drain_all(); - replay_disable_events(); ret =3D bdrv_flush_all(); =20 return ret; @@ -2059,7 +2058,6 @@ int vm_prepare_start(void) qapi_event_send_stop(&error_abort); res =3D -1; } else { - replay_enable_events(); cpu_enable_ticks(); runstate_set(RUN_STATE_RUNNING); vm_state_notify(1, RUN_STATE_RUNNING); From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152491946371966.04075701034344; Sat, 28 Apr 2018 05:44:23 -0700 (PDT) Received: from localhost ([::1]:52037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPDC-0007oF-TA for importer@patchew.org; Sat, 28 Apr 2018 08:44:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6a-0002TE-Vr for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6W-0004Vx-0A for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:32 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55970) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP69-0004D3-DL for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:27 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 5E6B454008C; Sat, 28 Apr 2018 15:37:04 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:36:57 +0300 Message-ID: <20180428123657.12445.44375.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 05/19] replay: finish record/replay before closing the disks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 After recent updates block devices cannot be closed on qemu exit. This happens due to the block request polling when replay is not finished. Therefore now we stop execution recording before closing the block devices. Signed-off-by: Pavel Dovgalyuk --- replay/replay.c | 2 ++ vl.c | 1 + 2 files changed, 3 insertions(+) diff --git a/replay/replay.c b/replay/replay.c index 8228261..58a986f 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -366,6 +366,8 @@ void replay_finish(void) g_free(replay_snapshot); replay_snapshot =3D NULL; =20 + replay_mode =3D REPLAY_MODE_NONE; + replay_finish_events(); } =20 diff --git a/vl.c b/vl.c index 39fc03a..3bf85a4 100644 --- a/vl.c +++ b/vl.c @@ -4761,6 +4761,7 @@ int main(int argc, char **argv, char **envp) =20 /* No more vcpu or device emulation activity beyond this point */ vm_shutdown(); + replay_finish(); =20 bdrv_close_all(); =20 From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919751259877.7712504915481; Sat, 28 Apr 2018 05:49:11 -0700 (PDT) Received: from localhost ([::1]:52060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPHl-0003aH-Fa for importer@patchew.org; Sat, 28 Apr 2018 08:49:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6a-0002TD-Vf for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6W-0004W1-0L for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:32 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6F-0004L3-4K for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:27 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 1AEF85400B9; Sat, 28 Apr 2018 15:37:10 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:02 +0300 Message-ID: <20180428123702.12445.39836.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 06/19] qcow2: introduce icount field for snapshots X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch introduces the icount field for saving within the snapshot. It is required for navigation between the snapshots in record/replay mode. Signed-off-by: Pavel Dovgalyuk -- v2: - documented format changes in docs/interop/qcow2.txt (suggested by Eric Blake) --- block/qcow2-snapshot.c | 7 +++++++ block/qcow2.h | 2 ++ docs/interop/qcow2.txt | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 74293be..d04553e 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -103,6 +103,12 @@ int qcow2_read_snapshots(BlockDriverState *bs) sn->disk_size =3D bs->total_sectors * BDRV_SECTOR_SIZE; } =20 + if (extra_data_size >=3D 24) { + sn->icount =3D be64_to_cpu(extra.icount); + } else { + sn->icount =3D -1ULL; + } + /* Read snapshot ID */ sn->id_str =3D g_malloc(id_str_size + 1); ret =3D bdrv_pread(bs->file, offset, sn->id_str, id_str_size); @@ -209,6 +215,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) memset(&extra, 0, sizeof(extra)); extra.vm_state_size_large =3D cpu_to_be64(sn->vm_state_size); extra.disk_size =3D cpu_to_be64(sn->disk_size); + extra.icount =3D cpu_to_be64(sn->icount); =20 id_str_size =3D strlen(sn->id_str); name_size =3D strlen(sn->name); diff --git a/block/qcow2.h b/block/qcow2.h index adf5c39..8880937 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -151,6 +151,7 @@ typedef struct QEMU_PACKED QCowSnapshotHeader { typedef struct QEMU_PACKED QCowSnapshotExtraData { uint64_t vm_state_size_large; uint64_t disk_size; + uint64_t icount; } QCowSnapshotExtraData; =20 =20 @@ -164,6 +165,7 @@ typedef struct QCowSnapshot { uint32_t date_sec; uint32_t date_nsec; uint64_t vm_clock_nsec; + uint64_t icount; } QCowSnapshot; =20 struct Qcow2Cache; diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index feb711f..ff5b4ed 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -506,6 +506,10 @@ Snapshot table entry: =20 Byte 48 - 55: Virtual disk size of the snapshot in b= ytes =20 + Byte 56 - 63: icount value which corresponds to + the record/replay step when the snapsh= ot + was taken + Version 3 images must include extra data at least up to byte 55. =20 From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919465062981.83044996999; Sat, 28 Apr 2018 05:44:25 -0700 (PDT) Received: from localhost ([::1]:52036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPDC-0007nG-OP for importer@patchew.org; Sat, 28 Apr 2018 08:44:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6a-0002TJ-Ve for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6W-0004WS-0k for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:32 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56038) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6L-0004Oq-0Y for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:27 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id BF7265400C1; Sat, 28 Apr 2018 15:37:15 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:08 +0300 Message-ID: <20180428123708.12445.23614.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 07/19] migration: introduce icount field for snapshots X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Saving icount as a parameters of the snapshot allows navigation between them in the execution replay scenario. This information can be used for finding a specific snapshot for rewinding the recorded execution to the specific moment of the time. E.g., 'reverse step' action needs to load the nearest snapshot which is prior to the current moment of time . Signed-off-by: Pavel Dovgalyuk -- v2: - made icount in SnapshotInfo optional (suggested by Eric Blake) --- block/qapi.c | 17 +++++++++++++---- block/qcow2-snapshot.c | 2 ++ blockdev.c | 10 ++++++++++ include/block/snapshot.h | 1 + migration/savevm.c | 5 +++++ qapi/block-core.json | 5 ++++- qapi/block.json | 3 ++- 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index 04c6fc6..b4f9c2f 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -210,6 +210,7 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs, info->date_nsec =3D sn_tab[i].date_nsec; info->vm_clock_sec =3D sn_tab[i].vm_clock_nsec / 1000000000; info->vm_clock_nsec =3D sn_tab[i].vm_clock_nsec % 1000000000; + info->icount =3D sn_tab[i].icount; =20 info_list =3D g_new0(SnapshotInfoList, 1); info_list->value =3D info; @@ -648,14 +649,15 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf= , void *f, QEMUSnapshotInfo *sn) { char buf1[128], date_buf[128], clock_buf[128]; + char icount_buf[128] =3D {0}; struct tm tm; time_t ti; int64_t secs; =20 if (!sn) { func_fprintf(f, - "%-10s%-20s%7s%20s%15s", - "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK"); + "%-10s%-18s%7s%20s%13s%11s", + "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK", "ICOUNT"); } else { ti =3D sn->date_sec; localtime_r(&ti, &tm); @@ -668,13 +670,18 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf= , void *f, (int)((secs / 60) % 60), (int)(secs % 60), (int)((sn->vm_clock_nsec / 1000000) % 1000)); + if (sn->icount !=3D -1ULL) { + snprintf(icount_buf, sizeof(icount_buf), + "%"PRId64, sn->icount); + } func_fprintf(f, - "%-10s%-20s%7s%20s%15s", + "%-10s%-18s%7s%20s%13s%11s", sn->id_str, sn->name, get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size), date_buf, - clock_buf); + clock_buf, + icount_buf); } } =20 @@ -842,6 +849,8 @@ void bdrv_image_info_dump(fprintf_function func_fprintf= , void *f, .date_nsec =3D elem->value->date_nsec, .vm_clock_nsec =3D elem->value->vm_clock_sec * 1000000000U= LL + elem->value->vm_clock_nsec, + .icount =3D elem->value->has_icount ? + elem->value->icount : -1ULL, }; =20 pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id); diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index d04553e..0af32c3 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -379,6 +379,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSna= pshotInfo *sn_info) sn->date_sec =3D sn_info->date_sec; sn->date_nsec =3D sn_info->date_nsec; sn->vm_clock_nsec =3D sn_info->vm_clock_nsec; + sn->icount =3D sn_info->icount; =20 /* Allocate the L1 table of the snapshot and copy the current one ther= e. */ l1_table_offset =3D qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint6= 4_t)); @@ -698,6 +699,7 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnaps= hotInfo **psn_tab) sn_info->date_sec =3D sn->date_sec; sn_info->date_nsec =3D sn->date_nsec; sn_info->vm_clock_nsec =3D sn->vm_clock_nsec; + sn_info->icount =3D sn->icount; } *psn_tab =3D sn_tab; return s->nb_snapshots; diff --git a/blockdev.c b/blockdev.c index c31bf3d..965c96a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -56,6 +56,7 @@ #include "block/trace.h" #include "sysemu/arch_init.h" #include "sysemu/qtest.h" +#include "sysemu/replay.h" #include "qemu/cutils.h" #include "qemu/help_option.h" #include "qemu/throttle-options.h" @@ -1348,6 +1349,10 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_= sync(const char *device, info->vm_state_size =3D sn.vm_state_size; info->vm_clock_nsec =3D sn.vm_clock_nsec % 1000000000; info->vm_clock_sec =3D sn.vm_clock_nsec / 1000000000; + if (sn.icount !=3D -1ULL) { + info->icount =3D sn.icount; + info->has_icount =3D true; + } =20 return info; =20 @@ -1556,6 +1561,11 @@ static void internal_snapshot_prepare(BlkActionState= *common, sn->date_sec =3D tv.tv_sec; sn->date_nsec =3D tv.tv_usec * 1000; sn->vm_clock_nsec =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + if (replay_mode !=3D REPLAY_MODE_NONE) { + sn->icount =3D replay_get_current_step(); + } else { + sn->icount =3D -1ULL; + } =20 ret1 =3D bdrv_snapshot_create(bs, sn); if (ret1 < 0) { diff --git a/include/block/snapshot.h b/include/block/snapshot.h index f73d109..c9c8975 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -42,6 +42,7 @@ typedef struct QEMUSnapshotInfo { uint32_t date_sec; /* UTC date of the snapshot */ uint32_t date_nsec; uint64_t vm_clock_nsec; /* VM clock relative to boot */ + uint64_t icount; /* record/replay step */ } QEMUSnapshotInfo; =20 int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, diff --git a/migration/savevm.c b/migration/savevm.c index e2be02a..08c1d4c 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2270,6 +2270,11 @@ int save_snapshot(const char *name, Error **errp) sn->date_sec =3D tv.tv_sec; sn->date_nsec =3D tv.tv_usec * 1000; sn->vm_clock_nsec =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + if (replay_mode !=3D REPLAY_MODE_NONE) { + sn->icount =3D replay_get_current_step(); + } else { + sn->icount =3D -1ULL; + } =20 if (name) { ret =3D bdrv_snapshot_find(bs, old_sn, name); diff --git a/qapi/block-core.json b/qapi/block-core.json index c50517b..f82ec45 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -25,13 +25,16 @@ # # @vm-clock-nsec: fractional part in nano seconds to be used with vm-clock= -sec # +# @icount: current instruction count for execution record/replay (since 2.= 13) +# # Since: 1.3 # ## { 'struct': 'SnapshotInfo', 'data': { 'id': 'str', 'name': 'str', 'vm-state-size': 'int', 'date-sec': 'int', 'date-nsec': 'int', - 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int' } } + 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int', + '*icount': 'int' } } =20 ## # @ImageInfoSpecificQCow2EncryptionBase: diff --git a/qapi/block.json b/qapi/block.json index c694524..2f364f7 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -148,7 +148,8 @@ # "date-sec": 1000012, # "date-nsec": 10, # "vm-clock-sec": 100, -# "vm-clock-nsec": 20 +# "vm-clock-nsec": 20, +# "icount": 220414 # } # } # From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919614340155.10981376679217; Sat, 28 Apr 2018 05:46:54 -0700 (PDT) Received: from localhost ([::1]:52052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPFd-00025D-Gw for importer@patchew.org; Sat, 28 Apr 2018 08:46:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6a-0002TI-Vd for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6W-0004Wd-1K for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:32 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56062) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6Q-0004SI-MR for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:27 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id A7A045400C2; Sat, 28 Apr 2018 15:37:21 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:14 +0300 Message-ID: <20180428123714.12445.19186.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 08/19] replay: introduce info hmp/qmp command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch introduces 'info replay' monitor command and corresponding qmp request. These commands request the current record/replay mode, replay log file name, and the execution step (number or recorded/replayed instructions). Signed-off-by: Pavel Dovgalyuk -- v2: - renamed info_replay qmp into query-replay (suggested by Eric Blake) --- hmp-commands-info.hx | 14 ++++++++++++++ hmp.h | 1 + qapi/misc.json | 35 +++++++++++++++++++++++++++++++++++ replay/Makefile.objs | 3 ++- replay/replay-debugging.c | 41 +++++++++++++++++++++++++++++++++++++++++ replay/replay-internal.h | 2 ++ replay/replay.c | 3 +-- 7 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 replay/replay-debugging.c diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ddfcd5a..f5631be 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -883,6 +883,20 @@ STEXI Show SEV information. ETEXI =20 + { + .name =3D "replay", + .args_type =3D "", + .params =3D "", + .help =3D "show parameters of the record/replay", + .cmd =3D hmp_info_replay, + }, + +STEXI +@item info replay +@findex info replay +Display the current record/replay mode and the currently executing step. +ETEXI + STEXI @end table ETEXI diff --git a/hmp.h b/hmp.h index 4e2ec37..084fb62 100644 --- a/hmp.h +++ b/hmp.h @@ -144,5 +144,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *q= dict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); +void hmp_info_replay(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/qapi/misc.json b/qapi/misc.json index 5636f4a..0b0e874 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3064,6 +3064,41 @@ 'data': [ 'none', 'record', 'play' ] } =20 ## +# @ReplayInfo: +# +# Status of the record/replay mode. +# +# @mode: current mode. +# +# @filename: name of the record/replay log file. +# +# @step: current step number. +# +# Since: 2.13 +# +## +{ 'struct': 'ReplayInfo', + 'data': { 'mode': 'ReplayMode', '*filename': 'str', 'step': 'int' } } + +## +# @query-replay: +# +# Retrieves the status of the execution record/replay. +# +# Returns: structure with the properties of the record/replay. +# +# Since: 2.13 +# +# Example: +# +# -> { "execute": "query-replay" } +# <- { "return": { "mode": "play", "filename": "log.rr", "step": 220414 } } +# +## +{ 'command': 'query-replay', + 'returns': 'ReplayInfo' } + +## # @xen-load-devices-state: # # Load the state of all devices from file. The RAM and the block devices diff --git a/replay/Makefile.objs b/replay/Makefile.objs index cee6539..6694e3e 100644 --- a/replay/Makefile.objs +++ b/replay/Makefile.objs @@ -6,4 +6,5 @@ common-obj-y +=3D replay-input.o common-obj-y +=3D replay-char.o common-obj-y +=3D replay-snapshot.o common-obj-y +=3D replay-net.o -common-obj-y +=3D replay-audio.o \ No newline at end of file +common-obj-y +=3D replay-audio.o +common-obj-y +=3D replay-debugging.o diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c new file mode 100644 index 0000000..03e7db8 --- /dev/null +++ b/replay/replay-debugging.c @@ -0,0 +1,41 @@ +/* + * replay-debugging.c + * + * Copyright (c) 2010-2018 Institute for System Programming + * of the Russian Academy of Sciences. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "sysemu/replay.h" +#include "replay-internal.h" +#include "hmp.h" +#include "monitor/monitor.h" +#include "qapi/qapi-commands-misc.h" + +void hmp_info_replay(Monitor *mon, const QDict *qdict) +{ + if (replay_mode =3D=3D REPLAY_MODE_NONE) { + monitor_printf(mon, "No record/replay\n"); + } else { + monitor_printf(mon, "%s execution '%s': current step =3D %"PRId64"= \n", + replay_mode =3D=3D REPLAY_MODE_RECORD ? "Recording" : "Replayi= ng", + replay_filename, replay_get_current_step()); + } +} + +ReplayInfo *qmp_query_replay(Error **errp) +{ + ReplayInfo *retval =3D g_new0(ReplayInfo, 1); + retval->mode =3D replay_mode; + if (replay_filename) { + retval->filename =3D g_strdup(replay_filename); + retval->has_filename =3D true; + } + retval->step =3D replay_get_current_step(); + return retval; +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h index ac4b27b..ef82b5e 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -91,6 +91,8 @@ extern ReplayState replay_state; =20 /* File for replay writing */ extern FILE *replay_file; +/*! Name of replay file */ +extern char *replay_filename; =20 void replay_put_byte(uint8_t byte); void replay_put_event(uint8_t event); diff --git a/replay/replay.c b/replay/replay.c index 58a986f..8b70d7d 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -29,8 +29,7 @@ ReplayMode replay_mode =3D REPLAY_MODE_NONE; char *replay_snapshot; =20 -/* Name of replay file */ -static char *replay_filename; +char *replay_filename; ReplayState replay_state; static GSList *replay_blockers; =20 From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919294038775.2318442042954; Sat, 28 Apr 2018 05:41:34 -0700 (PDT) Received: from localhost ([::1]:52022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPAT-0005O4-5a for importer@patchew.org; Sat, 28 Apr 2018 08:41:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6a-0002TK-Vm for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6W-0004XO-QL for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:32 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6W-0004Wt-DM for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:28 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 611CD5400C3; Sat, 28 Apr 2018 15:37:27 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:20 +0300 Message-ID: <20180428123720.12445.38753.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 09/19] replay: introduce breakpoint at the specified step X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch introduces replay_break qmp and hmp commands. These commands allow stopping at the specified instruction. It may be useful for debugging when there are some known events that should be investigated. The commands have one argument - number of instructions executed since the start of the replay. Signed-off-by: Pavel Dovgalyuk -- v2: - renamed replay_break qmp command into replay-break (suggested by Eric Blake) --- hmp-commands.hx | 15 ++++++++++++ hmp.h | 1 + include/sysemu/replay.h | 3 ++ qapi/misc.json | 17 ++++++++++++++ replay/replay-debugging.c | 55 +++++++++++++++++++++++++++++++++++++++++= ++++ replay/replay-internal.h | 4 +++ replay/replay.c | 17 ++++++++++++++ 7 files changed, 112 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 35d862a..f162f5e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1820,6 +1820,21 @@ Set QOM property @var{property} of object at locatio= n @var{path} to value @var{v ETEXI =20 { + .name =3D "replay_break", + .args_type =3D "step:i", + .params =3D "step", + .help =3D "sets breakpoint on the specified step of the repl= ay", + .cmd =3D hmp_replay_break, + }, + +STEXI +@item replay_break @var{step} +@findex replay_break +Set breakpoint on the specified step of the replay. +Execution stops when the specified step is reached. +ETEXI + + { .name =3D "info", .args_type =3D "item:s?", .params =3D "[subcommand]", diff --git a/hmp.h b/hmp.h index 084fb62..5ef8f56 100644 --- a/hmp.h +++ b/hmp.h @@ -145,5 +145,6 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDic= t *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); void hmp_info_replay(Monitor *mon, const QDict *qdict); +void hmp_replay_break(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 3ced6bc..98d709c 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -71,6 +71,9 @@ void replay_start(void); void replay_finish(void); /*! Adds replay blocker with the specified error description */ void replay_add_blocker(Error *reason); +/*! Sets breakpoint at the specified step. + If step =3D -1LL the existing breakpoint is removed. */ +void replay_break(int64_t step, QEMUTimerCB callback, void *opaque); =20 /* Processing the instructions */ =20 diff --git a/qapi/misc.json b/qapi/misc.json index 0b0e874..ef8fe3c 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3099,6 +3099,23 @@ 'returns': 'ReplayInfo' } =20 ## +# @replay-break: +# +# Set breakpoint on the specified step of the replay. +# Execution stops when the specified step is reached. +# +# @step: execution step to stop at +# +# Since: 2.13 +# +# Example: +# +# -> { "execute": "replay-break", "data": { "step": 220414 } } +# +## +{ 'command': 'replay-break', 'data': { 'step': 'int' } } + +## # @xen-load-devices-state: # # Load the state of all devices from file. The RAM and the block devices diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 03e7db8..819017e 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -16,6 +16,8 @@ #include "hmp.h" #include "monitor/monitor.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/qmp/qdict.h" +#include "qemu/timer.h" =20 void hmp_info_replay(Monitor *mon, const QDict *qdict) { @@ -39,3 +41,56 @@ ReplayInfo *qmp_query_replay(Error **errp) retval->step =3D replay_get_current_step(); return retval; } + +void replay_break(int64_t step, QEMUTimerCB callback, void *opaque) +{ + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + assert(replay_mutex_locked()); + + replay_break_step =3D step; + if (replay_break_timer) { + timer_del(replay_break_timer); + timer_free(replay_break_timer); + replay_break_timer =3D NULL; + } + + if (replay_break_step =3D=3D -1LL) { + return; + } + assert(replay_break_step >=3D replay_get_current_step()); + assert(callback); + + replay_break_timer =3D timer_new_ns(QEMU_CLOCK_REALTIME, callback, opa= que); +} + +static void replay_stop_vm(void *opaque) +{ + vm_stop(RUN_STATE_PAUSED); + replay_break(-1LL, NULL, NULL); +} + +void qmp_replay_break(int64_t step, Error **errp) +{ + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + if (step >=3D replay_get_current_step()) { + replay_break(step, replay_stop_vm, NULL); + } else { + error_setg(errp, "cannot set break at the step in the past"); + } + } else { + error_setg(errp, "setting the break is allowed only in play mode"); + } +} + +void hmp_replay_break(Monitor *mon, const QDict *qdict) +{ + int64_t step =3D qdict_get_try_int(qdict, "step", -1LL); + Error *err =3D NULL; + + qmp_replay_break(step, &err); + if (err) { + monitor_printf(mon, "replay_break error: %s\n", error_get_pretty(e= rr)); + error_free(err); + return; + } +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h index ef82b5e..34d19eb 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -93,6 +93,10 @@ extern ReplayState replay_state; extern FILE *replay_file; /*! Name of replay file */ extern char *replay_filename; +/*! Step of the replay breakpoint */ +extern int64_t replay_break_step; +/*! Timer for the replay breakpoint callback */ +extern QEMUTimer *replay_break_timer; =20 void replay_put_byte(uint8_t byte); void replay_put_event(uint8_t event); diff --git a/replay/replay.c b/replay/replay.c index 8b70d7d..dcce902 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -33,6 +33,10 @@ char *replay_filename; ReplayState replay_state; static GSList *replay_blockers; =20 +/* Replay breakpoints */ +int64_t replay_break_step =3D -1LL; +QEMUTimer *replay_break_timer; + bool replay_next_event_is(int event) { bool res =3D false; @@ -72,6 +76,13 @@ int replay_get_instructions(void) replay_mutex_lock(); if (replay_next_event_is(EVENT_INSTRUCTION)) { res =3D replay_state.instructions_count; + if (replay_break_step !=3D -1LL) { + uint64_t current =3D replay_get_current_step(); + assert(replay_break_step >=3D current); + if (current + res > replay_break_step) { + res =3D replay_break_step - current; + } + } } replay_mutex_unlock(); return res; @@ -98,6 +109,12 @@ void replay_account_executed_instructions(void) will be read from the log. */ qemu_notify_event(); } + /* Execution reached the break step */ + if (replay_break_step =3D=3D replay_state.current_step) { + /* Cannot make callback directly from the vCPU thread */ + timer_mod_ns(replay_break_timer, + qemu_clock_get_ns(QEMU_CLOCK_REALTIME)); + } } } } From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919247809823.8476843454704; Sat, 28 Apr 2018 05:40:47 -0700 (PDT) Received: from localhost ([::1]:52018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP9i-0004cJ-S6 for importer@patchew.org; Sat, 28 Apr 2018 08:40:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6d-0002W0-P1 for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6c-0004fI-J3 for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:35 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6c-0004dp-3v for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:34 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 144EC54008C; Sat, 28 Apr 2018 15:37:33 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:25 +0300 Message-ID: <20180428123725.12445.82101.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 10/19] replay: implement replay-seek command to proceed to the desired step X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch adds hmp/qmp commands replay_seek/replay-seek that proceed the execution to the specified step. The commands automatically loads nearest snapshot and replay the execution to find the desired step. Signed-off-by: Pavel Dovgalyuk -- v2: - renamed replay_seek qmp command into replay-seek (suggested by Eric Blake) --- hmp-commands.hx | 15 ++++++++ hmp.h | 1 + qapi/misc.json | 16 ++++++++ replay/replay-debugging.c | 89 +++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 121 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index f162f5e..18b287e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1835,6 +1835,21 @@ Execution stops when the specified step is reached. ETEXI =20 { + .name =3D "replay_seek", + .args_type =3D "step:i", + .params =3D "step", + .help =3D "rewinds replay to the specified step", + .cmd =3D hmp_replay_seek, + }, + +STEXI +@item replay_seek @var{step} +@findex replay_seek +Automatically proceeds to the specified step, when replaying +the execution. +ETEXI + + { .name =3D "info", .args_type =3D "item:s?", .params =3D "[subcommand]", diff --git a/hmp.h b/hmp.h index 5ef8f56..31f830c 100644 --- a/hmp.h +++ b/hmp.h @@ -146,5 +146,6 @@ void hmp_info_memory_size_summary(Monitor *mon, const Q= Dict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); void hmp_info_replay(Monitor *mon, const QDict *qdict); void hmp_replay_break(Monitor *mon, const QDict *qdict); +void hmp_replay_seek(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/qapi/misc.json b/qapi/misc.json index ef8fe3c..a57f5bf 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3116,6 +3116,22 @@ { 'command': 'replay-break', 'data': { 'step': 'int' } } =20 ## +# @replay-seek: +# +# Automatically proceeds to the specified step, when replaying +# the execution. +# +# @step: destination execution step +# +# Since: 2.13 +# +# Example: +# +# -> { "execute": "replay-seek", "data": { "step": 220414 } } +## +{ 'command': 'replay-seek', 'data': { 'step': 'int' } } + +## # @xen-load-devices-state: # # Load the state of all devices from file. The RAM and the block devices diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 819017e..8d6c03d 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -18,6 +18,8 @@ #include "qapi/qapi-commands-misc.h" #include "qapi/qmp/qdict.h" #include "qemu/timer.h" +#include "block/snapshot.h" +#include "migration/snapshot.h" =20 void hmp_info_replay(Monitor *mon, const QDict *qdict) { @@ -94,3 +96,90 @@ void hmp_replay_break(Monitor *mon, const QDict *qdict) return; } } + +static char *replay_find_nearest_snapshot(int64_t step, int64_t* snapshot_= step) +{ + BlockDriverState *bs; + QEMUSnapshotInfo *sn_tab; + QEMUSnapshotInfo *nearest =3D NULL; + char *ret =3D NULL; + int nb_sns, i; + AioContext *aio_context; + + *snapshot_step =3D -1; + + bs =3D bdrv_all_find_vmstate_bs(); + if (!bs) { + goto fail; + } + aio_context =3D bdrv_get_aio_context(bs); + + aio_context_acquire(aio_context); + nb_sns =3D bdrv_snapshot_list(bs, &sn_tab); + aio_context_release(aio_context); + + for (i =3D 0; i < nb_sns; i++) { + if (bdrv_all_find_snapshot(sn_tab[i].name, &bs) =3D=3D 0) { + if (sn_tab[i].icount !=3D -1ULL + && sn_tab[i].icount <=3D step + && (!nearest || nearest->icount < sn_tab[i].icount)) { + nearest =3D &sn_tab[i]; + } + } + } + if (nearest) { + ret =3D g_strdup(nearest->name); + *snapshot_step =3D nearest->icount; + } + g_free(sn_tab); + +fail: + return ret; +} + +static void replay_seek(int64_t step, Error **errp, QEMUTimerCB callback) +{ + char *snapshot =3D NULL; + if (replay_mode !=3D REPLAY_MODE_PLAY) { + error_setg(errp, "replay must be enabled to seek"); + return; + } + if (!replay_snapshot) { + error_setg(errp, "snapshotting is disabled"); + return; + } + int64_t snapshot_step =3D -1; + snapshot =3D replay_find_nearest_snapshot(step, &snapshot_step); + if (snapshot) { + if (step < replay_get_current_step() + || replay_get_current_step() < snapshot_step) { + vm_stop(RUN_STATE_RESTORE_VM); + load_snapshot(snapshot, errp); + } + g_free(snapshot); + } + if (replay_get_current_step() <=3D step) { + replay_break(step, callback, NULL); + vm_start(); + } else { + error_setg(errp, "cannot seek to the specified step"); + } +} + +void qmp_replay_seek(int64_t step, Error **errp) +{ + replay_seek(step, errp, replay_stop_vm); +} + +void hmp_replay_seek(Monitor *mon, const QDict *qdict) +{ + int64_t step =3D qdict_get_try_int(qdict, "step", -1LL); + Error *err =3D NULL; + + qmp_replay_seek(step, &err); + if (err) { + monitor_printf(mon, "replay_seek error: %s\n", error_get_pretty(er= r)); + error_free(err); + return; + } +} From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919862223836.5177519578426; Sat, 28 Apr 2018 05:51:02 -0700 (PDT) Received: from localhost ([::1]:52072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPJd-0005xZ-Hn for importer@patchew.org; Sat, 28 Apr 2018 08:51:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6m-0002dD-Uj for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6i-0004nR-29 for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:44 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6h-0004nA-Pg for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:39 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id B8AF854008C; Sat, 28 Apr 2018 15:37:38 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:31 +0300 Message-ID: <20180428123731.12445.68139.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 11/19] replay: flush events when exitting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch adds events processing when emulation finishes instead of just cleaning the queue. Now the bdrv coroutines will be in consistent state when emulator closes. It allows correct polling of the block layer at exit. Signed-off-by: Pavel Dovgalyuk --- replay/replay-events.c | 14 +------------- replay/replay-internal.h | 2 -- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/replay/replay-events.c b/replay/replay-events.c index 707de38..0964a82 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -94,18 +94,6 @@ void replay_disable_events(void) } } =20 -void replay_clear_events(void) -{ - g_assert(replay_mutex_locked()); - - while (!QTAILQ_EMPTY(&events_list)) { - Event *event =3D QTAILQ_FIRST(&events_list); - QTAILQ_REMOVE(&events_list, event, events); - - g_free(event); - } -} - /*! Adds specified async event to the queue */ void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque, @@ -308,7 +296,7 @@ void replay_init_events(void) void replay_finish_events(void) { events_enabled =3D false; - replay_clear_events(); + replay_flush_events(); } =20 bool replay_events_enabled(void) diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 34d19eb..a2221e5 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -148,8 +148,6 @@ void replay_init_events(void); void replay_finish_events(void); /*! Flushes events queue */ void replay_flush_events(void); -/*! Clears events list before loading new VM state */ -void replay_clear_events(void); /*! Returns true if there are any unsaved events in the queue */ bool replay_has_events(void); /*! Saves events from queue into the file */ From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152491994277082.75376216982818; Sat, 28 Apr 2018 05:52:22 -0700 (PDT) Received: from localhost ([::1]:52078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPKw-0006mh-3v for importer@patchew.org; Sat, 28 Apr 2018 08:52:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6o-0002eo-PO for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6n-0004rP-Qy for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:46 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6n-0004qz-Iz for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:45 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 79A1C54008C; Sat, 28 Apr 2018 15:37:44 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:37 +0300 Message-ID: <20180428123737.12445.9935.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 12/19] timer: remove replay clock probe in deadline calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Ciro Santilli reported that commit a5ed352596a8b7eb2f9acce34371b944ac3056c4 breaks the execution replay. It happens due to the probing the clock for the new instances of iothread. However, this probing was made in replay mode for the timer lists that are empty. This patch removes clock probing in replay mode. It is an artifact of the old version with another thread model. Signed-off-by: Pavel Dovgalyuk --- util/qemu-timer.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 2ed1bf2..86bfe84 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -578,17 +578,10 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup= *tlg) { int64_t deadline =3D -1; QEMUClockType type; - bool play =3D replay_mode =3D=3D REPLAY_MODE_PLAY; for (type =3D 0; type < QEMU_CLOCK_MAX; type++) { if (qemu_clock_use_for_deadline(type)) { - if (!play || type =3D=3D QEMU_CLOCK_REALTIME) { - deadline =3D qemu_soonest_timeout(deadline, - timerlist_deadline_ns(tlg-= >tl[type])); - } else { - /* Read clock from the replay file and - do not calculate the deadline, based on virtual clock. = */ - qemu_clock_get_ns(type); - } + deadline =3D qemu_soonest_timeout(deadline, + timerlist_deadline_ns(tlg->tl[= type])); } } return deadline; From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919426183228.43431840423432; Sat, 28 Apr 2018 05:43:46 -0700 (PDT) Received: from localhost ([::1]:52034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPCM-00074T-Di for importer@patchew.org; Sat, 28 Apr 2018 08:43:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6y-0002nJ-IH for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6t-0004vo-JE for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:56 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6t-0004vI-9K for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:51 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 42B3654008C; Sat, 28 Apr 2018 15:37:50 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:43 +0300 Message-ID: <20180428123742.12445.25502.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 13/19] replay: refine replay-time module X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch removes refactoring artifacts from the replay/replay-time.c Signed-off-by: Pavel Dovgalyuk --- replay/replay-time.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/replay/replay-time.c b/replay/replay-time.c index 6a7565e..40030b8 100644 --- a/replay/replay-time.c +++ b/replay/replay-time.c @@ -17,14 +17,12 @@ =20 int64_t replay_save_clock(ReplayClockKind kind, int64_t clock) { + g_assert(replay_file); + g_assert(replay_mutex_locked()); =20 - if (replay_file) { - g_assert(replay_mutex_locked()); - - replay_save_instructions(); - replay_put_event(EVENT_CLOCK + kind); - replay_put_qword(clock); - } + replay_save_instructions(); + replay_put_event(EVENT_CLOCK + kind); + replay_put_qword(clock); =20 return clock; } @@ -46,20 +44,15 @@ void replay_read_next_clock(ReplayClockKind kind) /*! Reads next clock event from the input. */ int64_t replay_read_clock(ReplayClockKind kind) { + int64_t ret; g_assert(replay_file && replay_mutex_locked()); =20 replay_account_executed_instructions(); =20 - if (replay_file) { - int64_t ret; - if (replay_next_event_is(EVENT_CLOCK + kind)) { - replay_read_next_clock(kind); - } - ret =3D replay_state.cached_clock[kind]; - - return ret; + if (replay_next_event_is(EVENT_CLOCK + kind)) { + replay_read_next_clock(kind); } + ret =3D replay_state.cached_clock[kind]; =20 - error_report("REPLAY INTERNAL ERROR %d", __LINE__); - exit(1); + return ret; } From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919564242842.7958695147546; Sat, 28 Apr 2018 05:46:04 -0700 (PDT) Received: from localhost ([::1]:52051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPEp-0001Ud-Ea for importer@patchew.org; Sat, 28 Apr 2018 08:46:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP70-0002nZ-8f for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP6z-0004zw-7l for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:58 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP6y-0004zO-VN for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:37:57 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id EAD7754008C; Sat, 28 Apr 2018 15:37:55 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:48 +0300 Message-ID: <20180428123748.12445.36182.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 14/19] translator: fix breakpoint processing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 QEMU cannot pass through the breakpoints when 'si' command is used in remote gdb. This patch disables inserting the breakpoints when we are already single stepping though the gdb remote protocol. This patch also fixes icount calculation for the blocks that include breakpoints - instruction with breakpoint is not executed and shouldn't be used in icount calculation. Signed-off-by: Pavel Dovgalyuk --- accel/tcg/translator.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 23c6602..3c7a035 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -35,6 +35,7 @@ void translator_loop(const TranslatorOps *ops, DisasConte= xtBase *db, CPUState *cpu, TranslationBlock *tb) { int max_insns; + int bp_insn =3D 0; =20 /* Initialize DisasContext */ db->tb =3D tb; @@ -73,11 +74,13 @@ void translator_loop(const TranslatorOps *ops, DisasCon= textBase *db, tcg_debug_assert(db->is_jmp =3D=3D DISAS_NEXT); /* no early exit = */ =20 /* Pass breakpoint hits to target for further processing */ - if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) { + if (!db->singlestep_enabled + && unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) { CPUBreakpoint *bp; QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { if (bp->pc =3D=3D db->pc_next) { if (ops->breakpoint_check(db, cpu, bp)) { + bp_insn =3D 1; break; } } @@ -119,7 +122,7 @@ void translator_loop(const TranslatorOps *ops, DisasCon= textBase *db, =20 /* Emit code to exit the TB, as indicated by db->is_jmp. */ ops->tb_stop(db, cpu); - gen_tb_end(db->tb, db->num_insns); + gen_tb_end(db->tb, db->num_insns - bp_insn); =20 /* The disas_log hook may use these values rather than recompute. */ db->tb->size =3D db->pc_next - db->pc_first; From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524920016265676.2621217665882; Sat, 28 Apr 2018 05:53:36 -0700 (PDT) Received: from localhost ([::1]:52081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPM7-0007QF-If for importer@patchew.org; Sat, 28 Apr 2018 08:53:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP79-0002wR-Ra for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP74-00054W-UJ for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:07 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56228) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP74-00054D-LP for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:02 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 9AFDE5400B9; Sat, 28 Apr 2018 15:38:01 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:37:54 +0300 Message-ID: <20180428123754.12445.81488.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 15/19] replay: flush rr queue before loading the vmstate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Non-empty record/replay queue prevents saving and loading the VM state, because it includes pending bottom halves and block coroutines. But when the new VM state is loaded, we don't have to preserve the consiste= ncy of the current state anymore. Therefore this patch just flushes the queue allowing the coroutines to finish. Signed-off-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 2 ++ migration/savevm.c | 10 ++++------ replay/replay-internal.h | 2 -- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 98d709c..84a1ec5 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -132,6 +132,8 @@ void replay_disable_events(void); void replay_enable_events(void); /*! Returns true when saving events is enabled */ bool replay_events_enabled(void); +/*! Flushes events queue */ +void replay_flush_events(void); /*! Adds bottom half event to the queue */ void replay_bh_schedule_event(QEMUBH *bh); /*! Adds input event to the queue */ diff --git a/migration/savevm.c b/migration/savevm.c index 08c1d4c..abe7d2f 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2423,12 +2423,6 @@ int load_snapshot(const char *name, Error **errp) AioContext *aio_context; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 - if (!replay_can_snapshot()) { - error_report("Record/replay does not allow loading snapshot " - "right now. Try once more later."); - return -EINVAL; - } - if (!bdrv_all_can_snapshot(&bs)) { error_setg(errp, "Device '%s' is writable but does not support snapshots= ", @@ -2462,6 +2456,10 @@ int load_snapshot(const char *name, Error **errp) return -EINVAL; } =20 + /* Flush the record/replay queue. Now the VM state is going + to change. Therefore we don't need to preserve its consistency */ + replay_flush_events(); + /* Flush all IO requests so they don't interfere with the new state. = */ bdrv_drain_all_begin(); =20 diff --git a/replay/replay-internal.h b/replay/replay-internal.h index a2221e5..08ef2ec 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -146,8 +146,6 @@ void replay_read_next_clock(unsigned int kind); void replay_init_events(void); /*! Clears internal data structures for events handling */ void replay_finish_events(void); -/*! Flushes events queue */ -void replay_flush_events(void); /*! Returns true if there are any unsaved events in the queue */ bool replay_has_events(void); /*! Saves events from queue into the file */ From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919465060949.8055150947421; Sat, 28 Apr 2018 05:44:25 -0700 (PDT) Received: from localhost ([::1]:52035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPDB-0007m0-KO for importer@patchew.org; Sat, 28 Apr 2018 08:44:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7C-0002yd-37 for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP7A-00059D-PK for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:10 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7A-00058b-CS for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:08 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 526FD54008C; Sat, 28 Apr 2018 15:38:07 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:38:00 +0300 Message-ID: <20180428123800.12445.15147.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 16/19] gdbstub: add reverse step support in replay mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 GDB remote protocol supports two reverse debugging commands: reverse step and reverse continue. This patch adds support of the first one to the gdbstub. Reverse step is intended to step one instruction in the backwards direction. This is not possible in regular execution. But replayed execution is deterministic, therefore we can load one of the prior snapshots and proceed to the desired step. It is equivalent to stepping one instruction back. There should be at least one snapshot preceding the debugged part of the replay log. Signed-off-by: Pavel Dovgalyuk --- accel/tcg/translator.c | 1 + cpus.c | 14 +++++++++++--- exec.c | 5 +++++ gdbstub.c | 42 +++++++++++++++++++++++++++++++++++++++--- include/sysemu/replay.h | 7 +++++++ replay/replay-debugging.c | 33 +++++++++++++++++++++++++++++++++ stubs/replay.c | 5 +++++ 7 files changed, 101 insertions(+), 6 deletions(-) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 3c7a035..4adb37c 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -17,6 +17,7 @@ #include "exec/gen-icount.h" #include "exec/log.h" #include "exec/translator.h" +#include "sysemu/replay.h" =20 /* Pairs with tcg_clear_temp_count. To be called by #TranslatorOps.{translate_insn,tb_stop} if diff --git a/cpus.c b/cpus.c index 140cc4f..3fb9321 100644 --- a/cpus.c +++ b/cpus.c @@ -1042,9 +1042,17 @@ static bool cpu_can_run(CPUState *cpu) =20 static void cpu_handle_guest_debug(CPUState *cpu) { - gdb_set_stop_cpu(cpu); - qemu_system_debug_request(); - cpu->stopped =3D true; + if (!replay_running_debug()) { + gdb_set_stop_cpu(cpu); + qemu_system_debug_request(); + cpu->stopped =3D true; + } else { + if (!cpu->singlestep_enabled) { + cpu_single_step(cpu, SSTEP_ENABLE); + } else { + cpu_single_step(cpu, 0); + } + } } =20 #ifdef CONFIG_LINUX diff --git a/exec.c b/exec.c index c7fcefa..0802aa4 100644 --- a/exec.c +++ b/exec.c @@ -2546,6 +2546,11 @@ static void check_watchpoint(int offset, int len, Me= mTxAttrs attrs, int flags) QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { if (cpu_watchpoint_address_matches(wp, vaddr, len) && (wp->flags & flags)) { + if (replay_running_debug()) { + /* Don't process the watchpoints when we are + in a reverse debugging operation. */ + return; + } if (flags =3D=3D BP_MEM_READ) { wp->flags |=3D BP_WATCHPOINT_HIT_READ; } else { diff --git a/gdbstub.c b/gdbstub.c index 3c38073..86dec56 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -39,6 +39,7 @@ #include "sysemu/kvm.h" #include "exec/semihost.h" #include "exec/exec-all.h" +#include "sysemu/replay.h" =20 #ifdef CONFIG_USER_ONLY #define GDB_ATTACHED "0" @@ -334,6 +335,19 @@ typedef struct GDBState { */ static int sstep_flags =3D SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; =20 +/*! Retrieves flags for single step mode. */ +static int get_sstep_flags(void) +{ + /* In replay mode all events written into the log should be replayed. + * That is why NOIRQ flag is removed in this mode. + */ + if (replay_mode !=3D REPLAY_MODE_NONE) { + return SSTEP_ENABLE; + } else { + return sstep_flags; + } +} + static GDBState *gdbserver_state; =20 bool gdb_has_xml; @@ -424,7 +438,7 @@ static int gdb_continue_partial(GDBState *s, char *news= tates) CPU_FOREACH(cpu) { if (newstates[cpu->cpu_index] =3D=3D 's') { trace_gdbstub_op_stepping(cpu->cpu_index); - cpu_single_step(cpu, sstep_flags); + cpu_single_step(cpu, get_sstep_flags()); } } s->running_state =3D 1; @@ -443,7 +457,7 @@ static int gdb_continue_partial(GDBState *s, char *news= tates) break; /* nothing to do here */ case 's': trace_gdbstub_op_stepping(cpu->cpu_index); - cpu_single_step(cpu, sstep_flags); + cpu_single_step(cpu, get_sstep_flags()); cpu_resume(cpu); flag =3D 1; break; @@ -1072,9 +1086,28 @@ static int gdb_handle_packet(GDBState *s, const char= *line_buf) addr =3D strtoull(p, (char **)&p, 16); gdb_set_cpu_pc(s, addr); } - cpu_single_step(s->c_cpu, sstep_flags); + cpu_single_step(s->c_cpu, get_sstep_flags()); gdb_continue(s); return RS_IDLE; + case 'b': + /* Backward debugging commands */ + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + switch (*p) { + case 's': + if (replay_reverse_step()) { + gdb_continue(s); + return RS_IDLE; + } else { + put_packet(s, "E14"); + break; + } + default: + goto unknown_command; + } + } else { + put_packet(s, "E22"); + } + goto unknown_command; case 'F': { target_ulong ret; @@ -1337,6 +1370,9 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) if (cc->gdb_core_xml_file !=3D NULL) { pstrcat(buf, sizeof(buf), ";qXfer:features:read+"); } + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + pstrcat(buf, sizeof(buf), ";ReverseStep+"); + } put_packet(s, buf); break; } diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 84a1ec5..611eabb 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -74,6 +74,13 @@ void replay_add_blocker(Error *reason); /*! Sets breakpoint at the specified step. If step =3D -1LL the existing breakpoint is removed. */ void replay_break(int64_t step, QEMUTimerCB callback, void *opaque); +/*! Start making one step in backward direction. + Used by gdbstub for backwards debugging. + Returns true on success. */ +bool replay_reverse_step(void); +/*! Returns true if replay module is processing + reverse_continue or reverse_step request */ +bool replay_running_debug(void); =20 /* Processing the instructions */ =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 8d6c03d..388cf12 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -21,6 +21,13 @@ #include "block/snapshot.h" #include "migration/snapshot.h" =20 +static bool replay_is_debugging; + +bool replay_running_debug(void) +{ + return replay_is_debugging; +} + void hmp_info_replay(Monitor *mon, const QDict *qdict) { if (replay_mode =3D=3D REPLAY_MODE_NONE) { @@ -183,3 +190,29 @@ void hmp_replay_seek(Monitor *mon, const QDict *qdict) return; } } + +static void replay_stop_vm_debug(void *opaque) +{ + replay_is_debugging =3D false; + vm_stop(RUN_STATE_DEBUG); + replay_break(-1LL, NULL, NULL); +} + +bool replay_reverse_step(void) +{ + Error *err =3D NULL; + + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + + if (replay_get_current_step() !=3D 0) { + replay_seek(replay_get_current_step() - 1, &err, replay_stop_vm_de= bug); + if (err) { + error_free(err); + return false; + } + replay_is_debugging =3D true; + return true; + } + + return false; +} diff --git a/stubs/replay.c b/stubs/replay.c index 04279ab..b0fba0e 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -80,3 +80,8 @@ void replay_mutex_lock(void) void replay_mutex_unlock(void) { } + +bool replay_reverse_step(void) +{ + return false; +} From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919707242487.67366663057555; Sat, 28 Apr 2018 05:48:27 -0700 (PDT) Received: from localhost ([::1]:52059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPH8-0003C7-Gb for importer@patchew.org; Sat, 28 Apr 2018 08:48:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7L-00037T-Cl for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP7G-0005D4-FM for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:19 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7G-0005CQ-1l for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:14 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 118CD54008C; Sat, 28 Apr 2018 15:38:13 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:38:05 +0300 Message-ID: <20180428123805.12445.97858.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 17/19] gdbstub: add reverse continue support in replay mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch adds support of the reverse continue operation for gdbstub. Reverse continue finds the last breakpoint that would happen in normal execution from the beginning to the current moment. Implementation of the reverse continue replays the execution twice: to find the breakpoints that were hit and to seek to the last breakpoint. Reverse continue loads the previous snapshot and tries to find the breakpoi= nt since that moment. If there are no such breakpoints, it proceeds to the earlier snapshot, and so on. When no breakpoints or watchpoints were hit at all, execution stops at the beginning of the replay log. Signed-off-by: Pavel Dovgalyuk --- cpus.c | 3 ++ exec.c | 1 + gdbstub.c | 10 ++++++- include/sysemu/replay.h | 6 ++++ replay/replay-debugging.c | 69 +++++++++++++++++++++++++++++++++++++++++= ++++ stubs/replay.c | 5 +++ 6 files changed, 93 insertions(+), 1 deletion(-) diff --git a/cpus.c b/cpus.c index 3fb9321..9e81e9a 100644 --- a/cpus.c +++ b/cpus.c @@ -1048,6 +1048,9 @@ static void cpu_handle_guest_debug(CPUState *cpu) cpu->stopped =3D true; } else { if (!cpu->singlestep_enabled) { + /* Report about the breakpoint and + make a single step to skip it */ + replay_breakpoint(); cpu_single_step(cpu, SSTEP_ENABLE); } else { cpu_single_step(cpu, 0); diff --git a/exec.c b/exec.c index 0802aa4..e5fe4dd 100644 --- a/exec.c +++ b/exec.c @@ -2549,6 +2549,7 @@ static void check_watchpoint(int offset, int len, Mem= TxAttrs attrs, int flags) if (replay_running_debug()) { /* Don't process the watchpoints when we are in a reverse debugging operation. */ + replay_breakpoint(); return; } if (flags =3D=3D BP_MEM_READ) { diff --git a/gdbstub.c b/gdbstub.c index 86dec56..1645b7f 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1101,6 +1101,14 @@ static int gdb_handle_packet(GDBState *s, const char= *line_buf) put_packet(s, "E14"); break; } + case 'c': + if (replay_reverse_continue()) { + gdb_continue(s); + return RS_IDLE; + } else { + put_packet(s, "E14"); + break; + } default: goto unknown_command; } @@ -1371,7 +1379,7 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) pstrcat(buf, sizeof(buf), ";qXfer:features:read+"); } if (replay_mode =3D=3D REPLAY_MODE_PLAY) { - pstrcat(buf, sizeof(buf), ";ReverseStep+"); + pstrcat(buf, sizeof(buf), ";ReverseStep+;ReverseContinue+"= ); } put_packet(s, buf); break; diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 611eabb..a3113c1 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -78,9 +78,15 @@ void replay_break(int64_t step, QEMUTimerCB callback, vo= id *opaque); Used by gdbstub for backwards debugging. Returns true on success. */ bool replay_reverse_step(void); +/*! Start searching the last breakpoint/watchpoint. + Used by gdbstub for backwards debugging. + Returns true if the process successfully started. */ +bool replay_reverse_continue(void); /*! Returns true if replay module is processing reverse_continue or reverse_step request */ bool replay_running_debug(void); +/*! Called in reverse debugging mode to collect breakpoint information */ +void replay_breakpoint(void); =20 /* Processing the instructions */ =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 388cf12..edab98e 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -22,6 +22,8 @@ #include "migration/snapshot.h" =20 static bool replay_is_debugging; +static int64_t replay_last_breakpoint; +static int64_t replay_last_snapshot; =20 bool replay_running_debug(void) { @@ -216,3 +218,70 @@ bool replay_reverse_step(void) =20 return false; } + +static void replay_continue_end(void) +{ + replay_is_debugging =3D false; + vm_stop(RUN_STATE_DEBUG); + replay_break(-1LL, NULL, NULL); +} + +static void replay_continue_stop(void *opaque) +{ + Error *err =3D NULL; + if (replay_last_breakpoint !=3D -1LL) { + replay_seek(replay_last_breakpoint, &err, replay_stop_vm_debug); + if (err) { + error_free(err); + replay_continue_end(); + } + return; + } + /* No breakpoints since the last snapshot. + Find previous snapshot and try again. */ + if (replay_last_snapshot !=3D 0) { + replay_seek(replay_last_snapshot - 1, &err, replay_continue_stop); + if (err) { + error_free(err); + replay_continue_end(); + } + replay_last_snapshot =3D replay_get_current_step(); + return; + } else { + /* Seek to the very first step */ + replay_seek(0, &err, replay_stop_vm_debug); + if (err) { + error_free(err); + replay_continue_end(); + } + return; + } + replay_continue_end(); +} + +bool replay_reverse_continue(void) +{ + Error *err =3D NULL; + + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + + if (replay_get_current_step() !=3D 0) { + replay_seek(replay_get_current_step() - 1, &err, replay_continue_s= top); + if (err) { + error_free(err); + return false; + } + replay_last_breakpoint =3D -1LL; + replay_is_debugging =3D true; + replay_last_snapshot =3D replay_get_current_step(); + return true; + } + + return false; +} + +void replay_breakpoint(void) +{ + assert(replay_mode =3D=3D REPLAY_MODE_PLAY); + replay_last_breakpoint =3D replay_get_current_step(); +} diff --git a/stubs/replay.c b/stubs/replay.c index b0fba0e..781974e 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -85,3 +85,8 @@ bool replay_reverse_step(void) { return false; } + +bool replay_reverse_continue(void) +{ + return false; +} From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524919614391797.1079954605675; Sat, 28 Apr 2018 05:46:54 -0700 (PDT) Received: from localhost ([::1]:52053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPFd-00025p-K5 for importer@patchew.org; Sat, 28 Apr 2018 08:46:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7M-0003AH-Rn for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP7M-0005GR-0Q for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:20 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7L-0005Fz-Oa for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:19 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id B2FCA54006B; Sat, 28 Apr 2018 15:38:18 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:38:11 +0300 Message-ID: <20180428123811.12445.70678.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 18/19] replay: describe reverse debugging in docs/replay.txt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch updates the documentation and describes usage of the reverse debugging in QEMU+GDB. Signed-off-by: Pavel Dovgalyuk --- docs/replay.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/replay.txt b/docs/replay.txt index f7def53..086d3f8 100644 --- a/docs/replay.txt +++ b/docs/replay.txt @@ -293,6 +293,39 @@ for recording and replaying must contain identical num= ber of ports in record and replay modes, but their backends may differ. E.g., '-serial stdio' in record mode, and '-serial null' in replay mode. =20 +Reverse debugging +----------------- + +Reverse debugging allows "executing" the program in reverse direction. +GDB remote protocol supports "reverse step" and "reverse continue" +commands. The first one steps single instruction backwards in time, +and the second one finds the last breakpoint in the past. + +Recorded executions may be used to enable reverse debugging. QEMU can't +execute the code in backwards direction, but can load a snapshot and +replay forward to find the desired position or breakpoint. + +The following GDB commands are supported: + - reverse-stepi (or rsi) - step one instruction backwards + - reverse-continue (or rc) - find last breakpoint in the past + +Reverse step loads the nearest snapshot and replays the execution until +the required instruction is met. + +Reverse continue may include several passes of examining the execution +between the snapshots. Each of the passes include the following steps: + 1. loading the snapshot + 2. replaying to examine the breakpoints + 3. if breakpoint or watchpoint was met + - loading the snaphot again + - replaying to the required breakpoint + 4. else + - proceeding to the p.1 with the earlier snapshot + +Therefore usage of the reverse debugging requires at least one snapshot +created in advance. See the "Snapshotting" section to learn about running +record/replay and creating the snapshot in these modes. + Replay log format ----------------- =20 From nobody Wed Oct 29 06:38:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524920104669749.816694410305; Sat, 28 Apr 2018 05:55:04 -0700 (PDT) Received: from localhost ([::1]:52085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCPNS-0008AJ-TA for importer@patchew.org; Sat, 28 Apr 2018 08:54:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7W-0003HC-Mq for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCP7R-0005Km-R5 for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:30 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCP7R-0005KK-Hn for qemu-devel@nongnu.org; Sat, 28 Apr 2018 08:38:25 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 6477B54006B; Sat, 28 Apr 2018 15:38:24 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Sat, 28 Apr 2018 15:38:17 +0300 Message-ID: <20180428123817.12445.83865.stgit@pasha-VirtualBox> In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox> References: <20180428123627.12445.9923.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 19/19] replay: allow loading any snapshots before recording X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, quintela@redhat.com, ciro.santilli@gmail.com, jasowang@redhat.com, crosthwaite.peter@gmail.com, zuban32s@gmail.com, armbru@redhat.com, maria.klimushenkova@ispras.ru, mst@redhat.com, kraxel@redhat.com, boost.lists@gmail.com, thomas.dullien@googlemail.com, dovgaluk@ispras.ru, mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch enables using -loadvm in recording mode to allow starting the execution recording from any of the available snapshots. It also fixes loading of the record/replay state, therefore snapshots created in replay mode may also be used for starting the new recording. Signed-off-by: Pavel Dovgalyuk --- replay/replay-snapshot.c | 17 ++++++++++++----- vl.c | 7 ++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 2ab85cf..16bacc9 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -33,11 +33,18 @@ static int replay_pre_save(void *opaque) static int replay_post_load(void *opaque, int version_id) { ReplayState *state =3D opaque; - fseek(replay_file, state->file_offset, SEEK_SET); - qemu_clock_set_last(QEMU_CLOCK_HOST, state->host_clock_last); - /* If this was a vmstate, saved in recording mode, - we need to initialize replay data fields. */ - replay_fetch_data_kind(); + if (replay_mode =3D=3D REPLAY_MODE_PLAY) { + fseek(replay_file, state->file_offset, SEEK_SET); + qemu_clock_set_last(QEMU_CLOCK_HOST, state->host_clock_last); + /* If this was a vmstate, saved in recording mode, + we need to initialize replay data fields. */ + replay_fetch_data_kind(); + } else if (replay_mode =3D=3D REPLAY_MODE_RECORD) { + /* This is only useful for loading the initial state. + Therefore reset all the counters. */ + state->instructions_count =3D 0; + state->block_request_id =3D 0; + } =20 return 0; } diff --git a/vl.c b/vl.c index 3bf85a4..122ee6b 100644 --- a/vl.c +++ b/vl.c @@ -4724,15 +4724,16 @@ int main(int argc, char **argv, char **envp) replay_checkpoint(CHECKPOINT_RESET); qemu_system_reset(SHUTDOWN_CAUSE_NONE); register_global_state(); - if (replay_mode !=3D REPLAY_MODE_NONE) { - replay_vmstate_init(); - } else if (loadvm) { + if (loadvm) { Error *local_err =3D NULL; if (load_snapshot(loadvm, &local_err) < 0) { error_report_err(local_err); autostart =3D 0; } } + if (replay_mode !=3D REPLAY_MODE_NONE) { + replay_vmstate_init(); + } =20 qdev_prop_check_globals(); if (vmstate_dump_file) {