linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Kuzmichev <vitaly_kuzmichev@mentor.com>
To: <gregkh@linuxfoundation.org>
Cc: <hch@lst.de>, <m.szyprowski@samsung.com>, <robin.murphy@arm.com>,
	<linux-kernel@vger.kernel.org>, <linux-next@vger.kernel.org>,
	"George G. Davis" <george_davis@mentor.com>
Subject: [PATCH v2 1/2] drivers: dma-coherent: Fix dev->cma_area vs dev->dma_mem breakage
Date: Fri, 7 Jul 2017 16:22:59 +0300	[thread overview]
Message-ID: <1499433779-16437-1-git-send-email-vitaly_kuzmichev@mentor.com> (raw)
In-Reply-To: <1499433759-16397-1-git-send-email-vitaly_kuzmichev@mentor.com>

From: "George G. Davis" <george_davis@mentor.com>

When a "linux,dma-default" DMA coherent region is defined, the
dma_coherent_default_memory pointer is returned by function
dev_get_coherent_memory() for any struct device *dev which has not
explicitly assigned a dev->dma_mem memory region, i.e. dev->dma_mem is
the NULL pointer. Unfortunately this overlooks the fact that for the
CONFIG_DMA_CMA case, it is also possible that a device may have assigned
a CMA memory region via the dev->cma_area pointer in which case,
the "linux,dma-default" DMA coherent region should not be used.
Since the current code did not consider this case, dev->cma_area regions
are not used when a "linux,dma-default" DMA coherent region is defined.
Instead, memory is allocated from the "linux,dma-default" DMA coherent
region.  This omission could lead to DMA memory allocation failures for
devices such as the "viv,galcore" which require a large contiguous
address space which cannot be supplied by the "linux,dma-default" region
IFF it has been reconfigured to use a CMA memory region. Similar DMA
allocation failures are likely to occur for other devices which require
large memory regions and/or overall allocation requests exceed the size
of the "linux,dma-default" DMA coherent region size.

Fix this by updating the dev_get_coherent_memory() function to return
the NULL pointer if a dev->cma_area region is assigned to a device.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: George G. Davis <george_davis@mentor.com>
Signed-off-by: Vitaly Kuzmichev <vitaly_kuzmichev@mentor.com>
---
 drivers/base/dma-coherent.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
index 2ae24c2..acfe140 100644
--- a/drivers/base/dma-coherent.c
+++ b/drivers/base/dma-coherent.c
@@ -25,6 +25,10 @@ static inline struct dma_coherent_mem *dev_get_coherent_memory(struct device *de
 {
 	if (dev && dev->dma_mem)
 		return dev->dma_mem;
+#ifdef CONFIG_DMA_CMA
+	if (dev && dev->cma_area)
+		return NULL;
+#endif
 	return dma_coherent_default_memory;
 }
 
-- 
1.9.1

  reply	other threads:[~2017-07-07 13:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-03 14:51 [PATCH 0/2] Implement default DMA coherent pool vitaly_kuzmichev
2017-07-03 14:51 ` [PATCH 1/2] drivers: dma-coherent: Add support for " vitaly_kuzmichev
2017-07-04 21:02   ` kbuild test robot
2017-07-05  5:55   ` kbuild test robot
2017-07-10  0:36   ` Rob Herring
2017-07-03 14:51 ` [PATCH 2/2] drivers: dma-coherent: show per-device DMA region utilization via procfs vitaly_kuzmichev
2017-07-07 13:22 ` [PATCH v2 0/2] Additions to default DMA coherent pool Vitaly Kuzmichev
2017-07-07 13:22   ` Vitaly Kuzmichev [this message]
2017-07-07 14:27     ` [PATCH v2 1/2] drivers: dma-coherent: Fix dev->cma_area vs dev->dma_mem breakage Christoph Hellwig
2017-07-07 15:40       ` Vladimir Murzin
2017-07-07 16:06         ` Robin Murphy
2017-07-07 16:44           ` Vladimir Murzin
2017-07-07 17:55             ` Robin Murphy
2017-07-10 13:42               ` Vladimir Murzin
2017-07-11 14:19           ` Christoph Hellwig
2017-07-07 13:23   ` [PATCH v2 2/2] drivers: dma-coherent: show per-device DMA region utilization via procfs Vitaly Kuzmichev
2017-07-07 14:28     ` Christoph Hellwig
2017-07-07 13:55   ` [PATCH v2 0/2] Additions to default DMA coherent pool Stephen Rothwell

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=1499433779-16437-1-git-send-email-vitaly_kuzmichev@mentor.com \
    --to=vitaly_kuzmichev@mentor.com \
    --cc=george_davis@mentor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.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;
as well as URLs for NNTP newsgroup(s).