All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>,
	kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock
Date: Wed, 15 Feb 2012 16:07:49 +0200	[thread overview]
Message-ID: <4F3BBC35.6010502@redhat.com> (raw)
In-Reply-To: <4F3B9902.5000306@linux.vnet.ibm.com>

On 02/15/2012 01:37 PM, Xiao Guangrong wrote:
> >>
> >> I would really like to move the IPI back out of the lock.
> >>
> >> How about something like a sequence lock:
> >>
> >>
> >>     spin_lock(mmu_lock)
> >>     need_flush = write_protect_stuff();
> >>     atomic_add(kvm->want_flush_counter, need_flush);
> >>     spin_unlock(mmu_lock);
> >>
> >>     while ((done = atomic_read(kvm->done_flush_counter)) < (want =
> >> atomic_read(kvm->want_flush_counter)) {
> >>           kvm_make_request(flush)
> >>           atomic_cmpxchg(kvm->done_flush_counter, done, want)
> >>     }
> >>
> >> This (or maybe a corrected and optimized version) ensures that any
> >> need_flush cannot pass the while () barrier, no matter which thread
> >> encounters it first.  However it violates the "do not invent new locking
> >> techniques" commandment.  Can we map it to some existing method?
> > 
> > There is no need to advance 'want' in the loop.  So we could do
> > 
> > /* must call with mmu_lock held */
> > void kvm_mmu_defer_remote_flush(kvm, need_flush)
> > {
> >       if (need_flush)
> >             ++kvm->flush_counter.want;
> > }
> > 
> > /* may call without mmu_lock */
> > void kvm_mmu_commit_remote_flush(kvm)
> > {
> >       want = ACCESS_ONCE(kvm->flush_counter.want)
> >       while ((done = atomic_read(kvm->flush_counter.done) < want) {
> >             kvm_make_request(flush)
> >             atomic_cmpxchg(kvm->flush_counter.done, done, want)
> >       }
> > }
> > 
>
>
> Hmm, we already have kvm->tlbs_dirty, so, we can do it like this:
>
> #define SPTE_INVALID_UNCLEAN (1 << 63 )
>
> in invalid page path:
> lock mmu_lock
> if (spte is invalid)
> 	kvm->tlbs_dirty |= SPTE_INVALID_UNCLEAN;
> need_tlb_flush = kvm->tlbs_dirty;
> unlock mmu_lock
> if (need_tlb_flush)
> 	kvm_flush_remote_tlbs()
>
> And in page write-protected path:
> lock mmu_lock
> 	if (it has spte change to readonly |
> 	      kvm->tlbs_dirty & SPTE_INVALID_UNCLEAN)
> 		kvm_flush_remote_tlbs()
> unlock mmu_lock
>
> How about this?

Well, it still has flushes inside the lock.  And it seems to be more
complicated, but maybe that's because I thought of my idea and didn't
fully grok yours yet.

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2012-02-15 14:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10  6:28 [PATCH 1/2] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock Takuya Yoshikawa
2012-02-10  6:29 ` [PATCH 2/2] KVM: MMU: Flush TLBs only once in invlpg() " Takuya Yoshikawa
2012-02-10  6:55   ` Xiao Guangrong
2012-02-10  7:21     ` Takuya Yoshikawa
2012-02-10  7:42       ` Xiao Guangrong
2012-02-14  4:36         ` Takuya Yoshikawa
2012-02-14  4:56           ` Takuya Yoshikawa
2012-02-14 17:21             ` Andrea Arcangeli
2012-02-10  7:52 ` [PATCH 1/2] KVM: mmu_notifier: Flush TLBs " Xiao Guangrong
2012-02-13  6:00   ` Takuya Yoshikawa
2012-02-14 17:27   ` Andrea Arcangeli
2012-02-10 17:26 ` Marcelo Tosatti
2012-02-14 17:10 ` Andrea Arcangeli
2012-02-14 17:29   ` Marcelo Tosatti
2012-02-14 18:53     ` Andrea Arcangeli
2012-02-14 19:43       ` Marcelo Tosatti
2012-02-15  9:18         ` Avi Kivity
2012-02-15  9:47           ` Avi Kivity
2012-02-15 11:37             ` Xiao Guangrong
2012-02-15 14:07               ` Avi Kivity [this message]
2012-02-15 19:16                 ` Andrea Arcangeli
2012-02-16  4:50                 ` Xiao Guangrong
2012-02-16 11:57                   ` Avi Kivity
2012-02-17  2:36                     ` Xiao Guangrong

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=4F3BBC35.6010502@redhat.com \
    --to=avi@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=xiaoguangrong@linux.vnet.ibm.com \
    --cc=yoshikawa.takuya@oss.ntt.co.jp \
    /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.