From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 02F0F3A169B for ; Thu, 19 Mar 2026 15:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773934778; cv=none; b=XB+JP10afa3tt8aUvWNiqNEfb3akkvcuZqlA3kB79XVZbCBr4erW1R3HskA+dR4QkPn6D5dFScTYz8FX7cHxIzehEZ1bgG0o5uEsX+UjSNDH6h/zurJaIem0waE3vRpheFGHcDY11oJGJ97QLUjXeuKEXNiwpzTepZxtqlmxaXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773934778; c=relaxed/simple; bh=x//o4bWkdTa7UjZoqWBDqdBqMxSW98X7OQ5Mn059qxs=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=Pl6Y5i5ImVGfapjix+a+t1OrtOFi2uAOJltz+XsmUaDVixSEk0WEyIXAc+yES6AqPi+4C1EUp4looeLKj/uWsKkYn5JKnRwMjWWwP3OW7YZGv5k81+aD/7uosTuJ5ct+EfNUv3SmhPOs9iuzEcDWk2KE5k3+CaSgw+BrxjEhDQU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b=QbBSLqt/; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b="QbBSLqt/" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-89c55a0a470so13610346d6.0 for ; Thu, 19 Mar 2026 08:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20230601.gappssmtp.com; s=20230601; t=1773934776; x=1774539576; darn=vger.kernel.org; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9f+nxQqpbmkQKG1AStGiZRyAzlhJyR4x4hzFywy9Ago=; b=QbBSLqt/a46IQeKhCnmfhXuvfzQ71UUU/ir9ucua7JBrMQ5AJ58dWuXrKFc6CmAaB4 uSq7kxkbMpcxAzdSHs45yyv9FxsInnIoURGn4uwWRqS725tUzbkxyb693cPtcAL+hP2u UqQMEP1edtW8/r9UnTAtQjnxIAX2ML7vvA2pYyEoZ+sy1extujt04qgcoZjniIU/wQRm PIXC2rNRmQCQlIsb08ZMmrbBBd06LqmClJHOX+cuZg7Mt1Vv0SGrkFfaYNCD9LLhhAHG 1YST7blvwdFGXt2BHxWiEoU33Zf3MInEDzSJJzy75SCHckZjnRL5lQP078gofnmmsHsC 4C5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773934776; x=1774539576; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9f+nxQqpbmkQKG1AStGiZRyAzlhJyR4x4hzFywy9Ago=; b=ZwY3LZj+kNrfeDOtFBOhADpOpk9AkTkIeYxvmZ8fVLCO7tewglk+3jmpdoteRRTkdM /3wZS2308306jhY6ZJ5wrPOfYI0+mEW/+Bvnwcze/LmcCrdgAvFG5Pksg+aTLeKbTr++ Y11lXREFTD338cu6gzV1CgtE8BOp030xEQYit4Q92/o9poVSNZy75Ih74JcSiXCZmHnP SADpSYBwAJj7Fly1yn7FEV8A/Ts7Ri6K3bVPH5jaLpViBG3lHcfoECCAKAkhBOrbVcUU AY8UMhxjZRbzPpH/7E2fup1AzrCL+4VpfDiVuttG7SjgPNXtKEE7i01s/bgBVCZ56B1M dO2g== X-Forwarded-Encrypted: i=1; AJvYcCXvUIacSg7HXQmzW8hG6SqPCJ13p3rR208lGuemDSw/Uxo9YEun2MXC3ZkPWNFwhUX1E1IFA6NtETu3uxk=@vger.kernel.org X-Gm-Message-State: AOJu0Ywrz+LItK+rUyKT4vqeToAMRdOAwRfxsoB6jbYhefU9KX/FPAYt 4BoV10kPhM/tnN+FNobxN8A9pEuJvXTxeBU5xiOPeN3vJd+u1idIIp0/0ApxpJiMIoI= X-Gm-Gg: ATEYQzxr79IsPTx9ipgvdoMGxlLGGWOjn7n6NGtSvqwKq+vQs73wPdqg8+kl3UW5QXY Ei7aDynLv7fffZvjhInh+KcT5J5M7RD4UHBUDyDvRLzXnPTlzzHd2mLpcg0XxNZh3XS+8e3jKPr dA9tLC+aKIII3wgBgcXQteBZNzn3RZnofGZcMLU3OqNq/9TG8bWm/sRKGC38V/86QuDJHJbttaI +ZCsb3U8zgjo62+CZOXw3zUANZ1Cpb3Zec+0iWyvHQi61Afizhr1OcEdGHAReUZ4XokHv6eJ/uq uJJkIn0nxqqnRJSWsaLrRnbueuwFFcP/QO/haMvlVWnxd2JPAeOn7/ZV+Bxt/Pv9wnto/+KzCSF gmMlgxvfoOZLfgLhW3W8JkEoWGUt9yp78Ou6QjHzcdn6ht0ZybaC1xPAqT1hmKxIV/CV0Bz+Nxp su/gxVMypmIQi2QPxllO5fuL4= X-Received: by 2002:a05:6214:3003:b0:89c:6252:4a4a with SMTP id 6a1803df08f44-89c6b5a797emr112213066d6.49.1773934775593; Thu, 19 Mar 2026 08:39:35 -0700 (PDT) Received: from localhost ([140.174.219.137]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89c6b90d1a8sm63300886d6.18.2026.03.19.08.39.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Mar 2026 08:39:35 -0700 (PDT) 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 Date: Thu, 19 Mar 2026 11:39:34 -0400 Message-Id: To: "Chengkaitao" , , , , , , , , , , , , , , , Cc: , Subject: Re: [PATCH bpf-next v8 1/8] bpf: refactor kfunc checks using table-driven approach in verifier From: "Emil Tsalapatis" X-Mailer: aerc 0.20.1 References: <20260316112843.78657-1-pilgrimtao@gmail.com> <20260316112843.78657-2-pilgrimtao@gmail.com> In-Reply-To: <20260316112843.78657-2-pilgrimtao@gmail.com> On Mon Mar 16, 2026 at 7:28 AM EDT, Chengkaitao wrote: > From: Kaitao Cheng > > Replace per-kfunc btf_id chains in list/rbtree/res_lock and graph node > checks with btf_id_in_kfunc_table() and static kfunc tables for easier > maintenance. > > Prepare for future extensions to the bpf_list API family. > > Signed-off-by: Kaitao Cheng Reviewed-by: Emil Tsalapatis The change is valid, can you see if you can remove some of the is_bpf_*api_kfunc calls areound line 13000 and replace them with=20 btf_id_in_kfunc_table calls?=20 And can you also do this refactoring for the other kfunc families? That way we replace all functions that match on the btf_id into a single call that takes in the array we are scanning for a match. > --- > kernel/bpf/verifier.c | 79 +++++++++++++++++++++++++++++++------------ > 1 file changed, 57 insertions(+), 22 deletions(-) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 4fbacd2149cd..64c1f8343dfa 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -12639,6 +12639,53 @@ BTF_ID(func, bpf_session_is_return) > BTF_ID(func, bpf_stream_vprintk) > BTF_ID(func, bpf_stream_print_stack) > =20 > +static const enum special_kfunc_type bpf_list_api_kfuncs[] =3D { > + KF_bpf_list_push_front_impl, > + KF_bpf_list_push_back_impl, > + KF_bpf_list_pop_front, > + KF_bpf_list_pop_back, > + KF_bpf_list_front, > + KF_bpf_list_back, > +}; > + > +/* Kfuncs that take a list node argument (bpf_list_node *). */ Nit: Why add a description on just this and bpf_rbtree_node_api_kfuncs? I think a small comment on top of each if fine if a bit wordy because it's easy to spot when scanning for a specific kfunc family. > +static const enum special_kfunc_type bpf_list_node_api_kfuncs[] =3D { > + KF_bpf_list_push_front_impl, > + KF_bpf_list_push_back_impl, > +}; > + > +/* Kfuncs that take an rbtree node argument (bpf_rb_node *). */ > +static const enum special_kfunc_type bpf_rbtree_node_api_kfuncs[] =3D { > + KF_bpf_rbtree_remove, > + KF_bpf_rbtree_add_impl, > + KF_bpf_rbtree_left, > + KF_bpf_rbtree_right, > +}; > + > +static const enum special_kfunc_type bpf_rbtree_api_kfuncs[] =3D { > + KF_bpf_rbtree_add_impl, > + KF_bpf_rbtree_remove, > + KF_bpf_rbtree_first, > + KF_bpf_rbtree_root, > + KF_bpf_rbtree_left, > + KF_bpf_rbtree_right, > +}; > + > +static const enum special_kfunc_type bpf_res_spin_lock_kfuncs[] =3D { > + KF_bpf_res_spin_lock, > + KF_bpf_res_spin_unlock, > + KF_bpf_res_spin_lock_irqsave, > + KF_bpf_res_spin_unlock_irqrestore, > +}; > + > +static bool btf_id_in_kfunc_table(u32 btf_id, const enum special_kfunc_t= ype *kfuncs, int n) > +{ > + for (int i =3D 0; i < n; i++) > + if (btf_id =3D=3D special_kfunc_list[kfuncs[i]]) > + return true; > + return false; > +} > + > static bool is_task_work_add_kfunc(u32 func_id) > { > return func_id =3D=3D special_kfunc_list[KF_bpf_task_work_schedule_sign= al] || > @@ -13038,22 +13085,14 @@ static int check_reg_allocation_locked(struct b= pf_verifier_env *env, struct bpf_ > =20 > static bool is_bpf_list_api_kfunc(u32 btf_id) > { > - return btf_id =3D=3D special_kfunc_list[KF_bpf_list_push_front_impl] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_list_push_back_impl] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_list_pop_front] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_list_pop_back] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_list_front] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_list_back]; > + return btf_id_in_kfunc_table(btf_id, bpf_list_api_kfuncs, > + ARRAY_SIZE(bpf_list_api_kfuncs)); > } > =20 > static bool is_bpf_rbtree_api_kfunc(u32 btf_id) > { > - return btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_add_impl] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_remove] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_first] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_root] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_left] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_right]; > + return btf_id_in_kfunc_table(btf_id, bpf_rbtree_api_kfuncs, > + ARRAY_SIZE(bpf_rbtree_api_kfuncs)); > } > =20 > static bool is_bpf_iter_num_api_kfunc(u32 btf_id) > @@ -13071,10 +13110,8 @@ static bool is_bpf_graph_api_kfunc(u32 btf_id) > =20 > static bool is_bpf_res_spin_lock_kfunc(u32 btf_id) > { > - return btf_id =3D=3D special_kfunc_list[KF_bpf_res_spin_lock] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_res_spin_unlock] || > - btf_id =3D=3D special_kfunc_list[KF_bpf_res_spin_lock_irqsave] |= | > - btf_id =3D=3D special_kfunc_list[KF_bpf_res_spin_unlock_irqresto= re]; > + return btf_id_in_kfunc_table(btf_id, bpf_res_spin_lock_kfuncs, > + ARRAY_SIZE(bpf_res_spin_lock_kfuncs)); > } > =20 > static bool is_bpf_arena_kfunc(u32 btf_id) > @@ -13163,14 +13200,12 @@ static bool check_kfunc_is_graph_node_api(struc= t bpf_verifier_env *env, > =20 > switch (node_field_type) { > case BPF_LIST_NODE: > - ret =3D (kfunc_btf_id =3D=3D special_kfunc_list[KF_bpf_list_push_front= _impl] || > - kfunc_btf_id =3D=3D special_kfunc_list[KF_bpf_list_push_back_im= pl]); > + ret =3D btf_id_in_kfunc_table(kfunc_btf_id, bpf_list_node_api_kfuncs, > + ARRAY_SIZE(bpf_list_node_api_kfuncs)); > break; > case BPF_RB_NODE: > - ret =3D (kfunc_btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_remove] = || > - kfunc_btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_add_impl] = || > - kfunc_btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_left] || > - kfunc_btf_id =3D=3D special_kfunc_list[KF_bpf_rbtree_right]); > + ret =3D btf_id_in_kfunc_table(kfunc_btf_id, bpf_rbtree_node_api_kfuncs= , > + ARRAY_SIZE(bpf_rbtree_node_api_kfuncs)); > break; > default: > verbose(env, "verifier internal error: unexpected graph node argument = type %s\n",