Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1736530

Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as a helper

From Robin Murphy <robin.murphy@arm.com>
Newsgroups linux.kernel
Subject Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as a helper
Date 2017-09-21 12:50 +0200
Message-ID <us7dn-8hx-1@gated-at.bofh.it> (permalink)
References <urmxP-1Xm-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 19/09/17 09:52, Huacai Chen wrote:
> We will use device_is_coherent() as a helper function, which will be
> used in the next patch.
> 
> There is a MIPS-specific plat_device_is_coherent(), but we need a more
> generic solution, so add and use a new function pointer in dma_map_ops.

I think we're heading in the right direction with the series, but I
still don't like this patch. I can pretty much guarantee that driver
authors *will* abuse a generic device_is_coherent() API to mean "I can
skip other DMA API calls and just use virt_to_phys()".

I think it would be far better to allow architectures to provide their
own override of dma_get_cache_alignment(), and let the coherency detail
remain internal to the relevant arch implementations.

[...]
> @@ -697,6 +698,15 @@ static inline void *dma_zalloc_coherent(struct device *dev, size_t size,
>  }
>  
>  #ifdef CONFIG_HAS_DMA
> +static inline int device_is_coherent(struct device *dev)
> +{
> +	const struct dma_map_ops *ops = get_dma_ops(dev);
> +	if (ops && ops->device_is_coherent)
> +		return ops->device_is_coherent(dev);
> +	else
> +		return 1;    /* compatible behavior */

That is also quite scary - if someone now adds a new
dma_get_cache_alignemnt() call and dutifully passes a non-NULL device,
they will now get back an alignment of 1 on all non-coherent platforms
except MIPS: hello data corruption.

Robin.

> +}
> +
>  static inline int dma_get_cache_alignment(void)
>  {
>  #ifdef ARCH_DMA_MINALIGN
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as a helper Huacai Chen <chenhc@lemote.com> - 2017-09-19 11:00 +0200
  [PATCH V6 2/3] dma-mapping: Rework dma_get_cache_alignment() function Huacai Chen <chenhc@lemote.com> - 2017-09-19 11:00 +0200
    Re: [PATCH V6 2/3] dma-mapping: Rework dma_get_cache_alignment()         function Christoph Hellwig <hch@lst.de> - 2017-09-19 17:10 +0200
      Re: [PATCH V6 2/3] dma-mapping: Rework dma_get_cache_alignment()function "陈华才" <chenhc@lemote.com> - 2017-09-21 06:30 +0200
        Re: [PATCH V6 2/3] dma-mapping: Rework         dma_get_cache_alignment()function Christoph Hellwig <hch@lst.de> - 2017-09-21 16:40 +0200
  Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as a  helper Robin Murphy <robin.murphy@arm.com> - 2017-09-21 12:50 +0200
    Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as ahelper "陈华才" <chenhc@lemote.com> - 2017-09-22 04:20 +0200
      Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as  ahelper Robin Murphy <robin.murphy@arm.com> - 2017-09-22 15:50 +0200
        Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as         ahelper Christoph Hellwig <hch@lst.de> - 2017-09-22 15:50 +0200

csiph-web