From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Mackerras Date: Thu, 11 Apr 2019 10:27:10 +0000 Subject: Re: [PATCH v5 16/16] KVM: PPC: Book3S HV: XIVE: introduce a 'release' device operation Message-Id: <20190411102710.GD21252@blackberry> List-Id: References: <20190410170448.3923-1-clg@kaod.org> <20190410170448.3923-17-clg@kaod.org> In-Reply-To: <20190410170448.3923-17-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: =?iso-8859-1?Q?C=E9dric?= Le Goater Cc: kvm-ppc@vger.kernel.org, David Gibson , kvm@vger.kernel.org, Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Paolo Bonzini On Wed, Apr 10, 2019 at 07:04:48PM +0200, C=E9dric Le Goater wrote: > When a P9 sPAPR VM boots, the CAS negotiation process determines which > interrupt mode to use (XICS legacy or XIVE native) and invokes a > machine reset to activate the chosen mode. >=20 > To be able to switch from one mode to another, we introduce the > capability to release a KVM device without destroying the VM. The KVM > device interface is extended with a new 'release' operation which is > called when the file descriptor of the device is closed. Unfortunately, I think there is now a memory leak: > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index ea2018ae1cd7..ea2619d5ca98 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -2938,6 +2938,19 @@ static int kvm_device_release(struct inode *inode,= struct file *filp) > struct kvm_device *dev =3D filp->private_data; > struct kvm *kvm =3D dev->kvm; > =20 > + if (!dev) > + return -ENODEV; > + > + if (dev->kvm !=3D kvm) > + return -EPERM; > + > + if (dev->ops->release) { > + mutex_lock(&kvm->lock); > + list_del(&dev->vm_node); Because the device is now no longer in the kvm->devices list, kvm_destroy_devices() won't find it there and therefore won't call the device's destroy method. In fact now the device's destroy method will never get called; I can't see how kvmppc_xive_free() or kvmppc_xive_native_free() will ever get called. Thus the memory for the kvmppc_xive structs will never get freed as far as I can see. We could fix that by freeing both of the kvm->arch.xive_devices entries at VM destruction time. If it is true that any device that has a release method will never see its destroy method being called, then that needs to be documented clearly somewhere. Paul.