All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Ziyang Zhang <functioner@sjtu.edu.cn>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	 Riku Voipio <riku.voipio@iki.fi>,
	Laurent Vivier <laurent@vivier.eu>,
	 Alexandre Iooss <erdnaxe@crans.org>,
	Mahmoud Mandour <ma.mandourr@gmail.com>,
	 Pierrick Bouvier <pierrick.bouvier@linaro.org>,
	 Richard Henderson <richard.henderson@linaro.org>,
	 Zhengwei Qi <qizhwei@sjtu.edu.cn>,
	 Yun Wang <yunwang94@sjtu.edu.cn>,
	 Mingyuan Xia <xiamy@ultrarisc.com>,
	Kailiang Xu <xukl2019@sjtu.edu.cn>
Subject: Re: [PATCH v2 2/2] tcg tests: add a test to verify the syscall filter plugin API
Date: Fri, 12 Dec 2025 16:00:55 +0000	[thread overview]
Message-ID: <87ldj7sn9k.fsf@draig.linaro.org> (raw)
In-Reply-To: <20251212141541.1792111-3-functioner@sjtu.edu.cn> (Ziyang Zhang's message of "Fri, 12 Dec 2025 22:15:41 +0800")

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

> Register a syscall filter callback in tests/tcg/plugins/sycall.c,
> returns a specific value for a magic system call number, and check
> it in tests/tcg/multiarch/test-plugin-syscall-filter.c.
>
> Signed-off-by: Ziyang Zhang <functioner@sjtu.edu.cn>
> Co-authored-by: Mingyuan Xia <xiamy@ultrarisc.com>
> ---
>  tests/tcg/multiarch/Makefile.target           |  4 +++-
>  .../multiarch/test-plugin-syscall-filter.c    | 20 +++++++++++++++++++
>  tests/tcg/plugins/syscall.c                   | 15 ++++++++++++++
>  3 files changed, 38 insertions(+), 1 deletion(-)
>  create mode 100644 tests/tcg/multiarch/test-plugin-syscall-filter.c
>
> diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target
> index f5b4d2b813..4005e3a8a9 100644
> --- a/tests/tcg/multiarch/Makefile.target
> +++ b/tests/tcg/multiarch/Makefile.target
> @@ -202,8 +202,10 @@ run-plugin-test-plugin-mem-access-with-libmem.so: \
>  	CHECK_PLUGIN_OUTPUT_COMMAND= \
>  	$(SRC_PATH)/tests/tcg/multiarch/check-plugin-output.sh \
>  	$(QEMU) $<
> +run-plugin-test-plugin-syscall-filter-with-libsyscall.so:
>  
> -EXTRA_RUNS_WITH_PLUGIN += run-plugin-test-plugin-mem-access-with-libmem.so
> +EXTRA_RUNS_WITH_PLUGIN += run-plugin-test-plugin-mem-access-with-libmem.so \
> +			   			  run-plugin-test-plugin-syscall-filter-with-libsyscall.so
>  endif
>  
>  # Update TESTS
> diff --git a/tests/tcg/multiarch/test-plugin-syscall-filter.c b/tests/tcg/multiarch/test-plugin-syscall-filter.c
> new file mode 100644
> index 0000000000..cc694e0a71
> --- /dev/null
> +++ b/tests/tcg/multiarch/test-plugin-syscall-filter.c
> @@ -0,0 +1,20 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * This test attempts to execute a magic syscall. The syscall test plugin
> + * should intercept this and returns an expected value.
> + */
> +
> +#include <stdint.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +int main(int argc, char *argv[]) {
> +    long ret = syscall(0x66CCFF);
> +    if (ret != 0xFFCC66) {
> +        perror("ERROR: syscall returned unexpected value!!!");
> +        return EXIT_FAILURE;
> +    }
> +    return EXIT_SUCCESS;
> +}

  This breaks some arches:

  (gdb) r
  Starting program: /home/alex/lsrc/qemu.git/builds/sanitisers/qemu-arm -plugin tests/tcg/plugins/libsyscall.so -d plugin ./tests/tcg/arm-linux-user/test-plugin-syscall-filter
  [New Thread 0x7ffff37ff6c0 (LWP 63692)]                                                                                                                                       
  qemu: uncaught target signal 4 (Illegal instruction) - core dumped
  syscall no.  calls  errors
  45           5      0
  338          1      1
  256          1      0
  191          1      0
  398          1      1
  125          1      0
  384          1      0
  332          1      0

  Thread 1 "qemu-arm" received signal SIGILL, Illegal instruction.
  Download failed: Invalid argument.  Continuing without source file ./nptl/../sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S.
  __syscall_cancel_arch () at ../sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S:56
  warning: 56     ../sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S: No such file or directory
  (gdb) bt
  #0  __syscall_cancel_arch () at ../sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S:56
  #1  0x00007ffff6a51668 in __internal_syscall_cancel (a1=<optimized out>, a2=a2@entry=8, a3=a3@entry=0, a4=a4@entry=0, a5=a5@entry=0, a6=a6@entry=0, nr=130)
      at ./nptl/cancellation.c:49
  #2  0x00007ffff6a516ad in __syscall_cancel (a1=<optimized out>, a2=a2@entry=8, a3=a3@entry=0, a4=a4@entry=0, a5=a5@entry=0, a6=a6@entry=0, nr=130)
      at ./nptl/cancellation.c:75
  #3  0x00007ffff6a0207d in __GI___sigsuspend (set=<optimized out>) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
  #4  0x0000555555a49b80 in die_with_signal (host_sig=4) at ../../linux-user/signal.c:807
  #5  0x0000555555a49ed0 in dump_core_and_abort (env=0x532000004300, target_sig=4) at ../../linux-user/signal.c:847
  #6  0x0000555555a4c969 in handle_pending_signal (cpu_env=0x532000004300, sig=4, k=0x5250000029d0) at ../../linux-user/signal.c:1306
  #7  0x0000555555a4d0e5 in process_pending_signals (cpu_env=0x532000004300) at ../../linux-user/signal.c:1386
  #8  0x0000555555873930 in cpu_loop (env=0x532000004300) at ../../linux-user/arm/cpu_loop.c:479
  #9  0x0000555555a3eca7 in main (argc=6, argv=0x7fffffffe588, envp=0x7fffffffe5c0) at ../../linux-user/main.c:1035
  (gdb) 

> \ No newline at end of file
> diff --git a/tests/tcg/plugins/syscall.c b/tests/tcg/plugins/syscall.c
> index 42801f5c86..1323e18bc0 100644
> --- a/tests/tcg/plugins/syscall.c
> +++ b/tests/tcg/plugins/syscall.c
> @@ -170,6 +170,20 @@ static void vcpu_syscall_ret(qemu_plugin_id_t id, unsigned int vcpu_idx,
>      }
>  }
>  
> +static bool vcpu_syscall_filter(qemu_plugin_id_t id, unsigned int vcpu_index,
> +                                int64_t num, uint64_t a1, uint64_t a2,
> +                                uint64_t a3, uint64_t a4, uint64_t a5,
> +                                uint64_t a6, uint64_t a7, uint64_t a8,
> +                                uint64_t *ret)
> +{
> +    if (num == 0x66CCFF) {
> +        *ret = 0xFFCC66;
> +        qemu_plugin_outs("syscall 0x66CCFF filtered, ret=0xFFCC66\n");
> +        return true;
> +    }
> +    return false;
> +}
> +
>  static void print_entry(gpointer val, gpointer user_data)
>  {
>      SyscallStats *entry = (SyscallStats *) val;
> @@ -255,6 +269,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
>  
>      qemu_plugin_register_vcpu_syscall_cb(id, vcpu_syscall);
>      qemu_plugin_register_vcpu_syscall_ret_cb(id, vcpu_syscall_ret);
> +    qemu_plugin_register_vcpu_syscall_filter_cb(id, vcpu_syscall_filter);
>      qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
>      return 0;
>  }

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2025-12-12 16:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-12 14:15 [PATCH v2 0/2] linux-user: add a syscall-filter plugin API Ziyang Zhang
2025-12-12 14:15 ` [PATCH v2 1/2] linux-user: add a plugin API to filter syscalls Ziyang Zhang
2025-12-12 14:15 ` [PATCH v2 2/2] tcg tests: add a test to verify the syscall filter plugin API Ziyang Zhang
2025-12-12 16:00   ` Alex Bennée [this message]
2025-12-12 17:32     ` Pierrick Bouvier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ldj7sn9k.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=erdnaxe@crans.org \
    --cc=functioner@sjtu.edu.cn \
    --cc=laurent@vivier.eu \
    --cc=ma.mandourr@gmail.com \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qizhwei@sjtu.edu.cn \
    --cc=richard.henderson@linaro.org \
    --cc=riku.voipio@iki.fi \
    --cc=xiamy@ultrarisc.com \
    --cc=xukl2019@sjtu.edu.cn \
    --cc=yunwang94@sjtu.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.