Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751584AbdCAO2t (ORCPT ); Wed, 1 Mar 2017 09:28:49 -0500 Received: from smtpout.microchip.com ([198.175.253.82]:44500 "EHLO email.microchip.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751038AbdCAO2p (ORCPT ); Wed, 1 Mar 2017 09:28:45 -0500 Subject: Re: [RFC PATCH 2/2] mtd: devices: m25p80: Enable spi-nor bounce buffer support To: Vignesh R , Richard Weinberger , "David Woodhouse" , Brian Norris , Boris Brezillon , Marek Vasut References: <20170227120839.16545-1-vigneshr@ti.com> <20170227120839.16545-3-vigneshr@ti.com> <8f999a27-c3ce-2650-452c-b21c3e44989d@ti.com> CC: , , , Frode Isaksen , , Mark Brown From: Cyrille Pitchen Message-ID: <8a2c9b3b-dd5f-fca7-fa5c-690e5bed949f@atmel.com> Date: Wed, 1 Mar 2017 15:21:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: =?iso-8859-15?Q?H4sIAAAAAAAAC+NgFmpmk+JIrShJLcpLzFFi42Lh4vJh0X11Y1uEwZadU?= =?iso-8859-15?Q?+cxWxx4sZDFYurDJ2wWRy6sZbaYuHIys8XTS/9YLS7vmsNmsbtpGbvF7C?= =?iso-8859-15?Q?X9LBaNH2+yWxzdc4/ZYvLON4wW/89+YHfg8Xh/o5Xd48mmi4weO2fdZff?= =?iso-8859-15?Q?YvELLY9OqTjaPzUvqPW7OK/Q4fmM7k8fnTXIBnFGsmXlJ+RUJrBmds9ey?= =?iso-8859-15?Q?FkzWqnjTNJGpgbFdqYuRi0NIYDmjxMJ7R1i7GDk5hAUiJf69fswEkhAR+?= =?iso-8859-15?Q?MUo8flwJxNE1SImiSOrVrGDOMwChxglNs1tYQFpYRMwlHj74ChYO6+Ajc?= =?iso-8859-15?Q?S1I11gcRYBFYk7z/4zgdiiAhES85+uYoKoEZQ4OfMJWA2ngJXEv933mUF?= =?iso-8859-15?Q?sZgF9idUNB9ggbHmJ5q2zweJCAmoSC1tWgNkSAoESdy+sZoGwnSR2Lp8K?= =?iso-8859-15?Q?ZdtJHJ5+kR3CdpBY+nsOO0xN+9I3rBC2tsT2V/ugbB2JbQf7oXptJfbMm?= =?iso-8859-15?Q?MgEYbtLPHi0HMr2lZj1sAGqJkri7bxTLBMYJWcheWEWkrNnITl7ASPzKk?= =?iso-8859-15?Q?ZpZw8/3eAwXdcIZw8DU73c5IwC3dzEzDy95PzcTYyQ5JC1g/F3Z8QhRkk?= =?iso-8859-15?Q?OJiVR3t2rtkUI8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuDNvg6UEyxKTU+t?= =?iso-8859-15?Q?SMvMAaYpmDQTBycwMjh4lER434PU8BYXJOYWZ6ZD5E8xSkqJ80qBJARAE?= =?iso-8859-15?Q?hmleXC9lxhFpYR5Uy4C5XgKUotyM0sg4rcYxTgeMnE8ZhJiycvPS5UCOp?= =?iso-8859-15?Q?UBCAwYXzGKczAqCfOKXwNpycwrgVvzCugCJqALXqhsBbmgJBEhJdXA2NN?= =?iso-8859-15?Q?9S7PtyXammg6DyOfTJbMuaecJ8trtiA+c9drq4MmMHX0FW+yen8vmumX4?= =?iso-8859-15?Q?TdnWOEbWvWTuf9lXy7hjLHglTqbJHD0ZuVSD94iwlY1ZTNC8PVu81vi0n?= =?iso-8859-15?Q?/uxZNPf/N6bhql7Vlk3evz70pPqmNm+vVB13snKu9+2XShOnqTm3S7y1u?= =?iso-8859-15?Q?fmPl5dJZbijERDLeai4kQAc2Q5rJYDAAA=3D?= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5264 Lines: 129 + Mark Le 01/03/2017 ? 12:46, Vignesh R a ?crit : > > > On Wednesday 01 March 2017 04:13 PM, Cyrille Pitchen wrote: >> Le 01/03/2017 ? 05:54, Vignesh R a ?crit : >>> >>> >>> On Wednesday 01 March 2017 03:11 AM, Richard Weinberger wrote: >>>> Vignesh, >>>> >>>> Am 27.02.2017 um 13:08 schrieb Vignesh R: >>>>> Many SPI controller drivers use DMA to read/write from m25p80 compatible >>>>> flashes. Therefore enable bounce buffers support provided by spi-nor >>>>> framework to take care of handling vmalloc'd buffers which may not be >>>>> DMA'able. >>>>> >>>>> Signed-off-by: Vignesh R >>>>> --- >>>>> drivers/mtd/devices/m25p80.c | 1 + >>>>> 1 file changed, 1 insertion(+) >>>>> >>>>> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c >>>>> index c4df3b1bded0..d05acf22eadf 100644 >>>>> --- a/drivers/mtd/devices/m25p80.c >>>>> +++ b/drivers/mtd/devices/m25p80.c >>>>> @@ -241,6 +241,7 @@ static int m25p_probe(struct spi_device *spi) >>>>> else >>>>> flash_name = spi->modalias; >>>>> >>>>> + nor->flags |= SNOR_F_USE_BOUNCE_BUFFER; >>>> >>>> Isn't there a better way to detect whether a bounce buffer is needed or not? >>> >> >> I agree with Richard: the bounce buffer should be enabled only if needed >> by the SPI controller. >> >>> Yes, I can poke the spi->master struct to see of dma channels are >>> populated and request SNOR_F_USE_BOUNCE_BUFFER accordingly: >>> >>> - nor->flags |= SNOR_F_USE_BOUNCE_BUFFER; >>> + if (spi->master->dma_tx || spi->master->dma_rx) >>> + nor->flags |= SNOR_F_USE_BOUNCE_BUFFER; >>> + >>> >> >> However I don't agree with this solution: master->dma_{tx|rx} can be set >> for SPI controllers which already rely on spi_map_msg() to handle >> vmalloc'ed memory during DMA transfers. >> Such SPI controllers don't need the spi-nor bounce buffer. >> >> spi_map_msg() can build a scatter-gather list from vmalloc'ed buffer >> then map this sg list with dma_map_sg(). AFAIK, It is safe to do so for >> architectures using PIPT caches since the possible cache aliases issue >> present for VIPT or VIVT caches is always avoided for PIPT caches. >> >> For instance, the drivers/spi/spi-atmel.c driver relies on spi_map_sg() >> to be called from the SPI sub-system to handle vmalloc'ed buffers and >> both master->dma_tx and master->dma_rx are set by the this driver. >> >> >> By the way, Is there any case where the same physical page is actually >> mapped into two different virtual addresses for the buffers allocated by >> the MTD sub-system? Because for a long time now I wonder whether the >> cache aliases issue is a real or only theoretical issue but I have no >> answer to that question. >> > > I have atleast one evidence of VIVT aliasing causing problem. Please see > this thread on DMA issues with davinci-spi driver > https://www.spinics.net/lists/arm-kernel/msg563420.html > https://www.spinics.net/lists/arm-kernel/msg563445.html > >> Then my next question: is spi_map_msg() enough in every case, even with >> VIPT or VIVT caches? >> > > Not really, I am debugging another issue with UBIFS on DRA74 EVM (ARM > cortex-a15) wherein pages allocated by vmalloc are in highmem region > that are not addressable using 32 bit addresses and is backed by LPAE. > So, a 32 bit DMA cannot access these buffers at all. > When dma_map_sg() is called to map these pages by spi_map_buf() the > physical address is just truncated to 32 bit in pfn_to_dma() (as part of > dma_map_sg() call). This results in random crashes as DMA starts > accessing random memory during SPI read. > > IMO, there may be more undiscovered caveat with using dma_map_sg() for > non kmalloc'd buffers and its better that spi-nor starts handling these > buffers instead of relying on spi_map_msg() and working around every > time something pops up. > Both Frode and you confirmed that the alias issue does occur at least with VIVT caches, hence we can't rely on spi_map_msg() in that case. So I agree with you: adding a bounce buffer in spi-nor seems to be a good solution at least till some rework is done in the ubifs layer, as proposed by Boris, to replace vmalloc'ed buffers by kmalloc'ed memory. However I still think testing spi->master->dma_{tx|rx} only is not accurate enough to decided whether or not the SNOR_F_USE_BOUNCE_BUFFER flag should be set. I have doubts about forcing the use of the bounce buffer for *all* SPI controllers doing DMA transfers. We already know that the cache aliases issue can't occur with PIPT caches or some VIPT caches. So in those cases spi_map_buf() is enough, hence can we justify the performance loss of the copy into the bounce buffer for people who don't suffer the issue? Besides, some SPI controller drivers may already use their own bounce buffer for other reasons. Then for those controllers, it would be one more copy. Then I don't whether we should: 1 - extend in SPI sub-system API to tell us if the SPI controller can deal with non-kmalloc'd buffer for DMA transfers or 2 - get the answer at a system-wide level. Indeed, the question cache aliases is clearly not specific to the MTD or SPI sub-systems but only the SPI controller driver can tell whether it already uses its own bounce buffer. Best regards, Cyrille