Skip to content

rust: io: convert ResourceSize into a transparent newtype

Lorenzo Delgado dri-devel driver-core lkml rust-for-linux 4 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected] change-id 20260920-resource-size-newtype-63a82d4f2cdb

Versions newest first

  1. v4 Latest2 patches 1 replyApplied
  2. v31 patch 2 repliesSuperseded inferred link
  3. v21 patch 0 repliesSuperseded inferred link
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch5 repliesSuperseded

Changes in v4 from the cover letter

- New patch 1: return u32 from SGEntry::dma_len(), as suggested by
Danilo.
- Patch 2 no longer touches scatterlist.rs, tyr or nova-core.
- Drop FromSafeCastArch<ResourceSize> for usize. Its only user was the
dma_len() conversion in nova-core.
- Link to v3: https://patch.msgid.link/[email protected]

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/2rust: scatterlist: return u32 from SGEntry::dma_len()drivers/gpu/drm/tyr/vm.rs rust/kernel/scatterlist.rs+3 -70 replies
2/2rust: io: convert ResourceSize into a transparent newtyperust/kernel/io.rs rust/kernel/io/resource.rs+72 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/2] rust: io: convert ResourceSize into a transparent newtype

This turns ResourceSize from a type alias into a #[repr(transparent)] newtype, so that every conversion at the FFI boundary is explicit.

The first patch changes SGEntry::dma_len() to return u32. The length of a DMA segment is an unsigned int on the C side, so it was never a ResourceSize. Doing that first means the newtype patch no longer has to touch tyr or nova-core.

Note that Alexandre's nova_num series [1] rewrites the dma_len() line in nova-core's gsp.rs to usize::from_safe_cast_arch(), which takes a u64. With patch 1 applied, that line needs usize::from_safe_cast() instead, and the FromSafeCastArch import goes away. The two series apply on top of each other without conflicts, so this only shows up as a build error. I can rebase on top of nova_num if it lands first.

[1] https://lore.kernel.org/r/[email protected]

---
Changes in v4:
- New patch 1: return u32 from SGEntry::dma_len(), as suggested by
Danilo.
- Patch 2 no longer touches scatterlist.rs, tyr or nova-core.
- Drop FromSafeCastArch<ResourceSize> for usize. Its only user was the
dma_len() conversion in nova-core.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Rebase on rust-next (v7.3-rc4).
- Implement FromSafeCastArch<ResourceSize> for usize in the kernel crate, next to the type, now that the lossless casts live in kernel::num::casts. Drop the impl from nova-core's num.rs, and switch gsp.rs to usize::from_safe_cast_arch(), the same line the nova-core conversion to kernel::num uses.
- Convert the dma_len() user in tyr, added since v2. Without it, tyr fails to build on 32-bit ARM without LPAE.
- Link to v2: https://lore.kernel.org/r/[email protected]
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Lorenzo Delgado (2):
rust: scatterlist: return u32 from SGEntry::dma_len()
rust: io: convert ResourceSize into a transparent newtype

 drivers/gpu/drm/tyr/vm.rs  |  1 -
 rust/kernel/io.rs          | 74 ++++++++++++++++++++++++++++++++++++++++++----
 rust/kernel/io/resource.rs |  6 ++--
 rust/kernel/scatterlist.rs |  9 ++----
 4 files changed, 75 insertions(+), 15 deletions(-)

---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260920-resource-size-newtype-63a82d4f2cdb

Best regards,

Signature · 1 line
Lorenzo Delgado <[email protected]>