[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <834f95f8-c1ca-17da-b709-69d5c55e8fcd@de.ibm.com>
Date: Wed, 12 May 2021 18:49:23 +0200
From: Christian Borntraeger <borntraeger@...ibm.com>
To: Tony Krowiak <akrowiak@...ux.ibm.com>, linux-s390@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: cohuck@...hat.com, pasic@...ux.vnet.ibm.com, jjherne@...ux.ibm.com,
jgg@...dia.com, alex.williamson@...hat.com, kwankhede@...dia.com,
stable@...r.kernel.org, Vasily Gorbik <gor@...ux.ibm.com>
Subject: Re: [PATCH v2] s390/vfio-ap: fix memory leak in mdev remove callback
On 10.05.21 23:48, Tony Krowiak wrote:
> 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@...r.kernel.org
> Signed-off-by: Tony Krowiak <akrowiak@...y.rr.com>
applied to the internal s390 tree. Lets give it some days of testing coverage of
CI and others.
Vasily, can you add this for the s390/fixes branch early next week if nothing
goes wrong?
> ---
> 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);
>
Powered by blists - more mailing lists