From nobody Thu Apr 2 10:57:38 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010058.outbound.protection.outlook.com [52.101.61.58]) (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 792383254B9; Tue, 10 Feb 2026 23:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770766346; cv=fail; b=TkhJVebGPXiuC6SRYlTsphuNlVKBme7Kkl7g7Cqj52XwPnjZZ7J+aq9L2zZ5KwriWfX+jE3mroX4YtSjhF0/cBxWET9Rv72LSF60xr791mmo8rduDQsNwwG4bjKayPsiArPirfZ7d2vV7y4KBqLryI6VpxvlvDZLKtHrnDN8lZc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770766346; c=relaxed/simple; bh=9Xb+rXRYaQ8scq4mStxpKGLWAEUu+tLFZZAmApaV3Cs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=h6BQnueIp7XSIuiZHtYw0MkNoij12UP0kWQvhlcpcZk8Ho+K0u3yf1xLFsFwV5OFyZd05GzmMTbv7BanLB4L6gVAWxMMU9PcaZjsH0qzncHKDsLTwrRJljKP3rNTh6Q0HyGw8Z8JU9F80DaWicoEbBeRMN11kN7AK6dbw9zmPlA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=X03L3i/W; arc=fail smtp.client-ip=52.101.61.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="X03L3i/W" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Zkiki1kr2KDIkoY8ivqK/6HjBvtc8exMYshUID2u5ene0COKu+SZheabOUcVCPnJEM5m9fGUs6tw1H95Pb6y7THmaiGnK1ZJeM+ReUaUCcipo34k2YcMaihIobbs97HTCBI0Sqq9jkYvloHR1aiAkqmBZCKCvMuPoGyIYdU2oSV95yod18GJBPl9fChYvcPVhBIfRyd2c9bp74VHywIIpW4afp8F34gb0RHGi+4/dN6OPRB4zZ42ocfHyXXEKgCFOzOaypR+eWTTM3DVSlkJJu/sUbq2ZWUPChA0frQ13WLZ53Q8AvTiLTNPr95LquCcgOOL+xtdOmzuN96Nl6IqsA== 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=0gtoHDQkt6SKHCVxHIaW5+24u06Aw4W4MlX+cpB+gHQ=; b=RSFcKipbm5gkPe+Pm5C5HP9eNooWgFDlFSxpPfA9HiJlz+h7OnsJlrTHC49BQXgnn2Z/iEhbDhin1G6l6gDaYZMnanBkTpu0TcQ2n3KTsjnv36mob3jEcLSU7yKlchp8sq8FYIdsLf/Izix/EWYsItXzfZbC3xGYmF0CyjC1KvPUrasef7qouMu+WcjR1NVuJbQSLvg5CTE8C31q04M6iDEH8lqZyDRFV/FhLbiTh9g2WmiyBYVHvgyEI8QEw05ootoE4QNR9C7fiCyrR29GEu0Cq0aTxSPmiJQga6BEogED9xomWE+IEXQRU40CvdHR45s3vw6XMncBJOsjUlKrqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0gtoHDQkt6SKHCVxHIaW5+24u06Aw4W4MlX+cpB+gHQ=; b=X03L3i/W/AWltg8GMubxf2yxa6NL88AHe3FJ7A86vQGRsBw9Evpryrl+SK2fvaaXRcrc7mlf3IU3vA/8L0A47NuAB+gMiA/W4ai+dphjeH7OXSl1fFjqSoGxkFk1VZjd4WQOr8Bu9YZxdxqS8zvcB4wczsFLe6ty3lG+1t5f5ohmUBd/sL9LXlpxUKAWRyTqdMTzWZq4E3x4rGZ2isSX9qNXolFxK6pkZYh4bcCB5W1eARHvro1+7S8w1ieEJFXD8fVIwfSQLMaXxuLxGy+23vFxar6uQBghll16xKnb0UPL7JE+fMCJswXVDEeTmgkhPXBVzfS05zNfMuBBIWcJnA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB6486.namprd12.prod.outlook.com (2603:10b6:8:c5::21) by IA1PR12MB8586.namprd12.prod.outlook.com (2603:10b6:208:44e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.10; Tue, 10 Feb 2026 23:32:16 +0000 Received: from DS0PR12MB6486.namprd12.prod.outlook.com ([fe80::88a9:f314:c95f:8b33]) by DS0PR12MB6486.namprd12.prod.outlook.com ([fe80::88a9:f314:c95f:8b33%4]) with mapi id 15.20.9587.017; Tue, 10 Feb 2026 23:32:16 +0000 From: Joel Fernandes To: linux-kernel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Simona Vetter , Jonathan Corbet , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Huang Rui , Matthew Auld , Matthew Brost , Lucas De Marchi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Helge Deller , Danilo Krummrich , Alice Ryhl , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Alistair Popple , Alexandre Courbot , Andrea Righi , Zhi Wang , Philipp Stanner , Elle Rhumsaa , Daniel Almeida , David Airlie , Edwin Peer , John Hubbard , Andy Ritger , Balbir Singh , Timur Tabi , joel@joelfernandes.org, nouveau@lists.freedesktop.org, 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, Joel Fernandes Subject: [PATCH -next v9 1/3] rust: clist: Add support to interface with C linked lists Date: Tue, 10 Feb 2026 18:32:02 -0500 Message-Id: <20260210233204.790524-2-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260210233204.790524-1-joelagnelf@nvidia.com> References: <20260210233204.790524-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CY8PR19CA0014.namprd19.prod.outlook.com (2603:10b6:930:44::19) To DS0PR12MB6486.namprd12.prod.outlook.com (2603:10b6:8:c5::21) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB6486:EE_|IA1PR12MB8586:EE_ X-MS-Office365-Filtering-Correlation-Id: 266f87e1-76bc-4051-a500-08de68fc9fa9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: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kgNvhwWtU6uF3zDy6Rh?= =?us-ascii?Q?prfTtXdbMsoMQ6ifuWpTy4/askvsLElg4uhhXoJgGNeMx0d/KdmKP0IilW7l?= =?us-ascii?Q?wavO0RPq6mP+GH64kEY8sj9PyHrFd6S5hvDxHcfIcjhpI2zj6ydOsZV68Zp3?= =?us-ascii?Q?ASDg1rOQJOHiaqWe00UXgz7vbMJi06knUDOdSW2/jtZKg7JB5l8FEThVUJfn?= =?us-ascii?Q?TcLjqs5ud8dGFMjLBoSIR4gejK4jJ3kbX2aU68qZqDDW2XhUZPL4hXljUFMx?= =?us-ascii?Q?MU6ghTj4PrbkdT7p9p1Cnk2vjVC2JxFHhsIIT2u7xo8xUKVBhFyx4x2Pm98b?= =?us-ascii?Q?aTpGpPWRVPJuqbnD6pFiuIJsWxnnpZC9QzuPYIkjte7eI7Cf0WGWOhu2Dl0I?= =?us-ascii?Q?zt+6EB8OG6OCnx8uyzJc7lGBBMiVlACR9aCNODW176fPZF+KeigkI8ialBHX?= =?us-ascii?Q?XUY+4IsygA4uYfvaiaHg6/+XJR4hna4KzHYv2x7cD+eekGRMf9U2dbU5nPbH?= =?us-ascii?Q?PIQrUEwFn3n3m6Rgv5JWL4y+4dEyiWmS8I4MkuuADfsn2cgHhe6KW+PRYB8G?= =?us-ascii?Q?X2dZQsjwqiCct8usZE1dBEV5K+G061Oed/RURKEeTauD7wY4GsCi57DsJ613?= =?us-ascii?Q?E7SWbyzkh/4SkZFSvHUeiAh0ZwWY1V53WMkOB9or+0InuTDOrUYAa1MzqPqC?= =?us-ascii?Q?ODKq+tOe6T2eA0OpiB4=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB6486.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-A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=?us-ascii?Q?YOAqTQVJQg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 266f87e1-76bc-4051-a500-08de68fc9fa9 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB6486.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2026 23:32:15.4490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QXKOUpfiT0jz7Xrw0xqZaBJ35BZJKk4Ojcj88ZOUGBS6SqdSIwHZ7WOTIAmToPHs88nyLscuoLkR4kN/dxYY1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8586 Content-Type: text/plain; charset="utf-8" Add a new module `clist` 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. Reviewed-by: Daniel Almeida Acked-by: Gary Guo Signed-off-by: Joel Fernandes --- MAINTAINERS | 7 + rust/helpers/helpers.c | 1 + rust/helpers/list.c | 17 +++ rust/kernel/clist.rs | 320 +++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 5 files changed, 346 insertions(+) create mode 100644 rust/helpers/list.c create mode 100644 rust/kernel/clist.rs diff --git a/MAINTAINERS b/MAINTAINERS index 7cfb766112cd..b0050b478dc9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23205,6 +23205,13 @@ S: Maintained T: git https://github.com/Rust-for-Linux/linux.git rust-analyzer-next F: scripts/generate_rust_analyzer.py =20 +RUST TO C LIST INTERFACES +M: Joel Fernandes +M: Alexandre Courbot +L: rust-for-linux@vger.kernel.org +S: Maintained +F: rust/kernel/clist.rs + RXRPC SOCKETS (AF_RXRPC) M: David Howells M: Marc Dionne diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index a3c42e51f00a..724fcb8240ac 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -35,6 +35,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..4c1f9c111ec8 --- /dev/null +++ b/rust/helpers/list.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Helpers for C Circular doubly linked list implementation. + */ + +#include + +__rust_helper void rust_helper_INIT_LIST_HEAD(struct list_head *list) +{ + INIT_LIST_HEAD(list); +} + +__rust_helper void rust_helper_list_add_tail(struct list_head *new, struct= list_head *head) +{ + list_add_tail(new, head); +} diff --git a/rust/kernel/clist.rs b/rust/kernel/clist.rs new file mode 100644 index 000000000000..8aa72b5d54be --- /dev/null +++ b/rust/kernel/clist.rs @@ -0,0 +1,320 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! A C doubly circular intrusive linked list interface for rust code. +//! +//! # Examples +//! +//! ``` +//! use kernel::{ +//! bindings, +//! clist_create, +//! types::Opaque, // +//! }; +//! # // Create test list with values (0, 10, 20) - normally done by C cod= e but it is +//! # // emulated here for doctests using the C bindings. +//! # use core::mem::MaybeUninit; +//! # +//! # /// C struct with embedded `list_head` (typically will be allocated = by C code). +//! # #[repr(C)] +//! # pub struct SampleItemC { +//! # pub value: i32, +//! # pub link: bindings::list_head, +//! # } +//! # +//! # let mut head =3D MaybeUninit::::uninit(); +//! # +//! # let head =3D head.as_mut_ptr(); +//! # // SAFETY: head and all the items are test objects allocated in this= scope. +//! # unsafe { bindings::INIT_LIST_HEAD(head) }; +//! # +//! # let mut items =3D [ +//! # MaybeUninit::::uninit(), +//! # MaybeUninit::::uninit(), +//! # MaybeUninit::::uninit(), +//! # ]; +//! # +//! # for (i, item) in items.iter_mut().enumerate() { +//! # let ptr =3D item.as_mut_ptr(); +//! # // SAFETY: pointers are to allocated test objects with a list_he= ad field. +//! # unsafe { +//! # (*ptr).value =3D i as i32 * 10; +//! # // &raw mut computes address of link directly as link is uni= nitialized. +//! # bindings::INIT_LIST_HEAD(&raw mut (*ptr).link); +//! # bindings::list_add_tail(&mut (*ptr).link, head); +//! # } +//! # } +//! +//! // Rust wrapper for the C struct. +//! // The list item struct in this example is defined in C code as: +//! // struct SampleItemC { +//! // int value; +//! // struct list_head link; +//! // }; +//! // +//! #[repr(transparent)] +//! pub struct Item(Opaque); +//! +//! impl Item { +//! pub fn value(&self) -> i32 { +//! // SAFETY: [`Item`] has same layout as [`SampleItemC`]. +//! unsafe { (*self.0.get()).value } +//! } +//! } +//! +//! // Create typed [`CList`] from sentinel head. +//! // SAFETY: head is valid, items are [`SampleItemC`] with embedded `lin= k` field. +//! let list =3D unsafe { clist_create!(head, Item, SampleItemC, link) }; +//! +//! // Iterate directly over typed items. +//! let mut found_0 =3D false; +//! let mut found_10 =3D false; +//! let mut found_20 =3D false; +//! +//! for item in list.iter() { +//! let val =3D item.value(); +//! if val =3D=3D 0 { found_0 =3D true; } +//! if val =3D=3D 10 { found_10 =3D true; } +//! if val =3D=3D 20 { found_20 =3D true; } +//! } +//! +//! assert!(found_0 && found_10 && found_20); +//! ``` + +use core::{ + iter::FusedIterator, + marker::PhantomData, // +}; + +use crate::{ + bindings, + types::Opaque, // +}; + +use pin_init::{ + pin_data, + pin_init, + PinInit // +}; + +/// Wraps a `list_head` object for use in intrusive linked lists. +/// +/// # Invariants +/// +/// - [`CListHead`] represents an allocated and valid `list_head` structur= e. +#[pin_data] +#[repr(transparent)] +pub struct CListHead { + #[pin] + inner: Opaque, +} + +impl CListHead { + /// Create a `&CListHead` reference from a raw `list_head` pointer. + /// + /// # Safety + /// + /// - `ptr` must be a valid pointer to an allocated and initialized `l= ist_head` structure. + /// - `ptr` must remain valid and unmodified for the lifetime `'a`. + /// - The list and all linked `list_head` nodes must not be modified b= y non-Rust code + /// for the lifetime `'a`. + #[inline] + pub unsafe fn from_raw<'a>(ptr: *mut bindings::list_head) -> &'a Self { + // SAFETY: + // - [`CListHead`] has same layout as `list_head`. + // - `ptr` is valid and unmodified for 'a per caller guarantees. + unsafe { &*ptr.cast() } + } + + /// Get the raw `list_head` pointer. + #[inline] + pub fn as_raw(&self) -> *mut bindings::list_head { + self.inner.get() + } + + /// Get the next [`CListHead`] in the list. + #[inline] + pub fn next(&self) -> &Self { + let raw =3D self.as_raw(); + // SAFETY: + // - `self.as_raw()` is valid per type invariants. + // - The `next` pointer is guaranteed to be non-NULL. + unsafe { Self::from_raw((*raw).next) } + } + + /// Check if this node is linked in a list (not isolated). + #[inline] + pub fn is_linked(&self) -> bool { + let raw =3D self.as_raw(); + // SAFETY: self.as_raw() is valid per type invariants. + unsafe { (*raw).next !=3D raw && (*raw).prev !=3D raw } + } + + /// Pin-initializer that initializes the list head. + pub fn new() -> impl PinInit { + pin_init!(Self { + // SAFETY: `INIT_LIST_HEAD` initializes `slot` to a valid empt= y list. + inner <- Opaque::ffi_init(|slot| unsafe { bindings::INIT_LIST_= HEAD(slot) }), + }) + } +} + +// SAFETY: [`CListHead`] can be sent to any thread. +unsafe impl Send for CListHead {} + +// SAFETY: [`CListHead`] can be shared among threads as it is not modified +// by non-Rust code per safety requirements of [`CListHead::from_raw`]. +unsafe impl Sync for CListHead {} + +impl PartialEq for CListHead { + #[inline] + fn eq(&self, other: &Self) -> bool { + core::ptr::eq(self, other) + } +} + +impl Eq for CListHead {} + +/// Low-level iterator over `list_head` nodes. +/// +/// An iterator used to iterate over a C intrusive linked list (`list_head= `). Caller has to +/// perform conversion of returned [`CListHead`] to an item (using `contai= ner_of` macro or similar). +/// +/// # Invariants +/// +/// [`CListHeadIter`] is iterating over an allocated, initialized and vali= d list. +struct CListHeadIter<'a> { + /// Current position in the list. + current: &'a CListHead, + /// The sentinel head (used to detect end of iteration). + sentinel: &'a CListHead, +} + +impl<'a> Iterator for CListHeadIter<'a> { + type Item =3D &'a CListHead; + + #[inline] + fn next(&mut self) -> Option { + // Check if we've reached the sentinel (end of list). + if self.current =3D=3D self.sentinel { + return None; + } + + let item =3D self.current; + self.current =3D item.next(); + Some(item) + } +} + +impl<'a> FusedIterator for CListHeadIter<'a> {} + +/// A typed C linked list with a sentinel head. +/// +/// A sentinel head represents the entire linked list and can be used for +/// iteration over items of type `T`, it is not associated with a specific= item. +/// +/// The const generic `OFFSET` specifies the byte offset of the `list_head= ` field within +/// the struct that `T` wraps. +/// +/// # Invariants +/// +/// - The [`CListHead`] is an allocated and valid sentinel C `list_head` s= tructure. +/// - `OFFSET` is the byte offset of the `list_head` field within the stru= ct that `T` wraps. +/// - All the list's `list_head` nodes are allocated and have valid next/p= rev pointers. +#[repr(transparent)] +pub struct CList(CListHead, PhantomData); + +impl CList { + /// Create a typed [`CList`] reference from a raw sentinel `list_head`= pointer. + /// + /// # Safety + /// + /// - `ptr` must be a valid pointer to an allocated and initialized `l= ist_head` structure + /// representing a list sentinel. + /// - `ptr` must remain valid and unmodified for the lifetime `'a`. + /// - The list must contain items where the `list_head` field is at by= te offset `OFFSET`. + /// - `T` must be `#[repr(transparent)]` over the C struct. + #[inline] + pub unsafe fn from_raw<'a>(ptr: *mut bindings::list_head) -> &'a Self { + // SAFETY: + // - [`CList`] has same layout as [`CListHead`] due to repr(transp= arent). + // - Caller guarantees `ptr` is a valid, sentinel `list_head` obje= ct. + unsafe { &*ptr.cast() } + } + + /// Check if the list is empty. + #[inline] + pub fn is_empty(&self) -> bool { + !self.0.is_linked() + } + + /// Create an iterator over typed items. + #[inline] + pub fn iter(&self) -> CListIter<'_, T, OFFSET> { + let head =3D &self.0; + CListIter { + head_iter: CListHeadIter { + current: head.next(), + sentinel: head, + }, + _phantom: PhantomData, + } + } +} + +/// High-level iterator over typed list items. +pub struct CListIter<'a, T, const OFFSET: usize> { + head_iter: CListHeadIter<'a>, + _phantom: PhantomData<&'a T>, +} + +impl<'a, T, const OFFSET: usize> Iterator for CListIter<'a, T, OFFSET> { + type Item =3D &'a T; + + fn next(&mut self) -> Option { + let head =3D self.head_iter.next()?; + + // Convert to item using OFFSET. + // SAFETY: `item_ptr` calculation from `OFFSET` (calculated using = offset_of!) + // is valid per invariants. + Some(unsafe { &*head.as_raw().byte_sub(OFFSET).cast::() }) + } +} + +impl<'a, T, const OFFSET: usize> FusedIterator for CListIter<'a, T, OFFSET= > {} + +/// Create a C doubly-circular linked list interface `CList` from a raw `l= ist_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 bindi= ngs::list_head`). +/// - `$rust_type`: Each item's rust wrapper type. +/// - `$c_type`: Each item's C struct type that contains the embedded `lis= t_head`. +/// - `$field`: The name of the `list_head` field within the C struct. +/// +/// # Safety +/// +/// This is an unsafe macro. The caller must ensure: +/// +/// - `$head` is a valid, initialized sentinel `list_head` pointing to a l= ist that remains +/// unmodified for the lifetime of the rust `CList`. +/// - The list contains items of type `$c_type` linked via an embedded `$f= ield`. +/// - `$rust_type` is `#[repr(transparent)]` over `$c_type` or has compati= ble layout. +/// +/// # Examples +/// +/// Refer to the examples in this module's documentation. +#[macro_export] +macro_rules! clist_create { + ($head:expr, $rust_type:ty, $c_type:ty, $($field:tt).+) =3D> {{ + // Compile-time check that field path is a list_head. + let _: fn(*const $c_type) -> *const $crate::bindings::list_head = =3D + |p| &raw const (*p).$($field).+; + + // Calculate offset and create `CList`. + const OFFSET: usize =3D ::core::mem::offset_of!($c_type, $($field)= .+); + $crate::clist::CList::<$rust_type, OFFSET>::from_raw($head) + }}; +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 3da92f18f4ee..fe711d34ca1e 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -75,6 +75,7 @@ pub mod bug; #[doc(hidden)] pub mod build_assert; +pub mod clist; pub mod clk; #[cfg(CONFIG_CONFIGFS_FS)] pub mod configfs; --=20 2.34.1 From nobody Thu Apr 2 10:57:38 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010058.outbound.protection.outlook.com [52.101.61.58]) (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 6F20D314D3D; Tue, 10 Feb 2026 23:32:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770766348; cv=fail; b=kEQyQi9yyIod+LBnL0VoQylkCUmnBWs+fr8c4CWR5cytiSugoJzJiJrDZOuhhYQSEV3/q4LoyzADvt03awzuxvUBDUIEryWdUdvZWYNuVU9iGYLl3/CEoFltf6wNEgaU/rzaj33TCTUz4ZHkjqoFHNrN2wjvc+jzZ3jtQy2RTF4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770766348; c=relaxed/simple; bh=0bIVFUiZ31VnK72GnXIbkVRdf+w3uDs9lWh4hUtXRDU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=bdBQrut4z7asZuLv4n9dwvMXTh9bZQiV7ZlubbeFLavubl4SSE/sW6hoPCJr+iyK0Ea9r8dsNgHDKCUMJR25WfmsVgE3GWfOHewdIgwImauAt4YEyWj/JK12Xj1ksm4PKRMi1JKWCmAQJXsCeapyOR1zv58ZrDtvvYmvuBaLZNc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ViKnszD9; arc=fail smtp.client-ip=52.101.61.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ViKnszD9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Cyn/hiQ1UbaLcThu6QwzITUsTsfnJAuYpLPdKuzBFYlG68B34Zw1/JHhxcTNcI6h2UEvVSrrM4nFQW124dbh1jBNbRdPtXSQ2Ffmuqt9I0x4R7nqzhEuMNmRCiM36sHtJZaYQuRVDpmUTBfKk+lE5F6mhSyWTiykyonu3jrW/iIUayXZspkQSNGUkJu+PWh+7Joo8ahYZ90tVOtraLYGdpUoe9B+XWx/q/QzYV1cs1T1NHcZGd4LhUCODFfOVJb/1ur2ymG12W5XJRalVOaLBc7jR6B4MRGsej4sOVnYYP0hfQCkB8ydwHUX4DNUgOIiZtaCf0drBOSMvcsEiVN67Q== 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=I6pP5iyuhAc03+N+96TCvFk9mmUr48kpVZssCE8l//Y=; b=R+f0LoRad+9hreMxGtxokNfDanqEwAuZkHKeu7tV72bgqcEZJiIUZujA1byGUdXzsrC4QA5pjv2lgB+PMPlLbnVvkuKIjxBzvM788S5cgjo/bhVWPEYQD3rLTAnYbzSPOUkJOk1W/oinQn5IXFpFa8EWAW6JI/U7Z7ZKxnGMO9BTVr2JPfBSbqBDCa8/1OukKzUSqpuZY4oOi5z2pPM4e2cIJKB1z1vW5g2mDKI1trsBMRZMROPhiRwdyy9lfKaAnjMPLvdaMPBKNC0eD1OkoLK3cHVAOjTq/qXsp18ygAPZvAnYbKDncfRnViuSn4hfgKA1GUlEGh8rYsFS3uJ+5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I6pP5iyuhAc03+N+96TCvFk9mmUr48kpVZssCE8l//Y=; b=ViKnszD9JKpVvDGFVlJeLafwwAsepC5ZwfOPdlsvS9np0ER26yvxzZQtk89NlFTkc2ah5kKJ2B6kXQX+qP2zLx8dh7wWJew+uFpRBbslqoMKaQ82CHbK4lkRhvJ4qqY6Jr90k9pOJkSOzgowCi9XgBhX55rEuGY2tFB1rkGuMGskr6yp++wvwPgAgVamveS0yvcxmGVuPjzTq6gVaeYT8xWdnST1MH1rSMDgqOFPCe38yTX5OCT6Jtz7DXAqUaEsQo2DxWZ+/laSOSZze8A8j3aV+8Pdo2tXv2yuVY9FLJgrDpbKTWNFSvFMaym0Bji4T23vw9Kv/0NloQslm0WRMQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB6486.namprd12.prod.outlook.com (2603:10b6:8:c5::21) by IA1PR12MB8586.namprd12.prod.outlook.com (2603:10b6:208:44e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.10; Tue, 10 Feb 2026 23:32:17 +0000 Received: from DS0PR12MB6486.namprd12.prod.outlook.com ([fe80::88a9:f314:c95f:8b33]) by DS0PR12MB6486.namprd12.prod.outlook.com ([fe80::88a9:f314:c95f:8b33%4]) with mapi id 15.20.9587.017; Tue, 10 Feb 2026 23:32:17 +0000 From: Joel Fernandes To: linux-kernel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Simona Vetter , Jonathan Corbet , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Huang Rui , Matthew Auld , Matthew Brost , Lucas De Marchi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Helge Deller , Danilo Krummrich , Alice Ryhl , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Alistair Popple , Alexandre Courbot , Andrea Righi , Zhi Wang , Philipp Stanner , Elle Rhumsaa , Daniel Almeida , David Airlie , Edwin Peer , John Hubbard , Andy Ritger , Balbir Singh , Timur Tabi , joel@joelfernandes.org, nouveau@lists.freedesktop.org, 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, Joel Fernandes Subject: [PATCH -next v9 2/3] rust: gpu: Add GPU buddy allocator bindings Date: Tue, 10 Feb 2026 18:32:03 -0500 Message-Id: <20260210233204.790524-3-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260210233204.790524-1-joelagnelf@nvidia.com> References: <20260210233204.790524-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CYXPR02CA0026.namprd02.prod.outlook.com (2603:10b6:930:cc::9) To DS0PR12MB6486.namprd12.prod.outlook.com (2603:10b6:8:c5::21) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB6486:EE_|IA1PR12MB8586:EE_ X-MS-Office365-Filtering-Correlation-Id: 669fb05f-e16f-4076-0425-08de68fca0d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?gM+ztHJrz38G3/5Uci0+JS1lQAgOMQ6zktmttEyNvOH+PpZUvuIA1a72V4ma?= =?us-ascii?Q?EWk9jOZce3TPXpW2YxoQFpspq6th8+1HXrFSw0qAjCYP4IdaAYAay1fEgYZd?= =?us-ascii?Q?NrFAWuNuisigVyOCuycdQhJSJkYVQjyBarJ7lwwKYrtvybiEEnvu2nacWgI8?= =?us-ascii?Q?Ld28z5ANwFFY72+ukOcnvgZVydxcedKJzXo1fztF2zR4VBu7l5HeEWCE5sEh?= =?us-ascii?Q?HVsX9pBgbyjVFSdprjvLC8WMUpO2VYHXKARyMAQJS8mwcRsoP1SXuUwLi0qZ?= =?us-ascii?Q?5CFomlUwiiUrrY44h34ax6F8tArCQzWKR/FVSfp8ymwue/JwiIYwXhF6mBgh?= =?us-ascii?Q?pnqOx9Re/TxSL9bFi+UOHA7SMYReonrsWXqk+s4Cxx/bHChGtLkbUtRk5uUn?= =?us-ascii?Q?Sgk9jx0MNi7IfpAU6k7sKG6x/9N1HwyEbzUC+OFfLmKW/PjxvcOjBKIhB9ON?= =?us-ascii?Q?jb+kRB3vZlmDNxIm11nvH3RsaAq/8bSTUiBJ8BWItqfG4hu7tl41gFtYwKC+?= =?us-ascii?Q?9axcE4o1tU3XVdQ1aQOdr4ZZnFDpGaQDgFplibroG8ujKWUMT2wPSAdeTQhb?= =?us-ascii?Q?6YDzXFVd+acFb2OdC1kkUAu9UIMFJwBgduvuYf4PS4e5RK/F2Z6MWoJReEmC?= =?us-ascii?Q?wthSXbEfkdsE97l+Fh3fpk1zNA6ANh0JJOkPeDWff49LDsCsEbSwLu5CJ2AD?= =?us-ascii?Q?7SfXykf7pBCZcncSege1af61kAuPPwuC77isW5cjk/BiIZ17AX0S2/T8LTc8?= =?us-ascii?Q?Y/QX5FX0foirLuCOqORRiMVk6QYYsYgu87IM/SKo0uqqsOE/Nnre4XaQh32H?= =?us-ascii?Q?RYIXIMArL1QzHDEAd9OjSChDH+WSMQBlH35K3bl2fcXmtsc+eiHmPvrAg+zp?= =?us-ascii?Q?r0bVQl5E5oJERo5YgIOYicnlsrP7bTLIFmj5aFBn1r2T3aP1eceqJcwUkiy8?= =?us-ascii?Q?XvGgYXG8+7VDiRS3Nbk5+8wsENLilPirofWkmA4y+mZ8G3ARNqKo6h76jvGd?= =?us-ascii?Q?WxnxlA8ON+lA/Z3iAibDUDxQfcxv1mzQo4+5fleQjybToVLBKs2kYH/SSOK5?= =?us-ascii?Q?/lemNA6LErWQBhUBlgBcXBIN7uuayW0jy4+mnGXR0ebR8B9q3hYmcIDihOq6?= =?us-ascii?Q?Hfs+BjAiQxbvoVMOxPF4ROkang9QVw3ryIy3PYjr5lKlwR3h3WDoaurEJ2/H?= =?us-ascii?Q?mCXygi4YrJqUKA9TvbkoQ2QcBXULKj/Oe/tcXEu3SqcjmcTA6VITlBOksRu/?= =?us-ascii?Q?UR02IU7y6TglhQ8Dwxx5h1HODuVp2wPAXEemHmm3H14V8bX2wZSjRvgeW6yQ?= =?us-ascii?Q?dotSM+Z95mAwmT8BeT8abqQPbOqrcD1rkQpu1pH8Byh1clq/MoXSVRL42xLI?= =?us-ascii?Q?9ta7p9JviSH3dIc8CnzyOFMTmhIpOCEX6UHqm6Eyy0UaJdM7SuZXfKUnwa6O?= =?us-ascii?Q?1d9z2keN0/DR/6nRy6XnEvB3TxixeR0Y7o1tf7o3gP+b8NSoD55h5iwHTuFK?= =?us-ascii?Q?kzVjhxZjSpDx7dmyZhWaVaeQtv7PzCNktUN+IhEQUrZGMWog0d8rAvR3Dgdb?= =?us-ascii?Q?O0wl7tkQwowdI69KBAs=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB6486.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iWxKYecOKhZfae+2v2CPqZrzGpwk3OBSZSZzZ2PBHfxntOvF3YlWSuYubJvH?= =?us-ascii?Q?TFmNla0p2H95e1I5sqnhnIAHoM8dOMeTaWcLbBNGOKb6u9ZwacW0mmizAxuv?= =?us-ascii?Q?sxlxGDoBEup22dZ2Jpjs8gbfjy+upc/gcn0kfAXhlh6vhQLXeuH2CEFKUn7c?= =?us-ascii?Q?hN+Pqm6InqNXdHnYQsjX4gbMgiGpUoIGcBCTMNqi7JTBoXnwh6TrO7EUUDoy?= =?us-ascii?Q?gMdmZ3ztWAuL98F1TIDLXl0CggqMlyjgcw0sNFxLRNjotwZXLymO4/lsE8+P?= =?us-ascii?Q?22ouYpTKIVcBNdMRrqf151VMxR0wDYaifzk/ihka7UbF9P/B56uhVqHNSvjX?= =?us-ascii?Q?48H7i3d/NqeNYgZxdCU/YhSo1J72O390BNnG8L7HxQIYKlviOmLdAbp7heFc?= =?us-ascii?Q?gJ8GpX1Xx+dlJqWPtq3oZTr05I+pI4OKWV8ye/j0FZMokWCMAhj5ejvpbOS4?= =?us-ascii?Q?hwCsIM3CtWMETXyV2LezfSR0wfEg1O6Ev1mg6j1II5cO1ouh+3ucKpsdDKnZ?= =?us-ascii?Q?Xo3AKKtzCDWrbGOrJnas9zHu/KUIaZsSlyRVikyjPQaB+IxgVthtSXlUySoR?= =?us-ascii?Q?zeFzpupcRtXJw0TmNJwBoW/VOMTpGOkMWmVQl5+XsRi1JGL5KZ9pd3iU9Fym?= =?us-ascii?Q?ZneI5QyxoB/1+OuFtzKutiC4yFFHtGP/q8/y0u9xZdEaL+1hndkT/aC3r9VS?= =?us-ascii?Q?0dpIOdRE4XqLV43/35Dy+j5BDirVw0m+uD/za7KpEo/7vDKlFTrp1zsq4Mbc?= =?us-ascii?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ku2XqAN88rZ7TtyTYcE?= =?us-ascii?Q?iT88f6fDFD44Fy6EGbDXCA39nGdZmQ6xxntLn28cFqcFBDjORfQZLJ0ZkJdu?= =?us-ascii?Q?/Ib3sNma9w=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 669fb05f-e16f-4076-0425-08de68fca0d1 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB6486.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2026 23:32:17.3794 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RW610ZATMspjsBme3KJqxmzyg5Geaf0vfeyaLBSMlk3IOrYJhkvGqm9z7h3hhdhQAyZAlwjuwF9KuOuYGBTulw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8586 Content-Type: text/plain; charset="utf-8" Add safe Rust abstractions over the Linux kernel's GPU buddy allocator for physical memory management. The GPU buddy allocator implements a binary buddy system useful for GPU physical memory allocation. nova-core will use it for physical memory allocation. Signed-off-by: Joel Fernandes --- rust/bindings/bindings_helper.h | 11 + rust/helpers/gpu.c | 23 ++ rust/helpers/helpers.c | 1 + rust/kernel/gpu/buddy.rs | 537 ++++++++++++++++++++++++++++++++ rust/kernel/gpu/mod.rs | 5 + rust/kernel/lib.rs | 2 + 6 files changed, 579 insertions(+) create mode 100644 rust/helpers/gpu.c create mode 100644 rust/kernel/gpu/buddy.rs create mode 100644 rust/kernel/gpu/mod.rs diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index 083cc44aa952..dbb765a9fdbd 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -29,6 +29,7 @@ #include =20 #include +#include #include #include #include @@ -146,6 +147,16 @@ const vm_flags_t RUST_CONST_HELPER_VM_MIXEDMAP =3D VM_= MIXEDMAP; const vm_flags_t RUST_CONST_HELPER_VM_HUGEPAGE =3D VM_HUGEPAGE; const vm_flags_t RUST_CONST_HELPER_VM_NOHUGEPAGE =3D VM_NOHUGEPAGE; =20 +#if IS_ENABLED(CONFIG_GPU_BUDDY) +const unsigned long RUST_CONST_HELPER_GPU_BUDDY_RANGE_ALLOCATION =3D GPU_B= UDDY_RANGE_ALLOCATION; +const unsigned long RUST_CONST_HELPER_GPU_BUDDY_TOPDOWN_ALLOCATION =3D GPU= _BUDDY_TOPDOWN_ALLOCATION; +const unsigned long RUST_CONST_HELPER_GPU_BUDDY_CONTIGUOUS_ALLOCATION =3D + GPU_BUDDY_CONTIGUOUS_ALLOCATION; +const unsigned long RUST_CONST_HELPER_GPU_BUDDY_CLEAR_ALLOCATION =3D GPU_B= UDDY_CLEAR_ALLOCATION; +const unsigned long RUST_CONST_HELPER_GPU_BUDDY_CLEARED =3D GPU_BUDDY_CLEA= RED; +const unsigned long RUST_CONST_HELPER_GPU_BUDDY_TRIM_DISABLE =3D GPU_BUDDY= _TRIM_DISABLE; +#endif + #if IS_ENABLED(CONFIG_ANDROID_BINDER_IPC_RUST) #include "../../drivers/android/binder/rust_binder.h" #include "../../drivers/android/binder/rust_binder_events.h" diff --git a/rust/helpers/gpu.c b/rust/helpers/gpu.c new file mode 100644 index 000000000000..38b1a4e6bef8 --- /dev/null +++ b/rust/helpers/gpu.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#ifdef CONFIG_GPU_BUDDY + +__rust_helper u64 rust_helper_gpu_buddy_block_offset(const struct gpu_budd= y_block *block) +{ + return gpu_buddy_block_offset(block); +} + +__rust_helper unsigned int rust_helper_gpu_buddy_block_order(struct gpu_bu= ddy_block *block) +{ + return gpu_buddy_block_order(block); +} + +__rust_helper u64 rust_helper_gpu_buddy_block_size(struct gpu_buddy *mm, + struct gpu_buddy_block *block) +{ + return gpu_buddy_block_size(mm, block); +} + +#endif /* CONFIG_GPU_BUDDY */ diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index 724fcb8240ac..a53929ce52a3 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -32,6 +32,7 @@ #include "err.c" #include "irq.c" #include "fs.c" +#include "gpu.c" #include "io.c" #include "jump_label.c" #include "kunit.c" diff --git a/rust/kernel/gpu/buddy.rs b/rust/kernel/gpu/buddy.rs new file mode 100644 index 000000000000..102414eba65a --- /dev/null +++ b/rust/kernel/gpu/buddy.rs @@ -0,0 +1,537 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! GPU buddy allocator bindings. +//! +//! C header: [`include/linux/gpu_buddy.h`](srctree/include/linux/gpu_budd= y.h) +//! +//! This module provides Rust abstractions over the Linux kernel's GPU bud= dy +//! allocator, which implements a binary buddy memory allocator. +//! +//! The buddy allocator manages a contiguous address space and allocates b= locks +//! in power-of-two sizes, useful for GPU physical memory management. +//! +//! # Examples +//! +//! ``` +//! use kernel::{ +//! gpu::buddy::{BuddyFlags, GpuBuddy, GpuBuddyAllocParams, GpuBuddyPa= rams}, +//! prelude::*, +//! sizes::*, // +//! }; +//! +//! // Create a 1GB buddy allocator with 4KB minimum chunk size. +//! let buddy =3D GpuBuddy::new(GpuBuddyParams { +//! base_offset_bytes: 0, +//! physical_memory_size_bytes: SZ_1G as u64, +//! chunk_size_bytes: SZ_4K as u64, +//! })?; +//! +//! // Verify initial state. +//! assert_eq!(buddy.size(), SZ_1G as u64); +//! assert_eq!(buddy.chunk_size(), SZ_4K as u64); +//! let initial_free =3D buddy.free_memory_bytes(); +//! +//! // Base allocation params - mutated between calls for field overrides. +//! let mut params =3D GpuBuddyAllocParams { +//! start_range_address: 0, +//! end_range_address: 0, // Entire range. +//! size_bytes: SZ_16M as u64, +//! min_block_size_bytes: SZ_16M as u64, +//! buddy_flags: BuddyFlags::try_new(BuddyFlags::RANGE_ALLOCATION)?, +//! }; +//! +//! // Test top-down allocation (allocates from highest addresses). +//! params.buddy_flags =3D BuddyFlags::try_new(BuddyFlags::TOPDOWN_ALLOCAT= ION)?; +//! let topdown =3D KBox::pin_init(buddy.alloc_blocks(¶ms), GFP_KERNEL= )?; +//! assert_eq!(buddy.free_memory_bytes(), initial_free - SZ_16M as u64); +//! +//! for block in topdown.iter() { +//! assert_eq!(block.offset(), (SZ_1G - SZ_16M) as u64); +//! assert_eq!(block.order(), 12); // 2^12 pages +//! assert_eq!(block.size(), SZ_16M as u64); +//! } +//! drop(topdown); +//! assert_eq!(buddy.free_memory_bytes(), initial_free); +//! +//! // Allocate 16MB - should result in a single 16MB block at offset 0. +//! params.buddy_flags =3D BuddyFlags::try_new(BuddyFlags::RANGE_ALLOCATIO= N)?; +//! let allocated =3D KBox::pin_init(buddy.alloc_blocks(¶ms), GFP_KERN= EL)?; +//! assert_eq!(buddy.free_memory_bytes(), initial_free - SZ_16M as u64); +//! +//! for block in allocated.iter() { +//! assert_eq!(block.offset(), 0); +//! assert_eq!(block.order(), 12); // 2^12 pages +//! assert_eq!(block.size(), SZ_16M as u64); +//! } +//! drop(allocated); +//! assert_eq!(buddy.free_memory_bytes(), initial_free); +//! +//! // Test non-contiguous allocation with fragmented memory. +//! // Create fragmentation by allocating 4MB blocks at [0,4M) and [8M,12M= ). +//! params.end_range_address =3D SZ_4M as u64; +//! params.size_bytes =3D SZ_4M as u64; +//! params.min_block_size_bytes =3D SZ_4M as u64; +//! let frag1 =3D KBox::pin_init(buddy.alloc_blocks(¶ms), GFP_KERNEL)?; +//! assert_eq!(buddy.free_memory_bytes(), initial_free - SZ_4M as u64); +//! +//! params.start_range_address =3D SZ_8M as u64; +//! params.end_range_address =3D (SZ_8M + SZ_4M) as u64; +//! let frag2 =3D KBox::pin_init(buddy.alloc_blocks(¶ms), GFP_KERNEL)?; +//! assert_eq!(buddy.free_memory_bytes(), initial_free - SZ_8M as u64); +//! +//! // Allocate 8MB without CONTIGUOUS - should return 2 blocks from the h= oles. +//! params.start_range_address =3D 0; +//! params.end_range_address =3D SZ_16M as u64; +//! params.size_bytes =3D SZ_8M as u64; +//! let fragmented =3D KBox::pin_init(buddy.alloc_blocks(¶ms), GFP_KER= NEL)?; +//! assert_eq!(buddy.free_memory_bytes(), initial_free - (SZ_16M) as u64); +//! +//! let (mut count, mut total) =3D (0u32, 0u64); +//! for block in fragmented.iter() { +//! // The 8MB allocation should return 2 blocks, each 4MB. +//! assert_eq!(block.size(), SZ_4M as u64); +//! total +=3D block.size(); +//! count +=3D 1; +//! } +//! assert_eq!(total, SZ_8M as u64); +//! assert_eq!(count, 2); +//! drop(fragmented); +//! drop(frag2); +//! drop(frag1); +//! assert_eq!(buddy.free_memory_bytes(), initial_free); +//! +//! // Test CONTIGUOUS failure when only fragmented space available. +//! // Create a small buddy allocator with only 16MB of memory. +//! let small =3D GpuBuddy::new(GpuBuddyParams { +//! base_offset_bytes: 0, +//! physical_memory_size_bytes: SZ_16M as u64, +//! chunk_size_bytes: SZ_4K as u64, +//! })?; +//! +//! // Allocate 4MB blocks at [0,4M) and [8M,12M) to create fragmented mem= ory. +//! params.start_range_address =3D 0; +//! params.end_range_address =3D SZ_4M as u64; +//! params.size_bytes =3D SZ_4M as u64; +//! let hole1 =3D KBox::pin_init(small.alloc_blocks(¶ms), GFP_KERNEL)?; +//! +//! params.start_range_address =3D SZ_8M as u64; +//! params.end_range_address =3D (SZ_8M + SZ_4M) as u64; +//! let hole2 =3D KBox::pin_init(small.alloc_blocks(¶ms), GFP_KERNEL)?; +//! +//! // 8MB contiguous should fail - only two non-contiguous 4MB holes exis= t. +//! params.start_range_address =3D 0; +//! params.end_range_address =3D 0; +//! params.size_bytes =3D SZ_8M as u64; +//! params.buddy_flags =3D BuddyFlags::try_new(BuddyFlags::CONTIGUOUS_ALLO= CATION)?; +//! let result =3D KBox::pin_init(small.alloc_blocks(¶ms), GFP_KERNEL); +//! assert!(result.is_err()); +//! drop(hole2); +//! drop(hole1); +//! +//! # Ok::<(), Error>(()) +//! ``` + +use crate::{ + bindings, + clist::CListHead, + clist_create, + error::to_result, + new_mutex, + prelude::*, + sync::{ + lock::mutex::MutexGuard, + Arc, + Mutex, // + }, + types::Opaque, +}; + +/// Flags for GPU buddy allocator operations. +/// +/// These flags control the allocation behavior of the buddy allocator. +#[derive(Clone, Copy, Default, PartialEq, Eq)] +pub struct BuddyFlags(usize); + +impl BuddyFlags { + /// Range-based allocation from start to end addresses. + pub const RANGE_ALLOCATION: usize =3D bindings::GPU_BUDDY_RANGE_ALLOCA= TION; + + /// Allocate from top of address space downward. + pub const TOPDOWN_ALLOCATION: usize =3D bindings::GPU_BUDDY_TOPDOWN_AL= LOCATION; + + /// Allocate physically contiguous blocks. + pub const CONTIGUOUS_ALLOCATION: usize =3D bindings::GPU_BUDDY_CONTIGU= OUS_ALLOCATION; + + /// Request allocation from the cleared (zeroed) memory. The zero'ing = is not + /// done by the allocator, but by the caller before freeing old blocks. + pub const CLEAR_ALLOCATION: usize =3D bindings::GPU_BUDDY_CLEAR_ALLOCA= TION; + + /// Disable trimming of partially used blocks. + pub const TRIM_DISABLE: usize =3D bindings::GPU_BUDDY_TRIM_DISABLE; + + /// Mark blocks as cleared (zeroed) when freeing. When set during free, + /// indicates that the caller has already zeroed the memory. + pub const CLEARED: usize =3D bindings::GPU_BUDDY_CLEARED; + + /// Create [`BuddyFlags`] from a raw value with validation. + /// + /// Use `|` operator to combine flags if needed, before calling this m= ethod. + pub fn try_new(flags: usize) -> Result { + // Flags must not exceed u32::MAX to satisfy the GPU buddy allocat= or C API. + if flags > u32::MAX as usize { + return Err(EINVAL); + } + + // `TOPDOWN_ALLOCATION` only works without `RANGE_ALLOCATION`. Whe= n both are + // set, `TOPDOWN_ALLOCATION` is silently ignored by the allocator.= Reject this. + if (flags & Self::RANGE_ALLOCATION) !=3D 0 && (flags & Self::TOPDO= WN_ALLOCATION) !=3D 0 { + return Err(EINVAL); + } + + Ok(Self(flags)) + } + + /// Get raw value of the flags. + pub(crate) fn as_raw(self) -> usize { + self.0 + } +} + +/// Parameters for creating a GPU buddy allocator. +pub struct GpuBuddyParams { + /// Base offset in bytes where the managed memory region starts. + /// Allocations will be offset by this value. + pub base_offset_bytes: u64, + /// Total physical memory size managed by the allocator in bytes. + pub physical_memory_size_bytes: u64, + /// Minimum allocation unit / chunk size in bytes, must be >=3D 4KB. + pub chunk_size_bytes: u64, +} + +/// Parameters for allocating blocks from a GPU buddy allocator. +pub struct GpuBuddyAllocParams { + /// Start of allocation range in bytes. Use 0 for beginning. + pub start_range_address: u64, + /// End of allocation range in bytes. Use 0 for entire range. + pub end_range_address: u64, + /// Total size to allocate in bytes. + pub size_bytes: u64, + /// Minimum block size for fragmented allocations in bytes. + pub min_block_size_bytes: u64, + /// Buddy allocator behavior flags. + pub buddy_flags: BuddyFlags, +} + +/// Inner structure holding the actual buddy allocator. +/// +/// # Synchronization +/// +/// The C `gpu_buddy` API requires synchronization (see `include/linux/gpu= _buddy.h`). +/// The internal [`GpuBuddyGuard`] ensures that the lock is held for all +/// allocator and free operations, preventing races between concurrent all= ocations +/// and the freeing that occurs when [`AllocatedBlocks`] is dropped. +/// +/// # Invariants +/// +/// The inner [`Opaque`] contains a valid, initialized buddy allocator. +#[pin_data(PinnedDrop)] +struct GpuBuddyInner { + #[pin] + inner: Opaque, + // TODO: Replace `Mutex<()>` with `Mutex>` once `Mutex::new= ()` + // accepts `impl PinInit`. + #[pin] + lock: Mutex<()>, + /// Base offset for all allocations (does not change after init). + base_offset: u64, + /// Cached chunk size (does not change after init). + chunk_size: u64, + /// Cached total size (does not change after init). + size: u64, +} + +impl GpuBuddyInner { + /// Create a pin-initializer for the buddy allocator. + fn new(params: GpuBuddyParams) -> impl PinInit { + let base_offset =3D params.base_offset_bytes; + let size =3D params.physical_memory_size_bytes; + let chunk_size =3D params.chunk_size_bytes; + + try_pin_init!(Self { + inner <- Opaque::try_ffi_init(|ptr| { + // SAFETY: ptr points to valid uninitialized memory from t= he pin-init + // infrastructure. gpu_buddy_init will initialize the stru= cture. + to_result(unsafe { bindings::gpu_buddy_init(ptr, size, chu= nk_size) }) + }), + lock <- new_mutex!(()), + base_offset: base_offset, + chunk_size: chunk_size, + size: size, + }) + } + + /// Lock the mutex and return a guard for accessing the allocator. + fn lock(&self) -> GpuBuddyGuard<'_> { + GpuBuddyGuard { + inner: self, + _guard: self.lock.lock(), + } + } +} + +#[pinned_drop] +impl PinnedDrop for GpuBuddyInner { + fn drop(self: Pin<&mut Self>) { + let guard =3D self.lock(); + + // SAFETY: guard provides exclusive access to the allocator. + unsafe { + bindings::gpu_buddy_fini(guard.as_raw()); + } + } +} + +// SAFETY: [`GpuBuddyInner`] can be sent between threads. +unsafe impl Send for GpuBuddyInner {} + +// SAFETY: [`GpuBuddyInner`] is `Sync` because the internal [`GpuBuddyGuar= d`] +// serializes all access to the C allocator, preventing data races. +unsafe impl Sync for GpuBuddyInner {} + +/// Guard that proves the lock is held, enabling access to the allocator. +/// +/// # Invariants +/// +/// The inner `_guard` holds the lock for the duration of this guard's lif= etime. +pub(crate) struct GpuBuddyGuard<'a> { + inner: &'a GpuBuddyInner, + _guard: MutexGuard<'a, ()>, +} + +impl GpuBuddyGuard<'_> { + /// Get a raw pointer to the underlying C `gpu_buddy` structure. + fn as_raw(&self) -> *mut bindings::gpu_buddy { + self.inner.inner.get() + } +} + +/// GPU buddy allocator instance. +/// +/// This structure wraps the C `gpu_buddy` allocator using reference count= ing. +/// The allocator is automatically cleaned up when all references are drop= ped. +/// +/// # Invariants +/// +/// The inner [`Arc`] points to a valid, initialized GPU buddy allocator. +pub struct GpuBuddy(Arc); + +impl GpuBuddy { + /// Create a new buddy allocator. + /// + /// Creates a buddy allocator that manages a contiguous address space = of the given + /// size, with the specified minimum allocation unit (chunk_size must = be at least 4KB). + pub fn new(params: GpuBuddyParams) -> Result { + Ok(Self(Arc::pin_init( + GpuBuddyInner::new(params), + GFP_KERNEL, + )?)) + } + + /// Get the base offset for allocations. + pub fn base_offset(&self) -> u64 { + self.0.base_offset + } + + /// Get the chunk size (minimum allocation unit). + pub fn chunk_size(&self) -> u64 { + self.0.chunk_size + } + + /// Get the total managed size. + pub fn size(&self) -> u64 { + self.0.size + } + + /// Get the available (free) memory in bytes. + pub fn free_memory_bytes(&self) -> u64 { + let guard =3D self.0.lock(); + // SAFETY: guard provides exclusive access to the allocator. + unsafe { (*guard.as_raw()).avail } + } + + /// Allocate blocks from the buddy allocator. + /// + /// Returns a pin-initializer for [`AllocatedBlocks`]. + /// + /// Takes `&self` instead of `&mut self` because the internal [`Mutex`= ] provides + /// synchronization - no external `&mut` exclusivity needed. + pub fn alloc_blocks( + &self, + params: &GpuBuddyAllocParams, + ) -> impl PinInit { + let buddy_arc =3D Arc::clone(&self.0); + let start =3D params.start_range_address; + let end =3D params.end_range_address; + let size =3D params.size_bytes; + let min_block_size =3D params.min_block_size_bytes; + let flags =3D params.buddy_flags; + + // Create pin-initializer that initializes list and allocates bloc= ks. + try_pin_init!(AllocatedBlocks { + buddy: buddy_arc, + list <- CListHead::new(), + flags: flags, + _: { + // Lock while allocating to serialize with concurrent free= s. + let guard =3D buddy.lock(); + + // SAFETY: `guard` provides exclusive access to the buddy = allocator. + to_result(unsafe { + bindings::gpu_buddy_alloc_blocks( + guard.as_raw(), + start, + end, + size, + min_block_size, + list.as_raw(), + flags.as_raw(), + ) + })? + } + }) + } +} + +/// Allocated blocks from the buddy allocator with automatic cleanup. +/// +/// This structure owns a list of allocated blocks and ensures they are +/// automatically freed when dropped. Use `iter()` to iterate over all +/// allocated [`Block`] structures. +/// +/// # Invariants +/// +/// - `list` is an initialized, valid list head containing allocated block= s. +/// - `buddy` references a valid [`GpuBuddyInner`]. +#[pin_data(PinnedDrop)] +pub struct AllocatedBlocks { + #[pin] + list: CListHead, + buddy: Arc, + flags: BuddyFlags, +} + +impl AllocatedBlocks { + /// Check if the block list is empty. + pub fn is_empty(&self) -> bool { + // An empty list head points to itself. + !self.list.is_linked() + } + + /// Iterate over allocated blocks. + /// + /// Returns an iterator yielding [`AllocatedBlock`] references. The bl= ocks + /// are only valid for the duration of the borrow of `self`. + pub fn iter(&self) -> impl Iterator> + '_ { + // SAFETY: list contains gpu_buddy_block items linked via __bindge= n_anon_1.link. + let clist =3D unsafe { + clist_create!( + self.list.as_raw(), + Block, + bindings::gpu_buddy_block, + __bindgen_anon_1.link + ) + }; + + clist + .iter() + .map(|block| AllocatedBlock { block, alloc: self }) + } +} + +#[pinned_drop] +impl PinnedDrop for AllocatedBlocks { + fn drop(self: Pin<&mut Self>) { + let guard =3D self.buddy.lock(); + + // SAFETY: + // - list is valid per the type's invariants. + // - guard provides exclusive access to the allocator. + // CAST: BuddyFlags were validated to fit in u32 at construction. + unsafe { + bindings::gpu_buddy_free_list( + guard.as_raw(), + self.list.as_raw(), + self.flags.as_raw() as u32, + ); + } + } +} + +/// A GPU buddy block. +/// +/// Transparent wrapper over C `gpu_buddy_block` structure. This type is r= eturned +/// as references from [`CListIter`] during iteration over [`AllocatedBloc= ks`]. +/// +/// # Invariants +/// +/// The inner [`Opaque`] contains a valid, allocated `gpu_buddy_block`. +#[repr(transparent)] +pub struct Block(Opaque); + +impl Block { + /// Get a raw pointer to the underlying C block. + fn as_raw(&self) -> *mut bindings::gpu_buddy_block { + self.0.get() + } + + /// Get the block's offset in the address space. + pub(crate) fn offset(&self) -> u64 { + // SAFETY: self.as_raw() is valid per the type's invariants. + unsafe { bindings::gpu_buddy_block_offset(self.as_raw()) } + } + + /// Get the block order. + pub(crate) fn order(&self) -> u32 { + // SAFETY: self.as_raw() is valid per the type's invariants. + unsafe { bindings::gpu_buddy_block_order(self.as_raw()) } + } +} + +// SAFETY: `Block` is a transparent wrapper over `gpu_buddy_block` which i= s not +// modified after allocation. It can be safely sent between threads. +unsafe impl Send for Block {} + +// SAFETY: `Block` is a transparent wrapper over `gpu_buddy_block` which i= s not +// modified after allocation. It can be safely shared among threads. +unsafe impl Sync for Block {} + +/// An allocated block with access to the allocation list. +/// +/// # Invariants +/// +/// - `block` is a valid reference to an allocated [`Block`]. +/// - `alloc` is a valid reference to the [`AllocatedBlocks`] that owns th= is block. +pub struct AllocatedBlock<'a> { + block: &'a Block, + alloc: &'a AllocatedBlocks, +} + +impl AllocatedBlock<'_> { + /// Get the block's offset in the address space. + /// + /// Returns the absolute offset including the allocator's base offset. + /// This is the actual address to use for accessing the allocated memo= ry. + pub fn offset(&self) -> u64 { + self.alloc.buddy.base_offset + self.block.offset() + } + + /// Get the block order (size =3D chunk_size << order). + pub fn order(&self) -> u32 { + self.block.order() + } + + /// Get the block's size in bytes. + pub fn size(&self) -> u64 { + self.alloc.buddy.chunk_size << self.block.order() + } +} diff --git a/rust/kernel/gpu/mod.rs b/rust/kernel/gpu/mod.rs new file mode 100644 index 000000000000..8f25e6367edc --- /dev/null +++ b/rust/kernel/gpu/mod.rs @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! GPU subsystem abstractions. + +pub mod buddy; diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index fe711d34ca1e..02ec5b9b22c8 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -98,6 +98,8 @@ pub mod firmware; pub mod fmt; pub mod fs; +#[cfg(CONFIG_GPU_BUDDY)] +pub mod gpu; #[cfg(CONFIG_I2C =3D "y")] pub mod i2c; pub mod id_pool; --=20 2.34.1 From nobody Thu Apr 2 10:57:38 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010058.outbound.protection.outlook.com [52.101.61.58]) (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 AB1833164DF; Tue, 10 Feb 2026 23:32:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770766358; cv=fail; b=TcgrJVKFDEjBKeVADNrdhnaTb4GE1M1A9FWuh+zT9M+n8+okfqBGC/jys97c98uzT17AsXaLY0KJCJewXW51HLAXc879XzrCEVBRaP78O3UI8Z25W8x1YkpzkGLXR/s1dqtys4MkOQ8FsLOZhAlqhKOWZ7vZIMIY3TGRiObeY/A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770766358; c=relaxed/simple; bh=4aKOKjfeNtHhRhQ2mxO2dCFqgjVBSRvJ0DgFnVmhOIE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=LLOE2MoSyJe7egQb3DZbyq3RLJ/7SzLGSRM5Bx7xgxvtne2gqaHrc784VpsqpnwBIM9F9YPCzBlAjcBJwQpWaLJ4XVKT9ZolhEZFgtOCzd9PtD8hgOS0A25qFm+FezgXF5y6Tf4G9nwiSU+2He97PCJjz+TtR746t2epK5cR8h8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=pEHQUYiq; arc=fail smtp.client-ip=52.101.61.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="pEHQUYiq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=U8KC1hIZ7ISWMqDhEeYciUhPzrK07xM9rq5WmQ619RyS3wQ4V0ZaiB09wG09ycCuBwVEqYXFX/Y2Kllm0PBZddJI29mSOYEClhtxh25HsS62QDtvMnCUV2uQCDxe+8ymKooPm/AaxV/kMjrXM7vRx2GFjxeO05jnLdeN1rCrNizn6S+zGvNhVzFQZFMfb9pPI0lTbVY7pknmDSFpQ3CcCJQFTfifCWDOnKiKPJCPNviIg++2pA29ZUnQvpjQtOm+oURNzbQUlVPQ7GFsiSfoD53wy7FYF2LMZKkgUqTZtQ0vPDXg83DhKSDXgzfg8YdYhd+QJ1rVQhIdmDo486dWpQ== 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=tNsiECXK2jxOwC0wWhs3b0oXxNKQAoQ5yH3CrYiCEd0=; b=WzvOoeUnHvZZqaypz95LgUqQT+K4iSBzZ6DDCyrOtTupjomPS0PVgmOxT4QUuhce83bYP90JU2rxN4wTwl83Gof89KHuw6DguTIqM2bUopCFGq60vvuZeHT/5+RIv1lc/ZHc/+mHkVBXJ3JbI68OVsS/g0/fnw2E2bLnAptrjFnZAeHNkaoWksk7iQW8fcKmEB+0k4o2VlFFKypoWPXWOVVBdTS0Exi6CAU5+2gpTm1BXDQeVvrAWwOIIgRRLMe1QoWm4CGj7vy1PqTp06O9ZD/BhOQh8m82ki2M5ap+cLKf1uOnlOVQqTq36TpylcRISZhLH3DrsrcJhyfyaHE/cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tNsiECXK2jxOwC0wWhs3b0oXxNKQAoQ5yH3CrYiCEd0=; b=pEHQUYiq3jLfshxs0LEfb50N7Szg/ypw3ydilcOSarmVZK625HjyTYgCLv3JtcNkoZ0Bt3+y4LhRKEXpzhw5NBp7w9Jj2Ms/RsA7V0S6pmfmNxQVIvHzhUxoPPEskxQRpEDb1eWDhv6wmVLYkzrVBtUbTZrVFIlejZaJX3Q2VPu091n01cMHjduqQUkjzLMsU0GxOVP08i6Iy7t3ytmseB0CJiV2Rd8ox0yt81/NehKw9kGd/oYA9JY1Kj5UChNj9TfaWt8MRPyORCDyiuOGPjiX0p8VPPMJ6JM1a8bx0bl8u8QA7bWY+KPhocdyaGzZfaHT8FyOTKEzMfZtCWN7gA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB6486.namprd12.prod.outlook.com (2603:10b6:8:c5::21) by IA1PR12MB8586.namprd12.prod.outlook.com (2603:10b6:208:44e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.10; Tue, 10 Feb 2026 23:32:19 +0000 Received: from DS0PR12MB6486.namprd12.prod.outlook.com ([fe80::88a9:f314:c95f:8b33]) by DS0PR12MB6486.namprd12.prod.outlook.com ([fe80::88a9:f314:c95f:8b33%4]) with mapi id 15.20.9587.017; Tue, 10 Feb 2026 23:32:19 +0000 From: Joel Fernandes To: linux-kernel@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Simona Vetter , Jonathan Corbet , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Huang Rui , Matthew Auld , Matthew Brost , Lucas De Marchi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Helge Deller , Danilo Krummrich , Alice Ryhl , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Alistair Popple , Alexandre Courbot , Andrea Righi , Zhi Wang , Philipp Stanner , Elle Rhumsaa , Daniel Almeida , David Airlie , Edwin Peer , John Hubbard , Andy Ritger , Balbir Singh , Timur Tabi , joel@joelfernandes.org, nouveau@lists.freedesktop.org, 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, Joel Fernandes Subject: [PATCH -next v9 3/3] nova-core: mm: Select GPU_BUDDY for VRAM allocation Date: Tue, 10 Feb 2026 18:32:04 -0500 Message-Id: <20260210233204.790524-4-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260210233204.790524-1-joelagnelf@nvidia.com> References: <20260210233204.790524-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CY8P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:930:6b::12) To DS0PR12MB6486.namprd12.prod.outlook.com (2603:10b6:8:c5::21) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB6486:EE_|IA1PR12MB8586:EE_ X-MS-Office365-Filtering-Correlation-Id: 29016d9a-e37f-4999-03a6-08de68fca1dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?KRHF2XDEHVdd+RxAiRhe73a61HyeUH5uVwD41U8TBVhsqsELvoQd58kXW4EI?= =?us-ascii?Q?I57JkNbOturs0fYJB1hFEg+e0Qn2DTXwzH3MJj1bd93dgcIFgC1I9jgr8c4A?= =?us-ascii?Q?mk4HiY6WLt23i06VZoWChspXMC0tfI85mNqYTpgA+zkafKwEanrdmPzbpxSl?= =?us-ascii?Q?Da80e9+JYkCZQhw8NeltnmkvIci+2fwDg5+Dm79nl0MrW6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4F+mO9gIg2os4ETDWaNBiviL1cR97bSk/ZCs/L?= =?us-ascii?Q?s7fUThsbRcoBR+QglfAiPlkSqN/OWcxbHExObCp8qIW9tg/fz3wIFh9R+mv5?= =?us-ascii?Q?NdhV8oOJw07ihQ9YCtIMH8o9AF01nOwOtscgDMpCotMPbhWsrJ3daz1fgHMb?= =?us-ascii?Q?dyNMUV2QbteK4vkv0Xk17QgUUz9UivjsZFo7pRhs+TAezNNmvNLCwEh1l/xZ?= =?us-ascii?Q?v4n0chA3cq8seeEiwwBp7qCdduE3dWJQc72dk7UQ/z0pJiKY0cqTGRg6Ik9X?= =?us-ascii?Q?6Kt+Io2GvpPBxdjyspLUjmLS0/BSfjG2zMOOkWQPaVYNDvGqO/AQcd2MmXqK?= =?us-ascii?Q?FMwavncTYUNsASL1NMq7fB/wWZGK1t1t1sePr7AaUY5Y8ZsQJiW3Il/TS6O1?= =?us-ascii?Q?HGEfNjVgpynxsRPzgFFSOIJfMQhLVBMorTyCvhA0wscKE1/rDWorgWAhNXP9?= =?us-ascii?Q?BVA1iksHEzQ/0G5nYPM=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB6486.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wMLZd7eLowTkOiqzPso2yRzG1sTIglFFIp+ZNi7wCEackObAZF99f5zsnlI6?= =?us-ascii?Q?X3zKbgq+07n/kKYuMPywUq6+ceHxPtjNTogWRcE8loYNM4L5L4xBTYwCUOEb?= =?us-ascii?Q?kW004gSQx2DXiPwHyv0z4KIrIazSK7gloUG2R22vLQI2cQ4bT5zIIKBtjF+D?= =?us-ascii?Q?PN8aYQN6vTORJA+cgFBQwV9/WsCvW5aH61G9K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7wCcQvtgo9ByPiZNohg9zVjds1x1WelP6uklv4WByy53lDi6M6uyfkP41?= =?us-ascii?Q?KMr7ywlW9ldPO7VduO1Wam/tspFbDDyVeMIZWGFUAW3Rdy3hhqlRgMZ85J5u?= =?us-ascii?Q?N9MOwBCnsjxGJBsBQagEZOk+QHZwQ+Q7iyppyJs/b+qXKTcx6BsmDyWPFYQ8?= =?us-ascii?Q?AEn1+QZcuv9fOwOhlwJ39irt1c8cT0kI7sraqgtiMxmmGaBDwcmNM1Lc9Vaq?= =?us-ascii?Q?+G+YLhrTY97MOyZuiRc0Q1nop7U/J2rSbZhggI0UmhOlUN9lixWxo64XYIOE?= =?us-ascii?Q?1YwLrLXV7RlAZ3+MZ6S4exLvJNLSawvhiXmS4amkxGSLA07Z3FN4OGTWWQmy?= =?us-ascii?Q?m6wFQQ0LxaWQzK4jlMz0kS8nPTObz/5LeXangsQAFeXnfnO3+nomgkaEEbFh?= =?us-ascii?Q?0kOf2s9ZShQIgb82b96KzyvWmDLHzMqnvkKC7wOnjBDz1kVfLxmstew7hsf+?= =?us-ascii?Q?CuzBxcKoTXIg3yiog9muBwMeKrZ7XOK9fdeAuFtNiPL0Cr75kV6JrjoEM7xX?= =?us-ascii?Q?klDGch71Z2unoIk9tY7Ft27Q0kfz0mbcJodguXEZZkQ0XXSH2DS3Tqnjj/Py?= =?us-ascii?Q?au4W23iVQ/aErOBjsxoKavRvCCTsB1KV+RC/RFdwXFGFDsXSoJJOHwx5Qrm3?= =?us-ascii?Q?VnW02PU/AQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29016d9a-e37f-4999-03a6-08de68fca1dd X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB6486.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2026 23:32:19.1679 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RY7lXTMFDdvpSu3B4fn2ODs3byHCcoismnMBv8v4B4ZTu8posj0Ja1MWz9myscUp7YwSv4XB7bE5d2eplzEo/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8586 Content-Type: text/plain; charset="utf-8" nova-core will use the GPU buddy allocator for physical VRAM management. Enable it in Kconfig. Signed-off-by: Joel Fernandes --- drivers/gpu/nova-core/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nova-core/Kconfig b/drivers/gpu/nova-core/Kconfig index 527920f9c4d3..6513007bf66f 100644 --- a/drivers/gpu/nova-core/Kconfig +++ b/drivers/gpu/nova-core/Kconfig @@ -3,8 +3,9 @@ config NOVA_CORE depends on 64BIT depends on PCI depends on RUST - select RUST_FW_LOADER_ABSTRACTIONS select AUXILIARY_BUS + select GPU_BUDDY + select RUST_FW_LOADER_ABSTRACTIONS default n help Choose this if you want to build the Nova Core driver for Nvidia --=20 2.34.1