Subject: Re: [PATCH net-next v8 4/7] net: macsec: introduce mdo_insert_tx_tag

From: Jakub Kicinski <[email-masked]>
Date: Wed, 25 Oct 2023 15:40:23 -0700

On Mon, 23 Oct 2023 12:43:24 +0300 Radu Pirea (NXP OSS) wrote:
> +	if (unlikely(skb_headroom(skb) < ops->needed_headroom ||
> +		     skb_tailroom(skb) < ops->needed_tailroom)) {

This sort of "if head / tail room is to small, realloc" helper would 
be more widely applicable, we should factor it out.

> +		struct sk_buff *nskb = skb_copy_expand(skb,

And this should perhaps be pskb_expand_head().

> +						       ops->needed_headroom,
> +						       ops->needed_tailroom,
> +						       GFP_ATOMIC);
> +		if (likely(nskb)) {
> +			consume_skb(skb);
> +			skb = nskb;
> +		} else {
> +			err = -ENOMEM;
> +			goto cleanup;
> +		}
> +	} else {
> +		skb = skb_unshare(skb, GFP_ATOMIC);

You don't need to unshare if tailroom is 0, you just need to call
skb_cow_head(). 

I think we have this sort of code in DSA already, IIRC Vladimir wrote
it. dsa_realloc_skb() ? Can we factor out / reuse that?

> +		if (!skb)
> +			return ERR_PTR(-ENOMEM);
> +	}
> +
> +	err = ops->mdo_insert_tx_tag(phydev, skb);
> +	if (unlikely(err))
> +		goto cleanup;
> +
> +	if (unlikely(skb->len - ETH_HLEN > macsec_priv(dev)->real_dev->mtu)) {

You can check that first, if the packet is going to be dropped no point
doing the expansions.

> +		err = -EINVAL;
> +		goto cleanup;
> +	}