From patchwork Tue Jan 23 02:56:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 190695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp90818dyi; Mon, 22 Jan 2024 19:00:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhwjShCEcxuz05cCRg0n8AnrljnC64O7MwtvA7hOWVbW0sRPs74kOaZmiDTXt1kiwZ98xI X-Received: by 2002:a05:6871:7288:b0:210:63fa:3856 with SMTP id mm8-20020a056871728800b0021063fa3856mr1026477oac.71.1705978834423; Mon, 22 Jan 2024 19:00:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705978834; cv=pass; d=google.com; s=arc-20160816; b=Z0CFfWLJSwYXzUHSuddahaKwv0skz+A+bEI/MtT0Y3kUkDcrQhDMv57tHzkbL4VAuh mE8TrFV7kgvQdp5lCEi8GbjwloDVk+MeaicZms7mF9Y772/qH8INAJg6Cbipc6+vBaAj hXNkN9Mbfbtl7pwRBllMDsnfqyrsnsVib9AvRkg4TJgKJiRkzP6gvlIltevIYgdIDY32 gcknJjgrmfSPLFVPMxzCU6dJw18x/wa6OCtQSxZqjS0pCERef4rfHA7lAsH34qsvEtGD cSskajz9ZfK9hWP3QDEZ+812VzeockfDzUTFLVGukyq1YUI3hSiskNZ5q6dtooZzxNHD cvYw== 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=3Y7YWmALaYgWSUGA63vPZuWX7T8I7RPOB8Da+ZRdKX8=; fh=Us/DORbzHj5XmgnBeJW+VlCBdo2pSXKHAejHonylCvY=; b=eCD8qyfG1j2TNJ3pxZsTLrkt4lv5tMHyZhUHiW9XS9nKSEmdDfHEAVu6YhwtqpNJk7 SYzHY+lLSvyuBFeBQVA7PZMvdKzIS1PsScDOqqk0s78lmyjj5gWLFLgfEYZPgn1O04i4 n3TNNySHn5LkkXT0CfGLfXp1kPUo05/0KBG51s2CCuH508hfJXxxAO+1QuJvdy+c30Qp lhz+bVjVUWlPTixy6erqH3f+yU60N1T8AsvU93nJr0fIVD/gaqc4De58/Jjo+6AMmqF8 +Unam5NZaMaV2XTzxfcqPGqEn0oksxbBGUMs6g54qUQ0dMr3wlTQRQtg2CWEduwSZhQv 58yg== 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-34659-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34659-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bz6-20020a056a02060600b0057745d87b50si9484460pgb.139.2024.01.22.19.00.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 19:00:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34659-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-34659-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34659-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 0A568290814 for ; Tue, 23 Jan 2024 02:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F94FF512; Tue, 23 Jan 2024 02:55:20 +0000 (UTC) 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 5314DA3F; Tue, 23 Jan 2024 02:55:15 +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=1705978518; cv=none; b=on2OPFKaByGdKpgYkupFyuejNP0l7+bL47GipS6jVJf6V+94hx4J31MwUvwZ0r1LgQZIE0CpMkF23aV+vrD/ej33mU1rZQwvZ08ElrSLOJind7JEQEMMfp9aCaPPtBZ2t30U8hkdO6hpqrblY9cHGW80u7kHawcT694BQIQnQKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705978518; c=relaxed/simple; bh=pHdZHFG+EXUIZJhSA7rnvMbd1K6r4z+UAhyNamX37Cs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LtQRlXPkBsyXVdmab3hjBxzyp563Y0m4qqADdZJw0OC5344zP9trEREzpqvf0P+qGwnVOg8kLBnaxN6lOvl3TLbQNp+qHRu8A7PjnBID6g09GBiAPt7OUr+QowSlu46HMDJCPmNemRxxrFCLcA+j9Ytjlcuh0nU0Bbj9b1o/CKU= 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.163.44]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TJs952KWFz1S5QH; Tue, 23 Jan 2024 10:53:29 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id C7A911404FD; Tue, 23 Jan 2024 10:55:12 +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 10:53:34 +0800 From: Ye Bin To: , , , CC: , Subject: [PATCH v3 4/7] tracing/probes: support '%pD' type for print struct file's name Date: Tue, 23 Jan 2024 10:56:05 +0800 Message-ID: <20240123025608.2370978-5-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240123025608.2370978-1-yebin10@huawei.com> References: <20240123025608.2370978-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: 1788848462112704622 X-GMAIL-MSGID: 1788848462112704622 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 cc8bd7ea5341..6215b9573793 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" @@ -1574,28 +1575,38 @@ int traceprobe_expand_dentry_args(int argc, const char *argv[], char *buf, 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 (!str_has_suffix(argv[i], ":%pd", &idx) && + !str_has_suffix(argv[i], ":%pD", &idx)) + 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[idx] = '\0'; + equal = strchr(tmp, '='); + if (equal) + *equal = '\0'; + tmp[idx] = '\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;