[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 24/47] tcg: Return the TB pointer from the rx region from exit_tb
From: |
Richard Henderson |
Subject: |
[PULL 24/47] tcg: Return the TB pointer from the rx region from exit_tb |
Date: |
Thu, 7 Jan 2021 10:14:25 -1000 |
This produces a small pc-relative displacement within the
generated code to the TB structure that preceeds it.
Reviewed-by: Joelle van Dyne <j@getutm.app>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/cpu-exec.c | 35 +++++++++++++++++++++--------------
tcg/tcg-op.c | 13 ++++++++++++-
2 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 29294f2804..e0df9b6a1d 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -154,13 +154,12 @@ static void init_delay_params(SyncClocks *sc, const
CPUState *cpu)
* TCG is not considered a security-sensitive part of QEMU so this does not
* affect the impact of CFI in environment with high security requirements
*/
-QEMU_DISABLE_CFI
-static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock
*itb)
+static inline TranslationBlock * QEMU_DISABLE_CFI
+cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
{
CPUArchState *env = cpu->env_ptr;
uintptr_t ret;
TranslationBlock *last_tb;
- int tb_exit;
const void *tb_ptr = itb->tc.ptr;
qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
@@ -188,11 +187,20 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu,
TranslationBlock *itb)
ret = tcg_qemu_tb_exec(env, tb_ptr);
cpu->can_do_io = 1;
- last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
- tb_exit = ret & TB_EXIT_MASK;
- trace_exec_tb_exit(last_tb, tb_exit);
+ /*
+ * TODO: Delay swapping back to the read-write region of the TB
+ * until we actually need to modify the TB. The read-only copy,
+ * coming from the rx region, shares the same host TLB entry as
+ * the code that executed the exit_tb opcode that arrived here.
+ * If we insist on touching both the RX and the RW pages, we
+ * double the host TLB pressure.
+ */
+ last_tb = tcg_splitwx_to_rw((void *)(ret & ~TB_EXIT_MASK));
+ *tb_exit = ret & TB_EXIT_MASK;
- if (tb_exit > TB_EXIT_IDX1) {
+ trace_exec_tb_exit(last_tb, *tb_exit);
+
+ if (*tb_exit > TB_EXIT_IDX1) {
/* We didn't start executing this TB (eg because the instruction
* counter hit zero); we must restore the guest PC to the address
* of the start of the TB.
@@ -210,7 +218,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu,
TranslationBlock *itb)
cc->set_pc(cpu, last_tb->pc);
}
}
- return ret;
+ return last_tb;
}
#ifndef CONFIG_USER_ONLY
@@ -221,6 +229,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
{
TranslationBlock *tb;
uint32_t cflags = curr_cflags() | CF_NOCACHE;
+ int tb_exit;
if (ignore_icount) {
cflags &= ~CF_USE_ICOUNT;
@@ -238,7 +247,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
/* execute the generated code */
trace_exec_tb_nocache(tb, tb->pc);
- cpu_tb_exec(cpu, tb);
+ cpu_tb_exec(cpu, tb, &tb_exit);
mmap_lock();
tb_phys_invalidate(tb, -1);
@@ -272,6 +281,7 @@ void cpu_exec_step_atomic(CPUState *cpu)
uint32_t flags;
uint32_t cflags = 1;
uint32_t cf_mask = cflags & CF_HASH_MASK;
+ int tb_exit;
if (sigsetjmp(cpu->jmp_env, 0) == 0) {
start_exclusive();
@@ -288,7 +298,7 @@ void cpu_exec_step_atomic(CPUState *cpu)
cpu_exec_enter(cpu);
/* execute the generated code */
trace_exec_tb(tb, pc);
- cpu_tb_exec(cpu, tb);
+ cpu_tb_exec(cpu, tb, &tb_exit);
cpu_exec_exit(cpu);
} else {
/*
@@ -684,13 +694,10 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
TranslationBlock **last_tb, int *tb_exit)
{
- uintptr_t ret;
int32_t insns_left;
trace_exec_tb(tb, tb->pc);
- ret = cpu_tb_exec(cpu, tb);
- tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
- *tb_exit = ret & TB_EXIT_MASK;
+ tb = cpu_tb_exec(cpu, tb, tb_exit);
if (*tb_exit != TB_EXIT_REQUESTED) {
*last_tb = tb;
return;
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 19fa8e4691..0374b5d56d 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -2666,7 +2666,18 @@ void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi,
TCGv_i64 arg)
void tcg_gen_exit_tb(const TranslationBlock *tb, unsigned idx)
{
- uintptr_t val = (uintptr_t)tb + idx;
+ /*
+ * Let the jit code return the read-only version of the
+ * TranslationBlock, so that we minimize the pc-relative
+ * distance of the address of the exit_tb code to TB.
+ * This will improve utilization of pc-relative address loads.
+ *
+ * TODO: Move this to translator_loop, so that all const
+ * TranslationBlock pointers refer to read-only memory.
+ * This requires coordination with targets that do not use
+ * the translator_loop.
+ */
+ uintptr_t val = (uintptr_t)tcg_splitwx_to_rx((void *)tb) + idx;
if (tb == NULL) {
tcg_debug_assert(idx == 0);
--
2.25.1
- [PULL 14/47] tcg: Adjust tcg_out_call for const, (continued)
- [PULL 14/47] tcg: Adjust tcg_out_call for const, Richard Henderson, 2021/01/07
- [PULL 13/47] tcg: Adjust TCGLabel for const, Richard Henderson, 2021/01/07
- [PULL 11/47] tcg: Add in_code_gen_buffer, Richard Henderson, 2021/01/07
- [PULL 15/47] tcg: Adjust tcg_out_label for const, Richard Henderson, 2021/01/07
- [PULL 16/47] tcg: Adjust tcg_register_jit for const, Richard Henderson, 2021/01/07
- [PULL 17/47] tcg: Adjust tb_target_set_jmp_target for split-wx, Richard Henderson, 2021/01/07
- [PULL 19/47] tcg: Make tb arg to synchronize_from_tb const, Richard Henderson, 2021/01/07
- [PULL 18/47] tcg: Make DisasContextBase.tb const, Richard Henderson, 2021/01/07
- [PULL 25/47] tcg/i386: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 23/47] accel/tcg: Support split-wx for darwin/iOS with vm_remap, Richard Henderson, 2021/01/07
- [PULL 24/47] tcg: Return the TB pointer from the rx region from exit_tb,
Richard Henderson <=
- [PULL 21/47] tcg: Add --accel tcg,split-wx property, Richard Henderson, 2021/01/07
- [PULL 22/47] accel/tcg: Support split-wx for linux with memfd, Richard Henderson, 2021/01/07
- [PULL 27/47] tcg/aarch64: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 29/47] tcg/tci: Push const down through bytecode reading, Richard Henderson, 2021/01/07
- [PULL 32/47] tcg/ppc: Use tcg_out_mem_long to reset TCG_REG_TB, Richard Henderson, 2021/01/07
- [PULL 36/47] tcg/s390: Use tcg_tbrel_diff, Richard Henderson, 2021/01/07
- [PULL 20/47] tcg: Use Error with alloc_code_gen_buffer, Richard Henderson, 2021/01/07
- [PULL 33/47] tcg/ppc: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 37/47] tcg/s390: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 38/47] tcg/riscv: Fix branch range checks, Richard Henderson, 2021/01/07