Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1053369rdb; Fri, 19 Jan 2024 06:58:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQy5KFV0lTAufwgNiV8AfPDlB+pMEZWkOhshoFZWHjWyj3DBgk1YoaCg85aAXi4ssUwaXF X-Received: by 2002:a05:6a20:d396:b0:19a:d8d2:c645 with SMTP id iq22-20020a056a20d39600b0019ad8d2c645mr3211626pzb.109.1705676319780; Fri, 19 Jan 2024 06:58:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705676319; cv=pass; d=google.com; s=arc-20160816; b=LrHGN9xQUvvHXnTBoweEHlePf4ox5RT7EB90a7lGqfaXwbPHinOkoe/RDG1fM4pw/h zi/i1jts7hfyJHgkQGZrB0XXw194KM3qXJOG2ghWTr99PYqchrwQEA87J6fEo2BipbKu hMzzLPaqstjtaeEJyBA4f2Txn5Ehx0oKv1/wvJZKqLCM/mH/FypPbtsUCFdGKo6mR6s/ dby+Jawh/TYKhKA8dI4GxGNf+AjT/xfEOCjY1VLrdPZSSYc7/hIT+loUe19WP2nzg2bX utlpzspXmeP7X1wCOoUcw6ywy640FUfN/iqESWDvSI+wgrmpkdr/dwibgiuGfBEQehk/ MLFg== 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 :subject:cc:to:from:date:dkim-signature; bh=y9vLYmgxZBRusDBbKgfZplQnPyWhKG7rJccga8BfVjU=; fh=Cg71qZKzR4YfOJF8hZF4uwq7cJbJuaEt0vZOj81Q828=; b=WiR0vlABHBz3kUr2n5fl491uRqE2+sXBNMa1v8XV83Q4/GLEC+DX9Xxukxc3HrnnyU gXwoRccCcQ3rzILpJQKxx+bHIH1dlPFPbwVFex1J54REpb1t0nEAyuFosSePxBGtnFbY amAGiQgGm5F/Ns6h22H2Qm5feJ4scjmSovN3FpJkL526FKhfqWr0RokwZ7JaBmNsU3S3 o50KfwJ1suzERqvTo2fZfL9iFUystYa3B5s2wRNXTXg5I42JgrxMXLDoxHzdW2lEzqhJ FUXyWoqEOCM6u6LqzW1IFltYfyVdIjci+wchUoUeXRmWuD+77G8b/8/9/1YgXVU/snL3 NPVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXRT9MRD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-31295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o8-20020a17090ab88800b0029038f4c902si2242746pjr.88.2024.01.19.06.58.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 06:58:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXRT9MRD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-31295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 10D4A287EA5 for ; Fri, 19 Jan 2024 14:58:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D69C555763; Fri, 19 Jan 2024 14:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QXRT9MRD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0D54554FB0; Fri, 19 Jan 2024 14:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705676231; cv=none; b=Mq/aRQ0YJQyuhZfTICHeho0D2m+4te0wIMuC0fHYsPhYepdyzdY73sOS/5IXqfvqAC6tlQwhzG1xf+lkf3hJdsNgRG8q/2RGcNA529cvnIwqLXNZU82QklM9H/4eHbiaY2a1dmGaxRtH6U5jyu5uleyYfYct9cmy5j3qP2BdhtM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705676231; c=relaxed/simple; bh=0+4OncppuBjBS1DVIfYJuQGGGGBFqfj/oxaz1paaCyQ=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=UWi/YHeo2KPfh/rICxSPTprWuc3zopQOtCbUxWEM0WPrdUbWxORxUHV6hPhr2xqee9vJnP28kEn85z7jtD3bRwamyN5W/a6idTVEpqTSmir29VM8P7/qkgn19dzffIMxGNdAT97ZW1McocZMcrI16AiX3+Pq0IDp52AhVzmflqg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QXRT9MRD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1C39C433C7; Fri, 19 Jan 2024 14:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705676230; bh=0+4OncppuBjBS1DVIfYJuQGGGGBFqfj/oxaz1paaCyQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QXRT9MRDy4dwtum2pdDyfttpjOhV+jaVO+YRpimt8H7Uu/VnpsEzWFFizHIz9K20b gX79Xd4wDztLkTQxv3+MYHsmHfUFbiDYlMjryPsFSu9ZCtJFJbyki6ABESpIdQWA46 4XwBbGk+B1LwFC11+eCEBVbQHq10zQ9HzbTopW2K7Egq+ZBlV2Pk6wF53SGKVKmzgf xpSa9NZUe0gR73S29Tff6ducCusnn53LBHS0TZ05ojq9fqXTu8cZhLgk8BBjwCZpmG kBKj2zdqvmoILKR5bpi6LxpaFOOy4cUEc+ZuXywlrqqRoAGZ6fBmfn+lnMeAVoVPY8 aW+dNFttzTXAQ== Date: Fri, 19 Jan 2024 23:57:06 +0900 From: Masami Hiramatsu (Google) To: Ye Bin Cc: , , , Subject: Re: [PATCH 1/3] tracing/probes: support '%pd' type for print struct dentry's name Message-Id: <20240119235706.65ff7f6c9a7a6ad8a79934af@kernel.org> In-Reply-To: <20240119013848.3111364-2-yebin10@huawei.com> References: <20240119013848.3111364-1-yebin10@huawei.com> <20240119013848.3111364-2-yebin10@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 19 Jan 2024 09:38:46 +0800 Ye Bin wrote: > Similar to '%pd' for printk, use 'pd' for print struct dentry's name. No, please use '%pd' as a type instead. > > 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[]"), And you don't need to add a new type. Similar to the preprocessor macro, this should be done before parsing the args. See traceprobe_expand_meta_args(), you can scan the args and search argument end with ':%pd'. If you find that, you can replace it with "+0x%lx(%s):string". Then, you don't need any of these complex fetch type. Thank you, > /* 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 > -- Masami Hiramatsu (Google)