From patchwork Tue Sep 3 16:08:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 172857 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp98364ily; Tue, 3 Sep 2019 09:43:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2zxgyQt1mo0poTCwxF0N4ThKD3rdB6x3UZ2LitQFWji13idQjW2Fo06652QnTUcJWMSfn X-Received: by 2002:a50:e691:: with SMTP id z17mr3461355edm.84.1567528996882; Tue, 03 Sep 2019 09:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567528996; cv=none; d=google.com; s=arc-20160816; b=X662vgOCKWyy9irZ89pqlnK51yyHkH3/8QWfHmQyx6wI/18N4v/ep3o38xHnBh7qup iQrw2868Rdqn1J9R3R0D1p9+w5I2qZs47N2YwWm0U3QtKRk9QqDKeeb5qLq5vY3/9jtm 1HiPQIyen/6AEIQDwZUDx1762q2LiBDZIP88gt/DaC9X4DQ9fdchQ+mOgtMWV+jY5yGC wSTSr8kphh6SIeL3grb1ldw4vwDVum1m8Ey2M1ncsNT8i34xoUEm8PyREl+FzZeY7fCp gY0qy30WWaXH3EW7z6hHT6B8qz8+30fDX0soGhFP/tXKWOZ0JvhzRpUlaD85MG25Kxkc 1waQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=4hy82QgJUYjjhSQJRivLUVd+yZYge9fg7c759/kiQtk=; b=CztJxHCLSVnYC9z05G9/v7PDvYlgOXZ6xuseI0mZcYC0y4G5LGRqw9PqRXTKTu5/Iu h5mK0VlaM7JbQYaF/xjQr0eF+pQCEY1JDGkLW5/JL/FZVZJ8tq8KLY/C+RcV9DmGYh99 CO3gaU+9CZYoNbO4E2Y8ZzO1hvSrIG5EEzlox70d20NPNsa4r3hKVO6SkQB1Nq4OQ/cM z39ImqHVLCDZSS2zY8WxsMRtjpCgMrRciQ6n1i5WXlGme7RI/BouwATgQnzoo7BA3oiI yQBBVQFRQf6GcnkOzoG+UIHy2+fHuF6dFbVNliZxBVnAQjsKjeFydIMEOJ5zxU2lHy9z fEkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BAc1hO9f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 27si5084943edz.186.2019.09.03.09.43.16 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Sep 2019 09:43:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BAc1hO9f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5Btj-0004Hu-GD for patch@linaro.org; Tue, 03 Sep 2019 12:43:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37333) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5BN4-0001PV-6x for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5BN2-0003tH-Te for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:30 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:39315) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i5BN2-0003sv-Mr for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:28 -0400 Received: by mail-pl1-x632.google.com with SMTP id bd8so1767124plb.6 for ; Tue, 03 Sep 2019 09:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4hy82QgJUYjjhSQJRivLUVd+yZYge9fg7c759/kiQtk=; b=BAc1hO9froJH+HxamFXVaI4SCfXzyOVFPo6PFjPs0jp7nyiWDttIK2ubV+kb7P6vMe ltMzs6LUQi009lBuD2KVUyn8/WF4CQhJ3Tzs5FGy1whzev8sNm5J8V1tC77APM90PEgn Srsxff8WOTRwmnaK0XrdqJSFJD9ObRkKzCE17iUvC4fC67qiVOHwDi+xUi4oZg6ECSDU XXypujcyaLIyUNgPUeIhGUkbGirlj81KyfUKnIB8A6SwoCrlNUewWbE68zzqH5tA9f2y rn5HVyBwvLA0bfAjT2CdOZ9kklxQbSX8GLIdFmY6HMa+3Cl2wud6UWpMgEfPrPjHCwLl itzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4hy82QgJUYjjhSQJRivLUVd+yZYge9fg7c759/kiQtk=; b=UxMe1HDL/wjeTQ8y9oJzqRfaOUKXGPvPDVxDk1s+zkj98EbqnmiL9lSEZSZYkEPyf7 cT5xdHlV3VjbNoQ+PrQV5+n7E/BUl6HikI8OX3mFyYyfuS+bol/25mKiQtVJ/7QpDJ5o 9Hu2MSyyc9XAxS2A1pwrWPmwgd65klH84mjrzuj8ixeGS5p3fhZaa5qhuhYrg0IOGnr8 12AeODLcxwT/Z3JvylrvNwEALmXCO5+LPJEivQOhKkH00DX6S/eT7jCvA/WD5lJic+rb u6HbF8yWZVOeSXW3BhKgkyC7ubMSVtXy1F7yCSTDl8bT6GUgehPNB2iimzdbscwDG4oZ 5QMA== X-Gm-Message-State: APjAAAWlzv4/NWI8pnHABJOht7N7PDd9Iu8QNFNxTvvI8B7mMvSqu8cT M9L9FnrQyNnKTA18aQEvyh7YoVXiskE= X-Received: by 2002:a17:902:aa02:: with SMTP id be2mr10797954plb.172.1567526966733; Tue, 03 Sep 2019 09:09:26 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id 127sm28089711pfy.56.2019.09.03.09.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 09:09:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 3 Sep 2019 09:08:43 -0700 Message-Id: <20190903160858.5296-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190903160858.5296-1-richard.henderson@linaro.org> References: <20190903160858.5296-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::632 Subject: [Qemu-devel] [PATCH 21/36] exec: Factor out core logic of check_watchpoint() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, David Hildenbrand Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We want to perform the same checks in probe_write() to trigger a cpu exit before doing any modifications. We'll have to pass a PC. Signed-off-by: David Hildenbrand Reviewed-by: Richard Henderson Message-Id: <20190823100741.9621-9-david@redhat.com> [rth: Use vaddr for len, like other watchpoint functions; Move user-only stub to static inline.] Signed-off-by: Richard Henderson --- include/hw/core/cpu.h | 7 +++++++ exec.c | 26 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 6de688059d..7bd8bed5b2 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -1091,6 +1091,11 @@ static inline void cpu_watchpoint_remove_by_ref(CPUState *cpu, static inline void cpu_watchpoint_remove_all(CPUState *cpu, int mask) { } + +static inline void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, + MemTxAttrs atr, int fl, uintptr_t ra) +{ +} #else int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len, int flags, CPUWatchpoint **watchpoint); @@ -1098,6 +1103,8 @@ int cpu_watchpoint_remove(CPUState *cpu, vaddr addr, vaddr len, int flags); void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint); void cpu_watchpoint_remove_all(CPUState *cpu, int mask); +void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, + MemTxAttrs attrs, int flags, uintptr_t ra); #endif /** diff --git a/exec.c b/exec.c index 31fb75901f..cb6f5763dc 100644 --- a/exec.c +++ b/exec.c @@ -2789,11 +2789,10 @@ static const MemoryRegionOps notdirty_mem_ops = { }; /* Generate a debug exception if a watchpoint has been hit. */ -static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags) +void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, + MemTxAttrs attrs, int flags, uintptr_t ra) { - CPUState *cpu = current_cpu; CPUClass *cc = CPU_GET_CLASS(cpu); - target_ulong vaddr; CPUWatchpoint *wp; assert(tcg_enabled()); @@ -2804,17 +2803,17 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags) cpu_interrupt(cpu, CPU_INTERRUPT_DEBUG); return; } - vaddr = (cpu->mem_io_vaddr & TARGET_PAGE_MASK) + offset; - vaddr = cc->adjust_watchpoint_address(cpu, vaddr, len); + + addr = cc->adjust_watchpoint_address(cpu, addr, len); QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { - if (cpu_watchpoint_address_matches(wp, vaddr, len) + if (cpu_watchpoint_address_matches(wp, addr, len) && (wp->flags & flags)) { if (flags == BP_MEM_READ) { wp->flags |= BP_WATCHPOINT_HIT_READ; } else { wp->flags |= BP_WATCHPOINT_HIT_WRITE; } - wp->hitaddr = vaddr; + wp->hitaddr = MAX(addr, wp->vaddr); wp->hitattrs = attrs; if (!cpu->watchpoint_hit) { if (wp->flags & BP_CPU && @@ -2829,11 +2828,14 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags) if (wp->flags & BP_STOP_BEFORE_ACCESS) { cpu->exception_index = EXCP_DEBUG; mmap_unlock(); - cpu_loop_exit(cpu); + cpu_loop_exit_restore(cpu, ra); } else { /* Force execution of one insn next time. */ cpu->cflags_next_tb = 1 | curr_cflags(); mmap_unlock(); + if (ra) { + cpu_restore_state(cpu, ra, true); + } cpu_loop_exit_noexc(cpu); } } @@ -2843,6 +2845,14 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags) } } +static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags) +{ + CPUState *cpu = current_cpu; + vaddr addr = (cpu->mem_io_vaddr & TARGET_PAGE_MASK) + offset; + + cpu_check_watchpoint(cpu, addr, len, attrs, flags, 0); +} + /* Watchpoint access routines. Watchpoints are inserted using TLB tricks, so these check for a hit then pass through to the normal out-of-line phys routines. */