From patchwork Wed Dec 13 07:04:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhoujian (jay)" X-Patchwork-Id: 10109369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 606E860352 for ; Wed, 13 Dec 2017 07:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5012B28C06 for ; Wed, 13 Dec 2017 07:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 432D528E9C; Wed, 13 Dec 2017 07:06:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ABBE728C06 for ; Wed, 13 Dec 2017 07:06:29 +0000 (UTC) Received: from localhost ([::1]:34119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eP17d-0000By-09 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Dec 2017 02:06:29 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = QLIST_HEAD_INITIALIZER(vhost_devices); +bool used_memslots_exceeded; + bool vhost_has_free_slot(void) { unsigned int slots_limit = ~0U; @@ -1254,6 +1256,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, 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 = true; r = -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" +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" typedef struct VhostUserState { NetClientState nc; @@ -311,6 +312,10 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, net_vhost_user_event, NULL, nc0->name, NULL, true); + if (used_memslots_exceeded) { + error_report("used memslots exceeded the backend limit, quit loop"); + return -1; + } } while (!s->started); assert(s->vhost_net);