From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 46694103E171 for ; Wed, 18 Mar 2026 12:46:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0CA9D10E7FC; Wed, 18 Mar 2026 12:46:52 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="sT4qsHsB"; dkim-atps=neutral Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7976710E77B for ; Wed, 18 Mar 2026 09:10:06 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-667d8f30c50so463079a12.0 for ; Wed, 18 Mar 2026 02:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773825005; x=1774429805; darn=lists.freedesktop.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=03huxt4oynUT1355qRW2FMfKGuIDazVvmXTmtQppc9Q=; b=sT4qsHsB5s9kky9OqEAPsVhmqsY6f1uENiHTxzznaxlsuDBufxpjzsTFAcWfZ8tUFT KAKTyaM+MnQPRKb+3Gx2V0Y6qrGkIpRokAkII0bH14f1KKa48Xq6No0j4C9lWLag6IKM nKTbf2LPsbESEbo4yQHx8Vjsh3rQGWEORi/HnLelsnCpxyN+OT5Wg+weV5Rpj92MG60F mjOdZKlLirZfU57/AM7dbqu/84A99hZXceopWF+T0YCPI9R99sJcUdFjZuEiWqpluUxM l/p0/MLKA6T04VbYliy1eO6JylmWWauOpvWg18CLdF5IyBwAWORRX20mexcCinv3hLit dxMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773825005; x=1774429805; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=03huxt4oynUT1355qRW2FMfKGuIDazVvmXTmtQppc9Q=; b=KkbMZ8UJVHVNILy+gczsGzlb6E/IuRqLBEaoKxek6ikQtRcMfFz7G2FnFRMo/Ww4Rg 9NTeACsivzmmfFH4/bndPYITaOAezKvjniItm2Bo5FAss9VRebTvs3H55kXeelXmBT6t 5ojJY6Vc/aeYGqBU/3n7hF1VbVcHdusx2kbf/kCdyXaQyEDzfSnYcIRJgj3bZuj+Aplr BozwJDkHRTjgp3kSKY5GPDruTgrKDrFkGoZc5z4kovxii+3++RQnTaAFWlwilZj2QaF9 djaVR6hG+sLumRisVPV0C92SbRtGQ7DJk5c8ci7uMzHXnDpdado3hYaRdm7LUzp83jjp TLHQ== X-Forwarded-Encrypted: i=1; AJvYcCX4fgBlboBZynXHSlmz9sLTGAQd0pG4+YHj/fbudx5YU+JvHG2wqPJKwWRcGdPDrWvhYgfxZClh@lists.freedesktop.org X-Gm-Message-State: AOJu0Yz3jTlvh07K89GKLrm9ZtmAIvMesi8eWSjzvbzctjf13kTuBlkP +laJW3Z++RJ4221AKvC79drdKYa/3fYCEw2KtyQJjyxa/2CakD4OnOyL1l0USfv1ZgxH84CFDFg 2BCq7JHGlMFydYH8LSA== X-Received: from ejjr7.prod.google.com ([2002:a17:906:7047:b0:b94:2c7d:9fe]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:c145:b0:b97:ca81:e89a with SMTP id a640c23a62f3a-b97f435a1afmr186730166b.0.1773825004253; Wed, 18 Mar 2026 02:10:04 -0700 (PDT) Date: Wed, 18 Mar 2026 09:10:03 +0000 In-Reply-To: <20260317201710.934932-2-joelagnelf@nvidia.com> Mime-Version: 1.0 References: <20260317201710.934932-1-joelagnelf@nvidia.com> <20260317201710.934932-2-joelagnelf@nvidia.com> Message-ID: Subject: Re: [PATCH v13 1/1] rust: interop: Add list module for C linked list interface From: Alice Ryhl To: Joel Fernandes Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Alex Gaynor , Danilo Krummrich , Dave Airlie , David Airlie , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simona Vetter , Daniel Almeida , Koen Koning , Nikola Djukic , Alexandre Courbot , Philipp Stanner , Elle Rhumsaa , Jonathan Corbet , Alex Deucher , "Christian =?utf-8?B?S8O2bmln?=" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Huang Rui , Matthew Auld , Matthew Brost , Lucas De Marchi , "Thomas =?utf-8?Q?Hellstr=C3=B6m?=" , Helge Deller , John Hubbard , Alistair Popple , Timur Tabi , Edwin Peer , Andrea Righi , Andy Ritger , Zhi Wang , Balbir Singh , alexeyi@nvidia.com, Eliot Courtney , dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-fbdev@vger.kernel.org Content-Type: text/plain; charset="utf-8" X-Mailman-Approved-At: Wed, 18 Mar 2026 12:46:48 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" On Tue, Mar 17, 2026 at 04:17:10PM -0400, Joel Fernandes wrote: > Add a new module `kernel::interop::list` for working with C's doubly > circular linked lists. Provide low-level iteration over list nodes. > > Typed iteration over actual items is provided with a `clist_create` > macro to assist in creation of the `CList` type. > > Cc: Nikola Djukic > Reviewed-by: Daniel Almeida > Reviewed-by: Alexandre Courbot > Acked-by: Alexandre Courbot > Acked-by: Gary Guo > Acked-by: Miguel Ojeda > Signed-off-by: Joel Fernandes I have a few nits below. But overall I think this looks ok: Reviewed-by: Alice Ryhl Please do consider my mod.rs suggestion too, though. > +//! ``` > +//! use kernel::{ > +//! bindings, > +//! clist_create, IMO the automatic re-exports of macros at the root shouldn't be used. Import it from kernel::interop::list::clist_create instead. Note that you need to put a re-export below macro definition to do this. macro_rules! clist_create { (unsafe { $head:ident, $rust_type:ty, $c_type:ty, $($field:tt).+ }) => {{ // Compile-time check that field path is a `list_head`. // SAFETY: `p` is a valid pointer to `$c_type`. let _: fn(*const $c_type) -> *const $crate::bindings::list_head = |p| unsafe { &raw const (*p).$($field).+ }; // Calculate offset and create `CList`. const OFFSET: usize = ::core::mem::offset_of!($c_type, $($field).+); // SAFETY: The caller of this macro is responsible for ensuring safety. unsafe { $crate::interop::list::CList::<$rust_type, OFFSET>::from_raw($head) } }}; } pub use clist_create; // <-- you need this See tracepoint.rs or any of the other macros for an example. > +//! // Create typed [`CList`] from sentinel head. > +//! // SAFETY: `head` is valid and initialized, items are `SampleItemC` with > +//! // embedded `link` field, and `Item` is `#[repr(transparent)]` over `SampleItemC`. > +//! let list = clist_create!(unsafe { head, Item, SampleItemC, link }); Did you try using this in your real use-case? You require `head` to be an :ident, but I think for any 'struct list_head' not stored on the stack, accepting an :expr would be easier to use so that you can just pass `&raw mut my_c_struct.the_list_head` directly to the macro. Right now you have to put the raw pointer in a local variable first. Alice