From: Abdiel Janulgue <abdiel.janulgue@gmail.com>
To: acourbot@nvidia.com, jgg@ziepe.ca, lyude@redhat.com, dakr@kernel.org
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Valentin Obst" <kernel@valentinobst.de>,
linux-kernel@vger.kernel.org (open list),
"Marek Szyprowski" <m.szyprowski@samsung.com>,
"Robin Murphy" <robin.murphy@arm.com>,
airlied@redhat.com, rust-for-linux@vger.kernel.org,
iommu@lists.linux.dev (open list:DMA MAPPING HELPERS),
"Petr Tesarik" <petr@tesarici.cz>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"Sui Jingfeng" <sui.jingfeng@linux.dev>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Michael Kelley" <mhklinux@outlook.com>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>
Subject: [PATCH v2 0/2] rust: add initial scatterlist abstraction
Date: Thu, 26 Jun 2025 23:30:06 +0300 [thread overview]
Message-ID: <20250626203247.816273-1-abdiel.janulgue@gmail.com> (raw)
Hi
Took some time to re-work this after the initial feedback but here is
v2 of the scatterlist abstraction.
Basically what this version accomplishes is attempt to enforce proper
use of the scatterlist api for device drivers in Rust. This comes down
to a couple of things:
(1) Ensure ownership of the backing pages is moved to the sg table.
This is done via the SGTablePages trait. By allowing users to implement
this trait, we allow users flexibility in how the list of pages are
stored and organised. During construction, the sg table takes ownership
of an object implementing the SGTablePages trait to build and allocate
the sg table.
(2) Prevent invalid use of the API such as retrieving the DMA address of
entries of an sg table which is not yet mapped for DMA. Another invalid
use is setting the page entries of an sg table which is already mapped
for DMA.
Safe use is enforced using Rust's newtype pattern which allows us to
ensure that only specific variants of `SGTable` objects are allowed to
safely return an iterator. For example a `DeviceSGTable` (a sg table that
is mapped for DMA operation) is the only object allowed to safely iterate
and retrieve the DMA address for sg entries. A `DeviceSGTable` object
likewise is returned only by the safe variant of the dma_map function.
Also, the set_pages interface is now hidden from users of the API and is
only internally called when building the table.
Lastly, a glue layer provides unsafe interfaces to help in writing
Rust abstractions for other kernel subsystems is provided (currently
targeting Lyude's gem shmem work).
I'd like to acknowledge Alexandre Courbot for providing the feedback and
initial idea for the SGTablePages trait approach.
Changes since v2:
- Drop typestate pattern. Introduce SGTablePages trait to enforce ownership
of the pages to SGTable.
Link to v1: https://lore.kernel.org/lkml/20250528221525.1705117-1-abdiel.janulgue@gmail.com/
Abdiel Janulgue (2):
rust: add initial scatterlist bindings
samples: rust: add sample code for scatterlist bindings
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 +
rust/helpers/scatterlist.c | 30 +++
rust/kernel/dma.rs | 18 ++
rust/kernel/lib.rs | 1 +
rust/kernel/scatterlist.rs | 390 ++++++++++++++++++++++++++++++++
samples/rust/rust_dma.rs | 29 ++-
7 files changed, 469 insertions(+), 1 deletion(-)
create mode 100644 rust/helpers/scatterlist.c
create mode 100644 rust/kernel/scatterlist.rs
base-commit: 0303584766b7bdb6564c7e8f13e0b59b6ef44984
--
2.43.0
next reply other threads:[~2025-06-26 20:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-26 20:30 Abdiel Janulgue [this message]
2025-06-26 20:30 ` [PATCH v2 1/2] rust: add initial scatterlist bindings Abdiel Janulgue
2025-06-30 8:34 ` Alexandre Courbot
2025-06-30 12:56 ` Alexandre Courbot
2025-07-02 2:37 ` Alexandre Courbot
2025-07-03 7:03 ` Alexandre Courbot
2025-07-09 11:59 ` Abdiel Janulgue
2025-07-11 7:05 ` Alexandre Courbot
2025-06-26 20:30 ` [PATCH v2 2/2] samples: rust: add sample code for " Abdiel Janulgue
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=20250626203247.816273-1-abdiel.janulgue@gmail.com \
--to=abdiel.janulgue@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=herbert@gondor.apana.org.au \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=kernel@valentinobst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=m.szyprowski@samsung.com \
--cc=mhklinux@outlook.com \
--cc=ojeda@kernel.org \
--cc=petr@tesarici.cz \
--cc=rdunlap@infradead.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=sui.jingfeng@linux.dev \
--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
all inboxes | Powered by JetHome®