linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Petr Tesarik <ptesarik@suse.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Bagas Sanjaya <bagasdotme@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	Leon Romanovsky <leon@kernel.org>,
	Keith Busch <kbusch@kernel.org>,
	Caleb Sander Mateos <csander@purestorage.com>,
	Sagi Grimberg <sagi@grimberg.me>, Jens Axboe <axboe@kernel.dk>,
	John Garry <john.g.garry@oracle.com>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>,
	iommu@lists.linux.dev
Subject: Re: [PATCH 7/8] docs: dma-api: update streaming DMA API physical address constraints
Date: Fri, 27 Jun 2025 13:32:46 +0200	[thread overview]
Message-ID: <20250627133246.1d0a6d46@mordecai.tesarici.cz> (raw)
In-Reply-To: <f3164113-a834-4b22-adb4-9da1e7ca2c73@arm.com>

On Fri, 27 Jun 2025 12:07:56 +0100
Robin Murphy <robin.murphy@arm.com> wrote:

> On 2025-06-26 8:40 pm, Petr Tesarik wrote:
> > On Thu, 26 Jun 2025 17:45:18 +0100
> > Robin Murphy <robin.murphy@arm.com> wrote:
> >   
> >> On 26/06/2025 2:48 pm, Petr Tesarik wrote:  
> >>> On Thu, 26 Jun 2025 10:58:00 +0100
> >>> Robin Murphy <robin.murphy@arm.com> wrote:
>[...]
> >>>> It's not really that simple. SWIOTLB, ZONE_DMA, etc. require platform
> >>>> support, which end users can't just turn on if it's not there to begin with.  
> >>>
> >>> I know this very well. As you may not be aware, my ultimate goal is to
> >>> get rid of ZONE_DMA and instead enhance the buddy allocator to allow
> >>> allocations within an arbitrary physical address range, which will not
> >>> rely on platform support. But that's another story; for now, let's just
> >>> agree on how the DMA API is supposed to work.  
> >>
> >> Indeed that might actually end up pushing things in the opposite
> >> direction, at least in some cases. Right now, a driver with, say, a
> >> 40-bit DMA mask is usually better off not special-casing DMA buffers,
> >> and just making plain GFP_KERNEL allocations for everything (on the
> >> assumption that 64-bit systems with masses of memory *should* have
> >> SWIOTLB to cover things in the worst case), vs. artificially
> >> constraining its DMA buffers to GFP_DMA32 and having to deal with
> >> allocation failure more often. However with a more precise and flexible
> >> allocator, there's then a much stronger incentive for such drivers to
> >> explicitly mark *every* allocation that may be used for DMA, in order to
> >> get the optimal behaviour.  
> > 
> > I have a different opinion. Most buffers that are passed to the
> > streaming DMA API are I/O data (data read from/written to disk, or
> > received from/sent to network). For the write/send case, these pages
> > were previously allocated by user space, and at that point the kernel
> > had no clue that they would be later used for device I/O.
> > 
> > For example, consider this user-space sequence:
> > 
> > 	buffer = malloc(BUFFER_SIZE);
> > 	fill_in_data(buffer);
> > 	res = write(fd, buffer, BUFFER_SIZE);
> > 
> > The write(2) syscall will try to do zero copy, and that's how the
> > buffer address is passed down to a device driver. If the buffer is not
> > directly accessible by the device, its content must be copied to a
> > different physical location. That should be done by SWIOTLB, not the
> > device driver. Last chance to chose a better placement for the buffer
> > was at malloc(3) time, but at that time the device driver was not
> > involved at all. Er, yes, we may want to provide an ioctl to allocate
> > a suitable buffer for a target device. I think DRM even had such an
> > ioctl once and then removed it, because it was not used in any released
> > userspace code...
> > 
> > In short, the device driver has no control of how these buffers were
> > allocated, and it's not fair to expect anything from the driver.  
> 
> Indeed, for true zero-copy to existing userspace memory then there's not 
> much anyone can change, hence "at least in some cases". However, there 
> are an awful lot of drivers/subsystems which use streaming DMA on their 
> own relatively short-lived kmalloc() allocations - the first example 
> which always comes to mind is all the interfaces like SPI, I2C, UART, 
> etc. which are either dmaengine clients or have their own DMA (and 
> indeed some of which were historically trying to do it from temporary 
> buffers on the stack). Heck, even alloc_skb() might end up being 
> commonly used if this "ethernet" thing ever catches on...

I have been looking around a bit already, and I didn't see an _awful_
lot of these short-lived allocations, but yes, I've found some, and
yes, most of them are in the subsystems you mentioned...

Anyway, thank you for your patience with reading my DMA API docs
update!

Petr T


  reply	other threads:[~2025-06-27 11:32 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24 13:39 [PATCH 0/8] update DMA API documentation Petr Tesarik
2025-06-24 13:39 ` [PATCH 1/8] docs: dma-api: use "DMA API" consistently throughout the document Petr Tesarik
2025-06-25  2:41   ` Randy Dunlap
2025-06-24 13:39 ` [PATCH 2/8] docs: dma-api: replace consistent with coherent Petr Tesarik
2025-06-26  4:51   ` Petr Tesarik
2025-06-26  7:21     ` Marek Szyprowski
2025-06-24 13:39 ` [PATCH 3/8] docs: dma-api: remove remnants of PCI DMA API Petr Tesarik
2025-06-26  1:46   ` Bagas Sanjaya
2025-06-24 13:39 ` [PATCH 4/8] docs: dma-api: add a kernel-doc comment for dma_pool_zalloc() Petr Tesarik
2025-06-24 13:39 ` [PATCH 5/8] docs: dma-api: remove duplicate description of the DMA pool API Petr Tesarik
2025-06-25  2:40   ` Randy Dunlap
2025-06-25  6:41     ` Petr Tesarik
2025-06-24 13:39 ` [PATCH 6/8] docs: dma-api: clarify DMA addressing limitations Petr Tesarik
2025-06-26  1:47   ` Bagas Sanjaya
2025-06-24 13:39 ` [PATCH 7/8] docs: dma-api: update streaming DMA API physical address constraints Petr Tesarik
2025-06-26  1:49   ` Bagas Sanjaya
2025-06-26  5:06     ` Petr Tesarik
2025-06-26  7:09       ` Marek Szyprowski
2025-06-26  8:25         ` Petr Tesarik
2025-06-26  9:58       ` Robin Murphy
2025-06-26 13:48         ` Petr Tesarik
2025-06-26 16:45           ` Robin Murphy
2025-06-26 19:40             ` Petr Tesarik
2025-06-27 11:07               ` Robin Murphy
2025-06-27 11:32                 ` Petr Tesarik [this message]
2025-06-27 12:55             ` Christoph Hellwig
2025-06-27 13:02               ` Petr Tesarik
2025-06-27 12:52       ` Christoph Hellwig
2025-06-24 13:39 ` [PATCH 8/8] docs: dma-api: clean up documentation of dma_map_sg() Petr Tesarik
2025-06-26  1:50   ` Bagas Sanjaya

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=20250627133246.1d0a6d46@mordecai.tesarici.cz \
    --to=ptesarik@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bagasdotme@gmail.com \
    --cc=corbet@lwn.net \
    --cc=csander@purestorage.com \
    --cc=iommu@lists.linux.dev \
    --cc=john.g.garry@oracle.com \
    --cc=kbusch@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.com \
    --cc=sagi@grimberg.me \
    /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