qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: arei.gonglei@huawei.com, mst@redhat.com, ciro.santilli@gmail.com,
	maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru,
	kraxel@redhat.com, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH] ps2: prevent changing irq state on save and load
Date: Fri, 11 May 2018 11:16:01 +0300	[thread overview]
Message-ID: <20180511081601.14610.39946.stgit@pasha-VirtualBox> (raw)

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 <Pavel.Dovgaluk@ispras.ru>
---
 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];
 
     /* set the useful data buffer queue size, < PS2_QUEUE_SIZE */
-    size = (q->count < 0 || q->count > PS2_QUEUE_SIZE) ? 0 : q->count;
+    size = q->count;
+    if (q->count < 0) {
+        size = 0;
+    } else if (q->count > PS2_QUEUE_SIZE) {
+        size = PS2_QUEUE_SIZE;
+    }
 
     /* move the queue elements to the start of data array */
     for (i = 0; i < size; i++) {
@@ -852,7 +857,6 @@ static void ps2_common_post_load(PS2State *s)
     q->rptr = 0;
     q->wptr = size;
     q->count = size;
-    s->update_irq(s->update_arg, q->count != 0);
 }
 
 static void ps2_kbd_reset(void *opaque)

             reply	other threads:[~2018-05-11  8:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11  8:16 Pavel Dovgalyuk [this message]
2018-05-11  9:13 ` [Qemu-devel] [PATCH] ps2: prevent changing irq state on save and load Paolo Bonzini
2018-09-11 10:18   ` Pavel Dovgalyuk
2018-09-11 11:10     ` Paolo Bonzini
2018-09-11 11:25       ` Gerd Hoffmann
2018-09-11 11:26         ` Paolo Bonzini
2018-09-11 11:27           ` Pavel Dovgalyuk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180511081601.14610.39946.stgit@pasha-VirtualBox \
    --to=pavel.dovgaluk@ispras.ru \
    --cc=arei.gonglei@huawei.com \
    --cc=ciro.santilli@gmail.com \
    --cc=dovgaluk@ispras.ru \
    --cc=kraxel@redhat.com \
    --cc=maria.klimushenkova@ispras.ru \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).