linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: "Russell King (Oracle)" <linux@armlinux.org.uk>, pali@kernel.org
Cc: Christoph Hellwig <hch@lst.de>,
	Robin Murphy <robin.murphy@arm.com>,
	Arnd Bergmann <arnd@kernel.org>,
	Andre Przywara <andre.przywara@arm.com>,
	Marc Zyngier <maz@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Lunn <andrew@lunn.ch>,
	Gregory Clement <gregory.clement@bootlin.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	iommu@lists.linux-foundation.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: REGRESSION in 6.0-rc7 caused by patch "ARM/dma-mapping: use dma-direct unconditionally"
Date: Mon, 3 Oct 2022 17:25:33 +0200	[thread overview]
Message-ID: <20221003172533.6dc87184@dellmb> (raw)
In-Reply-To: <YzrtoNYtmEmftrjU@shell.armlinux.org.uk>

[-- Attachment #1: Type: text/plain, Size: 2399 bytes --]

On Mon, 3 Oct 2022 15:11:44 +0100
"Russell King (Oracle)" <linux@armlinux.org.uk> wrote:

> On Mon, Oct 03, 2022 at 09:30:37AM +0200, Christoph Hellwig wrote:
> > On Fri, Sep 30, 2022 at 05:02:05PM +0200, Marek Behún wrote:  
> > > It seems that the null pointer dereference comes from the data variable
> > > having zero value. We assign
> > >   data = (u8 *)(uintptr_t)rx_desc->buf_cookie;  
> > 
> > I never see any assignment to ->buf_cookie in the driver, what am
> > I missing?  
> 
> I think Marek's setup (like my setups) use the hardware buffer manager,
> and it's hardware that fills in the "buf_cookie", which is supposed to
> be the virtual address of the buffer.
> 
> Each buffer supplied to the hardware buffer manager is supposed to
> contain the virtual address in the first 32-bit word in that buffer.
> 
> This is done by mvneta_bm_construct():
> 
>         /* In order to update buf_cookie field of RX descriptor properly,
>          * BM hardware expects buf virtual address to be placed in the
>          * first four bytes of mapped buffer.
>          */
>         *(u32 *)buf = (u32)buf;
> 
> immediately prior to dma_map_single(..., DMA_FROM_DEVICE) is called.
> 
> If I had to guess, I would suggest that this write is being lost via
> cache invalidation, and given that the hardware BM both reads and
> writes this buffer, DMA_FROM_DEVICE is not correct, it should be
> DMA_BIDIRECTIONAL.
> 
> Changing that is probably going to need DMA_FROM_DEVICE also changed
> elsewhere in the mvneta_bm and mvneta driver.
> 
> I'm not in a position where I could test that out. Marek?
> 

Hello Russell,

thanks for your suggestion!

Adding Pali, since he has some information (see at the end of this
message).

The attached patch seems to solve the null-pointer dereference.
I booted into single user mode and enabled eth2. Before it caused the
NULL pointer dereference after link got up, not it does not happen.

But I am still encountering the freeze after booting into system.

Maybe these are different bugs?

I am thinking whether we don't need something similar like
  7bea67a99430 ("ARM: dts integrator: Fix DMA ranges")
also for mvebu.
I seem to remember Pali talking about how the ranges defined in some
upstream mvebu-tree, using MBUS_ID() macros, are incorrect.
Pali, what do you remember about this?

Marek

[-- Attachment #2: mvneta-dma-bidir.patch --]
[-- Type: text/x-patch, Size: 1820 bytes --]

diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index ff3e361e06e7..28eeba9bece2 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -2587,7 +2587,7 @@ static int mvneta_rx_hwbm(struct napi_struct *napi,
 			                              rx_desc->buf_phys_addr,
 			                              MVNETA_MH_SIZE + NET_SKB_PAD,
 			                              rx_bytes,
-			                              DMA_FROM_DEVICE);
+			                              DMA_BIDIRECTIONAL);
 			skb_put_data(skb, data + MVNETA_MH_SIZE + NET_SKB_PAD,
 				     rx_bytes);
 
@@ -2629,7 +2629,7 @@ static int mvneta_rx_hwbm(struct napi_struct *napi,
 		 * the skb is successfully built or not.
 		 */
 		dma_unmap_single(&pp->bm_priv->pdev->dev, phys_addr,
-				 bm_pool->buf_size, DMA_FROM_DEVICE);
+				 bm_pool->buf_size, DMA_BIDIRECTIONAL);
 		if (!skb)
 			goto err_drop_frame;
 
diff --git a/drivers/net/ethernet/marvell/mvneta_bm.c b/drivers/net/ethernet/marvell/mvneta_bm.c
index 46c942ef2287..7b93538078df 100644
--- a/drivers/net/ethernet/marvell/mvneta_bm.c
+++ b/drivers/net/ethernet/marvell/mvneta_bm.c
@@ -103,7 +103,7 @@ int mvneta_bm_construct(struct hwbm_pool *hwbm_pool, void *buf)
 	 */
 	*(u32 *)buf = (u32)buf;
 	phys_addr = dma_map_single(&priv->pdev->dev, buf, bm_pool->buf_size,
-				   DMA_FROM_DEVICE);
+				   DMA_BIDIRECTIONAL);
 	if (unlikely(dma_mapping_error(&priv->pdev->dev, phys_addr)))
 		return -ENOMEM;
 
@@ -243,7 +243,7 @@ void mvneta_bm_bufs_free(struct mvneta_bm *priv, struct mvneta_bm_pool *bm_pool,
 			break;
 
 		dma_unmap_single(&priv->pdev->dev, buf_phys_addr,
-				 bm_pool->buf_size, DMA_FROM_DEVICE);
+				 bm_pool->buf_size, DMA_BIDIRECTIONAL);
 		hwbm_buf_free(&bm_pool->hwbm_pool, vaddr);
 	}
 

[-- Attachment #3: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-10-03 15:26 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 13:10 REGRESSION in 6.0-rc7 caused by patch "ARM/dma-mapping: use dma-direct unconditionally" Marek Behún
2022-09-30 13:46 ` Robin Murphy
2022-09-30 14:52   ` Marek Behún
2022-09-30 15:02     ` Marek Behún
2022-09-30 16:41       ` Robin Murphy
2022-09-30 18:02         ` Marek Behún
2022-10-03  7:21           ` Christoph Hellwig
2022-10-03  7:30       ` Christoph Hellwig
2022-10-03 14:11         ` Russell King (Oracle)
2022-10-03 15:25           ` Marek Behún [this message]
2022-10-03 16:09             ` Pali Rohár
2022-10-03 19:04               ` Marek Behún
2022-10-03 19:08                 ` Pali Rohár
2022-10-03 21:30             ` Marcin Wojtas
2022-10-03 21:35               ` Pali Rohár
2022-10-03 22:03                 ` Marcin Wojtas
2022-10-04  7:10               ` Christoph Hellwig
2022-10-04  8:15                 ` Marek Behún
2022-10-04  8:17                   ` [PATCH] ARM: mvebu: select OF_DMA_DEFAULT_COHERENT if MACH_MVEBU_V7 Marek Behún
2022-10-04  8:30                     ` Christoph Hellwig
2022-10-04 12:54                       ` Marek Behún
2022-10-04  8:30                     ` Arnd Bergmann
2022-10-04  9:14                     ` Thorsten Leemhuis
2022-10-04  9:22                       ` Russell King (Oracle)
2022-10-04  9:56                 ` REGRESSION in 6.0-rc7 caused by patch "ARM/dma-mapping: use dma-direct unconditionally" Robin Murphy
2022-10-04  7:25               ` Russell King (Oracle)
2022-10-04  8:30                 ` Marcin Wojtas
2022-10-04  9:08                   ` Russell King (Oracle)
2022-10-04 12:36                     ` Marek Behún
2022-10-04 12:59                       ` Marcin Wojtas
2022-10-04 18:51                         ` Pali Rohár
2022-10-04 19:35                           ` Marcin Wojtas
2022-10-04  8:26               ` Marek Behún
2022-10-04  8:36                 ` Marcin Wojtas
2022-10-20 18:22                   ` Russell King (Oracle)
2022-10-20 19:10                     ` Marek Behún
2022-10-21 16:25                     ` Linus Torvalds
2022-10-21 16:30                     ` Christoph Hellwig
2022-10-21 18:21                       ` Russell King (Oracle)
2022-10-23 11:58                     ` Klaus Kudielka
2022-10-03 18:57         ` Marek Behún
2022-10-01  9:31 ` Thorsten Leemhuis
2022-11-04 12:08   ` REGRESSION in 6.0-rc7 caused by patch "ARM/dma-mapping: use dma-direct unconditionally" #forregzbot Thorsten Leemhuis

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=20221003172533.6dc87184@dellmb \
    --to=kabel@kernel.org \
    --cc=andre.przywara@arm.com \
    --cc=andrew@lunn.ch \
    --cc=arnd@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregory.clement@bootlin.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=maz@kernel.org \
    --cc=pali@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=torvalds@linux-foundation.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).