From: Feng Zhou <zhoufeng.zf@bytedance.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Yosry Ahmed <yosryahmed@google.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
john fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@kernel.org>,
Dave Marchevsky <davemarchevsky@fb.com>,
Joanne Koong <joannekoong@fb.com>,
Geliang Tang <geliang.tang@suse.com>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Xiongchun Duan <duanxiongchun@bytedance.com>,
Muchun Song <songmuchun@bytedance.com>,
Dongdong Wang <wangdongdong.6@bytedance.com>,
Cong Wang <cong.wang@bytedance.com>,
Chengming Zhou <zhouchengming@bytedance.com>
Subject: Re: [External] Re: [PATCH bpf-next] bpf: add bpf_map_lookup_percpu_elem for percpu map
Date: Tue, 10 May 2022 13:52:52 +0800 [thread overview]
Message-ID: <e003aa4e-0837-b819-390e-72da65e50c67@bytedance.com> (raw)
In-Reply-To: <CAADnVQL+Vq5y47J++VCppti1728w3U0maxg9d4SqAtArY+h1yg@mail.gmail.com>
在 2022/5/10 上午11:15, Alexei Starovoitov 写道:
> On Mon, May 9, 2022 at 7:41 PM Feng Zhou <zhoufeng.zf@bytedance.com> wrote:
>> 在 2022/5/10 上午9:04, Yosry Ahmed 写道:
>>> On Mon, May 9, 2022 at 5:34 PM Andrii Nakryiko
>>> <andrii.nakryiko@gmail.com> wrote:
>>>> On Fri, May 6, 2022 at 7:49 PM Feng zhou <zhoufeng.zf@bytedance.com> wrote:
>>>>> From: Feng Zhou <zhoufeng.zf@bytedance.com>
>>>>>
>>>>> Trace some functions, such as enqueue_task_fair, need to access the
>>>>> corresponding cpu, not the current cpu, and bpf_map_lookup_elem percpu map
>>>>> cannot do it. So add bpf_map_lookup_percpu_elem to accomplish it for
>>>>> percpu_array_map, percpu_hash_map, lru_percpu_hash_map.
>>>>>
>>>>> The implementation method is relatively simple, refer to the implementation
>>>>> method of map_lookup_elem of percpu map, increase the parameters of cpu, and
>>>>> obtain it according to the specified cpu.
>>>>>
>>>> I don't think it's safe in general to access per-cpu data from another
>>>> CPU. I'd suggest just having either a ARRAY_OF_MAPS or adding CPU ID
>>>> as part of the key, if you need such a custom access pattern.
>>> I actually just sent an RFC patch series containing a similar patch
>>> for the exact same purpose. There are instances in the kernel where
>>> per-cpu data is accessed from other cpus (e.g.
>>> mem_cgroup_css_rstat_flush()). I believe, like any other variable,
>>> percpu data can be safe or not safe to access, based on the access
>>> pattern. It is up to the user to coordinate accesses to the variable.
>>>
>>> For example, in my use case, one of the accessors only reads percpu
>>> values of different cpus, so it should be safe. If a user accesses
>>> percpu data of another cpu without guaranteeing safety, they corrupt
>>> their own data. I understand that the main purpose of percpu data is
>>> lockless (and therefore fast) access, but in some use cases the user
>>> may be able to safely (and locklessly) access the data concurrently.
>>>
>> Regarding data security, I think users need to consider before using it,
>> such
>> as hook enqueue_task_fair, the function itself takes the rq lock of the
>> corresponding cpu, there is no problem, and the kernel only provides a
>> method,
>> like bpf_per_cpu_ptr and bpf_this_cpu_ptr, data security needs to be
>> guaranteed
>> by users in different scenarios, such as using bpf_spin_lock.
> Right. The new helper looks useful and is safe.
> Please add a selftest and respin.
Ok, will do. Thanks.
prev parent reply other threads:[~2022-05-10 5:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-07 2:48 [PATCH bpf-next] bpf: add bpf_map_lookup_percpu_elem for percpu map Feng zhou
2022-05-10 0:34 ` Andrii Nakryiko
2022-05-10 1:04 ` Yosry Ahmed
2022-05-10 2:41 ` [External] " Feng Zhou
2022-05-10 3:15 ` Alexei Starovoitov
2022-05-10 5:52 ` Feng Zhou [this message]
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=e003aa4e-0837-b819-390e-72da65e50c67@bytedance.com \
--to=zhoufeng.zf@bytedance.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=davemarchevsky@fb.com \
--cc=duanxiongchun@bytedance.com \
--cc=geliang.tang@suse.com \
--cc=joannekoong@fb.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=songmuchun@bytedance.com \
--cc=wangdongdong.6@bytedance.com \
--cc=yhs@fb.com \
--cc=yosryahmed@google.com \
--cc=zhouchengming@bytedance.com \
/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).