From patchwork Wed Jul 24 19:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 814174 Delivered-To: patch@linaro.org Received: by 2002:adf:e641:0:b0:367:895a:4699 with SMTP id b1csp94685wrn; Wed, 24 Jul 2024 12:48:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWT0Z7gILKcPqAsDMYJ/2TQJSsT4y1LXA/ExO03eSLbXnAQRF0SxvfhDoEOi9bsN+L5MuJJlvC3cNisOizFPesu X-Google-Smtp-Source: AGHT+IE6w66W6h89tGIpssdiXY8yaZ/cEwHhSD3ymRG8hfM9t0rgb+7ND5Jji6m+OM17UGIdW5J4 X-Received: by 2002:a05:6358:7524:b0:1ac:1492:8d5a with SMTP id e5c5f4694b2df-1acf8a24fd0mr111618455d.14.1721850485756; Wed, 24 Jul 2024 12:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721850485; cv=none; d=google.com; s=arc-20160816; b=1JDbWwLZbUBoV9Gr5d/lnO0XSP0Yju5Ckt+Tn9V1C8lF1NUNSFhV3b8Jtbp0PWj8/t +XjT1SrpprAXDXiNxjmuj01Kb8jOIn694ptyxq4macuL++y8NHPbxr20AuNl0bffJO8K 8YJwbH5VTmI7KFHKeKVSQ2+kscQkTn9ihOjSxMH5n6svRkmg6sFU5iNwGkifsf5QEWpN lzC4D72SGmDFItoM6eHkfok5qTCb1S/05Czaagy3HhI5eFkNo8PWO8Vb88rS21uvjkWG eJdmWXUCanyjCggO0NN500v+iE/el35k3qxBrJmTChw3DPh+eJDpnPelpH13aQbgZF/c +G/A== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pjRe9WOOgnZVoD/80IX7JyvW7Ap72zwjrzdwxvANZMw=; fh=xnCpbbVYJFFG+A0G6b4cSDVMgju0ymiCog0e/FTUtiE=; b=jTJlUsLgKSGqi4zvCrl7bAg3V5i8byTZcJ6EkgWlv/YVyD18F2mp4zuAqILdcjl9RR xFdYoNNKm4nkTCrjLKF2FezirQCxChGNdv/Tet8gOkl+SPao047/YF3d/I5h0oa28pIl 9tii4SZ8lHdz2gv8coRxJiCMIcS36rokXA6cDCzqPYy2pC5TXeOxeFNxYrAeIXdT3X+x 7Nasb0OirPY9ilo0Ogz2XTW0BDFXvU3EvsSoD87yhhT+6wy76pyIvJreOUFH+n+QTMiK vvWu5dxHoqtGf8Tng6VBug1P4+4/7+0aKvG5QN4C+sljwC1x2Li+eKXnuX5MJ+NvRC2K lVOA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ukeOWWTz; 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 6a1803df08f44-6b7ac7c3f96si135563496d6.133.2024.07.24.12.48.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2024 12:48:05 -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=ukeOWWTz; 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 1sWhxY-0002Q8-C0; Wed, 24 Jul 2024 15:47:36 -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 1sWhxR-0002MR-Nv for qemu-devel@nongnu.org; Wed, 24 Jul 2024 15:47:30 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWhxP-0006EC-C0 for qemu-devel@nongnu.org; Wed, 24 Jul 2024 15:47:29 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-70d138e06e3so150595b3a.2 for ; Wed, 24 Jul 2024 12:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721850439; x=1722455239; 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=pjRe9WOOgnZVoD/80IX7JyvW7Ap72zwjrzdwxvANZMw=; b=ukeOWWTzcfFJNFLZpydNYX0A92mv9f0pugHQf+NEw8PEXH4OlNtrkvuaEfUyk0Trhe u5DFpe86jTkBilpjBWS49WTJxYtOD/bzPUKmcIfeqkfdGu8RxhEIidUvqoiSWctNjwF8 UlqhzSxKG4nUocT1CqGY2hF5WpwzwNvRXPIFxDFtkqJZBnvzMooTE0iTtjlZiMHMWFm+ mZ32/ijThYL8DQWBs4TbI/CrW8wrqHpLF93/E+2baD9PulmFQuJ4QVui9XIORNzCaDS1 ZQOBNWFJVZvm+OeRNmQsBtixJO5UgQ95cDT23lgK5LfvixcJDmbFS3D0GDCplQzVHRy9 9aoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721850439; x=1722455239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pjRe9WOOgnZVoD/80IX7JyvW7Ap72zwjrzdwxvANZMw=; b=T0mQUOvPutUqQZdti4YJHkKaDykaQciGInFFZWdeuZWjRnxSTAoDcoiTBtUyznof2i GjrWfjTeh3aJQa6/G5xsj3uCvlA6JcJjh87S2QOiQ39A6LAujunQotOobSAiUqs3joiI jY7GOU4CBrSMrUu+j20sEMABUCRyCsYTx1Ecg2piV73JyyKvarInnP7y/uLuMOj4crF+ 9sz9G2BZM6L34hnd95Rrwd31z/kV8x/xE3kPBuAMnmmIsaBK/ODxJb/88xGUwA8VorAl bUEknAfq+yOEHo8I7H9Plix6BqaHRu0l+FqR9UPxIA+BiUkOPAqf6EH/HU3bR+HzwjL+ ypwg== X-Gm-Message-State: AOJu0Yy18oL0j2Q0ABkWojTpVmm3Q+VORkamzlEAFLOUwJhZK+/thkOu HIPXTUHvutmbhlPVsudZhq1AHG+iZV6Ox7FDbylJtA41qJXACRpgeo9+WxW2sBH47dZo3mMi2EA CaIg= X-Received: by 2002:a05:6a20:12c4:b0:1c3:ea21:dc31 with SMTP id adf61e73a8af0-1c4732d0562mr1086504637.42.1721850439626; Wed, 24 Jul 2024 12:47:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 12:47:19 -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 , Xingtao Yao Subject: [PATCH v7 2/6] plugins: extend API to get latest memory value accessed Date: Wed, 24 Jul 2024 12:47:04 -0700 Message-Id: <20240724194708.1843704-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240724194708.1843704-1-pierrick.bouvier@linaro.org> References: <20240724194708.1843704-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x434.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 value can be accessed only during a memory callback, using new qemu_plugin_mem_get_value function. Returned value can be extended when QEMU will support accesses wider than 128 bits. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1719 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2152 Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Reviewed-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- include/qemu/qemu-plugin.h | 32 ++++++++++++++++++++++++++++++++ plugins/api.c | 33 +++++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 1 + 3 files changed, 66 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index c71c705b699..649ce89815f 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -262,6 +262,29 @@ enum qemu_plugin_mem_rw { QEMU_PLUGIN_MEM_RW, }; +enum qemu_plugin_mem_value_type { + QEMU_PLUGIN_MEM_VALUE_U8, + QEMU_PLUGIN_MEM_VALUE_U16, + QEMU_PLUGIN_MEM_VALUE_U32, + QEMU_PLUGIN_MEM_VALUE_U64, + QEMU_PLUGIN_MEM_VALUE_U128, +}; + +/* typedef qemu_plugin_mem_value - value accessed during a load/store */ +typedef struct { + enum qemu_plugin_mem_value_type type; + union { + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + struct { + uint64_t low; + uint64_t high; + } u128; + } data; +} qemu_plugin_mem_value; + /** * enum qemu_plugin_cond - condition to enable callback * @@ -551,6 +574,15 @@ bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info); QEMU_PLUGIN_API bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info); +/** + * qemu_plugin_mem_get_mem_value() - return last value loaded/stored + * @info: opaque memory transaction handle + * + * Returns: memory value + */ +QEMU_PLUGIN_API +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info); + /** * qemu_plugin_get_hwaddr() - return handle for memory operation * @info: opaque memory info structure diff --git a/plugins/api.c b/plugins/api.c index 2ff13d09de6..3316d4a04d4 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -351,6 +351,39 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info) return get_plugin_meminfo_rw(info) & QEMU_PLUGIN_MEM_W; } +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info) +{ + uint64_t low = current_cpu->neg.plugin_mem_value_low; + qemu_plugin_mem_value value; + + switch (qemu_plugin_mem_size_shift(info)) { + case 0: + value.type = QEMU_PLUGIN_MEM_VALUE_U8; + value.data.u8 = (uint8_t)low; + break; + case 1: + value.type = QEMU_PLUGIN_MEM_VALUE_U16; + value.data.u16 = (uint16_t)low; + break; + case 2: + value.type = QEMU_PLUGIN_MEM_VALUE_U32; + value.data.u32 = (uint32_t)low; + break; + case 3: + value.type = QEMU_PLUGIN_MEM_VALUE_U64; + value.data.u64 = low; + break; + case 4: + value.type = QEMU_PLUGIN_MEM_VALUE_U128; + value.data.u128.low = low; + value.data.u128.high = current_cpu->neg.plugin_mem_value_high; + break; + default: + g_assert_not_reached(); + } + return value; +} + /* * Virtual Memory queries */ diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index ca773d8d9fe..eed9d8abd90 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -13,6 +13,7 @@ qemu_plugin_insn_size; qemu_plugin_insn_symbol; qemu_plugin_insn_vaddr; + qemu_plugin_mem_get_value; qemu_plugin_mem_is_big_endian; qemu_plugin_mem_is_sign_extended; qemu_plugin_mem_is_store;