From patchwork Tue Nov 1 15:52:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9407547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 68F9E60585 for ; Tue, 1 Nov 2016 15:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58B1529A1A for ; Tue, 1 Nov 2016 15:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A70C29A36; Tue, 1 Nov 2016 15:52:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C55129A1A for ; Tue, 1 Nov 2016 15:52:55 +0000 (UTC) Received: from localhost ([::1]:48835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1bMs-0004UD-Ek for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Nov 2016 11:52:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1bMK-0004SB-8r for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:52:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1bMH-0003YW-5z for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:52:20 -0400 Received: from mail-co1nam03on0049.outbound.protection.outlook.com ([104.47.40.49]:49120 helo=NAM03-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1bMG-0003Xs-T8 for qemu-devel@nongnu.org; Tue, 01 Nov 2016 11:52:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=dIsNGCU28Ugdet5KDjKwLzvImzRNDmXg+rWpnlRhu3s=; b=aul3NGfisgvvIziEEtmub/hjQZNbkVqjHgJJC8Xmo8RZj0IU8MFd85ltNUriXKqyLKGTl+IN/gS9wSsBj7u2ugcK2ocp6O9oV00HN0E4cpBI+YTktLeu59NsvKuSojZQQ0oj5WdrlaQ5dxfmK+DZB3UsvVoI4KDWvbaX6M2GprE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by CY1PR12MB0665.namprd12.prod.outlook.com (10.163.238.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Tue, 1 Nov 2016 15:52:12 +0000 From: Brijesh Singh To: , , , , , , , , , Date: Tue, 1 Nov 2016 11:52:08 -0400 Message-ID: <147801552830.18237.5554011905674997120.stgit@brijesh-build-machine> In-Reply-To: <147801550845.18237.12915616525154608660.stgit@brijesh-build-machine> References: <147801550845.18237.12915616525154608660.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BLUPR01CA046.prod.exchangelabs.com (10.160.23.36) To CY1PR12MB0665.namprd12.prod.outlook.com (10.163.238.150) X-MS-Office365-Filtering-Correlation-Id: 810faa78-963a-473b-7f19-08d4026f0c61 X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 2:Aiv/Ie5Ut1kc1i8GolRr5NN9FIFco22V0dKJfjH4cCyZ51/Sh3TOnTclJsVwgKM+MWscMZNUM+HIQkaVnpYCF8kn6Me2c2ILObnj/vNGyiXsHGEOW/0AF3MByHS333rSjehQmW8j72jifsPiiRybEPoyWu+l0eIGQEHi0Agx7wSULJFlvTcZNjWqPuLodnbC2qpiUKTDTwfRUzXbGdtGHA==; 3:8Bam7hiXcZPXRw25TFoUO2lOdjb76thnrSbToCJ9/4ql8fMRGtWL6JYb8r6xJxSYxUH3tpAyxDP5wRiiPNXDKFo9cK7ViITphiTzfp+XXpJsDFTTnx1HfJAWfBxJnp6Egna63q+f0+aIuBdDSxAWsw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0665; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 25:qbBC/ix6ifMwkAB8Vxsd/+L6zbjlhGhU41/geWxgztqTpO8yjE3OrlyQ1ivGBquma/fET+uOELiO1rspnoQ1YQd+eZx1/4dsb4Xg95dt1xPVDLe+OhwMhxrDCcJ/FVmLzt1h5IJl8ktVg8MUpkBQxXy5zKl1LLoPPvmazSkk9D2pbr3TsJZKCiDul9u09U6KdcDb5fbMCGLte0I6gr4Wo+oriZ59rEXOz3bKfhn202JvCGbsVWshO4yk73Ih3dUPFS9oJ8EbBT6ASabnMTJTvFusJz8uOHXqBpwjDf2X513D9VVWRAaNj/drnujbu7BNIUtbj+Uu0Ky+rO4IRYtx2KMVv1Rm+yeEu2AwBdtGYL1SaSyLV9FisrvaqBDWcFlgwW+WJbYd1qRpzc5dlr/d42vKhquu8gY6cDLNuV89U9FB24lUjnhavZ16D02jzfMraAk9HMAkO6OPk2O+QutY6eGZjlgC+T86U0Zhza5Blj1JFhvyvAScmf//rX9Dig7Sil1FnK9bthlab6yJfoiij3X8A12lfUkVV9cJLMlOd4zk8tgXpYdQgaxV6Ic+wekf0OtUiLH9yvtq9J2618MWXD4B+NFf4zfRf0V/cphQgr8fvCYvDhFaPonDS43AkDmxU4dl7Ccrd0vxbx6hvjToDhvdJyarCbE67h8tWMRdOUqT3DqV5ISW0hGYAYcp008e+f2S/xDge002znsWOxLkXMJqiJAMbAijCI7ldX9eCqb1lfs4rdsezpNn4KRfopVb X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 31:3FiocuKQwcWx2PywnKwaXSGwXPoep90ra6wVxPtEnN5c+7P2V5vXIPjMrmScmDld1HeMauG4UhJRDsgHB/QbRjKj+VmCo1zgY9iqq7N/hx/GGGQeypeCu4WStp8lj0u+30rdqqt+Zu41voCeCpv/vl1ABaMMFJC9nMnFfe1buxo6pI085y3t0QgaNwtyy1OD7WpIie7yRbEW2In+go+HgkmWagEwptndTPp8fnFQ1Mhy0/dmB9Zmo25bAApcsBW4; 20:YzL4lzqJav2zSQjP+KWn5vyVAg/LRBWPqxJ13FC/mWy/MIDvKwVHOlbkCedSNqKToqMFXsZUUt9CKMBldCyw2yCRb79VEDJI2riC6tmDNkOjM3xiHM1HIFofUCbk9/kx4/hZNDB/lF4Qgp/qbw98RQOTfff7fU70Eyd8iSxaYaOQqQ8ZEweRR5CdFq1+xfCtFcG6Wpjv7QhNjstiS+5IUPCWFgHOLqDXIHedGk0p/g96Z9y2YvIPU4ucXXW9Efv7j6FlaSMQFjvhsQMqYglMdEVHiLdYh8n92RoW85nb3cepIpLP6QYHKh1H/mozGmbgIUpiTWxkaDrbX5HS6UoSYKuni2k7NPEbmr3AxGiBqyGemgRrz11GmG1IxSKO/v7SOjDD5R7IAW1ggHZY8JPsWTCy3BQnJiuHu474OXaiFPkXezQcI0LJrOw3VflMR433doVQln1XwZ9bZaonyeoXgd+IP5RJMZAhC0rHkkA/lZWdYxKAEhbuEI+nw4EFijjP X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:CY1PR12MB0665; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0665; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 4:RdkP58DEm5YuJj4TKfvVq4q8Ja+bfZtJKNyAEOVUtVHSVfWoJzU9GTlrYtAxV7t5J7jmg+QSBSLpB/n0KquCHvYemWidGcMjmha3WKgxCRLOJGVRrMBD/QpRPVXY36mijd4QpyI0tEjq+GnoCAWMVVdQouKKleP7wbAlPXbqKkrUsaW1qDiLXdGBak5a5xz0pBJBZDZAViua6rkU7fWkkUulHkuTuv7Scxw3q9ksl6OPgUMsq2k67nMa9fUw+U4H+Sq8dzkXc+LGU2ehU5Zm1SGCc1rOOMdi372TH0xk311TTKd/Mp4XBx5SURUVW20VyIqgDDmdqiG/YCXKkmYLySyKpFCHUHGrVJ5653kBT+rVdf2UkA401+KbYcQwdSmbPEqxV28YKrYdOAStIQB+itpyja1KOCtbt37KoioTTwKekiZy2rotU/kaDxJdo8kT8o3Uua2zrbjvx0Y/R7rDGw== X-Forefront-PRVS: 01136D2D90 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(189002)(199003)(103116003)(81156014)(33646002)(50986999)(47776003)(76176999)(106356001)(6116002)(42186005)(189998001)(230700001)(81166006)(4326007)(3846002)(586003)(23676002)(9686002)(105586002)(54356999)(229853001)(66066001)(68736007)(101416001)(33716001)(305945005)(19580405001)(7736002)(6666003)(77096005)(83506001)(2950100002)(50466002)(7846002)(5660300001)(7416002)(97736004)(92566002)(2906002)(86362001)(19580395003)(8676002)(5001770100001)(4001350100001)(2201001)(921003)(217873001)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0665; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permit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f-8?B?dUdwU1JLd0YzdlYvQkpBUT09?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 6:39+lTPJ2WgNOiLpuJBmvFY8/3jZTCa9gQo0896x4I0ZprtjbojwD8WFrJQD7iIIpmco8MocBARXI9tBIApcu7tyCBkXyPPceGYI5BJckinb9OxUzx+46PMZLXpaglHu/P9AGb3zEKTvc5jmBc/Ui/S3TRvmv5anGasyD0NWwCGn0WelaQDyGbazvGXFoiyLyErnXxjGs8YZYTWZ5Jh+jZIdbfKjlar/0JDgXwp+YDPVgdlnZzKp0jKM4VJuuXBBycG2T6h24n+20PpqTlKRV2z6YOJmQ6F4UY71nVg3ykzN4zKOYE9nSsXn/5TIpT9TQSsGQYDSexUBEsBLdOIv9eU9qXFq4ErRkNe47CNmuZTQ=; 5:VaCbfh+CMTq1/B/92AYJOgJLc9oSIYrh8xIlotnJiUBNlugLD4spLjMtuHZLL/mu5HpOse+DFedVmG+6cCUN3FyOCsVQ4pHOYMJJYHVxEbwOKTgd/H8i1VBBa/hg+H0HqxF960CEm4zMYgbjBLrlqA==; 24:LeqqTCkdQ6Q7deTerzizMixMWk7YIrp7fhoJeDVp7l/fy81H824lsifKv143ZZCi479M6AWuBhXdflQcmkU8TajjEd3h2EjlioIU2naPOOw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 7:bAEiRPWFuCxz3oZ971lrHBoQhbG3RMyUfG187Dp2iEQ8NG8bDjDPb9zIarh1FkIJyOo9fpPwiVQGL2x2m3dtuBNU0VOFQxxk/nZAvguJ0+D5bxpx/UW7sllkp4m+MGNpoL9U1EbXu4HhTUDSv2OTtIyZhKXZjsFAR+gxiJzKUY9DNHuAAUvBupN2y9ITQa2t45KxNVfnZ0HdM7IdZExq1GNVombm/yNeFEhHfOL4CcJGgmQamYi2H18YKZCj4aItNKMmIfcM+fpt45L4YxNrm1ySeqd1GG2DC73NilX4ZryPQObnk2baGfT+t0sqGiK3YvjdoD8P56NCYZ/LXL309fLWIvzSPQiqVKfhuLyLe/E=; 20:sk9q943jRMKwnd2Z/qZRY9pO9azUfh9fSO+gUsHMAtMe5FZXTtFHUJv5XRu8tMdxcLpkXyooHsbxQjZnFHafpt9IpgnDoyMSA8zAHC4QThSXfzPF8QoAbGYhDktLcfMqWG68OKeDIHQq2aeIqdLNuDJXdWX/fDStNRgYVYcfxg/z44BWDK9YhnQxUZaCdoc0faWCuZyKTAXhpfYIyKpHOjRHHFOSWV8xh4xkcL0rTx+AWTnIYwgMi4yNDRgL9MtW X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2016 15:52:12.6584 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0665 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.40.49 Subject: [Qemu-devel] [RFC PATCH v3 02/18] exec: add guest RAM read and write ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: brijesh.ksingh@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In current implementation, read and write of the guest RAM is performed using using memcpy(). This patch adds support to register a callback which can override the memcpy() with something else. This feature will be used in Secure Encrypted Virtualization (SEV) guests in which read and write of guest memory should be performed using the SEV commands. a typical usage: mem_read(uint8_t *dst, uint8_t *src, uint32_t len, MemTxAttrs *attrs); mem_write(uint8_t *dst, uint8_t *src, uint32_t len, MemTxAttrs *attrs); MemoryRegionRAMReadWriteOps ops; ops.read = mem_read; ops.write = mem_write; memory_region_init_ram(mem, NULL, "memory", size, NULL); memory_region_set_ram_debug_ops(mem, ops); Signed-off-by: Brijesh Singh --- exec.c | 55 ++++++++++++++++++++++++++++++++++++------------- include/exec/memory.h | 25 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index 4d08581..d3356cd 100644 --- a/exec.c +++ b/exec.c @@ -2751,11 +2751,13 @@ void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf, enum write_rom_type { WRITE_DATA, + READ_DATA, FLUSH_CACHE, }; -static inline void cpu_physical_memory_write_rom_internal(AddressSpace *as, - hwaddr addr, const uint8_t *buf, int len, enum write_rom_type type) +static inline void cpu_physical_memory_rw_debug_internal(AddressSpace *as, + hwaddr addr, uint8_t *buf, int len, MemTxAttrs attrs, + enum write_rom_type type) { hwaddr l; uint8_t *ptr; @@ -2769,13 +2771,33 @@ static inline void cpu_physical_memory_write_rom_internal(AddressSpace *as, if (!(memory_region_is_ram(mr) || memory_region_is_romd(mr))) { - l = memory_access_size(mr, l, addr1); + /* Pass MMIO down to address address_space_rw */ + switch (type) { + case READ_DATA: + case WRITE_DATA: + address_space_rw(as, addr, attrs, buf, l, + type == WRITE_DATA); + break; + case FLUSH_CACHE: + break; + } } else { /* ROM/RAM case */ ptr = qemu_map_ram_ptr(mr->ram_block, addr1); switch (type) { + case READ_DATA: + if (mr->ram_debug_ops) { + mr->ram_debug_ops->read(buf, ptr, l, attrs); + } else { + memcpy(buf, ptr, l); + } + break; case WRITE_DATA: - memcpy(ptr, buf, l); + if (mr->ram_debug_ops) { + mr->ram_debug_ops->write(ptr, buf, l, attrs); + } else { + memcpy(ptr, buf, l); + } invalidate_and_set_dirty(mr, addr1, l); break; case FLUSH_CACHE: @@ -2794,7 +2816,8 @@ static inline void cpu_physical_memory_write_rom_internal(AddressSpace *as, void cpu_physical_memory_write_rom(AddressSpace *as, hwaddr addr, const uint8_t *buf, int len) { - cpu_physical_memory_write_rom_internal(as, addr, buf, len, WRITE_DATA); + cpu_physical_memory_rw_debug_internal(as, addr, (uint8_t *)buf, len, + MEMTXATTRS_UNSPECIFIED, WRITE_DATA); } void cpu_flush_icache_range(hwaddr start, int len) @@ -2809,8 +2832,10 @@ void cpu_flush_icache_range(hwaddr start, int len) return; } - cpu_physical_memory_write_rom_internal(&address_space_memory, - start, NULL, len, FLUSH_CACHE); + cpu_physical_memory_rw_debug_internal(&address_space_memory, + start, NULL, len, + MEMTXATTRS_UNSPECIFIED, + FLUSH_CACHE); } typedef struct { @@ -3641,6 +3666,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, int l; hwaddr phys_addr; target_ulong page; + int type = is_write ? WRITE_DATA : READ_DATA; while (len > 0) { int asidx; @@ -3649,6 +3675,10 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, page = addr & TARGET_PAGE_MASK; phys_addr = cpu_get_phys_page_attrs_debug(cpu, page, &attrs); asidx = cpu_asidx_from_attrs(cpu, attrs); + + /* set debug attribute */ + attrs.debug = 1; + /* if no physical page mapped, return an error */ if (phys_addr == -1) return -1; @@ -3656,14 +3686,9 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, if (l > len) l = len; phys_addr += (addr & ~TARGET_PAGE_MASK); - if (is_write) { - cpu_physical_memory_write_rom(cpu->cpu_ases[asidx].as, - phys_addr, buf, l); - } else { - address_space_rw(cpu->cpu_ases[asidx].as, phys_addr, - MEMTXATTRS_UNSPECIFIED, - buf, l, 0); - } + cpu_physical_memory_rw_debug_internal(cpu->cpu_ases[asidx].as, + phys_addr, buf, l, attrs, + type); len -= l; buf += l; addr += l; diff --git a/include/exec/memory.h b/include/exec/memory.h index 79ccaab..ce389be 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -167,6 +167,18 @@ struct MemoryRegionOps { const MemoryRegionMmio old_mmio; }; +/* Memory Region RAM callback */ +typedef struct MemoryRegionRAMReadWriteOps MemoryRegionRAMReadWriteOps; + +struct MemoryRegionRAMReadWriteOps { + /* Write data into guest memory */ + int (*write) (uint8_t *dest, const uint8_t *src, + uint32_t len, MemTxAttrs attrs); + /* Read data from guest memory */ + int (*read) (uint8_t *dest, const uint8_t *src, + uint32_t len, MemTxAttrs attrs); +}; + typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps; struct MemoryRegionIOMMUOps { @@ -224,6 +236,7 @@ struct MemoryRegion { MemoryRegionIoeventfd *ioeventfds; QLIST_HEAD(, IOMMUNotifier) iommu_notify; IOMMUNotifierFlag iommu_notify_flags; + const MemoryRegionRAMReadWriteOps *ram_debug_ops; }; /** @@ -506,6 +519,18 @@ void memory_region_init_rom_device(MemoryRegion *mr, Error **errp); /** + * memory_region_set_ram_ops: Set the Read/Write ops for accessing the RAM + * + * @mr: the #MemoryRegion to be initialized + * @ops: a function that will be used to read/write @target region + */ +static inline void memory_region_set_ram_debug_ops(MemoryRegion *mr, + const MemoryRegionRAMReadWriteOps *ops) +{ + mr->ram_debug_ops = ops; +} + +/** * memory_region_init_reservation: Initialize a memory region that reserves * I/O space. *