From: Nicolin Chen <nicoleotsuka@gmail.com>
To: hch@lst.de, robin.murphy@arm.com
Cc: vdumpa@nvidia.com, linux@armlinux.org.uk,
catalin.marinas@arm.com, will.deacon@arm.com, joro@8bytes.org,
m.szyprowski@samsung.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
tony@atomide.com
Subject: [PATCH v2 RFC/RFT 4/5] arm64: dma-mapping: Add fallback normal page allocations
Date: Tue, 26 Mar 2019 16:01:30 -0700 [thread overview]
Message-ID: <20190326230131.16275-5-nicoleotsuka@gmail.com> (raw)
In-Reply-To: <20190326230131.16275-1-nicoleotsuka@gmail.com>
The cma allocation will skip allocations of single pages to save CMA
resource. This requires its callers to rebound those page allocations
from normal area. So this patch adds fallback routines.
Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
---
arch/arm64/mm/dma-mapping.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 78c0a72f822c..be2302533334 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -156,17 +156,20 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size,
}
} else if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) {
pgprot_t prot = arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs);
+ unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
struct page *page;
- page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT,
- get_order(size), gfp & __GFP_NOWARN);
+ page = dma_alloc_from_contiguous(dev, count, get_order(size),
+ gfp & __GFP_NOWARN);
+ if (!page)
+ page = alloc_pages(gfp, get_order(size));
if (!page)
return NULL;
*handle = iommu_dma_map_page(dev, page, 0, iosize, ioprot);
if (*handle == DMA_MAPPING_ERROR) {
- dma_release_from_contiguous(dev, page,
- size >> PAGE_SHIFT);
+ if (!dma_release_from_contiguous(dev, page, count))
+ __free_pages(page, get_order(size));
return NULL;
}
addr = dma_common_contiguous_remap(page, size, VM_USERMAP,
@@ -178,8 +181,8 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size,
memset(addr, 0, size);
} else {
iommu_dma_unmap_page(dev, *handle, iosize, 0, attrs);
- dma_release_from_contiguous(dev, page,
- size >> PAGE_SHIFT);
+ if (!dma_release_from_contiguous(dev, page, count))
+ __free_pages(page, get_order(size));
}
} else {
pgprot_t prot = arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs);
@@ -201,6 +204,7 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size,
static void __iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr,
dma_addr_t handle, unsigned long attrs)
{
+ unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
size_t iosize = size;
size = PAGE_ALIGN(size);
@@ -222,7 +226,8 @@ static void __iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr,
struct page *page = vmalloc_to_page(cpu_addr);
iommu_dma_unmap_page(dev, handle, iosize, 0, attrs);
- dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT);
+ if (!dma_release_from_contiguous(dev, page, count))
+ __free_pages(page, get_order(size));
dma_common_free_remap(cpu_addr, size, VM_USERMAP);
} else if (is_vmalloc_addr(cpu_addr)){
struct vm_struct *area = find_vm_area(cpu_addr);
--
2.17.1
next prev parent reply other threads:[~2019-03-26 23:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 23:01 [PATCH v2 RFC/RFT 0/5] Save single pages from CMA area Nicolin Chen
2019-03-26 23:01 ` [PATCH v2 RFC/RFT 1/5] ARM: dma-mapping: Add fallback normal page allocations Nicolin Chen
2019-04-24 15:06 ` Christoph Hellwig
2019-04-24 15:08 ` Christoph Hellwig
2019-04-24 18:33 ` Nicolin Chen
2019-04-24 19:26 ` Christoph Hellwig
2019-04-24 19:38 ` Nicolin Chen
2019-04-30 15:24 ` Catalin Marinas
2019-05-02 13:26 ` Christoph Hellwig
2019-04-26 20:21 ` Nicolin Chen
2019-04-26 20:25 ` Christoph Hellwig
2019-03-26 23:01 ` [PATCH v2 RFC/RFT 2/5] dma-remap: Run alloc_pages() on failure Nicolin Chen
2019-03-26 23:01 ` [PATCH v2 RFC/RFT 3/5] iommu: amd_iommu: Add fallback normal page allocations Nicolin Chen
2019-03-26 23:01 ` Nicolin Chen [this message]
2019-03-26 23:01 ` [PATCH v2 RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Nicolin Chen
2019-03-27 8:08 ` [PATCH v2 RFC/RFT 0/5] Save single pages " Christoph Hellwig
2019-03-27 18:42 ` Nicolin Chen
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=20190326230131.16275-5-nicoleotsuka@gmail.com \
--to=nicoleotsuka@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=tony@atomide.com \
--cc=vdumpa@nvidia.com \
--cc=will.deacon@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).