From 57e5cab805c94d56f801a7e21098389a77584e34 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Mon, 5 Dec 2022 11:14:02 -0500 Subject: [PATCH] memory: sanity check flatview deref on mr transactions Content-type: text/plain Signed-off-by: Peter Xu --- include/exec/memory.h | 9 +++++++++ softmmu/memory.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 91f8a2395a..e136ab9558 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1069,8 +1069,17 @@ struct FlatView { MemoryRegion *root; }; +extern unsigned memory_region_transaction_depth; + 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. + */ + assert(memory_region_transaction_depth == 0); return qatomic_rcu_read(&as->current_map); } diff --git a/softmmu/memory.c b/softmmu/memory.c index bc0be3f62c..7cfcf5dffe 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -37,7 +37,7 @@ //#define DEBUG_UNASSIGNED -static unsigned memory_region_transaction_depth; +unsigned memory_region_transaction_depth; static bool memory_region_update_pending; static bool ioeventfd_update_pending; unsigned int global_dirty_tracking; -- 2.37.3