linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH kernel] KVM: PPC: Release all hardware TCE tables attached to a group
@ 2019-02-12  4:37 Alexey Kardashevskiy
  2019-02-22  9:39 ` Paul Mackerras
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Kardashevskiy @ 2019-02-12  4:37 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Alexey Kardashevskiy, Paul E . McKenney, kvm-ppc, David Gibson

The SPAPR TCE KVM device references all hardware IOMMU tables assigned to
some IOMMU group to ensure that in-kernel KVM acceleration of H_PUT_TCE
can work. The tables are references when an IOMMU group gets registered
with the VFIO KVM device by the KVM_DEV_VFIO_GROUP_ADD ioctl;
KVM_DEV_VFIO_GROUP_DEL calls into the dereferencing code
in kvm_spapr_tce_release_iommu_group() which walks through the list of
LIOBNs, finds a matching IOMMU table and calls kref_put() when found.

However that code stops after the very first successful derefencing
leaving other tables referenced till the SPAPR TCE KVM device is destroyed
which normally happens on guest reboot or termination so if we do hotplug
and unplug in a loop, we are leaking IOMMU tables here.

This removes a premature return to let kvm_spapr_tce_release_iommu_group()
find and dereference all attached tables.

Fixes: 121f80ba68f "KVM: PPC: VFIO: Add in-kernel acceleration for VFIO"
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---

I kinda hoped to blame RCU for misbehaviour but it was me all over again :)

---
 arch/powerpc/kvm/book3s_64_vio.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index 532ab797..6630dde 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -133,7 +133,6 @@ extern void kvm_spapr_tce_release_iommu_group(struct kvm *kvm,
 					continue;
 
 				kref_put(&stit->kref, kvm_spapr_tce_liobn_put);
-				return;
 			}
 		}
 	}
-- 
2.17.1


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

* Re: [PATCH kernel] KVM: PPC: Release all hardware TCE tables attached to a group
  2019-02-12  4:37 [PATCH kernel] KVM: PPC: Release all hardware TCE tables attached to a group Alexey Kardashevskiy
@ 2019-02-22  9:39 ` Paul Mackerras
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Mackerras @ 2019-02-22  9:39 UTC (permalink / raw)
  To: Alexey Kardashevskiy
  Cc: Paul E . McKenney, linuxppc-dev, kvm-ppc, David Gibson

On Tue, Feb 12, 2019 at 03:37:45PM +1100, Alexey Kardashevskiy wrote:
> The SPAPR TCE KVM device references all hardware IOMMU tables assigned to
> some IOMMU group to ensure that in-kernel KVM acceleration of H_PUT_TCE
> can work. The tables are references when an IOMMU group gets registered
> with the VFIO KVM device by the KVM_DEV_VFIO_GROUP_ADD ioctl;
> KVM_DEV_VFIO_GROUP_DEL calls into the dereferencing code
> in kvm_spapr_tce_release_iommu_group() which walks through the list of
> LIOBNs, finds a matching IOMMU table and calls kref_put() when found.
> 
> However that code stops after the very first successful derefencing
> leaving other tables referenced till the SPAPR TCE KVM device is destroyed
> which normally happens on guest reboot or termination so if we do hotplug
> and unplug in a loop, we are leaking IOMMU tables here.
> 
> This removes a premature return to let kvm_spapr_tce_release_iommu_group()
> find and dereference all attached tables.
> 
> Fixes: 121f80ba68f "KVM: PPC: VFIO: Add in-kernel acceleration for VFIO"
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>

Thanks, applied to my kvm-ppc-next tree.

Paul.

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

end of thread, other threads:[~2019-02-22  9:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-12  4:37 [PATCH kernel] KVM: PPC: Release all hardware TCE tables attached to a group Alexey Kardashevskiy
2019-02-22  9:39 ` Paul Mackerras

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).