[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <88825625-283a-d521-3e7e-058784455577@bytedance.com>
Date: Wed, 13 Sep 2023 12:56:55 +0800
From: Chuyi Zhou <zhouchuyi@...edance.com>
To: Martin KaFai Lau <martin.lau@...ux.dev>
Cc: ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
martin.lau@...nel.org, tj@...nel.org, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org
Subject: Re: [PATCH bpf-next v2 2/6] bpf: Introduce css_task open-coded
iterator kfuncs
Hello Martin.
在 2023/9/13 03:57, Martin KaFai Lau 写道:
> On 9/12/23 12:01 AM, Chuyi Zhou wrote:
>> +__bpf_kfunc int bpf_iter_css_task_new(struct bpf_iter_css_task *it,
>> + struct cgroup_subsys_state *css, unsigned int flags)
>> +{
>> + struct bpf_iter_css_task_kern *kit = (void *)it;
>> +
>> + BUILD_BUG_ON(sizeof(struct bpf_iter_css_task_kern) !=
>> sizeof(struct bpf_iter_css_task));
>> + BUILD_BUG_ON(__alignof__(struct bpf_iter_css_task_kern) !=
>> + __alignof__(struct bpf_iter_css_task));
>> +
>> + switch (flags) {
>> + case CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED:
>> + case CSS_TASK_ITER_PROCS:
>> + case 0:
>> + break;
>> + default:
>> + return -EINVAL;
>> + }
>> +
>> + kit->css_it = kzalloc(sizeof(struct css_task_iter), GFP_KERNEL);
>> + if (!kit->css_it)
>> + return -ENOMEM;
>> + css_task_iter_start(css, flags, kit->css_it);
>> + return 0;
>> +}
>> +
>
>> +static bool check_css_task_iter_allowlist(struct bpf_verifier_env *env)
>> +{
>> + enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
>> +
>> + switch (prog_type) {
>> + case BPF_PROG_TYPE_LSM:
>
> This will allow the non-sleepable lsm prog to call
> bpf_iter_css_task_new. The above kzalloc(GFP_KERNEL) in
> bpf_iter_css_task_new should trigger a lockdep error in the lsm selftest
> in patch 6.
Thanks for your test. I missed the dmesg error since I did not set
CONFIG_LOCKDEP.
I think here we can use kzalloc(GFP_ATOMIC) to eliminate this error if
we want to use this iter in non-sleepable lsm prog. I just tested, it
works well.
>
>> + return true;
>> + case BPF_TRACE_ITER:
>> + return env->prog->aux->sleepable;
>> + default:
>> + return false;
>> + }
>> +}
>
Powered by blists - more mailing lists