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]

Signed-off-by: Lorenzo Delgado <[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,
--  
Lorenzo Delgado <[email protected]>


Reply via email to