From nobody Wed Oct 29 11:29:44 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 1526026642217955.6693080627061; Fri, 11 May 2018 01:17:22 -0700 (PDT) Received: from localhost ([::1]:37438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH3Eo-0002RN-BV for importer@patchew.org; Fri, 11 May 2018 04:17:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH3Dl-00024Z-OL for qemu-devel@nongnu.org; Fri, 11 May 2018 04:16:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH3Dj-0006ku-41 for qemu-devel@nongnu.org; Fri, 11 May 2018 04:16:09 -0400 Received: from mail.ispras.ru ([83.149.199.45]:44272) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH3Di-0006kU-SJ for qemu-devel@nongnu.org; Fri, 11 May 2018 04:16:07 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 5C468540188; Fri, 11 May 2018 11:16:04 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 11:16:01 +0300 Message-ID: <20180511081601.14610.39946.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] 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: maria.klimushenkova@ispras.ru, mst@redhat.com, ciro.santilli@gmail.com, arei.gonglei@huawei.com, dovgaluk@ispras.ru, kraxel@redhat.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com 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 06f5d2a..8b1931b 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -837,7 +837,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++) { @@ -852,7 +857,6 @@ static void ps2_common_post_load(PS2State *s) q->rptr =3D 0; q->wptr =3D size; q->count =3D size; - s->update_irq(s->update_arg, q->count !=3D 0); } =20 static void ps2_kbd_reset(void *opaque)