From: Tingwei Zhang <tingwei@codeaurora.org>
To: Will Deacon <will@kernel.org>, Mark Rutland <mark.rutland@arm.com>
Cc: Tingwei Zhang <tingwei@codeaurora.org>,
Catalin Marinas <catalin.marinas@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] arm64: hw_breakpoint: don't clear debug registers in halt mode
Date: Sat, 28 Mar 2020 16:32:09 +0800 [thread overview]
Message-ID: <20200328083209.21793-1-tingwei@codeaurora.org> (raw)
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.
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
---
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
next reply other threads:[~2020-03-28 8:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-28 8:32 Tingwei Zhang [this message]
2020-03-30 12:39 ` [PATCH] arm64: hw_breakpoint: don't clear debug registers in halt mode Mark Rutland
2020-03-30 13:42 ` Will Deacon
2020-03-31 2:39 ` tingwei
2020-03-31 7:41 ` Will Deacon
2020-03-31 11:33 ` tingwei
2020-03-31 11:45 ` Will Deacon
2020-04-21 3:49 ` tingwei
2020-04-21 7:10 ` Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200328083209.21793-1-tingwei@codeaurora.org \
--to=tingwei@codeaurora.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox