[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACLfguUaDo3seJZT_yQNp_fa4bELHwwAb8OTbXGwBLw2fGdj+w@mail.gmail.com>
Date: Mon, 22 Jul 2024 15:56:38 +0800
From: Cindy Lu <lulu@...hat.com>
To: Jason Wang <jasowang@...hat.com>
Cc: dtatulea@...dia.com, mst@...hat.com, parav@...dia.com, sgarzare@...hat.com,
netdev@...r.kernel.org, virtualization@...ts.linux-foundation.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATH v4 2/3] vdpa_sim_net: Add the support of set mac address
On Mon, 22 Jul 2024 at 15:48, Jason Wang <jasowang@...hat.com> wrote:
>
> On Mon, Jul 22, 2024 at 9:06 AM Cindy Lu <lulu@...hat.com> wrote:
> >
> > Add the function to support setting the MAC address.
> > For vdpa_sim_net, the driver will write the MAC address
> > to the config space, and other devices can implement
> > their own functions to support this.
> >
> > Signed-off-by: Cindy Lu <lulu@...hat.com>
> > ---
> > drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 22 +++++++++++++++++++++-
> > 1 file changed, 21 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
> > index cfe962911804..936e33e5021a 100644
> > --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
> > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
> > @@ -414,6 +414,25 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
> > net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
> > }
> >
> > +static int vdpasim_net_set_attr(struct vdpa_mgmt_dev *mdev,
> > + struct vdpa_device *dev,
> > + const struct vdpa_dev_set_config *config)
> > +{
> > + struct vdpasim *vdpasim = container_of(dev, struct vdpasim, vdpa);
> > + struct virtio_net_config *vio_config = vdpasim->config;
> > +
> > + mutex_lock(&vdpasim->mutex);
> > +
> > + if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> > + memcpy(vio_config->mac, config->net.mac, ETH_ALEN);
> > + mutex_unlock(&vdpasim->mutex);
> > + return 0;
> > + }
> > +
> > + mutex_unlock(&vdpasim->mutex);
>
> Do we need to protect:
>
> case VIRTIO_NET_CTRL_MAC_ADDR_SET:
> read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->in_iov,
> vio_config->mac, ETH_ALEN);
> if (read == ETH_ALEN)
> status = VIRTIO_NET_OK;
> break;
>
> As both are modifying vio_config?
>
> Thanks
>
i have added a lock for this; CVQ also needs to take this lock to
change the MAC address.I thinks maybe this can protect?
Do you mean I need to compare the mac address from the vdpa_tool and
mac address in vio_config?
this vdpa tool should not be used after the guest load, if this is
different this is also acceptable
thanks
Cindy
> > + return -EINVAL;
> > +}
> > +
> > static void vdpasim_net_setup_config(struct vdpasim *vdpasim,
> > const struct vdpa_dev_set_config *config)
> > {
> > @@ -510,7 +529,8 @@ static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev,
> >
> > static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {
> > .dev_add = vdpasim_net_dev_add,
> > - .dev_del = vdpasim_net_dev_del
> > + .dev_del = vdpasim_net_dev_del,
> > + .dev_set_attr = vdpasim_net_set_attr
> > };
> >
> > static struct virtio_device_id id_table[] = {
> > --
> > 2.45.0
> >
>
Powered by blists - more mailing lists