accel/tcg: Fix some CLI uses of icount / replay
cover accel/tcg: Fix some CLI uses of icount / replay
I got confused why trying replay and icount edge cases; clarify in case others do the same mis-uses.
Philippe Mathieu-Daudé (2):
replay: Explicitly require round-robin TCG accel/tcg/icount: Fix shift=auto incompatibility checks
accel/tcg/icount-common.c | 4 ++-- accel/tcg/tcg-all.c | 13 +++++++++++-- replay/replay.c | 6 ++++++ 3 files changed, 19 insertions(+), 4 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/2 replay: Explicitly require round-robin TCG
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().
--- accel/tcg/tcg-all.c | 13 +++++++++++-- replay/replay.c | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-)
accel/tcg/tcg-all.c +11 -2
@@ -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 ;
replay/replay.c +6 -0
@@ -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. */
Signature · 1 line
2.55.0
Re: [PATCH 1/2] replay: Explicitly require round-robin TCG
Quoted 42 lines · Philippe Mathieu-Daudé
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()andtcg_init_machine()when record/replay is active, with a message mentioning record/replay, never auto-select MTTCG then, and add a final check inreplay_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(-)accel/tcg/tcg-all.c +7
-1@@ -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);
accel/tcg/tcg-all.c static void tcg_set_thread(Object *obj, const char *value, Error **errp) · line 210
Quoted 10 lines
accel/tcg/tcg-all.c +4
-1if (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 ;
This part looks good.
Quoted 14 lines
replay/replay.c +1
-0@@ -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" );
replay/replay.c void replay_start(void) · line 458
Quoted 10 lines
replay/replay.c +5
-0exit (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. */
This part looks redundant.
Surely all of replay_start is covered by the accel/tcg bits above. I would expect this to be as simple as
{
if (replay_mode == REPLAY_MODE_NONE) {
return;
}
assert(tcg_enabled());
if (replay_blockers) {
error_reportf_err(replay_blockers->data, "Record/replay: ");
exit(1);
}
/* Timer for snapshotting will be set up here. */
replay_enable_events();
}r~
Re: [PATCH 1/2] replay: Explicitly require round-robin TCG
Quoted 97 lines · Richard Henderson
Quoted 44 lines · Philippe Mathieu-Daudé
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()andtcg_init_machine()when record/replay is active, with a message mentioning record/replay, never auto-select MTTCG then, and add a final check inreplay_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(-)accel/tcg/tcg-all.c +2
-1@@ -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 {
accel/tcg/tcg-all.c +0
-0@@ -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");accel/tcg/tcg-all.c +0
-0@@ -195,7 +201,10 @@ static void tcg_set_thread(Object *obj, const char *value, Error **errp)accel/tcg/tcg-all.c static void tcg_set_thread(Object *obj, const · line 210
Quoted 10 lines
accel/tcg/tcg-all.c +4
-1TCGState *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;This part looks good.
Quoted 13 lines
replay/replay.c +1
-0@@ -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"replay/replay.c void replay_start(void) · line 456
Quoted 9 lines
replay/replay.c +5
-0@@ -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. */This part looks redundant.
Surely all ofreplay_startis covered by the accel/tcg bits above. I would expect this to be as simple as{
if (replay_mode==REPLAY_MODE_NONE) {
return;
}assert(tcg_enabled());
if (
replay_blockers) {error_reportf_err(replay_blockers->data, "Record/replay: "); exit(1);
}
Quoted 4 lines
/* Timer for snapshotting will be set up here. */
replay_enable_events();
}
Indeed; I dropped that replay/replay.c change, thanks.
PATCH 2/2 accel/tcg/icount: Fix shift=auto incompatibility checks
In reply to Philippe Mathieu-Daudéicount_configure() rejects "shift=auto" combined with "align=on" or "sleep=off", but the checks read the file-scope variables icount_align_option and icount_sleep. Those are only assigned from the parsed options after the checks, so at that point they still hold their defaults (false and true). Neither check can trigger, and both invalid combinations were silently accepted:
$ qemu-system-aarch64 -M virt -icount shift=auto,sleep=off $ qemu-system-aarch64 -M virt -icount shift=auto,align=on
Test the values just parsed from the command line instead. Both commands now fail with:
qemu-system-aarch64: -icount shift=auto,sleep=off: shift=auto and sleep=off are incompatible
qemu-system-aarch64: -icount shift=auto,align=on: shift=auto and align=on are incompatible
Valid combinations still accepted:
- shift=auto
- shift=3,sleep=off
- shift=3,align=on
--- accel/tcg/icount-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
accel/tcg/icount-common.c +2 -2
@@ -441,10 +441,10 @@ bool icount_configure(QemuOpts *opts, Error **errp)error_setg (errp,"icount: Invalid shift value" );return false; } - }else if (icount_align_option) { + }else if (align) {error_setg (errp,"shift=auto and align=on are incompatible" );return false; - }else if (!icount_sleep) { + }else if (!sleep) {error_setg (errp,"shift=auto and sleep=off are incompatible" );return false; }
Signature · 1 line
2.55.0
Re: [PATCH 2/2] accel/tcg/icount: Fix shift=auto incompatibility checks
Quoted 22 lines · Philippe Mathieu-Daudé
icount_configure()rejects "shift=auto" combined with "align=on" or "sleep=off", but the checks read the file-scope variablesicount_align_optionandicount_sleep. Those are only assigned from the parsed options after the checks, so at that point they still hold their defaults (false and true). Neither check can trigger, and both invalid combinations were silently accepted:$ qemu-system-aarch64 -M virt -icount shift=auto,sleep=off $ qemu-system-aarch64 -M virt -icount shift=auto,align=onTest the values just parsed from the command line instead. Both commands now fail with:
qemu-system-aarch64: -icount shift=auto,sleep=off: shift=auto and sleep=off are incompatible
qemu-system-aarch64: -icount shift=auto,align=on: shift=auto and align=on are incompatibleValid combinations still accepted:
- shift=auto
- shift=3,sleep=off
- shift=3,align=on
Quoted 5 lines
Fixes abc9bf69a66a ("cpus: Fix configure_icount() error API violation")Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- accel/tcg/icount-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~