From: Peter Xu <peterx@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-devel@nongnu.org, "Maxim Levitsky" <mlevitsk@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
"Chuang Xu" <xuchuangxclwt@bytedance.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH RFC 0/4] memory: Fix (/ Discuss) a few rcu issues
Date: Wed, 1 Mar 2023 11:08:01 -0500 [thread overview]
Message-ID: <Y/94YfBFIqZhrplF@x1n> (raw)
In-Reply-To: <Y/6X1buYOXDpaXO0@fedora>
On Tue, Feb 28, 2023 at 07:09:57PM -0500, Stefan Hajnoczi wrote:
> On Sat, Feb 25, 2023 at 11:31:37AM -0500, Peter Xu wrote:
> > [not for merging, but for discussion; this is something I found when
> > looking at another issue on Chuang's optimization for migration downtime]
> >
> > Summary: we tried to access memory_listeners, address_spaces, etc. in RCU
> > way. However we didn't implement them with RCU-safety. This patchset is
> > trying to do that; at least making it closer.
> >
> > NOTE! It's doing it wrongly for now, so please feel free to see this as a
> > thread to start discussing this problem, as in subject.
> >
> > The core problem here is how to make sure memory listeners will be freed in
> > RCU ways, per when unlinking them from the global memory_listeners list.
> >
> > The current patchset (in patch 1) did it with drain_call_rcu(), but of
> > course it's wrong, because of at least two things:
> >
> > (1) drain_call_rcu() will release BQL; currently there's no way to me to
> > guarantee that releasing BQL is safe here.
> >
> > (2) memory_listener_unregister() can be called within a RCU read lock
> > itself (we're so happy to take rcu read lock in many places but we
> > don't think much on how long it'll be taken; at least not as strict
> > as the kernel variance, so we're just less care about that fact yet).
> > It means, drain_call_rcu() should deadlock there waiting for itself.
> > For an example, see Appendix A.
> >
> > Side question to Stefan / Maxim: why do we need drain_call_rcu() and what's
> > its difference from synchronize_rcu() in API level besides releasing and
> > retaking BQL when taken?
>
> Hi,
> I haven't taken a look at the patches or thought about the larger
> problem you're tackling here, but I wanted to reply to this specific
> question.
>
> It's been a long time since Maxim, Paolo, and I discussed this, but
> drain_call_rcu() and synchronize_rcu() do different things:
> - drain_call_rcu() is about waiting until the current thread's
> call_rcu() callbacks have completed.
> - synchronize_rcu() is about waiting until there are no more readers in
> the last grace period.
>
> Calling synchronize_rcu() doesn't guarantee that call_rcu_thread() has
> completed pending call_rcu() callbacks. Therefore it's not appropriate
> for the existing drain_call_rcu() callers because they rely on previous
> call_rcu() callbacks to have finished.
Ah I missed that detail.
I was quickly thinking whether such a requirement can also be done with a
customized rcu callback that will simply kick a signal after the real
"free" is done, while the call_rcu() context can wait for the signal. It's
just that assuming RCU callbacks will be executed in order is slightly
tricky. But I guess it's also hard if the call_rcu() is deep in the stack
so drain_call_rcu() should avoid fiddling on the details.
Thanks Stefan!
--
Peter Xu
next prev parent reply other threads:[~2023-03-01 16:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-25 16:31 [PATCH RFC 0/4] memory: Fix (/ Discuss) a few rcu issues Peter Xu
2023-02-25 16:31 ` [PATCH RFC 1/4] memory: Make memory_listeners RCU-safe for real Peter Xu
2023-02-25 16:31 ` [PATCH RFC 2/4] memory: Use rcu list variance for address_spaces modifications Peter Xu
2023-02-25 16:31 ` [PATCH RFC 3/4] memory: Protect memory_region_clear_dirty_bitmap with RCU Peter Xu
2023-02-25 16:31 ` [PATCH RFC 4/4] memory: Use rcu traversal in memory_region_to_address_space Peter Xu
2023-03-01 0:09 ` [PATCH RFC 0/4] memory: Fix (/ Discuss) a few rcu issues Stefan Hajnoczi
2023-03-01 16:08 ` Peter Xu [this message]
2023-03-02 9:46 ` David Hildenbrand
2023-03-02 14:45 ` Peter Xu
2023-03-02 14:56 ` Peter Xu
2023-03-02 15:11 ` David Hildenbrand
2023-03-02 21:50 ` Peter Xu
2023-03-03 9:10 ` David Hildenbrand
2023-03-03 16:20 ` Peter Xu
2023-03-03 16:58 ` David Hildenbrand
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=Y/94YfBFIqZhrplF@x1n \
--to=peterx@redhat.com \
--cc=david@redhat.com \
--cc=dgilbert@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.com \
--cc=xuchuangxclwt@bytedance.com \
/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).