From: Song Liu <songliubraving@fb.com>
To: Martin Lau <kafai@fb.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 3/6] bpf: btf: Add struct bpf_btf_info
Date: Tue, 8 May 2018 21:09:58 +0000 [thread overview]
Message-ID: <FC544AF8-A7AF-4546-9F66-93900CAB04E7@fb.com> (raw)
In-Reply-To: <20180504214955.1058805-4-kafai@fb.com>
> On May 4, 2018, at 2:49 PM, Martin KaFai Lau <kafai@fb.com> wrote:
>
> During BPF_OBJ_GET_INFO_BY_FD on a btf_fd, the current bpf_attr's
> info.info is directly filled with the BTF binary data. It is
> not extensible. In this case, we want to add BTF ID.
>
> This patch adds "struct bpf_btf_info" which has the BTF ID as
> one of its member. The BTF binary data itself is exposed through
> the "btf" and "btf_size" members.
>
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> Acked-by: Alexei Starovoitov <ast@fb.com>
> ---
> include/uapi/linux/bpf.h | 6 ++++++
> kernel/bpf/btf.c | 26 +++++++++++++++++++++-----
> kernel/bpf/syscall.c | 17 ++++++++++++++++-
> 3 files changed, 43 insertions(+), 6 deletions(-)
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 6106f23a9a8a..d615c777b573 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -2137,6 +2137,12 @@ struct bpf_map_info {
> __u32 btf_value_id;
> } __attribute__((aligned(8)));
>
> +struct bpf_btf_info {
> + __aligned_u64 btf;
> + __u32 btf_size;
> + __u32 id;
> +} __attribute__((aligned(8)));
> +
> /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
> * by user and intended to be used by socket (e.g. to bind to, depends on
> * attach attach type).
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 40950b6bf395..ded10ab47b8a 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -2114,12 +2114,28 @@ int btf_get_info_by_fd(const struct btf *btf,
> const union bpf_attr *attr,
> union bpf_attr __user *uattr)
> {
> - void __user *udata = u64_to_user_ptr(attr->info.info);
> - u32 copy_len = min_t(u32, btf->data_size,
> - attr->info.info_len);
> + struct bpf_btf_info __user *uinfo;
> + struct bpf_btf_info info = {};
> + u32 info_copy, btf_copy;
> + void __user *ubtf;
> + u32 uinfo_len;
>
> - if (copy_to_user(udata, btf->data, copy_len) ||
> - put_user(btf->data_size, &uattr->info.info_len))
> + uinfo = u64_to_user_ptr(attr->info.info);
> + uinfo_len = attr->info.info_len;
> +
> + info_copy = min_t(u32, uinfo_len, sizeof(info));
> + if (copy_from_user(&info, uinfo, info_copy))
> + return -EFAULT;
> +
> + info.id = btf->id;
> + ubtf = u64_to_user_ptr(info.btf);
> + btf_copy = min_t(u32, btf->data_size, info.btf_size);
> + if (copy_to_user(ubtf, btf->data, btf_copy))
> + return -EFAULT;
> + info.btf_size = btf->data_size;
> +
> + if (copy_to_user(uinfo, &info, info_copy) ||
> + put_user(info_copy, &uattr->info.info_len))
> return -EFAULT;
>
> return 0;
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 8b0a45d65454..d2895e3e5cbf 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -2019,6 +2019,21 @@ static int bpf_map_get_info_by_fd(struct bpf_map *map,
> return 0;
> }
>
> +static int bpf_btf_get_info_by_fd(struct btf *btf,
> + const union bpf_attr *attr,
> + union bpf_attr __user *uattr)
> +{
> + struct bpf_btf_info __user *uinfo = u64_to_user_ptr(attr->info.info);
> + u32 info_len = attr->info.info_len;
> + int err;
> +
> + err = check_uarg_tail_zero(uinfo, sizeof(*uinfo), info_len);
> + if (err)
> + return err;
> +
> + return btf_get_info_by_fd(btf, attr, uattr);
> +}
> +
> #define BPF_OBJ_GET_INFO_BY_FD_LAST_FIELD info.info
>
> static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,
> @@ -2042,7 +2057,7 @@ static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,
> err = bpf_map_get_info_by_fd(f.file->private_data, attr,
> uattr);
> else if (f.file->f_op == &btf_fops)
> - err = btf_get_info_by_fd(f.file->private_data, attr, uattr);
> + err = bpf_btf_get_info_by_fd(f.file->private_data, attr, uattr);
> else
> err = -EINVAL;
>
> --
> 2.9.5
>
Acked-by: Song Liu <songliubraving@fb.com>
next prev parent reply other threads:[~2018-05-08 21:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-04 21:49 [PATCH bpf-next 0/6] Introduce BTF ID Martin KaFai Lau
2018-05-04 21:49 ` [PATCH bpf-next 1/6] bpf: btf: Avoid WARN_ON when CONFIG_REFCOUNT_FULL=y Martin KaFai Lau
2018-05-08 21:09 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 2/6] bpf: btf: Introduce BTF ID Martin KaFai Lau
2018-05-08 21:09 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 3/6] bpf: btf: Add struct bpf_btf_info Martin KaFai Lau
2018-05-08 21:09 ` Song Liu [this message]
2018-05-04 21:49 ` [PATCH bpf-next 4/6] bpf: btf: Some test_btf clean up Martin KaFai Lau
2018-05-08 21:18 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 5/6] bpf: btf: Update tools/include/uapi/linux/btf.h with BTF ID Martin KaFai Lau
2018-05-08 21:18 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 6/6] bpf: btf: Tests for BPF_OBJ_GET_INFO_BY_FD and BPF_BTF_GET_FD_BY_ID Martin KaFai Lau
2018-05-08 21:18 ` Song Liu
2018-05-09 16:08 ` [PATCH bpf-next 0/6] Introduce BTF ID Daniel Borkmann
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=FC544AF8-A7AF-4546-9F66-93900CAB04E7@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=netdev@vger.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