linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] s390/vfio-ap: fix memory leak in mdev remove callback
@ 2021-05-10 21:48 Tony Krowiak
  2021-05-10 21:56 ` Tony Krowiak
                   ` (4 more replies)
  0 siblings, 5 replies; 34+ messages in thread
From: Tony Krowiak @ 2021-05-10 21:48 UTC (permalink / raw)
  To: linux-s390, linux-kernel
  Cc: borntraeger, cohuck, pasic, jjherne, jgg, alex.williamson,
	kwankhede, Tony Krowiak, stable, Tony Krowiak

The mdev remove callback for the vfio_ap device driver bails out with
-EBUSY if the mdev is in use by a KVM guest. The intended purpose was
to prevent the mdev from being removed while in use; however, returning a
non-zero rc does not prevent removal. This could result in a memory leak
of the resources allocated when the mdev was created. In addition, the
KVM guest will still have access to the AP devices assigned to the mdev
even though the mdev no longer exists.

To prevent this scenario, cleanup will be done - including unplugging the
AP adapters, domains and control domains - regardless of whether the mdev
is in use by a KVM guest or not.

Fixes: 258287c994de ("s390: vfio-ap: implement mediated device open callback")
Cc: stable@vger.kernel.org
Signed-off-by: Tony Krowiak <akrowiak@stny.rr.com>
---
 drivers/s390/crypto/vfio_ap_ops.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index b2c7e10dfdcd..f90c9103dac2 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -26,6 +26,7 @@
 
 static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev);
 static struct vfio_ap_queue *vfio_ap_find_queue(int apqn);
+static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev);
 
 static int match_apqn(struct device *dev, const void *data)
 {
@@ -366,17 +367,7 @@ static int vfio_ap_mdev_remove(struct mdev_device *mdev)
 	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
 
 	mutex_lock(&matrix_dev->lock);
-
-	/*
-	 * If the KVM pointer is in flux or the guest is running, disallow
-	 * un-assignment of control domain.
-	 */
-	if (matrix_mdev->kvm_busy || matrix_mdev->kvm) {
-		mutex_unlock(&matrix_dev->lock);
-		return -EBUSY;
-	}
-
-	vfio_ap_mdev_reset_queues(mdev);
+	vfio_ap_mdev_unset_kvm(matrix_mdev);
 	list_del(&matrix_mdev->node);
 	kfree(matrix_mdev);
 	mdev_set_drvdata(mdev, NULL);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2021-05-19 13:02 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 21:48 [PATCH v2] s390/vfio-ap: fix memory leak in mdev remove callback Tony Krowiak
2021-05-10 21:56 ` Tony Krowiak
2021-05-12 10:35 ` Cornelia Huck
2021-05-12 12:41 ` Jason Gunthorpe
2021-05-12 15:32   ` Christian Borntraeger
2021-05-12 16:50     ` Jason Gunthorpe
2021-05-13 14:19     ` Tony Krowiak
2021-05-13 14:18   ` Tony Krowiak
2021-05-13 17:25     ` Jason Gunthorpe
2021-05-13 17:32       ` Halil Pasic
2021-05-13 17:34         ` Jason Gunthorpe
2021-05-12 16:49 ` Christian Borntraeger
2021-05-12 18:35 ` Halil Pasic
2021-05-13 14:35   ` Tony Krowiak
2021-05-13 17:45     ` Halil Pasic
2021-05-13 19:23       ` Tony Krowiak
2021-05-14  0:15         ` Halil Pasic
2021-05-17 13:37           ` Tony Krowiak
2021-05-17 19:10             ` Halil Pasic
2021-05-18  9:30               ` Christian Borntraeger
2021-05-18 13:42                 ` Tony Krowiak
2021-05-18 13:59                   ` Christian Borntraeger
2021-05-18 15:33                     ` Halil Pasic
2021-05-18 17:01                       ` Christian Borntraeger
2021-05-18 23:27                         ` Halil Pasic
2021-05-19  8:17                           ` Christian Borntraeger
2021-05-19 11:22                             ` Christian Borntraeger
2021-05-19 12:59                               ` Halil Pasic
2021-05-19 13:02                               ` Jason Gunthorpe
2021-05-19 11:25                             ` Halil Pasic
2021-05-18 18:14                     ` Tony Krowiak
2021-05-18 18:22                       ` Christian Borntraeger
2021-05-18 18:40                         ` Tony Krowiak
2021-05-18 13:41               ` Tony Krowiak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).