From patchwork Fri Jun 17 02:42:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, YuanX" X-Patchwork-Id: 112945 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6C490A00C2; Fri, 17 Jun 2022 04:43:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A8B9A41148; Fri, 17 Jun 2022 04:43:00 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id BEBE940689; Fri, 17 Jun 2022 04:42:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655433777; x=1686969777; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=aCWSrI4wXCAROXjZaWhJGUN/b9p8Z2udAM8uRZ2SFUA=; b=ZtHRiVHg3R2OX+Xm9wceH5Ulfqz7oOBCwVPWd2SpMsT47PaPhu3Lq/Ao K6fIyFigF8K/SBPrJdJCdqFfM3Ki9d1X+KwMuSYMwjc/zkAmReQI0+PgF TOHGJxYysxdEXUwj6+8fhW6zAjbC5KwxC5btAAQAKpefaGvGZNidzmWOl lTrvRAXYKZoYWbTAqDPPWnffOK8gXI+AfG0lVD7/28AitpJDpT6Q4GMPZ 6L9UyGdScegpb4Iap3aiVo8aQWfsgmyUw1sWmVWfZGvTxlYEV+GKQlFxg oHSkeeAGcGZrwUkIApH+zQuylKXmku4593m9UXK606ziudQz1nw3nJ1PT w==; X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="259254256" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="259254256" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2022 19:42:55 -0700 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="589921640" Received: from unknown (HELO localhost.localdomain) ([10.239.252.55]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2022 19:42:53 -0700 From: Yuan Wang To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, dev@dpdk.org Cc: jiayu.hu@intel.com, xingguang.he@intel.com, Yuan Wang , stable@dpdk.org Subject: [PATCH] net/virtio: fix socket nonblocking mode affects initialization Date: Fri, 17 Jun 2022 10:42:29 +0800 Message-Id: <20220617024229.706826-1-yuanx.wang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The virtio-user initialization requires unix socket to receive backend messages in block mode. However, vhost_user_update_link_state() 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. Thread 1: virtio_init_device() --> virtio_user_start_device() --> vhost_user_set_memory_table() --> vhost_user_check_reply_ack() Thread 2: virtio_interrupt_handler() --> vhost_user_update_link_state() Fix that by replacing O_NONBLOCK with the recv per-call option MSG_DONTWAIT. Fixes: ef53b6030039 ("net/virtio-user: support LSC") Cc: stable@dpdk.org Signed-off-by: Yuan Wang Acked-by: Stephen Hemminger Reviewed-by: Chenbo Xia --- drivers/net/virtio/virtio_user/vhost_user.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 7d1749114d..198bd63d3c 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -940,15 +940,8 @@ vhost_user_update_link_state(struct virtio_user_dev *dev) if (data->vhostfd >= 0) { int r; - int flags; - flags = fcntl(data->vhostfd, F_GETFL); - if (fcntl(data->vhostfd, F_SETFL, flags | O_NONBLOCK) == -1) { - PMD_DRV_LOG(ERR, "error setting O_NONBLOCK flag"); - return -1; - } - - r = recv(data->vhostfd, buf, 128, MSG_PEEK); + r = recv(data->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", dev->hw.port_id); @@ -963,12 +956,6 @@ vhost_user_update_link_state(struct virtio_user_dev *dev) } else { dev->net_status |= VIRTIO_NET_S_LINK_UP; } - - if (fcntl(data->vhostfd, F_SETFL, - flags & ~O_NONBLOCK) == -1) { - PMD_DRV_LOG(ERR, "error clearing O_NONBLOCK flag"); - return -1; - } } else if (dev->is_server) { dev->net_status &= (~VIRTIO_NET_S_LINK_UP); if (virtio_user_dev_server_reconnect(dev) >= 0)