Changes in v3:
 - Split in two commits
   - guest-visible tdata CSR availability change
   - icount trigger exception PC
 - reword the commit log to properly phrase the rationale
 - Added fixes to CSR available change

Changes in v2:
 - Added fixes tag
 - Always load itrigger_enabled flag in migration load
 - Reload itrigger_enabled flag after tdata3 write
 - Refresh stale itrigger_enabled after mcontext writes

Changes in v1:
Per the Sdtrig specification, on a breakpoint exception with icount, the
xepc must contain the virtual address of the next instruction that must
be executed to preserve the program flow. So for a one-instruction
trigger must fire only after the counted instruction retires. The xepc
must contains the architectural successor PC which for a taken branch
should be the branch target and the fallthrough otherwise.

QEMU previously disabled the translated-block trigger flag when icount was
enabled and relied on timer and privilege-change callbacks to update the
count, so the trigger could fire outside instruction retirement before the
guest PC advanced, causing Linux to observe the old PC and re-enter the same
breakpoint while single-stepping with icount.

Fix this by
  - publishing the icount trigger flag in translated blocks even with
    icount enabled
  - making the helper decrement the trigger count after the
    instruction has committed its successor PC and raise the trigger
    action only then
  - privilege-change callbacks refresh cached enabled state because itriggers
    tied to privilege mode.

Also make trigger data CSR availability depend on an implemented trigger slot
rather than the currently selected trigger type, so software can disable a
trigger with type zero and still write the rest of the slot state before
selecting another supported type.

itrigger timers are completely removed as they are not required now.

Himanshu Chauhan (2):
  target/riscv: Keep tdata CSRs available for disabled slots
  target/riscv: Fix icount trigger exception PC

 target/riscv/cpu.h            |   5 +-
 target/riscv/machine.c        |   5 +-
 target/riscv/tcg/cpu_helper.c |  10 +-
 target/riscv/tcg/csr.c        |   3 +
 target/riscv/tcg/debug.c      | 171 ++++++++++------------------------
 target/riscv/tcg/tcg-cpu.c    |   7 +-
 6 files changed, 66 insertions(+), 135 deletions(-)

-- 
2.43.0


Reply via email to