On Mon, Sep 23, 2019 at 06:24:07PM -0300, Leonardo Bras wrote: > Given that in kvm_create_vm() there is: > kvm->mm = current->mm; > > And that on every kvm_*_ioctl we have: > if (kvm->mm != current->mm) > return -EIO; > > I see no reason to keep using current->mm instead of kvm->mm. > > By doing so, we would reduce the use of 'global' variables on code, relying > more in the contents of kvm struct. This patch led to a crash on shutting down a VM, because of this hunk: > diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c > index c4b606fe73eb..8069b35f2905 100644 > --- a/arch/powerpc/kvm/book3s_64_vio.c > +++ b/arch/powerpc/kvm/book3s_64_vio.c > @@ -255,7 +255,7 @@ static int kvm_spapr_tce_release(struct inode *inode, struct file *filp) > > kvm_put_kvm(stt->kvm); > > - account_locked_vm(current->mm, > + account_locked_vm(kvm->mm, > kvmppc_stt_pages(kvmppc_tce_pages(stt->size)), false); You are referencing kvm->mm after having done kvm_put_kvm a couple of lines earlier, which means that *kvm can be freed at the point where you use kvm->mm. If you want to make this change you will need to move the kvm_put_kvm call to after the last use of it. I have dropped this patch for now. Paul.