Received: from eggs.gnu.org ([2001:4830:134:3::10]:38000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c50Gx-0002Qr-8M for qemu-devel@nongnu.org; Thu, 10 Nov 2016 20:04:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c50Gu-0007cB-KI for qemu-devel@nongnu.org; Thu, 10 Nov 2016 20:04:51 -0500 Date: Fri, 11 Nov 2016 10:01:06 +1100 From: David Gibson Message-ID: <20161110230106.GB18868@umbus.fritz.box> References: <1478768797-26401-1-git-send-email-thuth@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="xgyAXRrhYN0wYx8y" Content-Disposition: inline In-Reply-To: <1478768797-26401-1-git-send-email-thuth@redhat.com> 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 Cc: qemu-ppc@nongnu.org, Alexander Graf , qemu-devel@nongnu.org, pbonzini@redhat.com --xgyAXRrhYN0wYx8y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 10, 2016 at 10:06:37AM +0100, 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. Adding Paolo to CC, as qemu-char maintainer. So, vastly increasing the buffer like this doesn't seem right - the plain 16550 serial driver doesn't maintain a buffer bigger than its small internal FIFO (32 characters IIRC) - or a single byte if the FIFO is disabled. I thought the other side of the char driver was supposed to call can_receive() first and not deliver more bytes than we can handle - hence the assert. That said, I think vty_can_receive() has a bug - looking at other drivers, I think it's supposed to return the amount of buffer space available, but we're just returning 0 or 1. Although AFAICT that should still work, just inefficiently. If you use a serial port with the same GTK interface, do you get the same problem with pastes of >16 characters being truncated? >=20 > 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(-) >=20 > 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" > =20 > -#define VTERM_BUFSIZE 16 > +#define VTERM_BUFSIZE 2048 > =20 > typedef struct VIOsPAPRVTYDevice { > VIOsPAPRDevice sdev; > @@ -37,7 +38,15 @@ static void vty_receive(void *opaque, const uint8_t *b= uf, int size) > qemu_irq_pulse(spapr_vio_qirq(&dev->sdev)); > } > for (i =3D 0; i < size; i++) { > - assert((dev->in - dev->out) < VTERM_BUFSIZE); > + if (dev->in - dev->out >=3D VTERM_BUFSIZE) { > + static bool reported; > + if (!reported) { > + error_report("VTY input buffer exhausted - characters dr= opped." > + " (input size =3D %i)", size); > + reported =3D true; > + } > + break; > + } > dev->buf[dev->in++ % VTERM_BUFSIZE] =3D buf[i]; > } > } --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --xgyAXRrhYN0wYx8y Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYJPwvAAoJEGw4ysog2bOSUH8QAMkh4GpoQqhQ++sY5o4znP8d kA+q7D/ouV26aAOaDHn5HCxrTyFIAlkswONx4DeJKU1McDc6Ryapr27d95fI4yqy QAgJOlHLR4eQQt3AUHs5L3h6sIr/XPzqvn/MvVlwZbEFL8doY/DoqEfTqmMBRXDI y0xL7QOxoqyfsIFeyp+zLi+IM+sHcYcQdNKq777vOubxXAgAUALDq7fgSzZoyRAK diOpu65O8tRzcoe5OiUjqOzyqYsW5jW5dvkj1r4RC7b7vOflXU2hC22lAWA6vSkS X5hwSptMs/4vymUiGVk10XHpDvnYNjt/vrRdG0TzKgxX2y1RL7SxWlk6yQzK7xF5 1v3PeL9QQdBm1prx1Ir0kBTVE/Yfdx5RFRaes06P4AhZrKCguwJsXcCS4i7drQoM sS6wvqp/p0kimWU/3DSWCmno6gVR8OXLAhiH3pTTNf1ie5zypyGMaxncDuVFcNZc AFLx+NkVnKriDGo1xumVYVT1/ZB/WH5/sbO9YggBUGB0Ggufz7zpoyUYEdbllIUa geS0+QO1H1633sETM6l+MCBlgphdpOkqpy7X1clQTcz5BHfphECyuxi5iTy/31BE 4o01sSjPZhWZtw2c9HDDI4g83DB+qZpR+oGCt26K/mXAS74oepFjFXj6N8io8XVA rK4g0cM58+JvHrDSYokA =k/CI -----END PGP SIGNATURE----- --xgyAXRrhYN0wYx8y--