From patchwork Mon Sep 16 08:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828986 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681509wrb; Mon, 16 Sep 2024 01:55:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVcHoPv3ARsRQaFRNP/4iUXmcyLfuz4fcj9zzoN+yOfwOHq8WDsNTazDMFaItGRnvRg0ZB4Hw==@linaro.org X-Google-Smtp-Source: AGHT+IFND3jsUak7ehBgPphQKny3CtfCJh3CjL5ciD5trodBlmqpldS9WmitT+ya3K8CQLl/jI8i X-Received: by 2002:a05:620a:4514:b0:7a9:a1f4:d4e1 with SMTP id af79cd13be357-7ab30d5eacbmr1655945885a.39.1726476950806; Mon, 16 Sep 2024 01:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726476950; cv=none; d=google.com; s=arc-20240605; b=TFDk/C7vWcJe4nrST/3zVI+f7uurvfeeo7qnujcX5M4ngxH9U/kd0XwY9AIOZ3Oos2 0UlQMlS/1h5JxZR8iNfzzHnua7qO1CN0uJkjvi+HKII0PnLO9nuXCevUb8doUT0LPK0Y cORqdJD0aCAUFu/itgW+xl0WTpkhsR+nRKIetQwSYCdPZp/wt8OJgCBlbkdntL31FcJC z80PGWRMxkB+taHEfk62HQJhixzn4uSCYJwi4e9SQUNe4fJ1JNf/n57sw6Ls8vuJDjq+ P3NQlV8j4jl/57pYy91tqoAs/ip0TIKZzVSG8wh79sobmGGlcFr4y1PQbenZC36sFnW7 Sk3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=fLxUQUnLDvLi/r8JTuG1fjcjViW7gUT9q/lZ9pYtQys=; fh=J7xxoiH/FgLINVeQdLJSQ9A6Jne2JYMDx39ZFxN4EsU=; b=SpegqYpaGKjfl7XqqHJc7fPfZ4265/IMnE78stHbl3kbQccU2cEeAEh+QVA6ZrQaHw zzo8z91/lRHagSPhrSc6SdVqTy1b0Fiw7yfcUPShbx42Q0XMLOEhUCmAWrEAohupNDDL yNuFnihjrQY4gI1te2Hvdt3xmxjFpbFpKpbkndRrc4QodCSbXELRyRMijBIIENEH+pcF 7XxpO0fTqHbbRriy3baKwsdy/tzqmTOvExUdgMi/ZajrOTKWDJ8sV50r99XQckdEqMae hYA8BJfWjN3sZ5jK3ixAEZ2QWJ9it6TyZ2M5csl2XFvXN4Efy7GAWibTH0R8CfvkLRN2 eOZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JUIUAfib; 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-7ab3eb652e2si512463385a.515.2024.09.16.01.55.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:55:50 -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=JUIUAfib; 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 1sq7VU-0001Rn-LQ; Mon, 16 Sep 2024 04:54:52 -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 1sq7V3-0000GQ-T2 for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:26 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Um-0005Cw-CY for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:24 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42cb2191107so31972335e9.1 for ; Mon, 16 Sep 2024 01:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476846; x=1727081646; 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=fLxUQUnLDvLi/r8JTuG1fjcjViW7gUT9q/lZ9pYtQys=; b=JUIUAfibIm77eE3GtairYaltNz9w1t7AAo+Paar/KxqEOH5nGqRHpct3LMCUkmom0l jnXR7LY4lX66FB22a6ZAnnpXat9WuCnV2V1erJ39Pv28S8ByIwFcQmwxhr7m4q5DJKKl K5b0CCuI4J3qRH3/VwlzUbSXJ/ur7nruN8S0jNVSvk6BUAeD3kiIqi/zPfugn8bRv0pb IGSRkvGrVD0Dw8+7x0hDNvsdRPhMtheYcslgB29CixrdGdFdlK3e+lecdR5qE+gI/+p3 9REXUWPf+JqAtyb4FKsY/MYW0bYlvOPXHnMQT6cab9zOQyVhXcY/FR7jULWaekSKjyX0 14UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476846; x=1727081646; 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=fLxUQUnLDvLi/r8JTuG1fjcjViW7gUT9q/lZ9pYtQys=; b=qHTUzMxSKrBW2E2AXakUCui1YYhbh2+JFgXdFJr4ZmCQk1soN+fhlxKHYZLqsL28JX k4ScuawHKMTRpibMhamupYHvbEwo+Ic44oRTEEjTOuQWmcf2VrfW4N4SkE/smEJOMe2N stAqJKzbsxXg4iipDEqu0w+jlsDU4VjQXu7/ZGdQnRQNGSFOhffkkNzDfvH9BLzNHAgR PUwATr3vHheXJkbzSEjA5+eAkRYXSesoPBpmtOZrcyiWMk8oe5MGF9Vh0Df0GazRWBc2 h9j35G5b3+FepetRuMQpo6aFjaGgi0I91UFqnA3IrusT9f5Fe5n4Dv9DWy9q8vRYmzNg EzBw== X-Gm-Message-State: AOJu0YyYKzfhj2BMaHJ/IiQwjkA1EyInLrhgS5ve6tG+KYn+K+Jut40I eE/X0i5C/I85E7Hv4EwDgrS005mWoRa18Ub/JCTDnIMKLcuujKQVm1tUup7qMSU= X-Received: by 2002:a5d:4092:0:b0:374:c481:3f6 with SMTP id ffacd0b85a97d-378c2cd58c5mr7633901f8f.8.1726476845854; Mon, 16 Sep 2024 01:54:05 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e71f0683sm6632128f8f.13.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C4BF85F91C; Mon, 16 Sep 2024 09:54:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v2 05/18] plugins: extend API to get latest memory value accessed Date: Mon, 16 Sep 2024 09:53:47 +0100 Message-Id: <20240916085400.1046925-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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-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 From: Pierrick Bouvier 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 Message-Id: <20240724194708.1843704-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- 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 c71c705b69..649ce89815 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 2ff13d09de..3316d4a04d 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 ca773d8d9f..eed9d8abd9 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;