From patchwork Sat Feb 10 23:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 199341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1701221dyd; Sat, 10 Feb 2024 15:55:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi/VDx4aooB3HAiUp6Y3YWEAv5+T0Rvnxc+TZKXCSuMb1Zx60/7YIdac6nRVikHywlkN6F X-Received: by 2002:a05:6402:c03:b0:561:998b:878f with SMTP id co3-20020a0564020c0300b00561998b878fmr102068edb.16.1707609304301; Sat, 10 Feb 2024 15:55:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707609304; cv=pass; d=google.com; s=arc-20160816; b=WH9ZQ9PtL8q3Is1RSOQAcdaSkh5bUQjW95XAghgGQB3TuXlh1Vvx6Nq6vsvWZMHIJP 90lzfw8wC36fRJQ10EIk1IXjGyIGruM9kYGwE0IoT7Ihr1FNQoyrwyj7BRyLeuHBuJXX PN91phEJ0WeCHht3EaFM9pbmfaqP0sZtE85nY6D9rLtBaeEF6czkgQZceEN6NnIIekej OutrS8Kj/5ds9mQHloEw8y0rVGHiV0Fz8ZIDd+BZ/TXLEIqQU2uk6r/2rWtDfpfm1qCc e+FE9dzeNzD6PIYEMYMv+jJ4DjNZel9GwBYRHNp1OVpUNpiptMTGBV9l7DtD37CImwRO n+NA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GcUhkZrXlF5pRwcMyaOQX2HOmfuyNRPW8LUolF8mADY=; fh=ejf5IFup4zu7PrZ8M0FHyAcUCWMQGMvAdoP67OO7Oi8=; b=CgYuV4AJMj9G7G6SGbri5+DzI9DBI0lTKdANTrqrm6GUGRCGqrYpd5ONmOH13xn2AV 7d4bxiYIBtZSMT9Htvit3DPP6LLjYgHrjqpNyy/6T5rUA45IX/gljNU9xPwBphtPTuXb HRB3qIHFcusaLw/hAXufyfnh9Aqva6nvWKGh3B/3ALu74uNhpvqe+ORmKMT31ov42BaX Gooa6dmhJTV8ddzTHTyUA4SlIBvIDyXeE2JXby9VAXA2HWuT1GPEJ1BlEdPhAyyQG3rm EXr+8PAnI1aQHvGb8ERk1z/MBpJ9W20IZFuPXIpT7iBC6kusFVI80x+htmTj23+cLMAR hsOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CPIYffui; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60600-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60600-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCWcug1pkFCzjU+oKIKu2+HlMTXFF+214eriOjn4aJzlJ+5izMIANtLvreDUz5UBvwETFv55+HGdGWCHz6PREWZn56En6A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r10-20020a05640251ca00b005619ccb4bddsi6568edd.612.2024.02.10.15.55.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 15:55:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60600-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CPIYffui; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60600-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60600-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BA47D1F21B8C for ; Sat, 10 Feb 2024 23:55:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C004F6216A; Sat, 10 Feb 2024 23:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CPIYffui" Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70B6C612EE for ; Sat, 10 Feb 2024 23:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707609061; cv=none; b=WlJjYXNwHQ5W2orhEPZ3FT22FWNrKBHGq5ggegtq9je7h4Xj6WpIvWfcaoCzHt2fOA0uT4LofAIC8WM7iQTNS2OaiziYnieeYVUyELYCMrStgh9PFGzPtBWxRpofmqDe3Atfe1O8vUIgNiVUPKTTfC1O1B6qZbUMfPiKMN+K6/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707609061; c=relaxed/simple; bh=xaGmcsjd+lkOWUksrw9hG2GtCYA1l7WNpGBbOaK1l7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nIuQW5U7xOIRYjA6wM5h34zUGDTAQJ1x4u3UMMZU1oo0CzK2o7pzQ2YzB8h4yRj8p8nScQdhC+6aU0ZXkJSwlPwjM5M3LMY5l2r21mJ6EAQORtLx0af3bDAS3afOR5qud1DHQhOU2xEs7STKPwcaqySbfSuLXzKsN7MmxZqggdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=CPIYffui; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5114cd44f6aso2840942e87.1 for ; Sat, 10 Feb 2024 15:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707609057; x=1708213857; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GcUhkZrXlF5pRwcMyaOQX2HOmfuyNRPW8LUolF8mADY=; b=CPIYffuiExah5o8/w1W4dH7kwyrLP8oCPHOTmz9hHRvAwYKIA12VgqBo5F7CBC5AHC 1xKmAuRwCTsFPGDgIsWFyU3NzYfCMhA0ortwVZdcTkb8Hc02fIH3I6XU0DqEcJaE/l2i Vo/4NhwNW0g2/bwKTKKaafMLja2804uFWFGAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707609057; x=1708213857; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GcUhkZrXlF5pRwcMyaOQX2HOmfuyNRPW8LUolF8mADY=; b=V48JXzB0tsjfIej67/ES25qaGLMzyHAXh0Uy6OmLWCFOtQTfNjsdpTw0z8dkTMwvd/ faxsPgC55PRcBmIhbOfeYVxlFleLx9I5gB3MZ9BtHAeK21s7DsY/vIEkfJx3wsuWaFGd 0m7t2fI9IlIBj2pydDfeHqrFiN085K2NSlqxckyhasdKLOQ5t7TH3GjVfPqtsv8r4uMr mVVQypyV8QIqjHR71ypeV5bauEPbCMcJ6DlDcGTX8VC2k+cWx5Z8coBj7EHXhnZCeMzK +jr66s/TydiM+rOkaqqbq+X4cscCO4hiripAxMxkT4fyBWvpm0f7m4gKMvfs53YxdwR5 6/9A== X-Gm-Message-State: AOJu0YzBTjNFSYRs/cRoeGXyK3Mbf2v+Hf1VgUjayoAift/8ZtVUIUV+ VLesPtpCuKcQUIg+buduXk0YKLEwIZE3DmYkFkNI5pLAccVI2nI3tByDKuBRzCnupM24f3aRZQ= = X-Received: by 2002:ac2:5eda:0:b0:511:55fb:2405 with SMTP id d26-20020ac25eda000000b0051155fb2405mr1659223lfq.50.1707609057566; Sat, 10 Feb 2024 15:50:57 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUMvMLuG7XWucjAH59S42BW92allZjpZHUiTZ04ZDytLeYM3qAkBnJsfwWB+mu9HTVVqkcciJ2PvdqAXL+Lw/CxLX016E2mfnFbGVXnY4elEdNKDkGpNxiUOYCSisgKf1x8g/1rvNOyPKkE7awdV/V2tNXIMG2+eX+vwEd0vj0I++44WalYTfoi/iz01iuR1a0rZc+lwoApvUQa1jeTb1+/LkdZtduzXmRkb0QP59tdOhrsYomvHmv8c1bwMsUTMrUWncRoVJiOLiQnvCIc/qA+VLmZ6SgoTbTSFzwVizQOyAQfL2y9lQp6EPli4UFC3Ij3o16Rw8+VofwvhZ+om7zvHg3Rg1sqrIHuXqKOzECasCWmLw56VaIkVsECEHXf2qNT4UfbAA2qgpA49xvATtvbzfeiMVoqfWFLEv3R7aiZBEs7BOWbzmOFFmklDvv7MGT8wmtLB+RZmmUpnMPYKMdjk82ZwKMCDAC0ZabHDlsdJcMq/Dv3jwUWxKyAWB2L0NbjC0Xhz7u09oheM4IgOzkEQCrUAACCyBEnNg9MmNx3rSju6D8riT7ffwLW2W1cxlSEwquJ5ugc8Ok5p9QiHTL9IdBfRru3ucbuEaCUhbERMoJCog== Received: from ukaszb-l.roam.corp.google.com (alfa56.extreme-net.one.pl. [213.77.89.56]) by smtp.gmail.com with ESMTPSA id o27-20020a056512051b00b0051179ae1846sm365561lfb.280.2024.02.10.15.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 15:50:57 -0800 (PST) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Jason Baron , Jim Cromie , Greg Kroah-Hartman , Andrew Morton , Kees Cook , Douglas Anderson Cc: Guenter Roeck , Yaniv Tzoreff , Benson Leung , Steven Rostedt , Vincent Whitchurch , Pekka Paalanen , Sean Paul , Daniel Vetter , Simon Ser , John Ogness , Petr Mladek , Sergey Senozhatsky , linux-kernel@vger.kernel.org, upstream@semihalf.com Subject: [PATCH v4 17/39] dyndbg: add support for hex_dump output to trace Date: Sun, 11 Feb 2024 00:49:47 +0100 Message-ID: <20240210235009.2405808-18-ukaszb@chromium.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240210235009.2405808-1-ukaszb@chromium.org> References: <20240210235009.2405808-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790558134002340272 X-GMAIL-MSGID: 1790558134002340272 Add support for writing hex_dump debug logs to trace. Signed-off-by: Ɓukasz Bartosik Co-developed-by: Jim Cromie Signed-off-by: Jim Cromie --- include/linux/dynamic_debug.h | 16 ++++++++++------ lib/dynamic_debug.c | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index dc10c7535f13..76eec3f05be9 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -298,12 +298,16 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor, _dynamic_func_call(fmt, __dynamic_ibdev_dbg, \ dev, fmt, ##__VA_ARGS__) -#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ - groupsize, buf, len, ascii) \ - _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ - print_hex_dump, \ - KERN_DEBUG, prefix_str, prefix_type, \ - rowsize, groupsize, buf, len, ascii) +void _print_hex_dump(struct _ddebug *descriptor, const char *level, + const char *prefix_str, int prefix_type, int rowsize, + int groupsize, const void *buf, size_t len, bool ascii); + +#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + _dynamic_func_call(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ + _print_hex_dump, \ + KERN_DEBUG, prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii) /* for test only, generally expect drm.debug style macro wrappers */ #define __pr_debug_cls(cls, fmt, ...) do { \ diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index d379e05837be..dbae1ed6ab5b 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -1377,6 +1377,42 @@ static void ddebug_dev_printk(struct _ddebug *desc, const struct device *dev, } } +void _print_hex_dump(struct _ddebug *descriptor, const char *level, + const char *prefix_str, int prefix_type, int rowsize, + int groupsize, const void *buf, size_t len, bool ascii) +{ + const u8 *ptr = buf; + int i, linelen, remaining = len; + unsigned char linebuf[32 * 3 + 2 + 32 + 1]; + + if (rowsize != 16 && rowsize != 32) + rowsize = 16; + + for (i = 0; i < len; i += rowsize) { + linelen = min(remaining, rowsize); + remaining -= rowsize; + + hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, + linebuf, sizeof(linebuf), ascii); + + switch (prefix_type) { + case DUMP_PREFIX_ADDRESS: + ddebug_printk(descriptor, KERN_DEBUG "%s%s%p: %s\n", + level, prefix_str, ptr + i, linebuf); + break; + case DUMP_PREFIX_OFFSET: + ddebug_printk(descriptor, KERN_DEBUG "%s%s%.8x: %s\n", + level, prefix_str, i, linebuf); + break; + default: + ddebug_printk(descriptor, KERN_DEBUG "%s%s%s\n", + level, prefix_str, linebuf); + break; + } + } +} +EXPORT_SYMBOL(_print_hex_dump); + void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) { va_list args;