From patchwork Wed Jun 1 15:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Beichler X-Patchwork-Id: 1638023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=tmIdqHi4; dkim=fail reason="signature verification failed" header.d=uni-rostock.de header.i=@uni-rostock.de header.a=ed25519-sha256 header.s=itmze header.b=6kfXov/h; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=uni-rostock.de header.i=@uni-rostock.de header.a=rsa-sha256 header.s=itmz header.b=anI+lOJG; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LCtZz1qW9z9s0r for ; Thu, 2 Jun 2022 01:38:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=BJZ/lDfoFquUt2mHDydOffTANVhyjedMxKXLdsZ6+Tc=; b=tmIdqHi4mdJgCm T2EAXCHnfpE42JUq2U5T1uwwm6h83jvmQwn6JFqYxW0mBXbTyDecSVqyz2lDp+M5MGZb+LxeMZolT HfcctQdskmECMeHHrTvoHD05/jtx0n5Yh/W4rzW3A9cAWuxwP2Rg222ih7t0s8519UhdPYI+4/Zha jnB0snQDDi4EbbOgL/cDdakqoTqlP2ufqKKPlfgZVd08qsIeTc9PqUyZoSnvmpW/xGK5nUjeORUV4 WqXIQVT/ykABPfVnFv4OJulU7vppFDDVW+o6zb90dLfzKnfyp6SA4vbacW72oz21obXogfUJgefK/ JB7t8rtMKMnRWctOMeyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nwQQA-00GwAg-Az; Wed, 01 Jun 2022 15:38:06 +0000 Received: from mx1.uni-rostock.de ([139.30.22.71]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nwQQ6-00Gw7t-Q8 for linux-um@lists.infradead.org; Wed, 01 Jun 2022 15:38:05 +0000 DKIM-Signature: v=1; c=relaxed/relaxed; d=uni-rostock.de; s=itmze; t=1654097871; bh=PKtd8/u8nWjPZdGzm0jz3lmh4Yz0PlPqWAloSXTo6Z8=; h= "Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id"; a=ed25519-sha256; b= 6kfXov/hiy58kWFWjSHXhI4vNABC6bffFqWOsJcg+b0W5QH9j9HjLZDfk+BvG5FaI6cSSPkz44NybJcB3Lk7CA== DKIM-Signature: v=1; c=relaxed/relaxed; d=uni-rostock.de; s=itmz; t=1654097871; bh=PKtd8/u8nWjPZdGzm0jz3lmh4Yz0PlPqWAloSXTo6Z8=; h= "Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id"; a=rsa-sha256; b= anI+lOJGOjXGhC67isOqDl7m7OBz99DhbhX0eZJv5RGWxX7l1CiI3okmtAhaQAP29mPm1D3CBL60qkag43ZO+lyHZpUXHdLd6ya4Dlkz+ylavx2Q1Pvl5rzPakRXe25wYsFcqa2r9aPdxhz1ash3anJdeTmyqEkzl2/DJGkidyA= Received: from 139.30.22.81 by mx1.uni-rostock.de (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Wed, 01 Jun 2022 15:37:51 GMT Received: from meshdev.amd.e-technik.uni-rostock.de (139.30.202.94) by email1.uni-rostock.de (139.30.22.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Wed, 1 Jun 2022 17:37:50 +0200 From: Benjamin Beichler To: , Richard Weinberger , Anton Ivanov , Johannes Berg CC: Benjamin Beichler , Johannes Berg , , Subject: [PATCH] um: read multiple msg from virtio slave request fd Date: Wed, 1 Jun 2022 15:37:22 +0000 Message-ID: <20220601153722.181427-1-benjamin.beichler@uni-rostock.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [139.30.202.94] X-ClientProxiedBy: EMAIL2.uni-rostock.de (139.30.22.82) To email1.uni-rostock.de (139.30.22.81) X-TM-SNTS-SMTP: 65432843B81598EC2F6963A9BD00A45E17CF9588109DE9673455B75DF549C1F72002:8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220601_083803_842766_C0CA1BAE X-CRM114-Status: GOOD ( 16.07 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: If VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS is activated, the user mode linux virtio irq handler only read one msg from the corresponding socket. This creates issues, when the device emulation creat [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [139.30.22.71 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS is activated, the user mode linux virtio irq handler only read one msg from the corresponding socket. This creates issues, when the device emulation creates multiple call requests (e.g. for multiple virtqueues), as the socket buffer tend to fill up and the call requests are delayed. This creates a deadlock situation, when the device simulation blocks, because of sending a msg and the kernel side blocks because of synchronously waiting for an acknowledge of kick request. Actually inband notifications are meant to be used in combination with the time travel protocol, but it is not required, therefore this corner case needs to be handled. Anyways, in general it seems to be more natural to consume always all messages from a socket, instead of only a single one. Fixes: 2cd097ba8c05 ("um: virtio: Implement VHOST_USER_PROTOCOL_F_SLAVE_REQ") Signed-off-by: Benjamin Beichler --- arch/um/drivers/virtio_uml.c | 72 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c index ba562d68dc04..0c171dd11414 100644 --- a/arch/um/drivers/virtio_uml.c +++ b/arch/um/drivers/virtio_uml.c @@ -363,45 +363,47 @@ static irqreturn_t vu_req_read_message(struct virtio_uml_device *vu_dev, struct vhost_user_msg msg; u8 extra_payload[512]; } msg; - int rc; - - rc = vhost_user_recv_req(vu_dev, &msg.msg, - sizeof(msg.msg.payload) + - sizeof(msg.extra_payload)); - - if (rc) - return IRQ_NONE; - - switch (msg.msg.header.request) { - case VHOST_USER_SLAVE_CONFIG_CHANGE_MSG: - vu_dev->config_changed_irq = true; - response = 0; - break; - case VHOST_USER_SLAVE_VRING_CALL: - virtio_device_for_each_vq((&vu_dev->vdev), vq) { - if (vq->index == msg.msg.payload.vring_state.index) { - response = 0; - vu_dev->vq_irq_vq_map |= BIT_ULL(vq->index); - break; + irqreturn_t rc = IRQ_NONE; + + while (1) { + if (vhost_user_recv_req(vu_dev, &msg.msg, + sizeof(msg.msg.payload) + + sizeof(msg.extra_payload))) + break; + + switch (msg.msg.header.request) { + case VHOST_USER_SLAVE_CONFIG_CHANGE_MSG: + vu_dev->config_changed_irq = true; + response = 0; + break; + case VHOST_USER_SLAVE_VRING_CALL: + virtio_device_for_each_vq((&vu_dev->vdev), vq) { + if (vq->index == + msg.msg.payload.vring_state.index) { + response = 0; + vu_dev->vq_irq_vq_map |= + BIT_ULL(vq->index); + break; + } } + break; + case VHOST_USER_SLAVE_IOTLB_MSG: + /* not supported - VIRTIO_F_ACCESS_PLATFORM */ + case VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG: + /* not supported - VHOST_USER_PROTOCOL_F_HOST_NOTIFIER */ + default: + vu_err(vu_dev, "unexpected slave request %d\n", + msg.msg.header.request); } - break; - case VHOST_USER_SLAVE_IOTLB_MSG: - /* not supported - VIRTIO_F_ACCESS_PLATFORM */ - case VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG: - /* not supported - VHOST_USER_PROTOCOL_F_HOST_NOTIFIER */ - default: - vu_err(vu_dev, "unexpected slave request %d\n", - msg.msg.header.request); - } - - if (ev && !vu_dev->suspended) - time_travel_add_irq_event(ev); - if (msg.msg.header.flags & VHOST_USER_FLAG_NEED_REPLY) - vhost_user_reply(vu_dev, &msg.msg, response); + if (ev && !vu_dev->suspended) + time_travel_add_irq_event(ev); - return IRQ_HANDLED; + if (msg.msg.header.flags & VHOST_USER_FLAG_NEED_REPLY) + vhost_user_reply(vu_dev, &msg.msg, response); + rc = IRQ_HANDLED; + } + return rc; } static irqreturn_t vu_req_interrupt(int irq, void *data)