From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 65E9116DEB1 for ; Thu, 21 May 2026 04:07:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779336469; cv=none; b=q1jcVUylpm5DVIOLqsU27dR8nGVCwx3IrwadB51rE0c4CCCWfftFavgmg+ScJgjvh2xE2WLENK55MekdBfmT+RqqE+T7KEBTVgcxe3wLBT/uyNL/yUdSJvvITj2Rz8CW7waSgKyx6gZVqFnbEChMX+M973izqHB4RwMBhO01/5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779336469; c=relaxed/simple; bh=fBEBu93b5jczK6qq9CsUWP0pGZF6IcTC/U317pLv/p0=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=DagcV8wFkUDj2TjHcL8xtmUbM0v9TSVElKf3Ww/HNKKL45xXN+OdN1qpZGNw9NonVFT5HzXdj4FXPl8DK8Um9s/OfEKyG5tHfxZN9WZWpqBh59H9AYfB6HrwrvtG8J+/AxCljkYcu6JVKa8mbd52RpogenUYNZ3u11WgoWXmMbw= 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.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b=tCW6JKcf; arc=none smtp.client-ip=209.85.210.174 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.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b="tCW6JKcf" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-837b39eb078so3821063b3a.2 for ; Wed, 20 May 2026 21:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20251104.gappssmtp.com; s=20251104; t=1779336466; x=1779941266; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=C2hkMG41D7UumAODedFGWVazHZhYrfBwUFGTzkSTLig=; b=tCW6JKcfI9EGAM1193Ed+NuMH9j0D3IGgFL/aZ6Ch6M2HAc8jHcvElQv05aM0107Bl 2cCoejLkWJpc7rgGb9/OUGfL2lXAPwMgD88JnXVcUJWMLrRexKp7zzD/TD32BDfgr3YP 6a2PMyBa0PImLh6ZN4GqNEBEVugTWnGtYmcoR4/6AWPF9Ie57jSCmvLyxMob30RRW/6B z6PSkY/ouGA4H+cxjMy0uxTLZtcvt5p8vVO5fiQbNyeh0MrHyfGyBjq9i5dy0Y6G9M6W 1zUplY9L3zW2U9N7XCAPSS4csEu0faRlnhzYOLVtZ0lPF9+WpdP5gH+mrd9l4LzgiTEQ QNCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779336466; x=1779941266; h=in-reply-to:references:to:from:subject:cc: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=C2hkMG41D7UumAODedFGWVazHZhYrfBwUFGTzkSTLig=; b=kpnxh8BIo+RhHYuMlWtqG3qmJERHqai2SZyzMMwnIn6lMDLBg+Zil23/nW4ZAMWpnG F014Np3rwsDJDsV51xNNrfOTNud6gzeAkTv3XrPjj0WOqsHd/oZOG18RKxjwr7eD+CNy yRmC5xvIN/PapO+pzOplK2FvxrXmg3n9Fl8u4z39U9NJD9i4MPr0DPZrazMvxI3utt7t 2BtIwPkiw1nWPTk9ufjQ/UAagktCn+o/fDa4gAaF0AHU1RPxBLwNfZMtdyY8kxLjJF0J 5Irapy2/+F9WPLY4/hBW+EU1SscsDdLT7NIzcfwUNNbSg3V30YhGPNseQBMKm2r6mIJe hz7A== X-Forwarded-Encrypted: i=1; AFNElJ8v9KWnHzCbfyitGX/1+Lc8zAnvF1wbLURX0+WwPtEVaZrRnPMOA8giXu3Mi1A9+kMdLZbxY9EYOYiYulc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9tP2uQHciuGIa4smmOyHcF4MlQC+Rq/fpZiWtelHCSbOpahoQ 7nqKLJk2XRI1UL5NXt8jf5Qqouvg7xTKmL636+iCDbwg4P7nAFcrnL1bsaoWsrS79U8= X-Gm-Gg: Acq92OEUchb6iEfZCO1u9WLYiFMhPF2GCiYoUUWwHxyCetMysfx87BeEubVJNlHoPbE OSLhKN2zopkwlts/96UklJp9l7K13dK7XaPT56qL2peU9stOG57ZQ40Q6Qh9VDWPcEtq+Wgku29 wWehNqqvuxJ40cUFuvFsgfM1FNH3vYy8CdnWMCqKWdwsbsKD9n0Y0WARPhwkGpzsbGk7C1gzMWn NYJf8QbzvhMUcCzETCjj0wrUV1BtxkS7zoHiWRe98nk+4DqB9yCPmQx00b37t5u5OmU5dCeYlUv t+99Wo3EKQLKr1RUD+Lons0lhH1ThlLpMou0KIgGTJuCeuluRnxoMmSkkqkFb/lay+s5EEfoG/g VBEoiPWSh9molpbPC3Df74EiYvoEKZjbz2m0bLgT8z1Y08TclQeli4bFkT8kX7LCh/Ta397w1K7 kujeyHerFJcFW0qBt0j6wvFCsk2+CwEyXI/8I= X-Received: by 2002:a05:6a00:4c8c:b0:83f:250d:59c with SMTP id d2e1a72fcca58-8414ae6e912mr1347583b3a.39.1779336465527; Wed, 20 May 2026 21:07:45 -0700 (PDT) Received: from localhost ([2001:569:58a0:da00:a5c8:c4ce:f7c1:40c1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19f7cd19sm22757564b3a.54.2026.05.20.21.07.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 May 2026 21:07:45 -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, 21 May 2026 00:07:44 -0400 Message-Id: Cc: "Peter Zijlstra" , "Catalin Marinas" , "Will Deacon" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , "Andrew Morton" , "David Hildenbrand" , "Mike Rapoport" , "Emil Tsalapatis" , , , , , , Subject: Re: [PATCH 4/8] bpf: Add bpf_struct_ops_for_each_prog() From: "Emil Tsalapatis" To: "Tejun Heo" , "David Vernet" , "Andrea Righi" , "Changwoo Min" , "Alexei Starovoitov" , "Andrii Nakryiko" , "Daniel Borkmann" , "Martin KaFai Lau" , "Kumar Kartikeya Dwivedi" X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260520235052.4180316-1-tj@kernel.org> <20260520235052.4180316-5-tj@kernel.org> In-Reply-To: <20260520235052.4180316-5-tj@kernel.org> On Wed May 20, 2026 at 7:50 PM EDT, Tejun Heo wrote: > Add a helper that walks the member progs of the struct_ops map > containing a given @kdata vmtable. struct_ops ->reg() callbacks (and > similar) sometimes need to inspect the loaded BPF programs, e.g. to > discover maps they reference via prog->aux->used_maps. > > The implementation mirrors bpf_struct_ops_id(): container_of @kdata > to recover the bpf_struct_ops_map, then iterate st_map->links[i]->prog > for i in [0, funcs_cnt). Same access pattern, no new locking - by the > time ->reg() fires st_map is fully populated and stable. > > A sched_ext follow-up walks the member progs of a cid-form scheduler's > struct_ops map, reads prog->aux->arena directly, and requires all member > progs to reference exactly one arena, without requiring the BPF program > to call a registration kfunc. > > Signed-off-by: Tejun Heo Reviewed-by: Emil Tsalapatis > --- > include/linux/bpf.h | 3 +++ > kernel/bpf/bpf_struct_ops.c | 36 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 39 insertions(+) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 64968ca6db51..5b99d786e98c 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -2129,6 +2129,9 @@ int bpf_prog_assoc_struct_ops(struct bpf_prog *prog= , struct bpf_map *map); > void bpf_prog_disassoc_struct_ops(struct bpf_prog *prog); > void *bpf_prog_get_assoc_struct_ops(const struct bpf_prog_aux *aux); > u32 bpf_struct_ops_id(const void *kdata); > +int bpf_struct_ops_for_each_prog(const void *kdata, > + int (*cb)(struct bpf_prog *prog, void *data), > + void *data); > =20 > #ifdef CONFIG_NET > /* Define it here to avoid the use of forward declaration */ > diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c > index 05b366b821c3..16aec18ed31b 100644 > --- a/kernel/bpf/bpf_struct_ops.c > +++ b/kernel/bpf/bpf_struct_ops.c > @@ -1203,6 +1203,42 @@ u32 bpf_struct_ops_id(const void *kdata) > } > EXPORT_SYMBOL_GPL(bpf_struct_ops_id); > =20 > +/** > + * bpf_struct_ops_for_each_prog - Invoke @cb for each member prog > + * @kdata: kernel-side struct_ops vmtable (the @kdata arg to ->reg/->upd= ate/->unreg) > + * @cb: callback invoked once per member prog; non-zero return stops ite= ration > + * @data: opaque argument passed to @cb > + * > + * Walks the struct_ops member progs registered on the map containing @k= data. > + * Intended for use from struct_ops ->reg() callbacks (and similar) that= need to > + * inspect the loaded BPF programs (for example to discover maps they re= ference > + * via @prog->aux->used_maps). > + * > + * Return 0 if iteration completed, otherwise the first non-zero @cb ret= urn. > + */ > +int bpf_struct_ops_for_each_prog(const void *kdata, > + int (*cb)(struct bpf_prog *prog, void *data), > + void *data) > +{ > + struct bpf_struct_ops_value *kvalue; > + struct bpf_struct_ops_map *st_map; > + u32 i; > + int ret; > + > + kvalue =3D container_of(kdata, struct bpf_struct_ops_value, data); > + st_map =3D container_of(kvalue, struct bpf_struct_ops_map, kvalue); > + > + for (i =3D 0; i < st_map->funcs_cnt; i++) { > + if (!st_map->links[i]) > + continue; > + ret =3D cb(st_map->links[i]->prog, data); > + if (ret) > + return ret; > + } > + return 0; > +} > +EXPORT_SYMBOL_GPL(bpf_struct_ops_for_each_prog); > + > static bool bpf_struct_ops_valid_to_reg(struct bpf_map *map) > { > struct bpf_struct_ops_map *st_map =3D (struct bpf_struct_ops_map *)map;