From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 64598C36E for ; Wed, 1 Jul 2015 04:14:08 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 30 Jun 2015 19:14:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,382,1432623600"; d="scan'208";a="597836800" Received: from kmsmsx153.gar.corp.intel.com ([172.21.73.88]) by orsmga003.jf.intel.com with ESMTP; 30 Jun 2015 19:14:06 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by KMSMSX153.gar.corp.intel.com (172.21.73.88) with Microsoft SMTP Server (TLS) id 14.3.224.2; Wed, 1 Jul 2015 10:14:06 +0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.165]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.246]) with mapi id 14.03.0224.002; Wed, 1 Jul 2015 10:14:04 +0800 From: "Ouyang, Changchun" To: "Xie, Huawei" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v4 1/4] vhost: call fdset_del_slot to remove connection fd Thread-Index: AQHQsxYlU1EfyOw5XEy0GYdBzfbUGp3F4MFQ Date: Wed, 1 Jul 2015 02:14:03 +0000 Message-ID: References: <1434649260-26317-2-git-send-email-huawei.xie@intel.com> <1435656050-3539-1-git-send-email-huawei.xie@intel.com> <1435656050-3539-2-git-send-email-huawei.xie@intel.com> In-Reply-To: <1435656050-3539-2-git-send-email-huawei.xie@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v4 1/4] vhost: call fdset_del_slot to remove connection fd X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jul 2015 02:14:08 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Huawei Xie > Sent: Tuesday, June 30, 2015 5:21 PM > To: dev@dpdk.org > Subject: [dpdk-dev] [PATCH v4 1/4] vhost: call fdset_del_slot to remove > connection fd >=20 > In the event handler of connection fd, the connection fd could be possibl= y > closed. The event dispatch loop would then try to remove the fd from fdse= t. > 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 wo= uld > wrongly clean up the new listenfd. A new function fdset_del_slot is provi= ded > to cleanup the fd at the specified location. >=20 > v4 changes: > - call fdset_del_slot to remove connection fd >=20 > Signed-off-by: Huawei Xie Acked-by: Changchun Ouyang > --- > lib/librte_vhost/vhost_user/fd_man.c | 27 > ++++++++++++++++++++++++++- > 1 file changed, 26 insertions(+), 1 deletion(-) >=20 > 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) } >=20 > /** > + * Unregister the fd at the specified slot from the fdset. > + */ > +static void > +fdset_del_slot(struct fdset *pfdset, int index) { > + if (pfdset =3D=3D NULL || index < 0 || index >=3D MAX_FDS) > + return; > + > + pthread_mutex_lock(&pfdset->fd_mutex); > + > + pfdset->fd[index].fd =3D -1; > + pfdset->fd[index].rcb =3D pfdset->fd[index].wcb =3D 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 f= d. > * > @@ -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