From patchwork Wed Jul 24 19:47:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 814176 Delivered-To: patch@linaro.org Received: by 2002:adf:e641:0:b0:367:895a:4699 with SMTP id b1csp94710wrn; Wed, 24 Jul 2024 12:48:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXAaXFCTTp/y0ms6cSuT3PFd/jEtWDn0dA2m3I6vTekKqxcOn361cRz7AqWk63yKXms9xSQK+6LE5wMm/+W7vc8 X-Google-Smtp-Source: AGHT+IG9FjX9p02JunijoQRrRkJ00zR8L+tiFLN/vCqcATtSq8K7dy2a2kxnhcH/LI2cGe4V1xqT X-Received: by 2002:a0c:fa52:0:b0:6b5:2aa3:3a7f with SMTP id 6a1803df08f44-6b99154d6c9mr47448306d6.20.1721850489530; Wed, 24 Jul 2024 12:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721850489; cv=none; d=google.com; s=arc-20160816; b=TACvIeVGJrZVlQRscLjtNieFIhMUTQ3OTuN4KjZH6TdGWYv/eIRjTukKOwbc5zeNCy w6Up1D89YOqXAYx4r//IK7zFdHPjk50ah6jJ8Pv4b1g3rPg7wQ4UBKSN7+OVENCDDJ8z 6ufZewJWV9W4ImwvTU56AQSfhjPoykORh//05jaI4Flo3Wqm74MYo11OTotIHYEjE5QE Io6dtnTFzVRlIMORXjxUcHrNKU2BR7kKgkBPSpesIRwUpd44akw1ghO5oMkxSfMwKgfo DjyldA+Lh5vC6ZEnJSo2SncBay75MxH8Sfwt8R/ITkvYRgdg8jcSXFCTtSJ7Di53zDAu UxMw== 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=2T6v7O+qpLKDTCsjZT5QHx2PqI6oPBcDkqwMfHyRUkE=; fh=09dcrC9Ioow2a8D7GWVCgSFZoGX1h+FdtzvbbKw6T4c=; b=vQ2Na3KDPgMujRyfSV0FONfR2pOPyVWxJQVgA+/pQ1GpD7r6u6FKcOf4saZWq6UEOQ Wsc5Vj+ZwQfcn9koTzLugKP0nc31WrdTdYnG4GrHdt52MyEhAmTI/VTcKS6N5q/LscYH /2hpFqdrpCdJXChRov+w/kHISVVDSn23rkfOZJtIxQrP9QwjOASirYjR4FMnnzdQ15Mn E8WNvQOsmWneoDP/kjovZiG2PAe8GW6stF4ANIYOJrEeLlEqOVJv30HbS+YvX3jGBCIQ Mj1Ttug1bfUu5yzNDcy0KxZSxBA1RTxPwqMC/Je36/pggJczN/vQfRrNsJwLLt63YJ73 Hf0Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P2tV2EWM; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a1990a8346si1379235585a.674.2024.07.24.12.48.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2024 12:48:09 -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=P2tV2EWM; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWhxm-0002a9-J6; Wed, 24 Jul 2024 15:47: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 1sWhxT-0002Mo-A1 for qemu-devel@nongnu.org; Wed, 24 Jul 2024 15:47:32 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWhxP-0006E2-Bs for qemu-devel@nongnu.org; Wed, 24 Jul 2024 15:47:29 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-70d1d6369acso919739b3a.0 for ; Wed, 24 Jul 2024 12:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721850437; x=1722455237; 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=2T6v7O+qpLKDTCsjZT5QHx2PqI6oPBcDkqwMfHyRUkE=; b=P2tV2EWMBkEoI3GgTrgZd6QaGxwwC0OFKbWzdo4trnT86vT6NuRGmcrlL/NcqwIzKL 9izXnwkGxzMwD2Cr9NITxEDWMRq6quRgo5iKUv4yFYaZy9Hjas6PUbZBgSMo5C8q4Zh4 qfAiRFgpLBP0d8VwgVJ+DJoBFT14M9yAySTIgPbnLogzK7mE8fSLsnCdeVNrtNfGR3x/ v/nRaCKl3qhl1vz1XgBEpc9AQujToUP0UBXCaUUF6A25EQH1CCUV2Cp2GgIkQMM/bb7c F/8ETWowcV3KpiRlM0+Qq3s/JtJJaEuUVpzgev15rXs+TJj9a15MVyLlT8KMjg1bIxyi 3Pjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721850437; x=1722455237; 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=2T6v7O+qpLKDTCsjZT5QHx2PqI6oPBcDkqwMfHyRUkE=; b=K7asuq1jtQvFccPxoZKJLAVP3nIfo+o4zGVQeWd4rRLA3TNqPnBlcqUEsYLCHEbKS1 4/mxJ/I17bTD9ZV3QkhONpq3cOfrfRMFW0HoDXqWIZcb5AgHakJIacEOU7jJStnedxV1 +TYYnb9v41HUYXeWzlzPvVhXU9iW4Knp2Nwax6Oj6I1FfFSp9TqObdohadS5XYKTCpS9 07UtYkeaad5fLz9A14ibuWsZvY20B5ayRET1r+d8UdYE1PdnbnTbdpbWfZGJGesXBF4k soK2/VXbIFoAJ4Us3gBtq7hW+OHbTrYi64itwEmSSw4K6nM7YbZnEZeLyNyUsl2lV3jh YL3g== X-Gm-Message-State: AOJu0Yxozkfub44GSsvRucCIljPt+1/dFrX1PihUavg9vmcnwrt3W8jM s3cx1RRHOO2FpLBAJ2P0ennlS37lmfwfh+Wz5RgoG2YcVCAvso8WxCBIl6Ob0YbwPmQknGRuKRI Fbrg= X-Received: by 2002:a05:6a20:2451:b0:1c3:acd1:5caf with SMTP id adf61e73a8af0-1c47403db98mr900138637.23.1721850437179; Wed, 24 Jul 2024 12:47:17 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::b861]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70d19c52a62sm6339116b3a.124.2024.07.24.12.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 12:47:16 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Alexandre Iooss , Zhao Liu , Mahmoud Mandour , Yanan Wang , Pierrick Bouvier , Eduardo Habkost , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum Subject: [PATCH v7 0/6] plugins: access values during a memory read/write Date: Wed, 24 Jul 2024 12:47:02 -0700 Message-Id: <20240724194708.1843704-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::42f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x42f.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 tracking specific values in memory. Needs review: Patch 7: tests/tcg/multiarch: add test for plugin memory access 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/plugin/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/plugin/mem.c | 69 ++++++- tests/tcg/multiarch/test-plugin-mem-access.c | 175 ++++++++++++++++++ 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/multiarch/Makefile.target | 7 + .../tcg/multiarch/check-plugin-mem-access.sh | 30 +++ 15 files changed, 524 insertions(+), 32 deletions(-) create mode 100644 tests/tcg/multiarch/test-plugin-mem-access.c create mode 100755 tests/tcg/multiarch/check-plugin-mem-access.sh