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 08C5AC433F5 for ; Mon, 14 Feb 2022 13:05:24 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qbzIjtscUn1hMn2e/T8MPvmuACEqCQsOeCxqVfA4Rs4=; b=DmdLxoI+pT5Xx7 o6KaRqYOMKOn6brjzVJ61GbmgPngjYdGp5zcCQL0vnT53lVq1IIeVfZuYCxmb9E52PUcxuQvnoi2q bp0WvU8WN31AjmNWxp57ETawi7C8jq9tpDXhKaajXNVIC6SsdQH00n32Rlj00KZTB0LJae3Atk6HU coEfftVkG0UnpIQX8rgunqn6KsTS5+8AjsRwaP9RJBaWIxxGAiUTIsG4JqHqrF0BLwLAUdF3ffiEP K6YKtPSBb3HxMz9Gs+UFDeK1NErXj6DhdBa7bodN0DnsNThe5IwCxUPXqWCg2dmsjUlzJIU63Bogc 0DDfVlQGCesspnT4D8cA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJb0r-00FL83-Oc; Mon, 14 Feb 2022 13:03:30 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJauF-00FIEp-4P for linux-arm-kernel@lists.infradead.org; Mon, 14 Feb 2022 12:56:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2kGnGHk2PCRxCzb4a437GePj5bgC7Va36uI5T1MN0e4=; b=RFX3KTgGuGpKLln5FxxWtCgISE QnVHSAqNRZ9VvaN6wGiYQ3M6Ko3vjG010sdyjS4YmfdwTQQ9DgnR4Hqh9No35Glvr/LAUvWxSsJ+4 wQ3ohc0VDjuXeON8Bna3Hhp7jiqRKbGyRKlrzqep83lZQl6232ISHOLiy0NBPenfNu6Qr8s9MB10I 8GNTtqEKJ7AHkCoSAgWB3C82BaMSy9xs8vpeti7pGCdFIZPEvE/KsOZpuzDGP0xzVp/ytjLql1U7s drDeX77wRjhTvNv9QKcq5tmzgW8YIMDkuOx29LUaUu123s7Nckro9b8h/NAzkN3CN43BUVa6Y+gxE Vr1p99Kg==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:57246) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nJauA-0001TO-EM; Mon, 14 Feb 2022 12:56:34 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1nJau9-0006Xe-PP; Mon, 14 Feb 2022 12:56:33 +0000 Date: Mon, 14 Feb 2022 12:56:33 +0000 From: "Russell King (Oracle)" To: Johannes Stezenbach Cc: linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] arm kgdb: fix breakpoint for thumb2 Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220214_045639_238055_F7B30B8C X-CRM114-Status: GOOD ( 24.80 ) 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 Mon, Feb 14, 2022 at 12:05:56PM +0100, Johannes Stezenbach wrote: > On Mon, Feb 14, 2022 at 10:13:43AM +0000, Russell King (Oracle) wrote: > > On Mon, Feb 14, 2022 at 10:59:49AM +0100, Johannes Stezenbach wrote: > > > Entering kdb via SysRq-G with CONFIG_THUMB2_KERNEL=y > > > on Cortex-A7 in Qemu results in an Ooops, and it is > > > not possible to continue because of "Catastrophic error detected". > > > The root cause is using an arm breakpoint instruction in > > > thumb code. > > > > This sounds like a bug in qemu. > > > > 0xe7ffdeXX is two 16-bit instructions: > > > > 0: e7ff b.n 2 <.text+0x2> > > 2: def1 udf #241 ; 0xf1 > > > > 0xe7ff is a branch to the UDF instruction. > > > > 0xdeXX is a UDF (Permanently undefined) instruction which should raise a > > undefined instruction trap. As per the Arm ARM on UDF: "Permanently > > Undefined generates an Undefined Instruction exception." > > > > The encoding is also a 32-bit UDF instruction: > > > > 0: e7ffdef1 udf #64993 ; 0xfde1 > > > > which is exactly why these opcodes were chosen - so we can instrument > > both ARM and Thumb code without caring which it is. > > > > Qemu needs fixing if it complains about this. > > My apologies for the incomplete problem description. > > Qemu is not complaining at all and correctly raises the invalid > instruction exception. But the kgdb_compiled_brkpt_hook undef_hook > only sees the 0xdef1 part and thus does not match. The kgdb code needs to register an undef hook for the Thumb UDF instruction that will fault, in addition to the ARM version. Probably something like this (untested). Please let me know if this works. diff --git a/arch/arm/kernel/kgdb.c b/arch/arm/kernel/kgdb.c index 7bd30c0a4280..a3602cacda0b 100644 --- a/arch/arm/kernel/kgdb.c +++ b/arch/arm/kernel/kgdb.c @@ -154,22 +154,38 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr) return 0; } -static struct undef_hook kgdb_brkpt_hook = { +static struct undef_hook kgdb_brkpt_arm_hook = { .instr_mask = 0xffffffff, .instr_val = KGDB_BREAKINST, - .cpsr_mask = MODE_MASK, + .cpsr_mask = PSR_T_BIT | MODE_MASK, .cpsr_val = SVC_MODE, .fn = kgdb_brk_fn }; -static struct undef_hook kgdb_compiled_brkpt_hook = { +static struct undef_hook kgdb_brkpt_thumb_hook = { + .instr_mask = 0xffff, + .instr_val = KGDB_BREAKINST & 0xffff, + .cpsr_mask = PSR_T_BIT | MODE_MASK, + .cpsr_val = PSR_T_BIT | SVC_MODE, + .fn = kgdb_brk_fn +}; + +static struct undef_hook kgdb_compiled_brkpt_arm_hook = { .instr_mask = 0xffffffff, .instr_val = KGDB_COMPILED_BREAK, - .cpsr_mask = MODE_MASK, + .cpsr_mask = PSR_T_BIT | MODE_MASK, .cpsr_val = SVC_MODE, .fn = kgdb_compiled_brk_fn }; +static struct undef_hook kgdb_compiled_brkpt_thumb_hook = { + .instr_mask = 0xffff, + .instr_val = KGDB_COMPILED_BREAK & 0xffff, + .cpsr_mask = PSR_T_BIT | MODE_MASK, + .cpsr_val = PSR_T_BIT | SVC_MODE, + .fn = kgdb_compiled_brk_fn +}; + static int __kgdb_notify(struct die_args *args, unsigned long cmd) { struct pt_regs *regs = args->regs; @@ -210,8 +226,10 @@ int kgdb_arch_init(void) if (ret != 0) return ret; - register_undef_hook(&kgdb_brkpt_hook); - register_undef_hook(&kgdb_compiled_brkpt_hook); + register_undef_hook(&kgdb_brkpt_arm_hook); + register_undef_hook(&kgdb_brkpt_thumb_hook); + register_undef_hook(&kgdb_compiled_brkpt_arm_hook); + register_undef_hook(&kgdb_compiled_brkpt_thumb_hook); return 0; } -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel