From: Peter Xu <peterx@redhat.com>
To: Chuang Xu <xuchuangxclwt@bytedance.com>
Cc: qemu-devel@nongnu.org, dgilbert@redhat.com, quintela@redhat.com,
pbonzini@redhat.com, david@redhat.com, philmd@linaro.org,
zhouyibo@bytedance.com
Subject: Re: [RFC v4 2/3] memory: add depth assert in address_space_to_flatview
Date: Fri, 23 Dec 2022 10:37:00 -0500 [thread overview]
Message-ID: <Y6XLHFNqKzcXaeSD@x1n> (raw)
In-Reply-To: <20221223142307.1614945-3-xuchuangxclwt@bytedance.com>
On Fri, Dec 23, 2022 at 10:23:06PM +0800, Chuang Xu wrote:
> Before using any flatview, sanity check we're not during a memory
> region transaction or the map can be invalid.
>
> Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com>
> ---
> include/exec/memory.h | 9 +++++++++
> softmmu/memory.c | 5 +++++
> 2 files changed, 14 insertions(+)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 91f8a2395a..66c43b4862 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -1069,8 +1069,17 @@ struct FlatView {
> MemoryRegion *root;
> };
>
> +int memory_region_transaction_get_depth(void);
> +
> static inline FlatView *address_space_to_flatview(AddressSpace *as)
> {
> + /*
> + * Before using any flatview, sanity check we're not during a memory
> + * region transaction or the map can be invalid. Note that this can
> + * also be called during commit phase of memory transaction, but that
> + * should also only happen when the depth decreases to 0 first.
Nitpick: after adding the RCU check the comment may need slight touch up:
* Meanwhile it's safe to access current_map with RCU read lock held
* even if during a memory transaction. It means the user can bear
* with an obsolete map.
> + */
> + assert(memory_region_transaction_get_depth() == 0 || rcu_read_locked());
> return qatomic_rcu_read(&as->current_map);
> }
>
> diff --git a/softmmu/memory.c b/softmmu/memory.c
> index bc0be3f62c..01192e2e5b 100644
> --- a/softmmu/memory.c
> +++ b/softmmu/memory.c
> @@ -1116,6 +1116,11 @@ void memory_region_transaction_commit(void)
> }
> }
>
> +int memory_region_transaction_get_depth(void)
> +{
> + return memory_region_transaction_depth;
> +}
> +
> static void memory_region_destructor_none(MemoryRegion *mr)
> {
> }
> --
> 2.20.1
>
--
Peter Xu
next prev parent reply other threads:[~2022-12-23 15:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-23 14:23 [RFC v4 0/3] migration: reduce time of loading non-iterable vmstate Chuang Xu
2022-12-23 14:23 ` [RFC v4 1/3] rcu: introduce rcu_read_locked() Chuang Xu
2023-01-04 14:20 ` Alex Bennée
2023-01-05 8:17 ` Chuang Xu
2022-12-23 14:23 ` [RFC v4 2/3] memory: add depth assert in address_space_to_flatview Chuang Xu
2022-12-23 15:37 ` Peter Xu [this message]
2022-12-23 15:47 ` Paolo Bonzini
2022-12-23 15:54 ` Peter Xu
2022-12-28 8:27 ` Paolo Bonzini
2023-01-03 17:43 ` Peter Xu
2023-01-10 8:09 ` Chuang Xu
2023-01-10 14:45 ` Peter Xu
2023-01-12 7:59 ` Chuang Xu
2023-01-12 15:13 ` Peter Xu
2023-01-13 19:29 ` Chuang Xu
2022-12-28 10:50 ` Philippe Mathieu-Daudé
2023-01-04 7:39 ` [External] " Chuang Xu
2022-12-23 14:23 ` [RFC v4 3/3] migration: reduce time of loading non-iterable vmstate Chuang Xu
2022-12-23 16:06 ` David Hildenbrand
2023-01-04 7:31 ` Chuang Xu
2022-12-23 15:50 ` [RFC v4 0/3] " Peter Xu
2022-12-23 19:11 ` Chuang 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=Y6XLHFNqKzcXaeSD@x1n \
--to=peterx@redhat.com \
--cc=david@redhat.com \
--cc=dgilbert@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=xuchuangxclwt@bytedance.com \
--cc=zhouyibo@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).