From nobody Mon Feb 9 10:48:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620265546; cv=none; d=zohomail.com; s=zohoarc; b=WxBukQyBppt1v7f4XD3rMP2OyD4HRMHtSgTJ9JBFrO0j48hcrSNZrjzVlrXa4wxUjci8dCNemeVNExPFSPpzeordyn4gMeL+YVgvf5f/b/T38PorsKYAvMwOfgpslveXgXMR2rP6Yaxvsc8gQrXytwouA9bqOPH6PfhgWbQFRho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620265546; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=mAf9Nmirwyr3GiBfMvQ08larsBUMwy+4+Fh51WcwJ9s=; b=M3L1YnUkpOCBe7G1/QbXCtOwhgcpXQZOe9DqztzFX2r6W7WiigSbwG6dmld9eTA4qvEJLoyfvQlJNzqMlmKWj+6WBPwcibqUfNQfopZhpuUDXise2qJmvEiQSYH8bqnR6XTYce4tr5hzAkCB9aOOAth1FH8XbXTdJx23OK98n14= ARC-Authentication-Results: i=1; mx.zohomail.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620265546763604.7417618792613; Wed, 5 May 2021 18:45:46 -0700 (PDT) Received: from localhost ([::1]:59778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leT5F-0000Nw-PK for importer@patchew.org; Wed, 05 May 2021 21:45:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leT0q-0002ca-Li for qemu-devel@nongnu.org; Wed, 05 May 2021 21:41:12 -0400 Received: from mga17.intel.com ([192.55.52.151]:23057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leT0o-0007bf-AJ for qemu-devel@nongnu.org; Wed, 05 May 2021 21:41:12 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2021 18:41:08 -0700 Received: from yy-desk-7060.sh.intel.com ([10.239.159.38]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2021 18:40:57 -0700 IronPort-SDR: Ux8tefLZPxZEpWBCrXwzy1BfRfvL+YnIxLJYWnQRuKiIQa22um3U3pz8RO7XYehlX1GAqbB4Mf pg0dGrrHGmgw== X-IronPort-AV: E=McAfee;i="6200,9189,9975"; a="178579137" X-IronPort-AV: E=Sophos;i="5.82,276,1613462400"; d="scan'208";a="178579137" IronPort-SDR: gsQl2CG711TFP2h5d0I0AByrDQOClSnXfc2qiNvEDN3PjPRLf/LL5/xuSbtHhEnI5NMKmHJJbs 59ntSv8QpGIg== X-IronPort-AV: E=Sophos;i="5.82,276,1613462400"; d="scan'208";a="469220338" From: Yuan Yao To: pbonzini@redhat.com Subject: [RFC][PATCH v1 02/10] Currently, guest memory access for debugging purposes is performed using memcpy(). Extend the 'struct MemoryRegion' to include new callbacks that can be used to override the use of memcpy() with something else. Date: Thu, 6 May 2021 09:40:29 +0800 Message-Id: <20210506014037.11982-3-yuan.yao@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210506014037.11982-1-yuan.yao@linux.intel.com> References: <20210506014037.11982-1-yuan.yao@linux.intel.com> 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: none client-ip=192.55.52.151; envelope-from=yuan.yao@linux.intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: isaku.yamahata@intel.com, Thomas.Lendacky@amd.com, ashish.kalra@amd.com, brijesh.singh@amd.com, ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, mtosatti@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, yuan.yao@intel.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Brijesh Singh The new callbacks can be used to display the guest memory of an SEV guest by registering callbacks to the SEV memory encryption/decryption APIs. Typical usage: mem_read(uint8_t *dest, const uint8_t *hva_src, hwaddr gpa_src, uint32_t len, MemTxAttrs attrs); mem_write(uint8_t *hva_dest, hwaddr gpa_des, const uint8_t *src, uint32_t len, MemTxAttrs attrs); MemoryRegionRAMReadWriteOps ops; ops.read =3D mem_read; ops.write =3D mem_write; memory_region_init_ram(mem, NULL, "memory", size, NULL); memory_region_set_ram_debug_ops(mem, ops); Yuan Yao: - Add the gpa_src/gpa_des for read/write interface Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Signed-off-by: Yuan Yao diff --git a/include/exec/memory.h b/include/exec/memory.h index 5728a681b2..7e6fdcb8e4 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -444,6 +444,19 @@ struct IOMMUMemoryRegionClass { typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; =20 +/* Memory Region RAM debug callback */ +typedef struct MemoryRegionRAMReadWriteOps MemoryRegionRAMReadWriteOps; + +struct MemoryRegionRAMReadWriteOps { + /* Write data into guest memory */ + int (*write) (uint8_t *hva_dest, hwaddr gpa_des, + const uint8_t *src, uint32_t len, MemTxAttrs attrs); + /* Read data from guest memory */ + int (*read) (uint8_t *dest, + const uint8_t *hva_src, hwaddr gpa_src, + uint32_t len, MemTxAttrs attrs); +}; + /** MemoryRegion: * * A struct representing a memory region. @@ -487,6 +500,7 @@ struct MemoryRegion { const char *name; unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; + const MemoryRegionRAMReadWriteOps *ram_debug_ops; }; =20 struct IOMMUMemoryRegion { @@ -1130,6 +1144,20 @@ void memory_region_init_rom_nomigrate(MemoryRegion *= mr, uint64_t size, Error **errp); =20 +/** + * memory_region_set_ram_debug_ops: Set access ops for a give memory regio= n. + * + * @mr: the #MemoryRegion to be initialized + * @ops: a function that will be used when accessing @target region during + * debug + */ +static inline void +memory_region_set_ram_debug_ops(MemoryRegion *mr, + const MemoryRegionRAMReadWriteOps *ops) +{ + mr->ram_debug_ops =3D ops; +} + /** * memory_region_init_rom_device_nomigrate: Initialize a ROM memory regio= n. * Writes are handled via callbacks. --=20 2.20.1