[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v2 1/3] memory: add depth assert in address_space_to_flatview
From: |
Chuang Xu |
Subject: |
[RFC v2 1/3] memory: add depth assert in address_space_to_flatview |
Date: |
Tue, 13 Dec 2022 00:49:40 +0800 |
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 | 1 -
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 91f8a2395a..b43cd46084 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1069,8 +1069,17 @@ struct FlatView {
MemoryRegion *root;
};
+static 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..f177c40cd8 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -37,7 +37,6 @@
//#define DEBUG_UNASSIGNED
-static unsigned memory_region_transaction_depth;
static bool memory_region_update_pending;
static bool ioeventfd_update_pending;
unsigned int global_dirty_tracking;
--
2.20.1