mbox series

[v2,0/2] Clean up vfio_ap resources when KVM pointer invalidated

Message ID 20201211222211.20869-1-akrowiak@linux.ibm.com
Headers show
Series Clean up vfio_ap resources when KVM pointer invalidated | expand

Message

Anthony Krowiak Dec. 11, 2020, 10:22 p.m. UTC
The vfio_ap device driver registers a group notifier with VFIO when the
file descriptor for a VFIO mediated device attached to a KVM guest is
opened. The group notifier is registered to receive notification that the
KVM pointer for the guest is set (VFIO_GROUP_NOTIFY_SET_KVM event). When
the KVM pointer is set to a non-NULL value, the vfio_ap driver takes the
following actions:
1. Stashes the KVM pointer in the vfio_ap_mdev struct that holds the state
   of the mediated device.
2. Calls the kvm_get_kvm() function to increment its reference counter.
3. Sets the function pointer to the function that handles interception of
   the instruction that enables/disables interrupt processing for the
   KVM guest.
4. Plugs the AP devices assigned to the mediated device into the KVM
   guest.

These actions are reversed by the release callback which is invoked when
userspace closes the mediated device's file descriptor. In this case, the
group notifier does not get called to invalidate the KVM pointer because
the notifier is unregistered by the release callback; however, there are no
guarantees that userspace will do the right thing before shutting down.
To ensure that there are no resource leaks should the group notifier get
called to set the KVM pointer to NULL, the notifier should also reverse
the actions taken when it was called to set the pointer. This patch series
ensures proper clean up is done via the group notifier.

Tony Krowiak (2):
  s390/vfio-ap: No need to disable IRQ after queue reset
  s390/vfio-ap: reverse group notifier actions when KVM pointer
    invalidated

 drivers/s390/crypto/vfio_ap_drv.c     |  1 -
 drivers/s390/crypto/vfio_ap_ops.c     | 80 +++++++++++++++++----------
 drivers/s390/crypto/vfio_ap_private.h |  1 -
 3 files changed, 50 insertions(+), 32 deletions(-)

Comments

Greg Kroah-Hartman Dec. 12, 2020, 8:20 a.m. UTC | #1
On Fri, Dec 11, 2020 at 05:22:10PM -0500, Tony Krowiak wrote:
> The queues assigned to a matrix mediated device are currently reset when:

> 

> * The VFIO_DEVICE_RESET ioctl is invoked

> * The mdev fd is closed by userspace (QEMU)

> * The mdev is removed from sysfs.

> 

> Immediately after the reset of a queue, a call is made to disable

> interrupts for the queue. This is entirely unnecessary because the reset of

> a queue disables interrupts, so this will be removed.

> 

> Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>

> ---

>  drivers/s390/crypto/vfio_ap_drv.c     |  1 -

>  drivers/s390/crypto/vfio_ap_ops.c     | 40 +++++++++++++++++----------

>  drivers/s390/crypto/vfio_ap_private.h |  1 -

>  3 files changed, 26 insertions(+), 16 deletions(-)


<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>