From patchwork Mon Oct 26 16:39:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 82212 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 DD74FA04DD; Mon, 26 Oct 2020 17:41:28 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5DDF22C1A; Mon, 26 Oct 2020 17:39:59 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 438FB2BCE for ; Mon, 26 Oct 2020 17:39:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603730392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k1r2/4fuP3DPbeMDl6Xzr0eOM1r3dYy8sT+ZvoXM1Fk=; b=HEznmTWU8Ujj0u7vT9PWPnzNhhauK6ZM1LbX3iaZR7PAl5obEX07myeXv1IONgJ2MegPSf EoIprPBZNKdJ/cVSJwB2FqU3rLJfjbrA+iaUUviRQtUgDG1UtFKLgPBYZj+REySKstSXz2 xiaRmHiwZSdkTWAQ3rnKgtMVhzYGOlg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-0yw-HwSpMRGIdNmFcnDBqQ-1; Mon, 26 Oct 2020 12:39:48 -0400 X-MC-Unique: 0yw-HwSpMRGIdNmFcnDBqQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E882018C9F41; Mon, 26 Oct 2020 16:39:46 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3FBB62A14; Mon, 26 Oct 2020 16:39:44 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: yinan.wang@intel.com, patrick.fu@intel.com, chenbo.xia@intel.com, zhihong.wang@intel.com, maxime.coquelin@redhat.com, Adrian Moreno , stable@dpdk.org, Kevin Traynor Date: Mon, 26 Oct 2020 17:39:25 +0100 Message-Id: <20201026163930.94032-2-amorenoz@redhat.com> In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com> References: <20201026163930.94032-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 1/6] net/virtio-user: fix backend selection if stat fails 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" If stat fails because the file does not exist, it means that the backend must be vhost-user in server mode. Also, log the detected backend type. Bugzilla ID: 559 Fixes: f908b22ea47a ("net/virtio: move backend type selection to ethdev") Cc: stable@dpdk.org Reviewed-by: Maxime Coquelin Acked-by: Kevin Traynor Signed-off-by: Adrian Moreno --- drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 +++++++ drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 3681758ef..27814eadb 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -22,6 +22,13 @@ #define VIRTIO_USER_MEM_EVENT_CLB_NAME "virtio_user_mem_event_clb" +const char * const virtio_user_backend_strings[] = { + [VIRTIO_USER_BACKEND_UNKNOWN] = "VIRTIO_USER_BACKEND_UNKNOWN", + [VIRTIO_USER_BACKEND_VHOST_USER] = "VHOST_USER", + [VIRTIO_USER_BACKEND_VHOST_KERNEL] = "VHOST_NET", + [VIRTIO_USER_BACKEND_VHOST_VDPA] = "VHOST_VDPA", +}; + static int virtio_user_create_queue(struct virtio_user_dev *dev, uint32_t queue_sel) { diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 3e9d1a1eb..998986875 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -83,4 +83,5 @@ void virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs); int virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status); int virtio_user_update_status(struct virtio_user_dev *dev); +extern const char * const virtio_user_backend_strings[]; #endif diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 042665bc0..e870fb2ff 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -560,6 +560,9 @@ virtio_user_backend_type(const char *path) struct stat sb; if (stat(path, &sb) == -1) { + if (errno == ENOENT) + return VIRTIO_USER_BACKEND_VHOST_USER; + PMD_INIT_LOG(ERR, "Stat fails: %s (%s)\n", path, strerror(errno)); return VIRTIO_USER_BACKEND_UNKNOWN; @@ -697,7 +700,8 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) path); goto end; } - + PMD_INIT_LOG(INFO, "Backend type detected: %s", + virtio_user_backend_strings[backend_type]); if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_INTERFACE_NAME) == 1) { if (backend_type != VIRTIO_USER_BACKEND_VHOST_KERNEL) { From patchwork Mon Oct 26 16:39:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 82214 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 E17AAA04DD; Mon, 26 Oct 2020 17:42:10 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E2CFA37B1; Mon, 26 Oct 2020 17:40:05 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id 9592E2C01 for ; Mon, 26 Oct 2020 17:39:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603730396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3PT3V6DRNE44usHKy5kHV5UliaBQQHriOaQCEz0QsnU=; b=S4kp3B4+CnnoyNSMwqjQdR4h2HBjYvc7+FePLitjtkBdiNkDDIVYMRNMLXh+vv7VVhGkjo 2afbL4F0/Qsa0ly22ACxkUQQdhQ1lzW2bXjgb5FiMoCeiFPyLGhpoQ5GPHUIk/eXFWNfvk 9V3cz4f6r570dpJ0tsPWBsLkcq+wFwA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-KlhM2tQYOXyM3XT_Kaqh4w-1; Mon, 26 Oct 2020 12:39:52 -0400 X-MC-Unique: KlhM2tQYOXyM3XT_Kaqh4w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C651287507D; Mon, 26 Oct 2020 16:39:50 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6835A5577D; Mon, 26 Oct 2020 16:39:47 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: yinan.wang@intel.com, patrick.fu@intel.com, chenbo.xia@intel.com, zhihong.wang@intel.com, maxime.coquelin@redhat.com, Adrian Moreno , stable@dpdk.org Date: Mon, 26 Oct 2020 17:39:26 +0100 Message-Id: <20201026163930.94032-3-amorenoz@redhat.com> In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com> References: <20201026163930.94032-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 2/6] net/virtio-user: don't set/get_status until FEATURES_OK 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" According to the virtio spec, ACK and DRIVER status bits should be set before feature negotiation. However, until the protocol features are negotiated, the driver does not know if the device actually supports those vhost-user messages. Therefore, until FEATURES_OK is set, the GET/SET_STATUS messages should not be sent. Fixes: 57912824615f ("net/virtio-user: support vhost status setting") Cc: maxime.coquelin@redhat.com Cc: stable@dpdk.org Reviewed-by: Maxime Coquelin Signed-off-by: Adrian Moreno --- drivers/net/virtio/virtio_user/vhost_user.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index ef290c357..450d77e92 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -278,8 +278,9 @@ vhost_user_sock(struct virtio_user_dev *dev, switch (req) { case VHOST_USER_GET_STATUS: - if (!(dev->protocol_features & - (1ULL << VHOST_USER_PROTOCOL_F_STATUS))) + if (!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK) || + (!(dev->protocol_features & + (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))) return 0; /* Fallthrough */ case VHOST_USER_GET_FEATURES: @@ -288,8 +289,9 @@ vhost_user_sock(struct virtio_user_dev *dev, break; case VHOST_USER_SET_STATUS: - if (!(dev->protocol_features & - (1ULL << VHOST_USER_PROTOCOL_F_STATUS))) + if (!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK) || + (!(dev->protocol_features & + (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))) return 0; if (has_reply_ack) From patchwork Mon Oct 26 16:39:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 82213 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 6D39AA04DD; Mon, 26 Oct 2020 17:41:48 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4E27B354D; Mon, 26 Oct 2020 17:40:04 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id A22672C15 for ; Mon, 26 Oct 2020 17:39:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603730396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hsXsvli/f76Ou04a3sm1+WpOxa5Xsj6zxlSnLYwUWrA=; b=G8Cldyc5aFQTc8q5EXiLOpB37/76lFRGmNrWtgEfhfAQt589IyOvzjnHqj5xQepshi+VxB 8hhBk70w46oUCy6QeINomlEbnxxOdjXHwqP3A9NXQc1wv7A4gpriUCjbvbZ4xco+BuAWI9 54Jz2LLIkOr2yptszEY6Tati7y5cCCM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-541-HqE1kEGrP1W0LtH7vakfrw-1; Mon, 26 Oct 2020 12:39:54 -0400 X-MC-Unique: HqE1kEGrP1W0LtH7vakfrw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6B0B8799EF; Mon, 26 Oct 2020 16:39:52 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4024162A15; Mon, 26 Oct 2020 16:39:51 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: yinan.wang@intel.com, patrick.fu@intel.com, chenbo.xia@intel.com, zhihong.wang@intel.com, maxime.coquelin@redhat.com, Adrian Moreno Date: Mon, 26 Oct 2020 17:39:27 +0100 Message-Id: <20201026163930.94032-4-amorenoz@redhat.com> In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com> References: <20201026163930.94032-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 3/6] net/virtio-user: ignore result if STATUS is unsupported 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" GET/SET STATUS is an optional feature, so it may not be negotiated. In that case, the VIRTIO_GET_STATUS call will not update the status (given as a pointer argument). Failing to identify this case would lead to undefined behavior as the device status will be updated with the value of a stack-allocated variable. To fix this, return ENOTSUP if the feature is not supported and, in that case, don't update device status. Fixes: 44102e6298e7 ("net/virtio: check protocol feature in user backend") Cc: maxime.coquelin@redhat.com Cc stable@dpdk.org Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/vhost_user.c | 4 +-- .../net/virtio/virtio_user/virtio_user_dev.c | 28 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 450d77e92..b93e65c60 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -281,7 +281,7 @@ vhost_user_sock(struct virtio_user_dev *dev, if (!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK) || (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))) - return 0; + return -ENOTSUP; /* Fallthrough */ case VHOST_USER_GET_FEATURES: case VHOST_USER_GET_PROTOCOL_FEATURES: @@ -292,7 +292,7 @@ vhost_user_sock(struct virtio_user_dev *dev, if (!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK) || (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))) - return 0; + return -ENOTSUP; if (has_reply_ack) msg.flags |= VHOST_USER_NEED_REPLY_MASK; diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 27814eadb..5a1e76006 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -818,15 +818,13 @@ virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status) ret = dev->ops->send_request(dev, VHOST_USER_SET_STATUS, &status); else - return 0; + ret = -ENOTSUP; - if (ret) { + if (ret && ret != -ENOTSUP) { PMD_INIT_LOG(ERR, "VHOST_USER_SET_STATUS failed (%d): %s", ret, strerror(errno)); - return -1; } - - return 0; + return ret; } int @@ -849,17 +847,12 @@ virtio_user_update_status(struct virtio_user_dev *dev) err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &status); } else { - return 0; - } - - if (err) { - PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err, - strerror(errno)); - return -1; + err = -ENOTSUP; } - dev->status = status; - PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n" + if (!err) { + dev->status = status; + PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n" "\t-RESET: %u\n" "\t-ACKNOWLEDGE: %u\n" "\t-DRIVER: %u\n" @@ -875,5 +868,10 @@ virtio_user_update_status(struct virtio_user_dev *dev) !!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK), !!(dev->status & VIRTIO_CONFIG_STATUS_DEV_NEED_RESET), !!(dev->status & VIRTIO_CONFIG_STATUS_FAILED)); - return 0; + } else if (err != -ENOTSUP) { + PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err, + strerror(errno)); + } + + return err; } From patchwork Mon Oct 26 16:39:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 82215 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 E3E68A04DD; Mon, 26 Oct 2020 17:42:30 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 24EA04C89; Mon, 26 Oct 2020 17:40:08 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 1760C2C15 for ; Mon, 26 Oct 2020 17:39:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603730397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bAXkpWVRe8bfWzm7TiygIDAussPqnmB1T8YXYNpPSnc=; b=jIvJ3mW4pTML4v5WugveiQQRhcKpp2qCH5nla44laLyXcZjaL5EaeTfQJkzxiUNdwnCdi9 U7hnoyKKrx7fcUxDRXwdBcT+OcnCz6lC1g04drtXrPJc/TYXNR9kGeMkTYIwofOIlrAk0I +rfeztgirE7D4v4SLgpjF5HfB9KrPhM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-176-ZvN5Vm1vOiS9qtfYcfXCdA-1; Mon, 26 Oct 2020 12:39:56 -0400 X-MC-Unique: ZvN5Vm1vOiS9qtfYcfXCdA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C96F0809DC0; Mon, 26 Oct 2020 16:39:54 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42CA15577D; Mon, 26 Oct 2020 16:39:53 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: yinan.wang@intel.com, patrick.fu@intel.com, chenbo.xia@intel.com, zhihong.wang@intel.com, maxime.coquelin@redhat.com, Adrian Moreno Date: Mon, 26 Oct 2020 17:39:28 +0100 Message-Id: <20201026163930.94032-5-amorenoz@redhat.com> In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com> References: <20201026163930.94032-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 4/6] net/virtio-user: lock-protect status updates 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" In order to safely set and get the device status from different threads (e.g: interrupt handlers). Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/virtio_user_dev.c | 14 +++++++++++--- drivers/net/virtio/virtio_user/virtio_user_dev.h | 4 ++-- drivers/net/virtio/virtio_user_ethdev.c | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 5a1e76006..36e5619df 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -806,11 +806,13 @@ virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx) } int -virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status) +virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status) { int ret; uint64_t arg = status; + pthread_mutex_lock(&dev->mutex); + dev->status = status; if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER) ret = dev->ops->send_request(dev, VHOST_USER_SET_STATUS, &arg); @@ -824,22 +826,26 @@ virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status) PMD_INIT_LOG(ERR, "VHOST_USER_SET_STATUS failed (%d): %s", ret, strerror(errno)); } + + pthread_mutex_unlock(&dev->mutex); return ret; } int -virtio_user_update_status(struct virtio_user_dev *dev) +virtio_user_dev_update_status(struct virtio_user_dev *dev) { uint64_t ret; uint8_t status; int err; + pthread_mutex_lock(&dev->mutex); if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER) { err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret); if (!err && ret > UINT8_MAX) { PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS " "response 0x%" PRIx64 "\n", ret); - return -1; + err = -1; + goto error; } status = ret; @@ -873,5 +879,7 @@ virtio_user_update_status(struct virtio_user_dev *dev) strerror(errno)); } +error: + pthread_mutex_unlock(&dev->mutex); return err; } diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 998986875..e053897d8 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -81,7 +81,7 @@ void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx); void virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx); uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs); -int virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status); -int virtio_user_update_status(struct virtio_user_dev *dev); +int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status); +int virtio_user_dev_update_status(struct virtio_user_dev *dev); extern const char * const virtio_user_backend_strings[]; #endif diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index e870fb2ff..97ddc5651 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -278,8 +278,8 @@ virtio_user_set_status(struct virtio_hw *hw, uint8_t status) virtio_user_start_device(dev); else if (status == VIRTIO_CONFIG_STATUS_RESET) virtio_user_reset(hw); - dev->status = status; - virtio_user_send_status_update(dev, status); + + virtio_user_dev_set_status(dev, status); } static uint8_t @@ -287,7 +287,7 @@ virtio_user_get_status(struct virtio_hw *hw) { struct virtio_user_dev *dev = virtio_user_get_dev(hw); - virtio_user_update_status(dev); + virtio_user_dev_update_status(dev); return dev->status; } From patchwork Mon Oct 26 16:39:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 82216 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 0F3C2A04DD; Mon, 26 Oct 2020 17:42:50 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 50AB74C94; Mon, 26 Oct 2020 17:40:12 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id A36E937AF for ; Mon, 26 Oct 2020 17:40:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603730402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OeUuGepVoCBebD+MkNGvbkMiuskRc3grFgPjhWvaBEk=; b=Pudrno02kxuyZf9k1UBq7bf9GB7Kng+RvB23m0sCqhuu1FDQXdwmSW1Hti6tG1tHE0M9fB OV/zMb4nQaNvN0Ha3lCIeR5CjcsAl2RXna6aNNR1c09o7pBgdoJpDpLgr8gJ+x/f2gvQTf UCt6DxuMte9Tp4ikR9t1VxjJnBT/xeo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-Y9xz2C5IMmG9NVhRjOHamg-1; Mon, 26 Oct 2020 12:39:58 -0400 X-MC-Unique: Y9xz2C5IMmG9NVhRjOHamg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2FA218C9F46; Mon, 26 Oct 2020 16:39:56 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F7CF55762; Mon, 26 Oct 2020 16:39:55 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: yinan.wang@intel.com, patrick.fu@intel.com, chenbo.xia@intel.com, zhihong.wang@intel.com, maxime.coquelin@redhat.com, Adrian Moreno , stable@dpdk.org Date: Mon, 26 Oct 2020 17:39:29 +0100 Message-Id: <20201026163930.94032-6-amorenoz@redhat.com> In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com> References: <20201026163930.94032-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 5/6] net/virtio-user: don't assume vhost status feature 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" There are some status reads and updates that need to happen before the protocol features are negotiated. Therefore, assuming the backend does support this feature can lead to failures. On server mode, do not assume the backend supports VHOST_USER_PROTOCOL_F_STATUS. Activate it back on reconnection and cleare it on disconnection. Fixes: 57912824615f ("net/virtio-user: support vhost status setting") Cc: maxime.coquelin@redhat.com Cc: stable@dpdk.org Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 ++++++ drivers/net/virtio/virtio_user_ethdev.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 36e5619df..053f0267c 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -523,6 +523,12 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, * later. */ dev->device_features = VIRTIO_USER_SUPPORTED_FEATURES; + + /* We cannot assume VHOST_USER_PROTOCOL_F_STATUS is supported + * until it's negotiated + */ + dev->protocol_features &= + ~(1ULL << VHOST_USER_PROTOCOL_F_STATUS); } diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 97ddc5651..142bdc0bd 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -92,6 +92,9 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev) &protocol_features)) return -1; + /* Offer VHOST_USER_PROTOCOL_F_STATUS */ + dev->protocol_features |= + (1ULL << VHOST_USER_PROTOCOL_F_STATUS); dev->protocol_features &= protocol_features; if (dev->ops->send_request(dev, @@ -168,6 +171,11 @@ virtio_user_delayed_handler(void *param) if (dev->vhostfd >= 0) { close(dev->vhostfd); dev->vhostfd = -1; + /* Until the featuers are negotiated again, don't assume + * the backend supports VHOST_USER_PROTOCOL_F_STATUS + */ + dev->protocol_features &= + ~(1ULL << VHOST_USER_PROTOCOL_F_STATUS); } eth_dev->intr_handle->fd = dev->listenfd; rte_intr_callback_register(eth_dev->intr_handle, From patchwork Mon Oct 26 16:39:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 82217 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 565C5A04DD; Mon, 26 Oct 2020 17:43:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D388A4F90; Mon, 26 Oct 2020 17:40:14 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id 11606493D for ; Mon, 26 Oct 2020 17:40:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603730407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KcKnldrg5r1IYW680vebzNxN2juPi1C+sMIxNOUlHYE=; b=GC3P2Rko3yTZUnVmws7FVuIHCErGb0JRAVf+KkOCDWQ0ZKHcQgIK99Xnv5RFDuYZuQGBFI x5jok+1+Mo/V5JMzLZ/GOpgzLdAJrDI0BRF6Qqi9iQWq/dXjSSo/uB/8YuKtDGxxH1rmpW g4V5hwH+f5m7pkFnW6YkK7nPDVzZuec= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-3s1kcLgQNV24PqAdi4-NJA-1; Mon, 26 Oct 2020 12:40:05 -0400 X-MC-Unique: 3s1kcLgQNV24PqAdi4-NJA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F9C0804B94; Mon, 26 Oct 2020 16:40:04 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E2E45576E; Mon, 26 Oct 2020 16:39:57 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: yinan.wang@intel.com, patrick.fu@intel.com, chenbo.xia@intel.com, zhihong.wang@intel.com, maxime.coquelin@redhat.com, Adrian Moreno , stable@dpdk.org Date: Mon, 26 Oct 2020 17:39:30 +0100 Message-Id: <20201026163930.94032-7-amorenoz@redhat.com> In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com> References: <20201026163930.94032-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 6/6] net/virtio-user: set status on socket reconnect 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" Newer vhost-user backends will rely on SET_STATUS to start the device so this required to support them. Fixes: 57912824615f ("net/virtio-user: support vhost status setting") Cc: maxime.coquelin@redhat.com Cc: stable@dpdk.org Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user_ethdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 142bdc0bd..40345193e 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -67,8 +67,7 @@ virtio_user_reset_queues_packed(struct rte_eth_dev *dev) static int virtio_user_server_reconnect(struct virtio_user_dev *dev) { - int ret; - int connectfd; + int ret, connectfd, old_status; struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id]; struct virtio_hw *hw = eth_dev->data->dev_private; uint64_t protocol_features; @@ -78,6 +77,14 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev) return -1; dev->vhostfd = connectfd; + old_status = vtpci_get_status(hw); + + vtpci_reset(hw); + + vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_ACK); + + vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER); + if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES, &dev->device_features) < 0) { PMD_INIT_LOG(ERR, "get_features failed: %s", @@ -116,14 +123,17 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev) /* For packed ring, resetting queues is required in reconnection. */ if (vtpci_packed_queue(hw) && - (vtpci_get_status(hw) & VIRTIO_CONFIG_STATUS_DRIVER_OK)) { + (old_status & VIRTIO_CONFIG_STATUS_DRIVER_OK)) { PMD_INIT_LOG(NOTICE, "Packets on the fly will be dropped" " when packed ring reconnecting."); virtio_user_reset_queues_packed(eth_dev); } - ret = virtio_user_start_device(dev); - if (ret < 0) + vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK); + + /* Start the device */ + vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK); + if (!dev->started) return -1; if (dev->queue_pairs > 1) {