Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2409993ybb; Mon, 30 Mar 2020 05:40:24 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvGUIhltO3OlBylEl0YT4BB9cLcQ7ICVVcleBrufGXQclAU8Fz46KViYSFVMHe3fM+JPde2 X-Received: by 2002:a4a:8041:: with SMTP id y1mr9130003oof.65.1585572023750; Mon, 30 Mar 2020 05:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585572023; cv=none; d=google.com; s=arc-20160816; b=hhgvrjkWPoe8+fymLqePC6YC96F8uTweBgOSqF8VXL9EuCXc85Rnvc9kJ+0iQjjKZV CrFbrq+IAiMtGAbFEIlza5bvlKdm39fg4rjhOShFr0KIHrrdzS4POBrRMe1aNtHAxL/S T9C8+oomyFamdFbernnQo2TQNFsohBLgqhW0wBpuUcbVxz5/TpyTNyMQtFBIg80fuO2D d36DuS2vYGSEuynhj2wnqyrKIeYztNfr7RL9v+BE7xeB2I21Hrf4gVNje5sYBz00+RS7 bbFKDqQNth7zR5XCjimVUAWTT3+esOaECbfobGV81P6QVnY3bkW327JUnHu8VJEHILU2 PISQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ogq0/xLSNLvVu0OOf37tl6ONw8EhXAIGCF0pwTguHv8=; b=oFofqaZ187DBLGGfITUTFSoS7oW4piOlJkUiSBwcT7LJjCsF+wVOyrZsZ7HjBrbusK yZvCjdGXrQx3RZNF0Oq7xqhpQyCsUVrj8W36rdmvqAiurWcbr6elOf+RNlgf5pNdgciW S3KtJXqrZconGBx77OjUQ04yJZ3wRhC9ArvXJRUso9ZZdle6qzGGvibrHTpbZSVS5cWp mERTm1yEZJ9xyIp0CSegPpgHO9pFgCt04zI62e7MiJjvC68fIWmzkHbmtTUIwvwbNjQ2 uL42WNEUFEvzGxsISel1E7WkYjcWQg0LK0EUdGOeY7UU529WsCRC4dSMvo/KeqEE86ph WnYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a69si5877463oib.90.2020.03.30.05.40.11; Mon, 30 Mar 2020 05:40:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730211AbgC3Mjv (ORCPT + 99 others); Mon, 30 Mar 2020 08:39:51 -0400 Received: from foss.arm.com ([217.140.110.172]:52634 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730064AbgC3Mjv (ORCPT ); Mon, 30 Mar 2020 08:39:51 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D43B30E; Mon, 30 Mar 2020 05:39:50 -0700 (PDT) Received: from C02TD0UTHF1T.local (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E6E203F68F; Mon, 30 Mar 2020 05:39:48 -0700 (PDT) Date: Mon, 30 Mar 2020 13:39:46 +0100 From: Mark Rutland To: Tingwei Zhang Cc: Will Deacon , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: hw_breakpoint: don't clear debug registers in halt mode Message-ID: <20200330123946.GH1309@C02TD0UTHF1T.local> References: <20200328083209.21793-1-tingwei@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200328083209.21793-1-tingwei@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 28, 2020 at 04:32:09PM +0800, Tingwei Zhang wrote: > If external debugger sets a breakpoint for one Kernel function > when device is in bootloader mode and loads Kernel, this breakpoint > will be wiped out in hw_breakpoint_reset(). To fix this, check > MDSCR_EL1.HDE in hw_breakpoint_reset(). When MDSCR_EL1.HDE is > 0b1, halting debug is enabled. Don't reset debug registers in this case. I don't think this is sufficient, because the kernel can still subsequently mess with breakpoints, and the HW debugger might not be attached at this point in time anyhow. I reckon this should hang off the existing "nodebumon" command line option, and we shouldn't use HW breakpoints at all when that is passed. Then you can pass that to prevent the kernel stomping on the external debugger. Will, thoughts? Mark. > > Signed-off-by: Tingwei Zhang > --- > arch/arm64/include/asm/debug-monitors.h | 1 + > arch/arm64/kernel/hw_breakpoint.c | 19 +++++++++++++++++++ > 2 files changed, 20 insertions(+) > > diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h > index 7619f473155f..8dc2c28791a0 100644 > --- a/arch/arm64/include/asm/debug-monitors.h > +++ b/arch/arm64/include/asm/debug-monitors.h > @@ -18,6 +18,7 @@ > > /* MDSCR_EL1 enabling bits */ > #define DBG_MDSCR_KDE (1 << 13) > +#define DBG_MDSCR_HDE (1 << 14) > #define DBG_MDSCR_MDE (1 << 15) > #define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE) > > diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c > index 0b727edf4104..0180306f74d7 100644 > --- a/arch/arm64/kernel/hw_breakpoint.c > +++ b/arch/arm64/kernel/hw_breakpoint.c > @@ -927,6 +927,17 @@ void hw_breakpoint_thread_switch(struct task_struct *next) > !next_debug_info->wps_disabled); > } > > +/* > + * Check if halted debug mode is enabled. > + */ > +static u32 hde_enabled(void) > +{ > + u32 mdscr; > + > + asm volatile("mrs %0, mdscr_el1" : "=r" (mdscr)); > + return (mdscr & DBG_MDSCR_HDE); > +} > + > /* > * CPU initialisation. > */ > @@ -934,6 +945,14 @@ static int hw_breakpoint_reset(unsigned int cpu) > { > int i; > struct perf_event **slots; > + > + /* > + * When halting debug mode is enabled, break point could be already > + * set be external debugger. Don't reset debug registers here to > + * reserve break point from external debugger. > + */ > + if (hde_enabled()) > + return 0; > /* > * When a CPU goes through cold-boot, it does not have any installed > * slot, so it is safe to share the same function for restoring and > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project