From patchwork Thu Feb 15 15:39:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10221953 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 B2317601D7 for ; Thu, 15 Feb 2018 15:42:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A25982942B for ; Thu, 15 Feb 2018 15:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95BB029444; Thu, 15 Feb 2018 15:42:18 +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 C905F2942B for ; Thu, 15 Feb 2018 15:42:17 +0000 (UTC) Received: from localhost ([::1]:60708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emLfs-0005iq-Uw for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Feb 2018 10:42:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emLeC-00044R-5x for qemu-devel@nongnu.org; Thu, 15 Feb 2018 10:40:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emLe8-0003NS-7a for qemu-devel@nongnu.org; Thu, 15 Feb 2018 10:40:32 -0500 Received: from mail-cys01nam02on0072.outbound.protection.outlook.com ([104.47.37.72]:1882 helo=NAM02-CY1-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 1emLe7-0003NC-P0 for qemu-devel@nongnu.org; Thu, 15 Feb 2018 10:40:28 -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=nMA9ogExyOhyIA3BjSpYoH0Ie1l10nc77QqxjluBH2E=; b=Op5kjwEDgjbITOZgIU9LWQW07QLGNhl4xqealAawMir+zTOZaenTyaazQ2y5cjvF182oPTAQhRdALSD3gcHfqCyEIB7n2mBE//loc41zZ6JJE7OfAbfED9yxu/7IIlfBU4zRWsu/Dd9tcVg6s6Hfok00BpGWmu8kWurbz9Ma/BY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by SN1PR12MB0157.namprd12.prod.outlook.com (10.162.3.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Thu, 15 Feb 2018 15:40:22 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Thu, 15 Feb 2018 09:39:28 -0600 Message-Id: <20180215153955.3253-3-brijesh.singh@amd.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180215153955.3253-1-brijesh.singh@amd.com> References: <20180215153955.3253-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: CY4PR04CA0044.namprd04.prod.outlook.com (10.172.133.30) To SN1PR12MB0157.namprd12.prod.outlook.com (10.162.3.144) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e09e9e35-b97e-451d-86f1-08d5748a6dac X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:SN1PR12MB0157; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0157; 3:b3OSmMN6Y5ei9vm2RLt0O2Et8aK142YGql7HGRDdWS+kdpTNuqL3KGRSc1vfPn0M5Eo5bnhUnayCqVGTWH8YuO3XHJkV0eyRuUUFzx5pqyCzxf110hyCKUJ+yAgLC6v6gOKoqjMUYpF0eqrkqqbPjaxGu8LUVHVxowDtA+anwp8oSF1bfaUhiTUky/jP+ERIvI7GYIPZ7TMJZ+7hlh+Rdxpe3fA+eeHMEmFv7Vkjzt/SQX+IQwZVSdDPj5sEzBrS; 25:tmPAHY1XPDm2btZ0nDtaAEAoXK/B190BI8lyXVxdXL5mcTBycTOr31LD9SGDeEHjoIf6hxyZie6OZYLsJ0oy9AXa47p/D3mLH/PlP38bFtTpXUrpAaOeWdoiG852/o4WvKV1ORmLCdvXKXWcafpDPG9GY3VpPHNHIpsv+DzXCbHXtIhtd/IfYy/43Ul5H0XnonRiZ9Puc8UMrsYABHUfoAu44k5d3+67PufWDsdEEi/z2oXKaSYOpelTgh3T68LidLlQMw5B9DQjh1mP8ZNhfX+dThBUZCx9Ak2mhD7Q/NQVmDLRVvsSbjcyOKJtEA/mGszfIlnoBRo2RIdpbuBcvw==; 31:3jE8e1OwYOU5eby6ti2QmKqYezUk2GR/kKss5lBaaQDGX4KS18V7kmc81E0lxRYlomcaCNz88/bjcOMfJ097NSBwPr04o0ZJhTW0PLF8ttjoxaoValtze/q+FF+KUsrhyzPJqYfd05ccghZAwRfEXjn7ytTHggEkVImB5KuTlDEPv1fNojcxZAchMUvZimWqZg+rg+CkPcqTVw34EDAXr0lGgUj1lHTm32MbfeBJ4Oc= X-MS-TrafficTypeDiagnostic: SN1PR12MB0157: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0157; 20:oXZAf+EliSSgn1o+xtgMIqYVK4OrCHMvtQEcRRUyYfalB25VLTpoUNTyqLUbJYhUEeI+xchTvTUJ2E6fP+D4V82Uxh0hD3RL0qm2YJjov90UjTzqPBHxT/LTiJTLLQHXlKqWk5hWTtwPvSoX8gz5aWTUEurPLTnicYuRXhODa6ETkllwX7+Sct25Osdkbfv5FMm/OixT8er3H4J7wvTFEkwlU0vzKUGe2UQKqA0RBPFoI+yHKagZulLZaZT6dMBr8y8kcRuSfEzKunCBASRrDwYMxQ1O3rNLvTvZfQHS2FJkaQfwoOcZWimngcBFQr6fMC23WgUV7chBgWcta6+0ogrHHtlbsSkvqtLAEV6SQPdfq/aVuImdLWtGtGc/uVDTXcw3tmcZ2+TOoxZZ+r4Bz8Wdw+l0+BiuyQXe9o6u2ESHQzsnx18GdHWAWHTQmUrLfBi/qNIP9a3Dp6MmchVXc5u9+UGTHUWYoL8MulKvJhluu8SVC+wN4EW6VnN4OAO/; 4:3c5SS0Q4xkFN3LaT8WpUyJl75AIsMZszoI5rOI2rRTztvvf8UTzoKuBPbeA5XIR50i0YghFdOw5edsyRqRDTAPJaETOUGQhb7V3LzzkDGY4ba0aUZbmtOruEa3AnpYnrvkr01GlGoRKWylb+iLLcwcNl9kR94BOT9T942+C/B5yHhvyDH5zpmDi5vSms9e71mO09npvZ4dom06cjEd0SmdbABAF2KECn5WDLEABfM/1b5MELyI2oF3YQYCgqShr3KTFn7zL7O/1uVfuNEzG+jGAJ64Kfb/KXcpvbVNUU1KqnRzWQN3JhOo6d3UnsdJyhfPRQB1rT7jeQ5Y1Dvh+WXg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231101)(944501161)(6055026)(6041288)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:SN1PR12MB0157; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0157; X-Forefront-PRVS: 058441C12A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(39380400002)(346002)(396003)(39860400002)(366004)(189003)(199004)(26005)(3846002)(386003)(8936002)(5660300001)(186003)(16526019)(316002)(8666007)(1076002)(54906003)(6116002)(48376002)(50466002)(7416002)(478600001)(59450400001)(8676002)(68736007)(86362001)(16586007)(2906002)(50226002)(39060400002)(2351001)(6916009)(7736002)(106356001)(51416003)(8656006)(52116002)(25786009)(4326008)(97736004)(2950100002)(6486002)(2361001)(36756003)(76176011)(81166006)(53416004)(66066001)(53936002)(81156014)(47776003)(305945005)(105586002)(7696005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0157; 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; SN1PR12MB0157; 23:CDxt0YeJ6yQ/KZ+LfF0yAoPt1KXYZDHc+vcCmLy+x?= =?us-ascii?Q?wZW6rajJ0UygGfmAZqkLDz9JoTFTa7VYjL7Vr/q540La2heVPzEXYEq6DHtx?= =?us-ascii?Q?Y8GoMxtHS7y2ekc7kZlDXj1WYCdRqQzLl39WDCxIrGE542m6XzvVy0aSKnEa?= =?us-ascii?Q?7kJC3jzqPzrLcC8tDerQE220U5DRxl0tIgo05z5nq+38946tzEm7TGYLKC6G?= =?us-ascii?Q?hvNLv1c6l69g77/LBGSsE1ZGjq5uattSQUcy6nc6S1kzxkaW11rjroA7HMiE?= =?us-ascii?Q?RZSkiqNxCOpDF7UXCi3AeP4ycBoKFcHf4odHW9kQFymrt3Mi+dBy6c7PAq9j?= =?us-ascii?Q?NHc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diagnostics: 1; SN1PR12MB0157; 20:RArb5xNm+shaFv7NsiKwmDGJ40VoGw4NbH5t8/JAdTJVSd6JXFzI9UtvB15UUBYCSEzCbfuLXFOSIiSqQbLIrAAuZLDYe2I6MzS/m69oxmtMIgfZ1gsmCfsJYQLRQyWUA9Ihb7mM9xH3Qi6u6Lk9s8SDYiySs8cwGsGRkl88k1GOqQbAYFr1lxPWJbfLt1f0c6cyTT1jN9qFIofP07TPl2NOjJ9MpRc7bsyv7Cc7hvFiY322tXgaaTXaLwaLtN5R X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2018 15:40:22.0562 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e09e9e35-b97e-451d-86f1-08d5748a6dac X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0157 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.72 Subject: [Qemu-devel] [PATCH v9 02/29] 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 e8d7b335b601..b1366f85b07b 100644 --- a/exec.c +++ b/exec.c @@ -3050,7 +3050,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); } @@ -3148,7 +3152,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) { @@ -3222,7 +3230,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; @@ -3242,7 +3251,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: @@ -3261,7 +3274,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) @@ -3276,8 +3291,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 { @@ -3592,6 +3608,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; @@ -3600,13 +3620,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 fff9b1d871cc..88fd3a74f253 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 { @@ -632,6 +645,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. @@ -1915,7 +1943,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;