bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuyi Zhou <zhouchuyi@bytedance.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	Tejun Heo <tj@kernel.org>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RESEND PATCH bpf-next v6 8/8] selftests/bpf: Add tests for open-coded task and css iter
Date: Fri, 20 Oct 2023 22:46:48 +0800	[thread overview]
Message-ID: <272de0e9-539c-4d89-9b9c-0652b0826cdd@bytedance.com> (raw)
In-Reply-To: <CAADnVQKafk_junRyE=-FVAik4hjTRDtThymYGEL8hGTuYoOGpA@mail.gmail.com>



在 2023/10/20 08:03, Alexei Starovoitov 写道:
> On Tue, Oct 17, 2023 at 11:18 PM Chuyi Zhou <zhouchuyi@bytedance.com> wrote:
>>
>> +
>> +SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
>> +__failure __msg("css_task_iter is only allowed in bpf_lsm and bpf iter-s")
>> +int BPF_PROG(iter_css_task_for_each)
>> +{
>> +       u64 cg_id = bpf_get_current_cgroup_id();
>> +       struct cgroup *cgrp = bpf_cgroup_from_id(cg_id);
>> +       struct cgroup_subsys_state *css;
>> +       struct task_struct *task;
>> +
>> +       if (cgrp == NULL)
>> +               return 0;
>> +       css = &cgrp->self;
>> +
>> +       bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {
>> +
>> +       }
>> +       bpf_cgroup_release(cgrp);
>> +       return 0;
>> +}
> 
> I think we should relax allowlist in patch 2 further.
> Any sleepable is safe.
> Allowlist is needed to avoid dead locking on css_set_lock.
> Any lsm and any iter (even non-sleepable) and any sleepable
> seems to be safe.

Yes, I just try to read the corresponding code. IIUC, the key point here 
is we should not hold the css_set_lock before we invoking a BPF Prog 
which may use css_task iters.

1. For lsm hooks and task_iters, it would be clearly know from the code 
that we would not try to hold that lock.

2. For cgroup_iters, we will hold the cgroup_muetx before we enter the 
Prog and it's OK.(see __cgroup_procs_write())

3. For any sleepable progs, bpf_check_attach_target() would only allow 
them to attach some sepecifc hooks, currently, these hooks are OK.


Thanks for the suggestion again! I would do it.


  parent reply	other threads:[~2023-10-20 14:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18  6:17 [RESEND PATCH bpf-next v6 0/8] Add Open-coded task, css_task and css iters Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 1/8] cgroup: Prepare for using css_task_iter_*() in BPF Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 2/8] bpf: Introduce css_task open-coded iterator kfuncs Chuyi Zhou
2023-10-29 17:09   ` Guenter Roeck
2023-10-30  2:32     ` Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 3/8] bpf: Introduce task open coded " Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 4/8] bpf: Introduce css open-coded " Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 5/8] bpf: teach the verifier to enforce css_iter and task_iter in RCU CS Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 6/8] bpf: Let bpf_iter_task_new accept null task ptr Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 7/8] selftests/bpf: rename bpf_iter_task.c to bpf_iter_tasks.c Chuyi Zhou
2023-10-18  6:17 ` [RESEND PATCH bpf-next v6 8/8] selftests/bpf: Add tests for open-coded task and css iter Chuyi Zhou
2023-10-20  0:03   ` Alexei Starovoitov
2023-10-20  0:30     ` Chuyi Zhou
2023-10-20 14:46     ` Chuyi Zhou [this message]
2023-10-18  6:21 ` [RESEND PATCH bpf-next v6 0/8] Add Open-coded task, css_task and css iters Chuyi Zhou
2023-10-20  0:10 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=272de0e9-539c-4d89-9b9c-0652b0826cdd@bytedance.com \
    --to=zhouchuyi@bytedance.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).