From: Alexei Starovoitov <ast@plumgrid.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: "David S. Miller" <davem@davemloft.net>,
Ingo Molnar <mingo@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Wang Nan <wangnan0@huawei.com>, Li Zefan <lizefan@huawei.com>,
Daniel Wagner <daniel.wagner@bmw-carit.de>,
Daniel Borkmann <daniel@iogearbox.net>,
Linux API <linux-api@vger.kernel.org>,
Network Development <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next 1/3] bpf: introduce current->pid, tgid, uid, gid, comm accessors
Date: Fri, 12 Jun 2015 15:44:43 -0700 [thread overview]
Message-ID: <557B60DB.5030200@plumgrid.com> (raw)
In-Reply-To: <CALCETrUidQ9ig-xZrAFX8_==aVbDNKU-GfeYNMsT6uHugqSydg@mail.gmail.com>
On 6/12/15 3:08 PM, Andy Lutomirski wrote:
> On Fri, Jun 12, 2015 at 2:40 PM, Alexei Starovoitov <ast@plumgrid.com> wrote:
>> eBPF programs attached to kprobes need to filter based on
>> current->pid, uid and other fields, so introduce helper functions:
>>
>> u64 bpf_get_current_pid_tgid(void)
>> Return: current->tgid << 32 | current->pid
>>
>> u64 bpf_get_current_uid_gid(void)
>> Return: current_gid << 32 | current_uid
>
> How does this work wrt namespaces,
from_kuid(current_user_ns(), uid)
> and why the weird packing?
to minimize number of calls.
We've considered several alternatives.
1. 5 different helpers
Cons: every call adds performance overhead
2a: single helper that populates 'struct bpf_task_info'
and uses 'flags' with bit per field.
+struct bpf_task_info {
+ __u32 pid;
+ __u32 tgid;
+ __u32 uid;
+ __u32 gid;
+ char comm[16];
+};
bpf_get_current_task_info(task_info, size, flags)
bit 0 - fill in pid
bit 1 - fill in tgid
Pros: single helper
Cons: ugly to use and a lot of compares in the helper
itself (two compares for each field)
2b. single helper that populates 'struct bpf_task_info'
and uses 'size' to tell how many fields to fill in.
bpf_get_current_task_info(task_info, size);
+ if (size >= offsetof(struct bpf_task_info, pid) + sizeof(info->pid))
+ info->pid = task->pid;
+ if (size >= offsetof(struct bpf_task_info, tgid) +
sizeof(info->tgid))
+ info->tgid = task->tgid;
Pros: single call (with single compare per field).
Cons: still hard to use when only uid is needed.
These three helpers looked as the best balance between
performance and usability.
next prev parent reply other threads:[~2015-06-12 22:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-12 21:40 [PATCH net-next 0/3] bpf: share helpers between tracing and networking Alexei Starovoitov
[not found] ` <1434145226-17892-1-git-send-email-ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2015-06-12 21:40 ` [PATCH net-next 1/3] bpf: introduce current->pid, tgid, uid, gid, comm accessors Alexei Starovoitov
[not found] ` <1434145226-17892-2-git-send-email-ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2015-06-12 22:08 ` Andy Lutomirski
2015-06-12 22:44 ` Alexei Starovoitov [this message]
2015-06-12 22:54 ` Andy Lutomirski
2015-06-12 23:23 ` Alexei Starovoitov
2015-06-12 23:25 ` Andy Lutomirski
2015-06-12 23:38 ` Alexei Starovoitov
2015-06-12 23:47 ` Andy Lutomirski
2015-06-12 23:55 ` Alexei Starovoitov
2015-06-13 0:03 ` Andy Lutomirski
[not found] ` <CALCETrWYHkBtVr5D0zdrXswoH2gSXsxhtD23w6J7EP=HEwPt8A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-13 0:15 ` Alexei Starovoitov
2015-06-13 0:24 ` Andy Lutomirski
[not found] ` <CALCETrWUuoZz2XOox5FJJPAfFdBakLnY1d7LLP5Uxq9tqgkpzg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-13 0:26 ` Alexei Starovoitov
2015-06-12 21:40 ` [PATCH net-next 2/3] bpf: allow networking programs to use bpf_trace_printk() for debugging Alexei Starovoitov
2015-06-12 21:40 ` [PATCH net-next 3/3] bpf: let kprobe programs use bpf_get_smp_processor_id() helper Alexei Starovoitov
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=557B60DB.5030200@plumgrid.com \
--to=ast@plumgrid.com \
--cc=daniel.wagner@bmw-carit.de \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=wangnan0@huawei.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).