Skip to content

Enable PC diversion via the plugin API

Florian Hofhammer qemu-devel 7 versions – In review

Get series with b4
b4 am [email protected] change-id 20260303-setpc-v5-c1df30bad07f

Versions newest first

  1. v7 Latest8 patches 9 repliesIn review
  2. v67 patches 18 repliesSuperseded inferred link
  3. v57 patches 8 repliesSuperseded inferred link
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v47 patches38 repliesSuperseded inferred link
v35 patches9 repliesSuperseded inferred link
v2 RFC2 patches13 repliesSuperseded inferred link
v11 patch2 repliesSuperseded

Changes in v7 from the cover letter

- Add Pierrick's patch to clamp 32-bit registers to prevent accidental
sign extension
- Fix documentation build by using __attribute__((__noreturn__)) instead
of G_NORETURN (required adjusting scripts/qemu-plugin-symbols.py).
- Rework test-plugin-set-pc test to get rid of volatile guard and make control flow more linear
- Link to v6: https://lore.kernel.org/qemu-devel/[email protected]

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8plugins/core: clamp syscall arguments if target is 32-bitplugins/core.c+21 -07 replies
2/8plugins: add flag to specify whether PC is rwinclude/plugins/qemu-plugin.h plugins/api.c plugins/core.c+22 -140 replies
3/8linux-user: make syscall emulation interruptiblelinux-user/aarch64/cpu_loop.c linux-user/alpha/cpu_loop.c linux-user/arm/cpu_loop.c +16 more+60 -220 replies
4/8plugins: add PC diversion API functioninclude/plugins/qemu-plugin.h plugins/api.c scripts/qemu-plugin-symbols.py+31 -20 replies
5/8tests/tcg: add tests for qemu_plugin_set_pc APIMAINTAINERS tests/tcg/arm/Makefile.target tests/tcg/hexagon/Makefile.target +6 more+273 -31 reply
6/8plugins: add read-only property for registersinclude/plugins/qemu-plugin.h plugins/api.c+19 -00 replies
7/8plugins: prohibit writing to read-only registersplugins/api.c+8 -30 replies
8/8tests/tcg/plugins: test register accessestests/tcg/plugins/meson.build tests/tcg/plugins/registers.c+80 -00 replies

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by.

PatchPierrick BouvierAlex BennéeWarner Losh
1/8R-b
2/8R-b R-b
3/8R-b R-b R-b
4/8R-b
5/8R-b
6/8R-b R-b
7/8R-b R-b
8/8R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v7 thread

Cover letter [PATCH v7 0/8] Enable PC diversion via the plugin API

Hi,

This patch series builds on top of the discussion from the thread at
https://lore.kernel.org/qemu-devel/[email protected]/
and adds a plugin API function to set the program counter of the guest, as just writing to it via qemu_plugin_write_register() has no direct effect.

This version v7 of the patch series addresses the requested changes from the previous v6 submission (details below).

Note: checkpatch.pl still reports a warning about line length violations in patch nr. 7/8 but I did not fix this, as the line was already > 80 characters long previously, the change added only a single character, and I think the readability of the code is better as it is now. Please let me know if you disagree and would like me to fix this!

@Pierrick: you already reviewed patch 3/7 (now 4/8) previously, but I had to change the regex in scripts/qemu-plugin-symbols.py to account for attributes, so please re-review!

Best regards,
Florian

Changes:
v7:
- Add Pierrick's patch to clamp 32-bit registers to prevent accidental
sign extension
- Fix documentation build by using __attribute__((__noreturn__)) instead
of G_NORETURN (required adjusting scripts/qemu-plugin-symbols.py).
- Rework test-plugin-set-pc test to get rid of volatile guard and make control flow more linear
- Link to v6: https://lore.kernel.org/qemu-devel/[email protected]
v6:
- update commit message for patch 4/7
v5:
- make QEMU abort via asserts instead of just returning an error from
the plugin API if preconditions are violated
- extend tests for qemu_plugin_set_pc() to different contexts
- fix issues highlighted by checkpatch.pl
v4:
- switch strcmp out in favor of g_strcmp0
- split the patch introducing the qemu_plugin_set_pc() API into three patches, two for preparing the plugin infrastructure and the syscall handling code and a third introducing the actual plugin API
v3:
- make PC registers read-only across architectures
- add tests for read-only registers
- adjust test structure for qemu_plugin_set_pc() by moving architecture-specific tests into corresponding directories
v2:
- add setjmp() in syscall handling path to allow PC redirection from
syscall callbacks (via longjmp(), the cpu_loop()'s setjmp() for
exiting a TB would not be live anymore in syscall handlers)
- add flags to ensure the qemu_plugin_set_pc() API is only called from contexts where the CPU is live
- add test for qemu_plugin_set_pc() API
v1:
- initial version

---
Florian Hofhammer (7):
plugins: add flag to specify whether PC is rw
linux-user: make syscall emulation interruptible
plugins: add PC diversion API function tests/tcg: add tests for qemu_plugin_set_pc API
plugins: add read-only property for registers
plugins: prohibit writing to read-only registers tests/tcg/plugins: test register accesses

Pierrick Bouvier (1):
plugins/core: clamp syscall arguments if target is 32-bit

 MAINTAINERS                                        |   1 +
 include/plugins/qemu-plugin.h                      |  19 +++
 linux-user/aarch64/cpu_loop.c                      |   2 +-
 linux-user/alpha/cpu_loop.c                        |   2 +-
 linux-user/arm/cpu_loop.c                          |   2 +-
 linux-user/hexagon/cpu_loop.c                      |   2 +-
 linux-user/hppa/cpu_loop.c                         |   1 +
 linux-user/i386/cpu_loop.c                         |   8 +-
 linux-user/include/special-errno.h                 |   8 ++
 linux-user/loongarch64/cpu_loop.c                  |   5 +-
 linux-user/m68k/cpu_loop.c                         |   2 +-
 linux-user/microblaze/cpu_loop.c                   |   2 +-
 linux-user/mips/cpu_loop.c                         |   9 +-
 linux-user/or1k/cpu_loop.c                         |   2 +-
 linux-user/ppc/cpu_loop.c                          |  10 +-
 linux-user/riscv/cpu_loop.c                        |   2 +-
 linux-user/s390x/cpu_loop.c                        |   2 +-
 linux-user/sh4/cpu_loop.c                          |   2 +-
 linux-user/sparc/cpu_loop.c                        |   4 +-
 linux-user/syscall.c                               |  16 +++
 linux-user/xtensa/cpu_loop.c                       |   1 +
 plugins/api.c                                      |  42 ++++++-
 plugins/core.c                                     |  50 ++++++--
 scripts/qemu-plugin-symbols.py                     |   9 +-
 tests/tcg/arm/Makefile.target                      |   6 +
 tests/tcg/hexagon/Makefile.target                  |   8 ++
 tests/tcg/multiarch/Makefile.target                |  17 ++-
 .../multiarch/{ => plugin}/check-plugin-output.sh  |   0
 .../{ => plugin}/test-plugin-mem-access.c          |   0
 tests/tcg/multiarch/plugin/test-plugin-set-pc.c    | 134 +++++++++++++++++++++
 tests/tcg/plugins/meson.build                      |   2 +
 tests/tcg/plugins/registers.c                      |  79 ++++++++++++
 tests/tcg/plugins/setpc.c                          | 109 +++++++++++++++++
 33 files changed, 514 insertions(+), 44 deletions(-)

---
base-commit: 3fb456e9a0e9eef6a71d9b49bfff596a0f0046e9
change-id: 20260303-setpc-v5-c1df30bad07f