All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>,
	Mark Brown <broonie@kernel.org>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>
Subject: Re: [PATCH v1 1/1] spi: Remove unneded check for orig_nents
Date: Wed, 22 May 2024 18:24:04 +0300	[thread overview]
Message-ID: <Zk4OFI3WObm1C1SY@smile.fi.intel.com> (raw)
In-Reply-To: <76763ae4-557a-401e-9497-9295e7da3fd7@notapiano>

On Wed, May 22, 2024 at 11:12:43AM -0400, Nícolas F. R. A. Prado wrote:
> On Wed, May 22, 2024 at 05:24:40PM +0300, Andy Shevchenko wrote:
> > On Wed, May 22, 2024 at 03:18:18PM +0200, Neil Armstrong wrote:
> > > On 22/05/2024 13:53, Neil Armstrong wrote:
> > > > On 22/05/2024 13:33, Andy Shevchenko wrote:
> > > > > On Wed, May 22, 2024 at 12:03:33PM +0200, Neil Armstrong wrote:
> > > > > > On 15/05/2024 23:09, Nícolas F. R. A. Prado wrote:
> > > > > > > On Tue, May 07, 2024 at 11:10:27PM +0300, Andy Shevchenko wrote:
> > > > > > > > Both dma_unmap_sgtable() and sg_free_table() in spi_unmap_buf_attrs()
> > > > > > > > have checks for orig_nents against 0. No need to duplicate this.
> > > > > > > > All the same applies to other DMA mapping API calls.
> > > > > > > > 
> > > > > > > > Also note, there is no other user in the kernel that does this kind of
> > > > > > > > checks.
> > > > > > > > 
> > > > > > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > this commit caused a regression which I reported here:
> > > > > > > 
> > > > > > > https://lore.kernel.org/all/d3679496-2e4e-4a7c-97ed-f193bd53af1d@notapiano
> > > > > > > 
> > > > > > > along with some thoughts on the cause and a possible solution, though I'm not
> > > > > > > familiar with this code base at all and would really appreciate any feedback you
> > > > > > > may have.
> > > > > > 
> > > > > > I also see the same regression on the SM8550 and SM8650 platforms,
> > > > > > please CC linux-arm-msm@vger.kernel.org and me for a potential fix to test on those platforms.
> > > > > 
> > > > > There is still no answer from IOMMU patch author. Do you have the same trace
> > > > > due to IOMMU calls? Anyway, I guess it would be nice to see it.
> [..]
> > > > > 
> > > > > Meanwhile, I have three changes I posted in the replies to the initial report,
> > > > > can you combine them all and test? This will be a plan B (? or A, depending on
> > > > > the culprit).
> > > > > 
> > > > 
> > > > I'll try to apply them and test.
> > > 
> > > I stacked the 3 changes, and it works:
> > > Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-QRD
> > 
> > Thank you!
> > 
> > I will try to develop and submit a fix against IOMMU which I believe is the
> > correct place to address this. So, this one will be plan B in case the IOMMU
> > folks will refuse the other one.
> 
> Hi,
> 
> that change did not work for me. Stack trace follows at the end.
> 
> But adding the following on top did fix it:
> 
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 0851c5e1fd1f..5d3972d9d1da 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1253,8 +1253,13 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
>                 /* The sync is done before each transfer. */
>                 unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC;
> 
> -               if (!ctlr->can_dma(ctlr, msg->spi, xfer))
> +               if (!ctlr->can_dma(ctlr, msg->spi, xfer)) {
> +                       memset(&xfer->tx_sg, 0, sizeof(xfer->tx_sg));
> +                       xfer->tx_sg.sgl = &dummy_sg;
> +                       memset(&xfer->rx_sg, 0, sizeof(xfer->rx_sg));
> +                       xfer->rx_sg.sgl = &dummy_sg;
>                         continue;
> +               }
> 
>                 if (xfer->tx_buf != NULL) {
>                         ret = spi_map_buf_attrs(ctlr, tx_dev, &xfer->tx_sg,
> 
> 
> The thing is that even with all the previous changes applied, if one of the
> transfers inside the message doesn't support DMA, the null pointer would still
> be passed to the DMA API.

Ah, indeed, the conditionals also can be translated to

	can_dma = can_dma();

	if (can_dma && _buf)
		...
	else
		...

but...


> Alternatively, I think a better way to achieve the same is (I have verified this
> also works):

I agree that this one is much better approach. I will clean it up and send
as a quick fix. IOMMU will still be on the table as I think it's wrong to
dereference SG when nents = 0.

> I'll let you decide what is the best fix for the issue (what has been posted so
> far in this thread or another fix in IOMMU). If you go with this, feel free to
> add my
> 
> Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>

Thank you!

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2024-05-22 15:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07 20:10 [PATCH v1 1/1] spi: Remove unneded check for orig_nents Andy Shevchenko
2024-05-08 12:08 ` Mark Brown
2024-05-16 11:28   ` [PATCH] spi: Remove unneeded " Markus Elfring
2024-05-15 21:09 ` [PATCH v1 1/1] spi: Remove unneded " Nícolas F. R. A. Prado
2024-05-16 10:18   ` Andy Shevchenko
2024-05-16 13:25     ` Andy Shevchenko
2024-05-16 16:25       ` Nícolas F. R. A. Prado
2024-05-16 17:46         ` Andy Shevchenko
2024-05-16 21:11           ` Nícolas F. R. A. Prado
2024-05-17 15:40             ` Andy Shevchenko
2024-05-22 10:03   ` Neil Armstrong
2024-05-22 11:33     ` Andy Shevchenko
2024-05-22 11:53       ` Neil Armstrong
2024-05-22 13:18         ` Neil Armstrong
2024-05-22 14:24           ` Andy Shevchenko
2024-05-22 15:12             ` Nícolas F. R. A. Prado
2024-05-22 15:24               ` Andy Shevchenko [this message]

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=Zk4OFI3WObm1C1SY@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=nfraprado@collabora.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.