Linux Tegra architecture development
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: "Russell King (Oracle)" <linux@armlinux.org.uk>,
	Thierry Reding <thierry.reding@gmail.com>
Cc: Robin Murphy <robin.murphy@arm.com>, Furong Xu <0x1207@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Jose Abreu <joabreu@synopsys.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	xfr@outlook.com, Suraj Jaiswal <quic_jsuraj@quicinc.com>,
	Thierry Reding <treding@nvidia.com>,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
	Will Deacon <will@kernel.org>
Subject: Re: [PATCH net v1] net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data
Date: Wed, 4 Dec 2024 17:02:19 +0000	[thread overview]
Message-ID: <9719982a-d40c-4110-9233-def2e6cb4d74@nvidia.com> (raw)
In-Reply-To: <Z1CFz7GpeIzkDro1@shell.armlinux.org.uk>

Hi Russell,

On 04/12/2024 16:39, Russell King (Oracle) wrote:
> On Wed, Dec 04, 2024 at 04:58:34PM +0100, Thierry Reding wrote:
>> This doesn't match the location from earlier, but at least there's
>> something afoot here that needs fixing. I suppose this could simply be
>> hiding any subsequent errors, so once this is fixed we might see other
>> similar issues.
> 
> Well, having a quick look at this, the first thing which stands out is:
> 
> In stmmac_tx_clean(), we have:
> 
>                  if (likely(tx_q->tx_skbuff_dma[entry].buf &&
>                             tx_q->tx_skbuff_dma[entry].buf_type != STMMAC_TXBUF_T
> _XDP_TX)) {
>                          if (tx_q->tx_skbuff_dma[entry].map_as_page)
>                                  dma_unmap_page(priv->device,
>                                                 tx_q->tx_skbuff_dma[entry].buf,
>                                                 tx_q->tx_skbuff_dma[entry].len,
>                                                 DMA_TO_DEVICE);
>                          else
>                                  dma_unmap_single(priv->device,
>                                                   tx_q->tx_skbuff_dma[entry].buf,
>                                                   tx_q->tx_skbuff_dma[entry].len,
>                                                   DMA_TO_DEVICE);
>                          tx_q->tx_skbuff_dma[entry].buf = 0;
>                          tx_q->tx_skbuff_dma[entry].len = 0;
>                          tx_q->tx_skbuff_dma[entry].map_as_page = false;
>                  }
> 
> So, tx_skbuff_dma[entry].buf is expected to point appropriately to the
> DMA region.
> 
> Now if we look at stmmac_tso_xmit():
> 
>          des = dma_map_single(priv->device, skb->data, skb_headlen(skb),
>                               DMA_TO_DEVICE);
>          if (dma_mapping_error(priv->device, des))
>                  goto dma_map_err;
> 
>          if (priv->dma_cap.addr64 <= 32) {
> ...
>          } else {
> ...
>                  des += proto_hdr_len;
> ...
> 	}
> 
>          tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des;
>          tx_q->tx_skbuff_dma[tx_q->cur_tx].len = skb_headlen(skb);
>          tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = false;
>          tx_q->tx_skbuff_dma[tx_q->cur_tx].buf_type = STMMAC_TXBUF_T_SKB;
> 
> This will result in stmmac_tx_clean() calling dma_unmap_single() using
> "des" and "skb_headlen(skb)" as the buffer start and length.
> 
> One of the requirements of the DMA mapping API is that the DMA handle
> returned by the map operation will be passed into the unmap function.
> Not something that was offset. The length will also be the same.
> 
> We can clearly see above that there is a case where the DMA handle has
> been offset by proto_hdr_len, and when this is so, the value that is
> passed into the unmap operation no longer matches this requirement.
> 
> So, a question to the reporter - what is the value of
> priv->dma_cap.addr64 in your failing case? You should see the value
> in the "Using %d/%d bits DMA host/device width" kernel message.

It is ...

  dwc-eth-dwmac 2490000.ethernet: Using 40/40 bits DMA host/device width

Thanks
Jon

-- 
nvpublic


  reply	other threads:[~2024-12-04 17:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20241021061023.2162701-1-0x1207@gmail.com>
2024-11-27 18:39 ` [PATCH net v1] net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data Jon Hunter
2024-11-28  6:45   ` Furong Xu
2024-12-03  0:33     ` Jakub Kicinski
2024-12-03  2:03       ` Furong Xu
2024-12-03  2:34         ` Jakub Kicinski
2024-12-03  3:16           ` Furong Xu
2024-12-04 13:57             ` Thierry Reding
2024-12-04 14:06               ` Robin Murphy
2024-12-04 15:58                 ` Thierry Reding
2024-12-04 16:39                   ` Russell King (Oracle)
2024-12-04 17:02                     ` Jon Hunter [this message]
2024-12-04 17:45                       ` Russell King (Oracle)
2024-12-04 18:18                         ` Thierry Reding
2024-12-05 10:57                           ` Jon Hunter
2024-12-05 11:02                             ` Jon Hunter
2024-12-05  9:34                         ` Furong Xu
2024-12-04 17:03             ` Jon Hunter

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=9719982a-d40c-4110-9233-def2e6cb4d74@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=0x1207@gmail.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=joabreu@synopsys.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=quic_jsuraj@quicinc.com \
    --cc=robin.murphy@arm.com \
    --cc=thierry.reding@gmail.com \
    --cc=treding@nvidia.com \
    --cc=will@kernel.org \
    --cc=xfr@outlook.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