From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm2-f9.google.com (mail-wm2-f9.google.com [74.125.225.137]) (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 5A2A123E358 for ; Tue, 4 Aug 2026 08:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.137 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785833012; cv=none; b=tmCmsQxh/W6QZE3P/2WLukiSMF17JJZK18mAQ4P4JCGaT+8JOHFWPrykS9sf055CnJZ8dEkNQmGWZCiAZoQtbQjXunm/NTeXJNxUSmwd/njEdMG+k6nqnovu++SmzEouwnJv5mtLcDQ0aoo9OF3Y0Z3asry423AhCtYTIenk0Ns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785833012; c=relaxed/simple; bh=hPFf1ypLPsXSxk5jJ/tdXLRHlGtS/pCEQCDRTah8aic=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=agMnEmXDvzvXRHjiGBPH4pjfVy8INtqG64U/ZO8dj3PAz9dMPfY3EShrKiHGCnFEePKQSzyYLe299zHL70MG+/MDL7y+UWfLjavvWQDSib+z6AahHaUWiy/hKFu2NkZyig1mBP5CDna05WFZL19zGlqNWNVsqCFb2iSfAznvscw= 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=FcwbohFl; arc=none smtp.client-ip=74.125.225.137 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="FcwbohFl" Received: by mail-wm2-f9.google.com with SMTP id 5b1f17b1804b1-49553da76dcso11014825e9.1 for ; Tue, 04 Aug 2026 01:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785833010; x=1786437810; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=CPBdcxqneLJaWRE3D0wohrfsaMJhDjseJnAc+v/1Cjs=; b=FcwbohFluF66cQhY5wqtvfWDUlyna3+GBn6FRG6MtuGufcc2k/RB1TBtJwfvHZKAln VV59hmWTsGuih8nGTZE2siHiGKMqVGqJGIJSs+D9pQmK5fe4YzEq7l2OiSbdPBnEm2BC AZ4mP95mFxI4Wxc0AhzA4PndH+B5kP4CFNko1MvtcTFmzMGH1tJXOxrFlVDeoIFYNyxF MsqrArDbXB+4YjDi4mX3Il8a9VaawIEnQ9oGE8UHp3rXSZBKziCPSI3juJ4RxaatekXH gtSYsn6BxhX12kFO2u/4JLwUOP+Xt4G3VE8Et7bl/Hg8g185reCTe4xjeafvJeYzj3FG rMpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785833010; x=1786437810; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CPBdcxqneLJaWRE3D0wohrfsaMJhDjseJnAc+v/1Cjs=; b=DMyF1WHBNeuX/QcO9/o0zR3OEx3s0nu0TspILYgkeVLIjCDyHfek6m72C5i6zdBawn BoHLzyvk1EPLBukhuYa8Y3RBKxIP56yegcVeAPHW7yZpXS6WwALLrcYYY4bp8G78Z+ev +qwIvpP1jUpq3rN75WDd63ybJ1xl0yzbABqbYA7efrQb6yUUl3sHa9b7TyjGPd54Xg5S ITk4Kl8Y2bsYJgrscLx60oPUEmQC4TRwIGOwHgSjk5Miw8UOuJ0TmCUGH7W75z5QH3nD RNQUaHnvv9bJ1z8tsljXsgOUvp+950v4fA7M/vmREnNto7Co9VdUeQHlld4J0QxsGrZr CUGA== X-Forwarded-Encrypted: i=1; AHgh+RooOEL7mabeDmJ1lVUnBAcMV4JsKdcVr/tyL5V6JRnM+WClRcseyTpm4sMtZ/HxVcn2l4kbmOwwO/v3WjQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzqW18usBV+kTEDNlABz4GAPojF1IxofYeKEauB2xfaHQW+X/XW o4IR9QeaS0U716PepBmpQ9wvJFE7obogNwhsPwOTzjotBIo0cpNuo6W4 X-Gm-Gg: AR+sD13y1kkpUqAIybYBknf/3/iOO8XKb9aXtpy8JNoqSs2DPYBIRrPDBcwZlI+Py9C 75bafBcKWeVtERw2dRtXnLx7KrFXiJlAU3fKAkTldjXZMCiiBXOMLdzGuXXHrxJLAn68mZGcobO hpKCh79Fbhf5hEnBhV7qXyoqTiL7tNo1n2dgvOAdcM6Ve0mRWs4j83fYLHW4vlN09OH9DsTpe9T D6G4gWY2LOX1MaxeVBsofHawYGOJQUdYt1HTeHQKctqbZRJ2Ch9aNIoM+2Nxn4WGduIpHqrtHeN vyqE/8CFGjVWbkOEiyQezrmX2DPY9bSjJIFehtHV7sZK+idUQWOYsFNTpFRDdVtiQjckzVYA5ol B2mbuUBo9tcmmP0LPj1UcTwCKqhmdNfVWhknxpJ7aggxi/+atk4YE3o583TeasX0pjdhggVVAAD 57g2FyoRayXs6XvSuuG+02YRh4aVUDL0XcwDfAEosW7ReA3yZqKI1saA4CugGW0Tox9fttT7+Ss uJjXKhFEQEkQ5lu63mrlsPjUb+eeIZKrMlx7ExDcD1cFIlq+UEQZlje4BncrKSCk1MD6OiO2cuX SpX6RvoLgdvX9p+BLVU1soiJKPc= X-Received: by 2002:a05:600c:4e52:b0:496:bbce:fc with SMTP id 5b1f17b1804b1-4980c658ff3mr345856595e9.12.1785833009276; Tue, 04 Aug 2026 01:43:29 -0700 (PDT) Received: from localhost (nat-icclus-192-26-29-3.epfl.ch. [192.26.29.3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994a0fca55sm72931465e9.13.2026.08.04.01.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2026 01:43:28 -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: Tue, 04 Aug 2026 10:43:28 +0200 Message-Id: Cc: , , "Kaitao Cheng" Subject: Re: [PATCH] bpf: add KF_SPIN_LOCK flag for kfuncs under bpf_spin_lock From: "Kumar Kartikeya Dwivedi" To: "Kaitao Cheng" , "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Eduard Zingerman" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "John Fastabend" , "Ihor Solodrai" X-Mailer: aerc 0.21.0 References: <20260804083212.79271-1-kaitao.cheng@linux.dev> In-Reply-To: <20260804083212.79271-1-kaitao.cheng@linux.dev> On Tue Aug 4, 2026 at 10:32 AM CEST, Kaitao Cheng wrote: > From: Kaitao Cheng > > Introduce the KF_SPIN_LOCK kfunc metadata flag in BTF so kfuncs may be > explicitly marked as safe to call while holding bpf_spin_lock. > > Allow kfuncs defined in kernel modules to be marked with KF_SPIN_LOCK. > > Example: BTF_ID_FLAGS(func, $kfunc_name, KF_SPIN_LOCK) > > Signed-off-by: Kaitao Cheng > --- > include/linux/btf.h | 1 + > kernel/bpf/verifier.c | 20 +++++++++++++++----- > 2 files changed, 16 insertions(+), 5 deletions(-) > > diff --git a/include/linux/btf.h b/include/linux/btf.h > index c09b7994de4e..380dc10b6750 100644 > --- a/include/linux/btf.h > +++ b/include/linux/btf.h > @@ -79,6 +79,7 @@ > #define KF_ARENA_ARG1 (1 << 14) /* kfunc takes an arena pointer as its= first argument */ > #define KF_ARENA_ARG2 (1 << 15) /* kfunc takes an arena pointer as its= second argument */ > #define KF_IMPLICIT_ARGS (1 << 16) /* kfunc has implicit arguments suppl= ied by the verifier */ > +#define KF_SPIN_LOCK (1 << 17) /* kfunc is allowed inside bpf_spin_lo= ck-ed region */ > > /* > * Tag marking a kernel function as a kfunc. This is meant to minimize t= he > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 7aa47342dc65..9f3feba3c2fe 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -11657,11 +11657,21 @@ static bool is_bpf_stream_kfunc(u32 btf_id) > btf_id =3D=3D special_kfunc_list[KF_bpf_stream_print_stack]; > } > > -static bool kfunc_spin_allowed(u32 btf_id) > +static bool kfunc_spin_allowed(struct bpf_verifier_env *env, s32 func_id= , s16 offset) > { > - return is_bpf_graph_api_kfunc(btf_id) || is_bpf_iter_num_api_kfunc(btf_= id) || > - is_bpf_res_spin_lock_kfunc(btf_id) || is_bpf_arena_kfunc(btf_id)= || > - is_bpf_stream_kfunc(btf_id); > + struct bpf_kfunc_meta kfunc; > + int err; > + > + if (is_bpf_graph_api_kfunc(func_id) || is_bpf_iter_num_api_kfunc(func_i= d) || > + is_bpf_res_spin_lock_kfunc(func_id) || is_bpf_arena_kfunc(func_id) = || > + is_bpf_stream_kfunc(func_id)) > + return true; > + > + err =3D fetch_kfunc_meta(env, func_id, offset, &kfunc); > + if (err || !kfunc.flags) > + return false; > + > + return *kfunc.flags & KF_SPIN_LOCK; > } > > static bool is_sync_callback_calling_kfunc(u32 btf_id) > @@ -17289,7 +17299,7 @@ static int do_check_insn(struct bpf_verifier_env = *env, bool *do_print_state) > insn->imm !=3D BPF_FUNC_spin_unlock && > insn->imm !=3D BPF_FUNC_kptr_xchg) || > (insn->src_reg =3D=3D BPF_PSEUDO_KFUNC_CALL && > - (insn->off !=3D 0 || !kfunc_spin_allowed(insn->imm)))) { > + !kfunc_spin_allowed(env, insn->imm, insn->off))) { > verbose(env, > "function calls are not allowed while holding a lock\n"); > return -EINVAL; Why not apply it to all of the existing kfuncs? Also, use [PATCH bpf-next] = subject. pw-bot: cr