From: Daniel Almeida <daniel.almeida@collabora.com>
To: Alvin Sun <alvin.sun@linux.dev>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Lyude Paul" <lyude@redhat.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Johan Hovold" <johan@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org,
driver-core@lists.linux.dev, "Ke Sun" <sunke@kylinos.cn>
Subject: Re: [PATCH v7 02/10] rust: task: add task_size()
Date: Wed, 25 Nov 2026 11:45:32 -0300 [thread overview]
Message-ID: <332FBBF2-CC76-4A2C-BCB7-DCFC296B035A@collabora.com> (raw)
In-Reply-To: <20261122-tyr-ioctls-v7-2-3a2af624b992@linux.dev>
> On 22 Nov 2026, at 09:50, Alvin Sun <alvin.sun@linux.dev> wrote:
>
> From: Sami Tolvanen <samitolvanen@google.com>
>
> A DRM driver that lets userspace pick GPU virtual addresses needs the
> address space size of the calling task, so it can offer a GPU range
> that the CPU can map at the same addresses. TASK_SIZE_OF() is a macro,
> so reading it from Rust needs a helper.
>
> Add CurrentTask::task_size(). It is bound to the current task because
> TASK_SIZE_OF() falls back to TASK_SIZE on architectures that do not
> define it, and TASK_SIZE describes current.
>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> [ Add the <linux/mm.h> include, needed where TASK_SIZE is defined in
> <asm/pgtable.h> (e.g. riscv). - Alvin ]
> Co-developed-by: Alvin Sun <alvin.sun@linux.dev>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> rust/helpers/task.c | 6 ++++++
> rust/kernel/task.rs | 12 ++++++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/rust/helpers/task.c b/rust/helpers/task.c
> index b46b1433a67e8..b49bd40027154 100644
> --- a/rust/helpers/task.c
> +++ b/rust/helpers/task.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0
>
> #include <linux/kernel.h>
> +#include <linux/mm.h>
> #include <linux/sched/task.h>
>
> __rust_helper void rust_helper_might_resched(void)
> @@ -13,6 +14,11 @@ __rust_helper struct task_struct *rust_helper_get_current(void)
> return current;
> }
>
> +__rust_helper unsigned long rust_helper_current_task_size(void)
> +{
> + return TASK_SIZE_OF(current);
> +}
> +
> __rust_helper void rust_helper_get_task_struct(struct task_struct *t)
> {
> get_task_struct(t);
> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> index a733816fd5dd4..1978f54fe5897 100644
> --- a/rust/kernel/task.rs
> +++ b/rust/kernel/task.rs
> @@ -317,6 +317,18 @@ pub fn mm(&self) -> Option<&MmWithUser> {
> Some(unsafe { MmWithUser::from_raw(mm) })
> }
>
> + /// Returns the size of the userspace address space of the current task.
> + ///
> + /// This is the first address above the userspace range, so it is smaller
> + /// for a task running in compat mode than for a native one. See
> + /// `TASK_SIZE_OF()` in [`include/linux/sched.h`](srctree/include/linux/sched.h).
> + #[doc(alias = "TASK_SIZE_OF")]
> + #[inline]
> + pub fn task_size(&self) -> usize {
> + // SAFETY: FFI call without preconditions, valid in any context.
> + unsafe { bindings::current_task_size() as usize }
Do we need this cast?
> + }
> +
> /// Access the pid namespace of the current task.
> ///
> /// This function does not touch the refcount of the namespace or use RCU protection.
>
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2026-11-25 14:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 12:50 [PATCH v7 00/10] drm/tyr: add VM and BO ioctl support Alvin Sun
2026-11-22 12:50 ` [PATCH v7 01/10] rust: sizes: add SZ_4G constant Alvin Sun
2026-11-22 12:50 ` [PATCH v7 02/10] rust: task: add task_size() Alvin Sun
2026-11-25 14:45 ` Daniel Almeida [this message]
2026-11-22 12:50 ` [PATCH v7 03/10] rust: sync: arc: relax `ForeignOwnable` for `Arc<T>` Alvin Sun
2026-11-22 12:50 ` [PATCH v7 04/10] drm/tyr: add per-file VM pool Alvin Sun
2026-11-24 23:43 ` Deborah Brouwer
2026-11-25 15:14 ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 05/10] drm/tyr: add user and MCU VM specifications Alvin Sun
2026-11-25 16:13 ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 06/10] drm/tyr: add BO creation and lookup helpers Alvin Sun
2026-11-22 12:50 ` [PATCH v7 07/10] drm/tyr: add VM-related ioctls Alvin Sun
2026-11-24 23:40 ` Deborah Brouwer
2026-11-25 18:49 ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 08/10] rust: device: expose the device DMA attribute Alvin Sun
2026-11-25 18:52 ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 09/10] drm/tyr: support write-combine BO mappings Alvin Sun
2026-11-25 19:59 ` Daniel Almeida
2026-11-30 20:09 ` Deborah Brouwer
2026-11-22 12:50 ` [PATCH v7 10/10] drm/tyr: add BO-related ioctls Alvin Sun
2026-11-25 21:02 ` Daniel Almeida
2026-11-23 22:25 ` [PATCH v7 00/10] drm/tyr: add VM and BO ioctl support Daniel Almeida
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=332FBBF2-CC76-4A2C-BCB7-DCFC296B035A@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=alvin.sun@linux.dev \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=simona@ffwll.ch \
--cc=sunke@kylinos.cn \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox