Skip to contentSkip to conversation

reset src fd field to -1 in fdset_move of vhost

PATCH In review Bing Zhao 2 participants 3 messages Dec 21, 2017 – Jan 22, 2018

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

PATCH 1/1 reset src fd field to -1 in fdset_move of vhost

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.

---
 lib/librte_vhost/fd_man.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/fd_man.c +1 -0
index 4c6fed418..48594dd7f 100644
@@ -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
Signature · 1 line
2.11.0.windows.1
#1 lore raw
Quoted 4 lines · Bing Zhao

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
Quoted 20 lines
---
 lib/librte_vhost/fd_man.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/fd_man.c +1 -0
index 4c6fed418..48594dd7f 100644
@@ -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
Signature · 1 line
2.11.0.windows.1
author
#2 lore raw
Quoted 30 lines · Yuanhan Liu
Quoted 4 lines · Bing Zhao

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
Quoted 16 lines
---
  lib/librte_vhost/fd_man.c | 1 +
  1 file changed, 1 insertion(+)
lib/librte_vhost/fd_man.c +1 -0
index 4c6fed418..48594dd7f 100644
@@ -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;
  }
 
Quoted 4 lines
Quoted 4 lines
lib/librte_vhost/fd_man.c +0 -0
  static void
Signature · 1 line
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.