From: Boqun Feng <boqun.feng@gmail.com>
To: Filipe Xavier <felipeaggger@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
rust-for-linux@vger.kernel.org,
"Filipe Xavier" <felipe_life@live.com>
Subject: Re: [PATCH] rust: generalize userSliceReader to support any Vec
Date: Sun, 22 Dec 2024 09:20:12 -0800 [thread overview]
Message-ID: <Z2hKTPIBaJ2K9HJn@boqun-archlinux> (raw)
In-Reply-To: <20241222-gen-userslice-readall-alloc-v1-1-c57b7d4972f0@gmail.com>
On Sun, Dec 22, 2024 at 01:37:02PM -0300, Filipe Xavier wrote:
> The UserSliceReader::read_all function is currently restricted to use
> only Vec with the kmalloc allocator.
> However, there is no reason for this limitation.
> This patch generalizes the function to accept any Vec regardless of the
> allocator used.
>
Interesting idea, however...
> Link: https://github.com/Rust-for-Linux/linux/issues/1136
> Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
> ---
> rust/kernel/uaccess.rs | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
> index cc044924867b89f6116c7f9ec216d8cea2b3f8d7..719b0a48ff5550acc19f2e607c0a09f818145def 100644
> --- a/rust/kernel/uaccess.rs
> +++ b/rust/kernel/uaccess.rs
> @@ -5,7 +5,7 @@
> //! C header: [`include/linux/uaccess.h`](srctree/include/linux/uaccess.h)
>
> use crate::{
> - alloc::Flags,
> + alloc::{Allocator, Flags},
> bindings,
> error::Result,
> ffi::c_void,
> @@ -127,7 +127,7 @@ pub fn new(ptr: UserPtr, length: usize) -> Self {
> /// Reads the entirety of the user slice, appending it to the end of the provided buffer.
> ///
> /// Fails with [`EFAULT`] if the read happens on a bad address.
> - pub fn read_all(self, buf: &mut KVec<u8>, flags: Flags) -> Result {
> + pub fn read_all<A: Allocator>(self, buf: &mut Vec<u8, A>, flags: Flags) -> Result {
> self.reader().read_all(buf, flags)
> }
>
> @@ -281,7 +281,7 @@ pub fn read<T: FromBytes>(&mut self) -> Result<T> {
> /// Reads the entirety of the user slice, appending it to the end of the provided buffer.
> ///
> /// Fails with [`EFAULT`] if the read happens on a bad address.
> - pub fn read_all(mut self, buf: &mut KVec<u8>, flags: Flags) -> Result {
> + pub fn read_all<A: Allocator>(mut self, buf: &mut Vec<u8, A>, flags: Flags) -> Result {
... what if the copy hit a page fault because the target memory (e.g. a
VVec) is not mapped? Would copy_from_user() handle this? Or would it
return a different error code than `EFAULT`?
Do you have a usage of usig this functionality?
Regards,
Boqun
> let len = self.length;
> buf.reserve(len, flags)?;
>
>
> ---
> base-commit: 0c5928deada15a8d075516e6e0d9ee19011bb000
> change-id: 20241222-gen-userslice-readall-alloc-8049c668e65e
>
> Best regards,
> --
> Filipe Xavier <felipeaggger@gmail.com>
>
next prev parent reply other threads:[~2024-12-22 17:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-22 16:37 [PATCH] rust: generalize userSliceReader to support any Vec Filipe Xavier
2024-12-22 17:20 ` Boqun Feng [this message]
2024-12-30 13:21 ` Alice Ryhl
2024-12-30 16:23 ` Boqun Feng
2025-01-06 13:34 ` Alice Ryhl
2025-01-06 15:31 ` Boqun Feng
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=Z2hKTPIBaJ2K9HJn@boqun-archlinux \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=felipe_life@live.com \
--cc=felipeaggger@gmail.com \
--cc=gary@garyguo.net \
--cc=ojeda@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 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.