cgroup: Prepare for using css_task_iter_*() in BPF
JIRA: https://issues.redhat.com/browse/RHEL-23643 commit 6da88306811b40a207c94c9da9faf07bdb20776e Author: Chuyi Zhou <zhouchuyi@bytedance.com> Date: Wed Oct 18 14:17:39 2023 +0800 cgroup: Prepare for using css_task_iter_*() in BPF This patch makes some preparations for using css_task_iter_*() in BPF Program. 1. Flags CSS_TASK_ITER_* are #define-s and it's not easy for bpf prog to use them. Convert them to enum so bpf prog can take them from vmlinux.h. 2. In the next patch we will add css_task_iter_*() in common kfuncs which is not safe. Since css_task_iter_*() does spin_unlock_irq() which might screw up irq flags depending on the context where bpf prog is running. So we should use irqsave/irqrestore here and the switching is harmless. Suggested-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20231018061746.111364-2-zhouchuyi@bytedance.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Artem Savkov <asavkov@redhat.com>
This commit is contained in:
parent
a80e4af486
commit
695a88af02
|
@ -40,13 +40,11 @@ struct kernel_clone_args;
|
||||||
#define CGROUP_WEIGHT_DFL 100
|
#define CGROUP_WEIGHT_DFL 100
|
||||||
#define CGROUP_WEIGHT_MAX 10000
|
#define CGROUP_WEIGHT_MAX 10000
|
||||||
|
|
||||||
/* walk only threadgroup leaders */
|
enum {
|
||||||
#define CSS_TASK_ITER_PROCS (1U << 0)
|
CSS_TASK_ITER_PROCS = (1U << 0), /* walk only threadgroup leaders */
|
||||||
/* walk all threaded css_sets in the domain */
|
CSS_TASK_ITER_THREADED = (1U << 1), /* walk all threaded css_sets in the domain */
|
||||||
#define CSS_TASK_ITER_THREADED (1U << 1)
|
CSS_TASK_ITER_SKIPPED = (1U << 16), /* internal flags */
|
||||||
|
};
|
||||||
/* internal flags */
|
|
||||||
#define CSS_TASK_ITER_SKIPPED (1U << 16)
|
|
||||||
|
|
||||||
/* a css_task_iter should be treated as an opaque object */
|
/* a css_task_iter should be treated as an opaque object */
|
||||||
struct css_task_iter {
|
struct css_task_iter {
|
||||||
|
|
|
@ -4841,9 +4841,11 @@ repeat:
|
||||||
void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
|
void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
|
||||||
struct css_task_iter *it)
|
struct css_task_iter *it)
|
||||||
{
|
{
|
||||||
|
unsigned long irqflags;
|
||||||
|
|
||||||
memset(it, 0, sizeof(*it));
|
memset(it, 0, sizeof(*it));
|
||||||
|
|
||||||
spin_lock_irq(&css_set_lock);
|
spin_lock_irqsave(&css_set_lock, irqflags);
|
||||||
|
|
||||||
it->ss = css->ss;
|
it->ss = css->ss;
|
||||||
it->flags = flags;
|
it->flags = flags;
|
||||||
|
@ -4857,7 +4859,7 @@ void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
|
||||||
|
|
||||||
css_task_iter_advance(it);
|
css_task_iter_advance(it);
|
||||||
|
|
||||||
spin_unlock_irq(&css_set_lock);
|
spin_unlock_irqrestore(&css_set_lock, irqflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4870,12 +4872,14 @@ void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
|
||||||
*/
|
*/
|
||||||
struct task_struct *css_task_iter_next(struct css_task_iter *it)
|
struct task_struct *css_task_iter_next(struct css_task_iter *it)
|
||||||
{
|
{
|
||||||
|
unsigned long irqflags;
|
||||||
|
|
||||||
if (it->cur_task) {
|
if (it->cur_task) {
|
||||||
put_task_struct(it->cur_task);
|
put_task_struct(it->cur_task);
|
||||||
it->cur_task = NULL;
|
it->cur_task = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_irq(&css_set_lock);
|
spin_lock_irqsave(&css_set_lock, irqflags);
|
||||||
|
|
||||||
/* @it may be half-advanced by skips, finish advancing */
|
/* @it may be half-advanced by skips, finish advancing */
|
||||||
if (it->flags & CSS_TASK_ITER_SKIPPED)
|
if (it->flags & CSS_TASK_ITER_SKIPPED)
|
||||||
|
@ -4888,7 +4892,7 @@ struct task_struct *css_task_iter_next(struct css_task_iter *it)
|
||||||
css_task_iter_advance(it);
|
css_task_iter_advance(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irq(&css_set_lock);
|
spin_unlock_irqrestore(&css_set_lock, irqflags);
|
||||||
|
|
||||||
return it->cur_task;
|
return it->cur_task;
|
||||||
}
|
}
|
||||||
|
@ -4901,11 +4905,13 @@ struct task_struct *css_task_iter_next(struct css_task_iter *it)
|
||||||
*/
|
*/
|
||||||
void css_task_iter_end(struct css_task_iter *it)
|
void css_task_iter_end(struct css_task_iter *it)
|
||||||
{
|
{
|
||||||
|
unsigned long irqflags;
|
||||||
|
|
||||||
if (it->cur_cset) {
|
if (it->cur_cset) {
|
||||||
spin_lock_irq(&css_set_lock);
|
spin_lock_irqsave(&css_set_lock, irqflags);
|
||||||
list_del(&it->iters_node);
|
list_del(&it->iters_node);
|
||||||
put_css_set_locked(it->cur_cset);
|
put_css_set_locked(it->cur_cset);
|
||||||
spin_unlock_irq(&css_set_lock);
|
spin_unlock_irqrestore(&css_set_lock, irqflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it->cur_dcset)
|
if (it->cur_dcset)
|
||||||
|
|
Loading…
Reference in New Issue