DPDK patches and discussions
 help / color / mirror / Atom feed
From: Adrian Moreno <amorenoz@redhat.com>
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 <amorenoz@redhat.com>
Subject: [dpdk-dev] [PATCH v3 3/6] net/virtio-user: ignore result if STATUS is unsupported
Date: Mon, 26 Oct 2020 17:39:27 +0100	[thread overview]
Message-ID: <20201026163930.94032-4-amorenoz@redhat.com> (raw)
In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com>

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 <amorenoz@redhat.com>
---
 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;
 }
-- 
2.26.2


  parent reply	other threads:[~2020-10-26 16:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 16:39 [dpdk-dev] [PATCH v3 0/6] net/virtio-user: fix server mode Adrian Moreno
2020-10-26 16:39 ` [dpdk-dev] [PATCH v3 1/6] net/virtio-user: fix backend selection if stat fails Adrian Moreno
2020-10-26 16:39 ` [dpdk-dev] [PATCH v3 2/6] net/virtio-user: don't set/get_status until FEATURES_OK Adrian Moreno
2020-10-26 16:39 ` Adrian Moreno [this message]
2020-10-28  9:39   ` [dpdk-dev] [PATCH v3 3/6] net/virtio-user: ignore result if STATUS is unsupported Maxime Coquelin
2020-10-26 16:39 ` [dpdk-dev] [PATCH v3 4/6] net/virtio-user: lock-protect status updates Adrian Moreno
2020-10-28 10:35   ` Maxime Coquelin
2020-10-26 16:39 ` [dpdk-dev] [PATCH v3 5/6] net/virtio-user: don't assume vhost status feature Adrian Moreno
2020-10-28 10:37   ` Maxime Coquelin
2020-10-26 16:39 ` [dpdk-dev] [PATCH v3 6/6] net/virtio-user: set status on socket reconnect Adrian Moreno
2020-10-28 11:01   ` Maxime Coquelin
2020-10-27  3:09 ` [dpdk-dev] [PATCH v3 0/6] net/virtio-user: fix server mode Jiang, YuX
2020-10-29  8:27 ` Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201026163930.94032-4-amorenoz@redhat.com \
    --to=amorenoz@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=patrick.fu@intel.com \
    --cc=yinan.wang@intel.com \
    --cc=zhihong.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).