From: Alice Ryhl <aliceryhl@google.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu, mmaurer@google.com,
rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/8] rust: uaccess: add UserSliceWriter::write_slice_partial()
Date: Tue, 21 Oct 2025 14:00:42 +0000 [thread overview]
Message-ID: <aPeSCuFNrV-_qvBf@google.com> (raw)
In-Reply-To: <20251020222722.240473-4-dakr@kernel.org>
On Tue, Oct 21, 2025 at 12:26:15AM +0200, Danilo Krummrich wrote:
> The existing write_slice() method is a wrapper around copy_to_user() and
> expects the user buffer to be larger than the source buffer.
>
> However, userspace may split up reads in multiple partial operations
> providing an offset into the source buffer and a smaller user buffer.
>
> In order to support this common case, provide a helper for partial
> writes.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> rust/kernel/uaccess.rs | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
> index 2061a7e10c65..40d47e94b54f 100644
> --- a/rust/kernel/uaccess.rs
> +++ b/rust/kernel/uaccess.rs
> @@ -463,6 +463,30 @@ pub fn write_slice(&mut self, data: &[u8]) -> Result {
> Ok(())
> }
>
> + /// Writes raw data to this user pointer from a kernel buffer partially.
> + ///
> + /// This is the same as [`Self::write_slice`] but considers the given `offset` into `data` and
> + /// truncates the write to the boundaries of `self` and `data`.
> + ///
> + /// On success, returns the number of bytes written.
> + pub fn write_slice_partial(&mut self, data: &[u8], offset: file::Offset) -> Result<usize> {
I think for the current function signature, it's kind of weird to take a
file::Offset parameter
On one hand, it is described like a generic function for writing a
partial slice, and if that's what it is, then I would argue it should
take usize because it's an offset into the slice.
On another hand, I think what you're actually trying to do is implement
the simple_[read_from|write_to]_buffer utilities for user slices, but
it's only a "partial" version of those utilities. The full utility takes
a `&mut loff_t` so that it can also perform the required modification to
the offset.
Alice
next prev parent reply other threads:[~2025-10-21 14:00 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-20 22:26 [PATCH v2 0/8] Binary Large Objects for Rust DebugFS Danilo Krummrich
2025-10-20 22:26 ` [PATCH v2 1/8] rust: fs: add file::Offset type alias Danilo Krummrich
2025-10-21 13:40 ` Alice Ryhl
2025-10-21 15:08 ` Miguel Ojeda
2025-10-21 15:26 ` Danilo Krummrich
2025-10-21 16:00 ` Miguel Ojeda
2025-10-21 16:25 ` Danilo Krummrich
2025-10-21 16:47 ` Miguel Ojeda
2025-10-21 17:34 ` Danilo Krummrich
2025-10-21 23:16 ` Miguel Ojeda
2025-10-29 12:49 ` Christian Brauner
2025-10-29 15:26 ` Danilo Krummrich
2025-10-20 22:26 ` [PATCH v2 2/8] rust: uaccess: add UserSliceReader::read_slice_partial() Danilo Krummrich
2025-10-20 22:26 ` [PATCH v2 3/8] rust: uaccess: add UserSliceWriter::write_slice_partial() Danilo Krummrich
2025-10-21 14:00 ` Alice Ryhl [this message]
2025-10-21 14:14 ` Danilo Krummrich
2025-10-21 14:18 ` Alice Ryhl
2025-10-21 14:34 ` Danilo Krummrich
2025-10-22 8:22 ` Alice Ryhl
2025-10-22 9:06 ` Danilo Krummrich
2025-10-20 22:26 ` [PATCH v2 4/8] rust: debugfs: support for binary large objects Danilo Krummrich
2025-10-21 14:03 ` Alice Ryhl
2025-10-22 5:58 ` Alexandre Courbot
2025-10-20 22:26 ` [PATCH v2 5/8] rust: debugfs: support blobs from smart pointers Danilo Krummrich
2025-10-22 5:57 ` Alexandre Courbot
2025-10-22 9:34 ` Danilo Krummrich
2025-10-20 22:26 ` [PATCH v2 6/8] samples: rust: debugfs: add example for blobs Danilo Krummrich
2025-10-20 22:26 ` [PATCH v2 7/8] rust: debugfs: support binary large objects for ScopedDir Danilo Krummrich
2025-10-20 22:26 ` [PATCH v2 8/8] samples: rust: debugfs_scoped: add example for blobs Danilo Krummrich
2025-10-21 7:09 ` [PATCH v2 0/8] Binary Large Objects for Rust DebugFS Greg KH
2025-10-21 21:26 ` Matthew Maurer
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=aPeSCuFNrV-_qvBf@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mmaurer@google.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).