From nobody Mon Feb 9 16:04:22 2026 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=1648484597; cv=none; d=zohomail.com; s=zohoarc; b=HHuoaowb2Ah7QzZ0nC0/IYwzay6W03eLxWsy3Hf5H8B72niOhL9xb5WwKvB8vnQxyyr59i4xVySAC48H6hLx8JR4e3VDZwJO48kc3WfdqXUD0Am9Iq4J8hKYwK7eCfkXueXHBpfMe6ln91sRZ6tIGuCqsOwU9df2bKdBXLRoPUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648484597; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=S9LvyunZRKCz5Znph26GsfStG7dZn+DiXOeKzgWb+Zc=; b=WROVTEUSUSsu/4FphQA6FqaiFA+FD34JYf+SxP8OW6turC8b4LnP+fbyb1Wv6nkw2/NgqLof8TpKYUFuYOV2aBGt91gyhHSAeFi3zs5Wv5OMwiHHw58QfKERssdO8IO9Q5mKRcT+jtz5CWry9A6VOehakiVAKcBRQvJ1fKaM5kY= 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 1648484597810439.5868350661815; Mon, 28 Mar 2022 09:23:17 -0700 (PDT) Received: from localhost ([::1]:35454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nYs9E-0000lf-Ce for importer@patchew.org; Mon, 28 Mar 2022 12:23:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYs7G-00084o-Nn; Mon, 28 Mar 2022 12:21:18 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:5137) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYs7D-00023n-D8; Mon, 28 Mar 2022 12:21:14 -0400 Received: from canpemm500004.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KRyYg0RGDzCrQc; Tue, 29 Mar 2022 00:18:47 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500004.china.huawei.com (7.192.104.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 29 Mar 2022 00:20:58 +0800 To: , , , , CC: , , Subject: [PATCH] hw/vhost-user-blk: fix ioeventfd add failed when start reenter Date: Tue, 29 Mar 2022 00:15:46 +0800 Message-ID: <20220328161546.917234-1-wangjie88@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500004.china.huawei.com (7.192.104.92) X-CFilter-Loop: Reflected 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=45.249.212.188; envelope-from=wangjie88@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Jie Wang From: Jie Wang via X-ZM-MESSAGEID: 1648484599867100001 Content-Type: text/plain; charset="utf-8" During Virtio1.0 dev(start_on_kick) in vhost_user_blk_start process, if spdk abnormal after vhost_dev_enable_notifiers, then vhost_user_blk_star= t will goto vhost_dev_disable_notifiers and reenter vhost_user_blk_start, and add ioeventfd again. func call Process as follows: vhost_user_blk_start(spdk abnormal after vhost_dev_enable_notifiers) ->vhost_dev_disable_notifiers ->virtio_bus_cleanup_host_notifier ->virtio_queue_host_notifier_read ->virtio_queue_notify_vq ->vhost_user_blk_handle_output ->vhost_user_blk_start ->vhost_dev_enable_notifiers then kvm_mem_ioeventfd_add will failed with errno17(File exists) and abort(). The GDB stack is as follows: (gdb) bt 0 0x00007fca4264c81b in raise () from /usr/lib64/libc.so.6 1 0x00007fca4264db41 in abort () from /usr/lib64/libc.so.6 2 0x00007fca423ebe8b in kvm_mem_ioeventfd_add 3 0x00007fca4241c816 in address_space_add_del_ioeventfds 4 0x00007fca4241ddc6 in address_space_update_ioeventfds 5 0x00007fca424203d5 in memory_region_commit () 6 0x00007fca424204e5 in memory_region_transaction_commit () 7 0x00007fca42421861 in memory_region_add_eventfd 8 0x00007fca42917a4c in virtio_pci_ioeventfd_assign 9 0x00007fca41054178 in virtio_bus_set_host_notifier 10 0x00007fca41058729 in vhost_dev_enable_notifiers 11 0x00007fca40fdec1e in vhost_user_blk_start 12 0x00007fca40fdefa8 in vhost_user_blk_handle_output 13 0x00007fca4104e135 in virtio_queue_notify_vq 14 0x00007fca4104f192 in virtio_queue_host_notifier_read 15 0x00007fca41054054 in virtio_bus_cleanup_host_notifier 16 0x00007fca41058916 in vhost_dev_disable_notifiers 17 0x00007fca40fdede0 in vhost_user_blk_start 18 0x00007fca40fdefa8 in vhost_user_blk_handle_output 19 0x00007fca41050a6d in virtio_queue_notify 20 0x00007fca4241bbae in memory_region_write_accessor 21 0x00007fca4241ab1d in access_with_adjusted_size 22 0x00007fca4241e466 in memory_region_dispatch_write 23 0x00007fca4242da36 in flatview_write_continue 24 0x00007fca4242db75 in flatview_write 25 0x00007fca42430beb in address_space_write 26 0x00007fca42430c25 in address_space_rw 27 0x00007fca423e8ecc in kvm_handle_io 28 0x00007fca423ecb48 in kvm_cpu_exec 29 0x00007fca424279d5 in qemu_kvm_cpu_thread_fn 30 0x00007fca423c9480 in qemu_thread_start 31 0x00007fca4257ff3b in ?? () from /usr/lib64/libpthread.so.0 32 0x00007fca4270b550 in clone () from /usr/lib64/libc.so.6 Signed-off-by: Jie Wang --- hw/block/vhost-user-blk.c | 12 +++++++++++- include/hw/virtio/vhost-user-blk.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1a42ae9187..2182769676 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -124,6 +124,13 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Er= ror **errp) VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int i, ret; =20 + if (vdev->start_on_kick) { + if (s->starting) { + return 0; + } + s->starting =3D true; + } + if (!k->set_guest_notifiers) { error_setg(errp, "binding does not support guest notifiers"); return -ENOSYS; @@ -178,6 +185,8 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Err= or **errp) vhost_virtqueue_mask(&s->dev, vdev, i, false); } =20 + s->starting =3D false; + return ret; =20 err_guest_notifiers: @@ -344,7 +353,7 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) } =20 /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { + if (s->starting || virtio_device_started(vdev, vdev->status)) { ret =3D vhost_user_blk_start(vdev, errp); if (ret < 0) { return ret; @@ -500,6 +509,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) vhost_user_blk_handle_output); } =20 + s->starting =3D false; s->inflight =3D g_new0(struct vhost_inflight, 1); s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); =20 diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-u= ser-blk.h index 7c91f15040..6e67f36962 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -51,6 +51,8 @@ struct VHostUserBlk { bool connected; /* vhost_user_blk_start/vhost_user_blk_stop */ bool started_vu; + + bool starting; }; =20 #endif --=20 2.23.0