History

cma: factor out minimum alignment requirement

Patch series "mm: enforce pageblock_order < MAX_ORDER". Having pageblock_order >= MAX_ORDER seems to be able to happen in corner cases and some parts of the kernel are not prepared for it. For example, Aneesh has shown [1] that such kernels can be compiled on ppc64 with 64k base pages by setting FORCE_MAX_ZONEORDER=8, which will run into a WARN_ON_ONCE(order >= MAX_ORDER) in comapction code right during boot. We can get pageblock_order >= MAX_ORDER when the default hugetlb size is bigger than the maximum allocation granularity of the buddy, in which case we are no longer talking about huge pages but instead gigantic pages. Having pageblock_order >= MAX_ORDER can only make alloc_contig_range() of such gigantic pages more likely to succeed. Reliable use of gigantic pages either requires boot time allcoation or CMA, no need to overcomplicate some places in the kernel to optimize for corner cases that are broken in other areas of the kernel. This patch (of 2): Let's enforce pageblock_order < MAX_ORDER and simplify. Especially patch #1 can be regarded a cleanup before: [PATCH v5 0/6] Use pageblock_order for cma and alloc_contig_range alignment. [2] [1] https://lkml.kernel.org/r/87r189a2ks.fsf@linux.ibm.com [2] https://lkml.kernel.org/r/20220211164135.1803616-1-zi.yan@sent.com Link: https://lkml.kernel.org/r/20220214174132.219303-2-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Zi Yan <ziy@nvidia.com> Acked-by: Rob Herring <robh@kernel.org> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Frank Rowand <frowand.list@gmail.com> Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: John Garry via iommu <iommu@lists.linux-foundation.org>

David Hildenbrand committed 4 years ago

Commit e16faf21 parent 56651376 files · +19 −30Browse files

Showing the changes to kernel (1 of 6 files). Show all

Unified · Split

kernel/dma/contiguous.c+1−3
@@ -399,8 +399,6 @@ static const struct reserved_mem_ops rmem_cma_ops = { · 398 unmodified lines
399 399
400static int __init rmem_cma_setup(struct reserved_mem *rmem)400static int __init rmem_cma_setup(struct reserved_mem *rmem)
401{401{
402 phys_addr_t align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order);
403 phys_addr_t mask = align - 1;
404 unsigned long node = rmem->fdt_node;402 unsigned long node = rmem->fdt_node;
405 bool default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL);403 bool default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL);
406 struct cma *cma;404 struct cma *cma;
@@ -416,7 +414,7 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem) · 9 unmodified lines
416 of_get_flat_dt_prop(node, "no-map", NULL))414 of_get_flat_dt_prop(node, "no-map", NULL))
417 return -EINVAL;415 return -EINVAL;
418 416
419 if ((rmem->base & mask) || (rmem->size & mask)) {417 if (!IS_ALIGNED(rmem->base | rmem->size, CMA_MIN_ALIGNMENT_BYTES)) {
420 pr_err("Reserved memory: incorrect alignment of CMA region\n");418 pr_err("Reserved memory: incorrect alignment of CMA region\n");
421 return -EINVAL;419 return -EINVAL;
422 }420 }