From nobody Tue Oct 28 21:11:13 2025 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513148809783768.5750919361941; Tue, 12 Dec 2017 23:06:49 -0800 (PST) Received: from localhost ([::1]:34119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eP17r-0000By-2Y for importer@patchew.org; Wed, 13 Dec 2017 02:06:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eP16x-0008Ka-LO for qemu-devel@nongnu.org; Wed, 13 Dec 2017 02:05:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eP16u-0005gp-GT for qemu-devel@nongnu.org; Wed, 13 Dec 2017 02:05:47 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2743) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eP16t-0005et-Td for qemu-devel@nongnu.org; Wed, 13 Dec 2017 02:05:44 -0500 Received: from 172.30.72.59 (EHLO DGGEMS401-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DMC56282; Wed, 13 Dec 2017 15:05:30 +0800 (CST) Received: from localhost (10.177.19.14) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.361.1; Wed, 13 Dec 2017 15:05:21 +0800 From: Jay Zhou To: Date: Wed, 13 Dec 2017 15:04:50 +0800 Message-ID: <1513148690-23440-1-git-send-email-jianjay.zhou@huawei.com> X-Mailer: git-send-email 2.6.1.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.19.14] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.5A30D13B.00D2, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 3d18cb79b5bc34c1b98f02f769597112 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [RFC PATCH] vhost-user: quit infinite loop while used memslots is more than the backend limit 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: weidong.huang@huawei.com, mst@redhat.com, jasowang@redhat.com, arei.gonglei@huawei.com, jianjay.zhou@huawei.com, marcandre.lureau@redhat.com, wangxinxin.wang@huawei.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 Content-Type: text/plain; charset="utf-8" Steps to 100% reproduce: (1) start a VM with two VFIO 82599 PCI NICs successfully (2) hot plug a RAM, which is attached successfully (3) hot plug another RAM, which is attached successfully (4) hot plug a vhost-user NIC, which is attached successfully (5) hot plug another vhost-user NIC, which is hanged then the qemu process infinitely and quickly print the logs below: [...] vhost backend memory slots limit is less than current number of present= memory slots failed to init vhost_net for queue 0 vhost backend memory slots limit is less than current number of present= memory slots failed to init vhost_net for queue 0 vhost backend memory slots limit is less than current number of present= memory slots failed to init vhost_net for queue 0 [...] and the cpu utilization of the systemd-journal process on host is 100%, the reason is clear: "used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)" is true in vhost_dev_init, and the main thread in the infinite do and while loop in net_vhost_user_init. One way is to increase the vhost backend memory slots limit, some discussions are here: https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg04572.html I think if "used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)" is true, it does not make sense to try to initialize the vhost-user again and again, because the main thread can not handle other qmps at all, which means it can not reduce the number of memslots, it must be failed at last. Signed-off-by: Jay Zhou --- hw/virtio/vhost.c | 3 +++ include/hw/virtio/vhost.h | 2 ++ net/vhost-user.c | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e4290ce..1cc4a18 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -47,6 +47,8 @@ static unsigned int used_memslots; static QLIST_HEAD(, vhost_dev) vhost_devices =3D QLIST_HEAD_INITIALIZER(vhost_devices); =20 +bool used_memslots_exceeded; + bool vhost_has_free_slot(void) { unsigned int slots_limit =3D ~0U; @@ -1254,6 +1256,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev= )) { error_report("vhost backend memory slots limit is less" " than current number of present memory slots"); + used_memslots_exceeded =3D true; r =3D -1; goto fail; } diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 467dc77..bcc66d9 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -6,6 +6,8 @@ #include "hw/virtio/virtio.h" #include "exec/memory.h" =20 +extern bool used_memslots_exceeded; + /* Generic structures common for any vhost based device. */ struct vhost_virtqueue { int kick; diff --git a/net/vhost-user.c b/net/vhost-user.c index c23927c..8b7bfff 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -17,6 +17,7 @@ #include "qemu/error-report.h" #include "qmp-commands.h" #include "trace.h" +#include "include/hw/virtio/vhost.h" =20 typedef struct VhostUserState { NetClientState nc; @@ -311,6 +312,10 @@ static int net_vhost_user_init(NetClientState *peer, c= onst char *device, qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, net_vhost_user_event, NULL, nc0->name, NU= LL, true); + if (used_memslots_exceeded) { + error_report("used memslots exceeded the backend limit, quit l= oop"); + return -1; + } } while (!s->started); =20 assert(s->vhost_net); --=20 1.8.3.1