From patchwork Tue Jan 23 09:21:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 190798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp213451dyi; Tue, 23 Jan 2024 01:20:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtuBd2XcOdn87FqkYoU1bBJpxe0RVY9D3AibGcCpBgVomDrS88H5/0D7MBEkRPxNHHChvu X-Received: by 2002:a05:620a:2982:b0:783:9fd8:c339 with SMTP id r2-20020a05620a298200b007839fd8c339mr4268691qkp.76.1706001651047; Tue, 23 Jan 2024 01:20:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706001651; cv=pass; d=google.com; s=arc-20160816; b=BAAMXkHcZ0fER3XheaGF239nptdIEx86KEZnddt27kgfGK/sqY8gxYxhmzl9/U/g8o ryxRicVwnagdu6ys1Gdr9MpFVxpbnutJx1AVHzezWQXuPs1qIE2f2u87pti9kr2lH4Po t+CDVVp30uloyCzJBtS4pMrsVY/HtfRiEPESsV1bORhgSjsUU2/YIRveOHh12u5Fx1i0 ZU2Le0OC1UxQXL6VZQIjmtam1iwi6BeTF1XYBxYlcvtWfn9Dsiesajdx/l/G0PkEIIXn t9g/+lIaEn3bZOZ3Ky5Apu4LBTzwL0DcyTEc6uvi5nw5RCKExVC5oqudTXQ+lRYnSUS4 p4xQ== 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=tekadwNDTYY1f1pVfZfWEfb5DOi2B+SzdaFOBHxJS6w=; fh=Us/DORbzHj5XmgnBeJW+VlCBdo2pSXKHAejHonylCvY=; b=OUqxlk1JsoHbApN9dtFIx8VehIhifYVfB0G/GBxRyK6oTp7K6cPKxsMjUwpLzU8eFX qk0ZhUCdqy1Zd0Vy11rIVMNoXYZIemhUk1xHeVorjk4m5/FmK3OvrhD0sb1l+AnjvmCn AHgT/d9EYbyRr87zcYC9aE6zj3hpZirBd1W7LobCYW1nPJYRUq5nN3KT1t44cp/lvLlu 9FDxPC1bVqtVnIlYxqOT4P6ZqajGE2aGczMTLTprV1DHK7g5eaor+wjkUmhTQDT/a+EM tL7Yg3g16BfS+OnMU+ynh/mKW5yfHABEcjTgSHviTuVIQZXmh2u1Td7+scNpxIppPion CQwQ== 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-34982-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34982-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x1-20020a05620a098100b007834a7b552fsi7240270qkx.289.2024.01.23.01.20.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34982-ouuuleilei=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-34982-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34982-ouuuleilei=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 8E4D51C2286F for ; Tue, 23 Jan 2024 09:20:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B5C25C5E4; Tue, 23 Jan 2024 09:19:18 +0000 (UTC) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 00F1758212; Tue, 23 Jan 2024 09:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706001556; cv=none; b=EyUUfEbjVhSO1wnjGtnF7NhFtxL4EZT+gj7vW8Sb93m0EdzoGK6P5FBkSaWdpmFFDRfQWYL83/JOGS2S0Oq6Ph+5m1BG0trzoQsmWLGZykhzip0sCdo0IO2RAFM3Uetl2IFaANP4pO6H4eYQ6Rh+0QKDoI+NXGllgqqXFkBb0yA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706001556; c=relaxed/simple; bh=kYEzP77hAItk65iHZF+3d1AGqaHOMtv6LJ964mV0QIM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HYt3KvD8CfU4UUJOtC3Qe4NCE3jik+BtdVh2xx6NOVjvE4+JIxyQHoRYbestF9dptas+oEsV/wpRtTi/LsIEEOTMQFHcZESVTmLjWcMkPLzY4xCjE7jz55YwolHSsGBFClhXgg62jKKT87Fn0KVHBy3otkNYZbvZ0UZNxN2/XLM= 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.255 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 szxga08-in.huawei.com (SkyGuard) with ESMTP id 4TK1hv44lmz18LMp; Tue, 23 Jan 2024 17:18:07 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id DC21E140578; Tue, 23 Jan 2024 17:19:08 +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; Tue, 23 Jan 2024 17:19:04 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v4 2/7] tracing/probes: add traceprobe_expand_dentry_args() helper Date: Tue, 23 Jan 2024 17:21:34 +0800 Message-ID: <20240123092139.3698375-3-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240123092139.3698375-1-yebin10@huawei.com> References: <20240123092139.3698375-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-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) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788872387371416825 X-GMAIL-MSGID: 1788872387371416825 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 | 36 ++++++++++++++++++++++++++++++++++++ kernel/trace/trace_probe.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 4dc74d73fc1d..cc8bd7ea5341 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1565,6 +1565,42 @@ 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++) { + size_t idx; + + if (str_has_suffix(argv[i], ":%pd", &idx)) { + char *tmp = kstrdup(argv[i], GFP_KERNEL); + char *equal; + + if (!tmp) + return -ENOMEM; + + equal = strchr(tmp, '='); + if (equal) + *equal = '\0'; + tmp[idx] = '\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 Tue Jan 23 09:21:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 190799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp213801dyi; Tue, 23 Jan 2024 01:21:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcG6Z5TPxKGpCtgi5zYbgMLnxbFVIY3xnRvmZgUxEkXeUDnZYn6hbtW5SEiOjyFmdDvgSm X-Received: by 2002:a17:903:22c5:b0:1d7:4a08:351e with SMTP id y5-20020a17090322c500b001d74a08351emr4209587plg.67.1706001700093; Tue, 23 Jan 2024 01:21:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706001700; cv=pass; d=google.com; s=arc-20160816; b=xRh3RUOHctapVZWnjvWw8cgM4s2EbyKC8MRZNazsDubJ0KRKcP5fg8HIwOXpeZ46fs 3eUdGPHOa+t8FRKJidilevs5xI0wD5+7TEzdfApPpx8vcTOrFDX5DrwavHbt3zYfRRPo OjY+LVfpblhx7eTxmR7lbJ5/8F58fS9CHJm1SOFw1yj/Bfwj7uI3BzCcQbjmmvLoBpvh 7f4M/GGcw75XXguN3Axnh2V/46c6ZdHXKe/zlleDJxhyBbZWpc6LLI1+EQjDMNZBcZd/ 8X71gEQ7NCxCU+6hCduN/bry/nHYPwS5XrVdM5mtZ4N/YirqI5fourgZdcWBEZ75HuJL 93xQ== 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=6/XQvalnxwBoE0JeQUz1ckWQn9Ogdxk175QFj+rhRDU=; fh=Us/DORbzHj5XmgnBeJW+VlCBdo2pSXKHAejHonylCvY=; b=UIGIdejUfCANWmJr6B40JjEIpjJGcZfLKw3/H/k37Og9GbMHTHsbJcREfTD1dW4XN0 dn5j1yBIp5uJOPJUJ1HQeJs7IEbHueu/5Lr6i+1ntipWwlgdpFT3+y8RN8PUe8/R2ElA izQLQ56ZWtYEuyRRVVe93vz9N8zvB9gpZdoNOst6250PPsdvgLNdTrK0Yjrn7B6cTlLN JrBKuwgQmicuC5hrXI/QPa5XHI6ncz88q7Um0jewTgQ18imlSJ9Ga5H77SCxfdx8G0aG g6fG6ZRXNZGQrHAQpNEXEKNpPsPd2EazCaUF/aA9c/0+3WhYn0OCR0nX2FMor3WHWXx4 OHMQ== 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-34985-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34985-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w19-20020a170902a71300b001d76212d76dsi1871893plq.457.2024.01.23.01.21.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:21:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34985-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-34985-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34985-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B9FF9289E81 for ; Tue, 23 Jan 2024 09:21:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C76F59B51; Tue, 23 Jan 2024 09:19:53 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 2E7405914C; Tue, 23 Jan 2024 09:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706001591; cv=none; b=o75whJJPO+UxQxmSYmXaZ9SNY/Bs9VqdOucXseOatNOuzQYXdSW0TBcAqqJT1rZprrPDLnsKrjjibOzT74WFn4Wr5jKDlyA+00UMavEbLDwXpEIEPLFGDdSMqoe3ZsWe4VksE8cyulvIFRmXj+Np08UbmEiuCdgybpYY9ojHiaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706001591; c=relaxed/simple; bh=wqD3BcIyhEmryJcEFaCD5uVA14nzmG5cK5v0iik8hsM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HfWtv8hwHPhFTGnnNiZ8GxiFVxkXhHs+RorN3pB7B74q8ChvYcxZUDj36tEobDpfHRlvq3fJRW7Zjns87+xUEc/WQVBKHozQdZ4LtNnNr+3XluSSBOM1RpwcsoFK049ZbBOcw5XEM6R75nWwOgD0KfVLGOADmv6WYuikT/1dtfg= 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.187 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.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4TK1j50k71zvVDK; Tue, 23 Jan 2024 17:18:17 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 3693E18007C; Tue, 23 Jan 2024 17:19:33 +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; Tue, 23 Jan 2024 17:19:06 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v4 7/7] selftests/ftrace: add test cases for VFS type "%pd" and "%pD" Date: Tue, 23 Jan 2024 17:21:39 +0800 Message-ID: <20240123092139.3698375-8-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240123092139.3698375-1-yebin10@huawei.com> References: <20240123092139.3698375-1-yebin10@huawei.com> Precedence: bulk X-Mailing-List: linux-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) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788872438629989211 X-GMAIL-MSGID: 1788872438629989211 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