mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: Robert Hancock <robert.hancock@calian.com>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Claudiu Beznea <claudiu.beznea@microchip.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"Richard Cochran" <richardcochran@gmail.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net] net: macb: fix PTP TX timestamp failure due to packet padding
Date: Tue, 17 Jan 2023 16:07:14 -0800	[thread overview]
Message-ID: <0946c513-867d-0ddc-a632-b03fea2cc921@intel.com> (raw)
In-Reply-To: <20230116214133.1834364-1-robert.hancock@calian.com>



On 1/16/2023 1:41 PM, Robert Hancock wrote:
> PTP TX timestamp handling was observed to be broken with this driver
> when using the raw Layer 2 PTP encapsulation. ptp4l was not receiving
> the expected TX timestamp after transmitting a packet, causing it to
> enter a failure state.
> 
> The problem appears to be due to the way that the driver pads packets
> which are smaller than the Ethernet minimum of 60 bytes. If headroom
> space was available in the SKB, this caused the driver to move the data
> back to utilize it. However, this appears to cause other data references
> in the SKB to become inconsistent. In particular, this caused the
> ptp_one_step_sync function to later (in the TX completion path) falsely
> detect the packet as a one-step SYNC packet, even when it was not, which
> caused the TX timestamp to not be processed when it should be.
> 
> Using the headroom for this purpose seems like an unnecessary complexity
> as this is not a hot path in the driver, and in most cases it appears
> that there is sufficient tailroom to not require using the headroom
> anyway. Remove this usage of headroom to prevent this inconsistency from
> occurring and causing other problems.
> 
> Fixes: 653e92a9175e ("net: macb: add support for padding and fcs computation")
> Signed-off-by: Robert Hancock <robert.hancock@calian.com>
> ---

Makes sense and is a nice cleanup.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

>  drivers/net/ethernet/cadence/macb_main.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 95667b979fab..72e42820713d 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -2187,7 +2187,6 @@ static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *ndev)
>  	bool cloned = skb_cloned(*skb) || skb_header_cloned(*skb) ||
>  		      skb_is_nonlinear(*skb);
>  	int padlen = ETH_ZLEN - (*skb)->len;
> -	int headroom = skb_headroom(*skb);
>  	int tailroom = skb_tailroom(*skb);
>  	struct sk_buff *nskb;
>  	u32 fcs;
> @@ -2201,9 +2200,6 @@ static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *ndev)
>  		/* FCS could be appeded to tailroom. */
>  		if (tailroom >= ETH_FCS_LEN)
>  			goto add_fcs;
> -		/* FCS could be appeded by moving data to headroom. */
> -		else if (!cloned && headroom + tailroom >= ETH_FCS_LEN)
> -			padlen = 0;
>  		/* No room for FCS, need to reallocate skb. */
>  		else
>  			padlen = ETH_FCS_LEN;
> @@ -2212,10 +2208,7 @@ static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *ndev)
>  		padlen += ETH_FCS_LEN;
>  	}
>  
> -	if (!cloned && headroom + tailroom >= padlen) {
> -		(*skb)->data = memmove((*skb)->head, (*skb)->data, (*skb)->len);
> -		skb_set_tail_pointer(*skb, (*skb)->len);
> -	} else {
> +	if (cloned || tailroom < padlen) {
>  		nskb = skb_copy_expand(*skb, 0, padlen, GFP_ATOMIC);
>  		if (!nskb)
>  			return -ENOMEM;

  reply	other threads:[~2023-01-18  0:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 21:41 Robert Hancock
2023-01-18  0:07 ` Jacob Keller [this message]
2023-01-18  9:39 ` Claudiu.Beznea
2023-01-18  9:39 ` Claudiu.Beznea
2023-01-18 14:30 ` patchwork-bot+netdevbpf

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=0946c513-867d-0ddc-a632-b03fea2cc921@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=robert.hancock@calian.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

all inboxes | Powered by JetHome®