From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADAF3233704; Fri, 28 Nov 2025 18:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764353875; cv=pass; b=ZSUoTi/BfYpedcdduxsjarNW+16SXHEq/U6//gFsET2sguSNvgHCMu1CFzR9XLgQopCC5BLEMV7IVcgE54q+PUVXi7ugQDt9iQyI9Gl89dl/wdyVSnfxNivDv47ePBqAnyp/kDk+M6SFi7fKE0uVChN2suxAwOvFM1DUQF1/OJw= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764353875; c=relaxed/simple; bh=+ksH2T43V2eRQ24In3PfEQ6FpXFpSoBTQadpWD61qdM=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=D7Svu7aP8IxX9cXEZ/GP5QyKMqRDda8yM6Fz3kRqrR10itBfC3sKF7G3v57yh7UdCwNwuAJWs5WPrMqBeyh334KoRgcraknrwsIQ4unhpv/WKzrhQLUl0kP14+JqlNlUNeuykZFKtVx3pDaAyzZ6wLO9q7f99ag6O1r+feAbu9w= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b=Pl3GZYY+; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b="Pl3GZYY+" ARC-Seal: i=1; a=rsa-sha256; t=1764353846; cv=none; d=zohomail.com; s=zohoarc; b=Jox1fFDdDRfcOoaUgQo3oiYvtsKKyp/YmElZftXBiNabSoJDMwjAeZ8QCxGMVjAc4KOLw0WaxhklQDsQt8rSajaMg4RAhi+ZXarYcT8FwyULXgvdbcj4WxP8NbpmDel9q0q+dlHbBTZgVPBR/xjImt6sQlF4dZzDIf1fBj8Iu7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764353846; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=j4ivFqigThk49301zG4PXOGvB2HvqPMCvI/Ch9oE6HM=; b=BuS1PoU0dfPkp4tWlSJ5l50GqoWc8lALMKL/6XCHaNkVF0o+jg9dgksFBUdQUnca6LjnA41fIJJjW3hFqYTGxXXkYTjaP9z5ER0Eht6ZdYtW0JpodVBAptOG3yx3QIkxEWjqXy8mARDZ6uwi/1tWXyIwtMfqwSvsbLvDnvR03ug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=daniel.almeida@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1764353846; s=zohomail; d=collabora.com; i=daniel.almeida@collabora.com; h=Content-Type:Mime-Version:Subject:Subject:From:From:In-Reply-To:Date:Date:Cc:Cc:Content-Transfer-Encoding:Message-Id:Message-Id:References:To:To:Reply-To; bh=j4ivFqigThk49301zG4PXOGvB2HvqPMCvI/Ch9oE6HM=; b=Pl3GZYY+Ovwc5F3PMyeD3yvPF1/f3kJCS8Av5PgSmlwKTg11xBIaD/g1eWjGdcE5 viCH5seUu2P6NrKPv/h3v6AVMEsi32WUrbSFFC1HGpsaYlhRztN26MZ3XSJyzLoUVWm QM+nFM7x5XKLljDuPFPUW9spJ0bgc0U31Z2femyM= Received: by mx.zohomail.com with SMTPS id 1764353845000735.4598349893454; Fri, 28 Nov 2025 10:17:25 -0800 (PST) Content-Type: text/plain; charset=utf-8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PATCH v2 1/3] rust: helpers: Add list helpers for C linked list operations From: Daniel Almeida In-Reply-To: Date: Fri, 28 Nov 2025 15:17:07 -0300 Cc: Joel Fernandes , "linux-kernel@vger.kernel.org" , "rust-for-linux@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "dakr@kernel.org" , "airlied@gmail.com" , Alistair Popple , "ojeda@kernel.org" , "alex.gaynor@gmail.com" , "boqun.feng@gmail.com" , "gary@garyguo.net" , "bjorn3_gh@protonmail.com" , "lossin@kernel.org" , "a.hindborg@kernel.org" , "aliceryhl@google.com" , "tmgross@umich.edu" , "simona@ffwll.ch" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "tzimmermann@suse.de" , John Hubbard , Timur Tabi , "joel@joelfernandes.org" , "elle@weathered-steel.dev" , Andrea Righi , "phasta@kernel.org" , "nouveau@lists.freedesktop.org" , Nouveau Content-Transfer-Encoding: quoted-printable Message-Id: <5F21F7D7-D0E7-4B25-AC3E-D21331EE4A1F@collabora.com> References: <20251111171315.2196103-1-joelagnelf@nvidia.com> <095D38BD-A8AA-4BC3-8C24-9454964EB8F8@nvidia.com> To: Alexandre Courbot X-Mailer: Apple Mail (2.3826.700.81) X-ZohoMailClient: External > On 25 Nov 2025, at 22:16, Alexandre Courbot = wrote: >=20 > On Wed Nov 26, 2025 at 3:16 AM JST, Joel Fernandes wrote: >>=20 >>=20 >>> On Nov 25, 2025, at 9:52=E2=80=AFAM, Alexandre Courbot = wrote: >>>=20 >>> =EF=BB=BFOn Wed Nov 12, 2025 at 2:13 AM JST, Joel Fernandes wrote: >>>> Add Rust helper functions for common C linked list operations >>>> that are implemented as macros or inline functions and thus not >>>> directly accessible from Rust. >>>>=20 >>>> Signed-off-by: Joel Fernandes >>>> --- >>>> rust/helpers/helpers.c | 1 + >>>> rust/helpers/list.c | 32 ++++++++++++++++++++++++++++++++ >>>> 2 files changed, 33 insertions(+) >>>> create mode 100644 rust/helpers/list.c >>>>=20 >>>> diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c >>>> index 79c72762ad9c..634fa2386bbb 100644 >>>> --- a/rust/helpers/helpers.c >>>> +++ b/rust/helpers/helpers.c >>>> @@ -32,6 +32,7 @@ >>>> #include "io.c" >>>> #include "jump_label.c" >>>> #include "kunit.c" >>>> +#include "list.c" >>>> #include "maple_tree.c" >>>> #include "mm.c" >>>> #include "mutex.c" >>>> diff --git a/rust/helpers/list.c b/rust/helpers/list.c >>>> new file mode 100644 >>>> index 000000000000..fea2a18621da >>>> --- /dev/null >>>> +++ b/rust/helpers/list.c >>>> @@ -0,0 +1,32 @@ >>>> +// SPDX-License-Identifier: GPL-2.0 >>>> + >>>> +/* >>>> + * Helpers for C Circular doubly linked list implementation. >>>> + */ >>>> + >>>> +#include >>>> + >>>> +bool rust_helper_list_empty(const struct list_head *head) >>>> +{ >>>> + return list_empty(head); >>>> +} >>>> + >>>> +void rust_helper_list_del(struct list_head *entry) >>>> +{ >>>> + list_del(entry); >>>> +} >>>> + >>>> +void rust_helper_INIT_LIST_HEAD(struct list_head *list) >>>> +{ >>>> + INIT_LIST_HEAD(list); >>>> +} >>>> + >>>> +void rust_helper_list_add(struct list_head *new, struct list_head = *head) >>>> +{ >>>> + list_add(new, head); >>>> +} >>>> + >>>> +void rust_helper_list_add_tail(struct list_head *new, struct = list_head *head) >>>> +{ >>>> + list_add_tail(new, head); >>>> +} >>>=20 >>> Just noticed, but of these helpers only `INIT_LIST_HEAD` and >>> `list_add_tail` seem to be used (in doccomments). >>=20 >> Correct, but it makes sense to add the most obvious/common ones (also = to make it clear that using these are supported). >=20 > "It makes sense" is subjective, and in this case I am confident it is > not the right intuition to add dead code just for the sake of it. >=20 > Each of these helpers adds a potential breakage point from the C API > should the latter change, so we should only add them if they are = indeed > necessary. >=20 > Actually, some of these helpers are not used when they could have been = - > you have a `is_empty` method that rewrites the C function instead of > calling the helper. The only helpers that are unjustified as of now as > `list_add` and `list_del`, and these are easy to add when they become > necessary. >=20 > But this raises an interesting dilemma: these helpers cannot be = inlined > and add the overhead of a function call. On the other hand, the > definition of `list_head` is so excessively simple that manipulating = it > directly is virtually as intuitive as invoking the helper - and = doesn't > bear the overhead. So should we double-down on these helpers, or just > drop them completely and re-implement the list functionality we need = for > increased performance? IIRC, there is someone working to fix this overhead by working on LTO = support, or at least I remember this talk at some iteration of Kangrejos. If you use the helpers, you=E2=80=99ll be covered in the future. =E2=80=94 Daniel=