Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp937564lqp; Thu, 21 Mar 2024 23:42:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW6nPvSHB/+qNgrV8ay+KGqk5c0qaoiwA3tOlFWCllCB1zuXiG+axM8bE9wI2MtjJpVioYb2vq4SJI8JbDMgtbOJFJBMmvmAMyT+4lnew== X-Google-Smtp-Source: AGHT+IE2FMqcY8bgbHYLPKZUtQwoYdP6c0j7rwTVmYmapEagBVACb6WaF/PeZ4BQnI8pg5z4Puel X-Received: by 2002:a0d:f6c5:0:b0:60f:bb2f:b6c5 with SMTP id g188-20020a0df6c5000000b0060fbb2fb6c5mr1500175ywf.27.1711089735112; Thu, 21 Mar 2024 23:42:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711089735; cv=pass; d=google.com; s=arc-20160816; b=MI0Mdm0MtFGyHms3BGrAGZft4YXH82ku/7Xht3mEJNTLV8cB8yokgu4NzPuM8dFOnD 7cRXM4HzDSkHYEnTX3MbsnnHKdkuhveFK/qMTr1Xy7/VpsTOlJEn0fUjvyc4C9HIiZgl U1CI4rMzMC380pcIbLiQv9B5drFuFy8OZprahRmMdNja/WWwrAQErgMYRMviVu7g8ch5 xkRG8muGDmxJxu0hvhaYW9/dr61Sm7sB7/yLaIiuStMNVxV1XpHi+LzWmAeF08Oyy0/1 Eu1/lLuSXHRQHc45CSZiAph3gf4YW+4tp7TVvKcK9IweYmYysm5ksN0DzTfLTfGfVTok J7Sw== 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=lBlUnUS1KLqt94ROFwoC7xTzlJwoAz8RuBo8YrtSps4=; fh=Us/DORbzHj5XmgnBeJW+VlCBdo2pSXKHAejHonylCvY=; b=WcW/AUmMMfxkUg0MFqmgC7LyLq1FIu21aqKgk5Yt+bFLI5d+6FNjZwK5We43l7L6TA Smx7kf5oMLpdfOhEAWEDcTPQukn8iEcxa6l8teJ/L4nJBdaSqMwi18cu7gq9wUYNGsAv FkzGfwrGyAx7m933R2yhz3OvZWHkVpPD4Jgt/6XMUu5anQrLugIcLzV0eTjpPHSU3cVV fgWr4YuNYcg1HJ0eJfDDJkcX7BKaqbfUL8WueIjmsh4F3udZK3Dhves4/RnpqRpu//Vl 76UBHxwP02mM9K3I8HqGNxDHOmAolYCHO/k5PSILtyNeQ7++Z/uFUKF6WBWxlwmcwFDC yO9g==; dara=google.com 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-111010-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111010-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l8-20020a05622a050800b004311df318a7si1370059qtx.464.2024.03.21.23.42.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 23:42:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111010-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-111010-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111010-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id F0F851C2378A for ; Fri, 22 Mar 2024 06:42:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB075D51A; Fri, 22 Mar 2024 06:42:02 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 5009912E4E; Fri, 22 Mar 2024 06:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711089722; cv=none; b=D0cfg3sLuy3QZZ39oxRUdcFuXE9jejnmP4r51cxc7XWdITYotwOgvmgjI04DsezUPhGiI9IzaceJwkVbD7j6AqTD1udZ9N6SjWuIx1fI/Qc14rifa3ObQrEivLzVzTk136hMeD328S5wEg0FAm4ua3Jgw7hwiJfNR16vxUehJqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711089722; c=relaxed/simple; bh=ABUHxKws4avAJz+YGWjTdqpUD07z3KyEgfMh8LEm8rw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dFia2xjV7YxubNOnojJjhixfW+DQ6qw7E7IOn2rQ0yLhzAn/y9/Gb64TICFtwd7VAv3YoAbaY6UVm5NgS4rTiAnrKSbihFq+vB/5I2UyIW3WM6uSra8kTMVHuXoF/SifDJ829jijHD3Oj7LtbJ62qFOZiood7pBlu1m5KZaXOdA= 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.188 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.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4V1CNQ3994zXjTV; Fri, 22 Mar 2024 14:39:18 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id BDADC140336; Fri, 22 Mar 2024 14:41:57 +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_256_GCM_SHA384) id 15.1.2507.35; Fri, 22 Mar 2024 14:41:57 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v8 2/5] tracing/probes: support '%pD' type for print struct file's name Date: Fri, 22 Mar 2024 14:43:05 +0800 Message-ID: <20240322064308.284457-3-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240322064308.284457-1-yebin10@huawei.com> References: <20240322064308.284457-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: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) As like previous patch, this patch support print type '%pD' for print file's name. For example "name=$arg1:%pD" casts the `$arg1` as (struct file*), dereferences the "file.f_path.dentry.d_name.name" field and stores it to "name" argument as a kernel string. Here is an example: [tracing]# echo 'p:testprobe vfs_read name=$arg1:%pD' > kprobe_event [tracing]# echo 1 > events/kprobes/testprobe/enable [tracing]# grep -q "1" events/kprobes/testprobe/enable [tracing]# echo 0 > events/kprobes/testprobe/enable [tracing]# grep "vfs_read" trace | grep "enable" grep-15108 [003] ..... 5228.328609: testprobe: (vfs_read+0x4/0xbb0) name="enable" Note that this expects the given argument (e.g. $arg1) is an address of struct file. User must ensure it. Signed-off-by: Ye Bin --- kernel/trace/trace.c | 2 +- kernel/trace/trace_probe.c | 57 +++++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index ac26b8446337..831dfd0773a4 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5510,7 +5510,7 @@ static const char readme_msg[] = "\t +|-[u](), \\imm-value, \\\"imm-string\"\n" "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, char, string, symbol,\n" "\t b@/, ustring,\n" - "\t symstr, %pd, \\[\\]\n" + "\t symstr, %pd/%pD, \\[\\]\n" #ifdef CONFIG_HIST_TRIGGERS "\t field: ;\n" "\t stype: u8/u16/u32/u64, s8/s16/s32/s64, pid_t,\n" diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index a27567e16c36..7bfc6c0d5436 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -12,6 +12,7 @@ #define pr_fmt(fmt) "trace_probe: " fmt #include +#include #include "trace_btf.h" #include "trace_probe.h" @@ -1581,35 +1582,47 @@ int traceprobe_expand_dentry_args(int argc, const char *argv[], char **buf) used = 0; for (i = 0; i < argc; i++) { - if (glob_match("*:%pd", argv[i])) { - char *tmp; - char *equal; - - if (!tmpbuf) { - tmpbuf = kmalloc(bufsize, GFP_KERNEL); - if (!tmpbuf) - return -ENOMEM; - } + char *tmp; + char *equal; + size_t arg_len; - tmp = kstrdup(argv[i], GFP_KERNEL); - if (!tmp) - goto nomem; + if (!glob_match("*:%p[dD]", argv[i])) + continue; - equal = strchr(tmp, '='); - if (equal) - *equal = '\0'; - tmp[strlen(argv[i]) - 4] = '\0'; + if (!tmpbuf) { + tmpbuf = kmalloc(bufsize, GFP_KERNEL); + if (!tmpbuf) + return -ENOMEM; + } + + tmp = kstrdup(argv[i], GFP_KERNEL); + if (!tmp) + goto nomem; + + equal = strchr(tmp, '='); + if (equal) + *equal = '\0'; + arg_len = strlen(argv[i]); + tmp[arg_len - 4] = '\0'; + if (argv[i][arg_len - 1] == 'd') ret = snprintf(tmpbuf + used, bufsize - used, "%s%s+0x0(+0x%zx(%s)):string", equal ? tmp : "", equal ? "=" : "", offsetof(struct dentry, d_name.name), equal ? equal + 1 : tmp); - kfree(tmp); - if (ret >= bufsize - used) - goto nomem; - argv[i] = tmpbuf + used; - used += ret + 1; - } + else + ret = snprintf(tmpbuf + used, bufsize - used, + "%s%s+0x0(+0x%zx(+0x%zx(%s))):string", + equal ? tmp : "", equal ? "=" : "", + offsetof(struct dentry, d_name.name), + offsetof(struct file, f_path.dentry), + equal ? equal + 1 : tmp); + + kfree(tmp); + if (ret >= bufsize - used) + goto nomem; + argv[i] = tmpbuf + used; + used += ret + 1; } *buf = tmpbuf; -- 2.31.1