From patchwork Wed Jul 20 05:03:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 9238901 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 181A6602F0 for ; Wed, 20 Jul 2016 05:13:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0773120587 for ; Wed, 20 Jul 2016 05:13:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB7E7275A2; Wed, 20 Jul 2016 05:13: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=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,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 63B8620587 for ; Wed, 20 Jul 2016 05:13:18 +0000 (UTC) Received: from localhost ([::1]:60622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPjor-0000hU-9G for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Jul 2016 01:13:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42657) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPjfQ-00083N-Gz for qemu-devel@nongnu.org; Wed, 20 Jul 2016 01:03:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPjfM-0004hv-7J for qemu-devel@nongnu.org; Wed, 20 Jul 2016 01:03:31 -0400 Received: from mail-pa0-x242.google.com ([2607:f8b0:400e:c03::242]:33754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPjfL-0004hb-Sv; Wed, 20 Jul 2016 01:03:28 -0400 Received: by mail-pa0-x242.google.com with SMTP id q2so2577481pap.0; Tue, 19 Jul 2016 22:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=djqvyyDAFrMmkZ2o2JvtspsKM4YYdo0SnbNIWv0YbCU=; b=mErcruk2jDgpLNmlBEJJ2Rb6GBchjqxi6H302y5cZPIE7DqgNPSnqnQ/s3Z+0nzFk3 PKaDY4yF5saq3veJJ+lUQv8tDw2gee2lI80Y7G/xtxTDXVA78Urd3fUzftNAQi7z+mUC POUfSeV4mZLLheLLuNDQt1R8FV0iZH5ZWtAAl9XxTSYDZNG2NqQdTdh2UXec3PgKklbe svl5I6Q/X8gl95umtg++LGV6CsfnJrivUNRi6N3B8QWv0NlwtaP1MI9t/Kp0Rzlyx8aR zmWdHgYjvl/YocVsuvilLhMC5r1ZEIxoYPBYuw7jI84qjpMLCyLrwXr7rsJnPKb+fbOl kePw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=djqvyyDAFrMmkZ2o2JvtspsKM4YYdo0SnbNIWv0YbCU=; b=bbVOE6or7ul8avzZqzidra3lSV2pkRAU1ce1ofNzbsgvry4km2qmYTh0IdPwyhnyY4 7UZgfaK8G/u/GuZQsk8yykCPusO4gShhZTOK0wYvvaVnJpqe1Nbfk+uhyMssSCSFijrj eLochW/PbGsUZA8259HS3OHIUa5boVue4s+9z5AppyIky1KzjeVmceL48ldzGk6I9pcs XSAxlEIg1v7EcgoB27ZuLYDo04Umj8mA/b3ZCpHo3/PEI1hEBpz1kqU0U7och8YAC2fA jGgJqUFehpSjowGEyv3g6fCPxxSqXxkG2DX/0ZQmEs+/c3580ny5jYNxPJnXFka8vF0k laHA== X-Gm-Message-State: ALyK8tLi6DOVBQNbgqMDMqIspK0slVk6C2MLjeOjNG5awY7zWXcPowtPcKEFQl9oSPX8gw== X-Received: by 10.66.191.234 with SMTP id hb10mr29612441pac.149.1468991007080; Tue, 19 Jul 2016 22:03:27 -0700 (PDT) Received: from squirtle.localdomain.localdomain (c-73-225-163-254.hsd1.wa.comcast.net. [73.225.163.254]) by smtp.gmail.com with ESMTPSA id c66sm1031757pfd.24.2016.07.19.22.03.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 22:03:26 -0700 (PDT) From: Andrey Smirnov To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 22:03:00 -0700 Message-Id: <1468990980-4598-11-git-send-email-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468990980-4598-1-git-send-email-andrew.smirnov@gmail.com> References: <1468990980-4598-1-git-send-email-andrew.smirnov@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::242 Subject: [Qemu-devel] [PATCH v3 10/10] exec: Use address_space_rw to handle reads and wirtes 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 , kvm@vger.kernel.org, Andrey Smirnov , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use address_space_rw to handle reads and wirtes in cpu_memory_rw_debug() this way it becomes possible to modify memory mapped registers through GDB connection. Signed-off-by: Andrey Smirnov --- exec.c | 55 ++++++++++++++++++++++++++++++++++++++++--------------- gdbstub.c | 2 +- include/qom/cpu.h | 3 ++- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/exec.c b/exec.c index 5557cc9..565d494 100644 --- a/exec.c +++ b/exec.c @@ -2444,7 +2444,8 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, uint8_t *buf = b; g_assert(access_type == MEM_DATA_STORE || - access_type == MEM_DATA_LOAD); + access_type == MEM_DATA_LOAD || + access_type == MEM_DEBUG_STORE); while (len > 0) { page = addr & TARGET_PAGE_MASK; @@ -2556,7 +2557,8 @@ static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, const uint8_t *buf, int len, hwaddr addr1, - hwaddr l, MemoryRegion *mr) + hwaddr l, MemoryRegion *mr, + bool debug) { uint8_t *ptr; uint64_t val; @@ -2564,7 +2566,15 @@ static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr, bool release_lock = false; for (;;) { - if (!memory_access_is_direct(mr, true)) { + /* + * debug_direct is used to copy the semantics of + * cpu_physical_memory_write_rom() which was originally used + * to handle writes to memory with GDBStub + */ + const bool debug_direct = (debug && !(memory_region_is_ram(mr) || + memory_region_is_romd(mr))); + + if (!memory_access_is_direct(mr, true) || !debug_direct) { release_lock |= prepare_mmio_access(mr); l = memory_access_size(mr, l, addr1); /* XXX: could force current_cpu to NULL to avoid @@ -2615,8 +2625,10 @@ static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr, return result; } -MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, - const void *buf, int len) +static MemTxResult address_space_write_combined(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, + const void *buf, int len, + bool debug) { hwaddr l; hwaddr addr1; @@ -2628,11 +2640,25 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, l = len; mr = address_space_translate(as, addr, &addr1, &l, true); result = address_space_write_continue(as, addr, attrs, buf, len, - addr1, l, mr); + addr1, l, mr, debug); rcu_read_unlock(); } return result; + +} + +MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, + const void *buf, int len) +{ + return address_space_write_combined(as, addr, attrs, buf, len, false); +} + +static MemTxResult address_space_write_debug(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, + const void *buf, int len) +{ + return address_space_write_combined(as, addr, attrs, buf, len, true); } /* Called within RCU critical section. */ @@ -2734,6 +2760,8 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, return address_space_write(as, addr, attrs, buf, len); case MEM_DATA_LOAD: return address_space_read(as, addr, attrs, buf, len); + case MEM_DEBUG_STORE: + return address_space_write_debug(as, addr, attrs, buf, len); default: abort(); } @@ -3633,7 +3661,8 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, uint8_t *buf = b; g_assert(access_type == MEM_DATA_STORE || - access_type == MEM_DATA_LOAD); + access_type == MEM_DATA_LOAD || + access_type == MEM_DEBUG_STORE); while (len > 0) { int asidx; @@ -3649,14 +3678,10 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, if (l > len) l = len; phys_addr += (addr & ~TARGET_PAGE_MASK); - if (access_type == MEM_DATA_STORE) { - 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, access_type); - } + address_space_rw(cpu->cpu_ases[asidx].as, phys_addr, + MEMTXATTRS_UNSPECIFIED, + buf, l, access_type); + len -= l; buf += l; addr += l; diff --git a/gdbstub.c b/gdbstub.c index c215672..03d45f7 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -991,7 +991,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } hextomem(mem_buf, p, len); if (target_memory_rw_debug(s->g_cpu, addr, mem_buf, len, - MEM_DATA_STORE) != 0) { + MEM_DEBUG_STORE) != 0) { put_packet(s, "E14"); } else { put_packet(s, "OK"); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index b23b4b1..28e30a1 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -63,7 +63,8 @@ typedef uint64_t vaddr; typedef enum MemoryAccessType { MEM_DATA_LOAD = 0, MEM_DATA_STORE = 1, - MEM_INST_FETCH = 2 + MEM_INST_FETCH = 2, + MEM_DEBUG_STORE = 3, } MemoryAccessType; typedef struct CPUWatchpoint CPUWatchpoint;