From nobody Sat May 18 09:23:02 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674149167541777.8154978715686; Thu, 19 Jan 2023 09:26:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIYfj-0005oq-Ji; Thu, 19 Jan 2023 12:25:57 -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 1pIYfg-0005mn-3H for qemu-devel@nongnu.org; Thu, 19 Jan 2023 12:25:52 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIYfe-0006sN-6g for qemu-devel@nongnu.org; Thu, 19 Jan 2023 12:25:51 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-529-8g_LtXV4OkK0JwZPlTvAxw-1; Thu, 19 Jan 2023 12:24:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8BF65858F09; Thu, 19 Jan 2023 17:24:29 +0000 (UTC) Received: from bahia.redhat.com (unknown [10.39.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9502E1121315; Thu, 19 Jan 2023 17:24:27 +0000 (UTC) X-MC-Unique: 8g_LtXV4OkK0JwZPlTvAxw-1 From: Greg Kurz To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , "Dr. David Alan Gilbert" , Maxime Coquelin , Laurent Vivier , "Michael S. Tsirkin" , Yajun Wu , Peter Maydell , Parav Pandit , qemu-stable@nongnu.org, Greg Kurz , Yanghang Liu Subject: [PATCH 1/2] Revert "vhost-user: Monitor slave channel in vhost_user_read()" Date: Thu, 19 Jan 2023 18:24:23 +0100 Message-Id: <20230119172424.478268-2-groug@kaod.org> In-Reply-To: <20230119172424.478268-1-groug@kaod.org> References: <20230119172424.478268-1-groug@kaod.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.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_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1674149171170100001 Content-Type: text/plain; charset="utf-8" This reverts commit db8a3772e300c1a656331a92da0785d81667dc81. Motivation : this is breaking vhost-user with DPDK as reported in [0]. Received unexpected msg type. Expected 22 received 40 Fail to update device iotlb Received unexpected msg type. Expected 40 received 22 Received unexpected msg type. Expected 22 received 11 Fail to update device iotlb Received unexpected msg type. Expected 11 received 22 vhost VQ 1 ring restore failed: -71: Protocol error (71) Received unexpected msg type. Expected 22 received 11 Fail to update device iotlb Received unexpected msg type. Expected 11 received 22 vhost VQ 0 ring restore failed: -71: Protocol error (71) unable to start vhost net: 71: falling back on userspace virtio The failing sequence that leads to the first error is : - QEMU sends a VHOST_USER_GET_STATUS (40) request to DPDK on the master socket - QEMU starts a nested event loop in order to wait for the VHOST_USER_GET_STATUS response and to be able to process messages from the slave channel - DPDK sends a couple of legitimate IOTLB miss messages on the slave channel - QEMU processes each IOTLB request and sends VHOST_USER_IOTLB_MSG (22) updates on the master socket - QEMU assumes to receive a response for the latest VHOST_USER_IOTLB_MSG but it gets the response for the VHOST_USER_GET_STATUS instead The subsequent errors have the same root cause : the nested event loop breaks the order by design. It lures QEMU to expect responses to the latest message sent on the master socket to arrive first. Since this was only needed for DAX enablement which is still not merged upstream, just drop the code for now. A working solution will have to be merged later on. Likely protect the master socket with a mutex and service the slave channel with a separate thread, as discussed with Maxime in the mail thread below. [0] https://lore.kernel.org/qemu-devel/43145ede-89dc-280e-b953-6a2b436de395= @redhat.com/ Reported-by: Yanghang Liu Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D2155173 Signed-off-by: Greg Kurz Acked-by: Maxime Coquelin Acked-by: Stefan Hajnoczi --- hw/virtio/vhost-user.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index d9ce0501b2c7..7fb78af22c56 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -356,35 +356,6 @@ end: return G_SOURCE_REMOVE; } =20 -static gboolean slave_read(QIOChannel *ioc, GIOCondition condition, - gpointer opaque); - -/* - * This updates the read handler to use a new event loop context. - * Event sources are removed from the previous context : this ensures - * that events detected in the previous context are purged. They will - * be re-detected and processed in the new context. - */ -static void slave_update_read_handler(struct vhost_dev *dev, - GMainContext *ctxt) -{ - struct vhost_user *u =3D dev->opaque; - - if (!u->slave_ioc) { - return; - } - - if (u->slave_src) { - g_source_destroy(u->slave_src); - g_source_unref(u->slave_src); - } - - u->slave_src =3D qio_channel_add_watch_source(u->slave_ioc, - G_IO_IN | G_IO_HUP, - slave_read, dev, NULL, - ctxt); -} - static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -406,7 +377,6 @@ static int vhost_user_read(struct vhost_dev *dev, Vhost= UserMsg *msg) * be prepared for re-entrancy. So we create a new one and switch chr * to use it. */ - slave_update_read_handler(dev, ctxt); qemu_chr_be_update_read_handlers(chr->chr, ctxt); qemu_chr_fe_add_watch(chr, G_IO_IN | G_IO_HUP, vhost_user_read_cb, &da= ta); =20 @@ -418,7 +388,6 @@ static int vhost_user_read(struct vhost_dev *dev, Vhost= UserMsg *msg) * context that have been processed by the nested loop are purged. */ qemu_chr_be_update_read_handlers(chr->chr, prev_ctxt); - slave_update_read_handler(dev, NULL); =20 g_main_loop_unref(loop); g_main_context_unref(ctxt); @@ -1807,7 +1776,9 @@ static int vhost_setup_slave_channel(struct vhost_dev= *dev) return -ECONNREFUSED; } u->slave_ioc =3D ioc; - slave_update_read_handler(dev, NULL); + u->slave_src =3D qio_channel_add_watch_source(u->slave_ioc, + G_IO_IN | G_IO_HUP, + slave_read, dev, NULL, NUL= L); =20 if (reply_supported) { msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; --=20 2.39.0 From nobody Sat May 18 09:23:02 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674149140960750.6876888712258; Thu, 19 Jan 2023 09:25:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIYeW-0005Ic-Rx; Thu, 19 Jan 2023 12:24:40 -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 1pIYeW-0005IT-70 for qemu-devel@nongnu.org; Thu, 19 Jan 2023 12:24:40 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIYeT-0006So-Nv for qemu-devel@nongnu.org; Thu, 19 Jan 2023 12:24:39 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646--PSKBDw6NRuXob42NeBBqQ-1; Thu, 19 Jan 2023 12:24:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A2ADC29AA3AE; Thu, 19 Jan 2023 17:24:31 +0000 (UTC) Received: from bahia.redhat.com (unknown [10.39.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC44C1121315; Thu, 19 Jan 2023 17:24:29 +0000 (UTC) X-MC-Unique: -PSKBDw6NRuXob42NeBBqQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , "Dr. David Alan Gilbert" , Maxime Coquelin , Laurent Vivier , "Michael S. Tsirkin" , Yajun Wu , Peter Maydell , Parav Pandit , qemu-stable@nongnu.org, Greg Kurz Subject: [PATCH 2/2] Revert "vhost-user: Introduce nested event loop in vhost_user_read()" Date: Thu, 19 Jan 2023 18:24:24 +0100 Message-Id: <20230119172424.478268-3-groug@kaod.org> In-Reply-To: <20230119172424.478268-1-groug@kaod.org> References: <20230119172424.478268-1-groug@kaod.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.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_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1674149143555100003 Content-Type: text/plain; charset="utf-8" This reverts commit a7f523c7d114d445c5d83aecdba3efc038e5a692. The nested event loop is broken by design. It's only user was removed. Drop the code as well so that nobody ever tries to use it again. I had to fix a couple of trivial conflicts around return values because of 025faa872bcf ("vhost-user: stick to -errno error return convention"). Signed-off-by: Greg Kurz Acked-by: Maxime Coquelin --- hw/virtio/vhost-user.c | 65 ++++-------------------------------------- 1 file changed, 5 insertions(+), 60 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 7fb78af22c56..e14895c919ef 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -305,19 +305,8 @@ static int vhost_user_read_header(struct vhost_dev *de= v, VhostUserMsg *msg) return 0; } =20 -struct vhost_user_read_cb_data { - struct vhost_dev *dev; - VhostUserMsg *msg; - GMainLoop *loop; - int ret; -}; - -static gboolean vhost_user_read_cb(void *do_not_use, GIOCondition conditio= n, - gpointer opaque) +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) { - struct vhost_user_read_cb_data *data =3D opaque; - struct vhost_dev *dev =3D data->dev; - VhostUserMsg *msg =3D data->msg; struct vhost_user *u =3D dev->opaque; CharBackend *chr =3D u->user->chr; uint8_t *p =3D (uint8_t *) msg; @@ -325,8 +314,7 @@ static gboolean vhost_user_read_cb(void *do_not_use, GI= OCondition condition, =20 r =3D vhost_user_read_header(dev, msg); if (r < 0) { - data->ret =3D r; - goto end; + return r; } =20 /* validate message size is sane */ @@ -334,8 +322,7 @@ static gboolean vhost_user_read_cb(void *do_not_use, GI= OCondition condition, error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", msg->hdr.size, VHOST_USER_PAYLOAD_SIZE); - data->ret =3D -EPROTO; - goto end; + return -EPROTO; } =20 if (msg->hdr.size) { @@ -346,53 +333,11 @@ static gboolean vhost_user_read_cb(void *do_not_use, = GIOCondition condition, int saved_errno =3D errno; error_report("Failed to read msg payload." " Read %d instead of %d.", r, msg->hdr.size); - data->ret =3D r < 0 ? -saved_errno : -EIO; - goto end; + return r < 0 ? -saved_errno : -EIO; } } =20 -end: - g_main_loop_quit(data->loop); - return G_SOURCE_REMOVE; -} - -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) -{ - struct vhost_user *u =3D dev->opaque; - CharBackend *chr =3D u->user->chr; - GMainContext *prev_ctxt =3D chr->chr->gcontext; - GMainContext *ctxt =3D g_main_context_new(); - GMainLoop *loop =3D g_main_loop_new(ctxt, FALSE); - struct vhost_user_read_cb_data data =3D { - .dev =3D dev, - .loop =3D loop, - .msg =3D msg, - .ret =3D 0 - }; - - /* - * We want to be able to monitor the slave channel fd while waiting - * for chr I/O. This requires an event loop, but we can't nest the - * one to which chr is currently attached : its fd handlers might not - * be prepared for re-entrancy. So we create a new one and switch chr - * to use it. - */ - qemu_chr_be_update_read_handlers(chr->chr, ctxt); - qemu_chr_fe_add_watch(chr, G_IO_IN | G_IO_HUP, vhost_user_read_cb, &da= ta); - - g_main_loop_run(loop); - - /* - * Restore the previous event loop context. This also destroys/recreat= es - * event sources : this guarantees that all pending events in the orig= inal - * context that have been processed by the nested loop are purged. - */ - qemu_chr_be_update_read_handlers(chr->chr, prev_ctxt); - - g_main_loop_unref(loop); - g_main_context_unref(ctxt); - - return data.ret; + return 0; } =20 static int process_message_reply(struct vhost_dev *dev, --=20 2.39.0