From nobody Thu Oct 30 15:31:14 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525818307915474.98028376519255; Tue, 8 May 2018 15:25:07 -0700 (PDT) Received: from localhost ([::1]:53559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGB2g-00044U-Qq for importer@patchew.org; Tue, 08 May 2018 18:25:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGAsq-0002on-30 for qemu-devel@nongnu.org; Tue, 08 May 2018 18:14:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGAso-0001H9-WD for qemu-devel@nongnu.org; Tue, 08 May 2018 18:14:56 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:34642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGAso-0001Gy-PI for qemu-devel@nongnu.org; Tue, 08 May 2018 18:14:54 -0400 Received: by mail-wm0-x22d.google.com with SMTP id a137-v6so20816824wme.1 for ; Tue, 08 May 2018 15:14:54 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-189-60.clienti.tiscali.it. [78.12.189.60]) by smtp.gmail.com with ESMTPSA id c15-v6sm14020129edr.78.2018.05.08.15.14.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 15:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=GW3SDe8XKvsURWQSo5HbQ2/f9qTUQvmtRUzIaJWJIDg=; b=S9y4zf9nmw7jzl7cB6ghJ158b99En0Rk97qDq1tOvoA+3SY21hXYkPTuzcFMM1ytf6 oywZKUX/hFUDffeTdYW1Db4vSzvk1zZhhRW9kTmgRxJFfOzweLVP0pufcoQCSISMxjG7 gYfYZoLGiaIVBxxl/g1Ozkju2hwq3mwrupspuoYii8z+gsQ4XVTEOFYOi1sPNCKwOpTp GEf4fLaATzKFzaSI3I18d3FH/66gUDgFDQUCcdfb1mbOQ0n5yzVnmIXYoN/2dbM5pmTk uHCfD8BUjjn0R4SPsBGO0bQP1uX1xOH4XFL0n97JIjstbSXKo93fI83KBnZnNtBiUa5R YQ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=GW3SDe8XKvsURWQSo5HbQ2/f9qTUQvmtRUzIaJWJIDg=; b=hzTf+Y3LnQwv3rpdFJIzP+zqufxCrtOmFwXfzTCYXWQ1HxvMBrUvVz8pfyxkl4vuh/ aI+uv9k8VHnfDk79GsABWZGlm8MQTyvCsYQHpbmiC7abHGmHo5SwM06vv3rONcoMhHFV iwvDn8IVEiU2StAcVWE6X56hNNIzfBgeRc5d9TC1lp4HUC0p22SJ9Td9m095dA+/td7C 9AAYCStW5Gzjv4wjYfDd3MXfk8nKfiwMFO6+njR+PSm60wSih3NOWnhVDXT+iGX5myGc gJWALo9uRLVK2EQ9DKTSAV4VcXvZPHpguX2eXgCWANpe8eUuHsnXhUVsCX9vn1tUnqhx UHHQ== X-Gm-Message-State: ALQs6tD9M6Enjrn2ZBgHYBGiMlXTiSEa3G4HUIxFjwAqR3B2ocBNQEe8 RTNpawKbOpgY2iV3CAhCGffa9wyr X-Google-Smtp-Source: AB8JxZoWmY6tO+F8MnwQTfgdhVHoy/LoqPJhKFolybxumxWlwrMK8ltfLC3Po8BzmAbrDcKAC/TFuQ== X-Received: by 2002:a50:97a3:: with SMTP id e32-v6mr56583208edb.58.1525817693381; Tue, 08 May 2018 15:14:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 00:14:19 +0200 Message-Id: <1525817687-34620-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525817687-34620-1-git-send-email-pbonzini@redhat.com> References: <1525817687-34620-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22d Subject: [Qemu-devel] [PULL 02/30] cpus: Fix event order on resume of stopped guest 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: Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster When resume of a stopped guest immediately runs into block device errors, the BLOCK_IO_ERROR event is sent before the RESUME event. Reproducer: 1. Create a scratch image $ dd if=3D/dev/zero of=3Dscratch.img bs=3D1M count=3D100 Size doesn't actually matter. 2. Prepare blkdebug configuration: $ cat >blkdebug.conf < ' Issue QMP command 'qmp_capabilities': QMP> { "execute": "qmp_capabilities" } 5. Boot the guest. 6. In the guest, write to the scratch disk, e.g. like this: # dd if=3D/dev/zero of=3D/dev/vdb count=3D1 Do double-check the device specified with of=3D is actually the scratch device! 7. Issue QMP command 'cont': QMP> { "execute": "cont" } After step 6, I get a BLOCK_IO_ERROR event followed by a STOP event. Good. After step 7, I get BLOCK_IO_ERROR, then RESUME, then STOP. Not so good; I'd expect RESUME, then BLOCK_IO_ERROR, then STOP. The funny event order confuses libvirt: virsh -r domstate DOMAIN --reason reports "paused (unknown)" rather than "paused (I/O error)". The culprit is vm_prepare_start(). /* Ensure that a STOP/RESUME pair of events is emitted if a * vmstop request was pending. The BLOCK_IO_ERROR event, for * example, according to documentation is always followed by * the STOP event. */ if (runstate_is_running()) { 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); } /* We are sending this now, but the CPUs will be resumed shortly later = */ qapi_event_send_resume(&error_abort); return res; When resuming a stopped guest, we take the else branch before we get to sending RESUME. vm_state_notify() runs virtio_vmstate_change(), among other things. This restarts I/O, triggering the BLOCK_IO_ERROR event. Reshuffle vm_prepare_start() to send the RESUME event earlier. Fixes RHBZ 1566153. Cc: Paolo Bonzini Signed-off-by: Markus Armbruster Message-Id: <20180423084518.2426-1-armbru@redhat.com> Signed-off-by: Paolo Bonzini --- cpus.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cpus.c b/cpus.c index 5bcd3ec..be3a4eb 100644 --- a/cpus.c +++ b/cpus.c @@ -2043,7 +2043,6 @@ int vm_stop(RunState state) int vm_prepare_start(void) { RunState requested; - int res =3D 0; =20 qemu_vmstop_requested(&requested); if (runstate_is_running() && requested =3D=3D RUN_STATE__MAX) { @@ -2057,17 +2056,18 @@ int vm_prepare_start(void) */ if (runstate_is_running()) { 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); + qapi_event_send_resume(&error_abort); + return -1; } =20 /* We are sending this now, but the CPUs will be resumed shortly later= */ qapi_event_send_resume(&error_abort); - return res; + + replay_enable_events(); + cpu_enable_ticks(); + runstate_set(RUN_STATE_RUNNING); + vm_state_notify(1, RUN_STATE_RUNNING); + return 0; } =20 void vm_start(void) --=20 1.8.3.1