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: <DBOE907J16WH.1IOU3M11RX5SH@kernel.org>
Date: Tue, 29 Jul 2025 10:25:33 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Vitaly Wool" <vitaly.wool@...sulko.se>
Cc: <linux-mm@...ck.org>, <akpm@...ux-foundation.org>,
 <linux-kernel@...r.kernel.org>, "Uladzislau Rezki" <urezki@...il.com>,
 "Alice Ryhl" <aliceryhl@...gle.com>, "Vlastimil Babka" <vbabka@...e.cz>,
 <rust-for-linux@...r.kernel.org>, "Lorenzo Stoakes"
 <lorenzo.stoakes@...cle.com>, "Liam R . Howlett" <Liam.Howlett@...cle.com>,
 "Kent Overstreet" <kent.overstreet@...ux.dev>,
 <linux-bcachefs@...r.kernel.org>, <bpf@...r.kernel.org>, "Herbert Xu"
 <herbert@...dor.apana.org.au>, "Jann Horn" <jannh@...gle.com>, "Pedro
 Falcato" <pfalcato@...e.de>
Subject: Re: [PATCH v13 3/4] rust: add support for NUMA ids in allocations

On Tue Jul 15, 2025 at 3:58 PM CEST, Vitaly Wool wrote:
>  pub unsafe trait Allocator {
> -    /// Allocate memory based on `layout` and `flags`.
> +    /// Allocate memory based on `layout`, `flags` and `nid`.
>      ///
>      /// On success, returns a buffer represented as `NonNull<[u8]>` that satisfies the layout
>      /// constraints (i.e. minimum size and alignment as specified by `layout`).
> @@ -153,13 +180,21 @@ pub unsafe trait Allocator {
>      ///
>      /// Additionally, `Flags` are honored as documented in
>      /// <https://docs.kernel.org/core-api/mm-api.html#mm-api-gfp-flags>.
> -    fn alloc(layout: Layout, flags: Flags) -> Result<NonNull<[u8]>, AllocError> {
> +    fn alloc(layout: Layout, flags: Flags, nid: NumaNode) -> Result<NonNull<[u8]>, AllocError> {
>          // SAFETY: Passing `None` to `realloc` is valid by its safety requirements and asks for a
>          // new memory allocation.
> -        unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags) }
> +        unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, nid) }
>      }
>  
> -    /// Re-allocate an existing memory allocation to satisfy the requested `layout`.
> +    /// Re-allocate an existing memory allocation to satisfy the requested `layout` and
> +    /// a specific NUMA node request to allocate the memory for.
> +    ///
> +    /// Systems employing a Non Uniform Memory Access (NUMA) architecture contain collections of
> +    /// hardware resources including processors, memory, and I/O buses, that comprise what is
> +    /// commonly known as a NUMA node.
> +    ///
> +    /// `nid` stands for NUMA id, i. e. NUMA node identifier, which is a non-negative integer
> +    /// if a node needs to be specified, or [`NumaNode::NO_NODE`] if the caller doesn't care.
>      ///
>      /// If the requested size is zero, `realloc` behaves equivalent to `free`.
>      ///
> @@ -196,6 +231,7 @@ unsafe fn realloc(
>          layout: Layout,
>          old_layout: Layout,
>          flags: Flags,
> +        nid: NumaNode,
>      ) -> Result<NonNull<[u8]>, AllocError>;
>  
>      /// Free an existing memory allocation.
> @@ -211,7 +247,15 @@ unsafe fn free(ptr: NonNull<u8>, layout: Layout) {
>          // SAFETY: The caller guarantees that `ptr` points at a valid allocation created by this
>          // allocator. We are passing a `Layout` with the smallest possible alignment, so it is
>          // smaller than or equal to the alignment previously used with this allocation.
> -        let _ = unsafe { Self::realloc(Some(ptr), Layout::new::<()>(), layout, Flags(0)) };
> +        let _ = unsafe {
> +            Self::realloc(
> +                Some(ptr),
> +                Layout::new::<()>(),
> +                layout,
> +                Flags(0),
> +                NumaNode::NO_NODE,
> +            )
> +        };
>      }
>  }

Regarding the change in the Allocator trait, we also have to consider
the Cmalloc allocator in rust/kernel/alloc/allocator_test.rs, which is there to
support userspace tests.

While we're planning to remove this (see also [1]), we still have to consider
it for now.

[1] https://lore.kernel.org/rust-for-linux/20250726180750.2735836-1-ojeda@kernel.org/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ