* [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO
@ 2023-11-10 17:08 Richard Henderson
2023-11-14 12:55 ` Clément Chigot
2023-11-14 13:38 ` Claudio Fontana
0 siblings, 2 replies; 4+ messages in thread
From: Richard Henderson @ 2023-11-10 17:08 UTC (permalink / raw)
To: qemu-devel; +Cc: Clément Chigot
In cpu_exec_step_atomic, we did not set CF_LAST_IO, which can
lead to a loop with cpu_io_recompile.
But since 18a536f1f8 ("Always require can_do_io") we no longer need
a flag to indicate when the last insn should have can_do_io set, so
remove the flag entirely.
Reported-by: Clément Chigot <chigot@adacore.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1961
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
docs/devel/tcg-icount.rst | 6 ------
include/exec/translation-block.h | 13 ++++++-------
accel/tcg/cpu-exec.c | 2 +-
accel/tcg/tb-maint.c | 6 ++----
accel/tcg/translate-all.c | 4 ++--
accel/tcg/translator.c | 22 +++++++++-------------
system/watchpoint.c | 6 ++----
7 files changed, 22 insertions(+), 37 deletions(-)
diff --git a/docs/devel/tcg-icount.rst b/docs/devel/tcg-icount.rst
index 50c8e8dabc..7df883446a 100644
--- a/docs/devel/tcg-icount.rst
+++ b/docs/devel/tcg-icount.rst
@@ -62,12 +62,6 @@ To deal with this case, when an I/O access is made we:
- re-compile a single [1]_ instruction block for the current PC
- exit the cpu loop and execute the re-compiled block
-The new block is created with the CF_LAST_IO compile flag which
-ensures the final instruction translation starts with a call to
-gen_io_start() so we don't enter a perpetual loop constantly
-recompiling a single instruction block. For translators using the
-common translator_loop this is done automatically.
-
.. [1] sometimes two instructions if dealing with delay slots
Other I/O operations
diff --git a/include/exec/translation-block.h b/include/exec/translation-block.h
index b785751774..e2b26e16da 100644
--- a/include/exec/translation-block.h
+++ b/include/exec/translation-block.h
@@ -71,13 +71,12 @@ struct TranslationBlock {
#define CF_NO_GOTO_TB 0x00000200 /* Do not chain with goto_tb */
#define CF_NO_GOTO_PTR 0x00000400 /* Do not chain with goto_ptr */
#define CF_SINGLE_STEP 0x00000800 /* gdbstub single-step in effect */
-#define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */
-#define CF_MEMI_ONLY 0x00010000 /* Only instrument memory ops */
-#define CF_USE_ICOUNT 0x00020000
-#define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */
-#define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */
-#define CF_NOIRQ 0x00100000 /* Generate an uninterruptible TB */
-#define CF_PCREL 0x00200000 /* Opcodes in TB are PC-relative */
+#define CF_MEMI_ONLY 0x00001000 /* Only instrument memory ops */
+#define CF_USE_ICOUNT 0x00002000
+#define CF_INVALID 0x00004000 /* TB is stale. Set with @jmp_lock held */
+#define CF_PARALLEL 0x00008000 /* Generate code for a parallel context */
+#define CF_NOIRQ 0x00010000 /* Generate an uninterruptible TB */
+#define CF_PCREL 0x00020000 /* Opcodes in TB are PC-relative */
#define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */
#define CF_CLUSTER_SHIFT 24
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 1a5bc90220..c938eb96f8 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -721,7 +721,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
&& cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0) {
/* Execute just one insn to trigger exception pending in the log */
cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
- | CF_LAST_IO | CF_NOIRQ | 1;
+ | CF_NOIRQ | 1;
}
#endif
return false;
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index e678d20dc2..3d2a896220 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -1083,8 +1083,7 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc)
if (current_tb_modified) {
/* Force execution of one insn next time. */
CPUState *cpu = current_cpu;
- cpu->cflags_next_tb =
- 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
+ cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
return true;
}
return false;
@@ -1154,8 +1153,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,
if (current_tb_modified) {
page_collection_unlock(pages);
/* Force execution of one insn next time. */
- current_cpu->cflags_next_tb =
- 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
+ current_cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
mmap_unlock();
cpu_loop_exit_noexc(current_cpu);
}
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index b263857ecc..79a88f5fb7 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -304,7 +304,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
if (phys_pc == -1) {
/* Generate a one-shot TB with 1 insn in it */
- cflags = (cflags & ~CF_COUNT_MASK) | CF_LAST_IO | 1;
+ cflags = (cflags & ~CF_COUNT_MASK) | 1;
}
max_insns = cflags & CF_COUNT_MASK;
@@ -632,7 +632,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
* operations only (which execute after completion) so we don't
* double instrument the instruction.
*/
- cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | CF_LAST_IO | n;
+ cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | n;
if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
vaddr pc = log_pc(cpu, tb);
diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index 575b9812ad..38c34009a5 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -89,7 +89,7 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
* each translation block. The cost is minimal, plus it would be
* very easy to forget doing it in the translator.
*/
- set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO));
+ set_can_do_io(db, db->max_insns == 1);
return icount_start_insn;
}
@@ -151,13 +151,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
ops->tb_start(db, cpu);
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */
- if (cflags & CF_MEMI_ONLY) {
- /* We should only see CF_MEMI_ONLY for io_recompile. */
- assert(cflags & CF_LAST_IO);
- plugin_enabled = plugin_gen_tb_start(cpu, db, true);
- } else {
- plugin_enabled = plugin_gen_tb_start(cpu, db, false);
- }
+ plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY);
db->plugin_enabled = plugin_enabled;
while (true) {
@@ -169,11 +163,13 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
plugin_gen_insn_start(cpu, db);
}
- /* Disassemble one instruction. The translate_insn hook should
- update db->pc_next and db->is_jmp to indicate what should be
- done next -- either exiting this loop or locate the start of
- the next instruction. */
- if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) {
+ /*
+ * Disassemble one instruction. The translate_insn hook should
+ * update db->pc_next and db->is_jmp to indicate what should be
+ * done next -- either exiting this loop or locate the start of
+ * the next instruction.
+ */
+ if (db->num_insns == db->max_insns) {
/* Accept I/O on the last instruction. */
set_can_do_io(db, true);
}
diff --git a/system/watchpoint.c b/system/watchpoint.c
index 45d1f12faf..ba5ad13352 100644
--- a/system/watchpoint.c
+++ b/system/watchpoint.c
@@ -179,8 +179,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
*/
if (!cpu->neg.can_do_io) {
/* Force execution of one insn next time. */
- cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
- | curr_cflags(cpu);
+ cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
cpu_loop_exit_restore(cpu, ra);
}
/*
@@ -212,8 +211,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
cpu_loop_exit(cpu);
} else {
/* Force execution of one insn next time. */
- cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
- | curr_cflags(cpu);
+ cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
mmap_unlock();
cpu_loop_exit_noexc(cpu);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO
2023-11-10 17:08 [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO Richard Henderson
@ 2023-11-14 12:55 ` Clément Chigot
2023-11-14 13:38 ` Claudio Fontana
1 sibling, 0 replies; 4+ messages in thread
From: Clément Chigot @ 2023-11-14 12:55 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
Tested-by: Clément Chigot <chigot@adacore.com>
On Fri, Nov 10, 2023 at 6:08 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> In cpu_exec_step_atomic, we did not set CF_LAST_IO, which can
> lead to a loop with cpu_io_recompile.
>
> But since 18a536f1f8 ("Always require can_do_io") we no longer need
> a flag to indicate when the last insn should have can_do_io set, so
> remove the flag entirely.
>
> Reported-by: Clément Chigot <chigot@adacore.com>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1961
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> docs/devel/tcg-icount.rst | 6 ------
> include/exec/translation-block.h | 13 ++++++-------
> accel/tcg/cpu-exec.c | 2 +-
> accel/tcg/tb-maint.c | 6 ++----
> accel/tcg/translate-all.c | 4 ++--
> accel/tcg/translator.c | 22 +++++++++-------------
> system/watchpoint.c | 6 ++----
> 7 files changed, 22 insertions(+), 37 deletions(-)
>
> diff --git a/docs/devel/tcg-icount.rst b/docs/devel/tcg-icount.rst
> index 50c8e8dabc..7df883446a 100644
> --- a/docs/devel/tcg-icount.rst
> +++ b/docs/devel/tcg-icount.rst
> @@ -62,12 +62,6 @@ To deal with this case, when an I/O access is made we:
> - re-compile a single [1]_ instruction block for the current PC
> - exit the cpu loop and execute the re-compiled block
>
> -The new block is created with the CF_LAST_IO compile flag which
> -ensures the final instruction translation starts with a call to
> -gen_io_start() so we don't enter a perpetual loop constantly
> -recompiling a single instruction block. For translators using the
> -common translator_loop this is done automatically.
> -
> .. [1] sometimes two instructions if dealing with delay slots
>
> Other I/O operations
> diff --git a/include/exec/translation-block.h b/include/exec/translation-block.h
> index b785751774..e2b26e16da 100644
> --- a/include/exec/translation-block.h
> +++ b/include/exec/translation-block.h
> @@ -71,13 +71,12 @@ struct TranslationBlock {
> #define CF_NO_GOTO_TB 0x00000200 /* Do not chain with goto_tb */
> #define CF_NO_GOTO_PTR 0x00000400 /* Do not chain with goto_ptr */
> #define CF_SINGLE_STEP 0x00000800 /* gdbstub single-step in effect */
> -#define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */
> -#define CF_MEMI_ONLY 0x00010000 /* Only instrument memory ops */
> -#define CF_USE_ICOUNT 0x00020000
> -#define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */
> -#define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */
> -#define CF_NOIRQ 0x00100000 /* Generate an uninterruptible TB */
> -#define CF_PCREL 0x00200000 /* Opcodes in TB are PC-relative */
> +#define CF_MEMI_ONLY 0x00001000 /* Only instrument memory ops */
> +#define CF_USE_ICOUNT 0x00002000
> +#define CF_INVALID 0x00004000 /* TB is stale. Set with @jmp_lock held */
> +#define CF_PARALLEL 0x00008000 /* Generate code for a parallel context */
> +#define CF_NOIRQ 0x00010000 /* Generate an uninterruptible TB */
> +#define CF_PCREL 0x00020000 /* Opcodes in TB are PC-relative */
> #define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */
> #define CF_CLUSTER_SHIFT 24
>
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 1a5bc90220..c938eb96f8 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -721,7 +721,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
> && cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0) {
> /* Execute just one insn to trigger exception pending in the log */
> cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
> - | CF_LAST_IO | CF_NOIRQ | 1;
> + | CF_NOIRQ | 1;
> }
> #endif
> return false;
> diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
> index e678d20dc2..3d2a896220 100644
> --- a/accel/tcg/tb-maint.c
> +++ b/accel/tcg/tb-maint.c
> @@ -1083,8 +1083,7 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc)
> if (current_tb_modified) {
> /* Force execution of one insn next time. */
> CPUState *cpu = current_cpu;
> - cpu->cflags_next_tb =
> - 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
> + cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
> return true;
> }
> return false;
> @@ -1154,8 +1153,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,
> if (current_tb_modified) {
> page_collection_unlock(pages);
> /* Force execution of one insn next time. */
> - current_cpu->cflags_next_tb =
> - 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
> + current_cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
> mmap_unlock();
> cpu_loop_exit_noexc(current_cpu);
> }
> diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
> index b263857ecc..79a88f5fb7 100644
> --- a/accel/tcg/translate-all.c
> +++ b/accel/tcg/translate-all.c
> @@ -304,7 +304,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
>
> if (phys_pc == -1) {
> /* Generate a one-shot TB with 1 insn in it */
> - cflags = (cflags & ~CF_COUNT_MASK) | CF_LAST_IO | 1;
> + cflags = (cflags & ~CF_COUNT_MASK) | 1;
> }
>
> max_insns = cflags & CF_COUNT_MASK;
> @@ -632,7 +632,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
> * operations only (which execute after completion) so we don't
> * double instrument the instruction.
> */
> - cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | CF_LAST_IO | n;
> + cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | n;
>
> if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
> vaddr pc = log_pc(cpu, tb);
> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
> index 575b9812ad..38c34009a5 100644
> --- a/accel/tcg/translator.c
> +++ b/accel/tcg/translator.c
> @@ -89,7 +89,7 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
> * each translation block. The cost is minimal, plus it would be
> * very easy to forget doing it in the translator.
> */
> - set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO));
> + set_can_do_io(db, db->max_insns == 1);
>
> return icount_start_insn;
> }
> @@ -151,13 +151,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
> ops->tb_start(db, cpu);
> tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */
>
> - if (cflags & CF_MEMI_ONLY) {
> - /* We should only see CF_MEMI_ONLY for io_recompile. */
> - assert(cflags & CF_LAST_IO);
> - plugin_enabled = plugin_gen_tb_start(cpu, db, true);
> - } else {
> - plugin_enabled = plugin_gen_tb_start(cpu, db, false);
> - }
> + plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY);
> db->plugin_enabled = plugin_enabled;
>
> while (true) {
> @@ -169,11 +163,13 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
> plugin_gen_insn_start(cpu, db);
> }
>
> - /* Disassemble one instruction. The translate_insn hook should
> - update db->pc_next and db->is_jmp to indicate what should be
> - done next -- either exiting this loop or locate the start of
> - the next instruction. */
> - if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) {
> + /*
> + * Disassemble one instruction. The translate_insn hook should
> + * update db->pc_next and db->is_jmp to indicate what should be
> + * done next -- either exiting this loop or locate the start of
> + * the next instruction.
> + */
> + if (db->num_insns == db->max_insns) {
> /* Accept I/O on the last instruction. */
> set_can_do_io(db, true);
> }
> diff --git a/system/watchpoint.c b/system/watchpoint.c
> index 45d1f12faf..ba5ad13352 100644
> --- a/system/watchpoint.c
> +++ b/system/watchpoint.c
> @@ -179,8 +179,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
> */
> if (!cpu->neg.can_do_io) {
> /* Force execution of one insn next time. */
> - cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
> - | curr_cflags(cpu);
> + cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
> cpu_loop_exit_restore(cpu, ra);
> }
> /*
> @@ -212,8 +211,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
> cpu_loop_exit(cpu);
> } else {
> /* Force execution of one insn next time. */
> - cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
> - | curr_cflags(cpu);
> + cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
> mmap_unlock();
> cpu_loop_exit_noexc(cpu);
> }
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO
2023-11-10 17:08 [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO Richard Henderson
2023-11-14 12:55 ` Clément Chigot
@ 2023-11-14 13:38 ` Claudio Fontana
1 sibling, 0 replies; 4+ messages in thread
From: Claudio Fontana @ 2023-11-14 13:38 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: Clément Chigot
Reviewed-by: Claudio Fontana <cfontana@suse.de>
On 11/10/23 18:08, Richard Henderson wrote:
> In cpu_exec_step_atomic, we did not set CF_LAST_IO, which can
> lead to a loop with cpu_io_recompile.
>
> But since 18a536f1f8 ("Always require can_do_io") we no longer need
> a flag to indicate when the last insn should have can_do_io set, so
> remove the flag entirely.
>
> Reported-by: Clément Chigot <chigot@adacore.com>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1961
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> docs/devel/tcg-icount.rst | 6 ------
> include/exec/translation-block.h | 13 ++++++-------
> accel/tcg/cpu-exec.c | 2 +-
> accel/tcg/tb-maint.c | 6 ++----
> accel/tcg/translate-all.c | 4 ++--
> accel/tcg/translator.c | 22 +++++++++-------------
> system/watchpoint.c | 6 ++----
> 7 files changed, 22 insertions(+), 37 deletions(-)
>
> diff --git a/docs/devel/tcg-icount.rst b/docs/devel/tcg-icount.rst
> index 50c8e8dabc..7df883446a 100644
> --- a/docs/devel/tcg-icount.rst
> +++ b/docs/devel/tcg-icount.rst
> @@ -62,12 +62,6 @@ To deal with this case, when an I/O access is made we:
> - re-compile a single [1]_ instruction block for the current PC
> - exit the cpu loop and execute the re-compiled block
>
> -The new block is created with the CF_LAST_IO compile flag which
> -ensures the final instruction translation starts with a call to
> -gen_io_start() so we don't enter a perpetual loop constantly
> -recompiling a single instruction block. For translators using the
> -common translator_loop this is done automatically.
> -
> .. [1] sometimes two instructions if dealing with delay slots
>
> Other I/O operations
> diff --git a/include/exec/translation-block.h b/include/exec/translation-block.h
> index b785751774..e2b26e16da 100644
> --- a/include/exec/translation-block.h
> +++ b/include/exec/translation-block.h
> @@ -71,13 +71,12 @@ struct TranslationBlock {
> #define CF_NO_GOTO_TB 0x00000200 /* Do not chain with goto_tb */
> #define CF_NO_GOTO_PTR 0x00000400 /* Do not chain with goto_ptr */
> #define CF_SINGLE_STEP 0x00000800 /* gdbstub single-step in effect */
> -#define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */
> -#define CF_MEMI_ONLY 0x00010000 /* Only instrument memory ops */
> -#define CF_USE_ICOUNT 0x00020000
> -#define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */
> -#define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */
> -#define CF_NOIRQ 0x00100000 /* Generate an uninterruptible TB */
> -#define CF_PCREL 0x00200000 /* Opcodes in TB are PC-relative */
> +#define CF_MEMI_ONLY 0x00001000 /* Only instrument memory ops */
> +#define CF_USE_ICOUNT 0x00002000
> +#define CF_INVALID 0x00004000 /* TB is stale. Set with @jmp_lock held */
> +#define CF_PARALLEL 0x00008000 /* Generate code for a parallel context */
> +#define CF_NOIRQ 0x00010000 /* Generate an uninterruptible TB */
> +#define CF_PCREL 0x00020000 /* Opcodes in TB are PC-relative */
> #define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */
> #define CF_CLUSTER_SHIFT 24
>
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 1a5bc90220..c938eb96f8 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -721,7 +721,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
> && cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0) {
> /* Execute just one insn to trigger exception pending in the log */
> cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
> - | CF_LAST_IO | CF_NOIRQ | 1;
> + | CF_NOIRQ | 1;
> }
> #endif
> return false;
> diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
> index e678d20dc2..3d2a896220 100644
> --- a/accel/tcg/tb-maint.c
> +++ b/accel/tcg/tb-maint.c
> @@ -1083,8 +1083,7 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc)
> if (current_tb_modified) {
> /* Force execution of one insn next time. */
> CPUState *cpu = current_cpu;
> - cpu->cflags_next_tb =
> - 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
> + cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
> return true;
> }
> return false;
> @@ -1154,8 +1153,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,
> if (current_tb_modified) {
> page_collection_unlock(pages);
> /* Force execution of one insn next time. */
> - current_cpu->cflags_next_tb =
> - 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
> + current_cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
> mmap_unlock();
> cpu_loop_exit_noexc(current_cpu);
> }
> diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
> index b263857ecc..79a88f5fb7 100644
> --- a/accel/tcg/translate-all.c
> +++ b/accel/tcg/translate-all.c
> @@ -304,7 +304,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
>
> if (phys_pc == -1) {
> /* Generate a one-shot TB with 1 insn in it */
> - cflags = (cflags & ~CF_COUNT_MASK) | CF_LAST_IO | 1;
> + cflags = (cflags & ~CF_COUNT_MASK) | 1;
> }
>
> max_insns = cflags & CF_COUNT_MASK;
> @@ -632,7 +632,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
> * operations only (which execute after completion) so we don't
> * double instrument the instruction.
> */
> - cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | CF_LAST_IO | n;
> + cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | n;
>
> if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
> vaddr pc = log_pc(cpu, tb);
> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
> index 575b9812ad..38c34009a5 100644
> --- a/accel/tcg/translator.c
> +++ b/accel/tcg/translator.c
> @@ -89,7 +89,7 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
> * each translation block. The cost is minimal, plus it would be
> * very easy to forget doing it in the translator.
> */
> - set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO));
> + set_can_do_io(db, db->max_insns == 1);
>
> return icount_start_insn;
> }
> @@ -151,13 +151,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
> ops->tb_start(db, cpu);
> tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */
>
> - if (cflags & CF_MEMI_ONLY) {
> - /* We should only see CF_MEMI_ONLY for io_recompile. */
> - assert(cflags & CF_LAST_IO);
> - plugin_enabled = plugin_gen_tb_start(cpu, db, true);
> - } else {
> - plugin_enabled = plugin_gen_tb_start(cpu, db, false);
> - }
> + plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY);
> db->plugin_enabled = plugin_enabled;
>
> while (true) {
> @@ -169,11 +163,13 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
> plugin_gen_insn_start(cpu, db);
> }
>
> - /* Disassemble one instruction. The translate_insn hook should
> - update db->pc_next and db->is_jmp to indicate what should be
> - done next -- either exiting this loop or locate the start of
> - the next instruction. */
> - if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) {
> + /*
> + * Disassemble one instruction. The translate_insn hook should
> + * update db->pc_next and db->is_jmp to indicate what should be
> + * done next -- either exiting this loop or locate the start of
> + * the next instruction.
> + */
> + if (db->num_insns == db->max_insns) {
> /* Accept I/O on the last instruction. */
> set_can_do_io(db, true);
> }
> diff --git a/system/watchpoint.c b/system/watchpoint.c
> index 45d1f12faf..ba5ad13352 100644
> --- a/system/watchpoint.c
> +++ b/system/watchpoint.c
> @@ -179,8 +179,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
> */
> if (!cpu->neg.can_do_io) {
> /* Force execution of one insn next time. */
> - cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
> - | curr_cflags(cpu);
> + cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
> cpu_loop_exit_restore(cpu, ra);
> }
> /*
> @@ -212,8 +211,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
> cpu_loop_exit(cpu);
> } else {
> /* Force execution of one insn next time. */
> - cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
> - | curr_cflags(cpu);
> + cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
> mmap_unlock();
> cpu_loop_exit_noexc(cpu);
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH for-8.2 00/11] target/hppa: PA2.0 fixes
@ 2023-11-11 1:31 Richard Henderson
2023-11-11 1:31 ` [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO Richard Henderson
0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2023-11-11 1:31 UTC (permalink / raw)
To: qemu-devel; +Cc: deller
Fixes to the recent hppa64 cpu support to enable booting
the 64-bit linux kernel to user-space.
r~
Helge Deller (6):
target/hppa: Update to SeaBIOS-hppa version 11
hw/hppa: Require at least SeaBIOS-hppa version 11
target/hppa: Mask reserved PSW bits in expand_sm_imm
target/hppa: Fix calculation of CR_IIASQ back register
target/hppa: Fix possible overflow in TLB size calculation
hw/pci-host/astro: Fix boot for C3700 machine
Richard Henderson (5):
target/hppa: Use only low 2 immediate bits for PROBEI
target/hppa: Use PRIV_P_TO_MMU_IDX in helper_probe
target/hppa: Introduce MMU_IDX_MMU_DISABLED
target/hppa: Replace MMU_PHYS_IDX with MMU_ABS_IDX, MMU_ABS_W_IDX
target/hppa: Reduce TARGET_PHYS_ADDR_SPACE_BITS to 44
target/hppa/cpu-param.h | 2 +-
target/hppa/cpu.h | 25 +++++-----
hw/hppa/machine.c | 2 +-
hw/pci-host/astro.c | 73 +++++++++++++---------------
target/hppa/int_helper.c | 2 +-
target/hppa/mem_helper.c | 97 ++++++++++++++++++++++----------------
target/hppa/op_helper.c | 5 +-
target/hppa/translate.c | 41 +++++++++-------
hw/pci-host/meson.build | 2 +-
pc-bios/hppa-firmware.img | Bin 755480 -> 681132 bytes
roms/seabios-hppa | 2 +-
11 files changed, 134 insertions(+), 117 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO
2023-11-11 1:31 [PATCH for-8.2 00/11] target/hppa: PA2.0 fixes Richard Henderson
@ 2023-11-11 1:31 ` Richard Henderson
0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2023-11-11 1:31 UTC (permalink / raw)
To: qemu-devel; +Cc: deller, Clément Chigot
In cpu_exec_step_atomic, we did not set CF_LAST_IO, which can
lead to a loop with cpu_io_recompile.
But since 18a536f1f8 ("Always require can_do_io") we no longer need
a flag to indicate when the last insn should have can_do_io set, so
remove the flag entirely.
Reported-by: Clément Chigot <chigot@adacore.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1961
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
docs/devel/tcg-icount.rst | 6 ------
include/exec/translation-block.h | 13 ++++++-------
accel/tcg/cpu-exec.c | 2 +-
accel/tcg/tb-maint.c | 6 ++----
accel/tcg/translate-all.c | 4 ++--
accel/tcg/translator.c | 22 +++++++++-------------
system/watchpoint.c | 6 ++----
7 files changed, 22 insertions(+), 37 deletions(-)
diff --git a/docs/devel/tcg-icount.rst b/docs/devel/tcg-icount.rst
index 50c8e8dabc..7df883446a 100644
--- a/docs/devel/tcg-icount.rst
+++ b/docs/devel/tcg-icount.rst
@@ -62,12 +62,6 @@ To deal with this case, when an I/O access is made we:
- re-compile a single [1]_ instruction block for the current PC
- exit the cpu loop and execute the re-compiled block
-The new block is created with the CF_LAST_IO compile flag which
-ensures the final instruction translation starts with a call to
-gen_io_start() so we don't enter a perpetual loop constantly
-recompiling a single instruction block. For translators using the
-common translator_loop this is done automatically.
-
.. [1] sometimes two instructions if dealing with delay slots
Other I/O operations
diff --git a/include/exec/translation-block.h b/include/exec/translation-block.h
index b785751774..e2b26e16da 100644
--- a/include/exec/translation-block.h
+++ b/include/exec/translation-block.h
@@ -71,13 +71,12 @@ struct TranslationBlock {
#define CF_NO_GOTO_TB 0x00000200 /* Do not chain with goto_tb */
#define CF_NO_GOTO_PTR 0x00000400 /* Do not chain with goto_ptr */
#define CF_SINGLE_STEP 0x00000800 /* gdbstub single-step in effect */
-#define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */
-#define CF_MEMI_ONLY 0x00010000 /* Only instrument memory ops */
-#define CF_USE_ICOUNT 0x00020000
-#define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */
-#define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */
-#define CF_NOIRQ 0x00100000 /* Generate an uninterruptible TB */
-#define CF_PCREL 0x00200000 /* Opcodes in TB are PC-relative */
+#define CF_MEMI_ONLY 0x00001000 /* Only instrument memory ops */
+#define CF_USE_ICOUNT 0x00002000
+#define CF_INVALID 0x00004000 /* TB is stale. Set with @jmp_lock held */
+#define CF_PARALLEL 0x00008000 /* Generate code for a parallel context */
+#define CF_NOIRQ 0x00010000 /* Generate an uninterruptible TB */
+#define CF_PCREL 0x00020000 /* Opcodes in TB are PC-relative */
#define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */
#define CF_CLUSTER_SHIFT 24
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 1a5bc90220..c938eb96f8 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -721,7 +721,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
&& cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0) {
/* Execute just one insn to trigger exception pending in the log */
cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
- | CF_LAST_IO | CF_NOIRQ | 1;
+ | CF_NOIRQ | 1;
}
#endif
return false;
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index e678d20dc2..3d2a896220 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -1083,8 +1083,7 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc)
if (current_tb_modified) {
/* Force execution of one insn next time. */
CPUState *cpu = current_cpu;
- cpu->cflags_next_tb =
- 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
+ cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
return true;
}
return false;
@@ -1154,8 +1153,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,
if (current_tb_modified) {
page_collection_unlock(pages);
/* Force execution of one insn next time. */
- current_cpu->cflags_next_tb =
- 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu);
+ current_cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu);
mmap_unlock();
cpu_loop_exit_noexc(current_cpu);
}
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index b263857ecc..79a88f5fb7 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -304,7 +304,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
if (phys_pc == -1) {
/* Generate a one-shot TB with 1 insn in it */
- cflags = (cflags & ~CF_COUNT_MASK) | CF_LAST_IO | 1;
+ cflags = (cflags & ~CF_COUNT_MASK) | 1;
}
max_insns = cflags & CF_COUNT_MASK;
@@ -632,7 +632,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
* operations only (which execute after completion) so we don't
* double instrument the instruction.
*/
- cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | CF_LAST_IO | n;
+ cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | n;
if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
vaddr pc = log_pc(cpu, tb);
diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index 575b9812ad..38c34009a5 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -89,7 +89,7 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
* each translation block. The cost is minimal, plus it would be
* very easy to forget doing it in the translator.
*/
- set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO));
+ set_can_do_io(db, db->max_insns == 1);
return icount_start_insn;
}
@@ -151,13 +151,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
ops->tb_start(db, cpu);
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */
- if (cflags & CF_MEMI_ONLY) {
- /* We should only see CF_MEMI_ONLY for io_recompile. */
- assert(cflags & CF_LAST_IO);
- plugin_enabled = plugin_gen_tb_start(cpu, db, true);
- } else {
- plugin_enabled = plugin_gen_tb_start(cpu, db, false);
- }
+ plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY);
db->plugin_enabled = plugin_enabled;
while (true) {
@@ -169,11 +163,13 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
plugin_gen_insn_start(cpu, db);
}
- /* Disassemble one instruction. The translate_insn hook should
- update db->pc_next and db->is_jmp to indicate what should be
- done next -- either exiting this loop or locate the start of
- the next instruction. */
- if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) {
+ /*
+ * Disassemble one instruction. The translate_insn hook should
+ * update db->pc_next and db->is_jmp to indicate what should be
+ * done next -- either exiting this loop or locate the start of
+ * the next instruction.
+ */
+ if (db->num_insns == db->max_insns) {
/* Accept I/O on the last instruction. */
set_can_do_io(db, true);
}
diff --git a/system/watchpoint.c b/system/watchpoint.c
index 45d1f12faf..ba5ad13352 100644
--- a/system/watchpoint.c
+++ b/system/watchpoint.c
@@ -179,8 +179,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
*/
if (!cpu->neg.can_do_io) {
/* Force execution of one insn next time. */
- cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
- | curr_cflags(cpu);
+ cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
cpu_loop_exit_restore(cpu, ra);
}
/*
@@ -212,8 +211,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
cpu_loop_exit(cpu);
} else {
/* Force execution of one insn next time. */
- cpu->cflags_next_tb = 1 | CF_LAST_IO | CF_NOIRQ
- | curr_cflags(cpu);
+ cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(cpu);
mmap_unlock();
cpu_loop_exit_noexc(cpu);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-14 13:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-10 17:08 [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO Richard Henderson
2023-11-14 12:55 ` Clément Chigot
2023-11-14 13:38 ` Claudio Fontana
-- strict thread matches above, loose matches on Subject: below --
2023-11-11 1:31 [PATCH for-8.2 00/11] target/hppa: PA2.0 fixes Richard Henderson
2023-11-11 1:31 ` [PATCH for-8.2] accel/tcg: Remove CF_LAST_IO Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).