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

target/riscv/pmp: Convert qemu_log_mask(LOG_TRACE) to trace events

Use the always-compiled trace events, remove the now unused
RISCV_DEBUG_PMP definition.

Note pmpaddr_csr_read() could previously do out-of-bound accesses
passing addr_index >= MAX_RISCV_PMPS.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>

authored by

Philippe Mathieu-Daudé and committed by
Palmer Dabbelt
6591efb5 0b84b662

+16 -21
+10 -21
target/riscv/pmp.c
··· 27 27 #include "qemu/log.h" 28 28 #include "qapi/error.h" 29 29 #include "cpu.h" 30 - 31 - #define RISCV_DEBUG_PMP 0 32 - #define PMP_DEBUG(fmt, ...) \ 33 - do { \ 34 - if (RISCV_DEBUG_PMP) { \ 35 - qemu_log_mask(LOG_TRACE, "%s: " fmt "\n", __func__, ##__VA_ARGS__);\ 36 - } \ 37 - } while (0) 30 + #include "trace.h" 38 31 39 32 static void pmp_write_cfg(CPURISCVState *env, uint32_t addr_index, 40 33 uint8_t val); ··· 302 295 int i; 303 296 uint8_t cfg_val; 304 297 305 - PMP_DEBUG("hart " TARGET_FMT_ld ": reg%d, val: 0x" TARGET_FMT_lx, 306 - env->mhartid, reg_index, val); 298 + trace_pmpcfg_csr_write(env->mhartid, reg_index, val); 307 299 308 300 if ((reg_index & 1) && (sizeof(target_ulong) == 8)) { 309 301 qemu_log_mask(LOG_GUEST_ERROR, ··· 332 324 val = pmp_read_cfg(env, (reg_index * sizeof(target_ulong)) + i); 333 325 cfg_val |= (val << (i * 8)); 334 326 } 335 - 336 - PMP_DEBUG("hart " TARGET_FMT_ld ": reg%d, val: 0x" TARGET_FMT_lx, 337 - env->mhartid, reg_index, cfg_val); 327 + trace_pmpcfg_csr_read(env->mhartid, reg_index, cfg_val); 338 328 339 329 return cfg_val; 340 330 } ··· 346 336 void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, 347 337 target_ulong val) 348 338 { 349 - PMP_DEBUG("hart " TARGET_FMT_ld ": addr%d, val: 0x" TARGET_FMT_lx, 350 - env->mhartid, addr_index, val); 351 - 339 + trace_pmpaddr_csr_write(env->mhartid, addr_index, val); 352 340 if (addr_index < MAX_RISCV_PMPS) { 353 341 if (!pmp_is_locked(env, addr_index)) { 354 342 env->pmp_state.pmp[addr_index].addr_reg = val; ··· 369 357 */ 370 358 target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index) 371 359 { 372 - PMP_DEBUG("hart " TARGET_FMT_ld ": addr%d, val: 0x" TARGET_FMT_lx, 373 - env->mhartid, addr_index, 374 - env->pmp_state.pmp[addr_index].addr_reg); 360 + target_ulong val = 0; 361 + 375 362 if (addr_index < MAX_RISCV_PMPS) { 376 - return env->pmp_state.pmp[addr_index].addr_reg; 363 + val = env->pmp_state.pmp[addr_index].addr_reg; 364 + trace_pmpaddr_csr_read(env->mhartid, addr_index, val); 377 365 } else { 378 366 qemu_log_mask(LOG_GUEST_ERROR, 379 367 "ignoring pmpaddr read - out of bounds\n"); 380 - return 0; 381 368 } 369 + 370 + return val; 382 371 }
+6
target/riscv/trace-events
··· 1 1 # target/riscv/cpu_helper.c 2 2 riscv_trap(uint64_t hartid, bool async, uint64_t cause, uint64_t epc, uint64_t tval, const char *desc) "hart:%"PRId64", async:%d, cause:%"PRId64", epc:0x%"PRIx64", tval:0x%"PRIx64", desc=%s" 3 + 4 + # pmp.c 5 + pmpcfg_csr_read(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": read reg%" PRIu32", val: 0x%" PRIx64 6 + pmpcfg_csr_write(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": write reg%" PRIu32", val: 0x%" PRIx64 7 + pmpaddr_csr_read(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": read addr%" PRIu32", val: 0x%" PRIx64 8 + pmpaddr_csr_write(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": write addr%" PRIu32", val: 0x%" PRIx64