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 03D33C7115C for ; Fri, 20 Jun 2025 21:42:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y0XDozIgHBTuryXqhnh8H2JD5/cpVpZyVVY8uuAwAOw=; b=YXw/+9y2L6gVJJ G5TpgAB1CA0QHvZHbvTrDieqASoafGTc3ism6oQKbwsn9iD6YixoCc2SeEjuG5AuGO7UCuo2xAWMR NzmHRrFAZEYo/HeqRlsXOy5Q0lEr99XuhVA1AKCBl258EyevAMcJT/v74vojtZsAhHbc28PW3xy// F960JRNPzEh1pgdwEwl3r9h1J4yk7ABgsYALt6xxoB5QEqqG/PMO0D2JCSKaLqsPbVzmQCTlWksLS Eu3CQLsPXhQPja9IgBMLe7qZW/O55qMaviztJUn/Xrjh+sObtIdSiU28EnpihrBgKIWjiJ7H8LPy0 96/t+ihzLqdL7pbo3q6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uSjUu-0000000GdcB-3Xmn; Fri, 20 Jun 2025 21:42:08 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uSj2R-0000000Gb1s-3Ofn for linux-arm-kernel@lists.infradead.org; Fri, 20 Jun 2025 21:12:45 +0000 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 732C0169C; Fri, 20 Jun 2025 14:12:23 -0700 (PDT) Received: from e137867.arm.com (unknown [10.57.50.192]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4B0EA3F673; Fri, 20 Jun 2025 14:12:41 -0700 (PDT) From: Ada Couprie Diaz To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 12/13] arm64: debug: split bkpt32 exception entry Date: Fri, 20 Jun 2025 22:12:06 +0100 Message-ID: <20250620211207.773980-13-ada.coupriediaz@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250620211207.773980-1-ada.coupriediaz@arm.com> References: <20250620211207.773980-1-ada.coupriediaz@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250620_141243_977069_7FA8449A X-CRM114-Status: GOOD ( 14.38 ) 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: , Cc: Mark Rutland , Anshuman Khandual , "Luis Claudio R . Goncalves" , Catalin Marinas , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently all debug exceptions share common entry code and are routed to `do_debug_exception()`, which calls dynamically-registered handlers for each specific debug exception. This is unfortunate as different debug exceptions have different entry handling requirements, and it would be better to handle these distinct requirements earlier. The BKPT32 exception can only be triggered by a BKPT instruction. Thus, we know that the PC is a legitimate address and isn't being used to train a branch predictor with a bogus address : we don't need to call `arm64_apply_bp_hardening()`. The handler for this exception only pends a signal and doesn't depend on any per-CPU state : we don't need to inhibit preemption, nor do we need to keep the DAIF exceptions masked, so we can unmask them earlier. Split the BKPT32 exception entry and adjust function signatures and its behaviour to match its relaxed constraints compared to other debug exceptions. We can also remove `NOKRPOBE_SYMBOL`, as this cannot lead to a kprobe recursion. This replaces the last usage of `el0_dbg()`, so remove it. Signed-off-by: Ada Couprie Diaz Tested-by: Luis Claudio R. Goncalves --- arch/arm64/include/asm/exception.h | 1 + arch/arm64/kernel/debug-monitors.c | 7 +++++++ arch/arm64/kernel/entry-common.c | 21 +++++++++------------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/exception.h b/arch/arm64/include/asm/exception.h index 075fb81cacc2..484809ff03d5 100644 --- a/arch/arm64/include/asm/exception.h +++ b/arch/arm64/include/asm/exception.h @@ -68,6 +68,7 @@ void do_watchpoint(unsigned long addr, unsigned long esr, struct pt_regs *regs); void do_el0_brk64(unsigned long esr, struct pt_regs *regs); void do_el1_brk64(unsigned long esr, struct pt_regs *regs); +void do_bkpt32(unsigned long esr, struct pt_regs *regs); void do_fpsimd_acc(unsigned long esr, struct pt_regs *regs); void do_sve_acc(unsigned long esr, struct pt_regs *regs); void do_sme_acc(unsigned long esr, struct pt_regs *regs); diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index 7c1c89bb9ad1..43a612eaa7d2 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -270,6 +270,13 @@ void do_el1_brk64(unsigned long esr, struct pt_regs *regs) } NOKPROBE_SYMBOL(do_el1_brk64); +#ifdef CONFIG_COMPAT +void do_bkpt32(unsigned long esr, struct pt_regs *regs) +{ + arm64_notify_die("aarch32 BKPT", regs, SIGTRAP, TRAP_BRKPT, regs->pc, esr); +} +#endif /* CONFIG_COMPAT */ + bool try_handle_aarch32_break(struct pt_regs *regs) { u32 arm_instr; diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 1e8306817056..bbf58fcab142 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -866,17 +866,6 @@ static void noinstr el0_brk64(struct pt_regs *regs, unsigned long esr) exit_to_user_mode(regs); } -static void noinstr el0_dbg(struct pt_regs *regs, unsigned long esr) -{ - /* Only watchpoints write FAR_EL1, otherwise its UNKNOWN */ - unsigned long far = read_sysreg(far_el1); - - enter_from_user_mode(regs); - do_debug_exception(far, esr, regs); - local_daif_restore(DAIF_PROCCTX); - exit_to_user_mode(regs); -} - static void noinstr el0_svc(struct pt_regs *regs) { enter_from_user_mode(regs); @@ -1037,6 +1026,14 @@ static void noinstr el0_svc_compat(struct pt_regs *regs) exit_to_user_mode(regs); } +static void noinstr el0_bkpt32(struct pt_regs *regs, unsigned long esr) +{ + enter_from_user_mode(regs); + local_daif_restore(DAIF_PROCCTX); + do_bkpt32(esr, regs); + exit_to_user_mode(regs); +} + asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs) { unsigned long esr = read_sysreg(esr_el1); @@ -1080,7 +1077,7 @@ asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs) el0_watchpt(regs, esr); break; case ESR_ELx_EC_BKPT32: - el0_dbg(regs, esr); + el0_bkpt32(regs, esr); break; default: el0_inv(regs, esr); -- 2.43.0