* [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17
@ 2025-06-25 5:15 Boqun Feng
2025-06-25 5:15 ` [PATCH v2 1/5] rust: sync: Mark CondVar::notify_*() inline Boqun Feng
` (5 more replies)
0 siblings, 6 replies; 10+ messages in thread
From: Boqun Feng @ 2025-06-25 5:15 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm
Hi Ingo & Peter,
This is the updated version from my pull request last cycle:
v1: https://lore.kernel.org/rust-for-linux/20250506045843.51258-1-boqun.feng@gmail.com/
Please take a look, thanks!
Changes since v1:
- `Location::file_with_nul()` is used to avoid the C changes of
__might_sleep()
Regards,
Boqun
The following changes since commit 5bc34be478d09c4d16009e665e020ad0fcd0deea:
sched/core: Reorganize cgroup bandwidth control interface file writes (2025-06-18 13:59:57 +0200)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git tags/rust-sched.2025.06.24
for you to fetch changes up to 7e611710acf966df1e14bcf4e067385e38e549a1:
rust: task: Add Rust version of might_sleep() (2025-06-24 15:53:50 -0700)
----------------------------------------------------------------
Rust task & schedule changes for v6.17:
- Make Task, CondVar and PollCondVar methods inline to avoid unnecessary
function calls
- Add might_sleep() support for Rust code: Rust's "#[track_caller]"
mechanism is used so that Rust's might_sleep() doesn't need to be
defined as a macro
----------------------------------------------------------------
Boqun Feng (1):
rust: Introduce file_from_location()
FUJITA Tomonori (1):
rust: task: Add Rust version of might_sleep()
Kunwu Chan (2):
rust: sync: Mark CondVar::notify_*() inline
rust: sync: Mark PollCondVar::drop() inline
Panagiotis Foliadis (1):
rust: task: Mark Task methods inline
init/Kconfig | 3 +++
rust/helpers/task.c | 6 +++++
rust/kernel/lib.rs | 48 +++++++++++++++++++++++++++++++++++++
rust/kernel/sync/condvar.rs | 3 +++
rust/kernel/sync/poll.rs | 1 +
rust/kernel/task.rs | 33 +++++++++++++++++++++++++
6 files changed, 94 insertions(+)
--
2.39.5 (Apple Git-154)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/5] rust: sync: Mark CondVar::notify_*() inline
2025-06-25 5:15 [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
@ 2025-06-25 5:15 ` Boqun Feng
2025-06-25 5:15 ` [PATCH v2 2/5] rust: sync: Mark PollCondVar::drop() inline Boqun Feng
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-06-25 5:15 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm,
Grace Deng
From: Kunwu Chan <kunwu.chan@hotmail.com>
When build the kernel using the llvm-18.1.3-rust-1.85.0-x86_64
with ARCH=arm64, the following symbols are generated:
$nm vmlinux | grep ' _R'.*CondVar | rustfilt
... T <kernel::sync::condvar::CondVar>::notify_all
... T <kernel::sync::condvar::CondVar>::notify_one
... T <kernel::sync::condvar::CondVar>::notify_sync
...
These notify_*() symbols are trivial wrappers around the C functions
__wake_up() and __wake_up_sync(). It doesn't make sense to go through
a trivial wrapper for these functions, so mark them inline.
[boqun: Reword the commit title for consistency and reformat the commit
log.]
Suggested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Co-developed-by: Grace Deng <Grace.Deng006@Gmail.com>
Signed-off-by: Grace Deng <Grace.Deng006@Gmail.com>
Signed-off-by: Kunwu Chan <kunwu.chan@hotmail.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250324061835.1693125-1-kunwu.chan@linux.dev
---
rust/kernel/sync/condvar.rs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
index caebf03f553b..c6ec64295c9f 100644
--- a/rust/kernel/sync/condvar.rs
+++ b/rust/kernel/sync/condvar.rs
@@ -216,6 +216,7 @@ fn notify(&self, count: c_int) {
/// This method behaves like `notify_one`, except that it hints to the scheduler that the
/// current thread is about to go to sleep, so it should schedule the target thread on the same
/// CPU.
+ #[inline]
pub fn notify_sync(&self) {
// SAFETY: `wait_queue_head` points to valid memory.
unsafe { bindings::__wake_up_sync(self.wait_queue_head.get(), TASK_NORMAL) };
@@ -225,6 +226,7 @@ pub fn notify_sync(&self) {
///
/// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost
/// completely (as opposed to automatically waking up the next waiter).
+ #[inline]
pub fn notify_one(&self) {
self.notify(1);
}
@@ -233,6 +235,7 @@ pub fn notify_one(&self) {
///
/// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost
/// completely (as opposed to automatically waking up the next waiter).
+ #[inline]
pub fn notify_all(&self) {
self.notify(0);
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/5] rust: sync: Mark PollCondVar::drop() inline
2025-06-25 5:15 [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
2025-06-25 5:15 ` [PATCH v2 1/5] rust: sync: Mark CondVar::notify_*() inline Boqun Feng
@ 2025-06-25 5:15 ` Boqun Feng
2025-06-25 5:15 ` [PATCH v2 3/5] rust: task: Mark Task methods inline Boqun Feng
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-06-25 5:15 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm,
Grace Deng
From: Kunwu Chan <kunwu.chan@hotmail.com>
When building the kernel using the llvm-18.1.3-rust-1.85.0-x86_64
with ARCH=arm64, the following symbols are generated:
$nm vmlinux | grep ' _R'.*PollCondVar | rustfilt
... T <kernel::sync::poll::PollCondVar as kernel::init::PinnedDrop>::drop
...
This Rust symbol is trivial wrappers around the C functions
__wake_up_pollfree() and synchronize_rcu(). It doesn't make sense to go
through a trivial wrapper for its functions, so mark it inline.
[boqun: Reword the commit title and re-format the commit log per tip
tree's requirement, remove unnecessary information from "nm vmlinux"
result.]
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Suggested-by: Alice Ryhl <aliceryhl@google.com>
Co-developed-by: Grace Deng <Grace.Deng006@Gmail.com>
Signed-off-by: Grace Deng <Grace.Deng006@Gmail.com>
Signed-off-by: Kunwu Chan <kunwu.chan@hotmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250317025205.2366518-1-kunwu.chan@linux.dev
---
rust/kernel/sync/poll.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs
index d7e6e59e124b..7b973d72229b 100644
--- a/rust/kernel/sync/poll.rs
+++ b/rust/kernel/sync/poll.rs
@@ -107,6 +107,7 @@ fn deref(&self) -> &CondVar {
#[pinned_drop]
impl PinnedDrop for PollCondVar {
+ #[inline]
fn drop(self: Pin<&mut Self>) {
// Clear anything registered using `register_wait`.
//
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/5] rust: task: Mark Task methods inline
2025-06-25 5:15 [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
2025-06-25 5:15 ` [PATCH v2 1/5] rust: sync: Mark CondVar::notify_*() inline Boqun Feng
2025-06-25 5:15 ` [PATCH v2 2/5] rust: sync: Mark PollCondVar::drop() inline Boqun Feng
@ 2025-06-25 5:15 ` Boqun Feng
2025-06-25 5:15 ` [PATCH v2 4/5] rust: Introduce file_from_location() Boqun Feng
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-06-25 5:15 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm,
Christian Schrefl, Charalampos Mitrodimas
From: Panagiotis Foliadis <pfoliadis@posteo.net>
When building the kernel using the llvm-18.1.3-rust-1.85.0-x86_64
toolchain provided by kernel.org, the following symbols are generated:
$ nm vmlinux | grep ' _R'.*Task | rustfilt
... T <kernel::task::Task>::get_pid_ns
... T <kernel::task::Task>::tgid_nr_ns
... T <kernel::task::Task>::current_pid_ns
... T <kernel::task::Task>::signal_pending
... T <kernel::task::Task>::uid
... T <kernel::task::Task>::euid
... T <kernel::task::Task>::current
... T <kernel::task::Task>::wake_up
... T <kernel::task::Task as kernel::types::AlwaysRefCounted>::dec_ref
... T <kernel::task::Task as kernel::types::AlwaysRefCounted>::inc_ref
These Rust symbols are trivial wrappers around the C functions. It
doesn't make sense to go through a trivial wrapper for these functions,
so mark them inline.
[boqun: Capitalize the title, reword a bit to avoid listing all the C
functions as the code already shows them and remove the addresses of the
symbols in the commit log as they are different from build to build.]
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com>
Reviewed-by: Charalampos Mitrodimas <charmitro@posteo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Panagiotis Foliadis <pfoliadis@posteo.net>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250315-inline-c-wrappers-v3-1-048e43fcef7d@posteo.net
---
rust/kernel/task.rs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
index 927413d85484..834368313088 100644
--- a/rust/kernel/task.rs
+++ b/rust/kernel/task.rs
@@ -173,6 +173,7 @@ pub fn current_raw() -> *mut bindings::task_struct {
/// Callers must ensure that the returned object is only used to access a [`CurrentTask`]
/// within the task context that was active when this function was called. For more details,
/// see the invariants section for [`CurrentTask`].
+ #[inline]
pub unsafe fn current() -> impl Deref<Target = CurrentTask> {
struct TaskRef {
task: *const CurrentTask,
@@ -222,24 +223,28 @@ pub fn pid(&self) -> Pid {
}
/// Returns the UID of the given task.
+ #[inline]
pub fn uid(&self) -> Kuid {
// SAFETY: It's always safe to call `task_uid` on a valid task.
Kuid::from_raw(unsafe { bindings::task_uid(self.as_ptr()) })
}
/// Returns the effective UID of the given task.
+ #[inline]
pub fn euid(&self) -> Kuid {
// SAFETY: It's always safe to call `task_euid` on a valid task.
Kuid::from_raw(unsafe { bindings::task_euid(self.as_ptr()) })
}
/// Determines whether the given task has pending signals.
+ #[inline]
pub fn signal_pending(&self) -> bool {
// SAFETY: It's always safe to call `signal_pending` on a valid task.
unsafe { bindings::signal_pending(self.as_ptr()) != 0 }
}
/// Returns task's pid namespace with elevated reference count
+ #[inline]
pub fn get_pid_ns(&self) -> Option<ARef<PidNamespace>> {
// SAFETY: By the type invariant, we know that `self.0` is valid.
let ptr = unsafe { bindings::task_get_pid_ns(self.as_ptr()) };
@@ -255,6 +260,7 @@ pub fn get_pid_ns(&self) -> Option<ARef<PidNamespace>> {
/// Returns the given task's pid in the provided pid namespace.
#[doc(alias = "task_tgid_nr_ns")]
+ #[inline]
pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid {
let pidns = match pidns {
Some(pidns) => pidns.as_ptr(),
@@ -268,6 +274,7 @@ pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid {
}
/// Wakes up the task.
+ #[inline]
pub fn wake_up(&self) {
// SAFETY: It's always safe to call `wake_up_process` on a valid task, even if the task
// running.
@@ -341,11 +348,13 @@ pub fn active_pid_ns(&self) -> Option<&PidNamespace> {
// SAFETY: The type invariants guarantee that `Task` is always refcounted.
unsafe impl crate::types::AlwaysRefCounted for Task {
+ #[inline]
fn inc_ref(&self) {
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
unsafe { bindings::get_task_struct(self.as_ptr()) };
}
+ #[inline]
unsafe fn dec_ref(obj: ptr::NonNull<Self>) {
// SAFETY: The safety requirements guarantee that the refcount is nonzero.
unsafe { bindings::put_task_struct(obj.cast().as_ptr()) }
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 4/5] rust: Introduce file_from_location()
2025-06-25 5:15 [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
` (2 preceding siblings ...)
2025-06-25 5:15 ` [PATCH v2 3/5] rust: task: Mark Task methods inline Boqun Feng
@ 2025-06-25 5:15 ` Boqun Feng
2025-06-25 5:15 ` [PATCH v2 5/5] rust: task: Add Rust version of might_sleep() Boqun Feng
2025-06-30 13:50 ` [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
5 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-06-25 5:15 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm
Most of kernel debugging facilities take a nul-terminated string for
file names for a callsite (generated from __FILE__), however the Rust
courterpart, Location, would return a Rust string (not nul-terminated)
from method .file(). And such a string cannot be passed to C debugging
function directly.
There is ongoing work to support a Location::file_with_nul() [1], which
returns a nul-terminated string from a Location. Since it's still
working in progress, and it will take some time before the feature
finally gets stabilized and the kernel's minimal rustc version might
also take a while to bump to a version that at least has that feature,
introduce a file_from_location() function, which returns a warning
string if Location::file_with_nul() is not available.
This should work in most cases because as for now the known usage of
Location::file_with_nul() is only in debugging code (e.g. might_sleep())
and there might be other information reported by the debugging code that
could help locate the problematic function, so missing the file name is
fine at the moment.
Link: https://github.com/rust-lang/rust/issues/141727 [1]
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250619151007.61767-2-boqun.feng@gmail.com
---
init/Kconfig | 3 +++
rust/kernel/lib.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/init/Kconfig b/init/Kconfig
index af4c2f085455..6f4ec5633ffa 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -142,6 +142,9 @@ config RUSTC_HAS_SPAN_FILE
config RUSTC_HAS_UNNECESSARY_TRANSMUTES
def_bool RUSTC_VERSION >= 108800
+config RUSTC_HAS_FILE_WITH_NUL
+ def_bool RUSTC_VERSION >= 108900
+
config PAHOLE_VERSION
int
default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE))
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 6b4774b2b1c3..717a5b6160ca 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -40,6 +40,10 @@
#![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(coerce_unsized))]
#![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(dispatch_from_dyn))]
#![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(unsize))]
+//
+// `feature(file_with_nul)` is expected to become stable. Before Rust 1.89.0, it did not exist, so
+// enable it conditionally.
+#![cfg_attr(CONFIG_RUSTC_HAS_FILE_WITH_NUL, feature(file_with_nul))]
// Ensure conditional compilation based on the kernel configuration works;
// otherwise we may silently break things like initcall handling.
@@ -274,3 +278,47 @@ macro_rules! asm {
::core::arch::asm!( $($asm)*, $($rest)* )
};
}
+
+/// Gets the C string file name of a [`Location`].
+///
+/// If `file_with_nul()` is not available, returns a string that warns about it.
+///
+/// [`Location`]: core::panic::Location
+///
+/// # Examples
+///
+/// ```
+/// # use kernel::file_from_location;
+///
+/// #[track_caller]
+/// fn foo() {
+/// let caller = core::panic::Location::caller();
+///
+/// // Output:
+/// // - A path like "rust/kernel/example.rs" if file_with_nul() is available.
+/// // - "<Location::file_with_nul() not supported>" otherwise.
+/// let caller_file = file_from_location(caller);
+///
+/// // Prints out the message with caller's file name.
+/// pr_info!("foo() called in file {caller_file:?}\n");
+///
+/// # if cfg!(CONFIG_RUSTC_HAS_FILE_WITH_NUL) {
+/// # assert_eq!(Ok(caller.file()), caller_file.to_str());
+/// # }
+/// }
+///
+/// # foo();
+/// ```
+#[inline]
+pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
+ #[cfg(CONFIG_RUSTC_HAS_FILE_WITH_NUL)]
+ {
+ loc.file_with_nul()
+ }
+
+ #[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
+ {
+ let _ = loc;
+ c"<Location::file_with_nul() not supported>"
+ }
+}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 5/5] rust: task: Add Rust version of might_sleep()
2025-06-25 5:15 [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
` (3 preceding siblings ...)
2025-06-25 5:15 ` [PATCH v2 4/5] rust: Introduce file_from_location() Boqun Feng
@ 2025-06-25 5:15 ` Boqun Feng
2025-06-30 13:50 ` [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
5 siblings, 0 replies; 10+ messages in thread
From: Boqun Feng @ 2025-06-25 5:15 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
Add a helper function equivalent to the C's might_sleep(), which
serves as a debugging aid and a potential scheduling point.
Note that this function can only be used in a nonatomic context.
This will be used by Rust version of read_poll_timeout().
[boqun: Use file_from_location() to get a C string instead of changing
__might_sleep()]
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250619151007.61767-3-boqun.feng@gmail.com
---
rust/helpers/task.c | 6 ++++++
rust/kernel/task.rs | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/rust/helpers/task.c b/rust/helpers/task.c
index 31c33ea2dce6..2c85bbc2727e 100644
--- a/rust/helpers/task.c
+++ b/rust/helpers/task.c
@@ -1,7 +1,13 @@
// SPDX-License-Identifier: GPL-2.0
+#include <linux/kernel.h>
#include <linux/sched/task.h>
+void rust_helper_might_resched(void)
+{
+ might_resched();
+}
+
struct task_struct *rust_helper_get_current(void)
{
return current;
diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
index 834368313088..7d0935bc325c 100644
--- a/rust/kernel/task.rs
+++ b/rust/kernel/task.rs
@@ -400,3 +400,27 @@ fn eq(&self, other: &Kuid) -> bool {
}
impl Eq for Kuid {}
+
+/// Annotation for functions that can sleep.
+///
+/// Equivalent to the C side [`might_sleep()`], this function serves as
+/// a debugging aid and a potential scheduling point.
+///
+/// This function can only be used in a nonatomic context.
+///
+/// [`might_sleep()`]: https://docs.kernel.org/driver-api/basics.html#c.might_sleep
+#[track_caller]
+#[inline]
+pub fn might_sleep() {
+ #[cfg(CONFIG_DEBUG_ATOMIC_SLEEP)]
+ {
+ let loc = core::panic::Location::caller();
+ let file = kernel::file_from_location(loc);
+
+ // SAFETY: `file.as_ptr()` is valid for reading and guaranteed to be nul-terminated.
+ unsafe { crate::bindings::__might_sleep(file.as_ptr().cast(), loc.line() as i32) }
+ }
+
+ // SAFETY: Always safe to call.
+ unsafe { crate::bindings::might_resched() }
+}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17
2025-06-25 5:15 [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
` (4 preceding siblings ...)
2025-06-25 5:15 ` [PATCH v2 5/5] rust: task: Add Rust version of might_sleep() Boqun Feng
@ 2025-06-30 13:50 ` Boqun Feng
2025-07-21 11:00 ` Alice Ryhl
5 siblings, 1 reply; 10+ messages in thread
From: Boqun Feng @ 2025-06-30 13:50 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Miguel Ojeda, Alex Gaynor, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, FUJITA Tomonori, Tamir Duberstein,
Kunwu Chan, Mitchell Levy, Martin Rodriguez Reboredo, Borys Tyran,
Christian Brauner, Panagiotis Foliadis, linux-kernel,
rust-for-linux, llvm
On Tue, Jun 24, 2025 at 10:15:13PM -0700, Boqun Feng wrote:
> Hi Ingo & Peter,
>
> This is the updated version from my pull request last cycle:
>
> v1: https://lore.kernel.org/rust-for-linux/20250506045843.51258-1-boqun.feng@gmail.com/
>
> Please take a look, thanks!
>
Ping ;-) I forgot to add that this is a dependency for Rust version's
read_poll_timeout(), which is a dependency to a few things:
* In the `Tyr` driver:
https://lore.kernel.org/rust-for-linux/20250628.224928.690831629261546521.fujita.tomonori@gmail.com/
* In Nova, the gpu driver:
https://lore.kernel.org/rust-for-linux/20250619-nova-frts-v6-24-ecf41ef99252@nvidia.com/
* In the qt2025 phy driver:
https://lore.kernel.org/lkml/20250220070611.214262-9-fujita.tomonori@gmail.com/
Thanks!
Regards,
Boqun
> Changes since v1:
>
> - `Location::file_with_nul()` is used to avoid the C changes of
> __might_sleep()
>
> Regards,
> Boqun
>
>
> The following changes since commit 5bc34be478d09c4d16009e665e020ad0fcd0deea:
>
> sched/core: Reorganize cgroup bandwidth control interface file writes (2025-06-18 13:59:57 +0200)
>
> are available in the Git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git tags/rust-sched.2025.06.24
>
> for you to fetch changes up to 7e611710acf966df1e14bcf4e067385e38e549a1:
>
> rust: task: Add Rust version of might_sleep() (2025-06-24 15:53:50 -0700)
>
> ----------------------------------------------------------------
> Rust task & schedule changes for v6.17:
>
> - Make Task, CondVar and PollCondVar methods inline to avoid unnecessary
> function calls
>
> - Add might_sleep() support for Rust code: Rust's "#[track_caller]"
> mechanism is used so that Rust's might_sleep() doesn't need to be
> defined as a macro
>
> ----------------------------------------------------------------
> Boqun Feng (1):
> rust: Introduce file_from_location()
>
> FUJITA Tomonori (1):
> rust: task: Add Rust version of might_sleep()
>
> Kunwu Chan (2):
> rust: sync: Mark CondVar::notify_*() inline
> rust: sync: Mark PollCondVar::drop() inline
>
> Panagiotis Foliadis (1):
> rust: task: Mark Task methods inline
>
> init/Kconfig | 3 +++
> rust/helpers/task.c | 6 +++++
> rust/kernel/lib.rs | 48 +++++++++++++++++++++++++++++++++++++
> rust/kernel/sync/condvar.rs | 3 +++
> rust/kernel/sync/poll.rs | 1 +
> rust/kernel/task.rs | 33 +++++++++++++++++++++++++
> 6 files changed, 94 insertions(+)
>
> --
> 2.39.5 (Apple Git-154)
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17
2025-06-30 13:50 ` [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
@ 2025-07-21 11:00 ` Alice Ryhl
2025-07-21 13:50 ` Boqun Feng
0 siblings, 1 reply; 10+ messages in thread
From: Alice Ryhl @ 2025-07-21 11:00 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Boqun Feng, Ingo Molnar, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Miguel Ojeda, Alex Gaynor, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm
On Mon, Jun 30, 2025 at 3:50 PM Boqun Feng <boqun.feng@gmail.com> wrote:
>
> On Tue, Jun 24, 2025 at 10:15:13PM -0700, Boqun Feng wrote:
> > Hi Ingo & Peter,
> >
> > This is the updated version from my pull request last cycle:
> >
> > v1: https://lore.kernel.org/rust-for-linux/20250506045843.51258-1-boqun.feng@gmail.com/
> >
> > Please take a look, thanks!
> >
>
> Ping ;-) I forgot to add that this is a dependency for Rust version's
> read_poll_timeout(), which is a dependency to a few things:
>
> * In the `Tyr` driver:
>
> https://lore.kernel.org/rust-for-linux/20250628.224928.690831629261546521.fujita.tomonori@gmail.com/
>
> * In Nova, the gpu driver:
>
> https://lore.kernel.org/rust-for-linux/20250619-nova-frts-v6-24-ecf41ef99252@nvidia.com/
>
> * In the qt2025 phy driver:
>
> https://lore.kernel.org/lkml/20250220070611.214262-9-fujita.tomonori@gmail.com/
>
> Thanks!
I would love to see this land to unblock the above users. I wanted to
add that I fixed the Rust language so that it NUL-terminates these
filename strings, so Ingo's concern from the last cycle should not
apply to this version of the PR.
Thanks!
Alice
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17
2025-07-21 11:00 ` Alice Ryhl
@ 2025-07-21 13:50 ` Boqun Feng
2025-07-21 14:35 ` Alice Ryhl
0 siblings, 1 reply; 10+ messages in thread
From: Boqun Feng @ 2025-07-21 13:50 UTC (permalink / raw)
To: Alice Ryhl
Cc: Ingo Molnar, Peter Zijlstra, Ingo Molnar, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, Miguel Ojeda, Alex Gaynor,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm
On Mon, Jul 21, 2025 at 01:00:49PM +0200, Alice Ryhl wrote:
> On Mon, Jun 30, 2025 at 3:50 PM Boqun Feng <boqun.feng@gmail.com> wrote:
> >
> > On Tue, Jun 24, 2025 at 10:15:13PM -0700, Boqun Feng wrote:
> > > Hi Ingo & Peter,
> > >
> > > This is the updated version from my pull request last cycle:
> > >
> > > v1: https://lore.kernel.org/rust-for-linux/20250506045843.51258-1-boqun.feng@gmail.com/
> > >
> > > Please take a look, thanks!
> > >
> >
> > Ping ;-) I forgot to add that this is a dependency for Rust version's
> > read_poll_timeout(), which is a dependency to a few things:
> >
> > * In the `Tyr` driver:
> >
> > https://lore.kernel.org/rust-for-linux/20250628.224928.690831629261546521.fujita.tomonori@gmail.com/
> >
> > * In Nova, the gpu driver:
> >
> > https://lore.kernel.org/rust-for-linux/20250619-nova-frts-v6-24-ecf41ef99252@nvidia.com/
> >
> > * In the qt2025 phy driver:
> >
> > https://lore.kernel.org/lkml/20250220070611.214262-9-fujita.tomonori@gmail.com/
> >
> > Thanks!
>
> I would love to see this land to unblock the above users. I wanted to
Thanks, Alice. It's already merged in tip tree:
https://lore.kernel.org/lkml/175153176741.406.14557081807475800171.tip-bot2@tip-bot2/
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=7e611710acf966df1e14bcf4e067385e38e549a1
> add that I fixed the Rust language so that it NUL-terminates these
> filename strings, so Ingo's concern from the last cycle should not
> apply to this version of the PR.
>
Thanks a lot for pushing the changes at the Rust language side.
Regards,
Boqun
> Thanks!
> Alice
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17
2025-07-21 13:50 ` Boqun Feng
@ 2025-07-21 14:35 ` Alice Ryhl
0 siblings, 0 replies; 10+ messages in thread
From: Alice Ryhl @ 2025-07-21 14:35 UTC (permalink / raw)
To: Boqun Feng
Cc: Ingo Molnar, Peter Zijlstra, Ingo Molnar, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, Miguel Ojeda, Alex Gaynor,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, FUJITA Tomonori,
Tamir Duberstein, Kunwu Chan, Mitchell Levy,
Martin Rodriguez Reboredo, Borys Tyran, Christian Brauner,
Panagiotis Foliadis, linux-kernel, rust-for-linux, llvm
On Mon, Jul 21, 2025 at 3:50 PM Boqun Feng <boqun.feng@gmail.com> wrote:
>
> On Mon, Jul 21, 2025 at 01:00:49PM +0200, Alice Ryhl wrote:
> > On Mon, Jun 30, 2025 at 3:50 PM Boqun Feng <boqun.feng@gmail.com> wrote:
> > >
> > > On Tue, Jun 24, 2025 at 10:15:13PM -0700, Boqun Feng wrote:
> > > > Hi Ingo & Peter,
> > > >
> > > > This is the updated version from my pull request last cycle:
> > > >
> > > > v1: https://lore.kernel.org/rust-for-linux/20250506045843.51258-1-boqun.feng@gmail.com/
> > > >
> > > > Please take a look, thanks!
> > > >
> > >
> > > Ping ;-) I forgot to add that this is a dependency for Rust version's
> > > read_poll_timeout(), which is a dependency to a few things:
> > >
> > > * In the `Tyr` driver:
> > >
> > > https://lore.kernel.org/rust-for-linux/20250628.224928.690831629261546521.fujita.tomonori@gmail.com/
> > >
> > > * In Nova, the gpu driver:
> > >
> > > https://lore.kernel.org/rust-for-linux/20250619-nova-frts-v6-24-ecf41ef99252@nvidia.com/
> > >
> > > * In the qt2025 phy driver:
> > >
> > > https://lore.kernel.org/lkml/20250220070611.214262-9-fujita.tomonori@gmail.com/
> > >
> > > Thanks!
> >
> > I would love to see this land to unblock the above users. I wanted to
>
> Thanks, Alice. It's already merged in tip tree:
>
> https://lore.kernel.org/lkml/175153176741.406.14557081807475800171.tip-bot2@tip-bot2/
> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=7e611710acf966df1e14bcf4e067385e38e549a1
Thanks for clarifying.
Alice
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-07-21 14:36 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-25 5:15 [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
2025-06-25 5:15 ` [PATCH v2 1/5] rust: sync: Mark CondVar::notify_*() inline Boqun Feng
2025-06-25 5:15 ` [PATCH v2 2/5] rust: sync: Mark PollCondVar::drop() inline Boqun Feng
2025-06-25 5:15 ` [PATCH v2 3/5] rust: task: Mark Task methods inline Boqun Feng
2025-06-25 5:15 ` [PATCH v2 4/5] rust: Introduce file_from_location() Boqun Feng
2025-06-25 5:15 ` [PATCH v2 5/5] rust: task: Add Rust version of might_sleep() Boqun Feng
2025-06-30 13:50 ` [GIT PULL] [PATCH v2 0/5] rust: Task & schedule related changes for v6.17 Boqun Feng
2025-07-21 11:00 ` Alice Ryhl
2025-07-21 13:50 ` Boqun Feng
2025-07-21 14:35 ` Alice Ryhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).