From patchwork Wed Dec 6 20:03:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10097111 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 B3D19602BF for ; Wed, 6 Dec 2017 20:25:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A32BB29C1F for ; Wed, 6 Dec 2017 20:25:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96EC829D95; Wed, 6 Dec 2017 20:25:01 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 A5D7929C1F for ; Wed, 6 Dec 2017 20:25:00 +0000 (UTC) Received: from localhost ([::1]:57641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMgFX-00038Y-Rm for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Dec 2017 15:24:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMfva-0005k7-81 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 15:04:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMfvW-0002Mh-PQ for qemu-devel@nongnu.org; Wed, 06 Dec 2017 15:04:22 -0500 Received: from mail-sn1nam01on0083.outbound.protection.outlook.com ([104.47.32.83]:38343 helo=NAM01-SN1-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 1eMfvW-0002MW-Gh for qemu-devel@nongnu.org; Wed, 06 Dec 2017 15:04:18 -0500 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=+XmUivdY8jsXQyZB+oGMmrd2yL2lnQMXfyTEpsC/XaY=; b=k/U4zSS9LuSxoIG96p3j3IuqJ1yI/yYry1IGWvetcf3A57j5i9tIsIDFSUEVxUFzfD5oHAlc8lEwsb9DiD8zo7gZr8N5TlZ288wBoFVb3bvWtwfvKKUWt0kOhS+bjLS3POqW5okVoCHbyU0hum98LQrS70VagjFCE1tIZdDWIPw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Wed, 6 Dec 2017 20:04:12 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Wed, 6 Dec 2017 14:03:25 -0600 Message-Id: <20171206200346.116537-3-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171206200346.116537-1-brijesh.singh@amd.com> References: <20171206200346.116537-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: BN6PR14CA0035.namprd14.prod.outlook.com (10.171.172.149) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3237ff97-8693-4a9a-f2dd-08d53ce48631 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603286); SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:P5qHwIUDoywioDsk6gtQWoizhJmdobuq8unlhf3gJTMmkTevfXwOyQzOBpTIrM/xXXgSdLfingtWzJ0R+0NdGEKiQ2HW8CmgJB41EchzRZhEYRRZWthmjejT+tUQ4mXgG9vniEQL7IER+PwRSLAWfGPbBcSJysex1n3AjcZMfV7pvTSnekxCP0wrQBQwhXaZ9AvzJfTy8dT6DPgzK1UUO1ee2YvWLqdu4eZSkHAYLfu/rs2dzrILxAjbxdZirlCS; 25:L0pZfmSxc/a3S1gnOlkTto/WFXGIFCot+shO/1d+QlJTh0CMyAp+8X++qQJE6XCq/LdXdIy/tCGupzeTDFQjBycpsk6Eel0mOv5t9EBJKTJHiCdsI6kou3St28ukXLgi3IZ2ry/H4arozjhfeZrOhUAK9C8YNDse45zoGCRdJ9vD+zCMCUjXOqdG2z3McRqPeLhFhb3Km1DdSyC2rAraLHif7ARJMt+xDBBJrYDmAbmlva8btRDPHUB8IKhIz5Kc2cSzKm4RR6I25vr1exs3aj/DUUOitl+vfGi4R0nYPOFQljT3sm/QCQxzPbhPOi8xwd8qmhmUCPBIx5u851xBWQ==; 31:Lkrpl6Im67UUxaiN9IOQyS/4/smzieSwZN6ePReKZxdOl9NyDtzzNnn8oynwiJfMnjeQjvAHTfXFkTOtrCgijhJNPjPaw01yeA4edXlpD0G1yhg99YKbq2evpnCCgGhAe27ec/HUR1pw4G8ZVx0uHNZdRyrNi2+caHqSD2vocIR+gwHXRBWlH6rAU+y16X4PVPaxl+K3h+NrTX3QGHQb6ChMEqaN46qmEr79GjY01JE= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:r6AHCNvolh64QEsaoVr2E1VCHaPsDBmH+LuR1wm2OymGmQa58w/tQucKKH8lpRZCc55mKE2SRw8qFJbAydaz8BgGTTLq+SPkWt/wsM6eh2Xgi2tB7Kz7kMLKaUBnECPvA+WGcSPcaIb3vviwDj+eq/lXG/rLQMQq3i0qy7hLo6EA8eCfoB8VNB5nud+9eRWGaSIac9gPIB1VwU614wQekN47xyxfa2Is3oaU/4b+q84bBJcQDYXSzspUhyjXRmox37XVhJyKZSYjQIvr2TMi4ba1MzHzS7VX3rlsnd89IhFD4T0r7rzCX4sW3dr9QI7Ng3vuNjuQyL/ji4WLDREBKUMjtE4ffWwg3CuYhhurtU8MpODOz36LqW3qZHOprvPf4NtXSMLIRwWfmCAAwZzy+zZGBGelIQmKcJ+WTfiaBXto2ibygxmL5JzMqKW5hCF+lD1MWWtP5gEKfnzK86bTJs/fdjmGsyHMXfcGd1ZSbSN5T8DgxAhuEG7rjcVVah/G; 4:RzgGTqWSbv0Bn/9Dy1gPO3VxriVQW1Pfgc/OuNFtQux3W56lw+LXwJpI5Y7ObAbjK+SvxTdcK9eZrB9blpVRXYdnTJ1BS4TzRA2yfgufsZkDEeLukCfytSH+rlLyaoMWo5uKPVUMcWC9xmsSR/gEce+wZSNBYN9vYubQ2aDZydSziBRF32gK6Mkqpux69xZXCorskSGwRQcfeRoXovEr5DSw/Ti38fYx/WgSSBtqVxWRLGYlXh22aW0DUyCc6ixUuIfjTeHbZXYCqoLFVnIwk6mGV784wPpkTvjJvecG6LoqKcZ5ZtnGn4owUkaJRM46 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231022)(6055026)(6041248)(20161123555025)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(6072148)(201708071742011); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 05134F8B4F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(39860400002)(346002)(366004)(199004)(189003)(16526018)(16586007)(33646002)(53416004)(105586002)(39060400002)(4326008)(305945005)(2351001)(106356001)(2361001)(7736002)(7696005)(86362001)(52116002)(8936002)(316002)(575784001)(53936002)(97736004)(76176011)(51416003)(36756003)(66066001)(1076002)(3846002)(25786009)(6116002)(47776003)(50226002)(68736007)(54906003)(6916009)(2950100002)(478600001)(6666003)(8666007)(5660300001)(8656006)(8676002)(101416001)(81156014)(81166006)(2906002)(7416002)(48376002)(6486002)(50466002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:wsp141597wss.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0158; 23:IlaaZzQOC0R+4771UYhA/436JJTf2sLRjJv434zda?= =?us-ascii?Q?FLKI0vw47mj+9bmKkUZc7IahKZUCFSjNC2S9qlxTInTVVx0pHP9Ho0jFDdo4?= =?us-ascii?Q?XP3WVf3Rn9Ta3dzsQLS1UG2pUAZtWi3m1hEWSx7gbHGV+EPP1+QnvS+Nkg85?= =?us-ascii?Q?NeAqkFFn7wQRDtnzD3GyEpf0Wmo/6DF3pbMwMZXIpJhTwFPfSqvhcmEJWWy6?= =?us-ascii?Q?twp64XnQF3zVJffZ30/3sKXHunRWvbfS6oIWqbOQlQaQVNdmcYx5nKGitGl6?= =?us-ascii?Q?+tYQNCTJwFXEDrzVOk7h3Q3ez7B+d02AWEVF73oRZEQmBbm9Az1wuIzwZY8O?= =?us-ascii?Q?pPv7ecVtdqwI3JhgMsZcaVnun2Wn29cVjBe75XPugOaL6MfIg7S99wKSw+eS?= =?us-ascii?Q?C2/V/DOwJtu+E3/PvLl05vtVWM9mjC9AN3f0jzuua0eaXtO0lbP55IakxW4+?= =?us-ascii?Q?gB5fcto4b6qTBUOtcjR/GiynMt3KAsoZpmTLdUFFWHTk+hBY48bf4XGE8odC?= =?us-ascii?Q?pTRBxAalkreTn/lmiz+MfcPPwX9kdhRnDF9hjQsAbvERKO3EIrXY8LwCtTPm?= =?us-ascii?Q?Mq4N9yFveFMZYMvMA6eb/Ds6YQyzOFUCdfX4I+3Cp4d046Gfa15wYO2Jw1yh?= =?us-ascii?Q?lbGhe9jW+M18FlYWDvdtl2qEIinNmcrkLWGmdS701kqeAQDHGH7uLZ0yEGLc?= =?us-ascii?Q?4HG8xe9+xHJIQyqsHOBrMUrgFiRZiQCRaaH5d1nljNwoeovIU+mSVFt8b1jT?= =?us-ascii?Q?7m+QMiboI1E6sWI4Es0IRr/t7p9dfQjnZH2pFol4CYLBBsawAw1uBlP7D7hQ?= =?us-ascii?Q?DzLbkCFHP1ga7eKV5IY+D8uuUPFRqWQQnkm7grnkz/PH0XrN8nDL7Zbi1YXF?= =?us-ascii?Q?kOHdNprceeydY7tLoDmDdDJykN/ALtTH1emIMh7mFtljB6MP2jbA934Ml80f?= =?us-ascii?Q?o3x/+z9u7vUoEp0srDVnXu5YGaZB/gv3DMNjq1ut2H5cMoidwPvyryYlVSaE?= =?us-ascii?Q?7y6zKdKwpxjBp5ZmEK5vwZeI08hmwrfWW4EBGV8mmQ1/Z87JSHEDjTVAmdRA?= =?us-ascii?Q?gm++9AylcIadzPawoobsnJ7af71BG3s3301DdXvvG0sulIRiogPq1Q3/NIK5?= =?us-ascii?Q?Oc4gMlQ/QXs5aF6cB01/pBvn4bJaYktKnNiX4QWhxwGSMIXqg7W16nLoTYUw?= =?us-ascii?Q?Dcflh9ucWCac6iM1ZlNHLiXS+Sg5oU8bxvPmtyUYl+NdX0lSVWEJP/V08fUk?= =?us-ascii?Q?rGbCSduw53Ny7cBulI=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 6:RQVqZu9tSllxXoLOnLzNn5+6pNztiUxkVxXOnpOYUjnOh2ygu+2q2Bj6c0/MsOi1Xqixm1cqDddxGuw0UhrWW+uS53FHE7vhP4dfk77RbSwNZcSPG+GmQ/P/sSA8kNYaNK5aCbAyNc1xMgdlJYH2y9yFcVz8+OoytbJgg2Brr79Q/8PY8gPD1PioDsRb94yx2S4Pm+xduhqI06cPfZp/M/Qg5iiKtkEDtcx9tX7Z5F2wFLaTfqw6/K5d+2wsiI7ShlxCpmTYK7l0cbeB/rZNhRzXBpTphf8lmMw3LhELutRKJp44E7Q6goPHBj/zdZFbueegisVekK6yLz5ppT2bIsMrNpKa6QNfWIUPuWGycx0=; 5:k4R9kilYVXB+0OVBtZiOA7Ic8oC8jHTgNneUTrq5+WAt5kXyW2mYjhJI6/gtv8J3H/mJO+UPxEyohy6W53f4KS9OMWZxKzIv8RsfjESX9nHhXxirEP2Uq5vHFabS6HPOLIno1iVDMzYXRaGr+jOfKTfciK/8KAXHY+9vqwRHwcQ=; 24:3Xr/z0p77vyjRm+olSUNVHxsmQjjCIvZ5EsHVVnsskZm/EHV8ZheHKA2evqNYjHMws6gIg1p8rE870sDVo9QddXbJw7c1xc6OURWLXiZg5Q=; 7:d17V8BzptarzJjQzi3x7TxjOfHBEGJFeG/TS2hPhBOydiPZ/CZevOUkUNeSrWhybMZJeVRGSd3Vy4b712i9UfNOke1i6bPczLy1iCuao5DJejgLrwSw51RHjEBtD/Sqd2YVI5XN3BhqfGzKhbDwGE+0+04yQmKHH99AJCNltYbVnxW2T41xrVkNvw0AsaVaRs2X0vkB7VYLKzMOH0ej68McYDSPQJEJEhPsTketOCSECXM4Gce0mFDXlqVKWB4cr SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:LHaDWX5Eq3LCCCkuQ+DCpqNndrU9kgd+7oyGmpYTkkd7agPjLX0qz+KqvFvl0klfj6Z0S9tADD08HtMvHRjyBbrXV2lLucq6+F8iCJJtVZ/gHkPNjBnSN1vE1OWVVoyQxQBn4f4IoM+p9ZTppHLRxEM+6A6U9foEFu+1/0/USmtWRZHNJRfxMcIfPBfLtU1Y3LbhXmXC/1x1cyltYzRvTmVvntJiIYBc0dB2xpTVLDkWtFaqM3vBzwE7PI3JE1m9 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2017 20:04:12.7392 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3237ff97-8693-4a9a-f2dd-08d53ce48631 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.32.83 Subject: [Qemu-devel] [PATCH v5 02/23] exec: add ram_debug_ops support 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: "Edgar E . Iglesias " , Peter Maydell , Peter Crosthwaite , Eduardo Habkost , kvm@vger.kernel.org, Marcel Apfelbaum , Markus Armbruster , "Michael S. Tsirkin" , Richard Henderson , "Dr. David Alan Gilbert" , Alistair Francis , Christian Borntraeger , Brijesh Singh , Stefan Hajnoczi , Cornelia Huck , Paolo Bonzini , Thomas Lendacky , Borislav Petkov , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, the guest memory access for the debug purpose is performed using the memcpy(). Lets extend the 'struct MemoryRegion' to include ram_debug_ops callbacks. The ram_debug_ops can be used to override memcpy() with something else. The feature can be used by encrypted guest -- which can register callbacks to override memcpy() with memory encryption/decryption APIs. 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); Cc: Paolo Bonzini Cc: Peter Crosthwaite Cc: Richard Henderson Signed-off-by: Brijesh Singh --- exec.c | 65 ++++++++++++++++++++++++++++++++++++++------------- include/exec/memory.h | 27 +++++++++++++++++++++ 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/exec.c b/exec.c index 03238a3449d9..9b0ab1648945 100644 --- a/exec.c +++ b/exec.c @@ -2981,7 +2981,11 @@ static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, } else { /* RAM case */ ptr = qemu_ram_ptr_length(mr->ram_block, addr1, &l, false); - memcpy(ptr, buf, l); + if (attrs.debug && 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); } @@ -3079,7 +3083,10 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, } else { /* RAM case */ ptr = qemu_ram_ptr_length(mr->ram_block, addr1, &l, false); - memcpy(buf, ptr, l); + if (attrs.debug && mr->ram_debug_ops) + mr->ram_debug_ops->read(buf, ptr, l, attrs); + else + memcpy(buf, ptr, l); } if (release_lock) { @@ -3149,11 +3156,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; @@ -3168,12 +3177,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, addr1, 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: @@ -3192,7 +3222,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) @@ -3207,8 +3238,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 { @@ -3514,6 +3547,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; cpu_synchronize_state(cpu); while (len > 0) { @@ -3523,6 +3557,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; @@ -3530,14 +3568,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 5ed4042f877d..546a67bf0dac 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -215,6 +215,18 @@ typedef struct IOMMUMemoryRegionClass { typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; +/* Memory Region RAM debug 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); +}; + struct MemoryRegion { Object parent_obj; @@ -254,6 +266,7 @@ struct MemoryRegion { const char *name; unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; + const MemoryRegionRAMReadWriteOps *ram_debug_ops; }; struct IOMMUMemoryRegion { @@ -621,6 +634,20 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr, Error **errp); /** + * memory_region_set_ram_debug_ops: Set debug access ops for a given memory region + * + * @mr: the #MemoryRegion to be initialized + * @ops: a function that will be used for when accessing @target region during + * debug + */ +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. *