[PATCH 1/2] dma-pool: fix coherent pool allocations for IOMMU mappings

Nicolas Saenz Julienne nsaenzjulienne at suse.de
Tue Jul 28 10:56:29 EDT 2020


On Tue, 2020-07-28 at 12:47 +0200, Christoph Hellwig wrote:
> When allocating coherent pool memory for an IOMMU mapping we don't care
> about the DMA mask.  Move the guess for the initial GFP mask into the
> dma_direct_alloc_pages and pass dma_coherent_ok as a function pointer
> argument so that it doesn't get applied to the IOMMU case.
> 
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
>  drivers/iommu/dma-iommu.c   |   4 +-
>  include/linux/dma-direct.h  |   3 -
>  include/linux/dma-mapping.h |   5 +-
>  kernel/dma/direct.c         |  13 ++--
>  kernel/dma/pool.c           | 114 +++++++++++++++---------------------
>  5 files changed, 62 insertions(+), 77 deletions(-)
> 

[...]

> -static inline struct gen_pool *dma_get_safer_pool(struct gen_pool *bad_pool)
> +static struct page *__dma_alloc_from_pool(struct device *dev, size_t size,
> +		struct gen_pool *pool, void **cpu_addr,
> +		bool (*phys_addr_ok)(struct device *, phys_addr_t, size_t))
>  {
> -	if (bad_pool == atomic_pool_kernel)
> -		return atomic_pool_dma32 ? : atomic_pool_dma;
> +	unsigned long addr;
> +	phys_addr_t phys;
>  
> -	if (bad_pool == atomic_pool_dma32)
> -		return atomic_pool_dma;
> +	addr = gen_pool_alloc(pool, size);
> +	if (!addr)
> +		return NULL;
>  
> -	return NULL;
> -}
> +	phys = gen_pool_virt_to_phys(pool, addr);
> +	if (!phys_addr_ok(dev, phys, size)) {

Shoudn't we check if phys_addr_ok() != NULL?

Regards,
Nicolas


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-rpi-kernel/attachments/20200728/4066d3cf/attachment.sig>


More information about the linux-rpi-kernel mailing list