[RFC PATCH v2 02/48] system/cpus: Defer memory layout changes until vCPUs are realized

Philippe Mathieu-Daudé posted 48 patches 4 months, 3 weeks ago
Only 41 patches received!
There is a newer version of this series
[RFC PATCH v2 02/48] system/cpus: Defer memory layout changes until vCPUs are realized
Posted by Philippe Mathieu-Daudé 4 months, 3 weeks ago
vCPUs are not really usable until fully realized. Do not attempt
to commit memory changes in the middle of vCPU realization. Defer
until realization is completed and vCPU fully operational.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 system/physmem.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/system/physmem.c b/system/physmem.c
index a8a9ca309ea..7004de3992c 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -2773,6 +2773,14 @@ static void tcg_commit(MemoryListener *listener)
     cpuas = container_of(listener, CPUAddressSpace, tcg_as_listener);
     cpu = cpuas->cpu;
 
+    if (!qdev_is_realized(DEVICE(cpu))) {
+        /*
+         * The listener is also called during realize, before
+         * all of the tcg machinery for run-on is initialized.
+         */
+        return;
+    }
+
     /*
      * Defer changes to as->memory_dispatch until the cpu is quiescent.
      * Otherwise we race between (1) other cpu threads and (2) ongoing
-- 
2.49.0