From patchwork Tue Dec 6 14:51:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 86852 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2055328qgi; Tue, 6 Dec 2016 06:53:57 -0800 (PST) X-Received: by 10.200.37.7 with SMTP id 7mr62460993qtm.102.1481036037565; Tue, 06 Dec 2016 06:53:57 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id h94si11864899qtd.16.2016.12.06.06.53.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 06 Dec 2016 06:53:57 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60761 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEH81-00017L-7L for patch@linaro.org; Tue, 06 Dec 2016 09:53:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEH6a-0008Eg-Jm for qemu-devel@nongnu.org; Tue, 06 Dec 2016 09:52:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEH6W-0002Vd-M3 for qemu-devel@nongnu.org; Tue, 06 Dec 2016 09:52:28 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:38906) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cEH6W-0002V3-Eq for qemu-devel@nongnu.org; Tue, 06 Dec 2016 09:52:24 -0500 Received: by mail-wm0-f44.google.com with SMTP id f82so128753268wmf.1 for ; Tue, 06 Dec 2016 06:52:24 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=e96IJmjIUDHVpKh/JO78ARImiO++VPlz1Ir8/+Zw+P0=; b=GgJgy+BPifZYke7kNGcrLEhAC2WNIg40En/rL6S2UFTKpifkJBc/bH//yqjHkRPKU6 gbHkTBVTcNTeLuxSLwCjxKDxcCDWs7t1CyVdMn+Cw2mEEQtM2Dd1cbOFrWTLDEe612rr R/vXJNSr+X8s37UT2ZOLfaFKfsrc0A0sin7ms= 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:mime-version:content-transfer-encoding; bh=e96IJmjIUDHVpKh/JO78ARImiO++VPlz1Ir8/+Zw+P0=; b=FkHjVWlnSFgCWrPoa9PpWo9NpCj3Epi2WLG3rzw8CPCJmSm/jnmePwaUxSEnU14CG6 iAPdBKdCx5UI0MFwFyo3/mXBzStd/DKi+1ouq9Hly+Ijd1BnX9ftt1Np77wyxyEIqW2c OShqq5UBQksH5puP8RG3h1maZktGdES2iS+TYiSoqMZmOATZKXusdubYgLyrjHvtaRMU /m6BXdeV+yA8DZSeBAasNhaVt4i4KyR7neLSQorFqFfVfqiSY4CHZ8NQ2tqx0/a0WxJH s/hx0GoUv6OKoxO/S8xSVFtST8eztU4GJbFH+yxaNcypn/s5pCTkDSrnEq0qF/JmZFnM jLtA== X-Gm-Message-State: AKaTC004BsorN3rVIVAn8crA97iAZWIdDaWRjWaTH8M997gvpa/rhAzI8y8yEpid/AmGe2XK X-Received: by 10.28.214.133 with SMTP id n127mr3307174wmg.28.1481035883098; Tue, 06 Dec 2016 06:51:23 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 204sm4411636wmj.7.2016.12.06.06.51.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Dec 2016 06:51:22 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id BEBFE3E019C; Tue, 6 Dec 2016 14:51:21 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: 1647683@bugs.launchpad.net Date: Tue, 6 Dec 2016 14:51:04 +0000 Message-Id: <20161206145104.16048-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161206113915.26308.72810.malonedeb@wampee.canonical.com> References: <20161206113915.26308.72810.malonedeb@wampee.canonical.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.44 Subject: [Qemu-devel] [PATCH] exec.c: simplify the breakpoint invalidation logic 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@linaro.org, Peter Crosthwaite , "open list:Overall" , pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" A bug (1647683) was reported showing a crash when removing breakpoints. The reproducer was bisected to 3359baad when tb_flush was finally made thread safe. While in MTTCG the locking in breakpoint_invalidate should have prevented any problems currently tb_lock() is a NOP for system emulation. On top of it all the invalidation code was special-cased between user and system emulation which was ugly. As we now have a safe tb_flush() we might as well use that when breakpoints and added and removed. This is the same thing we do for single-stepping and as this is during debugging it isn't a major performance concern. Reported-by: Julian Brown Signed-off-by: Alex Bennée --- exec.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) -- 2.10.2 diff --git a/exec.c b/exec.c index 3d867f1..e991221 100644 --- a/exec.c +++ b/exec.c @@ -685,29 +685,6 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) } #if defined(CONFIG_USER_ONLY) -static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) -{ - mmap_lock(); - tb_lock(); - tb_invalidate_phys_page_range(pc, pc + 1, 0); - tb_unlock(); - mmap_unlock(); -} -#else -static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) -{ - MemTxAttrs attrs; - hwaddr phys = cpu_get_phys_page_attrs_debug(cpu, pc, &attrs); - int asidx = cpu_asidx_from_attrs(cpu, attrs); - if (phys != -1) { - /* Locks grabbed by tb_invalidate_phys_addr */ - tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as, - phys | (pc & ~TARGET_PAGE_MASK)); - } -} -#endif - -#if defined(CONFIG_USER_ONLY) void cpu_watchpoint_remove_all(CPUState *cpu, int mask) { @@ -839,7 +816,7 @@ int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags, QTAILQ_INSERT_TAIL(&cpu->breakpoints, bp, entry); } - breakpoint_invalidate(cpu, pc); + tb_flush(cpu); if (breakpoint) { *breakpoint = bp; @@ -855,6 +832,7 @@ int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags) QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { if (bp->pc == pc && bp->flags == flags) { cpu_breakpoint_remove_by_ref(cpu, bp); + tb_flush(cpu); return 0; } } @@ -865,9 +843,6 @@ int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags) void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint) { QTAILQ_REMOVE(&cpu->breakpoints, breakpoint, entry); - - breakpoint_invalidate(cpu, breakpoint->pc); - g_free(breakpoint); } @@ -881,6 +856,8 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask) cpu_breakpoint_remove_by_ref(cpu, bp); } } + + tb_flush(cpu); } /* enable or disable single step mode. EXCP_DEBUG is returned by the