Commit da939ef4 authored by Alice Ryhl's avatar Alice Ryhl Committed by Andrew Morton
Browse files

rust: maple_tree: add MapleTree

Patch series "Add Rust abstraction for Maple Trees", v3.

This will be used in the Tyr driver [1] to allocate from the GPU's VA
space that is not owned by userspace, but by the kernel, for kernel GPU
mappings.

Danilo tells me that in nouveau, the maple tree is used for keeping track
of "VM regions" on top of GPUVM, and that he will most likely end up doing
the same in the Rust Nova driver as well.

These abstractions intentionally do not expose any way to make use of
external locking.  You are required to use the internal spinlock.  For
now, we do not support loads that only utilize rcu for protection.

This contains some parts taken from Andrew Ballance's RFC [2] from April. 
However, it has also been reworked significantly compared to that RFC
taking the use-cases in Tyr into account.


This patch (of 3):

The maple tree will be used in the Tyr driver to allocate and keep track
of GPU allocations created internally (i.e.  not by userspace).  It will
likely also be used in the Nova driver eventually.

This adds the simplest methods for additional and removal that do not
require any special care with respect to concurrency.

This implementation is based on the RFC by Andrew but with significant
changes to simplify the implementation.

[ojeda@kernel.org: fix intra-doc links]
  Link: https://lkml.kernel.org/r/20250910140212.997771-1-ojeda@kernel.org
Link: https://lkml.kernel.org/r/20250902-maple-tree-v3-0-fb5c8958fb1e@google.com
Link: https://lkml.kernel.org/r/20250902-maple-tree-v3-1-fb5c8958fb1e@google.com
Link: https://lore.kernel.org/r/20250627-tyr-v1-1-cb5f4c6ced46@collabora.com [1]
Link: https://lore.kernel.org/r/20250405060154.1550858-1-andrewjballance@gmail.com

 [2]
Co-developed-by: default avatarAndrew Ballance <andrewjballance@gmail.com>
Signed-off-by: default avatarAndrew Ballance <andrewjballance@gmail.com>
Signed-off-by: default avatarAlice Ryhl <aliceryhl@google.com>
Reviewed-by: default avatarDanilo Krummrich <dakr@kernel.org>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Daniel Almeida <daniel.almeida@collabora.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Trevor Gross <tmgross@umich.edu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 8147bc15
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -14672,6 +14672,8 @@ F: net/mctp/
MAPLE TREE
M:	Liam R. Howlett <Liam.Howlett@oracle.com>
R:	Alice Ryhl <aliceryhl@google.com>
R:	Andrew Ballance <andrewjballance@gmail.com>
L:	maple-tree@lists.infradead.org
L:	linux-mm@kvack.org
S:	Supported
@@ -14680,6 +14682,8 @@ F: include/linux/maple_tree.h
F:	include/trace/events/maple_tree.h
F:	lib/maple_tree.c
F:	lib/test_maple_tree.c
F:	rust/helpers/maple_tree.c
F:	rust/kernel/maple_tree.rs
F:	tools/testing/radix-tree/maple.c
F:	tools/testing/shared/linux/maple_tree.h
+3 −0
Original line number Diff line number Diff line
@@ -481,6 +481,9 @@ struct ma_wr_state {
#define MA_ERROR(err) \
		((struct maple_enode *)(((unsigned long)err << 2) | 2UL))

/*
 * When changing MA_STATE, remember to also change rust/kernel/maple_tree.rs
 */
#define MA_STATE(name, mt, first, end)					\
	struct ma_state name = {					\
		.tree = mt,						\
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "io.c"
#include "jump_label.c"
#include "kunit.c"
#include "maple_tree.c"
#include "mm.c"
#include "mutex.c"
#include "of.c"
+8 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0

#include <linux/maple_tree.h>

void rust_helper_mt_init_flags(struct maple_tree *mt, unsigned int flags)
{
	mt_init_flags(mt, flags);
}
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@
#[cfg(CONFIG_KUNIT)]
pub mod kunit;
pub mod list;
pub mod maple_tree;
pub mod miscdevice;
pub mod mm;
#[cfg(CONFIG_NET)]
Loading