2022-04-06 22:09:34

by Vladimir Oltean

[permalink] [raw]
Subject: [PATCH stable 0/3] SOF_TIMESTAMPING_OPT_ID backport to 4.14 and 4.19

As discussed with Willem here:
https://lore.kernel.org/netdev/CA+FuTSdQ57O6RWj_Lenmu_Vd3NEX9xMzMYkB0C3rKMzGgcPc6A@mail.gmail.com/T/

the kernel silently doesn't act upon the SOF_TIMESTAMPING_OPT_ID socket
option in several cases on older kernels, yet user space has no way to
find out about this, practically resulting in broken functionality.

This patch set backports the support towards linux-4.14.y and linux-4.19.y,
which fixes the issue described above by simply making the kernel act
upon SOF_TIMESTAMPING_OPT_ID as expected.

Testing was done with the most recent (not the vintage-correct one)
kselftest script at:
tools/testing/selftests/networking/timestamping/txtimestamp.sh
with the message "OK. All tests passed".

I tried to backport the changes to linux-4.9.y as well, but something
apparently unrelated is broken there, and I didn't investigate further
so I'm not targeting that stable branch:

./txtimestamp.sh
protocol: TCP
payload: 10
server port: 9000

family: INET
test SND
USR: 1581090724 s 856088 us (seq=0, len=0)
./txtimestamp: poll

Willem de Bruijn (2):
ipv6: add missing tx timestamping on IPPROTO_RAW
net: add missing SOF_TIMESTAMPING_OPT_ID support

include/net/sock.h | 25 +++++++++++++++++++++----
net/can/raw.c | 2 +-
net/ipv4/raw.c | 2 +-
net/ipv6/raw.c | 7 +++++--
net/packet/af_packet.c | 6 +++---
5 files changed, 31 insertions(+), 11 deletions(-)

--
2.25.1


2022-04-06 23:46:40

by Vladimir Oltean

[permalink] [raw]
Subject: [PATCH 4.14 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW

From: Willem de Bruijn <[email protected]>

[ Upstream commit fbfb2321e950918b430e7225546296b2dcadf725 ]

Raw sockets support tx timestamping, but one case is missing.

IPPROTO_RAW takes a separate packet construction path. raw_send_hdrinc
has an explicit call to sock_tx_timestamp, but rawv6_send_hdrinc does
not. Add it.

Fixes: 11878b40ed5c ("net-timestamp: SOCK_RAW and PING timestamping")
Signed-off-by: Willem de Bruijn <[email protected]>
Acked-by: Soheil Hassas Yeganeh <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Vladimir Oltean <[email protected]>
---
net/ipv6/raw.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 3d9d20074203..f0d8b7e9a685 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -622,7 +622,7 @@ static int rawv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,

static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
struct flowi6 *fl6, struct dst_entry **dstp,
- unsigned int flags)
+ unsigned int flags, const struct sockcm_cookie *sockc)
{
struct ipv6_pinfo *np = inet6_sk(sk);
struct net *net = sock_net(sk);
@@ -659,6 +659,8 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,

skb->ip_summed = CHECKSUM_NONE;

+ sock_tx_timestamp(sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+
if (flags & MSG_CONFIRM)
skb_set_dst_pending_confirm(skb, 1);

@@ -945,7 +947,8 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)

back_from_confirm:
if (hdrincl)
- err = rawv6_send_hdrinc(sk, msg, len, &fl6, &dst, msg->msg_flags);
+ err = rawv6_send_hdrinc(sk, msg, len, &fl6, &dst,
+ msg->msg_flags, &sockc);
else {
ipc6.opt = opt;
lock_sock(sk);
--
2.25.1

2022-04-07 01:15:25

by Willem de Bruijn

[permalink] [raw]
Subject: Re: [PATCH 4.14 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW

On Wed, Apr 6, 2022 at 3:30 PM Vladimir Oltean <[email protected]> wrote:
>
> From: Willem de Bruijn <[email protected]>
>
> [ Upstream commit fbfb2321e950918b430e7225546296b2dcadf725 ]
>
> Raw sockets support tx timestamping, but one case is missing.
>
> IPPROTO_RAW takes a separate packet construction path. raw_send_hdrinc
> has an explicit call to sock_tx_timestamp, but rawv6_send_hdrinc does
> not. Add it.
>
> Fixes: 11878b40ed5c ("net-timestamp: SOCK_RAW and PING timestamping")
> Signed-off-by: Willem de Bruijn <[email protected]>
> Acked-by: Soheil Hassas Yeganeh <[email protected]>
> Signed-off-by: David S. Miller <[email protected]>
> Signed-off-by: Vladimir Oltean <[email protected]>

For 4.14.y cherry-pick:

Acked-by: Willem de Bruijn <[email protected]>

Might be good to point out that this is not only a clean cherry-pick
of the one-line patch, but has to include part of commit a818f75e311c
("net: ipv6: Hook into time based transmission") to plumb the
sockcm_cookie. The rest of that patch is not a candidate for stable,
so LGTM.

2022-04-07 01:21:50

by Vladimir Oltean

[permalink] [raw]
Subject: [PATCH 4.14 2/2] net: add missing SOF_TIMESTAMPING_OPT_ID support

From: Willem de Bruijn <[email protected]>

[ Upstream commit 8f932f762e7928d250e21006b00ff9b7718b0a64 ]

SOF_TIMESTAMPING_OPT_ID is supported on TCP, UDP and RAW sockets.
But it was missing on RAW with IPPROTO_IP, PF_PACKET and CAN.

Add skb_setup_tx_timestamp that configures both tx_flags and tskey
for these paths that do not need corking or use bytestream keys.

Fixes: 09c2d251b707 ("net-timestamp: add key to disambiguate concurrent datagrams")
Signed-off-by: Willem de Bruijn <[email protected]>
Acked-by: Soheil Hassas Yeganeh <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Vladimir Oltean <[email protected]>
---
include/net/sock.h | 25 +++++++++++++++++++++----
net/can/raw.c | 2 +-
net/ipv4/raw.c | 2 +-
net/ipv6/raw.c | 2 +-
net/packet/af_packet.c | 6 +++---
5 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index f72753391acc..f729ccfe756a 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2311,22 +2311,39 @@ static inline void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags);

/**
- * sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
+ * _sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
* @sk: socket sending this packet
* @tsflags: timestamping flags to use
* @tx_flags: completed with instructions for time stamping
+ * @tskey: filled in with next sk_tskey (not for TCP, which uses seqno)
*
* Note: callers should take care of initial ``*tx_flags`` value (usually 0)
*/
-static inline void sock_tx_timestamp(const struct sock *sk, __u16 tsflags,
- __u8 *tx_flags)
+static inline void _sock_tx_timestamp(struct sock *sk, __u16 tsflags,
+ __u8 *tx_flags, __u32 *tskey)
{
- if (unlikely(tsflags))
+ if (unlikely(tsflags)) {
__sock_tx_timestamp(tsflags, tx_flags);
+ if (tsflags & SOF_TIMESTAMPING_OPT_ID && tskey &&
+ tsflags & SOF_TIMESTAMPING_TX_RECORD_MASK)
+ *tskey = sk->sk_tskey++;
+ }
if (unlikely(sock_flag(sk, SOCK_WIFI_STATUS)))
*tx_flags |= SKBTX_WIFI_STATUS;
}

+static inline void sock_tx_timestamp(struct sock *sk, __u16 tsflags,
+ __u8 *tx_flags)
+{
+ _sock_tx_timestamp(sk, tsflags, tx_flags, NULL);
+}
+
+static inline void skb_setup_tx_timestamp(struct sk_buff *skb, __u16 tsflags)
+{
+ _sock_tx_timestamp(skb->sk, tsflags, &skb_shinfo(skb)->tx_flags,
+ &skb_shinfo(skb)->tskey);
+}
+
/**
* sk_eat_skb - Release a skb if it is no longer needed
* @sk: socket to eat this skb from
diff --git a/net/can/raw.c b/net/can/raw.c
index 2a987a6ea6d7..bda2113a8529 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -814,7 +814,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
if (err < 0)
goto free_skb;

- sock_tx_timestamp(sk, sk->sk_tsflags, &skb_shinfo(skb)->tx_flags);
+ skb_setup_tx_timestamp(skb, sk->sk_tsflags);

skb->dev = dev;
skb->sk = sk;
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 9c4b2c0dc68a..19a6ec2adc6c 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -390,7 +390,7 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,

skb->ip_summed = CHECKSUM_NONE;

- sock_tx_timestamp(sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+ skb_setup_tx_timestamp(skb, sockc->tsflags);

if (flags & MSG_CONFIRM)
skb_set_dst_pending_confirm(skb, 1);
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index f0d8b7e9a685..e8926ebfe74c 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -659,7 +659,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,

skb->ip_summed = CHECKSUM_NONE;

- sock_tx_timestamp(sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+ skb_setup_tx_timestamp(skb, sockc->tsflags);

if (flags & MSG_CONFIRM)
skb_set_dst_pending_confirm(skb, 1);
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 92394595920c..b0dd17d1992e 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2017,7 +2017,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
skb->priority = sk->sk_priority;
skb->mark = sk->sk_mark;

- sock_tx_timestamp(sk, sockc.tsflags, &skb_shinfo(skb)->tx_flags);
+ skb_setup_tx_timestamp(skb, sockc.tsflags);

if (unlikely(extra_len == 4))
skb->no_fcs = 1;
@@ -2539,7 +2539,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
skb->dev = dev;
skb->priority = po->sk.sk_priority;
skb->mark = po->sk.sk_mark;
- sock_tx_timestamp(&po->sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+ skb_setup_tx_timestamp(skb, sockc->tsflags);
skb_zcopy_set_nouarg(skb, ph.raw);

skb_reserve(skb, hlen);
@@ -3002,7 +3002,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
goto out_free;
}

- sock_tx_timestamp(sk, sockc.tsflags, &skb_shinfo(skb)->tx_flags);
+ skb_setup_tx_timestamp(skb, sockc.tsflags);

if (!vnet_hdr.gso_type && (len > dev->mtu + reserve + extra_len) &&
!packet_extra_vlan_len_allowed(dev, skb)) {
--
2.25.1

2022-04-07 01:32:20

by Vladimir Oltean

[permalink] [raw]
Subject: Re: [PATCH 4.14 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW

On Wed, Apr 06, 2022 at 03:45:14PM -0400, Willem de Bruijn wrote:
> On Wed, Apr 6, 2022 at 3:30 PM Vladimir Oltean <[email protected]> wrote:
> >
> > From: Willem de Bruijn <[email protected]>
> >
> > [ Upstream commit fbfb2321e950918b430e7225546296b2dcadf725 ]
> >
> > Raw sockets support tx timestamping, but one case is missing.
> >
> > IPPROTO_RAW takes a separate packet construction path. raw_send_hdrinc
> > has an explicit call to sock_tx_timestamp, but rawv6_send_hdrinc does
> > not. Add it.
> >
> > Fixes: 11878b40ed5c ("net-timestamp: SOCK_RAW and PING timestamping")
> > Signed-off-by: Willem de Bruijn <[email protected]>
> > Acked-by: Soheil Hassas Yeganeh <[email protected]>
> > Signed-off-by: David S. Miller <[email protected]>
> > Signed-off-by: Vladimir Oltean <[email protected]>
>
> For 4.14.y cherry-pick:
>
> Acked-by: Willem de Bruijn <[email protected]>

Thanks.

> Might be good to point out that this is not only a clean cherry-pick
> of the one-line patch, but has to include part of commit a818f75e311c
> ("net: ipv6: Hook into time based transmission") to plumb the
> sockcm_cookie. The rest of that patch is not a candidate for stable,
> so LGTM.

Point out how?

2022-04-07 04:32:42

by Willem de Bruijn

[permalink] [raw]
Subject: Re: [PATCH 4.14 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW

On Wed, Apr 6, 2022 at 5:15 PM Vladimir Oltean <[email protected]> wrote:
>
> On Wed, Apr 06, 2022 at 03:45:14PM -0400, Willem de Bruijn wrote:
> > On Wed, Apr 6, 2022 at 3:30 PM Vladimir Oltean <[email protected]> wrote:
> > >
> > > From: Willem de Bruijn <[email protected]>
> > >
> > > [ Upstream commit fbfb2321e950918b430e7225546296b2dcadf725 ]
> > >
> > > Raw sockets support tx timestamping, but one case is missing.
> > >
> > > IPPROTO_RAW takes a separate packet construction path. raw_send_hdrinc
> > > has an explicit call to sock_tx_timestamp, but rawv6_send_hdrinc does
> > > not. Add it.
> > >
> > > Fixes: 11878b40ed5c ("net-timestamp: SOCK_RAW and PING timestamping")
> > > Signed-off-by: Willem de Bruijn <[email protected]>
> > > Acked-by: Soheil Hassas Yeganeh <[email protected]>
> > > Signed-off-by: David S. Miller <[email protected]>
> > > Signed-off-by: Vladimir Oltean <[email protected]>
> >
> > For 4.14.y cherry-pick:
> >
> > Acked-by: Willem de Bruijn <[email protected]>
>
> Thanks.
>
> > Might be good to point out that this is not only a clean cherry-pick
> > of the one-line patch, but has to include part of commit a818f75e311c
> > ("net: ipv6: Hook into time based transmission") to plumb the
> > sockcm_cookie. The rest of that patch is not a candidate for stable,
> > so LGTM.
>
> Point out how?

In this case I did, so we're good. In general, perhaps it's fine to
add such comments below the original Signed-off-by/Acked-by/.. block?
Not sure what the common approach is, if any.

2022-04-09 03:40:26

by Vladimir Oltean

[permalink] [raw]
Subject: Re: [PATCH stable 0/3] SOF_TIMESTAMPING_OPT_ID backport to 4.14 and 4.19

Hello Greg, Sasha,

On Wed, Apr 06, 2022 at 10:29:53PM +0300, Vladimir Oltean wrote:
> As discussed with Willem here:
> https://lore.kernel.org/netdev/CA+FuTSdQ57O6RWj_Lenmu_Vd3NEX9xMzMYkB0C3rKMzGgcPc6A@mail.gmail.com/T/
>
> the kernel silently doesn't act upon the SOF_TIMESTAMPING_OPT_ID socket
> option in several cases on older kernels, yet user space has no way to
> find out about this, practically resulting in broken functionality.
>
> This patch set backports the support towards linux-4.14.y and linux-4.19.y,
> which fixes the issue described above by simply making the kernel act
> upon SOF_TIMESTAMPING_OPT_ID as expected.
>
> Testing was done with the most recent (not the vintage-correct one)
> kselftest script at:
> tools/testing/selftests/networking/timestamping/txtimestamp.sh
> with the message "OK. All tests passed".

Could you please pick up these backports for "stable"? Thanks.

2022-04-12 17:30:16

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH stable 0/3] SOF_TIMESTAMPING_OPT_ID backport to 4.14 and 4.19

On Fri, Apr 08, 2022 at 03:29:30PM +0000, Vladimir Oltean wrote:
> Hello Greg, Sasha,
>
> On Wed, Apr 06, 2022 at 10:29:53PM +0300, Vladimir Oltean wrote:
> > As discussed with Willem here:
> > https://lore.kernel.org/netdev/CA+FuTSdQ57O6RWj_Lenmu_Vd3NEX9xMzMYkB0C3rKMzGgcPc6A@mail.gmail.com/T/
> >
> > the kernel silently doesn't act upon the SOF_TIMESTAMPING_OPT_ID socket
> > option in several cases on older kernels, yet user space has no way to
> > find out about this, practically resulting in broken functionality.
> >
> > This patch set backports the support towards linux-4.14.y and linux-4.19.y,
> > which fixes the issue described above by simply making the kernel act
> > upon SOF_TIMESTAMPING_OPT_ID as expected.
> >
> > Testing was done with the most recent (not the vintage-correct one)
> > kselftest script at:
> > tools/testing/selftests/networking/timestamping/txtimestamp.sh
> > with the message "OK. All tests passed".
>
> Could you please pick up these backports for "stable"? Thanks.

You sent this 2 days ago!

Please relax :)

2022-04-12 23:12:52

by Sasha Levin

[permalink] [raw]
Subject: Re: [PATCH stable 0/3] SOF_TIMESTAMPING_OPT_ID backport to 4.14 and 4.19

On Fri, Apr 08, 2022 at 05:42:30PM +0200, Greg Kroah-Hartman wrote:
>On Fri, Apr 08, 2022 at 03:29:30PM +0000, Vladimir Oltean wrote:
>> Hello Greg, Sasha,
>>
>> On Wed, Apr 06, 2022 at 10:29:53PM +0300, Vladimir Oltean wrote:
>> > As discussed with Willem here:
>> > https://lore.kernel.org/netdev/CA+FuTSdQ57O6RWj_Lenmu_Vd3NEX9xMzMYkB0C3rKMzGgcPc6A@mail.gmail.com/T/
>> >
>> > the kernel silently doesn't act upon the SOF_TIMESTAMPING_OPT_ID socket
>> > option in several cases on older kernels, yet user space has no way to
>> > find out about this, practically resulting in broken functionality.
>> >
>> > This patch set backports the support towards linux-4.14.y and linux-4.19.y,
>> > which fixes the issue described above by simply making the kernel act
>> > upon SOF_TIMESTAMPING_OPT_ID as expected.
>> >
>> > Testing was done with the most recent (not the vintage-correct one)
>> > kselftest script at:
>> > tools/testing/selftests/networking/timestamping/txtimestamp.sh
>> > with the message "OK. All tests passed".
>>
>> Could you please pick up these backports for "stable"? Thanks.
>
>You sent this 2 days ago!
>
>Please relax :)

I've queued these up.

In general, we don't pick up new patches during -rc releases, which is
when you've sent this patchset and which is why sometimes it takes a few
days for stuff to go in.

--
Thanks,
Sasha

2022-04-29 12:29:53

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH stable 0/3] SOF_TIMESTAMPING_OPT_ID backport to 4.14 and 4.19

On Fri, Apr 08, 2022 at 03:29:30PM +0000, Vladimir Oltean wrote:
> Hello Greg, Sasha,
>
> On Wed, Apr 06, 2022 at 10:29:53PM +0300, Vladimir Oltean wrote:
> > As discussed with Willem here:
> > https://lore.kernel.org/netdev/CA+FuTSdQ57O6RWj_Lenmu_Vd3NEX9xMzMYkB0C3rKMzGgcPc6A@mail.gmail.com/T/
> >
> > the kernel silently doesn't act upon the SOF_TIMESTAMPING_OPT_ID socket
> > option in several cases on older kernels, yet user space has no way to
> > find out about this, practically resulting in broken functionality.
> >
> > This patch set backports the support towards linux-4.14.y and linux-4.19.y,
> > which fixes the issue described above by simply making the kernel act
> > upon SOF_TIMESTAMPING_OPT_ID as expected.
> >
> > Testing was done with the most recent (not the vintage-correct one)
> > kselftest script at:
> > tools/testing/selftests/networking/timestamping/txtimestamp.sh
> > with the message "OK. All tests passed".
>
> Could you please pick up these backports for "stable"? Thanks.

Do you not already see these in a released kernel? If not, please
resubmit what is missing as I think they are all there...

thanks,

greg k-h

2022-05-02 20:24:32

by Vladimir Oltean

[permalink] [raw]
Subject: Re: [PATCH stable 0/3] SOF_TIMESTAMPING_OPT_ID backport to 4.14 and 4.19

On Fri, Apr 29, 2022 at 10:38:42AM +0200, Greg Kroah-Hartman wrote:
> On Fri, Apr 08, 2022 at 03:29:30PM +0000, Vladimir Oltean wrote:
> > Hello Greg, Sasha,
> >
> > On Wed, Apr 06, 2022 at 10:29:53PM +0300, Vladimir Oltean wrote:
> > > As discussed with Willem here:
> > > https://lore.kernel.org/netdev/CA+FuTSdQ57O6RWj_Lenmu_Vd3NEX9xMzMYkB0C3rKMzGgcPc6A@mail.gmail.com/T/
> > >
> > > the kernel silently doesn't act upon the SOF_TIMESTAMPING_OPT_ID socket
> > > option in several cases on older kernels, yet user space has no way to
> > > find out about this, practically resulting in broken functionality.
> > >
> > > This patch set backports the support towards linux-4.14.y and linux-4.19.y,
> > > which fixes the issue described above by simply making the kernel act
> > > upon SOF_TIMESTAMPING_OPT_ID as expected.
> > >
> > > Testing was done with the most recent (not the vintage-correct one)
> > > kselftest script at:
> > > tools/testing/selftests/networking/timestamping/txtimestamp.sh
> > > with the message "OK. All tests passed".
> >
> > Could you please pick up these backports for "stable"? Thanks.
>
> Do you not already see these in a released kernel? If not, please
> resubmit what is missing as I think they are all there...

They're there, thanks.
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.14.y&id=add668be8f5e53f4471a075edaa70a7cb85fd036
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.14.y&id=a96c57a72f477b42ab238fad3c2c1f8e8c091256
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.19.y&id=cd7295d0bea3f56a3f024f1b22d50a0f3fc727f1