All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Ashutosh Desai <ashutoshdesai993@gmail.com>
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>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: add task_work abstraction
Date: Tue, 21 Apr 2026 08:44:01 +0200	[thread overview]
Message-ID: <2026042140-trickily-apprehend-0076@gregkh> (raw)
In-Reply-To: <20260421063836.742965-1-ashutoshdesai993@gmail.com>

On Tue, Apr 21, 2026 at 06:38:36AM +0000, Ashutosh Desai wrote:
> The kernel's task_work API (include/linux/task_work.h) allows any
> kernel thread to queue a callback that runs on a specific task the
> next time it returns to user space (or on exit). The C interface
> requires manual lifetime management of the callback_head allocation
> and careful ordering of init_task_work() and task_work_add().
> 
> Add a safe Rust abstraction consisting of:
> 
>  - TaskWork<T>: an owned, heap-allocated work item. Allocating
>    with TaskWork::new() ties a user-supplied value T (bound by the
>    new TaskWorkItem trait) to a callback_head. Scheduling with
>    TaskWork::add() initializes the callback, transfers ownership to
>    the kernel, and returns Err((ESRCH, data)) if the target task is
>    already exiting, so callers can always recover the value.
> 
>  - TaskWorkItem: a trait for types that can be scheduled as a task
>    work item. Implementors provide a run() method that receives the
>    inner value by move when the callback fires.
> 
>  - NotifyMode: a type-safe enum wrapping task_work_notify_mode,
>    covering TWA_NONE, TWA_RESUME, TWA_SIGNAL, TWA_SIGNAL_NO_IPI,
>    and TWA_NMI_CURRENT.
> 
> The repr(C) layout of the internal TaskWorkInner<T> places
> callback_head at offset 0, which lets the C callback pointer be
> cast back to the full allocation. Option<T> in that struct permits
> moving the data out before dropping the allocation without a Drop
> impl on TaskWork<T>.
> 
> Signed-off-by: Ashutosh Desai <ashutoshdesai993@gmail.com>
> ---
>  rust/kernel/lib.rs       |   1 +
>  rust/kernel/task_work.rs | 158 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 159 insertions(+)
>  create mode 100644 rust/kernel/task_work.rs

Do you have a user for this binding so that we can see how it is being
used to determine if it is correct?

thanks,

greg k-h

  reply	other threads:[~2026-04-21  6:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21  6:38 [PATCH] rust: add task_work abstraction Ashutosh Desai
2026-04-21  6:44 ` Greg KH [this message]
2026-04-22  0:31   ` Ashutosh Desai
2026-04-22  5:37     ` Greg KH

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=2026042140-trickily-apprehend-0076@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=ashutoshdesai993@gmail.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.