On Tue, Oct 20, 2026 at 04:25:19PM +0800, Ke Sun wrote:
> From: Alvin Sun <[email protected]>

I was testing Tyr's auto allocation for the user va range,
and was surprised to see that mm.task_size() is always returning 0.
It seems like it should work since it uses the task_size from
struct mm_struct, but it doesn't, at least for me. 

If you look at tyr-dev, I think it would be better to use Sami's approach:
  428d71932b6f rust: task: add task_size()

Sami creates a task_size() method for CurrentTask which is our equivalent
to the `current` global and then you can see that task_size becomes much
more clearly the equivalent of "TASK_SIZE_OF" used by panthor.

This approach also correctly returns a user va range when Tyr has to
assign it in my tests, so let's switch over.

> 
> Expose the task's address space size. It is used by the Tyr driver
> for splitting a VM's GPU address space into user and kernel regions.
> 
> Signed-off-by: Alvin Sun <[email protected]>
> Reviewed-by: Daniel Almeida <[email protected]>
> ---
>  rust/kernel/mm.rs | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs
> index 4764d7b68f2a7..d2dfbb7d43972 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
>          }
>      }
> +
> +    /// The size of the process virtual address space.
> +    #[inline]
> +    pub fn task_size(&self) -> usize {
> +        // SAFETY: `self.as_raw()` is a valid pointer to an `mm_struct` per 
> the type invariants.
> +        unsafe { (*self.as_raw()).__bindgen_anon_1.task_size }
> +    }
>  }
>  
>  // These methods require `mm_users` to be non-zero.
> 
> -- 
> 2.43.0
> 

Reply via email to