[PATCH v1 0/2] add Rust version of might_sleep()

From: FUJITA Tomonori
Date: Sun Apr 06 2025 - 07:08:29 EST


This patchset adds Rust version of might_sleep().

These patches were previously part of the IO polling patchset [1], but
they were split out to make upstreaming easier.

The first patch is for sched/core, which adds
__might_sleep_precision(), rust friendly version of __might_sleep(),
which takes a pointer to a string with the length instead of a
null-terminated string. Rust's core::panic::Location::file(), which
gives the file name of a caller, doesn't provide a null-terminated
string. __might_sleep_precision() uses a precision specifier in the
printk format, which specifies the length of a string; a string
doesn't need to be a null-terminated. Providing a null-terminated
string for better C interoperability is under discussion [2].

The second patch adds a Rust implementation of might_sleep(), on top
of the changes in the first patch.

[1]: https://lore.kernel.org/lkml/20250220070611.214262-1-fujita.tomonori@xxxxxxxxx/
[2]: https://github.com/rust-lang/libs-team/issues/466

FUJITA Tomonori (2):
sched/core: Add __might_sleep_precision()
rust: task: add Rust version of might_sleep()

include/linux/kernel.h | 2 ++
kernel/sched/core.c | 62 ++++++++++++++++++++++++++++--------------
rust/helpers/task.c | 6 ++++
rust/kernel/task.rs | 26 ++++++++++++++++++
4 files changed, 75 insertions(+), 21 deletions(-)


base-commit: f4d2ef48250ad057e4f00087967b5ff366da9f39
--
2.43.0