vfio: Split creation of a vfio_device into init and register ops
stable inclusion from stable-v5.10.137 commit a2fbf4acd28069d4922c33e4b5b0d58fc38073f8 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I60PLB Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a2fbf4acd28069d4922c33e4b5b0d58fc38073f8 -------------------------------- [ Upstream commit 0bfc6a4e ] This makes the struct vfio_device part of the public interface so it can be used with container_of and so forth, as is typical for a Linux subystem. This is the first step to bring some type-safety to the vfio interface by allowing the replacement of 'void *' and 'struct device *' inputs with a simple and clear 'struct vfio_device *' For now the self-allocating vfio_add_group_dev() interface is kept so each user can be updated as a separate patch. The expected usage pattern is driver core probe() function: my_device = kzalloc(sizeof(*mydevice)); vfio_init_group_dev(&my_device->vdev, dev, ops, mydevice); /* other driver specific prep */ vfio_register_group_dev(&my_device->vdev); dev_set_drvdata(dev, my_device); driver core remove() function: my_device = dev_get_drvdata(dev); vfio_unregister_group_dev(&my_device->vdev); /* other driver specific tear down */ kfree(my_device); Allowing the driver to be able to use the drvdata and vfio_device to go to/from its own data. The pattern also makes it clear that vfio_register_group_dev() must be last in the sequence, as once it is called the core code can immediately start calling ops. The init/register gap is provided to allow for the driver to do setup before ops can be called and thus avoid races. Reviewed-by: NChristoph Hellwig <hch@lst.de> Reviewed-by: NLiu Yi L <yi.l.liu@intel.com> Reviewed-by: NCornelia Huck <cohuck@redhat.com> Reviewed-by: NMax Gurtovoy <mgurtovoy@nvidia.com> Reviewed-by: NKevin Tian <kevin.tian@intel.com> Reviewed-by: NEric Auger <eric.auger@redhat.com> Signed-off-by: NJason Gunthorpe <jgg@nvidia.com> Message-Id: <3-v3-225de1400dfc+4e074-vfio1_jgg@nvidia.com> Signed-off-by: NAlex Williamson <alex.williamson@redhat.com> Signed-off-by: NSasha Levin <sashal@kernel.org> Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com> Reviewed-by: NWei Li <liwei391@huawei.com>
Showing
想要评论请 注册 或 登录