🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.netbsd.tech.kern
Article #11

Re: bus_dma without bouncing

#11
From: Yuri Honegger
Date: Tue, 27 Oct 2026 14:51
88 lines
5788 bytes

> Am 27.10.2026 um 15:16 schrieb Taylor R Campbell <riastradh@NetBSD.org>:
> 
> NIC drivers allocate rx buffers for the device to read network data
> into through DMA.  In some devices the device's DMA has constraints,
> specified through the DMA tag and/or bus_dmamap_create parameters, and
> enforced in bus_dmamap_load by bouncing.
> 
> To avoid bouncing, or to satisfy alignment requirements imposed by the
> device[1], drivers will often allocate rx buffers themselves with
> bus_dmamem_alloc/map.

Another case that I currently don’t know how to represent is a device that support multisegment dma, but all segment sizes need to be a multiple of 64 bytes. This is the case for the DMA controller on some TI SoCs (am335x, am1808).

> 
> But, given constraints, bus_dmamap_create will _also_ allocate bounce
> buffers with bus_dmamem_alloc/map -- even if the driver will never
> bounce because it already allocated rx buffers satisfying the
> constraint.  This wastes physical pages and kva that will never be
> used -- except if there's a driver bug causing every rx buffer to be
> bounced unintentionally, which quietly gives bad performance!
> 
> Should we have a way to avoid this?

Yes, but that is treating the symptoms. I’ve been wondering what if we allow drivers to express more constraints for how their DMA memory looks like so they no longer need to manage bounce buffer themselves?

> 
> Here are a couple options that come to mind (with 30sec of thought put
> into each name, and alternate bike shed paint suggestions welcome):
> 
> 1. An option BUS_DMA_BOUNCELESS to bus_dmamap_create that causes
>   bus_dmamap_load to fail instead of bouncing if constraints are not
>   met.

BUS_DMA_NOBOUNCE would be a bit more in line with the other constants, but I don’t particularly care.

> 
>   => This simple API change generally obviates the need to allocate
>      bounce buffers in the scenario above.  However, some
>      architectural constraints such as confidential computing
>      architecture (AMD SEV, Intel TDX) may still require bouncing for
>      other reasons (must selectively expose page unencrypted to the
>      hypervisor).
> 
> 2. (a) An option BUS_DMA_ALLOCBUF to bus_dmamap_create that _forces_
>       it to allocate a bounce buffer with bus_dmamem_alloc/map
>       meeting the constraints.

How does this differ from BUS_DMA_ALLOCNOW?

>   (b) Another operation, such as bus_dmamap_bufmem, to get at the
>       bounce buffer so a driver can work directly with it instead of
>       calling bus_dmamem_alloc/map itself.
> 
>   => This would allow us to avoid the duplicate bounce buffer in the
>      confidential computing case.  But it's a more complicated change
>      to the API, and some bus_dma implementations -- such as sparc
>      and sparc64 -- appear not to bounce at all, ever, so they would
>      have to be adapted to add logic for allocating bounce bufers.

To me, the complexity doesn’t seem worth it compared to adding a BOUNCELESS flag.

> 
> 
> 
> [1] It seems there is no MI way with bus_dma tags or bus_dmamap_create
>    to make bus_dmamap_load enforce alignment by bouncing into an
>    aligned bounce buffer if the given address is misaligned.  But
>    there are plenty of devices that require aligned addresses for
>    DMA, such as Intel wireless cards which require 8- or 12-bit
>    alignment.  Am I missing something?  Is there just no way to
>    express this constraint in bus_dmamap_create so that
>    bus_dmamap_load will _either_ fail noisily or bounce on misaligned
>    inputs?


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <274F60C0-FF09-42CC-94AC-0B4EEFCDA238@NetBSD.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
References: <20261027141625.CCD2884D05@mail.netbsd.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: Yuri Honegger <yurix@NetBSD.org>
Newsgroups: muc.lists.netbsd.tech.kern
Subject: Re: bus_dma without bouncing
Date: Tue, 27 Oct 2026 15:51:36 +0100
Organization: Newsgate at muc.de e.V.
Sender: tech-kern-owner@NetBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <274F60C0-FF09-42CC-94AC-0B4EEFCDA238@NetBSD.org>
References: <20261027141625.CCD2884D05@mail.netbsd.org>
MIME-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.10\))
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="35974"; mail-complaints-to="news-admin@muc.de"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netbsd.org;
	s=20240131; t=1793112706;
	bh=vNxB5d9KF2kFvenruSvLFxeMYwJNZF+whU4GXoSN3Qc=;
	h=Subject:From:In-Reply-To:Date:Cc:References:To:List-Id:
	 List-Unsubscribe;
	b=XeKJcI8oX8XuroBfRa7tNcorKtZPIeysGCwNSjdJeKWvEIbxfgIuDegEU2cj0EOP8
	 XmpcHKRFBmT0c5WW+CozFQhRAcFRsISphTo4pH1QhekPXOVXEdDmL7L9aFPFqRzUzd
	 yfUJjrNGGQN1PGi5JW8YP5NHFs9LY5VMpIxKsz5o=
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netbsd.org;
	s=20240131; t=1793112700;
	bh=vNxB5d9KF2kFvenruSvLFxeMYwJNZF+whU4GXoSN3Qc=;
	h=Subject:From:In-Reply-To:Date:Cc:References:To;
	b=eSMEIxWS840ZOPhizGm04634nZisDFMzE2Od8Mi53DpotkdA/6Y2eC+Z1HwNK/7fY
	 OlWWke8G9EBKsogenOE9ytliOE5Vkubwq7Htbf/YB0pmOEWzcNVansL1eGQfR5050o
	 XqWfa3i8tQKFWSLyW5S94e0+P1/apdYRZEWL7pSA=
In-Reply-To: <20261027141625.CCD2884D05@mail.netbsd.org>
Precedence: bulk
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes