This adds a bpf helper that's similar to the skb_in_cgroup helper to check
whether the probe is currently executing in the context of a specific
subset of the cgroupsv2 hierarchy. It does this based on membership test
for a cgroup arraymap. It is invalid to call this in an interrupt, and
it'll return an error. The helper is primarily to be used in debugging
activities for containers, where you may have multiple programs running in
a given top-level "container".
Signed-off-by: Sargun Dhillon <redacted>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
---
include/uapi/linux/bpf.h | 11 +++++++++++
kernel/bpf/arraymap.c | 2 +-
kernel/bpf/verifier.c | 4 +++-
kernel/trace/bpf_trace.c | 30 ++++++++++++++++++++++++++++++
4 files changed, 45 insertions(+), 2 deletions(-)
@@ -538,7 +538,7 @@ static int __init register_perf_event_array_map(void)}late_initcall(register_perf_event_array_map);-#ifdef CONFIG_SOCK_CGROUP_DATA+#ifdef CONFIG_CGROUPSstaticvoid*cgroup_fd_array_get_ptr(structbpf_map*map,structfile*map_file/* not used */,intfd)
On Thu, Aug 11, 2016 at 08:14:56PM -0700, Sargun Dhillon wrote:
This adds a bpf helper that's similar to the skb_in_cgroup helper to check
whether the probe is currently executing in the context of a specific
subset of the cgroupsv2 hierarchy. It does this based on membership test
for a cgroup arraymap. It is invalid to call this in an interrupt, and
it'll return an error. The helper is primarily to be used in debugging
activities for containers, where you may have multiple programs running in
a given top-level "container".
Signed-off-by: Sargun Dhillon <redacted>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
---
+ /**
+ * bpf_current_task_under_cgroup(map, index) - Check cgroup2 membership of current task
+ * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
+ * @index: index of the cgroup in the bpf_map
+ * Return:
+ * == 0 current failed the cgroup2 descendant test
+ * == 1 current succeeded the cgroup2 descendant test
+ * < 0 error
+ */
+ BPF_FUNC_current_task_under_cgroup,
..
case BPF_MAP_TYPE_CGROUP_ARRAY:
- if (func_id != BPF_FUNC_skb_in_cgroup)
+ if (func_id != BPF_FUNC_skb_in_cgroup &&
+ func_id != BPF_FUNC_current_task_under_cgroup)
goto error;
...
+ case BPF_FUNC_current_task_under_cgroup:
case BPF_FUNC_skb_in_cgroup:
Tejun,
do you feel strongly about 'under' ?
It just looks inconsistent vs existing skb_in_cgroup...
"in cgroup" - 4k google hits
"under cgroup" - 2k google hits
I realize that in_cgroup is more consistent, but under_cgroup makes
far more sense to me. I think it's more intuitive.
On Thu, Aug 11, 2016 at 9:48 PM, Alexei Starovoitov
[off-list ref] wrote:
On Thu, Aug 11, 2016 at 08:14:56PM -0700, Sargun Dhillon wrote:
quoted
This adds a bpf helper that's similar to the skb_in_cgroup helper to check
whether the probe is currently executing in the context of a specific
subset of the cgroupsv2 hierarchy. It does this based on membership test
for a cgroup arraymap. It is invalid to call this in an interrupt, and
it'll return an error. The helper is primarily to be used in debugging
activities for containers, where you may have multiple programs running in
a given top-level "container".
Signed-off-by: Sargun Dhillon <redacted>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
---
+ /**
+ * bpf_current_task_under_cgroup(map, index) - Check cgroup2 membership of current task
+ * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
+ * @index: index of the cgroup in the bpf_map
+ * Return:
+ * == 0 current failed the cgroup2 descendant test
+ * == 1 current succeeded the cgroup2 descendant test
+ * < 0 error
+ */
+ BPF_FUNC_current_task_under_cgroup,
..
quoted
case BPF_MAP_TYPE_CGROUP_ARRAY:
- if (func_id != BPF_FUNC_skb_in_cgroup)
+ if (func_id != BPF_FUNC_skb_in_cgroup &&
+ func_id != BPF_FUNC_current_task_under_cgroup)
goto error;
...
quoted
+ case BPF_FUNC_current_task_under_cgroup:
case BPF_FUNC_skb_in_cgroup:
Tejun,
do you feel strongly about 'under' ?
It just looks inconsistent vs existing skb_in_cgroup...
"in cgroup" - 4k google hits
"under cgroup" - 2k google hits
From: Daniel Borkmann <daniel@iogearbox.net> Date: 2016-08-12 07:16:12
On 08/12/2016 06:50 AM, Sargun Dhillon wrote:
I realize that in_cgroup is more consistent, but under_cgroup makes
far more sense to me. I think it's more intuitive.
On Thu, Aug 11, 2016 at 9:48 PM, Alexei Starovoitov
[off-list ref] wrote:
quoted
On Thu, Aug 11, 2016 at 08:14:56PM -0700, Sargun Dhillon wrote:
quoted
This adds a bpf helper that's similar to the skb_in_cgroup helper to check
whether the probe is currently executing in the context of a specific
subset of the cgroupsv2 hierarchy. It does this based on membership test
for a cgroup arraymap. It is invalid to call this in an interrupt, and
it'll return an error. The helper is primarily to be used in debugging
activities for containers, where you may have multiple programs running in
a given top-level "container".
Signed-off-by: Sargun Dhillon <redacted>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
---
+ /**
+ * bpf_current_task_under_cgroup(map, index) - Check cgroup2 membership of current task
+ * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
+ * @index: index of the cgroup in the bpf_map
+ * Return:
+ * == 0 current failed the cgroup2 descendant test
+ * == 1 current succeeded the cgroup2 descendant test
+ * < 0 error
+ */
+ BPF_FUNC_current_task_under_cgroup,
..
quoted
case BPF_MAP_TYPE_CGROUP_ARRAY:
- if (func_id != BPF_FUNC_skb_in_cgroup)
+ if (func_id != BPF_FUNC_skb_in_cgroup &&
+ func_id != BPF_FUNC_current_task_under_cgroup)
goto error;
...
quoted
+ case BPF_FUNC_current_task_under_cgroup:
case BPF_FUNC_skb_in_cgroup:
Tejun,
do you feel strongly about 'under' ?
It just looks inconsistent vs existing skb_in_cgroup...
"in cgroup" - 4k google hits
"under cgroup" - 2k google hits
Alternative could be that we take "BPF_FUNC_current_in_cgroup" as a
helper enum to keep consistency with what we have wrt skb helper, but
for the cgroup header have the suggested task_under_cgroup_hierarchy()
name.
On Fri, Aug 12, 2016 at 09:16:07AM +0200, Daniel Borkmann wrote:
On 08/12/2016 06:50 AM, Sargun Dhillon wrote:
quoted
I realize that in_cgroup is more consistent, but under_cgroup makes
far more sense to me. I think it's more intuitive.
On Thu, Aug 11, 2016 at 9:48 PM, Alexei Starovoitov
[off-list ref] wrote:
quoted
On Thu, Aug 11, 2016 at 08:14:56PM -0700, Sargun Dhillon wrote:
quoted
This adds a bpf helper that's similar to the skb_in_cgroup helper to check
whether the probe is currently executing in the context of a specific
subset of the cgroupsv2 hierarchy. It does this based on membership test
for a cgroup arraymap. It is invalid to call this in an interrupt, and
it'll return an error. The helper is primarily to be used in debugging
activities for containers, where you may have multiple programs running in
a given top-level "container".
Signed-off-by: Sargun Dhillon <redacted>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
---
+ /**
+ * bpf_current_task_under_cgroup(map, index) - Check cgroup2 membership of current task
+ * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
+ * @index: index of the cgroup in the bpf_map
+ * Return:
+ * == 0 current failed the cgroup2 descendant test
+ * == 1 current succeeded the cgroup2 descendant test
+ * < 0 error
+ */
+ BPF_FUNC_current_task_under_cgroup,
..
quoted
case BPF_MAP_TYPE_CGROUP_ARRAY:
- if (func_id != BPF_FUNC_skb_in_cgroup)
+ if (func_id != BPF_FUNC_skb_in_cgroup &&
+ func_id != BPF_FUNC_current_task_under_cgroup)
goto error;
...
quoted
+ case BPF_FUNC_current_task_under_cgroup:
case BPF_FUNC_skb_in_cgroup:
Tejun,
do you feel strongly about 'under' ?
It just looks inconsistent vs existing skb_in_cgroup...
"in cgroup" - 4k google hits
"under cgroup" - 2k google hits
Alternative could be that we take "BPF_FUNC_current_in_cgroup" as a
helper enum to keep consistency with what we have wrt skb helper, but
for the cgroup header have the suggested task_under_cgroup_hierarchy()
name.
I actually wish we could rename skb_in_cgroup to skb_under_cgroup. If we ever
introduced a check for absolute membership versus ancestral membership, what
would we call that?
From: Daniel Borkmann <daniel@iogearbox.net> Date: 2016-08-12 08:06:01
On 08/12/2016 09:22 AM, Sargun Dhillon wrote:
On Fri, Aug 12, 2016 at 09:16:07AM +0200, Daniel Borkmann wrote:
quoted
On 08/12/2016 06:50 AM, Sargun Dhillon wrote:
quoted
I realize that in_cgroup is more consistent, but under_cgroup makes
far more sense to me. I think it's more intuitive.
On Thu, Aug 11, 2016 at 9:48 PM, Alexei Starovoitov
[off-list ref] wrote:
quoted
On Thu, Aug 11, 2016 at 08:14:56PM -0700, Sargun Dhillon wrote:
quoted
This adds a bpf helper that's similar to the skb_in_cgroup helper to check
whether the probe is currently executing in the context of a specific
subset of the cgroupsv2 hierarchy. It does this based on membership test
for a cgroup arraymap. It is invalid to call this in an interrupt, and
it'll return an error. The helper is primarily to be used in debugging
activities for containers, where you may have multiple programs running in
a given top-level "container".
Signed-off-by: Sargun Dhillon <redacted>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
---
+ /**
+ * bpf_current_task_under_cgroup(map, index) - Check cgroup2 membership of current task
+ * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
+ * @index: index of the cgroup in the bpf_map
+ * Return:
+ * == 0 current failed the cgroup2 descendant test
+ * == 1 current succeeded the cgroup2 descendant test
+ * < 0 error
+ */
+ BPF_FUNC_current_task_under_cgroup,
..
quoted
case BPF_MAP_TYPE_CGROUP_ARRAY:
- if (func_id != BPF_FUNC_skb_in_cgroup)
+ if (func_id != BPF_FUNC_skb_in_cgroup &&
+ func_id != BPF_FUNC_current_task_under_cgroup)
goto error;
...
quoted
+ case BPF_FUNC_current_task_under_cgroup:
case BPF_FUNC_skb_in_cgroup:
Tejun,
do you feel strongly about 'under' ?
It just looks inconsistent vs existing skb_in_cgroup...
"in cgroup" - 4k google hits
"under cgroup" - 2k google hits
Alternative could be that we take "BPF_FUNC_current_in_cgroup" as a
helper enum to keep consistency with what we have wrt skb helper, but
for the cgroup header have the suggested task_under_cgroup_hierarchy()
name.
I actually wish we could rename skb_in_cgroup to skb_under_cgroup. If we ever
introduced a check for absolute membership versus ancestral membership, what
would we call that?
That option is, by the way, still on the table for -net tree, since 4.8 is not
released yet, so it could still be renamed into BPF_FUNC_skb_under_cgroup.
Then you could make this one here for -net-next as "BPF_FUNC_current_under_cgroup".
Tejun, Alexei?
On Thu, Aug 11, 2016 at 09:50:48PM -0700, Sargun Dhillon wrote:
I realize that in_cgroup is more consistent, but under_cgroup makes
far more sense to me. I think it's more intuitive.
So, I think in_cgroup should mean that the object is in that
particular cgroup while under_cgroup in the subhierarchy of that
cgroup. Let's rename the other subhierarchy test to under too. I
think that'd be a lot less confusing going forward.
Thanks.
--
tejun
On Fri, Aug 12, 2016 at 09:21:39AM -0400, Tejun Heo wrote:
On Thu, Aug 11, 2016 at 09:50:48PM -0700, Sargun Dhillon wrote:
quoted
I realize that in_cgroup is more consistent, but under_cgroup makes
far more sense to me. I think it's more intuitive.
So, I think in_cgroup should mean that the object is in that
particular cgroup while under_cgroup in the subhierarchy of that
cgroup. Let's rename the other subhierarchy test to under too. I
think that'd be a lot less confusing going forward.
Ah, I suppose the bpf part is userland visible? If so, there isn't
much we can do and probably best to stick with in_cgroup for that
part. Bummer but no big deal.
Thanks.
--
tejun
Hello,
On Fri, Aug 12, 2016 at 09:40:39AM +0200, Daniel Borkmann wrote:
quoted
I actually wish we could rename skb_in_cgroup to skb_under_cgroup. If we ever
introduced a check for absolute membership versus ancestral membership, what
would we call that?
That option is, by the way, still on the table for -net tree, since 4.8 is not
released yet, so it could still be renamed into BPF_FUNC_skb_under_cgroup.
Then you could make this one here for -net-next as "BPF_FUNC_current_under_cgroup".
Tejun, Alexei?
lol I should have read the whole thread before replying twice. Sorry
about that. Yeah, if we can still rename it, let's do "under". It's
more intuitive and gives us the room to implement the real "in" test
if ever necessary in the future.
Thanks.
--
tejun
On Fri, Aug 12, 2016 at 09:29:35AM -0400, Tejun Heo wrote:
Hello,
On Fri, Aug 12, 2016 at 09:40:39AM +0200, Daniel Borkmann wrote:
quoted
quoted
I actually wish we could rename skb_in_cgroup to skb_under_cgroup. If we ever
introduced a check for absolute membership versus ancestral membership, what
would we call that?
That option is, by the way, still on the table for -net tree, since 4.8 is not
released yet, so it could still be renamed into BPF_FUNC_skb_under_cgroup.
Then you could make this one here for -net-next as "BPF_FUNC_current_under_cgroup".
Tejun, Alexei?
lol I should have read the whole thread before replying twice. Sorry
about that. Yeah, if we can still rename it, let's do "under". It's
more intuitive and gives us the room to implement the real "in" test
if ever necessary in the future.
agree. Thanks for explaining 'in' vs 'under' terminology.
since we can still rename skb_in_cgroup we should do it.
and since that was my only nit for this patch.
Acked-by: Alexei Starovoitov <ast@kernel.org>
All 3 patches should go via net-next and to avoid conflicts 1/3 can be
in cgroup tree as well (if you think there will be conflicts).
We did that in the past with tip and net-next and it worked out well.
Daniel or Martin, do you mind preparing in->under renaming patch for net?
Thanks!
Hello, Alexei.
On Fri, Aug 12, 2016 at 08:21:21AM -0700, Alexei Starovoitov wrote:
quoted
lol I should have read the whole thread before replying twice. Sorry
about that. Yeah, if we can still rename it, let's do "under". It's
more intuitive and gives us the room to implement the real "in" test
if ever necessary in the future.
agree. Thanks for explaining 'in' vs 'under' terminology.
since we can still rename skb_in_cgroup we should do it.
Sounds good to me.
and since that was my only nit for this patch.
Acked-by: Alexei Starovoitov <ast@kernel.org>
FWIW,
Acked-by: Tejun Heo <tj@kernel.org>
All 3 patches should go via net-next and to avoid conflicts 1/3 can be
in cgroup tree as well (if you think there will be conflicts).
We did that in the past with tip and net-next and it worked out well.
Yeah, just route it through net-next. If other changes ever need it,
I'll include the commit in cgroup tree.
Thanks.
--
tejun