Skip to contentSkip to conversation

bpf: Allow bpf_current_task_under_cgroup in interrupt

PATCH Superseded Teng Qin 3 participants 4 messages Apr 28, 2018 – Apr 29, 2018

Subsystems (6)
lore
Share & tools
lore

Teng Qin

author
#0 lore raw

PATCH 1/1 bpf: Allow bpf_current_task_under_cgroup in interrupt

Currently, the bpf_current_task_under_cgroup helper has a check where if the BPF program is running in_interrupt(), it will return -EINVAL. This prevents the helper to be used in many useful scenarios, particularly BPF programs attached to Perf Events.

This commit removes the check. Tested a few NMI (Perf Event) and some softirq context, the helper returns the correct result.

---
 kernel/trace/bpf_trace.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/bpf_trace.c +0 -2
index 56ba0f2..f94890c 100644
@@ -474,8 +474,6 @@ BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)
 	struct bpf_array *array = container_of(map, struct bpf_array, map);
 	struct cgroup *cgrp;
 
-	if (unlikely(in_interrupt()))
-		return -EINVAL;
 	if (unlikely(idx >= array->map.max_entries))
 		return -E2BIG;
 
Signature · 1 line
2.9.5
#1 lore raw
Quoted 16 lines · Teng Qin

Currently, the bpf_current_task_under_cgroup helper has a check where if the BPF program is running in_interrupt(), it will return -EINVAL. This prevents the helper to be used in many useful scenarios, particularly BPF programs attached to Perf Events.

This commit removes the check. Tested a few NMI (Perf Event) and some softirq context, the helper returns the correct result.

---
 kernel/trace/bpf_trace.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/bpf_trace.c +0 -0
index 56ba0f2..f94890c 100644

kernel/trace/bpf_trace.c BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx) · line 479

Quoted 8 lines
kernel/trace/bpf_trace.c +0 -2
@@ -474,8 +474,6 @@ BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)
 	struct bpf_array *array = container_of(map, struct bpf_array, map);
 	struct cgroup *cgrp;
 
-	if (unlikely(in_interrupt()))
-		return -EINVAL;
 	if (unlikely(idx >= array->map.max_entries))
 		return -E2BIG;
 

looks good, but SOB is missing. Please respin.

author
#2 lore raw

PATCH v2 1/1 bpf: Allow bpf_current_task_under_cgroup in interrupt

In reply to Teng Qin

Currently, the bpf_current_task_under_cgroup helper has a check where if the BPF program is running in_interrupt(), it will return -EINVAL. This prevents the helper to be used in many useful scenarios, particularly BPF programs attached to Perf Events.

This commit removes the check. Tested a few NMI (Perf Event) and some softirq context, the helper returns the correct result.

---
 kernel/trace/bpf_trace.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/bpf_trace.c +0 -2
index 56ba0f2..f94890c 100644
@@ -474,8 +474,6 @@ BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)
 	struct bpf_array *array = container_of(map, struct bpf_array, map);
 	struct cgroup *cgrp;
 
-	if (unlikely(in_interrupt()))
-		return -EINVAL;
 	if (unlikely(idx >= array->map.max_entries))
 		return -E2BIG;
 
Signature · 1 line
2.9.5
#3 lore raw
Quoted 9 lines · Teng Qin

Currently, the bpf_current_task_under_cgroup helper has a check where if the BPF program is running in_interrupt(), it will return -EINVAL. This prevents the helper to be used in many useful scenarios, particularly BPF programs attached to Perf Events.

This commit removes the check. Tested a few NMI (Perf Event) and some softirq context, the helper returns the correct result.

Applied, Thanks Teng.