[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250410.224724.1795885541320306236.fujita.tomonori@gmail.com>
Date: Thu, 10 Apr 2025 22:47:24 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: aliceryhl@...gle.com
Cc: fujita.tomonori@...il.com, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org, boqun.feng@...il.com, ojeda@...nel.org,
alex.gaynor@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me, a.hindborg@...sung.com, tmgross@...ch.edu,
dakr@...nel.org, mingo@...hat.com, peterz@...radead.org,
juri.lelli@...hat.com, vincent.guittot@...aro.org,
dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
mgorman@...e.de, vschneid@...hat.com, pmladek@...e.com
Subject: Re: [PATCH v1 2/2] rust: task: add Rust version of might_sleep()
On Wed, 9 Apr 2025 08:51:44 +0000
Alice Ryhl <aliceryhl@...gle.com> wrote:
>> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
>> index 9e6f6854948d..1f0156b38ab5 100644
>> --- a/rust/kernel/task.rs
>> +++ b/rust/kernel/task.rs
>> @@ -380,3 +380,29 @@ 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.
>> +#[track_caller]
>> +#[inline]
>> +pub fn might_sleep() {
>> + #[cfg(CONFIG_DEBUG_ATOMIC_SLEEP)]
>> + {
>> + let loc = core::panic::Location::caller();
>> + // SAFETY: FFI call.
>
> Overall this looks okay to me, but this safety comment could be
> improved. This being an FFI call is not the reason *why* it is safe to
> make this call.
Undertood.
> // SAFETY: `file.as_ptr()` is valid for reading for `file.len()` bytes.
>
> And I might separate the file into a separate variable for clarity:
> let loc = core::panic::Location::caller();
> let file = loc.file();
Fixed.
>> + unsafe {
>> + crate::bindings::__might_sleep_precision(
>> + loc.file().as_ptr().cast(),
>> + loc.file().len() as i32,
>> + loc.line() as i32,
>> + )
>> + }
>> + }
>> +
>> + // SAFETY: FFI call.
>> + unsafe { crate::bindings::might_resched() }
>
> And here you can say
> // SAFETY: Always safe to call.
Fixed.
Thanks a lot!
Powered by blists - more mailing lists