From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CWXP265CU009.outbound.protection.outlook.com (mail-ukwestazon11021096.outbound.protection.outlook.com [52.101.100.96]) (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 7A94D3AD507; Thu, 19 Mar 2026 11:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.100.96 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773920406; cv=fail; b=mVx0sK3irwBJyPQNa8kdd+u33UkwrNvUOhMuDe4w/1dzTQemrgq9MiEvU8zZgJJr3xotx0gIsd0Hs1pDTn2px1CLOSdw7554Ep/HSgmzSLTnpny4+7ZdZ6CFGDTa49mv66PXtPRuEtVcnblDgEZsbaPfKECSmwlFKfcGX9dwHB4= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773920406; c=relaxed/simple; bh=yKxJN7Cl6m6P6dOGG2VyNu8gGm6ux4KhwCXb/W/9B48=; h=Content-Type:Date:Message-Id:Cc:Subject:From:To:References: In-Reply-To:MIME-Version; b=SqKy7JpAE66Zu7IccJW3fat6sdnl0DorLXoc+INzs3/0Rgz5pfl+rRjr4AQyRf0nDRJXxqXHmEN3bmmlgt2Hi3nUY/ykLbiqDJ+3t7XEHd0AwCEHWhscVha5zaBMxq+Xsgs1lWSgnCBG7SNosxxSXjZuocX0pGvirS5pkeFC3co= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=gy/gBzx6; arc=fail smtp.client-ip=52.101.100.96 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="gy/gBzx6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DN0aa/S2WCl6eWslOshkdTkCuuX5QvvwMLeNaWhCyCnP0YwkJTsOlaWuxPhwJ2TQ5AbPnciBh7sB3sWiESCC/p8F54FtHmElfH8kggDEYIfDnj63SG5yY4K148QVL6yMBc82fBulE15gOIcCrVZlR4o3laesyjWhnC/+9dBd4vDYhAgEoq4PDY8lKLXZfKTM8ef7achWdqXfjayIg15+so/OcbIBnobzCF5uByUlp9fEf2QFp3j68DN3nIZM2ZZfbZ8Bi/OGEZmX4hjX+iIyocg3CU4d7h2gO0jTt4ytsd4A3KpLKANeIqbtZbjpN1kjHb8hjBy1W3tIaboASFxazQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gl3L1QjF+kTy/gkSiItt0dDU/qdj9xcElaHgQGuLCjA=; b=btiKHkNArmJTDqllnbJvQshPzLEy4BgOY0WAiS64hYq6nSiHxF/M2CcFUxYV54NtNRpC7t7pJ+OTQNJ9tusPh+6W4ccW0q/Ikus8L9WR2Y76DEv+KyCuoGk2eVI2nkXzCxmfO2s2fGm9gdjyc4sErWoKELIGEeXlLWa0vhfp3tNj5t68TpG0K9KlV+sDLxOspIi+WGpMiXvf3LryQXvIDPUOdnJ2O/0+3wwZnRZRHzbF1SUGjRF3C/nDYdRmJmq6foYITr1txBsgAAWSz2qSJm0rLuVtc21G1Wrf67R6d0OhgaVrycFKB05d+X+uEnLY/mKeQKPfnk0Osiu7mwamng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gl3L1QjF+kTy/gkSiItt0dDU/qdj9xcElaHgQGuLCjA=; b=gy/gBzx66P/e2mOjjph28F+emkNj92lKIbO/tUQVjmA15j2nZ0sNEldTqwtldPrnw5VY3TEEvKZ2z15n8/3eoUXiBlgIgKgZ54P7IM9HhhUwlhiadpXd+cB2QDefR+LMtvqGhN3CA/0dvHXluIIXVZ0sZf5jqUz6Da3+rItidiA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) by LOYP265MB2176.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:11f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.19; Thu, 19 Mar 2026 11:39:55 +0000 Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986]) by LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986%5]) with mapi id 15.20.9723.018; Thu, 19 Mar 2026 11:39:55 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 19 Mar 2026 11:39:54 +0000 Message-Id: Cc: "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "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" , =?utf-8?q?Christian_K=C3=B6nig?= , "Jani Nikula" , "Joonas Lahtinen" , "Rodrigo Vivi" , "Tvrtko Ursulin" , "Huang Rui" , "Matthew Auld" , "Matthew Brost" , "Lucas De Marchi" , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , "Helge Deller" , "John Hubbard" , "Alistair Popple" , "Timur Tabi" , "Edwin Peer" , "Andrea Righi" , "Andy Ritger" , "Zhi Wang" , "Balbir Singh" , , "Eliot Courtney" , , , , , , , Subject: Re: [PATCH v13 1/1] rust: interop: Add list module for C linked list interface From: "Gary Guo" To: "Joel Fernandes" , X-Mailer: aerc 0.21.0 References: <20260317201710.934932-1-joelagnelf@nvidia.com> <20260317201710.934932-2-joelagnelf@nvidia.com> In-Reply-To: <20260317201710.934932-2-joelagnelf@nvidia.com> X-ClientProxiedBy: LO2P265CA0081.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::21) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|LOYP265MB2176:EE_ X-MS-Office365-Filtering-Correlation-Id: 20b83634-9607-478b-f95b-08de85ac3e26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|376014|366016|10070799003|7053199007|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: vpwER8soRUOOaPEAR0lU9YuZNmyo/nH6XdSrVjTzGWmZHTeCe5D6wI1mUp1GBZSKabAi9cKtPSDewJp40JcXBZGlHZTgHRTj/5ZHnq2IVINsY9EzVfRhox+6VKP4pb9HYTNnf7yyVtobJeI4fEsHshV6D0WzY6v/3PL+Ed2noxU2WJqZBIzNsAuKc0lqJL9Nj3LHb9bdMnmve8hbvO5p5hE2IkNEZ5BOUcchsa5WFyYL/PCwiXXKMB+P9WuCrZZtIiEX+iyRl72z1p7+CFnsDmmNT4/Kg/qjA6wh+fdUggTw4XvtK0o7J2tLWZtyPM+QetZefv2Atu50vfshWjeUXkIBx8nXujb46kAVvGWhx7l064cEXOOT35W+SLfXlFuH60qcYLVe40RqTjAv9hACzdXxbrNheaaQlVUEoZhaxXG46buiqMFJXX5PaQjtjNByKCnoVeo8BIDiU41nuIlu7ey76YxVG4Y4tS4G6Je1rH6mBWKGV5HBXPNI+yogxXfD58PGsMDRth9YomUY5ioI3SSz9P/Sc508dpxnCwX1pVCGcnYzs4yB7otwMpYA9EOyTdpgV/5G4TVdvckwxqLOPrzSzD6Aysq+fmJmyIZrdSR0cpcgpAj6Of3mPz9TskzHEi+5TPeuks46MZKGdTusMvSDKP/iddLF/8ZwFnxTQQ16JJh9TMf1b676s1q5xwmtuBVwkDjIWOTNNbAuLQeHnvbvuQkzseOU2yUlNBfnTf4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(376014)(366016)(10070799003)(7053199007)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SUN5N0pmaTlEeFc3TUZUMHRtSHpTa093SndGcURqODFYS2QvQWdmNWhoS2pB?= =?utf-8?B?cW9XKzFZSXJXWGQxUHQ0UU03eXZUdzlLWmdwNUxEeTNTR2Q5SzdHYk13VHlr?= =?utf-8?B?UFlHV293b0ljNnIxM0h6TkhFYkZhOU5HMlFSNFBkL2ZQQ2s5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N28zb3o3Z2diWjVZc0dSc0NrZG1rNTZ3T2JKV0djOEU4VkZDTksrZThn?= =?utf-8?B?ck04VHAzazUybkdSemZLcTVhSFE3R1B1V1hvV2UyU3YrL1NVOFNHOU9vUHBO?= =?utf-8?B?R3BVRTF3QXBBUlBSS3JmaWk4Tm5LQzlRNEhRSzVvNmpjNVVUc2w0NVZIMzA3?= =?utf-8?B?Z0tTT1RleXJsQTAreHF2RWorbGFtRjR2YmpkTHoxK3dPNlZkMTZjVUR2MDda?= =?utf-8?B?anNPMjNrZ1hINVl0R1RLZU5FSUlmNmtYTnRiS0ZvQS9FcGlWYkZZUHNKdUhk?= =?utf-8?B?UzcrT1NJNVlOZk1jdmhrVW52L3dESExsb2MwU2ZkR1RCNVRPQVl5ZVRSWlhK?= =?utf-8?B?QTIxUnplQ2xiKzdhRGtEeStobG1YU0p2a0Y1WEZ0N0dzVTFkMnMrQT09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 20b83634-9607-478b-f95b-08de85ac3e26 X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2026 11:39:55.8229 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xLxBoePccVpNlqqGktuIU87BKHOMxGn/YHRulmBaqLXY4ahRyqJ58fBogDV0h5yRvVvr9ZGDv77iYw7FA3bvTg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LOYP265MB2176 On Tue Mar 17, 2026 at 8:17 PM GMT, 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 > --- > MAINTAINERS | 8 + > rust/helpers/helpers.c | 1 + > rust/helpers/list.c | 17 ++ > rust/kernel/interop.rs | 9 + > rust/kernel/interop/list.rs | 342 ++++++++++++++++++++++++++++++++++++ > rust/kernel/lib.rs | 2 + > 6 files changed, 379 insertions(+) > create mode 100644 rust/helpers/list.c > create mode 100644 rust/kernel/interop.rs > create mode 100644 rust/kernel/interop/list.rs > > +/// Create a C doubly-circular linked list interface [`CList`] from a ra= w `list_head` pointer. > +/// > +/// This macro creates a `CList` that can iterate over items = of type `$rust_type` > +/// linked via the `$field` field in the underlying C struct `$c_type`. > +/// > +/// # Arguments > +/// > +/// - `$head`: Raw pointer to the sentinel `list_head` object (`*mut bin= dings::list_head`). > +/// - `$rust_type`: Each item's rust wrapper type. > +/// - `$c_type`: Each item's C struct type that contains the embedded `l= ist_head`. > +/// - `$field`: The name of the `list_head` field within the C struct. > +/// > +/// # Safety > +/// > +/// The caller must ensure: > +/// > +/// - `$head` is a valid, initialized sentinel `list_head` (e.g. via `IN= IT_LIST_HEAD()`) > +/// pointing to a list that is not concurrently modified for the lifet= ime of the [`CList`]. > +/// - The list contains items of type `$c_type` linked via an embedded `= $field`. > +/// - `$rust_type` is `#[repr(transparent)]` over `$c_type` or has compa= tible layout. > +/// > +/// # Examples > +/// > +/// Refer to the examples in the [`crate::interop::list`] module documen= tation. > +#[macro_export] > +macro_rules! clist_create { > + (unsafe { $head:ident, $rust_type:ty, $c_type:ty, $($field:tt).+ }) = =3D> {{ > + // 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 = =3D > + |p| unsafe { &raw const (*p).$($field).+ }; Actually, this check is insufficient, you should create a reference instead (just in case people put this inside `repr(packed)`. This could be something like let _ =3D |p: &$c_type| { _ =3D &p.$($field).+ } ? > + > + // Calculate offset and create `CList`. > + const OFFSET: usize =3D ::core::mem::offset_of!($c_type, $($fiel= d).+); > + // SAFETY: The caller of this macro is responsible for ensuring = safety. > + unsafe { $crate::interop::list::CList::<$rust_type, OFFSET>::fro= m_raw($head) } Given that this is unsafe, I am not sure why the macro should have unsafe keyword in it, rather than just being `clist_create(a, b, c, d)` and just h= ave user write unsafe. The offset could probably benefit from similar strategies we used for other embedded data structure like Rust list and work items. Boqun has a series unifying these and clist could probably use it, too. (As a follow-up) Best, Gary > + }}; > +} > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index d93292d47420..bdcf632050ee 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -29,6 +29,7 @@ > #![feature(lint_reasons)] > // > // Stable since Rust 1.82.0. > +#![feature(offset_of_nested)] > #![feature(raw_ref_op)] > // > // Stable since Rust 1.83.0. > @@ -107,6 +108,7 @@ > #[doc(hidden)] > pub mod impl_flags; > pub mod init; > +pub mod interop; > pub mod io; > pub mod ioctl; > pub mod iommu; G