Re: [PATCH v6 0/9] i2c: document DMA handling and add helpers for it
On Mon, 4 Dec 2017 22:05:41 + Mark Brownwrote: > On Sun, Dec 03, 2017 at 08:43:47PM +0100, Wolfram Sang wrote: > > > > It's a bit different in that it's much more likely that a SPI controller > > > will actually do DMA than an I2C one since the speeds are higher and > > > there's frequent applications that do large transfers so it's more > > > likely that people will do the right thing as issues would tend to come > > > up if they don't. > > > Yes, for SPI this is true. I was thinking more of regmap with its > > usage of different transport mechanisms. But I guess they should all be > > DMA safe because some of them need to be DMA safe? > > Possibly. Hopefully. I guess we'll find out. > Yeah, optimistic assumption. Plenty of drivers use regmap for the convenience of it's caching and field access etc rather than because they support multiple buses. I'll audit the IIO drivers and see where we have issues if we start assuming DMA safe for regmap (which makes sense to me). Probably worth fixing them all up anyway and tends to be straightforward. Jonathan
Re: [PATCH v6 0/9] i2c: document DMA handling and add helpers for it
On Sun, Dec 03, 2017 at 08:43:47PM +0100, Wolfram Sang wrote: > > It's a bit different in that it's much more likely that a SPI controller > > will actually do DMA than an I2C one since the speeds are higher and > > there's frequent applications that do large transfers so it's more > > likely that people will do the right thing as issues would tend to come > > up if they don't. > Yes, for SPI this is true. I was thinking more of regmap with its > usage of different transport mechanisms. But I guess they should all be > DMA safe because some of them need to be DMA safe? Possibly. Hopefully. I guess we'll find out. signature.asc Description: PGP signature
Re: [PATCH v6 0/9] i2c: document DMA handling and add helpers for it
On Sat, Nov 04, 2017 at 09:20:00PM +0100, Wolfram Sang wrote: > So, after revisiting old mail threads, taking part in a similar discussion on > the USB list, and implementing a not-convincing solution before, here is what > I > cooked up to document and ease DMA handling for I2C within Linux. Please have > a > look at the documentation introduced in patch 7 for details. And to make it > clear again: The stuff below is opt-in. If host drivers are not updated, they > will continue to work like before. > > While previous versions until v3 tried to magically apply bounce buffers when > needed, it became clear that detecting DMA safe buffers is too fragile. This > approach is now opt-in, a DMA_SAFE flag needs to be set on an i2c_msg. The > outcome so far is very convincing IMO. The core additions are simple and easy > to understand. The driver changes for the Renesas IP cores became easy to > understand, too. > > Of course, we must now whitelist DMA safe buffers. This series implements it > for core functionality: > > a) for the I2C_RDWR when messages come from userspace > b) for i2c_smbus_xfer_emulated(), DMA safe buffers are now allocated for >block transfers > c) i2c_master_{send|recv} have now a *_dmasafe variant > > I am still not sure how we can teach regmap this new flag. regmap is a heavy > user of I2C, so broonie's opinion here would be great to have. The rest should > mostly be updating individual drivers which can be done when needed. > > All patches have been tested with a Renesas Salvator-X board (r8a7796/M3-W) > and > Renesas Lager board (r8a7790/H2). But more testing is really really welcome. > > The branch can be found here: > > git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git > renesas/topic/i2c-core-dma-v6 > > It is planned to land upstream in v4.16 and I want to push it to linux-next > early after v4.15 to get lots of testing for the core changes. > > Big kudos to Renesas Electronics for funding this work, thank you very much! > > Regards, > >Wolfram Applied to for-next after fixing some cosmetic checkpatch issues! signature.asc Description: PGP signature
Re: [PATCH v6 0/9] i2c: document DMA handling and add helpers for it
> > > We pretty much assume everything is DMA safe already, the majority of > > > transfers go to/from kmalloc()ed scratch buffers so actually are DMA > > > safe but for bulk transfers we use the caller buffer and there might be > > > some problem users. > > > So, pretty much the situation I2C was in before this patch set: we > > pretty much assume DMA safety but there might be problem users. > > It's a bit different in that it's much more likely that a SPI controller > will actually do DMA than an I2C one since the speeds are higher and > there's frequent applications that do large transfers so it's more > likely that people will do the right thing as issues would tend to come > up if they don't. Yes, for SPI this is true. I was thinking more of regmap with its usage of different transport mechanisms. But I guess they should all be DMA safe because some of them need to be DMA safe? > > > I can't really think of a particularly good way of > > > handling it off the top of my head, obviously not setting the flag is > > > easy but doesn't get the benefit while always using a bounce buffer > > > would involve lots of unneeded memcpy(). Doing _dmasafe() isn't > > > particularly appealing either but might be what we end up with. > > > Okay. That sounds you are fine with the approach taken here, in general? > > It's hard to summon enthusiasm but yes, without changes to the DMA stuff > it's probably as good as we can do. That sums it up pretty nicely. However, despite even my limited enthusiasm for this extra flag, I think this set of rules has value. For some platforms, DMA works more or less by coincidence and can lead to surprises with e.g. virtual stacks. This is not good engineering practice, I'd say. I am going to apply this series now. Thanks for your input! signature.asc Description: PGP signature
Re: [PATCH v6 0/9] i2c: document DMA handling and add helpers for it
On Mon, Nov 27, 2017 at 07:51:16PM +0100, Wolfram Sang wrote: > On Wed, Nov 08, 2017 at 10:50:37PM +, Mark Brown wrote: > > We pretty much assume everything is DMA safe already, the majority of > > transfers go to/from kmalloc()ed scratch buffers so actually are DMA > > safe but for bulk transfers we use the caller buffer and there might be > > some problem users. > So, pretty much the situation I2C was in before this patch set: we > pretty much assume DMA safety but there might be problem users. It's a bit different in that it's much more likely that a SPI controller will actually do DMA than an I2C one since the speeds are higher and there's frequent applications that do large transfers so it's more likely that people will do the right thing as issues would tend to come up if they don't. > > I can't really think of a particularly good way of > > handling it off the top of my head, obviously not setting the flag is > > easy but doesn't get the benefit while always using a bounce buffer > > would involve lots of unneeded memcpy(). Doing _dmasafe() isn't > > particularly appealing either but might be what we end up with. > Okay. That sounds you are fine with the approach taken here, in general? It's hard to summon enthusiasm but yes, without changes to the DMA stuff it's probably as good as we can do. signature.asc Description: PGP signature
Re: [PATCH v6 0/9] i2c: document DMA handling and add helpers for it
On Wed, Nov 08, 2017 at 10:50:37PM +, Mark Brown wrote: > On Sat, Nov 04, 2017 at 09:20:00PM +0100, Wolfram Sang wrote: > > > While previous versions until v3 tried to magically apply bounce buffers > > when > > needed, it became clear that detecting DMA safe buffers is too fragile. This > > approach is now opt-in, a DMA_SAFE flag needs to be set on an i2c_msg. The > > outcome so far is very convincing IMO. The core additions are simple and > > easy > > to understand. The driver changes for the Renesas IP cores became easy to > > understand, too. > > It would really help a lot of things if there were a way to detect if a > given memory block is DMA safe, having to pass the information around > causes so much pain. I so agree. > > I am still not sure how we can teach regmap this new flag. regmap is a heavy > > user of I2C, so broonie's opinion here would be great to have. The rest > > should > > mostly be updating individual drivers which can be done when needed. > > We pretty much assume everything is DMA safe already, the majority of > transfers go to/from kmalloc()ed scratch buffers so actually are DMA > safe but for bulk transfers we use the caller buffer and there might be > some problem users. So, pretty much the situation I2C was in before this patch set: we pretty much assume DMA safety but there might be problem users. > I can't really think of a particularly good way of > handling it off the top of my head, obviously not setting the flag is > easy but doesn't get the benefit while always using a bounce buffer > would involve lots of unneeded memcpy(). Doing _dmasafe() isn't > particularly appealing either but might be what we end up with. Okay. That sounds you are fine with the approach taken here, in general? Thanks, Wolfram signature.asc Description: PGP signature
Re: [PATCH v6 0/9] i2c: document DMA handling and add helpers for it
On Sat, Nov 04, 2017 at 09:20:00PM +0100, Wolfram Sang wrote: > While previous versions until v3 tried to magically apply bounce buffers when > needed, it became clear that detecting DMA safe buffers is too fragile. This > approach is now opt-in, a DMA_SAFE flag needs to be set on an i2c_msg. The > outcome so far is very convincing IMO. The core additions are simple and easy > to understand. The driver changes for the Renesas IP cores became easy to > understand, too. It would really help a lot of things if there were a way to detect if a given memory block is DMA safe, having to pass the information around causes so much pain. There's the fun with vmalloc() mappings too needing to be handled differently too though that's less likely to bite I2C. > I am still not sure how we can teach regmap this new flag. regmap is a heavy > user of I2C, so broonie's opinion here would be great to have. The rest should > mostly be updating individual drivers which can be done when needed. We pretty much assume everything is DMA safe already, the majority of transfers go to/from kmalloc()ed scratch buffers so actually are DMA safe but for bulk transfers we use the caller buffer and there might be some problem users. I can't really think of a particularly good way of handling it off the top of my head, obviously not setting the flag is easy but doesn't get the benefit while always using a bounce buffer would involve lots of unneeded memcpy(). Doing _dmasafe() isn't particularly appealing either but might be what we end up with. signature.asc Description: PGP signature
[PATCH v6 0/9] i2c: document DMA handling and add helpers for it
So, after revisiting old mail threads, taking part in a similar discussion on the USB list, and implementing a not-convincing solution before, here is what I cooked up to document and ease DMA handling for I2C within Linux. Please have a look at the documentation introduced in patch 7 for details. And to make it clear again: The stuff below is opt-in. If host drivers are not updated, they will continue to work like before. While previous versions until v3 tried to magically apply bounce buffers when needed, it became clear that detecting DMA safe buffers is too fragile. This approach is now opt-in, a DMA_SAFE flag needs to be set on an i2c_msg. The outcome so far is very convincing IMO. The core additions are simple and easy to understand. The driver changes for the Renesas IP cores became easy to understand, too. Of course, we must now whitelist DMA safe buffers. This series implements it for core functionality: a) for the I2C_RDWR when messages come from userspace b) for i2c_smbus_xfer_emulated(), DMA safe buffers are now allocated for block transfers c) i2c_master_{send|recv} have now a *_dmasafe variant I am still not sure how we can teach regmap this new flag. regmap is a heavy user of I2C, so broonie's opinion here would be great to have. The rest should mostly be updating individual drivers which can be done when needed. All patches have been tested with a Renesas Salvator-X board (r8a7796/M3-W) and Renesas Lager board (r8a7790/H2). But more testing is really really welcome. The branch can be found here: git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/topic/i2c-core-dma-v6 It is planned to land upstream in v4.16 and I want to push it to linux-next early after v4.15 to get lots of testing for the core changes. Big kudos to Renesas Electronics for funding this work, thank you very much! Regards, Wolfram Change since V5: * i2c_master_{send|recv} have now a *_dmasafe variant * for i2c_smbus_xfer_emulated(), DMA safe buffers are now allocated for block transfers * updated the documentation * merged some rewording suggestions from Jonathan Cameron (thanks!) * rebased the patches v4.14-rc6+i2c/for-next, reordered patches Wolfram Sang (9): i2c: add a message flag for DMA safe buffers i2c: add helpers to ease DMA handling i2c: dev: mark RDWR buffers as DMA_SAFE i2c: refactor i2c_master_{send_recv} i2c: add i2c_master_{send|recv}_dmasafe i2c: smbus: use DMA safe buffers for emulated SMBus transactions i2c: add docs to clarify DMA handling i2c: sh_mobile: use core helper to decide when to use DMA i2c: rcar: skip DMA if buffer is not safe Documentation/i2c/DMA-considerations | 67 + drivers/i2c/busses/i2c-rcar.c| 2 +- drivers/i2c/busses/i2c-sh_mobile.c | 8 ++- drivers/i2c/i2c-core-base.c | 110 --- drivers/i2c/i2c-core-smbus.c | 45 -- drivers/i2c/i2c-dev.c| 2 + include/linux/i2c.h | 68 -- include/uapi/linux/i2c.h | 3 + 8 files changed, 246 insertions(+), 59 deletions(-) create mode 100644 Documentation/i2c/DMA-considerations -- 2.11.0