* Re: [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case
2023-08-10 3:15 [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case Hawkins Jiawei
@ 2023-08-10 4:12 ` Jason Wang
2023-08-10 8:44 ` Eugenio Perez Martin
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2023-08-10 4:12 UTC (permalink / raw)
To: Hawkins Jiawei
Cc: Michael S. Tsirkin, Xuan Zhuo, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, eperezma, 18801353760,
virtualization, netdev, linux-kernel
On Thu, Aug 10, 2023 at 11:16 AM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> Kernel uses `struct virtio_net_ctrl_rss` to save command-specific-data
> for both the VIRTIO_NET_CTRL_MQ_HASH_CONFIG and
> VIRTIO_NET_CTRL_MQ_RSS_CONFIG commands.
This is tricky.
>
> According to the VirtIO standard, "Field reserved MUST contain zeroes.
> It is defined to make the structure to match the layout of
> virtio_net_rss_config structure, defined in 5.1.6.5.7.".
>
> Yet for the VIRTIO_NET_CTRL_MQ_HASH_CONFIG command case, the `max_tx_vq`
> field in struct virtio_net_ctrl_rss, which corresponds to the
> `reserved` field in struct virtio_net_hash_config, is not zeroed,
> thereby violating the VirtIO standard.
>
> This patch solves this problem by zeroing this field in
> virtnet_init_default_rss().
>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> ---
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case
2023-08-10 3:15 [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case Hawkins Jiawei
2023-08-10 4:12 ` Jason Wang
@ 2023-08-10 8:44 ` Eugenio Perez Martin
2023-08-10 8:49 ` Michael S. Tsirkin
2023-08-10 8:51 ` Michael S. Tsirkin
3 siblings, 0 replies; 6+ messages in thread
From: Eugenio Perez Martin @ 2023-08-10 8:44 UTC (permalink / raw)
To: Hawkins Jiawei
Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, 18801353760,
virtualization, netdev, linux-kernel
On Thu, Aug 10, 2023 at 5:16 AM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> Kernel uses `struct virtio_net_ctrl_rss` to save command-specific-data
> for both the VIRTIO_NET_CTRL_MQ_HASH_CONFIG and
> VIRTIO_NET_CTRL_MQ_RSS_CONFIG commands.
>
> According to the VirtIO standard, "Field reserved MUST contain zeroes.
> It is defined to make the structure to match the layout of
> virtio_net_rss_config structure, defined in 5.1.6.5.7.".
>
> Yet for the VIRTIO_NET_CTRL_MQ_HASH_CONFIG command case, the `max_tx_vq`
> field in struct virtio_net_ctrl_rss, which corresponds to the
> `reserved` field in struct virtio_net_hash_config, is not zeroed,
> thereby violating the VirtIO standard.
>
> This patch solves this problem by zeroing this field in
> virtnet_init_default_rss().
>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Acked-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>
> TestStep
> ========
> 1. Boot QEMU with one virtio-net-pci net device with `mq` and `hash`
> feature on, command line like:
> -netdev tap,vhost=off,...
> -device virtio-net-pci,mq=on,hash=on,...
>
> 2. Trigger VIRTIO_NET_CTRL_MQ_HASH_CONFIG command in guest, command
> line like:
> ethtool -K eth0 rxhash on
>
> Without this patch, in virtnet_commit_rss_command(), we can see the
> `max_tx_vq` field is 1 in gdb like below:
>
> pwndbg> p vi->ctrl->rss
> $1 = {
> hash_types = 63,
> indirection_table_mask = 0,
> unclassified_queue = 0,
> indirection_table = {0 <repeats 128 times>},
> max_tx_vq = 1,
> hash_key_length = 40 '(',
> ...
> }
>
> With this patch, in virtnet_commit_rss_command(), we can see the
> `max_tx_vq` field is 0 in gdb like below:
>
> pwndbg> p vi->ctrl->rss
> $1 = {
> hash_types = 63,
> indirection_table_mask = 0,
> unclassified_queue = 0,
> indirection_table = {0 <repeats 128 times>},
> max_tx_vq = 0,
> hash_key_length = 40 '(',
> ...
> }
>
> drivers/net/virtio_net.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 1270c8d23463..8db38634ae82 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2761,7 +2761,7 @@ static void virtnet_init_default_rss(struct virtnet_info *vi)
> vi->ctrl->rss.indirection_table[i] = indir_val;
> }
>
> - vi->ctrl->rss.max_tx_vq = vi->curr_queue_pairs;
> + vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0;
> vi->ctrl->rss.hash_key_length = vi->rss_key_size;
>
> netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case
2023-08-10 3:15 [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case Hawkins Jiawei
2023-08-10 4:12 ` Jason Wang
2023-08-10 8:44 ` Eugenio Perez Martin
@ 2023-08-10 8:49 ` Michael S. Tsirkin
2023-08-10 8:51 ` Michael S. Tsirkin
3 siblings, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2023-08-10 8:49 UTC (permalink / raw)
To: Hawkins Jiawei
Cc: Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, eperezma, 18801353760,
virtualization, netdev, linux-kernel
On Thu, Aug 10, 2023 at 11:15:57AM +0800, Hawkins Jiawei wrote:
> Kernel uses `struct virtio_net_ctrl_rss` to save command-specific-data
> for both the VIRTIO_NET_CTRL_MQ_HASH_CONFIG and
> VIRTIO_NET_CTRL_MQ_RSS_CONFIG commands.
>
> According to the VirtIO standard, "Field reserved MUST contain zeroes.
> It is defined to make the structure to match the layout of
> virtio_net_rss_config structure, defined in 5.1.6.5.7.".
>
> Yet for the VIRTIO_NET_CTRL_MQ_HASH_CONFIG command case, the `max_tx_vq`
> field in struct virtio_net_ctrl_rss, which corresponds to the
> `reserved` field in struct virtio_net_hash_config, is not zeroed,
> thereby violating the VirtIO standard.
>
> This patch solves this problem by zeroing this field in
> virtnet_init_default_rss().
>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> ---
>
> TestStep
> ========
> 1. Boot QEMU with one virtio-net-pci net device with `mq` and `hash`
> feature on, command line like:
> -netdev tap,vhost=off,...
> -device virtio-net-pci,mq=on,hash=on,...
>
> 2. Trigger VIRTIO_NET_CTRL_MQ_HASH_CONFIG command in guest, command
> line like:
> ethtool -K eth0 rxhash on
>
> Without this patch, in virtnet_commit_rss_command(), we can see the
> `max_tx_vq` field is 1 in gdb like below:
>
> pwndbg> p vi->ctrl->rss
> $1 = {
> hash_types = 63,
> indirection_table_mask = 0,
> unclassified_queue = 0,
> indirection_table = {0 <repeats 128 times>},
> max_tx_vq = 1,
> hash_key_length = 40 '(',
> ...
> }
>
> With this patch, in virtnet_commit_rss_command(), we can see the
> `max_tx_vq` field is 0 in gdb like below:
>
> pwndbg> p vi->ctrl->rss
> $1 = {
> hash_types = 63,
> indirection_table_mask = 0,
> unclassified_queue = 0,
> indirection_table = {0 <repeats 128 times>},
> max_tx_vq = 0,
> hash_key_length = 40 '(',
> ...
> }
>
> drivers/net/virtio_net.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Fixes tag pls?
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 1270c8d23463..8db38634ae82 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2761,7 +2761,7 @@ static void virtnet_init_default_rss(struct virtnet_info *vi)
> vi->ctrl->rss.indirection_table[i] = indir_val;
> }
>
> - vi->ctrl->rss.max_tx_vq = vi->curr_queue_pairs;
> + vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0;
> vi->ctrl->rss.hash_key_length = vi->rss_key_size;
>
> netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size);
> --
> 2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case
2023-08-10 3:15 [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case Hawkins Jiawei
` (2 preceding siblings ...)
2023-08-10 8:49 ` Michael S. Tsirkin
@ 2023-08-10 8:51 ` Michael S. Tsirkin
2023-08-10 10:41 ` Hawkins Jiawei
3 siblings, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2023-08-10 8:51 UTC (permalink / raw)
To: Hawkins Jiawei
Cc: Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, eperezma, 18801353760,
virtualization, netdev, linux-kernel
On Thu, Aug 10, 2023 at 11:15:57AM +0800, Hawkins Jiawei wrote:
> Kernel uses `struct virtio_net_ctrl_rss` to save command-specific-data
> for both the VIRTIO_NET_CTRL_MQ_HASH_CONFIG and
> VIRTIO_NET_CTRL_MQ_RSS_CONFIG commands.
>
> According to the VirtIO standard, "Field reserved MUST contain zeroes.
> It is defined to make the structure to match the layout of
> virtio_net_rss_config structure, defined in 5.1.6.5.7.".
>
> Yet for the VIRTIO_NET_CTRL_MQ_HASH_CONFIG command case, the `max_tx_vq`
> field in struct virtio_net_ctrl_rss, which corresponds to the
> `reserved` field in struct virtio_net_hash_config, is not zeroed,
> thereby violating the VirtIO standard.
>
> This patch solves this problem by zeroing this field in
> virtnet_init_default_rss().
>
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Fixes: c7114b1249fa ("drivers/net/virtio_net: Added basic RSS support.")
Cc: Andrew Melnychenko <andrew@daynix.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
And this is stable material I believe.
> ---
>
> TestStep
> ========
> 1. Boot QEMU with one virtio-net-pci net device with `mq` and `hash`
> feature on, command line like:
> -netdev tap,vhost=off,...
> -device virtio-net-pci,mq=on,hash=on,...
>
> 2. Trigger VIRTIO_NET_CTRL_MQ_HASH_CONFIG command in guest, command
> line like:
> ethtool -K eth0 rxhash on
>
> Without this patch, in virtnet_commit_rss_command(), we can see the
> `max_tx_vq` field is 1 in gdb like below:
>
> pwndbg> p vi->ctrl->rss
> $1 = {
> hash_types = 63,
> indirection_table_mask = 0,
> unclassified_queue = 0,
> indirection_table = {0 <repeats 128 times>},
> max_tx_vq = 1,
> hash_key_length = 40 '(',
> ...
> }
>
> With this patch, in virtnet_commit_rss_command(), we can see the
> `max_tx_vq` field is 0 in gdb like below:
>
> pwndbg> p vi->ctrl->rss
> $1 = {
> hash_types = 63,
> indirection_table_mask = 0,
> unclassified_queue = 0,
> indirection_table = {0 <repeats 128 times>},
> max_tx_vq = 0,
> hash_key_length = 40 '(',
> ...
> }
>
> drivers/net/virtio_net.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 1270c8d23463..8db38634ae82 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2761,7 +2761,7 @@ static void virtnet_init_default_rss(struct virtnet_info *vi)
> vi->ctrl->rss.indirection_table[i] = indir_val;
> }
>
> - vi->ctrl->rss.max_tx_vq = vi->curr_queue_pairs;
> + vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0;
> vi->ctrl->rss.hash_key_length = vi->rss_key_size;
>
> netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size);
> --
> 2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] virtio-net: Zero max_tx_vq field for VIRTIO_NET_CTRL_MQ_HASH_CONFIG case
2023-08-10 8:51 ` Michael S. Tsirkin
@ 2023-08-10 10:41 ` Hawkins Jiawei
0 siblings, 0 replies; 6+ messages in thread
From: Hawkins Jiawei @ 2023-08-10 10:41 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, eperezma, 18801353760,
virtualization, netdev, linux-kernel
On 2023/8/10 16:51, Michael S. Tsirkin wrote:
> On Thu, Aug 10, 2023 at 11:15:57AM +0800, Hawkins Jiawei wrote:
>> Kernel uses `struct virtio_net_ctrl_rss` to save command-specific-data
>> for both the VIRTIO_NET_CTRL_MQ_HASH_CONFIG and
>> VIRTIO_NET_CTRL_MQ_RSS_CONFIG commands.
>>
>> According to the VirtIO standard, "Field reserved MUST contain zeroes.
>> It is defined to make the structure to match the layout of
>> virtio_net_rss_config structure, defined in 5.1.6.5.7.".
>>
>> Yet for the VIRTIO_NET_CTRL_MQ_HASH_CONFIG command case, the `max_tx_vq`
>> field in struct virtio_net_ctrl_rss, which corresponds to the
>> `reserved` field in struct virtio_net_hash_config, is not zeroed,
>> thereby violating the VirtIO standard.
>>
>> This patch solves this problem by zeroing this field in
>> virtnet_init_default_rss().
>>
>> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
>
>
>
> Fixes: c7114b1249fa ("drivers/net/virtio_net: Added basic RSS support.")
> Cc: Andrew Melnychenko <andrew@daynix.com>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>
> And this is stable material I believe.
Hi Michael,
Thank you for the reminder, I will send the v2 patch with all these tags
included.
Thanks!
>
>
>
>> ---
>>
>> TestStep
>> ========
>> 1. Boot QEMU with one virtio-net-pci net device with `mq` and `hash`
>> feature on, command line like:
>> -netdev tap,vhost=off,...
>> -device virtio-net-pci,mq=on,hash=on,...
>>
>> 2. Trigger VIRTIO_NET_CTRL_MQ_HASH_CONFIG command in guest, command
>> line like:
>> ethtool -K eth0 rxhash on
>>
>> Without this patch, in virtnet_commit_rss_command(), we can see the
>> `max_tx_vq` field is 1 in gdb like below:
>>
>> pwndbg> p vi->ctrl->rss
>> $1 = {
>> hash_types = 63,
>> indirection_table_mask = 0,
>> unclassified_queue = 0,
>> indirection_table = {0 <repeats 128 times>},
>> max_tx_vq = 1,
>> hash_key_length = 40 '(',
>> ...
>> }
>>
>> With this patch, in virtnet_commit_rss_command(), we can see the
>> `max_tx_vq` field is 0 in gdb like below:
>>
>> pwndbg> p vi->ctrl->rss
>> $1 = {
>> hash_types = 63,
>> indirection_table_mask = 0,
>> unclassified_queue = 0,
>> indirection_table = {0 <repeats 128 times>},
>> max_tx_vq = 0,
>> hash_key_length = 40 '(',
>> ...
>> }
>>
>> drivers/net/virtio_net.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
>> index 1270c8d23463..8db38634ae82 100644
>> --- a/drivers/net/virtio_net.c
>> +++ b/drivers/net/virtio_net.c
>> @@ -2761,7 +2761,7 @@ static void virtnet_init_default_rss(struct virtnet_info *vi)
>> vi->ctrl->rss.indirection_table[i] = indir_val;
>> }
>>
>> - vi->ctrl->rss.max_tx_vq = vi->curr_queue_pairs;
>> + vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0;
>> vi->ctrl->rss.hash_key_length = vi->rss_key_size;
>>
>> netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size);
>> --
>> 2.34.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread