From patchwork Tue Sep 10 17:20:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 1983402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Gg7kyDOQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X39V76QWZz1y1l for ; Wed, 11 Sep 2024 03:21:35 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1so4Xq-00033q-1O; Tue, 10 Sep 2024 13:20:50 -0400 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 1so4Xo-00032Z-P7 for qemu-ppc@nongnu.org; Tue, 10 Sep 2024 13:20:49 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xm-0002m1-Sf for qemu-ppc@nongnu.org; Tue, 10 Sep 2024 13:20:48 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2d89229ac81so4561639a91.0 for ; Tue, 10 Sep 2024 10:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988845; x=1726593645; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AfNU4E2Cw9UkkRJul++973/P7trBC9AonoQW9F/AiDA=; b=Gg7kyDOQPRw9PDo/tY4nxqphXktaMncH+dLVirxXndl+96LO2gNBIhCXnunyoJwm76 4r8nty4mOopFkK9hewcqcqufQ6/7xcIybpOKhZiE2H7dE5NM4EgutXL56uMpQEpseorz RQ9S4QR+NUCaTpwQT/jOlWxjsSpUSaGW6M4UZ4Of8QIFGDk9hnPjCf10HD1IZiwnmVXd QhZYhxZ8FnzsV03lAZ5943Iw3j6yw6MRwexKy4nmQ98d9jd/jKlrmKOBNBVLh79Sea2s Xd5AWOykkl9bkmNtrjKS8OacwEjKWbWHFRoPy79AgLTTyfNqCOSKTitP0JKdDsgrfaJO bh8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988845; x=1726593645; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AfNU4E2Cw9UkkRJul++973/P7trBC9AonoQW9F/AiDA=; b=M+a0y8Yu1977IzwCwWHANN05XcN8/FhIVyUqdvgam/rhtJcyBYSfMz9fgkmt54xois CZfeTND0jH9JdFyAxIcjaJaWQVWkvDj9jmGIjxjtSptuPy5jX+m4Ss/Byf7Jo0C331Jb 2bEGYgRo0hSOUWFGbbFYJo6+g73blzYHCr0Yd4wWuKtceUiw1Sdi6gHbDSKYXXJDA26N 7dy9b8bcg1RasOV014ByyWIv8HWJUZ2dRASQU3e2eeOi1A/8mk2PkpBxIVNlufsA+n75 lvQihpITAvsi/GmxxqOZIrZIbJIsSLFcUSKwuhgL6evCGdBIZSTxgpLovT7sqMzEOo3Q 7DKQ== X-Forwarded-Encrypted: i=1; AJvYcCW7ikQn6PMaQTMmjtgchq4+mzWO0R+RoNdgEmCMhWb2+TyGzhFVq00bngZT00Vl8zzX0j116Z1zKQ==@nongnu.org X-Gm-Message-State: AOJu0Yx6RLup/vv862XGI9nGOGN2CxUn26DGU/FSNiN0MZkXdxUNTUAo YjObrLdfJtsbJ+hYXe7v66+XwFkbrs3XW7s56Fk9RMHRoUI/cSkHZVgj+O7SVDg= X-Google-Smtp-Source: AGHT+IHkX8yC7ScDO1qto3R4A4ULn9W3KYjJqtj11VaG2ul2srX9B2Lgbj3sqNAkQ+dohmZFZaUyng== X-Received: by 2002:a17:90a:ef0b:b0:2d8:b91d:d284 with SMTP id 98e67ed59e1d1-2dad50106a0mr17990709a91.16.1725988845256; Tue, 10 Sep 2024 10:20:45 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:44 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu Subject: [PATCH v8 0/6] plugins: access values during a memory read/write Date: Tue, 10 Sep 2024 10:20:27 -0700 Message-Id: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x1035.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-ppc@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org This series allows plugins to know which value is read/written during a memory access. For every memory access, we know copy this value before calling mem callbacks, and those can query it using new API function: - qemu_plugin_mem_get_value Mem plugin was extended to print accesses, and a new test was added to check functionality work as expected. A bug was found where callbacks were not called as expected. This will open new use cases for plugins, such as tracking specific values in memory. Needs review: Patch 6: tests/tcg/multiarch: add test for plugin memory access v8: - fix test for all target architecture v7 - renamed variable for adding plugins tests in Makefile - do not run any command when plugin output should not be checked (thanks Alex) - add LICENSE + summary for tests/tcg/multiarch/test-plugin-mem-access.c - test for mem access is now multiarch (tested on aarch64, x86_64, i386) v6 - fix big endian offset for plugin_gen_mem_callbacks_i32 v5 - fixed width output for mem values in mem plugin - move plugin_mem_value to CPUNegativeOffset - tcg/tcg-op-ldst.c: only store word size mem access (do not set upper bits) v4 - fix prototype for stubs qemu_plugin_vcpu_mem_cb (inverted low/high parameters names) - link gitlab bugs resolved (thanks @Anton Kochkov for reporting) https://gitlab.com/qemu-project/qemu/-/issues/1719 https://gitlab.com/qemu-project/qemu/-/issues/2152 v3 - simplify API: return an algebraic data type for value accessed this can be easily extended when QEMU will support wider accesses - fix Makefile test (use quiet-command instead of manually run the command) - rename upper/lower to high/low - reorder functions parameters and code to low/high instead of high/low, to follow current convention in QEMU codebase v2 - fix compilation on aarch64 (missing undef in accel/tcg/atomic_template.h) v3 - add info when printing memory accesses (insn_vaddr,mem_vaddr,mem_hwaddr) Pierrick Bouvier (6): plugins: save value during memory accesses plugins: extend API to get latest memory value accessed tests/tcg: add mechanism to run specific tests with plugins tests/tcg: allow to check output of plugins tests/tcg/plugins/mem: add option to print memory accesses tests/tcg/multiarch: add test for plugin memory access accel/tcg/atomic_template.h | 66 ++++++- include/hw/core/cpu.h | 4 + include/qemu/plugin.h | 4 + include/qemu/qemu-plugin.h | 32 ++++ plugins/api.c | 33 ++++ plugins/core.c | 6 + tcg/tcg-op-ldst.c | 66 ++++++- tests/tcg/multiarch/test-plugin-mem-access.c | 177 +++++++++++++++++++ tests/tcg/plugins/mem.c | 69 +++++++- accel/tcg/atomic_common.c.inc | 13 +- accel/tcg/ldst_common.c.inc | 38 ++-- plugins/qemu-plugins.symbols | 1 + tests/tcg/Makefile.target | 12 +- tests/tcg/alpha/Makefile.target | 3 + tests/tcg/multiarch/Makefile.target | 11 ++ tests/tcg/multiarch/check-plugin-output.sh | 36 ++++ tests/tcg/ppc64/Makefile.target | 5 + 17 files changed, 544 insertions(+), 32 deletions(-) create mode 100644 tests/tcg/multiarch/test-plugin-mem-access.c create mode 100755 tests/tcg/multiarch/check-plugin-output.sh