From patchwork Thu Dec 15 14:29:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 13074264 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 4D30BC4332F for ; Thu, 15 Dec 2022 14:30:56 +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=Si8fBL/357b+JWX2E51tD+D9YPkNLvPyqRg38pz/Es0=; b=OENcxqRpkvKyQO 206kLFwyXvykbVWU1rYY8TePUTc7R+XjSqKNlWB597S0G5hX/GWsN/KhajGzXlMRCzobT2CZEj2KK zqdPrZm6FA07uvQxuMSq9Oai/uK1S2ihU+zhcqUQoi3x3s2GQiKOJ/xnqsTwbB75SgdQwgu2lNhh5 ydkKluAp3pm+oWhFz8h/6OHBjib+xQe05ec/xZ3fF2nGL4Rup7+3OBXGcsmpAVbGjoap4Lh1qKqRM GPDW8tvKcftpC7h6BdeovJ1BdLCz6jr+x0oY12jzGzigbW0ecboMMrirZI0QSBi8hsgBQWuZdDnWp yWvAsTmikVTlxqadMI0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p5pF7-009oYd-OP; Thu, 15 Dec 2022 14:29:49 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p5pEr-009oU3-Vf for linux-arm-kernel@lists.infradead.org; Thu, 15 Dec 2022 14:29:35 +0000 Received: by mail-pj1-x1030.google.com with SMTP id z8-20020a17090abd8800b00219ed30ce47so2897865pjr.3 for ; Thu, 15 Dec 2022 06:29:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FuxPSSo3Y0HNcsTRiv4LvjgP5Z2vwZbV6xJtY/KrG9Q=; b=GH+o3xGpbeSkSiHU4ZhFMZ9jkmwSgjEShmS+hkyC7LNuC+FLDPkFdCt39W2pFj3AEq 3As93RhfetUr/a7+HyILd1yr1jzNA4jL3g65bSUssPV3DXNsyRiz7MB4Q1IZMNyHQdX0 KdKsXm+wpuXZumoARgb0dOpHO6JxWQXv3nabufiTcvvLq6C/KV29jIjx6SzomLlD3CiL cdoIvLW6MjHKI32o3jL/M6+DbJaMmhAHE3iNhv8LQxF0tqxqQJjUq/W3D0jzhC0oKL1F tjpZFM6Dv21s0Dp9a6xoJGxJmlCzbNMtmDDN3LEC4KyS+J3XtdDbTB03jQdaw5kLlIce EKjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FuxPSSo3Y0HNcsTRiv4LvjgP5Z2vwZbV6xJtY/KrG9Q=; b=fudhRkUuQAfhS2kVElvGKPKpabAhHz+q65HDYXOYUENcPDPxkyBtnSCcF/uRHSEcpz DZH97MKz5muC/1KmAS5wHX1K1ZLyMrWr0MDQX9PRye0hPh9Zi/5hn9RZTzZiWeQ6PFuQ CIzgaKGF8Lqmijp7OfmJkQCudgA0JObY4IVX3yN/zGObQu1V4/R1xDtF7V5yhn19BkQN jYvOjrSEpMhe+Ti66BAyMYyqUFR9uOs0k5X3XvbGBzcJdFunOsaJC8I2KCrYFskuVmPP YY4xtsngq6+xfiiSenEJaCYpv+aeY9UbfZMB9FIq/wwetwIxHjrTLE3JeWT3nteJX8qS 1ZPw== X-Gm-Message-State: ANoB5plT7H1RyWCyjujTuiYvreQuxxYT2krpRaEWU7f8u1kXADr37YVo Xhxk+53iTbNYmkkNoeZwrmM9ig== X-Google-Smtp-Source: AA0mqf6Fe2RSsBxw7IoI8CLHsSgyH2bi7UGfEUMoabxqwYlOQ8jx9uJ48AQ0FQtFljyOfs1EiF8dQA== X-Received: by 2002:a17:903:251:b0:189:7891:574d with SMTP id j17-20020a170903025100b001897891574dmr32757233plh.47.1671114566259; Thu, 15 Dec 2022 06:29:26 -0800 (PST) Received: from sumit-X1.. ([223.178.208.45]) by smtp.gmail.com with ESMTPSA id z1-20020a170902d54100b0017f5ad327casm3922010plf.103.2022.12.15.06.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 06:29:25 -0800 (PST) From: Sumit Garg To: will@kernel.org, catalin.marinas@arm.com, daniel.thompson@linaro.org, dianders@chromium.org Cc: liwei391@huawei.com, mark.rutland@arm.com, mhiramat@kernel.org, maz@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH v4 2/2] arm64: kgdb: Set PSTATE.SS to 1 to re-enable single-step Date: Thu, 15 Dec 2022 19:59:03 +0530 Message-Id: <20221215142903.2624142-3-sumit.garg@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221215142903.2624142-1-sumit.garg@linaro.org> References: <20221215142903.2624142-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-20221215_062934_048823_7E388562 X-CRM114-Status: GOOD ( 14.00 ) 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 Currently only the first attempt to single-step has any effect. After that all further stepping remains "stuck" at the same program counter value. Refer to the ARM Architecture Reference Manual (ARM DDI 0487E.a) D2.12, PSTATE.SS=1 should be set at each step before 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 Tested-by: Douglas Anderson --- 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 7b7e05c02691..ce3875ad5cd3 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 3da09778267e..9af898b22ed4 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 cda9c1e9864f..51f204bbcf87 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -224,6 +224,8 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, */ if (!kernel_active_single_step()) kernel_enable_single_step(linux_regs); + else + kernel_regs_reset_single_step(linux_regs); err = 0; break; default: