* [PATCH 0/4] rust: Add helper functions and constants for Tyr driver
@ 2026-04-17 1:05 Alvin Sun
2026-04-17 1:05 ` [PATCH 1/4] rust: sizes: add SZ_4G constant Alvin Sun
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 1:05 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein
Cc: rust-for-linux, linux-kernel, linux-mm, Onur Özkan, Alvin Sun
This patchset provides helper functions and constants that will be used
by the Tyr driver's VM and BO related ioctl implementations.
These patches add:
- SZ_4G constant for VA layout calculations
- A task_size() method to Mm for determining process VA space size
- Updated StoreError comments for alloc() usage
- Guard::find() helper for finding the first present entry in XArray
This patchset depends on Onur's xa_alloc implementation [1].
The complete patchset, including the Tyr driver ioctl implementations
can be found at [2].
Link: https://lore.kernel.org/rust-for-linux/20251006163024.18473-1-work@onurozkan.dev/ [1]
Link: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/64 [2]
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
Alvin Sun (4):
rust: sizes: add SZ_4G constant
rust: mm: Add task_size() method to Mm
rust: xarray: Update StoreError comments for alloc()
rust: xarray: Add Guard::find() helper
rust/kernel/mm.rs | 7 +++++++
rust/kernel/sizes.rs | 2 ++
rust/kernel/xarray.rs | 28 +++++++++++++++++++++++++---
3 files changed, 34 insertions(+), 3 deletions(-)
---
base-commit: d1d81e9d1a4dd846aee9ae77ff9ecc2800d72148
change-id: 20260416-tyr-ioctls-deps-25805eedf332
prerequisite-message-id: <20251006163024.18473-1-work@onurozkan.dev>
prerequisite-patch-id: c472a9548969ac774d36fead73378961a0d0489c
prerequisite-patch-id: 63890b91e911cf96cb42308c056d639580ac0fa0
prerequisite-patch-id: 337eb93db35359c611abe9cba299e6ab0525a2b5
Best regards,
--
Alvin Sun <alvin.sun@linux.dev>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/4] rust: sizes: add SZ_4G constant
2026-04-17 1:05 [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Alvin Sun
@ 2026-04-17 1:05 ` Alvin Sun
2026-04-17 3:18 ` Alexandre Courbot
2026-04-17 1:05 ` [PATCH 2/4] rust: mm: Add task_size() method to Mm Alvin Sun
` (3 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 1:05 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein
Cc: rust-for-linux, linux-kernel, linux-mm, Onur Özkan, Alvin Sun
Add SZ_4G constant defined as SZ_2G * 2. This constant will be used by
the Tyr driver for calculating user and kernel VA layout.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/sizes.rs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/rust/kernel/sizes.rs b/rust/kernel/sizes.rs
index 661e680d93306..872f5bb181ecf 100644
--- a/rust/kernel/sizes.rs
+++ b/rust/kernel/sizes.rs
@@ -48,3 +48,5 @@
pub const SZ_1G: usize = bindings::SZ_1G as usize;
/// 0x80000000
pub const SZ_2G: usize = bindings::SZ_2G as usize;
+/// 0x100000000
+pub const SZ_4G: usize = SZ_2G * 2;
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/4] rust: mm: Add task_size() method to Mm
2026-04-17 1:05 [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Alvin Sun
2026-04-17 1:05 ` [PATCH 1/4] rust: sizes: add SZ_4G constant Alvin Sun
@ 2026-04-17 1:05 ` Alvin Sun
2026-04-17 1:05 ` [PATCH 3/4] rust: xarray: Update StoreError comments for alloc() Alvin Sun
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 1:05 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein
Cc: rust-for-linux, linux-kernel, linux-mm, Onur Özkan, Alvin Sun
Add a task_size() method to the Mm struct to expose the process
virtual address space size. This is used by the Tyr driver's VmLayout
to determine the user VA range when VmUserSize::Auto is specified.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/mm.rs | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs
index 4764d7b68f2a7..c6ba4da52688b 100644
--- a/rust/kernel/mm.rs
+++ b/rust/kernel/mm.rs
@@ -149,6 +149,13 @@ pub fn mmget_not_zero(&self) -> Option<ARef<MmWithUser>> {
None
}
}
+
+ /// Returns task size for this mm_struct.
+ #[inline]
+ pub fn task_size(&self) -> u64 {
+ // SAFETY: self.as_raw() is a valid pointer to an mm_struct.
+ unsafe { (*self.as_raw()).__bindgen_anon_1.task_size as u64 }
+ }
}
// These methods require `mm_users` to be non-zero.
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 3/4] rust: xarray: Update StoreError comments for alloc()
2026-04-17 1:05 [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Alvin Sun
2026-04-17 1:05 ` [PATCH 1/4] rust: sizes: add SZ_4G constant Alvin Sun
2026-04-17 1:05 ` [PATCH 2/4] rust: mm: Add task_size() method to Mm Alvin Sun
@ 2026-04-17 1:05 ` Alvin Sun
2026-04-17 1:05 ` [PATCH 4/4] rust: xarray: Add Guard::find() helper Alvin Sun
2026-04-17 7:43 ` [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Onur Özkan
4 siblings, 0 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 1:05 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein
Cc: rust-for-linux, linux-kernel, linux-mm, Onur Özkan, Alvin Sun
Update StoreError documentation comments to mention alloc() usage since
this error type will be used by the upcoming alloc() helper.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/xarray.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index 1b882cd2f58bf..235fda0e394ba 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -161,13 +161,13 @@ fn drop(&mut self) {
}
}
-/// The error returned by [`store`](Guard::store).
+/// The error returned by [`Guard::store`] and [`Guard::alloc`].
///
-/// Contains the underlying error and the value that was not stored.
+/// Contains the underlying error and the value that was not stored or allocated.
pub struct StoreError<T> {
/// The error that occurred.
pub error: Error,
- /// The value that was not stored.
+ /// The value that was not stored or allocated.
pub value: T,
}
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 4/4] rust: xarray: Add Guard::find() helper
2026-04-17 1:05 [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Alvin Sun
` (2 preceding siblings ...)
2026-04-17 1:05 ` [PATCH 3/4] rust: xarray: Update StoreError comments for alloc() Alvin Sun
@ 2026-04-17 1:05 ` Alvin Sun
2026-04-17 1:18 ` Matthew Wilcox
2026-04-17 8:28 ` Onur Özkan
2026-04-17 7:43 ` [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Onur Özkan
4 siblings, 2 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 1:05 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein
Cc: rust-for-linux, linux-kernel, linux-mm, Onur Özkan, Alvin Sun
Add a helper to find the first present entry in the XArray.
Returns the index of the first present entry, or None if the array
is empty.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/xarray.rs | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index 235fda0e394ba..e43129d032d9d 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -217,6 +217,28 @@ pub fn remove(&mut self, index: usize) -> Option<T> {
unsafe { T::try_from_foreign(ptr) }
}
+ /// Finds the first present entry.
+ ///
+ /// Returns the index of the first present entry, or `None` if the array is empty.
+ pub fn find(&mut self) -> Option<usize> {
+ let mut index = 0usize;
+ // SAFETY: `self.xa.xa` is always valid by the type invariant, and we hold the lock.
+ let ptr = unsafe {
+ bindings::xa_find(
+ self.xa.xa.get(),
+ &mut index,
+ usize::MAX,
+ bindings::XA_PRESENT,
+ )
+ };
+
+ if ptr.is_null() {
+ None
+ } else {
+ Some(index)
+ }
+ }
+
/// Stores an element at the given index.
///
/// May drop the lock if needed to allocate memory, and then reacquire it afterwards.
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] rust: xarray: Add Guard::find() helper
2026-04-17 1:05 ` [PATCH 4/4] rust: xarray: Add Guard::find() helper Alvin Sun
@ 2026-04-17 1:18 ` Matthew Wilcox
2026-04-17 2:16 ` Alvin Sun
2026-04-17 8:28 ` Onur Özkan
1 sibling, 1 reply; 13+ messages in thread
From: Matthew Wilcox @ 2026-04-17 1:18 UTC (permalink / raw)
To: Alvin Sun
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm,
Onur Özkan
On Fri, Apr 17, 2026 at 09:05:54AM +0800, Alvin Sun wrote:
> Add a helper to find the first present entry in the XArray.
Why would you expose a function which does striclty less than the
underlying C implementation, rather than exposing all the functionality
that xa_find does?
> Returns the index of the first present entry, or None if the array
> is empty.
Why not return the value found, like xa_find() does?
This is all very troubling. I don't think Rust should depart from
what C has without good reason.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] rust: xarray: Add Guard::find() helper
2026-04-17 1:18 ` Matthew Wilcox
@ 2026-04-17 2:16 ` Alvin Sun
0 siblings, 0 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 2:16 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm,
Onur Özkan
On 4/17/26 09:18, Matthew Wilcox wrote:
> On Fri, Apr 17, 2026 at 09:05:54AM +0800, Alvin Sun wrote:
>> Add a helper to find the first present entry in the XArray.
> Why would you expose a function which does striclty less than the
> underlying C implementation, rather than exposing all the functionality
> that xa_find does?
>
>> Returns the index of the first present entry, or None if the array
>> is empty.
> Why not return the value found, like xa_find() does?
Hi Matthew,
Thanks for the feedback! I had considered both returning a tuple (key,
&value)
and an Entry struct, but only returned the key since that's all Tyr
currently
needs. I'll look at other Rust code to see which approach fits better, then
implement it properly in v2.
Best regards,
Alvin
>
> This is all very troubling. I don't think Rust should depart from
> what C has without good reason.
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/4] rust: sizes: add SZ_4G constant
2026-04-17 1:05 ` [PATCH 1/4] rust: sizes: add SZ_4G constant Alvin Sun
@ 2026-04-17 3:18 ` Alexandre Courbot
2026-04-17 11:56 ` Alvin Sun
0 siblings, 1 reply; 13+ messages in thread
From: Alexandre Courbot @ 2026-04-17 3:18 UTC (permalink / raw)
To: Alvin Sun
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm,
Onur Özkan
Hi Alvin,
On Fri Apr 17, 2026 at 10:05 AM JST, Alvin Sun wrote:
> Add SZ_4G constant defined as SZ_2G * 2. This constant will be used by
> the Tyr driver for calculating user and kernel VA layout.
>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> rust/kernel/sizes.rs | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/rust/kernel/sizes.rs b/rust/kernel/sizes.rs
> index 661e680d93306..872f5bb181ecf 100644
> --- a/rust/kernel/sizes.rs
> +++ b/rust/kernel/sizes.rs
> @@ -48,3 +48,5 @@
> pub const SZ_1G: usize = bindings::SZ_1G as usize;
> /// 0x80000000
> pub const SZ_2G: usize = bindings::SZ_2G as usize;
> +/// 0x100000000
> +pub const SZ_4G: usize = SZ_2G * 2;
Note that the way size constants are defined has changed in `master` -
you will probably want to update this patch accordingly.
Also there is a `SZ_4G` define in `include/linux/sizes.h`; I am not sure
why it is not in the bindings, but we should probably add it and get our
value from that.
Finally, maybe I missed something but the new value doesn't appear to be
used by this series?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] rust: Add helper functions and constants for Tyr driver
2026-04-17 1:05 [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Alvin Sun
` (3 preceding siblings ...)
2026-04-17 1:05 ` [PATCH 4/4] rust: xarray: Add Guard::find() helper Alvin Sun
@ 2026-04-17 7:43 ` Onur Özkan
2026-04-17 12:44 ` Alvin Sun
4 siblings, 1 reply; 13+ messages in thread
From: Onur Özkan @ 2026-04-17 7:43 UTC (permalink / raw)
To: Alvin Sun
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm
On Fri, 17 Apr 2026 09:05:50 +0800
Alvin Sun <alvin.sun@linux.dev> wrote:
> This patchset provides helper functions and constants that will be used
> by the Tyr driver's VM and BO related ioctl implementations.
>
> These patches add:
> - SZ_4G constant for VA layout calculations
> - A task_size() method to Mm for determining process VA space size
> - Updated StoreError comments for alloc() usage
> - Guard::find() helper for finding the first present entry in XArray
>
> This patchset depends on Onur's xa_alloc implementation [1].
>
> The complete patchset, including the Tyr driver ioctl implementations
> can be found at [2].
>
> Link: https://lore.kernel.org/rust-for-linux/20251006163024.18473-1-work@onurozkan.dev/ [1]
> Link: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/64 [2]
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
FYI, there is v2 exist and I will probably need to send v3 to address some of
the review notes. It's good that we have a use case for the series, I will share
(probably during the next week) the v3 before sending it to make sure it works
for you.
Thanks,
Onur
> Alvin Sun (4):
> rust: sizes: add SZ_4G constant
> rust: mm: Add task_size() method to Mm
> rust: xarray: Update StoreError comments for alloc()
> rust: xarray: Add Guard::find() helper
>
> rust/kernel/mm.rs | 7 +++++++
> rust/kernel/sizes.rs | 2 ++
> rust/kernel/xarray.rs | 28 +++++++++++++++++++++++++---
> 3 files changed, 34 insertions(+), 3 deletions(-)
> ---
> base-commit: d1d81e9d1a4dd846aee9ae77ff9ecc2800d72148
> change-id: 20260416-tyr-ioctls-deps-25805eedf332
> prerequisite-message-id: <20251006163024.18473-1-work@onurozkan.dev>
> prerequisite-patch-id: c472a9548969ac774d36fead73378961a0d0489c
> prerequisite-patch-id: 63890b91e911cf96cb42308c056d639580ac0fa0
> prerequisite-patch-id: 337eb93db35359c611abe9cba299e6ab0525a2b5
>
> Best regards,
> --
> Alvin Sun <alvin.sun@linux.dev>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] rust: xarray: Add Guard::find() helper
2026-04-17 1:05 ` [PATCH 4/4] rust: xarray: Add Guard::find() helper Alvin Sun
2026-04-17 1:18 ` Matthew Wilcox
@ 2026-04-17 8:28 ` Onur Özkan
2026-04-17 12:43 ` Alvin Sun
1 sibling, 1 reply; 13+ messages in thread
From: Onur Özkan @ 2026-04-17 8:28 UTC (permalink / raw)
To: Alvin Sun
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm
On Fri, 17 Apr 2026 09:05:54 +0800
Alvin Sun <alvin.sun@linux.dev> wrote:
> Add a helper to find the first present entry in the XArray.
>
> Returns the index of the first present entry, or None if the array
> is empty.
>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> rust/kernel/xarray.rs | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
> index 235fda0e394ba..e43129d032d9d 100644
> --- a/rust/kernel/xarray.rs
> +++ b/rust/kernel/xarray.rs
> @@ -217,6 +217,28 @@ pub fn remove(&mut self, index: usize) -> Option<T> {
> unsafe { T::try_from_foreign(ptr) }
> }
>
> + /// Finds the first present entry.
> + ///
> + /// Returns the index of the first present entry, or `None` if the array is empty.
> + pub fn find(&mut self) -> Option<usize> {
> + let mut index = 0usize;
Nit: I don't know if this verbosity can ever be useful, it can simply be `= 0`;
> + // SAFETY: `self.xa.xa` is always valid by the type invariant, and we hold the lock.
> + let ptr = unsafe {
> + bindings::xa_find(
> + self.xa.xa.get(),
> + &mut index,
> + usize::MAX,
> + bindings::XA_PRESENT,
> + )
> + };
> +
> + if ptr.is_null() {
> + None
> + } else {
> + Some(index)
> + }
This can be written with the `then_some` chain e.g., !ptr.is_null().then_some(..
.) but I don't know if it ever makes it more readable or simpler. I guess it's
up to preference.
-Onur
> + }
> +
> /// Stores an element at the given index.
> ///
> /// May drop the lock if needed to allocate memory, and then reacquire it afterwards.
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/4] rust: sizes: add SZ_4G constant
2026-04-17 3:18 ` Alexandre Courbot
@ 2026-04-17 11:56 ` Alvin Sun
0 siblings, 0 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 11:56 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm,
Onur Özkan
Hi Alexandre,
On 4/17/26 11:18, Alexandre Courbot wrote:
> Hi Alvin,
>
> On Fri Apr 17, 2026 at 10:05 AM JST, Alvin Sun wrote:
>> Add SZ_4G constant defined as SZ_2G * 2. This constant will be used by
>> the Tyr driver for calculating user and kernel VA layout.
>>
>> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
>> ---
>> rust/kernel/sizes.rs | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/rust/kernel/sizes.rs b/rust/kernel/sizes.rs
>> index 661e680d93306..872f5bb181ecf 100644
>> --- a/rust/kernel/sizes.rs
>> +++ b/rust/kernel/sizes.rs
>> @@ -48,3 +48,5 @@
>> pub const SZ_1G: usize = bindings::SZ_1G as usize;
>> /// 0x80000000
>> pub const SZ_2G: usize = bindings::SZ_2G as usize;
>> +/// 0x100000000
>> +pub const SZ_4G: usize = SZ_2G * 2;
> Note that the way size constants are defined has changed in `master` -
> you will probably want to update this patch accordingly.
I just noticed that my development baseline is based on the stable
repository.
>
> Also there is a `SZ_4G` define in `include/linux/sizes.h`; I am not sure
> why it is not in the bindings, but we should probably add it and get our
> value from that.
SZ_4G is a complex macro that internally uses the _AC macro, which bindgen
cannot handle by default. I found a similar issue that Miguel replied to in
October 2025 [1], where adding --clang-macro-fallback to bindgen can solve
this problem.
I tried adding this parameter to bindgen_parameters, but SZ_4G still
doesn't appear in bindings_generated.rs. However, when using
--clang-macro-fallback with just sizes.h alone, I can successfully generate
the bindings.
>
> Finally, maybe I missed something but the new value doesn't appear to be
> used by this series?
This patchset is a prerequisite for the Tyr ioctls patchset [2] that I'm
currently developing, which hasn't been submitted to the list yet.
[1]:
https://lore.kernel.org/rust-for-linux/CANiq72m20pom+B9EmWO+91E8fjbMEob3JmvHRQ6UaXe_JmatfA@mail.gmail.com/
[2]: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/64
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] rust: xarray: Add Guard::find() helper
2026-04-17 8:28 ` Onur Özkan
@ 2026-04-17 12:43 ` Alvin Sun
0 siblings, 0 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 12:43 UTC (permalink / raw)
To: Onur Özkan
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm
Hi Onur,
On 4/17/26 16:28, Onur Özkan wrote:
> On Fri, 17 Apr 2026 09:05:54 +0800
> Alvin Sun <alvin.sun@linux.dev> wrote:
>
>> Add a helper to find the first present entry in the XArray.
>>
>> Returns the index of the first present entry, or None if the array
>> is empty.
>>
>> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
>> ---
>> rust/kernel/xarray.rs | 22 ++++++++++++++++++++++
>> 1 file changed, 22 insertions(+)
>>
>> diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
>> index 235fda0e394ba..e43129d032d9d 100644
>> --- a/rust/kernel/xarray.rs
>> +++ b/rust/kernel/xarray.rs
>> @@ -217,6 +217,28 @@ pub fn remove(&mut self, index: usize) -> Option<T> {
>> unsafe { T::try_from_foreign(ptr) }
>> }
>>
>> + /// Finds the first present entry.
>> + ///
>> + /// Returns the index of the first present entry, or `None` if the array is empty.
>> + pub fn find(&mut self) -> Option<usize> {
>> + let mut index = 0usize;
> Nit: I don't know if this verbosity can ever be useful, it can simply be `= 0`;
Yeah, you're right - we can let the compiler infer the type automatically.
I haven't gotten used to that convenience yet :P
>
>> + // SAFETY: `self.xa.xa` is always valid by the type invariant, and we hold the lock.
>> + let ptr = unsafe {
>> + bindings::xa_find(
>> + self.xa.xa.get(),
>> + &mut index,
>> + usize::MAX,
>> + bindings::XA_PRESENT,
>> + )
>> + };
>> +
>> + if ptr.is_null() {
>> + None
>> + } else {
>> + Some(index)
>> + }
> This can be written with the `then_some` chain e.g., !ptr.is_null().then_some(..
> .) but I don't know if it ever makes it more readable or simpler. I guess it's
> up to preference.
I'm still not very used to the chained syntax style. For me, the if/else
approach is quite intuitive.
Best regards,
Alvin
>
> -Onur
>
>> + }
>> +
>> /// Stores an element at the given index.
>> ///
>> /// May drop the lock if needed to allocate memory, and then reacquire it afterwards.
>>
>> --
>> 2.43.0
>>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] rust: Add helper functions and constants for Tyr driver
2026-04-17 7:43 ` [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Onur Özkan
@ 2026-04-17 12:44 ` Alvin Sun
0 siblings, 0 replies; 13+ messages in thread
From: Alvin Sun @ 2026-04-17 12:44 UTC (permalink / raw)
To: Onur Özkan
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Lorenzo Stoakes, Liam R. Howlett,
Tamir Duberstein, rust-for-linux, linux-kernel, linux-mm
On 4/17/26 15:43, Onur Özkan wrote:
> On Fri, 17 Apr 2026 09:05:50 +0800
> Alvin Sun <alvin.sun@linux.dev> wrote:
>
>> This patchset provides helper functions and constants that will be used
>> by the Tyr driver's VM and BO related ioctl implementations.
>>
>> These patches add:
>> - SZ_4G constant for VA layout calculations
>> - A task_size() method to Mm for determining process VA space size
>> - Updated StoreError comments for alloc() usage
>> - Guard::find() helper for finding the first present entry in XArray
>>
>> This patchset depends on Onur's xa_alloc implementation [1].
>>
>> The complete patchset, including the Tyr driver ioctl implementations
>> can be found at [2].
>>
>> Link: https://lore.kernel.org/rust-for-linux/20251006163024.18473-1-work@onurozkan.dev/ [1]
>> Link: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/64 [2]
>> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
>> ---
> FYI, there is v2 exist and I will probably need to send v3 to address some of
> the review notes. It's good that we have a use case for the series, I will share
> (probably during the next week) the v3 before sending it to make sure it works
> for you.
I didn't notice there was a v2 version. No rush - I'll wait for your v3
version!
Best regards,
Alvin
>
> Thanks,
> Onur
>
>> Alvin Sun (4):
>> rust: sizes: add SZ_4G constant
>> rust: mm: Add task_size() method to Mm
>> rust: xarray: Update StoreError comments for alloc()
>> rust: xarray: Add Guard::find() helper
>>
>> rust/kernel/mm.rs | 7 +++++++
>> rust/kernel/sizes.rs | 2 ++
>> rust/kernel/xarray.rs | 28 +++++++++++++++++++++++++---
>> 3 files changed, 34 insertions(+), 3 deletions(-)
>> ---
>> base-commit: d1d81e9d1a4dd846aee9ae77ff9ecc2800d72148
>> change-id: 20260416-tyr-ioctls-deps-25805eedf332
>> prerequisite-message-id: <20251006163024.18473-1-work@onurozkan.dev>
>> prerequisite-patch-id: c472a9548969ac774d36fead73378961a0d0489c
>> prerequisite-patch-id: 63890b91e911cf96cb42308c056d639580ac0fa0
>> prerequisite-patch-id: 337eb93db35359c611abe9cba299e6ab0525a2b5
>>
>> Best regards,
>> --
>> Alvin Sun <alvin.sun@linux.dev>
>>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-04-17 12:45 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-17 1:05 [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Alvin Sun
2026-04-17 1:05 ` [PATCH 1/4] rust: sizes: add SZ_4G constant Alvin Sun
2026-04-17 3:18 ` Alexandre Courbot
2026-04-17 11:56 ` Alvin Sun
2026-04-17 1:05 ` [PATCH 2/4] rust: mm: Add task_size() method to Mm Alvin Sun
2026-04-17 1:05 ` [PATCH 3/4] rust: xarray: Update StoreError comments for alloc() Alvin Sun
2026-04-17 1:05 ` [PATCH 4/4] rust: xarray: Add Guard::find() helper Alvin Sun
2026-04-17 1:18 ` Matthew Wilcox
2026-04-17 2:16 ` Alvin Sun
2026-04-17 8:28 ` Onur Özkan
2026-04-17 12:43 ` Alvin Sun
2026-04-17 7:43 ` [PATCH 0/4] rust: Add helper functions and constants for Tyr driver Onur Özkan
2026-04-17 12:44 ` Alvin Sun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox