Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp536749rwi; Mon, 10 Oct 2022 04:08:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4K7f1lwdfoSWxxqgCjt3Tazh0DTM3hK74bMbjjGYAuGGZLFfbD9+Vez1xY3I5oQfgimH6b X-Received: by 2002:a17:906:dc89:b0:78d:5616:4c24 with SMTP id cs9-20020a170906dc8900b0078d56164c24mr11833999ejc.118.1665400084487; Mon, 10 Oct 2022 04:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665400084; cv=none; d=google.com; s=arc-20160816; b=WCLj3DmI6Lq8Cl5ODMw1q0TQsICAuDvgpgKpRmKN9jJwfVtonYK1u5APxZl+PHi0jC G73Z84TA5zdt9fOx7WHiWanJYIbf/yOubOb1i+c5Jldzr1tVNtNQxTKs+XpbPRv5N1p3 Pe6e+qpFB8D5mx4572p5AD43VeyiDh49vqN6ps3RbR6zLikfcvufaXspbWSUOpJiy4ds 6DQmzQb7nQF5TYBUMJD7yBaMLLuO55A+tInmiwv7I/2ZX+YTBqFVN8mrBoTScL54+YYL M6F5gg1mOSU+UW1C+wLCJYxvjMF5g3MbMryaBgseKkfVMydsb5CRevmrRMDTw/WglMtR Fsxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cUQkv9T6V1GYXcupntK0but2Rul9ZPUMfqnOJ9mc4sE=; b=ScJ6MaIHE/HL2MbUWHfe2AEfpBzR6BwDIrzBWd2SrSKkyEgXrgg2mtc6tNIcvuUtvF HlVjLXhh1cGk9wIX6Fc7FFVPeehHEaJwzteg1QTvpbu8ftBjbYWkncqiwZPwOgBDQ7Gs 7hfBYmoPCSjV88EQDyTPFibSDLeoq9tfY5fKqry35VHQ6HowWQWBfGXTaUzvD4cvH5Au az8jgP5ILnT27y80aD5OGxWgJZa2RIM5Hf3cCO70YsM3zAeZcCq7P0N5UtNXEewNqrdc t+CM4dIjV6d7wAf4pZnRy68Yn3OUckXykNn9EluH346hYZsSj1ksiCVX0QhFRpQtoLHE j2+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tr+465bc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb24-20020a1709071c9800b0078cffd3ce3esi10149044ejc.654.2022.10.10.04.07.25; Mon, 10 Oct 2022 04:08:04 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tr+465bc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231539AbiJJKKq (ORCPT + 99 others); Mon, 10 Oct 2022 06:10:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231440AbiJJKKn (ORCPT ); Mon, 10 Oct 2022 06:10:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B31F33C8FD for ; Mon, 10 Oct 2022 03:10:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2232FB80E6A for ; Mon, 10 Oct 2022 10:10:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3FCAC433D6 for ; Mon, 10 Oct 2022 10:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665396637; bh=/7KzcIlUMYgbYA0zGrOVHVeZ5fCL2Ww3MvQl4Wew+lU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Tr+465bcOT5hFO7SlhSs8repdkZSmga1G50kMHHnXPBNcsVwLI/6rHUTs8fnmotfu iG0iWR4i8U/7/auxXAzNLU8x/rNNqJp6pMuyux65I/yIyNuWEIuK/zt/GO9SMjk22k GCzYzotdLUKaXz2WDWBm0AoxsyIUS/qlmNsHz42o+GqZVRlAV7XOZhPA8oSX0795EB e8Li3P7ZqQ4b6TGBezI0s9vD2XHFPyx5ry+BU32zbYhkqoalji4RXvG//q3DbIKIkK seqfTP7sR+4QLrnADEAR4FLu9P8SNjajHbrDmmsNScrAAgvUXlC2hIQ3vHz9r/7hqD jJ8GfPlk0xWCg== Received: by mail-lf1-f44.google.com with SMTP id s20so15835782lfi.11 for ; Mon, 10 Oct 2022 03:10:37 -0700 (PDT) X-Gm-Message-State: ACrzQf0NcTOb0aj1pshsiMcXnyLaQ9hhINbeeyKJRZH20RRHWJHsxZWs O0E+vcITBkoUsqUOwY11r4Nc7aor/z2RuYgA/0Y= X-Received: by 2002:a05:6512:150e:b0:492:d9fd:9bdf with SMTP id bq14-20020a056512150e00b00492d9fd9bdfmr6174870lfb.583.1665396635846; Mon, 10 Oct 2022 03:10:35 -0700 (PDT) MIME-Version: 1.0 References: <20221010095346.1957-1-thunder.leizhen@huawei.com> <20221010095346.1957-3-thunder.leizhen@huawei.com> In-Reply-To: <20221010095346.1957-3-thunder.leizhen@huawei.com> From: Ard Biesheuvel Date: Mon, 10 Oct 2022 12:10:24 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/2] ARM: Make the dumped instructions are consistent with the disassembled ones To: Zhen Lei Cc: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Mon, 10 Oct 2022 at 11:56, Zhen Lei wrote: > > 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); Better use swab16() here instead of the ugly __force cast, given that the swab is going to occur unconditionally here. > + else > + val = (__force unsigned int)cpu_to_le32(val); and swab32() here > + } > + > if (!bad) > p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ", > width, val); > -- > 2.25.1 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel