[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87sf043pfc.fsf@metaspace.dk>
Date: Tue, 02 Apr 2024 14:43:51 +0200
From: Andreas Hindborg <nmi@...aspace.dk>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: Jens Axboe <axboe@...nel.dk>, Christoph Hellwig <hch@....de>, Keith
Busch <kbusch@...nel.org>, Damien Le Moal <Damien.LeMoal@....com>, Bart
Van Assche <bvanassche@....org>, Hannes Reinecke <hare@...e.de>,
"linux-block@...r.kernel.org" <linux-block@...r.kernel.org>, Andreas
Hindborg <a.hindborg@...sung.com>, Niklas Cassel <Niklas.Cassel@....com>,
Greg KH <gregkh@...uxfoundation.org>, Matthew Wilcox
<willy@...radead.org>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor
<alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn
Roy Baron <bjorn3_gh@...tonmail.com>, Alice Ryhl <aliceryhl@...gle.com>,
Chaitanya Kulkarni <chaitanyak@...dia.com>, Luis Chamberlain
<mcgrof@...nel.org>, Yexuan Yang <1182282462@...t.edu.cn>, Sergio
González Collado <sergio.collado@...il.com>, Joel
Granados
<j.granados@...sung.com>, "Pankaj Raghav (Samsung)"
<kernel@...kajraghav.com>, Daniel Gomez <da.gomez@...sung.com>, open
list <linux-kernel@...r.kernel.org>, "rust-for-linux@...r.kernel.org"
<rust-for-linux@...r.kernel.org>, "lsf-pc@...ts.linux-foundation.org"
<lsf-pc@...ts.linux-foundation.org>, "gost.dev@...sung.com"
<gost.dev@...sung.com>
Subject: Re: [RFC PATCH 3/5] rust: block: allow `hrtimer::Timer` in
`RequestData`
Benno Lossin <benno.lossin@...ton.me> writes:
> On 3/13/24 12:05, Andreas Hindborg wrote:> From: Andreas Hindborg <a.hindborg@...sung.com>
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@...sung.com>
>> ---
>> rust/kernel/block/mq/request.rs | 67 ++++++++++++++++++++++++++++++++-
>> 1 file changed, 66 insertions(+), 1 deletion(-)
>>
>> diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request.rs
>> index cccffde45981..8b7f08f894be 100644
>> --- a/rust/kernel/block/mq/request.rs
>> +++ b/rust/kernel/block/mq/request.rs
>> @@ -4,13 +4,16 @@
>> //!
>> //! C header: [`include/linux/blk-mq.h`](srctree/include/linux/blk-mq.h)
>>
>> +use kernel::hrtimer::RawTimer;
>> +
>> use crate::{
>> bindings,
>> block::mq::Operations,
>> error::{Error, Result},
>> + hrtimer::{HasTimer, TimerCallback},
>> types::{ARef, AlwaysRefCounted, Opaque},
>> };
>> -use core::{ffi::c_void, marker::PhantomData, ops::Deref};
>> +use core::{ffi::c_void, marker::PhantomData, ops::Deref, ptr::NonNull};
>>
>> use crate::block::bio::Bio;
>> use crate::block::bio::BioIterator;
>> @@ -175,6 +178,68 @@ fn deref(&self) -> &Self::Target {
>> }
>> }
>>
>> +impl<T> RawTimer for RequestDataRef<T>
>> +where
>> + T: Operations,
>> + T::RequestData: HasTimer<T::RequestData>,
>> + T::RequestData: Sync,
>> +{
>> + fn schedule(self, expires: u64) {
>> + let self_ptr = self.deref() as *const T::RequestData;
>> + core::mem::forget(self);
>> +
>> + // SAFETY: `self_ptr` is a valid pointer to a `T::RequestData`
>> + let timer_ptr = unsafe { T::RequestData::raw_get_timer(self_ptr) };
>> +
>> + // `Timer` is `repr(transparent)`
>> + let c_timer_ptr = timer_ptr.cast::<bindings::hrtimer>();
>> +
>> + // Schedule the timer - if it is already scheduled it is removed and
>> + // inserted
>> +
>> + // SAFETY: c_timer_ptr points to a valid hrtimer instance that was
>> + // initialized by `hrtimer_init`
>> + unsafe {
>> + bindings::hrtimer_start_range_ns(
>> + c_timer_ptr as *mut _,
>> + expires as i64,
>> + 0,
>> + bindings::hrtimer_mode_HRTIMER_MODE_REL,
>> + );
>> + }
>> + }
>> +}
>> +
>> +impl<T> kernel::hrtimer::RawTimerCallback for RequestDataRef<T>
>> +where
>> + T: Operations,
>> + T: Sync,
>
> Why is this needed? Shouldn't this be `T::RequestData: Sync`?
>
> Is the `run` function below executed on a different thread compared to
> the `schedule` function above?
> If yes, then `T::RequestData` probably also needs to be `Send`.
> You also would need to adjust the bounds in the impl above.
It's a typo, thanks for spotting. It should be `T::RequestData: Sync`.
BR Andreas
Powered by blists - more mailing lists