DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huawei Xie <huawei.xie@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4 1/4] vhost: call fdset_del_slot to remove connection fd
Date: Tue, 30 Jun 2015 17:20:47 +0800	[thread overview]
Message-ID: <1435656050-3539-2-git-send-email-huawei.xie@intel.com> (raw)
In-Reply-To: <1435656050-3539-1-git-send-email-huawei.xie@intel.com>

In the event handler of connection fd, the connection fd could be possibly
closed. The event dispatch loop would then try to remove the fd from fdset.
Between these two actions, another thread might register a new listenfd
reusing the val of just closed fd, so we couldn't call fdset_del which would
wrongly clean up the new listenfd. A new function fdset_del_slot is provided
to cleanup the fd at the specified location.

v4 changes:
- call fdset_del_slot to remove connection fd

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
 lib/librte_vhost/vhost_user/fd_man.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/lib/librte_vhost/vhost_user/fd_man.c b/lib/librte_vhost/vhost_user/fd_man.c
index 831c9c1..bd30f8d 100644
--- a/lib/librte_vhost/vhost_user/fd_man.c
+++ b/lib/librte_vhost/vhost_user/fd_man.c
@@ -188,6 +188,24 @@ fdset_del(struct fdset *pfdset, int fd)
 }
 
 /**
+ *  Unregister the fd at the specified slot from the fdset.
+ */
+static void
+fdset_del_slot(struct fdset *pfdset, int index)
+{
+	if (pfdset == NULL || index < 0 || index >= MAX_FDS)
+		return;
+
+	pthread_mutex_lock(&pfdset->fd_mutex);
+
+	pfdset->fd[index].fd = -1;
+	pfdset->fd[index].rcb = pfdset->fd[index].wcb = NULL;
+	pfdset->num--;
+
+	pthread_mutex_unlock(&pfdset->fd_mutex);
+}
+
+/**
  * This functions runs in infinite blocking loop until there is no fd in
  * pfdset. It calls corresponding r/w handler if there is event on the fd.
  *
@@ -248,8 +266,15 @@ fdset_event_dispatch(struct fdset *pfdset)
 			 * We don't allow fdset_del to be called in callback
 			 * directly.
 			 */
+			/*
+			 * When we are to clean up the fd from fdset,
+			 * because the fd is closed in the cb,
+			 * the old fd val could be reused by when creates new
+			 * listen fd in another thread, we couldn't call
+			 * fd_set_del.
+			 */
 			if (remove1 || remove2)
-				fdset_del(pfdset, fd);
+				fdset_del_slot(pfdset, i);
 		}
 	}
 }
-- 
1.8.1.4

  reply	other threads:[~2015-06-30  9:21 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-02  1:50 [dpdk-dev] [PATCH] vhost: provide vhost API to unregister vhost unix domain socket Huawei Xie
2015-06-03  9:42 ` Loftus, Ciara
2015-06-03 12:55 ` Ouyang, Changchun
2015-06-03 19:03   ` Xie, Huawei
2015-06-05  3:26 ` [dpdk-dev] [PATCH v2] " Huawei Xie
2015-06-05  9:04   ` Loftus, Ciara
2015-06-08 15:38     ` Xie, Huawei
2015-06-08 20:25       ` Thomas F Herbert
2015-06-17  8:10       ` Panu Matilainen
2015-06-17  3:33     ` Xie, Huawei
2015-06-17 20:59   ` Thomas Monjalon
2015-06-18  1:40     ` Xie, Huawei
2015-06-18 17:40   ` [dpdk-dev] [PATCH v3 0/2] vhost: vhost unix domain socket cleanup Huawei Xie
2015-06-18 17:40     ` [dpdk-dev] [PATCH v3 1/2] " Huawei Xie
2015-06-29 18:28       ` Xie, Huawei
2015-06-29 21:02         ` Thomas Monjalon
2015-06-30  6:19           ` Xie, Huawei
2015-06-30  9:20       ` [dpdk-dev] [PATCH v4 0/4] " Huawei Xie
2015-06-30  9:20         ` Huawei Xie [this message]
2015-07-01  2:14           ` [dpdk-dev] [PATCH v4 1/4] vhost: call fdset_del_slot to remove connection fd Ouyang, Changchun
2015-06-30  9:20         ` [dpdk-dev] [PATCH v4 2/4] vhost: vhost unix domain socket cleanup Huawei Xie
2015-07-01  2:14           ` Ouyang, Changchun
2015-06-30  9:20         ` [dpdk-dev] [PATCH v4 3/4] vhost: version map file update Huawei Xie
2015-07-01  2:15           ` Ouyang, Changchun
2015-06-30  9:20         ` [dpdk-dev] [PATCH v4 4/4] vhost: add comment for potential unwanted callback on listenfds Huawei Xie
2015-07-01  2:15           ` Ouyang, Changchun
2015-06-30 15:55         ` [dpdk-dev] [PATCH v4 0/4] vhost: vhost unix domain socket cleanup Thomas Monjalon
2015-06-18 17:41     ` [dpdk-dev] [PATCH v3 2/2] vhost: version map file update Huawei Xie
2015-06-17  4:17 ` [dpdk-dev] [PATCH] vhost: provide vhost API to unregister vhost unix domain socket Tetsuya Mukawa
2015-06-17 11:05   ` Xie, Huawei
2015-06-18  1:00     ` Tetsuya Mukawa

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=1435656050-3539-2-git-send-email-huawei.xie@intel.com \
    --to=huawei.xie@intel.com \
    --cc=dev@dpdk.org \
    /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).