Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1771587rwi; Thu, 13 Oct 2022 19:59:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59R0M4hog763c0rQjWBw20gdv0n0ZRd65pXRU500mv0MSVMREzBdSsc1tcyX/2EPYffgNd X-Received: by 2002:a05:6402:2707:b0:45c:d8a3:6cfc with SMTP id y7-20020a056402270700b0045cd8a36cfcmr2374489edd.269.1665716351830; Thu, 13 Oct 2022 19:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665716351; cv=none; d=google.com; s=arc-20160816; b=gRVAEVH27G2dHsAziwI2AA3JOhujzleWxDtIjqPliQ8NoLj1Oam6nVfnPd2jerOhVK jw8B1Ywpcy+GCotKEZg9DXNyu/k/4m4JfNCixKZ8zYKrFxs1oEMmXye6IyyGImyLUI+e uQ1zmg1Ba1YRAXD7AxCI3V7rOVTpoCjemSJJL5qU0sDDnKJ9EhkPS0fz1XZPTwOJ3IVS oUtsjUeW/rG1OSTUooxa6xMt0GLqREdVUtL5D4j5zbhXgBxJqZMHapyf/vOIG7gCc41s ggSt6S2wCvvM3lPmVYtMc6vJ6n+Qs/6SCsyuXmDY6fSoHhUlMveJdCxE6namEhpeqUXq LsAQ== 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=XNJJiMv2unl+KLI1jcBrnVMTTEMN2OihAodlahnnAxw=; b=lKCEXYTHJR0vHJ9zpxDghNrf2dVYjrXJuKeVnUMxmOriraTWbh2zpQyxohtWupk/ri G6bcKU/gX0SRTN4viVc+03/T3gNqwG/KJ2HCA4QdwFFZlF3xVvMsUbdN09fljZvJ6C5z OizFJwEDxmC1BgqgHMKrHDq7BnjnmTvg2zO6ElDP260vEhE43gReTxDYQOx30mfAecI6 qqW2kiHbQ9ZQZv5dGytrI/LjPIXF8KZjYEpVq1llwwaugtfEnwFsh6CxCO4I3UPXD+En r8QMLRsCxgiVxK+tYmsmIghQL/1u8Z9u2JKkW5Y7YluPWoIOweTTlhYsXRsvzQb4mWyJ M5xQ== 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 oz14-20020a1709077d8e00b0078e06ba4deasi1524656ejc.218.2022.10.13.19.58.32; Thu, 13 Oct 2022 19:59:11 -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 S229733AbiJNCBA (ORCPT + 99 others); Thu, 13 Oct 2022 22:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229559AbiJNCAr (ORCPT ); Thu, 13 Oct 2022 22:00:47 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DCB87CE30 for ; Thu, 13 Oct 2022 19:00:46 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MpV3G2JHHzHtxF; Fri, 14 Oct 2022 10:00:42 +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; Fri, 14 Oct 2022 10:00:44 +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; Fri, 14 Oct 2022 10:00:44 +0800 From: Zhen Lei To: Russell King , Ard Biesheuvel , , CC: Zhen Lei Subject: [PATCH v3 3/3] ARM: Make the dumped instructions are consistent with the disassembled ones Date: Fri, 14 Oct 2022 09:59:56 +0800 Message-ID: <20221014015956.2006-4-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20221014015956.2006-1-thunder.leizhen@huawei.com> References: <20221014015956.2006-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: dggems705-chm.china.huawei.com (10.3.19.182) 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 182469a5b28a394..8a7f216156675a1 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_regs *regs) else bad = get_kernel_nofault(tmp, &((u16 *)addr)[i]); - val = tmp; + val = __mem_to_opcode_thumb16(tmp); } else { if (user_mode(regs)) bad = get_user(val, &((u32 __user *)addr)[i]); else bad = get_kernel_nofault(val, &((u32 *)addr)[i]); + + val = __mem_to_opcode_arm(val); } if (!bad) -- 2.25.1