From ac46898b3c99da9bd78931e6ef2e91b441bc2366 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Fri, 16 Feb 2018 08:39:07 -0500 Subject: [PATCH] cpu-exec: invalidate nocache translation if they are interrupted In this case, QEMU might longjmp out of cpu-exec.c and miss the final cleanup in cpu_exec_nocache. Do this manually through a new compile flag. Backports commit d8a499f17ee5f05407874f29f69f0e3e3198a853 from qemu --- qemu/include/exec/exec-all.h | 1 + qemu/translate-all.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/qemu/include/exec/exec-all.h b/qemu/include/exec/exec-all.h index 976de3e3..6923f6fb 100644 --- a/qemu/include/exec/exec-all.h +++ b/qemu/include/exec/exec-all.h @@ -193,6 +193,7 @@ struct TranslationBlock { uint16_t cflags; /* compile flags */ #define CF_COUNT_MASK 0x7fff #define CF_LAST_IO 0x8000 /* Last insn may be an IO access. */ +#define CF_NOCACHE 0x10000 /* To be freed after execution */ void *tc_ptr; /* pointer to the translated code */ /* next matching tb for physical address. */ diff --git a/qemu/translate-all.c b/qemu/translate-all.c index 3dfa1fe7..955b7b50 100644 --- a/qemu/translate-all.c +++ b/qemu/translate-all.c @@ -283,6 +283,12 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) tb = tb_find_pc(env->uc, retaddr); if (tb) { cpu_restore_state_from_tb(cpu, tb, retaddr); + if (tb->cflags & CF_NOCACHE) { + /* one-shot translation, invalidate it immediately */ + cpu->current_tb = NULL; + tb_phys_invalidate(cpu->uc, tb, -1); + tb_free(cpu->uc, tb); + } return true; } return false;