BPF List
 help / color / mirror / Atom feed
From: sdf@google.com
To: Martin KaFai Lau <kafai@fb.com>
Cc: YiFei Zhu <zhuyifei@google.com>,
	YiFei Zhu <zhuyifei1999@gmail.com>,
	bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Mahesh Bandewar <maheshb@google.com>,
	Roman Gushchin <guro@fb.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>
Subject: Re: [PATCH v4 bpf-next 3/5] bpf: Make cgroup storages shared across attaches on the same cgroup
Date: Tue, 21 Jul 2020 15:56:36 -0700	[thread overview]
Message-ID: <20200721225636.GB184844@google.com> (raw)
In-Reply-To: <20200721224158.ylrgjjljlighny4f@kafai-mbp>

On 07/21, Martin KaFai Lau wrote:
> On Tue, Jul 21, 2020 at 04:20:00PM -0500, YiFei Zhu wrote:
> > On Tue, Jul 21, 2020 at 1:05 PM Martin KaFai Lau <kafai@fb.com> wrote:
> > > I quickly checked zero is actually BPF_CGROUP_INET_INGRESS instead
> > > of UNSPEC for attach_type.  It will be confusing on the syscall
> > > side. e.g. map dumping with key.attach_type == BPF_CGROUP_INET_INGRESS
> > > while the only cgroup program is actually attaching to  
> BPF_CGROUP_INET_EGRESS.
> > >
> > > I don't have a clean way out for this.  Adding a non-zero UNSPEC
> > > to "enum bpf_attach_type" seems wrong also.
> > > One possible way out is to allow the bpf_cgroup_storage_map
> > > to have a smaller key size (i.e. allow both sizeof(cgroup_inode_id)
> > > and the existing sizeof(struct bpf_cgroup_storage_key).  That
> > > will completely remove attach_type from the picture if the user
> > > specified to use sizeof(cgroup_inode_id) as the key_size.
> > > If sizeof(struct bpf_cgroup_storage_key) is specified, the attach_type
> > > is still used in cmp().
> > >
> > > The bpf_cgroup_storage_key_cmp() need to do cmp accordingly.
> > > Same changes is needed to lookup_elem, delete_elem, check_btf,  
> map_alloc...etc.
> >
> > ACK. Considering that the cgroup_inode_id is the first field of struct
> > bpf_cgroup_storage_key, I can probably just use this fact and directly
> > use the user-provided map key (after it's copied to kernel space) and
> > cast the pointer to a __u64 - or are there any architectures where the
> > first field is not at offset zero? If this is done then we can change
> > all the kernel internal APIs to use __u64 cgroup_inode_id, ignoring
> > the existence of the struct aside from the map creation (size checking
> > and BTF checking).
> Just to be clear.  The problem is the userspace is expecting
> the whole key (cgroup_id, attach_type) to be meaningful and
> we cannot stop supporting this existing key type now.
To step back a bit. I think in the commit message we mentioned that
attach_type is essentially (mostly) meaningless right now.
If I want to share cgroup storage between BPF_CGROUP_INET_INGRESS and
BPF_CGROUP_INET_EGRESS, the verifier will refuse to load those programs.
So doing lookup with different attach_type for the same storage
shouldn't really happen.

Except. There is one use-case where it does make sense. If you take
the same loaded program and attach it to both ingress and egress, each
one will get a separate storage copy. And only in this case
attach_type really has any meaning.

But since more and more attach types started to require
expected_attach_type, it seems that the case where the same
prog is attached to two different hooks should be almost
non-existent. That's why we've decided to go with
the idea of completely ignoring it.

So the question is: is it really worth it trying to preserve
that obscure use-case (and have more complex implementation) or we can
safely assume that nobody is doing that sort of thing in the wild (and
can simplify the internal logic a bit)?

  reply	other threads:[~2020-07-21 22:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 19:54 [PATCH v4 bpf-next 0/5] Make BPF CGROUP_STORAGE map usable by different programs at once YiFei Zhu
2020-07-20 19:54 ` [PATCH v4 bpf-next 1/5] selftests/bpf: Add test for CGROUP_STORAGE map on multiple attaches YiFei Zhu
2020-07-20 19:54 ` [PATCH v4 bpf-next 2/5] selftests/bpf: Test CGROUP_STORAGE map can't be used by multiple progs YiFei Zhu
2020-07-20 19:54 ` [PATCH v4 bpf-next 3/5] bpf: Make cgroup storages shared across attaches on the same cgroup YiFei Zhu
2020-07-21 18:05   ` Martin KaFai Lau
2020-07-21 21:20     ` YiFei Zhu
2020-07-21 22:41       ` Martin KaFai Lau
2020-07-21 22:56         ` sdf [this message]
2020-07-22  0:09           ` Martin KaFai Lau
2020-07-22  0:19             ` YiFei Zhu
2020-07-22  0:49               ` Martin KaFai Lau
2020-07-20 19:54 ` [PATCH v4 bpf-next 4/5] selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress YiFei Zhu
2020-07-20 19:54 ` [PATCH v4 bpf-next 5/5] Documentation/bpf: Document CGROUP_STORAGE map type YiFei Zhu

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=20200721225636.GB184844@google.com \
    --to=sdf@google.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=guro@fb.com \
    --cc=kafai@fb.com \
    --cc=maheshb@google.com \
    --cc=zhuyifei1999@gmail.com \
    --cc=zhuyifei@google.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