From nobody Wed May 1 15:13:55 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.zohomail.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 1505888204075858.6004320385371; Tue, 19 Sep 2017 23:16:44 -0700 (PDT) Received: from localhost ([::1]:46895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duYJO-0000uJ-21 for importer@patchew.org; Wed, 20 Sep 2017 02:16:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duYIZ-0000b7-DS for qemu-devel@nongnu.org; Wed, 20 Sep 2017 02:15:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duYIV-0008PR-Ag for qemu-devel@nongnu.org; Wed, 20 Sep 2017 02:15:51 -0400 Received: from proxmox.maurer-it.com ([212.186.127.180]:20823) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1duYIV-00088F-2l for qemu-devel@nongnu.org; Wed, 20 Sep 2017 02:15:47 -0400 Received: from proxmox.maurer-it.com (localhost [127.0.0.1]) by proxmox.maurer-it.com (Proxmox) with ESMTP id 55CDA10005A9; Wed, 20 Sep 2017 08:09:35 +0200 (CEST) From: Wolfgang Bumiller To: qemu-devel@nongnu.org Date: Wed, 20 Sep 2017 08:09:33 +0200 Message-Id: <20170920060933.11593-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 212.186.127.180 Subject: [Qemu-devel] [PATCH] virtio: fix descriptor counting in virtqueue_pop 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: Paolo Bonzini , "Michael S . Tsirkin" 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" While changing the s/g list allocation, commit 3b3b0628 also changed the descriptor counting to count iovec entries as split by cpu_physical_memory_map(). Previously only the actual descriptor entries were counted and the split into the iovec happened afterwards in virtqueue_map(). Count the entries again instead to avoid erroneous "Looped descriptor" errors. Reported-by: Hans Middelhoek Link: https://forum.proxmox.com/threads/vm-crash-with-memory-hotplug.35904/ Fixes: 3b3b0628217e ("virtio: slim down allocation of VirtQueueElements") Signed-off-by: Wolfgang Bumiller Reported-by: Hans Middelhoek =20 --- hw/virtio/virtio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 890b4d7eb7..33bb770177 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -834,7 +834,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) int64_t len; VirtIODevice *vdev =3D vq->vdev; VirtQueueElement *elem =3D NULL; - unsigned out_num, in_num; + unsigned out_num, in_num, elem_entries; hwaddr addr[VIRTQUEUE_MAX_SIZE]; struct iovec iov[VIRTQUEUE_MAX_SIZE]; VRingDesc desc; @@ -852,7 +852,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) smp_rmb(); =20 /* When we start there are none of either input nor output. */ - out_num =3D in_num =3D 0; + out_num =3D in_num =3D elem_entries =3D 0; =20 max =3D vq->vring.num; =20 @@ -922,7 +922,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) } =20 /* If we've got too many, that implies a descriptor loop. */ - if ((in_num + out_num) > max) { + if (++elem_entries > max) { virtio_error(vdev, "Looped descriptor"); goto err_undo_map; } --=20 2.11.0