From: Carlos Bilbao <cbilbao@digitalocean.com>
Initialize the speed and duplex fields in virtio_net_config to UNKNOWN.
This is needed because mlx5_vdpa vDPA devices currently do not support the
VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex. Add
needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.
Signed-off-by: Carlos Bilbao <cbilbao@digitalocean.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index b56aae3f7be3..41ca268d43ff 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
}
+static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
+{
+ return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
{
if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
@@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
init_rwsem(&ndev->reslock);
config = &ndev->config;
+ /*
+ * mlx5_vdpa vDPA devices currently don't support reporting or
+ * setting the speed or duplex.
+ */
+ config->speed = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
+ config->duplex = DUPLEX_UNKNOWN;
+
if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
err = config_func_mtu(mdev, add_config->net.mtu);
if (err)
--
2.34.1
On Wed, Sep 04, 2024 at 10:11:14AM -0500, Carlos Bilbao wrote:
> From: Carlos Bilbao <cbilbao@digitalocean.com>
>
> Initialize the speed and duplex fields in virtio_net_config to UNKNOWN.
> This is needed because mlx5_vdpa vDPA devices currently do not support the
> VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.
I see no logic here. Without this feature bit, guests will not read
this field, why do we suddenly need to initialize it?
> Add
> needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.
>
> Signed-off-by: Carlos Bilbao <cbilbao@digitalocean.com>
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index b56aae3f7be3..41ca268d43ff 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
> return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
> }
>
> +static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
> +{
> + return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
> +}
> +
> static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
> {
> if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
> @@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
> init_rwsem(&ndev->reslock);
> config = &ndev->config;
>
> + /*
> + * mlx5_vdpa vDPA devices currently don't support reporting or
> + * setting the speed or duplex.
> + */
> + config->speed = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
> + config->duplex = DUPLEX_UNKNOWN;
> +
> if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
> err = config_func_mtu(mdev, add_config->net.mtu);
> if (err)
> --
> 2.34.1
On 07.11.24 22:50, Michael S. Tsirkin wrote:
> On Wed, Sep 04, 2024 at 10:11:14AM -0500, Carlos Bilbao wrote:
>> From: Carlos Bilbao <cbilbao@digitalocean.com>
>>
>> Initialize the speed and duplex fields in virtio_net_config to UNKNOWN.
>> This is needed because mlx5_vdpa vDPA devices currently do not support the
>> VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.
>
> I see no logic here. Without this feature bit, guests will not read
> this field, why do we suddenly need to initialize it?
>
IIRC, Carlos was reading data via ioctl VHOST_VDPA_GET_CONFIG which calls
.get_config() directly, always exposing the speed and duplex config fields [0].
Carlos, was this the case?
[0] https://lore.kernel.org/lkml/afcbf041-7613-48e6-8088-9d52edd907ff@nvidia.com/T/
Thanks,
Dragos
>> Add
>> needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.
>>
>> Signed-off-by: Carlos Bilbao <cbilbao@digitalocean.com>
>> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
>> ---
>> drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
>> 1 file changed, 12 insertions(+)
>>
>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> index b56aae3f7be3..41ca268d43ff 100644
>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> @@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
>> return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
>> }
>>
>> +static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
>> +{
>> + return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
>> +}
>> +
>> static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
>> {
>> if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
>> @@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>> init_rwsem(&ndev->reslock);
>> config = &ndev->config;
>>
>> + /*
>> + * mlx5_vdpa vDPA devices currently don't support reporting or
>> + * setting the speed or duplex.
>> + */
>> + config->speed = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
>> + config->duplex = DUPLEX_UNKNOWN;
>> +
>> if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
>> err = config_func_mtu(mdev, add_config->net.mtu);
>> if (err)
>> --
>> 2.34.1
>
On Fri, Nov 08, 2024 at 10:31:58AM +0100, Dragos Tatulea wrote:
>
>
> On 07.11.24 22:50, Michael S. Tsirkin wrote:
> > On Wed, Sep 04, 2024 at 10:11:14AM -0500, Carlos Bilbao wrote:
> >> From: Carlos Bilbao <cbilbao@digitalocean.com>
> >>
> >> Initialize the speed and duplex fields in virtio_net_config to UNKNOWN.
> >> This is needed because mlx5_vdpa vDPA devices currently do not support the
> >> VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.
> >
> > I see no logic here. Without this feature bit, guests will not read
> > this field, why do we suddenly need to initialize it?
> >
> IIRC, Carlos was reading data via ioctl VHOST_VDPA_GET_CONFIG which calls
> .get_config() directly, always exposing the speed and duplex config fields [0].
> Carlos, was this the case?
>
> [0] https://lore.kernel.org/lkml/afcbf041-7613-48e6-8088-9d52edd907ff@nvidia.com/T/
>
> Thanks,
> Dragos
Basically, driver should ignore these if feature is not set.
> >> Add
> >> needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.
> >>
> >> Signed-off-by: Carlos Bilbao <cbilbao@digitalocean.com>
> >> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
> >> ---
> >> drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
> >> 1 file changed, 12 insertions(+)
> >>
> >> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> >> index b56aae3f7be3..41ca268d43ff 100644
> >> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> >> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> >> @@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
> >> return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
> >> }
> >>
> >> +static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
> >> +{
> >> + return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
> >> +}
> >> +
> >> static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
> >> {
> >> if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
> >> @@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
> >> init_rwsem(&ndev->reslock);
> >> config = &ndev->config;
> >>
> >> + /*
> >> + * mlx5_vdpa vDPA devices currently don't support reporting or
> >> + * setting the speed or duplex.
> >> + */
> >> + config->speed = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
> >> + config->duplex = DUPLEX_UNKNOWN;
> >> +
> >> if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
> >> err = config_func_mtu(mdev, add_config->net.mtu);
> >> if (err)
> >> --
> >> 2.34.1
> >
Hello,
On 11/8/24 5:51 AM, Michael S. Tsirkin wrote:
> On Fri, Nov 08, 2024 at 10:31:58AM +0100, Dragos Tatulea wrote:
>>
>> On 07.11.24 22:50, Michael S. Tsirkin wrote:
>>> On Wed, Sep 04, 2024 at 10:11:14AM -0500, Carlos Bilbao wrote:
>>>> From: Carlos Bilbao <cbilbao@digitalocean.com>
>>>>
>>>> Initialize the speed and duplex fields in virtio_net_config to UNKNOWN.
>>>> This is needed because mlx5_vdpa vDPA devices currently do not support the
>>>> VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.
>>> I see no logic here. Without this feature bit, guests will not read
>>> this field, why do we suddenly need to initialize it?
>>>
>> IIRC, Carlos was reading data via ioctl VHOST_VDPA_GET_CONFIG which calls
>> .get_config() directly, always exposing the speed and duplex config fields [0].
>> Carlos, was this the case?
>>
>> [0] https://lore.kernel.org/lkml/afcbf041-7613-48e6-8088-9d52edd907ff@nvidia.com/T/
>>
>> Thanks,
>> Dragos
> Basically, driver should ignore these if feature is not set.
There _is_ a chance the guest could read this field; As Dragos mentioned, I
was using the VHOST_VDPA_GET_CONFIG ioctl from userspace, and the incorrect
field initialization led me to believe I was in half-duplex mode --
something people told me they hadn't seen since the 80s. But as Andrew
(CCed) mentioned, "If the speed is 0, does duplex even matter?".
I also tried to remove the pointless ioctl call altogether to avoid further
confusion [0] but that wasn't viable due to spec compliance.
Initializing the fields seems the simple solution here (and, IMHO, more
generally, it's as a good programming practice)
Thanks for looking into this!
Best,
Carlos
[0] https://lore.kernel.org/lkml/CACGkMEvfdUYLjx-Z+oB11XW-54ErJsQMKcnu2p=dsj5N_BiEKw@mail.gmail.com/
>
>
>>>> Add
>>>> needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.
>>>>
>>>> Signed-off-by: Carlos Bilbao <cbilbao@digitalocean.com>
>>>> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
>>>> ---
>>>> drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
>>>> 1 file changed, 12 insertions(+)
>>>>
>>>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>>> index b56aae3f7be3..41ca268d43ff 100644
>>>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>>> @@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
>>>> return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
>>>> }
>>>>
>>>> +static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
>>>> +{
>>>> + return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
>>>> +}
>>>> +
>>>> static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
>>>> {
>>>> if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
>>>> @@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>>>> init_rwsem(&ndev->reslock);
>>>> config = &ndev->config;
>>>>
>>>> + /*
>>>> + * mlx5_vdpa vDPA devices currently don't support reporting or
>>>> + * setting the speed or duplex.
>>>> + */
>>>> + config->speed = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
>>>> + config->duplex = DUPLEX_UNKNOWN;
>>>> +
>>>> if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
>>>> err = config_func_mtu(mdev, add_config->net.mtu);
>>>> if (err)
>>>> --
>>>> 2.34.1
On Wed, Sep 4, 2024 at 11:18 PM Carlos Bilbao
<carlos.bilbao.osdev@gmail.com> wrote:
>
> From: Carlos Bilbao <cbilbao@digitalocean.com>
>
> Initialize the speed and duplex fields in virtio_net_config to UNKNOWN.
> This is needed because mlx5_vdpa vDPA devices currently do not support the
> VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex. Add
> needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.
>
> Signed-off-by: Carlos Bilbao <cbilbao@digitalocean.com>
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index b56aae3f7be3..41ca268d43ff 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
> return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
> }
>
> +static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
> +{
> + return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
> +}
> +
> static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
> {
> if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
> @@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
> init_rwsem(&ndev->reslock);
> config = &ndev->config;
>
> + /*
> + * mlx5_vdpa vDPA devices currently don't support reporting or
> + * setting the speed or duplex.
> + */
> + config->speed = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
> + config->duplex = DUPLEX_UNKNOWN;
> +
> if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
> err = config_func_mtu(mdev, add_config->net.mtu);
> if (err)
> --
> 2.34.1
>
© 2016 - 2025 Red Hat, Inc.