Hi,
This commit introduces a syscall filtering mechanism for user-mode
emulation, allowing plugins to intercept and handle system calls.
The filtering mechanism works by allowing the plugins to register a
callback that is invoked before each system call. The callback can decide
whether to filter and skip the current syscall.
The syscall arguments will be dispatched in sequence to all the plugins
that have registered the filter callback. If a plugin returns true,
indicating that it has filtered this syscall, it needs to set the sysret.
After that, the syscall will no longer be dispatched to the rest plugins
and will also not be dispatched to the default handler (i.e. do_syscall1)
of QEMU.
The original syscall tracing will not be affected. If syscall is filtered,
then the callbacks used to track sysret will be recorded to the filtered
sysret.
Key changes from RFC V1 [1] to V2:
- Simplify the syscall filter mechanism and remove the fork-cpu-loop part,
which may be implemented in the future due to its complexity.
- Reuse the existing linked list registration utility, following the
registration style of the original syscall tracing APIs.
- Add the QEMU_PLUGIN_EV_VCPU_SYSCALL_FILTER enum to qemu_plugin_event.
- Introduce a new plugin API: qemu_plugin_register_vcpu_syscall_filter_cb.
Though Florian's set_pc method [2] offers greater flexibility, I believe
that the security and reliability guaranteed by this event filtering
approach is more important.
## Work Presented at KVM Forum Conference
At KVM Forum 2025, we presented Lorelei, a system designed to enable
guest programs executed by the QEMU user-mode emulator to accelerate
performance by invoking natively compiled host libraries via syscalls.
We have successfully supported libraries such as SDL, OpenGL, and
Vulkan, allowing QEMU user-mode to emulate GPU-dependent games.
Following an invitation from Mr. Bouvier to upstream Lorelei to QEMU, we
refined its architecture to load the Lorelei module as a TCG plugin.
Slides: https://gitlab.com/qemu-project/kvm-forum/-/raw/main/_attachments/2025/Slides_DQPMaZE.pdf
Video: https://www.youtube.com/watch?v=_jioQFm7wyU&list=PLW3ep1uCIRfxwmllXTOA2txfDWN6vUOHp&index=22
The core features required by Lorelei are the filtering processing of
system calls and the reentry and exit of CPU loops. We can start talking
about syscall filtering first.
This site [3] shows the currently supported libraries and games by
Lorelei-patched qemu-x86_64. The original qemu-x86_64 cannot leverage the
host hardware accelerators, thus fails to run these games.
We will gradually update this site, including adding the usage of
qemu-lorelei, allowing users to run games and other GUI programs using
QEMU by themselves.
[1] https://lore.kernel.org/qemu-devel/625873322.3277896.1759930752814.JavaMail.zimbra@sjtu.edu.cn/
[2] https://lists.nongnu.org/archive/html/qemu-devel/2025-08/msg00656.html
[3] https://lorelei-project.github.io/
Regards,
Ziyang Zhang
Signed-off-by: Ziyang Zhang <functioner@sjtu.edu.cn>
---
Ziyang Zhang (2):
linux-user: add a plugin API to filter syscalls
tcg tests: add a test to verify the syscall filter plugin API
include/qemu/plugin-event.h | 1 +
include/qemu/plugin.h | 28 +++++++++++++------
include/qemu/qemu-plugin.h | 24 +++++++++++++++++
include/user/syscall-trace.h | 16 +++++++++++
linux-user/syscall.c | 7 +++--
plugins/api.c | 7 +++++
plugins/core.c | 34 ++++++++++++++++++++++++
tests/tcg/multiarch/Makefile.target | 4 ++-
tests/tcg/multiarch/test-plugin-syscall-filter.c | 21 +++++++++++++++
tests/tcg/plugins/syscall.c | 14 ++++++++++
10 files changed, 145 insertions(+), 11 deletions(-)
---
base-commit: 37ad0e48e9fd58b170abbf31c18a994346f62ed7
change-id: 20251022-lorelei-rfc-b4-03297a039dae
Best regards,
--
Ziyang Zhang <functioner@sjtu.edu.cn>