public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Gleb Natapov <gleb@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Davidlohr Bueso <davi@redhat.com>,
	Davidlohr Bueso <davidlohr@hp.com>,
	KOSAKI Motohiro <kosaki.motohiro@gmail.com>,
	Rik van Riel <riel@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mel Gorman <mgorman@suse.de>,
	Michel Lespinasse <walken@google.com>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: async_pf.c && use_mm() (Was: mm,vmacache: also flush cache for VM_CLONE)
Date: Fri, 14 Mar 2014 19:23:31 +0100	[thread overview]
Message-ID: <20140314182331.GA11482@redhat.com> (raw)
In-Reply-To: <CA+55aFzBjMQGapsS1Jw3rdrPaOYYPn7NamtjN47_W_r1QKX+8Q@mail.gmail.com>

On 03/13, Linus Torvalds wrote:
>
> Ok, no longer on my phone, and no, it clearly does the reference count with a
>
>     atomic_inc(&work->mm->mm_count);
>
> separately. The use_mm/unuse_mm seems entirely specious.

Yes, it really looks as if we can simply remove it.

But once again, with or without use_mm() it seems that the refcounting
is buggy. get_user_pages() is simply wrong if ->mm_users == 0 and
exit_mmap/etc was already called (or in progress).

So I think we need something like below, but I can't test this change
or audit other (potential) users of kvm_async_pf->mm.

Perhaps this is not a bug and somehow it is guaranteed that, say,
kvm_clear_async_pf_completion_queue() must be always called before the
caller of kvm_setup_async_pf() can exit? I don't know, but in this case
we do not need any accounting and this should be documented.

Gleb, what do you think?

Oleg.

--- x/virt/kvm/async_pf.c
+++ x/virt/kvm/async_pf.c
@@ -65,11 +65,9 @@ static void async_pf_execute(struct work_struct *work)
 
 	might_sleep();
 
-	use_mm(mm);
 	down_read(&mm->mmap_sem);
 	get_user_pages(current, mm, addr, 1, 1, 0, NULL, NULL);
 	up_read(&mm->mmap_sem);
-	unuse_mm(mm);
 
 	spin_lock(&vcpu->async_pf.lock);
 	list_add_tail(&apf->link, &vcpu->async_pf.done);
@@ -85,7 +83,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);
 }
 
@@ -98,7 +96,7 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu)
 				   typeof(*work), queue);
 		list_del(&work->queue);
 		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);
 		}
@@ -162,7 +160,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
 	work->addr = gfn_to_hva(vcpu->kvm, gfn);
 	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
@@ -180,7 +178,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
 	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-03-14 18:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-27 21:48 [PATCH v4] mm: per-thread vma caching Davidlohr Bueso
2014-02-28  4:39 ` Davidlohr Bueso
     [not found] ` <20140303160021.3001634fa62781d7b0359158@linux-foundation.org>
2014-03-04  0:18   ` Davidlohr Bueso
     [not found] ` <20140303164002.02df915e12d05bb98762407f@linux-foundation.org>
2014-03-04  0:59   ` Davidlohr Bueso
     [not found]     ` <20140303172348.3f00c9df.akpm@linux-foundation.org>
2014-03-04  2:42       ` Davidlohr Bueso
     [not found]         ` <20140303191224.96f93142.akpm@linux-foundation.org>
2014-03-04  3:13           ` Davidlohr Bueso
2014-03-04  3:26             ` Linus Torvalds
2014-03-04  5:32               ` Davidlohr Bueso
2014-03-14  3:05               ` Li Zefan
2014-03-14  4:43                 ` Andrew Morton
2014-03-06 22:56     ` Andrew Morton
     [not found] ` <20140308184040.GA29602@redhat.com>
     [not found]   ` <CA+55aFw88xiY+o5FE6VtHNkpUZDK3FPt31oCpNsgn1BH7wAPZw@mail.gmail.com>
2014-03-08 19:57     ` Oleg Nesterov
     [not found]     ` <20140308194405.GA32403@redhat.com>
2014-03-08 20:02       ` Linus Torvalds
2014-03-09  3:22         ` Davidlohr Bueso
2014-03-09 12:57         ` Oleg Nesterov
2014-03-09 15:57           ` Linus Torvalds
2014-03-09 17:09             ` Oleg Nesterov
2014-03-09 17:16               ` Linus Torvalds
2014-03-10 19:56                 ` [PATCH -next] mm,vmacache: also flush cache for VM_CLONE Davidlohr Bueso
2014-03-13 14:59                   ` Oleg Nesterov
2014-03-13 15:32                     ` Oleg Nesterov
2014-03-13 19:04                       ` Davidlohr Bueso
     [not found]                     ` <CA+55aFyNd7L+G3hFauJPxUOengK-_o2G-SFmVooPZ-sE6xBj=g@mail.gmail.com>
2014-03-13 16:36                       ` Oleg Nesterov
2014-03-13 18:27                         ` async_pf.c && use_mm() (Was: mm,vmacache: also flush cache for VM_CLONE) Oleg Nesterov
     [not found]                           ` <CA+55aFwqTbsYCyPf6_i6RmBkPHpEhJjiRfZm6_1_yPa_kUkYiQ@mail.gmail.com>
2014-03-13 21:44                             ` Linus Torvalds
2014-03-14 18:23                               ` Oleg Nesterov [this message]

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=20140314182331.GA11482@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=davi@redhat.com \
    --cc=davidlohr@hp.com \
    --cc=gleb@redhat.com \
    --cc=kosaki.motohiro@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=walken@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox