libvhost-user: fix SLAVE_SEND_FD handling
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.
--- contrib/libvhost-user/libvhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
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 )) {return false; }
Signature · 1 line
2.23.0
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_FDis defined to 10, but thedev->protocol_featureshas a bitmap. I suppose the peer this was tested with also supportedVHOST_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
Signed-off-by Johannes Berg <[email protected]>--- contrib/libvhost-user/libvhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)contrib/libvhost-user/libvhost-user.c +0
-0
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
-0return false; }Signature · 1 line
2.23.0
Tiwei Bie
Reviewed-byQuoted 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_FDis defined to 10, but thedev->protocol_featureshas a bitmap. I suppose the peer this was tested with also supportedVHOST_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 becauseVHOST_USER_PROTOCOL_F_LOG_SHMFDhas 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
Signed-off-by Johannes Berg <[email protected]>--- contrib/libvhost-user/libvhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)contrib/libvhost-user/libvhost-user.c +0
-0@@ -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()andvu_has_feature()called by other code in this file directly. Not sure which one is preferred.. Personally, I thinkvu_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: