From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85E2935E955 for ; Wed, 18 Mar 2026 09:10:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773825008; cv=none; b=kAZGdLdVZXu+SkCwT6/zogHF3zQW0BzM1A2ApJoQ/g93tWb1eFgz83GNKG3lb7p61X6njKmdXTXcuwjNPK8wb2ew7Srnfg1tzwlIbmUSg+npqeservXDsphAM5+uiIxClvGgC2mcl4waT7nBMl5x+c7n/OGFJmwYQu0azTDwMUs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773825008; c=relaxed/simple; bh=RGacs2beT3PZu9097upNzyWrZnaBTNv6EpBqYfjVR1M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LFuvInztjj9TsazUsL0EH69SFvE7DJLbBIRdx6L9s8mAPe3upFwR6YjGrnk537IxeW90o5ROx2FkejFXsYGQ8GabcWqLqpR+nv4wpNEEDkyuOTElJWhbFTv+tIEj72aqXKvzCF7Xb716a2tg5b1tzPUxtMlwc1Exc4WZ+XJ7ok8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B957Sag8; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B957Sag8" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b934e96af9dso51917766b.3 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=vger.kernel.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=B957Sag8/5rMK3yws4YNEazOyKBP7kFgS3fNbdJFAdEAcOpg7G2CptIZZB4vtipgTT KoLrFopsLoSg+gGmhXvSRCKKE0WdQwT2tfHb5+vYGzE9u15o1+L4fB1EV+UotXoJdQ9X A7F5CZjM8A+QHYAhcrjx9G512RSszgs1KPSU4fDvCuXEW0JCxxyZy0r3ywP9la+outVk GreyDltUoMb+AZGuTYmkq/t+DyIHgfK4WilQyqxzavKGD4IRJedR6uFTeen4ZcTT6bEi 8E23a2Anm4DLA3DR53ZvL4A/mHypRGRXMlWslsFGTX6tdCY8HHZ4j+GdViGz6Z+VUlel 4UYA== 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=OJ524GacpYqVXCyp8axi3MdGszjUfXsEAqOtoAApkAaye0v0cJwsGoPhHaEl+umh3x be3d4+R9d8O/MIyQVHjby9q7eSWqEKf/3tDPXR858mW3vAAxkzsJ2nUAHjQwwOYXw137 SX8t6XeVPXtMt/BVxskmAOw48UT658RnimUP3NDR8FEYT53BLe/k0vYkZhkL+/PYZi80 PQxsTG+IlsSuaV06nGBuGeh2XFRKEQxLDTAuzzdYXwcKujGS2hkdxn3mSlif6vOm21LW AnVwGKMst0+pRLSDti5fXhAmV1/eTUg7h2vXGDNSh+dqWZh0W91D6Bd/4FG6SseyuYdp Ng0Q== X-Gm-Message-State: AOJu0Yy+jc8Ev8QqHhF9U7dLeugMICXM5Pv9m+oBaRO9vBmi1YbnmA40 2qUekkJue026wpOdUtsLpjFwuhcAuymX0/6eSvVAiu4+GzcXCrQYl0ziGUUMtnu3RVMWzJr4UOh kqT59MlpFCqqIA4q0rA== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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" 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