From patchwork Tue Jul 2 01:10:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 13718831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B272DC2BD09 for ; Tue, 2 Jul 2024 01:12:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOS2e-0005Su-Kb; Mon, 01 Jul 2024 21:10: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 1sOS2X-0005RJ-7J for qemu-devel@nongnu.org; Mon, 01 Jul 2024 21:10:39 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOS2N-0002AO-EI for qemu-devel@nongnu.org; Mon, 01 Jul 2024 21:10:28 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-70aaab1cb72so2190269b3a.0 for ; Mon, 01 Jul 2024 18:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719882625; x=1720487425; 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=NgZfKU7tYXfEOC/70NsW0CAjeY4aEJw+E56SlRpuWWc=; b=S2FIzis6TuagyS4oE6UkA9eIay+PHVQ9n8mLc88hF42+HOl7aNsHNPAkOtT/RvrDY7 gcomdXUznUHd71uHCTgL0v+zoPF1JjG5t2lLDWLm5Y9yZIr113aRwPcyIla8+QXuUSts ws8R5YSsmb6qWKU+GekiKe6qHJH1xH01WTQh7D9WpbkPMr9cbFqu5zvcBaYj1i0P4Igi TaQ7XzV1hMxfxMm+WXYs6q0up/s0h9J/PqnrCRZ2/bkMPcx7q9+vDOIqerE4unU/vz2F dBTSz852nkuyL70ICoDFgEO9f4oaPfarBIi7oPc5c9Y9R99ZFXBv2Q05yoy7dxCk0wSG C7qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719882625; x=1720487425; 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=NgZfKU7tYXfEOC/70NsW0CAjeY4aEJw+E56SlRpuWWc=; b=ID3+0kcl9SEFPKRax/A/3nE2+eaXcWMPOoTvC+fpANAiVwvsfm6YBJABwwrC/3vulg n/iVuzGrQ/seUyN03roY4mfd+ptT1CI3ziCyan1WEKNDeeiIIDWjCXaeth/LzMrtekky 8hzIlquXpJZkxPqugIZZQEOrsk0QyMakeIaCOJf4jbQ7acDvHJDDTfu1Vs3yJC/zbIuW yO/2XOsrybQGKMI52YnsYEBcKGgxHxyuZcH0ytpyzdKjmaVIIxj3WspyiOT27tQquudb wBaBNaIOxxjk/uhp4nsRR5y+MqBxXK5avI/iX/NZMgsBw2lnPJ4ICg1lrPXyNBJxM7AB tA9Q== X-Gm-Message-State: AOJu0Yx5SfEjH1VynyVLnJ7fQ52zfkBbedm5axnXIKragZfpXnKT0nVy E+P8t5+pPaXUuymBWBQDFJ/35xtle2ca/5ZbWULJ59JhkleLZ8LuQl6eew2FGH272+W4rsb8ssf Y X-Google-Smtp-Source: AGHT+IHIGWMmswNTkPiExtT5lbUbTDszJQCqRa2HIjHklu8ZUBcOXgKIASxzHsXdoKYM5IFIbadMBQ== X-Received: by 2002:a05:6a21:99a5:b0:1be:b312:abd3 with SMTP id adf61e73a8af0-1bef60f5f03mr11530030637.8.1719882624652; Mon, 01 Jul 2024 18:10:24 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce1f198sm7480317a91.2.2024.07.01.18.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 18:10:24 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Eduardo Habkost , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Alexandre Iooss , Richard Henderson , Mahmoud Mandour Subject: [PATCH v3 3/7] plugins: extend API to get latest memory value accessed Date: Mon, 1 Jul 2024 18:10:11 -0700 Message-Id: <20240702011015.325609-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240702011015.325609-1-pierrick.bouvier@linaro.org> References: <20240702011015.325609-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x436.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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. Signed-off-by: Pierrick Bouvier --- include/qemu/qemu-plugin.h | 32 ++++++++++++++++++++++++++++++++ plugins/api.c | 34 ++++++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 1 + 3 files changed, 67 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..e9c07610052 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -351,6 +351,40 @@ 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->plugin_state->mem_value_low; + uint64_t high = current_cpu->plugin_state->mem_value_high; + 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 = 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;