From: Yonghong Song <yhs@meta.com>
To: Donald Hunter <donald.hunter@gmail.com>,
David Vernet <void@manifault.com>
Cc: bpf@vger.kernel.org, linux-doc@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Jonathan Corbet <corbet@lwn.net>
Subject: Re: [PATCH bpf-next v3] docs/bpf: Add documentation for BPF_MAP_TYPE_SK_STORAGE
Date: Thu, 8 Dec 2022 09:19:48 -0800 [thread overview]
Message-ID: <36eec74e-684f-aa12-8249-1929282dae7b@meta.com> (raw)
In-Reply-To: <m2wn71yhtp.fsf@gmail.com>
On 12/8/22 8:35 AM, Donald Hunter wrote:
> Donald Hunter <donald.hunter@gmail.com> writes:
>
>> David Vernet <void@manifault.com> writes:
>>
>>> On Wed, Dec 07, 2022 at 10:27:21AM +0000, Donald Hunter wrote:
>>>> +
>>>> +This snippet shows how to retrieve socket-local storage in a BPF program:
>>>> +
>>>> +.. code-block:: c
>>>> +
>>>> + SEC("sockops")
>>>> + int _sockops(struct bpf_sock_ops *ctx)
>>>> + {
>>>> + struct my_storage *storage;
>>>> + struct bpf_sock *sk;
>>>> +
>>>> + sk = ctx->sk;
>>>> + if (!sk)
>>>> + return 1;
>>>
>>> Don't feel strongly about this one, but IMO it's nice for examples to
>>> illustrate code that's as close to real and pristine as possible. To
>>> that point, should this example perhaps be updated to return -ENOENT
>>> here, and -ENOMEM below?
>>
>> Will do.
>>
>
> After digging into this a bit more I notice that the sockops programs in
> tools/testing/selftests/bpf/progs mostly return 1 in all cases.
>
> I'm assuming that sockops programs should return valid values for
> some op types such as BPF_SOCK_OPS_TIMEOUT_INIT. Other than that I can't
> find a definitive list. Do you know if valid return values are
> enumerated anywhere, or do I need to dig some more?
It can return any integer.
static inline u32 tcp_timeout_init(struct sock *sk)
{
int timeout;
timeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT, 0, NULL);
if (timeout <= 0)
timeout = TCP_TIMEOUT_INIT;
return min_t(int, timeout, TCP_RTO_MAX);
}
In uapi bpf.h,
BPF_SOCK_OPS_TIMEOUT_INIT, /* Should return SYN-RTO value
to use or
* -1 if default value should
be used
*/
I think the above code is from selftests tcp_rtt.c. You can add a
reference to provide more context. If people are really interested,
they can go to selftest to find more.
>
>>>> +
>>>> + storage = bpf_sk_storage_get(&socket_storage, sk, 0,
>>>> + BPF_LOCAL_STORAGE_GET_F_CREATE);
>>>> + if (!storage)
>>>> + return 1;
>>>> +
>>>> + /* Use 'storage' here */
>>>
>>> Let's return 0 at the end to make the example program technically
>>> correct.
>>
>> Will do.
In this case, 'return 0' probably not correct. I suggest keep the
code as is to sync with selftests. Add a reference to selftest
for more reference.
>>
>>>> + }
>>>
>>> Thanks,
>>> David
prev parent reply other threads:[~2022-12-08 17:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 10:27 [PATCH bpf-next v3] docs/bpf: Add documentation for BPF_MAP_TYPE_SK_STORAGE Donald Hunter
2022-12-07 16:41 ` Yonghong Song
2022-12-07 21:13 ` David Vernet
2022-12-08 12:05 ` Donald Hunter
2022-12-08 16:35 ` Donald Hunter
2022-12-08 17:19 ` Yonghong Song [this message]
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=36eec74e-684f-aa12-8249-1929282dae7b@meta.com \
--to=yhs@meta.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=donald.hunter@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=void@manifault.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