From nobody Mon Feb 9 20:31:40 2026 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 C47E62FD685 for ; Fri, 23 Jan 2026 08:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769158593; cv=none; b=sBK78EdeDeRdSbGu3okyGNtaS9HRxlT9gAuBnzS6ihww56Yw8XHOK9me+4xkjw0ffTlEAbSdNns5B3+pVdNhyE9N95P5CftrYbSARLcsmf96FATWRH0jiUWhfFheGO4pT1AcT2tX3jFtPXEn5mRHaMIczlDp4ZHCOQA1Ukv7SfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769158593; c=relaxed/simple; bh=VMWSjdZBbwCROxtM45L3N2YVJItH/AEKdFdBA0R/Kg8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gef5U08QWjEXRZL1AxQRu3Mwk+D0+oRkr+Xr6ys6I3AJUaYF4rtjmCr77HO+XHdZ4E7TMrQ7/eB/vQlKUYyvSZ0au5Rs4IoyxP+eHlEdT5bBjs2kfXk6YaLysRQbRLPjzw88h2favPmmsrlhqz3Prw5EFrvpx2tV2ePnxIlIp7U= 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=NMD50k4b; arc=none smtp.client-ip=91.218.175.181 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="NMD50k4b" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1769158589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mRzQHCKarCYBi7G1xIo0Ho9ytROzsvuCqz+L2Dk75mk=; b=NMD50k4bUm77bwDcYhOB0EpujUCmId6LC0LnmOQ+cN7HRcsMqcCVMBNhz7FEmicI88cTzs fCiKD/e7ZUORx7uTYhwqmUndQiS7GsgwVJdfUZ4G1Wtzv8/QnHJOyc0nCpr8f/K4LOtplX e4UW3EsGa7P7cP1zRrhbOsTQC9UwH8w= From: Hui Zhu To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Peter Zijlstra , Miguel Ojeda , Nathan Chancellor , Kees Cook , Tejun Heo , Jeff Xu , mkoutny@suse.com, Jan Hendrik Farr , Christian Brauner , Randy Dunlap , Brian Gerst , Masahiro Yamada , davem@davemloft.net, Jakub Kicinski , Jesper Dangaard Brouer , JP Kobryn , Willem de Bruijn , Jason Xing , Paul Chaignon , Anton Protopopov , Amery Hung , Chen Ridong , Lance Yang , Jiayuan Chen , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH bpf-next v3 02/12] bpf: initial support for attaching struct ops to cgroups Date: Fri, 23 Jan 2026 16:55:20 +0800 Message-ID: In-Reply-To: References: 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Roman Gushchin When a struct ops is being attached and a bpf link is created, allow to pass a cgroup fd using bpf attr, so that struct ops can be attached to a cgroup instead of globally. Attached struct ops doesn't hold a reference to the cgroup, only preserves cgroup id. Signed-off-by: Roman Gushchin --- include/linux/bpf.h | 1 + kernel/bpf/bpf_struct_ops.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 031682f1ad39..7c15bac782fc 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1885,6 +1885,7 @@ struct bpf_struct_ops_link { struct bpf_link link; struct bpf_map __rcu *map; wait_queue_head_t wait_hup; + u64 cgroup_id; }; =20 struct bpf_link_primer { diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index de01cf3025b3..f575c5cd0dc8 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -13,6 +13,7 @@ #include #include #include +#include =20 struct bpf_struct_ops_value { struct bpf_struct_ops_common_value common; @@ -1377,6 +1378,18 @@ int bpf_struct_ops_link_create(union bpf_attr *attr) } bpf_link_init(&link->link, BPF_LINK_TYPE_STRUCT_OPS, &bpf_struct_ops_map_= lops, NULL, attr->link_create.attach_type); +#ifdef CONFIG_CGROUPS + if (attr->link_create.cgroup.relative_fd) { + struct cgroup *cgrp; + + cgrp =3D cgroup_get_from_fd(attr->link_create.cgroup.relative_fd); + if (IS_ERR(cgrp)) + return PTR_ERR(cgrp); + + link->cgroup_id =3D cgroup_id(cgrp); + cgroup_put(cgrp); + } +#endif /* CONFIG_CGROUPS */ =20 err =3D bpf_link_prime(&link->link, &link_primer); if (err) --=20 2.43.0