Skip to content

Commit e2f466e

Browse files
lynxeye-devtorvalds
authored andcommitted
mm: cma_alloc: allow to specify GFP mask
Most users of this interface just want to use it with the default GFP_KERNEL flags, but for cases where DMA memory is allocated it may be called from a different context. No functional change yet, just passing through the flag to the underlying alloc_contig_range function. Link: http://lkml.kernel.org/r/20170127172328.18574-2-l.stach@pengutronix.de Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Radim Krcmar <rkrcmar@redhat.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Chris Zankel <chris@zankel.net> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Alexander Graf <agraf@suse.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ca96b62 commit e2f466e

5 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎arch/powerpc/kvm/book3s_hv_builtin.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ struct page *kvm_alloc_hpt_cma(unsigned long nr_pages)
5656
{
5757
VM_BUG_ON(order_base_2(nr_pages) < KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
5858

59-
return cma_alloc(kvm_cma, nr_pages, order_base_2(HPT_ALIGN_PAGES));
59+
return cma_alloc(kvm_cma, nr_pages, order_base_2(HPT_ALIGN_PAGES),
60+
GFP_KERNEL);
6061
}
6162
EXPORT_SYMBOL_GPL(kvm_alloc_hpt_cma);
6263

‎drivers/base/dma-contiguous.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
193193
if (align > CONFIG_CMA_ALIGNMENT)
194194
align = CONFIG_CMA_ALIGNMENT;
195195

196-
return cma_alloc(dev_get_cma_area(dev), count, align);
196+
return cma_alloc(dev_get_cma_area(dev), count, align, GFP_KERNEL);
197197
}
198198

199199
/**

‎include/linux/cma.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern int __init cma_declare_contiguous(phys_addr_t base,
2929
extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
3030
unsigned int order_per_bit,
3131
struct cma **res_cma);
32-
extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align);
32+
extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
33+
gfp_t gfp_mask);
3334
extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count);
3435
#endif

‎mm/cma.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ int __init cma_declare_contiguous(phys_addr_t base,
357357
* This function allocates part of contiguous memory on specific
358358
* contiguous memory area.
359359
*/
360-
struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align)
360+
struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
361+
gfp_t gfp_mask)
361362
{
362363
unsigned long mask, offset;
363364
unsigned long pfn = -1;
@@ -403,7 +404,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align)
403404
pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
404405
mutex_lock(&cma_mutex);
405406
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,
406-
GFP_KERNEL);
407+
gfp_mask);
407408
mutex_unlock(&cma_mutex);
408409
if (ret == 0) {
409410
page = pfn_to_page(pfn);

‎mm/cma_debug.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int cma_alloc_mem(struct cma *cma, int count)
138138
if (!mem)
139139
return -ENOMEM;
140140

141-
p = cma_alloc(cma, count, 0);
141+
p = cma_alloc(cma, count, 0, GFP_KERNEL);
142142
if (!p) {
143143
kfree(mem);
144144
return -ENOMEM;

0 commit comments

Comments
 (0)