Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp927654ybk; Wed, 13 May 2020 17:27:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRQwGc3NC5+h97uO/HPyULztIJJ3oajh4CUNs9Qd/nTGaL9kXZzKO5mdawK/MSj3NtU+1N X-Received: by 2002:a17:906:5ac1:: with SMTP id x1mr1437512ejs.303.1589416022440; Wed, 13 May 2020 17:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589416022; cv=none; d=google.com; s=arc-20160816; b=UCH6jyEJx0auagmWwDZaAX8yPkLq/llaHjMmqGeLp1S1T8kgBZrLf5qRnZvX/jXBSU 95ldG/e6Z38el8Eoob2t5p5Ux/AJdLW3YqgFYobBD+F+5ZDN1B55WzO2wJXQ1JrF5/z1 qKpiG0GTsQ2SdseE5BZY31gLq660UmgpAyuC4KJDHllil6i6s7iX7D/pNVQ3iLc1gIah Sb60TfTkiYqtLgScO7bCU/+qcIVSo4Jn3Xp8gRYzCEkKaLpn3/g2oO/sRH0b1ZdgnqaQ HfrbHETX/OZGT3kvA2yqe2Guq+a65qE1s+r3OYYPrAEQNbbN8eMCCz0qklk+M4HP+Gq3 qGCw== 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=ar6IwW9xd9CUZqFR53TmmUgiYezSnsTH5c4aEJicFwY=; b=dEfI61IQmmJIeSueM2FnrmXyPlH6ULS/p+CgRyHzOomlS+1QxPuzOOQ8wC7OoBZOQH H/v36cz6gQwFMucaSZ5mjK2+MH3PNFrcuw8/VNcJ8Rptg0C9OUis+v8iafgAc/n9MKFs tWqeE1gmxfap+RivV1OyXEn3mM09a9cB2XnKuQgUi+ToXYeJGw0oOE8MerHm70N+Ug9U cVA69/cWircjxm/J56aVlRt/ifTcef69M9nldtvQXZ56DWRQPcwPS5LsK+TyE7WvkMqL 1hnD7xHFcmGW9sFgfHnXSXk9ls+2DCtFucl5mlCsSWC+m7SVx1lQ/YqjUaJABdck61B4 2C5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Ef/7kJ1O"; 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 a10si617452edm.203.2020.05.13.17.26.38; Wed, 13 May 2020 17:27:02 -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="Ef/7kJ1O"; 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 S1733095AbgENAWN (ORCPT + 99 others); Wed, 13 May 2020 20:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1732847AbgENAWM (ORCPT ); Wed, 13 May 2020 20:22:12 -0400 Received: from mail-vs1-xe41.google.com (mail-vs1-xe41.google.com [IPv6:2607:f8b0:4864:20::e41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E424C061A0C for ; Wed, 13 May 2020 17:22:12 -0700 (PDT) Received: by mail-vs1-xe41.google.com with SMTP id v26so856494vsa.1 for ; Wed, 13 May 2020 17:22:12 -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=ar6IwW9xd9CUZqFR53TmmUgiYezSnsTH5c4aEJicFwY=; b=Ef/7kJ1OgQsBcYpqbjKZ80BhEPfGQ8T9NYpeCZF59s3/0hMpMXJml0o+s1v92bHvKY QDlxZ4CnYPvspa+kIKFiyrzrTdxHTL207udAMd/8wY3VIp6nrIh6R2lN3X1eDX2PeoVO qoJUGpC8qzQpxqEOhoWeJs6B7skgnSLpXzZKY= 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=ar6IwW9xd9CUZqFR53TmmUgiYezSnsTH5c4aEJicFwY=; b=n1SE/V8aBhLWavnZKS6qMBexVKKKE7tJ3CgJ0fc/4Wy2AMITyWG1+fReQHUDQak8XA xgIEPev+kkTGFlIJgh+wj/uDMVWELFb6FDjRH5QylzD0fM4lrSc3Nhl+ivSCzVzWLaeR n8ZVIzKsqsV7zzlSovSk6hPWLc5HIS0uhy/sgiPw1auyy/d27E9SesrI39XmMpkEAOaO dHuc6FJEvpDXToD2BjWErz1PCXcQSwN9dzwzbi5P3NUbCa/CPvTKxPx07gEqsU6TssAE Ugcsj7llC/M56v8JVk10si0AoOH4YIr/8mPm8zcbSa6A/7unYXAofUkpsiqu1itrdnHn 9PpA== X-Gm-Message-State: AOAM531y42RQQUmFn8N6+Dz8hbYGLc0V4SVk0AH36Slx8Lj1TErmTwpA CjFV/a9CuFnMz6oVPu2HgVGBfeDVG+Y= X-Received: by 2002:a67:d81b:: with SMTP id e27mr1564953vsj.40.1589415730766; Wed, 13 May 2020 17:22:10 -0700 (PDT) Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com. [209.85.217.44]) by smtp.gmail.com with ESMTPSA id v16sm340442vsq.18.2020.05.13.17.22.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2020 17:22:09 -0700 (PDT) Received: by mail-vs1-f44.google.com with SMTP id 62so963607vsi.2 for ; Wed, 13 May 2020 17:22:09 -0700 (PDT) X-Received: by 2002:a67:f5d6:: with SMTP id t22mr1506572vso.73.1589415729146; Wed, 13 May 2020 17:22:09 -0700 (PDT) MIME-Version: 1.0 References: <20200509214159.19680-1-liwei391@huawei.com> <20200509214159.19680-4-liwei391@huawei.com> In-Reply-To: <20200509214159.19680-4-liwei391@huawei.com> From: Doug Anderson Date: Wed, 13 May 2020 17:21:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/4] arm64: kgdb: Fix single-stepping into the irq handler wrongly 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 the single-step exception handling oops is fixed, when we execute > single-step in kdb/kgdb, we may see it jumps to the irq_handler (where > PSTATE.D is cleared) instead of the next instruction. > > Add the prepare and cleanup work for single-step when enabling and > disabling to maintain the PSTATE.I and PSTATE.D carefully. > > Before this patch: > * kdb: > Entering kdb (current=0xffff8000119e2dc0, pid 0) on processor 0 due to Keyboard Entry > [0]kdb> bp printk > Instruction(i) BP #0 at 0xffff8000101486cc (printk) > is enabled addr at ffff8000101486cc, hardtype=0 installed=0 > > [0]kdb> g > > / # echo h > /proc/sysrq-trigger > > Entering kdb (current=0xffff0000fada65c0, pid 267) on processor 0 due to Breakpoint @ 0xffff8000101486cc > [0]kdb> ss > > Entering kdb (current=0xffff0000fada65c0, pid 267) on processor 0 due to SS trap @ 0xffff800010082ab8 > [0]kdb> 0xffff800010082ab8 > 0xffff800010082ab8 = 0xffff800010082ab8 (el1_irq+0x78) > [0]kdb> > > 0xffff800010082ab0 <+112>: nop > 0xffff800010082ab4 <+116>: msr daifclr, #0xd > 0xffff800010082ab8 <+120>: adrp x1, 0xffff8000113a7000 > 0xffff800010082abc <+124>: ldr x1, [x1, #1408] > > * 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 0xffff8000101486cc: file /home/liwei/main_code/linux/kernel/printk/printk.c, line 2076. > (gdb) c > Continuing. > [New Thread 287] > [Switching to Thread 283] > > Thread 177 hit Breakpoint 1, printk (fmt=0xffff80001130c9d8 "\001\066sysrq: HELP : ") > at /home/liwei/main_code/linux/kernel/printk/printk.c:2076 > 2076 { > (gdb) stepi > el1_irq () at /home/liwei/main_code/linux/arch/arm64/kernel/entry.S:608 > 608 irq_handler > (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=0xffff0000fa6948c0, pid 265) on processor 0 due to Breakpoint @ 0xffff80001014874c > [0]kdb> ss > > Entering kdb (current=0xffff0000fa6948c0, pid 265) on processor 0 due to SS trap @ 0xffff800010148750 > [0]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) > > Fixes: 44679a4f142b ("arm64: KGDB: Add step debugging support") > Signed-off-by: Wei Li > --- > arch/arm64/kernel/kgdb.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c > index 1a157ca33262..3910ac06c261 100644 > --- a/arch/arm64/kernel/kgdb.c > +++ b/arch/arm64/kernel/kgdb.c > @@ -100,6 +100,8 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { > { "fpcr", 4, -1 }, > }; > > +static DEFINE_PER_CPU(unsigned long, kgdb_ss_flags); > + > char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs) > { > if (regno >= DBG_MAX_REG_NUM || regno < 0) > @@ -200,8 +202,11 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, > /* > * Received continue command, disable single step > */ > - if (kernel_active_single_step()) > + if (kernel_active_single_step()) { > + kernel_cleanup_single_step(per_cpu(kgdb_ss_flags, > + raw_smp_processor_id()), linux_regs); I don't think you need the raw_ version of smp_processor_id(), do you? -Doug