Message ID | 20210105103203.82508-7-parav@nvidia.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | Introduce vdpa management tool | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > Enable user to create vdpasim net simulate devices. > > Show vdpa management device that supports creating, deleting vdpa devices. > > $ vdpa mgmtdev show > vdpasim_net: > supported_classes > net > > $ vdpa mgmtdev show -jp > { > "show": { > "vdpasim_net": { > "supported_classes": { > "net" > } > } > } > > Create a vdpa device of type networking named as "foo2" from > the management device vdpasim: > > $ vdpa dev add mgmtdev vdpasim_net name foo2 > > Show the newly created vdpa device by its name: > $ vdpa dev show foo2 > foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 max_vq_size 256 > > $ vdpa dev show foo2 -jp > { > "dev": { > "foo2": { > "type": "network", > "mgmtdev": "vdpasim_net", > "vendor_id": 0, > "max_vqs": 2, > "max_vq_size": 256 > } > } > } I'd like an example of how do device specific (e.g. net specific) interfaces tie in to this. > Delete the vdpa device after its use: > $ vdpa dev del foo2 > > Signed-off-by: Parav Pandit <parav@nvidia.com> > Reviewed-by: Eli Cohen <elic@nvidia.com> > Acked-by: Jason Wang <jasowang@redhat.com> > --- > Changelog: > v2->v3: > - removed code branches due to default device removal patch > v1->v2: > - rebased > --- > drivers/vdpa/vdpa_sim/vdpa_sim.c | 3 +- > drivers/vdpa/vdpa_sim/vdpa_sim.h | 2 + > drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 96 ++++++++++++++++++++-------- > 3 files changed, 75 insertions(+), 26 deletions(-) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c > index db1636a99ba4..d5942842432d 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > @@ -235,7 +235,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) > ops = &vdpasim_config_ops; > > vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, > - dev_attr->nvqs, NULL); > + dev_attr->nvqs, dev_attr->name); > if (!vdpasim) > goto err_alloc; > > @@ -249,6 +249,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) > if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) > goto err_iommu; > set_dma_ops(dev, &vdpasim_dma_ops); > + vdpasim->vdpa.mdev = dev_attr->mgmt_dev; > > vdpasim->config = kzalloc(dev_attr->config_size, GFP_KERNEL); > if (!vdpasim->config) > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h > index b02142293d5b..6d75444f9948 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h > @@ -33,6 +33,8 @@ struct vdpasim_virtqueue { > }; > > struct vdpasim_dev_attr { > + struct vdpa_mgmt_dev *mgmt_dev; > + const char *name; > u64 supported_features; > size_t config_size; > size_t buffer_size; > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c > index f0482427186b..d344c5b7c914 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c > @@ -35,8 +35,6 @@ MODULE_PARM_DESC(macaddr, "Ethernet MAC address"); > > static u8 macaddr_buf[ETH_ALEN]; > > -static struct vdpasim *vdpasim_net_dev; > - > static void vdpasim_net_work(struct work_struct *work) > { > struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); > @@ -120,21 +118,23 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config) > memcpy(net_config->mac, macaddr_buf, ETH_ALEN); > } > > -static int __init vdpasim_net_init(void) > +static void vdpasim_net_mgmtdev_release(struct device *dev) > +{ > +} > + > +static struct device vdpasim_net_mgmtdev = { > + .init_name = "vdpasim_net", > + .release = vdpasim_net_mgmtdev_release, > +}; > + > +static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) > { > struct vdpasim_dev_attr dev_attr = {}; > + struct vdpasim *simdev; > int ret; > > - if (macaddr) { > - mac_pton(macaddr, macaddr_buf); > - if (!is_valid_ether_addr(macaddr_buf)) { > - ret = -EADDRNOTAVAIL; > - goto out; > - } > - } else { > - eth_random_addr(macaddr_buf); > - } > - > + dev_attr.mgmt_dev = mdev; > + dev_attr.name = name; > dev_attr.id = VIRTIO_ID_NET; > dev_attr.supported_features = VDPASIM_NET_FEATURES; > dev_attr.nvqs = VDPASIM_NET_VQ_NUM; > @@ -143,29 +143,75 @@ static int __init vdpasim_net_init(void) > dev_attr.work_fn = vdpasim_net_work; > dev_attr.buffer_size = PAGE_SIZE; > > - vdpasim_net_dev = vdpasim_create(&dev_attr); > - if (IS_ERR(vdpasim_net_dev)) { > - ret = PTR_ERR(vdpasim_net_dev); > - goto out; > + simdev = vdpasim_create(&dev_attr); > + if (IS_ERR(simdev)) > + return PTR_ERR(simdev); > + > + ret = _vdpa_register_device(&simdev->vdpa); > + if (ret) > + goto reg_err; > + > + return 0; > + > +reg_err: > + put_device(&simdev->vdpa.dev); > + return ret; > +} > + > +static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev, > + struct vdpa_device *dev) > +{ > + struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa); > + > + _vdpa_unregister_device(&simdev->vdpa); > +} > + > +static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = { > + .dev_add = vdpasim_net_dev_add, > + .dev_del = vdpasim_net_dev_del > +}; > + > +static struct virtio_device_id id_table[] = { > + { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, > + { 0 }, > +}; > + > +static struct vdpa_mgmt_dev mgmt_dev = { > + .device = &vdpasim_net_mgmtdev, > + .id_table = id_table, > + .ops = &vdpasim_net_mgmtdev_ops, > +}; > + > +static int __init vdpasim_net_init(void) > +{ > + int ret; > + > + if (macaddr) { > + mac_pton(macaddr, macaddr_buf); > + if (!is_valid_ether_addr(macaddr_buf)) > + return -EADDRNOTAVAIL; > + } else { > + eth_random_addr(macaddr_buf); > } Hmm so all devices start out with the same MAC until changed? And how is the change effected? > - ret = vdpa_register_device(&vdpasim_net_dev->vdpa); > + ret = device_register(&vdpasim_net_mgmtdev); > if (ret) > - goto put_dev; > + return ret; > > + ret = vdpa_mgmtdev_register(&mgmt_dev); > + if (ret) > + goto parent_err; > return 0; > > -put_dev: > - put_device(&vdpasim_net_dev->vdpa.dev); > -out: > +parent_err: > + device_unregister(&vdpasim_net_mgmtdev); > return ret; > } > > static void __exit vdpasim_net_exit(void) > { > - struct vdpa_device *vdpa = &vdpasim_net_dev->vdpa; > - > - vdpa_unregister_device(vdpa); > + vdpa_mgmtdev_unregister(&mgmt_dev); > + device_unregister(&vdpasim_net_mgmtdev); > } > > module_init(vdpasim_net_init); > -- > 2.26.2
> From: Michael S. Tsirkin <mst@redhat.com> > Sent: Tuesday, January 5, 2021 5:19 PM > > On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > > Enable user to create vdpasim net simulate devices. > > > > > > $ vdpa dev add mgmtdev vdpasim_net name foo2 > > > > Show the newly created vdpa device by its name: > > $ vdpa dev show foo2 > > foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 > > max_vq_size 256 > > > > $ vdpa dev show foo2 -jp > > { > > "dev": { > > "foo2": { > > "type": "network", > > "mgmtdev": "vdpasim_net", > > "vendor_id": 0, > > "max_vqs": 2, > > "max_vq_size": 256 > > } > > } > > } > > > I'd like an example of how do device specific (e.g. net specific) interfaces tie > in to this. Not sure I follow your question. Do you mean how to set mac address or mtu of this vdpa device of type net? If so, dev add command will be extended shortly in subsequent series to set this net specific attributes. (I did mention in the next steps in cover letter). > > +static int __init vdpasim_net_init(void) { > > + int ret; > > + > > + if (macaddr) { > > + mac_pton(macaddr, macaddr_buf); > > + if (!is_valid_ether_addr(macaddr_buf)) > > + return -EADDRNOTAVAIL; > > + } else { > > + eth_random_addr(macaddr_buf); > > } > > Hmm so all devices start out with the same MAC until changed? And how is > the change effected? Post this patchset and post we have iproute2 vdpa in the tree, will add the mac address as the input attribute during "vdpa dev add" command. So that each different vdpa device can have user specified (different) mac address.
On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: > > > > From: Michael S. Tsirkin <mst@redhat.com> > > Sent: Tuesday, January 5, 2021 5:19 PM > > > > On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > > > Enable user to create vdpasim net simulate devices. > > > > > > > > > > $ vdpa dev add mgmtdev vdpasim_net name foo2 > > > > > > Show the newly created vdpa device by its name: > > > $ vdpa dev show foo2 > > > foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 > > > max_vq_size 256 > > > > > > $ vdpa dev show foo2 -jp > > > { > > > "dev": { > > > "foo2": { > > > "type": "network", > > > "mgmtdev": "vdpasim_net", > > > "vendor_id": 0, > > > "max_vqs": 2, > > > "max_vq_size": 256 > > > } > > > } > > > } > > > > > > I'd like an example of how do device specific (e.g. net specific) interfaces tie > > in to this. > Not sure I follow your question. > Do you mean how to set mac address or mtu of this vdpa device of type net? > If so, dev add command will be extended shortly in subsequent series to set this net specific attributes. > (I did mention in the next steps in cover letter). > > > > +static int __init vdpasim_net_init(void) { > > > + int ret; > > > + > > > + if (macaddr) { > > > + mac_pton(macaddr, macaddr_buf); > > > + if (!is_valid_ether_addr(macaddr_buf)) > > > + return -EADDRNOTAVAIL; > > > + } else { > > > + eth_random_addr(macaddr_buf); > > > } > > > > Hmm so all devices start out with the same MAC until changed? And how is > > the change effected? > Post this patchset and post we have iproute2 vdpa in the tree, will add the mac address as the input attribute during "vdpa dev add" command. > So that each different vdpa device can have user specified (different) mac address. For now maybe just avoid VIRTIO_NET_F_MAC then for new devices then?
> From: Michael S. Tsirkin <mst@redhat.com> > Sent: Tuesday, January 5, 2021 5:45 PM > > On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: > > > > > > > From: Michael S. Tsirkin <mst@redhat.com> > > > Sent: Tuesday, January 5, 2021 5:19 PM > > > > > > On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > > > > Enable user to create vdpasim net simulate devices. > > > > > > > > > > > > > > $ vdpa dev add mgmtdev vdpasim_net name foo2 > > > > > > > > Show the newly created vdpa device by its name: > > > > $ vdpa dev show foo2 > > > > foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 > > > > max_vq_size 256 > > > > > > > > $ vdpa dev show foo2 -jp > > > > { > > > > "dev": { > > > > "foo2": { > > > > "type": "network", > > > > "mgmtdev": "vdpasim_net", > > > > "vendor_id": 0, > > > > "max_vqs": 2, > > > > "max_vq_size": 256 > > > > } > > > > } > > > > } > > > > > > > > > I'd like an example of how do device specific (e.g. net specific) > > > interfaces tie in to this. > > Not sure I follow your question. > > Do you mean how to set mac address or mtu of this vdpa device of type > net? > > If so, dev add command will be extended shortly in subsequent series to > set this net specific attributes. > > (I did mention in the next steps in cover letter). > > > > > > +static int __init vdpasim_net_init(void) { > > > > + int ret; > > > > + > > > > + if (macaddr) { > > > > + mac_pton(macaddr, macaddr_buf); > > > > + if (!is_valid_ether_addr(macaddr_buf)) > > > > + return -EADDRNOTAVAIL; > > > > + } else { > > > > + eth_random_addr(macaddr_buf); > > > > } > > > > > > Hmm so all devices start out with the same MAC until changed? And > > > how is the change effected? > > Post this patchset and post we have iproute2 vdpa in the tree, will add the > mac address as the input attribute during "vdpa dev add" command. > > So that each different vdpa device can have user specified (different) mac > address. > > For now maybe just avoid VIRTIO_NET_F_MAC then for new devices then? That would require book keeping existing net vdpa_sim devices created to avoid setting VIRTIO_NET_F_MAC. Such book keeping code will be short lived anyway. Not sure if its worth it. Until now only one device was created. So not sure two vdpa devices with same mac address will be a real issue. When we add mac address attribute in add command, at that point also remove the module parameter macaddr.
On Tue, Jan 05, 2021 at 12:30:15PM +0000, Parav Pandit wrote: > > > > From: Michael S. Tsirkin <mst@redhat.com> > > Sent: Tuesday, January 5, 2021 5:45 PM > > > > On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: > > > > > > > > > > From: Michael S. Tsirkin <mst@redhat.com> > > > > Sent: Tuesday, January 5, 2021 5:19 PM > > > > > > > > On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > > > > > Enable user to create vdpasim net simulate devices. > > > > > > > > > > > > > > > > > > $ vdpa dev add mgmtdev vdpasim_net name foo2 > > > > > > > > > > Show the newly created vdpa device by its name: > > > > > $ vdpa dev show foo2 > > > > > foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 > > > > > max_vq_size 256 > > > > > > > > > > $ vdpa dev show foo2 -jp > > > > > { > > > > > "dev": { > > > > > "foo2": { > > > > > "type": "network", > > > > > "mgmtdev": "vdpasim_net", > > > > > "vendor_id": 0, > > > > > "max_vqs": 2, > > > > > "max_vq_size": 256 > > > > > } > > > > > } > > > > > } > > > > > > > > > > > > I'd like an example of how do device specific (e.g. net specific) > > > > interfaces tie in to this. > > > Not sure I follow your question. > > > Do you mean how to set mac address or mtu of this vdpa device of type > > net? > > > If so, dev add command will be extended shortly in subsequent series to > > set this net specific attributes. > > > (I did mention in the next steps in cover letter). > > > > > > > > +static int __init vdpasim_net_init(void) { > > > > > + int ret; > > > > > + > > > > > + if (macaddr) { > > > > > + mac_pton(macaddr, macaddr_buf); > > > > > + if (!is_valid_ether_addr(macaddr_buf)) > > > > > + return -EADDRNOTAVAIL; > > > > > + } else { > > > > > + eth_random_addr(macaddr_buf); > > > > > } > > > > > > > > Hmm so all devices start out with the same MAC until changed? And > > > > how is the change effected? > > > Post this patchset and post we have iproute2 vdpa in the tree, will add the > > mac address as the input attribute during "vdpa dev add" command. > > > So that each different vdpa device can have user specified (different) mac > > address. > > > > For now maybe just avoid VIRTIO_NET_F_MAC then for new devices then? > > That would require book keeping existing net vdpa_sim devices created to avoid setting VIRTIO_NET_F_MAC. > Such book keeping code will be short lived anyway. > Not sure if its worth it. > Until now only one device was created. So not sure two vdpa devices with same mac address will be a real issue. > > When we add mac address attribute in add command, at that point also remove the module parameter macaddr. Will that be mandatory? I'm not to happy with a UAPI we intend to break straight away ...
> From: Michael S. Tsirkin <mst@redhat.com> > Sent: Tuesday, January 5, 2021 6:53 PM > > On Tue, Jan 05, 2021 at 12:30:15PM +0000, Parav Pandit wrote: > > > > > > > From: Michael S. Tsirkin <mst@redhat.com> > > > Sent: Tuesday, January 5, 2021 5:45 PM > > > > > > On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: > > > > > > > > > > > > > From: Michael S. Tsirkin <mst@redhat.com> > > > > > Sent: Tuesday, January 5, 2021 5:19 PM > > > > > > > > > > On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > > > > > > Enable user to create vdpasim net simulate devices. > > > > > > > > > > > > > > > > > > > > > > $ vdpa dev add mgmtdev vdpasim_net name foo2 > > > > > > > > > > > > Show the newly created vdpa device by its name: > > > > > > $ vdpa dev show foo2 > > > > > > foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 > > > > > > max_vq_size 256 > > > > > > > > > > > > $ vdpa dev show foo2 -jp > > > > > > { > > > > > > "dev": { > > > > > > "foo2": { > > > > > > "type": "network", > > > > > > "mgmtdev": "vdpasim_net", > > > > > > "vendor_id": 0, > > > > > > "max_vqs": 2, > > > > > > "max_vq_size": 256 > > > > > > } > > > > > > } > > > > > > } > > > > > > > > > > > > > > > I'd like an example of how do device specific (e.g. net > > > > > specific) interfaces tie in to this. > > > > Not sure I follow your question. > > > > Do you mean how to set mac address or mtu of this vdpa device of > > > > type > > > net? > > > > If so, dev add command will be extended shortly in subsequent > > > > series to > > > set this net specific attributes. > > > > (I did mention in the next steps in cover letter). > > > > > > > > > > +static int __init vdpasim_net_init(void) { > > > > > > + int ret; > > > > > > + > > > > > > + if (macaddr) { > > > > > > + mac_pton(macaddr, macaddr_buf); > > > > > > + if (!is_valid_ether_addr(macaddr_buf)) > > > > > > + return -EADDRNOTAVAIL; > > > > > > + } else { > > > > > > + eth_random_addr(macaddr_buf); > > > > > > } > > > > > > > > > > Hmm so all devices start out with the same MAC until changed? > > > > > And how is the change effected? > > > > Post this patchset and post we have iproute2 vdpa in the tree, > > > > will add the > > > mac address as the input attribute during "vdpa dev add" command. > > > > So that each different vdpa device can have user specified > > > > (different) mac > > > address. > > > > > > For now maybe just avoid VIRTIO_NET_F_MAC then for new devices > then? > > > > That would require book keeping existing net vdpa_sim devices created to > avoid setting VIRTIO_NET_F_MAC. > > Such book keeping code will be short lived anyway. > > Not sure if its worth it. > > Until now only one device was created. So not sure two vdpa devices with > same mac address will be a real issue. > > > > When we add mac address attribute in add command, at that point also > remove the module parameter macaddr. > > Will that be mandatory? I'm not to happy with a UAPI we intend to break > straight away ... No. Specifying mac address shouldn't be mandatory. UAPI wont' be broken.
Hi Michael, > From: Virtualization <virtualization-bounces@lists.linux-foundation.org> On > Behalf Of Parav Pandit > > > > > > When we add mac address attribute in add command, at that point also > > remove the module parameter macaddr. > > > > Will that be mandatory? I'm not to happy with a UAPI we intend to > > break straight away ... > No. Specifying mac address shouldn't be mandatory. UAPI wont' be broken. Shall we please proceed with this patchset? I would like to complete the iproute2 part and converting remaining two drivers to follow mgmt tool subsequent to this series.
On 2021/1/7 上午11:48, Parav Pandit wrote: > >> From: Michael S. Tsirkin <mst@redhat.com> >> Sent: Tuesday, January 5, 2021 6:53 PM >> >> On Tue, Jan 05, 2021 at 12:30:15PM +0000, Parav Pandit wrote: >>> >>>> From: Michael S. Tsirkin <mst@redhat.com> >>>> Sent: Tuesday, January 5, 2021 5:45 PM >>>> >>>> On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: >>>>> >>>>>> From: Michael S. Tsirkin <mst@redhat.com> >>>>>> Sent: Tuesday, January 5, 2021 5:19 PM >>>>>> >>>>>> On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: >>>>>>> Enable user to create vdpasim net simulate devices. >>>>>>> >>>>>>> >>>>>>> $ vdpa dev add mgmtdev vdpasim_net name foo2 >>>>>>> >>>>>>> Show the newly created vdpa device by its name: >>>>>>> $ vdpa dev show foo2 >>>>>>> foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 >>>>>>> max_vq_size 256 >>>>>>> >>>>>>> $ vdpa dev show foo2 -jp >>>>>>> { >>>>>>> "dev": { >>>>>>> "foo2": { >>>>>>> "type": "network", >>>>>>> "mgmtdev": "vdpasim_net", >>>>>>> "vendor_id": 0, >>>>>>> "max_vqs": 2, >>>>>>> "max_vq_size": 256 >>>>>>> } >>>>>>> } >>>>>>> } >>>>>> >>>>>> I'd like an example of how do device specific (e.g. net >>>>>> specific) interfaces tie in to this. >>>>> Not sure I follow your question. >>>>> Do you mean how to set mac address or mtu of this vdpa device of >>>>> type >>>> net? >>>>> If so, dev add command will be extended shortly in subsequent >>>>> series to >>>> set this net specific attributes. >>>>> (I did mention in the next steps in cover letter). >>>>> >>>>>>> +static int __init vdpasim_net_init(void) { >>>>>>> + int ret; >>>>>>> + >>>>>>> + if (macaddr) { >>>>>>> + mac_pton(macaddr, macaddr_buf); >>>>>>> + if (!is_valid_ether_addr(macaddr_buf)) >>>>>>> + return -EADDRNOTAVAIL; >>>>>>> + } else { >>>>>>> + eth_random_addr(macaddr_buf); >>>>>>> } >>>>>> Hmm so all devices start out with the same MAC until changed? >>>>>> And how is the change effected? >>>>> Post this patchset and post we have iproute2 vdpa in the tree, >>>>> will add the >>>> mac address as the input attribute during "vdpa dev add" command. >>>>> So that each different vdpa device can have user specified >>>>> (different) mac >>>> address. >>>> >>>> For now maybe just avoid VIRTIO_NET_F_MAC then for new devices >> then? >>> That would require book keeping existing net vdpa_sim devices created to >> avoid setting VIRTIO_NET_F_MAC. >>> Such book keeping code will be short lived anyway. >>> Not sure if its worth it. >>> Until now only one device was created. So not sure two vdpa devices with >> same mac address will be a real issue. >>> When we add mac address attribute in add command, at that point also >> remove the module parameter macaddr. >> >> Will that be mandatory? I'm not to happy with a UAPI we intend to break >> straight away ... > No. Specifying mac address shouldn't be mandatory. UAPI wont' be broken. If it's not mandatory. Does it mean the vDPA parent need to use its own logic to generate a validate mac? I'm not sure this is what management (libvirt want). Thanks >
> From: Jason Wang <jasowang@redhat.com> > Sent: Thursday, January 14, 2021 9:48 AM > > On 2021/1/7 上午11:48, Parav Pandit wrote: > > > >> From: Michael S. Tsirkin <mst@redhat.com> > >> Sent: Tuesday, January 5, 2021 6:53 PM > >> > >> On Tue, Jan 05, 2021 at 12:30:15PM +0000, Parav Pandit wrote: > >>> > >>>> From: Michael S. Tsirkin <mst@redhat.com> > >>>> Sent: Tuesday, January 5, 2021 5:45 PM > >>>> > >>>> On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: > >>>>> > >>>>>> From: Michael S. Tsirkin <mst@redhat.com> > >>>>>> Sent: Tuesday, January 5, 2021 5:19 PM > >>>>>> > >>>>>> On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > >>>>>>> Enable user to create vdpasim net simulate devices. > >>>>>>> > >>>>>>> > >>>>>>> $ vdpa dev add mgmtdev vdpasim_net name foo2 > >>>>>>> > >>>>>>> Show the newly created vdpa device by its name: > >>>>>>> $ vdpa dev show foo2 > >>>>>>> foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 > >>>>>>> max_vq_size 256 > >>>>>>> > >>>>>>> $ vdpa dev show foo2 -jp > >>>>>>> { > >>>>>>> "dev": { > >>>>>>> "foo2": { > >>>>>>> "type": "network", > >>>>>>> "mgmtdev": "vdpasim_net", > >>>>>>> "vendor_id": 0, > >>>>>>> "max_vqs": 2, > >>>>>>> "max_vq_size": 256 > >>>>>>> } > >>>>>>> } > >>>>>>> } > >>>>>> > >>>>>> I'd like an example of how do device specific (e.g. net > >>>>>> specific) interfaces tie in to this. > >>>>> Not sure I follow your question. > >>>>> Do you mean how to set mac address or mtu of this vdpa device of > >>>>> type > >>>> net? > >>>>> If so, dev add command will be extended shortly in subsequent > >>>>> series to > >>>> set this net specific attributes. > >>>>> (I did mention in the next steps in cover letter). > >>>>> > >>>>>>> +static int __init vdpasim_net_init(void) { > >>>>>>> + int ret; > >>>>>>> + > >>>>>>> + if (macaddr) { > >>>>>>> + mac_pton(macaddr, macaddr_buf); > >>>>>>> + if (!is_valid_ether_addr(macaddr_buf)) > >>>>>>> + return -EADDRNOTAVAIL; > >>>>>>> + } else { > >>>>>>> + eth_random_addr(macaddr_buf); > >>>>>>> } > >>>>>> Hmm so all devices start out with the same MAC until changed? > >>>>>> And how is the change effected? > >>>>> Post this patchset and post we have iproute2 vdpa in the tree, > >>>>> will add the > >>>> mac address as the input attribute during "vdpa dev add" command. > >>>>> So that each different vdpa device can have user specified > >>>>> (different) mac > >>>> address. > >>>> > >>>> For now maybe just avoid VIRTIO_NET_F_MAC then for new devices > >> then? > >>> That would require book keeping existing net vdpa_sim devices > >>> created to > >> avoid setting VIRTIO_NET_F_MAC. > >>> Such book keeping code will be short lived anyway. > >>> Not sure if its worth it. > >>> Until now only one device was created. So not sure two vdpa devices > >>> with > >> same mac address will be a real issue. > >>> When we add mac address attribute in add command, at that point also > >> remove the module parameter macaddr. > >> > >> Will that be mandatory? I'm not to happy with a UAPI we intend to > >> break straight away ... > > No. Specifying mac address shouldn't be mandatory. UAPI wont' be > broken. > > > If it's not mandatory. Does it mean the vDPA parent need to use its own logic > to generate a validate mac? I'm not sure this is what management (libvirt > want). > There are few use cases that I see with PFs, VFs and SFs supporting vdpa devices. 1. User wants to use the VF only for vdpa purpose. Here user got the VF which was pre-setup by the sysadmin. In this case whatever MAC assigned to the VF can be used by its vdpa device. Here, user doesn't need to pass the mac address during vdpa device creation time. This is done as the same MAC has been setup in the ACL rules on the switch side. Non VDPA users of a VF typically use the VF this way for Netdev and rdma functionality. They might continue same way for vdpa application as well. Here VF mac is either set using (a) devlink port function set hw_addr command or using (b) ip link set vf mac So vdpa tool didn't pass the mac. (optional). Though VIRTIO_NET_F_MAC is still valid. 2. User may want to create one or more vdpa device out of the mgmt. device. Here user wants to more/full control of all features, overriding what sysadmin has setup as MAC of the VF/SF. In this case user will specify the MAC via mgmt tool. (a) This is also used by those vdpa devices which doesn't have eswitch offloads. (b) This will work with eswitch offloads as well who does source learning. (c) User chose to use the vdpa device of a VF while VF Netdev and rdma device are used by hypervisor for something else as well. VIRTIO_NET_F_MAC remains valid in all 2.{a,b,c}. 3. A vendor mgmt. device always expects it user to provide mac for its vdpa devices. So when it is not provided, it can fail with error message string in extack or clear the VIRTIO_NET_F_MAC and let it work using virtio spec's 5.1.5 point 5 to proceed. As common denominator of all above cases, if QEMU or user pass the MAC during creation, it will almost always work. Advance user and QEMU with switchdev mode support who has done 1.a/1.b, will omit it. I do not know how deep integration of QEMU exist with the switchdev mode support. With that mac, mtu as optional input fields provide the necessary flexibility for different stacks to take appropriate shape as they desire.
On 2021/1/14 下午3:58, Parav Pandit wrote: > >> From: Jason Wang <jasowang@redhat.com> >> Sent: Thursday, January 14, 2021 9:48 AM >> >> On 2021/1/7 上午11:48, Parav Pandit wrote: >>>> From: Michael S. Tsirkin <mst@redhat.com> >>>> Sent: Tuesday, January 5, 2021 6:53 PM >>>> >>>> On Tue, Jan 05, 2021 at 12:30:15PM +0000, Parav Pandit wrote: >>>>>> From: Michael S. Tsirkin <mst@redhat.com> >>>>>> Sent: Tuesday, January 5, 2021 5:45 PM >>>>>> >>>>>> On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: >>>>>>>> From: Michael S. Tsirkin <mst@redhat.com> >>>>>>>> Sent: Tuesday, January 5, 2021 5:19 PM >>>>>>>> >>>>>>>> On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: >>>>>>>>> Enable user to create vdpasim net simulate devices. >>>>>>>>> >>>>>>>>> >>>>>>>>> $ vdpa dev add mgmtdev vdpasim_net name foo2 >>>>>>>>> >>>>>>>>> Show the newly created vdpa device by its name: >>>>>>>>> $ vdpa dev show foo2 >>>>>>>>> foo2: type network mgmtdev vdpasim_net vendor_id 0 max_vqs 2 >>>>>>>>> max_vq_size 256 >>>>>>>>> >>>>>>>>> $ vdpa dev show foo2 -jp >>>>>>>>> { >>>>>>>>> "dev": { >>>>>>>>> "foo2": { >>>>>>>>> "type": "network", >>>>>>>>> "mgmtdev": "vdpasim_net", >>>>>>>>> "vendor_id": 0, >>>>>>>>> "max_vqs": 2, >>>>>>>>> "max_vq_size": 256 >>>>>>>>> } >>>>>>>>> } >>>>>>>>> } >>>>>>>> I'd like an example of how do device specific (e.g. net >>>>>>>> specific) interfaces tie in to this. >>>>>>> Not sure I follow your question. >>>>>>> Do you mean how to set mac address or mtu of this vdpa device of >>>>>>> type >>>>>> net? >>>>>>> If so, dev add command will be extended shortly in subsequent >>>>>>> series to >>>>>> set this net specific attributes. >>>>>>> (I did mention in the next steps in cover letter). >>>>>>> >>>>>>>>> +static int __init vdpasim_net_init(void) { >>>>>>>>> + int ret; >>>>>>>>> + >>>>>>>>> + if (macaddr) { >>>>>>>>> + mac_pton(macaddr, macaddr_buf); >>>>>>>>> + if (!is_valid_ether_addr(macaddr_buf)) >>>>>>>>> + return -EADDRNOTAVAIL; >>>>>>>>> + } else { >>>>>>>>> + eth_random_addr(macaddr_buf); >>>>>>>>> } >>>>>>>> Hmm so all devices start out with the same MAC until changed? >>>>>>>> And how is the change effected? >>>>>>> Post this patchset and post we have iproute2 vdpa in the tree, >>>>>>> will add the >>>>>> mac address as the input attribute during "vdpa dev add" command. >>>>>>> So that each different vdpa device can have user specified >>>>>>> (different) mac >>>>>> address. >>>>>> >>>>>> For now maybe just avoid VIRTIO_NET_F_MAC then for new devices >>>> then? >>>>> That would require book keeping existing net vdpa_sim devices >>>>> created to >>>> avoid setting VIRTIO_NET_F_MAC. >>>>> Such book keeping code will be short lived anyway. >>>>> Not sure if its worth it. >>>>> Until now only one device was created. So not sure two vdpa devices >>>>> with >>>> same mac address will be a real issue. >>>>> When we add mac address attribute in add command, at that point also >>>> remove the module parameter macaddr. >>>> >>>> Will that be mandatory? I'm not to happy with a UAPI we intend to >>>> break straight away ... >>> No. Specifying mac address shouldn't be mandatory. UAPI wont' be >> broken. >> >> >> If it's not mandatory. Does it mean the vDPA parent need to use its own logic >> to generate a validate mac? I'm not sure this is what management (libvirt >> want). >> > There are few use cases that I see with PFs, VFs and SFs supporting vdpa devices. > > 1. User wants to use the VF only for vdpa purpose. Here user got the VF which was pre-setup by the sysadmin. > In this case whatever MAC assigned to the VF can be used by its vdpa device. > Here, user doesn't need to pass the mac address during vdpa device creation time. > This is done as the same MAC has been setup in the ACL rules on the switch side. > Non VDPA users of a VF typically use the VF this way for Netdev and rdma functionality. > They might continue same way for vdpa application as well. > Here VF mac is either set using > (a) devlink port function set hw_addr command or using > (b) ip link set vf mac > So vdpa tool didn't pass the mac. (optional). > Though VIRTIO_NET_F_MAC is still valid. > > 2. User may want to create one or more vdpa device out of the mgmt. device. > Here user wants to more/full control of all features, overriding what sysadmin has setup as MAC of the VF/SF. > In this case user will specify the MAC via mgmt tool. > (a) This is also used by those vdpa devices which doesn't have eswitch offloads. > (b) This will work with eswitch offloads as well who does source learning. > (c) User chose to use the vdpa device of a VF while VF Netdev and rdma device are used by hypervisor for something else as well. > VIRTIO_NET_F_MAC remains valid in all 2.{a,b,c}. > > 3. A vendor mgmt. device always expects it user to provide mac for its vdpa devices. > So when it is not provided, it can fail with error message string in extack or clear the VIRTIO_NET_F_MAC and let it work using virtio spec's 5.1.5 point 5 to proceed. > > As common denominator of all above cases, if QEMU or user pass the MAC during creation, it will almost always work. > Advance user and QEMU with switchdev mode support who has done 1.a/1.b, will omit it. > I do not know how deep integration of QEMU exist with the switchdev mode support. > > With that mac, mtu as optional input fields provide the necessary flexibility for different stacks to take appropriate shape as they desire. Thanks for the clarification. I think we'd better document the above in the patch that introduces the mac setting from management API. >
> From: Jason Wang <jasowang@redhat.com> > Sent: Friday, January 15, 2021 11:09 AM > > > On 2021/1/14 下午3:58, Parav Pandit wrote: > > > >> From: Jason Wang <jasowang@redhat.com> > >> Sent: Thursday, January 14, 2021 9:48 AM > >> > >> On 2021/1/7 上午11:48, Parav Pandit wrote: > >>>> From: Michael S. Tsirkin <mst@redhat.com> > >>>> Sent: Tuesday, January 5, 2021 6:53 PM > >>>> > >>>> On Tue, Jan 05, 2021 at 12:30:15PM +0000, Parav Pandit wrote: > >>>>>> From: Michael S. Tsirkin <mst@redhat.com> > >>>>>> Sent: Tuesday, January 5, 2021 5:45 PM > >>>>>> > >>>>>> On Tue, Jan 05, 2021 at 12:02:33PM +0000, Parav Pandit wrote: > >>>>>>>> From: Michael S. Tsirkin <mst@redhat.com> > >>>>>>>> Sent: Tuesday, January 5, 2021 5:19 PM > >>>>>>>> > >>>>>>>> On Tue, Jan 05, 2021 at 12:32:03PM +0200, Parav Pandit wrote: > >>>>>>>>> Enable user to create vdpasim net simulate devices. > >>>>>>>>> > >>>>>>>>> > >>>>>>>>> $ vdpa dev add mgmtdev vdpasim_net name foo2 > >>>>>>>>> > >>>>>>>>> Show the newly created vdpa device by its name: > >>>>>>>>> $ vdpa dev show foo2 > >>>>>>>>> foo2: type network mgmtdev vdpasim_net vendor_id 0 > max_vqs 2 > >>>>>>>>> max_vq_size 256 > >>>>>>>>> > >>>>>>>>> $ vdpa dev show foo2 -jp > >>>>>>>>> { > >>>>>>>>> "dev": { > >>>>>>>>> "foo2": { > >>>>>>>>> "type": "network", > >>>>>>>>> "mgmtdev": "vdpasim_net", > >>>>>>>>> "vendor_id": 0, > >>>>>>>>> "max_vqs": 2, > >>>>>>>>> "max_vq_size": 256 > >>>>>>>>> } > >>>>>>>>> } > >>>>>>>>> } > >>>>>>>> I'd like an example of how do device specific (e.g. net > >>>>>>>> specific) interfaces tie in to this. > >>>>>>> Not sure I follow your question. > >>>>>>> Do you mean how to set mac address or mtu of this vdpa device of > >>>>>>> type > >>>>>> net? > >>>>>>> If so, dev add command will be extended shortly in subsequent > >>>>>>> series to > >>>>>> set this net specific attributes. > >>>>>>> (I did mention in the next steps in cover letter). > >>>>>>> > >>>>>>>>> +static int __init vdpasim_net_init(void) { > >>>>>>>>> + int ret; > >>>>>>>>> + > >>>>>>>>> + if (macaddr) { > >>>>>>>>> + mac_pton(macaddr, macaddr_buf); > >>>>>>>>> + if (!is_valid_ether_addr(macaddr_buf)) > >>>>>>>>> + return -EADDRNOTAVAIL; > >>>>>>>>> + } else { > >>>>>>>>> + eth_random_addr(macaddr_buf); > >>>>>>>>> } > >>>>>>>> Hmm so all devices start out with the same MAC until changed? > >>>>>>>> And how is the change effected? > >>>>>>> Post this patchset and post we have iproute2 vdpa in the tree, > >>>>>>> will add the > >>>>>> mac address as the input attribute during "vdpa dev add" command. > >>>>>>> So that each different vdpa device can have user specified > >>>>>>> (different) mac > >>>>>> address. > >>>>>> > >>>>>> For now maybe just avoid VIRTIO_NET_F_MAC then for new devices > >>>> then? > >>>>> That would require book keeping existing net vdpa_sim devices > >>>>> created to > >>>> avoid setting VIRTIO_NET_F_MAC. > >>>>> Such book keeping code will be short lived anyway. > >>>>> Not sure if its worth it. > >>>>> Until now only one device was created. So not sure two vdpa > >>>>> devices with > >>>> same mac address will be a real issue. > >>>>> When we add mac address attribute in add command, at that point > >>>>> also > >>>> remove the module parameter macaddr. > >>>> > >>>> Will that be mandatory? I'm not to happy with a UAPI we intend to > >>>> break straight away ... > >>> No. Specifying mac address shouldn't be mandatory. UAPI wont' be > >> broken. > >> > >> > >> If it's not mandatory. Does it mean the vDPA parent need to use its > >> own logic to generate a validate mac? I'm not sure this is what > >> management (libvirt want). > >> > > There are few use cases that I see with PFs, VFs and SFs supporting vdpa > devices. > > > > 1. User wants to use the VF only for vdpa purpose. Here user got the VF > which was pre-setup by the sysadmin. > > In this case whatever MAC assigned to the VF can be used by its vdpa > device. > > Here, user doesn't need to pass the mac address during vdpa device > creation time. > > This is done as the same MAC has been setup in the ACL rules on the switch > side. > > Non VDPA users of a VF typically use the VF this way for Netdev and rdma > functionality. > > They might continue same way for vdpa application as well. > > Here VF mac is either set using > > (a) devlink port function set hw_addr command or using > > (b) ip link set vf mac > > So vdpa tool didn't pass the mac. (optional). > > Though VIRTIO_NET_F_MAC is still valid. > > > > 2. User may want to create one or more vdpa device out of the mgmt. > device. > > Here user wants to more/full control of all features, overriding what > sysadmin has setup as MAC of the VF/SF. > > In this case user will specify the MAC via mgmt tool. > > (a) This is also used by those vdpa devices which doesn't have eswitch > offloads. > > (b) This will work with eswitch offloads as well who does source learning. > > (c) User chose to use the vdpa device of a VF while VF Netdev and rdma > device are used by hypervisor for something else as well. > > VIRTIO_NET_F_MAC remains valid in all 2.{a,b,c}. > > > > 3. A vendor mgmt. device always expects it user to provide mac for its > vdpa devices. > > So when it is not provided, it can fail with error message string in extack or > clear the VIRTIO_NET_F_MAC and let it work using virtio spec's 5.1.5 point 5 > to proceed. > > > > As common denominator of all above cases, if QEMU or user pass the MAC > during creation, it will almost always work. > > Advance user and QEMU with switchdev mode support who has done > 1.a/1.b, will omit it. > > I do not know how deep integration of QEMU exist with the switchdev > mode support. > > > > With that mac, mtu as optional input fields provide the necessary flexibility > for different stacks to take appropriate shape as they desire. > > > Thanks for the clarification. I think we'd better document the above in the > patch that introduces the mac setting from management API. Yes. Will do. Thanks.
Hi Michael, Jason, > From: Jason Wang <jasowang@redhat.com> > Sent: Friday, January 15, 2021 11:09 AM > > > Thanks for the clarification. I think we'd better document the above in the > patch that introduces the mac setting from management API. Can we proceed with this patchset? We like to progress next to iproute2/vdpa, mac and other drivers post this series in this kernel version.
On 2021/1/15 下午2:27, Parav Pandit wrote: >>> With that mac, mtu as optional input fields provide the necessary flexibility >> for different stacks to take appropriate shape as they desire. >> >> >> Thanks for the clarification. I think we'd better document the above in the >> patch that introduces the mac setting from management API. > Yes. Will do. > Thanks. Adding Sean. Regarding to mac address setting. Do we plan to allow to modify mac address after the creation? It looks like Openstack wants this. Sean may share more information on this. Thanks
> From: Jason Wang <jasowang@redhat.com> > Sent: Tuesday, January 19, 2021 4:39 PM > To: Parav Pandit <parav@nvidia.com>; Michael S. Tsirkin <mst@redhat.com> > Cc: virtualization@lists.linux-foundation.org; Eli Cohen <elic@nvidia.com>; > netdev@vger.kernel.org; Sean Mooney <smooney@redhat.com> > Subject: Re: [PATCH linux-next v3 6/6] vdpa_sim_net: Add support for user > supported devices > > > On 2021/1/15 下午2:27, Parav Pandit wrote: > >>> With that mac, mtu as optional input fields provide the necessary > >>> flexibility > >> for different stacks to take appropriate shape as they desire. > >> > >> > >> Thanks for the clarification. I think we'd better document the above > >> in the patch that introduces the mac setting from management API. > > Yes. Will do. > > Thanks. > > > Adding Sean. > > Regarding to mac address setting. Do we plan to allow to modify mac > address after the creation? It looks like Openstack wants this. > Mac address is exposed in the features so yes, it should be possible to modify it as part of features modify command. (in future). User needs to make sure that device is not attached to vhost or higher layer stack when device configuration layout is modified. > Sean may share more information on this. > > Thanks
> From: Virtualization <virtualization-bounces@lists.linux-foundation.org> On > Behalf Of Parav Pandit > > > From: Jason Wang <jasowang@redhat.com> > > Sent: Tuesday, January 19, 2021 4:39 PM > > To: Parav Pandit <parav@nvidia.com>; Michael S. Tsirkin > > <mst@redhat.com> > > Cc: virtualization@lists.linux-foundation.org; Eli Cohen > > <elic@nvidia.com>; netdev@vger.kernel.org; Sean Mooney > > <smooney@redhat.com> > > Subject: Re: [PATCH linux-next v3 6/6] vdpa_sim_net: Add support for > > user supported devices > > > > > > On 2021/1/15 下午2:27, Parav Pandit wrote: > > >>> With that mac, mtu as optional input fields provide the necessary > > >>> flexibility > > >> for different stacks to take appropriate shape as they desire. > > >> > > >> > > >> Thanks for the clarification. I think we'd better document the > > >> above in the patch that introduces the mac setting from management > API. > > > Yes. Will do. > > > Thanks. > > > > > > Adding Sean. > > > > Regarding to mac address setting. Do we plan to allow to modify mac > > address after the creation? It looks like Openstack wants this. > > > Mac address is exposed in the features so yes, it should be possible to > modify it as part of features modify command. (in future). > User needs to make sure that device is not attached to vhost or higher layer > stack when device configuration layout is modified. > Just curious, why Openstack cannot set the mac address at device creation time? Is vdpa device created by non Openstack software? Does it always want to set the mac address of vdpa device? > > Sean may share more information on this.
On Mon, Jan 18, 2021 at 06:03:57PM +0000, Parav Pandit wrote: > Hi Michael, Jason, > > > From: Jason Wang <jasowang@redhat.com> > > Sent: Friday, January 15, 2021 11:09 AM > > > > > > Thanks for the clarification. I think we'd better document the above in the > > patch that introduces the mac setting from management API. > > Can we proceed with this patchset? > We like to progress next to iproute2/vdpa, mac and other drivers post this series in this kernel version. Let me put this in next so it can get some testing there for a week or so.
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index db1636a99ba4..d5942842432d 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -235,7 +235,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) ops = &vdpasim_config_ops; vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, - dev_attr->nvqs, NULL); + dev_attr->nvqs, dev_attr->name); if (!vdpasim) goto err_alloc; @@ -249,6 +249,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) goto err_iommu; set_dma_ops(dev, &vdpasim_dma_ops); + vdpasim->vdpa.mdev = dev_attr->mgmt_dev; vdpasim->config = kzalloc(dev_attr->config_size, GFP_KERNEL); if (!vdpasim->config) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index b02142293d5b..6d75444f9948 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -33,6 +33,8 @@ struct vdpasim_virtqueue { }; struct vdpasim_dev_attr { + struct vdpa_mgmt_dev *mgmt_dev; + const char *name; u64 supported_features; size_t config_size; size_t buffer_size; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index f0482427186b..d344c5b7c914 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -35,8 +35,6 @@ MODULE_PARM_DESC(macaddr, "Ethernet MAC address"); static u8 macaddr_buf[ETH_ALEN]; -static struct vdpasim *vdpasim_net_dev; - static void vdpasim_net_work(struct work_struct *work) { struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); @@ -120,21 +118,23 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config) memcpy(net_config->mac, macaddr_buf, ETH_ALEN); } -static int __init vdpasim_net_init(void) +static void vdpasim_net_mgmtdev_release(struct device *dev) +{ +} + +static struct device vdpasim_net_mgmtdev = { + .init_name = "vdpasim_net", + .release = vdpasim_net_mgmtdev_release, +}; + +static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) { struct vdpasim_dev_attr dev_attr = {}; + struct vdpasim *simdev; int ret; - if (macaddr) { - mac_pton(macaddr, macaddr_buf); - if (!is_valid_ether_addr(macaddr_buf)) { - ret = -EADDRNOTAVAIL; - goto out; - } - } else { - eth_random_addr(macaddr_buf); - } - + dev_attr.mgmt_dev = mdev; + dev_attr.name = name; dev_attr.id = VIRTIO_ID_NET; dev_attr.supported_features = VDPASIM_NET_FEATURES; dev_attr.nvqs = VDPASIM_NET_VQ_NUM; @@ -143,29 +143,75 @@ static int __init vdpasim_net_init(void) dev_attr.work_fn = vdpasim_net_work; dev_attr.buffer_size = PAGE_SIZE; - vdpasim_net_dev = vdpasim_create(&dev_attr); - if (IS_ERR(vdpasim_net_dev)) { - ret = PTR_ERR(vdpasim_net_dev); - goto out; + simdev = vdpasim_create(&dev_attr); + if (IS_ERR(simdev)) + return PTR_ERR(simdev); + + ret = _vdpa_register_device(&simdev->vdpa); + if (ret) + goto reg_err; + + return 0; + +reg_err: + put_device(&simdev->vdpa.dev); + return ret; +} + +static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev, + struct vdpa_device *dev) +{ + struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa); + + _vdpa_unregister_device(&simdev->vdpa); +} + +static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = { + .dev_add = vdpasim_net_dev_add, + .dev_del = vdpasim_net_dev_del +}; + +static struct virtio_device_id id_table[] = { + { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, + { 0 }, +}; + +static struct vdpa_mgmt_dev mgmt_dev = { + .device = &vdpasim_net_mgmtdev, + .id_table = id_table, + .ops = &vdpasim_net_mgmtdev_ops, +}; + +static int __init vdpasim_net_init(void) +{ + int ret; + + if (macaddr) { + mac_pton(macaddr, macaddr_buf); + if (!is_valid_ether_addr(macaddr_buf)) + return -EADDRNOTAVAIL; + } else { + eth_random_addr(macaddr_buf); } - ret = vdpa_register_device(&vdpasim_net_dev->vdpa); + ret = device_register(&vdpasim_net_mgmtdev); if (ret) - goto put_dev; + return ret; + ret = vdpa_mgmtdev_register(&mgmt_dev); + if (ret) + goto parent_err; return 0; -put_dev: - put_device(&vdpasim_net_dev->vdpa.dev); -out: +parent_err: + device_unregister(&vdpasim_net_mgmtdev); return ret; } static void __exit vdpasim_net_exit(void) { - struct vdpa_device *vdpa = &vdpasim_net_dev->vdpa; - - vdpa_unregister_device(vdpa); + vdpa_mgmtdev_unregister(&mgmt_dev); + device_unregister(&vdpasim_net_mgmtdev); } module_init(vdpasim_net_init);