[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87il3bgoee.fsf@metaspace.dk>
Date: Tue, 30 Jan 2024 10:15:11 +0100
From: "Andreas Hindborg (Samsung)" <nmi@...aspace.dk>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Alice Ryhl <aliceryhl@...gle.com>, Miguel Ojeda <ojeda@...nel.org>, Alex
Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>,
Gary Guo <gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Kees Cook <keescook@...omium.org>,
Al Viro <viro@...iv.linux.org.uk>, Andrew Morton
<akpm@...ux-foundation.org>, Greg Kroah-Hartman
<gregkh@...uxfoundation.org>, Arve Hjønnevåg
<arve@...roid.com>, Todd Kjos
<tkjos@...roid.com>, Martijn Coenen <maco@...roid.com>, Joel Fernandes
<joel@...lfernandes.org>, Carlos Llamas <cmllamas@...gle.com>, Suren
Baghdasaryan <surenb@...gle.com>, Arnd Bergmann <arnd@...db.de>,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org, Christian Brauner <brauner@...nel.org>
Subject: Re: [PATCH 3/3] rust: add abstraction for `struct page`
Boqun Feng <boqun.feng@...il.com> writes:
> On Wed, Jan 24, 2024 at 11:20:23AM +0000, Alice Ryhl wrote:
>> +
>> + /// Maps the page and writes into it from the given buffer.
>> + ///
>> + /// # Safety
>> + ///
>> + /// Callers must ensure that `src` is valid for reading `len` bytes.
>> + pub unsafe fn write(&self, src: *const u8, offset: usize, len: usize) -> Result {
>
> Use a slice like type as `src` maybe? Then the function can be safe:
>
> pub fn write<S: AsRef<[u8]>>(&self, src: S, offset: usize) -> Result
>
> Besides, since `Page` impl `Sync`, shouldn't this `write` and the
> `fill_zero` be a `&mut self` function? Or make them both `unsafe`
> because of potential race and add some safety requirement?
We can add a safe version that takes a slice later, as here [1]. Same
for the with_* that take a closure.
It would be nice to model ownership of pages that are only mapped in
kernel with `&mut`.
BR Andreas
[1] https://github.com/metaspace/linux/blob/702026e6645193fc89b7d55e00dac75fd492bfb8/rust/kernel/pages.rs#L178
Powered by blists - more mailing lists