From nobody Sun Dec 7 07:04:21 2025 Received: from forward206d.mail.yandex.net (forward206d.mail.yandex.net [178.154.239.215]) (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 78D151E98F3; Mon, 6 Oct 2025 16:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.215 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759768778; cv=none; b=pFFLU48wZASWUfTscn79hr55zKmQfdRmKQ62i/Of+/T8RjBiIgYxgIPBmBZyxxwJ4lyBC0j656P2B94E8LCuMUKAW0TausocAr0eGzOPJdaJLPZtjDFTpvCWCpyludXPkeEUYr51ZveM7eHC+y23+2vUEZ39Hqj75k63sRhi/A0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759768778; c=relaxed/simple; bh=JUSnWyLOB4Y3CkxaXpFFOkLJpwZSX0Z/YxSqkPIVmTQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ILMcCxLwvYs8DQgcFDjw1gMcZStUtJ7ZiBCEkXRdtohaRHqzscdZuK7Lw1+kLeXw3iqyH5Cbqjsl+xbNzIFqseE+c/foXEOD1L0BujTGWr7NnmiM+quJWdUDWoGMTy1LMG4BkJ/IE0PjMCuUKmCRx1R68j48IOd4PjVgCn0cYs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=GmphZBoX; arc=none smtp.client-ip=178.154.239.215 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="GmphZBoX" Received: from forward102d.mail.yandex.net (forward102d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d102]) by forward206d.mail.yandex.net (Yandex) with ESMTPS id 2DFFD81721; Mon, 06 Oct 2025 19:31:30 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net [IPv6:2a02:6b8:c43:4985:0:640:840f:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id 5A1BAC0020; Mon, 06 Oct 2025 19:31:22 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id QUnb3i1LqqM0-s618dfjU; Mon, 06 Oct 2025 19:31:21 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=mail; t=1759768281; bh=h9w3fGruuyxxZovTmUnVz6z/ZezxkUgog/9KTM7sRNU=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=GmphZBoXYH9ubVCL6t9of4gE+XoksrljirMXhAB0YFCLv6t4utL7plpArSomgu0wa qoXwyM6xLdQBtwYHtDf+go1iyADqQstbG+qXGZ/FBpNtcOFKtq/6hy9Dr+NLZQ9zGv u9/aP+i/L94WR/e1Kgm1j5k0gP3lHFuOrl5UL4rY= Authentication-Results: mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net; dkim=pass header.i=@onurozkan.dev From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rust-for-linux@vger.kernel.org Cc: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org, acourbot@nvidia.com, airlied@gmail.com, simona@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, corbet@lwn.net, lyude@redhat.com, linux-doc@vger.kernel.org, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH 1/3] rust: xarray: abstract `xa_alloc` Date: Mon, 6 Oct 2025 19:30:22 +0300 Message-ID: <20251006163024.18473-2-work@onurozkan.dev> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251006163024.18473-1-work@onurozkan.dev> References: <20251006163024.18473-1-work@onurozkan.dev> 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 Implements `alloc` function to `XArray` that wraps `xa_alloc` safely. Resolves a task from the nova/core task list under the "XArray bindings [XARR]" section in "Documentation/gpu/nova/core/todo.rst" file. Signed-off-by: Onur =C3=96zkan --- rust/kernel/xarray.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs index a49d6db28845..1b882cd2f58b 100644 --- a/rust/kernel/xarray.rs +++ b/rust/kernel/xarray.rs @@ -266,6 +266,45 @@ pub fn store( Ok(unsafe { T::try_from_foreign(old) }) } } + + /// Allocates an empty slot within the given limit range and stores `v= alue` there. + /// + /// May drop the lock if needed to allocate memory, and then reacquire= it afterwards. + /// + /// On success, returns the allocated id. + /// + /// On failure, returns the element which was attempted to be stored. + pub fn alloc( + &mut self, + limit: bindings::xa_limit, + value: T, + gfp: alloc::Flags, + ) -> Result> { + build_assert!( + T::FOREIGN_ALIGN >=3D 4, + "pointers stored in XArray must be 4-byte aligned" + ); + + let new =3D value.into_foreign(); + let mut id: u32 =3D 0; + + // SAFETY: + // - `self.xa.xa` is valid by the type invariant. + // - `new` came from `T::into_foreign`. + let ret =3D + unsafe { bindings::__xa_alloc(self.xa.xa.get(), &mut id, new, = limit, gfp.as_raw()) }; + + if ret < 0 { + // SAFETY: `__xa_alloc` doesn't take ownership on error. + let value =3D unsafe { T::from_foreign(new) }; + return Err(StoreError { + value, + error: Error::from_errno(ret), + }); + } + + Ok(id) + } } // SAFETY: `XArray` has no shared mutable state so it is `Send` iff `T`= is `Send`. -- 2.51.0 From nobody Sun Dec 7 07:04:21 2025 Received: from forward203d.mail.yandex.net (forward203d.mail.yandex.net [178.154.239.218]) (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 91A7221770A; Mon, 6 Oct 2025 16:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759768777; cv=none; b=ncymU6xv3OO68/0hOnoZOrd94w0OVqK+efRcNcYupx0KTtx3fVZJkOOmyw6AoyquKIXgmHju4Vi+95R7kPr7li38RUvCBUca9lKkfZSGoJhU2/HcNY+YlcHbvNLs2Vl28HSDTTOZbKa+aDOIR77d63z9w0ew/BsOcbX9PbeSRyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759768777; c=relaxed/simple; bh=fgi7F+vcqe0RzzCkxdSjpnKSsY3ZVogIjEyJ1V5Jgtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BA8NRfHBYiVrrpHJUihbSgnUWOx2alx37gWrtX1BH6b+ESjfDGzSEkdR5uo5EgsLF7rIM/ZbptYrgIMDtEIITGpUab+roIni7EjiYqZX3HPADPq1xOTSFJKG652/Vlq8G+C/963/1cA4TtuAdosnlzj8HDBJ15L8N9144ghP098= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=aIZ4DWJ+; arc=none smtp.client-ip=178.154.239.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="aIZ4DWJ+" Received: from forward101d.mail.yandex.net (forward101d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d101]) by forward203d.mail.yandex.net (Yandex) with ESMTPS id 5880E87263; Mon, 06 Oct 2025 19:31:34 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net [IPv6:2a02:6b8:c43:4985:0:640:840f:0]) by forward101d.mail.yandex.net (Yandex) with ESMTPS id 19018C006A; Mon, 06 Oct 2025 19:31:25 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id QUnb3i1LqqM0-yLIGxQ3w; Mon, 06 Oct 2025 19:31:24 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=mail; t=1759768284; bh=wRSUS9fJfSKjUxXWIv62A172UK/lxalhVSV+MQPi5gg=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=aIZ4DWJ+hQKF7E0UDY67rm5dnLgxygmn3WjUovjna+L8obrnlxU+4IWRUSmJ058KG xuRlkolySIivPJBnTGVodkQ69g6XSh5z6Fc2FMCp+5dt3NLiyAG+T0P/qOfpvcP5AL uB9InMYfzAhuL/gR/Di5Bm46fcZyBiUHHd3HjO2A= Authentication-Results: mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net; dkim=pass header.i=@onurozkan.dev From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rust-for-linux@vger.kernel.org Cc: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org, acourbot@nvidia.com, airlied@gmail.com, simona@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, corbet@lwn.net, lyude@redhat.com, linux-doc@vger.kernel.org, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH 2/3] rust: xarray: abstract `xa_alloc_cyclic` Date: Mon, 6 Oct 2025 19:30:23 +0300 Message-ID: <20251006163024.18473-3-work@onurozkan.dev> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251006163024.18473-1-work@onurozkan.dev> References: <20251006163024.18473-1-work@onurozkan.dev> 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 Implements `alloc_cyclic` function to `XArray` that wraps `xa_alloc_cyclic` safely. Resolves a task from the nova/core task list under the "XArray bindings [XARR]" section in "Documentation/gpu/nova/core/todo.rst" file. Signed-off-by: Onur =C3=96zkan --- rust/kernel/xarray.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs index 1b882cd2f58b..4c2fdf53c7af 100644 --- a/rust/kernel/xarray.rs +++ b/rust/kernel/xarray.rs @@ -305,6 +305,49 @@ pub fn alloc( Ok(id) } + + /// Allocates an empty slot within the given `limit`, storing `value` = and cycling from `*next`. + /// + /// May drop the lock if needed to allocate memory, and then reacquire= it afterwards. + /// + /// On success, returns the allocated id. + /// + /// On failure, returns the element which was attempted to be stored. + pub fn alloc_cyclic( + &mut self, + limit: bindings::xa_limit, + next: &mut u32, + value: T, + gfp: alloc::Flags, + ) -> Result> { + build_assert!( + T::FOREIGN_ALIGN >=3D 4, + "pointers stored in XArray must be 4-byte aligned" + ); + + let new =3D value.into_foreign(); + + // `__xa_alloc_cyclic` overwrites this. + let mut id: u32 =3D 0; + + // SAFETY: + // - `self.xa.xa` is valid by the type invariant. + // - `new` came from `T::into_foreign`. + let ret =3D unsafe { + bindings::__xa_alloc_cyclic(self.xa.xa.get(), &mut id, new, li= mit, next, gfp.as_raw()) + }; + + if ret < 0 { + // SAFETY: `__xa_alloc_cyclic` doesn't take ownership on error. + let value =3D unsafe { T::from_foreign(new) }; + return Err(StoreError { + value, + error: Error::from_errno(ret), + }); + } + + Ok(id) + } } // SAFETY: `XArray` has no shared mutable state so it is `Send` iff `T`= is `Send`. -- 2.51.0 From nobody Sun Dec 7 07:04:21 2025 Received: from forward100d.mail.yandex.net (forward100d.mail.yandex.net [178.154.239.211]) (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 9340921CC68; Mon, 6 Oct 2025 16:31:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.211 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759768298; cv=none; b=bfUo3Ar3dWtqjW6vfke7WxUfWrqGoLd5gYLqryV6EuYvauZHdD9SEZOeLWcgoXTOypacJIGtUvKZ68C4ZKD7+x4X8u42gt5rvkEUYcqyPfC+l/qAoZysq+sogz+Uc3u0rZSojoTeSF7fXzmNJ4F4U4NiXm8B0UMuf/lQvyv193w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759768298; c=relaxed/simple; bh=2uY5NoijnwdLmleoPPRrn2yh0v/tr1KGjdpZ1mjviHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ofbE2RBFHBM0grYW96ciZDuZFWpkQhnG1v5qmXQgrka3ej9ptFuFEEl64b3YDJkIvDtpVyOxQ/Z6OveTv4DO/q40+2fotIVRBOoLSmRAk0p7TRUard6WFjK4vbS3Q/SGLEg9aJbAD21ff8aguPbn0BMDDrmGNgCNFzXYGVkwaVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=G1ndKLox; arc=none smtp.client-ip=178.154.239.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="G1ndKLox" Received: from mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net [IPv6:2a02:6b8:c43:4985:0:640:840f:0]) by forward100d.mail.yandex.net (Yandex) with ESMTPS id D9B68C005A; Mon, 06 Oct 2025 19:31:27 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id QUnb3i1LqqM0-XVWqGg8c; Mon, 06 Oct 2025 19:31:27 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=mail; t=1759768287; bh=2uY5NoijnwdLmleoPPRrn2yh0v/tr1KGjdpZ1mjviHk=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=G1ndKLoxp0HthVEGilprHO0MELdxRUCDGzMNXK722hlgEHv2TlozqZcpu9fdxYum7 WPvKhNCZARfJO19jqPqutmnoSaasoRsiTYrThQ1WipEFAqPUUTy918nZWPYchkG4rn DrExsazmvePLYvvRrY/m1vvoo791ckQBM/+nZdUQ= Authentication-Results: mail-nwsmtp-smtp-production-main-80.klg.yp-c.yandex.net; dkim=pass header.i=@onurozkan.dev From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rust-for-linux@vger.kernel.org Cc: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org, acourbot@nvidia.com, airlied@gmail.com, simona@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, corbet@lwn.net, lyude@redhat.com, linux-doc@vger.kernel.org, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH 3/3] remove completed task from nova-core task list Date: Mon, 6 Oct 2025 19:30:24 +0300 Message-ID: <20251006163024.18473-4-work@onurozkan.dev> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251006163024.18473-1-work@onurozkan.dev> References: <20251006163024.18473-1-work@onurozkan.dev> 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 The task is completed in this series. Signed-off-by: Onur =C3=96zkan --- Documentation/gpu/nova/core/todo.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Documentation/gpu/nova/core/todo.rst b/Documentation/gpu/nova/= core/todo.rst index 0972cb905f7a..de70a857fcfd 100644 --- a/Documentation/gpu/nova/core/todo.rst +++ b/Documentation/gpu/nova/core/todo.rst @@ -210,14 +210,6 @@ capability, MSI API abstractions. | Complexity: Beginner -XArray bindings [XARR] ----------------------- - -We need bindings for `xa_alloc`/`xa_alloc_cyclic` in order to generate the -auxiliary device IDs. - -| Complexity: Intermediate - Debugfs abstractions -------------------- -- 2.51.0