lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <01106f43-3338-4eec-bd6b-2ee820f7267c@kernel.org>
Date: Thu, 15 Aug 2024 14:17:41 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com,
 boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
 benno.lossin@...ton.me, a.hindborg@...sung.com, akpm@...ux-foundation.org,
 daniel.almeida@...labora.com, faith.ekstrand@...labora.com,
 boris.brezillon@...labora.com, lina@...hilina.net, mcanal@...lia.com,
 zhiw@...dia.com, cjia@...dia.com, jhubbard@...dia.com, airlied@...hat.com,
 ajanulgu@...hat.com, lyude@...hat.com, linux-kernel@...r.kernel.org,
 rust-for-linux@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v5 13/26] rust: alloc: implement kernel `Vec` type

On 8/15/24 9:30 AM, Alice Ryhl wrote:
> On Thu, Aug 15, 2024 at 12:46 AM Danilo Krummrich <dakr@...nel.org> wrote:
>>
>> On Wed, Aug 14, 2024 at 10:42:28AM +0200, Alice Ryhl wrote:
>>>> +#[macro_export]
>>>> +macro_rules! kvec {
>>>> +    () => (
>>>> +        {
>>>> +            $crate::alloc::KVec::new()
>>>> +        }
>>>> +    );
>>>> +    ($elem:expr; $n:expr) => (
>>>> +        {
>>>> +            $crate::alloc::KVec::from_elem($elem, $n, GFP_KERNEL)
>>>> +        }
>>>> +    );
>>>> +    ($($x:expr),+ $(,)?) => (
>>>> +        {
>>>> +            match $crate::alloc::KBox::new([$($x),+], GFP_KERNEL) {
>>>> +                Ok(b) => Ok($crate::alloc::KBox::into_vec(b)),
>>>> +                Err(e) => Err(e),
>>>
>>> Hmm. This currently generates code that:
>>>
>>> 1. Creates the array.
>>> 2. Allocates the memory.
>>> 3. Moves the array into the box.
>>>
>>> Whereas the stdlib macro swaps step 1 and 2.
>>
>> Isn't stdlib [1] doing the same thing I do?
>>
>> [1] https://doc.rust-lang.org/1.80.1/src/alloc/macros.rs.html#49
> 
> Stdlib is using something called #[rustc_box] which has the effect I described.
> 
>>> You can do the same by utilizing new_uninit. A sketch:
>>>
>>> match KBox::<[_; _]>::new_uninit(GFP_KERNEL) {
>>
>> How do we get the size here? `#![feature(generic_arg_infer)]` seems to be
>> unstable.
> 
> It probably works if you don't specify the type at all:
> `KBox::new_uninit`. But you should double check.

That works, thanks.

> 
>>>      Ok(b) => Ok(KVec::from(KBox::write(b, [$($x),+]))),
>>>      Err(e) => Err(e),
>>> }
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ