From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ilovethull@163.com>
Received: from m50-135.163.com (m50-135.163.com [123.125.50.135])
 by dpdk.org (Postfix) with ESMTP id A32381B04C
 for <dev@dpdk.org>; Mon, 22 Jan 2018 08:52:06 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;
 s=s110527; h=Subject:From:Message-ID:Date:MIME-Version; bh=e0uiw
 +pNwTXXlPht/AsWqKr/AfE+xtf7q2xDILPzohE=; b=IrQOrpq0OZfwloeAEpzPW
 ZcqNy3wjd7Y8Y+SPXWI/vlEa9bJeT9AKdn6aADwbIDlsG+9Cif6VQY01o+2y3oZw
 1Ht7hIVi7yOmaI8aPUM1dLt1VYpzGtWTvLs7B6wl3ALiKjPGiAGq+ed+YvtDpExQ
 L3zZIVA2gqlam0wV8ochOU=
Received: from [10.65.21.36] (unknown [116.231.15.193])
 by smtp5 (Coremail) with SMTP id D9GowADXrWEjmGVa54ywAQ--.76S2;
 Mon, 22 Jan 2018 15:52:04 +0800 (CST)
To: Yuanhan Liu <yliu@fridaylinux.org>
Cc: dev@dpdk.org, bing.zhao@hxt-semitech.com
References: <20171221091540.8624-1-ilovethull@163.com>
 <20180119143729.GP29540@yliu-mob>
From: "Zhao, Bing" <ilovethull@163.com>
Message-ID: <e48f3f2c-4c6a-bbe9-4a6d-cc29ac38176f@163.com>
Date: Mon, 22 Jan 2018 15:52:11 +0800
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.5.2
MIME-Version: 1.0
In-Reply-To: <20180119143729.GP29540@yliu-mob>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-CM-TRANSID: D9GowADXrWEjmGVa54ywAQ--.76S2
X-Coremail-Antispam: 1Uf129KBjvJXoW7WFWDXrWkZF1xJFyUKF43GFg_yoW8WFykpa
 yrWF18KrZxtr10v3ZrZay8t348A3WFq343Crs3KFn0vF4Yqr10qrZxKryY9F9agr18X3W2
 yF40qFy5WayDXa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bjqXdUUUUU=
X-Originating-IP: [116.231.15.193]
X-CM-SenderInfo: xlor4vhwkxzzi6rwjhhfrp/xtbBDwjVt1O-9bK8BwAAs1
Subject: Re: [dpdk-dev] [PATCH] reset src fd field to -1 in fdset_move of
 vhost
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Jan 2018 07:52:07 -0000

On 2018/1/19 22:37, Yuanhan Liu wrote:
> On Thu, Dec 21, 2017 at 05:15:40PM +0800, Bing Zhao wrote:
>> In the fdset_move, after copying the fd&rwfds from the src to the dst, the fd should be set to -1. Or else in some cases, there will be a fault missing. E.g:
>> Before: 1 -1 3 4 -1 6 7 -1 9 10
>> After: 1 10 3 4 9 6 7 -1 9 10
>> Then the index7 will be returned correctly for the first time, but if another fd is to be added, it will fail.
> 
> Hi,
> 
> Have you met a real issue? I'm a bit doubt about that, since the fd array
> is also guarded by "pfdset->num", which makes sure we will not access
> those invalid entries (i.e. the last 2 entries in above example).
> 
> 	--yliu
> 
>> Signed-off-by: Bing Zhao <bing.zhao@hxt-semitech.com>
>> ---
>>   lib/librte_vhost/fd_man.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
>> index 4c6fed418..48594dd7f 100644
>> --- a/lib/librte_vhost/fd_man.c
>> +++ b/lib/librte_vhost/fd_man.c
>> @@ -63,6 +63,7 @@ fdset_move(struct fdset *pfdset, int dst, int src)
>>   {
>>   	pfdset->fd[dst]    = pfdset->fd[src];
>>   	pfdset->rwfds[dst] = pfdset->rwfds[src];
>> +	pfdset->fd[src].fd = -1;
>>   }
>>   
>>   static void
>> -- 
>> 2.11.0.windows.1
>>
Hello Yuanhan,
Thanks for your information. The answer is "no", and I just study the 
code and notice this. But yes you're right, I missed this. At first I 
thought there was a "-1" check in the "fdset_add_fd", indeed there isn't 
:). And no matter "-1" or other values in the "fd" element, if the "num" 
index points at that position, all the fields will be rewritten. So 
there is no problem.

Thanks again and please just ignore this.