From nobody Tue Jun 16 06:26:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 394672571DA; Fri, 17 Apr 2026 01:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; cv=none; b=f121amyTMfkv3k3XOY41lyFXILcPORR/Wl8iKG4Od7D3PrpS3NyfLQe+O9PfUeSQL/ErfGU6fJ+VKYYB5egwRfXG1z7LxFsRxtqhPzgJdF8mkH2Dp4cj+2gxq1HNiQTpJfvos+I7JnYuzKerCVnaSKrRdxTjVfNh/9dHBnowf5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; c=relaxed/simple; bh=hv4TGP+tCPibLRF/F0RTc2CpoNa3r8c8YYHZgnw/d40=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UuJBuuRHh4WBNYNJxvpTpFn7O0E68T4EtF+/TcxpOmgtj7TNm2nNOeLWQwGvIePZ0SC5ilsIUf+IooEMm+zUNBuwWJnlpRW2JgPf1eaMmKhwiVYbyOsTYjPgVWv/j1xng1tkNJH+SnjVLtq40HxiuJ7Bt8VBGsnXz4qK5j76QmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=i8AMfNng; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="i8AMfNng" Received: by smtp.kernel.org (Postfix) with ESMTPS id DCF45C2BCC9; Fri, 17 Apr 2026 01:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1776388291; bh=hv4TGP+tCPibLRF/F0RTc2CpoNa3r8c8YYHZgnw/d40=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=i8AMfNngDCDZb91lDsQvXzYUhSWj58fXjzfjM1iZtDmJP+h/w321m3HW883F2d5hi o2XeDVryOXExKc8DjjVN/7e4J7vQCaCJY75TDslFIH1dO8q4EWU5PA8lwxqZ0wj7js JEtHhegt7YplY0sWBY8VQLvQF6DmyJj4K2L7MKos= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2EBFF8E49B; Fri, 17 Apr 2026 01:11:30 +0000 (UTC) From: Alvin Sun Date: Fri, 17 Apr 2026 09:05:51 +0800 Subject: [PATCH 1/4] rust: sizes: add SZ_4G constant Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-tyr-ioctls-deps-v1-1-41c6e9bb061c@linux.dev> References: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> In-Reply-To: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Lorenzo Stoakes , "Liam R. Howlett" , Tamir Duberstein Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?utf-8?q?Onur_=C3=96zkan?= , Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1776388289; l=622; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=hv4TGP+tCPibLRF/F0RTc2CpoNa3r8c8YYHZgnw/d40=; b=S+iNkF483U9WR+fhQWZU8CgLNpKK5tzKrdQpDfJeKwwAKFnq1eIQG1QE2Vbudm17yD5D1Q1Ah LRbBsIrxCZ2AxirhO4muyub2XCtogmNE3/Jmde3gYKeYH9JshdNEVqm X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Add SZ_4G constant defined as SZ_2G * 2. This constant will be used by the Tyr driver for calculating user and kernel VA layout. Signed-off-by: Alvin Sun --- rust/kernel/sizes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/kernel/sizes.rs b/rust/kernel/sizes.rs index 661e680d93306..872f5bb181ecf 100644 --- a/rust/kernel/sizes.rs +++ b/rust/kernel/sizes.rs @@ -48,3 +48,5 @@ pub const SZ_1G: usize =3D bindings::SZ_1G as usize; /// 0x80000000 pub const SZ_2G: usize =3D bindings::SZ_2G as usize; +/// 0x100000000 +pub const SZ_4G: usize =3D SZ_2G * 2; --=20 2.43.0 From nobody Tue Jun 16 06:26:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 393FA2571C7; Fri, 17 Apr 2026 01:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; cv=none; b=qtUFVRz7UmqFNWrkLrAKuh97lEfu3w405ZtHDxggVmWTvTYhLM4jf489nS/xFHgwJcA4SVaqzU2WwNGsiJsycRCGE9+QMdej8oB5ljbX2XZOVh+RUFUc5YaAdZRxtf5JYf1wKmyZsp5WLBkAp+RU5j53ALhru7uKjf3jn8PpKRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; c=relaxed/simple; bh=CEPawZ6sXIb2An8dSVvX8IrZi7UWboan6QZmQB4W5f4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XJiWT08k+2RGfuwIm5sASVe4JjBDWb1lCgLKnagdmjyf6hcWtbA9QZKYA6WEjBoiEHce50UkoR27C0stDg9JqjRsI9c0RTZRw5awU1xVZ4FUqenYP3wV+CxqxA+2WYxxaq5rMmRDc1NaESaZxwLPrw3+O6WSUnKgaQ4mXw/mugw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=auTQRiek; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="auTQRiek" Received: by smtp.kernel.org (Postfix) with ESMTPS id EF902C2BCB8; Fri, 17 Apr 2026 01:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1776388291; bh=CEPawZ6sXIb2An8dSVvX8IrZi7UWboan6QZmQB4W5f4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=auTQRiekRCbbnhehqgsarbiyZ9+MIl9n4mrx4RAyZfmikqaGndZyfXvBi/zIlG10q eZtHFv8M0FEM0DNguds1lj8Q/j51ee61fZpOGnUg7mJjCLfq+Bl+HRl2DOA1f2i+63 H74dP9IhAzSdnRb9rb9ubnxnrNhJPUxAbijsb8qA= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E131FF8E49C; Fri, 17 Apr 2026 01:11:30 +0000 (UTC) From: Alvin Sun Date: Fri, 17 Apr 2026 09:05:52 +0800 Subject: [PATCH 2/4] rust: mm: Add task_size() method to Mm Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-tyr-ioctls-deps-v1-2-41c6e9bb061c@linux.dev> References: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> In-Reply-To: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Lorenzo Stoakes , "Liam R. Howlett" , Tamir Duberstein Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?utf-8?q?Onur_=C3=96zkan?= , Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1776388289; l=925; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=CEPawZ6sXIb2An8dSVvX8IrZi7UWboan6QZmQB4W5f4=; b=VhjBHoX9OG7AUX3/fgimlEwaBbhq84mQoNYpuucixnpKEzSkynw1I1YDpONyPwQb2ZxJnYiAx xdMwdIPQVOAAqa+DYmSyPAqlc34aXR+M1gMH67k4J5g01IGqgvkMwfx X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Add a task_size() method to the Mm struct to expose the process virtual address space size. This is used by the Tyr driver's VmLayout to determine the user VA range when VmUserSize::Auto is specified. Signed-off-by: Alvin Sun --- rust/kernel/mm.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs index 4764d7b68f2a7..c6ba4da52688b 100644 --- a/rust/kernel/mm.rs +++ b/rust/kernel/mm.rs @@ -149,6 +149,13 @@ pub fn mmget_not_zero(&self) -> Option> { None } } + + /// Returns task size for this mm_struct. + #[inline] + pub fn task_size(&self) -> u64 { + // SAFETY: self.as_raw() is a valid pointer to an mm_struct. + unsafe { (*self.as_raw()).__bindgen_anon_1.task_size as u64 } + } } =20 // These methods require `mm_users` to be non-zero. --=20 2.43.0 From nobody Tue Jun 16 06:26:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 408C02580CF; Fri, 17 Apr 2026 01:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; cv=none; b=dvh/iZEWtc7z9257z0qka6l+rUcdU0IZ4Q+1HdDhXyzTuAJwcMe2qC0eIXFcpsOtVsvJ44iCUlRvEJijxERWOQFoZPvkHm9XDTbzaA01VkXu2YhBxJNjt0G8wijrL1OmcVNIn01wkvl1uJN14sID6oWCIVF2D4OLgPZ5Y8QCcz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; c=relaxed/simple; bh=F/5SEP+S/zr/1Wvabq3W0ofBAhgKbB5EzANwuYwFetA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mlnsb5ZEqxKPyl2and6cqva1lOT07kTV7M86+yQR0+Gv5+SmhqZ5FLq5nTQcG0nN3I2MzfP606KblbA0rgPac2mbF79jFRGrkxGdCYKzBQ5Y8EaMoaEKVFqOwRPszPrnGq1evrdSwIjPsTT5l2Om1uhHhHwY8nxkChTFCha/wrg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ERVavyNP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ERVavyNP" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0A378C2BCB5; Fri, 17 Apr 2026 01:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1776388291; bh=F/5SEP+S/zr/1Wvabq3W0ofBAhgKbB5EzANwuYwFetA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ERVavyNPYzsodTs1O4T0WsRy2gXRbZLrmgkue83UvPa1p2Dfo9uLmg4KsFKSq5W/U xMh02BOb6fYSgWIUA9fRrXhtTv9DZCNlDdQEv/JGaU/juRxKn2g6BofyuDZNQVx2Ct GUKi1n3l50ELo9XAxiEj8hUMp/F3In3ar8dWmtIc= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F01B0F8E497; Fri, 17 Apr 2026 01:11:30 +0000 (UTC) From: Alvin Sun Date: Fri, 17 Apr 2026 09:05:53 +0800 Subject: [PATCH 3/4] rust: xarray: Update StoreError comments for alloc() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-tyr-ioctls-deps-v1-3-41c6e9bb061c@linux.dev> References: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> In-Reply-To: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Lorenzo Stoakes , "Liam R. Howlett" , Tamir Duberstein Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?utf-8?q?Onur_=C3=96zkan?= , Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1776388289; l=1003; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=F/5SEP+S/zr/1Wvabq3W0ofBAhgKbB5EzANwuYwFetA=; b=mHYTu9uPEnfW/Y/sIW8aE4App2+Eq7VQ+cJKYCM8Ln6csO3vDaC4O7okM3v+6xmI1n7e/ytq8 VUnKr8eWYQoCUmsdOOLPgvyM73PSb2biAEBFhMnuYrl1GylM0RFUgRh X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Update StoreError documentation comments to mention alloc() usage since this error type will be used by the upcoming alloc() helper. Signed-off-by: Alvin Sun --- rust/kernel/xarray.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs index 1b882cd2f58bf..235fda0e394ba 100644 --- a/rust/kernel/xarray.rs +++ b/rust/kernel/xarray.rs @@ -161,13 +161,13 @@ fn drop(&mut self) { } } =20 -/// The error returned by [`store`](Guard::store). +/// The error returned by [`Guard::store`] and [`Guard::alloc`]. /// -/// Contains the underlying error and the value that was not stored. +/// Contains the underlying error and the value that was not stored or all= ocated. pub struct StoreError { /// The error that occurred. pub error: Error, - /// The value that was not stored. + /// The value that was not stored or allocated. pub value: T, } =20 --=20 2.43.0 From nobody Tue Jun 16 06:26:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4B0132580E1; Fri, 17 Apr 2026 01:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; cv=none; b=qwutEgYG+hqS4QOKG5veyYFwWkkICDKGYJZM+y6gLpklCxT1kD6jGjigckQR4kpmI5PcTzuex33h2uHwrYqzjheYjUKWDi5FBtNSvL+Um8Sz0PDNvWhgmo/0ojs/PJdjwjRfoGdoSNe8BByJ38hMCqXbyUG/PYwxgnKCMsCwdNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776388291; c=relaxed/simple; bh=HK2c+z8dRuFsYNATe7JRBa5cKQyu3FlazejUuvyOuq8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fs600+42GO3UlewWtesjPARo24t3uiAfHdmNrF8LhOZD35J8uVLMleEfvmyjnaXIkMNYdOUOWD0J8ItTN5Dj2k74t6WjsezzVj6dzlg/1ORh+zVb2akPFVagnaqZmON+5tjBhPZt4t2++qcg/UmDcmzm+6gLiu+c1uxqOlwAmuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pfwEavzJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pfwEavzJ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 16CEDC2BCF4; Fri, 17 Apr 2026 01:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1776388291; bh=HK2c+z8dRuFsYNATe7JRBa5cKQyu3FlazejUuvyOuq8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pfwEavzJ72Cb4tU1vMmW+uXzNsJX5JN95bWz+EZTvCqx3jfME/SrrCvzDrIwjwv6M n20lcaa5rqsM/HLdEFldiS8HaRF3BPxh1f05XLfo7YKj2DHU0JcGPpXR5W27U2OSk+ 7rPgCARP3SP2oaRgwaoE3AvHZ42sXCRLU0k2H2vs= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C288F8E49E; Fri, 17 Apr 2026 01:11:31 +0000 (UTC) From: Alvin Sun Date: Fri, 17 Apr 2026 09:05:54 +0800 Subject: [PATCH 4/4] rust: xarray: Add Guard::find() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-tyr-ioctls-deps-v1-4-41c6e9bb061c@linux.dev> References: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> In-Reply-To: <20260417-tyr-ioctls-deps-v1-0-41c6e9bb061c@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Lorenzo Stoakes , "Liam R. Howlett" , Tamir Duberstein Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?utf-8?q?Onur_=C3=96zkan?= , Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1776388289; l=1408; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=HK2c+z8dRuFsYNATe7JRBa5cKQyu3FlazejUuvyOuq8=; b=c/lPoOZ1Arte0C/QoYrkBDlhgjCZ5b99pHUmEM6OFrj/WdCEt52K0YfvGN8Z06RSSMFQgpDdo JBKPQrDSNehAxdqNGVcwXaYyiVDut1xvEu8f1PV1IxWItviywlhjFt6 X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Add a helper to find the first present entry in the XArray. Returns the index of the first present entry, or None if the array is empty. Signed-off-by: Alvin Sun --- rust/kernel/xarray.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs index 235fda0e394ba..e43129d032d9d 100644 --- a/rust/kernel/xarray.rs +++ b/rust/kernel/xarray.rs @@ -217,6 +217,28 @@ pub fn remove(&mut self, index: usize) -> Option { unsafe { T::try_from_foreign(ptr) } } =20 + /// Finds the first present entry. + /// + /// Returns the index of the first present entry, or `None` if the arr= ay is empty. + pub fn find(&mut self) -> Option { + let mut index =3D 0usize; + // SAFETY: `self.xa.xa` is always valid by the type invariant, and= we hold the lock. + let ptr =3D unsafe { + bindings::xa_find( + self.xa.xa.get(), + &mut index, + usize::MAX, + bindings::XA_PRESENT, + ) + }; + + if ptr.is_null() { + None + } else { + Some(index) + } + } + /// Stores an element at the given index. /// /// May drop the lock if needed to allocate memory, and then reacquire= it afterwards. --=20 2.43.0