From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 D306A34DCD7 for ; Fri, 3 Apr 2026 17:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.215.182 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775238105; cv=pass; b=QfxacwjT0TEmBZcvXdUhLMJrnhNc2dlOXrRk2Zkoot1lqUIoUDI5VqelOGZP3/E9aCzneRWJ9PoL+QikS/a21LRGGlpKueOpHmiEx1VuhedQVo3sg6NYU32f4cmmOfUsbxE783pdwCYGLws5NAT6WjmlXQsIlVGEjWdcsY3U6+g= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775238105; c=relaxed/simple; bh=5lWVn8YMvYAwRs2zR285cHCiDnPH0plenXQD6VjDk7Y=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=NWQdVA2U2jjey3uTuFbcnNJhCjRZyZzdboO3WNS63eMpvr2v2hGURpbWWcxvqwPnBT+zqvsqMyK6hW64nf026FzTj60N1oAOb1eyY03yNHDPiolGWeLa1CTYmFCQ0wKMGGWvLTAPHCSCotc4TUQaF2u85YnT4Wo61o2joExY8i0= ARC-Authentication-Results:i=2; 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=HSpv9MDk; arc=pass smtp.client-ip=209.85.215.182 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="HSpv9MDk" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-c76864f4e58so852517a12.1 for ; Fri, 03 Apr 2026 10:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775238103; cv=none; d=google.com; s=arc-20240605; b=PNIyCt0InBVJ77tsN57DRQZ7PpH3cjMpfXW6cZXjR5g7lUxgJPg0qcNiXs7v1GXN8D hhIrHXoWcpQyF8pUFve7GxsA8a/FZW0KMOppUYsN83q/qbtTicaNXbpj7W7sCGBpl77T wYvXE62H4CH93yGD1SIrcbw4biSL5GHRR+0Bm4bseHgGDiwV+Dfb5Dzv3HIyO/oTQhRE 8Umq8DpyWhwq0Xt1dmQQ5NAFCKqMGrCzNu52KzockCjLgfrr53O9Q7wY6d8ATYwmJnG9 G7Cgt54LyGD1JxA8JM5DjX8WdSv4QQVkTbZfBT4XqzMFZcr89wXb92Pe1a5yaTMFc+Tc oykA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0W7mSWaqi0MOT0pMvqxQVOJ9twswqNKYzff6Qr8i4JI=; fh=G5EQSXEervRs1VfTZFG8Ew7t+l5bJZnKbVkK90pqXrY=; b=BCYP+/5ZRUQj5eNYgBkCX1lIVINphsFCq/TDdzd49wIKuURWxT3h6znvsSd4uz3pa8 SLOROKaRHN9/8hJEINfvNvpdg7cPcqiU5UOnMjq9gKXOU+GtNVgECyiwkeLRNCC5ZmIi daW6bLyD8aWrbolPyVK0fVj795saoqFpCRlWqn31n4uvrMiApwSpAzUi22a2Jq6eOOTK rh3vXExOUkwlNCSxTr2iRNiBJLto6+oPWj9eo/q72Sr+4rLqclZ/MdxMfA3nCYS0pSru CUZNik5Z4JmpkUEAXaQKmMchSPxtV7u7hkUuuJ48o4VGrg3Gi5gzloqaq1dCVg3hLXEO zNoQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775238103; x=1775842903; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0W7mSWaqi0MOT0pMvqxQVOJ9twswqNKYzff6Qr8i4JI=; b=HSpv9MDkKT/viPLD0hFieh7xKUWoJGWqEL4KzchnVZm/cet9S9gFXgbUsl1JVDWB+F sczg1985a16tvcxoYeurl9bj3T9tSN+GSSn+u7m6vY9EEZ2jKBuO/nddnNnZy4+u6yU4 BC3edVGDzPG23s6SbMqU6KiJcVeUWhWnKu80FN79xRQ96yWVQB2Sv/dImD47tIAb/CkN d8dhgo6mpb79RF9/WufLOqPMTK82zv2YS++IpInoInWJ6RigAYum/tBAYLdQWZ+vVTA+ C/c1ziEuiN1tERPZ4ka0TJbcKa9QHCOCVd3JqkgSK4d0rq9wfpCsQibgLJC0P7fTDAfZ +sUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775238103; x=1775842903; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0W7mSWaqi0MOT0pMvqxQVOJ9twswqNKYzff6Qr8i4JI=; b=Tu6ndfRR5RsVBKZRDKrShIJiJbvc9COL6TEqRXInJXnZetRLxs0d1SrQIZ+1qg4bTV 1W1X7QMiBdWCWDzbCie4GwuP7WcvrUNybVD7yNo3So31249Y49Vs0IetpgqTtTEqR2MH SLrka1QwBcsUYUQUDGS4UAjlPW/BbpsznHrt3IyLs+3L25sBejX5Y1R2GLuSweQWPof4 CBd83PSu/BH/OtsuNxDEz6ViHfgxB3zVq/19CQjqzDZEmhKcbbtRTdXH4BR5pS7z8w1B vHlysVJ5rwwVHuTEXRy+Ar+ShKwcr13CxvrWAYtT836d7OhILHSmnxa0DoNjEq+iQZNV /vCw== X-Forwarded-Encrypted: i=1; AJvYcCVAkt0pnTB/ERUJvGr2v/NB5dFbI17/KGrUczAWw9zOQUKW28+9saA4N9pKFCWGQPajp4WAkzNCvg6vW/o=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp22FZ5swz5EeKveMc9tdzv3T2uS54EFMDalMDifAHcyJHWaQc /4fZ00N9w+/AHhdf+dK3kdczz1UUdiTxQTGiTDzZk+73fGtTEUgAElHq3Q6tGn8tS5y7PlkRfTK LvfEP2i+C2IWbWaNDiLsCfSQvxfO2WKA= X-Gm-Gg: ATEYQzz481VHMlDRkU4wjblq4MX/6JcZ3rvS02MEAqBC0kVQufub0cVdxrnOcQ1sL2M oUg3p0luA47Vn3UoS1yF3lPnQwE9H1416unWyGpsFmN3qXfjJW7uVe21eJt4J8qCjAc+lOaeOIh 4wlqB/7P/0K35p378zXk8qzgVHITejN7CKdyAacxA+x7zJOOoPAFbepVwT16XhUhgfEHwIkt0KJ n4vsnPX3zXOpkF4FkJeVTCUTpjRU/0wjGjbU+MYw/p5d6Uudz8YHZW3tH6vkhUWt89ZkYWWi2bS dvJJvg== X-Received: by 2002:a05:6a20:12c5:b0:39b:835f:1730 with SMTP id adf61e73a8af0-39f2eff3fc0mr3843834637.15.1775238103105; Fri, 03 Apr 2026 10:41:43 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260329140506.9595-1-pilgrimtao@gmail.com> <20260329140506.9595-2-pilgrimtao@gmail.com> In-Reply-To: From: Chengkaitao Date: Sat, 4 Apr 2026 01:41:32 +0800 X-Gm-Features: AQROBzAJduT_bxIDNRvRaGan1qOkkmaaMw5BmIuyvPDf4XREPWFaFbQgB8Axi24 Message-ID: Subject: Re: [PATCH bpf-next v9 1/9] bpf: refactor kfunc checks using table-driven approach in verifier To: Alexei Starovoitov Cc: Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Chengkaitao , "open list:KERNEL SELFTEST FRAMEWORK" , bpf , LKML , ihor.solodrai@linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 31, 2026 at 1:05=E2=80=AFAM Alexei Starovoitov wrote: > > On Sun, Mar 29, 2026 at 7:05=E2=80=AFAM Chengkaitao wrote: > > > > From: Kaitao Cheng > > > > Replace per-kfunc btf_id chains check 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 > > --- > > kernel/bpf/verifier.c | 261 +++++++++++++++++++++++------------------- > > 1 file changed, 144 insertions(+), 117 deletions(-) > > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 4fbacd2149cd..f2d9863bb290 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -544,9 +544,6 @@ static bool is_async_callback_calling_kfunc(u32 btf= _id); > > static bool is_callback_calling_kfunc(u32 btf_id); > > static bool is_bpf_throw_kfunc(struct bpf_insn *insn); > > > > -static bool is_bpf_wq_set_callback_kfunc(u32 btf_id); > > -static bool is_task_work_add_kfunc(u32 func_id); > > - > > static bool is_sync_callback_calling_function(enum bpf_func_id func_id= ) > > { > > return func_id =3D=3D BPF_FUNC_for_each_map_elem || > > @@ -586,7 +583,7 @@ static bool is_async_cb_sleepable(struct bpf_verifi= er_env *env, struct bpf_insn > > > > /* bpf_wq and bpf_task_work callbacks are always sleepable. */ > > if (bpf_pseudo_kfunc_call(insn) && insn->off =3D=3D 0 && > > - (is_bpf_wq_set_callback_kfunc(insn->imm) || is_task_work_ad= d_kfunc(insn->imm))) > > + is_async_callback_calling_kfunc(insn->imm)) > > return true; > > > > verifier_bug(env, "unhandled async callback in is_async_cb_slee= pable"); > > @@ -11203,31 +11200,6 @@ static int set_task_work_schedule_callback_sta= te(struct bpf_verifier_env *env, > > return 0; > > } > > > > -static bool is_rbtree_lock_required_kfunc(u32 btf_id); > > - > > -/* Are we currently verifying the callback for a rbtree helper that mu= st > > - * be called with lock held? If so, no need to complain about unreleas= ed > > - * lock > > - */ > > -static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env) > > -{ > > - struct bpf_verifier_state *state =3D env->cur_state; > > - struct bpf_insn *insn =3D env->prog->insnsi; > > - struct bpf_func_state *callee; > > - int kfunc_btf_id; > > - > > - if (!state->curframe) > > - return false; > > - > > - callee =3D state->frame[state->curframe]; > > - > > - if (!callee->in_callback_fn) > > - return false; > > - > > - kfunc_btf_id =3D insn[callee->callsite].imm; > > - return is_rbtree_lock_required_kfunc(kfunc_btf_id); > > -} > > - > > static bool retval_range_within(struct bpf_retval_range range, const s= truct bpf_reg_state *reg) > > { > > if (range.return_32bit) > > @@ -12639,11 +12611,103 @@ BTF_ID(func, bpf_session_is_return) > > BTF_ID(func, bpf_stream_vprintk) > > BTF_ID(func, bpf_stream_print_stack) > > > > -static bool is_task_work_add_kfunc(u32 func_id) > > -{ > > - return func_id =3D=3D special_kfunc_list[KF_bpf_task_work_sched= ule_signal] || > > - func_id =3D=3D special_kfunc_list[KF_bpf_task_work_sched= ule_resume]; > > -} > > +/* Kfunc family related to list. */ > > +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 *). */ > > +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, > > +}; > > + > > +/* Kfunc family related to rbtree. */ > > +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, > > +}; > > + > > +/* Kfunc family related to spin_lock. */ > > +static const enum special_kfunc_type bpf_res_spin_lock_api_kfuncs[] = =3D { > > + KF_bpf_res_spin_lock, > > + KF_bpf_res_spin_unlock, > > + KF_bpf_res_spin_lock_irqsave, > > + KF_bpf_res_spin_unlock_irqrestore, > > +}; > > I think it's a step in the wrong direction. > I'd wait for Ihor's BTF_ID_NAMED cleanup. After reading Ihor's messages on the list, if I understand correctly, our two approaches seem to target different problems. What Ihor's work appears to achieve is the ability to remove the entire enum special_kfunc_type. My goal, on the other hand, is to replace many scattered func_id =3D=3D special_kfunc_list[...] comparisons with a table-driven approach. That said, once Ihor's solution lands, my approach would no longer be applicable as-is. So I have been thinking about an alternative, please see the patch linked below for details: https://lore.kernel.org/bpf/20260403170900.58659-1-pilgrimtao@gmail.com/ > Kaitao Cheng, > > also please start your part of code reviews. > Your patches are not going to be landing if you don't code review. > > https://lore.kernel.org/bpf/CAADnVQ+TKKptnNB25V3=3Dbcdybh5G6c2DyW2sYtXvyR= aVnPN8MA@mail.gmail.com/ I will do my best to carry this forward. --=20 Yours, Chengkaitao