vfio/ap_ops: Add missed vfio_uninit_group_dev()
Subsystems (4)
PATCH v3 1/1 vfio/ap_ops: Add missed vfio_uninit_group_dev()
Without this call an xarray entry is leaked when the vfio_ap device is unprobed. It was missed when the below patch was rebased across the dev_set patch. Keep the remove function in the same order as the error unwind in probe.
--- drivers/s390/crypto/vfio_ap_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
v3:
- Keep the remove sequence the same as remove to avoid a lockdep splat
v2: https://lore.kernel.org/r/[email protected]/
- Fix corrupted diff
v1: https://lore.kernel.org/r/[email protected]/
drivers/s390/crypto/vfio_ap_ops.c +3 -1
@@ -361,6 +361,7 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);list_del (&matrix_mdev->node);mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev); err_dec_available:atomic_inc (&matrix_dev->available_instances);
@@ -376,9 +377,10 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);vfio_ap_mdev_reset_queues (matrix_mdev);list_del (&matrix_mdev->node); +mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev);atomic_inc (&matrix_dev->available_instances); -mutex_unlock (&matrix_dev->lock); } static ssize_t name_show(struct mdev_type *mtype,
base-commit: 6880fa6c56601bb8ed59df6c30fd390cc5f6dd8f
Signature · 1 line
2.33.0
Tony Krowiak
maintainerQuoted 32 lines · Jason Gunthorpe
Without this call an xarray entry is leaked when the
vfio_apdevice is unprobed. It was missed when the below patch was rebased across thedev_setpatch. Keep the remove function in the same order as the error unwind in probe.Fixes eb0feefd4c02 ("vfio/ap_ops: Convert to use vfio_register_group_dev()")Reviewed-by Christoph Hellwig <[email protected]>Tested-by Tony Krowiak <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>--- drivers/s390/crypto/vfio_ap_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)v3:
- Keep the remove sequence the same as remove to avoid a lockdep splat
v2: https://lore.kernel.org/r/[email protected]/
- Fix corrupted diff
v1: https://lore.kernel.org/r/[email protected]/drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -361,6 +361,7 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);list_del (&matrix_mdev->node);mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev); err_dec_available:atomic_inc (&matrix_dev->available_instances);
drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_remove(struct mdev_device *mdev) · line 383
Quoted 7 lines
drivers/s390/crypto/vfio_ap_ops.c +2
-0@@ -376,9 +377,10 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);vfio_ap_mdev_reset_queues (matrix_mdev);list_del (&matrix_mdev->node); +mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev);atomic_inc (&matrix_dev->available_instances);
I think the above line of code should be done under the matrix_dev->lock after removing the matrix_mdev from the list since it is changing a value in matrix_dev.
Quoted 6 lines
drivers/s390/crypto/vfio_ap_ops.c +0
-1-mutex_unlock (&matrix_dev->lock); } static ssize_t name_show(struct mdev_type *mtype,base-commit:
6880fa6c56601bb8ed59df6c30fd390cc5f6dd8f
Quoted 36 lines · Tony Krowiak
Quoted 33 lines · Jason Gunthorpe
Without this call an xarray entry is leaked when the
vfio_apdevice is unprobed. It was missed when the below patch was rebased across thedev_setpatch. Keep the remove function in the same order as the error unwind in probe.Fixes eb0feefd4c02 ("vfio/ap_ops: Convert to use vfio_register_group_dev()")Reviewed-by Christoph Hellwig <[email protected]>Tested-by Tony Krowiak <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>drivers/s390/crypto/vfio_ap_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)v3:
- Keep the remove sequence the same as remove to avoid a lockdep splat
v2: https://lore.kernel.org/r/[email protected]/
- Fix corrupted diff
v1: https://lore.kernel.org/r/[email protected]/drivers/s390/crypto/vfio_ap_ops.c +2
-0+++ b/drivers/s390/crypto/vfio_ap_ops.c@@ -361,6 +361,7 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);list_del (&matrix_mdev->node);mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev); err_dec_available:atomic_inc (&matrix_dev->available_instances);@@ -376,9 +377,10 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);vfio_ap_mdev_reset_queues (matrix_mdev);list_del (&matrix_mdev->node);
Quoted 8 lines
drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_remove(struct mdev_device *mdev) · line 383
Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +2
-0+mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev);atomic_inc (&matrix_dev->available_instances);I think the above line of code should be done under the
matrix_dev->lockafter removing thematrix_mdevfrom the list since it is changing a value inmatrix_dev.
No, the read-side doesn't hold the lock
if ((atomic_dec_if_positive(&matrix_dev->available_instances) < 0)) return -EPERM;
I think it is just a leftover from the atomic conversion that Alex did to keep it under the matrix_dev struct.
If we were going to hold the lock then it wouldn't need to be an atomic.
Jason
Quoted 48 lines · On Wed, 22 Sep 2021 10:11:50 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 36 lines · Tony Krowiak
Quoted 33 lines · Jason Gunthorpe
Without this call an xarray entry is leaked when the
vfio_apdevice is unprobed. It was missed when the below patch was rebased across thedev_setpatch. Keep the remove function in the same order as the error unwind in probe.Fixes eb0feefd4c02 ("vfio/ap_ops: Convert to use vfio_register_group_dev()")Reviewed-by Christoph Hellwig <[email protected]>Tested-by Tony Krowiak <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>drivers/s390/crypto/vfio_ap_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)v3:
- Keep the remove sequence the same as remove to avoid a lockdep splat
v2: https://lore.kernel.org/r/[email protected]/
- Fix corrupted diff
v1: https://lore.kernel.org/r/[email protected]/drivers/s390/crypto/vfio_ap_ops.c +2
-0+++ b/drivers/s390/crypto/vfio_ap_ops.c@@ -361,6 +361,7 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);list_del (&matrix_mdev->node);mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev); err_dec_available:atomic_inc (&matrix_dev->available_instances);@@ -376,9 +377,10 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev)mutex_lock (&matrix_dev->lock);vfio_ap_mdev_reset_queues (matrix_mdev);list_del (&matrix_mdev->node);Quoted 8 lines
drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_remove(struct mdev_device *mdev) · line 383
Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +2
-0+mutex_unlock (&matrix_dev->lock); +vfio_uninit_group_dev (&matrix_mdev->vdev);kfree (matrix_mdev);atomic_inc (&matrix_dev->available_instances);I think the above line of code should be done under the
matrix_dev->lockafter removing thematrix_mdevfrom the list since it is changing a value inmatrix_dev.No, the read-side doesn't hold the lock
Quoted 8 lines
if ((atomic_dec_if_positive(&matrix_dev->available_instances) < 0)) return -EPERM;I think it is just a leftover from the atomic conversion that Alex did to keep it under the
matrix_devstruct.If we were going to hold the lock then it wouldn't need to be an atomic.
Tony, I'd love to get an ack if you're satisfied with this so we can close up fixes for v5.15. Thanks,
Alex
Quoted 4 lines · Alex Williamson
Tony, I'd love to get an ack if you're satisfied with this so we can close up fixes for v5.15. Thanks,
Alex