From patchwork Fri Sep 5 09:47:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 4851011 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DA9BBC0338 for ; Fri, 5 Sep 2014 09:52:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EBE0920266 for ; Fri, 5 Sep 2014 09:52:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D6C720120 for ; Fri, 5 Sep 2014 09:52:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XPq8q-0001SP-6l; Fri, 05 Sep 2014 09:49:16 +0000 Received: from mail-ie0-f178.google.com ([209.85.223.178]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XPq8R-0000rK-FI for linux-arm-kernel@lists.infradead.org; Fri, 05 Sep 2014 09:48:52 +0000 Received: by mail-ie0-f178.google.com with SMTP id tp5so849585ieb.37 for ; Fri, 05 Sep 2014 02:48:30 -0700 (PDT) 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; bh=AjT+ibaCR9V8F648qDAeyo/5ZI4Z+ezQ6EunyedUORs=; b=DI7hx/qg26Q67k5HcfOTyKGQTJ3lBg8W2nQy9+EbiNYPrVGHHj99oNtDt+J0XRd0y0 juqDL6bC6IrMzUxPPxW1H4t6XzcQqDVdstfCjL0msJnKbkPSwyjuiIUHwiSxdDMxDJiJ 7D2SoFyUYAmYf0iTyF6612ws5sqbwqIU22FK6pKkH6x/zRKoLXAweGaFN6p/WaTTIE5y 7/F6ZPwIb1DMx4o9dmV4XBxypksMFnwvX0nf0ruw1PvjozDuZI+cMg4xGWusS2LUhYnN cvIG2A74EtZwYJvOA6I3Aw97kBn46FAmYjm0GlRUUrBx0/p1fexuPxV3EYizVZlOtxv2 /5DQ== X-Gm-Message-State: ALoCoQnp1Dev51ACXVis9XBGwEPn9Ctrn+IyBijSud5UvAOwGmNePERnCR/Ca3r5R6l6sg9EmSrf X-Received: by 10.70.100.227 with SMTP id fb3mr19366086pdb.137.1409910507042; Fri, 05 Sep 2014 02:48:27 -0700 (PDT) Received: from localhost.localdomain (KD182249094004.au-net.ne.jp. [182.249.94.4]) by mx.google.com with ESMTPSA id uf6sm1414077pac.16.2014.09.05.02.48.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Sep 2014 02:48:26 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com Subject: [RFC] arm64: kgdb: fix single stepping Date: Fri, 5 Sep 2014 18:47:43 +0900 Message-Id: <1409910463-30936-1-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140905_024851_549785_84CF2E3C X-CRM114-Status: GOOD ( 15.90 ) X-Spam-Score: -1.3 (-) Cc: linaro-kernel@lists.linaro.org, Vijaya.Kumar@caviumnetworks.com, linux-kernel@vger.kernel.org, AKASHI Takahiro , dsaxena@linaro.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I tried to verify kgdb in vanilla kernel on fast model, but it seems that the single stepping with kgdb doesn't work correctly since its first appearance at v3.15. On v3.15, 'stepi' command after breaking the kernel at some breakpoint steps forward to the next instruction, but the succeeding 'stepi' never goes beyond that. On v3.16, 'stepi' moves forward to the second instruction just after call of do_debug_execption() in el1_dbg, and never goes beyond that. This variance of behavior seems to come in with the following patch in v3.16: commit 2a2830703a23 ("arm64: debug: avoid accessing mdscr_el1 on fault paths where possible") I cannot deny the possibility that this migh be a bug of fast model, but this patch works for me better than vanilla, and hopefully will help you see what's happening behind this issue. Signed-off-by: AKASHI Takahiro --- arch/arm64/include/asm/assembler.h | 7 +++++++ arch/arm64/kernel/entry.S | 4 ++-- arch/arm64/kernel/kgdb.c | 15 ++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 5901480..a345973 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -87,6 +87,13 @@ 9990: .endm + .macro enable_dbg_if_not_stepping, tmp + mrs \tmp, mdscr_el1 + tbnz \tmp, #0, 9990f + enable_dbg +9990: + .endm + /* * Enable both debug exceptions and interrupts. This is likely to be * faster than two daifclr operations, since writes to this register diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index d5eb447..b882f5d 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -325,7 +325,7 @@ el1_dbg: mrs x0, far_el1 mov x2, sp // struct pt_regs bl do_debug_exception - enable_dbg + enable_dbg_if_not_stepping x2 kernel_exit 1 el1_inv: // TODO: add support for undefined instructions in kernel mode @@ -339,7 +339,7 @@ ENDPROC(el1_sync) .align 6 el1_irq: kernel_entry 1 - enable_dbg + enable_dbg_if_not_stepping x2 #ifdef CONFIG_TRACE_IRQFLAGS bl trace_hardirqs_off #endif diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index 75c9cf1..bbc085f 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -176,14 +176,6 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, * over and over again. */ kgdb_arch_update_addr(linux_regs, remcom_in_buffer); - atomic_set(&kgdb_cpu_doing_single_step, -1); - kgdb_single_step = 0; - - /* - * Received continue command, disable single step - */ - if (kernel_active_single_step()) - kernel_disable_single_step(); err = 0; break; @@ -198,13 +190,13 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, */ kgdb_arch_update_addr(linux_regs, remcom_in_buffer); atomic_set(&kgdb_cpu_doing_single_step, raw_smp_processor_id()); - kgdb_single_step = 1; /* * Enable single step handling */ if (!kernel_active_single_step()) kernel_enable_single_step(linux_regs); + err = 0; break; default: @@ -229,7 +221,12 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr) static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr) { + kernel_disable_single_step(); + kgdb_handle_exception(1, SIGTRAP, 0, regs); + + atomic_set(&kgdb_cpu_doing_single_step, -1); + return 0; }