Skip to content

Commit da939ef

Browse files
Darksonnakpm00
authored andcommitted
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: Andrew Ballance <andrewjballance@gmail.com> Signed-off-by: Andrew Ballance <andrewjballance@gmail.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Danilo 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: Andrew Morton <akpm@linux-foundation.org>
1 parent 8147bc1 commit da939ef

File tree

6 files changed

+366
-0
lines changed

6 files changed

+366
-0
lines changed

MAINTAINERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14672,6 +14672,8 @@ F: net/mctp/
1467214672

1467314673
MAPLE TREE
1467414674
M: Liam R. Howlett <Liam.Howlett@oracle.com>
14675+
R: Alice Ryhl <aliceryhl@google.com>
14676+
R: Andrew Ballance <andrewjballance@gmail.com>
1467514677
L: maple-tree@lists.infradead.org
1467614678
L: linux-mm@kvack.org
1467714679
S: Supported
@@ -14680,6 +14682,8 @@ F: include/linux/maple_tree.h
1468014682
F: include/trace/events/maple_tree.h
1468114683
F: lib/maple_tree.c
1468214684
F: lib/test_maple_tree.c
14685+
F: rust/helpers/maple_tree.c
14686+
F: rust/kernel/maple_tree.rs
1468314687
F: tools/testing/radix-tree/maple.c
1468414688
F: tools/testing/shared/linux/maple_tree.h
1468514689

include/linux/maple_tree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ struct ma_wr_state {
481481
#define MA_ERROR(err) \
482482
((struct maple_enode *)(((unsigned long)err << 2) | 2UL))
483483

484+
/*
485+
* When changing MA_STATE, remember to also change rust/kernel/maple_tree.rs
486+
*/
484487
#define MA_STATE(name, mt, first, end) \
485488
struct ma_state name = { \
486489
.tree = mt, \

rust/helpers/helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "io.c"
2727
#include "jump_label.c"
2828
#include "kunit.c"
29+
#include "maple_tree.c"
2930
#include "mm.c"
3031
#include "mutex.c"
3132
#include "of.c"

rust/helpers/maple_tree.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/maple_tree.h>
4+
5+
void rust_helper_mt_init_flags(struct maple_tree *mt, unsigned int flags)
6+
{
7+
mt_init_flags(mt, flags);
8+
}

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub mod jump_label;
9696
#[cfg(CONFIG_KUNIT)]
9797
pub mod kunit;
9898
pub mod list;
99+
pub mod maple_tree;
99100
pub mod miscdevice;
100101
pub mod mm;
101102
#[cfg(CONFIG_NET)]

0 commit comments

Comments
 (0)