From nobody Sat Apr 27 10:34:30 2024 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.zoho.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490365570284246.71919835073936; Fri, 24 Mar 2017 07:26:10 -0700 (PDT) Received: from localhost ([::1]:33425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crQAK-0004Dk-8y for importer@patchew.org; Fri, 24 Mar 2017 10:26:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crQ9F-0003Yx-AG for qemu-devel@nongnu.org; Fri, 24 Mar 2017 10:25:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1crQ9C-00059p-Fn for qemu-devel@nongnu.org; Fri, 24 Mar 2017 10:25:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56458) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1crQ9C-00059Z-2r for qemu-devel@nongnu.org; Fri, 24 Mar 2017 10:24:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 29AD764A61 for ; Fri, 24 Mar 2017 14:24:58 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (dhcp-1-129.brq.redhat.com [10.34.1.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 573275DD62; Fri, 24 Mar 2017 14:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 29AD764A61 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lprosek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 29AD764A61 From: Ladi Prosek To: qemu-devel@nongnu.org Date: Fri, 24 Mar 2017 15:24:49 +0100 Message-Id: <1490365490-4854-2-git-send-email-lprosek@redhat.com> In-Reply-To: <1490365490-4854-1-git-send-email-lprosek@redhat.com> References: <1490365490-4854-1-git-send-email-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 24 Mar 2017 14:24:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] virtio-input: free event queue when finalizing 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: kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" VirtIOInput.queue was never freed. This commit adds an explicit g_free to virtio_input_finalize and switches the allocation function from realloc to g_realloc in virtio_input_send. Signed-off-by: Ladi Prosek --- hw/input/virtio-input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index b678ee9..728832a 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -32,8 +32,8 @@ void virtio_input_send(VirtIOInput *vinput, virtio_input_= event *event) /* queue up events ... */ if (vinput->qindex =3D=3D vinput->qsize) { vinput->qsize++; - vinput->queue =3D realloc(vinput->queue, vinput->qsize * - sizeof(virtio_input_event)); + vinput->queue =3D g_realloc(vinput->queue, vinput->qsize * + sizeof(virtio_input_event)); } vinput->queue[vinput->qindex++] =3D *event; =20 @@ -272,6 +272,8 @@ static void virtio_input_finalize(Object *obj) QTAILQ_REMOVE(&vinput->cfg_list, cfg, node); g_free(cfg); } + + g_free(vinput->queue); } static void virtio_input_device_unrealize(DeviceState *dev, Error **errp) { --=20 2.7.4 From nobody Sat Apr 27 10:34:30 2024 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.zoho.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490365682126702.4446166046339; Fri, 24 Mar 2017 07:28:02 -0700 (PDT) Received: from localhost ([::1]:33433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crQC8-0005gZ-1F for importer@patchew.org; Fri, 24 Mar 2017 10:28:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crQ9F-0003Yw-9k for qemu-devel@nongnu.org; Fri, 24 Mar 2017 10:25:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1crQ9D-0005AE-Bt for qemu-devel@nongnu.org; Fri, 24 Mar 2017 10:25:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47930) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1crQ9D-00059t-41 for qemu-devel@nongnu.org; Fri, 24 Mar 2017 10:24:59 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30840804FA for ; Fri, 24 Mar 2017 14:24:59 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (dhcp-1-129.brq.redhat.com [10.34.1.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7007D18A75; Fri, 24 Mar 2017 14:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 30840804FA Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lprosek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 30840804FA From: Ladi Prosek To: qemu-devel@nongnu.org Date: Fri, 24 Mar 2017 15:24:50 +0100 Message-Id: <1490365490-4854-3-git-send-email-lprosek@redhat.com> In-Reply-To: <1490365490-4854-1-git-send-email-lprosek@redhat.com> References: <1490365490-4854-1-git-send-email-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 24 Mar 2017 14:24:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] virtio-input: fix eventq batching 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: kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" virtio_input_send buffers input events until it sees a SYNC. Then it either sends or drops the entire batch, depending on whether eventq has enough space available. The case to avoid here is partial sends where only part of the batch would get to the guest. Using virtqueue_get_avail_bytes to check the state of eventq was not correct. The queue may have a smaller number of larger buffers available so bytes may be enough but the batch would still not be possible to send, leading to the "Huh? No vq elem available" error. Instead of checking available bytes, this patch optimistically pops buffers from the queue and puts them back in case it runs out of space and the batch needs to be dropped. Signed-off-by: Ladi Prosek --- hw/input/virtio-input.c | 29 ++++++++++++++--------------- include/hw/virtio/virtio-input.h | 5 ++++- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index 728832a..0e42f0d 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -22,7 +22,6 @@ void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event) { VirtQueueElement *elem; - unsigned have, need; int i, len; =20 if (!vinput->active) { @@ -33,9 +32,9 @@ void virtio_input_send(VirtIOInput *vinput, virtio_input_= event *event) if (vinput->qindex =3D=3D vinput->qsize) { vinput->qsize++; vinput->queue =3D g_realloc(vinput->queue, vinput->qsize * - sizeof(virtio_input_event)); + sizeof(vinput->queue[0])); } - vinput->queue[vinput->qindex++] =3D *event; + vinput->queue[vinput->qindex++].event =3D *event; =20 /* ... until we see a report sync ... */ if (event->type !=3D cpu_to_le16(EV_SYN) || @@ -44,24 +43,24 @@ void virtio_input_send(VirtIOInput *vinput, virtio_inpu= t_event *event) } =20 /* ... then check available space ... */ - need =3D sizeof(virtio_input_event) * vinput->qindex; - virtqueue_get_avail_bytes(vinput->evt, &have, NULL, need, 0); - if (have < need) { - vinput->qindex =3D 0; - trace_virtio_input_queue_full(); - return; - } - - /* ... and finally pass them to the guest */ for (i =3D 0; i < vinput->qindex; i++) { elem =3D virtqueue_pop(vinput->evt, sizeof(VirtQueueElement)); if (!elem) { - /* should not happen, we've checked for space beforehand */ - fprintf(stderr, "%s: Huh? No vq elem available ...\n", __func= __); + while (--i >=3D 0) { + virtqueue_unpop(vinput->evt, vinput->queue[i].elem, 0); + } + vinput->qindex =3D 0; + trace_virtio_input_queue_full(); return; } + vinput->queue[i].elem =3D elem; + } + + /* ... and finally pass them to the guest */ + for (i =3D 0; i < vinput->qindex; i++) { + elem =3D vinput->queue[i].elem; len =3D iov_from_buf(elem->in_sg, elem->in_num, - 0, vinput->queue+i, sizeof(virtio_input_event)); + 0, &vinput->queue[i].event, sizeof(virtio_input= _event)); virtqueue_push(vinput->evt, elem, len); g_free(elem); } diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-in= put.h index 55db310..91df57e 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -62,7 +62,10 @@ struct VirtIOInput { VirtQueue *evt, *sts; char *serial; =20 - virtio_input_event *queue; + struct { + virtio_input_event event; + VirtQueueElement *elem; + } *queue; uint32_t qindex, qsize; =20 bool active; --=20 2.7.4