From patchwork Tue Aug 8 02:41:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 132503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1853814vqr; Mon, 7 Aug 2023 20:27:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8nSMR+lmjAe/NO+3xJvlMNnBjjyr+rqN4f3tVNWu+DU7hplifeiVnpXGCixChMfXC+Qje X-Received: by 2002:a17:907:2c75:b0:99b:c8db:d92f with SMTP id ib21-20020a1709072c7500b0099bc8dbd92fmr8828011ejc.69.1691465264019; Mon, 07 Aug 2023 20:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691465264; cv=none; d=google.com; s=arc-20160816; b=p3DgzmBof+wELUerNSRirDGcKIIkMG8X7nuM/GVA4r0naoPFsaIVLnNnzZMpJ1uxVM zGvgRQzCeI+w2zEpiXNIMwjf7OtzOxtPfEcAP4QMfJqSJPHLnPZAC46o25qblDiJnSkf zUGLKRnJtMk58z18b0srGa34fLaMNOPmLN5QpXvezbenQAoXid5rr5W0rzBaO02/nQN9 LhE+5zFZ648+Euj81zjdU15YtxY7NpcRfXAoQTPnmOaOQ5fLbJXhAqHg2ohCYNzK54I2 hHpYh/CFYdATbjSQkEKo0g7hgDOs70KTDnCtOegSxBjl0f9vFRDNq4yuVDN3eWPvCFS8 3F7w== 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=QQTpdlb+L2fjArHhytJQUzzRthVBPlYu29uhbEqVgFU=; fh=BHdAqCtXQk2EWZNv3TzltgEN0mmKIS4hw5j/7slC4No=; b=tWwZ8any5Vz2nJcxzM7e4KZdzPgMAGoi0xQ1cNlCZwDFr/dEdzHPLO+E+n1VUHakE4 PjqQmlwinXQ3DQfhtwDhPk+3NRzeTwkVksLq4sawQkv+uFje4thzsi7+s17T/xEPlEvZ FN2kjTg1x3UwsUe3RHvuirtKfKka6vW03oGbvY/kp8428xHMnq/WWtKZf8YmNO678C05 0S0Ak7sl+FSI8EZDqydbFrWA2pso/Yae51AP9m+Qhb4+KbOQbmLrQQ3p2xg/w2vAg3dT 3F5bHw9fZnSRucAQxkuWBSiDqvQRVO6VntQnqg1l7PN6dDJ1lLt6jWXWvmisO1BlqQGF pooA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx19-20020a170906ca5300b009929eee322dsi6392870ejb.180.2023.08.07.20.27.20; Mon, 07 Aug 2023 20:27:44 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbjHHCmP (ORCPT + 99 others); Mon, 7 Aug 2023 22:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbjHHCmH (ORCPT ); Mon, 7 Aug 2023 22:42:07 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50E92E78 for ; Mon, 7 Aug 2023 19:42:04 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RKcsM1ZJQz4f3lKf for ; Tue, 8 Aug 2023 10:41:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.174.178.55]) by APP4 (Coremail) with SMTP id gCh0CgA3x6l1q9FkbBbIAA--.8214S6; Tue, 08 Aug 2023 10:42:02 +0800 (CST) From: thunder.leizhen@huaweicloud.com To: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness , linux-kernel@vger.kernel.org Cc: Zhen Lei , Randy Dunlap Subject: [PATCH v2 2/2] hexdump: add a new dump prefix DUMP_PREFIX_ADDRESS_LOW16 Date: Tue, 8 Aug 2023 10:41:46 +0800 Message-Id: <20230808024146.1335-3-thunder.leizhen@huaweicloud.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230808024146.1335-1-thunder.leizhen@huaweicloud.com> References: <20230808024146.1335-1-thunder.leizhen@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgA3x6l1q9FkbBbIAA--.8214S6 X-Coremail-Antispam: 1UD129KBjvJXoWxWF1UGw45KFWUuF17Jw1kZrb_yoW5Ww1rpa s0gryUGF40gF4xGr1UJFWUCr1jyrZ8Ca40kFWqyw109ryxWFW7Xw4kJFW3Gr15GrWFqFnx Jry7t3s8Kr1UCw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9vb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6r1S6rWUM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8y89tUUUUU== X-CM-SenderInfo: hwkx0vthuozvpl2kv046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773629880508437145 X-GMAIL-MSGID: 1773629880508437145 From: Zhen Lei Currently, function print_hex_dump() supports three dump prefixes: DUMP_PREFIX_NONE, DUMP_PREFIX_ADDRESS and DUMP_PREFIX_OFFSET. But for some usage scenarios, they don't work perfectly. For example, dump the content of one task's stack. In order to quickly identify a stack frame, DUMP_PREFIX_ADDRESS is preferred. But printing multiple 64-bit addresses is a bit unwise when the 'sp' value is already printed. It is redundant. For example: dump memory at sp=ffff800080883a90: ffff800080883a90: 80883ac0 ffff8000 3d8e936c ffffbd5b ffff800080883aa0: 5833f000 ffff3580 00000001 00000000 ffff800080883ab0: 40299840 ffff3580 590dfa00 ffff3580 ffff800080883ac0: 80883b30 ffff8000 3d938b28 ffffbd5b ffff800080883ad0: 40877180 ffff3580 590dfa00 ffff3580 ffff800080883ae0: 4090f600 ffff3580 80883cb0 ffff8000 ffff800080883af0: 00000010 00000000 00000000 00000000 ffff800080883b00: 4090f700 ffff3580 00000001 00000000 Generally, we do not dump more than 64 KB memory. It is sufficient to print only the lower 16 bits of the address. dump memory at sp=ffff800080883a90: 3a90: 80883ac0 ffff8000 3d8e936c ffffbd5b 3aa0: 5833f000 ffff3580 00000001 00000000 3ab0: 40299840 ffff3580 590dfa00 ffff3580 3ac0: 80883b30 ffff8000 3d938b28 ffffbd5b 3ad0: 40877180 ffff3580 590dfa00 ffff3580 3ae0: 4090f600 ffff3580 80883cb0 ffff8000 3af0: 00000010 00000000 00000000 00000000 3b00: 4090f700 ffff3580 00000001 00000000 Another benefit of adding DUMP_PREFIX_ADDRESS_LOW16 is that we don't have to worry about %p outputting address as hashed value. Signed-off-by: Zhen Lei Reviewed-by: Randy Dunlap --- include/linux/printk.h | 1 + lib/hexdump.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/linux/printk.h b/include/linux/printk.h index 8ef499ab3c1ed2e..ccad9e8eaaf0c31 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -704,6 +704,7 @@ extern const struct file_operations kmsg_fops; enum { DUMP_PREFIX_NONE, DUMP_PREFIX_ADDRESS, + DUMP_PREFIX_ADDRESS_LOW16, DUMP_PREFIX_OFFSET }; extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, diff --git a/lib/hexdump.c b/lib/hexdump.c index 1064706d57c15ed..9458738de397e84 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -281,6 +281,10 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, printk("%s%s%p: %s\n", level, prefix_str, ptr + i, linebuf); break; + case DUMP_PREFIX_ADDRESS_LOW16: + printk("%s%s%04lx: %s\n", level, + prefix_str, 0xffff & (unsigned long)(ptr + i), linebuf); + break; case DUMP_PREFIX_OFFSET: if (!width) { unsigned long tmp = len - 1; /* offset start from 0, so minus 1 */