From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751107AbdEaL40 (ORCPT ); Wed, 31 May 2017 07:56:26 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:27912 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751022AbdEaL4Y (ORCPT ); Wed, 31 May 2017 07:56:24 -0400 Subject: Re: RE: [PATCH v3 0/2] usb: Check for DMA capable buffer sanity To: David Laight , "'Wolfram Sang'" , Florian Fainelli CC: "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , Felipe Balbi , Peter Chen , Roger Quadros , Alan Stern , Mathias Nyman , Javier Martinez Canillas , Baoyou Xie , Sekhar Nori , William wu , Arnd Bergmann , Chris Bainbridge , Wolfram Sang , Krzysztof Opasiak , =?UTF-8?Q?Felix_H=c3=a4dicke?= , Colin Ian King , "open list:USB SUBSYSTEM" , "clemens@ladisch.de" , "maksim.salau@gmail.com" References: <20170426005612.24850-1-f.fainelli@gmail.com> <84087586-d5fc-3115-4b16-93c75e411c59@gmail.com> <20170528160330.xjseehf6nnoooe75@ninjato> <063D6719AE5E284EB5DD2968C1650D6DD0005BB4@AcuExch.aculab.com> From: Vignesh R Message-ID: <3619ab73-b9f0-89b8-a8e8-b6600a0bf73d@ti.com> Date: Wed, 31 May 2017 17:25:48 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DD0005BB4@AcuExch.aculab.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday 31 May 2017 04:34 PM, David Laight wrote: > From: Wolfram Sang >> Sent: 28 May 2017 17:04 >> >> On Fri, May 05, 2017 at 02:08:31PM -0700, Florian Fainelli wrote: >>> On 04/25/2017 05:56 PM, Florian Fainelli wrote: >>>> Changes in v3: >>>> >>>> - added check in usb_gadget_map_request_by_dev (Felipe), new patch >>>> - improved commit message description (Clemens) >>>> - added additiona checks for urb->setup_packet (Alan) >>>> >>>> Changes in v2: >>>> >>>> - moved the check from usb_start_wait_urb() to usb_hcd_map_urb_for_dma() >>> >>> Is this version looking good now? Thanks! >> >> So, it seems I am in a similar situation with the I2C subsystem right >> now. I need to check the message buffers if they are DMA capable. >> >> Because you have basically the same checks in 3 different places, and I >> need something similar for I2C, I wondered about a generic place to put >> these checks. Especially since we want future improvements to these >> checks applied everywhere immediately. Here is a small diff on what I >> have now: > ... >> + } else if (!is_dma_capable_addr(urb->transfer_buffer)) { > > For a generic function I'd pass the length as well. > It might be that buffers that don't cross page boundaries might be > deemed 'dma-able'. > > Possibly more useful would be a variant of (IIRC) dma_map_for_device() > that will allocate a suitable bounce buffer for non-dma memory. > I think it can already do so for memory that is outside the address > range that the device can address (eg for a 32bit PCIe master in 64bit > system). > Such generic DMA API would be greatly useful! I tried adding bounce buffers support to handle vmalloc'd buffers in MTD/SPI subsystem. But, there was a need felt for generic DMA API that can allocate bounce buffer for non-dma'able buffers that all drivers can make use of[1][2] [1] https://lkml.org/lkml/2017/3/1/488 [2] https://lkml.org/lkml/2017/4/25/278 -- Regards Vignesh