mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-18 03:23:53 -04:00
vfio: Introduce a vfio_uninit_group_dev() API call
This pairs with vfio_init_group_dev() and allows undoing any state that is stored in the vfio_device unrelated to registration. Add appropriately placed calls to all the drivers. The following patch will use this to add pre-registration state for the device set. Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/3-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
committed by
Alex Williamson
parent
de5494af48
commit
ae03c3771b
@@ -559,6 +559,7 @@ static int mbochs_probe(struct mdev_device *mdev)
|
||||
dev_set_drvdata(&mdev->dev, mdev_state);
|
||||
return 0;
|
||||
err_mem:
|
||||
vfio_uninit_group_dev(&mdev_state->vdev);
|
||||
kfree(mdev_state->pages);
|
||||
kfree(mdev_state->vconfig);
|
||||
kfree(mdev_state);
|
||||
@@ -572,6 +573,7 @@ static void mbochs_remove(struct mdev_device *mdev)
|
||||
struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev);
|
||||
|
||||
vfio_unregister_group_dev(&mdev_state->vdev);
|
||||
vfio_uninit_group_dev(&mdev_state->vdev);
|
||||
atomic_add(mdev_state->type->mbytes, &mbochs_avail_mbytes);
|
||||
kfree(mdev_state->pages);
|
||||
kfree(mdev_state->vconfig);
|
||||
|
||||
@@ -235,17 +235,16 @@ static int mdpy_probe(struct mdev_device *mdev)
|
||||
|
||||
mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL);
|
||||
if (mdev_state->vconfig == NULL) {
|
||||
kfree(mdev_state);
|
||||
return -ENOMEM;
|
||||
ret = -ENOMEM;
|
||||
goto err_state;
|
||||
}
|
||||
|
||||
fbsize = roundup_pow_of_two(type->width * type->height * type->bytepp);
|
||||
|
||||
mdev_state->memblk = vmalloc_user(fbsize);
|
||||
if (!mdev_state->memblk) {
|
||||
kfree(mdev_state->vconfig);
|
||||
kfree(mdev_state);
|
||||
return -ENOMEM;
|
||||
ret = -ENOMEM;
|
||||
goto err_vconfig;
|
||||
}
|
||||
dev_info(dev, "%s: %s (%dx%d)\n", __func__, type->name, type->width,
|
||||
type->height);
|
||||
@@ -260,13 +259,18 @@ static int mdpy_probe(struct mdev_device *mdev)
|
||||
mdpy_count++;
|
||||
|
||||
ret = vfio_register_group_dev(&mdev_state->vdev);
|
||||
if (ret) {
|
||||
kfree(mdev_state->vconfig);
|
||||
kfree(mdev_state);
|
||||
return ret;
|
||||
}
|
||||
if (ret)
|
||||
goto err_mem;
|
||||
dev_set_drvdata(&mdev->dev, mdev_state);
|
||||
return 0;
|
||||
err_mem:
|
||||
vfree(mdev_state->memblk);
|
||||
err_vconfig:
|
||||
kfree(mdev_state->vconfig);
|
||||
err_state:
|
||||
vfio_uninit_group_dev(&mdev_state->vdev);
|
||||
kfree(mdev_state);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void mdpy_remove(struct mdev_device *mdev)
|
||||
@@ -278,6 +282,7 @@ static void mdpy_remove(struct mdev_device *mdev)
|
||||
vfio_unregister_group_dev(&mdev_state->vdev);
|
||||
vfree(mdev_state->memblk);
|
||||
kfree(mdev_state->vconfig);
|
||||
vfio_uninit_group_dev(&mdev_state->vdev);
|
||||
kfree(mdev_state);
|
||||
|
||||
mdpy_count--;
|
||||
|
||||
@@ -718,8 +718,8 @@ static int mtty_probe(struct mdev_device *mdev)
|
||||
|
||||
mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL);
|
||||
if (mdev_state == NULL) {
|
||||
atomic_add(nr_ports, &mdev_avail_ports);
|
||||
return -ENOMEM;
|
||||
ret = -ENOMEM;
|
||||
goto err_nr_ports;
|
||||
}
|
||||
|
||||
vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mtty_dev_ops);
|
||||
@@ -732,9 +732,8 @@ static int mtty_probe(struct mdev_device *mdev)
|
||||
mdev_state->vconfig = kzalloc(MTTY_CONFIG_SPACE_SIZE, GFP_KERNEL);
|
||||
|
||||
if (mdev_state->vconfig == NULL) {
|
||||
kfree(mdev_state);
|
||||
atomic_add(nr_ports, &mdev_avail_ports);
|
||||
return -ENOMEM;
|
||||
ret = -ENOMEM;
|
||||
goto err_state;
|
||||
}
|
||||
|
||||
mutex_init(&mdev_state->ops_lock);
|
||||
@@ -743,14 +742,19 @@ static int mtty_probe(struct mdev_device *mdev)
|
||||
mtty_create_config_space(mdev_state);
|
||||
|
||||
ret = vfio_register_group_dev(&mdev_state->vdev);
|
||||
if (ret) {
|
||||
kfree(mdev_state);
|
||||
atomic_add(nr_ports, &mdev_avail_ports);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ret)
|
||||
goto err_vconfig;
|
||||
dev_set_drvdata(&mdev->dev, mdev_state);
|
||||
return 0;
|
||||
|
||||
err_vconfig:
|
||||
kfree(mdev_state->vconfig);
|
||||
err_state:
|
||||
vfio_uninit_group_dev(&mdev_state->vdev);
|
||||
kfree(mdev_state);
|
||||
err_nr_ports:
|
||||
atomic_add(nr_ports, &mdev_avail_ports);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void mtty_remove(struct mdev_device *mdev)
|
||||
@@ -761,6 +765,7 @@ static void mtty_remove(struct mdev_device *mdev)
|
||||
vfio_unregister_group_dev(&mdev_state->vdev);
|
||||
|
||||
kfree(mdev_state->vconfig);
|
||||
vfio_uninit_group_dev(&mdev_state->vdev);
|
||||
kfree(mdev_state);
|
||||
atomic_add(nr_ports, &mdev_avail_ports);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user