From: Vitaly Wool <vitaly.wool@konsulko.se>
To: Danilo Krummrich <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
Uladzislau Rezki <urezki@gmail.com>,
Alice Ryhl <aliceryhl@google.com>,
Vlastimil Babka <vbabka@suse.cz>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Miguel Ojeda <ojeda@kernel.org>,
Alex Gaynor <alex.gaynor@gmail.com>,
Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>,
Bjorn Roy Baron <bjorn3_gh@protonmail.com>,
Benno Lossin <lossin@kernel.org>,
Andreas Hindborg <a.hindborg@kernel.org>,
Trevor Gross <tmgross@umich.edu>,
Johannes Weiner <hannes@cmpxchg.org>,
Yosry Ahmed <yosry.ahmed@linux.dev>,
Nhat Pham <nphamcs@gmail.com>,
linux-mm@kvack.org
Subject: Re: [PATCH v4 2/2] rust: zpool: add abstraction for zpool drivers
Date: Thu, 28 Aug 2025 12:01:06 +0200 [thread overview]
Message-ID: <d91e6483-c5a6-468f-b40e-1acdd28a80cd@konsulko.se> (raw)
In-Reply-To: <b1509e7f-4817-4466-bd2b-c083f024c0d4@konsulko.se>
<snip>
>>> + extern "C" fn destroy_(pool: *mut c_void) {
>>> + // SAFETY: The pointer originates from an `into_foreign` call.
>>> + T::destroy(unsafe { T::Pool::from_foreign(pool) })
>>> + }
>>> + extern "C" fn malloc_(
>>> + pool: *mut c_void,
>>> + size: usize,
>>> + gfp: u32,
>>> + handle: *mut usize,
>>> + nid: c_int,
>>> + ) -> c_int {
>>> + // SAFETY: The pointer originates from an `into_foreign`
>>> call. If `pool` is passed to
>>> + // `from_foreign`, then that happens in `_destroy` which
>>> will not be called during this
>>> + // method.
>>> + let pool = unsafe { T::Pool::borrow_mut(pool) };
>>
>> Wait, can't this happen concurrently to all the other functions that
>> borrow the
>> pool? This would be undefined behavior, no?
>
> Theoretically, yes, but since pool is actually Box<T>, it's only the
> inner T that is mutable.
>
> Anyway, the only reason for malloc() to require a mutable reference is
> that the backend implementation *may* use RBTree::cursor_lower_bound()
> which requires a mutable reference of the tree.
>
> Would it be okay if I
> * change the Zpool API so that malloc takes an immutable reference
> * extend the RBTree API with a cursor_lower_bound analog which doesn't
> require a mutable tree?
As a matter of fact, the RBTree change may be postponed and submitted
together with zblock, it is not relevant until then.
~Vitaly
next prev parent reply other threads:[~2025-08-28 10:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-23 13:04 [PATCH v4 0/2] rust: zpool: add abstraction for zpool drivers Vitaly Wool
2025-08-23 13:05 ` [PATCH v4 1/2] rust: alloc: add from_raw method to Flags Vitaly Wool
2025-08-26 10:57 ` Danilo Krummrich
2025-08-23 13:05 ` [PATCH v4 2/2] rust: zpool: add abstraction for zpool drivers Vitaly Wool
2025-08-26 12:20 ` Danilo Krummrich
2025-08-27 20:43 ` Vitaly Wool
2025-08-28 10:01 ` Vitaly Wool [this message]
2025-08-26 17:02 ` Benno Lossin
2025-08-27 14:24 ` Vitaly Wool
2025-08-27 15:59 ` Benno Lossin
2025-08-28 7:22 ` Vitaly Wool
2025-08-26 10:43 ` [PATCH v4 0/2] " Miguel Ojeda
2025-08-26 11:37 ` Danilo Krummrich
2025-08-27 12:37 ` Alice Ryhl
2025-08-26 12:44 ` Johannes Weiner
2025-08-26 14:56 ` Vitaly Wool
2025-08-27 13:07 ` Johannes Weiner
2025-09-02 15:16 ` Vitaly Wool
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d91e6483-c5a6-468f-b40e-1acdd28a80cd@konsulko.se \
--to=vitaly.wool@konsulko.se \
--cc=Liam.Howlett@oracle.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=lossin@kernel.org \
--cc=nphamcs@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
--cc=yosry.ahmed@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).