From: Martin KaFai Lau <martin.lau@linux.dev>
To: "Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
"Jörn-Thorben Hinz" <j-t.hinz@alumni.tu-berlin.de>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Shuah Khan <shuah@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Deepa Dinamani <deepa.kernel@gmail.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next] bpf: Allow setting SO_TIMESTAMPING* with bpf_setsockopt()
Date: Wed, 17 Jan 2024 13:23:25 -0800 [thread overview]
Message-ID: <73235f05-8474-4341-b70b-34bd0e6dfac5@linux.dev> (raw)
In-Reply-To: <65a7f855821cc_6d500294d0@willemb.c.googlers.com.notmuch>
On 1/17/24 7:55 AM, Willem de Bruijn wrote:
> Martin KaFai Lau wrote:
>> On 1/16/24 7:17 AM, Willem de Bruijn wrote:
>>> Jörn-Thorben Hinz wrote:
>>>> A BPF application, e.g., a TCP congestion control, might benefit from or
>>>> even require precise (=hardware) packet timestamps. These timestamps are
>>>> already available through __sk_buff.hwtstamp and
>>>> bpf_sock_ops.skb_hwtstamp, but could not be requested: BPF programs were
>>>> not allowed to set SO_TIMESTAMPING* on sockets.
>>
>> This patch only uses the SOF_TIMESTAMPING_RX_HARDWARE in the selftest. How about
>> others? e.g. the SOF_TIMESTAMPING_TX_* that will affect the sk->sk_error_queue
>> which seems not good. If rx tstamp is useful, tx tstamp should be useful also?
>
> Good point. Or should not be allowed to be set from BPF.
>
> That significantly changes process behavior, e.g., by returning POLLERR.
>
>>>>
>>>> Enable BPF programs to actively request the generation of timestamps
>>>> from a stream socket. The also required ioctl(SIOCSHWTSTAMP) on the
>>>> network device must still be done separately, in user space.
>>
>> hmm... so both ioctl(SIOCSHWTSTAMP) of the netdevice and the
>> SOF_TIMESTAMPING_RX_HARDWARE of the sk must be done?
>>
>> I likely miss something. When skb is created in the driver rx path, the sk is
>> not known yet though. How the SOF_TIMESTAMPING_RX_HARDWARE of the sk affects the
>> skb_shinfo(skb)->hwtstamps?
>
> Indeed it does not seem to do anything in the datapath.
>
> Requesting SOF_TIMESTAMPING_RX_SOFTWARE will call net_enable_timestamp
> to start timestamping packets.
>
> But SOF_TIMESTAMPING_RX_HARDWARE does not so thing.
>
> Drivers do use it in ethtool get_ts_info to signal hardware
> capabilities. But those must be configured using the ioctl.
>
> It is there more for consistency with the other timestamp recording
> options, I suppose.
>
Thanks for the explanation on the SOF_TIMESTAMPING_RX_{HARDWARE,SOFTWARE}.
__sk_buff.hwtstamp should have the NIC rx timestamp then as long as the NIC is
ioctl configured.
Jorn, do you need RX_SOFTWARE? From looking at net_timestamp_set(), any socket
requested RX_SOFTWARE should be enough to get a skb->tstamp for all skbs. A
workaround is to manually create a socket and turn on RX_SOFTWARE.
It will still be nice to get proper bpf_setsockopt() support for RX_SOFTWARE but
it should be considered together with how SO_TIMESTAMPING_TX_* should work in
bpf prog considering the TX tstamping does not have a workaround solution like
RX_SOFTWARE.
It is probably cleaner to have a separate bit in sk->sk_tsflags for bpf such
that the bpf prog won't be affected by the userspace turning it on/off and it
won't change the userspace's expectation also (e.g. sk_error_queue and POLLERR).
The part that needs more thoughts in the tx tstamp is how to notify the bpf prog
to consume it. Potentially the kernel can involve a bpf prog to collect the tx
timestamp when the bpf bit in sk->sk_tsflags is set. An example on how TCP-CC is
using it will help to think of the approach here.
next prev parent reply other threads:[~2024-01-17 21:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 13:41 [PATCH bpf-next] bpf: Allow setting SO_TIMESTAMPING* with bpf_setsockopt() Jörn-Thorben Hinz
2024-01-16 15:17 ` Willem de Bruijn
2024-01-17 7:33 ` Martin KaFai Lau
2024-01-17 15:55 ` Willem de Bruijn
2024-01-17 21:23 ` Martin KaFai Lau [this message]
2024-01-18 14:53 ` Jörn-Thorben Hinz
2024-01-18 11:04 ` Jörn-Thorben Hinz
2024-01-18 14:46 ` Willem de Bruijn
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=73235f05-8474-4341-b70b-34bd0e6dfac5@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=deepa.kernel@gmail.com \
--cc=edumazet@google.com \
--cc=j-t.hinz@alumni.tu-berlin.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=willemdebruijn.kernel@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.