Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp474872rwi; Mon, 10 Oct 2022 03:11:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5zHq72n7Z2819TjmjZhmC0jYI4m+odCYoC9o1Fa2kPAuS8NWDl1hPlu5u4DbhJJX4VWMUa X-Received: by 2002:a17:907:2cd9:b0:78d:9f4c:9cff with SMTP id hg25-20020a1709072cd900b0078d9f4c9cffmr6602120ejc.345.1665396673964; Mon, 10 Oct 2022 03:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665396673; cv=none; d=google.com; s=arc-20160816; b=RWQMQIafj06aLohwzdfHaxwJDyBrZ310VLDRlc+4WEO8yJl8gXvqwS6+Y0AI7p/O8x 3XPKJdvHHZoHqvxkKRhlyp74uA/RekMqQAYHMluzYfCFG7X0am6dnvGmZbQ7nwBf30Ip 0UaVmU3ayKTx/UenljNFFRzggVfBiDz+e/Csn5KuwquOcCoBzc2NlQf0sGwXmwSUTboV qq6qSKVrQaw6NXHvfldoOErv54vcZDdOcmFDUxdQF8aR8yy/5vSIJZ5hBbJ1dcwq3w3m ukQwZXPel88zCYqxkayRbwKqIfZOS8c4tzXf4cOv+Y0Kf6M4Q12gJOLuEZMw3jzJJDsf kTwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=F5DMp+bUE/ffdFr+essRZfFHNCDE7gy5beZ/FAU5nWo=; b=h65dAyGypqMZj8i8RMfjgF6VGT8caT74H/Lhb5M15/q+ZPoFhLxMCHPo0u+ewMJZYY UXqAoyrkG/LIvH5e9dhnApU0wKsyJd3f+r8iEX0kinJO/+/n+3eKZLeIPgBjtC9+80Fv +0DZsEjb2sbi3PCNSkpkHBQber4h78bkfegxniXisqSbNFSwihH4UVORThPgJsyOnrAn MPvDqOG6uOgW8B7aC8MIAMGEbrgzywdF+YdGBU/UUNBIjy8g1jhd7lEEp4Mh2R1ud6fK cDyvdIw7KdkbkNMkyrdt+7w7A+5NolPLmI5fdCwD42UtlfeZs/GV587hjtMD7htpPoPR 6DNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb9-20020a170907160900b0078b0865d468si11372518ejc.549.2022.10.10.03.10.44; Mon, 10 Oct 2022 03:11:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231316AbiJJJzM (ORCPT + 99 others); Mon, 10 Oct 2022 05:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230246AbiJJJzF (ORCPT ); Mon, 10 Oct 2022 05:55:05 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 205322A274 for ; Mon, 10 Oct 2022 02:55:02 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MmDg86WgYzmVBd; Mon, 10 Oct 2022 17:50:28 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 10 Oct 2022 17:55:01 +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, 10 Oct 2022 17:55:00 +0800 From: Zhen Lei To: Russell King , , CC: Zhen Lei Subject: [PATCH v2 2/2] ARM: Make the dumped instructions are consistent with the disassembled ones Date: Mon, 10 Oct 2022 17:53:46 +0800 Message-ID: <20221010095346.1957-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20221010095346.1957-1-thunder.leizhen@huawei.com> References: <20221010095346.1957-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=y, 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 --- arch/arm/kernel/traps.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 34aa80c09c508c1..50b00c9091f079d 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -193,6 +193,13 @@ static void dump_instr(const char *lvl, struct pt_regs *regs) bad = get_user(val, &((u32 __user *)addr)[i]); } + if (IS_ENABLED(CONFIG_CPU_ENDIAN_BE8)) { + if (thumb) + val = (__force unsigned int)cpu_to_le16(val); + else + val = (__force unsigned int)cpu_to_le32(val); + } + if (!bad) p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ", width, val); -- 2.25.1