Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp715660rdb; Thu, 18 Jan 2024 17:36:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhYady0TfjdNPd8lLjmaenHkgoNFQIPQxBK2+Qqp2L/7r7HStQ7NP3FTg3GAWXEsuVDdl0 X-Received: by 2002:a1c:4b15:0:b0:40e:5962:faf7 with SMTP id y21-20020a1c4b15000000b0040e5962faf7mr1117062wma.102.1705628213086; Thu, 18 Jan 2024 17:36:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705628213; cv=pass; d=google.com; s=arc-20160816; b=VIfrCXAc3oQu5WLLtfPfyKSsoAi6idfaHPiEnYrPZ5jEd3iU+vissmljwvQYQUAkZE zodfheD3CaRxRDV4WAJ5AEvsX1RiPdwQdegR0E8iswArz10ysPzYKX0EbBFtJFFAckHV LxdTxFp6TkMsv8X5rZ+fwjsDCfFkZYI9tV3beVPlH+Ql3SClqLenU/AtC5ZCiPbbYscG mBK9JFSVPAE2L5KF75ifxT9tFneI3B/o/8w2CvYLTdvDQ+YtGTgtzvom/shsOYLwnozf wb71seUhSdDpKzv+5c6sqj3tJkOfyraNvKMkqsnsaL/nXKXNOdi4CkgGI/Gbcq5E4Hpi 878g== 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=wfgHjHtmw0px4uSXCu15VJZAOYdqfEfqQw6KwQLKsFY=; fh=Us/DORbzHj5XmgnBeJW+VlCBdo2pSXKHAejHonylCvY=; b=sAZfskmQTh1+XYJifIo8xYzq/N6zpviIDMYSAMo7dtmDcpklcvJXbZcWvHa2740gHJ vmdb46uJlZLw3fpcNY42zFLnadN3pQnCNYAl7ccXjulby/puOaE3qJSnilKwCwCPgyIx BDd6qtWZNqF6xq9e/aONAQ+e2lxYf+PpjsT9KMiE0xc/aAI58vclB/pb9WmWDqCOYa0Z eyNS7R0s4Wfr5eS8aNrJIEeqpKxEYUyaokNQE8Z3wj2PYH1rBtCFovXsX48CVr98TAt8 Z5mIT6skPinmFcLHNfSkoYI5TLRKcodENXaG6ucZoU0bxU9G0SVwPzK9xVhf7rz15k31 5vYQ== 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-30688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x8-20020a1709060a4800b00a2777fddfefsi7283905ejf.772.2024.01.18.17.36.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 17:36:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-30688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30688-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D256B1F2121D for ; Fri, 19 Jan 2024 01:36:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B55A4A02; Fri, 19 Jan 2024 01:36:21 +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 48B24ED9; 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=1705628181; cv=none; b=IcLK54/OOoCcLycL+qf+i3rF+eABVCAjG03V1lpg8W/83nQLGcrM7q9c+NbVSUOjGJ7+YDvKf2mp3P/OvrAwt5UcTx5T8LqX3raogkQdOox8q60+qLSezbH9SGzEr/XuaUqB3EXD38+g2EVgklPFW055Jzm2hroae1owk8wJZu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705628181; c=relaxed/simple; bh=9v9m7nPcfnEvdIhqDenml4Or78lsJCXEaQSzOCTjMqs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qKhtvSkchW48cYhzLHdf6tbnioT54wMRkc+YbCP8TtRMl7KMmT0Uo1jw7E0lo6gTY0Tf170ABdxi7NX9uPBltX4xRTBb+HfuT8KYVmqXW3px82ObpkfJQFqvMXnk/ZF1pWGQ/PDZ/4CsS36pTFMZOLcmn4/YDrUe6OtGFe2OuBU= 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.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TGMcx0wGTz1xmR9; Fri, 19 Jan 2024 09:35:29 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id C0304140113; 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:15 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH 2/3] tracing/probes: support '%pD' type for print struct file's name Date: Fri, 19 Jan 2024 09:38:47 +0800 Message-ID: <20240119013848.3111364-3-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 file's name. Signed-off-by: Ye Bin --- kernel/trace/trace_probe.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 460f98b85b1c..400a1dd52c39 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 #include "trace_btf.h" @@ -89,6 +90,8 @@ static const struct fetch_type probe_fetch_types[] = { "__data_loc char[]"), __ASSIGN_FETCH_TYPE("pd", 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), @@ -1093,18 +1096,26 @@ 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) +static char* traceprobe_expand_dentry_file(const char *argv, bool is_dentry) { #define DENTRY_EXPAND_LEN 7 /* +0xXX() */ + #define FILE_EXPAND_LEN 15 /* +0xXX(+0xXXX()) */ char *new_argv; - int len = strlen(argv) + 1 + DENTRY_EXPAND_LEN; + int len, ret; + len = strlen(argv) + 1 + (is_dentry ? DENTRY_EXPAND_LEN : FILE_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) { + if (is_dentry) + ret = snprintf(new_argv, len, "+0x%lx(%s)", + offsetof(struct dentry, d_name.name), argv); + else + ret = snprintf(new_argv, len, "+0x%lx(+0x%lx(%s))", + offsetof(struct dentry, d_name.name), + offsetof(struct file, f_path.dentry), argv); + if (ret >= len) { kfree(new_argv); return NULL; } @@ -1205,10 +1216,11 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, parg->count); } - if (!strcmp("pd", parg->type->name)) { + if (!strcasecmp("pd", parg->type->name)) { char *temp; - temp = traceprobe_expand_dentry(arg); + temp = traceprobe_expand_dentry_file(arg, + parg->type->name[1] == 'd'); if (!temp) goto out; org_arg = arg; @@ -1277,7 +1289,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, } } - if (!strcmp(parg->type->name, "pd")) + if (!strcasecmp(parg->type->name, "pd")) code++; /* If op == DEREF, replace it with STRING */ -- 2.31.1