* [PATCH v2] rust: dma: return zero for Coherent reads past EOF
@ 2026-07-30 16:34 Younes Akhouayri via B4 Relay
2026-08-01 6:01 ` Alexandre Courbot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Younes Akhouayri via B4 Relay @ 2026-07-30 16:34 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
Tamir Duberstein, Alexandre Courbot, Onur Özkan, Timur Tabi
Cc: driver-core, rust-for-linux, linux-kernel, stable,
Younes Akhouayri
From: Younes Akhouayri <git@younes.io>
Coherent<T>::write_to_slice() calculates a zero-byte copy when the file
offset is beyond the allocation, but still calls
UserSliceWriter::write_dma(). The latter rejects offsets beyond the
allocation even when the copy length is zero, so a debugfs read past EOF
returns -ERANGE.
Return before calling write_dma() when the offset is at or beyond the
allocation, matching simple_read_from_buffer() EOF semantics.
Fixes: 016818513936 ("rust: dma: implement BinaryWriter for Coherent<[u8]>")
Cc: stable@vger.kernel.org
Link: https://rust-for-linux.zulipchat.com/#narrow/channel/291566-Library/topic/.E2.9C.94.20Possible.20past-EOF.20bug.20in.20Coherent.3CT.3E.3A.3Awrite_to_slice/near/611677095
Signed-off-by: Younes Akhouayri <git@younes.io>
---
Changes in v2:
- Use ordinary subtraction after the explicit EOF check, which makes
underflow impossible.
- Link to v1: https://patch.msgid.link/20260720-fix-dma-coherent-eof-v1-1-d92685db8da6@younes.io
---
rust/kernel/dma.rs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 200def84fb69..556424b88fb9 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -1005,7 +1005,11 @@ fn write_to_slice(
return Ok(0);
};
- let count = self.size().saturating_sub(offset_val).min(writer.len());
+ if offset_val >= self.size() {
+ return Ok(0);
+ }
+
+ let count = (self.size() - offset_val).min(writer.len());
writer.write_dma(self, offset_val, count)?;
---
base-commit: 667d0fb32149f023b8b34a1f6f3d384556eafb5a
change-id: 20260720-fix-dma-coherent-eof-d0d08c91e013
Best regards,
--
Younes Akhouayri <git@younes.io>
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] rust: dma: return zero for Coherent reads past EOF
2026-07-30 16:34 [PATCH v2] rust: dma: return zero for Coherent reads past EOF Younes Akhouayri via B4 Relay
@ 2026-08-01 6:01 ` Alexandre Courbot
2026-08-02 13:54 ` Onur Özkan
2026-08-03 20:52 ` Danilo Krummrich
2 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2026-08-01 6:01 UTC (permalink / raw)
To: Younes Akhouayri via B4 Relay
Cc: git, Danilo Krummrich, Abdiel Janulgue, Daniel Almeida,
Robin Murphy, Andreas Hindborg, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
Trevor Gross, Tamir Duberstein, Onur Özkan, Timur Tabi,
driver-core, rust-for-linux, linux-kernel, stable
On Fri Jul 31, 2026 at 1:34 AM JST, Younes Akhouayri via B4 Relay wrote:
> From: Younes Akhouayri <git@younes.io>
>
> Coherent<T>::write_to_slice() calculates a zero-byte copy when the file
> offset is beyond the allocation, but still calls
> UserSliceWriter::write_dma(). The latter rejects offsets beyond the
> allocation even when the copy length is zero, so a debugfs read past EOF
> returns -ERANGE.
>
> Return before calling write_dma() when the offset is at or beyond the
> allocation, matching simple_read_from_buffer() EOF semantics.
>
> Fixes: 016818513936 ("rust: dma: implement BinaryWriter for Coherent<[u8]>")
> Cc: stable@vger.kernel.org
> Link: https://rust-for-linux.zulipchat.com/#narrow/channel/291566-Library/topic/.E2.9C.94.20Possible.20past-EOF.20bug.20in.20Coherent.3CT.3E.3A.3Awrite_to_slice/near/611677095
> Signed-off-by: Younes Akhouayri <git@younes.io>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] rust: dma: return zero for Coherent reads past EOF
2026-07-30 16:34 [PATCH v2] rust: dma: return zero for Coherent reads past EOF Younes Akhouayri via B4 Relay
2026-08-01 6:01 ` Alexandre Courbot
@ 2026-08-02 13:54 ` Onur Özkan
2026-08-02 14:51 ` Onur Özkan
2026-08-03 20:52 ` Danilo Krummrich
2 siblings, 1 reply; 5+ messages in thread
From: Onur Özkan @ 2026-08-02 13:54 UTC (permalink / raw)
To: Younes Akhouayri via B4 Relay
Cc: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
Tamir Duberstein, Alexandre Courbot, Timur Tabi, driver-core,
rust-for-linux, linux-kernel, stable, Younes Akhouayri
On Thu, 30 Jul 2026 18:34:38 +0200
Younes Akhouayri via B4 Relay <devnull+git.younes.io@kernel.org> wrote:
> From: Younes Akhouayri <git@younes.io>
>
> Coherent<T>::write_to_slice() calculates a zero-byte copy when the file
> offset is beyond the allocation, but still calls
> UserSliceWriter::write_dma(). The latter rejects offsets beyond the
> allocation even when the copy length is zero, so a debugfs read past EOF
> returns -ERANGE.
>
> Return before calling write_dma() when the offset is at or beyond the
> allocation, matching simple_read_from_buffer() EOF semantics.
>
> Fixes: 016818513936 ("rust: dma: implement BinaryWriter for Coherent<[u8]>")
> Cc: stable@vger.kernel.org
> Link: https://rust-for-linux.zulipchat.com/#narrow/channel/291566-Library/topic/.E2.9C.94.20Possible.20past-EOF.20bug.20in.20Coherent.3CT.3E.3A.3Awrite_to_slice/near/611677095
> Signed-off-by: Younes Akhouayri <git@younes.io>
> ---
> Changes in v2:
> - Use ordinary subtraction after the explicit EOF check, which makes
> underflow impossible.
> - Link to v1: https://patch.msgid.link/20260720-fix-dma-coherent-eof-v1-1-d92685db8da6@younes.io
> ---
> rust/kernel/dma.rs | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> index 200def84fb69..556424b88fb9 100644
> --- a/rust/kernel/dma.rs
> +++ b/rust/kernel/dma.rs
> @@ -1005,7 +1005,11 @@ fn write_to_slice(
> return Ok(0);
> };
>
> - let count = self.size().saturating_sub(offset_val).min(writer.len());
Nit: I would probably just check if `count` is zero next to this line.
> + if offset_val >= self.size() {
> + return Ok(0);
> + }
> +
> + let count = (self.size() - offset_val).min(writer.len());
>
> writer.write_dma(self, offset_val, count)?;
>
>
> ---
> base-commit: 667d0fb32149f023b8b34a1f6f3d384556eafb5a
> change-id: 20260720-fix-dma-coherent-eof-d0d08c91e013
>
> Best regards,
> --
> Younes Akhouayri <git@younes.io>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] rust: dma: return zero for Coherent reads past EOF
2026-08-02 13:54 ` Onur Özkan
@ 2026-08-02 14:51 ` Onur Özkan
0 siblings, 0 replies; 5+ messages in thread
From: Onur Özkan @ 2026-08-02 14:51 UTC (permalink / raw)
To: Onur Özkan
Cc: Younes Akhouayri via B4 Relay, Danilo Krummrich, Abdiel Janulgue,
Daniel Almeida, Robin Murphy, Andreas Hindborg, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Alice Ryhl, Trevor Gross, Tamir Duberstein, Alexandre Courbot,
Timur Tabi, driver-core, rust-for-linux, linux-kernel, stable,
Younes Akhouayri
On Sun, 02 Aug 2026 16:54:40 +0300
Onur Özkan <work@onurozkan.dev> wrote:
> On Thu, 30 Jul 2026 18:34:38 +0200
> Younes Akhouayri via B4 Relay <devnull+git.younes.io@kernel.org> wrote:
>
> > From: Younes Akhouayri <git@younes.io>
> >
> > Coherent<T>::write_to_slice() calculates a zero-byte copy when the file
> > offset is beyond the allocation, but still calls
> > UserSliceWriter::write_dma(). The latter rejects offsets beyond the
> > allocation even when the copy length is zero, so a debugfs read past EOF
> > returns -ERANGE.
> >
> > Return before calling write_dma() when the offset is at or beyond the
> > allocation, matching simple_read_from_buffer() EOF semantics.
> >
> > Fixes: 016818513936 ("rust: dma: implement BinaryWriter for Coherent<[u8]>")
> > Cc: stable@vger.kernel.org
> > Link: https://rust-for-linux.zulipchat.com/#narrow/channel/291566-Library/topic/.E2.9C.94.20Possible.20past-EOF.20bug.20in.20Coherent.3CT.3E.3A.3Awrite_to_slice/near/611677095
> > Signed-off-by: Younes Akhouayri <git@younes.io>
> > ---
> > Changes in v2:
> > - Use ordinary subtraction after the explicit EOF check, which makes
> > underflow impossible.
> > - Link to v1: https://patch.msgid.link/20260720-fix-dma-coherent-eof-v1-1-d92685db8da6@younes.io
> > ---
> > rust/kernel/dma.rs | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> > index 200def84fb69..556424b88fb9 100644
> > --- a/rust/kernel/dma.rs
> > +++ b/rust/kernel/dma.rs
> > @@ -1005,7 +1005,11 @@ fn write_to_slice(
> > return Ok(0);
> > };
> >
> > - let count = self.size().saturating_sub(offset_val).min(writer.len());
>
> Nit: I would probably just check if `count` is zero next to this line.
I just noticed there is already been quite a bit of discussion about this topic
so you can ignore my comment since it was just a "nit" anyway. I don't think
there's much difference either way, so there's probably no need to reignite the
discussion.
Thanks for the fix.
Reviewed-by: Onur Özkan <work@onurozkan.dev>
>
> > + if offset_val >= self.size() {
> > + return Ok(0);
> > + }
> > +
> > + let count = (self.size() - offset_val).min(writer.len());
> >
> > writer.write_dma(self, offset_val, count)?;
> >
> >
> > ---
> > base-commit: 667d0fb32149f023b8b34a1f6f3d384556eafb5a
> > change-id: 20260720-fix-dma-coherent-eof-d0d08c91e013
> >
> > Best regards,
> > --
> > Younes Akhouayri <git@younes.io>
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] rust: dma: return zero for Coherent reads past EOF
2026-07-30 16:34 [PATCH v2] rust: dma: return zero for Coherent reads past EOF Younes Akhouayri via B4 Relay
2026-08-01 6:01 ` Alexandre Courbot
2026-08-02 13:54 ` Onur Özkan
@ 2026-08-03 20:52 ` Danilo Krummrich
2 siblings, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2026-08-03 20:52 UTC (permalink / raw)
To: Younes Akhouayri
Cc: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
Tamir Duberstein, Alexandre Courbot, Onur Özkan, Timur Tabi,
driver-core, rust-for-linux, linux-kernel, stable
On Thu, 30 Jul 2026 18:34:38 +0200, Younes Akhouayri wrote:
> [PATCH v2] rust: dma: return zero for Coherent reads past EOF
Applied, thanks!
Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
[1/1] rust: dma: return zero for Coherent reads past EOF
commit: 5391b147d9fd
The patch will appear in the next linux-next integration (typically within 24
hours on weekdays).
The patch is in the driver-core-testing branch and will be promoted to
driver-core-next after validation.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-03 20:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-30 16:34 [PATCH v2] rust: dma: return zero for Coherent reads past EOF Younes Akhouayri via B4 Relay
2026-08-01 6:01 ` Alexandre Courbot
2026-08-02 13:54 ` Onur Özkan
2026-08-02 14:51 ` Onur Özkan
2026-08-03 20:52 ` Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox