Record/replay needs a single deterministic instruction stream,
which only round-robin TCG provides. This was enforced only
implicitly, through icount being incompatible with MTTCG.

Reject thread=multi in tcg_set_thread() and tcg_init_machine()
when record/replay is active, with a message mentioning record/replay,
never auto-select MTTCG then, and add a final check in replay_start().

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 accel/tcg/tcg-all.c | 13 +++++++++++--
 replay/replay.c     |  6 ++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index bbc733a7070b..6ffe04649072 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -125,7 +125,8 @@ static int tcg_init_machine(AccelState *as, MachineState 
*ms)
          * there is one remaining limitation to check:
          *   - The guest can't be oversized (e.g. 64 bit guest on 32 bit host)
          */
-        if (mttcg_supported && !icount_enabled()) {
+        if (mttcg_supported && !icount_enabled()
+                            && replay_mode == REPLAY_MODE_NONE) {
             s->mttcg_enabled = ON_OFF_AUTO_ON;
             max_threads = ms->smp.max_cpus;
         } else {
@@ -133,6 +134,11 @@ static int tcg_init_machine(AccelState *as, MachineState 
*ms)
         }
         break;
     case ON_OFF_AUTO_ON:
+        if (replay_mode != REPLAY_MODE_NONE) {
+            error_report("MTTCG is not supported with record/replay, "
+                         "use round-robin TCG (thread=single)");
+            return -1;
+        }
         if (!mttcg_supported) {
             warn_report("Guest not yet converted to MTTCG - "
                         "you may get unexpected results");
@@ -195,7 +201,10 @@ static void tcg_set_thread(Object *obj, const char *value, 
Error **errp)
     TCGState *s = TCG_STATE(obj);
 
     if (strcmp(value, "multi") == 0) {
-        if (icount_enabled()) {
+        if (replay_mode != REPLAY_MODE_NONE) {
+            error_setg(errp, "No MTTCG with record/replay, "
+                             "use round-robin TCG (thread=single)");
+        } else if (icount_enabled()) {
             error_setg(errp, "No MTTCG when icount is enabled");
         } else {
             s->mttcg_enabled = ON_OFF_AUTO_ON;
diff --git a/replay/replay.c b/replay/replay.c
index 14437b32566b..d7d5ddc5a326 100644
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -14,6 +14,7 @@
 #include "exec/icount.h"
 #include "system/replay.h"
 #include "system/runstate.h"
+#include "system/tcg.h"
 #include "replay-internal.h"
 #include "qemu/main-loop.h"
 #include "qemu/option.h"
@@ -447,6 +448,11 @@ void replay_start(void)
         error_report("Please enable icount to use record/replay");
         exit(1);
     }
+    if (tcg_enabled() && qemu_tcg_mttcg_enabled()) {
+        error_report("Record/replay requires round-robin TCG, "
+                     "not MTTCG");
+        exit(1);
+    }
 
     /* Timer for snapshotting will be set up here. */
 
-- 
2.55.0


Reply via email to