From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?iso-8859-1?Q?=D8rjan_Eide?= Subject: Re: [Linaro-mm-sig] [PATCH 2/4] staging: android: ion: Restrict cache maintenance to dma mapped memory Date: Thu, 7 Feb 2019 15:45:05 +0000 Message-ID: <20190207154502.GD3768@e106893-lin.trondheim.arm.com> References: <1547836667-13695-1-git-send-email-lmark@codeaurora.org> <1547836667-13695-3-git-send-email-lmark@codeaurora.org> <69b18f39-8ce0-3c4d-3528-dfab8399f24f@ti.com> <20190130113122.fipxgcmgrqggozcm@DESKTOP-E1NTVVP.localdomain> <20190206154021.GC3768@e106893-lin.trondheim.arm.com> <20190207073104.GA16222@infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20190207073104.GA16222@infradead.org> Content-Language: en-US Content-ID: Sender: linux-kernel-owner@vger.kernel.org To: Christoph Hellwig Cc: Brian Starkey , Liam Mark , "devel@driverdev.osuosl.org" , "tkjos@android.com" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linaro-mm-sig@lists.linaro.org" , "arve@android.com" , "joel@joelfernandes.org" , nd , "maco@android.com" , "christian@brauner.io" List-Id: dri-devel@lists.freedesktop.org On Wed, Feb 06, 2019 at 11:31:04PM -0800, Christoph Hellwig wrote: > The CPU may only access DMA mapped memory if ownership has been > transferred back to the CPU using dma_sync_{single,sg}_to_cpu, and then > before the device can access it again ownership needs to be transferred > back to the device using dma_sync_{single,sg}_to_device. >=20 > > I've run some testing, and this patch does indeed fix the crash in > > dma_sync_sg_for_cpu when it tried to use the 0 dma_address from the sg > > list. > >=20 > > Tested-by: =D8rjan Eide > >=20 > > I tested this on an older kernel, v4.14, since the dma-mapping code > > moved, in v4.19, to ignore the dma_address and instead use sg_phys() to > > get a valid address from the page, which is always valid in the ion sg > > lists. While this wouldn't crash on newer kernels, it's still good to > > avoid the unnecessary work when no CMO is needed. >=20 > Can you also test is with CONFIG_DMA_API_DEBUG enabled, as that should > catch all the usual mistakes in DMA API usage, including the one found? I checked again with CONFIG_DMA_API_DEBUG=3Dy, both with and without this patch, and I didn't get any dma-mapping errors.=20 The issue I hit, without this patch, is when a CPU access starts after a device have attached, which caused ion to create a copy of the buffer's sg list with dma_address zeroed, but before the device have mapped the buffer. --=20 =D8rjan