From patchwork Tue Jul 28 06:52:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Wang X-Patchwork-Id: 74922 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D57C3A0521; Tue, 28 Jul 2020 08:59:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 687CC1C10E; Tue, 28 Jul 2020 08:59:11 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id AEC6C1C042; Tue, 28 Jul 2020 08:59:09 +0200 (CEST) IronPort-SDR: ZuSDAcAgnfMXIli3TvJh7WwAD6r3IeYwdpKccGinIung2vn/UpvU/wBUS/8UIYNg3MB8PM+0hT M8Eb+idHADJQ== X-IronPort-AV: E=McAfee;i="6000,8403,9695"; a="150333663" X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="150333663" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2020 23:59:08 -0700 IronPort-SDR: wu64WJFJVZldsbZ0mNLdhdUt/k2uvmxhXhFbqsFtj0g6JpQU5HOABwaBDq/xAGb4Z46cGXYMJo P8v80mp/6aZg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="272224280" Received: from dpdk-xiao1.sh.intel.com ([10.67.110.193]) by fmsmga007.fm.intel.com with ESMTP; 27 Jul 2020 23:59:06 -0700 From: Xiao Wang To: maxime.coquelin@redhat.com Cc: dev@dpdk.org, zhihong.wang@intel.com, chenbo.xia@intel.com, Xiao Wang , stable@dpdk.org Date: Tue, 28 Jul 2020 14:52:12 +0800 Message-Id: <20200728065212.16703-1-xiao.w.wang@intel.com> X-Mailer: git-send-email 2.15.1 Subject: [dpdk-dev] [PATCH] net/virtio-user: fix virtio net status management X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Apart from the virtio status, there should be also a network related status for link status management, current implementation mixes up these two statuses. One issue caused by this mixup is when virtio-user running in server mode and vhost as a client connects to it, a RARP packet will be generated by virtio-user due to VIRTIO_NET_S_ANNOUNCE bit is detected in the "status" in interrupt handler. VIRTIO_NET_S_LINK_UP and VIRTIO_NET_S_ANNOUNCE should be managed by a separated field. This patch adds a "net_status" field for this purpose. Fixes: e9efa4d93821 ("net/virtio-user: add new virtual PCI driver") Cc: stable@dpdk.org Signed-off-by: Xiao Wang Reviewed-by: Chenbo Xia Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 56e638f8a..554174e81 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -44,6 +44,7 @@ struct virtio_user_dev { * (Vhost-user only) */ uint8_t status; + uint16_t net_status; uint16_t port_id; uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; char path[PATH_MAX]; diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index e51425c4f..6003f6d50 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -205,7 +205,7 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, } r = recv(dev->vhostfd, buf, 128, MSG_PEEK); if (r == 0 || (r < 0 && errno != EAGAIN)) { - dev->status &= (~VIRTIO_NET_S_LINK_UP); + dev->net_status &= (~VIRTIO_NET_S_LINK_UP); PMD_DRV_LOG(ERR, "virtio-user port %u is down", hw->port_id); @@ -217,7 +217,7 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, virtio_user_delayed_handler, (void *)hw); } else { - dev->status |= VIRTIO_NET_S_LINK_UP; + dev->net_status |= VIRTIO_NET_S_LINK_UP; } if (fcntl(dev->vhostfd, F_SETFL, flags & ~O_NONBLOCK) == -1) { @@ -225,12 +225,12 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, return; } } else if (dev->is_server) { - dev->status &= (~VIRTIO_NET_S_LINK_UP); + dev->net_status &= (~VIRTIO_NET_S_LINK_UP); if (virtio_user_server_reconnect(dev) >= 0) - dev->status |= VIRTIO_NET_S_LINK_UP; + dev->net_status |= VIRTIO_NET_S_LINK_UP; } - *(uint16_t *)dst = dev->status; + *(uint16_t *)dst = dev->net_status; } if (offset == offsetof(struct virtio_net_config, max_virtqueue_pairs))