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 33110C54EE9 for ; Tue, 13 Sep 2022 10:22:01 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Ry8KQHRoad3w2CIYOO0IlRyePklvw7PUO+uUnZBh44E=; b=4ssg0CO9Q4eFdD WUVXLDGAYqwUIIg4RkmE15DFoYubnNMLRYBnde1JdDS7pyDU3xRZl8LV632OhBhj/qle0Wmnv5hTG YoTCeKMiC7VGWy2GaaNsJC4KmLbwWFgXJ/Cz9KFotTy7MgOR1Nm7SiyN8jtBeYBlxaZJZ69sfbaZ+ egwytTqn8NNC2KCvLPDy9QbXiynZmB5RvGTZGJW0HDAfVv5brHf6horQSr9MM2i42+ifrrbc3UmXL 1jSArEvDRMFWiijkSzeTrWw2Oo4Atr0ho0RBrQMnouC85Qv20f1S2TWHGiguN/XEJmc8se2/W8Tkp vVhRdYbtCwjGKoG08yTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oY325-006QuI-7F; Tue, 13 Sep 2022 10:20:47 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oY2zJ-006MLA-EO for linux-arm-kernel@lists.infradead.org; Tue, 13 Sep 2022 10:18:02 +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 2AAED1063; Tue, 13 Sep 2022 03:17:53 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8C8BA3F71A; Tue, 13 Sep 2022 03:17:45 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com Cc: alexandru.elisei@arm.com, amit.kachhap@arm.com, anshuman.khandual@arm.com, broonie@kernel.org, james.morse@arm.com, mark.rutland@arm.com, will@kernel.org Subject: [PATCH v2 0/5] arm64: report EL1 exceptions better Date: Tue, 13 Sep 2022 11:17:27 +0100 Message-Id: <20220913101732.3925290-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220913_031753_712168_E32CA8FC X-CRM114-Status: UNSURE ( 8.47 ) X-CRM114-Notice: Please train this message. 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 We treat BTI, FPAC, and UNDEFINED exceptions as fatal when taken from EL1, but due to the way we make these fatal, we end up throwing away information that could be used to diagnose the cause of the exception. We have an anti-pattern where in the handler for the exception we do: BUG_ON(!user_mode(regs)); ... and consequently, the BUG handler logs the context of the exception handler which contained the BUG_ON(), rather than the context from which the fatal exception was taken. For example, today we report UNDEFINED exceptions as: | kernel BUG at arch/arm64/kernel/traps.c:497! | Internal error: Oops - BUG: 0 [#1] PREEMPT SMP | Modules linked in: | CPU: 0 PID: 0 Comm: swapper Not tainted 5.19.0-rc3-00127-geff044f1b04e-dirty #3 | Hardware name: linux,dummy-virt (DT) | pstate: 000000c5 (nzcv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) | pc : do_undefinstr+0x28c/0x2ac | lr : do_undefinstr+0x298/0x2ac | sp : ffff800009f63bc0 | x29: ffff800009f63bc0 x28: ffff800009f73c00 x27: ffff800009644a70 | x26: ffff8000096778a8 x25: 0000000000000040 x24: 0000000000000000 | x23: 00000000800000c5 x22: ffff800009894060 x21: ffff800009f63d90 | x20: 0000000000000000 x19: ffff800009f63c40 x18: 0000000000000006 | x17: 0000000000403000 x16: 00000000bfbfd000 x15: ffff800009f63830 | x14: ffffffffffffffff x13: 0000000000000000 x12: 0000000000000019 | x11: 0101010101010101 x10: 0000000000161b98 x9 : 0000000000000000 | x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000 | x5 : ffff800009f761d0 x4 : 0000000000000000 x3 : ffff80000a2b80f8 | x2 : 0000000000000000 x1 : ffff800009f73c00 x0 : 00000000800000c5 | Call trace: | do_undefinstr+0x28c/0x2ac | el1_undef+0x2c/0x4c | el1h_64_sync_handler+0x84/0xd0 | el1h_64_sync+0x64/0x68 | setup_arch+0x550/0x598 | start_kernel+0x88/0x6ac | __primary_switched+0xb8/0xc0 | Code: 17ffff95 a9425bf5 17ffffb8 a9025bf5 (d4210000) ... where the code dump is for the BRK instruction in the BUG_ON(), and the register contents are for the innards of do_undefinstr(). The instruction which triggered the UNDEFINED exception is nowhere in the dump. This series reworks the handling of these exceptions to be more useful, reporting the original context of the exception, and calling die() directly rather than using BUG_ON(). For example, as of this series being applied, UNDEFINED exceptions are reported as: | Internal error: Oops - Undefined instruction: 0 [#1] PREEMPT SMP | Modules linked in: | CPU: 0 PID: 0 Comm: swapper Not tainted 5.19.0-rc3-00128-gf27cfcc80e52-dirty #5 | Hardware name: linux,dummy-virt (DT) | pstate: 800000c5 (Nzcv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) | pc : setup_arch+0x550/0x598 | lr : setup_arch+0x50c/0x598 | sp : ffff800009f63d90 | x29: ffff800009f63d90 x28: 0000000081000200 x27: ffff800009644a70 | x26: ffff8000096778c8 x25: 0000000000000040 x24: 0000000000000000 | x23: 0000000000000100 x22: ffff800009f69a58 x21: ffff80000a2b80b8 | x20: 0000000000000000 x19: 0000000000000000 x18: 0000000000000006 | x17: 0000000000403000 x16: 00000000bfbfd000 x15: ffff800009f63830 | x14: ffffffffffffffff x13: 0000000000000000 x12: 0000000000000019 | x11: 0101010101010101 x10: 0000000000161b98 x9 : 0000000000000000 | x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000 | x5 : 0000000000000008 x4 : 0000000000000010 x3 : 0000000000000000 | x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000000 | Call trace: | setup_arch+0x550/0x598 | start_kernel+0x88/0x6ac | __primary_switched+0xb8/0xc0 | Code: b4000080 90ffed80 912ac000 97db745f (00000000) ... where the code dump includes the instruction which triggered the exception, and the register contents are for the context the instruction was executed in. Since v1 [1]: * Rebase (trivial) to v6.0-rc3 * Fix typos * Consistently pass ESR to die() * Add Reviewed-by tags [1] https://lore.kernel.org/linux-arm-kernel/20220712161452.4142444-1-mark.rutland@arm.com/ Mark. Mark Rutland (5): arm64: report EL1 UNDEFs better arm64: die(): pass 'err' as long arm64: consistently pass ESR_ELx to die() arm64: rework FPAC exception handling arm64: rework BTI exception handling arch/arm64/include/asm/exception.h | 8 +++-- arch/arm64/include/asm/system_misc.h | 2 +- arch/arm64/kernel/entry-common.c | 32 +++++++++++++------ arch/arm64/kernel/traps.c | 48 +++++++++++++++++----------- 4 files changed, 57 insertions(+), 33 deletions(-) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel