From patchwork Mon Mar 4 03:40:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200505dyc; Sun, 3 Mar 2024 19:40:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/hUKBjTR1HGRTWHBOPtX7ONGn3f+TxwawBb0GMM4BfbTG6TUMBr5yfZM2uJn2nNmCkzlWJCLw6V1C1UOobaJHsoDVoA== X-Google-Smtp-Source: AGHT+IEYee+4ywhgOkzDQ5XvBu18MFjZ86FRlcPHd32yluiHXOri/tkZmePzArFjhKgilkuHAxRB X-Received: by 2002:a05:6214:11b1:b0:68f:2b35:5edf with SMTP id u17-20020a05621411b100b0068f2b355edfmr9374605qvv.13.1709523631981; Sun, 03 Mar 2024 19:40:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523631; cv=pass; d=google.com; s=arc-20160816; b=mTPoQPQWstztZVM4Zplg8lruCQ5eEZXvfrFisALI5fCPg3xML47K0cr3Ltq1iD01kv ZsO/LGLquwGpTS30nuNlgH8rTFzPUKZF/Lde9gtBwLswfMjBGHVgC97mSE1+pSzAdg95 gCt6vw32VMAYfIyEDx7IQPnEN6GYyGx8GOU9YcpaITf8DD4t19wZwE+7zibQ9KGIF2V0 j4Ee9SEtrjDWqBrtFLKYGcle1mRMOSMeLQdF1eCBBkhxF7FE9OBiBOc+dB9dpja6d1A3 th3791XcTYD1I1PIPe3POxzI4AfZfy4Fgg3M2PqXy29BPzfChQ2BALPsdRjyeSX6iWTk OrGQ== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=pQiqdxJSsXjk2K24IpNGVSc7INniEvPFX2F0k2u2Hz4=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=fZenPUOeX7jxXXYu57H+YWgtTuJCJfey5NC60N1tnwYCA87VGa2EiF757RWf+/nxij SjNojzgRnyBbxP1iFU/vFiLBOkW9WK5hrzljExSDlPpf0pJPd3xvK63RyKiHmEx/0L9S 1gD/m/RxkjCS24XkeRIyi7m4+6d5uZ54U6l/hlJAXMrgY3iGytspT80Op7VGnxqlRPE6 qw3vEsOvrAlvxLv1v0L9Vm5YEYuneaBKwkLWvor761WsFxcLGF724V3jgX5WxRTqzRaH NR2HkaVh7moCgeRmFzx6wllkSphE+rNaUuCfyHz1NYPW3xMLbLH7nstJAVwnXFgin6Ui xSdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NacBqozn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90019-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90019-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j5-20020a05621419c500b0068fcc76644bsi8978101qvc.99.2024.03.03.19.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90019-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NacBqozn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90019-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90019-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C2E211C2098E for ; Mon, 4 Mar 2024 03:40:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D5D66FDC; Mon, 4 Mar 2024 03:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NacBqozn" 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 005346ABF; Mon, 4 Mar 2024 03:40: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=1709523611; cv=none; b=SglWrATUccwsld1cnE998xkQK2AtRTuLd4LfqW1lguhag7HTUn7yNWCnvVfXmZTaoA0/7O2DyJq83h29N9+QWO8RI87f1Hl8eg+ZfYs1cxuM14Gogb/L0dSAhrLYxQtF8PTg8VEz8e9+Pl4ocpDCr/NWHEPHC+2OiZi1SaZ8n5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523611; c=relaxed/simple; bh=S57LBagA5sfS5PxIPRcS7nfl3DEhORZYcIUUZT8qPdc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=tvY3NgJHHDo84RKB8mZhz/nGHgQE4QCdqAOLZzQliVvHAxOazLd2opmLI0/bi07LsGH6yU4/0d3oc0DR76BBLpJFN8bNZnr1HYnlgJH8tMocZdtU17IxbS8ozibz+o4edtH2MpngrpRioQignfseu4Omqk6tfFP+JqztPLvjycU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NacBqozn; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A2D8C433F1; Mon, 4 Mar 2024 03:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523610; bh=S57LBagA5sfS5PxIPRcS7nfl3DEhORZYcIUUZT8qPdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NacBqoznCzzfaWEgzeK4cvGYokk7JfPd7hZI2y1k3H9t5eH8As1V1XnB/k5PW8iIA LHiFLnzBTQ4dfIsZTn7REGHpP+GdHprxLw50GHsRIgjC6fJyU7DFGF/I7rJzQ7JcdK XuyJMdgX9pPMbh10GuKq2QWoupVs4QhdOdgDJULEMQinHfHPrBwOaW+A+IF1uzzYcD tvTBbnDwx6g21Phai5nKIh0L++9ZZcVdcgqqRiV/01leBSzP28ZK3/5fB7GYlUF3J+ KSzCYCRKKb2yNHSLn368v5CR0iqK45rFyAFoNXQUJTOl3gtc4AoCYIZRw0bv6Oi/S/ S6Wr1vQUJCfuw== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 1/8] fprobe: Fix to allocate entry_data_size buffer with rethook instances Date: Mon, 4 Mar 2024 12:40:06 +0900 Message-Id: <170952360657.229804.345771440723430834.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565451651165051 X-GMAIL-MSGID: 1792565451651165051 From: Masami Hiramatsu (Google) Fix to allocate fprobe::entry_data_size buffer with rethook instances. If fprobe doesn't allocate entry_data_size buffer for each rethook instance, fprobe entry handler can cause a buffer overrun when storing entry data in entry handler. Link: https://lore.kernel.org/all/170920576727.107552.638161246679734051.stgit@devnote2/ Reported-by: Jiri Olsa Closes: https://lore.kernel.org/all/Zd9eBn2FTQzYyg7L@krava/ Fixes: 4bbd93455659 ("kprobes: kretprobe scalability improvement") Cc: stable@vger.kernel.org Tested-by: Jiri Olsa Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/fprobe.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 6cd2a4e3afb8..9ff018245840 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -189,9 +189,6 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) { int size; - if (num <= 0) - return -EINVAL; - if (!fp->exit_handler) { fp->rethook = NULL; return 0; @@ -199,15 +196,16 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) /* Initialize rethook if needed */ if (fp->nr_maxactive) - size = fp->nr_maxactive; + num = fp->nr_maxactive; else - size = num * num_possible_cpus() * 2; - if (size <= 0) + num *= num_possible_cpus() * 2; + if (num <= 0) return -EINVAL; + size = sizeof(struct fprobe_rethook_node) + fp->entry_data_size; + /* Initialize rethook */ - fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler, - sizeof(struct fprobe_rethook_node), size); + fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler, size, num); if (IS_ERR(fp->rethook)) return PTR_ERR(fp->rethook); From patchwork Mon Mar 4 03:40:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200583dyc; Sun, 3 Mar 2024 19:40:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVDXC3AqHxgLJtEMI1T2JWPMKMFhCY0JgY+mA/JFtuSU3m3CAuqcdd64nwbMXrziSQV0VL8xT0++V02B8MnRnzzFyn6fw== X-Google-Smtp-Source: AGHT+IEndr+PIZ+eOYXGDbVgVdunMclstVtu0aq+rgrnTk5xU7TmtpEDmHZ26F7Wf7VIFcVs8U1L X-Received: by 2002:a05:6a20:43ac:b0:19e:9c82:b139 with SMTP id i44-20020a056a2043ac00b0019e9c82b139mr7260579pzl.45.1709523652212; Sun, 03 Mar 2024 19:40:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523652; cv=pass; d=google.com; s=arc-20160816; b=WfrCspa5YddbuAkqaAiOmUqCRhSWF3zNkrj2XC/KHHh/8h61KNk5NqxXrtiPz8/Kio KbhwcvxQzs3GvBtCwaMe07rDXf/8/NTo/OLrCtWaVFtZzZq1qoWdS9t7P2xxJw43IDf+ y0BLri7INA5gFsEW1RusP4ej2ExLTbSa/f97XRsINrdZTI3wTC9DMZA+0eBeFwiIoAHs XPF/i+MGp3gf09JA5xdmNUnUEMwuC3o6A4G+dm7lH6AeP9YIxSjxe21xHCjga7ya3o22 a7mymV0Bky28EhFptvbPcfPic72BjUohvE75L7wRVyNC8oDz80jTZfgpv4jORq9qGynO qrzw== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=DuDAwXdize1QtPIer2b7UqWEahnyu/KOAFXGYltAAls=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=FbAqX3k6pVwwJriX2pBVmQJmgFUJjCQueSIs04qMMG1Z4s1xBiuuene2zK/85kilhj FyXAZ5wW+YZX24mY9DAVCT6FvQEMd3/LraBAlsTIp+J82r0wtkhC9phQ2e49I+xMZ6yb qD+MYmc8YYiJ25d01vM9gluYc/J97OH4Qqd+dVc9/Zo31iurpCAHai9KO4lidnalkwO+ NsELcV9VD+jkDxigMwKri0PCculSLLpD2cfy/91Pfzbn+FvivRGsE04VKzQeBipHh+l6 bjmE10B1YXLXeAtPiXM/YtoRlNRllntc1wkLwhVe7BL2ysrU7GI+00KEpK1xgRohsnWE TqIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="OF/QoMlN"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90020-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90020-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w4-20020a170902e88400b001dc0e6db066si7928966plg.394.2024.03.03.19.40.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:40:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90020-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="OF/QoMlN"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90020-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90020-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 46CEBB20C8E for ; Mon, 4 Mar 2024 03:40:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C96048F44; Mon, 4 Mar 2024 03:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OF/QoMlN" 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 042F64C6B; Mon, 4 Mar 2024 03:40:20 +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=1709523621; cv=none; b=R/WYOarwYpMZhkzXEEAdzQX/LATMuD4de5u9himM+90qzPnzZQA5L8jVWU7RR4QP2sHDg6WLdFsB5w9GFLyGTO1rLOCIAQ5AUPYNSiQWwssG4bq/AMCwfw5oVe9N/cmijpoEJnOa4tVkbpoiUcyTff2InvK92IyVPSB2S7GqZ8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523621; c=relaxed/simple; bh=/dyCFA6euqljnFjmQrQ+oafm97nJtVOUz8aX5A22W/g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=jAWWJR8WVRpSLP9rCmkSug+m/qElNGYZlmz3HddS7Kh4CE04esXkjDu1aZUFkA2A/YohRWtLW+3CW4CL8Iq3YZGo3WPXYhccGu1+VAxWE+ERqHIfpKbEqweLxrgCRfVL1FVM0YL5KTIwPC5PQ1oLz2JkHghTxyUujlKGtFQ9Tho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OF/QoMlN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2A4FC433F1; Mon, 4 Mar 2024 03:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523620; bh=/dyCFA6euqljnFjmQrQ+oafm97nJtVOUz8aX5A22W/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OF/QoMlNRXrDJEYBArP5rVYtONQ/MDAnwmWXMjnSsy6T1mdCtsG56hdvm9olasW0f Cq7ttZGrHeD5EtO1i7E4WM8o+KpVAiD5xZIgYwLFSauhEe8QhnuoXiODJbX/0ISkD2 jZi0VDdXmtIMf/TcbBGVaLVpwAAGLSe5j8INAx41pMNgvd6+RyMdw9/FYMGOwDry0+ 7Wf/HD/WL5VmTIN2dxmJ2HHudNngFDfWDS00QIEv4ggROLwX3n/YgyOEPrHYpgr4ro JZzdSCeSM8IYyV657LQIpQ+heVROkomQ+CHLxf0dLSnpbToYaCk5gbH/4rjEhhvhgF Y5aT4r4NwiM6Q== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 2/8] tracing/fprobe-event: cleanup: Fix a wrong comment in fprobe event Date: Mon, 4 Mar 2024 12:40:16 +0900 Message-Id: <170952361630.229804.10832200172327797860.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565473302508029 X-GMAIL-MSGID: 1792565473302508029 From: Masami Hiramatsu (Google) Despite the fprobe event, "Kretprobe" was commented. So fix it. Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_fprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 7d2ddbcfa377..3ccef4d82235 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -210,7 +210,7 @@ fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, } NOKPROBE_SYMBOL(fentry_trace_func); -/* Kretprobe handler */ +/* function exit handler */ static nokprobe_inline void __fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, From patchwork Mon Mar 4 03:40:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200627dyc; Sun, 3 Mar 2024 19:41:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUFcpYcZ9bl32YVaoV9aXhdTHZvs5W1/snwhKs3cNdmdnpYG8ovz727c39kvwCzSCrP8OdoxGmYpVGrzdQAvrSyeT7fLQ== X-Google-Smtp-Source: AGHT+IEkWwM/ixS1Hb5bGD1H1Y2G9SyeKpPS/jsiScuLJxd+9hMCX6RdXtM3JFFflgENW0rxjZEl X-Received: by 2002:ac2:4ac2:0:b0:512:e51f:b58 with SMTP id m2-20020ac24ac2000000b00512e51f0b58mr4851558lfp.24.1709523663159; Sun, 03 Mar 2024 19:41:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523663; cv=pass; d=google.com; s=arc-20160816; b=ypFYDgdkJSvBI0G/uUYPrGVLzllAPBiY5Ww2/Bat9IxuZFNcJVGXltjV3Vt1ps0nHu twa8rM6Yt1j5uUIOvpKfhLUMRjMYIycDvLP5r91j6EJkyntaPhnHC9DTe2PIP2kRWGYB OPHMDWcSHZfrY2BasSVJ+rI5LrZ9hLK7Q7S9Db5kte2vsBKTZXc7fIsAkIwoSTYcX9kX IWozEMDfURTy3D67p0BJ/HsO/Au5+O78O8rySWV2g54ng4+lZtugWHgZX4EHd+xfcrOp Iar/6bkv22X6EJFDSU8wWcXSCxHsglZKHL1XQf12YarRDi3OYi6wWe3pJMbX6S/XyNzE ywzQ== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=rQClFIrmeAMBSuhIocTaxwWugYWZ+96W+5NVjp9zCX8=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=ajGcavQxTBSm5WCqGCaY0mpuCjCgjO61tk39EpJ4jbE+rHXTRIlyPM8YKspZbTP3c0 R2JqcP2hO8u6G6/q2lZ6ypwMT9N1zE4dNecd1xuGJG0SskcbB1SydmJsnYJ9cE/RNxjX VE+ZaLiRyhMdylg5FPLd++PAQipDL4hTiVWIVc/dt2crz16JifFw21nuzDhPWavwc5g/ 54Hmqn4cLPvZ5aS95Cseu7HxhZDeCAXwmsXX9ngYvWemsMQIPwUfKoNKaFakVXzg5upa SoNZ/2Tt5T7MXawHvde7BJVYYm4qW8QuHGrk7p1VwttV1sYmUtiebGBxCaezwij+Oy2q V8NA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="h1YGFPh/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90021-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90021-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ec14-20020a170906b6ce00b00a455711ad06si306887ejb.170.2024.03.03.19.41.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:41:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90021-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="h1YGFPh/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90021-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90021-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9537A1F21377 for ; Mon, 4 Mar 2024 03:41:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 676D679DE; Mon, 4 Mar 2024 03:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h1YGFPh/" 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 8A6DD4696; Mon, 4 Mar 2024 03:40:30 +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=1709523630; cv=none; b=UdJr+bx1Bv49NkPigdC//sFl+do8yhph5y9jf9CzBHBPiplinxcBzHe9oB3WDuVZBIlUQwpA5ma3f4WvMdxI2kNi0ckzJyvAg+TiwZm2yB0HbwdcKy9t9joy1dB81tuBSNBbIDPF34uqBF06pHvygONxSrn0RK/51om2eIUe0Is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523630; c=relaxed/simple; bh=oIJcYTq1SwlQ4Abvogqr2lB8H41c4KmqOmtDdXxqEPY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=aCs5Ss4Y8rw4UFOxb0Tshy1NET0RB+r3sNzptC+bSVrfWOldhSydmaj36Zkx5HZae9P4jB9EYXGE9iWX8grwh8hWbXrtqhfDmRbdREBAGraou/Gu8ebj5RP0y0/XoLBeivKvWH2C1Lx+4z+bovZnrvb3afvOsSkHXRVdTTqKlmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h1YGFPh/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99628C433F1; Mon, 4 Mar 2024 03:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523630; bh=oIJcYTq1SwlQ4Abvogqr2lB8H41c4KmqOmtDdXxqEPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h1YGFPh/7gNmwpRMdKttkdUFHhmGjAkO1m1MzgqbUEVHzhrkckDEokM8DCB8i9JRb tYqgsHaz+0Vnj9Gg99KInIlULuCWmWiBbg8IPHpZmXWxD26L5/iXcE7CzcQk4AyTH4 OAd28QUo4+9gEVGw4Q+oFLg7ZMMA8sItPUYaSCiMQZMi3JosnB1ssa0t5C1oSNDM3T 2bvkG/slB7U66tbL9r6s4v2+HRBmqCGgx4s+h4pUegEhAzmSnl2b+VNF3IYRyIy9og OJiESIEXIa8Z8wE4DNSpXiHH/fmacYsuSdNgVj5IbbEkW+4wyMo3XDjEK3Hi/5qrsb +IJ9oov+/7pZw== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 3/8] tracing/probes: Cleanup probe argument parser Date: Mon, 4 Mar 2024 12:40:26 +0900 Message-Id: <170952362603.229804.9942703761682605372.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565484367747250 X-GMAIL-MSGID: 1792565484367747250 From: Masami Hiramatsu (Google) Cleanup traceprobe_parse_probe_arg_body() to split out the type parser and post-processing part of fetch_insn. This makes no functional change. Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe.c | 230 ++++++++++++++++++++++++++------------------ 1 file changed, 137 insertions(+), 93 deletions(-) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 34289f9c6707..67a0b9cbb648 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1090,67 +1090,45 @@ static int __parse_bitfield_probe_arg(const char *bf, return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0; } -/* String length checking wrapper */ -static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, - struct probe_arg *parg, - struct traceprobe_parse_context *ctx) +/* Split type part from @arg and return it. */ +static char *parse_probe_arg_type(char *arg, struct probe_arg *parg, + struct traceprobe_parse_context *ctx) { - struct fetch_insn *code, *scode, *tmp = NULL; - char *t, *t2, *t3; - int ret, len; - char *arg; + char *t = NULL, *t2, *t3; + int offs; - arg = kstrdup(argv, GFP_KERNEL); - if (!arg) - return -ENOMEM; - - ret = -EINVAL; - len = strlen(arg); - if (len > MAX_ARGSTR_LEN) { - trace_probe_log_err(ctx->offset, ARG_TOO_LONG); - goto out; - } else if (len == 0) { - trace_probe_log_err(ctx->offset, NO_ARG_BODY); - goto out; - } - - ret = -ENOMEM; - parg->comm = kstrdup(arg, GFP_KERNEL); - if (!parg->comm) - goto out; - - ret = -EINVAL; t = strchr(arg, ':'); if (t) { - *t = '\0'; - t2 = strchr(++t, '['); + *t++ = '\0'; + t2 = strchr(t, '['); if (t2) { *t2++ = '\0'; t3 = strchr(t2, ']'); if (!t3) { - int offs = t2 + strlen(t2) - arg; + offs = t2 + strlen(t2) - arg; trace_probe_log_err(ctx->offset + offs, ARRAY_NO_CLOSE); - goto out; + return ERR_PTR(-EINVAL); } else if (t3[1] != '\0') { trace_probe_log_err(ctx->offset + t3 + 1 - arg, BAD_ARRAY_SUFFIX); - goto out; + return ERR_PTR(-EINVAL); } *t3 = '\0'; if (kstrtouint(t2, 0, &parg->count) || !parg->count) { trace_probe_log_err(ctx->offset + t2 - arg, BAD_ARRAY_NUM); - goto out; + return ERR_PTR(-EINVAL); } if (parg->count > MAX_ARRAY_LEN) { trace_probe_log_err(ctx->offset + t2 - arg, ARRAY_TOO_BIG); - goto out; + return ERR_PTR(-EINVAL); } } } + offs = t ? t - arg : 0; /* * Since $comm and immediate string can not be dereferenced, @@ -1161,74 +1139,52 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, strncmp(arg, "\\\"", 2) == 0)) { /* The type of $comm must be "string", and not an array type. */ if (parg->count || (t && strcmp(t, "string"))) { - trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), - NEED_STRING_TYPE); - goto out; + trace_probe_log_err(ctx->offset + offs, NEED_STRING_TYPE); + return ERR_PTR(-EINVAL); } parg->type = find_fetch_type("string", ctx->flags); } else parg->type = find_fetch_type(t, ctx->flags); + if (!parg->type) { - trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), BAD_TYPE); - goto out; + trace_probe_log_err(ctx->offset + offs, BAD_TYPE); + return ERR_PTR(-EINVAL); } - code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL); - if (!code) - goto out; - code[FETCH_INSN_MAX - 1].op = FETCH_OP_END; - - ctx->last_type = NULL; - ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1], - ctx); - if (ret) - goto fail; - - /* Update storing type if BTF is available */ - if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS) && - ctx->last_type) { - if (!t) { - parg->type = find_fetch_type_from_btf_type(ctx); - } else if (strstr(t, "string")) { - ret = check_prepare_btf_string_fetch(t, &code, ctx); - if (ret) - goto fail; - } - } - parg->offset = *size; - *size += parg->type->size * (parg->count ?: 1); + return t; +} - if (parg->count) { - len = strlen(parg->type->fmttype) + 6; - parg->fmt = kmalloc(len, GFP_KERNEL); - if (!parg->fmt) { - ret = -ENOMEM; - goto out; - } - snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype, - parg->count); - } +/* After parsing, adjust the fetch_insn according to the probe_arg */ +static int finalize_fetch_insn(struct fetch_insn *code, + struct probe_arg *parg, + char *type, + int type_offset, + struct traceprobe_parse_context *ctx) +{ + struct fetch_insn *scode; + int ret; - ret = -EINVAL; /* Store operation */ if (parg->type->is_string) { + /* Check bad combination of the type and the last fetch_insn. */ if (!strcmp(parg->type->name, "symstr")) { if (code->op != FETCH_OP_REG && code->op != FETCH_OP_STACK && code->op != FETCH_OP_RETVAL && code->op != FETCH_OP_ARG && code->op != FETCH_OP_DEREF && code->op != FETCH_OP_TP_ARG) { - trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), + trace_probe_log_err(ctx->offset + type_offset, BAD_SYMSTRING); - goto fail; + return -EINVAL; } } else { if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_UDEREF && code->op != FETCH_OP_IMM && code->op != FETCH_OP_COMM && code->op != FETCH_OP_DATA && code->op != FETCH_OP_TP_ARG) { - trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), + trace_probe_log_err(ctx->offset + type_offset, BAD_STRING); - goto fail; + return -EINVAL; } } + if (!strcmp(parg->type->name, "symstr") || (code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM || code->op == FETCH_OP_DATA) || code->op == FETCH_OP_TP_ARG || @@ -1244,9 +1200,10 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, code++; if (code->op != FETCH_OP_NOP) { trace_probe_log_err(ctx->offset, TOO_MANY_OPS); - goto fail; + return -EINVAL; } } + /* If op == DEREF, replace it with STRING */ if (!strcmp(parg->type->name, "ustring") || code->op == FETCH_OP_UDEREF) @@ -1267,47 +1224,134 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, code++; if (code->op != FETCH_OP_NOP) { trace_probe_log_err(ctx->offset, TOO_MANY_OPS); - goto fail; + return -E2BIG; } code->op = FETCH_OP_ST_RAW; code->size = parg->type->size; } + + /* Save storing fetch_insn. */ scode = code; + /* Modify operation */ - if (t != NULL) { - ret = __parse_bitfield_probe_arg(t, parg->type, &code); + if (type != NULL) { + /* Bitfield needs a special fetch_insn. */ + ret = __parse_bitfield_probe_arg(type, parg->type, &code); if (ret) { - trace_probe_log_err(ctx->offset + t - arg, BAD_BITFIELD); - goto fail; + trace_probe_log_err(ctx->offset + type_offset, BAD_BITFIELD); + return ret; } } else if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS) && ctx->last_type) { + /* If user not specified the type, try parsing BTF bitfield. */ ret = parse_btf_bitfield(&code, ctx); if (ret) - goto fail; + return ret; } - ret = -EINVAL; + /* Loop(Array) operation */ if (parg->count) { if (scode->op != FETCH_OP_ST_MEM && scode->op != FETCH_OP_ST_STRING && scode->op != FETCH_OP_ST_USTRING) { - trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), - BAD_STRING); - goto fail; + trace_probe_log_err(ctx->offset + type_offset, BAD_STRING); + return -EINVAL; } code++; if (code->op != FETCH_OP_NOP) { trace_probe_log_err(ctx->offset, TOO_MANY_OPS); - goto fail; + return -E2BIG; } code->op = FETCH_OP_LP_ARRAY; code->param = parg->count; } + + /* Finalize the fetch_insn array. */ code++; code->op = FETCH_OP_END; - ret = 0; + return 0; +} + +/* String length checking wrapper */ +static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, + struct probe_arg *parg, + struct traceprobe_parse_context *ctx) +{ + struct fetch_insn *code, *tmp = NULL; + char *type, *arg; + int ret, len; + + len = strlen(argv); + if (len > MAX_ARGSTR_LEN) { + trace_probe_log_err(ctx->offset, ARG_TOO_LONG); + return -E2BIG; + } else if (len == 0) { + trace_probe_log_err(ctx->offset, NO_ARG_BODY); + return -EINVAL; + } + + arg = kstrdup(argv, GFP_KERNEL); + if (!arg) + return -ENOMEM; + + parg->comm = kstrdup(arg, GFP_KERNEL); + if (!parg->comm) { + ret = -ENOMEM; + goto out; + } + + type = parse_probe_arg_type(arg, parg, ctx); + if (IS_ERR(type)) { + ret = PTR_ERR(type); + goto out; + } + + code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL); + if (!code) { + ret = -ENOMEM; + goto out; + } + code[FETCH_INSN_MAX - 1].op = FETCH_OP_END; + + ctx->last_type = NULL; + ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1], + ctx); + if (ret < 0) + goto fail; + + /* Update storing type if BTF is available */ + if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS) && + ctx->last_type) { + if (!type) { + parg->type = find_fetch_type_from_btf_type(ctx); + } else if (strstr(type, "string")) { + ret = check_prepare_btf_string_fetch(type, &code, ctx); + if (ret) + goto fail; + } + } + parg->offset = *size; + *size += parg->type->size * (parg->count ?: 1); + + if (parg->count) { + len = strlen(parg->type->fmttype) + 6; + parg->fmt = kmalloc(len, GFP_KERNEL); + if (!parg->fmt) { + ret = -ENOMEM; + goto out; + } + snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype, + parg->count); + } + + ret = finalize_fetch_insn(code, parg, type, type ? type - arg : 0, ctx); + if (ret < 0) + goto fail; + + for (; code < tmp + FETCH_INSN_MAX; code++) + if (code->op == FETCH_OP_END) + break; /* Shrink down the code buffer */ parg->code = kcalloc(code - tmp + 1, sizeof(*code), GFP_KERNEL); if (!parg->code) @@ -1316,7 +1360,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, memcpy(parg->code, tmp, sizeof(*code) * (code - tmp + 1)); fail: - if (ret) { + if (ret < 0) { for (code = tmp; code < tmp + FETCH_INSN_MAX; code++) if (code->op == FETCH_NOP_SYMBOL || code->op == FETCH_OP_DATA) From patchwork Mon Mar 4 03:40:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200682dyc; Sun, 3 Mar 2024 19:41:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUWP5H+KlPmvPrci0QzhQPekIlfMRZ7Tjo5cY5nEvuY31yf5/LbnP4/BD0Xktq2LWq1NHLJ758OJuo3xzHDpIujBZG0oA== X-Google-Smtp-Source: AGHT+IFmDWHXz3SmJCXxsQXTSsn7BpzC/bNSHdPIXx3240eRoxQQq03v2HLbCojisHdoYdZQhhyk X-Received: by 2002:a17:903:1209:b0:1dd:4d7:aa0b with SMTP id l9-20020a170903120900b001dd04d7aa0bmr3171217plh.37.1709523676609; Sun, 03 Mar 2024 19:41:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523676; cv=pass; d=google.com; s=arc-20160816; b=U37ECas1NrX6ODv5qaAE+yf/OhEl1cMBiLMIAKGFd885gu1f7XNP9C7sdwgsd4H35O nqoYro+VIQ4Sy+FC/Tng9Z8eM9XK5KjIvjSadV7bIYjD+fiOjVJDkbEHjsEfDwd418Xf jyc7pVsoFBacrpU8DT/EXadkxE9bHYRRV0X5DmeJLNiVgkaQNuTYFAB3UzNQKLE+IkeD ehDibhgzCPC3TQfBlblkSnkS4lZ7zRVccfskmXIYatIzd4aJ01akOWzpdhAwGd5Gi+ao XWmebhDrevEFuDmO60peDwsoBmawSc9Lkvb1m3KW9EYcFCXlfjR0lhaIuTdKqzek4VjZ uVwg== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=WceA5X4zySJRiCzj/s37/X+BTFu3hUuKgjCeBGPkVeE=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=RqnOqMJuXOdnzaG2kiNez5Sa1VHK6p0rq5XEo5q+SaXm7wQI6/ETFbcY4hMmR3FtJa vjsruOGkaR9ZOsz6cG+FRiKE8ByfvgAY6NXDii5+zrKWlDIcOslcjE0Ol975vir3aWIg p9ECeOJ1FqOlsNsxB4PF/GlHNCFQ7aLal9aJQ1TY6k8fToUcmjVB3xhpaQvmrGKoCmd7 VWYkaz3Iw5vd+XNDLosuHjWXHNQrBg9b8p/fUY+tq/9cjqMRubFW6Q875xZQckvR3nLR FC1L6GXG8a2x0ZwwFd8T9X4YAgrVdB3r+xkRK1hZqNSYExHJLGbpnkFwuISdRDxdUMfq vjSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PaHIctQh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90022-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90022-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w20-20020a170903311400b001dc8344a2bcsi7347652plc.217.2024.03.03.19.41.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:41:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90022-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PaHIctQh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90022-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90022-ouuuleilei=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 4AE792814C1 for ; Mon, 4 Mar 2024 03:41:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47835AD39; Mon, 4 Mar 2024 03:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PaHIctQh" 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 816134A3E; Mon, 4 Mar 2024 03:40:40 +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=1709523640; cv=none; b=Xk2bveyiKWtQkexjAt8c2nuS2ILnrPwcqWBtyvcfN435dJMVGe21NK6su+TRF7Z8eUN+L2O1uX5Vql9N6l/wGRehxM4uOo3OLXuldGv0b9B4Xd4cpg3sw8n1D0sX4+DjsFpcPtFhSVk8fhDdxyxyfuVEKwNKWJKqOyFE+uFU30s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523640; c=relaxed/simple; bh=1Hey3CwK05YwZTBeLUkTieaMt+Bw603JtB4gBPGwNVM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=XvGmyqOc2Bc1hIgjrsZTxXi9RZTnto9flUoY9p91C9ExXc208155vY4RItPTHVXfJQ1nYX/Jh/qrKZX18SKzFNFSufyhw195L4h+3h0NrJUoRxrVKzmJs0RIyi4pkCPO4uaZM+jJKquXkNewLAVfC+i+AylzwvAljgPtbTc60fM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PaHIctQh; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F7A5C433C7; Mon, 4 Mar 2024 03:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523640; bh=1Hey3CwK05YwZTBeLUkTieaMt+Bw603JtB4gBPGwNVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PaHIctQhHtpyjMJXYj9gt6Lyd5xUZNW7l9YosYBvcmDxl9j7+nRA1dkrEF9jIHsoH cleeBdVrsBqKws+w8m6irkbRqpYi88wToWpAVnYmLn2JGzecDlwfi0hbKW7GOIxIZx LQrXk/BZRTIRyryW2SyJtaPFxHDhJ+3vwI8HMSNbh1iP0DPx7CxB6UE/tIOAtjQZAZ P2crVQr9Baken/GG1iyCdCpQ+at0SM9EPPZ6LG7vh4GUbRX8JZkEuxQ84IuWgyuDAL VW9VOGD7nVAb8FlJrprdPTftatNOj5FmXcusCfQLvj2fzx/zQIWiVozqV+AOCFYTc3 s0/colTYgkk0w== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 4/8] tracing/probes: cleanup: Set trace_probe::nr_args at trace_probe_init Date: Mon, 4 Mar 2024 12:40:36 +0900 Message-Id: <170952363585.229804.13060759900346411951.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565498304479373 X-GMAIL-MSGID: 1792565498304479373 From: Masami Hiramatsu (Google) Instead of incrementing the trace_probe::nr_args, init it at trace_probe_init(). Without this change, there is no way to get the number of trace_probe arguments while parsing it. This is a cleanup, so the behavior is not changed. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Fix build error in trace_{kprobe,fprobe}.c. - Update changelog. --- kernel/trace/trace_eprobe.c | 2 +- kernel/trace/trace_fprobe.c | 2 +- kernel/trace/trace_kprobe.c | 2 +- kernel/trace/trace_probe.c | 10 ++++++---- kernel/trace/trace_probe.h | 2 +- kernel/trace/trace_uprobe.c | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index 03c851f57969..eb72def7410f 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -220,7 +220,7 @@ static struct trace_eprobe *alloc_event_probe(const char *group, if (!ep->event_system) goto error; - ret = trace_probe_init(&ep->tp, this_event, group, false); + ret = trace_probe_init(&ep->tp, this_event, group, false, nargs); if (ret < 0) goto error; diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 3ccef4d82235..5109650b0d82 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -389,7 +389,7 @@ static struct trace_fprobe *alloc_trace_fprobe(const char *group, tf->tpoint = tpoint; tf->fp.nr_maxactive = maxactive; - ret = trace_probe_init(&tf->tp, event, group, false); + ret = trace_probe_init(&tf->tp, event, group, false, nargs); if (ret < 0) goto error; diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index c4c6e0e0068b..843f13f839df 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -290,7 +290,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group, INIT_HLIST_NODE(&tk->rp.kp.hlist); INIT_LIST_HEAD(&tk->rp.kp.list); - ret = trace_probe_init(&tk->tp, event, group, false); + ret = trace_probe_init(&tk->tp, event, group, false, nargs); if (ret < 0) goto error; diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 67a0b9cbb648..93f36f8a108e 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1423,9 +1423,6 @@ int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg, struct probe_arg *parg = &tp->args[i]; const char *body; - /* Increment count for freeing args in error case */ - tp->nr_args++; - body = strchr(arg, '='); if (body) { if (body - arg > MAX_ARG_NAME_LEN) { @@ -1810,7 +1807,7 @@ void trace_probe_cleanup(struct trace_probe *tp) } int trace_probe_init(struct trace_probe *tp, const char *event, - const char *group, bool alloc_filter) + const char *group, bool alloc_filter, int nargs) { struct trace_event_call *call; size_t size = sizeof(struct trace_probe_event); @@ -1846,6 +1843,11 @@ int trace_probe_init(struct trace_probe *tp, const char *event, goto error; } + tp->nr_args = nargs; + /* Make sure pointers in args[] are NULL */ + if (nargs) + memset(tp->args, 0, sizeof(tp->args[0]) * nargs); + return 0; error: diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index c1877d018269..ed8d1052f8a7 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -338,7 +338,7 @@ static inline bool trace_probe_has_single_file(struct trace_probe *tp) } int trace_probe_init(struct trace_probe *tp, const char *event, - const char *group, bool alloc_filter); + const char *group, bool alloc_filter, int nargs); void trace_probe_cleanup(struct trace_probe *tp); int trace_probe_append(struct trace_probe *tp, struct trace_probe *to); void trace_probe_unlink(struct trace_probe *tp); diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index a84b85d8aac1..796ebcae9b38 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -337,7 +337,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret) if (!tu) return ERR_PTR(-ENOMEM); - ret = trace_probe_init(&tu->tp, event, group, true); + ret = trace_probe_init(&tu->tp, event, group, true, nargs); if (ret < 0) goto error; From patchwork Mon Mar 4 03:40:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200733dyc; Sun, 3 Mar 2024 19:41:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7K5W4Be291vLUuifSXqLDaNGl2GTRma8Bs45yR8du3a2Z9mDyjakB81ABVFeX3UPhZHsh/8FBlzrfH6ZeBOl+O7fKcg== X-Google-Smtp-Source: AGHT+IFr7qr+0Tu3+yp5Y3KY8jwVNqGlZj62NLHENBOz7A1vxU0sf063WqO3t9sI8YzM3pOhsihI X-Received: by 2002:a17:902:f688:b0:1dc:3d5:bdcc with SMTP id l8-20020a170902f68800b001dc03d5bdccmr8187710plg.42.1709523689992; Sun, 03 Mar 2024 19:41:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523689; cv=pass; d=google.com; s=arc-20160816; b=UCGGZtRCi34slXkJUbhnO+udQjasUOAxe01cpFJnzAVCMSzhMjjiwCBexAMU4bzSOx +QieqkOJHRzWPA2onncsyddFXIKLe01soPkpQTEzv3dYeuzzemKv6UOc0+SYUCQDEat+ 56RJpu57IxxuSab95iJ3WDgIMmk/NlprevIj3td5cT2TJ82dktmgmGEw7mz0f2UA/txq VgFqhz+ufBijeX3lGmgtYiTnYtK7Ks56ROuSihV+cJnDzV6tqtBMZTkHJsR6yQVg9yWx 5RHj6lwPN5065Az/fSuQwnhMHbqNvO/kHxf8BaZMFmIdf6QCFb5Hyuvi/W+AUp3DiUKd XDbg== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=dIB6L4xypx9KPlcjL2ZjNOu8Qz79/CagUbnq6KVyVRg=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=g9yPJ1qkyvBrxeyJShVg7d8ckw/s3MLX9HSLRdpaDeDr5tVixoWD2zGVQY6cMirvye S+hI2T2fbJHvqQ3QPM64lrwTGu2yX0hCgM9Pwp+VIRrHV4Enu4AUJ945q0E9TK/5NS4R ccnqknVtguv+xEsmF1CzYsHH3aPU7qT9MYr//bJrqz/jFWUk9RYIG0O7+e0PY7M96RM2 j9iTFt/2c6w2pnuAN9QazED1HPpZZiHa0DE3EOi7VKpXjhS5q3VlUrK4xFtDPzmzpbQk 7TdWbAao1VBLPMP9LGtJF9RMzVF0afmFk3XKETiDkRgEQfKUh4Zb7kT25mtftvFwvAwI jl6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nMfzHCFR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90023-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90023-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p16-20020a1709027ed000b001dd117b7b35si1071386plb.612.2024.03.03.19.41.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:41:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90023-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nMfzHCFR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90023-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90023-ouuuleilei=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 C2B4E2815DE for ; Mon, 4 Mar 2024 03:41:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4DC4AD5E; Mon, 4 Mar 2024 03:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nMfzHCFR" 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 36D56613A; Mon, 4 Mar 2024 03:40:50 +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=1709523650; cv=none; b=Za2kRW6DBTnEey9Eq7TD/0PErCNUbczhuQAGLMpdkZCA8wr/o/BEdnP78WnBZvs49fe+AW4Dyopy3Pq3mxuE4e5/03+eGzTei2MGFo+DyVlxxcuggqNMC6PCkZHN4kCq8bX6uWk92zX+iDO7DL2cmyYdIS22fJChbfDs9e+29nY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523650; c=relaxed/simple; bh=JOiQGf8AkuLDba6mZptSjrJ64jXNcst88pFN6BENs2Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=XnpiO+7Kl5ddfIf5cHE/uR40kLSaSNvTWC9f6TQHBZ5uoCkwPttDwq9AvHz3kgobB+vzEQAwFW3kh+sFhXMO0Gzvnatg7TX+J1rgaa+rpS2vf3z/ZyW4fyOk0JxJV9eVKrwmXw/jrfdwKTY52nfusb5ajeNUas9d6qfBQKztoeM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nMfzHCFR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 461ACC433F1; Mon, 4 Mar 2024 03:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523650; bh=JOiQGf8AkuLDba6mZptSjrJ64jXNcst88pFN6BENs2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nMfzHCFRn1m/iFXZjsu3f9uPO6ciPqAFm5qem2l0RoitTTr3fj31eKZRyOkdnRHgV IRvw1ocrf5bc/FrITz2gA4KQMIKPI/oIDoGbnbTyF/xKE1pw6Y7RTBUJb1wCn6m8IK fqnPdfQHWKg4bq+7W+vi0aIaOu2QU/HLsfTUoRKDAbUxNWPtIMMNyI/73Av/yJY8O5 39M/S/44JhZvRnqh4l17i3jLrmpu83mT3LqAJjhLiz24JVrIaeSg0oqziST8r1Son3 e6prsPegjgk2tu3h8rtrqp+8+6Kb+iWqqNe5QtBK6Lx345uRBx7QIwQKu2MGJ6WEvN 36s6eXaAMDQ0w== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 5/8] tracing: Remove redundant #else block for BTF args from README Date: Mon, 4 Mar 2024 12:40:45 +0900 Message-Id: <170952364558.229804.17285528811097152410.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565512638391596 X-GMAIL-MSGID: 1792565512638391596 From: Masami Hiramatsu (Google) Remove redundant #else block for BTF args from README message. This is a cleanup, so no change on the message. Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8198bfc54b58..516c585f5879 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5747,11 +5747,9 @@ static const char readme_msg[] = "\t args: =fetcharg[:type]\n" "\t fetcharg: (%|$), @
, @[+|-],\n" #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API -#ifdef CONFIG_PROBE_EVENTS_BTF_ARGS "\t $stack, $stack, $retval, $comm, $arg,\n" +#ifdef CONFIG_PROBE_EVENTS_BTF_ARGS "\t [->field[->field|.field...]],\n" -#else - "\t $stack, $stack, $retval, $comm, $arg,\n" #endif #else "\t $stack, $stack, $retval, $comm,\n" From patchwork Mon Mar 4 03:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200813dyc; Sun, 3 Mar 2024 19:41:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX4TrBa4MHPWesGJ6+xo2d1JCqAhpIukfQNYojC3MWf5NA7YLH9ODnFXPSmWoh6lY99aT/BroEcTSPXuRkTBhhqDp1Oag== X-Google-Smtp-Source: AGHT+IFb+M5poID8zwNGU7pcvxLFoY+3EnQIKQPLj2dxhKqlw3uSUlcRqwF4DuFWEZi0n+cA4xGV X-Received: by 2002:a05:6830:108f:b0:6e4:7b1a:e334 with SMTP id y15-20020a056830108f00b006e47b1ae334mr8010331oto.20.1709523704577; Sun, 03 Mar 2024 19:41:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523704; cv=pass; d=google.com; s=arc-20160816; b=DSp2541GBcGvdpvD2OvgA3sffIHMaY56SSXVAQ9yawY3h6d90aGOXM17Itt68lp/hu sc6Q9EBGihisGds34Wo966cmalE9bRJj2A8n04/M/csBK5eb0Hlix3JR72sya7h7HJZi OKYLSU7ARPwNuqsFhYLrD9K8RiQ79xu4ZQ8KSazy3OuaRs4BDOvDvm5BbLhpZwvjMvoE iFtppH7WT6Giy+NddLOVmQfIOXWbVBazmmLOK6VsECRHscQT7e4Zrdoh8MAY6QzNu0x6 3Ce9XXzf9vAs9xIBAMNVbHvRVvc/wYqvX2UMsVkEwwc422LluS2mLEg0oMN3WxVDm9oi vO6w== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=RVJYoq3it/M8KjEQCl/eQ0wg2ptyxXOPicBC4QRv6KI=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=dnT0hamzJPH3DnB9LblD9oM52RDqRYSJO+TZ4gapOYSlKwMPLObJNur6tJnCeCEJye /4MkL69Bjtsmq1UzVcefsIvdr2PlSWjsGlClTEAs0vwMz+Owo5d2jivLex1lwAf/RzfM 4uO1JkgR6JQy2eulsNWqGOgLHcCh6Sh2KYi3BEOLwBeCKYcFuwSvBHX6XArRV8geQ6W2 JBRDAP/YfRFN8sbm8U0iyBxUneDNxQrdrNldP0BQvZdY7nSjJqj6oRdcFpogOl18tqha xZGmT3+8j0BUQxGN4C2eTjD7e8X5bAYQeN062hC/aQ+kx6M6+3wSJOYw9QBlcC78gPsi RE1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cppd5zti; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90024-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90024-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o6-20020a634106000000b005d8e2f56d82si7643010pga.867.2024.03.03.19.41.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:41:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90024-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cppd5zti; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90024-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90024-ouuuleilei=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 5A09D28157E for ; Mon, 4 Mar 2024 03:41:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38B668801; Mon, 4 Mar 2024 03:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cppd5zti" 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 05349522D; Mon, 4 Mar 2024 03:40:59 +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=1709523660; cv=none; b=IOGgSwsZMe4hSwvA6BWVzBrSVqhg2/Ii43nyfUzCO3MyYugpzQ5VZJDyfMjbsiwUFviI+1EZjjsOJEo+QDK2bdaLn/sFrVZZonW6B7ko8vZkQV0KQV0W59d+e1ONPF0W6vH6wbb7O1qAHdu6Cb/7DYGBFZAnfhVhwP7DbmjGCBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523660; c=relaxed/simple; bh=xm8eNDqvHmVGlbVU4cCHv8Nn3II5JsS0sODOnfHfYpI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=emOHcIBj1rB1SeQJQdhTp4NezDJXj+IihaFExgnI8SUeDmKpWBHmRweDDPYmBBMdmRxIapyuz2jDCNa+NXaz1dvQabSCEBd8M9M9KsAi/2CZ+zdlrrhuXvi7LoxSvhTgqcAKPEYUe+yHrNf3Y8Vqzf9WsgWHxw+sKrlLK3FlNHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cppd5zti; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE9CEC433F1; Mon, 4 Mar 2024 03:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523659; bh=xm8eNDqvHmVGlbVU4cCHv8Nn3II5JsS0sODOnfHfYpI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cppd5ztiuMjeJEsLZp1EVk1ExWf95XSjzA6J0WwQ3hr4KP2WgqzKmEU9fZQj1qV0x 1MbZ/OeGdTYE47OXEZamxO2oyCjLxq1pIdvSNLrMdK7WTtgjLR+u70EpzEFCQ13YvK 8nwQYPAWgbw7K/d1or/Il9C+PhZyFBqmJRCExmNZdlrGDt3InthVEBAE/i2GlVO881 ftykt1nRXIXihLlJY+rI0O293mi0djEbJZZo2iSHP8MTEv59PmlCYvArRvhKa9POK7 5zCzjpQ+ZPtxn4CxtToXen5HWqrcqnd8/o3gGAfnSoPNNPh6GuI2l0yGEIwPndaly9 WrYtyVD/R0AFw== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 6/8] tracing/probes: Support $argN in return probe (kprobe and fprobe) Date: Mon, 4 Mar 2024 12:40:55 +0900 Message-Id: <170952365552.229804.224112990211602895.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565528147082174 X-GMAIL-MSGID: 1792565528147082174 From: Masami Hiramatsu (Google) Support accessing $argN in the return probe events. This will help users to record entry data in function return (exit) event for simplfing the function entry/exit information in one event, and record the result values (e.g. allocated object/initialized object) at function exit. For example, if we have a function `int init_foo(struct foo *obj, int param)` sometimes we want to check how `obj` is initialized. In such case, we can define a new return event like below; # echo 'r init_foo retval=$retval param=$arg2 field1=+0($arg1)' >> kprobe_events Thus it records the function parameter `param` and its result `obj->field1` (the dereference will be done in the function exit timing) value at once. This also support fprobe, BTF args and'$arg*'. So if CONFIG_DEBUG_INFO_BTF is enabled, we can trace both function parameters and the return value by following command. # echo 'f target_function%return $arg* $retval' >> dynamic_events Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Fix syntax error check selftests because now some syntax error will not happen. Changes in v2: - Update README message --- kernel/trace/trace.c | 1 kernel/trace/trace_eprobe.c | 6 - kernel/trace/trace_fprobe.c | 55 ++++-- kernel/trace/trace_kprobe.c | 56 +++++- kernel/trace/trace_probe.c | 177 ++++++++++++++++++-- kernel/trace/trace_probe.h | 28 +++ kernel/trace/trace_probe_tmpl.h | 10 + kernel/trace/trace_uprobe.c | 12 + .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc | 4 .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 2 10 files changed, 289 insertions(+), 62 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 516c585f5879..71a96decc276 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5755,6 +5755,7 @@ static const char readme_msg[] = "\t $stack, $stack, $retval, $comm,\n" #endif "\t +|-[u](), \\imm-value, \\\"imm-string\"\n" + "\t kernel return probes support: $retval, $arg, $comm\n" "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, char, string, symbol,\n" "\t b@/, ustring,\n" "\t symstr, \\[\\]\n" diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index eb72def7410f..b0e0ec85912e 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -390,8 +390,8 @@ static int get_eprobe_size(struct trace_probe *tp, void *rec) /* Note that we don't verify it, since the code does not come from user space */ static int -process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, - void *base) +process_fetch_insn(struct fetch_insn *code, void *rec, void *edata, + void *dest, void *base) { unsigned long val; int ret; @@ -438,7 +438,7 @@ __eprobe_trace_func(struct eprobe_data *edata, void *rec) return; entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event); - store_trace_args(&entry[1], &edata->ep->tp, rec, sizeof(*entry), dsize); + store_trace_args(&entry[1], &edata->ep->tp, rec, NULL, sizeof(*entry), dsize); trace_event_buffer_commit(&fbuffer); } diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 5109650b0d82..4f4280815522 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -4,6 +4,7 @@ * Copyright (C) 2022 Google LLC. */ #define pr_fmt(fmt) "trace_fprobe: " fmt +#include #include #include @@ -129,8 +130,8 @@ static bool trace_fprobe_is_registered(struct trace_fprobe *tf) * from user space. */ static int -process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, - void *base) +process_fetch_insn(struct fetch_insn *code, void *rec, void *edata, + void *dest, void *base) { struct pt_regs *regs = rec; unsigned long val; @@ -152,6 +153,9 @@ process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, case FETCH_OP_ARG: val = regs_get_kernel_argument(regs, code->param); break; + case FETCH_OP_EDATA: + val = *(unsigned long *)((unsigned long)edata + code->offset); + break; #endif case FETCH_NOP_SYMBOL: /* Ignore a place holder */ code++; @@ -184,7 +188,7 @@ __fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, if (trace_trigger_soft_disabled(trace_file)) return; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, regs, NULL); entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry) + tf->tp.size + dsize); @@ -194,7 +198,7 @@ __fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, fbuffer.regs = regs; entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event); entry->ip = entry_ip; - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, regs, NULL, sizeof(*entry), dsize); trace_event_buffer_commit(&fbuffer); } @@ -211,10 +215,23 @@ fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, NOKPROBE_SYMBOL(fentry_trace_func); /* function exit handler */ +static int trace_fprobe_entry_handler(struct fprobe *fp, unsigned long entry_ip, + unsigned long ret_ip, struct pt_regs *regs, + void *entry_data) +{ + struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); + + if (tf->tp.entry_arg) + store_trace_entry_data(entry_data, &tf->tp, regs); + + return 0; +} +NOKPROBE_SYMBOL(trace_fprobe_entry_handler) + static nokprobe_inline void __fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, - struct trace_event_file *trace_file) + void *entry_data, struct trace_event_file *trace_file) { struct fexit_trace_entry_head *entry; struct trace_event_buffer fbuffer; @@ -227,7 +244,7 @@ __fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, if (trace_trigger_soft_disabled(trace_file)) return; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, regs, entry_data); entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry) + tf->tp.size + dsize); @@ -238,19 +255,19 @@ __fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event); entry->func = entry_ip; entry->ret_ip = ret_ip; - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, regs, entry_data, sizeof(*entry), dsize); trace_event_buffer_commit(&fbuffer); } static void fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs) + unsigned long ret_ip, struct pt_regs *regs, void *entry_data) { struct event_file_link *link; trace_probe_for_each_link_rcu(link, &tf->tp) - __fexit_trace_func(tf, entry_ip, ret_ip, regs, link->file); + __fexit_trace_func(tf, entry_ip, ret_ip, regs, entry_data, link->file); } NOKPROBE_SYMBOL(fexit_trace_func); @@ -269,7 +286,7 @@ static int fentry_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, if (hlist_empty(head)) return 0; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, regs, NULL); __size = sizeof(*entry) + tf->tp.size + dsize; size = ALIGN(__size + sizeof(u32), sizeof(u64)); size -= sizeof(u32); @@ -280,7 +297,7 @@ static int fentry_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, entry->ip = entry_ip; memset(&entry[1], 0, dsize); - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, regs, NULL, sizeof(*entry), dsize); perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, head, NULL); return 0; @@ -289,7 +306,8 @@ NOKPROBE_SYMBOL(fentry_perf_func); static void fexit_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs) + unsigned long ret_ip, struct pt_regs *regs, + void *entry_data) { struct trace_event_call *call = trace_probe_event_call(&tf->tp); struct fexit_trace_entry_head *entry; @@ -301,7 +319,7 @@ fexit_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, if (hlist_empty(head)) return; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, regs, entry_data); __size = sizeof(*entry) + tf->tp.size + dsize; size = ALIGN(__size + sizeof(u32), sizeof(u64)); size -= sizeof(u32); @@ -312,7 +330,7 @@ fexit_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, entry->func = entry_ip; entry->ret_ip = ret_ip; - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, regs, entry_data, sizeof(*entry), dsize); perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, head, NULL); } @@ -343,10 +361,10 @@ static void fexit_dispatcher(struct fprobe *fp, unsigned long entry_ip, struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE)) - fexit_trace_func(tf, entry_ip, ret_ip, regs); + fexit_trace_func(tf, entry_ip, ret_ip, regs, entry_data); #ifdef CONFIG_PERF_EVENTS if (trace_probe_test_flag(&tf->tp, TP_FLAG_PROFILE)) - fexit_perf_func(tf, entry_ip, ret_ip, regs); + fexit_perf_func(tf, entry_ip, ret_ip, regs, entry_data); #endif } NOKPROBE_SYMBOL(fexit_dispatcher); @@ -1109,6 +1127,11 @@ static int __trace_fprobe_create(int argc, const char *argv[]) goto error; /* This can be -ENOMEM */ } + if (is_return && tf->tp.entry_arg) { + tf->fp.entry_handler = trace_fprobe_entry_handler; + tf->fp.entry_data_size = traceprobe_get_entry_data_size(&tf->tp); + } + ret = traceprobe_set_print_fmt(&tf->tp, is_return ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL); if (ret < 0) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 843f13f839df..14099cc17fc9 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -740,6 +740,9 @@ static unsigned int number_of_same_symbols(char *func_name) return ctx.count; } +static int trace_kprobe_entry_handler(struct kretprobe_instance *ri, + struct pt_regs *regs); + static int __trace_kprobe_create(int argc, const char *argv[]) { /* @@ -948,6 +951,11 @@ static int __trace_kprobe_create(int argc, const char *argv[]) if (ret) goto error; /* This can be -ENOMEM */ } + /* entry handler for kretprobe */ + if (is_return && tk->tp.entry_arg) { + tk->rp.entry_handler = trace_kprobe_entry_handler; + tk->rp.data_size = traceprobe_get_entry_data_size(&tk->tp); + } ptype = is_return ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL; ret = traceprobe_set_print_fmt(&tk->tp, ptype); @@ -1303,8 +1311,8 @@ static const struct file_operations kprobe_profile_ops = { /* Note that we don't verify it, since the code does not come from user space */ static int -process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, - void *base) +process_fetch_insn(struct fetch_insn *code, void *rec, void *edata, + void *dest, void *base) { struct pt_regs *regs = rec; unsigned long val; @@ -1329,6 +1337,9 @@ process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, case FETCH_OP_ARG: val = regs_get_kernel_argument(regs, code->param); break; + case FETCH_OP_EDATA: + val = *(unsigned long *)((unsigned long)edata + code->offset); + break; #endif case FETCH_NOP_SYMBOL: /* Ignore a place holder */ code++; @@ -1359,7 +1370,7 @@ __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs, if (trace_trigger_soft_disabled(trace_file)) return; - dsize = __get_data_size(&tk->tp, regs); + dsize = __get_data_size(&tk->tp, regs, NULL); entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry) + tk->tp.size + dsize); @@ -1368,7 +1379,7 @@ __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs, fbuffer.regs = regs; entry->ip = (unsigned long)tk->rp.kp.addr; - store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tk->tp, regs, NULL, sizeof(*entry), dsize); trace_event_buffer_commit(&fbuffer); } @@ -1384,6 +1395,31 @@ kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs) NOKPROBE_SYMBOL(kprobe_trace_func); /* Kretprobe handler */ + +static int trace_kprobe_entry_handler(struct kretprobe_instance *ri, + struct pt_regs *regs) +{ + struct kretprobe *rp = get_kretprobe(ri); + struct trace_kprobe *tk; + + /* + * There is a small chance that get_kretprobe(ri) returns NULL when + * the kretprobe is unregister on another CPU between kretprobe's + * trampoline_handler and this function. + */ + if (unlikely(!rp)) + return -ENOENT; + + tk = container_of(rp, struct trace_kprobe, rp); + + /* store argument values into ri->data as entry data */ + if (tk->tp.entry_arg) + store_trace_entry_data(ri->data, &tk->tp, regs); + + return 0; +} + + static nokprobe_inline void __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, struct pt_regs *regs, @@ -1399,7 +1435,7 @@ __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, if (trace_trigger_soft_disabled(trace_file)) return; - dsize = __get_data_size(&tk->tp, regs); + dsize = __get_data_size(&tk->tp, regs, ri->data); entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry) + tk->tp.size + dsize); @@ -1409,7 +1445,7 @@ __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, fbuffer.regs = regs; entry->func = (unsigned long)tk->rp.kp.addr; entry->ret_ip = get_kretprobe_retaddr(ri); - store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tk->tp, regs, ri->data, sizeof(*entry), dsize); trace_event_buffer_commit(&fbuffer); } @@ -1557,7 +1593,7 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs) if (hlist_empty(head)) return 0; - dsize = __get_data_size(&tk->tp, regs); + dsize = __get_data_size(&tk->tp, regs, NULL); __size = sizeof(*entry) + tk->tp.size + dsize; size = ALIGN(__size + sizeof(u32), sizeof(u64)); size -= sizeof(u32); @@ -1568,7 +1604,7 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs) entry->ip = (unsigned long)tk->rp.kp.addr; memset(&entry[1], 0, dsize); - store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tk->tp, regs, NULL, sizeof(*entry), dsize); perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, head, NULL); return 0; @@ -1593,7 +1629,7 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, if (hlist_empty(head)) return; - dsize = __get_data_size(&tk->tp, regs); + dsize = __get_data_size(&tk->tp, regs, ri->data); __size = sizeof(*entry) + tk->tp.size + dsize; size = ALIGN(__size + sizeof(u32), sizeof(u64)); size -= sizeof(u32); @@ -1604,7 +1640,7 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, entry->func = (unsigned long)tk->rp.kp.addr; entry->ret_ip = get_kretprobe_retaddr(ri); - store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tk->tp, regs, ri->data, sizeof(*entry), dsize); perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, head, NULL); } diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 93f36f8a108e..217169de0920 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -594,6 +594,8 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type, return 0; } +static int __store_entry_arg(struct trace_probe *tp, int argnum); + static int parse_btf_arg(char *varname, struct fetch_insn **pcode, struct fetch_insn *end, struct traceprobe_parse_context *ctx) @@ -618,11 +620,7 @@ static int parse_btf_arg(char *varname, return -EOPNOTSUPP; } - if (ctx->flags & TPARG_FL_RETURN) { - if (strcmp(varname, "$retval") != 0) { - trace_probe_log_err(ctx->offset, NO_BTFARG); - return -ENOENT; - } + if (ctx->flags & TPARG_FL_RETURN && !strcmp(varname, "$retval")) { code->op = FETCH_OP_RETVAL; /* Check whether the function return type is not void */ if (query_btf_context(ctx) == 0) { @@ -654,11 +652,21 @@ static int parse_btf_arg(char *varname, const char *name = btf_name_by_offset(ctx->btf, params[i].name_off); if (name && !strcmp(name, varname)) { - code->op = FETCH_OP_ARG; - if (ctx->flags & TPARG_FL_TPOINT) - code->param = i + 1; - else - code->param = i; + if (tparg_is_function_entry(ctx->flags)) { + code->op = FETCH_OP_ARG; + if (ctx->flags & TPARG_FL_TPOINT) + code->param = i + 1; + else + code->param = i; + } else if (tparg_is_function_return(ctx->flags)) { + code->op = FETCH_OP_EDATA; + ret = __store_entry_arg(ctx->tp, i); + if (ret < 0) { + /* internal error */ + return ret; + } + code->offset = ret; + } tid = params[i].type; goto found; } @@ -755,6 +763,110 @@ static int check_prepare_btf_string_fetch(char *typename, #endif +#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API + +static int __store_entry_arg(struct trace_probe *tp, int argnum) +{ + struct probe_entry_arg *earg = tp->entry_arg; + bool match = false; + int i, offset; + + if (!earg) { + earg = kzalloc(sizeof(*tp->entry_arg), GFP_KERNEL); + if (!earg) + return -ENOMEM; + earg->size = 2 * tp->nr_args + 1; + earg->code = kcalloc(earg->size, sizeof(struct fetch_insn), + GFP_KERNEL); + if (!earg->code) { + kfree(earg); + return -ENOMEM; + } + /* Fill the code buffer with 'end' to simplify it */ + for (i = 0; i < earg->size; i++) + earg->code[i].op = FETCH_OP_END; + tp->entry_arg = earg; + } + + offset = 0; + for (i = 0; i < earg->size - 1; i++) { + switch (earg->code[i].op) { + case FETCH_OP_END: + earg->code[i].op = FETCH_OP_ARG; + earg->code[i].param = argnum; + earg->code[i + 1].op = FETCH_OP_ST_EDATA; + earg->code[i + 1].offset = offset; + return offset; + case FETCH_OP_ARG: + match = (earg->code[i].param == argnum); + break; + case FETCH_OP_ST_EDATA: + offset = earg->code[i].offset; + if (match) + return offset; + offset += sizeof(unsigned long); + break; + default: + break; + } + } + return -ENOSPC; +} + +int traceprobe_get_entry_data_size(struct trace_probe *tp) +{ + struct probe_entry_arg *earg = tp->entry_arg; + int i, size = 0; + + if (!earg) + return 0; + + for (i = 0; i < earg->size; i++) { + switch (earg->code[i].op) { + case FETCH_OP_END: + goto out; + case FETCH_OP_ST_EDATA: + size = earg->code[i].offset + sizeof(unsigned long); + break; + default: + break; + } + } +out: + return size; +} + +void store_trace_entry_data(void *edata, struct trace_probe *tp, struct pt_regs *regs) +{ + struct probe_entry_arg *earg = tp->entry_arg; + unsigned long val; + int i; + + if (!earg) + return; + + for (i = 0; i < earg->size; i++) { + struct fetch_insn *code = &earg->code[i]; + + switch (code->op) { + case FETCH_OP_ARG: + val = regs_get_kernel_argument(regs, code->param); + break; + case FETCH_OP_ST_EDATA: + *(unsigned long *)((unsigned long)edata + code->offset) = val; + break; + case FETCH_OP_END: + goto end; + default: + break; + } + } +end: + return; +} +NOKPROBE_SYMBOL(store_trace_entry_data) +#endif + #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) /* Parse $vars. @orig_arg points '$', which syncs to @ctx->offset */ @@ -830,7 +942,7 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t, #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API len = str_has_prefix(arg, "arg"); - if (len && tparg_is_function_entry(ctx->flags)) { + if (len) { ret = kstrtoul(arg + len, 10, ¶m); if (ret) goto inval; @@ -839,15 +951,29 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t, err = TP_ERR_BAD_ARG_NUM; goto inval; } + param--; /* argN starts from 1, but internal arg[N] starts from 0 */ - code->op = FETCH_OP_ARG; - code->param = (unsigned int)param - 1; - /* - * The tracepoint probe will probe a stub function, and the - * first parameter of the stub is a dummy and should be ignored. - */ - if (ctx->flags & TPARG_FL_TPOINT) - code->param++; + if (tparg_is_function_entry(ctx->flags)) { + code->op = FETCH_OP_ARG; + code->param = (unsigned int)param; + /* + * The tracepoint probe will probe a stub function, and the + * first parameter of the stub is a dummy and should be ignored. + */ + if (ctx->flags & TPARG_FL_TPOINT) + code->param++; + } else if (tparg_is_function_return(ctx->flags)) { + /* function entry argument access from return probe */ + ret = __store_entry_arg(ctx->tp, param); + if (ret < 0) /* This error should be an internal error */ + return ret; + + code->op = FETCH_OP_EDATA; + code->offset = ret; + } else { + err = TP_ERR_NOFENTRY_ARGS; + goto inval; + } return 0; } #endif @@ -1037,7 +1163,8 @@ parse_probe_arg(char *arg, const struct fetch_type *type, break; default: if (isalpha(arg[0]) || arg[0] == '_') { /* BTF variable */ - if (!tparg_is_function_entry(ctx->flags)) { + if (!tparg_is_function_entry(ctx->flags) && + !tparg_is_function_return(ctx->flags)) { trace_probe_log_err(ctx->offset, NOSUP_BTFARG); return -EINVAL; } @@ -1423,6 +1550,7 @@ int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg, struct probe_arg *parg = &tp->args[i]; const char *body; + ctx->tp = tp; body = strchr(arg, '='); if (body) { if (body - arg > MAX_ARG_NAME_LEN) { @@ -1479,7 +1607,8 @@ static int argv_has_var_arg(int argc, const char *argv[], int *args_idx, if (str_has_prefix(argv[i], "$arg")) { trace_probe_log_set_index(i + 2); - if (!tparg_is_function_entry(ctx->flags)) { + if (!tparg_is_function_entry(ctx->flags) && + !tparg_is_function_return(ctx->flags)) { trace_probe_log_err(0, NOFENTRY_ARGS); return -EINVAL; } @@ -1802,6 +1931,12 @@ void trace_probe_cleanup(struct trace_probe *tp) for (i = 0; i < tp->nr_args; i++) traceprobe_free_probe_arg(&tp->args[i]); + if (tp->entry_arg) { + kfree(tp->entry_arg->code); + kfree(tp->entry_arg); + tp->entry_arg = NULL; + } + if (tp->event) trace_probe_unlink(tp); } diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index ed8d1052f8a7..cef3a50628a3 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -92,6 +92,7 @@ enum fetch_op { FETCH_OP_ARG, /* Function argument : .param */ FETCH_OP_FOFFS, /* File offset: .immediate */ FETCH_OP_DATA, /* Allocated data: .data */ + FETCH_OP_EDATA, /* Entry data: .offset */ // Stage 2 (dereference) op FETCH_OP_DEREF, /* Dereference: .offset */ FETCH_OP_UDEREF, /* User-space Dereference: .offset */ @@ -102,6 +103,7 @@ enum fetch_op { FETCH_OP_ST_STRING, /* String: .offset, .size */ FETCH_OP_ST_USTRING, /* User String: .offset, .size */ FETCH_OP_ST_SYMSTR, /* Kernel Symbol String: .offset, .size */ + FETCH_OP_ST_EDATA, /* Store Entry Data: .offset */ // Stage 4 (modify) op FETCH_OP_MOD_BF, /* Bitfield: .basesize, .lshift, .rshift */ // Stage 5 (loop) op @@ -232,6 +234,11 @@ struct probe_arg { const struct fetch_type *type; /* Type of this argument */ }; +struct probe_entry_arg { + struct fetch_insn *code; + unsigned int size; /* The entry data size */ +}; + struct trace_uprobe_filter { rwlock_t rwlock; int nr_systemwide; @@ -253,6 +260,7 @@ struct trace_probe { struct trace_probe_event *event; ssize_t size; /* trace entry size */ unsigned int nr_args; + struct probe_entry_arg *entry_arg; /* This is only for return probe */ struct probe_arg args[]; }; @@ -355,6 +363,18 @@ int trace_probe_create(const char *raw_command, int (*createfn)(int, const char int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args, u8 *data, void *field); +#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API +int traceprobe_get_entry_data_size(struct trace_probe *tp); +/* This is a runtime function to store entry data */ +void store_trace_entry_data(void *edata, struct trace_probe *tp, struct pt_regs *regs); +#else /* !CONFIG_HAVE_FUNCTION_ARG_ACCESS_API */ +static inline int traceprobe_get_entry_data_size(struct trace_probe *tp) +{ + return 0; +} +#define store_trace_entry_data(edata, tp, regs) do { } while (0) +#endif + #define trace_probe_for_each_link(pos, tp) \ list_for_each_entry(pos, &(tp)->event->files, list) #define trace_probe_for_each_link_rcu(pos, tp) \ @@ -381,6 +401,11 @@ static inline bool tparg_is_function_entry(unsigned int flags) return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_FENTRY); } +static inline bool tparg_is_function_return(unsigned int flags) +{ + return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_RETURN); +} + struct traceprobe_parse_context { struct trace_event_call *event; /* BTF related parameters */ @@ -392,6 +417,7 @@ struct traceprobe_parse_context { const struct btf_type *last_type; /* Saved type */ u32 last_bitoffs; /* Saved bitoffs */ u32 last_bitsize; /* Saved bitsize */ + struct trace_probe *tp; unsigned int flags; int offset; }; @@ -506,7 +532,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call, C(NO_BTFARG, "This variable is not found at this probe point"),\ C(NO_BTF_ENTRY, "No BTF entry for this probe point"), \ C(BAD_VAR_ARGS, "$arg* must be an independent parameter without name etc."),\ - C(NOFENTRY_ARGS, "$arg* can be used only on function entry"), \ + C(NOFENTRY_ARGS, "$arg* can be used only on function entry or exit"), \ C(DOUBLE_ARGS, "$arg* can be used only once in the parameters"), \ C(ARGS_2LONG, "$arg* failed because the argument list is too long"), \ C(ARGIDX_2BIG, "$argN index is too big"), \ diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 3935b347f874..2caf0d2afb32 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -54,7 +54,7 @@ fetch_apply_bitfield(struct fetch_insn *code, void *buf) * If dest is NULL, don't store result and return required dynamic data size. */ static int -process_fetch_insn(struct fetch_insn *code, void *rec, +process_fetch_insn(struct fetch_insn *code, void *rec, void *edata, void *dest, void *base); static nokprobe_inline int fetch_store_strlen(unsigned long addr); static nokprobe_inline int @@ -232,7 +232,7 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val, /* Sum up total data length for dynamic arrays (strings) */ static nokprobe_inline int -__get_data_size(struct trace_probe *tp, struct pt_regs *regs) +__get_data_size(struct trace_probe *tp, struct pt_regs *regs, void *edata) { struct probe_arg *arg; int i, len, ret = 0; @@ -240,7 +240,7 @@ __get_data_size(struct trace_probe *tp, struct pt_regs *regs) for (i = 0; i < tp->nr_args; i++) { arg = tp->args + i; if (unlikely(arg->dynamic)) { - len = process_fetch_insn(arg->code, regs, NULL, NULL); + len = process_fetch_insn(arg->code, regs, edata, NULL, NULL); if (len > 0) ret += len; } @@ -251,7 +251,7 @@ __get_data_size(struct trace_probe *tp, struct pt_regs *regs) /* Store the value of each argument */ static nokprobe_inline void -store_trace_args(void *data, struct trace_probe *tp, void *rec, +store_trace_args(void *data, struct trace_probe *tp, void *rec, void *edata, int header_size, int maxlen) { struct probe_arg *arg; @@ -266,7 +266,7 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec, /* Point the dynamic data area if needed */ if (unlikely(arg->dynamic)) *dl = make_data_loc(maxlen, dyndata - base); - ret = process_fetch_insn(arg->code, rec, dl, base); + ret = process_fetch_insn(arg->code, rec, edata, dl, base); if (arg->dynamic && likely(ret > 0)) { dyndata += ret; maxlen -= ret; diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 796ebcae9b38..9e461362450a 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -211,8 +211,8 @@ static unsigned long translate_user_vaddr(unsigned long file_offset) /* Note that we don't verify it, since the code does not come from user space */ static int -process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, - void *base) +process_fetch_insn(struct fetch_insn *code, void *rec, void *edata, + void *dest, void *base) { struct pt_regs *regs = rec; unsigned long val; @@ -1490,11 +1490,11 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs) if (WARN_ON_ONCE(!uprobe_cpu_buffer)) return 0; - dsize = __get_data_size(&tu->tp, regs); + dsize = __get_data_size(&tu->tp, regs, NULL); esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); ucb = uprobe_buffer_get(); - store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize); + store_trace_args(ucb->buf, &tu->tp, regs, NULL, esize, dsize); if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) ret |= uprobe_trace_func(tu, regs, ucb, dsize); @@ -1525,11 +1525,11 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con, if (WARN_ON_ONCE(!uprobe_cpu_buffer)) return 0; - dsize = __get_data_size(&tu->tp, regs); + dsize = __get_data_size(&tu->tp, regs, NULL); esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); ucb = uprobe_buffer_get(); - store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize); + store_trace_args(ucb->buf, &tu->tp, regs, NULL, esize, dsize); if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) uretprobe_trace_func(tu, func, regs, ucb, dsize); diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc index 20e42c030095..61877d166451 100644 --- a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc +++ b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc @@ -34,7 +34,9 @@ check_error 'f vfs_read ^$stack10000' # BAD_STACK_NUM check_error 'f vfs_read ^$arg10000' # BAD_ARG_NUM +if !grep -q 'kernel return probes support:' README; then check_error 'f vfs_read $retval ^$arg1' # BAD_VAR +fi check_error 'f vfs_read ^$none_var' # BAD_VAR check_error 'f vfs_read ^'$REG # BAD_VAR @@ -99,7 +101,9 @@ if grep -q "" README; then check_error 'f vfs_read args=^$arg*' # BAD_VAR_ARGS check_error 'f vfs_read +0(^$arg*)' # BAD_VAR_ARGS check_error 'f vfs_read $arg* ^$arg*' # DOUBLE_ARGS +if !grep -q 'kernel return probes support:' README; then check_error 'f vfs_read%return ^$arg*' # NOFENTRY_ARGS +fi check_error 'f vfs_read ^hoge' # NO_BTFARG check_error 'f kfree ^$arg10' # NO_BTFARG (exceed the number of parameters) check_error 'f kfree%return ^$retval' # NO_RETVAL diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc index 65fbb26fd58c..a16c6a6f6055 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc @@ -108,7 +108,9 @@ if grep -q "" README; then check_error 'p vfs_read args=^$arg*' # BAD_VAR_ARGS check_error 'p vfs_read +0(^$arg*)' # BAD_VAR_ARGS check_error 'p vfs_read $arg* ^$arg*' # DOUBLE_ARGS +if !grep -q 'kernel return probes support:' README; then check_error 'r vfs_read ^$arg*' # NOFENTRY_ARGS +fi check_error 'p vfs_read+8 ^$arg*' # NOFENTRY_ARGS check_error 'p vfs_read ^hoge' # NO_BTFARG check_error 'p kfree ^$arg10' # NO_BTFARG (exceed the number of parameters) From patchwork Mon Mar 4 03:41:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200880dyc; Sun, 3 Mar 2024 19:41:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqduQYvRtTmaW+2fbPoPeTcpXivFTVpn1XFGnGaNRC+6pa1/OS7uCzDmsZWBruE8Qn2aeM4JqocljtzRl/yT6U3uN5vw== X-Google-Smtp-Source: AGHT+IEdM7+/QVCRvpDcq/A77an6j8mQN4zh+hZVq1cRwLZj/2t1jbE5XlDXxFoh0XvFzGsmIYL3 X-Received: by 2002:a50:d60f:0:b0:567:824:e36c with SMTP id x15-20020a50d60f000000b005670824e36cmr3814606edi.14.1709523719588; Sun, 03 Mar 2024 19:41:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523719; cv=pass; d=google.com; s=arc-20160816; b=HBXLHkvTzB0WwxRAmfc9azPC6GSOBfAewSH7+hPzqAWbuBVItUPSkmF2SqwsR4U2Ln 1TkYbmLWn5d+YGx+bMPDNqi7ptRGOxYVk4MzVrtXwTe4CKe5ON0FEycwmJcHvdppbRQh G/diOpIQJqJPhZUIy6Xhbw1MC8KUyaQCVvxqxyh1mOAfHJT3dNVTTepYQLfFT8qh2LFp yxjhrcsX1UkwEaxdCMiwWYpH9jjCZlb9N4tJnegTb8GLoL+/eySNwcIzkWpl7MepC1rF E3jmyr02BBDHYFVdYWvWFt1ytRGjTzYqvAvjYEJGOXgBl1fSsbLKmF3laGlPQRNK76MH Rh1w== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=FqGcgvCug/b37eIUszXIySScYCy7NP+ElgOoZyfJWG0=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=lbxnBK/y1k1ZLFiUGt0m0L0Ja/EAHFQN0VGZU/sLB096jZm+AhbzpryVXpJUtN84j2 j865Gmpn1DC+pkW6qzMSYpHGjcR5XDm37R5vnVk4Dg7vq/7ckbtu/D3wPnjfw95cTyW7 QVZVwlg5aR5DEGVg5XcS7d27D72nr9MHtt6G7Up2ioseWj8i772zBgolP7Z5i7PCurDQ hdFmAfFLpOO3C9nVm3dw5D5o2fzWUDZpl46yAm4BmHUCmX/FLwix+TWatCjLQtH4UHmg fp8Q2HWwsW2w5sZWJXWS0voQg9jKvJMAGglrtmzvzYzKRrzF8GZlmsoff4acLbzzUhDH Lc5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iJI13pja; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90025-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90025-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id di4-20020a056402318400b005671c547bddsi1234189edb.525.2024.03.03.19.41.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:41:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90025-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iJI13pja; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90025-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90025-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 24AF61F2134F for ; Mon, 4 Mar 2024 03:41:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14F7BC148; Mon, 4 Mar 2024 03:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iJI13pja" 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 74D2DBA3F; Mon, 4 Mar 2024 03:41: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=1709523670; cv=none; b=PfXluefsJOsibcSfcNqzqxehoGQVjgKHd/oUhtE5Ut5L71bitjj9jMryRkNYMNZp0udDngtEaq9VZXZBImnE6jQIcL9KBUkjimBvwAIb12bdTg9GSnIERCsEzsjzQ5D8SVjfXThmavuQvBm3MUJ+RM+a23y2hfqpgkk+TerxzOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523670; c=relaxed/simple; bh=1MG502dBW5ZFZkOGMGA4VMms5Lg9q3jfUg4fYOgVv58=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=m7KuUJSXElrSPbd0lVx+cU2c1neS+3rfJx9+Ozr7Z9RDthWnb0RjJZv4P7mFRG7cyn280OTIhfQ42UsvpSkVuIJJxOWedYTPFIsEocIvkzwD/cn8FRMHGvKfzJ7h7SY9q7xprU4lmWqr7Wj2VKkxLqWP50x7v7CnNOxPxxgtspc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iJI13pja; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89E4AC433C7; Mon, 4 Mar 2024 03:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523670; bh=1MG502dBW5ZFZkOGMGA4VMms5Lg9q3jfUg4fYOgVv58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iJI13pjan5FUMoibjtrvdcfTljbNLUhUSCrCjdf1lCfCbaUlq5bQEiMGiDZrqMVWV DFxLtGGzL/8Ac9mb8ylzh0LSA7PibAd/NLXOKdqVmi/3lJQ2l6OFNe1CzfGVYv1dN4 mhnCCqliAYJ+OFf8nN56ep4EizxlRnRAuflG+Xav4XDFCOFxCBTV+VaxB6sJTCL95G 1+QjQQunf+LXndKMQjSnntPki9KeE812L8eljM7E2rQNLWdpMwhy7O93jbldc0YSt5 TNdOJyf39ojdGAV58dnVI8zBfEzAj9ZU5MaQmTNpJp12ILXyqDbC9VTcT+tDYrFcfl oAuOjE2lHw7eA== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 7/8] selftests/ftrace: Add test cases for entry args at function exit Date: Mon, 4 Mar 2024 12:41:05 +0900 Message-Id: <170952366504.229804.11605173085475141091.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565543643560020 X-GMAIL-MSGID: 1792565543643560020 From: Masami Hiramatsu (Google) Add kretprobe and function exit probe test cases for checking whether those can access entry arguments at function exit correctly. Signed-off-by: Masami Hiramatsu (Google) --- .../ftrace/test.d/dynevent/fprobe_entry_arg.tc | 18 ++++++++++++++++++ .../ftrace/test.d/kprobe/kretprobe_entry_arg.tc | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/fprobe_entry_arg.tc create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_entry_arg.tc diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_entry_arg.tc b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_entry_arg.tc new file mode 100644 index 000000000000..d183b8a8ecf8 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_entry_arg.tc @@ -0,0 +1,18 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Function return probe entry argument access +# requires: dynamic_events 'f[:[/][]] ':README 'kernel return probes support:':README + +echo 'f:tests/myevent1 vfs_open arg=$arg1' >> dynamic_events +echo 'f:tests/myevent2 vfs_open%return arg=$arg1' >> dynamic_events + +echo 1 > events/tests/enable + +echo > trace +cat trace > /dev/null + +function streq() { + test $1 = $2 +} + +streq `grep -A 1 -m 1 myevent1 trace | sed -r 's/^.*(arg=.*)/\1/' ` diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_entry_arg.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_entry_arg.tc new file mode 100644 index 000000000000..53b82f36a1d0 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_entry_arg.tc @@ -0,0 +1,18 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Kretprobe entry argument access +# requires: kprobe_events 'kernel return probes support:':README + +echo 'p:myevent1 vfs_open arg=$arg1' >> kprobe_events +echo 'r:myevent2 vfs_open arg=$arg1' >> kprobe_events + +echo 1 > events/kprobes/enable + +echo > trace +cat trace > /dev/null + +function streq() { + test $1 = $2 +} + +streq `grep -A 1 -m 1 myevent1 trace | sed -r 's/^.*(arg=.*)/\1/' ` From patchwork Mon Mar 4 03:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 209375 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200957dyc; Sun, 3 Mar 2024 19:42:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/SI/3Dr711pU4/cKPNAd/EstHJH6/NTf+oew6mLWIzuBRhxQjHX1McZMqv6bPI2Wdqc/LBUPjVrsv2n1q8N8i/ZSbhQ== X-Google-Smtp-Source: AGHT+IGQsTukvvZh/QJ7PUpIu3XL5jALOG4rTF9mfROgULEJ83AQxp08HB4Bt5OTDmEL9wvc1dnh X-Received: by 2002:a05:620a:4ed:b0:788:2235:4ffc with SMTP id b13-20020a05620a04ed00b0078822354ffcmr3324421qkh.0.1709523737545; Sun, 03 Mar 2024 19:42:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523737; cv=pass; d=google.com; s=arc-20160816; b=RrwjWfSS3c37NJmHjL2ImSFf8/I5QJb0tVDKeOjJrEF37T/bgYdRdsb6EBEiqXUH1v Xwt1oKxA0Zd21iZS1DWaHJo5Ek39HjMbcwvMfLVEbLvD5/Ko1FInd5wrV8w2KcV1TxhF qaW8zVhSQLS79Fc+aU0gGcGgGe514NToD2EXxt76VPETNv7WlqYRYtOMiyGvphZc+F0b YC95qrJ/9O0fIv63QOxOBYEBYlm/GdewPu5iodKlBOElZs7Uft2BRcuqZq+KPsuGZApj KnpQG3h4fVMwP+GOF3g5sU6PpudOmmdf7VDhL8W9mwMcWQfnS+YLz5h1+I2KOBHuXKuK /T+A== 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:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=EXMyiZb4IWawI4CV21FGad8c+lr1MnDv46nXrQLUCbk=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=t54Zw7g3ZBENjr2pqqp+eSNDhySyS9TNFrn/Bet2hQliB8OrLEZqgHBjk6vdj+o5oZ bh7EEFLPLiMWf4vxqkGr3qLFubtWfnm3f0foe+Zx7VgKTvOjbu4oBC/szkFXVwxdAd+S MLe5AYNF2RZzFmODZB47X1PDwng6HCyHOr4XZtHR1wM5vokfkZBf4JPxOksd6tsmfKHR y7k4jZGeUkaPJ7boOaXthR2pW2tpU3lTGJueQRJINpHmcEVu9vV33OcqYfK4RGZfknKb zi+/09hoPweFJ3IqgZTRqMj0HRnLYZwJPLxP6rn+mlURnldBGxWCArbsuKgiSw3Rg8DK Qceg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hzCISer0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90026-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90026-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dt32-20020a05620a47a000b007881d5db1casi3662543qkb.400.2024.03.03.19.42.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:42:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90026-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hzCISer0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90026-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90026-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5706F1C20A3F for ; Mon, 4 Mar 2024 03:42:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14FFEDDD1; Mon, 4 Mar 2024 03:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hzCISer0" 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 41ED379C4; Mon, 4 Mar 2024 03:41:19 +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=1709523680; cv=none; b=MXc7S87lSbWRSUAI1AcVlB50UbDgJE0gu+JRB1kdMTahrgn3Fk1AnaOhCTmrHbgWvyOmi7Yx2h5xq97lEdigHMYkaPsn3oVime0zCkUhT8XvFF0dE2Gn8+1+ry8LWlGLhjiLpSAmorX7pLaZstxwlh1npZPZBu2HQ/m5HLQfMsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523680; c=relaxed/simple; bh=8NW/FHEoLd4ENSKfrOd68QHgWBaHFO7j15Gs6Cdq4nQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=qd1mL7jEb/JX3OZDTLyKqzPwUD9WZw1RGoQ20gzWwR4uv6TblPtcGOqS6T8FYvg3u9fCJPmIZqRrA0BX2RPO1zSfDwaQft0MiLyG3PyWBnJ6Ld5oOlA0QCARNxuoJawrbjLVdhUAgIG3vCiwJBiEFskMx5fq6jUuoqOtiSJOZMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hzCISer0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F012DC433C7; Mon, 4 Mar 2024 03:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523679; bh=8NW/FHEoLd4ENSKfrOd68QHgWBaHFO7j15Gs6Cdq4nQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hzCISer0GtepWuozvz7cEKxavhp98EbeA8d4akEnw3vepELLur4Z1hMN9Z39CoUnK 496ntpP5p6k1gpIOLrdnuP8C2WMpwYWKekw6xl7bTcy16UWDu1LBfNIx1t7b7r1s73 BwHFbbggHa4Y9R5Hbw0Ad2glqztI+5YRT4PSLE8/lg76ztAJrzdL810fq8ApbDD44b wl1RJbQrs+QZo0/oQn9GYtOFk8djcN0ucTJZihfBCgZ1f8PZqW/ktUSdghp0L2p+zP ONnFkvJFXZopjUYq06DyNGywAdhoGoM4iOcEyG0yeonZ0dqNkWZUyRLPzEgkbBm5F1 UJtylTioxrpsg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 8/8] Documentation: tracing: Add entry argument access at function exit Date: Mon, 4 Mar 2024 12:41:15 +0900 Message-Id: <170952367549.229804.8843506960483577062.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792565562415408210 X-GMAIL-MSGID: 1792565562415408210 From: Masami Hiramatsu (Google) Add a notes about the entry argument access at function exit probes for kprobes and fprobe trace event. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Add usage example in fprobetrace.rst. --- Documentation/trace/fprobetrace.rst | 31 +++++++++++++++++++++++++++++++ Documentation/trace/kprobetrace.rst | 9 +++++++++ 2 files changed, 40 insertions(+) diff --git a/Documentation/trace/fprobetrace.rst b/Documentation/trace/fprobetrace.rst index e35e6b18df40..0f187e3796e4 100644 --- a/Documentation/trace/fprobetrace.rst +++ b/Documentation/trace/fprobetrace.rst @@ -70,6 +70,14 @@ Synopsis of fprobe-events For the details of TYPE, see :ref:`kprobetrace documentation `. +Function arguments at exit +-------------------------- +Function arguments can be accessed at exit probe using $arg fetcharg. This +is useful to record the function parameter and return value at once, and +trace the difference of structure fields (for debuging a function whether it +correctly updates the given data structure or not) +See the :ref:`sample` below for how it works. + BTF arguments ------------- BTF (BPF Type Format) argument allows user to trace function and tracepoint @@ -218,3 +226,26 @@ traceprobe event, you can trace that field as below. -0 [000] d..3. 5606.690317: sched_switch: (__probestub_sched_switch+0x4/0x10) comm="kworker/0:1" usage=1 start_time=137000000 kworker/0:1-14 [000] d..3. 5606.690339: sched_switch: (__probestub_sched_switch+0x4/0x10) comm="swapper/0" usage=2 start_time=0 -0 [000] d..3. 5606.692368: sched_switch: (__probestub_sched_switch+0x4/0x10) comm="kworker/0:1" usage=1 start_time=137000000 + +.. _fprobetrace_exit_args_sample: + +The return probe allows us to access the results of some functions, which returns +the error code and its results are passed via function parameter, such as an +structure-initialization function. + +For example, vfs_open() will link the file structure to the inode and update +mode. You can trace that changes with return probe. +:: + + # echo 'f vfs_open mode=file->f_mode:x32 inode=file->f_inode:x64' >> dynamic_events + # echo 'f vfs_open%%return mode=file->f_mode:x32 inode=file->f_inode:x64' >> dynamic_events + # echo 1 > events/fprobes/enable + # cat trace + sh-131 [006] ...1. 1945.714346: vfs_open__entry: (vfs_open+0x4/0x40) mode=0x2 inode=0x0 + sh-131 [006] ...1. 1945.714358: vfs_open__exit: (do_open+0x274/0x3d0 <- vfs_open) mode=0x4d801e inode=0xffff888008470168 + cat-143 [007] ...1. 1945.717949: vfs_open__entry: (vfs_open+0x4/0x40) mode=0x1 inode=0x0 + cat-143 [007] ...1. 1945.717956: vfs_open__exit: (do_open+0x274/0x3d0 <- vfs_open) mode=0x4a801d inode=0xffff888005f78d28 + cat-143 [007] ...1. 1945.720616: vfs_open__entry: (vfs_open+0x4/0x40) mode=0x1 inode=0x0 + cat-143 [007] ...1. 1945.728263: vfs_open__exit: (do_open+0x274/0x3d0 <- vfs_open) mode=0xa800d inode=0xffff888004ada8d8 + +You can see the `file::f_mode` and `file::f_inode` are upated in `vfs_open()`. diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst index bf9cecb69fc9..a49662ccd53c 100644 --- a/Documentation/trace/kprobetrace.rst +++ b/Documentation/trace/kprobetrace.rst @@ -70,6 +70,15 @@ Synopsis of kprobe_events (\*3) this is useful for fetching a field of data structures. (\*4) "u" means user-space dereference. See :ref:`user_mem_access`. +Function arguments at kretprobe +------------------------------- +Function arguments can be accessed at kretprobe using $arg fetcharg. This +is useful to record the function parameter and return value at once, and +trace the difference of structure fields (for debuging a function whether it +correctly updates the given data structure or not). +See the :ref:`sample` in fprobe event for how +it works. + .. _kprobetrace_types: Types