Skip to content

s390/vfio-ap: fix memory leak in mdev remove callback

Tony Krowiak linux-s390 lkml 6 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest2 patches 7 repliesIn review
  2. v52 patches 3 repliesSuperseded
  3. v42 patches 21 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v32 patches12 repliesSuperseded
v21 patch33 repliesSuperseded
v11 patch7 repliesSuperseded

Changes in v6 from the cover letter

--------
* Replaced struct kvm_s390_module_hook with function pointer int (*crypto_hook)(struct kvm_vcpu *vcpu)

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2s390/vfio-ap: clean up mdev resources when remove callback invokeddrivers/s390/crypto/vfio_ap_ops.c+0 -102 replies
2/2s390/vfio-ap: r/w lock for PQAP interception handler function pointerarch/s390/include/asm/kvm_host.h arch/s390/kvm/kvm-s390.c arch/s390/kvm/priv.c +2 more+28 -165 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchJason Gunthorpe
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v6 thread

Cover letter [PATCH v6 0/2] s390/vfio-ap: fix memory leak in mdev remove callback

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 of the mdev. Consequently, the memory for the resources allocated when the mdev was created are leaked.

To fix this issue:

* The remove callback will not terminate with -EBUSY when the mdev is in use by a KVM guest.

* The memory for the resources allocated when the mdev was created will be freed.

* Since the struct ap_matrix_mdev now gets freed while the guest is is still running, we need to ensure that the pointer to the function that handles interception of the PQAP instruction executed on the guest is not accessed while it is being set to NULL. To prevent this, a r/w lock is introduced that protects the function pointer.

Change log:
v5 -> v6:
--------
* Replaced struct kvm_s390_module_hook with function pointer int (*crypto_hook)(struct kvm_vcpu *vcpu)

Tony Krowiak (2):
s390/vfio-ap: clean up mdev resources when remove callback invoked s390/vfio-ap: r/w lock for PQAP interception handler function pointer

 arch/s390/include/asm/kvm_host.h      |  8 +++----
 arch/s390/kvm/kvm-s390.c              |  1 +
 arch/s390/kvm/priv.c                  | 10 ++++----
 drivers/s390/crypto/vfio_ap_ops.c     | 33 ++++++++++++++-------------
 drivers/s390/crypto/vfio_ap_private.h |  2 +-
 5 files changed, 28 insertions(+), 26 deletions(-)
Signature · 1 line
2.30.2