From patchwork Wed Sep 18 21:06:59 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: 829423 Delivered-To: patch@linaro.org Received: by 2002:adf:ebcc:0:b0:367:895a:4699 with SMTP id v12csp36157wrn; Wed, 18 Sep 2024 14:09:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXAw0ZboVU8Hw0oexBvFOKpLtljJolSOVwdwK8yIaO836+CGgbv4UlMv9rmcSgAJj3eQ8gLrQ==@linaro.org X-Google-Smtp-Source: AGHT+IHaUZVZrBb1FXY5xrzT6xb6142iSSFIOMLiU5/ye8WdzdoqaMDCCvgO3yR9OUiOEkLaav1B X-Received: by 2002:a05:620a:f10:b0:79d:79cb:2a5f with SMTP id af79cd13be357-7a9e5fc9447mr4349253285a.63.1726693740488; Wed, 18 Sep 2024 14:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726693740; cv=none; d=google.com; s=arc-20240605; b=LfT5J68rYPrmczJkM4WuauLvuFpxTver6nGnShSVIamaE9Kol/qjil+dONbLjCq5lP Cmtd/e1B3UDSCft4iV3dLIAV5VGdAhNrjJwhTD70cVPuWQ4O9dhSrWdFH5xGldcUUA+W WBfWwbm2X7k5ZkxPJMuYqncKBm1+xc+vNCzzMI7loiJxwT/OwRhqpBVqlaow5zGFiC+N JOAX7D96TYlAHNg7ZYDpDV+J/iO+fYug3UsZoQQwFfHQpY88+wKBhKvA31UA4vTnPyOn Dn547iPXsqu0kgo8UNSSco81ZdShbOdgFi27ppkzjRJJ7Vf+diCE02MDXTmx8G82ZbXE ms/w== 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=N+FbOV5cANak4tvS11G6TRWhb5xp2aE/sDGBKNdQXN8=; fh=StH7YncFSzDQ1+w+/tMvqeMEta626WGmgDFqDvANF0o=; b=S1RWOuBQQSMppYiaTgefRze06xuwuKDNLgDGQoEjg6Eri58sfkH1S58h0uDbFJsuFY Ip/rhtoRCj6cEnN++0CzY0v8keY1Mxla0AyjnH0n6Oc3wJeaXB/irQZX5qBW0s5XiOdF o5UukRsAcUEDr5TxPC7a0rF/M0stTjNQqCY/lcVxdjYRWRU9pWNi/+gu/gWTnRAg60V6 kvFs74n3NoDm0KnJzAuKJIqkjEVyzbVa/eXBevgnP7NmaBwRXivawQIpe7mvSKZsQsHJ kAgXXDH/pe6YouVwsvRuq4ssEJ88ZmnfPv/loIIr7fYoodHcvt8ViYzbS7yd4UgTbAog js8A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s569fDSx; 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-7acb07f7bf6si32105685a.136.2024.09.18.14.09.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Sep 2024 14:09:00 -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=s569fDSx; 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 1sr1tT-00051N-FC; Wed, 18 Sep 2024 17:07:23 -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 1sr1tQ-0004qi-IW for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:21 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tO-0001bF-OV for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:20 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5356bb55224so184243e87.0 for ; Wed, 18 Sep 2024 14:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693637; x=1727298437; 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=N+FbOV5cANak4tvS11G6TRWhb5xp2aE/sDGBKNdQXN8=; b=s569fDSxJFvhx5IkcfJvm5D7LA2djEYPxZOlNNTQPe2+kgLnTDWGA5vy6hIktlHAZv N0yywnal2dOC9y8LaE979z1YZLknWF05sK7RBFomgE1T+vWakKyC065s+34PgsqrF/sJ 0zcBl0c4g3qM/trGm3Ee2zyOCAC2d6pclj9XfUqF0giMnPiSTFER5UveQR3Tte1n7SJi WSuvRUDclZBys1RkRBO81hMIuAonpyDf6yfS4fv14+smAxc03Idc+1zeCXzZ6xhFeDIj b1aOHBTKG32CjrRIYagd5KdzPw8avS/Vw713I3G0RWivgJSnDq086TlGpzaqmMD/ndHy 2Lqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693637; x=1727298437; 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=N+FbOV5cANak4tvS11G6TRWhb5xp2aE/sDGBKNdQXN8=; b=PTRwDNz4OHbHosa4jYUIUnFlyPV+qTfVGWNl4jr4JNagt8BNtUUGm2NK+IpC3+6DBh PdGK/I0QJoswdkJB8VTdcNlS4n68eVSbLF+R1g/FNxE7U9zr2KEyDCUX47FrrqW2/fhs HZ1qSwyJ6sfewJcsrE0kYKOxPvY3a+mOaupS+jixluokeD+waqFaO9pCp+1YLDI074UY d8DZ6xJxUdXBaCPiaVX0y7jtBL/viiiOR2Vuduik1DCOXfyZuksHKS3UXNqkVWk8ejWI PksaUQV40ezGJjQidlDfg4Ak6an93BjMXRoUJ2raNvW3qyZhXMYRC7EUfyK3dx4SHfDF j3qQ== X-Gm-Message-State: AOJu0YyeO6K8xH7dVulyVRD9rk+goMhq3hufy+9dEjQU+HKN73YcBFz0 u+PwtRZDDsKhCRo3yfiyiXlNsT/Jz4VCGmUgoSEa9k2mxJCyAVpjYe7iBVpwJSw= X-Received: by 2002:a05:6512:3350:b0:536:7a88:6185 with SMTP id 2adb3069b0e04-5367a8862e7mr10410876e87.15.1726693636428; Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90613303b4sm629745866b.213.2024.09.18.14.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:14 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id BBF0D5F90C; Wed, 18 Sep 2024 22:07:12 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Xingtao Yao , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 05/18] plugins: extend API to get latest memory value accessed Date: Wed, 18 Sep 2024 22:06:59 +0100 Message-Id: <20240918210712.2336854-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12a.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 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 Message-Id: <20240916085400.1046925-6-alex.bennee@linaro.org> 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;