All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Borntraeger <borntraeger@de.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>,
	Avi Kivity <avi.kivity@gmail.com>, Gleb Natapov <gleb@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Dominik Dingel <dingel@linux.vnet.ibm.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: async_pf: mm->mm_users can not pin apf->mm
Date: Tue, 22 Apr 2014 22:24:40 +0200	[thread overview]
Message-ID: <5356D008.8040204@de.ibm.com> (raw)
In-Reply-To: <20140421132601.GA13615@redhat.com>

On 21/04/14 15:26, Oleg Nesterov wrote:
> get_user_pages(mm) is simply wrong if mm->mm_users == 0 and exit_mmap/etc
> was already called (or is in progress), mm->mm_count can only pin mm->pgd
> and mm_struct itself.
> 
> Change kvm_setup_async_pf/async_pf_execute to inc/dec mm->mm_users.
> 
> kvm_create_vm/kvm_destroy_vm play with ->mm_count too but this case looks
> fine at first glance, it seems that this ->mm is only used to verify that
> current->mm == kvm->mm.
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

This looks fine, from what I can tell. The old code has the problem mentioned
in your patch description, so your version is probably better.


> ---
>  virt/kvm/async_pf.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
> index 0ced4f3..cda703e 100644
> --- a/virt/kvm/async_pf.c
> +++ b/virt/kvm/async_pf.c
> @@ -99,7 +99,7 @@ static void async_pf_execute(struct work_struct *work)
>  	if (waitqueue_active(&vcpu->wq))
>  		wake_up_interruptible(&vcpu->wq);
> 
> -	mmdrop(mm);
> +	mmput(mm);
>  	kvm_put_kvm(vcpu->kvm);
>  }
> 
> @@ -116,7 +116,7 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu)
>  		flush_work(&work->work);
>  #else
>  		if (cancel_work_sync(&work->work)) {
> -			mmdrop(work->mm);
> +			mmput(work->mm);
>  			kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */
>  			kmem_cache_free(async_pf_cache, work);
>  		}
> @@ -181,7 +181,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva,
>  	work->addr = hva;
>  	work->arch = *arch;
>  	work->mm = current->mm;
> -	atomic_inc(&work->mm->mm_count);
> +	atomic_inc(&work->mm->mm_users);
>  	kvm_get_kvm(work->vcpu->kvm);
> 
>  	/* this can't really happen otherwise gfn_to_pfn_async
> @@ -199,7 +199,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva,
>  	return 1;
>  retry_sync:
>  	kvm_put_kvm(work->vcpu->kvm);
> -	mmdrop(work->mm);
> +	mmput(work->mm);
>  	kmem_cache_free(async_pf_cache, work);
>  	return 0;
>  }
> 

  reply	other threads:[~2014-04-22 20:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-21 13:25 [PATCH 0/2] KVM: async_pf: use_mm/mm_users fixes Oleg Nesterov
2014-04-21 13:25 ` [PATCH 1/2] KVM: async_pf: kill the unnecessary use_mm/unuse_mm async_pf_execute() Oleg Nesterov
2014-04-22 20:15   ` Christian Borntraeger
2014-04-22 21:07     ` Christian Borntraeger
2014-04-23 19:32       ` Oleg Nesterov
2014-04-28 14:06         ` Andrea Arcangeli
2014-04-28 15:31           ` Paolo Bonzini
2014-04-21 13:26 ` [PATCH 2/2] KVM: async_pf: mm->mm_users can not pin apf->mm Oleg Nesterov
2014-04-22 20:24   ` Christian Borntraeger [this message]
2014-04-24 14:27 ` [PATCH 0/2] KVM: async_pf: use_mm/mm_users fixes Christian Borntraeger
2014-04-24 14:55   ` Oleg Nesterov
2014-04-28 11:06 ` Paolo Bonzini
2014-04-28 14:15   ` Andrea Arcangeli
2014-04-28 15:02     ` [PATCH 3/2] KVM: async_pf: change async_pf_execute() to use get_user_pages(tsk => NULL) Oleg Nesterov
2014-04-28 15:03       ` Oleg Nesterov
2014-04-28 15:27         ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5356D008.8040204@de.ibm.com \
    --to=borntraeger@de.ibm.com \
    --cc=avi.kivity@gmail.com \
    --cc=dingel@linux.vnet.ibm.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.