All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/3] Plugins fixes 2026-07-20
@ 2026-07-20 20:04 Pierrick Bouvier
  2026-07-20 20:04 ` [PULL 1/3] contrib/plugins/dlcall: correct the syscall number claim, note the data model Pierrick Bouvier
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pierrick Bouvier @ 2026-07-20 20:04 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, richard.henderson, pbonzini, stefanha
  Cc: pierrick.bouvier

The following changes since commit bd6079a7a1d14de0918a7715ef6db85dc32de3bb:

  Merge tag 'next-pull-request' of https://gitlab.com/peterx/qemu into staging (2026-07-20 11:12:38 -0400)

are available in the Git repository at:

  https://gitlab.com/p-b-o/qemu tags/pbouvier/pr/plugins-20260720

for you to fetch changes up to 533c98e769c79bcef56c6e466c4f3cb4c195181e:

  docs/about/emulation: sharpen the dlcall boundary and its guest requirements (2026-07-20 13:03:14 -0700)

----------------------------------------------------------------
Changes:
- [PATCH 0/3] dlcall: correct the syscall number claim and the guest (Ziyang Zhang <functioner@sjtu.edu.cn>)
  Link: https://lore.kernel.org/qemu-devel/20260719074730.1520517-1-functioner@sjtu.edu.cn

----------------------------------------------------------------
Ziyang Zhang (3):
      contrib/plugins/dlcall: correct the syscall number claim, note the data model
      tests/tcg: correct why the magic syscall number is safe here
      docs/about/emulation: sharpen the dlcall boundary and its guest requirements

 contrib/plugins/dlcall.c                         | 32 +++++++++++++++++-------
 docs/about/emulation.rst                         | 31 +++++++++++++++--------
 tests/tcg/multiarch/test-plugin-syscall-filter.c |  9 ++++---
 3 files changed, 50 insertions(+), 22 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PULL 1/3] contrib/plugins/dlcall: correct the syscall number claim, note the data model
  2026-07-20 20:04 [PULL 0/3] Plugins fixes 2026-07-20 Pierrick Bouvier
@ 2026-07-20 20:04 ` Pierrick Bouvier
  2026-07-20 20:04 ` [PULL 2/3] tests/tcg: correct why the magic syscall number is safe here Pierrick Bouvier
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Pierrick Bouvier @ 2026-07-20 20:04 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, richard.henderson, pbonzini, stefanha
  Cc: pierrick.bouvier

From: Ziyang Zhang <functioner@sjtu.edu.cn>

The comment claimed every Linux ABI keeps its syscall numbers well below the
minimum, and that the minimum is all N has to satisfy. Neither holds.

MIPS O32 bases its numbering at 4000, so the default 4096 is its getpriority.
Raising N does not rescue it either, because O32 answers numbers its table does
not define with ENOSYS before the filter runs, which leaves no number that is
both free and reachable on that ABI. arm32 bounds N from above too, with ENOSYS
or SIGILL past ARM_NR_BASE. Say all of this, so the number can be chosen with
the target in mind.

guest_base == 0 is not the only requirement either. Host pointers are written
back through the caller's out pointers, so the guest must match the host's
pointer width and endianness. Fold that into the existing warning.

Also assert the two out pointers that lacked it, and point at Lorelei for
argument marshalling, callbacks and variadic functions.

Co-authored-by: Kailiang Xu <xukl2019@sjtu.edu.cn>
Co-authored-by: Mingyuan Xia <xiamy@ultrarisc.com>
Signed-off-by: Ziyang Zhang <functioner@sjtu.edu.cn>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Link: https://lore.kernel.org/qemu-devel/20260719074730.1520517-2-functioner@sjtu.edu.cn
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
 contrib/plugins/dlcall.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/contrib/plugins/dlcall.c b/contrib/plugins/dlcall.c
index 9d2230b2d1a..b624735e62c 100644
--- a/contrib/plugins/dlcall.c
+++ b/contrib/plugins/dlcall.c
@@ -10,7 +10,8 @@
  * nothing about how a library is thunked. Any toolchain can implement the
  * userspace side. Lorelei is one end-to-end implementation (guest/host
  * runtimes plus a thunk compiler that generates thunks from a library's
- * headers):
+ * headers), and how it handles argument marshalling, callbacks and variadic
+ * functions can serve as a reference:
  * https://github.com/rover2024/lorelei
  *
  * See docs/about/emulation.rst|Dynamic Linking Call for details and examples.
@@ -20,12 +21,13 @@
  * execution in the QEMU host process. It is NOT a sandbox and provides no
  * isolation; only load it for guests you fully trust.
  *
- * WARNING: requires guest_base == 0, which is qemu-user's default. Pointer
- * operands are dereferenced as host addresses directly, and the invoked host
- * functions dereference guest pointers with no address translation, so guest
- * and host must share a single address space. A non-zero guest_base (e.g. set
- * via -B/-R) would make every pointer off by guest_base and hit unrelated
- * host memory.
+ * WARNING: requires guest_base == 0, which is qemu-user's default, and a
+ * guest whose pointer width and endianness match the host's. Pointer operands
+ * are dereferenced as host addresses directly, and the invoked host functions
+ * dereference guest pointers with no address translation, so guest and host
+ * must share a single address space and agree on how a pointer is stored. A
+ * non-zero guest_base (e.g. set via -B/-R) would make every pointer off by
+ * guest_base and hit unrelated host memory.
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
@@ -46,8 +48,18 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
  *
  * It defaults to DLCALL_SYSCALL_DEFAULT and can be overridden at load time
  * with the "syscall_num=N" argument. To avoid hijacking a real syscall the
- * guest might issue, N must be at least DLCALL_SYSCALL_MIN: every Linux ABI
- * keeps its syscall numbers well below this; numbers from here up are free.
+ * guest might issue, N must be at least DLCALL_SYSCALL_MIN, which most Linux
+ * ABIs keep their syscall numbers well below.
+ *
+ * N also has to reach the filter at all, which bounds it from above in a
+ * target specific way: arm32 answers anything past ARM_NR_BASE (0xf0000) with
+ * ENOSYS or SIGILL before do_syscall() runs, while aarch64 has no such bound.
+ *
+ * MIPS O32 bases its numbering at 4000, so the default is a real syscall there
+ * (getpriority). Raising N does not help either, because O32 rejects numbers
+ * its table does not define, again before the filter runs, which leaves no
+ * number that is both free and reachable on that ABI. Its N32 and N64 ABIs
+ * base at 6000 and 5000 and have no such gate, so they are unaffected.
  */
 enum {
     DLCALL_SYSCALL_DEFAULT = 4096,
@@ -168,6 +180,7 @@ static bool vcpu_syscall_filter(unsigned int vcpu_index,
         case DLCALL_ID_FREE_LIBRARY: {
             void *handle = (void *) a2;
             int *ret_ptr = (int *) a3;
+            assert(ret_ptr);
             *ret_ptr = dlclose(handle);
             *sysret = 0;
             break;
@@ -176,6 +189,7 @@ static bool vcpu_syscall_filter(unsigned int vcpu_index,
         /* Get the last error message for a library event. */
         case DLCALL_ID_GET_LIBRARY_ERROR: {
             const char **error_ptr = (const char **) a2;
+            assert(error_ptr);
             *error_ptr = dlerror();
             *sysret = 0;
             break;
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 2/3] tests/tcg: correct why the magic syscall number is safe here
  2026-07-20 20:04 [PULL 0/3] Plugins fixes 2026-07-20 Pierrick Bouvier
  2026-07-20 20:04 ` [PULL 1/3] contrib/plugins/dlcall: correct the syscall number claim, note the data model Pierrick Bouvier
@ 2026-07-20 20:04 ` Pierrick Bouvier
  2026-07-20 20:04 ` [PULL 3/3] docs/about/emulation: sharpen the dlcall boundary and its guest requirements Pierrick Bouvier
  2026-07-21 16:00 ` [PULL 0/3] Plugins fixes 2026-07-20 Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Pierrick Bouvier @ 2026-07-20 20:04 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, richard.henderson, pbonzini, stefanha
  Cc: pierrick.bouvier

From: Ziyang Zhang <functioner@sjtu.edu.cn>

The comment said 4096 was picked because no ISA in Linux uses it. The same
comment already notes that mips 32 bits numbers from 4000, which makes 4096 its
getpriority.

What actually keeps this test safe is the filter, which matches on the first
argument as well, so a real syscall carrying this number is left alone. Say
that instead.

Co-authored-by: Kailiang Xu <xukl2019@sjtu.edu.cn>
Co-authored-by: Mingyuan Xia <xiamy@ultrarisc.com>
Signed-off-by: Ziyang Zhang <functioner@sjtu.edu.cn>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Link: https://lore.kernel.org/qemu-devel/20260719074730.1520517-3-functioner@sjtu.edu.cn
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
 tests/tcg/multiarch/test-plugin-syscall-filter.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/tcg/multiarch/test-plugin-syscall-filter.c b/tests/tcg/multiarch/test-plugin-syscall-filter.c
index 951e338a7c9..089fb2a1107 100644
--- a/tests/tcg/multiarch/test-plugin-syscall-filter.c
+++ b/tests/tcg/multiarch/test-plugin-syscall-filter.c
@@ -23,9 +23,12 @@ int main(int argc, char *argv[])
      * "linux-user/arm/cpu_loop.c:cpu_loop".
      * As well, some arch expect a minimum, like 4000 for mips 32 bits.
      *
-     * Therefore, we pick 4096 because, as of now, no ISA in Linux uses this
-     * number. This is just a test case; replace this number as needed in the
-     * future.
+     * Therefore, we pick 4096, which sits between those bounds. It is not
+     * unused everywhere though: mips 32 bits numbers from 4000, so 4096 is its
+     * getpriority. This test is unaffected because the filter also requires
+     * the first argument to be 0x66CCFF, so a real syscall carrying this
+     * number falls through untouched. This is just a test case, so replace
+     * this number as needed in the future.
      *
      * The corresponding syscall filter is implemented in
      * "tests/tcg/plugins/syscall.c".
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 3/3] docs/about/emulation: sharpen the dlcall boundary and its guest requirements
  2026-07-20 20:04 [PULL 0/3] Plugins fixes 2026-07-20 Pierrick Bouvier
  2026-07-20 20:04 ` [PULL 1/3] contrib/plugins/dlcall: correct the syscall number claim, note the data model Pierrick Bouvier
  2026-07-20 20:04 ` [PULL 2/3] tests/tcg: correct why the magic syscall number is safe here Pierrick Bouvier
@ 2026-07-20 20:04 ` Pierrick Bouvier
  2026-07-21 16:00 ` [PULL 0/3] Plugins fixes 2026-07-20 Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Pierrick Bouvier @ 2026-07-20 20:04 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, richard.henderson, pbonzini, stefanha
  Cc: pierrick.bouvier

From: Ziyang Zhang <functioner@sjtu.edu.cn>

Record the same data model requirement as the plugin: guest_base == 0 is
necessary but not sufficient.

Describe the magic syscall number the way the plugin now does. It has to be a
number the guest ABI does not use and does not reject before the plugin sees
it, rather than merely a high one, so show syscall_num= being used as well.

A library is not turned into thunks, it is left alone and the thunks are
produced for it, so say that instead. Argument marshalling, callbacks and
variadic functions are also what the plugin does not do, and listing them in
its description blurs the boundary it draws. Move them to Lorelei, where they
are pointed at as a reference.

Co-authored-by: Kailiang Xu <xukl2019@sjtu.edu.cn>
Co-authored-by: Mingyuan Xia <xiamy@ultrarisc.com>
Signed-off-by: Ziyang Zhang <functioner@sjtu.edu.cn>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Link: https://lore.kernel.org/qemu-devel/20260719074730.1520517-4-functioner@sjtu.edu.cn
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
 docs/about/emulation.rst | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst
index b861501e85e..c58149086cd 100644
--- a/docs/about/emulation.rst
+++ b/docs/about/emulation.rst
@@ -1072,14 +1072,13 @@ syscall, so the real kernel never sees it.
    Trusted guests only. The guest can load arbitrary host libraries and run
    arbitrary code in the QEMU host process. The plugin is not a sandbox and
    provides no isolation. It also requires ``guest_base == 0`` (qemu-user's
-   default), as guest pointers are dereferenced as host addresses with no
-   translation.
+   default) and a guest whose pointer width and endianness match the host's, as
+   guest pointers are dereferenced as host addresses with no translation.
 
 The plugin intentionally keeps the QEMU side lightweight and knows nothing
-about any particular library or its calling convention. Turning a real library
-into working thunks, including argument marshalling, callbacks and variadic
-functions, is done entirely in userspace, and any toolchain can implement the
-interface.
+about any particular library or its calling convention. Producing the thunks
+for a real library is done entirely in userspace, and any toolchain can
+implement the interface.
 
 Loading the plugin is all that is required from QEMU's side:
 
@@ -1087,11 +1086,21 @@ Loading the plugin is all that is required from QEMU's side:
 
    qemu-x86_64 -plugin contrib/plugins/libdlcall.so <guest-program> ...
 
+If the default number does not suit the guest ABI, pick another one, and build
+the userspace side to issue the same one:
+
+.. code-block:: shell
+
+   qemu-x86_64 -plugin contrib/plugins/libdlcall.so,syscall_num=8192 \
+       <guest-program> ...
+
 `Lorelei <https://github.com/rover2024/lorelei>`_ is one end-to-end userspace
 implementation of this: it provides the guest and host runtimes and an
 automated toolchain that generates the thunks from a library's headers, so guest
-library calls run on the host's native libraries. It supports an x86_64 guest
-running on an x86_64, aarch64 or riscv64 host.
+library calls run on the host's native libraries. How it handles the parts the
+plugin leaves out, including argument marshalling, callbacks and variadic
+functions, can serve as a reference. It supports an x86_64 guest running on an
+x86_64, aarch64 or riscv64 host.
 
 A minimal end-to-end example uses a one-function library, ``libhello.so``, built
 two ways: the guest build tags its output ``(from the guest)`` and the host
@@ -1201,8 +1210,10 @@ which prints::
   * - Option
     - Description
   * - syscall_num=N
-    - The magic syscall number the guest issues (default 4096). Must be high
-      enough not to clash with a real syscall.
+    - The magic syscall number the guest issues (default 4096). It must be a
+      number the guest ABI does not use for a real syscall, and does not
+      reject before the plugin sees it, which bounds the choice from both
+      sides.
 
 Other emulation features
 ------------------------
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PULL 0/3] Plugins fixes 2026-07-20
  2026-07-20 20:04 [PULL 0/3] Plugins fixes 2026-07-20 Pierrick Bouvier
                   ` (2 preceding siblings ...)
  2026-07-20 20:04 ` [PULL 3/3] docs/about/emulation: sharpen the dlcall boundary and its guest requirements Pierrick Bouvier
@ 2026-07-21 16:00 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2026-07-21 16:00 UTC (permalink / raw)
  To: Pierrick Bouvier
  Cc: qemu-devel, peter.maydell, richard.henderson, pbonzini, stefanha,
	pierrick.bouvier

[-- Attachment #1: Type: text/plain, Size: 116 bytes --]

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/11.1 for any user-visible changes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-21 16:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 20:04 [PULL 0/3] Plugins fixes 2026-07-20 Pierrick Bouvier
2026-07-20 20:04 ` [PULL 1/3] contrib/plugins/dlcall: correct the syscall number claim, note the data model Pierrick Bouvier
2026-07-20 20:04 ` [PULL 2/3] tests/tcg: correct why the magic syscall number is safe here Pierrick Bouvier
2026-07-20 20:04 ` [PULL 3/3] docs/about/emulation: sharpen the dlcall boundary and its guest requirements Pierrick Bouvier
2026-07-21 16:00 ` [PULL 0/3] Plugins fixes 2026-07-20 Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.