DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: maxime.coquelin@redhat.com, stephen@networkplumber.org,
	chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com,
	xuan.ding@intel.com, mb@smartsharesystems.com
Subject: [PATCH v5 2/9] vhost: simplify need reply handling
Date: Wed,  1 Feb 2023 12:14:04 +0100	[thread overview]
Message-ID: <20230201111411.1509520-3-david.marchand@redhat.com> (raw)
In-Reply-To: <20230201111411.1509520-1-david.marchand@redhat.com>

Dedicate send_vhost_slave_message() helper to the case when no reply is
needed.

Add a send_vhost_slave_message_process_reply() helper for the opposite.
This new helper merges both send_vhost_slave_message() and the code
previously in process_slave_message_reply().
The slave_req_lock lock is then only handled in this helper which will
make lock checks trivial.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/vhost_user.c | 119 ++++++++++++++++++-----------------------
 1 file changed, 51 insertions(+), 68 deletions(-)

diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 9902ae9944..3f6c5df900 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2868,18 +2868,46 @@ send_vhost_reply(struct virtio_net *dev, int sockfd, struct vhu_msg_context *ctx
 }
 
 static int
-send_vhost_slave_message(struct virtio_net *dev,
-		struct vhu_msg_context *ctx)
+send_vhost_slave_message(struct virtio_net *dev, struct vhu_msg_context *ctx)
+{
+	return send_vhost_message(dev, dev->slave_req_fd, ctx);
+}
+
+static int
+send_vhost_slave_message_process_reply(struct virtio_net *dev, struct vhu_msg_context *ctx)
 {
+	struct vhu_msg_context msg_reply;
 	int ret;
 
-	if (ctx->msg.flags & VHOST_USER_NEED_REPLY)
-		rte_spinlock_lock(&dev->slave_req_lock);
+	rte_spinlock_lock(&dev->slave_req_lock);
+	ret = send_vhost_slave_message(dev, ctx);
+	if (ret < 0) {
+		VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to send config change (%d)\n", ret);
+		goto out;
+	}
 
-	ret = send_vhost_message(dev, dev->slave_req_fd, ctx);
-	if (ret < 0 && (ctx->msg.flags & VHOST_USER_NEED_REPLY))
-		rte_spinlock_unlock(&dev->slave_req_lock);
+	ret = read_vhost_message(dev, dev->slave_req_fd, &msg_reply);
+	if (ret <= 0) {
+		if (ret < 0)
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"vhost read slave message reply failed\n");
+		else
+			VHOST_LOG_CONFIG(dev->ifname, INFO, "vhost peer closed\n");
+		ret = -1;
+		goto out;
+	}
+
+	if (msg_reply.msg.request.slave != ctx->msg.request.slave) {
+		VHOST_LOG_CONFIG(dev->ifname, ERR,
+			"received unexpected msg type (%u), expected %u\n",
+			msg_reply.msg.request.slave, ctx->msg.request.slave);
+		ret = -1;
+		goto out;
+	}
 
+	ret = msg_reply.msg.payload.u64 ? -1 : 0;
+out:
+	rte_spinlock_unlock(&dev->slave_req_lock);
 	return ret;
 }
 
@@ -3203,42 +3231,6 @@ vhost_user_msg_handler(int vid, int fd)
 	return ret;
 }
 
-static int process_slave_message_reply(struct virtio_net *dev,
-				       const struct vhu_msg_context *ctx)
-{
-	struct vhu_msg_context msg_reply;
-	int ret;
-
-	if ((ctx->msg.flags & VHOST_USER_NEED_REPLY) == 0)
-		return 0;
-
-	ret = read_vhost_message(dev, dev->slave_req_fd, &msg_reply);
-	if (ret <= 0) {
-		if (ret < 0)
-			VHOST_LOG_CONFIG(dev->ifname, ERR,
-				"vhost read slave message reply failed\n");
-		else
-			VHOST_LOG_CONFIG(dev->ifname, INFO, "vhost peer closed\n");
-		ret = -1;
-		goto out;
-	}
-
-	ret = 0;
-	if (msg_reply.msg.request.slave != ctx->msg.request.slave) {
-		VHOST_LOG_CONFIG(dev->ifname, ERR,
-			"received unexpected msg type (%u), expected %u\n",
-			msg_reply.msg.request.slave, ctx->msg.request.slave);
-		ret = -1;
-		goto out;
-	}
-
-	ret = msg_reply.msg.payload.u64 ? -1 : 0;
-
-out:
-	rte_spinlock_unlock(&dev->slave_req_lock);
-	return ret;
-}
-
 int
 vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
 {
@@ -3267,10 +3259,9 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
 	return 0;
 }
 
-static int
-vhost_user_slave_config_change(struct virtio_net *dev, bool need_reply)
+int
+rte_vhost_slave_config_change(int vid, bool need_reply)
 {
-	int ret;
 	struct vhu_msg_context ctx = {
 		.msg = {
 			.request.slave = VHOST_USER_SLAVE_CONFIG_CHANGE_MSG,
@@ -3278,29 +3269,23 @@ vhost_user_slave_config_change(struct virtio_net *dev, bool need_reply)
 			.size = 0,
 		}
 	};
-
-	if (need_reply)
-		ctx.msg.flags |= VHOST_USER_NEED_REPLY;
-
-	ret = send_vhost_slave_message(dev, &ctx);
-	if (ret < 0) {
-		VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to send config change (%d)\n", ret);
-		return ret;
-	}
-
-	return process_slave_message_reply(dev, &ctx);
-}
-
-int
-rte_vhost_slave_config_change(int vid, bool need_reply)
-{
 	struct virtio_net *dev;
+	int ret;
 
 	dev = get_device(vid);
 	if (!dev)
 		return -ENODEV;
 
-	return vhost_user_slave_config_change(dev, need_reply);
+	if (!need_reply) {
+		ret = send_vhost_slave_message(dev, &ctx);
+	} else {
+		ctx.msg.flags |= VHOST_USER_NEED_REPLY;
+		ret = send_vhost_slave_message_process_reply(dev, &ctx);
+	}
+
+	if (ret < 0)
+		VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to send config change (%d)\n", ret);
+	return ret;
 }
 
 static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev,
@@ -3329,13 +3314,11 @@ static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev,
 		ctx.fd_num = 1;
 	}
 
-	ret = send_vhost_slave_message(dev, &ctx);
-	if (ret < 0) {
+	ret = send_vhost_slave_message_process_reply(dev, &ctx);
+	if (ret < 0)
 		VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to set host notifier (%d)\n", ret);
-		return ret;
-	}
 
-	return process_slave_message_reply(dev, &ctx);
+	return ret;
 }
 
 int rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable)
-- 
2.39.1


  parent reply	other threads:[~2023-02-01 11:16 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28 12:17 [RFC PATCH 0/5] vhost lock annotations David Marchand
2022-03-28 12:17 ` [RFC PATCH 1/5] vhost: fix missing virtqueue lock protection David Marchand
2022-03-28 12:17 ` [RFC PATCH 2/5] vhost: annotate virtqueue access lock David Marchand
2022-03-28 12:17 ` [RFC PATCH 3/5] vhost: fix async access David Marchand
2022-03-28 12:17 ` [RFC PATCH 4/5] vhost: annotate async locking requirement David Marchand
2022-03-28 12:17 ` [RFC PATCH 5/5] vhost: annotate IOTLB locks David Marchand
2022-03-30 13:49 ` [RFC PATCH v2 0/9] vhost lock annotations David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 1/9] vhost: fix missing virtqueue lock protection David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 2/9] eal: annotate spinlock and rwlock David Marchand
2022-03-31  9:22     ` David Marchand
2022-04-04  6:21     ` Stephen Hemminger
2022-04-07  8:20       ` David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 3/9] vhost: annotate virtqueue access lock David Marchand
2022-04-07  1:40     ` Hu, Jiayu
2022-04-07  7:03       ` David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 4/9] vhost: fix async access David Marchand
2022-03-31  8:00     ` Maxime Coquelin
2022-03-31 10:23       ` Hu, Jiayu
2022-04-04  6:57     ` Pai G, Sunil
2022-03-30 13:49   ` [RFC PATCH v2 5/9] vhost: annotate async acesses David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 6/9] vhost: annotate need reply handling David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 7/9] vhost: annotate VDPA device list accesses David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 8/9] vhost: annotate IOTLB locks David Marchand
2022-03-30 13:49   ` [RFC PATCH v2 9/9] vhost: enable lock check David Marchand
2022-03-30 14:03   ` [RFC PATCH v2 0/9] vhost lock annotations David Marchand
2022-03-30 14:37     ` Ali Alnubani
2022-04-05  7:11       ` David Marchand
2022-04-11 11:00 ` [RFC PATCH v3 0/8] " David Marchand
2022-04-11 11:00   ` [RFC PATCH v3 1/8] eal: annotate spinlock and rwlock David Marchand
2022-04-21 13:48     ` Maxime Coquelin
2022-04-28 12:16       ` David Marchand
2022-04-11 11:00   ` [RFC PATCH v3 2/8] vhost: annotate virtqueue access lock David Marchand
2022-04-21 15:25     ` Maxime Coquelin
2022-04-22  9:49       ` David Marchand
2022-04-11 11:00   ` [RFC PATCH v3 3/8] vhost: fix async access David Marchand
2022-04-21 19:21     ` Maxime Coquelin
2022-05-17 13:24     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 4/8] vhost: annotate async accesses David Marchand
2022-04-22  7:20     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 5/8] vhost: annotate need reply handling David Marchand
2022-04-22  7:25     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 6/8] vhost: annotate vDPA device list accesses David Marchand
2022-04-22  7:26     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 7/8] vhost: annotate IOTLB locks David Marchand
2022-04-22  7:46     ` Maxime Coquelin
2022-04-11 11:00   ` [RFC PATCH v3 8/8] vhost: enable lock check David Marchand
2022-04-22  7:47     ` Maxime Coquelin
2023-01-19 18:46 ` [PATCH v4 0/9] vhost lock annotations David Marchand
2023-01-19 18:46   ` [PATCH v4 1/9] eal: annotate spinlock, rwlock and seqlock David Marchand
2023-01-19 19:42     ` Stephen Hemminger
2023-01-19 20:39       ` Tyler Retzlaff
2023-01-19 21:16         ` David Marchand
2023-01-19 21:50           ` Tyler Retzlaff
2023-01-26 12:18             ` David Marchand
2023-01-19 20:55       ` David Marchand
2023-01-19 19:43     ` Stephen Hemminger
2023-01-31 16:18     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 2/9] vhost: simplify need reply handling David Marchand
2023-01-31 16:41     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 3/9] vhost: terminate when access lock is not taken David Marchand
2023-01-31 16:47     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 4/9] vhost: annotate virtqueue access lock David Marchand
2023-01-31 16:50     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 5/9] vhost: annotate async accesses David Marchand
2023-01-31 16:54     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 6/9] vhost: always take IOTLB lock David Marchand
2023-01-31 16:59     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 7/9] vhost: annotate " David Marchand
2023-01-31 17:05     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 8/9] vhost: annotate vDPA device list accesses David Marchand
2023-01-31 17:08     ` Maxime Coquelin
2023-01-19 18:46   ` [PATCH v4 9/9] vhost: enable lock check David Marchand
2023-01-31 17:14     ` Maxime Coquelin
2023-01-19 19:20   ` [PATCH v4 0/9] vhost lock annotations Morten Brørup
2023-02-01 11:14 ` [PATCH v5 0/9] Lock annotations David Marchand
2023-02-01 11:14   ` [PATCH v5 1/9] eal: annotate spinlock, rwlock and seqlock David Marchand
2023-02-01 12:32     ` David Marchand
2023-02-06  1:01       ` Tu, Lijuan
2023-02-06  8:12         ` David Marchand
2023-02-01 11:14   ` David Marchand [this message]
2023-02-01 11:14   ` [PATCH v5 3/9] vhost: terminate when access lock is not taken David Marchand
2023-02-01 11:14   ` [PATCH v5 4/9] vhost: annotate virtqueue access lock David Marchand
2023-02-01 11:14   ` [PATCH v5 5/9] vhost: annotate async accesses David Marchand
2023-02-01 11:14   ` [PATCH v5 6/9] vhost: always take IOTLB lock David Marchand
2023-02-01 11:14   ` [PATCH v5 7/9] vhost: annotate " David Marchand
2023-02-01 11:14   ` [PATCH v5 8/9] vhost: annotate vDPA device list accesses David Marchand
2023-02-01 11:14   ` [PATCH v5 9/9] vhost: enable lock check David Marchand
2023-02-07 10:45 ` [PATCH v6 0/9] Lock annotations David Marchand
2023-02-07 10:45   ` [PATCH v6 1/9] eal: annotate spinlock, rwlock and seqlock David Marchand
2023-02-09  8:00     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 2/9] vhost: simplify need reply handling David Marchand
2023-02-09  8:00     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 3/9] vhost: terminate when access lock is not taken David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 4/9] vhost: annotate virtqueue access lock David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 5/9] vhost: annotate async accesses David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 6/9] vhost: always take IOTLB lock David Marchand
2023-02-09  8:01     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 7/9] vhost: annotate " David Marchand
2023-02-09  8:02     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 8/9] vhost: annotate vDPA device list accesses David Marchand
2023-02-09  8:02     ` Xia, Chenbo
2023-02-07 10:45   ` [PATCH v6 9/9] vhost: enable lock check David Marchand
2023-02-09  8:05     ` Xia, Chenbo
2023-02-09  7:59   ` [PATCH v6 0/9] Lock annotations Xia, Chenbo
2023-02-09  8:08     ` David Marchand
2023-02-09  8:24       ` Xia, Chenbo
2023-02-09 13:48   ` David Marchand

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=20230201111411.1509520-3-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=jiayu.hu@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=mb@smartsharesystems.com \
    --cc=stephen@networkplumber.org \
    --cc=xuan.ding@intel.com \
    --cc=yuanx.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).