vhost-user: sync backend
v3 cover vhost-user: sync backend
To be used on top of:
[PATCH 0/4] vhost-user: protocol updates
https://lists.gnu.org/archive/html/qemu-devel/2015-07/msg03842.html
v2 -> v3:
- Addressed Michael S. Tsirkin's comments:
- Fixed a typo in patch 2/3 message
- MQ - I left it there for completeness,
it will be moved once the "protocol" bits will be 'active'
- unit-test - The bits were added to GET_FEATURES, not GET_PROTOCOL_FEATURES, no need to make any changes
- Added a new patch (1/3) that removes the unnecessary virtio bits related to vhost-user backend.
v1 -> v2:
- Addressed Michael S. Tsirkin's comments:
- Prefer a white-list of supported features
- Add a unit-test to show the problem we are trying to solve (run the unit-test before the patch and it will fail)
Currently the vhost-user supported features are not evaluated.
The way I see it, and please correct me, the best way to do this is to:
1. Get the backend features on vhost init.
2. Check them one by one (white-list) against all the currently supported virtio features.
3. All other code should remain the same.
Marcel Apfelbaum (3):
hw/vhost-user: remove unnecessary virtio control bits hw/vhost-user: sync backend features tests/vhost-user: check vhost-user feature negotiation
hw/net/vhost_net.c | 22 ---------------------- hw/virtio/vhost-user.c | 17 +++++++++++++++++ tests/vhost-user-test.c | 19 ++++++++++++++++--- 3 files changed, 33 insertions(+), 25 deletions(-)
Signature · 1 line
2.1.0
PATCH v3 1/3 hw/vhost-user: remove unnecessary virtio control bits
The backend is interested in negotiating only several virtio bits, remove the others.
--- hw/net/vhost_net.c | 22 ---------------------- 1 file changed, 22 deletions(-)
hw/net/vhost_net.c +0 -22
@@ -59,31 +59,9 @@ static const int kernel_feature_bits[] = {/* Features supported by others. */ static const int user_feature_bits[] = { -VIRTIO_F_NOTIFY_ON_EMPTY , -VIRTIO_RING_F_INDIRECT_DESC , -VIRTIO_RING_F_EVENT_IDX , -VIRTIO_F_ANY_LAYOUT ,VIRTIO_F_VERSION_1 , -VIRTIO_NET_F_CSUM , -VIRTIO_NET_F_GUEST_CSUM , -VIRTIO_NET_F_GSO , -VIRTIO_NET_F_GUEST_TSO4 , -VIRTIO_NET_F_GUEST_TSO6 , -VIRTIO_NET_F_GUEST_ECN , -VIRTIO_NET_F_GUEST_UFO , -VIRTIO_NET_F_HOST_TSO4 , -VIRTIO_NET_F_HOST_TSO6 , -VIRTIO_NET_F_HOST_ECN , -VIRTIO_NET_F_HOST_UFO ,VIRTIO_NET_F_MRG_RXBUF , -VIRTIO_NET_F_STATUS , -VIRTIO_NET_F_CTRL_VQ , -VIRTIO_NET_F_CTRL_RX , -VIRTIO_NET_F_CTRL_VLAN , -VIRTIO_NET_F_CTRL_RX_EXTRA , -VIRTIO_NET_F_CTRL_MAC_ADDR , -VIRTIO_NET_F_CTRL_GUEST_OFFLOADS ,VIRTIO_NET_F_MQ ,
Signature · 1 line
2.1.0
PATCH v3 2/3 hw/vhost-user: sync backend features
In reply to Marcel ApfelbaumComplete vhost-user negotiation by synching the features supported by the backend.
--- hw/virtio/vhost-user.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/virtio/vhost-user.c +17 -0
@@ -22,6 +22,7 @@#include <sys/socket.h> #include <sys/un.h> #include <linux/vhost.h> +#include <linux/virtio_net.h> #define VHOST_MEMORY_MAX_NREGIONS 8
@@ -358,6 +359,22 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)return err; } +if (__virtio_has_feature (msg.u64,VIRTIO_F_ANY_LAYOUT )) { + dev->backend_features |=1ULL <<VIRTIO_F_ANY_LAYOUT ; + } + +if (__virtio_has_feature (msg.u64,VIRTIO_F_VERSION_1 )) { + dev->backend_features |=1ULL <<VIRTIO_F_VERSION_1 ; + } + +if (__virtio_has_feature (msg.u64,VIRTIO_NET_F_MRG_RXBUF )) { + dev->backend_features |=1ULL <<VIRTIO_NET_F_MRG_RXBUF ; + } + +if (__virtio_has_feature (msg.u64,VIRTIO_NET_F_MQ )) { + dev->backend_features |=1ULL <<VIRTIO_NET_F_MQ ; + } +if (__virtio_has_feature (msg.u64,VHOST_USER_F_PROTOCOL_FEATURES )) { dev->backend_features |=1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ;
Signature · 1 line
2.1.0
PATCH v3 3/3 tests/vhost-user: check vhost-user feature negotiation
In reply to Marcel ApfelbaumCheck the backend receives all declared virtio features that are also supported by QEMU virtio.
--- tests/vhost-user-test.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
tests/vhost-user-test.c +16 -3
@@ -17,6 +17,7 @@#include "sysemu/sysemu.h" #include <linux/vhost.h> +#include <linux/virtio_net.h> #include <sys/mman.h> #include <sys/vfs.h> #include <qemu/sockets.h>
@@ -297,14 +298,26 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)/* send back features to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ; msg.size =sizeof (m.u64); - msg.u64 =0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; + msg.u64 = (0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ) | + (0x1ULL <<VIRTIO_F_ANY_LAYOUT ) | + (0x1ULL <<VIRTIO_F_VERSION_1 ) | + (0x1ULL <<VIRTIO_NET_F_MRG_RXBUF ) | + (0x1ULL <<VIRTIO_NET_F_MQ ); p = (uint8_t *) &msg;qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size);break ;case VHOST_USER_SET_FEATURES : -g_assert_cmpint (msg.u64 & (0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ), - !=, 0ULL); +g_assert_cmpint (msg.u64 & (0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ), + !=, 0ULL); +g_assert_cmpint (msg.u64 & (0x1ULL <<VIRTIO_F_ANY_LAYOUT ), + !=, 0ULL); +g_assert_cmpint (msg.u64 & (0x1ULL <<VIRTIO_F_VERSION_1 ), + !=, 0ULL); +g_assert_cmpint (msg.u64 & (0x1ULL <<VIRTIO_NET_F_MRG_RXBUF ), + !=, 0ULL); +g_assert_cmpint (msg.u64 & (0x1ULL <<VIRTIO_NET_F_MQ ), + !=, 0ULL);break ;case VHOST_USER_GET_PROTOCOL_FEATURES :
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V3 1/3] hw/vhost-user: remove unnecessary virtio control bits
In reply to Marcel ApfelbaumQuoted 35 lines · Marcel Apfelbaum
The backend is interested in negotiating only several virtio bits, remove the others.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/net/vhost_net.c | 22 ---------------------- 1 file changed, 22 deletions(-)hw/net/vhost_net.c +0
-15@@ -59,31 +59,9 @@ static const int kernel_feature_bits[] = {/* Features supported by others. */ static const int user_feature_bits[] = { -VIRTIO_F_NOTIFY_ON_EMPTY , -VIRTIO_RING_F_INDIRECT_DESC , -VIRTIO_RING_F_EVENT_IDX , -VIRTIO_F_ANY_LAYOUT ,VIRTIO_F_VERSION_1 , -VIRTIO_NET_F_CSUM , -VIRTIO_NET_F_GUEST_CSUM , -VIRTIO_NET_F_GSO , -VIRTIO_NET_F_GUEST_TSO4 , -VIRTIO_NET_F_GUEST_TSO6 , -VIRTIO_NET_F_GUEST_ECN , -VIRTIO_NET_F_GUEST_UFO , -VIRTIO_NET_F_HOST_TSO4 , -VIRTIO_NET_F_HOST_TSO6 , -VIRTIO_NET_F_HOST_ECN , -VIRTIO_NET_F_HOST_UFO ,VIRTIO_NET_F_MRG_RXBUF ,
hw/net/vhost_net.c static const int kernel_feature_bits[] = { · line 67
Quoted 10 lines
hw/net/vhost_net.c +0
-7-VIRTIO_NET_F_STATUS , -VIRTIO_NET_F_CTRL_VQ , -VIRTIO_NET_F_CTRL_RX , -VIRTIO_NET_F_CTRL_VLAN , -VIRTIO_NET_F_CTRL_RX_EXTRA , -VIRTIO_NET_F_CTRL_MAC_ADDR , -VIRTIO_NET_F_CTRL_GUEST_OFFLOADS , VIRTIO_NET_F_MQ,
Hi,
Please do not take this patch, I think that some bits I deleted are still required by the backend.
The others are OK in my opinion (at least until we change the MQ handshake) Thanks,
Marcel