Re: [PATCH bpf-next 3/4] bpf: Add new kfunc bpf_cpumask_set_from_pid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

On Fri, Dec 22, 2023 at 11:31:01AM +0000, Yafang Shao wrote:
> Introducing a new kfunc: bpf_cpumask_set_from_pid. This function serves the
> purpose of retrieving the cpumask associated with a specific PID. Its
> utility is particularly evident within container environments. For
> instance, it allows for extracting the cpuset of a container using the
> init task within it.
> 
> Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
...
> +__bpf_kfunc bool bpf_cpumask_set_from_pid(struct cpumask *cpumask, u32 pid)
> +{
> +	struct task_struct *task;
> +
> +	if (!cpumask)
> +		return false;
> +
> +	task = get_pid_task(find_vpid(pid), PIDTYPE_PID);
> +	if (!task)
> +		return false;
> +
> +	cpumask_copy(cpumask, task->cpus_ptr);
> +	put_task_struct(task);
> +	return true;
> +}

This seems awfully specific. Why is this necessary? Shouldn't the BPF prog
get the task and bpf_cpumask_copy() its ->cpus_ptr instead?

Thanks.

-- 
tejun




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux