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: Ye Bin X-Patchwork-Id: 189936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2416818dyb; Sun, 21 Jan 2024 23:38:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IET8QxbHXYuK3JiLlPBxtY9OerhQMIvzbO9amZUO8wbiCcnNeMEVqYYtEdKZEmz0xd/ixjv X-Received: by 2002:a05:6808:ec4:b0:3bd:6b73:58d9 with SMTP id q4-20020a0568080ec400b003bd6b7358d9mr5524767oiv.21.1705909136011; Sun, 21 Jan 2024 23:38:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705909135; cv=pass; d=google.com; s=arc-20160816; b=UDr3msov4xKdEz7fWUpqpJyqzBlRbpY4qk+10mQNmXZQMDL1UbQBe2NJ9eKl+BAttw G2rGCvFWsh7pOQfrcMS0aWxg2uV2FUpxPnrOqGE9qBLmJXN37OOFZWkevnlgDqji3vZy E7A7OExb6oa8vMYDZSVPDPstujwWduvrbqpM2KBIL4sb78veN212AA8fyNY7nZNd6Glu xI9CDBFT3f5KDpyifEajzQJ8cQbA0qH5nMt9q64jtXh9w9110KLRiQeMEjkK+9Ml1mS2 E0Nigg4oh7ZNdJw+qNO7J0UtA1UiKz1hKzQ2aFGwWoCubBTsXKcmImQSsne4hGeQevsI 2F5Q== 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=2dnJ+YRF+VhtsUOpiEMSpM2yJJYMTvJHPO69bl2ifRk=; fh=Us/DORbzHj5XmgnBeJW+VlCBdo2pSXKHAejHonylCvY=; b=L6/p+eMrubR08Leq5/km3IxZgi0QO44LlMZJRhaqUXTR0lDEMyzjfLL+/mATEADs4P mVfbvHxOy7vJnmQtvPPCvpz29syRh1x8TH6BBlGSt8Gn9DAYW0R/sEb3BSApXr3V2Q+O 1uWh7b0slGw8/U2eLC+EmgnJ57NyHuhiTJfN/5ww1txooBDW7caSOov+fDuPtOLRVQ2a WrIxcJsjJ/3uSrFpk3T/vdtOGI5aaJjR6rrOq9Lw322eUSnOz7GGe1gVxUTHxp4eeHAr zzOL8ZbBlx7UV0m37GiR8Umfd4Fnpchdwgu2cFSECMD+CjCM+TxwJuWeGPzvbmfFvBVz ozbw== 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-32437-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32437-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 c14-20020a63724e000000b005b86142ee56si7620400pgn.277.2024.01.21.23.38.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 23:38:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32437-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-32437-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32437-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 BB5A2281531 for ; Mon, 22 Jan 2024 07:38:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA8AB17729; Mon, 22 Jan 2024 07:38:13 +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 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-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: 1788775378089300277 X-GMAIL-MSGID: 1788775378089300277 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);