[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8230985e-1581-411f-895c-b49065234520@arm.com>
Date: Wed, 7 Aug 2024 14:13:06 +0100
From: Robin Murphy <robin.murphy@....com>
To: Baruch Siach <baruch@...s.co.il>, Christoph Hellwig <hch@....de>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>
Cc: iommu@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-s390@...r.kernel.org, Petr Tesařík
<petr@...arici.cz>, Ramon Fried <ramon@...reality.ai>,
Elad Nachman <enachman@...vell.com>
Subject: Re: [PATCH v5 1/3] dma: improve DMA zone selection
On 2024-08-02 7:03 am, Baruch Siach wrote:
> When device DMA limit does not fit in DMA32 zone it should use DMA zone,
> even when DMA zone is stricter than needed.
>
> Same goes for devices that can't allocate from the entire normal zone.
> Limit to DMA32 in that case.
Per the bot report this only works for CONFIG_ARCH_KEEP_MEMBLOCK,
however the whole concept looks wrong anyway. The logic here is that
we're only forcing a particular zone if there's *no* chance of the
higher zone being usable. For example, ignoring offsets for simplicity,
if we have a 40-bit DMA mask then we *do* want to initially try
allocating from ZONE_NORMAL even if max_pfn is above 40 bits, since we
still might get a usable allocation from between 32 and 40 bits, and if
we don't, then we'll fall back to retrying from the DMA zone(s) anyway.
I'm not sure if the rest of the series functionally depends on this
change, but I think it would be too needlessly restrictive in the
general case to be justified.
Thanks,
Robin.
> Reported-by: Catalin Marinas <catalin.marinas@....com>
> Reviewed-by: Catalin Marinas <catalin.marinas@....com>
> Signed-off-by: Baruch Siach <baruch@...s.co.il>
> ---
> kernel/dma/direct.c | 6 +++---
> kernel/dma/swiotlb.c | 4 ++--
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 4480a3cd92e0..3b4be4ca3b08 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -4,7 +4,7 @@
> *
> * DMA operations that map physical memory directly without using an IOMMU.
> */
> -#include <linux/memblock.h> /* for max_pfn */
> +#include <linux/memblock.h>
> #include <linux/export.h>
> #include <linux/mm.h>
> #include <linux/dma-map-ops.h>
> @@ -59,9 +59,9 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 *phys_limit)
> * zones.
> */
> *phys_limit = dma_to_phys(dev, dma_limit);
> - if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits))
> + if (*phys_limit < DMA_BIT_MASK(32))
> return GFP_DMA;
> - if (*phys_limit <= DMA_BIT_MASK(32))
> + if (*phys_limit < memblock_end_of_DRAM())
> return GFP_DMA32;
> return 0;
> }
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index df68d29740a0..043b0ecd3e8d 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -629,9 +629,9 @@ static struct page *swiotlb_alloc_tlb(struct device *dev, size_t bytes,
> }
>
> gfp &= ~GFP_ZONEMASK;
> - if (phys_limit <= DMA_BIT_MASK(zone_dma_bits))
> + if (phys_limit < DMA_BIT_MASK(32))
> gfp |= __GFP_DMA;
> - else if (phys_limit <= DMA_BIT_MASK(32))
> + else if (phys_limit < memblock_end_of_DRAM())
> gfp |= __GFP_DMA32;
>
> while (IS_ERR(page = alloc_dma_pages(gfp, bytes, phys_limit))) {
Powered by blists - more mailing lists