On 2020/3/18 下午8:22, Jason Gunthorpe wrote:
On Wed, Mar 18, 2020 at 04:03:27PM +0800, Jason Wang wrote:
From: Zhu Lingshan <lingshan.zhu@xxxxxxxxx>
+
+static int ifcvf_vdpa_attach(struct ifcvf_adapter *adapter)
+{
+ int ret;
+
+ adapter->vdpa_dev = vdpa_alloc_device(adapter->dev, adapter->dev,
+ &ifc_vdpa_ops);
+ if (IS_ERR(adapter->vdpa_dev)) {
+ IFCVF_ERR(adapter->dev, "Failed to init ifcvf on vdpa bus");
+ put_device(&adapter->vdpa_dev->dev);
+ return -ENODEV;
+ }
The point of having an alloc call is so that the drivers
ifcvf_adaptor memory could be placed in the same struct - eg use
container_of to flip between them, and have a kref for both memories.
It seem really weird to have an alloc followed immediately by
register.
I admit the ifcvf_adapter is not correctly ref-counted. What you suggest
should work. But it looks to me the following is more cleaner since the
members of ifcvf_adapter are all related to PCI device not vDPA itself.
- keep the current layout of ifcvf_adapter
- merge vdpa_alloc_device() and vdpa_register_device()
- use devres to bind ifcvf_adapter refcnt/lifcycle to the under PCI device
If we go for the container_of method, we probably need
- accept a size of parent parent structure in vdpa_alloc_device() and
mandate vdpa_device to be the first member of ifcvf_adapter
- we need provide a way to free resources of parent structure when we
destroy vDPA device
What's your thought?
diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index c30eb55030be..de64b88ee7e4 100644
+++ b/drivers/virtio/virtio_vdpa.c
@@ -362,6 +362,7 @@ static int virtio_vdpa_probe(struct vdpa_device *vdpa)
goto err;
vdpa_set_drvdata(vdpa, vd_dev);
+ dev_info(vd_dev->vdev.dev.parent, "device attached to VDPA bus\n");
return 0;
This hunk seems out of place
Jason
Right, will fix.
Thanks
_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization