From: Feng Zhou <zhoufeng.zf@bytedance.com>
To: Yosry Ahmed <yosryahmed@google.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: 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>,
duanxiongchun@bytedance.com,
Muchun Song <songmuchun@bytedance.com>,
Dongdong Wang <wangdongdong.6@bytedance.com>,
Cong Wang <cong.wang@bytedance.com>,
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 10:41:44 +0800 [thread overview]
Message-ID: <d20aef2a-273a-3183-0923-bde9657d4418@bytedance.com> (raw)
In-Reply-To: <CAJD7tkbd8qA-4goUCVW6Tf0xGpj2OSBXncpWhrWFn5y010oBMw@mail.gmail.com>
在 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.
>>> Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
>>> ---
>>> include/linux/bpf.h | 2 ++
>>> include/uapi/linux/bpf.h | 9 +++++++++
>>> kernel/bpf/arraymap.c | 15 +++++++++++++++
>>> kernel/bpf/core.c | 1 +
>>> kernel/bpf/hashtab.c | 32 ++++++++++++++++++++++++++++++++
>>> kernel/bpf/helpers.c | 18 ++++++++++++++++++
>>> kernel/bpf/verifier.c | 17 +++++++++++++++--
>>> kernel/trace/bpf_trace.c | 2 ++
>>> tools/include/uapi/linux/bpf.h | 9 +++++++++
>>> 9 files changed, 103 insertions(+), 2 deletions(-)
>>>
>> [...]
next prev parent reply other threads:[~2022-05-10 2:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-07 2:48 Feng zhou
2022-05-10 0:34 ` Andrii Nakryiko
2022-05-10 1:04 ` Yosry Ahmed
2022-05-10 2:41 ` Feng Zhou [this message]
2022-05-10 3:15 ` [External] " Alexei Starovoitov
2022-05-10 5:52 ` Feng Zhou
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=d20aef2a-273a-3183-0923-bde9657d4418@bytedance.com \
--to=zhoufeng.zf@bytedance.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
all inboxes | Powered by JetHome®