Re: [PATH v6 1/3] vdpa: support set mac address from vdpa tool

From: Cindy Lu
Date: Fri Jul 26 2024 - 09:20:32 EST


On Fri, 26 Jul 2024 at 01:29, Joe Damato <jdamato@xxxxxxxxxx> wrote:
>
> On Thu, Jul 25, 2024 at 09:31:02AM +0800, Cindy Lu wrote:
> [...]
> > diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
> > index 8d391947eb8d..532cf3b52b26 100644
> > --- a/drivers/vdpa/vdpa.c
> > +++ b/drivers/vdpa/vdpa.c
> > @@ -1361,6 +1361,81 @@ static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info
> > return err;
> > }
> >
> > +static int vdpa_dev_net_device_attr_set(struct vdpa_device *vdev,
> > + struct genl_info *info)
> > +{
> > + struct vdpa_dev_set_config set_config = {};
> > + const u8 *macaddr;
> > + struct vdpa_mgmt_dev *mdev = vdev->mdev;
> > + struct nlattr **nl_attrs = info->attrs;
> > + int err = -EINVAL;
>
> Nit: IIRC networking code prefers reverse-xmas tree style and
> macaddr above needs to be moved.
>
will fix this
thanks
cindy
> > + down_write(&vdev->cf_lock);
> > + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]) {
> > + set_config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR);
> > + macaddr = nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]);
> > +
> > + if (is_valid_ether_addr(macaddr)) {
> > + ether_addr_copy(set_config.net.mac, macaddr);
> > + memcpy(set_config.net.mac, macaddr, ETH_ALEN);
> > + if (mdev->ops->dev_set_attr) {
> > + err = mdev->ops->dev_set_attr(mdev, vdev,
> > + &set_config);
> > + } else {
> > + NL_SET_ERR_MSG_FMT_MOD(
> > + info->extack,
> > + "device does not support changing the MAC address");
> > + }
> > + } else {
> > + NL_SET_ERR_MSG_FMT_MOD(info->extack,
> > + "Invalid MAC address");
> > + }
> > + }
> > + up_write(&vdev->cf_lock);
> > + return err;
> > +}
>
> Nit: other code in this file has line breaks separating functions.
> Probably good to add one here?
>
sure will change this
thanks
Cindy
>
> > +static int vdpa_nl_cmd_dev_attr_set_doit(struct sk_buff *skb,
> > + struct genl_info *info)
>
> Nit: Does the above pass ./scripts/checkpatch.pl --strict ? I am asking
> because it seems like the alignment might be off?
>
I tried this, but there doesn't seem to have warning. I'll double-check this.
Thanks
cindy
> > +{
> > + const char *name;
> > + int err = 0;
> > + struct device *dev;
> > + struct vdpa_device *vdev;
> > + u64 classes;
>
> Nit: Same as above; I believe networking code is supposed to follow
> reverse xmas tree order so these variables should be rearranged.
>
will fix this

> > + if (!info->attrs[VDPA_ATTR_DEV_NAME])
> > + return -EINVAL;
> > +
> > + name = nla_data(info->attrs[VDPA_ATTR_DEV_NAME]);
> > +
> > + down_write(&vdpa_dev_lock);
> > + dev = bus_find_device(&vdpa_bus, NULL, name, vdpa_name_match);
> > + if (!dev) {
> > + NL_SET_ERR_MSG_MOD(info->extack, "device not found");
> > + err = -ENODEV;
> > + goto dev_err;
> > + }
> > + vdev = container_of(dev, struct vdpa_device, dev);
> > + if (!vdev->mdev) {
> > + NL_SET_ERR_MSG_MOD(info->extack, "unmanaged vdpa device");
> > + err = -EINVAL;
> > + goto mdev_err;
> > + }
> > + classes = vdpa_mgmtdev_get_classes(vdev->mdev, NULL);
> > + if (classes & BIT_ULL(VIRTIO_ID_NET)) {
> > + err = vdpa_dev_net_device_attr_set(vdev, info);
> > + } else {
> > + NL_SET_ERR_MSG_FMT_MOD(info->extack, "%s device not supported",
> > + name);
> > + }
> > +
> > +mdev_err:
> > + put_device(dev);
> > +dev_err:
> > + up_write(&vdpa_dev_lock);
> > + return err;
> > +}
>
> [...]
>