mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Petr Tesarik" <ptesarik@suse.com>
Cc: "Mark Brown" <broonie@kernel.org>,
	"Grant Likely" <grant.likely@secretlab.ca>,
	linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Subject: Re: [PATCH] spi: Ensure memory used for spi_write_then_read() is DMA safe
Date: Fri, 21 Mar 2025 22:21:03 +0100	[thread overview]
Message-ID: <b837b2a7-8a88-4782-96d4-1b637bba0664@app.fastmail.com> (raw)
In-Reply-To: <20250321151327.4c8f8d4c@mordecai.tesarici.cz>

On Fri, Mar 21, 2025, at 15:13, Petr Tesarik wrote:
> On Fri, 21 Mar 2025 13:41:52 +0100
>> Ok, then the question is what we should do about callers that pass
>> in stack data. I can send a patch that adds a WARN_ONCE() or similar,
>> but it would trigger on things like 
>> 
>> static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val)
>> {
>>         return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16));
>> }
>> static int rt1711h_write16(struct rt1711h_chip *chip, unsigned int reg, u16 val)
>> {
>>         return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u16));
>> }
>> 
>> which happens in a number of drivers but is harmless as long
>> as the driver doesn't actually try to DMA into that buffer.
>
> This sounds like we should push the WARN_ONCE() one level deeper, into
> the DMA code. That's a good idea, actually, because it's always wrong
> to do DMA to a stack address, not just when SPI does it.

This doesn't work for the current SPI code that uses
vmalloc_to_page() in order to deal with vmalloc addresses.
Passing a vmap stack address in here would continue working
on the address from the linear map.

There is already a check_for_stack() assertion in
debug_dma_map_page(), which is meant to catch this problem
in the DMA layer itself, but only when CONFIG_DMA_API_DEBUG
is enabled.

      Arnd

  reply	other threads:[~2025-03-21 21:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-27  6:35 Mark Brown
2013-02-05 14:21 ` Grant Likely
2025-03-20 11:43   ` Petr Tesarik
2025-03-20 12:29     ` Mark Brown
2025-03-20 13:35       ` Arnd Bergmann
2025-03-20 14:35         ` Petr Tesarik
2025-03-20 15:34           ` Mark Brown
2025-03-20 16:08             ` Petr Tesarik
2025-03-20 18:55               ` Mark Brown
2025-03-20 14:42         ` Mark Brown
2025-03-20 16:30           ` Arnd Bergmann
2025-03-20 18:39             ` Mark Brown
2025-03-21 12:41               ` Arnd Bergmann
2025-03-21 14:13                 ` Petr Tesarik
2025-03-21 21:21                   ` Arnd Bergmann [this message]
2025-03-21 14:45                 ` Mark Brown
2025-03-21 19:42                   ` Arnd Bergmann
2025-03-26 16:20                     ` Mark Brown
2025-03-26 21:45                       ` Arnd Bergmann
2025-03-27 15:03                         ` Mark Brown

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=b837b2a7-8a88-4782-96d4-1b637bba0664@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=ptesarik@suse.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

all inboxes | Powered by JetHome®