From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Hellwig Subject: Re: [PATCH 02/10] arm64/iommu: don't remap contiguous allocations for coherent devices Date: Mon, 10 Dec 2018 20:25:08 +0100 Message-ID: <20181210192508.GA31318@lst.de> References: <20181208173702.15158-1-hch@lst.de> <20181208173702.15158-3-hch@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Robin Murphy Cc: linux-parisc@vger.kernel.org, Vineet Gupta , linux-mips@vger.kernel.org, dri-devel@lists.freedesktop.org, "Matwey V. Kornilov" , iommu@lists.linux-foundation.org, openrisc@lists.librecores.org, Laurent Pinchart , sparclinux@vger.kernel.org, linux-snps-arc@lists.infradead.org, Ezequiel Garcia , Christoph Hellwig , linux-arm-kernel@vger.kernel.org, linux-media@vger.kernel.org List-Id: iommu@lists.linux-foundation.org T24gTW9uLCBEZWMgMTAsIDIwMTggYXQgMDc6MTk6MzBQTSArMDAwMCwgUm9iaW4gTXVycGh5IHdy b3RlOgo+IE9uIDA4LzEyLzIwMTggMTc6MzYsIENocmlzdG9waCBIZWxsd2lnIHdyb3RlOgo+PiBU aGVyZSBpcyBubyBuZWVkIHRvIGhhdmUgYW4gYWRkaXRpb25hbCBrZXJuZWwgbWFwcGluZyBmb3Ig YSBjb250aWd1b3VzCj4+IGFsbG9jYXRpb24gaWYgdGhlIGRldmljZSBhbHJlYWR5IGlzIERNQSBj b2hlcmVudCwgc28gc2tpcCBpdC4KPgo+IEZXSVcsIHRoZSAibmVlZCIgd2FzIHRoYXQgaXQga2Vw dCB0aGUgY29kZSBpbiB0aGlzIHBhdGggc2ltcGxlIGFuZCB0aGUgCj4gbWFwcGluZyBiZWhhdmlv dXIgY29uc2lzdGVudCB3aXRoIHRoZSByZWd1bGFyIGlvbW11X2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hZnRlciB6ZXJvaW5nIGl0IGxvb2tzIG9kZC4KX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVsIG1haWxp bmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlzdHMuZnJl ZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVsCg== From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.4 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D06CFC5CFFE for ; Mon, 10 Dec 2018 19:25:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 932562081F for ; Mon, 10 Dec 2018 19:25:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 932562081F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mips-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728725AbeLJTZK (ORCPT ); Mon, 10 Dec 2018 14:25:10 -0500 Received: from verein.lst.de ([213.95.11.211]:50698 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728067AbeLJTZK (ORCPT ); Mon, 10 Dec 2018 14:25:10 -0500 Received: by newverein.lst.de (Postfix, from userid 2407) id B9FD068DD2; Mon, 10 Dec 2018 20:25:08 +0100 (CET) Date: Mon, 10 Dec 2018 20:25:08 +0100 From: Christoph Hellwig To: Robin Murphy Cc: Christoph Hellwig , iommu@lists.linux-foundation.org, Vineet Gupta , "Matwey V. Kornilov" , Laurent Pinchart , linux-snps-arc@lists.infradead.org, Ezequiel Garcia , linux-media@vger.kernel.org, linux-arm-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, sparclinux@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linux-mips@vger.kernel.org Subject: Re: [PATCH 02/10] arm64/iommu: don't remap contiguous allocations for coherent devices Message-ID: <20181210192508.GA31318@lst.de> References: <20181208173702.15158-1-hch@lst.de> <20181208173702.15158-3-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On Mon, Dec 10, 2018 at 07:19:30PM +0000, Robin Murphy wrote: > On 08/12/2018 17:36, Christoph Hellwig wrote: >> There is no need to have an additional kernel mapping for a contiguous >> allocation if the device already is DMA coherent, so skip it. > > FWIW, the "need" was that it kept the code in this path simple and the > mapping behaviour consistent with the regular iommu_dma_alloc() case. One > could quite easily retort that there is no need for the extra complexity of > this patch, since vmalloc is cheap on a 64-bit architecture ;) Heh. Well, without the remap we do less work, we prepare for a simple implementation of DMA_ATTR_NON_CONSISTENT, and also prepapre the code to be better reusable for architectures that don't do remapping of DMA allocations at all. >> if (addr) { >> memset(addr, 0, size); >> - if (!coherent) >> - __dma_flush_area(page_to_virt(page), iosize); >> + __dma_flush_area(page_to_virt(page), iosize); > > Oh poo - seems I missed it at the time but the existing logic here is > wrong. Let me send a separate fix to flip those statements into the correct > order... Yes, flushing the remapped alias only after zeroing it looks odd. From mboxrd@z Thu Jan 1 00:00:00 1970 From: hch@lst.de (Christoph Hellwig) Date: Mon, 10 Dec 2018 20:25:08 +0100 Subject: [PATCH 02/10] arm64/iommu: don't remap contiguous allocations for coherent devices In-Reply-To: References: <20181208173702.15158-1-hch@lst.de> <20181208173702.15158-3-hch@lst.de> List-ID: Message-ID: <20181210192508.GA31318@lst.de> To: linux-snps-arc@lists.infradead.org On Mon, Dec 10, 2018@07:19:30PM +0000, Robin Murphy wrote: > On 08/12/2018 17:36, Christoph Hellwig wrote: >> There is no need to have an additional kernel mapping for a contiguous >> allocation if the device already is DMA coherent, so skip it. > > FWIW, the "need" was that it kept the code in this path simple and the > mapping behaviour consistent with the regular iommu_dma_alloc() case. One > could quite easily retort that there is no need for the extra complexity of > this patch, since vmalloc is cheap on a 64-bit architecture ;) Heh. Well, without the remap we do less work, we prepare for a simple implementation of DMA_ATTR_NON_CONSISTENT, and also prepapre the code to be better reusable for architectures that don't do remapping of DMA allocations at all. >> if (addr) { >> memset(addr, 0, size); >> - if (!coherent) >> - __dma_flush_area(page_to_virt(page), iosize); >> + __dma_flush_area(page_to_virt(page), iosize); > > Oh poo - seems I missed it at the time but the existing logic here is > wrong. Let me send a separate fix to flip those statements into the correct > order... Yes, flushing the remapped alias only after zeroing it looks odd. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Hellwig Date: Mon, 10 Dec 2018 20:25:08 +0100 Subject: [OpenRISC] [PATCH 02/10] arm64/iommu: don't remap contiguous allocations for coherent devices In-Reply-To: References: <20181208173702.15158-1-hch@lst.de> <20181208173702.15158-3-hch@lst.de> Message-ID: <20181210192508.GA31318@lst.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: openrisc@lists.librecores.org On Mon, Dec 10, 2018 at 07:19:30PM +0000, Robin Murphy wrote: > On 08/12/2018 17:36, Christoph Hellwig wrote: >> There is no need to have an additional kernel mapping for a contiguous >> allocation if the device already is DMA coherent, so skip it. > > FWIW, the "need" was that it kept the code in this path simple and the > mapping behaviour consistent with the regular iommu_dma_alloc() case. One > could quite easily retort that there is no need for the extra complexity of > this patch, since vmalloc is cheap on a 64-bit architecture ;) Heh. Well, without the remap we do less work, we prepare for a simple implementation of DMA_ATTR_NON_CONSISTENT, and also prepapre the code to be better reusable for architectures that don't do remapping of DMA allocations at all. >> if (addr) { >> memset(addr, 0, size); >> - if (!coherent) >> - __dma_flush_area(page_to_virt(page), iosize); >> + __dma_flush_area(page_to_virt(page), iosize); > > Oh poo - seems I missed it at the time but the existing logic here is > wrong. Let me send a separate fix to flip those statements into the correct > order... Yes, flushing the remapped alias only after zeroing it looks odd. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Hellwig Date: Mon, 10 Dec 2018 19:25:08 +0000 Subject: Re: [PATCH 02/10] arm64/iommu: don't remap contiguous allocations for coherent devices Message-Id: <20181210192508.GA31318@lst.de> List-Id: References: <20181208173702.15158-1-hch@lst.de> <20181208173702.15158-3-hch@lst.de> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Robin Murphy Cc: linux-parisc@vger.kernel.org, Vineet Gupta , linux-mips@vger.kernel.org, dri-devel@lists.freedesktop.org, "Matwey V. Kornilov" , iommu@lists.linux-foundation.org, openrisc@lists.librecores.org, Laurent Pinchart , sparclinux@vger.kernel.org, linux-snps-arc@lists.infradead.org, Ezequiel Garcia , Christoph Hellwig , linux-arm-kernel@vger.kernel.org, linux-media@vger.kernel.org On Mon, Dec 10, 2018 at 07:19:30PM +0000, Robin Murphy wrote: > On 08/12/2018 17:36, Christoph Hellwig wrote: >> There is no need to have an additional kernel mapping for a contiguous >> allocation if the device already is DMA coherent, so skip it. > > FWIW, the "need" was that it kept the code in this path simple and the > mapping behaviour consistent with the regular iommu_dma_alloc() case. One > could quite easily retort that there is no need for the extra complexity of > this patch, since vmalloc is cheap on a 64-bit architecture ;) Heh. Well, without the remap we do less work, we prepare for a simple implementation of DMA_ATTR_NON_CONSISTENT, and also prepapre the code to be better reusable for architectures that don't do remapping of DMA allocations at all. >> if (addr) { >> memset(addr, 0, size); >> - if (!coherent) >> - __dma_flush_area(page_to_virt(page), iosize); >> + __dma_flush_area(page_to_virt(page), iosize); > > Oh poo - seems I missed it at the time but the existing logic here is > wrong. Let me send a separate fix to flip those statements into the correct > order... Yes, flushing the remapped alias only after zeroing it looks odd.