From nobody Wed Nov 5 05:06:24 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 1532526359985804.2262117951368; Wed, 25 Jul 2018 06:45:59 -0700 (PDT) Received: from localhost ([::1]:49259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiIyE-00085O-AC for importer@patchew.org; Wed, 25 Jul 2018 08:32:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiIik-0003F6-0B for qemu-devel@nongnu.org; Wed, 25 Jul 2018 08:16:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiIig-0006co-W1 for qemu-devel@nongnu.org; Wed, 25 Jul 2018 08:16:45 -0400 Received: from mail.ispras.ru ([83.149.199.45]:36876) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiIig-0006bG-Le for qemu-devel@nongnu.org; Wed, 25 Jul 2018 08:16:42 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id BA9CC54006B; Wed, 25 Jul 2018 15:16:41 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Wed, 25 Jul 2018 15:16:43 +0300 Message-ID: <20180725121643.12867.61576.stgit@pasha-VirtualBox> In-Reply-To: <20180725121311.12867.21729.stgit@pasha-VirtualBox> References: <20180725121311.12867.21729.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] [PATCH v5 20/24] ps2: prevent changing irq state on save and load 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 Commit 2858ab09e6f708e381fc1a1cc87e747a690c4884 changed PS/2 keyboard/mouse buffers to the standard size. However, its state may change when migrating from the old buffer size and therefore irq needs updating. But this change made wrong, because it throws the whole queue if there are too much data instead of cropping it. That commit also updates irq (because the queue state may change). But updating the irq may change the VM state (and determinism of the execution). E.g., when replaying the execution, one may save the VM state and the state of the interrupt controller will be updated at the moment of saving, instead of using the recorded update events. This patch makes the queue update deterministic: it removes the update_irq call and crops the queue to prevent losing the characters and changing the required irq status. Signed-off-by: Pavel Dovgalyuk --- hw/input/ps2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index fdfcadf..6c43fc2 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -914,7 +914,12 @@ static void ps2_common_post_load(PS2State *s) uint8_t tmp_data[PS2_QUEUE_SIZE]; =20 /* set the useful data buffer queue size, < PS2_QUEUE_SIZE */ - size =3D (q->count < 0 || q->count > PS2_QUEUE_SIZE) ? 0 : q->count; + size =3D q->count; + if (q->count < 0) { + size =3D 0; + } else if (q->count > PS2_QUEUE_SIZE) { + size =3D PS2_QUEUE_SIZE; + } =20 /* move the queue elements to the start of data array */ for (i =3D 0; i < size; i++) { @@ -929,7 +934,6 @@ static void ps2_common_post_load(PS2State *s) q->rptr =3D 0; q->wptr =3D (size =3D=3D PS2_QUEUE_SIZE) ? 0 : size; q->count =3D size; - s->update_irq(s->update_arg, q->count !=3D 0); } =20 static void ps2_kbd_reset(void *opaque)