Re: [PATCH v3 bpf-next 05/11] cgroup: Add a new helper for cgroup1 hierarchy

Tejun Heo
2023-11-09T21:27:20Z

Hello,

On Sun, Oct 29, 2023 at 06:14:32AM +0000, Yafang Shao wrote:
> +/**
> + * task_get_cgroup1 - Acquires the associated cgroup of a task within a
> + * specific cgroup1 hierarchy. The cgroup1 hierarchy is identified by its
> + * hierarchy ID.
> + * @tsk: The target task
> + * @hierarchy_id: The ID of a cgroup1 hierarchy
> + *
> + * On success, the cgroup is returned. On failure, ERR_PTR is returned.
> + * We limit it to cgroup1 only.
> + */
> +struct cgroup *task_get_cgroup1(struct task_struct *tsk, int hierarchy_id)
> +{
> + struct cgroup *cgrp = ERR_PTR(-ENOENT);
> + struct cgroup_root *root;
> +
> + rcu_read_lock();
> + for_each_root(root) {
> + /* cgroup1 only*/
> + if (root == &cgrp_dfl_root)
> + continue;
> + if (root->hierarchy_id != hierarchy_id)
> + continue;
> + spin_lock_irq(&css_set_lock);
> + cgrp = task_cgroup_from_root(tsk, root);
> + if (!cgrp || !cgroup_tryget(cgrp))
> + cgrp = ERR_PTR(-ENOENT);
> + spin_unlock_irq(&css_set_lock);

As Hou suggested, please use irqsave/restore. Other than that, looks fine to
me.

Thanks.

--
tejun