From: Vignesh R <vigneshr@ti.com>
To: Trent Piepho <tpiepho@impinj.com>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
"linux@armlinux.org.uk" <linux@armlinux.org.uk>,
"broonie@kernel.org" <broonie@kernel.org>,
"cyrille.pitchen@wedev4u.fr" <cyrille.pitchen@wedev4u.fr>,
"dwmw2@infradead.org" <dwmw2@infradead.org>,
"computersforpeace@gmail.com" <computersforpeace@gmail.com>,
"boris.brezillon@free-electrons.com"
<boris.brezillon@free-electrons.com>,
"richard@nod.at" <richard@nod.at>,
"marek.vasut@gmail.com" <marek.vasut@gmail.com>
Cc: "linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"nicolas.ferre@microchip.com" <nicolas.ferre@microchip.com>,
"radu.pirea@microchip.com" <radu.pirea@microchip.com>,
"robh@kernel.org" <robh@kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH 1/3] mtd: spi-nor: add optional DMA-safe bounce buffer for data transfer
Date: Tue, 2 Jan 2018 15:30:37 +0530 [thread overview]
Message-ID: <b4794d21-817f-b67b-1569-05e1400bdbee@ti.com> (raw)
In-Reply-To: <1514570627.26695.114.camel@impinj.com>
On Friday 29 December 2017 11:33 PM, Trent Piepho wrote:
> On Fri, 2017-12-29 at 15:46 +0530, Vignesh R wrote:
>> On Friday 29 December 2017 12:24 AM, Trent Piepho wrote:
>> >
>> > > Vignesh has suggested to call virt_addr_valid() instead.
>> > > I think Boris has also told me about this function.
>> > > So it might be the right solution. What do you think about their proposal?
>> >
>> > Not sure what exactly the differences are between these methods. The
>> > fact that each of the many existing DMA fixes uses slightly different
>> > code to detect what is unsafe speaks to the difficulty of this problem!
>>
>> My understanding based on Documentation/DMA-API-HOWTO.txt and
>> Documentation/arm/memory.txt is that
>> virt_addr_valid() will guarantee that address is in range of
>> PAGE_OFFSET to high_memory-1 (Kernel direct-mapped RAM region) which is
>> address range of buffers that are DMA'able.
>
> There's code in gpmi-nand.c that does:
>
> /* first try to map the upper buffer directly */
> if (virt_addr_valid(this->upper_buf) &&
> !object_is_on_stack(this->upper_buf)) {
> sg_init_one(sgl, this->upper_buf, this->upper_len);
>
> So whoever wrote that thought that stack objects needed an additional
> test beyond virt_addr_valid. But it does appear to be far more common
> to depend on just virt_addr_valid, so perhaps the code in gpmi-nand is
> in error.
>
The test in gpmi-nand.c is right. Enabling CONFIG_DMA_API_DEBUG does
warn about DMA'ing into stack objects (in lib/dma-debug.c). So other
places needs to be fixed, I guess.
>> > virt_addr_valid() is already used by spi-ti-qspi. spi core uses for
>> > the buffer map helper, but that code path is for buffers which are NOT
>> > vmalloc or highmem, but are still not virt_addr_valid() for some other
>> > reason.
>> >
>>
>> if (vmalloced_buf || kmap_buf) {
>> /* Handle vmalloc'd or kmap'd buffers */
>> ...
> This stuff does get DMAed. So I have to wonder, if spi.c thinks it can
> use DMA with vmalloc or highmem, couldn't spi-not do the same instead
> of the bounce buffer?
SPI core does try to DMA into underlying physical pages of vmalloc'd
buffer. But this has two problems:
1. Does not work well with VIVT caches[1].
2. On ARM LPAE systems, vmalloc'd buffers can be from highmem region
that are not addressable using 32 bit addresses and is backed by LPAE.
So, a 32 bit DMA cannot access these buffers.
Both these issues lead to random crashes and errors with UBIFS and JFFS2
flash file systems which this patch series tries to address using bounce
buffer
[1] https://patchwork.kernel.org/patch/9579553/
--
Regards
Vignesh
next prev parent reply other threads:[~2018-01-02 10:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-24 4:36 [PATCH 0/3] mtd: spi-nor: fix DMA-unsafe buffer issue between MTD and SPI Cyrille Pitchen
2017-12-24 4:36 ` [PATCH 1/3] mtd: spi-nor: add optional DMA-safe bounce buffer for data transfer Cyrille Pitchen
[not found] ` <fc2440c6f52877f28286d89691049e5cba10e6a7.1514087323.git.cyrille.pitchen-yU5RGvR974pGWvitb5QawA@public.gmane.org>
2017-12-26 13:42 ` Vignesh R
[not found] ` <1126731d-cbf7-8fbf-34ab-8ccf1cc8241f-l0cyMroinI0@public.gmane.org>
2017-12-26 13:59 ` Cyrille Pitchen
[not found] ` <ae977280-28b4-d746-da4b-0f807dad609d-yU5RGvR974pGWvitb5QawA@public.gmane.org>
2018-01-07 20:07 ` Boris Brezillon
2017-12-26 19:43 ` Trent Piepho
[not found] ` <1514317385.26695.39.camel-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org>
2017-12-28 10:39 ` Cyrille Pitchen
2017-12-28 18:54 ` Trent Piepho
[not found] ` <1514487276.26695.94.camel-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org>
2017-12-29 10:16 ` Vignesh R
[not found] ` <08be8b42-732a-bf28-40c4-f46bf9d71c80-l0cyMroinI0@public.gmane.org>
2017-12-29 18:03 ` Trent Piepho
2018-01-02 10:00 ` Vignesh R [this message]
2018-01-07 20:49 ` Boris Brezillon
2017-12-24 4:36 ` [PATCH 2/3] dt-bindings: mtd: atmel-quadspi: add an optional property 'dmacap, memcpy' Cyrille Pitchen
[not found] ` <143542c61ca674d53da4985bbabc142e8e6ebefc.1514087323.git.cyrille.pitchen-yU5RGvR974pGWvitb5QawA@public.gmane.org>
2017-12-26 23:23 ` [PATCH 2/3] dt-bindings: mtd: atmel-quadspi: add an optional property 'dmacap,memcpy' Rob Herring
2017-12-27 21:40 ` Cyrille Pitchen
[not found] ` <0149ba05-64b1-2739-e61f-78d5170775fb-yU5RGvR974pGWvitb5QawA@public.gmane.org>
2018-01-02 10:22 ` Ludovic Desroches
[not found] ` <20180102102234.GG2612-fC2aZbRiGnsAAwgTK2POJVCF2YAvjlIb@public.gmane.org>
2018-01-02 19:18 ` Trent Piepho
[not found] ` <1514920738.26695.171.camel-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org>
2018-01-03 6:51 ` ludovic.desroches-UWL1GkI3JZL3oGB3hsPCZA
2018-01-03 11:51 ` Mark Brown
2017-12-24 4:36 ` [PATCH 3/3] mtd: atmel-quadspi: add support of DMA memcpy() Cyrille Pitchen
2017-12-26 18:45 ` [PATCH 0/3] mtd: spi-nor: fix DMA-unsafe buffer issue between MTD and SPI Trent Piepho
2017-12-27 10:36 ` Mark Brown
2017-12-27 20:15 ` Trent Piepho
[not found] ` <1514405711.26695.67.camel-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org>
2017-12-28 9:36 ` Cyrille Pitchen
2018-01-03 11:49 ` Mark Brown
2017-12-29 9:16 ` Vignesh R
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b4794d21-817f-b67b-1569-05e1400bdbee@ti.com \
--to=vigneshr@ti.com \
--cc=boris.brezillon@free-electrons.com \
--cc=broonie@kernel.org \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=devicetree@vger.kernel.org \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=marek.vasut@gmail.com \
--cc=nicolas.ferre@microchip.com \
--cc=radu.pirea@microchip.com \
--cc=richard@nod.at \
--cc=robh@kernel.org \
--cc=tpiepho@impinj.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).