qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH untested for-4.2] memory: fix race between TCG and accesses to dirty bitmap
Date: Wed, 7 Aug 2019 16:24:40 +0200	[thread overview]
Message-ID: <680dc43c-328f-ea59-553c-6e277c388d7c@redhat.com> (raw)
In-Reply-To: <CAFEAcA-gtfK1AwSFKo9XatJ_E9345Cd9+MS+1uu2WYG0i32sVA@mail.gmail.com>

On 06/08/19 16:23, Peter Maydell wrote:
> On Mon, 29 Jul 2019 at 22:47, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> The race is as follows:
>>
>>       vCPU thread                  reader thread
>>       -----------------------      -----------------------
>>       TLB check -> slow path
>>         notdirty_mem_write
>>           write to RAM
>>           set dirty flag
>>                                    clear dirty flag
>>       TLB check -> fast path
>>                                    read memory
>>         write to RAM
>>
>> and the second write is missed by the reader.
>>
>> Fortunately, in order to fix it, no change is required to the
>> vCPU thread.  However, the reader thread must delay the read after
>> the vCPU thread has finished the write.  This can be approximated
>> conservatively by run_on_cpu, which waits for the end of the current
>> translation block.
>>
>> A similar technique is used by KVM, which has to do a synchronous TLB
>> flush after doing a test-and-clear of the dirty-page flags.
>>
>> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>         I tested this some time ago, and enough has changed that I don't
>>         really trust those old results.  Nevertheless, I am throwing out
>>         the patch so that it is not forgotten.
> 
> This patch looks almost the same (maybe identical except for the
> commit message title?) as the patch "memory: introduce
> memory_global_after_dirty_log_sync" which you sent out at almost
> the same time as this one. Which patch should we be reviewing?

Yes, it's the same except for the commit message title.  I forgot a "-1"
after editing the .patch file.

Paolo



  reply	other threads:[~2019-08-07 14:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29 21:47 [Qemu-devel] [PATCH untested for-4.2] memory: fix race between TCG and accesses to dirty bitmap Paolo Bonzini
2019-07-29 21:47 ` [Qemu-devel] [PATCH] memory: introduce memory_global_after_dirty_log_sync Paolo Bonzini
2019-08-06 14:23 ` [Qemu-devel] [PATCH untested for-4.2] memory: fix race between TCG and accesses to dirty bitmap Peter Maydell
2019-08-07 14:24   ` Paolo Bonzini [this message]
2019-08-08  9:27 ` Alex Bennée

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=680dc43c-328f-ea59-553c-6e277c388d7c@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).