public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Tony Krowiak <akrowiak@linux.ibm.com>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	cohuck@redhat.com, pasic@linux.vnet.ibm.com,
	jjherne@linux.ibm.com, alex.williamson@redhat.com,
	kwankhede@nvidia.com, stable@vger.kernel.org,
	Tony Krowiak <akrowiak@stny.rr.com>
Subject: Re: [PATCH] s390/vfio-ap: fix memory leak in mdev remove callback
Date: Wed, 5 May 2021 15:00:38 -0300	[thread overview]
Message-ID: <20210505180038.GK1370958@nvidia.com> (raw)
In-Reply-To: <7b20afce-5782-53c6-beab-ae852ae69b40@de.ibm.com>

On Wed, May 05, 2021 at 07:44:55PM +0200, Christian Borntraeger wrote:
> 
> 
> On 05.05.21 19:28, 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.
> [...]
> >   static int vfio_ap_mdev_create(struct mdev_device *mdev)
> >   {
> >   	struct ap_matrix_mdev *matrix_mdev;
> > @@ -366,16 +392,9 @@ 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;
> > -	}
> > -
> > +	WARN(vfio_ap_mdev_has_crycb(matrix_mdev),
> > +	     "Removing mdev leaves KVM guest without any crypto devices");
> > +	vfio_ap_mdev_clear_apcb(matrix_mdev);
> 
> Triggering a kernel warning due to an administrative task is not good.
> Can't you simply clear the crycb? Maybe do a printk, but not a WARN.

+1

Jason

  reply	other threads:[~2021-05-05 18:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 17:28 [PATCH] s390/vfio-ap: fix memory leak in mdev remove callback Tony Krowiak
2021-05-05 17:44 ` Christian Borntraeger
2021-05-05 18:00   ` Jason Gunthorpe [this message]
2021-05-10 17:22   ` Tony Krowiak
2021-05-06 10:22 ` Cornelia Huck
2021-05-06 10:45   ` Cornelia Huck
2021-05-10 17:50     ` Tony Krowiak
2021-05-10 17:44   ` Tony Krowiak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210505180038.GK1370958@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=akrowiak@stny.rr.com \
    --cc=alex.williamson@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pasic@linux.vnet.ibm.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox