From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 09E463D34A4; Mon, 8 Jun 2026 14:25:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780928702; cv=none; b=A2yrKI8qi1XuACVuTmXQHUouyuT6xR/QQZ/gJ5ii13SzuJ3V+GpO7vcpjSRXcka2+ITNm3xncQFXeuDwCLS8RXBw/aeFobFPr7PmA7nfcJ1yxQgfzBrqdnf2M2eQUE4QqQpwV0hoCAIyihbGmVt6tEMe2Ia1FEuYY//9HrbFLOU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780928702; c=relaxed/simple; bh=mZYqD+WxyQ1SlDs/mXsKtQBftb99G0BzFoyKO0yat9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bgMbHAmWH1iL9fVftNorMiKbaG36+w5klXCmQdpltZSH/8P6nIXanOEW0c0x5FMnu8oZIEzgUNiqdJUfc9ivgS8jbphd+oUf4iuAndwpXsa4ufehPrQ/m2I8HdATe9zF3pMXMjkF9ivdKz31WWafhjpU2/34GIFrgnA/iyyj2Z0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U+jr3feM; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U+jr3feM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 792901F00893; Mon, 8 Jun 2026 14:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780928700; bh=8qTAGqtGn3AZzYpmsSksil2kynfsaWnAEpF5s06Uqnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U+jr3feMdP3z3SVsfKgRyywuv0kaS18QSg3xunSzLI7wdSK14lYkQXTF32jNwspsq H7hHRhjgnrSCxCSO0HPkCrrLW5LyQUEMHDnva2RhB1OmY+rPeXpfOKAcxao7p9FVXX afOeVLOkHRFH/rKK2gdR+4Uq7omoa/6FLdPhFyhZEUv6867KjWNHLtdkOhuntrnugn 5PftoG9ZQMUd1NP5KP+iqQozdhBNeCQ9tBHMpMB/Szus8asBstu4bRexRah6UiZa1b GoBZVBKAHk5yeWp2UCSe4WsAeFy+tcKXQO6glj+3A4AvmNY3S38/40v4EnArcAllJk 3YpgpTJM6+WTg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Mathieu Desnoyers Cc: Jonathan Corbet , Shuah Khan , Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH 4/7] tracing/probes: Add $current variable support Date: Mon, 8 Jun 2026 23:24:56 +0900 Message-ID: <178092869618.163648.515347808636675462.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <178092865666.163648.10457567771536160909.stgit@devnote2> References: <178092865666.163648.10457567771536160909.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit From: Masami Hiramatsu (Google) Since we can use the BTF to cast value to a structure pointer type, it is useful to introduce "$current" special variable support to fetcharg. User can define a fetcharg to access current task_struct properties using BTF typecast (or dereference - but this may be complicated) e.g. (task_struct)$current->cpus_ptr Signed-off-by: Masami Hiramatsu (Google) --- Documentation/trace/eprobetrace.rst | 1 + Documentation/trace/fprobetrace.rst | 1 + Documentation/trace/kprobetrace.rst | 1 + kernel/trace/trace.c | 2 +- kernel/trace/trace_probe.c | 6 ++++++ kernel/trace/trace_probe.h | 1 + kernel/trace/trace_probe_tmpl.h | 3 +++ 7 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/trace/eprobetrace.rst b/Documentation/trace/eprobetrace.rst index 680e0af43d5d..dcf92d5b4175 100644 --- a/Documentation/trace/eprobetrace.rst +++ b/Documentation/trace/eprobetrace.rst @@ -38,6 +38,7 @@ Synopsis of eprobe_events @ADDR : Fetch memory at ADDR (ADDR should be in kernel) @SYM[+|-offs] : Fetch memory at SYM +|- offs (SYM should be a data symbol) $comm : Fetch current task comm. + $current : Fetch the address of the current task_struct. +|-[u]OFFS(FETCHARG) : Fetch memory at FETCHARG +|- OFFS address.(\*3)(\*4) \IMM : Store an immediate value to the argument. NAME=FETCHARG : Set NAME as the argument name of FETCHARG. diff --git a/Documentation/trace/fprobetrace.rst b/Documentation/trace/fprobetrace.rst index 290a9e6f7491..3392cab016b3 100644 --- a/Documentation/trace/fprobetrace.rst +++ b/Documentation/trace/fprobetrace.rst @@ -50,6 +50,7 @@ Synopsis of fprobe-events $argN : Fetch the Nth function argument. (N >= 1) (\*2) $retval : Fetch return value.(\*3) $comm : Fetch current task comm. + $current : Fetch the address of the current task_struct. +|-[u]OFFS(FETCHARG) : Fetch memory at FETCHARG +|- OFFS address.(\*4)(\*5) \IMM : Store an immediate value to the argument. NAME=FETCHARG : Set NAME as the argument name of FETCHARG. diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst index a62707e6a9f2..81e4fe38791d 100644 --- a/Documentation/trace/kprobetrace.rst +++ b/Documentation/trace/kprobetrace.rst @@ -53,6 +53,7 @@ Synopsis of kprobe_events $argN : Fetch the Nth function argument. (N >= 1) (\*1) $retval : Fetch return value.(\*2) $comm : Fetch current task comm. + $current : Fetch the address of the current task_struct. +|-[u]OFFS(FETCHARG) : Fetch memory at FETCHARG +|- OFFS address.(\*3)(\*4) \IMM : Store an immediate value to the argument. NAME=FETCHARG : Set NAME as the argument name of FETCHARG. diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 0e36af853199..e185a006cb08 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4329,7 +4329,7 @@ static const char readme_msg[] = "\t [(structname[,field])](fetcharg)->field[->field|.field...],\n" #endif #else - "\t $stack, $stack, $retval, $comm,\n" + "\t $stack, $stack, $retval, $comm, $current\n" #endif "\t +|-[u](), \\imm-value, \\\"imm-string\"\n" "\t kernel return probes support: $retval, $arg, $comm\n" diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index ff0b619e9a90..2c5deb1e1463 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1235,6 +1235,12 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t, return 0; } + /* $current returns the address of the current task_struct. */ + if (strcmp(arg, "current") == 0) { + code->op = FETCH_OP_CURRENT; + return 0; + } + #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API len = str_has_prefix(arg, "arg"); if (len) { diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index b1a54da3c761..f2b31089779c 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -96,6 +96,7 @@ enum fetch_op { FETCH_OP_FOFFS, /* File offset: .immediate */ FETCH_OP_DATA, /* Allocated data: .data */ FETCH_OP_EDATA, /* Entry data: .offset */ + FETCH_OP_CURRENT, /* Current task_struct address */ // Stage 2 (dereference) op FETCH_OP_DEREF, /* Dereference: .offset */ FETCH_OP_UDEREF, /* User-space Dereference: .offset */ diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index f39b37fcdb3b..f630930288d2 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -112,6 +112,9 @@ process_common_fetch_insn(struct fetch_insn *code, unsigned long *val) case FETCH_OP_DATA: *val = (unsigned long)code->data; break; + case FETCH_OP_CURRENT: + *val = (unsigned long)current; + break; default: return -EILSEQ; }