All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>,
	QEMU Devel Mailing List <qemu-devel@nongnu.org>
Subject: Re: Question on memory commit during MR finalize()
Date: Mon, 20 Apr 2020 19:31:15 -0400	[thread overview]
Message-ID: <20200420233115.GB420399@xz-x1> (raw)
In-Reply-To: <fe73a74b-2324-68a5-a37f-530a6bb03ebc@redhat.com>

On Mon, Apr 20, 2020 at 11:44:11PM +0200, Paolo Bonzini wrote:
> On 20/04/20 23:00, Peter Xu wrote:
> > 
> > I'm still uncertain how the dirty ring branch can easily trigger this, however
> > the backtrace looks really odd to me in that we're going to do memory commit
> > and even sending KVM ioctls during finalize(), especially in the RCU thread...
> > I never expected that.
> 
> Short answer: it is really hard to not trigger finalize() from an RCU
> callback, and it's the reason why the RCU thread takes the big QEMU lock.
> 
> However, instead of memory_region_transaction_commit,
> memory_region_finalize probably should do something like
> 
>     --memory_region_transaction_depth;
>     assert (memory_region_transaction_depth ||
> 	    (!memory_region_update_pending &&
>              !ioeventfd_update_pending));

Ah I see; this makes sense.

And finally I found the problem, which is indeed the bug in my own tree - I
forgot to remove the previous changes to flush the dirty ring during mem
removal (basically that's run_on_cpu() called during a memory commit, that will
wrongly release the BQL without being noticed).

Besides above assert, I'm thinking maybe we can also assert on something like:

  !(memory_region_transaction_depth || memory_region_update_pending ||
    ioeventfd_update_pending)

When releasing BQL (unlock, or qemu_cond_wait() on BQL, which should cover
run_on_cpu()), so that we can identify misuse of BQL easier like this.

Let me know if you like these sanity checks. I can write up a small series if
you think that's a good idea.

Thanks,

-- 
Peter Xu



  reply	other threads:[~2020-04-20 23:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20 21:00 Question on memory commit during MR finalize() Peter Xu
2020-04-20 21:44 ` Paolo Bonzini
2020-04-20 23:31   ` Peter Xu [this message]
2020-04-21  9:43     ` Paolo Bonzini
2020-04-21 10:43       ` Peter Xu
2021-07-15 14:27         ` Thanos Makatos
2021-07-15 18:35           ` Peter Xu
2021-07-16 11:42             ` Thanos Makatos
2021-07-16 14:18               ` Peter Xu
2021-07-19 14:38                 ` Thanos Makatos
2021-07-19 15:56                   ` Peter Xu
2021-07-19 18:02                     ` Thanos Makatos
2021-07-19 19:05                       ` Thanos Makatos
2021-07-19 19:59                         ` Peter Xu
2021-07-19 20:58                           ` John Johnson
2021-07-20  1:22                             ` Peter Xu

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=20200420233115.GB420399@xz-x1 \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --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 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.