From nobody Fri Sep 19 05:33:39 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC1C5C433FE for ; Mon, 28 Nov 2022 11:46:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbiK1LqF (ORCPT ); Mon, 28 Nov 2022 06:46:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbiK1Lp7 (ORCPT ); Mon, 28 Nov 2022 06:45:59 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8744917416 for ; Mon, 28 Nov 2022 03:45:57 -0800 (PST) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NLNq70PNYzqSnB; Mon, 28 Nov 2022 19:41:55 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 19:45:55 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 19:45:55 +0800 From: Zhen Lei To: Russell King , Ard Biesheuvel , , , CC: Zhen Lei Subject: [PATCH 1/2] ARM: Refactor dump_instr() Date: Mon, 28 Nov 2022 19:42:42 +0800 Message-ID: <20221128114243.2042-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20221128114243.2042-1-thunder.leizhen@huawei.com> References: <20221128114243.2042-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 1. Rename local variable 'val16' to 'tmp'. So that the processing statements of thumb and arm can be aligned. 2. Fix two sparse check warnings: (add __user for type conversion) warning: incorrect type in initializer (different address spaces) expected unsigned short [noderef] __user *register __p got unsigned short [usertype] * 3. Prepare for the next patch to avoid repeated judgment. Before: if (!user_mode(regs)) { if (thumb) else } else { if (thumb) else } After: if (thumb) { if (user_mode(regs)) else } else { if (user_mode(regs)) else } Signed-off-by: Zhen Lei --- KernelVersion: v6.1-rc7 arch/arm/kernel/traps.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 20b2db6dcd1ced7..a92e0763739584e 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -178,19 +178,20 @@ static void dump_instr(const char *lvl, struct pt_reg= s *regs) for (i =3D -4; i < 1 + !!thumb; i++) { unsigned int val, bad; =20 - if (!user_mode(regs)) { - if (thumb) { - u16 val16; - bad =3D get_kernel_nofault(val16, &((u16 *)addr)[i]); - val =3D val16; - } else { - bad =3D get_kernel_nofault(val, &((u32 *)addr)[i]); - } + if (thumb) { + u16 tmp; + + if (user_mode(regs)) + bad =3D get_user(tmp, &((u16 __user *)addr)[i]); + else + bad =3D get_kernel_nofault(tmp, &((u16 *)addr)[i]); + + val =3D tmp; } else { - if (thumb) - bad =3D get_user(val, &((u16 *)addr)[i]); + if (user_mode(regs)) + bad =3D get_user(val, &((u32 __user *)addr)[i]); else - bad =3D get_user(val, &((u32 *)addr)[i]); + bad =3D get_kernel_nofault(val, &((u32 *)addr)[i]); } =20 if (!bad) --=20 2.25.1 From nobody Fri Sep 19 05:33:39 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38CCEC43217 for ; Mon, 28 Nov 2022 11:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231251AbiK1LqH (ORCPT ); Mon, 28 Nov 2022 06:46:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230521AbiK1Lp7 (ORCPT ); Mon, 28 Nov 2022 06:45:59 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CE81741C for ; Mon, 28 Nov 2022 03:45:57 -0800 (PST) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NLNq73nSwzqShk; Mon, 28 Nov 2022 19:41:55 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 19:45:56 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 19:45:55 +0800 From: Zhen Lei To: Russell King , Ard Biesheuvel , , , CC: Zhen Lei Subject: [PATCH 2/2] ARM: Make the dumped instructions are consistent with the disassembled ones Date: Mon, 28 Nov 2022 19:42:43 +0800 Message-ID: <20221128114243.2042-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20221128114243.2042-1-thunder.leizhen@huawei.com> References: <20221128114243.2042-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In ARM, the mapping of instruction memory is always little-endian, except some BE-32 supported ARM architectures. Such as ARMv7-R, its instruction endianness may be BE-32. Of course, its data endianness will also be BE-32 mode. Due to two negatives make a positive, the instruction stored in the register after reading is in little-endian format. But for the case of BE-8, the instruction endianness is LE, the instruction stored in the register after reading is in big-endian format, which is inconsistent with the disassembled one. For example: The content of disassembly: c0429ee8: e3500000 cmp r0, #0 c0429eec: 159f2044 ldrne r2, [pc, #68] c0429ef0: 108f2002 addne r2, pc, r2 c0429ef4: 1882000a stmne r2, {r1, r3} c0429ef8: e7f000f0 udf #0 The output of undefined instruction exception: Internal error: Oops - undefined instruction: 0 [#1] SMP ARM ... ... Code: 000050e3 44209f15 02208f10 0a008218 (f000f0e7) This inconveniences the checking of instructions. What's worse is that, for somebody who don't know about this, might think the instructions are all broken. So, when CONFIG_CPU_ENDIAN_BE8=3Dy, let's convert the instructions to little-endian format before they are printed. The conversion result is as follows: Code: e3500000 159f2044 108f2002 1882000a (e7f000f0) Signed-off-by: Zhen Lei --- KernelVersion: v6.1-rc7 arch/arm/kernel/traps.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index a92e0763739584e..40c7c807d67f4ed 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -186,12 +186,14 @@ static void dump_instr(const char *lvl, struct pt_reg= s *regs) else bad =3D get_kernel_nofault(tmp, &((u16 *)addr)[i]); =20 - val =3D tmp; + val =3D __mem_to_opcode_thumb16(tmp); } else { if (user_mode(regs)) bad =3D get_user(val, &((u32 __user *)addr)[i]); else bad =3D get_kernel_nofault(val, &((u32 *)addr)[i]); + + val =3D __mem_to_opcode_arm(val); } =20 if (!bad) --=20 2.25.1