[RFC PATCH v2 0/2] Enable PC diversion via the plugin API

Florian Hofhammer posted 2 patches 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/e9bcd7c7-2d67-469e-b2f3-d1a68e456b2b@epfl.ch
Maintainers: Laurent Vivier <laurent@vivier.eu>, Brian Cain <brian.cain@oss.qualcomm.com>, "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>
include/qemu/qemu-plugin.h                    | 15 +++++++
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                    |  4 ++
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                    |  5 ++-
linux-user/openrisc/cpu_loop.c                |  2 +-
linux-user/ppc/cpu_loop.c                     |  6 ++-
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                          |  8 ++++
linux-user/xtensa/cpu_loop.c                  |  3 ++
plugins/api.c                                 | 17 +++++++-
plugins/core.c                                | 25 ++++++-----
tests/tcg/multiarch/Makefile.target           | 42 +++++++++++++++++++
.../tcg/multiarch/test-plugin-skip-syscalls.c | 26 ++++++++++++
tests/tcg/plugins/syscall.c                   |  6 +++
25 files changed, 170 insertions(+), 32 deletions(-)
create mode 100644 tests/tcg/multiarch/test-plugin-skip-syscalls.c
[RFC PATCH v2 0/2] Enable PC diversion via the plugin API
Posted by Florian Hofhammer 1 month, 1 week ago
Hi,

As originally discussed in the thread at
https://lists.nongnu.org/archive/html/qemu-devel/2025-08/msg00656.html
and later proposed in a patch at
https://lists.nongnu.org/archive/html/qemu-devel/2025-09/msg02218.html,
I am sending an updated version of my patch based on the previous
feedback.

Notable changes to v1:
- Added a setjmp() in the syscall handling path to allow redirecting
  the PC via cpu_loop_exit() also in syscall callbacks. The previous
  version would only work in instruction execution / memory access
  callback contexts, as the setjmp() corresponding to the longjmp() in
  cpu_loop_exit() was only live in those contexts.
- Added a flag to make sure the new API function is only called in
  contexts where it makes sense, i.e., during execution of guest code.
- Added a test that checks the new functionality by skipping a
  non-existent sentinel syscall.

I made it an RFC patch this time as I am not entirely sure if my
setting/handling of the new flag makes sense the way it is. I briefly
looked into making the QEMU_PLUGIN_CB_* flags actual flags via a
bitfield instead of enum values, but that would have required touching
a lot of code all over the place, so I'm not sure this is the way to go.

Happy to get feedback and your thoughts on the patches!

Thanks,
Florian


Florian Hofhammer (2):
  plugins: Add PC diversion API function
  tests/tcg: add test for qemu_plugin_set_pc API

 include/qemu/qemu-plugin.h                    | 15 +++++++
 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                    |  4 ++
 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                    |  5 ++-
 linux-user/openrisc/cpu_loop.c                |  2 +-
 linux-user/ppc/cpu_loop.c                     |  6 ++-
 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                          |  8 ++++
 linux-user/xtensa/cpu_loop.c                  |  3 ++
 plugins/api.c                                 | 17 +++++++-
 plugins/core.c                                | 25 ++++++-----
 tests/tcg/multiarch/Makefile.target           | 42 +++++++++++++++++++
 .../tcg/multiarch/test-plugin-skip-syscalls.c | 26 ++++++++++++
 tests/tcg/plugins/syscall.c                   |  6 +++
 25 files changed, 170 insertions(+), 32 deletions(-)
 create mode 100644 tests/tcg/multiarch/test-plugin-skip-syscalls.c

-- 
2.51.0
Re: [RFC PATCH v2 0/2] Enable PC diversion via the plugin API
Posted by Florian Hofhammer 2 weeks, 2 days ago
Hi,

Sorry for necrobumping this thread. I just wanted to follow up on this
and ask if there is still interest in this plugin API extension or if it
is going to be dropped in favor of the Lorelei patches (which would also
fulfill my original use case).

Thanks for your time,
Florian

On 06/10/2025 15:21, Florian Hofhammer wrote:
> Hi,
> 
> As originally discussed in the thread at
> https://lists.nongnu.org/archive/html/qemu-devel/2025-08/msg00656.html
> and later proposed in a patch at
> https://lists.nongnu.org/archive/html/qemu-devel/2025-09/msg02218.html,
> I am sending an updated version of my patch based on the previous
> feedback.
> 
> Notable changes to v1:
> - Added a setjmp() in the syscall handling path to allow redirecting
>   the PC via cpu_loop_exit() also in syscall callbacks. The previous
>   version would only work in instruction execution / memory access
>   callback contexts, as the setjmp() corresponding to the longjmp() in
>   cpu_loop_exit() was only live in those contexts.
> - Added a flag to make sure the new API function is only called in
>   contexts where it makes sense, i.e., during execution of guest code.
> - Added a test that checks the new functionality by skipping a
>   non-existent sentinel syscall.
> 
> I made it an RFC patch this time as I am not entirely sure if my
> setting/handling of the new flag makes sense the way it is. I briefly
> looked into making the QEMU_PLUGIN_CB_* flags actual flags via a
> bitfield instead of enum values, but that would have required touching
> a lot of code all over the place, so I'm not sure this is the way to go.
> 
> Happy to get feedback and your thoughts on the patches!
> 
> Thanks,
> Florian
> 
> 
> Florian Hofhammer (2):
>   plugins: Add PC diversion API function
>   tests/tcg: add test for qemu_plugin_set_pc API
> 
>  include/qemu/qemu-plugin.h                    | 15 +++++++
>  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                    |  4 ++
>  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                    |  5 ++-
>  linux-user/openrisc/cpu_loop.c                |  2 +-
>  linux-user/ppc/cpu_loop.c                     |  6 ++-
>  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                          |  8 ++++
>  linux-user/xtensa/cpu_loop.c                  |  3 ++
>  plugins/api.c                                 | 17 +++++++-
>  plugins/core.c                                | 25 ++++++-----
>  tests/tcg/multiarch/Makefile.target           | 42 +++++++++++++++++++
>  .../tcg/multiarch/test-plugin-skip-syscalls.c | 26 ++++++++++++
>  tests/tcg/plugins/syscall.c                   |  6 +++
>  25 files changed, 170 insertions(+), 32 deletions(-)
>  create mode 100644 tests/tcg/multiarch/test-plugin-skip-syscalls.c
>