From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754982AbdIRPvl (ORCPT ); Mon, 18 Sep 2017 11:51:41 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:51164 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754465AbdIRPvi (ORCPT ); Mon, 18 Sep 2017 11:51:38 -0400 Date: Mon, 18 Sep 2017 08:51:34 -0700 From: Christoph Hellwig To: Robin Murphy Cc: Huacai Chen , Andrew Morton , Fuxin Zhang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [V5, 2/3] mm: dmapool: Align to ARCH_DMA_MINALIGN in non-coherent DMA mode Message-ID: <20170918155134.GC16672@infradead.org> References: <1505708548-4750-1-git-send-email-chenhc@lemote.com> <601437ae-2860-c48a-aa7c-4da37aeb6256@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <601437ae-2860-c48a-aa7c-4da37aeb6256@arm.com> User-Agent: Mutt/1.8.3 (2017-05-23) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 18, 2017 at 10:44:54AM +0100, Robin Murphy wrote: > On 18/09/17 05:22, Huacai Chen wrote: > > In non-coherent DMA mode, kernel uses cache flushing operations to > > maintain I/O coherency, so the dmapool objects should be aligned to > > ARCH_DMA_MINALIGN. Otherwise, it will cause data corruption, at least > > on MIPS: > > > > Step 1, dma_map_single > > Step 2, cache_invalidate (no writeback) > > Step 3, dma_from_device > > Step 4, dma_unmap_single > > This is a massive red warning flag for the whole series, because DMA > pools don't work like that. At best, this will do nothing, and at worst > it is papering over egregious bugs elsewhere. Streaming mappings of > coherent allocations means completely broken code. Oh, I hadn't even seen that part. Yes, dma coherent (and pool) allocations must never be used for streaming mappings. I wish we'd have some debug infrastructure to warn on such uses. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 18 Sep 2017 08:51:34 -0700 From: Christoph Hellwig To: Robin Murphy Cc: Huacai Chen , Andrew Morton , Fuxin Zhang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [V5, 2/3] mm: dmapool: Align to ARCH_DMA_MINALIGN in non-coherent DMA mode Message-ID: <20170918155134.GC16672@infradead.org> References: <1505708548-4750-1-git-send-email-chenhc@lemote.com> <601437ae-2860-c48a-aa7c-4da37aeb6256@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <601437ae-2860-c48a-aa7c-4da37aeb6256@arm.com> Sender: owner-linux-mm@kvack.org List-ID: On Mon, Sep 18, 2017 at 10:44:54AM +0100, Robin Murphy wrote: > On 18/09/17 05:22, Huacai Chen wrote: > > In non-coherent DMA mode, kernel uses cache flushing operations to > > maintain I/O coherency, so the dmapool objects should be aligned to > > ARCH_DMA_MINALIGN. Otherwise, it will cause data corruption, at least > > on MIPS: > > > > Step 1, dma_map_single > > Step 2, cache_invalidate (no writeback) > > Step 3, dma_from_device > > Step 4, dma_unmap_single > > This is a massive red warning flag for the whole series, because DMA > pools don't work like that. At best, this will do nothing, and at worst > it is papering over egregious bugs elsewhere. Streaming mappings of > coherent allocations means completely broken code. Oh, I hadn't even seen that part. Yes, dma coherent (and pool) allocations must never be used for streaming mappings. I wish we'd have some debug infrastructure to warn on such uses. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org