From patchwork Fri Jul 5 00:34:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 810346 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1388174wru; Thu, 4 Jul 2024 17:35:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUgj212DGtleyo9Pwp1KPjGFY0cUZ4z2W2pdgxE3f/+hyLqcJDAuvl6Dopu1+3zYoOhDGs4whAYPI+rjjq+Jum8 X-Google-Smtp-Source: AGHT+IEM13yqHJTKWQw+1XiNWWbebjnHvRK0XZlkapseSVd2Lrw+EHx9gkHz6FGj0DNkaB3tHrsa X-Received: by 2002:a05:6214:2423:b0:6b5:3f58:bb7d with SMTP id 6a1803df08f44-6b5ecf7a09fmr38506586d6.5.1720139726472; Thu, 04 Jul 2024 17:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720139726; cv=none; d=google.com; s=arc-20160816; b=t61OTYglCYX7kB46PIhpUb0cmz8H8fnB6KPRYz5PGRAL+KZqa+hG4TYpTjSGwOm3Qr EKrh5cGw+8PPpC/Udp3se+eMVQWxzb3bEEeanBtXp6zOw0u4e0ozDr/IioIuCRb8saHt WPLzv9Ap1a3+zNFMHi7/qLdscZv10cr6w7RxwtPbv96b+yMU5LFfVKZ6Br9VjYst1hZ6 J+QY9ewQ6VFaaNUzJ0RI4vdzOPjT+D/SrrznMxOhhYh4++agtxyqpDhh6exH7eKle9QM ErNk6Ue1OfQf9zQvd5o3xCQgr8P+8PFS2JmWxMFtuokrXKpYJg46o/Jz5wwZTMMMEn3z J1Lg== 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=52Vup5Vdc05sfIMDswHWSFk4NK0aeE4AML942us+C+U=; fh=2IzZKSAfkxDgXTtM7kFa1jWu0SUssVJhWA7cdsHH2KE=; b=pScJGVJhPgE9w29XpS07Bp+Dh/m10+TgKUD7uppn01YGUGaTIM+r2ZRxxNquz4TTE3 d9OAUh71SBWzYbglEldkO+h+HlI76IGVcIXce+OeLCM+rKe1Fs0D40lwne/raDwmP8ru Lq4XewZIWeXrXBmENU9sP9CYbtsqdpdVJqn0Qd6tvL+oeeUeClt6l+JgQjYLCOxWpAcQ HbsetRTFauLWBccxFqQzdngwzAA7/HbgfsIyYYDMppqmRcQIcf72pM2MCiqw9Y/q6u+M +Nqe52lT4oYX9DhyXyPCppWI7HkvBdN3LXA6c7UWZszyLcH3lxKXbOmwxS7aQLOgfRCz TRzQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Toctc8Ls; 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 6a1803df08f44-6b5dd21151esi60311326d6.510.2024.07.04.17.35.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jul 2024 17:35:26 -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=Toctc8Ls; 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 1sPWuc-0002rb-Tz; Thu, 04 Jul 2024 20:34:54 -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 1sPWuc-0002rJ-2f for qemu-devel@nongnu.org; Thu, 04 Jul 2024 20:34:54 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPWuZ-00006V-UY for qemu-devel@nongnu.org; Thu, 04 Jul 2024 20:34:53 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1fb0d88fdc8so5394465ad.2 for ; Thu, 04 Jul 2024 17:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720139689; x=1720744489; 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=52Vup5Vdc05sfIMDswHWSFk4NK0aeE4AML942us+C+U=; b=Toctc8Ls06cXO3O/ssBTSPa/f3E2r0VJlSfHgITUVb6efrJ/C5bwOO7yNfU22oWPTS EkE2tC7aDgxciEoxfUtx+aimSOUXUJyfdiSOdC+E6AWUW/MVI3m7SvafWsRgHupqWXCp pJxoRVqyXxS0lYXbULZH42bHgyd6/p4wD3VXGFoy22Uh5K5bpYHEU3K4ax0b+KtJZa+Z a/bevT1+PcktxQWoGZYQj4QoGhWiqPhifiiOGbKsZiQ/rZRZQKvwDhIH2oeHW1IBJyzf 0k3s/t9HdiBIiKOKwfPk51OK/9c6Sye8WwYcePr8CAeqS+mLliy7EJBsN/RoSz/FxCrs z/JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720139689; x=1720744489; 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=52Vup5Vdc05sfIMDswHWSFk4NK0aeE4AML942us+C+U=; b=clI/DJd2Yivf/GTxMoFnO6Km+ToHQ6z+bVjbm0FciGiEWJe/tUsVqYk39KAibUsjQR 3xwQKBwW9ZVnaSf7kvJRKgAZRKdt2h7wUXpI4VRRYCltoTvHnnsgKFHeilcLn3JPclYt 7u8sz4SONLB/tUBnGet6v/iH2N6FXfd1kT6ohc76jU12VsEfT+wVCsfstyTjHy+2zrS3 M9rwY0IWjEaOkU0gWwLkVnYYwZ4iTTffh85kYctFebP5tG4RS3vx0ZEw+sxBQs5gzpDM UB81tIX5qoqw3sYUkJbv+i+KKOVT6Ck24wIVRpN+uekBh5x3pyUGRZEurC1+m+U/zxRO 3kJA== X-Gm-Message-State: AOJu0Yy+Z3dplkjy7iZc0QUX8xWbfx1s4zozAwJj+j+dVgVhCez/pN8+ L1mNIbQVmL6Wlez7CEVRbCuy5tufX4vsAjMxOTVaWu9x/nerUqds0MPFWvgCQX4WFhbPQ/Bg40D KXPw= X-Received: by 2002:a17:903:1212:b0:1fb:2bce:4322 with SMTP id d9443c01a7336-1fb33e0a368mr24114995ad.11.1720139689520; Thu, 04 Jul 2024 17:34:49 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 17:34:49 -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 3/7] plugins: extend API to get latest memory value accessed Date: Thu, 4 Jul 2024 17:34:17 -0700 Message-Id: <20240705003421.750895-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705003421.750895-1-pierrick.bouvier@linaro.org> References: <20240705003421.750895-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x632.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 Signed-off-by: Pierrick Bouvier Reviewed-by: Xingtao Yao --- 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;