@@ -1123,6 +1123,23 @@ static inline FlatView *address_space_to_flatview(AddressSpace *as)
return qatomic_rcu_read(&as->current_map);
}
+/*
+ * We recommend using address_space_to_flatview() rather than this one.
+ * Note that if we use this during a memory region transaction, we may
+ * see obsolete flatviews. We must bear with an obsolete map until commit.
+ * And outside a memory region transaction, this is basically the same as
+ * address_space_to_flatview().
+ */
+static inline FlatView *address_space_to_flatview_rcu(AddressSpace *as)
+{
+ /*
+ * Before using any flatview, sanity check BQL or RCU is held.
+ */
+ assert(qemu_mutex_iothread_locked() || rcu_read_is_locked());
+
+ return qatomic_rcu_read(&as->current_map);
+}
+
/**
* typedef flatview_cb: callback for flatview_for_each_range()
*
@@ -815,7 +815,7 @@ FlatView *address_space_get_flatview(AddressSpace *as)
RCU_READ_LOCK_GUARD();
do {
- view = address_space_to_flatview(as);
+ view = address_space_to_flatview_rcu(as);
/* If somebody has replaced as->current_map concurrently,
* flatview_ref returns false.
*/
In last patch, we wrap vm_load with begin/commit, here we introduce address_space_to_flatview_rcu() to avoid unnecessary enforce commit during vm_load. Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com> --- include/exec/memory.h | 17 +++++++++++++++++ softmmu/memory.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-)