From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1432570AbdDYSFp (ORCPT ); Tue, 25 Apr 2017 14:05:45 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:57996 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S971581AbdDYSFh (ORCPT ); Tue, 25 Apr 2017 14:05:37 -0400 Date: Tue, 25 Apr 2017 19:05:26 +0100 From: Russell King - ARM Linux To: Catalin Marinas Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, geert@linux-m68k.org, a.hajda@samsung.com, robin.murphy@arm.com, Marek Szyprowski , Greg Kroah-Hartman Subject: Re: [RFC PATCH] drivers: dma-mapping: Do not attempt to create a scatterlist for from_coherent buffers Message-ID: <20170425180525.GT17774@n2100.armlinux.org.uk> References: <1493143059-2113-1-git-send-email-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1493143059-2113-1-git-send-email-catalin.marinas@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 25, 2017 at 06:57:39PM +0100, Catalin Marinas wrote: > Memory returned by dma_alloc_from_coherent() is not backed by struct > page and creating a scatterlist would use invalid page pointers. The > patch introduces the dma_vaddr_from_coherent() function and the > corresponding check in dma_get_sgtable_attrs(). > > Fixes: d2b7428eb0ca ("common: dma-mapping: introduce dma_get_sgtable() function") > Cc: Marek Szyprowski > Cc: Greg Kroah-Hartman > Cc: Russell King - ARM Linux > Signed-off-by: Catalin Marinas > --- > > In a recent discussion around the iommu DMA ops on arm64, Russell > pointed out that dma_get_sgtable is not safe since the coherent DMA > memory is not always backed by struct page. Russell has queued an > arm-specific patch checking for pfn_valid() but I thought I'd make a > more generic fix. This patch aims to bring the dma_get_sgtable() API in > line with the dma_alloc/mmap/free with respect to the from_coherent > memory. Sorry, I don't think this is the correct approach. You're assuming that 'vaddr' will always be a valid lowmem address. That isn't always the case - some dma coherent allocations provide remapped memory. The reason for dma_get_sgtable() existing is to coerce the DMA coherent memory into a scatterlist so that it can be passed through the dma_buf API - that's where the problem lies. The dma_buf API needs fixing so that coherent memory can be sanely passed, and dma_get_sgtable() needs to be put out of its misery. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.