From patchwork Tue May 23 04:30:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 9741905 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 9AFB560380 for ; Tue, 23 May 2017 04:46:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E1E32878F for ; Tue, 23 May 2017 04:46:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FC5328792; Tue, 23 May 2017 04:46:03 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E72692878F for ; Tue, 23 May 2017 04:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7GYTGlNJ0DNiX3TqVGBoseewKaYqsUDPxW9ex4R/HJY=; b=AUMIqu3Y8EVJb1ezAdrX1DiubD v2Uv5gjurk+atpriY/nDTRt9w0LD2ccpuHSp8EtFVLz27t7OxjG++m6PXXJJb97X3BSlviWK0GgPX gPRcqcslVnCCjF6bcTq9NBKcfQIkPh1WsbQbb4sfbFuNTac0APw+0GmaCCsSMCiywSxpx95vfwKTq w7f543SvYYAvRIn4aWm2uIgpt2sNB/E2rEjluPLbNiuLo8KBFowHaiH9XCQHRBnxBWdGyYoQE6l+v EMkR5+HYR1odObbRnwqnYcQflcx64WQoSqBl08U3XdHB2HbkF8GxRle4XPgjUo9XN1mpqSR/8z876 Uhc3IN5A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dD1hp-00021q-W6; Tue, 23 May 2017 04:46:02 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dD1ho-0001zM-NY for linux-arm-kernel@bombadil.infradead.org; Tue, 23 May 2017 04:46:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=06wP8wuPcNQR/c7qF6O5zAjN7vkWrqBCLNITvrCEtJU=; b=mMMbyqtaTHJGLkCIOnTb1XfIE E3WBVVxh10tGjdN953KVEh25jgjhAvZwPsSiHC6xf+wOx8JbyEPrWk3xgzkZrU/IQZDNMkkYAp2bo S99qTvScpE0ZOB7EWGMFfywn50Lr8MXlexrtxqtweGRVctHSuRvU762R+CV5q0TwZPsgrGWjtW4R0 1pDVY6PeMkGylORR/PHn4/PWSUQGGCDYdJz/jnXf6O+HbYEBtqrPz0YTQMUY7gmFEfXMhqvdmYz1x sm6znO5oce/y6CIdkW/zQMGN1ef/Hw/+uE7lt6+UcwRj92Df0gpuLBTSoMGxLZCPkvjJUv++D5o48 S7ZSWmlow==; Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dD1QQ-000202-Jv for linux-arm-kernel@lists.infradead.org; Tue, 23 May 2017 04:28:09 +0000 Received: by mail-pf0-x235.google.com with SMTP id n23so101762192pfb.2 for ; Mon, 22 May 2017 21:27:42 -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=06wP8wuPcNQR/c7qF6O5zAjN7vkWrqBCLNITvrCEtJU=; b=MAMN9HA/GIl7zRTpH32kJAuedrazSW2zDStJRYO/vf6As9t49UdYRsxWG9SkjGHAO6 Xp2MlG8yjXkA3vkgycQEid0JzTFeGeSGrC9yPru8mMdScEuVqtonxFEi5tUP+V5Fi41j AI43IGhbRXp/6JFu0YWWaLQhZX2K1b1HTfaak= 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=06wP8wuPcNQR/c7qF6O5zAjN7vkWrqBCLNITvrCEtJU=; b=RimChwYaQXTHCjvyNQXj6NC1YofIIcwOTFStcdiJOn9+80tiHKNBHf0QFTFxDmcI6y OwvgQyX8IoUbRpV7bj8TLhlmOqK4MdsMw+bGreCJqt25cWHSHshewft+EhyJp0wKnYYk 8UmoWB9YMmkl7abXEblZ7+1VCLh7gAWOotaHcGEfMI0iIEPlC9WWMPkbfGT9hwz4bhal YoeJ58H/iI4oI5B2onjD12NRUMihB6kTC18Nhe2lgcGt1YNIamx5u4pMXv2TYWboyctP XsD3yC8MDk9f/QVnbNWsMw4MEfp5azIbC1KCo1ax6vH7khCilTwgJAbXv8qYZgBJgSBS VwHg== X-Gm-Message-State: AODbwcDlTJFovU86+ESnEqHlaYLI8lJhu3DcUQmAKOahElVhkQdU31eH EtVcIe2H1gHB5l8U X-Received: by 10.84.229.72 with SMTP id d8mr33569988pln.159.1495513660751; Mon, 22 May 2017 21:27:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p89sm35443407pfk.67.2017.05.22.21.27.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 May 2017 21:27:40 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, jason.wessel@windriver.com Subject: [PATCH v3 4/4] kgdb: select a correct cpu while in a single stepping Date: Tue, 23 May 2017 13:30:58 +0900 Message-Id: <20170523043058.5463-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170523043058.5463-1-takahiro.akashi@linaro.org> References: <20170523043058.5463-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170523_052802_994821_7F5A4D9D X-CRM114-Status: GOOD ( 20.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kgdb-bugreport@lists.sourceforge.net, linux-arm-kernel@lists.infradead.org, AKASHI Takahiro MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When a breakpoint is set somewhere in an irq handler and it is hit almost at the same time on multiple cpus, we may see the following error from gdb in trying to do a single stepping: (gdb) si /home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty -amd64-tcwg-build/target/aarch64-linux-gnu/snapshots/binutils-gdb.git ~gdb-7.12-branch/gdb/infrun.c:5565: internal-error: int finish_step_o ver(execution_control_state*): Assertion `ecs->event_thread->control. trap_expected' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) This message indicates that, before and after a single stepping, different cpus/tasks are selected as a kgdb master in kgdb_cpu_enter (DCPU_WANT_MASTER). This issue was seen on arm64 when a breakpoint was set, for example, to gic_handle_irq. How can this happen? With the following commit, kgdb_cpu_enter() tries to "only enter on the processor that was single stepping." commit 028e7b175970 Author: Jason Wessel Date: Fri Dec 11 08:43:17 2009 -0600 kgdb: allow for cpu switch when single stepping If idle task is running when a breakpoint is hit, kgdb_info[cpu].task is set to current, pid of which is 0 (zero). (Actually 'current' has nothing to do with this breakpoint though.) Then if a few cpus are competing for becoming a kgdb master while in idle state, if (atomic_read(&kgdb_cpu_doing_single_step) != -1 && (kgdb_info[cpu].task && kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) this check will mistakenly pass and select a wrong cpu just because kgdb_info[cpu].task->pid can be equal to 0 for all of the cpus at this point. So the issue is fixed in this patch by using 'task_struct *' instead of process id to identify a targeted single-stepping cpu. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Cc: Jason Wessel --- kernel/debug/debug_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 65c0f1363788..4dd2a41c8309 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -135,7 +135,7 @@ struct task_struct *kgdb_usethread; struct task_struct *kgdb_contthread; int kgdb_single_step; -static pid_t kgdb_sstep_pid; +static struct task_struct *kgdb_sstep_thread; /* to keep track of the CPU which is doing the single stepping*/ atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1); @@ -555,7 +555,7 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs, */ if (atomic_read(&kgdb_cpu_doing_single_step) != -1 && (kgdb_info[cpu].task && - kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) { + kgdb_info[cpu].task != kgdb_sstep_thread) && --sstep_tries) { atomic_set(&kgdb_active, -1); raw_spin_unlock(&dbg_master_lock); dbg_touch_watchdogs(); @@ -658,9 +658,9 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs, if (atomic_read(&kgdb_cpu_doing_single_step) != -1) { int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step); if (kgdb_info[sstep_cpu].task) - kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid; + kgdb_sstep_thread = kgdb_info[sstep_cpu].task; else - kgdb_sstep_pid = 0; + kgdb_sstep_thread = NULL; } if (arch_kgdb_ops.correct_hw_break) arch_kgdb_ops.correct_hw_break();