From patchwork Mon Apr 11 09:38:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 12808781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B813BC433EF for ; Mon, 11 Apr 2022 09:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=51VabpvVPnA4BbjEfjBT3Izn4fj4HGzzmBkO6LclbwE=; b=MhyDDQHH18rHOJ noe4LEXk5ppUadBdkrZIwfQY/H1fH0ZAwzF7M/k99Va51+vrgUcXkeWVbx3xTcEMdoHjnMmENWZH9 Na7JQRfOGONVSgyQDKh+ok4yBzZaMRV3LGwDiCToByBbZ5aV8NccwhCE+vVQI1RLjzZNOpYdsiad9 7/yaT2n4W0b2ZiujjGuHtY5JAAF/RuThTh/bPvHregORJiAAojCygpr7i8dHc/OcUW5EyF1HiUdrh NkghbXfHb0CgPD2Z6yRXLJP52dfEOPphy+Q8qIMjbl9H5cHHw2ci65SPQ7+uebCSETlAlg7tAb6iG WO/ToQXulEz7D6ekhunA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndqVg-007ySs-6f; Mon, 11 Apr 2022 09:39:00 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndqVS-007yO9-SP for linux-arm-kernel@lists.infradead.org; Mon, 11 Apr 2022 09:38:48 +0000 Received: by mail-pf1-x42f.google.com with SMTP id z16so14132168pfh.3 for ; Mon, 11 Apr 2022 02:38:45 -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 :mime-version:content-transfer-encoding; bh=pRxuPWbMbs8wFhTVrK8n5N1s7DUnR1sc6NHEuW/6L+8=; b=g8s7VFcKbOqu/DOejzeFd33BpWvyQsXaqxN/rrPuVMr7ZvNMm7e0a/ZZ7WoUBV673d MGPQ+BME/ylqlGu2kCjKm4xjpbbxkClpaoK/mWxTaWpTUFvZbld/T1XsKrziOWFWIKpu AS57pZ3PmFGpd2UvCZp3K552m2n/r3CrvI5IMdGKgFyVO0hYgcECzTxq4o8iX23fRh8s RXhoPLd/T9oKaShXPO669WHdB+oOG7g/yR8IRTLffmnUcsQeviq+h6R/hZrDnmf+Fq3K YJce/odBrH9SwxFB1qSbag7cEHi/1fbB3L1T0wx5rj6LRZPXI6mKIlpnp/aiotiRhYSB Zwnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pRxuPWbMbs8wFhTVrK8n5N1s7DUnR1sc6NHEuW/6L+8=; b=hyOm0pjNcwMtcIm3Cq0V8uXGv5K+Ek6/JHUcL6Mn6ithgDCQxvfmT+raxl6UpbDD+k ccbFk5xZwkr6U53PHi7m7UVipGiAv518yuyunNFfOxPlBx/z7T9Lx153weTfM27OTQYL ZLx0ulYlEB5QO2vY67+YeS2PVLrprYY1fyRtOldFsVyXp08C4PpDh2UfRkz6KgShhgmI FeGTYePjcg1oUsNFrnD5YHL+S/aXt/YLjwWBLHKJQ2dfNKGjC0UoyKjSTBEc6bgahSAA PXxyxCHCAM1VWGSYHwgLKQDcrdGNSRm0iH0F/Sj/zmLbMXIyTh5xbCw4BeTazOiYDjYS 2w2w== X-Gm-Message-State: AOAM531j2vF5aU8PMDMcqZ75XcEAXyundRFvG8w3OzgIAFZdjoL1Oe1x C3S9gfkwz3vwdmOmOVDnfwPtuDtVjiv2bnYw X-Google-Smtp-Source: ABdhPJye9XGge34NNFjlN/s6B3+vnbcVaF9KVWw5sHTCfdGHlIZlxSeDf2G7QsgO3cii2n4XzlFqrg== X-Received: by 2002:a05:6a00:10c2:b0:4fd:a140:d5a9 with SMTP id d2-20020a056a0010c200b004fda140d5a9mr31894021pfu.77.1649669925260; Mon, 11 Apr 2022 02:38:45 -0700 (PDT) Received: from localhost.localdomain ([223.177.215.72]) by smtp.gmail.com with ESMTPSA id d6-20020a056a00244600b004f701135460sm36461596pfj.146.2022.04.11.02.38.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 02:38:45 -0700 (PDT) From: Sumit Garg To: linux-arm-kernel@lists.infradead.org, dianders@chromium.org, will@kernel.org, liwei391@huawei.com Cc: catalin.marinas@arm.com, mark.rutland@arm.com, mhiramat@kernel.org, daniel.thompson@linaro.org, jason.wessel@windriver.com, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH 2/2] arm64: kgdb: Set PSTATE.SS to 1 to re-enable single-step Date: Mon, 11 Apr 2022 15:08:19 +0530 Message-Id: <20220411093819.1012583-3-sumit.garg@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220411093819.1012583-1-sumit.garg@linaro.org> References: <20220411093819.1012583-1-sumit.garg@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220411_023846_963050_FA91A6D8 X-CRM114-Status: GOOD ( 14.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: ================== Entering kdb (current=0xffff3376039f0000, pid 1) on processor 0 due to Keyboard Entry [0]kdb> [0]kdb> [0]kdb> bp write_sysrq_trigger Instruction(i) BP #0 at 0xffffa45c13d09290 (write_sysrq_trigger) is enabled addr at ffffa45c13d09290, hardtype=0 installed=0 [0]kdb> go $ echo h > /proc/sysrq-trigger Entering kdb (current=0xffff4f7e453f8000, pid 175) on processor 1 due to Breakpoint @ 0xffffad651a309290 [1]kdb> ss Entering kdb (current=0xffff4f7e453f8000, pid 175) on processor 1 due to SS trap @ 0xffffad651a309294 [1]kdb> ss Entering kdb (current=0xffff4f7e453f8000, pid 175) on processor 1 due to SS trap @ 0xffffad651a309294 [1]kdb> After this patch: ================= Entering kdb (current=0xffff6851c39f0000, pid 1) on processor 0 due to Keyboard Entry [0]kdb> bp write_sysrq_trigger Instruction(i) BP #0 at 0xffffc02d2dd09290 (write_sysrq_trigger) is enabled addr at ffffc02d2dd09290, hardtype=0 installed=0 [0]kdb> go $ echo h > /proc/sysrq-trigger Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to Breakpoint @ 0xffffc02d2dd09290 [1]kdb> ss Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to SS trap @ 0xffffc02d2dd09294 [1]kdb> ss Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to SS trap @ 0xffffc02d2dd09298 [1]kdb> ss Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to SS trap @ 0xffffc02d2dd0929c [1]kdb> Fixes: 44679a4f142b ("arm64: KGDB: Add step debugging support") Co-developed-by: Wei Li Signed-off-by: Wei Li Signed-off-by: Sumit Garg --- arch/arm64/include/asm/debug-monitors.h | 1 + arch/arm64/kernel/debug-monitors.c | 5 +++++ arch/arm64/kernel/kgdb.c | 2 ++ 3 files changed, 8 insertions(+) diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h index 00c291067e57..9e1e864d6440 100644 --- a/arch/arm64/include/asm/debug-monitors.h +++ b/arch/arm64/include/asm/debug-monitors.h @@ -104,6 +104,7 @@ void user_regs_reset_single_step(struct user_pt_regs *regs, void kernel_enable_single_step(struct pt_regs *regs); void kernel_disable_single_step(void); int kernel_active_single_step(void); +void kernel_regs_reset_single_step(struct pt_regs *regs); #ifdef CONFIG_HAVE_HW_BREAKPOINT int reinstall_suspended_bps(struct pt_regs *regs); diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index 4f3661eeb7ec..ea3f410aa385 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -438,6 +438,11 @@ int kernel_active_single_step(void) } NOKPROBE_SYMBOL(kernel_active_single_step); +void kernel_regs_reset_single_step(struct pt_regs *regs) +{ + set_regs_spsr_ss(regs); +} + /* ptrace API */ void user_enable_single_step(struct task_struct *task) { diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index 653ad0d19f2f..783484a3a831 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -252,6 +252,8 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, if (!kernel_active_single_step()) { kgdb_save_local_irqflag(linux_regs); kernel_enable_single_step(linux_regs); + } else { + kernel_regs_reset_single_step(linux_regs); } err = 0; break;