From patchwork Wed Feb 28 21:10:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10249829 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 03ECF60211 for ; Wed, 28 Feb 2018 21:19:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E403028DBA for ; Wed, 28 Feb 2018 21:19:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6CDE28DBC; Wed, 28 Feb 2018 21:19:32 +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 1428028DBA for ; Wed, 28 Feb 2018 21:19:31 +0000 (UTC) Received: from localhost ([::1]:46992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er98M-00007K-Sg for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Feb 2018 16:19:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er908-000182-0c for qemu-devel@nongnu.org; Wed, 28 Feb 2018 16:11:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1er903-0005Qt-Oq for qemu-devel@nongnu.org; Wed, 28 Feb 2018 16:10:59 -0500 Received: from mail-dm3nam03on0050.outbound.protection.outlook.com ([104.47.41.50]:20864 helo=NAM03-DM3-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 1er903-0005Oa-Dx for qemu-devel@nongnu.org; Wed, 28 Feb 2018 16:10:55 -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=LyS0CxVns4KUGMBSQGKYy7mSSRP8LkZrSp+9K6ACTig=; b=hp5IFAZ7HcUQw4K1njlZgvhKFJMpjwJCAALu4pGeoJNGas7be/bY3HvY+2HmMGyGSah9p1yWB6XGlsNYiTdEpyTvFhwKC1XJEXl/a0d5/tXkY47NA7xXVgdjPsFi2wctcYp6LzPORhiXGCuIKTmNjerIPLAqSD3YPr+SizL6uPI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Wed, 28 Feb 2018 21:10:52 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Wed, 28 Feb 2018 15:10:02 -0600 Message-Id: <20180228211028.83970-3-brijesh.singh@amd.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180228211028.83970-1-brijesh.singh@amd.com> References: <20180228211028.83970-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR10CA0008.namprd10.prod.outlook.com (2603:10b6:4:2::18) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: acaaed56-8345-4f23-37c3-08d57eefc076 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:vOouyl3qvfh0ekXlJ7V+WEwoC59Pxhw65im+hx+D6LGL54cOgzL9wvN5uIbQz7KLSEyaw/rA5in2/pZ+RgcyBrds5ReT3EWlcCtQ10XkBQQ6qv4BrsVNFhEqsmiUhhkNA16X6yrSwWZ/Qw7Wgag+TrpR8K9fYIgu77zQRpAXCQa2a7NV1BKSLxzoZUBVhIsWDYDZyXsjsgMqd2dHccLYaxG8jjaKjvc5W5GpcX+uobaBSg3undhBpEmxJDxrSc4Q; 25:SyJsoSFs83ZwT7aZeKqojU8541vFICnh15cghRk67S0wQqP1QDZhRwq5QoYLauD+z5jUfzXTst3lHk4xUJ8VrzrcmZbBJw8bh+hMFYsuX0lI94fUkQcCUSnnzHAtSiMZjnHNPUSUZAlXwvJo6xYwb2A6g4I3cwNhfFVal8ECTURBosJuyJ6BgZHEy3W3yP3vE/mz86McVAOdSyQ/5tnsPNUbo/i9AlKN1KyrAAbC7i1wlopMLYJdPHsMQHZcZ/BGD/vsBj0ehfkdB1OvMTLMv19t1quo/ZkH51Vf0mYAtKi1TK3PYqgeA4CEmCZyuCuNFwFKOVU5EVqpUusX6432vQ==; 31:sz5JcRoad07XONOmtx66+DbeJM5Uwf3pJrTYP/lpmDQH1S7d8+SOZj96U2EYKKL9cnmWDEpZOLK79IPp8HV+9Imdp32ox6Fc/fPzSC9Y74vS3eQh/Qp6GqP1HG1WpRpmAmnF3DTDIjJs9q2COWkjfwlABIROMwHQLuKYwSj5zq3NZY/lIqSfb2M8JXfG3mk/HQz8uF5ChUR3DcI5Pt1JsR5hXCW9d6Xr/9fLFWlY0HQ= X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:EXv4URTSHb9Nt6BS9wGDntV2/ezEr45GzOyR6lXGRXCgQXBPoGzRuPewhK4EanURyN+QisyVPzNN9LDdS/A4F0m4Xejt/2OQvBAHzw/50roQdSQLbGqU1c3Hi8ei0UoKCGXAu75wbM3LdiUlHSo2xMQ3jpHyT1wrNNs1Wv5hIZ4n0nwmJC17AcdwFsaT/p9wcxo0MhAQyvUrbv3v+sRgc7rbTfrzQu4uc5W+9RbPHhy002w4mzo1yqZlExn1PJOwDE/ZrEPtmoAG7FsG6D4z4vUkSCdBOVK6uukOxHBIjaJZ4kq68HYn1P3lx8upqdbp/N0jz5C3OTMqipgFWyPAgt0OirYKWY06UFh32RLM+AHijL7hXaogGRd06d7MD2doUWpNcuE6xt6y7W3a9De5ZwAxRBtf65qE93f2PoYxZu9Fhul7+47+vnJkwnFdPesYCdKiVmO4Mu+9fwGWL3EvH+ynFwFXLUymcVn368OOZvJqFBnvFHhBWw6O6MyuXONG; 4:f4BxyHzp0fRGRqH6TznHo4rnq+DSBc/c3UfY1GIr2UvQdmdCJcp3I9n8ncDRuepO6DlrlHytI0PmqBvA+25CuJNaJ0WoYgT+tVsu4lCsNwP1nk2TaPsHgtzF+DGPm8Yfpw5z7RJcaUqhzvAd/4sG70zkdOMtyTljisgRT2a9Y5Kv/cOimXzm5apfcEBmaInGI6mi+CtA3WkxJ2wkPG3yNH4IlZGqrd5lXQGlg+SzlgzgFaNN2itnhGpMLNMu2D9Qkt6Mtxjn+SBYZRxWyPsK92ak8M+VtezWF59pdVNuqs9GEF1nzmRXkuRUcL3Paav0FnYD7i1ZQTaD/CPJlPPneA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040501)(2401047)(8121501046)(5005006)(3231220)(944501219)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041288)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:; SRVR:DM2PR12MB0155; X-Forefront-PRVS: 0597911EE1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(396003)(346002)(366004)(376002)(189003)(199004)(6486002)(6116002)(1076002)(2351001)(36756003)(16526019)(16586007)(54906003)(53416004)(26005)(53936002)(66066001)(186003)(47776003)(59450400001)(2361001)(478600001)(8666007)(316002)(81166006)(50226002)(8676002)(8936002)(386003)(106356001)(97736004)(5660300001)(2950100002)(6666003)(305945005)(4326008)(76176011)(7736002)(39060400002)(8656006)(105586002)(68736007)(50466002)(7696005)(51416003)(25786009)(48376002)(52116002)(3846002)(2906002)(86362001)(81156014)(7416002)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:wsp141597wss.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; DM2PR12MB0155; 23:zS0qmJ2iOy29CjgduG3PGbIRC//85SR5rkFuagUe6?= =?us-ascii?Q?K6KBY9+d5SUDdpbSq34ilyRKFFa+j6B6DFg8Ci3UXxj1/0bHZWDsCK+sPtpQ?= =?us-ascii?Q?LZxqsrRoiIJyHEWcPHSwGd7ba2uKR2SQ39Tv7AZNYka5enKijGqAurpZ0bYQ?= =?us-ascii?Q?1+BcJvPSgAgQZz+UJbzC5zLbYPiUMNBN0QSGKnTNjbPpaNjfZaJ3CdYZe2S7?= =?us-ascii?Q?fkSz1zahpZNHcV5cGQ0uIRBENdn2Cy5aDjjSre2uI8joVJt9Akw532U88gJ2?= =?us-ascii?Q?Y3DOBkvrm1x9b8+/rPoBJhW6OTQj5zzGjF/0pkBivHVHPtUHaxmGqjJRbbJB?= =?us-ascii?Q?U1slZMrdRZ7brtUZJhmhm4hXTD7T7Hnaujhw1PQCI4gCpVECuLDr+AzzUet5?= =?us-ascii?Q?NHICKNiLvhgDL311/sek2Y6z4ut1GQi/u1sT3HTGkXjEdTTbcdDjsHQQSDgp?= =?us-ascii?Q?wY3sFNGAzogg4Q/9udie9gHpzdvTFlqcFZ/4aaiUeYYGKxUp9sA5t6vz6MNs?= =?us-ascii?Q?aO124aE12S2SHbTYoWzx3HiDVuYOv2400XwRvGW8UsqaPyAN0HfN5kcPlVgL?= =?us-ascii?Q?EcfdeE26xdeVxBSSUrad3U5OfWN0sN8CWwjlfsDzzcHr/1PB7c/BGJQE01PO?= =?us-ascii?Q?krujRTzP+reVCLD1OSUgfd2Ajnv2OAkmotaVlUXnZSe/cQXIJq63wFsYZePo?= =?us-ascii?Q?FmTPWdO1RX98EYPwEdLEEFYmdb9KF4+B1g/fshATi1aJCZ5J02s9pjUDH57a?= =?us-ascii?Q?aDStFBv80cpElZNl3717UHYaeqhXWuDwCGkT6mnTmRZvWGocS6LUJ07fwAZI?= =?us-ascii?Q?fpkeYk8x3xhnS4/02/+G3ykbzoiYxgzx6RarBji+RL2/hRA3Bg85ztnVH92u?= =?us-ascii?Q?uUNUq6yqVshcHrttm/vxARb0rGXXtFAnExCgmSCq3eq6urVKe45+KVhbWRFl?= =?us-ascii?Q?a8x6avXjFmrNqI9SWweHzkVorQmehHYEmtbBMx2yX3IsysCj1SV1csshnSze?= =?us-ascii?Q?n1veXp81soAS8qkY9rHDQZEp+6TLV8AwXHyxkfhrbsgUXueEwKxBsa7oLQ3D?= =?us-ascii?Q?1er3M9bdtSpOtAKcf2aE+8RX+4ILI0siFm+XCUQSineI95udO+fTf+Y66Fzd?= =?us-ascii?Q?krXwtuzafkdPn7p0TzPJZquvCqVFCnVsotoVjWrPuiEhcmXinAZerAIbyWXA?= =?us-ascii?Q?q1rq9HqLBqZWHi65ZjzAAO2cOxfdcV7GupAjilOK8GfwsvCoVUMJRc4uHXU6?= =?us-ascii?Q?Q5T+lQq9XOKPwJiDpKzcohX8rMRu2b5qBvWw88m7JaBZEshCr+O8k6o11Gx6?= =?us-ascii?B?dz09?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 6:cJNWgcK3SQYUzWu8wS8Sqrhio88hH5PyoTyQgnLw5FxFgrWJlzk1DZeotCxZOgUSaIgrLYqhciOLX8B3CzJRITSWchPdKPQBQpVtDkBxrGVsqYL7TgNm7QlGleWdE+upNiUXvH4jwus8dIjdHB6/G6oOJ4lanm469Ats1f44FrMq0OZbYmo26TIwk2Z6x0nTGHIhZq2/5T2mfq9lhIdMIho36+U8UW2YSKy+QHEqSj8VBImTXGovcqpHoGqUK4P98Rz6bBUecVU40Qg5ctspK2VoyxLTH1KapJEMgpoCz0pwAIkbXu62A1dALEFiamQJtZE7vQsXAVyNiEHv5tNGhQOW+Gy6wFzhRPjATR4ZePM=; 5:hOMjQJbUMY/DkjreZaAkaRuZoetcEGwNEVMzN+9F7gMKseUiW05FmXO4VbYxqwxAz+oZAMN5pezqdKANwLOY04TTWQe4OVr/p3TYXwfUgjew3LndnIbMTyrWJwYblUzTWq7PeZRBfi76xftdV1DILuN84GrY3Aobd3+yu/wAcLY=; 24:jWvBerq0niKHim7xRF/qkXiPMBtA4JjamMS5CmZyIL6UWljgMaiNdSo1HNzZlnv5Wde5N8eQrZb5vYVLxQ+vGJVtPsz3PhJ0eAYnCwgOA+k=; 7:iywgmJmGJo4xaHoZfZj9DnfLl1GjnfRWZog71s2V43kodoJGik4XAzr90RPWhGPUx2K3yvKzeZfjjo49ZgNuopbz5oT+iHGhQ1vvPnU2h0I1913P0bCV3pFr3oX7SqZ1W3C/eqf7zZQr9Nu8psy1JuduwFjwTIea334uWdm/AvoDwVTOtXHeQwNP2u7URpoVKC8ZcXTghxLLSfIJQld9Jc2rUBGovvRrJJCm9DlETuSXoW+mBs5lrnhQWzbip0qE SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:hVzICWPS/WWsgIXh1VuDJ0jYUkUoR+krQc7vC2DWNZsG+yfLSRR2wwy5Gr2fZSTN1BoM7+8aZFdHlVP8If9vu0y6Upy6SAWSGTDujnIpiLb2M+kfkutRw8PKu/pDbH9zrTSvUZj4A8r9vyZf2y7kkK/EsiRRxvQ0uI39GD/0cZFCM6CNkT1jx6kqv/Bovybj1C73WKt1rWwt6p7138/eY6ps2SyQ27qMwRTyq9+iw2JzyjJo2Y9POnloCgPFktgO X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2018 21:10:52.6706 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: acaaed56-8345-4f23-37c3-08d57eefc076 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.41.50 Subject: [Qemu-devel] [PATCH v10 02/28] 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: Peter Maydell , Brijesh Singh , kvm@vger.kernel.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Alexander Graf , "Edgar E. Iglesias" , Markus Armbruster , Bruce Rogers , Christian Borntraeger , Marcel Apfelbaum , Borislav Petkov , Thomas Lendacky , Eduardo Habkost , Richard Henderson , "Dr. David Alan Gilbert" , Alistair Francis , Cornelia Huck , Richard Henderson , Peter Crosthwaite , Paolo Bonzini 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 | 43 ++++++++++++++++++++++++++++++++----------- include/exec/memory.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/exec.c b/exec.c index 4d8addb263a0..4408cd26c989 100644 --- a/exec.c +++ b/exec.c @@ -3054,7 +3054,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); } @@ -3152,7 +3156,11 @@ 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) { @@ -3226,7 +3234,8 @@ enum write_rom_type { }; static inline void cpu_physical_memory_write_rom_internal(AddressSpace *as, - hwaddr addr, const uint8_t *buf, int len, enum write_rom_type type) + hwaddr addr, const uint8_t *buf, int len, MemTxAttrs attrs, + enum write_rom_type type) { hwaddr l; uint8_t *ptr; @@ -3246,7 +3255,11 @@ static inline void cpu_physical_memory_write_rom_internal(AddressSpace *as, ptr = qemu_map_ram_ptr(mr->ram_block, addr1); switch (type) { 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: @@ -3265,7 +3278,9 @@ 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_write_rom_internal(as, addr, buf, len, + MEMTXATTRS_UNSPECIFIED, + WRITE_DATA); } void cpu_flush_icache_range(hwaddr start, int len) @@ -3280,8 +3295,9 @@ 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_write_rom_internal(&address_space_memory, start, NULL, + len, MEMTXATTRS_UNSPECIFIED, + FLUSH_CACHE); } typedef struct { @@ -3596,6 +3612,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 attrs to indicate memory access is from the debugger */ + attrs.debug = 1; + /* if no physical page mapped, return an error */ if (phys_addr == -1) return -1; @@ -3604,13 +3624,14 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, 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); + cpu_physical_memory_write_rom_internal(cpu->cpu_ases[asidx].as, + phys_addr, buf, l, attrs, + WRITE_DATA); } else { address_space_rw(cpu->cpu_ases[asidx].as, phys_addr, - MEMTXATTRS_UNSPECIFIED, - buf, l, 0); + attrs, buf, l, 0); } + len -= l; buf += l; addr += l; diff --git a/include/exec/memory.h b/include/exec/memory.h index 15e81113bac9..4a18bb3b38ec 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -223,6 +223,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; @@ -262,6 +274,7 @@ struct MemoryRegion { const char *name; unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; + const MemoryRegionRAMReadWriteOps *ram_debug_ops; }; struct IOMMUMemoryRegion { @@ -655,6 +668,21 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr, uint64_t size, 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. @@ -1938,7 +1966,7 @@ MemTxResult flatview_read(FlatView *fv, hwaddr addr, MemTxAttrs attrs, void *ptr; MemoryRegion *mr; - if (__builtin_constant_p(len)) { + if (__builtin_constant_p(len) && !attrs.debug) { if (len) { rcu_read_lock(); l = len;