From nobody Sat Nov 23 19:59:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1731316604; cv=none; d=zohomail.com; s=zohoarc; b=SzkMbRtRMB+7fD5M/8+4wodObJsS++lZtrMSjLpdDfGA4HzF8xl6XgiZfu9SmQuQunIkPDQM2ellsbF7VH4+ZEVQi7rUwmclbMRzdxO0xcx7560mTNjr+sTvc5+4vIf2fSxf7PUqtoOeiuc2p8ghfB/aQPrrsDiMB3PRtE778/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731316604; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=BDN1p5zrYlafOqZoUySVGcZs7abeh9MudUfmrGRycI4=; b=M07YPuPph4opsaiIVNX077Pgqm4JGiHwjhqR9tOLh5DPxU5TJQZJkbu2UWcgJ8CAf/Uk0YkTJegjP3xjFZhM/2KJ6wmJiE0b/Ri2Ijcm6Ke+UhIs2hB05t5I/yrbiLqGvAnozdyeObRyYs6XJrDlJK8UI9Q93UbBSnwpoT2/SnU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731316604341156.19594609810906; Mon, 11 Nov 2024 01:16:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAQWZ-0004vC-O6; Mon, 11 Nov 2024 04:15:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAQUy-0004ad-D2 for qemu-devel@nongnu.org; Mon, 11 Nov 2024 04:14:16 -0500 Received: from mx22.baidu.com ([220.181.50.185] helo=baidu.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAQUt-0006qq-LE for qemu-devel@nongnu.org; Mon, 11 Nov 2024 04:14:15 -0500 To: qemu-devel CC: "Michael S . Tsirkin" , Stefano Garzarella , Jason Wang , zuoboqun , Gao Shiyuan Subject: [PATCH] vhost_net: fix assertion triggered by batch of host notifiers processing Date: Mon, 11 Nov 2024 16:57:25 +0800 Message-ID: <20241111085725.2924-1-zuoboqun@baidu.com> X-Mailer: git-send-email 2.42.0.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.127.72.15] X-ClientProxiedBy: BC-Mail-EX05.internal.baidu.com (172.31.51.45) To BJHW-MAIL-EX26.internal.baidu.com (10.127.64.41) X-Baidu-BdMsfe-DateCheck: 1_BJHW-Mail-Ex15_2024-11-11 16:57:34:714 X-FEAS-Client-IP: 10.127.64.38 X-FE-Policy-ID: 52:10:53:SYSTEM Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=220.181.50.185; envelope-from=zuoboqun@baidu.com; helo=baidu.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Zuo boqun From: Zuo boqun via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1731316607160116600 Content-Type: text/plain; charset="utf-8" From: zuoboqun When the backend of vhost_net restarts during the vm is running, vhost_net is stopped and started. The virtio_device_grab_ioeventfd() fucntion in vhost_net_enable_notifiers() will result in a call to virtio_bus_set_host_notifier()(assign=3Dfalse). And now virtio_device_grab_ioeventfd() is batched in a single transaction with virtio_bus_set_host_notifier()(assign=3Dtrue). This triggers the following assertion: kvm_mem_ioeventfd_del: error deleting ioeventfd: Bad file descriptor This patch moves virtio_device_grab_ioeventfd() out of the batch to fix this problem. Fixes: 6166799f6 ("vhost_net: configure all host notifiers in a single MR t= ransaction") Reported-by: Gao Shiyuan Signed-off-by: Zuo Boqun --- hw/net/vhost_net.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 997aab0557..eb3e92ca0d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -229,9 +229,24 @@ static int vhost_net_enable_notifiers(VirtIODevice *de= v, int nvhosts =3D data_queue_pairs + cvq; struct vhost_net *net; struct vhost_dev *hdev; - int r, i, j; + int r, i, j, k; NetClientState *peer; =20 + /* + * We will pass the notifiers to the kernel, make sure that QEMU + * doesn't interfere. + */ + for (i =3D 0; i < nvhosts; i++) { + r =3D virtio_device_grab_ioeventfd(dev); + if (r < 0) { + error_report("vhost %d binding does not support host notifiers= ", i); + for (k =3D 0; k < i; k++) { + virtio_device_release_ioeventfd(dev); + } + return r; + } + } + /* * Batch all the host notifiers in a single transaction to avoid * quadratic time complexity in address_space_update_ioeventfds(). @@ -247,16 +262,6 @@ static int vhost_net_enable_notifiers(VirtIODevice *de= v, =20 net =3D get_vhost_net(peer); hdev =3D &net->dev; - /* - * We will pass the notifiers to the kernel, make sure that QEMU - * doesn't interfere. - */ - r =3D virtio_device_grab_ioeventfd(dev); - if (r < 0) { - error_report("binding does not support host notifiers"); - memory_region_transaction_commit(); - goto fail_nvhosts; - } =20 for (j =3D 0; j < hdev->nvqs; j++) { r =3D virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), @@ -277,6 +282,10 @@ static int vhost_net_enable_notifiers(VirtIODevice *de= v, return 0; fail_nvhosts: vhost_net_disable_notifiers_nvhosts(dev, ncs, data_queue_pairs, i); + for (k =3D i + 1; k < nvhosts; k++) { + virtio_device_release_ioeventfd(dev); + } + return r; } =20 --=20 2.42.0.windows.2