BPF List
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huawei.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	"quentin@isovalent.com" <quentin@isovalent.com>,
	"ast@kernel.org" <ast@kernel.org>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	"andrii@kernel.org" <andrii@kernel.org>,
	"martin.lau@linux.dev" <martin.lau@linux.dev>,
	"song@kernel.org" <song@kernel.org>,
	"john.fastabend@gmail.com" <john.fastabend@gmail.com>,
	"kpsingh@kernel.org" <kpsingh@kernel.org>,
	"sdf@google.com" <sdf@google.com>,
	"jevburton.kernel@gmail.com" <jevburton.kernel@gmail.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: RE: [RFC][PATCH v3 02/15] bpf: Set open_flags as last bpf_attr field for bpf_*_get_fd_by_id() funcs
Date: Mon, 1 Aug 2022 10:33:24 +0000	[thread overview]
Message-ID: <d3b9f2e1cb4a4fb5b5e47ea45df4be5c@huawei.com> (raw)
In-Reply-To: <CAEf4BzYmomMAEEQYH+fGQeH-_+4oxsFYc+qbZyf1DgF1E_CuSw@mail.gmail.com>

> From: Andrii Nakryiko [mailto:andrii.nakryiko@gmail.com]
> Sent: Friday, July 29, 2022 8:49 PM
> On Mon, Jul 25, 2022 at 12:10 AM Roberto Sassu <roberto.sassu@huawei.com>
> wrote:
> >
> > > From: Alexei Starovoitov [mailto:alexei.starovoitov@gmail.com]
> > > Sent: Friday, July 22, 2022 7:55 PM
> > > On Fri, Jul 22, 2022 at 07:18:23PM +0200, Roberto Sassu wrote:
> > > > The bpf() system call validates the bpf_attr structure received as
> > > > argument, and considers data until the last field, defined for each
> > > > operation. The remaing space must be filled with zeros.
> > > >
> > > > Currently, for bpf_*_get_fd_by_id() functions except
> bpf_map_get_fd_by_id()
> > > > the last field is *_id. Setting open_flags to BPF_F_RDONLY from user space
> > > > will result in bpf() rejecting the argument.
> > >
> > > The kernel is doing the right thing. It should not ignore fields.
> >
> > Exactly. As Andrii requested to add opts to all bpf_*_get_fd_by_id()
> > functions, the last field in the kernel needs to be updated accordingly.
> >
> 
> It's been a while ago so details are hazy. But the idea was that if we
> add _opts variant for bpf_map_get_fd_by_id() for interface consistency
> all the other bpf_*_get_fd_by_id() probably should get _opts variant
> and use the same opts struct. Right now kernel doesn't support
> specifying flags for non-maps and that's fine. I agree with Alexei
> that kernel shouldn't just ignore unrecognized field silently.
> 
> I think we still can add _opts() for all APIs, but user will need to
> know that non-map variants expect 0 as flags. For now. If we
> eventually add ability to specify flags for, say, links, then existing
> API will just work. One can see how this get_fd_by_id() can use
> read-only flags to return FDs that only support read-only operations
> on objects (e.g., fetching link info for links, dumping prog
> instructions for programs), but not modification operations (e.g.,
> updating prog for links, or whatever write operation could be for
> programs).
> 
> So I don't think there is contradiction here. We might choose to add
> bpf_map_get_fd_by_id_opts() only, but we probably still should use
> common struct name as if all bpf_*_get_fd_by_id_opts() exist.

Ok, understood.

Thanks

Roberto

  reply	other threads:[~2022-08-01 10:33 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 17:18 [RFC][PATCH v3 00/15] bpf: Per-operation map permissions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 01/15] bpftool: Attempt to link static libraries Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 02/15] bpf: Set open_flags as last bpf_attr field for bpf_*_get_fd_by_id() funcs Roberto Sassu
2022-07-22 17:55   ` Alexei Starovoitov
2022-07-25  7:10     ` Roberto Sassu
2022-07-29 18:49       ` Andrii Nakryiko
2022-08-01 10:33         ` Roberto Sassu [this message]
2022-08-25 12:21           ` Roberto Sassu
2022-08-25 22:06             ` Andrii Nakryiko
2022-07-22 17:18 ` [RFC][PATCH v3 03/15] libbpf: Introduce bpf_prog_get_fd_by_id_opts() Roberto Sassu
2022-07-29 18:51   ` Andrii Nakryiko
2022-07-22 17:18 ` [RFC][PATCH v3 04/15] libbpf: Introduce bpf_map_get_fd_by_id_opts() Roberto Sassu
2022-07-29 18:52   ` Andrii Nakryiko
2022-07-22 17:18 ` [RFC][PATCH v3 05/15] libbpf: Introduce bpf_btf_get_fd_by_id_opts() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 06/15] libbpf: Introduce bpf_link_get_fd_by_id_opts() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 07/15] libbpf: Introduce bpf_obj_get_opts() Roberto Sassu
2022-07-22 17:58   ` Stanislav Fomichev
2022-07-22 18:01     ` Alexei Starovoitov
2022-07-25  7:18       ` Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 08/15] bpftool: Add opts parameter to open_obj_pinned_any() and open_obj_pinned() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 09/15] bpftool: Add opts parameter to *_parse_fd() functions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 10/15] bpftool: Add opts parameter to *_parse_fds() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 11/15] bpftool: Add opts parameter to map_parse_fd_and_info() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 12/15] bpftool: Add opts parameter in struct_ops functions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 13/15] bpftool: Complete switch to bpf_*_get_fd_by_id_opts() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 14/15] bpftool: Adjust map permissions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 15/15] selftests/bpf: Add map access tests Roberto Sassu

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=d3b9f2e1cb4a4fb5b5e47ea45df4be5c@huawei.com \
    --to=roberto.sassu@huawei.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=daniel@iogearbox.net \
    --cc=jevburton.kernel@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=quentin@isovalent.com \
    --cc=sdf@google.com \
    --cc=song@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