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 211EBA00C5 for ; Thu, 14 Jul 2022 11:22:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1B60842B6D; Thu, 14 Jul 2022 11:22:11 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id 185974282B for ; Thu, 14 Jul 2022 11:22:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657790529; x=1689326529; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=bV361bxu4iUyswGiuWUvU71zceG+2jPF6kZukiyjle8=; b=AIIx51jHW3VhTa1T4IXuia6hoUxiujiszTL/QZeUt0XC58IT00BwtGR6 QGOOX4Rpf6yYpa66hwvgxwqlnB+YDKGIvfujLcm6eQldxcPYggkIyFIXV 1YI/yWZGwrr6e1jDR4beA5AiGz9DZvc3TmXYWryBQ7zrQ1vbUABE1gfiJ IuPioSHhpfNrzexUt3dUqDvrK0+tq8dRi1qwYZrkJyBQT12yrnoqCiiwW qPXnFitAkU/2tX7QKb8H08FnzGOH8ix1kW5/+WpmZKbRcYUagOj4Gb5JX NmYjdle/WlrtzJLEoJQvYjyLLvSx9+m+CF1hm3YcNU9m4uhf/vl1oLRaB A==; X-IronPort-AV: E=McAfee;i="6400,9594,10407"; a="265874257" X-IronPort-AV: E=Sophos;i="5.92,269,1650956400"; d="scan'208";a="265874257" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2022 02:22:07 -0700 X-IronPort-AV: E=Sophos;i="5.92,269,1650956400"; d="scan'208";a="653795433" Received: from unknown (HELO localhost.localdomain) ([10.239.252.55]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2022 02:22:05 -0700 From: Yuan Wang To: christian.ehrhardt@canonical.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 19.11] net/virtio-user: fix socket non-blocking mode Date: Fri, 15 Jul 2022 01:09:58 +0800 Message-Id: <20220714170958.554638-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 2fccf9fce..1c07caeb5 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -211,15 +211,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", @@ -235,11 +229,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