From: "Onur Özkan" <work@onurozkan.dev>
To: "Onur Özkan" <work@onurozkan.dev>
Cc: "Younes Akhouayri via B4 Relay"
<devnull+git.younes.io@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>,
driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
"Younes Akhouayri" <git@younes.io>
Subject: Re: [PATCH v2] rust: dma: return zero for Coherent reads past EOF
Date: Sun, 2 Aug 2026 17:51:17 +0300 [thread overview]
Message-ID: <20260802145118.236139-1-work@onurozkan.dev> (raw)
In-Reply-To: <20260802135442.140218-1-work@onurozkan.dev>
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>
> >
> >
next prev parent reply other threads:[~2026-08-02 14:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 16:34 [PATCH v2] rust: dma: return zero for Coherent reads past EOF Younes Akhouayri via B4 Relay
2026-07-30 16:34 ` Younes Akhouayri
2026-08-01 6:01 ` Alexandre Courbot
2026-08-02 13:54 ` Onur Özkan
2026-08-02 14:51 ` Onur Özkan [this message]
2026-08-03 20:52 ` Danilo Krummrich
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=20260802145118.236139-1-work@onurozkan.dev \
--to=work@onurozkan.dev \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=devnull+git.younes.io@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=git@younes.io \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.