From: Jason Gunthorpe <jgg@ziepe.ca>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: Danilo Krummrich <dakr@kernel.org>,
akpm@linux-foundation.org, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
abdiel.janulgue@gmail.com, lyude@redhat.com,
robin.murphy@arm.com, daniel.almeida@collabora.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/5] rust: scatterlist: Add type-state abstraction for sg_table
Date: Sat, 23 Aug 2025 11:32:11 -0300 [thread overview]
Message-ID: <20250823143211.GB1121521@ziepe.ca> (raw)
In-Reply-To: <DC9U87GQ7ONZ.1489DEN1PPUAC@nvidia.com>
On Sat, Aug 23, 2025 at 10:22:47PM +0900, Alexandre Courbot wrote:
> For reasons I am not completely clear about, the number of mapped
> segments on the device side can be smaller than the number of
> scatterlists provided by the sg_table. This is highlighted by the
> documentation for `dma_map_sg_attrs` [1] ("Returns the number of mapped
> entries (which can be less than nents) on success") and `sg_dma_address`
> [2] ("You should only work with the number of sg entries dma_map_sg
> returns, or alternatively stop on the first sg_dma_len(sg) which is 0.")
> So only calling `sg_next` until we reach the end of the list carries the
> risk that we iterate on more items than we should, with the extra ones
> having their length at 0
Correct, this is misusing the API, and I don't know if the lengths are
even guarenteed to be zero. To iterate the DMA list you must use the
length of the DMA list returned by dma_map_sg() and nothing else as
the stop condition.
To repeat again, the scatterlist data structure is "optimized" and
contains two completely different lists - the CPU list and the DMA
list. The DMA list is always <= the size of the CPU list.
For all purposes they are completely seperate things and we have a
unique set of iterators and accessors for the CPU vs DMA data.
Jason
next prev parent reply other threads:[~2025-08-23 14:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 16:52 [PATCH v2 0/5] Rust infrastructure for sg_table and scatterlist Danilo Krummrich
2025-08-20 16:52 ` [PATCH v2 1/5] rust: dma: implement DataDirection Danilo Krummrich
2025-08-22 11:38 ` Alice Ryhl
2025-08-23 11:09 ` Alexandre Courbot
2025-08-20 16:52 ` [PATCH v2 2/5] rust: dma: add type alias for bindings::dma_addr_t Danilo Krummrich
2025-08-22 11:38 ` Alice Ryhl
2025-08-23 11:10 ` Alexandre Courbot
2025-08-20 16:52 ` [PATCH v2 3/5] rust: scatterlist: Add type-state abstraction for sg_table Danilo Krummrich
2025-08-20 17:14 ` Daniel Almeida
2025-08-22 11:44 ` Alice Ryhl
2025-08-22 11:48 ` Danilo Krummrich
2025-08-22 11:52 ` Alice Ryhl
2025-08-22 11:54 ` Danilo Krummrich
2025-08-23 12:44 ` Alexandre Courbot
2025-08-23 13:22 ` Alexandre Courbot
2025-08-23 13:48 ` Danilo Krummrich
2025-08-23 14:12 ` Alexandre Courbot
2025-08-23 14:32 ` Jason Gunthorpe [this message]
2025-08-23 14:57 ` Danilo Krummrich
2025-08-23 13:47 ` Alexandre Courbot
2025-08-23 13:57 ` Danilo Krummrich
2025-08-23 14:16 ` Alexandre Courbot
2025-08-23 14:20 ` Danilo Krummrich
2025-08-23 14:29 ` Alexandre Courbot
2025-08-20 16:52 ` [PATCH v2 4/5] samples: rust: dma: add sample code for SGTable Danilo Krummrich
2025-08-20 16:52 ` [PATCH v2 5/5] MAINTAINERS: rust: dma: add scatterlist files Danilo Krummrich
2025-08-22 11:45 ` [PATCH v2 0/5] Rust infrastructure for sg_table and scatterlist Alice Ryhl
2025-08-22 13:31 ` Alexandre Courbot
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=20250823143211.GB1121521@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).