mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
vfio/platform: Use open_device() instead of open coding a refcnt scheme
Platform simply wants to run some code when the device is first opened/last closed. Use the core framework and locking for this. Aside from removing a bit of code this narrows the locking scope from a global lock. Reviewed-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Link: https://lore.kernel.org/r/7-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
da119f387e
commit
ab7e5e34a9
2 changed files with 40 additions and 56 deletions
|
@ -218,45 +218,35 @@ static int vfio_platform_call_reset(struct vfio_platform_device *vdev,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vfio_platform_release(struct vfio_device *core_vdev)
|
static void vfio_platform_close_device(struct vfio_device *core_vdev)
|
||||||
{
|
{
|
||||||
struct vfio_platform_device *vdev =
|
struct vfio_platform_device *vdev =
|
||||||
container_of(core_vdev, struct vfio_platform_device, vdev);
|
container_of(core_vdev, struct vfio_platform_device, vdev);
|
||||||
|
|
||||||
mutex_lock(&driver_lock);
|
|
||||||
|
|
||||||
if (!(--vdev->refcnt)) {
|
|
||||||
const char *extra_dbg = NULL;
|
const char *extra_dbg = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = vfio_platform_call_reset(vdev, &extra_dbg);
|
ret = vfio_platform_call_reset(vdev, &extra_dbg);
|
||||||
if (ret && vdev->reset_required) {
|
if (WARN_ON(ret && vdev->reset_required)) {
|
||||||
dev_warn(vdev->device, "reset driver is required and reset call failed in release (%d) %s\n",
|
dev_warn(
|
||||||
|
vdev->device,
|
||||||
|
"reset driver is required and reset call failed in release (%d) %s\n",
|
||||||
ret, extra_dbg ? extra_dbg : "");
|
ret, extra_dbg ? extra_dbg : "");
|
||||||
WARN_ON(1);
|
|
||||||
}
|
}
|
||||||
pm_runtime_put(vdev->device);
|
pm_runtime_put(vdev->device);
|
||||||
vfio_platform_regions_cleanup(vdev);
|
vfio_platform_regions_cleanup(vdev);
|
||||||
vfio_platform_irq_cleanup(vdev);
|
vfio_platform_irq_cleanup(vdev);
|
||||||
}
|
|
||||||
|
|
||||||
mutex_unlock(&driver_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vfio_platform_open(struct vfio_device *core_vdev)
|
static int vfio_platform_open_device(struct vfio_device *core_vdev)
|
||||||
{
|
{
|
||||||
struct vfio_platform_device *vdev =
|
struct vfio_platform_device *vdev =
|
||||||
container_of(core_vdev, struct vfio_platform_device, vdev);
|
container_of(core_vdev, struct vfio_platform_device, vdev);
|
||||||
int ret;
|
|
||||||
|
|
||||||
mutex_lock(&driver_lock);
|
|
||||||
|
|
||||||
if (!vdev->refcnt) {
|
|
||||||
const char *extra_dbg = NULL;
|
const char *extra_dbg = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
ret = vfio_platform_regions_init(vdev);
|
ret = vfio_platform_regions_init(vdev);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_reg;
|
return ret;
|
||||||
|
|
||||||
ret = vfio_platform_irq_init(vdev);
|
ret = vfio_platform_irq_init(vdev);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -268,15 +258,12 @@ static int vfio_platform_open(struct vfio_device *core_vdev)
|
||||||
|
|
||||||
ret = vfio_platform_call_reset(vdev, &extra_dbg);
|
ret = vfio_platform_call_reset(vdev, &extra_dbg);
|
||||||
if (ret && vdev->reset_required) {
|
if (ret && vdev->reset_required) {
|
||||||
dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n",
|
dev_warn(
|
||||||
|
vdev->device,
|
||||||
|
"reset driver is required and reset call failed in open (%d) %s\n",
|
||||||
ret, extra_dbg ? extra_dbg : "");
|
ret, extra_dbg ? extra_dbg : "");
|
||||||
goto err_rst;
|
goto err_rst;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
vdev->refcnt++;
|
|
||||||
|
|
||||||
mutex_unlock(&driver_lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_rst:
|
err_rst:
|
||||||
|
@ -284,8 +271,6 @@ err_rst:
|
||||||
vfio_platform_irq_cleanup(vdev);
|
vfio_platform_irq_cleanup(vdev);
|
||||||
err_irq:
|
err_irq:
|
||||||
vfio_platform_regions_cleanup(vdev);
|
vfio_platform_regions_cleanup(vdev);
|
||||||
err_reg:
|
|
||||||
mutex_unlock(&driver_lock);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,8 +601,8 @@ static int vfio_platform_mmap(struct vfio_device *core_vdev, struct vm_area_stru
|
||||||
|
|
||||||
static const struct vfio_device_ops vfio_platform_ops = {
|
static const struct vfio_device_ops vfio_platform_ops = {
|
||||||
.name = "vfio-platform",
|
.name = "vfio-platform",
|
||||||
.open = vfio_platform_open,
|
.open_device = vfio_platform_open_device,
|
||||||
.release = vfio_platform_release,
|
.close_device = vfio_platform_close_device,
|
||||||
.ioctl = vfio_platform_ioctl,
|
.ioctl = vfio_platform_ioctl,
|
||||||
.read = vfio_platform_read,
|
.read = vfio_platform_read,
|
||||||
.write = vfio_platform_write,
|
.write = vfio_platform_write,
|
||||||
|
|
|
@ -48,7 +48,6 @@ struct vfio_platform_device {
|
||||||
u32 num_regions;
|
u32 num_regions;
|
||||||
struct vfio_platform_irq *irqs;
|
struct vfio_platform_irq *irqs;
|
||||||
u32 num_irqs;
|
u32 num_irqs;
|
||||||
int refcnt;
|
|
||||||
struct mutex igate;
|
struct mutex igate;
|
||||||
const char *compat;
|
const char *compat;
|
||||||
const char *acpihid;
|
const char *acpihid;
|
||||||
|
|
Loading…
Add table
Reference in a new issue