From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65C0B25F99F for ; Mon, 19 Jan 2026 20:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768855402; cv=none; b=M57fg3GoOJYYSAoC/wLfK6AYEnZylsMpC6tQ1jm2v4knCTwtZdLlNFW9qMvMnEg/Mev6FPa3hzamLBqCGSbG8HAqtq2KZbg+wF0nN/eZgA1M8w/LfhGRnh7TYIa94iKvto0/xqLg8yMeluRx+zSamCXSZMpd+fAYHDRb3S/nOFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768855402; c=relaxed/simple; bh=DK2Ox8tRf41I/4CD4+ghBJ+W5QUWZRQ+vztmjdsTTqo=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=EAR1Udt/JHy8HxnO/tFowCmPFWWY2NF5Qu6j/yOrpG8Y3/VI8necTICiRzmqy4sWAoACNv1dK7tFfALbHikzIyY/SgDFTopInQrLzx0iPvZAy7t9pM5wKBkJt8j1d+CoHQD2IDwg2qIm7T1vHnJkUkomaLyVAQoWyaQ2KjssuuY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FhJ1HH99; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FhJ1HH99" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-2b6f5a9cecaso587890eec.0 for ; Mon, 19 Jan 2026 12:43:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768855400; x=1769460200; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=DTswKAcXHjAjSVyIK1XhIPE0y5rf4rz1XBF2jXNueWY=; b=FhJ1HH99snS+SHpToAS5YIGC0c4wfHyT7rHOCl+ez9ftC+4sX6NyHrXkdU/quQNQ6t tQKw7EVuPUwztix6MHNbgc9/NeSH9EzxUYs7S5qNN+A98VnRrOzGT8SZXc/PyoALvG95 8lRzV1brXD1TK45NucwleUPVa73k+RxtY3Nmd3ERUgZJfig9YpfBrGjxTSX9Wfg4zjct tUpz8Y/9zrnd/zsgkw3SpCCEPVTDLiDYMTAoHiQhxEUKWO1UE8wOh0qqfYrGan4e8Slt P5YccK2ylbXqUFHtCC7sYLeiEFNTBz45pIgConCxiXg7MziVGxef8uP5jH9PRiEYC3oc CmVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768855400; x=1769460200; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DTswKAcXHjAjSVyIK1XhIPE0y5rf4rz1XBF2jXNueWY=; b=qYCGHctLm5Q1lNx+uEOLt4+kZz0ij25w//XRnAnqKnYrtRa77yo6SIJZUb81Qmi8Kw tEkgijt5QCZ2quTT6dGxar6y6tIrxQxN2mD+PJvohYBFSFucF8SC2HA2hxEuc+VPPWkB +uHp4WUdhZs2b7a9eFyzS0t8O4D3cSADDWJ0xTFy0/bYygYi2GtBzYfq3QRMkC0LAbTR 8HdDTx8vbCU1DLmek2OpQt69wMy9EjpIUwLDAg/ch9Nn5L4HhXbwoUf1uJApEgKZRGYx ZT58U/RxlrycRajhDXxKmSivkEuEpebRN4uqGNQIhirDCE2MwJHOROhANOlfT2pxlUnV xMcQ== X-Forwarded-Encrypted: i=1; AJvYcCWEeAOKYYgsnXmDql9cE4P2Hl0VZMu63lO3Uz0RY6MoSmKgqppuJ0iw/xnePqjbMgxxDKIf36Yz1lfgWic=@vger.kernel.org X-Gm-Message-State: AOJu0YwwE8wwsP/U5bEYB6hDkpsYzfj/9j9ifGXASSeh1fIxr7UGZWqG L0Sa3y2wSfW7ZgyG1NdRVbic8aC3KOzzltdaSTTAUTMp+jvQt9/uArPZ X-Gm-Gg: AZuq6aKZDpkJcZCr8i4F5HHSV/5QpEJIP0wSPox4s/Yp7Cq3gjxUvBlVOefNMyyKI7e azAeezklut5oCjfMCbUrUV1Yu+d9DZPa3t1DNL0OZe+2/mcoR1AGWEkJj+eS1/lw1xMaRAuEHqX XeU7P5zE7VzaVzFkp0E0SmRgcgwir5qUtw/FB7Z7av7FpfqyFOX4X4maVQuv0nMMnSs6qbTp69i 4OhasRJy+Zq4UKxHAvG/2qSaRe0Kpps+4zcL4vFsf51/H+/dGjmX0BioqpkX47mj8BwRemBXmhg +vXiLDQAacc+Baqnogbp8FVvwgt0OxOV4oTncEDT4m1VZeAkvJe8KOc9iTWzsEj/sQx0Txns36t qb+Uo7Od6nf/4RyVDMf63qy3iIqSzp4dDsaDTkdvQ1Io2tguzJcDbdbMzRAgZOsxFRa6Ba+XuIg FBe+69xfJdYIKErx43BzFwycaOF7PqtHosRUlQjEgv2zHJoP9o4XxuGRQGbe0jdkfHYQ== X-Received: by 2002:a05:7300:dc85:b0:2ae:601f:f4f7 with SMTP id 5a478bee46e88-2b6b410b233mr8446466eec.40.1768855400395; Mon, 19 Jan 2026 12:43:20 -0800 (PST) Received: from ?IPv6:2a03:83e0:115c:1:4cd6:17bf:3333:255f? ([2620:10d:c090:500::aa81]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b6b367cbd4sm14492703eec.33.2026.01.19.12.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 12:43:20 -0800 (PST) Message-ID: Subject: Re: [PATCH bpf-next v5 1/2] bpf, x86: inline bpf_get_current_task() for x86_64 From: Eduard Zingerman To: Menglong Dong , ast@kernel.org Cc: daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 19 Jan 2026 12:43:17 -0800 In-Reply-To: <20260119070246.249499-2-dongml2@chinatelecom.cn> References: <20260119070246.249499-1-dongml2@chinatelecom.cn> <20260119070246.249499-2-dongml2@chinatelecom.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.2 (3.58.2-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2026-01-19 at 15:02 +0800, Menglong Dong wrote: > Inline bpf_get_current_task() and bpf_get_current_task_btf() for x86_64 ^^^^^^ Nit: this change is no longer x86 specific. > to obtain better performance. >=20 > In !CONFIG_SMP case, the percpu variable is just a normal variable, and > we can read the current_task directly. >=20 > Signed-off-by: Menglong Dong Acked-by: Eduard Zingerman [...] > @@ -23319,6 +23323,24 @@ static int do_misc_fixups(struct bpf_verifier_en= v *env) > insn =3D new_prog->insnsi + i + delta; > goto next_insn; > } > + > + /* Implement bpf_get_current_task() and bpf_get_current_task_btf() inl= ine. */ > + if ((insn->imm =3D=3D BPF_FUNC_get_current_task || insn->imm =3D=3D BP= F_FUNC_get_current_task_btf) && > + verifier_inlines_helper_call(env, insn->imm)) { > + insn_buf[0] =3D BPF_MOV64_IMM(BPF_REG_0, (u32)(unsigned long)¤t= _task); > + insn_buf[1] =3D BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0); > + insn_buf[2] =3D BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0); ^^^^^^^ Silly question: This assumes pointer size of 8 bytes. Which is true for all archs where bpf_jit_supports_percpu_insn() returns true at the moment. Do we want an additional safety check here? > + cnt =3D 3; > + > + new_prog =3D bpf_patch_insn_data(env, i + delta, insn_buf, cnt); > + if (!new_prog) > + return -ENOMEM; > + > + delta +=3D cnt - 1; > + env->prog =3D prog =3D new_prog; > + insn =3D new_prog->insnsi + i + delta; > + goto next_insn; > + } > #endif > /* Implement bpf_get_func_arg inline. */ > if (prog_type =3D=3D BPF_PROG_TYPE_TRACING &&