Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp927815ybk; Wed, 13 May 2020 17:27:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxj5TSIoo2J+o91YyZP03HOunwdAeki3CfYjzmkqcVyVeQsJw803uoYQZu1prjkeyhbF4RH X-Received: by 2002:a17:906:52da:: with SMTP id w26mr1436213ejn.143.1589416044843; Wed, 13 May 2020 17:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589416044; cv=none; d=google.com; s=arc-20160816; b=B5IbZeLURI2ILpyl59okkSMHeF03NhRF0AVrcJTb2JKFLz3d7ACKLuMBU2GieiBG2v Zp9XFkujBleMOi7iPIHHgyg1NAjSTtGSG4xLK7SZNnLStQ66i9gpos0SUJWAX9KSXQw1 VDkonUfRsZ0WmQ6oYvXT4hh1A9aCnA6hQpLCmOmfUMr538L4i3P/NhLJKHcxTvvqllaS 4x0u0OS8I5PenUA+VL8ACfuJLjT9u9RAASFmjsR93MC+q049TKYJDF+I51rRxCfBcPnF CSB2IiBMNn6MMqsgKwMrVHt7e4UuquPVpUejzRO/3t7WnW9cnfKKekPGr5Er4tUxDzQE tf4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+DNHtoGN8AEBU2XRBN2d1pQMaWosnFgb+E454pWapuo=; b=zb/BdgMnfh5mCVNhc2XStlVQw/yrkjvOt3CKVPMiXso7pfO42NqjP/doJ/cRfr/q3m W2Uqy7w8BJXij0OJfT3tX6HQNm4w218xgE1sQVhuuq2KSZZaFZjuM83n1brJePaihgV5 XwCt1ULa54q0lD2MMO2gtXJtRgBOViAB1Yn/6EP7qmhhk1ShKz0BLp7KfUOC1SbUz5q6 G2XHleDmy/BIqK0VUHK75QyD0MlTJ7CTX6+MN/xqZxD7uUQc3JXXrp51T5tZgXqHE1PD 5G5lIsngfgJ4aKObFBcTWw0DKC9L6be9fr1z8/YjSCEvAW88yAXOy820Pf5LLVYfQfjU CgzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hqEKtvQG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h2si775518ejc.510.2020.05.13.17.27.02; Wed, 13 May 2020 17:27:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hqEKtvQG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733109AbgENAXg (ORCPT + 99 others); Wed, 13 May 2020 20:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1732946AbgENAXf (ORCPT ); Wed, 13 May 2020 20:23:35 -0400 Received: from mail-ua1-x944.google.com (mail-ua1-x944.google.com [IPv6:2607:f8b0:4864:20::944]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19F24C061A0C for ; Wed, 13 May 2020 17:23:34 -0700 (PDT) Received: by mail-ua1-x944.google.com with SMTP id a11so489630uah.12 for ; Wed, 13 May 2020 17:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+DNHtoGN8AEBU2XRBN2d1pQMaWosnFgb+E454pWapuo=; b=hqEKtvQG5x4boOpMaDZ44lycvpN66hkdKuNeDQ0tCjH0g5wOLUw17Dtcq+EqvLhSVd 2SOSmEn7GzfaIuaaWi1xblgxsLC0YsEBbsji3COXyd4KmUmEsQCx7nEtXWz1+SQMFtct zUz5+AuJ8JIgviULQP0sgLBVTlhkpMb8ehXPo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+DNHtoGN8AEBU2XRBN2d1pQMaWosnFgb+E454pWapuo=; b=YWPU7sz1Hb5K6CLgp0S6Wo8BeN2TTAWMxdW68S2B4GHf4ag4zLa45sEVBM7CeVvneS d63uVgzDWpzzW58jS3kggUWrCVkoXpci+54bVH6dv7OJWjJAFDQ9KgwnE+nsdNX06Zl3 w//i/VHAVkvy+0L3O/MdOdn1rJoIUt6Ah/ZQEoiwXSPiL9+zblh4PV5+BqOludCxlpHq SraHW3cdy3P5VZ8cL04vLJvecbAIUDgCCzHkeWWwmyIPPmQDrxsTtCqS21TwxjDM3wKl SmXrZr+X/YT9UD44Tc9L2oPz4wgZwHPmGDXApICYmQMhsE22rRrNkJOSXlb/SIWK4aIp S/fQ== X-Gm-Message-State: AOAM532I88o7bbzndIhXz6phXHXmuKnJYQDBoH1mivDzQqgCKUaNfIqh /EMiI/OR33d0sEeyx3U4EUiVmZpkYrY= X-Received: by 2002:a9f:31cb:: with SMTP id w11mr1984516uad.128.1589415812641; Wed, 13 May 2020 17:23:32 -0700 (PDT) Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com. [209.85.222.54]) by smtp.gmail.com with ESMTPSA id e136sm345564vsc.9.2020.05.13.17.23.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2020 17:23:31 -0700 (PDT) Received: by mail-ua1-f54.google.com with SMTP id y10so497403uao.8 for ; Wed, 13 May 2020 17:23:31 -0700 (PDT) X-Received: by 2002:ab0:69cc:: with SMTP id u12mr1898920uaq.22.1589415810804; Wed, 13 May 2020 17:23:30 -0700 (PDT) MIME-Version: 1.0 References: <20200509214159.19680-1-liwei391@huawei.com> <20200509214159.19680-5-liwei391@huawei.com> In-Reply-To: <20200509214159.19680-5-liwei391@huawei.com> From: Doug Anderson Date: Wed, 13 May 2020 17:23:19 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/4] arm64: kgdb: Set PSTATE.SS to 1 to reenable single-step To: Wei Li Cc: Daniel Thompson , Jason Wessel , Marc Zyngier , Mark Rutland , Masami Hiramatsu , David Miller , Will Deacon , Catalin Marinas , Linux ARM , LKML , liwei1412@163.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sat, May 9, 2020 at 6:49 AM Wei Li wrote: > > After fixing wrongly single-stepping into the irq handler, when we execute > single-step in kdb/kgdb, we can see only the first step can work. > > Refer to the ARM Architecture Reference Manual (ARM DDI 0487E.a) D2.12, > i think PSTATE.SS=1 should be set each step for transferring the PE to the > 'Active-not-pending' state. The problem here is PSTATE.SS=1 is not set > since the second single-step. > > After the first single-step, the PE transferes to the 'Inactive' state, > with PSTATE.SS=0 and MDSCR.SS=1, thus PSTATE.SS won't be set to 1 due to > kernel_active_single_step()=true. Then the PE transferes to the > 'Active-pending' state when ERET and returns to the debugger by step > exception. > > Before this patch: > * kdb: > Entering kdb (current=0xffff8000119d2dc0, pid 0) on processor 0 due to Keyboard Entry > [0]kdb> bp printk > Instruction(i) BP #0 at 0xffff80001014874c (printk) > is enabled addr at ffff80001014874c, hardtype=0 installed=0 > > [0]kdb> g > > / # echo h > /proc/sysrq-trigger > > Entering kdb (current=0xffff0000fa6948c0, pid 265) on processor 3 due to Breakpoint @ 0xffff80001014874c > [3]kdb> ss > > Entering kdb (current=0xffff0000fa6948c0, pid 265) on processor 3 due to SS trap @ 0xffff800010148750 > [3]kdb> ss > > Entering kdb (current=0xffff0000fa6948c0, pid 265) on processor 3 due to SS trap @ 0xffff800010148750 > [3]kdb> ss > > Entering kdb (current=0xffff0000fa6948c0, pid 265) on processor 3 due to SS trap @ 0xffff800010148750 > [3]kdb> > > * kgdb: > (gdb) target remote 127.1:23002 > Remote debugging using 127.1:23002 > arch_kgdb_breakpoint () at /home/liwei/main_code/linux/arch/arm64/include/asm/kgdb.h:21 > 21 asm ("brk %0" : : "I" (KGDB_COMPILED_DBG_BRK_IMM)); > (gdb) b printk > Breakpoint 1 at 0xffff80001014874c: file /home/liwei/main_code/linux/kernel/printk/printk.c, line 2076. > (gdb) c > Continuing. > [New Thread 277] > [Switching to Thread 276] > > Thread 171 hit Breakpoint 1, printk (fmt=0xffff8000112fc130 "\001\066sysrq: HELP : ") > at /home/liwei/main_code/linux/kernel/printk/printk.c:2076 > 2076 { > (gdb) stepi > 0xffff800010148750 2076 { > (gdb) stepi > 0xffff800010148750 2076 { > (gdb) stepi > 0xffff800010148750 2076 { > (gdb) > > After this patch: > * kdb: > Entering kdb (current=0xffff8000119d2dc0, pid 0) on processor 0 due to Keyboard Entry > [0]kdb> bp printk > Instruction(i) BP #0 at 0xffff80001014874c (printk) > is enabled addr at ffff80001014874c, hardtype=0 installed=0 > > [0]kdb> g > > / # echo h > /proc/sysrq-trigger > > Entering kdb (current=0xffff0000fa800040, pid 264) on processor 2 due to Breakpoint @ 0xffff80001014874c > [2]kdb> ss > > Entering kdb (current=0xffff0000fa800040, pid 264) on processor 2 due to SS trap @ 0xffff800010148750 > [2]kdb> ss > > Entering kdb (current=0xffff0000fa800040, pid 264) on processor 2 due to SS trap @ 0xffff800010148754 > [2]kdb> ss > > Entering kdb (current=0xffff0000fa800040, pid 264) on processor 2 due to SS trap @ 0xffff800010148758 > [2]kdb> > > * kgdb: > (gdb) target remote 127.1:23002 > Remote debugging using 127.1:23002 > arch_kgdb_breakpoint () at /home/liwei/main_code/linux/arch/arm64/include/asm/kgdb.h:21 > 21 asm ("brk %0" : : "I" (KGDB_COMPILED_DBG_BRK_IMM)); > (gdb) b printk > Breakpoint 1 at 0xffff80001014874c: file /home/liwei/main_code/linux/kernel/printk/printk.c, line 2076. > (gdb) c > Continuing. > [New Thread 281] > [New Thread 280] > [Switching to Thread 281] > > Thread 174 hit Breakpoint 1, printk (fmt=0xffff8000112fc138 "\001\066sysrq: HELP : ") > at /home/liwei/main_code/linux/kernel/printk/printk.c:2076 > 2076 { > (gdb) stepi > 0xffff800010148750 2076 { > (gdb) stepi > 2080 va_start(args, fmt); > (gdb) stepi > 0xffff800010148758 2080 va_start(args, fmt); > (gdb) > > Fixes: 44679a4f142b ("arm64: KGDB: Add step debugging support") > Signed-off-by: Wei Li > --- > arch/arm64/include/asm/debug-monitors.h | 2 ++ > arch/arm64/kernel/debug-monitors.c | 2 +- > arch/arm64/kernel/kgdb.c | 3 ++- > 3 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h > index b62469f3475b..a48b507c89ee 100644 > --- a/arch/arm64/include/asm/debug-monitors.h > +++ b/arch/arm64/include/asm/debug-monitors.h > @@ -78,6 +78,8 @@ struct step_hook { > int (*fn)(struct pt_regs *regs, unsigned int esr); > }; > > +void set_regs_spsr_ss(struct pt_regs *regs); > + > void register_user_step_hook(struct step_hook *hook); > void unregister_user_step_hook(struct step_hook *hook); > > diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c > index 25ce6b5a52d2..7a58233677de 100644 > --- a/arch/arm64/kernel/debug-monitors.c > +++ b/arch/arm64/kernel/debug-monitors.c > @@ -141,7 +141,7 @@ postcore_initcall(debug_monitors_init); > /* > * Single step API and exception handling. > */ > -static void set_regs_spsr_ss(struct pt_regs *regs) > +void set_regs_spsr_ss(struct pt_regs *regs) > { > regs->pstate |= DBG_SPSR_SS; > } > diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c > index 3910ac06c261..093ad9d2e5e6 100644 > --- a/arch/arm64/kernel/kgdb.c > +++ b/arch/arm64/kernel/kgdb.c > @@ -230,7 +230,8 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, > kernel_prepare_single_step(&per_cpu(kgdb_ss_flags, > raw_smp_processor_id()), linux_regs); > kernel_enable_single_step(linux_regs); > - } > + } else > + set_regs_spsr_ss(linux_regs); One slight nit is that my personal preference is that if one half of an "if/else" needs braces then both halves should have braces. I don't know what Catalin and Will's policies are, though. Other than that, this seems right to me. I will leave it to the Catalin and Will folks to say if they'd rather have this call made from a different place or if they're happy with where you've put it. Reviewed-by: Douglas Anderson Tested-by: Douglas Anderson