qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

target/xtensa: statically allocate xtensa_insnbufs in DisasContext

Rather than dynamically allocate, and risk failing to free
when we longjmp out of the translator, allocate the maximum
buffer size based on the maximum supported instruction length.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Richard Henderson <richard.henderson@linaro.org>

+6 -16
+3
target/xtensa/cpu.h
··· 213 213 #define MEMCTL_IL0EN 0x1 214 214 215 215 #define MAX_INSN_LENGTH 64 216 + #define MAX_INSNBUF_LENGTH \ 217 + ((MAX_INSN_LENGTH + sizeof(xtensa_insnbuf_word) - 1) / \ 218 + sizeof(xtensa_insnbuf_word)) 216 219 #define MAX_INSN_SLOTS 32 217 220 #define MAX_OPCODE_ARGS 16 218 221 #define MAX_NAREG 64
+1
target/xtensa/helper.c
··· 96 96 97 97 config->isa = xtensa_isa_init(config->isa_internal, NULL, NULL); 98 98 assert(xtensa_isa_maxlength(config->isa) <= MAX_INSN_LENGTH); 99 + assert(xtensa_insnbuf_size(config->isa) <= MAX_INSNBUF_LENGTH); 99 100 opcodes = xtensa_isa_num_opcodes(config->isa); 100 101 formats = xtensa_isa_num_formats(config->isa); 101 102 regfiles = xtensa_isa_num_regfiles(config->isa);
+2 -16
target/xtensa/translate.c
··· 72 72 unsigned cpenable; 73 73 74 74 uint32_t op_flags; 75 - xtensa_insnbuf insnbuf; 76 - xtensa_insnbuf slotbuf; 75 + xtensa_insnbuf_word insnbuf[MAX_INSNBUF_LENGTH]; 76 + xtensa_insnbuf_word slotbuf[MAX_INSNBUF_LENGTH]; 77 77 }; 78 78 79 79 static TCGv_i32 cpu_pc; ··· 1173 1173 dc->cwoe = tb_flags & XTENSA_TBFLAG_CWOE; 1174 1174 dc->callinc = ((tb_flags & XTENSA_TBFLAG_CALLINC_MASK) >> 1175 1175 XTENSA_TBFLAG_CALLINC_SHIFT); 1176 - 1177 - /* 1178 - * FIXME: This will leak when a failed instruction load or similar 1179 - * event causes us to longjump out of the translation loop and 1180 - * hence not clean-up in xtensa_tr_tb_stop 1181 - */ 1182 - if (dc->config->isa) { 1183 - dc->insnbuf = xtensa_insnbuf_alloc(dc->config->isa); 1184 - dc->slotbuf = xtensa_insnbuf_alloc(dc->config->isa); 1185 - } 1186 1176 init_sar_tracker(dc); 1187 1177 } 1188 1178 ··· 1272 1262 DisasContext *dc = container_of(dcbase, DisasContext, base); 1273 1263 1274 1264 reset_sar_tracker(dc); 1275 - if (dc->config->isa) { 1276 - xtensa_insnbuf_free(dc->config->isa, dc->insnbuf); 1277 - xtensa_insnbuf_free(dc->config->isa, dc->slotbuf); 1278 - } 1279 1265 if (dc->icount) { 1280 1266 tcg_temp_free(dc->next_icount); 1281 1267 }