From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 269179954 for ; Thu, 25 May 2017 11:51:18 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 May 2017 02:51:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,391,1491289200"; d="scan'208";a="91624295" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by orsmga002.jf.intel.com with ESMTP; 25 May 2017 02:51:06 -0700 From: Yuanhan Liu To: Matthias Gatto Cc: Yuanhan Liu , dpdk stable Date: Thu, 25 May 2017 17:48:29 +0800 Message-Id: <1495705809-21416-57-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1495705809-21416-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1495705809-21416-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-stable] patch 'vhost: try to shrink pfdset when fdset_add fails' has been queued to stable release 17.02.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 May 2017 09:51:19 -0000 Hi, FYI, your patch has been queued to stable release 17.02.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/28/17. So please shout if anyone has objections. Thanks. --yliu --- >>From b182beb451c10a4c4ad7432cd5611d5856c12ce7 Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Tue, 21 Feb 2017 15:25:30 +0100 Subject: [PATCH] vhost: try to shrink pfdset when fdset_add fails [ upstream commit 1b815b89599cdd9b54e5aa70f5b97088225b2bcc ] fdset_add increments pfdset->num, but fdset_del doesn't decrement pfdset->num, so if we call fdset_add then fdset_del in a loop without calling fdset_shrink, we can easily exceed MAX_FDS with only a few number of fds used. So my solution is simply to call fdset_shrink in fdset_add when it exceeds MAX_FDS. Because fdset_shrink and fdset_add locks pfdset->fd_mutex we can't call fdset_shrink inside fdset_add because that would cause a dead lock, so this patch split fdset_shrink in two, fdset_shrink and fdset_shrink_nolock. Fixes: 59317cef249c ("vhost: allow many vhost-user ports") Signed-off-by: Matthias Gatto --- lib/librte_vhost/fd_man.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c index 8a075da..c7a4490 100644 --- a/lib/librte_vhost/fd_man.c +++ b/lib/librte_vhost/fd_man.c @@ -65,17 +65,12 @@ fdset_move(struct fdset *pfdset, int dst, int src) pfdset->rwfds[dst] = pfdset->rwfds[src]; } -/* - * Find deleted fd entries and remove them - */ static void -fdset_shrink(struct fdset *pfdset) +fdset_shrink_nolock(struct fdset *pfdset) { int i; int last_valid_idx = get_last_valid_idx(pfdset, pfdset->num - 1); - pthread_mutex_lock(&pfdset->fd_mutex); - for (i = 0; i < last_valid_idx; i++) { if (pfdset->fd[i].fd != -1) continue; @@ -84,7 +79,16 @@ fdset_shrink(struct fdset *pfdset) last_valid_idx = get_last_valid_idx(pfdset, last_valid_idx - 1); } pfdset->num = last_valid_idx + 1; +} +/* + * Find deleted fd entries and remove them + */ +static void +fdset_shrink(struct fdset *pfdset) +{ + pthread_mutex_lock(&pfdset->fd_mutex); + fdset_shrink_nolock(pfdset); pthread_mutex_unlock(&pfdset->fd_mutex); } @@ -151,8 +155,12 @@ fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat) pthread_mutex_lock(&pfdset->fd_mutex); i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; if (i == -1) { - pthread_mutex_unlock(&pfdset->fd_mutex); - return -2; + fdset_shrink_nolock(pfdset); + i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; + if (i == -1) { + pthread_mutex_unlock(&pfdset->fd_mutex); + return -2; + } } fdset_add_fd(pfdset, i, fd, rcb, wcb, dat); -- 1.9.0