From patchwork Mon Jan 22 07:40:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 13524888 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 2319D16416; Mon, 22 Jan 2024 07:37:49 +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=1705909072; cv=none; b=tCJpB3ZWssMxwMwmSiSpq/4HokrxhUzH4LgVxw6N2X8Fqutv/2JY5GIb4wMrU7b8HlGHBi3u2BwjTgUFFMQEqqJHolhp/QA/eOEH6gUWiSo9TkP/GgjkPHchobEiBKZjZgcQAfytMnblyLOEOOJXOwwsg4QPgxWQG6mA4yJTevo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909072; c=relaxed/simple; bh=sBwc0e0LX68ujIGPPtdpEdCtFeOhchnf4ztfTmcCrW4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PqdnJLFmR2y4yr6IFpsaa/yKHdTSXPzt3OZqQYX9CUSh8sw5QdTNl2T7fct/lxsUj66XLtH47+7utJiXYORZNx5BSTyOXtgMNRSOsgD1/hmDTl5dJpU+sn70ozaFgIDgu9NG9Z1uqGmlHcxpiZgS1pnXZ3tTfsim5bhHxPrf+jk= 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.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TJMVC181kzVjFn; Mon, 22 Jan 2024 15:36:35 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 49E9D1400E4; Mon, 22 Jan 2024 15:37:44 +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; Mon, 22 Jan 2024 15:37:39 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v2 1/7] string.h: add str_has_suffix() helper for test string ends with specify string Date: Mon, 22 Jan 2024 15:40:09 +0800 Message-ID: <20240122074015.4042575-2-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240122074015.4042575-1-yebin10@huawei.com> References: <20240122074015.4042575-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) str_has_suffix() is test string if ends with specify string. Signed-off-by: Ye Bin --- include/linux/string.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 433c207a01da..e47e9597af27 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -405,4 +405,24 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix return strncmp(str, prefix, len) == 0 ? len : 0; } +/** + * str_has_suffix - Test if a string has a given suffix + * @str: The string to test + * @suffix: The string to see if @str ends with + * + * Returns: + * * strlen(@suffix) if @str ends with @suffix + * * 0 if @str does not end with @suffix + */ +static __always_inline size_t str_has_suffix(const char *str, const char *suffix) +{ + size_t len = strlen(suffix); + size_t str_len = strlen(str); + + if (len > str_len) + return 0; + + return strncmp(str + str_len - len, suffix, len) == 0 ? len : 0; +} + #endif /* _LINUX_STRING_H_ */ From patchwork Mon Jan 22 07:40:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 13524890 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 BBC6320DEB; Mon, 22 Jan 2024 07:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909092; cv=none; b=QGCbOWPwmdFdcta/nVwjTdDYTlf2hLCKYITdeuKLIyKDuSgQMPS+0FXnayJqAyDp0X4eGuwLZLYdww1+gE5lLhyhCtGK8GfoPlm+9dC2FPPxAIr+eOQIwoGocboMGPdtjfB5TklS2CmfL889Px+L9JV//iWo2DPzda9c70jcOdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909092; c=relaxed/simple; bh=uRi7b/OnTFYE7tce+ThtNtXL9uYhQDA1900RsEUwyxY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kYJn2o4tGNAsHEab20yi+4Bj2khaofXAdKFOWQEtDlrNXJ3oozQm+P7gtwR3dulFs5+OxX3J0Jk4TcsQv6FptQ5V74Ko67YH5aQKBd/oxIWIpeAVRobippb5Z0o/BHDlNwzrB5ZjjbRASMgT1jN/MHpMVCDJ0rkt0YRD4+1zhjI= 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.35 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.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TJMV02SKYz1S5NB; Mon, 22 Jan 2024 15:36:24 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 1DE4C1A0179; Mon, 22 Jan 2024 15:37:52 +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; Mon, 22 Jan 2024 15:37:39 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v2 2/7] tracing/probes: add traceprobe_expand_dentry_args() helper Date: Mon, 22 Jan 2024 15:40:10 +0800 Message-ID: <20240122074015.4042575-3-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240122074015.4042575-1-yebin10@huawei.com> References: <20240122074015.4042575-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) Add traceprobe_expand_dentry_args() to expand dentry args. this API is prepare to support "%pd" print format for kprobe. Signed-off-by: Ye Bin --- kernel/trace/trace_probe.c | 34 ++++++++++++++++++++++++++++++++++ kernel/trace/trace_probe.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 4dc74d73fc1d..1599c0c3e6b7 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1565,6 +1565,40 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[], return ERR_PTR(ret); } +int traceprobe_expand_dentry_args(int argc, const char *argv[], char *buf, + int bufsize) +{ + int i, used, ret; + + used = 0; + for (i = 0; i < argc; i++) { + if (str_has_suffix(argv[i], ":%pd")) { + char *tmp = kstrdup(argv[i], GFP_KERNEL); + char *equal; + + if (!tmp) + return -ENOMEM; + + equal = strchr(tmp, '='); + if (equal) + *equal = '\0'; + tmp[strlen(argv[i]) - 4] = '\0'; + ret = snprintf(buf + 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) + return -ENOMEM; + argv[i] = buf + used; + used += ret + 1; + } + } + + return 0; +} + void traceprobe_finish_parse(struct traceprobe_parse_context *ctx) { clear_btf_context(ctx); diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 850d9ecb6765..553371a4e0b1 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -402,6 +402,8 @@ extern int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char **traceprobe_expand_meta_args(int argc, const char *argv[], int *new_argc, char *buf, int bufsize, struct traceprobe_parse_context *ctx); +extern int traceprobe_expand_dentry_args(int argc, const char *argv[], char *buf, + int bufsize); extern int traceprobe_update_arg(struct probe_arg *arg); extern void traceprobe_free_probe_arg(struct probe_arg *arg); From patchwork Mon Jan 22 07:40:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 13524891 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 9BBDE17BD1; Mon, 22 Jan 2024 07:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909121; cv=none; b=mrnDj/orcNUxuyXyEcY1m91zBs2Q93Z0nHXeQqo+J4FsGUTfTe8YgJLhMwynnrT5Uyx/C+JhOiRpOv7Q7ge1Yrc4/ZbLhSYAdt8qfdWy1m3Bp9Z5n+MfggCBKxLzxk5Gd2apwqCOBJ200WCUzSIM4nruFdr8byQCwVHtawfXZng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909121; c=relaxed/simple; bh=R+0EqFIiGaBBpGCVcH0I4eW51HMRsop2Clw0T8UHkPY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G0dyfKuvKCnr8dr6e/eaJFAbxPO9sNiFgwdSLykWVsbBalLpbtJ/WYDr92oIGk50VfdKqHnDQSWlULQUkYlXi2pLb06Px1mYmLUItYwXUbIhmriVG4omiu4wPHi4/tdULIbhCaPRwVoLGRkevluTieVXqhvELKaEqnNloVCcgSA= 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.191 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.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TJMRY6CBkz1FJcT; Mon, 22 Jan 2024 15:34:17 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 24FAD1A0173; Mon, 22 Jan 2024 15:38:22 +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; Mon, 22 Jan 2024 15:37:39 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v2 3/7] tracing/probes: support '%pd' type for print struct dentry's name Date: Mon, 22 Jan 2024 15:40:11 +0800 Message-ID: <20240122074015.4042575-4-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240122074015.4042575-1-yebin10@huawei.com> References: <20240122074015.4042575-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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_kprobe.c | 6 ++++++ kernel/trace/trace_probe.h | 1 + 2 files changed, 7 insertions(+) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index c4c6e0e0068b..00b74530fbad 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -779,6 +779,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) char buf[MAX_EVENT_NAME_LEN]; char gbuf[MAX_EVENT_NAME_LEN]; char abuf[MAX_BTF_ARGS_LEN]; + char dbuf[MAX_DENTRY_ARGS_LEN]; struct traceprobe_parse_context ctx = { .flags = TPARG_FL_KERNEL }; switch (argv[0][0]) { @@ -930,6 +931,11 @@ static int __trace_kprobe_create(int argc, const char *argv[]) argv = new_argv; } + ret = traceprobe_expand_dentry_args(argc, argv, dbuf, + MAX_DENTRY_ARGS_LEN); + if (ret) + goto out; + /* setup a probe */ tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive, argc, is_return); diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 553371a4e0b1..d9c053824975 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -34,6 +34,7 @@ #define MAX_ARRAY_LEN 64 #define MAX_ARG_NAME_LEN 32 #define MAX_BTF_ARGS_LEN 128 +#define MAX_DENTRY_ARGS_LEN 256 #define MAX_STRING_SIZE PATH_MAX #define MAX_ARG_BUF_LEN (MAX_TRACE_ARGS * MAX_ARG_NAME_LEN) From patchwork Mon Jan 22 07:40:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 13524893 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 CE64A1BC49; Mon, 22 Jan 2024 07:38:59 +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=1705909142; cv=none; b=SyXAVt/fO1wyfCI7D2+0vEMvvLVMihNFkIks+GJ1DSif1kMDNr4xUs5Bed8QnQUgtROAehDU4rMrajCOkRxNG2Nuz0a8cYf1zlXPvD7swVRWj8Lm+/2JobXCvIx9fyHoz0UrzNGoK3CaJ+4kikanU84zWpNrFvelSHRi1eh7c5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909142; c=relaxed/simple; bh=76LvXPCu8lBDHJ52SEwVPpx3KQzmKFwc0Brqv+mwS0Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GkWuZBMlOMY6PJa/QfCFPg8wRvaevCLJYdrgGwFtq6NYiVgAMqMVVWCeEbaC85e7wEGiO34hjLBtOgUc0t8VhLGzubQVkdcr3EV3F5D2pZTJP4S6X/VzCBa9tXX7vYoE672K3D8BfTad+eONHcYlBirDbLfwpwLVA3tgZ554EwY= 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.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TJMVs57T3z29kf3; Mon, 22 Jan 2024 15:37:09 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 297FC1A017F; Mon, 22 Jan 2024 15:38:37 +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; Mon, 22 Jan 2024 15:37:40 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v2 4/7] tracing/probes: support '%pD' type for print struct file's name Date: Mon, 22 Jan 2024 15:40:12 +0800 Message-ID: <20240122074015.4042575-5-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240122074015.4042575-1-yebin10@huawei.com> References: <20240122074015.4042575-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) Similar to '%pD' for printk, use '%pD' for print struct file's name. Signed-off-by: Ye Bin --- kernel/trace/trace_probe.c | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 1599c0c3e6b7..f9819625de58 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" @@ -1572,28 +1573,38 @@ int traceprobe_expand_dentry_args(int argc, const char *argv[], char *buf, used = 0; for (i = 0; i < argc; i++) { - if (str_has_suffix(argv[i], ":%pd")) { - char *tmp = kstrdup(argv[i], GFP_KERNEL); - char *equal; + if (!str_has_suffix(argv[i], ":%pd") && + !str_has_suffix(argv[i], ":%pD")) + continue; - if (!tmp) - return -ENOMEM; + char *tmp = kstrdup(argv[i], GFP_KERNEL); + char *equal; + + if (!tmp) + return -ENOMEM; - equal = strchr(tmp, '='); - if (equal) - *equal = '\0'; - tmp[strlen(argv[i]) - 4] = '\0'; + equal = strchr(tmp, '='); + if (equal) + *equal = '\0'; + tmp[strlen(argv[i]) - 4] = '\0'; + if (argv[i][strlen(argv[i]) - 1] == 'd') ret = snprintf(buf + 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) - return -ENOMEM; - argv[i] = buf + used; - used += ret + 1; - } + else + ret = snprintf(buf + 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) + return -ENOMEM; + argv[i] = buf + used; + used += ret + 1; } return 0; From patchwork Mon Jan 22 07:40:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 13524895 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 7EFDA2FE15; Mon, 22 Jan 2024 07:39:09 +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=1705909151; cv=none; b=qq6Zdd0tKJuY7hM/e+6XpN57ayVYLvelhbk05Pqa4Jt1x2xtKqDtT7THOhK+C0M73jYPQjdcRlPpLJQ4SdaSbKGhqiYWCrIrIWXZS2+uE5wDsft1fyP1WkzX1TCWgQ6Te4L196kGXCNdINGEg00N6vkY8GaTLstNz9ES+nrQfsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909151; c=relaxed/simple; bh=ASkvNL+WBKTxbaQNMIjBmg1cXddIy1p77kjdfuRrvQo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rB43jXMgFN4Z2jGxKjBENo4UCtqsPHP1o7Sm6WVfGdXBXNjh9Mz/D/QqRwnCn6+jea36AWlX5KenmDd30+2W/G5IUURfhJoYJRYDC6VamjOXTixc9g/p84kxCthcdk9ff1ptXbBu/50Abahz0s8tvx1yrYDDpEoYZWOYyv5ab7c= 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.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TJMX905Vqz1xmYs; Mon, 22 Jan 2024 15:38:17 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 2D2B41A016B; Mon, 22 Jan 2024 15:38:52 +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; Mon, 22 Jan 2024 15:37:40 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v2 5/7] tracing: add new type "%pd/%pD" in readme_msg[] Date: Mon, 22 Jan 2024 15:40:13 +0800 Message-ID: <20240122074015.4042575-6-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240122074015.4042575-1-yebin10@huawei.com> References: <20240122074015.4042575-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) Signed-off-by: Ye Bin --- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 2a7c6fd934e9..13197d3b86bd 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5745,7 +5745,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, \\[\\]\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" From patchwork Mon Jan 22 07:40:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 13524892 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 CDB6A168AA; Mon, 22 Jan 2024 07:39: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=1705909142; cv=none; b=PU4CsH6YoOS1MtXlEfw8dNCvfxgrdPR39sCSgJkOwqnOs0OqsMbOWLNiBNMAYs5co9fMri2QFmbyM+TuX1buxWmiqe+VivYso/eJiGj97Q88OEV8ztXXQbyADE4wQ2Ge8fU4AzH6baPBj98WvX1/dlzbG6SbjE42BZyizNSUah8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909142; c=relaxed/simple; bh=IZ2ztT+g8180deg7EL3rrFcIgg1N/vQXRmntkTF7fOc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DQ6elbccLNCRkKTj1QRYWxlHcgDPb8pkrKKwBBx1kt7scfyAEnDZLcsH0QVwfo2KRcSGpTt4A8CRDyntrhLPfo5F4l9K0p+x2veUumpbvNzTWG2PrVSTfJJCcLPOdcrC75SJ6JSy4/Z5fXmcSCOPNAuHs9+3PA2NkSrTVVraOT4= 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.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TJMXX6lbvzbcGP; Mon, 22 Jan 2024 15:38:36 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id EB71D1850C9; Mon, 22 Jan 2024 15:38:58 +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; Mon, 22 Jan 2024 15:37:41 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v2 6/7] Documentation: tracing: add new type '%pd' and '%pD' for kprobe Date: Mon, 22 Jan 2024 15:40:14 +0800 Message-ID: <20240122074015.4042575-7-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240122074015.4042575-1-yebin10@huawei.com> References: <20240122074015.4042575-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) Similar to printk() '%pd' is for fetch dentry's name from struct dentry's pointer, and '%pD' is for fetch file's name from struct file's pointer. Signed-off-by: Ye Bin --- Documentation/trace/kprobetrace.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst index bf9cecb69fc9..a1d12d65a8dc 100644 --- a/Documentation/trace/kprobetrace.rst +++ b/Documentation/trace/kprobetrace.rst @@ -58,7 +58,8 @@ Synopsis of kprobe_events NAME=FETCHARG : Set NAME as the argument name of FETCHARG. FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types - (x8/x16/x32/x64), "char", "string", "ustring", "symbol", "symstr" + (x8/x16/x32/x64), VFS layer common type(%pd/%pD) for print + file name, "char", "string", "ustring", "symbol", "symstr" and bitfield are supported. (\*1) only for the probe on function entry (offs == 0). Note, this argument access @@ -113,6 +114,9 @@ With 'symstr' type, you can filter the event with wildcard pattern of the symbols, and you don't need to solve symbol name by yourself. For $comm, the default type is "string"; any other type is invalid. +VFS layer common type(%pd/%pD) is a special type, which fetches dentry's or +file's name from struct dentry's pointer or struct file's pointer. + .. _user_mem_access: User Memory Access From patchwork Mon Jan 22 07:40:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 13524894 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 505B120DD2; Mon, 22 Jan 2024 07:39:01 +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=1705909142; cv=none; b=Hspp8Q5IAi2WudvIkeq269z6y26HRRu95pIGGDjVUyHhHC9zrqp46/BagGJqrFQx2aoFMO7mIFENTuofCVDWwXECgcqln9QZyQrceISGy1xCerkcN0Y1qzJtx+nxp+IWTB++s1ka4EZa8ZghaeYzzER6FCwAvUtfIvne3g8GKko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705909142; c=relaxed/simple; bh=wqD3BcIyhEmryJcEFaCD5uVA14nzmG5cK5v0iik8hsM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R6Hs6jZDOlUuv9DNioAM5VfLJ5ZJ/Q0qB+BOdQ7erHeFQHdg2KOQrwOHZzVuAx1RZz5D5K4osUQRvV0pHw1e7mC1qZtHmFZghKCxBlSDHeosOmNKlZYT8IEjq3bcVeBWyBC2fostEGemuGJEyRWGVTVcMPUx/kPJDBxbCGf7Pws= 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.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TJMWd6s7LzVhkZ; Mon, 22 Jan 2024 15:37:49 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 0E1201850CA; Mon, 22 Jan 2024 15:38:59 +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; Mon, 22 Jan 2024 15:37:41 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v2 7/7] selftests/ftrace: add test cases for VFS type "%pd" and "%pD" Date: Mon, 22 Jan 2024 15:40:15 +0800 Message-ID: <20240122074015.4042575-8-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240122074015.4042575-1-yebin10@huawei.com> References: <20240122074015.4042575-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500010.china.huawei.com (7.192.105.118) This patch adds test cases for new print format type "%pd/%pD".The test cases test the following items: 1. Test README if add "%pd/%pD" type; 2. Test "%pd" type for dput(); 3. Test "%pD" type for vfs_read(); Signed-off-by: Ye Bin --- .../ftrace/test.d/kprobe/kprobe_args_vfs.tc | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_vfs.tc diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_vfs.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_vfs.tc new file mode 100644 index 000000000000..1d8edd294dd6 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_vfs.tc @@ -0,0 +1,79 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Kprobe event VFS type argument +# requires: kprobe_events + +case `uname -m` in +x86_64) + ARG1=%di +;; +i[3456]86) + ARG1=%ax +;; +aarch64) + ARG1=%x0 +;; +arm*) + ARG1=%r0 +;; +ppc64*) + ARG1=%r3 +;; +ppc*) + ARG1=%r3 +;; +s390*) + ARG1=%r2 +;; +mips*) + ARG1=%r4 +;; +loongarch*) + ARG1=%r4 +;; +riscv*) + ARG1=%a0 +;; +*) + echo "Please implement other architecture here" + exit_untested +esac + +: "Test argument %pd/%pD in README" +grep -q "%pd/%pD" README + +: "Test argument %pd with name" +echo "p:testprobe dput name=${ARG1}:%pd" > kprobe_events +echo 1 > events/kprobes/testprobe/enable +grep -q "1" events/kprobes/testprobe/enable +echo 0 > events/kprobes/testprobe/enable +grep "dput" trace | grep -q "enable" +echo "" > kprobe_events +echo "" > trace + +: "Test argument %pd without name" +echo "p:testprobe dput ${ARG1}:%pd" > kprobe_events +echo 1 > events/kprobes/testprobe/enable +grep -q "1" events/kprobes/testprobe/enable +echo 0 > events/kprobes/testprobe/enable +grep "dput" trace | grep -q "enable" +echo "" > kprobe_events +echo "" > trace + +: "Test argument %pD with name" +echo "p:testprobe vfs_read name=${ARG1}:%pD" > kprobe_events +echo 1 > events/kprobes/testprobe/enable +grep -q "1" events/kprobes/testprobe/enable +echo 0 > events/kprobes/testprobe/enable +grep "vfs_read" trace | grep -q "enable" +echo "" > kprobe_events +echo "" > trace + +: "Test argument %pD without name" +echo "p:testprobe vfs_read ${ARG1}:%pD" > kprobe_events +echo 1 > events/kprobes/testprobe/enable +grep -q "1" events/kprobes/testprobe/enable +echo 0 > events/kprobes/testprobe/enable +grep "vfs_read" trace | grep -q "enable" +echo "" > kprobe_events +echo "" > trace