public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
To: kvm@vger.kernel.org
Subject: High Level Proof of The Correctness of Dirty Page Tracking
Date: Sun, 1 Apr 2012 00:12:55 +0900	[thread overview]
Message-ID: <20120401001255.62d558b570abed499bc06356@gmail.com> (raw)

This is what I wanted to read before starting GET_DIRTY_LOG work: about
possible race between VCPU threads and GET_DIRTY_LOG thread.

Although most things look trivial, there seem to be some interesting assumptions
the correctness is based on including mmu lock usage.

	Takuya

===
About MMU Page Fault Path:
1. Set bit in dirty bitmap
2. Make spte writable
3. Guest re-execute the write

If GET_DIRTY_LOG is allowed to write protect the page between step 1 and 2,
that page will be made writable again at step 2 and the write at step 3 will
not be caught.  Since the userspace can process that page before step 3, the
written data may be lost.  To avoid this mmu lock must be held correctly in
both sides as the current implementation does.

When GET_DIRTY_LOG write protects the page between step 2 and 3, the userspace
will process that page before or after step 3.  If it is after step 3, the
userspace will see the written data normally.  If it is before step 3, the
write protection including corresponding TLB flush is already completed and
the write at step 3 will be caught again.  Since the next GET_DIRTY_LOG will
catch this data, this is safe. -- (*1)

Other timings are trivial.


About Emulation Write Path:
1. Write to the guest memory
2. Set bit in dirty bitmap

The only concern here is what will happen if the userspace gets the dirty log
between step 1 and 2.  In that case the userspace sees the bit is clean and
may not process that page.  To not lose the written data, GET_DIRTY_LOG must
be done at least once more so that we get the remaining dirty bit. -- (*2)


About (*1), (*2):
These are really safe because the userspace stops the VCPUs before doing the
final GET_DIRTY_LOG.

             reply	other threads:[~2012-03-31 15:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-31 15:12 Takuya Yoshikawa [this message]
2012-04-01  3:38 ` High Level Proof of The Correctness of Dirty Page Tracking Xiao Guangrong
2012-04-02 13:53   ` Takuya Yoshikawa

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=20120401001255.62d558b570abed499bc06356@gmail.com \
    --to=takuya.yoshikawa@gmail.com \
    --cc=kvm@vger.kernel.org \
    /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