]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
KVM: Fix write protection race during dirty logging
authorTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Sun, 5 Feb 2012 11:42:41 +0000 (20:42 +0900)
committerAvi Kivity <avi@redhat.com>
Thu, 8 Mar 2012 12:10:12 +0000 (14:10 +0200)
commit6dbf79e7164e9a86c1e466062c48498142ae6128
tree2ffc942d370f5f239df05a154e0354ab06fc0489
parent10166744b80a41c30d82bc6e11140f5b28d257ab
KVM: Fix write protection race during dirty logging

This patch fixes a race introduced by:

  commit 95d4c16ce78cb6b7549a09159c409d52ddd18dae
  KVM: Optimize dirty logging by rmap_write_protect()

During protecting pages for dirty logging, other threads may also try
to protect a page in mmu_sync_children() or kvm_mmu_get_page().

In such a case, because get_dirty_log releases mmu_lock before flushing
TLB's, the following race condition can happen:

  A (get_dirty_log)     B (another thread)

  lock(mmu_lock)
  clear pte.w
  unlock(mmu_lock)
                        lock(mmu_lock)
                        pte.w is already cleared
                        unlock(mmu_lock)
                        skip TLB flush
                        return
  ...
  TLB flush

Though thread B assumes the page has already been protected when it
returns, the remaining TLB entry will break that assumption.

This patch fixes this problem by making get_dirty_log hold the mmu_lock
until it flushes the TLB's.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/x86.c