All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Honghui  Jiang" <jiang_hh2019@163.com>
To: "Andy Shevchenko" <andy.shevchenko@gmail.com>
Cc: broonie@kernel.org, andy@kernel.org,
	andriy.shevchenko@linux.intel.com, fancer.lancer@gmail.com,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] spi: Fix DMA mapping ownership on partial map failure
Date: Sun, 9 Aug 2026 01:54:28 +0800 (CST)	[thread overview]
Message-ID: <4adeeeb4.2dec.19fe283130a.Coremail.jiang_hh2019@163.com> (raw)
In-Reply-To: <CAHp75Vf=riT4uCVrF+bHuAB-xCLV8wRZrn0WVVRsfxN_-0WAPg@mail.gmail.com>

Thanks for the review.

On Thu, Aug 06, 2026 at 10:34:16PM +0300, Andy Shevchenko wrote:
> The Fixes tag refers to the commit that moved from per message to per
> transfer mapping flags. Can you elaborate why it was no problem
> before? (Not sure if we need the answer to be included in the commit
> message, probably the cover letter is the best choice for this info.)

The partial-failure handling was already incomplete before that commit,
but the failure mode was different. __spi_unmap_msg() was gated by
ctlr->cur_msg_mapped, which was set only after the whole message had
been mapped successfully. A partial failure therefore skipped the
normal unmap path: it could leak mappings made for earlier transfers,
but it could not unmap them again using an unpublished DMA device.

The per-transfer conversion removed that message-wide gate. The
per-transfer flags can now remain set after a partial failure, while
cur_{tx,rx}_dma_dev are still published only after the whole mapping
loop succeeds. The subsequent cleanup can therefore unmap those
transfers using a NULL or stale device. That is the regression referred
to by the Fixes tag.

Agreed. I'll add this explanation to the v2 cover letter.

> For a fix this is probably okay to introduce, but can we get rid of
> forward declaration by moving the unmapping routine above? If so, can
> you also add another patch for that?

Yes. I'll keep the forward declaration in the fix so that it remains
independently buildable and backportable. I'll then add a follow-up
cleanup patch moving __spi_unmap_msg() above __spi_map_msg() and
removing the declaration.

> Does unwind routine nullify them? If not, there is a chance that some
> code (maybe in the future) might use stale pointers.

It currently does not.

I checked the current users. The three users in the SPI core only use a
device when the corresponding *_sg_mapped flag is set. The accesses in
spi-amlogic-spisg also occur before spi_finalize_current_message() on
every path which reaches them.

Nevertheless, I agree that the pointers should not survive the message.
I'll clear them in a separate follow-up cleanup patch, in
spi_unmap_msg() after __spi_unmap_msg() returns, rather than inside
__spi_unmap_msg() itself. The latter is also used for the in-message
DMA-to-PIO fallback and therefore does not mark the end of the message
lifetime.

> Since you touched these lines, perhaps it makes sense to drop ' != 0'
> parts to make it follow the regular pattern.

Will do. Both checks will use plain if (ret) in v2.

Thanks,
Honghui

  reply	other threads:[~2026-08-08 17:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 15:14 [PATCH 0/2] spi: Fix DMA mapping ownership on partial map failure Honghui Jiang
2026-08-05 15:14 ` [PATCH 1/2] " Honghui Jiang
2026-08-06 19:34   ` Andy Shevchenko
2026-08-08 17:54     ` Honghui  Jiang [this message]
2026-08-05 15:14 ` [PATCH 2/2] spi: Add KUnit coverage for DMA mapping error paths Honghui Jiang
2026-08-05 21:57   ` Mark Brown
2026-08-06  4:20     ` 江宏辉 
2026-08-06 19:32     ` Andy Shevchenko

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=4adeeeb4.2dec.19fe283130a.Coremail.jiang_hh2019@163.com \
    --to=jiang_hh2019@163.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=broonie@kernel.org \
    --cc=fancer.lancer@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /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.