From nobody Tue Feb 10 09:01:47 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1769708338; cv=none; d=zohomail.com; s=zohoarc; b=kV+8BPlYLpxTpVO8su6NT1gjNxQiBkkGKx3cXkHB8LRbl8uoW1MzZw7tTk/m7CPstIp+3nwX4N5qRivRdIw6N7ZFVd1vs4505pTYtVvI85hUDcTsDo7PsbX1ZPrN58+4TJ7vgPjN0g0NJep0v+XZP0E640pRJzGQu1mEVmQapCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769708338; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jsztMEzgZHZfrQRWYcQj4QjAMuO/MHTF7LJ1DZnGjY4=; b=gejX0r1YKEZQmFKqiVTPjKDiBqwvpfS3/O0Os9GBXFWkm/+JUuDa7lCBalRQMRYXVL/HOyOGShRuZZJzmni5f5q/EWdQ6rtBlF1OFHG2XAv+aLIOn6WHkMLwerzrC7qDdZUzAXNjx2JiqfQ7hZ3MRQ6CR39RrgM4s+hGc8BrJHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769708338105372.10667688417857; Thu, 29 Jan 2026 09:38:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vlVyR-0004nF-Nh; Thu, 29 Jan 2026 12:38:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vlVyN-0004XI-RG for qemu-devel@nongnu.org; Thu, 29 Jan 2026 12:38:27 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vlVyL-0000eg-G3 for qemu-devel@nongnu.org; Thu, 29 Jan 2026 12:38:27 -0500 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-8230c2d3128so723709b3a.0 for ; Thu, 29 Jan 2026 09:38:25 -0800 (PST) Received: from pc.taild8403c.ts.net (216-71-219-44.dyn.novuscom.net. [216.71.219.44]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82379b222f1sm6706246b3a.7.2026.01.29.09.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 09:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1769708304; x=1770313104; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jsztMEzgZHZfrQRWYcQj4QjAMuO/MHTF7LJ1DZnGjY4=; b=lOtQiemX53Kg1b/00ZpCtTdBPBp1rcvT2fw0WweXqK45Bi1BxmkLMvJk2ZVQo3r0VT ByuhY+PMwjGX1YlXracPemnxYa0OszmJPqJaLklyrripJ4qmRzQGCHwQnHc/BJzGFVcq Joi6WazX5+nf128N5q9k2G1FvwV9lYZMfZo0emEaqUghd31IRmgNTxtMWxZPWnj24Qqn ajk+S2RK0bJdUKteaVvNb2yQYFX5LGBvaG8cVkjvKqtkPYoVMM0JFWf2FDfqQXYJ8uDr G8IPtN9rIIDsiJpZedAffg5g2Yn35VpaA77hhCTkjQav7qi9cU2Jxmp1ndF9x1rUe0cJ DuMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769708304; x=1770313104; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=jsztMEzgZHZfrQRWYcQj4QjAMuO/MHTF7LJ1DZnGjY4=; b=NjtrAxCj22jehvkJFLZQ5azNt/v0iMP+50Buzx+efSIj7jsKG8PJIBZWjoZNUgCkHX aa02s/eHmtcntNT1OGeBB0CxQxTGTAYhfINJ/X2T58eG57rcmQ8S7OB0ymbgNLB6izdn sFbZh2KReJrIAAI0YFSr8CV/lhwVkioqt3q6Jj9p4/j8IPYMA/RosmZUmsdGZ8XTOFJ/ Z1ixfE1VG7mb7SM+u4+aUhZ5/P6WHNOhPRCSEilt9+bnHYHuG+ORzB4Z/Q51DmLZBYkt 7zy5Z+TyukiuBKDrzsizhNvgmVP9fDSswbAcZoV60G+tt/f2SopSR0u4bPKUKw2eQ4Ze z8og== X-Gm-Message-State: AOJu0YzpvwKgIJ5PWm6oGIgpOnK91FyU3onsA4hOViwQTqJW3V7Cgfs3 O1jDq8ru0Njb63zbb4E1tRItdiic6Azclvdqguz6lYA8y4gKjXi0ElyH47fWIaNtXX1Torr/nOB VApi0 X-Gm-Gg: AZuq6aINpq6NiwxrCcBrvQ7vAgNgAgo+PIoQSWQUVcOu8+EQrqxSlQIe3DUp2ScGSM9 mKlgsx8Nen2TIo8rN+lIS7A2SBR9D5KVgKEhIHrieroRt9m7geOWMCX7zLy+9TPok3+LyXkoyhA aOQnGGEeZsvISfDzylEyATfQfkuWpBaiQuNjIvSA+l8VtJiSXMoG9YPa7J69aiSU48R7jTvA3rw yWptriHG96wUuDvfSPvWgfXePmY4cYY5nhoZiQTaYTDsH67aof8GrLHLymY+FKAFRVdd+4cG510 ezNTLezajWW3jgsFXxceyd/A4HUtVPeL25uje2bKzF1X/Ow6grcU7Iphbl2SP0Hyefamz+zykfY A73rW4btinV/wdOCprhckXhSczskkjuD+Rggu97sMtpsKZ37lv+okjQ17uyjk/6NfGrYhmUbNVq dO39bSyZmeRiecDl3KleC+452rhtA6zSCKKNPJP2jaDE4oTF8YR/qSspgSWmdOu+3P X-Received: by 2002:a05:6a20:a106:b0:38e:9b5d:dc2c with SMTP id adf61e73a8af0-38ec62dddf8mr9506633637.17.1769708303918; Thu, 29 Jan 2026 09:38:23 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Ziyang Zhang , Mingyuan Xia , Pierrick Bouvier Subject: [PULL 08/21] tcg tests: add a test to verify the syscall filter plugin API Date: Thu, 29 Jan 2026 09:37:54 -0800 Message-ID: <20260129173811.138036-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260129173811.138036-1-pierrick.bouvier@linaro.org> References: <20260129173811.138036-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1769708340573158500 Content-Type: text/plain; charset="utf-8" From: Ziyang Zhang 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 Co-authored-by: Mingyuan Xia Reviewed-by: Pierrick Bouvier [Pierrick - Changed syscall number to 4096 to make it work with mips32] [Pierrick - Skip test when compiling without plugins enabled] Link: https://lore.kernel.org/qemu-devel/20251214144620.179282-3-functioner= @sjtu.edu.cn Signed-off-by: Pierrick Bouvier --- .../multiarch/test-plugin-syscall-filter.c | 39 +++++++++++++++++++ tests/tcg/plugins/syscall.c | 19 +++++++++ tests/tcg/multiarch/Makefile.target | 7 +++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/multiarch/test-plugin-syscall-filter.c diff --git a/tests/tcg/multiarch/test-plugin-syscall-filter.c b/tests/tcg/m= ultiarch/test-plugin-syscall-filter.c new file mode 100644 index 00000000000..951e338a7c9 --- /dev/null +++ b/tests/tcg/multiarch/test-plugin-syscall-filter.c @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This test attempts to execute a magic syscall. The syscall test plugin + * should intercept this and return an expected value. + */ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ +#ifdef SKIP + return EXIT_SUCCESS; +#endif + /* + * We cannot use a very large magic syscall number, because on some IS= As, + * QEMU will treat it as an illegal instruction and trigger a critical + * exception. For instance, on arm32, the syscall number cannot exceed + * ARM_NR_BASE (0xf0000), as can be seen in + * "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 th= is + * number. This is just a test case; replace this number as needed in = the + * future. + * + * The corresponding syscall filter is implemented in + * "tests/tcg/plugins/syscall.c". + */ + long ret =3D syscall(4096, 0x66CCFF); + if (ret !=3D 0xFFCC66) { + fprintf(stderr, "Error: unexpected syscall return value %ld\n", re= t); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/tests/tcg/plugins/syscall.c b/tests/tcg/plugins/syscall.c index 42801f5c863..5658f830879 100644 --- a/tests/tcg/plugins/syscall.c +++ b/tests/tcg/plugins/syscall.c @@ -170,6 +170,24 @@ static void vcpu_syscall_ret(qemu_plugin_id_t id, unsi= gned int vcpu_idx, } } =20 +static bool vcpu_syscall_filter(qemu_plugin_id_t id, unsigned int vcpu_ind= ex, + 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 *sysret) +{ + /* Special syscall to test the filter functionality. */ + if (num =3D=3D 4096 && a1 =3D=3D 0x66CCFF) { + *sysret =3D 0xFFCC66; + + if (!statistics) { + qemu_plugin_outs("magic syscall filtered, set magic return\n"); + } + return true; + } + return false; +} + static void print_entry(gpointer val, gpointer user_data) { SyscallStats *entry =3D (SyscallStats *) val; @@ -255,6 +273,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 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; } diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index f5b4d2b8138..07d0b27bdd3 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -202,8 +202,13 @@ run-plugin-test-plugin-mem-access-with-libmem.so: \ CHECK_PLUGIN_OUTPUT_COMMAND=3D \ $(SRC_PATH)/tests/tcg/multiarch/check-plugin-output.sh \ $(QEMU) $< +run-plugin-test-plugin-syscall-filter-with-libsyscall.so: =20 -EXTRA_RUNS_WITH_PLUGIN +=3D run-plugin-test-plugin-mem-access-with-libmem.= so +EXTRA_RUNS_WITH_PLUGIN +=3D run-plugin-test-plugin-mem-access-with-libmem.= so \ + run-plugin-test-plugin-syscall-filter-with-libsyscall.so +else +# test-plugin-syscall-filter needs syscall plugin to succeed +test-plugin-syscall-filter: CFLAGS+=3D-DSKIP endif =20 # Update TESTS --=20 2.47.3