From patchwork Wed May 11 06:05:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 12845827 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 6C1CDC433F5 for ; Wed, 11 May 2022 06:07:03 +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=E5BD6TNQf7swvRB9OYWxSx+U+r8C+JLiOC4tMYjuygc=; b=HWoxK+upnSBMvM DEmVImMMEv0YMvZrUZ3lhf27Qf68DVp8CoQ6KFWo9jM7KO64BQqM8rqVTzwbeNvGcNLnHIJvUuZ32 ky2kk/MSA6YJS8089xOd/y23t/2iHlraXPZIJq80ITAg1A/9SiNbjK5h2xokE3ysTnqJPtfY+UC5N +H1VccePmkoy9znN24kaGqziL2l/zVE69wZXpXqFO+Qq6FVSDKi/E2E7V3vualkr3aM0r/BvAauKt DypzWyhujhF7u2d9rHwVniZRQicGEYdIE0txgsf9dLI9ni4xA6jKAajC5OtvEt/f5/bSW+PLCzgF8 Bt6xclFWyNW0lef6AaSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nofTx-005N8g-Tp; Wed, 11 May 2022 06:05:58 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nofTm-005N5G-Nl for linux-arm-kernel@lists.infradead.org; Wed, 11 May 2022 06:05:48 +0000 Received: by mail-pj1-x102d.google.com with SMTP id c1-20020a17090a558100b001dca2694f23so1134233pji.3 for ; Tue, 10 May 2022 23:05:44 -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=M2tMIjY53oynE5ZZlI/baO0lGZKZqD2qqN0eNb/iE2w=; b=PWhnEnJk9qvGqrSC7B+xbAQJFKIXMFzEqbX5YybccBDSFAD0JdmcVlA4aoZosIjEn6 jWruvxH1PxvP/amFuB48PZbbNr5pORQQafPTLAV5wflu7go3zAO6g7xXJwd0pUZJa1ij Qk1ooH64bNO2AbmgXsF4uDjg5H3A08W36IgEJjgSNozKEMuCXwOvZyrsk99wMmCe29uF uVwBU99akYHf+S7Ghh8jyLJhYc+txT750TY71WiD/u8RHc83zMTJGbefCmcjfvKuzfN1 4+KLv0uW/SqBrVpSfuygCQDQocWmhPikwA+9stwzEQcTHPvORve9yo5DzdMa88fdqGf4 zzHg== 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=M2tMIjY53oynE5ZZlI/baO0lGZKZqD2qqN0eNb/iE2w=; b=DJ1/1GW0vgfLC8olfGhUP0R622GNHB5kJqt9DQfWmpXS+z/0CwaNFCjfKu/nnrO9j+ vV6V0cKJJQOCKVKG0R9l4aCLqsYZoV6SpAlrttT0AeIMnvyJD75W0MNlBb24p4iEmqxp CXGLJXEdcmpMXetoTMpa/zoTLjTTwvVnADlgGVh5IpiwSslTQAoCxxSBoKF/3ultnyiF LeU877/gJsPtyu1JlTPO2C9QhlrAxyeydwE7f6Sa5S/FjWyDLr9FUvviP9I45uaQ5iII AuHtfimJNZ1sMfmALRsPB/6vILblfus4KXNHEh6C4MjJlBYzVIsT1adRP2iqLC6PAEZF 2Zdg== X-Gm-Message-State: AOAM530XVxaLJIAIxrk/Ipu68nScnYsDqgDKsyIE4FuXDkRHc4Sakqjt XUEa4X8YHlXNxzZFNh7TjWZHAA== X-Google-Smtp-Source: ABdhPJzCg92rzXG3n/bMXqch/TKUzBM6ZIxdElEeaqetBR69Pcu9FbBXio81XWJ/L3/M9y8Px6C/lg== X-Received: by 2002:a17:902:ec8c:b0:15e:a371:ad7d with SMTP id x12-20020a170902ec8c00b0015ea371ad7dmr23663232plg.12.1652249143871; Tue, 10 May 2022 23:05:43 -0700 (PDT) Received: from localhost.localdomain ([106.213.2.134]) by smtp.gmail.com with ESMTPSA id j7-20020a17090a31c700b001d960eaed66sm800216pjf.42.2022.05.10.23.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 23:05:42 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org, dianders@chromium.org, will@kernel.org, liwei391@huawei.com Cc: catalin.marinas@arm.com, mark.rutland@arm.com, mhiramat@kernel.org, jason.wessel@windriver.com, maz@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH v3 2/2] arm64: kgdb: Set PSTATE.SS to 1 to re-enable single-step Date: Wed, 11 May 2022 11:35:21 +0530 Message-Id: <20220511060521.465744-3-sumit.garg@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220511060521.465744-1-sumit.garg@linaro.org> References: <20220511060521.465744-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-20220510_230546_811079_81A4C812 X-CRM114-Status: GOOD ( 15.41 ) 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, 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 2aede780fb80..acf2196b1e9b 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: