Skip to contentSkip to conversation

libvhost-user: fix SLAVE_SEND_FD handling

PATCH In review Johannes Berg 2 participants 3 messages Sep 3, 2019 – Sep 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libvhost-user: fix SLAVE_SEND_FD handling

From: Johannes Berg <[email protected]>

It doesn't look like this could possibly work properly since VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD is defined to 10, but the dev->protocol_features has a bitmap. I suppose the peer this was tested with also supported VHOST_USER_PROTOCOL_F_LOG_SHMFD, in which case the test would always be false, but nevertheless the code seems wrong.

Use has_feature() to fix this.

Fixes d84599f56c82 ("libvhost-user: support host notifier")
---
 contrib/libvhost-user/libvhost-user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +2 -1
index 6a02eaffc672..fcf4a8a00ed2 100644
@@ -1097,7 +1097,8 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
 
     vmsg.fd_num = fd_num;
 
-    if ((dev->protocol_features & VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) == 0) {
+    if (!has_feature(dev->protocol_features,
+                     VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD)) {
         return false;
     }
 
Signature · 1 line
2.23.0
#1 lore raw
Quoted 8 lines · Johannes Berg

From: Johannes Berg <[email protected]>

It doesn't look like this could possibly work properly since VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD is defined to 10, but the dev->protocol_features has a bitmap. I suppose the peer this was tested with also supported VHOST_USER_PROTOCOL_F_LOG_SHMFD, in which case the test would always be false, but nevertheless the code seems wrong.

Ooops.. I tested tests/vhost-user-bridge -H. But as you said it worked because VHOST_USER_PROTOCOL_F_LOG_SHMFD has been negotiated. Thanks for spotting this!

Quoted 4 lines

Use has_feature() to fix this.

Fixes d84599f56c82 ("libvhost-user: support host notifier")
Quoted 10 lines
---
 contrib/libvhost-user/libvhost-user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +0 -0
index 6a02eaffc672..fcf4a8a00ed2 100644

contrib/libvhost-user/libvhost-user.c bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd, · line 1101

Quoted 6 lines
contrib/libvhost-user/libvhost-user.c +2 -1
@@ -1097,7 +1097,8 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
 
     vmsg.fd_num = fd_num;
 
-    if ((dev->protocol_features & VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) == 0) {
+    if (!has_feature(dev->protocol_features,
+                     VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD)) {

We have both of has_feature() and vu_has_feature() called by other code in this file directly. Not sure which one is preferred.. Personally, I think vu_has_feature() might be better.

Thanks!
Tiwei

Quoted 6 lines
contrib/libvhost-user/libvhost-user.c +0 -0
         return false;
     }
 
Signature · 1 line
2.23.0
Reviewed-by
#2 lore raw
Quoted 34 lines · Tiwei Bie
Quoted 8 lines · Johannes Berg

From: Johannes Berg <[email protected]>

It doesn't look like this could possibly work properly since VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD is defined to 10, but the dev->protocol_features has a bitmap. I suppose the peer this was tested with also supported VHOST_USER_PROTOCOL_F_LOG_SHMFD, in which case the test would always be false, but nevertheless the code seems wrong.

Ooops.. I tested tests/vhost-user-bridge -H. But as you said it worked because VHOST_USER_PROTOCOL_F_LOG_SHMFD has been negotiated. Thanks for spotting this!

Quoted 4 lines

Use has_feature() to fix this.

Fixes d84599f56c82 ("libvhost-user: support host notifier")
Quoted 13 lines
---
 contrib/libvhost-user/libvhost-user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +0 -0
index 6a02eaffc672..fcf4a8a00ed2 100644
@@ -1097,7 +1097,8 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
 
     vmsg.fd_num = fd_num;
 
Quoted 7 lines

contrib/libvhost-user/libvhost-user.c bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd, · line 1101

Quoted 3 lines
contrib/libvhost-user/libvhost-user.c +2 -1
-    if ((dev->protocol_features & VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) == 0) {
+    if (!has_feature(dev->protocol_features,
+                     VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD)) {

We have both of has_feature() and vu_has_feature() called by other code in this file directly. Not sure which one is preferred.. Personally, I think vu_has_feature() might be better.

Thanks for the patch introducing vu_has_protocol_feature(). This fix looks good to me. Thanks a lot!

I'm not the maintainer. But anyway, if this helps: