[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bUU6jGtJ7KdkuVp8UPORb0cmDoU6sRjc1iVRMfgO34u5ySo44Z5MXrnYgE6pfQDFu4-V5CBAuhS8uZDoEA6CsIiLUiWJedNZ2CTf9cRATfQ=@proton.me>
Date: Sat, 02 Dec 2023 10:16:36 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: a.hindborg@...sung.com, alex.gaynor@...il.com, arve@...roid.com,
bjorn3_gh@...tonmail.com, boqun.feng@...il.com, brauner@...nel.org,
cmllamas@...gle.com, dan.j.williams@...el.com, dxu@...uu.xyz,
gary@...yguo.net, gregkh@...uxfoundation.org,
joel@...lfernandes.org, keescook@...omium.org,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
maco@...roid.com, ojeda@...nel.org, peterz@...radead.org,
rust-for-linux@...r.kernel.org, surenb@...gle.com,
tglx@...utronix.de, tkjos@...roid.com, viro@...iv.linux.org.uk,
wedsonaf@...il.com, willy@...radead.org
Subject: Re: [PATCH 6/7] rust: file: add `DeferredFdCloser`
On 12/1/23 12:35, Alice Ryhl wrote:
> Benno Lossin <benno.lossin@...ton.me> writes:
>>> + // SAFETY: The `inner` pointer points at a valid and fully initialized task work that is
>>> + // ready to be scheduled.
>>> + unsafe { bindings::task_work_add(current, inner, TWA_RESUME) };
>>
>> I am a bit confused, when does `do_close_fd` actually run? Does
>> `TWA_RESUME` mean that `inner` is scheduled to run after the current
>> task has been completed?
>
> When the current syscall returns to userspace.
What happens when I use `DeferredFdCloser` outside of a syscall? Will
it never run? Maybe add some documentation about that?
>>> + // SAFETY: This function is an implementation detail of `close_fd`, so its safety comments
>>> + // should be read in extension of that method.
>>> + unsafe extern "C" fn do_close_fd(inner: *mut bindings::callback_head) {
>>> + // SAFETY: In `close_fd` we use this method together with a pointer that originates from a
>>> + // `Box<DeferredFdCloserInner>`, and we have just been given ownership of that allocation.
>>> + let inner = unsafe { Box::from_raw(inner as *mut DeferredFdCloserInner) };
>>
>> In order for this call to be sound, `inner` must be an exclusive
>> pointer (including any possible references into the `callback_head`).
>> Is this the case?
>
> Yes, when this is called, it's been removed from the linked list of task
> work. That's why we can kfree it.
Please add this to the SAFETY comment.
--
Cheers,
Benno
Powered by blists - more mailing lists