qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/1] ui/gtk: prevent QEMU lock up
@ 2021-07-25 16:46 Volker Rümelin
  2021-07-25 16:50 ` [PATCH for 6.1 v2 1/1] ui/gtk: add a keyboard fifo to the VTE consoles Volker Rümelin
  2021-07-26  8:28 ` [PATCH v2 0/1] ui/gtk: prevent QEMU lock up Gerd Hoffmann
  0 siblings, 2 replies; 3+ messages in thread
From: Volker Rümelin @ 2021-07-25 16:46 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Zack Marvel, qemu-devel

Since commit 8eb13bbbac ("ui/gtk: vte: fix sending multiple
characeters") it's very easy to lock up QEMU with the GTK ui.
If you configure a guest with a serial device and the guest
doesn't listen on this device, QEMU will lock up after
entering two characters in the serial console.

v2:
Gerd suggested to use the chr_accept_input() callback function
instead of a write retry timer and to drop patch 2/2.

Volker Rümelin (1):
   ui/gtk: add a keyboard fifo to the VTE consoles

  include/ui/gtk.h |  4 ++++
  ui/gtk.c         | 42 +++++++++++++++++++++++++++++++++---------
  2 files changed, 37 insertions(+), 9 deletions(-)

-- 
2.26.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH for 6.1 v2 1/1] ui/gtk: add a keyboard fifo to the VTE consoles
  2021-07-25 16:46 [PATCH v2 0/1] ui/gtk: prevent QEMU lock up Volker Rümelin
@ 2021-07-25 16:50 ` Volker Rümelin
  2021-07-26  8:28 ` [PATCH v2 0/1] ui/gtk: prevent QEMU lock up Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Volker Rümelin @ 2021-07-25 16:50 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Zack Marvel, qemu-devel

Since commit 8eb13bbbac ("ui/gtk: vte: fix sending multiple
characeters") it's very easy to lock up QEMU with the GTK ui.
If you configure a guest with a serial device and the guest
doesn't listen on this device, QEMU will lock up after
entering two characters in the serial console. That's because
current code uses a busy loop for the chardev write retries
and the busy loop doesn't terminate in this case.

To fix this problem add a fifo to the VTE consoles and use the
chr_accept_input() callback function to write the remaining
characters in the queue to the chardev.

The fifo has a size of 4096 bytes, so one can copy and paste
a fairly large URL or file path.

Fixes: 8eb13bbbac ("ui/gtk: vte: fix sending multiple characeters")
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 include/ui/gtk.h |  4 ++++
 ui/gtk.c         | 42 +++++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/include/ui/gtk.h b/include/ui/gtk.h
index 9516670ebc..80d6bbd9b5 100644
--- a/include/ui/gtk.h
+++ b/include/ui/gtk.h
@@ -25,6 +25,9 @@
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
 #endif
+#ifdef CONFIG_VTE
+#include "qemu/fifo8.h"
+#endif
 
 #define MAX_VCS 10
 
@@ -62,6 +65,7 @@ typedef struct VirtualVteConsole {
     GtkWidget *scrollbar;
     GtkWidget *terminal;
     Chardev *chr;
+    Fifo8 out_fifo;
     bool echo;
 } VirtualVteConsole;
 #endif
diff --git a/ui/gtk.c b/ui/gtk.c
index 376b4d528d..6cbcceda12 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1652,6 +1652,25 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
     }
 }
 
+static void gd_vc_send_chars(VirtualConsole *vc)
+{
+    uint32_t len, avail;
+
+    len = qemu_chr_be_can_write(vc->vte.chr);
+    avail = fifo8_num_used(&vc->vte.out_fifo);
+    if (len > avail) {
+        len = avail;
+    }
+    while (len > 0) {
+        const uint8_t *buf;
+        uint32_t size;
+
+        buf = fifo8_pop_buf(&vc->vte.out_fifo, len, &size);
+        qemu_chr_be_write(vc->vte.chr, (uint8_t *)buf, size);
+        len -= size;
+    }
+}
+
 static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
 {
     VCChardev *vcd = VC_CHARDEV(chr);
@@ -1661,6 +1680,14 @@ static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
     return len;
 }
 
+static void gd_vc_chr_accept_input(Chardev *chr)
+{
+    VCChardev *vcd = VC_CHARDEV(chr);
+    VirtualConsole *vc = vcd->console;
+
+    gd_vc_send_chars(vc);
+}
+
 static void gd_vc_chr_set_echo(Chardev *chr, bool echo)
 {
     VCChardev *vcd = VC_CHARDEV(chr);
@@ -1700,6 +1727,7 @@ static void char_gd_vc_class_init(ObjectClass *oc, void *data)
     cc->parse = qemu_chr_parse_vc;
     cc->open = gd_vc_open;
     cc->chr_write = gd_vc_chr_write;
+    cc->chr_accept_input = gd_vc_chr_accept_input;
     cc->chr_set_echo = gd_vc_chr_set_echo;
 }
 
@@ -1714,6 +1742,7 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
                          gpointer user_data)
 {
     VirtualConsole *vc = user_data;
+    uint32_t free;
 
     if (vc->vte.echo) {
         VteTerminal *term = VTE_TERMINAL(vc->vte.terminal);
@@ -1733,16 +1762,10 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
         }
     }
 
-    int remaining = size;
-    uint8_t* p = (uint8_t *)text;
-    while (remaining > 0) {
-        int can_write = qemu_chr_be_can_write(vc->vte.chr);
-        int written = MIN(remaining, can_write);
-        qemu_chr_be_write(vc->vte.chr, p, written);
+    free = fifo8_num_free(&vc->vte.out_fifo);
+    fifo8_push_all(&vc->vte.out_fifo, (uint8_t *)text, MIN(free, size));
+    gd_vc_send_chars(vc);
 
-        remaining -= written;
-        p += written;
-    }
     return TRUE;
 }
 
@@ -1759,6 +1782,7 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
     vc->s = s;
     vc->vte.echo = vcd->echo;
     vc->vte.chr = chr;
+    fifo8_create(&vc->vte.out_fifo, 4096);
     vcd->console = vc;
 
     snprintf(buffer, sizeof(buffer), "vc%d", idx);
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 0/1] ui/gtk: prevent QEMU lock up
  2021-07-25 16:46 [PATCH v2 0/1] ui/gtk: prevent QEMU lock up Volker Rümelin
  2021-07-25 16:50 ` [PATCH for 6.1 v2 1/1] ui/gtk: add a keyboard fifo to the VTE consoles Volker Rümelin
@ 2021-07-26  8:28 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2021-07-26  8:28 UTC (permalink / raw)
  To: Volker Rümelin; +Cc: Zack Marvel, qemu-devel

  Hi,

> Since commit 8eb13bbbac ("ui/gtk: vte: fix sending multiple
> characeters") it's very easy to lock up QEMU with the GTK ui.
> If you configure a guest with a serial device and the guest
> doesn't listen on this device, QEMU will lock up after
> entering two characters in the serial console.
> 
> v2:
> Gerd suggested to use the chr_accept_input() callback function
> instead of a write retry timer and to drop patch 2/2.

Very nice and easy to read patch now.

Queued up for 6.1.

thanks,
  Gerd



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-26  8:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-25 16:46 [PATCH v2 0/1] ui/gtk: prevent QEMU lock up Volker Rümelin
2021-07-25 16:50 ` [PATCH for 6.1 v2 1/1] ui/gtk: add a keyboard fifo to the VTE consoles Volker Rümelin
2021-07-26  8:28 ` [PATCH v2 0/1] ui/gtk: prevent QEMU lock up Gerd Hoffmann

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).