]> www.infradead.org Git - users/jedix/linux-maple.git/commit
rust: list: support heterogeneous lists
authorAlice Ryhl <aliceryhl@google.com>
Wed, 14 Aug 2024 08:05:28 +0000 (08:05 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Fri, 23 Aug 2024 04:26:57 +0000 (06:26 +0200)
commit2003c04b059759b0ec3bff108f24ded9de86a726
treec6e6eabf0291c197be28bba47fa11655ebc40311
parent9078a4f956dbef9366e1657915c883b380e6db39
rust: list: support heterogeneous lists

Support linked lists that can hold many different structs at once. This
is generally done using trait objects. The main challenge is figuring
what the struct is given only a pointer to the ListLinks.

We do this by storing a pointer to the struct next to the ListLinks
field. The container_of operation will then just read that pointer. When
the type is a trait object, that pointer will be a fat pointer whose
metadata is a vtable that tells you what kind of struct it is.

Heterogeneous lists are heavily used by Rust Binder. There are a lot of
so-called todo lists containing various events that need to be delivered
to userspace next time userspace calls into the driver. And there are
quite a few different todo item types: incoming transaction, changes to
refcounts, death notifications, and more.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240814-linked-list-v5-9-f5f5e8075da0@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/list.rs
rust/kernel/list/impl_list_item_mod.rs