From patchwork Fri Jul 5 00:34:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 810342 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1388048wru; Thu, 4 Jul 2024 17:35:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVZ95Z9GzC3CYHs33muasi+zrwOKwLZG1qsYFs17FoG6gQkeLeRwNcxii57Mf3lKMK1mdJFFddv2GJ9s0ZltcyG X-Google-Smtp-Source: AGHT+IH+K/oMXMAqpZdJdBdvAjfcT5aDz6JswcBdRr7dWXwwZ5pmF/QsIG/sMTTh2X1UfmcWYPwz X-Received: by 2002:a05:6102:21a7:b0:48c:42e9:1eeb with SMTP id ada2fe7eead31-48fee88d665mr3266363137.17.1720139704174; Thu, 04 Jul 2024 17:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720139704; cv=none; d=google.com; s=arc-20160816; b=pBl4Wqw6NBfb7dim4NJIZ/BTxrFKheFfKA8tZTy3Y+y9GDx68pFsznsVEVJ47+SlY8 A8kpC5JTAdP9WGwNzZhpb52q6hcf7w9LkFpBZ6cLuMw9ST5Qoz4s7tk7MjK/G2qlD8w0 kVqgAAlIB1DhY8LCYosJ9/s9rBgDfjzt/e1BW3/oul2cH6qeSDIyCncHVADjbfltnKAx I9idrHyi9VxxiST2cNQsXoiRy0TCCJuclf/rL+JoW2JJioOaGnDGCf8BJKWyJnp7HoEu og0SqSXx8bt0KURc/UOkfs7kvo/iwnmkj86AVsShnjXaY4A9Mey2i3/SUG6+eHCqLRWX l8Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=s03RC0K1xp3v9oXRtQJSIBQz5PP4M75DzZJLQM+JcYs=; fh=2IzZKSAfkxDgXTtM7kFa1jWu0SUssVJhWA7cdsHH2KE=; b=uwM56qDzZHTrG/lkRGkUY0pvjBYivL0/SemsUs/pDIPqP3MXzlzDi5mtf3FfM9FMC6 kORNtCVxcPmpfZOu75vBuTZ2YQXgHUSbD3BqgBU+3EMUsOO1E7ohxplbAADD6tsrqU+2 IWNTiK3dWnuM67vnVvC3/eZpiBU1oT9A6uIz/TUMwO+EHxvAhTkBBtR3oi+CgoORXlZe Uvq+yYCPIjDc7MJeWlOW9TTiOh3c5oOAuIvxx5PqsVyv8SWOqorBX1HpGGHJo9GwPyg+ 2VxDmulUE4IC+RFVLUX7tlcGDvpd0QjFMiqnVCepEj/ocsreE80iFBFUSXHW32UCQ57+ pn6Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="D/94udse"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-44651486423si158074841cf.385.2024.07.04.17.35.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jul 2024 17:35:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="D/94udse"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPWuS-0002qJ-Ol; Thu, 04 Jul 2024 20:34:44 -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 1sPWuR-0002q0-IB for qemu-devel@nongnu.org; Thu, 04 Jul 2024 20:34:43 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPWuP-00005E-JL for qemu-devel@nongnu.org; Thu, 04 Jul 2024 20:34:43 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1fa2ea1c443so7560105ad.0 for ; Thu, 04 Jul 2024 17:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720139679; x=1720744479; 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=s03RC0K1xp3v9oXRtQJSIBQz5PP4M75DzZJLQM+JcYs=; b=D/94udseBlsePXwc47cW7vFHbeBU9cBfRpkEQfIskq20lYv7SbPRVk6qBieOL4vrFE gaDNpmjV5O6NLgMlyosKCl7ZNTsePKXSOgvsND7tz6Qsqf/lyeCwF8FDGS5uIqOEtT+J okMLt0ugEAYagVOHkKrGPoidBbq7REZxUGT0ibH3BH33+hYA05y40caJcMChOltMaJPt wJrc8ie6cM5EzsEPAfv44eaFUIxzO3Zv7w6qmlrmaNDyNiB+/viSIsFXMIJRY8vIhhqG 7v4y7qPHZyv9JZUzUlaqhDBpOaT6f/R77IRan6jrWmEBWKjDurHVfQtVqGaRJgtadg2C sfkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720139679; x=1720744479; 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=s03RC0K1xp3v9oXRtQJSIBQz5PP4M75DzZJLQM+JcYs=; b=QzxgGUae4RIL3ulvfyXEratzqtuTKvWhH/VDUcyxBfhHj8EAz6GCQbmF1BhAJsFG59 HY0LFv7yWF5qwvSgVDSqiw+G/GReQ3ZSBJ64aDZEGT0a9Ge3M3t8SmFjvRzeh/LzsQDm 6JcxqaE8FHgW/hLP/PMXgKya1FGi8HNKDQX0B9f+/VUZXK5kQYJkR20W2wJP+ew3aUqP W8xWfToXf+WMrRGAxCuD5+62niK6GskZ1pTCAkdHI/3GYPTs2zeieQAYZoQT/fb85Q4p ZIuC69bvOfuepw8YI8WrNYnXPPvP+AoYJ1X82av++SPdlDWZL3bHE/JvEh4i3QbXhop2 0JEQ== X-Gm-Message-State: AOJu0Yy7r723ePuqypwsHyunS/tqCCmLDtvde1ZDl2exxp7oMjkTjlSL aCkWzZx2hpqVWKBvgLKYwFzvr+hrRN28ZgHrrKHmzyz2JvXUphvYGudLJPcRH0jHrK/1Rl6ojz6 d9rU= X-Received: by 2002:a17:903:192:b0:1fa:f9e1:5d33 with SMTP id d9443c01a7336-1fb33ed9f56mr26587825ad.50.1720139678766; Thu, 04 Jul 2024 17:34:38 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb1a075616sm39008595ad.15.2024.07.04.17.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 17:34:38 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Alexandre Iooss , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Yanan Wang , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH v5 0/7] plugins: access values during a memory read/write Date: Thu, 4 Jul 2024 17:34:14 -0700 Message-Id: <20240705003421.750895-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::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 following specific values in memory. 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 (7): plugins: fix mem callback array size 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/plugin/mem: add option to print memory accesses tests/tcg/x86_64: 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 ++++++++ accel/tcg/plugin-gen.c | 3 +- plugins/api.c | 33 ++++++++ plugins/core.c | 6 ++ tcg/tcg-op-ldst.c | 66 +++++++++++++-- tests/plugin/mem.c | 69 +++++++++++++++- tests/tcg/x86_64/test-plugin-mem-access.c | 89 +++++++++++++++++++++ accel/tcg/atomic_common.c.inc | 13 ++- accel/tcg/ldst_common.c.inc | 38 +++++---- plugins/qemu-plugins.symbols | 1 + tests/tcg/Makefile.target | 10 ++- tests/tcg/x86_64/Makefile.target | 7 ++ tests/tcg/x86_64/check-plugin-mem-access.sh | 48 +++++++++++ 16 files changed, 455 insertions(+), 34 deletions(-) create mode 100644 tests/tcg/x86_64/test-plugin-mem-access.c create mode 100755 tests/tcg/x86_64/check-plugin-mem-access.sh