From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751830AbdIVCOI (ORCPT ); Thu, 21 Sep 2017 22:14:08 -0400 Received: from smtpbg65.qq.com ([103.7.28.233]:20625 "EHLO smtpbg65.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751653AbdIVCOG (ORCPT ); Thu, 21 Sep 2017 22:14:06 -0400 X-QQ-GoodBg: 0 X-QQ-SSF: 00100000000000F0 X-QQ-FEAT: t/i7ssdcq51q4qa3PbvR8qSt8i31KgFIUGp5+uK0sNdu+EFJXEFPlFAze+fet +jFe7iFTwxOHmiYvDwSF1YO1sIppQmx/z+7PpoZUEfErsVcxp+E/7GNfxlul/hpGp1jL46L Q2hoCsJc38zAFc9Hxs+3GaxR/UOuzNHaavzbzbHPjZm8YKi33KrfBrvrk3727/m64qOxy2s NpMdHhn2mGeNxOPMeFF6Z4ffSLCbNFbg6MC6xnoUqtbYj8CNXKbDY+LPVZ0mH/yY0bq2ceh uVgPP2+JnzHzDoDa9o5DiP0Ng= X-QQ-BUSINESS-ORIGIN: 2 X-Originating-IP: 222.92.124.153 X-QQ-STYLE: X-QQ-mid: bizmailfree34t1506046430t9338 From: "=?utf-8?B?6ZmI5Y2O5omN?=" To: "=?utf-8?B?Um9iaW4gTXVycGh5?=" , "=?utf-8?B?Q2hyaXN0b3BoIEhlbGx3aWc=?=" Cc: "=?utf-8?B?TWFyZWsgU3p5cHJvd3NraQ==?=" , "=?utf-8?B?QW5kcmV3IE1vcnRvbg==?=" , "=?utf-8?B?RnV4aW4gWmhhbmc=?=" , "=?utf-8?B?bGludXgta2VybmVs?=" , "=?utf-8?B?SmFtZXMgRSAuIEogLiBCb3R0b21sZXk=?=" , "=?utf-8?B?TWFydGluIEsgLiBQZXRlcnNlbg==?=" , "=?utf-8?B?bGludXgtc2NzaQ==?=" , "=?utf-8?B?c3RhYmxl?=" Subject: Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as ahelper Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Date: Fri, 22 Sep 2017 10:13:50 +0800 X-Priority: 3 Message-ID: X-QQ-MIME: TCMime 1.0 by Tencent X-Mailer: QQMail 2.x X-QQ-Mailer: QQMail 2.x References: <1505811161-25246-1-git-send-email-chenhc@lemote.com> <5e792b21-1d63-9200-b36a-c423385e2a2e@arm.com> In-Reply-To: <5e792b21-1d63-9200-b36a-c423385e2a2e@arm.com> X-QQ-ReplyHash: 3232152103 X-QQ-SENDSIZE: 520 Feedback-ID: bizmailfree:lemote.com:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id v8M2EDSR025584 Hi, Robin, Before 2.6.36 dma_get_cache_alignment is arch-dependent, and it is unified in commit 4565f0170dfc849b3629c27d7 ("dma-mapping: unify dma_get_cache_alignment implementations"). Should we revert to the old implementation? Huacai ------------------ Original ------------------ From: "Robin Murphy"; Date: Thu, Sep 21, 2017 06:47 PM To: "Huacai Chen"; "Christoph Hellwig"; Cc: "Marek Szyprowski"; "Andrew Morton"; "Fuxin Zhang"; "linux-kernel"; "James E . J . Bottomley"; "Martin K . Petersen"; "linux-scsi"; "stable"; Subject: Re: [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as ahelper 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 >