All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: Christoph Hellwig <hch@lst.de>,
	Amit Pundir <amit.pundir@linaro.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	David Rientjes <rientjes@google.com>,
	linux-rpi-kernel@lists.infradead.org, jeremy.linton@arm.com,
	iommu@lists.linux-foundation.org,
	lkml <linux-kernel@vger.kernel.org>,
	John Stultz <john.stultz@linaro.org>,
	Sumit Semwal <sumit.semwal@linaro.org>
Subject: Re: [PATCH] dma-pool: Do not allocate pool memory from CMA
Date: Tue, 28 Jul 2020 11:13:35 +0200	[thread overview]
Message-ID: <20200728091335.GA23744@lst.de> (raw)
In-Reply-To: <a9b811a84ac21c13693e6ffefd2914b911542e18.camel@suse.de>

On Mon, Jul 27, 2020 at 07:56:56PM +0200, Nicolas Saenz Julienne wrote:
> Hi Christoph,
> thanks for having a look at this!
> 
> On Fri, 2020-07-24 at 15:41 +0200, Christoph Hellwig wrote:
> > Yes, the iommu is an interesting case, and the current code is
> > wrong for that.
> 
> Care to expand on this? I do get that checking dma_coherent_ok() on memory
> that'll later on be mapped into an iommu is kind of silly, although I think
> harmless in Amir's specific case, since devices have wide enough dma-ranges. Is
> there more to it?

I think the problem is that it can lead to not finding suitable memory.

> 
> > Can you try the patch below?  It contains a modified version of Nicolas'
> > patch to try CMA again for the expansion and a new (for now hackish) way to
> > not apply the addressability check for dma-iommu allocations.
> > 
> > diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> > index 6bc74a2d51273e..ec5e525d2b9309 100644
> > --- a/kernel/dma/pool.c
> > +++ b/kernel/dma/pool.c
> > @@ -3,7 +3,9 @@
> >   * Copyright (C) 2012 ARM Ltd.
> >   * Copyright (C) 2020 Google LLC
> >   */
> > +#include <linux/cma.h>
> >  #include <linux/debugfs.h>
> > +#include <linux/dma-contiguous.h>
> >  #include <linux/dma-direct.h>
> >  #include <linux/dma-noncoherent.h>
> >  #include <linux/init.h>
> > @@ -55,6 +57,31 @@ static void dma_atomic_pool_size_add(gfp_t gfp, size_t
> > size)
> >  		pool_size_kernel += size;
> >  }
> >  
> > +static bool cma_in_zone(gfp_t gfp)
> > +{
> > +	phys_addr_t end;
> > +	unsigned long size;
> > +	struct cma *cma;
> > +
> > +	cma = dev_get_cma_area(NULL);
> > +	if (!cma)
> > +		return false;
> > +
> > +	size = cma_get_size(cma);
> > +	if (!size)
> > +		return false;
> > +	end = cma_get_base(cma) - memblock_start_of_DRAM() + size - 1;
> > +
> > +	/* CMA can't cross zone boundaries, see cma_activate_area() */
> > +	if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA) &&
> > +	    end <= DMA_BIT_MASK(zone_dma_bits))
> > +		return true;
> > +	if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32) &&
> > +	    end <= DMA_BIT_MASK(32))
> > +		return true;
> > +	return true;
> 
> IIUC this will always return true given a CMA is present. Which reverts to the
> previous behaviour (previous as in breaking some rpi4 setups), isn't it?

Was that really what broke the PI?  I'll try to get the split out series
today, which might have a few more tweaks, and then we'll need to test it
both on these rpi4 setups and Amits phone.

WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: Amit Pundir <amit.pundir@linaro.org>,
	lkml <linux-kernel@vger.kernel.org>,
	jeremy.linton@arm.com, Sumit Semwal <sumit.semwal@linaro.org>,
	iommu@lists.linux-foundation.org,
	John Stultz <john.stultz@linaro.org>,
	linux-rpi-kernel@lists.infradead.org,
	David Rientjes <rientjes@google.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH] dma-pool: Do not allocate pool memory from CMA
Date: Tue, 28 Jul 2020 11:13:35 +0200	[thread overview]
Message-ID: <20200728091335.GA23744@lst.de> (raw)
In-Reply-To: <a9b811a84ac21c13693e6ffefd2914b911542e18.camel@suse.de>

On Mon, Jul 27, 2020 at 07:56:56PM +0200, Nicolas Saenz Julienne wrote:
> Hi Christoph,
> thanks for having a look at this!
> 
> On Fri, 2020-07-24 at 15:41 +0200, Christoph Hellwig wrote:
> > Yes, the iommu is an interesting case, and the current code is
> > wrong for that.
> 
> Care to expand on this? I do get that checking dma_coherent_ok() on memory
> that'll later on be mapped into an iommu is kind of silly, although I think
> harmless in Amir's specific case, since devices have wide enough dma-ranges. Is
> there more to it?

I think the problem is that it can lead to not finding suitable memory.

> 
> > Can you try the patch below?  It contains a modified version of Nicolas'
> > patch to try CMA again for the expansion and a new (for now hackish) way to
> > not apply the addressability check for dma-iommu allocations.
> > 
> > diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> > index 6bc74a2d51273e..ec5e525d2b9309 100644
> > --- a/kernel/dma/pool.c
> > +++ b/kernel/dma/pool.c
> > @@ -3,7 +3,9 @@
> >   * Copyright (C) 2012 ARM Ltd.
> >   * Copyright (C) 2020 Google LLC
> >   */
> > +#include <linux/cma.h>
> >  #include <linux/debugfs.h>
> > +#include <linux/dma-contiguous.h>
> >  #include <linux/dma-direct.h>
> >  #include <linux/dma-noncoherent.h>
> >  #include <linux/init.h>
> > @@ -55,6 +57,31 @@ static void dma_atomic_pool_size_add(gfp_t gfp, size_t
> > size)
> >  		pool_size_kernel += size;
> >  }
> >  
> > +static bool cma_in_zone(gfp_t gfp)
> > +{
> > +	phys_addr_t end;
> > +	unsigned long size;
> > +	struct cma *cma;
> > +
> > +	cma = dev_get_cma_area(NULL);
> > +	if (!cma)
> > +		return false;
> > +
> > +	size = cma_get_size(cma);
> > +	if (!size)
> > +		return false;
> > +	end = cma_get_base(cma) - memblock_start_of_DRAM() + size - 1;
> > +
> > +	/* CMA can't cross zone boundaries, see cma_activate_area() */
> > +	if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA) &&
> > +	    end <= DMA_BIT_MASK(zone_dma_bits))
> > +		return true;
> > +	if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32) &&
> > +	    end <= DMA_BIT_MASK(32))
> > +		return true;
> > +	return true;
> 
> IIUC this will always return true given a CMA is present. Which reverts to the
> previous behaviour (previous as in breaking some rpi4 setups), isn't it?

Was that really what broke the PI?  I'll try to get the split out series
today, which might have a few more tweaks, and then we'll need to test it
both on these rpi4 setups and Amits phone.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2020-07-28  9:13 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-08 16:49 [PATCH] dma-pool: Do not allocate pool memory from CMA Nicolas Saenz Julienne
2020-07-08 16:49 ` Nicolas Saenz Julienne
2020-07-08 16:58 ` Christoph Hellwig
2020-07-08 16:58   ` Christoph Hellwig
2020-07-08 23:14 ` Jeremy Linton
2020-07-08 23:14   ` Jeremy Linton
2020-07-09 21:47 ` David Rientjes
2020-07-09 21:47   ` David Rientjes via iommu
2020-07-21  7:21 ` Amit Pundir
2020-07-21  7:21   ` Amit Pundir
2020-07-21  8:39   ` Nicolas Saenz Julienne
2020-07-21  8:39     ` Nicolas Saenz Julienne
2020-07-21  8:54     ` Amit Pundir
2020-07-21  8:54       ` Amit Pundir
2020-07-21 11:15       ` Nicolas Saenz Julienne
2020-07-21 11:15         ` Nicolas Saenz Julienne
2020-07-21 11:28         ` Christoph Hellwig
2020-07-21 11:28           ` Christoph Hellwig
2020-07-21 11:37           ` Nicolas Saenz Julienne
2020-07-21 11:37             ` Nicolas Saenz Julienne
2020-07-21 12:16             ` Amit Pundir
2020-07-21 12:16               ` Amit Pundir
2020-07-21 12:15         ` Amit Pundir
2020-07-21 12:15           ` Amit Pundir
2020-07-21 12:45           ` Nicolas Saenz Julienne
2020-07-21 12:45             ` Nicolas Saenz Julienne
2020-07-21 15:22             ` Amit Pundir
2020-07-21 15:22               ` Amit Pundir
2020-07-21 16:27               ` Nicolas Saenz Julienne
2020-07-21 16:27                 ` Nicolas Saenz Julienne
2020-07-23  5:14                 ` Amit Pundir
2020-07-23  5:14                   ` Amit Pundir
2020-07-24  9:36                   ` Nicolas Saenz Julienne
2020-07-24  9:36                     ` Nicolas Saenz Julienne
2020-07-24 11:06                     ` Amit Pundir
2020-07-24 11:06                       ` Amit Pundir
2020-07-24 13:41                       ` Christoph Hellwig
2020-07-24 13:41                         ` Christoph Hellwig
2020-07-24 16:19                         ` Amit Pundir
2020-07-24 16:19                           ` Amit Pundir
2020-07-24 16:27                           ` Christoph Hellwig
2020-07-24 16:27                             ` Christoph Hellwig
2020-07-27 17:56                         ` Nicolas Saenz Julienne
2020-07-27 17:56                           ` Nicolas Saenz Julienne
2020-07-28  9:13                           ` Christoph Hellwig [this message]
2020-07-28  9:13                             ` Christoph Hellwig
2020-07-28  9:30                             ` Nicolas Saenz Julienne
2020-07-28  9:30                               ` Nicolas Saenz Julienne
2020-07-28 10:09                               ` Christoph Hellwig
2020-07-28 10:09                                 ` Christoph Hellwig
2020-07-31  1:10                                 ` Nathan Chancellor
2020-07-31  1:10                                   ` Nathan Chancellor
2020-07-31  7:19                                   ` Amit Pundir
2020-07-31  7:19                                     ` Amit Pundir
2020-07-31 10:09                                   ` Nicolas Saenz Julienne
2020-07-31 10:09                                     ` Nicolas Saenz Julienne

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=20200728091335.GA23744@lst.de \
    --to=hch@lst.de \
    --cc=amit.pundir@linaro.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jeremy.linton@arm.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=m.szyprowski@samsung.com \
    --cc=nsaenzjulienne@suse.de \
    --cc=rientjes@google.com \
    --cc=robin.murphy@arm.com \
    --cc=sumit.semwal@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.