From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (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 AC75242BC39 for ; Wed, 5 Aug 2026 16:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785948704; cv=none; b=BwC593WrCaU4mniYqorfQwQR9pAvXDLbX5VE4CcgwUJypxr1Xkvl6HYZX8VEpDmcboo1ZsiyFcilse30N/AUAYVyPzHq7RWqsnrGwa2KxO/6I5mgnr1gFqY2kJFjhBOdPb/d0gdiTRt1gOOZ8HXYD06BJ4t5nn6nKKLHJuJWFl4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785948704; c=relaxed/simple; bh=273XCrzmAdbCT89p9Ch08I6IsbJHTHk266OvP2ce1h8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aSgeaYRjxpI+JFcXwZ/4flpo1CJO1mXJGoxcWwdPn2oDjMSLYNa1j8Ds4gGZGVfebWCw1b8RghwX1FJuJ+VcWeevjDrryS54BHhQeXB0OvoiOVbJ6vVXZ8GKi3J4umivmpmk6Qpc60+3/m4L733HF9bMX/9EWKkmc8uH9PW0LJg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pCitqSgA; arc=none smtp.client-ip=95.215.58.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pCitqSgA" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785948690; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zpcBlsFzi4+7YT+H0jx3YNPc4qypxBr5/eqR94FR2YE=; b=pCitqSgA9Xtw97JhC3Y/0oWPfkxXS2AQgmtk0CGcym3yQ6YC78edeAkHjUh7Rc9KW5mS0a cpb8g9zIkVGN2/h+a5IMSSGHBXbSalu3if1sbcWdEcaGv3R10/5qMZaSoCP30chJd5BB5F fybZDNA9SbshMMiRngLiZIyn8VrjNHQ= Date: Thu, 6 Aug 2026 00:51:08 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v2 0/3] bpf: Allow selected kfuncs under bpf_spin_lock To: Kaitao Cheng , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , John Fastabend , Shuah Khan Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260805153340.34776-1-kaitao.cheng@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Leon Hwang In-Reply-To: <20260805153340.34776-1-kaitao.cheng@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2026/8/5 23:33, Kaitao Cheng wrote: > The verifier currently has a hard-coded allowlist of kfuncs that may be > called while a BPF program holds a bpf_spin_lock. This works for the > small set of built-in kfuncs known to the verifier, but it does not give > kfunc providers a registration-time way to declare that a kfunc is safe > in such a region. In particular, module kfuncs cannot be added to that > allowlist without changing verifier code. > > This series adds a new KF_SPINLOCK_SAFE kfunc flag and teaches the > verifier to use kfunc registration metadata when deciding whether a > kfunc call is allowed while a bpf_spin_lock is held. > > The built-in kfuncs that are currently accepted by the verifier's > lock-held allowlist are annotated with the new flag. This preserves the > existing behavior while removing the verifier-side category checks and > uses the same mechanism for built-in and module kfuncs. > > The selftest coverage marks one bpf_testmod kfunc as KF_SPINLOCK_SAFE > and verifies that it can be called under a bpf_spin_lock. It also calls > another registered but unmarked bpf_testmod kfunc under the lock and > checks that the verifier rejects it. > > Changes in v2: > - Rename KF_SPIN_LOCK to KF_SPINLOCK_SAFE. (Kumar Kartikeya Dwivedi, > Leon Hwang) > - Deprecate the verifier's lock-held allowlist mechanism and annotate the > relevant kfuncs uniformly with KF_SPINLOCK_SAFE (Kumar Kartikeya Dwivedi) > - Add selftests. (Leon Hwang) > > Link to v1: > https://lore.kernel.org/bpf/DKG0YUDSTBUY.1X220287HT9V3@gmail.com/ > > Kaitao Cheng (3): > bpf: Add KF_SPINLOCK_SAFE flag for kfuncs under bpf_spin_lock > bpf: Mark existing lock-safe kfuncs with KF_SPINLOCK_SAFE > selftests/bpf: Test module kfunc calls under spin lock > > include/linux/btf.h | 1 + > kernel/bpf/arena.c | 6 +- > kernel/bpf/helpers.c | 56 ++++++++++--------- > kernel/bpf/rqspinlock.c | 8 +-- > kernel/bpf/verifier.c | 38 +++---------- > .../selftests/bpf/prog_tests/kfunc_call.c | 2 + > .../selftests/bpf/progs/kfunc_call_fail.c | 12 ++++ > .../selftests/bpf/progs/kfunc_call_test.c | 12 ++++ > .../selftests/bpf/test_kmods/bpf_testmod.c | 2 +- > 9 files changed, 72 insertions(+), 65 deletions(-) > Nice to drop those 'is_*_kfunc()' helpers in verifier. BTW, some of those kfuncs can be dropped from the special_kfunc_list. That would be better. Any way, this series looks good to me. Acked-by: Leon Hwang