Vhost-vdpa Shadow Virtqueue _F_CTRL_RX commands support
cover Vhost-vdpa Shadow Virtqueue _F_CTRL_RX commands support
This series enables shadowed CVQ to intercept rx commands related to VIRTIO_NET_F_CTRL_RX feature through shadowed CVQ, update the virtio NIC device model so qemu send it in a migration, and the restore of that rx state in the destination.
Note that this patch should be based on [1], and conflicts [2], which have not been merged. I will submit the v2 patch after they are merged.
[1]. https://lore.kernel.org/all/[email protected]/
[2]. https://lore.kernel.org/all/[email protected]/
Hawkins Jiawei (3):
vdpa: Restore MAC address filtering state
vdpa: Restore packet receive filtering state relative with _F_CTRL_RX
feature
vdpa: Allow VIRTIO_NET_F_CTRL_RX in SVQ
net/vhost-vdpa.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
RFC PATCH 2/3 vdpa: Restore packet receive filtering state relative with _F_CTRL_RX feature
This patch introduces vhost_vdpa_net_load_rx_mode() and vhost_vdpa_net_load_rx() to restore the packet receive filtering state in relation to VIRTIO_NET_F_CTRL_RX feature at device's startup.
--- net/vhost-vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
net/vhost-vdpa.c +74 -0
@@ -754,6 +754,76 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,return *s->status !=VIRTIO_NET_OK ; } +static int vhost_vdpa_net_load_rx_mode (VhostVDPAState *s, +uint8_t cmd, +uint8_t on) +{ +ssize_t dev_written; + dev_written =vhost_vdpa_net_load_cmd (s,VIRTIO_NET_CTRL_RX , + cmd, &on,sizeof (on)); +if (unlikely (dev_written <0 )) { +return dev_written; + } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + } + +return 0 ; +} + +static int vhost_vdpa_net_load_rx (VhostVDPAState *s, +const VirtIONet *n) +{ +uint8_t on; +int r; + +if (virtio_vdev_has_feature (&n->parent_obj,VIRTIO_NET_F_CTRL_RX )) { +/* Load the promiscous mode */ +if (n->mac_table.uni_overflow) { +/* +* According to VirtIO standard, "Since there are no guarantees, +* it can use a hash filter or silently switch to +* allmulti or promiscuous mode if it is given too many addresses." +* +* QEMU ignores non-multicast(unicast) MAC addresses and +* marks `uni_overflow` for the device internal state +* if guest sets too many non-multicast(unicast) MAC addresses. +* Therefore, we should turn promiscous mode on in this case. +*/ + on =1 ; + }else { + on = n->promisc; + } + r =vhost_vdpa_net_load_rx_mode (s,VIRTIO_NET_CTRL_RX_PROMISC , on); +if (r <0 ) { +return r; + } + +/* Load the all-multicast mode */ +if (n->mac_table.multi_overflow) { +/* +* According to VirtIO standard, "Since there are no guarantees, +* it can use a hash filter or silently switch to +* allmulti or promiscuous mode if it is given too many addresses." +* +* QEMU ignores multicast MAC addresses and +* marks `multi_overflow` for the device internal state +* if guest sets too many multicast MAC addresses. +* Therefore, we should turn all-multicast mode on in this case. +*/ + on =1 ; + }else { + on = n->allmulti; + } + r =vhost_vdpa_net_load_rx_mode (s,VIRTIO_NET_CTRL_RX_ALLMULTI , on); +if (r <0 ) { +return r; + } + } + +return 0 ; +} +static int vhost_vdpa_net_load (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc);
@@ -780,6 +850,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)if (unlikely (r)) {return r; } + r =vhost_vdpa_net_load_rx (s, n); +if (unlikely (r)) { +return r; + }return 0 ; }
Signature · 1 line
2.25.1
RFC PATCH 1/3 vdpa: Restore MAC address filtering state
In reply to Hawkins JiaweiThis patch refactors vhost_vdpa_net_load_mac() to restore the MAC address filtering state at device's startup.
--- net/vhost-vdpa.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
net/vhost-vdpa.c +38 -1
@@ -651,8 +651,45 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)if (unlikely (dev_written <0 )) {return dev_written; } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + } + } + +if (virtio_vdev_has_feature (&n->parent_obj,VIRTIO_NET_F_CTRL_RX )) { +/* Load the MAC address filtering */ +uint32_t uni_entries = n->mac_table.first_multi, + uni_macs_size = uni_entries *ETH_ALEN , + uni_size =sizeof (struct virtio_net_ctrl_mac ) + uni_macs_size, + mul_entries = n->mac_table.in_use - uni_entries, + mul_macs_size = mul_entries *ETH_ALEN , + mul_size =sizeof (struct virtio_net_ctrl_mac ) + mul_macs_size, + data_size = uni_size + mul_size; +void *data =g_malloc (data_size); +struct virtio_net_ctrl_mac *ctrl_mac; + +/* Pack the non-multicast(unicast) MAC addresses */ + ctrl_mac = data; + ctrl_mac->entries =cpu_to_le32 (uni_entries); +memcpy (ctrl_mac->macs, n->mac_table.macs, uni_macs_size); + +/* Pack the multicast MAC addresses */ + ctrl_mac = data + uni_size; + ctrl_mac->entries =cpu_to_le32 (mul_entries); +memcpy (ctrl_mac->macs, &n->mac_table.macs[uni_macs_size], + mul_macs_size); + +ssize_t dev_written =vhost_vdpa_net_load_cmd (s,VIRTIO_NET_CTRL_MAC , +VIRTIO_NET_CTRL_MAC_TABLE_SET , + data, data_size); +g_free (data); -return *s->status !=VIRTIO_NET_OK ; +if (unlikely (dev_written <0 )) { +return dev_written; + } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + } }return 0 ;
Signature · 1 line
2.25.1
RFC PATCH 3/3 vdpa: Allow VIRTIO_NET_F_CTRL_RX in SVQ
In reply to Hawkins JiaweiEnable SVQ with VIRTIO_NET_F_CTRL_RX feature.
--- net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+)
net/vhost-vdpa.c +1 -0
@@ -99,6 +99,7 @@ static const uint64_t vdpa_svq_device_features =BIT_ULL (VIRTIO_NET_F_MRG_RXBUF ) |BIT_ULL (VIRTIO_NET_F_STATUS ) |BIT_ULL (VIRTIO_NET_F_CTRL_VQ ) | +BIT_ULL (VIRTIO_NET_F_CTRL_RX ) |BIT_ULL (VIRTIO_NET_F_MQ ) |BIT_ULL (VIRTIO_F_ANY_LAYOUT ) | BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) |
Signature · 1 line
2.25.1
Re: [PATCH RFC 1/3] vdpa: Restore MAC address filtering state
In reply to Hawkins JiaweiQuoted 14 lines · Hawkins Jiawei
This patch refactors
vhost_vdpa_net_load_mac()to restore the MAC address filtering state at device's startup.Signed-off-by Hawkins Jiawei <[email protected]>--- net/vhost-vdpa.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) · line 656
Quoted 6 lines
net/vhost-vdpa.c +3
-0@@ -651,8 +651,45 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)if (unlikely (dev_written <0 )) {return dev_written; } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + }
I think this part should go in its individual patch, explaining why it is needed and with corresponding Fixes tag.
net/vhost-vdpa.c static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) · line 668
Quoted 12 lines
net/vhost-vdpa.c +12
-0+ } + +if (virtio_vdev_has_feature (&n->parent_obj,VIRTIO_NET_F_CTRL_RX )) { +/* Load the MAC address filtering */ +uint32_t uni_entries = n->mac_table.first_multi, + uni_macs_size = uni_entries *ETH_ALEN , + uni_size =sizeof (struct virtio_net_ctrl_mac ) + uni_macs_size, + mul_entries = n->mac_table.in_use - uni_entries, + mul_macs_size = mul_entries *ETH_ALEN , + mul_size =sizeof (struct virtio_net_ctrl_mac ) + mul_macs_size, + data_size = uni_size + mul_size; +void *data =g_malloc (data_size);
If we keep this part, please use g_autofree here [1].
But I think it is not worth copying all the data actually. Maybe it is worth it to convert vhost_vdpa_net_load_cmd to const iovec?
Thanks!
[1] https://www.qemu.org/docs/master/devel/style#automatic-memory-deallocation
Quoted 31 lines
net/vhost-vdpa.c +23
-2+struct virtio_net_ctrl_mac *ctrl_mac; + +/* Pack the non-multicast(unicast) MAC addresses */ + ctrl_mac = data; + ctrl_mac->entries =cpu_to_le32 (uni_entries); +memcpy (ctrl_mac->macs, n->mac_table.macs, uni_macs_size); + +/* Pack the multicast MAC addresses */ + ctrl_mac = data + uni_size; + ctrl_mac->entries =cpu_to_le32 (mul_entries); +memcpy (ctrl_mac->macs, &n->mac_table.macs[uni_macs_size], + mul_macs_size); + +ssize_t dev_written =vhost_vdpa_net_load_cmd (s,VIRTIO_NET_CTRL_MAC , +VIRTIO_NET_CTRL_MAC_TABLE_SET , + data, data_size); +g_free (data); -return *s->status !=VIRTIO_NET_OK ; +if (unlikely (dev_written <0 )) { +return dev_written; + } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + } }return 0 ; --2.25.1
Re: [PATCH RFC 3/3] vdpa: Allow VIRTIO_NET_F_CTRL_RX in SVQ
In reply to Hawkins JiaweiQuoted 4 lines · Hawkins Jiawei
Enable SVQ with
VIRTIO_NET_F_CTRL_RXfeature.Signed-off-by Hawkins Jiawei <[email protected]>
Quoted 19 lines
--- net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+)net/vhost-vdpa.c +1
-1@@ -99,6 +99,7 @@ static const uint64_t vdpa_svq_device_features =BIT_ULL (VIRTIO_NET_F_MRG_RXBUF ) |BIT_ULL (VIRTIO_NET_F_STATUS ) |BIT_ULL (VIRTIO_NET_F_CTRL_VQ ) | +BIT_ULL (VIRTIO_NET_F_CTRL_RX ) |BIT_ULL (VIRTIO_NET_F_MQ ) |BIT_ULL (VIRTIO_F_ANY_LAYOUT ) | BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | --2.25.1
Re: [PATCH RFC 2/3] vdpa: Restore packet receive filtering state relative with _F_CTRL_RX feature
In reply to Hawkins JiaweiQuoted 74 lines · Hawkins Jiawei
This patch introduces
vhost_vdpa_net_load_rx_mode()andvhost_vdpa_net_load_rx()to restore the packet receive filtering state in relation toVIRTIO_NET_F_CTRL_RXfeature at device's startup.Signed-off-by Hawkins Jiawei <[email protected]>--- net/vhost-vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)net/vhost-vdpa.c +55
-0@@ -754,6 +754,76 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,return *s->status !=VIRTIO_NET_OK ; } +static int vhost_vdpa_net_load_rx_mode (VhostVDPAState *s, +uint8_t cmd, +uint8_t on) +{ +ssize_t dev_written; + dev_written =vhost_vdpa_net_load_cmd (s,VIRTIO_NET_CTRL_RX , + cmd, &on,sizeof (on)); +if (unlikely (dev_written <0 )) { +return dev_written; + } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + } + +return 0 ; +} + +static int vhost_vdpa_net_load_rx (VhostVDPAState *s, +const VirtIONet *n) +{ +uint8_t on; +int r; + +if (virtio_vdev_has_feature (&n->parent_obj,VIRTIO_NET_F_CTRL_RX )) { +/* Load the promiscous mode */ +if (n->mac_table.uni_overflow) { +/* +* According to VirtIO standard, "Since there are no guarantees, +* it can use a hash filter or silently switch to +* allmulti or promiscuous mode if it is given too many addresses." +* +* QEMU ignores non-multicast(unicast) MAC addresses and +* marks `uni_overflow` for the device internal state +* if guest sets too many non-multicast(unicast) MAC addresses. +* Therefore, we should turn promiscous mode on in this case. +*/ + on =1 ; + }else { + on = n->promisc; + } + r =vhost_vdpa_net_load_rx_mode (s,VIRTIO_NET_CTRL_RX_PROMISC , on); +if (r <0 ) { +return r; + } + +/* Load the all-multicast mode */ +if (n->mac_table.multi_overflow) { +/* +* According to VirtIO standard, "Since there are no guarantees, +* it can use a hash filter or silently switch to +* allmulti or promiscuous mode if it is given too many addresses." +* +* QEMU ignores multicast MAC addresses and +* marks `multi_overflow` for the device internal state +* if guest sets too many multicast MAC addresses.
net/vhost-vdpa.c static int vhost_vdpa_net_load_offloads(VhostVDPAState *s, · line 821
Quoted 10 lines
net/vhost-vdpa.c +10
-0+* Therefore, we should turn all-multicast mode on in this case. +*/ + on =1 ; + }else { + on = n->allmulti; + } + r =vhost_vdpa_net_load_rx_mode (s,VIRTIO_NET_CTRL_RX_ALLMULTI , on); +if (r <0 ) { +return r; + }
Can we skip the sending of the CVQ commands if the state matches the default state?
Thanks!
Quoted 22 lines
net/vhost-vdpa.c +9
-1+ } + +return 0 ; +} +static int vhost_vdpa_net_load (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc);@@ -780,6 +850,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)if (unlikely (r)) {return r; } + r =vhost_vdpa_net_load_rx (s, n); +if (unlikely (r)) { +return r; + }return 0 ; } --2.25.1
Re: [PATCH RFC 1/3] vdpa: Restore MAC address filtering state
In reply to Eugenio Perez MartinQuoted 10 lines · Eugenio Perez Martin
Quoted 9 lines · Hawkins Jiawei
This patch refactors
vhost_vdpa_net_load_mac()to restore the MAC address filtering state at device's startup.Signed-off-by Hawkins Jiawei <[email protected]>--- net/vhost-vdpa.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
Quoted 14 lines
net/vhost-vdpa.c static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) · line 656
Quoted 11 lines
net/vhost-vdpa.c +3
-0@@ -651,8 +651,45 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)if (unlikely (dev_written <0 )) {return dev_written; } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + }I think this part should go in its individual patch, explaining why it is needed and with corresponding Fixes tag.
Yes, you are right. And I have already submitted that patch "Return -EINVAL if device's ack is VIRTIO_NET_ERR" at [1], as mentioned in the cover letter for this series at [2].
[1]. https://lore.kernel.org/all/[email protected]/#t
[2]. https://lore.kernel.org/all/[email protected]/
Quoted 14 lines
net/vhost-vdpa.c static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) · line 668
Quoted 13 lines
net/vhost-vdpa.c +12
-0+ } + +if (virtio_vdev_has_feature (&n->parent_obj,VIRTIO_NET_F_CTRL_RX )) { +/* Load the MAC address filtering */ +uint32_t uni_entries = n->mac_table.first_multi, + uni_macs_size = uni_entries *ETH_ALEN , + uni_size =sizeof (struct virtio_net_ctrl_mac ) + uni_macs_size, + mul_entries = n->mac_table.in_use - uni_entries, + mul_macs_size = mul_entries *ETH_ALEN , + mul_size =sizeof (struct virtio_net_ctrl_mac ) + mul_macs_size, + data_size = uni_size + mul_size; +void *data =g_malloc (data_size);
Quoted 4 lines
If we keep this part, please use
g_autofreehere [1].But I think it is not worth copying all the data actually. Maybe it is worth it to convert
vhost_vdpa_net_load_cmdto const iovec?
Yes, you are right. I will try to add a helper function in the v2 patch as you have suggested.
Thanks!
Quoted 37 lines
Thanks!
[1] https://www.qemu.org/docs/master/devel/style#automatic-memory-deallocation
Quoted 31 lines
net/vhost-vdpa.c +23
-2+struct virtio_net_ctrl_mac *ctrl_mac; + +/* Pack the non-multicast(unicast) MAC addresses */ + ctrl_mac = data; + ctrl_mac->entries =cpu_to_le32 (uni_entries); +memcpy (ctrl_mac->macs, n->mac_table.macs, uni_macs_size); + +/* Pack the multicast MAC addresses */ + ctrl_mac = data + uni_size; + ctrl_mac->entries =cpu_to_le32 (mul_entries); +memcpy (ctrl_mac->macs, &n->mac_table.macs[uni_macs_size], + mul_macs_size); + +ssize_t dev_written =vhost_vdpa_net_load_cmd (s,VIRTIO_NET_CTRL_MAC , +VIRTIO_NET_CTRL_MAC_TABLE_SET , + data, data_size); +g_free (data); -return *s->status !=VIRTIO_NET_OK ; +if (unlikely (dev_written <0 )) { +return dev_written; + } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + } }return 0 ; --2.25.1
Re: [PATCH RFC 2/3] vdpa: Restore packet receive filtering state relative with _F_CTRL_RX feature
In reply to Eugenio Perez MartinQuoted 80 lines · Eugenio Perez Martin
Quoted 79 lines · Hawkins Jiawei
This patch introduces
vhost_vdpa_net_load_rx_mode()andvhost_vdpa_net_load_rx()to restore the packet receive filtering state in relation toVIRTIO_NET_F_CTRL_RXfeature at device's startup.Signed-off-by Hawkins Jiawei <[email protected]>--- net/vhost-vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)net/vhost-vdpa.c +60
-0@@ -754,6 +754,76 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,return *s->status !=VIRTIO_NET_OK ; } +static int vhost_vdpa_net_load_rx_mode (VhostVDPAState *s, +uint8_t cmd, +uint8_t on) +{ +ssize_t dev_written; + dev_written =vhost_vdpa_net_load_cmd (s,VIRTIO_NET_CTRL_RX , + cmd, &on,sizeof (on)); +if (unlikely (dev_written <0 )) { +return dev_written; + } +if (*s->status !=VIRTIO_NET_OK ) { +return -EINVAL ; + } + +return 0 ; +} + +static int vhost_vdpa_net_load_rx (VhostVDPAState *s, +const VirtIONet *n) +{ +uint8_t on; +int r; + +if (virtio_vdev_has_feature (&n->parent_obj,VIRTIO_NET_F_CTRL_RX )) { +/* Load the promiscous mode */ +if (n->mac_table.uni_overflow) { +/* +* According to VirtIO standard, "Since there are no guarantees, +* it can use a hash filter or silently switch to +* allmulti or promiscuous mode if it is given too many addresses." +* +* QEMU ignores non-multicast(unicast) MAC addresses and +* marks `uni_overflow` for the device internal state +* if guest sets too many non-multicast(unicast) MAC addresses. +* Therefore, we should turn promiscous mode on in this case. +*/ + on =1 ; + }else { + on = n->promisc; + } + r =vhost_vdpa_net_load_rx_mode (s,VIRTIO_NET_CTRL_RX_PROMISC , on); +if (r <0 ) { +return r; + } + +/* Load the all-multicast mode */ +if (n->mac_table.multi_overflow) { +/* +* According to VirtIO standard, "Since there are no guarantees, +* it can use a hash filter or silently switch to +* allmulti or promiscuous mode if it is given too many addresses." +* +* QEMU ignores multicast MAC addresses and +* marks `multi_overflow` for the device internal state +* if guest sets too many multicast MAC addresses. +* Therefore, we should turn all-multicast mode on in this case. +*/ + on =1 ; + }else { + on = n->allmulti;
Quoted 8 lines
net/vhost-vdpa.c static int vhost_vdpa_net_load_offloads(VhostVDPAState *s, · line 821
Quoted 5 lines
net/vhost-vdpa.c +5
-0+ } + r =vhost_vdpa_net_load_rx_mode (s,VIRTIO_NET_CTRL_RX_ALLMULTI , on); +if (r <0 ) { +return r; + }Can we skip the sending of the CVQ commands if the state matches the default state?
Thanks for your reminder, I forgot this part when coding. I will refactor the patch according to your suggestion and take care of it in the following patches for this part.
Thanks!
Quoted 26 lines
Thanks!
Quoted 22 lines
net/vhost-vdpa.c +9
-1+ } + +return 0 ; +} +static int vhost_vdpa_net_load (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc);@@ -780,6 +850,10 @@ static int vhost_vdpa_net_load(NetClientState *nc)if (unlikely (r)) {return r; } + r =vhost_vdpa_net_load_rx (s, n); +if (unlikely (r)) { +return r; + }return 0 ; } --2.25.1