From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4BDA8A00C5 for ; Mon, 15 Aug 2022 11:44:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1CB9940143; Mon, 15 Aug 2022 11:44:22 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 4E509400EF for ; Mon, 15 Aug 2022 11:44:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660556660; x=1692092660; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uXZFZCR2imp6wJizncxbe9KOE0hMacuA9yRTBhQ0gM0=; b=VKBTAg4IaxeSC1yKF3bq0QWdvOcK84jcaDwo24paX8XCBUo4ZjQ1uw95 tRfSMtmVvKrFHB8hvVQlF2ZLCKsDbPWJAgxCWTaxLzTVlKySfDH5zXC60 ylPz2qX5kceh6N3aJpUfR5+hPPp0qqGTfM33uwXzxvH/dmBbz7/fNSGKk ZT2FPjLlXCAzZYY8QPEzAsaHQteBcHKoWAyOiGZ5N2qE8Xy4cmfNqwj1w 597+r4zsjP8qftQTxhfLOLSvXDh8pmx1mDYq+Xa3XZxfXV5SXZ2bJpTCz khHK07FlF9d5jNxmiXZ5iaQcQRnRjHesmyN2JZrBVMtesvbJCGOHUc1IN A==; X-IronPort-AV: E=McAfee;i="6400,9594,10439"; a="378216079" X-IronPort-AV: E=Sophos;i="5.93,238,1654585200"; d="scan'208";a="378216079" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2022 02:44:19 -0700 X-IronPort-AV: E=Sophos;i="5.93,238,1654585200"; d="scan'208";a="557231826" Received: from unknown (HELO localhost.localdomain) ([10.239.252.55]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2022 02:44:16 -0700 From: Yuan Wang To: xuemingl@nvidia.com, stable@dpdk.org Cc: maxime.coquelin@redhat.com, chenbo.xia@intel.com, jiayu.hu@intel.com, cheng1.jiang@intel.com, qiming.yang@intel.com, Yuan Wang , Stephen Hemminger Subject: [PATCH 20.11] net/virtio-user: fix socket non-blocking mode Date: Tue, 16 Aug 2022 01:32:35 +0800 Message-Id: <20220815173235.52217-1-yuanx.wang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit 41f9a1757ffc010cc3debaad9a56af8ad88d0c6d ] The virtio-user initialization requires unix socket to receive backend messages in block mode. However, virtio_user_read_dev_config() sets the same socket to nonblocking via fcntl, which affects all threads. Enabling the rxq interrupt can causes both of these behaviors to occur concurrently, with the result that the initialization may fail because no messages are received in nonblocking socket. Fix that by replacing O_NONBLOCK with the recv per-call option MSG_DONTWAIT. Fixes: ef53b6030039 ("net/virtio-user: support LSC") Signed-off-by: Yuan Wang Acked-by: Stephen Hemminger Reviewed-by: Chenbo Xia --- drivers/net/virtio/virtio_user_ethdev.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 04d6d7e2f..347caeef4 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -252,15 +252,9 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, if (dev->vhostfd >= 0) { int r; - int flags; - flags = fcntl(dev->vhostfd, F_GETFL); - if (fcntl(dev->vhostfd, F_SETFL, - flags | O_NONBLOCK) == -1) { - PMD_DRV_LOG(ERR, "error setting O_NONBLOCK flag"); - return; - } - r = recv(dev->vhostfd, buf, 128, MSG_PEEK); + r = recv(dev->vhostfd, buf, 128, + MSG_PEEK | MSG_DONTWAIT); if (r == 0 || (r < 0 && errno != EAGAIN)) { dev->net_status &= (~VIRTIO_NET_S_LINK_UP); PMD_DRV_LOG(ERR, "virtio-user port %u is down", @@ -276,11 +270,6 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, } else { dev->net_status |= VIRTIO_NET_S_LINK_UP; } - if (fcntl(dev->vhostfd, F_SETFL, - flags & ~O_NONBLOCK) == -1) { - PMD_DRV_LOG(ERR, "error clearing O_NONBLOCK flag"); - return; - } } else if (dev->is_server) { dev->net_status &= (~VIRTIO_NET_S_LINK_UP); if (virtio_user_server_reconnect(dev) >= 0) -- 2.25.1