From patchwork Tue Jul 2 18:44:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 809133 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp353529wru; Tue, 2 Jul 2024 11:46:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV5Of+Bja0OIZkHSUPsxjaVsqoaEg/Gv5qrQ0fZHC/Oklj4cQZHIBoooHnh7vkgd8zNYQ/5AgXIQllOhU9qR3JL X-Google-Smtp-Source: AGHT+IEPv4v+lvj3UTEdnxHDwe4OC/QgjLHOGJlLvWYvW8D4kNm/TWh+TXVwvJQqkNqdNzOEOhbU X-Received: by 2002:a9d:68d8:0:b0:702:2550:4e2c with SMTP id 46e09a7af769-702255051e8mr1729861a34.14.1719945993561; Tue, 02 Jul 2024 11:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719945993; cv=none; d=google.com; s=arc-20160816; b=WjuJXgTGKTk/IAl9CNxiDZOfSMztfEDzOqE7xRVddNJETxxOm/NhdE52aOGtel/oey X1sGRA3Wd3L5em3sh4cRwdyCVl1Vjgqs4IoBoiDiLKf7JQDX3eKifPkitfOzvh1NhxBB hU9nHQN90hsU4tV4oA7A1Vo0HfBGP9E0rCwsLPp6mrCAx+cNALpGRlGRsW3No554TcWJ DHgIkA4rvnBzLmQ6oqAf+jCYV2eesVswczYRscUXolsReXlgiD1qQgk8uzkRI4cmCgNi LMccWVP0/AXxzN/p+ou+du42bGyBh0IU7uZ10w43orCkfAPx2ecau4ZkGPIvQ//vcAHe I0wA== 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=oyBXc49dKIhi+M2/Wd3aKEZ1Qn/WS2CXcYu906JKbew=; fh=gfpM3aBSiIRsf14INmaLJ3KRp8sEj+HIZZ4PMQV7Q/U=; b=gRESWRXU4LJ6fuQRXY7x15kRkPkG1TWgXK51+QznuoZ8dbActeoSP2nnlZVjkMbt8U vhFPd9YdA10JrjTslWmIgDbz2Aq7oAg0YY9ezWMQHSRr3oOITVut54NUTGifPcV4ZnL+ tInksNfgX/6stBWSX7DfFmaaiOdDa9bv5pk9k8KHss4FLxgGvMAZjBYCPR4wQQt7SkzL MaYjd+G9OkZjoq3xEXYVygEvSOtf77X2YT3MohPRm2u4C2Lq6/YrbLiFodIywTX3EWcR WKFV3Y75v/HtVLsSeKs8Hq7uV2vx/H33Yf570Gu/psT+SNBiCgmc0mKD+0KnfijqiK6Y 1p3g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kPRQDfIJ; 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 af79cd13be357-79d6933b2d4si1066442785a.656.2024.07.02.11.46.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2024 11:46:33 -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=kPRQDfIJ; 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 1sOiV8-0005NR-Pn; Tue, 02 Jul 2024 14:45:14 -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 1sOiV6-0005MR-5M for qemu-devel@nongnu.org; Tue, 02 Jul 2024 14:45:12 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOiV4-0008Ib-28 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 14:45:11 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-754d2b05db5so554138a12.0 for ; Tue, 02 Jul 2024 11:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719945907; x=1720550707; 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=oyBXc49dKIhi+M2/Wd3aKEZ1Qn/WS2CXcYu906JKbew=; b=kPRQDfIJTWyuivv323yihCtXF/LAyRk6D0wltAIaMNRNXIZ9GLKuplD3VvseSMkkr5 hM9Sd+YDPS+i++EBzQIWXlSvO1Sfn/m1g72NW+HucRX3fEXs9xsEmZEPrbz2njHtK7Jb 72W88SqimaZkDMejqMG0qlZLmRDswhz/Rh1fuUCi7DnRUxuT2JYeO/is/q4tdRvrp1eJ wk5a9qB1jPzq7u69JheOOK4PlELJnEoaw100CrpCUwtX56RkXdKa1L+0KmARWPG4r5jv rXUZbD7ZfKhdm3lB+I6wkf0YQitBs/V6TEQlV0OiLhdMq9ZdBs+pejpIGwt+iFwBe9Qg jG/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719945907; x=1720550707; 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=oyBXc49dKIhi+M2/Wd3aKEZ1Qn/WS2CXcYu906JKbew=; b=JXUVtVMBNH5cq+OEjrhsjAM2W+mWJRdmiCVwpocvlEdwdGw3OuG2uEQhgfHocbOwEy g7AnKM2Rwoww/2mNnPzhyfikJN4BJM236+BdkyDjWuhjhmgWLhf5jI/QsRf+sYTA/Hp2 /cZzfX/X0eunJFV34SpqpNkr8Oko/jo/nTFPZDpuEhR0ESMWT7V+XrEQqkG/5RCsumTI jtFCiXsYFBalWGM/mEa8cllprXMNwY0+c7VnqCUb3hvqgWLc9w311ENOCYPr++RFx6/z +X8+44xyCJKMstAXsWtteit+x8rqkDZo878NFe/TERQTslY3SDiHODahdnaIYNx/RYrL 72Hw== X-Gm-Message-State: AOJu0YyJ6OASdEUxj4P+xXuJsBShXnfbGUqxCsOyUj+YIgbhrYSdjfuB VmdI3OoBtTzPRJdbyYAWEBHB24A0VxfvqgWY+1R6ME4pd+oBpff4Jnr3c/KcdEu6Btl0PDhLNwa D X-Received: by 2002:a05:6a20:b2a3:b0:1be:c33b:11da with SMTP id adf61e73a8af0-1bef6246216mr6812640637.38.1719945906994; Tue, 02 Jul 2024 11:45:06 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3e8196sm9257394a91.49.2024.07.02.11.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 11:45:05 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH v4 3/7] plugins: extend API to get latest memory value accessed Date: Tue, 2 Jul 2024 11:44:44 -0700 Message-Id: <20240702184448.551705-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240702184448.551705-1-pierrick.bouvier@linaro.org> References: <20240702184448.551705-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pg1-x52a.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 Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- 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;