Re: [PATCH bpf-next 1/8] bpf: Invoke btf_struct_access() callback only for writes.

Andrii Nakryiko
2023-04-04T23:29:57Z

On Mon, Apr 3, 2023 at 9:50 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> From: Alexei Starovoitov <ast@kernel.org>
>
> Remove duplicated if (atype == BPF_READ) btf_struct_access() from
> btf_struct_access() callback and invoke it only for writes.

It would be nice to elaborate a bit why this is ok. As far as I can
tell, it's because custom btf_struct_access() callbacks are only
checking and overriding write accesses, delegating reads to generic
btf_struct_access(). Is that right? If so, can you please note it down
in the commit message?

Further, given btf_struct_access *callbacks* are now write-only, while
we still keep generic btf_struct_access for reads, should we
distinguish callback's write-only nature by renaming it to something
like "btf_struct_write_access"?

>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
> kernel/bpf/verifier.c | 2 +-
> net/bpf/bpf_dummy_struct_ops.c | 2 +-
> net/core/filter.c | 6 ------
> net/ipv4/bpf_tcp_ca.c | 3 ---
> 4 files changed, 2 insertions(+), 11 deletions(-)
> …