Article View: muc.lists.netbsd.tech.kern
Article #8bus_dma without bouncing
From: Taylor R Campbell
Date: Tue, 27 Oct 2026 14:16
Date: Tue, 27 Oct 2026 14:16
60 lines
4613 bytes
4613 bytes
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.
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?
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.
=> 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.
(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.
[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:
<20261027141625.CCD2884D05@mail.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-mailShow 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: Taylor R Campbell <riastradh@NetBSD.org> Newsgroups: muc.lists.netbsd.tech.kern Subject: bus_dma without bouncing Date: Tue, 27 Oct 2026 14:16:24 +0000 Organization: Newsgate at muc.de e.V. Sender: tech-kern-owner@NetBSD.org Approved: news-admin@muc.de Distribution: world Message-ID: <20261027141625.CCD2884D05@mail.netbsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="11428"; mail-complaints-to="news-admin@muc.de" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netbsd.org; s=20240131; t=1793110589; bh=mta2OWLpFD4MVaZHh0tMhthVuYSqv5WDnRchOF8K0ss=; h=To:Subject:Date:From:List-Id:List-Unsubscribe; b=vegCnRWPPJVBYjOE01rF8IeLpfkQBV6V/B6CjfMg05lN+Vge4bjYkNyNE7ew5s254 Vrn74LLeC23iQ0N9p3PMdiiJGWjljN/YbZW9HKICkh1jjuwkFMEoTM/7tvP5nZVC63 vFRk3q/GdmmQlMAbUf7CARaH/Yz/DCJsFCnUBsw8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netbsd.org; s=20240131; t=1793110585; bh=mta2OWLpFD4MVaZHh0tMhthVuYSqv5WDnRchOF8K0ss=; h=To:Subject:Date:From; b=h90OY0V+NdITex8KDov1yKYcSKKTJlYsIeNcQPIac7+8rS3aVRu9gM6TxoRGhmUIn ipsRiK4z04pYhcuOmRtJuFXG1lcE5ODiLMwqy+h5haS8vcmvAvsCZs98BiR139G6T0 OmvJbyF1Pa6pZWWGxB8+lQCDhF71vdCMmKNRDLoI= Precedence: bulk X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes