diff mbox series

[v2] net: packetmmap: fix only tx timestamp on request

Message ID 1620783082-28906-1-git-send-email-rsanger@wand.net.nz (mailing list archive)
State Accepted
Commit 171c3b151118a2fe0fc1e2a9d1b5a1570cfe82d2
Delegated to: Netdev Maintainers
Headers show
Series [v2] net: packetmmap: fix only tx timestamp on request | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers fail 2 blamed authors not CCed: willemb@google.com davem@davemloft.net; 9 maintainers not CCed: xie.he.0141@gmail.com john.ogness@linutronix.de kuba@kernel.org willemb@google.com wanghai38@huawei.com eyal.birger@gmail.com tannerlove@google.com davem@davemloft.net edumazet@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 85 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/header_inline success Link

Commit Message

Richard Sanger May 12, 2021, 1:31 a.m. UTC
The packetmmap tx ring should only return timestamps if requested via
setsockopt PACKET_TIMESTAMP, as documented. This allows compatibility
with non-timestamp aware user-space code which checks
tp_status == TP_STATUS_AVAILABLE; not expecting additional timestamp
flags to be set in tp_status.

Fixes: b9c32fb27170 ("packet: if hw/sw ts enabled in rx/tx ring, report which ts we got")
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Signed-off-by: Richard Sanger <rsanger@wand.net.nz>
---
 net/packet/af_packet.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Willem de Bruijn May 12, 2021, 2:24 p.m. UTC | #1
On Tue, May 11, 2021 at 9:32 PM Richard Sanger <rsanger@wand.net.nz> wrote:
>
> The packetmmap tx ring should only return timestamps if requested via
> setsockopt PACKET_TIMESTAMP, as documented. This allows compatibility
> with non-timestamp aware user-space code which checks
> tp_status == TP_STATUS_AVAILABLE; not expecting additional timestamp
> flags to be set in tp_status.
>
> Fixes: b9c32fb27170 ("packet: if hw/sw ts enabled in rx/tx ring, report which ts we got")
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> Signed-off-by: Richard Sanger <rsanger@wand.net.nz>

Code LGTM.

It would be good to capture more of the context: when these spurious
timestamps can appear (network namespaces) and as of which commit (the
one that changes orphaning). As is, I would not be able to understand
the issue addressed from this commit message alone.

Instead of adding context to the commit, you could also add a Link tag
to the archived email thread, if you prefer.

And perhaps: [PATCH net v3] net/packet: return software transmit
timestamp only when requested



> ---
>  net/packet/af_packet.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index ba96db1..ae906eb 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -422,7 +422,8 @@ static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,
>             ktime_to_timespec64_cond(shhwtstamps->hwtstamp, ts))
>                 return TP_STATUS_TS_RAW_HARDWARE;
>
> -       if (ktime_to_timespec64_cond(skb->tstamp, ts))
> +       if ((flags & SOF_TIMESTAMPING_SOFTWARE) &&
> +           ktime_to_timespec64_cond(skb->tstamp, ts))
>                 return TP_STATUS_TS_SOFTWARE;
>
>         return 0;
> @@ -2340,7 +2341,12 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
>
>         skb_copy_bits(skb, 0, h.raw + macoff, snaplen);
>
> -       if (!(ts_status = tpacket_get_timestamp(skb, &ts, po->tp_tstamp)))
> +       /* Always timestamp; prefer an existing software timestamp taken
> +        * closer to the time of capture.
> +        */
> +       ts_status = tpacket_get_timestamp(skb, &ts,
> +                                         po->tp_tstamp | SOF_TIMESTAMPING_SOFTWARE);
> +       if (!ts_status)
>                 ktime_get_real_ts64(&ts);
>
>         status |= ts_status;
> --
> 2.7.4
>
patchwork-bot+netdevbpf@kernel.org May 12, 2021, 9:10 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Wed, 12 May 2021 13:31:22 +1200 you wrote:
> The packetmmap tx ring should only return timestamps if requested via
> setsockopt PACKET_TIMESTAMP, as documented. This allows compatibility
> with non-timestamp aware user-space code which checks
> tp_status == TP_STATUS_AVAILABLE; not expecting additional timestamp
> flags to be set in tp_status.
> 
> Fixes: b9c32fb27170 ("packet: if hw/sw ts enabled in rx/tx ring, report which ts we got")
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> Signed-off-by: Richard Sanger <rsanger@wand.net.nz>
> 
> [...]

Here is the summary with links:
  - [v2] net: packetmmap: fix only tx timestamp on request
    https://git.kernel.org/netdev/net/c/171c3b151118

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Richard Sanger May 12, 2021, 10:01 p.m. UTC | #3
On Thu, May 13, 2021 at 2:24 AM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> On Tue, May 11, 2021 at 9:32 PM Richard Sanger <rsanger@wand.net.nz> wrote:
> >
> > The packetmmap tx ring should only return timestamps if requested via
> > setsockopt PACKET_TIMESTAMP, as documented. This allows compatibility
> > with non-timestamp aware user-space code which checks
> > tp_status == TP_STATUS_AVAILABLE; not expecting additional timestamp
> > flags to be set in tp_status.
> >
> > Fixes: b9c32fb27170 ("packet: if hw/sw ts enabled in rx/tx ring, report which ts we got")
> > Cc: Daniel Borkmann <daniel@iogearbox.net>
> > Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> > Signed-off-by: Richard Sanger <rsanger@wand.net.nz>
>
> Code LGTM.
>
> It would be good to capture more of the context: when these spurious
> timestamps can appear (network namespaces) and as of which commit (the
> one that changes orphaning). As is, I would not be able to understand
> the issue addressed from this commit message alone.
>
> Instead of adding context to the commit, you could also add a Link tag
> to the archived email thread, if you prefer.
>
> And perhaps: [PATCH net v3] net/packet: return software transmit
> timestamp only when requested
>

Ahh, looks like this patch has just been merged in.

For anyone looking for more details they are in this thread:
https://lore.kernel.org/netdev/1620085579-5646-1-git-send-email-rsanger@wand.net.nz/

>
> > ---
> >  net/packet/af_packet.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> > index ba96db1..ae906eb 100644
> > --- a/net/packet/af_packet.c
> > +++ b/net/packet/af_packet.c
> > @@ -422,7 +422,8 @@ static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,
> >             ktime_to_timespec64_cond(shhwtstamps->hwtstamp, ts))
> >                 return TP_STATUS_TS_RAW_HARDWARE;
> >
> > -       if (ktime_to_timespec64_cond(skb->tstamp, ts))
> > +       if ((flags & SOF_TIMESTAMPING_SOFTWARE) &&
> > +           ktime_to_timespec64_cond(skb->tstamp, ts))
> >                 return TP_STATUS_TS_SOFTWARE;
> >
> >         return 0;
> > @@ -2340,7 +2341,12 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
> >
> >         skb_copy_bits(skb, 0, h.raw + macoff, snaplen);
> >
> > -       if (!(ts_status = tpacket_get_timestamp(skb, &ts, po->tp_tstamp)))
> > +       /* Always timestamp; prefer an existing software timestamp taken
> > +        * closer to the time of capture.
> > +        */
> > +       ts_status = tpacket_get_timestamp(skb, &ts,
> > +                                         po->tp_tstamp | SOF_TIMESTAMPING_SOFTWARE);
> > +       if (!ts_status)
> >                 ktime_get_real_ts64(&ts);
> >
> >         status |= ts_status;
> > --
> > 2.7.4
> >
diff mbox series

Patch

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index ba96db1..ae906eb 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -422,7 +422,8 @@  static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,
 	    ktime_to_timespec64_cond(shhwtstamps->hwtstamp, ts))
 		return TP_STATUS_TS_RAW_HARDWARE;
 
-	if (ktime_to_timespec64_cond(skb->tstamp, ts))
+	if ((flags & SOF_TIMESTAMPING_SOFTWARE) &&
+	    ktime_to_timespec64_cond(skb->tstamp, ts))
 		return TP_STATUS_TS_SOFTWARE;
 
 	return 0;
@@ -2340,7 +2341,12 @@  static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
 
 	skb_copy_bits(skb, 0, h.raw + macoff, snaplen);
 
-	if (!(ts_status = tpacket_get_timestamp(skb, &ts, po->tp_tstamp)))
+	/* Always timestamp; prefer an existing software timestamp taken
+	 * closer to the time of capture.
+	 */
+	ts_status = tpacket_get_timestamp(skb, &ts,
+					  po->tp_tstamp | SOF_TIMESTAMPING_SOFTWARE);
+	if (!ts_status)
 		ktime_get_real_ts64(&ts);
 
 	status |= ts_status;