mbox series

[net-next,v6,0/3] Add option to provide OPT_ID value via cmsg

Message ID 20241001125716.2832769-1-vadfed@meta.com (mailing list archive)
Headers show
Series Add option to provide OPT_ID value via cmsg | expand

Message

Vadim Fedorenko Oct. 1, 2024, 12:57 p.m. UTC
SOF_TIMESTAMPING_OPT_ID socket option flag gives a way to correlate TX
timestamps and packets sent via socket. Unfortunately, there is no way
to reliably predict socket timestamp ID value in case of error returned
by sendmsg. For UDP sockets it's impossible because of lockless
nature of UDP transmit, several threads may send packets in parallel. In
case of RAW sockets MSG_MORE option makes things complicated. More
details are in the conversation [1].
This patch adds new control message type to give user-space
software an opportunity to control the mapping between packets and
values by providing ID with each sendmsg.

The first patch in the series adds all needed definitions and implements
the function for UDP sockets. The explicit check of socket's type is not
added because subsequent patches in the series will add support for other
types of sockets. The documentation is also included into the first
patch.

Patch 2/4 adds support for TCP sockets. This part is simple and straight
forward.

Patch 3/4 adds support for RAW sockets. It's a bit tricky because
sock_tx_timestamp functions has to be refactored to receive full socket
cookie information to fill in ID. The commit b534dc46c8ae ("net_tstamp:
add SOF_TIMESTAMPING_OPT_ID_TCP") did the conversion of sk_tsflags to
u32 but sock_tx_timestamp functions were not converted and still receive
16b flags. It wasn't a problem because SOF_TIMESTAMPING_OPT_ID_TCP was
not checked in these functions, that's why no backporting is needed.

Patch 4/4 adds selftests for new feature.

Changelog:
v5 -> v6:
- rebase on top of net-next
v4 -> v5:
- replace BUILD_BUG_ON_MSG with simple BUILD_BUG_ON
- adjust comment about added flag and check
- remove redefinition of flag from selftests
- adjust tcp_tx_timestamp() to use sock cookie 
v3 -> v4:
- remove static_assert from UAPI header
- add BUILD_BUG_ON_MSG with some explanation
- use SOF_TIMESTAMPING_OPT_ID flag in ipv4/ipv6 UDP case
- move ts_opt_id initialization under flag check to avoid extra
  assignment in the hot path
v2 -> v3:
- remove SOF_TIMESTAMPING_OPT_ID_CMSG UAPI value and use kernel-internal
  SOCKCM_FLAG_TS_OPT_ID which uses the highest bit of tsflags.
- add support for TCP and RAW sockets
v1 -> v2:
- add more selftests
- add documentation for the feature
- refactor UDP send function
RFC -> v1:
- add selftests
- add SOF_TIMESTAMPING_OPT_ID_CMSG to signal of custom ID provided by
	user-space instead of reserving value of 0 for this.

[1] https://lore.kernel.org/netdev/CALCETrU0jB+kg0mhV6A8mrHfTE1D1pr1SD_B9Eaa9aDPfgHdtA@mail.gmail.com/

Vadim Fedorenko (3):
  net_tstamp: add SCM_TS_OPT_ID to provide OPT_ID in control message
  net_tstamp: add SCM_TS_OPT_ID for RAW sockets
  selftests: txtimestamp: add SCM_TS_OPT_ID test

 Documentation/networking/timestamping.rst  | 14 +++++++
 arch/alpha/include/uapi/asm/socket.h       |  2 +
 arch/mips/include/uapi/asm/socket.h        |  2 +
 arch/parisc/include/uapi/asm/socket.h      |  2 +
 arch/sparc/include/uapi/asm/socket.h       |  2 +
 include/net/inet_sock.h                    |  4 +-
 include/net/sock.h                         | 34 ++++++++++++-----
 include/uapi/asm-generic/socket.h          |  2 +
 net/can/raw.c                              |  2 +-
 net/core/sock.c                            | 13 +++++++
 net/ipv4/ip_output.c                       | 21 ++++++++---
 net/ipv4/raw.c                             |  2 +-
 net/ipv4/tcp.c                             |  7 ++--
 net/ipv6/ip6_output.c                      | 22 +++++++----
 net/ipv6/raw.c                             |  2 +-
 net/packet/af_packet.c                     |  6 +--
 net/socket.c                               |  2 +-
 tools/include/uapi/asm-generic/socket.h    |  2 +
 tools/testing/selftests/net/txtimestamp.c  | 44 +++++++++++++++++-----
 tools/testing/selftests/net/txtimestamp.sh | 12 +++---
 20 files changed, 149 insertions(+), 48 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Oct. 4, 2024, 7:20 p.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 1 Oct 2024 05:57:13 -0700 you wrote:
> SOF_TIMESTAMPING_OPT_ID socket option flag gives a way to correlate TX
> timestamps and packets sent via socket. Unfortunately, there is no way
> to reliably predict socket timestamp ID value in case of error returned
> by sendmsg. For UDP sockets it's impossible because of lockless
> nature of UDP transmit, several threads may send packets in parallel. In
> case of RAW sockets MSG_MORE option makes things complicated. More
> details are in the conversation [1].
> This patch adds new control message type to give user-space
> software an opportunity to control the mapping between packets and
> values by providing ID with each sendmsg.
> 
> [...]

Here is the summary with links:
  - [net-next,v6,1/3] net_tstamp: add SCM_TS_OPT_ID to provide OPT_ID in control message
    https://git.kernel.org/netdev/net-next/c/4aecca4c7680
  - [net-next,v6,2/3] net_tstamp: add SCM_TS_OPT_ID for RAW sockets
    https://git.kernel.org/netdev/net-next/c/822b5bc6db55
  - [net-next,v6,3/3] selftests: txtimestamp: add SCM_TS_OPT_ID test
    https://git.kernel.org/netdev/net-next/c/a89568e9be75

You are awesome, thank you!