From mboxrd@z Thu Jan 1 00:00:00 1970 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 54B5FC433EF for ; Thu, 9 Jun 2022 11:21:21 +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: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sTn8t8UksC+wRjDHTqhDiqD7zHCjLgUhpKYiTr13iYQ=; b=A6T56NqxdJ+gnM gF8GWH40Qkaln0BV7MlH5h1uU6om3r+6oK8IJXQiZdyDF5HB0dNyq/bI+1osmZQzCl4k8PtM0YkJT MpvRgKucMkSr3UMEprPo1Fl6XnNmiDiyYpxkjXjDll8+K84WPw0uwX+limZvV04FXZ1i5R5FWySeM ykVU1xg5IMy9pLYB0AWLlaY5kB0hSUhJxk0ShjHqC5yAm57hz4OuBvNfhxIjXqHAI0j6+9/PJH+Ja m/TE00v23KdHOA29vGGzVNYrSd482bq6v6NPJ/VCUW9Yj0dHggryL1pXD6E2VpRAT196xDbcYTiuN e4+3Q2nn74dUeQVbwQIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzGD6-001FW2-F8; Thu, 09 Jun 2022 11:20:20 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzGD2-001FTj-Aa; Thu, 09 Jun 2022 11:20:18 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5B61AB82C1E; Thu, 9 Jun 2022 11:20:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21495C3411B; Thu, 9 Jun 2022 11:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654773613; bh=AWv2PV1W2uMcxim/FLcbB7lfU8oERNdihwirOIiMNyo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eiTpckFO5bKFgibe9V9qAdqPM0yQ6aEUPUkc1FNt6mKmG5Ud29rc/4pL0sQuiA3Tk X57bS9wr2Zv50nG2WYpX2W66eXmDw0qmR9lx9DWtlHzGJH0VDn75KMLjEfjoA7fpBI tiAl8gH9vBpCSEAdEEuOIc3y2LLzi7kA5hcwgbXI0cyf7s96mS7WpdpdCzQ0S8RlFz SGbjUJ7fxXkgOr8M3pMSPFc38BPWSw3Hj2fBAdKifXvZ9MegicJKBrk4c3jTK0athX cgJV2xgi/fPuZqpEa9iYhIe7mRYVoJNKmTeSFwDEhuhuc9o6Qk9dQqBQpjzC3YD2X5 6mQYyXdu46+Bw== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nzGCw-00GqYl-Nc; Thu, 09 Jun 2022 12:20:10 +0100 Date: Thu, 09 Jun 2022 12:20:10 +0100 Message-ID: <87edzy3wyd.wl-maz@kernel.org> From: Marc Zyngier To: Mark-PK Tsai Cc: Catalin Marinas , Will Deacon , Matthias Brugger , , Alexandru Elisei , , , Subject: Re: [PATCH] arm64: Clear OS lock in enable_debug_monitors In-Reply-To: <20220609033322.12436-1-mark-pk.tsai@mediatek.com> References: <20220609033322.12436-1-mark-pk.tsai@mediatek.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: mark-pk.tsai@mediatek.com, catalin.marinas@arm.com, will@kernel.org, matthias.bgg@gmail.com, yj.chiang@mediatek.com, alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_042016_716200_C777D56B X-CRM114-Status: GOOD ( 32.56 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 09 Jun 2022 04:33:18 +0100, Mark-PK Tsai wrote: > > Always clear OS lock before enable debug event. > > The OS lock is clear in cpuhp ops in recent kernel, > but when the debug exception happened before it > kernel might crash because debug event enable didn't > take effect when OS lock is hold. > > Below is the use case that having this problem: > > Register kprobe in console_unlock and kernel will > panic at secondary_start_kernel on secondary core. Feels a bit extreme to do that, but hey... > > CPU: 1 PID: 0 Comm: swapper/1 Tainted: P > ... > pstate: 004001c5 (nzcv dAIF +PAN -UAO) > pc : do_undefinstr+0x5c/0x60 > lr : do_undefinstr+0x2c/0x60 > sp : ffffffc01338bc50 > pmr_save: 000000f0 > x29: ffffffc01338bc50 x28: ffffff8115e95a00 T > x27: ffffffc01258e000 x26: ffffff8115e95a00 > x25: 00000000ffffffff x24: 0000000000000000 > x23: 00000000604001c5 x22: ffffffc014015008 > x21: 000000002232f000 x20: 00000000000000f0 j > x19: ffffffc01338bc70 x18: ffffffc0132ed040 > x17: ffffffc01258eb48 x16: 0000000000000403 L& > x15: 0000000000016480 x14: ffffffc01258e000 i/ > x13: 0000000000000006 x12: 0000000000006985 > x11: 00000000d5300000 x10: 0000000000000000 > x9 : 9f6c79217a8a0400 x8 : 00000000000000c5 > x7 : 0000000000000000 x6 : ffffffc01338bc08 2T > x5 : ffffffc01338bc08 x4 : 0000000000000002 > x3 : 0000000000000000 x2 : 0000000000000004 > x1 : 0000000000000000 x0 : 0000000000000001 *q > Call trace: > do_undefinstr+0x5c/0x60 > el1_undef+0x10/0xb4 > 0xffffffc014015008 > vprintk_func+0x210/0x290 > printk+0x64/0x90 > cpuinfo_detect_icache_policy+0x80/0xe0 > __cpuinfo_store_cpu+0x150/0x160 > secondary_start_kernel+0x154/0x440 > > The root cause is that OS_LSR_EL1.OSLK is reset > to 1 on a cold reset[1] and the firmware didn't > unlock it by default. > So the core didn't go to el1_dbg as expected after > kernel_enable_single_step and eret. > > [1] https://developer.arm.com/documentation/ddi0595/2021-06/AArch64-Registers/OSLSR-EL1--OS-Lock-Status-Register?lang=en > Signed-off-by: Mark-PK Tsai > --- > arch/arm64/kernel/debug-monitors.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c > index bf9fe71589bc..186f2846d652 100644 > --- a/arch/arm64/kernel/debug-monitors.c > +++ b/arch/arm64/kernel/debug-monitors.c > @@ -70,6 +70,17 @@ static int __init early_debug_disable(char *buf) > > early_param("nodebugmon", early_debug_disable); > > +/* > + * OS lock clearing. > + */ > +static int clear_os_lock(unsigned int cpu) > +{ > + write_sysreg(0, osdlr_el1); > + write_sysreg(0, oslar_el1); > + isb(); > + return 0; > +} > + > /* > * Keep track of debug users on each core. > * The ref counts are per-cpu so we use a local_t type. > @@ -91,6 +102,7 @@ void enable_debug_monitors(enum dbg_active_el el) > enable |= DBG_MDSCR_KDE; > > if (enable && debug_enabled) { > + clear_os_lock(0); > mdscr = mdscr_read(); > mdscr |= enable; > mdscr_write(mdscr); > @@ -119,17 +131,6 @@ void disable_debug_monitors(enum dbg_active_el el) > } > NOKPROBE_SYMBOL(disable_debug_monitors); > > -/* > - * OS lock clearing. > - */ > -static int clear_os_lock(unsigned int cpu) > -{ > - write_sysreg(0, osdlr_el1); > - write_sysreg(0, oslar_el1); > - isb(); > - return 0; > -} > - > static int __init debug_monitors_init(void) > { > return cpuhp_setup_state(CPUHP_AP_ARM64_DEBUG_MONITORS_STARTING, If the OS Lock is cleared every time we enabled debug, what is the point of the notifier then? Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel