Received: from eggs.gnu.org ([2001:4830:134:3::10]:47795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4qXw-0000Gy-GP for qemu-devel@nongnu.org; Thu, 10 Nov 2016 09:41:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4qXt-00068O-C7 for qemu-devel@nongnu.org; Thu, 10 Nov 2016 09:41:44 -0500 Sender: Paolo Bonzini References: <1478768797-26401-1-git-send-email-thuth@redhat.com> From: Paolo Bonzini Message-ID: <7039ad6d-052a-3b1a-8f27-1efba2b3b65d@redhat.com> Date: Thu, 10 Nov 2016 15:41:37 +0100 MIME-Version: 1.0 In-Reply-To: <1478768797-26401-1-git-send-email-thuth@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] spapr-vty: Fix bad assert() statement List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth , David Gibson , qemu-ppc@nongnu.org Cc: Alexander Graf , qemu-devel@nongnu.org On 10/11/2016 10:06, Thomas Huth wrote: > When using the serial console in the GTK interface of QEMU (and > QEMU has been compiled with CONFIG_VTE), it is possible to trigger > the assert() statement in vty_receive() in spapr_vty.c by pasting > a chunk of text with length > 16 into the QEMU window. > Most of the other serial backends seem to simply drop characters > that they can not handle, so I think we should also do the same in > spapr-vty to fix this issue. And since it is quite ugly when pasted > text is chopped after 16 bytes, we also increase the size of the > input buffer here so that we can at least handle a couple of text > lines. > > Buglink: https://bugs.launchpad.net/qemu/+bug/1639322 > Signed-off-by: Thomas Huth > --- > hw/char/spapr_vty.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c > index 31822fe..bee6c34 100644 > --- a/hw/char/spapr_vty.c > +++ b/hw/char/spapr_vty.c > @@ -1,4 +1,5 @@ > #include "qemu/osdep.h" > +#include "qemu/error-report.h" > #include "qapi/error.h" > #include "qemu-common.h" > #include "cpu.h" > @@ -7,7 +8,7 @@ > #include "hw/ppc/spapr.h" > #include "hw/ppc/spapr_vio.h" > > -#define VTERM_BUFSIZE 16 > +#define VTERM_BUFSIZE 2048 This change causes a change in the migration protocol. Paolo > > typedef struct VIOsPAPRVTYDevice { > VIOsPAPRDevice sdev; > @@ -37,7 +38,15 @@ static void vty_receive(void *opaque, const uint8_t *buf, int size) > qemu_irq_pulse(spapr_vio_qirq(&dev->sdev)); > } > for (i = 0; i < size; i++) { > - assert((dev->in - dev->out) < VTERM_BUFSIZE); > + if (dev->in - dev->out >= VTERM_BUFSIZE) { > + static bool reported; > + if (!reported) { > + error_report("VTY input buffer exhausted - characters dropped." > + " (input size = %i)", size); > + reported = true; > + } > + break; > + } > dev->buf[dev->in++ % VTERM_BUFSIZE] = buf[i]; > } > } >