Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp715547rdb; Thu, 18 Jan 2024 17:36:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHK7wvVRngCfCbDiIDRTWwxjb/I/NYBNVxFBcP7C2sCvNoKiX9AouBRFAJaP9Q+M1O2ebYk X-Received: by 2002:a17:902:f80d:b0:1d4:5fdb:59ff with SMTP id ix13-20020a170902f80d00b001d45fdb59ffmr1778655plb.136.1705628195305; Thu, 18 Jan 2024 17:36:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705628195; cv=pass; d=google.com; s=arc-20160816; b=VlOwMjxICOoTBeC8hI3GZZ+nAIKN876jgrcT68tsVelEelx57rLUr77vYuEYuhaJyp rL1KL8oLVEBRgBeVC9l5SVctSMirjMfoU/KG3eSXrgv8HSpONJqAr1zVRCYSY5lObMA9 H61wShiUlQT6eVWgShljWyJ0k/vXMEaIzzGm9qQQvfOcjbooMhWt123Z5TDyQC5uCC8F AU6HTg/Cfj1NPC29htO9v7IB6VknM9WhXUFEPrHfab//d/7nB3uBM05Z1SwJPqhHyKj2 ZLIaaUYuSLIVvpxh3OaeeQvQohlbTiKDuc4U0rNCQDMfEbVYmlIIQhZcWSS7Dj5LLVxd 6tTA== 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; bh=mB3qy6uaaNqhA7Jj75BSZCwK3GeJXR+T54RmoHlqzyM=; fh=Us/DORbzHj5XmgnBeJW+VlCBdo2pSXKHAejHonylCvY=; b=iQgtPBQJCte6Bsqj6neya4PgOuwGai5MgtjK5gDw6h3KvvLzlZcB/F5LyRvGcP+mpv Z3F5I3g6bSryFXkf0YncAF41E429j2EzvyjWBi1rwPWRVxBNDAttxgGFvQbBrn1WnKTz WOPKOD1ad5Vi1Z/N/y519udOgrd2TJJZggLHwVrK+Nd8rAg1g1CddXTHiTSz7oeFXKuY ixnUIn8RrpV2/RWXtCOr8IOynVxCTdLfXDJSo73k8j2nk8xQ5xy6J3Qllyz08CJRw8Hh hFMDugGMd9uo+sCuH3k73SHpkxBSHqf8MU0gcxEuTb7yAF7GnQmfmcOzNl3X+3YcFdIs EwXw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-30686-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30686-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y20-20020a170902ed5400b001d6ffb2668esi2313233plb.570.2024.01.18.17.36.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 17:36:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30686-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-30686-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30686-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4D7A6B2291E for ; Fri, 19 Jan 2024 01:36:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFBE7186F; Fri, 19 Jan 2024 01:36:20 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC54BECE; Fri, 19 Jan 2024 01:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705628180; cv=none; b=mL2Aa8oGG7Arg+B0ODLwYrGtZJXlxv9fwVpFPiMmruRUkeDqwKRygUsNhiCorU5DZZcpExd2Pr5GMaxZVbknr71jOl3OeD0evrtmpulhPQYevEjx7VfmlVvQEwOJ7WHYM+y+FXW/WevKdwWePemDr8UWtYvmsiSAgFhczS0226s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705628180; c=relaxed/simple; bh=K1XydoNo9p2aYOEQJT2vpbYUCm3g6AGCAQTIxql3fBM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gEkXP+1dDjuZRGFsfXGu3/xrYkkp2DFCY7hDozlfcTV33egpVDWFCCT9X/IeLDOmgmen9Ilau/h+rHfR0cScZAsmwcfQDpJAfH1GYsZF4S49DKdiBwrVgavCDjsLIICtUoya91a9SVaK9hyq1t0/wd8apPc6NowBngX++FWcMlA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TGMbv5TBDz29kHW; Fri, 19 Jan 2024 09:34:35 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 566181404F1; Fri, 19 Jan 2024 09:36:15 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 19 Jan 2024 09:36:14 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH 1/3] tracing/probes: support '%pd' type for print struct dentry's name Date: Fri, 19 Jan 2024 09:38:46 +0800 Message-ID: <20240119013848.3111364-2-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240119013848.3111364-1-yebin10@huawei.com> References: <20240119013848.3111364-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500010.china.huawei.com (7.192.105.118) Similar to '%pd' for printk, use 'pd' for print struct dentry's name. Signed-off-by: Ye Bin --- kernel/trace/trace_probe.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 4dc74d73fc1d..460f98b85b1c 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -11,6 +11,7 @@ */ #define pr_fmt(fmt) "trace_probe: " fmt +#include #include #include "trace_btf.h" @@ -86,6 +87,8 @@ static const struct fetch_type probe_fetch_types[] = { "__data_loc char[]"), __ASSIGN_FETCH_TYPE("symstr", string, string, sizeof(u32), 1, 1, "__data_loc char[]"), + __ASSIGN_FETCH_TYPE("pd", string, string, sizeof(u32), 1, 1, + "__data_loc char[]"), /* Basic types */ ASSIGN_FETCH_TYPE(u8, u8, 0), ASSIGN_FETCH_TYPE(u16, u16, 0), @@ -1090,6 +1093,25 @@ static int __parse_bitfield_probe_arg(const char *bf, return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0; } +static char* traceprobe_expand_dentry(const char *argv) +{ + #define DENTRY_EXPAND_LEN 7 /* +0xXX() */ + char *new_argv; + int len = strlen(argv) + 1 + DENTRY_EXPAND_LEN; + + new_argv = kmalloc(len, GFP_KERNEL); + if (!new_argv) + return NULL; + + if (snprintf(new_argv, len, "+0x%lx(%s)", + offsetof(struct dentry, d_name.name), argv) >= len) { + kfree(new_argv); + return NULL; + } + + return new_argv; +} + /* String length checking wrapper */ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, struct probe_arg *parg, @@ -1099,6 +1121,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, char *t, *t2, *t3; int ret, len; char *arg; + char *org_arg = NULL; arg = kstrdup(argv, GFP_KERNEL); if (!arg) @@ -1182,6 +1205,16 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, parg->count); } + if (!strcmp("pd", parg->type->name)) { + char *temp; + + temp = traceprobe_expand_dentry(arg); + if (!temp) + goto out; + org_arg = arg; + arg = temp; + } + code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL); if (!code) goto out; @@ -1243,6 +1276,10 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, goto fail; } } + + if (!strcmp(parg->type->name, "pd")) + code++; + /* If op == DEREF, replace it with STRING */ if (!strcmp(parg->type->name, "ustring") || code->op == FETCH_OP_UDEREF) @@ -1321,6 +1358,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, kfree(tmp); out: kfree(arg); + kfree(org_arg); return ret; } -- 2.31.1