[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231012.165810.303016284319181876.fujita.tomonori@gmail.com>
Date: Thu, 12 Oct 2023 16:58:10 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: tmgross@...ch.edu
Cc: boqun.feng@...il.com, fujita.tomonori@...il.com,
netdev@...r.kernel.org, rust-for-linux@...r.kernel.org, andrew@...n.ch,
miguel.ojeda.sandonis@...il.com, greg@...ah.com
Subject: Re: [PATCH net-next v3 1/3] rust: core abstractions for network
PHY drivers
On Thu, 12 Oct 2023 03:32:44 -0400
Trevor Gross <tmgross@...ch.edu> wrote:
> On Thu, Oct 12, 2023 at 3:13 AM Boqun Feng <boqun.feng@...il.com> wrote:
>
>> If `Device::from_raw`'s safety requirement is "only called in callbacks
>> with phydevice->lock held, etc.", then the exclusive access is
>> guaranteed by the safety requirement, therefore `mut` can be drop. It's
>> a matter of the exact semantics of the APIs.
>>
>> Regards,
>> Boqun
>
> That is correct to my understanding, the core handles
> locking/unlocking and no driver functions are called if the core
> doesn't hold an exclusive lock first. Which also means the wrapper
> type can't be `Sync`.
>
> Andrew said a bit about it in the second comment here:
> https://lore.kernel.org/rust-for-linux/ec6d8479-f893-4a3f-bf3e-aa0c81c4adad@lunn.ch/
resume/suspend are called without the mutex hold but we don't need the
details. PHYLIB guarantees the exclusive access inside the
callbacks. I updated the comment and drop mut in Device's methods.
/// Creates a new [`Device`] instance from a raw pointer.
///
/// # Safety
///
/// This function can be called only in the callbacks in `phy_driver`. PHYLIB guarantees
/// the exclusive access for the duration of the lifetime `'a`.
unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self {
Powered by blists - more mailing lists