From nobody Fri Apr 18 14:36:57 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZfHQf24FLz5stWG; Fri, 18 Apr 2025 14:36:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZfHQd6T7Fz3KGD; Fri, 18 Apr 2025 14:36:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744987017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=G21ZZM/ohXObVRcXAczoeIqgBq1icpUnsBB+f0c/W28=; b=oBnr/rrKvkYzsiRzBKacLiJPXeHhwR20d+012X55m4QNAZvxxmDwWsW4Js/64Q3MhESRwl AR9c5AL8RkVt6jMAw4ofHOzUq9aCrWX19ecyg7apTV1WgsWZq4vY46omVpfegQDiIssbV0 Ty3v5iqachcoK6+MMsv5vYEEd1rN6zwBBIOKRoF3JCx7nO1ojpJ+om0GZY+N0lN1n8hWLO ZGou4DE6HWgF+h+yrOVkZn9cTNw7ZYCF/KyqfV+mIkfxp8b7p1a2+okycZVm1U2s22ql4n H/42QMNR5GbgFUNH+RZ6PLM2TktHS+wn43ziGr93nlao0VgUs4+PmEMku8yn/A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744987017; a=rsa-sha256; cv=none; b=c8+VLIzxgehBjuP0Dcwlwa0ORdZ7nyBEU2vcDD2Df5C5h2GIojrif9JmdQC9ZX7CrWAUbh Wvc4c2L0NxA/qftuvaeSCdIOghDnEA/huSPirG1Y129qMCXz6L6T09emUujqA2ERn44jqP Mw/i6kjsBYPAj3j+G/QqWxGszu5YCpeogck7KBcDRYv8ZJ+5TGfPCG+869bPafgZpOYdN+ BkpVr2Xb/IAhbf7jhV9hM1/AFoIB6LaYTwBRYlrCHFsd/z57KwsF1zRB/c0iIQC/oJhhFb 37xDDXNeydOte9gE5o5otMvPGx3Bcp73QuPGaj+op1hGJd1VYVHbY99gjAMEQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744987017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=G21ZZM/ohXObVRcXAczoeIqgBq1icpUnsBB+f0c/W28=; b=OSsSwAbQNgI4SutaP2Hp7K+XhbVSGBs+0IUIgRxE5Bya9YXIEUYjDmWt2VuNidwykZCFsY 8TCzVOlSYnvcMVTv0gwcDc4aTtl0T54xARX1JySZDA6erxiH3IwX60Z1zJ3oH0luu/gxSj Bh0unqlc209tWI/6guaFwHYLg/Vg5ZWvOxDTeEshyyh2vUv0FEeP2qp4HXfD2EKt5s4LRl PjiXsV2i0gcjDkSVeZuPVX4Adhon0iOZauNfNb6e1EOir4rW2DvFdIbwYtVFjh+tf5ESe3 lxWvQJNdLq2t31O/UNdvfJmcWx/WDR/6ebZ6wDTj0x2zJakuotNioZuxj9L3tg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZfHQd62Zhzf3p; Fri, 18 Apr 2025 14:36:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53IEavOB091302; Fri, 18 Apr 2025 14:36:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53IEaveQ091299; Fri, 18 Apr 2025 14:36:57 GMT (envelope-from git) Date: Fri, 18 Apr 2025 14:36:57 GMT Message-Id: <202504181436.53IEaveQ091299@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 719721ca4b4e - stable/14 - LinuxKPI: add seq_hex_dump() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 719721ca4b4e03f9e4945fb6ba31a18023a45a0c Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=719721ca4b4e03f9e4945fb6ba31a18023a45a0c commit 719721ca4b4e03f9e4945fb6ba31a18023a45a0c Author: Bjoern A. Zeeb AuthorDate: 2025-04-02 18:06:05 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-04-18 14:35:58 +0000 LinuxKPI: add seq_hex_dump() Move the implementation of print_hex_dump() into linux_compat.c as lkpi_hex_dump() taking an extra function pointer and argument. Add two internal wrappers for printf and sbuf_printf to get a common function definition (sbuf_printf takes the extra argument). Use these to implement print_hex_dump() and the newly added seq_hex_dump(). This allows us to re-use the same implementation of print_hex_dump() for both functions without duplicating the code. Initial implementation: D49381 by dumbbell Sponsored by: The FreeBSD Foundation Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D49637 (cherry picked from commit 4359672e656af5e6758d0aae147212e58f445f5b) --- sys/compat/linuxkpi/common/include/linux/printk.h | 54 +++------------ .../linuxkpi/common/include/linux/seq_file.h | 14 ++++ sys/compat/linuxkpi/common/src/linux_compat.c | 80 ++++++++++++++++++++++ 3 files changed, 102 insertions(+), 46 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/printk.h b/sys/compat/linuxkpi/common/include/linux/printk.h index 3840a6e5fb8a..da9d45122d4d 100644 --- a/sys/compat/linuxkpi/common/include/linux/printk.h +++ b/sys/compat/linuxkpi/common/include/linux/printk.h @@ -44,57 +44,19 @@ enum { DUMP_PREFIX_OFFSET }; +int __lkpi_hexdump_printf(void *, const char *, ...) __printflike(2, 3); + +void lkpi_hex_dump(int(*)(void *, const char *, ...), void *arg1, + const char *, const char *, const int, const int, const int, + const void *, size_t, const bool); + static inline void print_hex_dump(const char *level, const char *prefix_str, const int prefix_type, const int rowsize, const int groupsize, const void *buf, size_t len, const bool ascii) { - typedef const struct { long long value; } __packed *print_64p_t; - typedef const struct { uint32_t value; } __packed *print_32p_t; - typedef const struct { uint16_t value; } __packed *print_16p_t; - const void *buf_old = buf; - int row; - - while (len > 0) { - if (level != NULL) - printf("%s", level); - if (prefix_str != NULL) - printf("%s ", prefix_str); - - switch (prefix_type) { - case DUMP_PREFIX_ADDRESS: - printf("[%p] ", buf); - break; - case DUMP_PREFIX_OFFSET: - printf("[%#tx] ", ((const char *)buf - - (const char *)buf_old)); - break; - default: - break; - } - for (row = 0; row != rowsize; row++) { - if (groupsize == 8 && len > 7) { - printf("%016llx ", ((print_64p_t)buf)->value); - buf = (const uint8_t *)buf + 8; - len -= 8; - } else if (groupsize == 4 && len > 3) { - printf("%08x ", ((print_32p_t)buf)->value); - buf = (const uint8_t *)buf + 4; - len -= 4; - } else if (groupsize == 2 && len > 1) { - printf("%04x ", ((print_16p_t)buf)->value); - buf = (const uint8_t *)buf + 2; - len -= 2; - } else if (len > 0) { - printf("%02x ", *(const uint8_t *)buf); - buf = (const uint8_t *)buf + 1; - len--; - } else { - break; - } - } - printf("\n"); - } + lkpi_hex_dump(__lkpi_hexdump_printf, NULL, level, prefix_str, prefix_type, + rowsize, groupsize, buf, len, ascii); } static inline void diff --git a/sys/compat/linuxkpi/common/include/linux/seq_file.h b/sys/compat/linuxkpi/common/include/linux/seq_file.h index d8b327f59538..876ef9e8dfe5 100644 --- a/sys/compat/linuxkpi/common/include/linux/seq_file.h +++ b/sys/compat/linuxkpi/common/include/linux/seq_file.h @@ -28,9 +28,13 @@ #ifndef _LINUXKPI_LINUX_SEQ_FILE_H_ #define _LINUXKPI_LINUX_SEQ_FILE_H_ +#include +#include + #include #include #include +#include #undef file #define inode vnode @@ -89,6 +93,16 @@ void lkpi_seq_printf(struct seq_file *m, const char *fmt, ...); #define seq_vprintf(...) lkpi_seq_vprintf(__VA_ARGS__) #define seq_printf(...) lkpi_seq_printf(__VA_ARGS__) +int __lkpi_hexdump_sbuf_printf(void *, const char *, ...) __printflike(2, 3); + +static inline void +seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, + int rowsize, int groupsize, const void *buf, size_t len, bool ascii) +{ + lkpi_hex_dump(__lkpi_hexdump_sbuf_printf, m->buf, NULL, prefix_str, prefix_type, + rowsize, groupsize, buf, len, ascii); +} + #define file linux_file #endif /* _LINUXKPI_LINUX_SEQ_FILE_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index a30523e88864..a2c2d18c8185 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -95,6 +95,8 @@ #include #include #include +#include +#include #if defined(__i386__) || defined(__amd64__) #include @@ -1917,6 +1919,84 @@ kasprintf(gfp_t gfp, const char *fmt, ...) return (p); } +int +__lkpi_hexdump_printf(void *arg1 __unused, const char *fmt, ...) +{ + va_list ap; + int result; + + va_start(ap, fmt); + result = vprintf(fmt, ap); + va_end(ap); + return (result); +} + +int +__lkpi_hexdump_sbuf_printf(void *arg1, const char *fmt, ...) +{ + va_list ap; + int result; + + va_start(ap, fmt); + result = sbuf_vprintf(arg1, fmt, ap); + va_end(ap); + return (result); +} + +void +lkpi_hex_dump(int(*_fpf)(void *, const char *, ...), void *arg1, + const char *level, const char *prefix_str, + const int prefix_type, const int rowsize, const int groupsize, + const void *buf, size_t len, const bool ascii) +{ + typedef const struct { long long value; } __packed *print_64p_t; + typedef const struct { uint32_t value; } __packed *print_32p_t; + typedef const struct { uint16_t value; } __packed *print_16p_t; + const void *buf_old = buf; + int row; + + while (len > 0) { + if (level != NULL) + _fpf(arg1, "%s", level); + if (prefix_str != NULL) + _fpf(arg1, "%s ", prefix_str); + + switch (prefix_type) { + case DUMP_PREFIX_ADDRESS: + _fpf(arg1, "[%p] ", buf); + break; + case DUMP_PREFIX_OFFSET: + _fpf(arg1, "[%#tx] ", ((const char *)buf - + (const char *)buf_old)); + break; + default: + break; + } + for (row = 0; row != rowsize; row++) { + if (groupsize == 8 && len > 7) { + _fpf(arg1, "%016llx ", ((print_64p_t)buf)->value); + buf = (const uint8_t *)buf + 8; + len -= 8; + } else if (groupsize == 4 && len > 3) { + _fpf(arg1, "%08x ", ((print_32p_t)buf)->value); + buf = (const uint8_t *)buf + 4; + len -= 4; + } else if (groupsize == 2 && len > 1) { + _fpf(arg1, "%04x ", ((print_16p_t)buf)->value); + buf = (const uint8_t *)buf + 2; + len -= 2; + } else if (len > 0) { + _fpf(arg1, "%02x ", *(const uint8_t *)buf); + buf = (const uint8_t *)buf + 1; + len--; + } else { + break; + } + } + _fpf(arg1, "\n"); + } +} + static void linux_timer_callback_wrapper(void *context) {