From nobody Sun May 19 03:38:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yadro.com ARC-Seal: i=1; a=rsa-sha256; t=1676564312; cv=none; d=zohomail.com; s=zohoarc; b=fNvP0uRGOVSIOXsa1vQLyndIQCOHJz6Bx/YWFkpkPI3MLqShFrC25pS6HKk6q6ybfajrKHwzfkr7Z/NHsfbDRRcuqjW2nilhocNrspwm7Cf4VCgIUkdYsRG68Y2EO7MGY7mrLy1L/WyMpLgJUyKL/eoN6g/rIPPe3LRy0AXSsrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676564312; h=Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=NbQ22chFNcHrTG4fGMJGKGCYJ6aC4/XmzbiljAuBXTI=; b=OlD1xHmkXj4PmOMXRkVhchH9KV2qPoOdWCbVKiHSTgac5TJKinbPlL2/rAq9a0o9RRIWy7lScuw8lM6pgDim5JkqfqxSwJuwOVFH97DaF4aWB+PMjY5YsI9NjEvhsYQoFnQXguSGNI1CYvIwbELPQmOJ15PT8H6SmnIQUQ2z5e0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676564311742593.0194135918472; Thu, 16 Feb 2023 08:18:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSgxi-00064h-3T; Thu, 16 Feb 2023 11:18:22 -0500 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 1pSgxg-00062q-KX for qemu-devel@nongnu.org; Thu, 16 Feb 2023 11:18:20 -0500 Received: from mta-02.yadro.com ([89.207.88.252] helo=mta-01.yadro.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSgxe-0004uS-Dg for qemu-devel@nongnu.org; Thu, 16 Feb 2023 11:18:20 -0500 Received: from mta-01.yadro.com (localhost.localdomain [127.0.0.1]) by mta-01.yadro.com (Proxmox) with ESMTP id E8A8E341DC2; Thu, 16 Feb 2023 19:18:15 +0300 (MSK) Received: from T-EXCH-08.corp.yadro.com (unknown [172.17.10.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Proxmox) with ESMTPS id DD193341D71; Thu, 16 Feb 2023 19:18:15 +0300 (MSK) Received: from T-Exch-05.corp.yadro.com (172.17.10.109) by T-EXCH-08.corp.yadro.com (172.17.11.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Thu, 16 Feb 2023 19:18:15 +0300 Received: from T-EXCH-08.corp.yadro.com (172.17.11.58) by T-Exch-05.corp.yadro.com (172.17.10.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Thu, 16 Feb 2023 19:18:15 +0300 Received: from T-EXCH-08.corp.yadro.com ([172.17.11.58]) by T-EXCH-08.corp.yadro.com ([172.17.11.58]) with mapi id 15.02.1118.009; Thu, 16 Feb 2023 19:18:15 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yadro.com; h=cc :cc:content-id:content-transfer-encoding:content-type :content-type:date:from:from:message-id:mime-version:reply-to :subject:subject:to:to; s=mta-01; bh=NbQ22chFNcHrTG4fGMJGKGCYJ6a C4/XmzbiljAuBXTI=; b=EW1M0zeww2pL6HxpB2hT0nNvh1nbgjigCrDY+vNIVa0 98ZAIKfylxJVu8s7lALcA9NNnN4Mlbr5HOS7LBeU9VzrrIa2oTYrJv5DVaJBqGq5 g7Y6Q1DDU6EG7FefE/24pZulHbJa1q3Iv3a4w17mxFciu92YOr5gQoT3IJxPTKKQ = From: Mikhail Tyutin To: "qemu-devel@nongnu.org" CC: "alex.bennee@linaro.org" , "erdnaxe@crans.org" , "ma.mandourr@gmail.com" Subject: [PATCH] TCG plugin API extension to read guest memory content by an address Thread-Topic: [PATCH] TCG plugin API extension to read guest memory content by an address Thread-Index: AQHZQiJFFLHBBoEMdkSyQJ0m9+QggA== Date: Thu, 16 Feb 2023 16:18:15 +0000 Message-ID: <209f0f05-b982-eecd-f4e2-70da12e91892@yadro.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.17.10.14] Content-Type: text/plain; charset="utf-8" Content-ID: <22706CAB80392C48ADCEBB25C1C56455@yadro.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=89.207.88.252; envelope-from=m.tyutin@yadro.com; helo=mta-01.yadro.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yadro.com) X-ZM-MESSAGEID: 1676564314051100001 TCG plugin API extension to read guest memory content. qemu_plugin_vcpu_rea= d_phys_mem() function can be used by TCG plugin inside of qemu_plugin_vcpu_mem_cb_t call= back to adjust received address according to internal memory mappings and read content of = guest memory. Works for both user-level and system-level emulation modes. Signed-off-by: Mikhail Tyutin Signed-off-by: Aleksey Titov --- QEMU_PLUGIN_READ_PHYS_MEM_ENABLED define below is to let plugins to check i= f this API is available in Qemu build. include/qemu/qemu-plugin.h | 18 ++++++++++++++++++ plugins/api.c | 20 ++++++++++++++++++++ plugins/qemu-plugins.symbols | 1 + 3 files changed, 39 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index d0e9d03adf..576597f601 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -625,4 +625,22 @@ uint64_t qemu_plugin_end_code(void); */ uint64_t qemu_plugin_entry_code(void); =20 + +#define QEMU_PLUGIN_READ_PHYS_MEM_ENABLED +/** + * qemu_plugin_vcpu_read_phys_mem() - reads guest's memory content + * + * @vcpu_index: vcpu index + * @addr: guest's virtual address + * @buf: destination buffer to read data to + * @len: number of bytes to read + * + * Adjusts address according to internal memory mapping and reads + * content of guest memory. + */ +void qemu_plugin_vcpu_read_phys_mem(unsigned int vcpu_index, + uint64_t addr, + void *buf, + uint64_t len); + #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index 2078b16edb..95753bce95 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -442,3 +442,23 @@ uint64_t qemu_plugin_entry_code(void) #endif return entry; } + +void qemu_plugin_vcpu_read_phys_mem(unsigned int vcpu_index, + uint64_t addr, + void *buf, + uint64_t len) { +#ifndef CONFIG_USER_ONLY + cpu_physical_memory_rw(addr, buf, len, false); +#else + CPUClass *cc; + CPUState *cpu; + + cpu =3D qemu_get_cpu(vcpu_index); + cc =3D CPU_GET_CLASS(cpu); + if (cc->memory_rw_debug) { + cc->memory_rw_debug(cpu, addr, buf, len, false); + } else { + cpu_memory_rw_debug(cpu, addr, buf, len, false); + } +#endif +} \ No newline at end of file diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..f0ce8c730f 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -42,4 +42,5 @@ qemu_plugin_tb_vaddr; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; + qemu_plugin_vcpu_read_phys_mem; }; --=20 2.34.1