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: <dce117a2-3e07-4fd6-a2cf-e06db8306249@proton.me>
Date: Tue, 20 Aug 2024 07:35:37 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Matt Gilbride <mattgilbride@...gle.com>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...sung.com>, Alice Ryhl <aliceryhl@...gle.com>, 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>, Christian Brauner <brauner@...nel.org>
Cc: Rob Landley <rob@...dley.net>, Davidlohr Bueso <dave@...olabs.net>, Michel Lespinasse <michel@...pinasse.org>, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v10 3/5] rust: rbtree: add mutable iterator

On 19.08.24 17:07, Matt Gilbride wrote:
> From: Wedson Almeida Filho <wedsonaf@...il.com>
> 
> Add mutable Iterator implementation for `RBTree`,
> allowing iteration over (key, value) pairs in key order. Only values are
> mutable, as mutating keys implies modifying a node's position in the tree.
> 
> Mutable iteration is used by the binder driver during shutdown to
> clean up the tree maintained by the "range allocator" [1].
> 
> Link: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-6-08ba9197f637@google.com/ [1]
> Signed-off-by: Wedson Almeida Filho <wedsonaf@...il.com>
> Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> Tested-by: Alice Ryhl <aliceryhl@...gle.com>
> Reviewed-by: Boqun Feng <boqun.feng@...il.com>
> Signed-off-by: Matt Gilbride <mattgilbride@...gle.com>
> ---

I got one nit below, but it already looks good:

Reviewed-by: Benno Lossin <benno.lossin@...ton.me>

>  rust/kernel/rbtree.rs | 104 +++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 90 insertions(+), 14 deletions(-)

[...]

> +impl<K, V> Iterator for IterRaw<K, V> {
> +    type Item = (*mut K, *mut V);
> +
>      fn next(&mut self) -> Option<Self::Item> {
>          if self.next.is_null() {
>              return None;
>          }
> 
> -        // SAFETY: By the type invariant of `Iter`, `self.next` is a valid node in an `RBTree`,
> +        // SAFETY: By the type invariant of `IterRaw`, `self.next` is a valid node in an `RBTree`,
>          // and by the type invariant of `RBTree`, all nodes point to the links field of `Node<K, V>` objects.
> -        let cur = unsafe { container_of!(self.next, Node<K, V>, links) };
> +        let cur: *mut Node<K, V> =

Do you need to specify this type? If not then the line would fit on one.

---
Cheers,
Benno

> +            unsafe { container_of!(self.next, Node<K, V>, links) }.cast_mut();
> 
>          // SAFETY: `self.next` is a valid tree node by the type invariants.
>          self.next = unsafe { bindings::rb_next(self.next) };
> 
> -        // SAFETY: By the same reasoning above, it is safe to dereference the node. Additionally,
> -        // it is ok to return a reference to members because the iterator must outlive it.
> -        Some(unsafe { (&(*cur).key, &(*cur).value) })
> +        // SAFETY: By the same reasoning above, it is safe to dereference the node.
> +        Some(unsafe { (addr_of_mut!((*cur).key), addr_of_mut!((*cur).value)) })
>      }
>  }
> 
> 
> --
> 2.46.0.184.g6999bdac58-goog
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ