Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3726939rwb; Mon, 7 Aug 2023 19:51:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbuhhvfaYJGRaB+699BKBAKVDapzIJ7yfnGMnxCf5tTl+6Q0qeGU4Hv7bMJJxI+T5DF1oJ X-Received: by 2002:a17:90a:1787:b0:268:2b38:c9b0 with SMTP id q7-20020a17090a178700b002682b38c9b0mr8155154pja.0.1691463102100; Mon, 07 Aug 2023 19:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691463102; cv=none; d=google.com; s=arc-20160816; b=aor/J8XSpcdGfmt8YgL37C71fWvPFGHEvHvy1i5+vaQXkwOwCoyPxGb+yuBvYoXUOm 3pGq3Vsh6R5GlrlW6VfySGQprHZVkIdXfeAPmDmc/595OHTOCVmTfvX/r63aBQ48hFae sPkf2d84S/JDLBDGZ+gDue7Yn+D3STFLX5h1YfqfiOEYCBNYw1+0TgrmsZOpm+Mirgi3 DS98RhWvhyrjoJT/P2hPCf/qvjGEI0krJtX9lfpy611FOar+GRpk10JCu2KbVIoA8TSv XNZQeOtWB0+za5Y/SwfF0VbgpP+wgeDhRnoj08SlkG2uBequTbB/R+2gJirixjgpDFhF oidA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lt14-20020a17090b354e00b0026811da0fafsi6642182pjb.65.2023.08.07.19.51.30; Mon, 07 Aug 2023 19:51:42 -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 S231185AbjHHCmO (ORCPT + 99 others); Mon, 7 Aug 2023 22:42:14 -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 Content-Transfer-Encoding: 8bit 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 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 */ -- 2.34.1