On Fri, Mar 21, 2025 at 12:29 PM Konstantin Shkolnyy <k...@linux.ibm.com> wrote:
>
> On 3/20/2025 20:22, Jason Wang wrote:
> > On Fri, Mar 21, 2025 at 12:45 AM Konstantin Shkolnyy <k...@linux.ibm.com> 
> > wrote:
> >>
> >> On 3/19/2025 19:58, Jason Wang wrote:
> >>> On Thu, Mar 20, 2025 at 12:34 AM Konstantin Shkolnyy <k...@linux.ibm.com> 
> >>> wrote:
> >>>> Upon reading this forum, I see that VHOST_VDPA_SET_CONFIG is
> >>>> “deprecated”, and so VIRTIO_NET_CTRL_MAC_ADDR_SET must be the right
> >>>> method, but it’s apparently called too late.
> >>>
> >>> VHOST_VDPA_SET_CONFIG requires the vDPA parent support which is not
> >>> necessarily there.
> >>
> >> The mlx5 driver doesn't do anything for VHOST_VDPA_SET_CONFIG. Intel's
> >> driver, however, apparently stores the configuration. So, it appears,
> >> Intel will avoid the problem... Perhaps mlx5 could do the same so that
> >> QEMU can set the address before it starts the VM (QEMU doesn't have to
> >> later let the VM change the config).
> >
> > The problem is that config space is not allowed to be written, that is
> > why mlx5 doesn't implement the write method.
> >
> >> Conceptually, setting the address
> >> by QEMU cmdline doesn't look different from setting it by "vdpa dev add".
> >
> > It's kind of different.
> >
> > E.g the device may not even have VIRTIO_NET_F_MAC feature etc.
>
> I'm not sure I understand... This is the MAC address returned by
> VHOST_VDPA_GET_CONFIG. If mlx5 allows it to be set by "vdpa dev add",
> shouldn't it also allow it to be set by VHOST_VDPA_SET_CONFIG called by
> virtio_net_device_realize(), before the VM exists.
>
> When VM starts running, it queries this MAC address and QEMU fetches it
> by VHOST_VDPA_GET_CONFIG. But, because VHOST_VDPA_SET_CONFIG hasn't
> stored it, it fetches a wrong stale address.
>
Hi Konstantin
This buggy process is functioning in the MLX driver as follow steps

0: kernel creates VDPA device [MLX: if the mac was not set  while
creating, the mac is 0 in hardware]

1. Get Mac from the cmd line.if the cmdline is 0, qemu will create a
random mac address, save it in VirtIONet->mac and
VirtIONet->nic_conf.macaddr

3. qemu called virtio_net_device_realize()
in this function, the mac address in VirtIONet->mac will set to kernel
while calling vhost_net_set_config() [ MLX not supported  ]

4. qemu boot called vhost_net_get_config, get the hardware mac address
and saved in VirtIONet->nic_conf.macaddr
this will read the mac from the kernel and change the mac address to
kernel's mac [ for MLX, if the hardware mac is 0, using the cmdline
mac(or random mac )  ]
NOTE the information in VirtIONet->mac was not change

5, the qemu will call vhost_vdpa_net_cvq_load(). Even if the cvq/svq
not enabled in qemu cmdline
this function will set the mac in VirtIONet->mac to the kernel.[mlx support]

This will result in QEMU's MAC address differing from the hardware's
MAC address.
So our fix is
1. Add a tool for users to set the MAC address before QEMU loads.
2. Include a parameter in QEMU to check the MAC address before
booting; QEMU will fail to load the system if the MAC addresses do not
match.

Thanks

Cindy


Reply via email to