Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp419684ybk; Sat, 9 May 2020 06:54:40 -0700 (PDT) X-Google-Smtp-Source: APiQypL47Tm5dVbyW4YEEpLHvtO4/v9ZETzBzQrpRviZvVGtZo9xOpg5suYLYPjA2zDwmaAqIdSs X-Received: by 2002:a50:a7e4:: with SMTP id i91mr6156108edc.381.1589032480484; Sat, 09 May 2020 06:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589032480; cv=none; d=google.com; s=arc-20160816; b=hLR+LO9bb3o+WqbwtQDdIQxCMW1wl54EE2HPHV30gtJ3DXeFOnZNl9KGM6li6oZRq+ OasGkLz645T8gByGZzL0r0srVVzGtCKEhKGTYRswG5ziLUQGOs9V6AUVVoRKeGYXbV4l WlpTCa3zlegiSy7LBP7uWdypHjq+5uMwo7xjJyQcENxRIzmjijpiFf0Ht3a7DUd3r6XD 3K67HbEj80f3MYSsBbwFlkVA+pFuL/+B6MTFstb9przqFoIP7r7D3PAizxMbFzcSYGnZ lVtRiaA64Ymd0d/3zCprqqe6ibjzB3B/1m1oCCuq7TCrrqZvUBPrx973To/hmHI07K6o CpVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=CkapY/ZuULEcVBATtYGXO4IlsfyvTsq7AesTzzLIx9o=; b=oyx6JNZb44eaagzjMAv+1H1HX/O6nQyInUiqSgIroh/q/2wdXzejYbuFTfZTD3h81x tfKGhNapQRYgatgDO/OQJCXFARbzgDPg9yVnmZFtqBuN45fzgGcZ0O7sCz913fmqbC1M EVSiFHTTnF+jaxLmnW+LKS1mRrM+57O504Kl6u5Jv8Kp29uU3EZPGzacQhmKN5sj0ixc FDRUA/uUI+ZhHnFYs0JAhEwCseOq/Z07cxBUiMBBE7wzh7z7t6LQZJsqyCL5nGKwS4AW PSu4X/ZSGktoXI0kB0DYQBzKuz+zo5UmoF5Iq/CrsUUuJd0cbjUk159TxoyBbo+/x9nc tb4w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si2645261ejq.91.2020.05.09.06.54.17; Sat, 09 May 2020 06:54:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728056AbgEINt3 (ORCPT + 99 others); Sat, 9 May 2020 09:49:29 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54368 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727834AbgEINt3 (ORCPT ); Sat, 9 May 2020 09:49:29 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 359F62E12B047D20BB97; Sat, 9 May 2020 21:49:14 +0800 (CST) Received: from euler.huawei.com (10.175.101.6) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Sat, 9 May 2020 21:49:09 +0800 From: Wei Li To: , , , , , , , , CC: , , Subject: [PATCH 3/4] arm64: kgdb: Fix single-stepping into the irq handler wrongly Date: Sun, 10 May 2020 05:41:58 +0800 Message-ID: <20200509214159.19680-4-liwei391@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200509214159.19680-1-liwei391@huawei.com> References: <20200509214159.19680-1-liwei391@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); kernel_disable_single_step(); + } err = 0; break; @@ -221,8 +226,12 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, /* * Enable single step handling */ - if (!kernel_active_single_step()) + if (!kernel_active_single_step()) { + kernel_prepare_single_step(&per_cpu(kgdb_ss_flags, + raw_smp_processor_id()), linux_regs); kernel_enable_single_step(linux_regs); + } + err = 0; break; default: -- 2.17.1