netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: Paul Barker <paul@pbarker.dev>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Mitsuhiro Kimura <mitsuhiro.kimura.kc@renesas.com>,
	netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Biju Das <biju.das.jz@bp.renesas.com>,
	Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 3/4] net: ravb: Enforce descriptor type ordering
Date: Wed, 22 Oct 2025 14:11:32 +0200	[thread overview]
Message-ID: <20251022121132.GD1694476@ragnatech.se> (raw)
In-Reply-To: <20251017151830.171062-4-prabhakar.mahadev-lad.rj@bp.renesas.com>

Hi Lad,

Thanks for reworking this and making it very clear what's going on.

On 2025-10-17 16:18:29 +0100, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> 
> Ensure the TX descriptor type fields are published in a safe order so the
> DMA engine never begins processing a descriptor chain before all descriptor
> fields are fully initialised.
> 
> For multi-descriptor transmits the driver writes DT_FEND into the last
> descriptor and DT_FSTART into the first. The DMA engine begins processing
> when it observes DT_FSTART. Move the dma_wmb() barrier so it executes
> immediately after DT_FEND and immediately before writing DT_FSTART
> (and before DT_FSINGLE in the single-descriptor case). This guarantees
> that all prior CPU writes to the descriptor memory are visible to the
> device before DT_FSTART is seen.
> 
> This avoids a situation where compiler/CPU reordering could publish
> DT_FSTART ahead of DT_FEND or other descriptor fields, allowing the DMA to
> start on a partially initialised chain and causing corrupted transmissions
> or TX timeouts. Such a failure was observed on RZ/G2L with an RT kernel as
> transmit queue timeouts and device resets.
> 
> Fixes: 2f45d1902acf ("ravb: minimize TX data copying")
> Cc: stable@vger.kernel.org
> Co-developed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
> Signed-off-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
> v1->v2:
> - Reflowed the code and updated the comment to clarify the ordering
>   requirements.
> - Updated commit message.
> - Split up adding memory barrier change before ringing doorbell
>   into a separate patch.
> ---
>  drivers/net/ethernet/renesas/ravb_main.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index a200e205825a..0e40001f64b4 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -2211,13 +2211,25 @@ static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev)
>  
>  		skb_tx_timestamp(skb);
>  	}
> -	/* Descriptor type must be set after all the above writes */
> -	dma_wmb();
> +
>  	if (num_tx_desc > 1) {
>  		desc->die_dt = DT_FEND;
>  		desc--;
> +		/* When using multi-descriptors, DT_FEND needs to get written
> +		 * before DT_FSTART, but the compiler may reorder the memory
> +		 * writes in an attempt to optimize the code.
> +		 * Use a dma_wmb() barrier to make sure DT_FEND and DT_FSTART
> +		 * are written exactly in the order shown in the code.
> +		 * This is particularly important for cases where the DMA engine
> +		 * is already running when we are running this code. If the DMA
> +		 * sees DT_FSTART without the corresponding DT_FEND it will enter
> +		 * an error condition.
> +		 */
> +		dma_wmb();
>  		desc->die_dt = DT_FSTART;
>  	} else {
> +		/* Descriptor type must be set after all the above writes */
> +		dma_wmb();
>  		desc->die_dt = DT_FSINGLE;
>  	}
>  	ravb_modify(ndev, TCCR, TCCR_TSRQ0 << q, TCCR_TSRQ0 << q);
> -- 
> 2.43.0
> 

-- 
Kind Regards,
Niklas Söderlund

  reply	other threads:[~2025-10-22 12:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17 15:18 [PATCH v2 0/4] net: ravb: Fix SoC-specific configuration and descriptor handling issues Prabhakar
2025-10-17 15:18 ` [PATCH v2 1/4] net: ravb: Make DBAT entry count configurable per-SoC Prabhakar
2025-10-23  1:13   ` Jakub Kicinski
2025-10-23 10:51     ` Lad, Prabhakar
2025-10-17 15:18 ` [PATCH v2 2/4] net: ravb: Allocate correct number of queues based on SoC support Prabhakar
2025-10-23  1:13   ` Jakub Kicinski
2025-10-23 10:52     ` Lad, Prabhakar
2025-10-17 15:18 ` [PATCH v2 3/4] net: ravb: Enforce descriptor type ordering Prabhakar
2025-10-22 12:11   ` Niklas Söderlund [this message]
2025-10-17 15:18 ` [PATCH v2 4/4] net: ravb: Ensure memory write completes before ringing TX doorbell Prabhakar
2025-10-22 12:16   ` Niklas Söderlund
2025-10-23  1:19 ` [PATCH v2 0/4] net: ravb: Fix SoC-specific configuration and descriptor handling issues Jakub Kicinski
2025-10-23  3:46 ` 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=20251022121132.GD1694476@ragnatech.se \
    --to=niklas.soderlund@ragnatech.se \
    --cc=andrew+netdev@lunn.ch \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mitsuhiro.kimura.kc@renesas.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paul@pbarker.dev \
    --cc=prabhakar.csengg@gmail.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).