From nobody Sun Feb 8 17:36:28 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 38ECC2874E3 for ; Thu, 8 Jan 2026 03:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767842237; cv=none; b=DvEOr6TFd2n+13l+EUxDMYilVLBTuNgZKRsjQobuOPV99CYvOQ/6r1a2Xyp271EKhN5KHERQFfGUb1AYUKONQZZIuWIgIhKVogy3ofJ1ADd5igb/FfiqS06yUrDmEv6qcADHi0XkzAmCGbSQz0ZIyM+88v9jZUxtx8mlRch8YT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767842237; c=relaxed/simple; bh=8smopcu78QnMs/YqVehnE5QN5ynjfgqRwGz8JYBm7fk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WzgZudctpLPBInVRmVPNCRGk8RnE6H30GG3UWHPTGke3wXMgOglHHeZ5LazYXV14KOwEDkfc5vSL0Ck7wwxz8/GBBD1+NEbqNejj5MTIWKpT7ZqIkOzSLMG90LcyDEbftI3iucRg/vPS3ncuhCFVGJIp94w8YXL03uY1beAFhS4= 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=C8z7S2Qu; arc=none smtp.client-ip=209.85.210.169 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="C8z7S2Qu" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7e1651ae0d5so1815068b3a.1 for ; Wed, 07 Jan 2026 19:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767842235; x=1768447035; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bv4kvnWYDSS1VS7MLzlNTRoM1YeZxUX9gh+m3TBBfX8=; b=C8z7S2QuqlKPXvUgQJuUPqHE4kx9vmqY1qW/G288hLTMmdq5Fx3OAEVd5KUMrAm3tQ IOIXaSStX2rxaTdE6U+GunU87xgryKMUNpGYVJZi8AMxJsmGXMIwtfCvJOeaisz1DpD5 QuIb4W4DYSy82qwJPxgDJDZ1+imFT1SSt1wMseXzrtDVvvFygVzDBnTDdTse/LDRSgyi wNJGanYFjdkryWrZ1C6Ujd/efANBHdpFBjzRo4ylf39638Trz9F7ock66ZB5q5h0Bvqh 9vGlvkxCSsVCMf5uIEJZJzisqviqFrKVqdP2GXaZPf1zSIJ7tyQidjDpyKya2h5XJGAS RYcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767842235; x=1768447035; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Bv4kvnWYDSS1VS7MLzlNTRoM1YeZxUX9gh+m3TBBfX8=; b=JxQibO9F59zoio67hYVi1lltOFlyD2BzDBVJQqEGO7YTxmmQGY+Ax9bwQN7NU6cbyI ihF8a5L5/+1ci8pZwA80Wll8FwRqcoQZe6uRV2mURG2qYMWgYb6XV6MpDXBGQBOu/f6l hujMnraH5WsL2qtjCIdURqCxKQ801gsxseW7Ru1LCWa27YupMoafEzCatUAV+Q0nnDau f6NW20/vyEnQ/KrM0wfgurRXKDdr+lEJKlafhJrwbW9kRuxbY2/0khm5FH9rrp82Xizi Bth3JOq/IZ6PFdwHQq4pKeRnBR8qlEnVjBOH0eA2GJyI8MwtzlyJPy0z3azYEPJ+irEU kPMw== X-Forwarded-Encrypted: i=1; AJvYcCWli+mAJnvLxHVyogmkMbbYsmMMfzaWFr9pfwweP6BX6RufVhON13byARhfcMgFVn8rG/0rOChro4lhSHw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw51YPdhiL8mDrtxUkifnkyHDi6VOHLg4sDqlq6aoGafXHHThbn ct2rybPsA1QKLbvViXfZCm7mivzt8uIPOEbTgG3xJEvbtwxGMnxD0NIf X-Gm-Gg: AY/fxX5DGKAjhH3MnIC7mCIwfgCy50sG/0Dlp/2KJgVHaCEl7FLKhisdedtI1thALvb Y6m3MX3Fvvo2y9uBIUtSwfogvBwkh4pPUti3ChTjs/nVOaAdMLzfb9w/UHrxVSHwy0+3eyeo6t5 iRsvcQweehYRSMqk/gV01IMsmxrlj+iqmaoNlQZwmovB23H+dLEywTFowrty49E0w6kjYvHbCZz 4Lzrzd7Ukox1gyMaUrHQhXyszS1n5M80dME5OeVg/X+AYapwIxu7B9DmqZFbWQjC+y1szSAlhKz XOD3N3qGsf7uwgIJt3GvozpvJw9szE9B+QO+myvfyKFLVeKhI1VK/L6J1qL1y3Vn92CmquMfYjj cW2rh0KC0lKhgACthcsDcV9WsFw0ylcKf7wnv2fzgZLLEdGlUijM1ta+8SfkQvflqW5BhuIWDrc +WqWVOHc+YB22CFa6UiNkv4hQaEt8= X-Google-Smtp-Source: AGHT+IG2kVTh4tMqTzJLgEcx1fBS0i8ONWGZ1nAHkGySVtfYuQa6+ivUGQpjGgc7PQMd59Rq0Vri8w== X-Received: by 2002:a05:6a00:1c83:b0:7e8:4587:e8cb with SMTP id d2e1a72fcca58-81b811a0929mr4193329b3a.62.1767842235546; Wed, 07 Jan 2026 19:17:15 -0800 (PST) Received: from pengdl-pc.mioffice.cn ([43.224.245.249]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-819c5de655bsm6134860b3a.60.2026.01.07.19.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 19:17:15 -0800 (PST) From: Donglin Peng To: ast@kernel.org, andrii.nakryiko@gmail.com, eddyz87@gmail.com Cc: zhangxiaoqin@xiaomi.com, ihor.solodrai@linux.dev, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Donglin Peng , Alan Maguire Subject: [PATCH bpf-next v11 08/11] bpf: Skip anonymous types in type lookup for performance Date: Thu, 8 Jan 2026 11:16:42 +0800 Message-Id: <20260108031645.1350069-9-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260108031645.1350069-1-dolinux.peng@gmail.com> References: <20260108031645.1350069-1-dolinux.peng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Donglin Peng Currently, vmlinux and kernel module BTFs are unconditionally sorted during the build phase, with named types placed at the end. Thus, anonymous types should be skipped when starting the search. In my vmlinux BTF, the number of anonymous types is 61,747, which means the loop count can be reduced by 61,747. Cc: Eduard Zingerman Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Alan Maguire Cc: Ihor Solodrai Cc: Xiaoqin Zhang Signed-off-by: Donglin Peng Acked-by: Eduard Zingerman --- kernel/bpf/btf.c | 10 ++++++---- kernel/bpf/verifier.c | 7 +------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 12eecf59d71f..686dbe18a97a 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -3534,7 +3534,8 @@ const char *btf_find_decl_tag_value(const struct btf = *btf, const struct btf_type const struct btf_type *t; int len, id; =20 - id =3D btf_find_next_decl_tag(btf, pt, comp_idx, tag_key, 0); + id =3D btf_find_next_decl_tag(btf, pt, comp_idx, tag_key, + btf_named_start_id(btf, false) - 1); if (id < 0) return ERR_PTR(id); =20 @@ -7844,12 +7845,13 @@ int btf_prepare_func_args(struct bpf_verifier_env *= env, int subprog) tname); return -EINVAL; } + /* Convert BTF function arguments into verifier types. * Only PTR_TO_CTX and SCALAR are supported atm. */ for (i =3D 0; i < nargs; i++) { u32 tags =3D 0; - int id =3D 0; + int id =3D btf_named_start_id(btf, false) - 1; =20 /* 'arg:' decl_tag takes precedence over derivation of * register type from BTF type itself @@ -9331,7 +9333,7 @@ bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 loc= al_type_id) } =20 /* Attempt to find target candidates in vmlinux BTF first */ - cands =3D bpf_core_add_cands(cands, main_btf, 1); + cands =3D bpf_core_add_cands(cands, main_btf, btf_named_start_id(main_btf= , true)); if (IS_ERR(cands)) return ERR_CAST(cands); =20 @@ -9363,7 +9365,7 @@ bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 loc= al_type_id) */ btf_get(mod_btf); spin_unlock_bh(&btf_idr_lock); - cands =3D bpf_core_add_cands(cands, mod_btf, btf_nr_types(main_btf)); + cands =3D bpf_core_add_cands(cands, mod_btf, btf_named_start_id(mod_btf,= true)); btf_put(mod_btf); if (IS_ERR(cands)) return ERR_CAST(cands); diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 9394b0de2ef0..05fa2e9181f5 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -20642,12 +20642,7 @@ static int find_btf_percpu_datasec(struct btf *btf) * types to look at only module's own BTF types. */ n =3D btf_nr_types(btf); - if (btf_is_module(btf)) - i =3D btf_nr_types(btf_vmlinux); - else - i =3D 1; - - for(; i < n; i++) { + for (i =3D btf_named_start_id(btf, true); i < n; i++) { t =3D btf_type_by_id(btf, i); if (BTF_INFO_KIND(t->info) !=3D BTF_KIND_DATASEC) continue; --=20 2.34.1