From nobody Sun Nov 24 06:13:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1726248637104815.1132836051889; Fri, 13 Sep 2024 10:30:37 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0A34B14B8; Fri, 13 Sep 2024 13:30:36 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 93E90182B; Fri, 13 Sep 2024 13:27:15 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2647F1788; Fri, 13 Sep 2024 13:27:11 -0400 (EDT) Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 598A41433 for ; Fri, 13 Sep 2024 13:27:03 -0400 (EDT) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a90188ae58eso263946966b.1 for ; Fri, 13 Sep 2024 10:27:03 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72861sm890889266b.105.2024.09.13.10.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 9C1255F9E2; Fri, 13 Sep 2024 18:26:56 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248422; x=1726853222; darn=lists.libvirt.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=bg1S7MpqFLKynDQMTW/BgVqsjzz9T+4SZvu94a93bN0=; b=OxOkgTR1McopbDY4Sm4WAc9mAlyxaVq+1icrfuux+AWszs+egFk7/Y7Tve2oK7Ast2 A/9yoqNBOX/vYXjh7AtRfwUkcUvyjljlFFCiLqJXCB+ixkdHUVwK5N3YE5d137/j7XBY l0jJDFNDIyVLnvusvDpkegffyc2srnf5WkpWvTawXAo7FFX5jeI0t14ppX0urEamqWAT GCL3dARwpTIUlsfaoKyA2UnGeEo0nLK1d97G3BZW0lyK8WQXSVzQrgKEV3UIYAxiEMCy LdAews0ODM7feoYkDsoS1LQevA/aG3f6809O2O16cM+kXHSip/T9gagCgel2EL6TQ+PK BlWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248422; x=1726853222; 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=bg1S7MpqFLKynDQMTW/BgVqsjzz9T+4SZvu94a93bN0=; b=xEb59c0/4uNZqX2K20Iusnpiy609kxNNxrYE31XZcapv3XjoELthYYbYc1Mwu81WBp SOigvNlIrsOUH9HinSC/pRIPBQo/XzLXJaiuk0pz66csxu/4A4BoJh7bSM7FXOaxjXPE ITwRKq76oFTMAnwGRCXEt2eRT1yitlM3udXfr7fusl8eDWYoQFtvNiSooD1VMHV4Av/6 OKRIFYdL9o1CNbGY49Y7gjadSmeyXYKRSpwIgzUuQ2ov7KG9+S2cAST6DR4HpAW0WwqB b33jFM2PvmTXejB0PGcmbiTeQlOylVL5QjGRBRcjEjWodFWiC67zDi5mb5eZizIa0oiL /Cyg== X-Forwarded-Encrypted: i=1; AJvYcCWdlE+0BYv93pQsHEf7BAB2xFdEBeHRhVEr8SBW+Aiezeuz0XCMReHUCtS7xVo5wU+/ai1M+g==@lists.libvirt.org X-Gm-Message-State: AOJu0YzFsqgOlDdjLWTFtAYUv9IwEupyLjD5Pbumr9jzrbopiuRu08Km p1DpChzCC8r6gvmHfS2y3KALs1O44DnOzDqY9HaNF0y9h4mPu8TxrIUTt8x/LXk= X-Google-Smtp-Source: AGHT+IGLdiyvCRAbVFKTTRI/yfVPVbqoQSZ8/27/OW2tLtvYMf4LNrIs0r6WsStQgUWWXN/5rWXdGw== X-Received: by 2002:a17:907:3e8b:b0:a8b:6ee7:ba1b with SMTP id a640c23a62f3a-a902943de74mr591772366b.15.1726248421629; Fri, 13 Sep 2024 10:27:01 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH 05/17] plugins: extend API to get latest memory value accessed Date: Fri, 13 Sep 2024 18:26:43 +0100 Message-Id: <20240913172655.173873-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KYR2Z665C46AGJ3ZLA2EXIADKDTE55YN X-Message-ID-Hash: KYR2Z665C46AGJ3ZLA2EXIADKDTE55YN X-MailFrom: alex.bennee@linaro.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Xingtao Yao X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1726248638853116600 Content-Type: text/plain; charset="utf-8" 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=C3=A9e Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e --- 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, }; =20 +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); =20 +/** + * 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 in= fo) return get_plugin_meminfo_rw(info) & QEMU_PLUGIN_MEM_W; } =20 +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info) +{ + uint64_t low =3D current_cpu->neg.plugin_mem_value_low; + qemu_plugin_mem_value value; + + switch (qemu_plugin_mem_size_shift(info)) { + case 0: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U8; + value.data.u8 =3D (uint8_t)low; + break; + case 1: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U16; + value.data.u16 =3D (uint16_t)low; + break; + case 2: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U32; + value.data.u32 =3D (uint32_t)low; + break; + case 3: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U64; + value.data.u64 =3D low; + break; + case 4: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U128; + value.data.u128.low =3D low; + value.data.u128.high =3D 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; --=20 2.39.2