From nobody Mon Jun 8 06:36:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 AA40D1429D; Wed, 3 Jun 2026 01:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450083; cv=none; b=Wy+IwLhFmdhkK7BGsEZWcjdymfKUF3itTkOsjUOaVmikfbQlwe8OtoqP7swa6PSJRfW1Ji5jljIxwH1jgHX9tt/R+v8CtDMxTo8nKp/IgPzzlBjU01pQ/pWAREv7DGj2DAerwglwR7BYoY1LOiOsd9AvfnWeDAOHa/mS5bfXnVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450083; c=relaxed/simple; bh=cXxNJK2Xuff/MabnWTvB1SqsWHxb7RgpicRRvpU5AL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VduHpo+sKcdQKtIwbtuTE09oADnx9r8gH5vKptIF8p9xrcGW3JvheVsyn6MvYqpQVwunDEC1XleMj0RNyiKD0nWZkS75FuyHzRR6OkmBfalJGS0I49Pt5Mm1HY90CEWl6a+ixQLsrDFRjgeGeMLNFT9VyQCpamIb9KkJvNzH4uo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OfsnbHR+; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OfsnbHR+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 639231F0089A; Wed, 3 Jun 2026 01:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780450082; bh=Zroeszp4iFiTtbrqGQ6aWtPmjlPL9U1c0ijXSEdtli8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OfsnbHR+n7fVCFsU4Ts5JkkOu5udMu+qsP0NghIl22mNv9MOfb0w4EI9KY96dIEFD OGkeC/s862AIxRbgaGketzY51C++dDKvhgc2IC90LyQ89k/Bg27BbJyUIyObr6WpTw Vd/CFQUmUHwVSRHhb7yKzc+6V62XQsH/WM8xIP1BLhFcKzGJc/Nuq4MrpeMhyETYfk lVby0B0wr6TBt0DxkBiYQzocRfs1JiASj2bgKOzpOP/E2hWNXmY7Q57atD7Qg1+VgD zIrIHYcQ3UiAxAYT6sPDS8XFt96yvrgRaFvgHZLel016LylaGmoC4a2mB1AP0Ljac3 JM4HlqTBtCqow== From: Danilo Krummrich To: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, acourbot@nvidia.com, ecourtney@nvidia.com, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, deborah.brouwer@collabora.com, boris.brezillon@collabora.com Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org Subject: [PATCH v2 1/7] rust: drm: Add Driver::ParentDevice associated type Date: Wed, 3 Jun 2026 03:15:43 +0200 Message-ID: <20260603011711.2077361-2-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603011711.2077361-1-dakr@kernel.org> References: <20260603011711.2077361-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a ParentDevice associated type to the Driver trait, allowing each DRM driver to declare its parent bus device type (e.g. auxiliary::Device, platform::Device). Change UnregisteredDevice::new() to take &T::ParentDevice, ensuring at the type level that the DRM device's parent matches the declared bus device type. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nova/driver.rs | 8 ++++++-- drivers/gpu/drm/tyr/driver.rs | 6 ++++-- rust/kernel/drm/device.rs | 7 +++++-- rust/kernel/drm/driver.rs | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs index 48933d86ddda..c5b0313006bd 100644 --- a/drivers/gpu/drm/nova/driver.rs +++ b/drivers/gpu/drm/nova/driver.rs @@ -2,7 +2,10 @@ =20 use kernel::{ auxiliary, - device::Core, + device::{ + Core, + DeviceContext, // + }, drm::{ self, gem, @@ -62,7 +65,7 @@ fn probe<'bound>( ) -> impl PinInit, Error> + 'bound { let data =3D try_pin_init!(NovaData { adev: adev.into() }); =20 - let drm =3D drm::UnregisteredDevice::::new(adev.as_ref(), da= ta)?; + let drm =3D drm::UnregisteredDevice::::new(adev, data)?; let drm =3D drm::Registration::new_foreign_owned(drm, adev.as_ref(= ), 0)?; =20 Ok(Nova { drm: drm.into() }) @@ -74,6 +77,7 @@ impl drm::Driver for NovaDriver { type Data =3D NovaData; type File =3D File; type Object =3D gem::Object; + type ParentDevice =3D auxiliary::Device; =20 const INFO: drm::DriverInfo =3D INFO; =20 diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs index d063bc664cc1..338c25ccc151 100644 --- a/drivers/gpu/drm/tyr/driver.rs +++ b/drivers/gpu/drm/tyr/driver.rs @@ -7,7 +7,8 @@ }, device::{ Core, - Device, // + Device, + DeviceContext, // }, dma::{ Device as DmaDevice, @@ -148,7 +149,7 @@ fn probe<'bound>( gpu_info, }); =20 - let tdev =3D drm::UnregisteredDevice::::new(pdev.as_= ref(), data)?; + let tdev =3D drm::UnregisteredDevice::::new(pdev, da= ta)?; let tdev =3D drm::driver::Registration::new_foreign_owned(tdev, pd= ev.as_ref(), 0)?; =20 let driver =3D TyrPlatformDriverData { @@ -182,6 +183,7 @@ impl drm::Driver for TyrDrmDriver { type Data =3D TyrDrmDeviceData; type File =3D TyrDrmFileData; type Object =3D drm::gem::shmem::Object; + type ParentDevice =3D platform::Device; =20 const INFO: drm::DriverInfo =3D INFO; const FEAT_RENDER: bool =3D true; diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index 477cf771fb10..858272fc2164 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -208,7 +208,10 @@ const fn compute_features() -> u32 { /// Create a new `UnregisteredDevice` for a `drm::Driver`. /// /// This can be used to create a [`Registration`](kernel::drm::Registr= ation). - pub fn new(dev: &device::Device, data: impl PinInit) -= > Result { + pub fn new( + dev: &T::ParentDevice, + data: impl PinInit, + ) -> Result { // `__drm_dev_alloc` uses `kmalloc()` to allocate memory, hence en= sure a `kmalloc()` // compatible `Layout`. let layout =3D Kmalloc::aligned_layout(Layout::new::>()); @@ -225,7 +228,7 @@ pub fn new(dev: &device::Device, data: impl PinInit) -> Result =3D unsafe { bindings::__drm_dev_alloc( - dev.as_raw(), + dev.as_ref().as_raw(), &alloc_vtable, layout.size(), mem::offset_of!(Device, dev), diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index 25f7e233884d..802e7fc13e30 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -116,6 +116,9 @@ pub trait Driver { /// The type used to represent a DRM File (client) type File: drm::file::DriverFile; =20 + /// The bus device type of the parent device that the DRM device is as= sociated with. + type ParentDevice: device::AsBusDevice; + /// Driver metadata const INFO: DriverInfo; =20 --=20 2.54.0 From nobody Mon Jun 8 06:36:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E917C1429D; Wed, 3 Jun 2026 01:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450088; cv=none; b=JirA1Bbl43zC4uH0XpP2qViKBxz3sSwTRZXVyrK8H4VBxrmkxNrc/+yedy94c+e6JDfFqfTJ4a77HTjyzAVWoCuCtSGR0XXUUF16DAJ0vnhQxMVl3B9Ad5m6qm1N32HJkUjrpRXYGJb4RCz9iqGdv1DnqBQlgYqLUlXGJ4VCgpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450088; c=relaxed/simple; bh=M98zjOm8FgChp1mgBvKMZ8vq/VhelKkwLB7c1sJh2jM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lHTihvEJPZR9BWLU3WAztz1ITAS4groLAhRscCdH08MPxiBmVM7Zh3M6rt5V8AUciAQ1yAtdn3am6tCY6eFdep4Mt/Ge+r5YTRcgMv40GiCqMMq9NxNRbfmY7ofi5FpNqdHK30G+vFEmb+FZ7P04qGLWiP1iR2geNgKYZ/uWkQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C70Hmhxu; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C70Hmhxu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1DDE1F00893; Wed, 3 Jun 2026 01:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780450086; bh=m2h4Z6OkkbbInzIbrprZlhpoCefuLJi9rVqO8HTD32Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C70Hmhxuy1lVEOh9LhZZUJf/tt0EN7qh7Zo5cog9AD2L8MZxMqmreaoSZYWVG9I3y R+uF9r8HVocj6dmLwfnKn2RBNG3hRjkyc5SoZ8M93qJ7fIyG7xFh4NHfEsSI3h6iRB CDt8IbyhablZ37BexlWC6RwTzVGibXgsYIyqqEVXCtMRfms/i4ZPAkz5B8tFYaP+zk jtpi2qlTyJW2Z5DIJ747joullX0N8bd6vzH2/nnVyKox4mrL2mJzMwoNZdHJG6XdR0 xovJ25DpCTbR76gF6pyteZiV8i91Gcz8BzJII8Om1ZZet+Cbaq5uCbIk30pIWR347+ A6KyPQuAIHnQw== From: Danilo Krummrich To: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, acourbot@nvidia.com, ecourtney@nvidia.com, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, deborah.brouwer@collabora.com, boris.brezillon@collabora.com Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org Subject: [PATCH v2 2/7] rust: drm: Add UnbindGuard for drm_dev_enter/exit critical sections Date: Wed, 3 Jun 2026 03:15:44 +0200 Message-ID: <20260603011711.2077361-3-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603011711.2077361-1-dakr@kernel.org> References: <20260603011711.2077361-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DRM ioctls do not guarantee that the parent bus device is still bound. However, since DRM device registration is managed through Devres, using drm_dev_unplug() on unregistration ensures that between drm_dev_enter() and drm_dev_exit() the parent device must be bound. Add UnbindGuard, a guard object representing a drm_dev_enter/exit SRCU critical section that dereferences to &Device of the parent bus device. The guard is only available on Device, ensuring it cannot be used on unregistered devices. Also add with_unbind_guard() as a convenience helper that executes a closure with the bound device reference. Switch Registration::drop from drm_dev_unregister() to drm_dev_unplug() to provide the SRCU barrier that UnbindGuard's safety argument relies on. Signed-off-by: Danilo Krummrich --- rust/kernel/drm/device.rs | 82 ++++++++++++++++++++++++++++++++++++++- rust/kernel/drm/driver.rs | 10 ++++- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index 858272fc2164..828618ae19af 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -7,7 +7,10 @@ use crate::{ alloc::allocator::Kmalloc, bindings, - device, + device::{ + self, + AsBusDevice as _, // + }, drm::{ self, driver::AllocImpl, @@ -355,6 +358,83 @@ pub(crate) unsafe fn assume_ctx= (&self) -> &Device Device { + /// Guard against the parent bus device being unbound. + /// + /// Returns an [`UnbindGuard`] if the device has not been unplugged, [= `None`] otherwise. + /// + /// The returned guard dereferences to the parent bus device in the [`= device::Bound`] context + /// (see [`Driver::ParentDevice`](drm::Driver::ParentDevice)). + /// + /// While [`UnbindGuard`] is held the parent device is guaranteed to b= e bound. + #[must_use] + pub fn unbind_guard(&self) -> Option> { + let mut idx: i32 =3D 0; + // SAFETY: `self.as_raw()` is a valid pointer to a `struct drm_dev= ice` by the type + // invariants of `Device`. + if unsafe { bindings::drm_dev_enter(self.as_raw(), &mut idx) } { + Some(UnbindGuard { dev: self, idx }) + } else { + None + } + } + + /// Execute a closure while the parent bus device is guaranteed to be = bound. + /// + /// Acquires the [`UnbindGuard`] and, if the device has not been unplu= gged, calls `f` with the + /// parent bus device. Returns `None` if the device has been unplugged. + pub fn with_unbind_guard( + &self, + f: impl FnOnce(&T::ParentDevice) -> R, + ) -> Option { + let guard =3D self.unbind_guard()?; + Some(f(&guard)) + } +} + +/// A guard preventing the parent bus device from being unbound. +/// +/// The guard dereferences to [`Driver::ParentDevice`](drm::Driver:= :ParentDevice), providing +/// access to the parent bus device with the guarantee that it is bound fo= r the entire duration of +/// the critical section. +/// +/// Internally this is backed by a `drm_dev_enter()` / `drm_dev_exit()` SR= CU critical section. +/// +/// See [`Device::unbind_guard`] for details on the safety argument. +/// +/// # Invariants +/// +/// - `idx` is the SRCU read lock index returned by a successful `drm_dev_= enter()` call. +/// - The parent bus device of `dev` is bound for the lifetime of this gua= rd. +#[must_use] +pub struct UnbindGuard<'a, T: drm::Driver> { + dev: &'a Device, + idx: i32, +} + +impl Deref for UnbindGuard<'_, T> { + type Target =3D T::ParentDevice; + + #[inline] + fn deref(&self) -> &Self::Target { + // SAFETY: + // - The parent `struct device` is embedded in a `T::ParentDevice`= , as guaranteed by + // `UnregisteredDevice::new` taking a `&T::ParentDevice`. + // - By the type invariants of `UnbindGuard`, the parent device is= bound for the lifetime + // of this guard. + unsafe { T::ParentDevice::from_device(self.dev.as_ref().as_bound()= ) } + } +} + +impl Drop for UnbindGuard<'_, T> { + #[inline] + fn drop(&mut self) { + // SAFETY: `self.idx` was returned by a successful `drm_dev_enter(= )` call, as guaranteed + // by the type invariants of `UnbindGuard`. + unsafe { bindings::drm_dev_exit(self.idx) }; + } +} + impl Deref for Device { type Target =3D T::Data; =20 diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index 802e7fc13e30..f68a17d8939d 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -199,8 +199,14 @@ unsafe impl Send for Registration {} =20 impl Drop for Registration { fn drop(&mut self) { + // Use `drm_dev_unplug` rather than `drm_dev_unregister` to ensure= that existing + // `drm_dev_enter()` critical sections complete before unregistrat= ion proceeds. This + // is required for the safety of `UnbindGuard`, which relies on th= e SRCU barrier in + // `drm_dev_unplug()` to guarantee that the parent device is still= bound within the + // critical section. + // // SAFETY: Safe by the invariant of `ARef>`. The ex= istence of this - // `Registration` also guarantees the this `drm::Device` is actual= ly registered. - unsafe { bindings::drm_dev_unregister(self.0.as_raw()) }; + // `Registration` also guarantees that this `drm::Device` is actua= lly registered. + unsafe { bindings::drm_dev_unplug(self.0.as_raw()) }; } } --=20 2.54.0 From nobody Mon Jun 8 06:36:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 C371C346AF1; Wed, 3 Jun 2026 01:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450092; cv=none; b=uAHcNu6ZtWD0ZSs2xwWQbZ7FXdzHpG2DSUxbcezom35dMKR2hvDIa7IXJjro4dG2F35vwOn5tQr17A8jfxnIslVO8NVeUIv5ESPFyLS3GfisM1g7kHB2YCEtt6y6FKF9x8DGKTDGpaobUanAHbHdieSgb749TUEK/jk6KEPSPwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450092; c=relaxed/simple; bh=70gZGOACG5KoFG+2ar6BRCAhW8Yvg7kXgd3vh/SEbxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VUDFXxmh1Pxu73UNaOCBy+XzzVaK4wi+KA7QLbAi9Hn51AJAiQ9IX7POl0VQjh6FVFsnjXXEYeeKEJrSISyWMgoLQ7EXbOmP40IBYeOATyH3DJfcNRawSgSiFV07DxGH+1ovToNOiRSW5NSuGBmBjUwZdlj9d/Ap0n4+OtfZWtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ikp5AkQM; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ikp5AkQM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED9671F00898; Wed, 3 Jun 2026 01:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780450090; bh=wqdLMk9UOO2RL+z1KE9q0wsuiVK++GcHoy4RNv9OvoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ikp5AkQMhvwTgIqrqR0zhDJer21JQMOHSyUbZojF5qTqgKT0D9bH3lbxTBPGUjm1v zo25Eu6QFe8VNkClKQ6Oueda9xdXAY3gEWpQSG+Rpuc+FuNJX/PBHovxQ1U+YAxUzW ip+LpIjU4g7+2MOCHVIaSeaIdnBkt0/cjrVMF0f+JsBvNI6lfpTReTElGOUCWHpjUC Rtod4mOKTgMoh3z2nHJAhugzXtmV3QpvbzsCFsmhHDeCCHEv/eDqCxKaoFNPGkfWoG YoMQgHEZDEegVLjzLNeryIHi+2WaqtLSVXlOJYlSpp/LofE+NBeWZwIlm0PJFZJNSX 6NuHEiqvnkjpA== From: Danilo Krummrich To: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, acourbot@nvidia.com, ecourtney@nvidia.com, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, deborah.brouwer@collabora.com, boris.brezillon@collabora.com Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org Subject: [PATCH v2 3/7] rust: drm: Add RegistrationData to drm::Driver Date: Wed, 3 Jun 2026 03:15:45 +0200 Message-ID: <20260603011711.2077361-4-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603011711.2077361-1-dakr@kernel.org> References: <20260603011711.2077361-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a RegistrationData associated type to drm::Driver. This is a ForLt type whose lifetime is tied to the parent bus device binding scope. Registration<'a, T> takes ownership of the data via Pin>, storing it with its real lifetime. The pointer is written to drm::Device before drm_dev_register() to ensure it is already in place when ioctls arrive. UnbindGuard::registration_data_with() provides access with the lifetime shortened from 'static via ForLt::cast_ref_unchecked. Since Registration::drop() calls drm_dev_unplug(), which performs an SRCU barrier waiting for all drm_dev_enter() critical sections to complete, the data is guaranteed to remain valid for the duration of any UnbindGuard. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nova/driver.rs | 16 +++-- drivers/gpu/drm/tyr/driver.rs | 16 +++-- rust/kernel/drm/device.rs | 49 +++++++++++++ rust/kernel/drm/driver.rs | 123 ++++++++++++++++++++++++--------- rust/kernel/drm/mod.rs | 1 + 5 files changed, 162 insertions(+), 43 deletions(-) diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs index c5b0313006bd..4267e6e6dbb4 100644 --- a/drivers/gpu/drm/nova/driver.rs +++ b/drivers/gpu/drm/nova/driver.rs @@ -12,7 +12,8 @@ ioctl, // }, prelude::*, - sync::aref::ARef, // + sync::aref::ARef, + types::ForLt, // }; =20 use crate::file::File; @@ -20,9 +21,10 @@ =20 pub(crate) struct NovaDriver; =20 -pub(crate) struct Nova { +pub(crate) struct Nova<'bound> { #[expect(unused)] drm: ARef>, + _reg: drm::Registration<'bound, NovaDriver>, } =20 /// Convienence type alias for the DRM device type for this driver @@ -56,7 +58,7 @@ pub(crate) struct NovaData { =20 impl auxiliary::Driver for NovaDriver { type IdInfo =3D (); - type Data<'bound> =3D Nova; + type Data<'bound> =3D Nova<'bound>; const ID_TABLE: auxiliary::IdTable =3D &AUX_TABLE; =20 fn probe<'bound>( @@ -66,15 +68,19 @@ fn probe<'bound>( let data =3D try_pin_init!(NovaData { adev: adev.into() }); =20 let drm =3D drm::UnregisteredDevice::::new(adev, data)?; - let drm =3D drm::Registration::new_foreign_owned(drm, adev.as_ref(= ), 0)?; + let reg =3D drm::Registration::new(adev.as_ref(), drm, (), 0)?; =20 - Ok(Nova { drm: drm.into() }) + Ok(Nova { + drm: reg.device().into(), + _reg: reg, + }) } } =20 #[vtable] impl drm::Driver for NovaDriver { type Data =3D NovaData; + type RegistrationData =3D ForLt!(()); type File =3D File; type Object =3D gem::Object; type ParentDevice =3D auxiliary::Device; diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs index 338c25ccc151..819f64a7573d 100644 --- a/drivers/gpu/drm/tyr/driver.rs +++ b/drivers/gpu/drm/tyr/driver.rs @@ -31,7 +31,8 @@ aref::ARef, Mutex, // }, - time, // + time, + types::ForLt, // }; =20 use crate::{ @@ -52,8 +53,9 @@ pub(crate) struct TyrPlatformDriver; =20 #[pin_data(PinnedDrop)] -pub(crate) struct TyrPlatformDriverData { +pub(crate) struct TyrPlatformDriverData<'bound> { _device: ARef, + _reg: drm::Registration<'bound, TyrDrmDriver>, } =20 #[pin_data] @@ -98,7 +100,7 @@ fn issue_soft_reset(dev: &Device, iomem: &IoMem<'_>) -> = Result { =20 impl platform::Driver for TyrPlatformDriver { type IdInfo =3D (); - type Data<'bound> =3D TyrPlatformDriverData; + type Data<'bound> =3D TyrPlatformDriverData<'bound>; const OF_ID_TABLE: Option> =3D Some(&OF_TABL= E); =20 fn probe<'bound>( @@ -150,10 +152,11 @@ fn probe<'bound>( }); =20 let tdev =3D drm::UnregisteredDevice::::new(pdev, da= ta)?; - let tdev =3D drm::driver::Registration::new_foreign_owned(tdev, pd= ev.as_ref(), 0)?; + let reg =3D drm::Registration::new(pdev.as_ref(), tdev, (), 0)?; =20 let driver =3D TyrPlatformDriverData { - _device: tdev.into(), + _device: reg.device().into(), + _reg: reg, }; =20 // We need this to be dev_info!() because dev_dbg!() does not work= at @@ -164,7 +167,7 @@ fn probe<'bound>( } =20 #[pinned_drop] -impl PinnedDrop for TyrPlatformDriverData { +impl PinnedDrop for TyrPlatformDriverData<'_> { fn drop(self: Pin<&mut Self>) {} } =20 @@ -181,6 +184,7 @@ fn drop(self: Pin<&mut Self>) {} #[vtable] impl drm::Driver for TyrDrmDriver { type Data =3D TyrDrmDeviceData; + type RegistrationData =3D ForLt!(()); type File =3D TyrDrmFileData; type Object =3D drm::gem::shmem::Object; type ParentDevice =3D platform::Device; diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index 828618ae19af..9e5e069b5135 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -23,6 +23,7 @@ AlwaysRefCounted, // }, types::{ + ForLt, NotThreadSafe, Opaque, // }, @@ -35,6 +36,7 @@ }; use core::{ alloc::Layout, + cell::UnsafeCell, marker::PhantomData, mem, ops::Deref, @@ -259,6 +261,9 @@ pub fn new( // SAFETY: `drm_dev` is still private to this function. unsafe { (*drm_dev).driver =3D const { &Self::VTABLE } }; =20 + // SAFETY: `raw_drm` is valid; no concurrent access before registr= ation. + unsafe { (*raw_drm.as_ptr()).registration_data =3D UnsafeCell::new= (NonNull::dangling()) }; + // SAFETY: The reference count is one, and now we take ownership o= f that reference as a // `drm::Device`. // INVARIANT: We just created the device above, but have yet to ca= ll `drm_dev_register`. @@ -290,6 +295,7 @@ pub fn new( pub struct Device { dev: Opaque, data: T::Data, + pub(super) registration_data: UnsafeCell::Of<'static>>>, _ctx: PhantomData, } =20 @@ -298,6 +304,27 @@ pub(crate) fn as_raw(&self) -> *mut bindings::drm_devi= ce { self.dev.get() } =20 + /// Returns a reference to the registration data with lifetime shorten= ed from `'static`. + /// + /// # Safety + /// + /// The caller must ensure that: + /// + /// - The parent bus device is bound (e.g. by holding an active `drm_d= ev_enter()` critical + /// section via [`UnbindGuard`]). + /// - The returned reference is not exposed to code that can choose a = concrete lifetime for + /// it, as that would be unsound for types that are invariant over t= heir lifetime parameter + /// (e.g. it must be passed through an HRTB-bounded closure). + unsafe fn registration_data_unchecked(&self) -> &::Of<'_> { + // SAFETY: Caller guarantees the parent bus device is bound, hence + // the pointer is valid. + let static_ref =3D unsafe { (*self.registration_data.get()).as_ref= () }; + + // SAFETY: Caller guarantees the reference is only used behind an = HRTB, making the + // round-trip from `'static` sound regardless of variance. + unsafe { T::RegistrationData::cast_ref_unchecked(static_ref) } + } + /// # Safety /// /// `ptr` must be a valid pointer to a `struct device` embedded in `Se= lf`. @@ -412,6 +439,28 @@ pub struct UnbindGuard<'a, T: drm::Driver> { idx: i32, } =20 +impl UnbindGuard<'_, T> { + /// Access the parent device and registration data through a closure, = with both lifetimes + /// tied to the closure scope. + /// + /// The data is owned by [`Registration`](drm::Registration) and is gu= aranteed to remain valid + /// for the duration of this guard, since [`Registration`](drm::Regist= ration)'s `drop` calls + /// `drm_dev_unplug()` which waits for all `drm_dev_enter()` critical = sections to complete. + pub fn registration_data_with(&self, f: F) -> R + where + F: for<'a> FnOnce( + &'a T::ParentDevice, + &'a ::Of<'a>, + ) -> R, + { + // SAFETY: We hold an active `drm_dev_enter()` critical section, s= o the parent bus + // device is guaranteed to be bound. The closure's HRTB `for<'a>` = prevents the caller + // from smuggling in references with a concrete short lifetime, sa= tisfying the lifetime + // requirement of `registration_data_unchecked`. + f(&**self, unsafe { self.dev.registration_data_unchecked() }) + } +} + impl Deref for UnbindGuard<'_, T> { type Target =3D T::ParentDevice; =20 diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index f68a17d8939d..6aa1cb99cc7f 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -7,11 +7,11 @@ use crate::{ bindings, device, - devres, drm, error::to_result, prelude::*, - sync::aref::ARef, // + sync::aref::ARef, + types::ForLt, // }; use core::{ mem, @@ -110,6 +110,16 @@ pub trait Driver { /// Context data associated with the DRM driver type Data: Sync + Send; =20 + /// Data owned by the [`Registration`] and accessible through [`drm::d= evice::UnbindGuard`]. + /// + /// This is a [`ForLt`](trait@ForLt) type whose lifetime is tied to th= e parent bus + /// device binding scope. + /// The data is only accessible while the parent bus device is bound (= i.e. within a + /// `drm_dev_enter/exit` critical section), and references handed out = by + /// [`UnbindGuard::registration_data_with()`](drm::device::UnbindGuard= ::registration_data_with) + /// ties the lifetime to the closure scope. + type RegistrationData: ForLt; + /// The type used to manage memory for this driver. type Object: AllocImpl; =20 @@ -139,12 +149,57 @@ pub trait Driver { /// The registration type of a `drm::Device`. /// /// Once the `Registration` structure is dropped, the device is unregister= ed. -pub struct Registration(ARef>); +pub struct Registration<'a, T: Driver> { + drm: ARef>, + _reg_data: Pin::Of<'a>>>, +} + +impl<'a, T: Driver> Registration<'a, T> +where + for<'b> ::Of<'b>: Send, +{ + /// Register a new [`UnregisteredDevice`](drm::UnregisteredDevice) wit= h userspace. + /// + /// # Safety + /// + /// The caller must not `mem::forget()` the returned [`Registration`] = or otherwise prevent its + /// [`Drop`] implementation from running, since the registration data = may contain borrowed + /// references that become invalid after `'a` ends. + /// + /// If the registration data is `'static`, use the safe [`Registration= ::new()`] instead. + pub unsafe fn new_with_lt( + dev: &'a device::Device, + drm: drm::UnregisteredDevice, + reg_data: impl PinInit<::Of<'a>, E>, + flags: usize, + ) -> Result + where + Error: From, + { + if drm.as_ref().as_raw() !=3D dev.as_raw() { + return Err(EINVAL); + } =20 -impl Registration { - fn new(drm: drm::UnregisteredDevice, flags: usize) -> Result { - // SAFETY: `drm.as_raw()` is valid by the invariants of `drm::Devi= ce`. - to_result(unsafe { bindings::drm_dev_register(drm.as_raw(), flags)= })?; + let reg_data: Pin::Of<'a>>> = =3D + KBox::pin_init(reg_data, GFP_KERNEL)?; + + // Store the registration data pointer in the device before regist= ration, so that it is + // visible once ioctls can be called. + // + // SAFETY: Lifetimes do not affect layout, so the pointer cast is = sound. + let ptr: NonNull<::Of<'static>> =3D + unsafe { mem::transmute(NonNull::from(Pin::get_ref(reg_data.as= _ref()))) }; + + // SAFETY: No concurrent access; the device is not yet registered. + unsafe { *drm.registration_data.get() =3D ptr }; + + // SAFETY: `drm` is a valid, initialized but not yet registered DR= M device. + let ret =3D unsafe { bindings::drm_dev_register(drm.as_raw(), flag= s) }; + if let Err(e) =3D to_result(ret) { + // SAFETY: No concurrent access; registration failed. + unsafe { *drm.registration_data.get() =3D NonNull::dangling() = }; + return Err(e); + } =20 // SAFETY: We just called `drm_dev_register` above let new =3D NonNull::from(unsafe { drm.assume_ctx() }); @@ -156,48 +211,49 @@ fn new(drm: drm::UnregisteredDevice, flags: usize)= -> Result { // one reference to the device - which we take ownership over here. let new =3D unsafe { ARef::from_raw(new) }; =20 - Ok(Self(new)) + Ok(Self { + drm: new, + _reg_data: reg_data, + }) } =20 - /// Registers a new [`UnregisteredDevice`](drm::UnregisteredDevice) wi= th userspace. - /// - /// Ownership of the [`Registration`] object is passed to [`devres::re= gister`]. - pub fn new_foreign_owned<'a>( - drm: drm::UnregisteredDevice, + /// Safe variant of [`Registration::new_with_lt()`] for registration d= ata that does not contain + /// borrowed references. + pub fn new( dev: &'a device::Device, + drm: drm::UnregisteredDevice, + reg_data: impl PinInit<::Of<'a>, E>, flags: usize, - ) -> Result<&'a drm::Device> + ) -> Result where - T: 'static, + ::Of<'a>: 'static, + Error: From, { - if drm.as_ref().as_raw() !=3D dev.as_raw() { - return Err(EINVAL); - } - - let reg =3D Registration::::new(drm, flags)?; - let drm =3D NonNull::from(reg.device()); - - devres::register(dev, reg, GFP_KERNEL)?; - - // SAFETY: Since `reg` was passed to devres::register(), the devic= e now owns the lifetime - // of the DRM registration - ensuring that this references lives f= or at least as long as 'a. - Ok(unsafe { drm.as_ref() }) + // SAFETY: `Of<'a>: 'static` guarantees the data contains no borro= wed references, + // so forgetting the `Registration` cannot cause use-after-free. + unsafe { Self::new_with_lt(dev, drm, reg_data, flags) } } =20 /// Returns a reference to the `Device` instance for this registration. pub fn device(&self) -> &drm::Device { - &self.0 + &self.drm } } =20 // SAFETY: `Registration` doesn't offer any methods or access to fields wh= en shared between // threads, hence it's safe to share it. -unsafe impl Sync for Registration {} +unsafe impl Sync for Registration<'_, T> where + for<'a> ::Of<'a>: Send +{ +} =20 // SAFETY: Registration with and unregistration from the DRM subsystem can= happen from any thread. -unsafe impl Send for Registration {} +unsafe impl Send for Registration<'_, T> where + for<'a> ::Of<'a>: Send +{ +} =20 -impl Drop for Registration { +impl Drop for Registration<'_, T> { fn drop(&mut self) { // Use `drm_dev_unplug` rather than `drm_dev_unregister` to ensure= that existing // `drm_dev_enter()` critical sections complete before unregistrat= ion proceeds. This @@ -207,6 +263,9 @@ fn drop(&mut self) { // // SAFETY: Safe by the invariant of `ARef>`. The ex= istence of this // `Registration` also guarantees that this `drm::Device` is actua= lly registered. - unsafe { bindings::drm_dev_unplug(self.0.as_raw()) }; + unsafe { bindings::drm_dev_unplug(self.drm.as_raw()) }; + // After drm_dev_unplug(), the SRCU barrier guarantees that all Un= bindGuard critical + // sections have completed, so no one holds a reference to reg_dat= a anymore. + // reg_data is dropped here automatically. } } diff --git a/rust/kernel/drm/mod.rs b/rust/kernel/drm/mod.rs index a66e7166f66b..59870bb09de2 100644 --- a/rust/kernel/drm/mod.rs +++ b/rust/kernel/drm/mod.rs @@ -12,6 +12,7 @@ pub use self::device::Device; pub use self::device::DeviceContext; pub use self::device::Registered; +pub use self::device::UnbindGuard; pub use self::device::Uninit; pub use self::device::UnregisteredDevice; pub use self::driver::Driver; --=20 2.54.0 From nobody Mon Jun 8 06:36:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 4371C346FAE; Wed, 3 Jun 2026 01:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450096; cv=none; b=ANlkkyDgSF4BXD/rXw3BDQQrP2k6U7K7MzOEH8KpEWlN5UhiKDtAkmMk8kkupab4EHylX8WyE9b3Tyxw9sJF5SQeWaAIdoXuvHA+/LoMBmEeSbx5jtnDdq6ZR+eEWKWUPQn24wf9WGeX7kGoyvxSRrfpQ7erTJAv6K0qy2hbL00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450096; c=relaxed/simple; bh=sd/UQLjD7pIzfJougflzjbLaSZ3GmrcgpnCNnJC4QKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P/BEJapMjV5ijW/OQ12cDWPhiAm61wqbbySmlV8VIBnpBmpLudlH8bBVQeb2rxQVnjx8HFnHcEONACgJUTfZCR+W5bzs4gEPuc2FBab/c868GpgPFTCXAeQn08fzvP2y5bDXvfE/Ma5Vc/F0LEeZVahzYxioHt6Rc1wsEXgn97M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JfpNCI45; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JfpNCI45" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 236CD1F00893; Wed, 3 Jun 2026 01:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780450094; bh=VZ54gvz6OwwVKxHHJn+g3dMr7wXlQCIuVETm9dQ6AQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JfpNCI45aZl1VcwG2vrWYWX61zPKKcTxktlBAqEXr8wrzisf0bnuekjwIGxF/v8AP ZFu3UH2+uOqvi4GIHK4pYt5j//frkixTUhBoWUIBYeWCg7scbchb9F0Rwh9hZAk0mD 2c5me5y3nB0TXWBMeY8NB5bMkNtK+E6EVdBOMMfM+s41Z5zDr4ZjN8GQDDdFLYxW1u 8Ba6mrK/DzRRVRi8xGB7PhWM7nR2y0yBbhdpBPCzrz6cZXpb7RKImyK4Ni4/Vige1G abA3DCMT2TJRUiBPzgj7h0NU0FJIoUNlVOjYJto/GjqRGTpg8Bx9cvbxWb+jkolMQL z/rVDu0h9tkzQ== From: Danilo Krummrich To: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, acourbot@nvidia.com, ecourtney@nvidia.com, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, deborah.brouwer@collabora.com, boris.brezillon@collabora.com Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org Subject: [PATCH v2 4/7] rust: drm: Wrap ioctl dispatch in UnbindGuard Date: Wed, 3 Jun 2026 03:15:46 +0200 Message-ID: <20260603011711.2077361-5-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603011711.2077361-1-dakr@kernel.org> References: <20260603011711.2077361-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Run every ioctl handler inside a drm_dev_enter/exit critical section via UnbindGuard. If the device has been unplugged, the ioctl returns ENODEV without calling the handler. A never-called closure anchors the driver type for the compiler by tying dev's type to the handler's first parameter, which the compiler cannot infer through method resolution and associated-type projections alone. Signed-off-by: Danilo Krummrich --- rust/kernel/drm/ioctl.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs index cf328101dde4..8ee6e8ea0ff6 100644 --- a/rust/kernel/drm/ioctl.rs +++ b/rust/kernel/drm/ioctl.rs @@ -87,7 +87,10 @@ pub mod internal { /// file: &kernel::drm::File, /// ) -> Result /// ``` -/// where `Self` is the drm::drv::Driver implementation these ioctls are b= eing declared within. +/// where `Self` is the `drm::Driver` implementation these ioctls are bein= g declared within. +/// +/// The ioctl runs inside a `drm_dev_enter/exit` critical section. If the = device has been +/// unplugged, the ioctl returns `ENODEV` without calling the handler. /// /// # Examples /// @@ -134,7 +137,19 @@ macro_rules! declare_drm_ioctls { // FIXME: Currently there is nothing enforcing= that the types of the // dev/file match the current driver these ioc= tls are being declared // for, and it's not clear how to enforce this= within the type system. - let dev =3D $crate::drm::device::Device::from_= raw(raw_dev); + let dev =3D unsafe { + $crate::drm::device::Device::from_raw(raw_= dev) + }; + + // Type-inference anchor: the closure is never= called but ties `dev`'s + // type to `$func`'s first parameter, which th= e compiler cannot infer + // through method resolution and associated-ty= pe projections alone. + #[allow(unreachable_code)] + let _ =3D || $func(dev, unreachable!(), unreac= hable!()); + + let Some(_guard) =3D dev.unbind_guard() else { + return $crate::error::code::ENODEV.to_errn= o(); + }; // SAFETY: The ioctl argument has size `_IOC_S= IZE(cmd)`, which we // asserted above matches the size of this typ= e, and all bit patterns of // UAPI structs must be valid. --=20 2.54.0 From nobody Mon Jun 8 06:36:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 6027A346E43; Wed, 3 Jun 2026 01:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450100; cv=none; b=o7T0PmOhk+6dJWjzmIGTOhwhQJd1KnaCSekPNBuHz7tu/jTUGnRBtQvd02WY6iSVCdOosq63+E4fHVTfdL5DXh1a8E1kW5DBZdwS4x/m1/Le+Sy/VuCZ1uE2xlr1+rvz/YkU2EYd1xDNYwf2pi677Ye2oY/87GEiCRqq1IQX6F8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450100; c=relaxed/simple; bh=i5GTZxEctkY7IFccePqtgsLYiKeLgI4WeT92PZLcmSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q4euW2mn30VreMIayuQBewVq/cYu37rJFS/cAKjBfnke7j+qJ3ea8RrfIE8bQB+0OLwLgBcAch+1vyVlJf1LVP0wKNj9rZypQDMZ1ZjgEWcgqpyXA8p6RTci2GRJbq/7uEFTHlQwiDhtbT0i4HGdG5ehRTZtYZ/7RS+fI4BGerg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SW/52M1l; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SW/52M1l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CBC31F00899; Wed, 3 Jun 2026 01:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780450099; bh=i/Xu79MDZXE/lVp1UAv6q2C76h6/tfquFPa2pKXMBS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SW/52M1lbbWDx0nWNsKuk/j0GQZFrSD56491taB/kEW84QyXSWv7Ym03tn81yXqaU 5nMJVDESKfYaVtfutxNh9JZQfy8vhUNP7X6BlBBAneZ5Tpx1RMac1jVm6hRfcYnvma pbcGcWZYTOzDE27hUJpCLxlISxg4lwf2paQl7JZahfDnPyz8azr4Dqp3nSkpB6caj3 Z9zOerwCDmwf1qoXXJezhy5Sl12Y6NQFfB/VNhx6BOtFbwUlCWfOL3DeMqhmy0Bq55 bykRoJXIuXlGB3pH3WNgzWGhFXCoHpUFZB4FgQCPyFPE0i+JPb2ycvtAvmjByijTJY LmkijhYlhuAEg== From: Danilo Krummrich To: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, acourbot@nvidia.com, ecourtney@nvidia.com, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, deborah.brouwer@collabora.com, boris.brezillon@collabora.com Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org Subject: [PATCH v2 5/7] rust: drm: Pass bound parent device to ioctl handlers Date: Wed, 3 Jun 2026 03:15:47 +0200 Message-ID: <20260603011711.2077361-6-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603011711.2077361-1-dakr@kernel.org> References: <20260603011711.2077361-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass &Self::ParentDevice as the second argument to ioctl handlers. This gives ioctl handlers direct access to the bound parent bus device. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nova/file.rs | 5 +++++ drivers/gpu/drm/tyr/file.rs | 3 +++ rust/kernel/drm/ioctl.rs | 7 ++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs index a3b7bd36792c..d43f92ee181d 100644 --- a/drivers/gpu/drm/nova/file.rs +++ b/drivers/gpu/drm/nova/file.rs @@ -4,6 +4,8 @@ use crate::gem::NovaObject; use kernel::{ alloc::flags::*, + auxiliary, + device::Bound, drm::{self, gem::BaseObject}, pci, prelude::*, @@ -24,6 +26,7 @@ impl File { /// IOCTL: get_param: Query GPU / driver metadata. pub(crate) fn get_param( dev: &NovaDevice, + _adev: &auxiliary::Device, getparam: &mut uapi::drm_nova_getparam, _file: &drm::File, ) -> Result { @@ -44,6 +47,7 @@ pub(crate) fn get_param( /// IOCTL: gem_create: Create a new DRM GEM object. pub(crate) fn gem_create( dev: &NovaDevice, + _adev: &auxiliary::Device, req: &mut uapi::drm_nova_gem_create, file: &drm::File, ) -> Result { @@ -57,6 +61,7 @@ pub(crate) fn gem_create( /// IOCTL: gem_info: Query GEM metadata. pub(crate) fn gem_info( _dev: &NovaDevice, + _adev: &auxiliary::Device, req: &mut uapi::drm_nova_gem_info, file: &drm::File, ) -> Result { diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs index 31411da203c5..181475f18c18 100644 --- a/drivers/gpu/drm/tyr/file.rs +++ b/drivers/gpu/drm/tyr/file.rs @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 or MIT =20 use kernel::{ + device, drm, + platform, prelude::*, uaccess::UserSlice, uapi, // @@ -29,6 +31,7 @@ fn open(_dev: &drm::Device) -> Result>> { impl TyrDrmFileData { pub(crate) fn dev_query( ddev: &TyrDrmDevice, + _pdev: &platform::Device, devquery: &mut uapi::drm_panthor_dev_query, _file: &TyrDrmFile, ) -> Result { diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs index 8ee6e8ea0ff6..2229dc55764b 100644 --- a/rust/kernel/drm/ioctl.rs +++ b/rust/kernel/drm/ioctl.rs @@ -83,6 +83,7 @@ pub mod internal { /// /// ```ignore /// fn foo(device: &kernel::drm::Device, +/// parent: &Self::ParentDevice, /// data: &mut uapi::argument_type, /// file: &kernel::drm::File, /// ) -> Result @@ -145,9 +146,9 @@ macro_rules! declare_drm_ioctls { // type to `$func`'s first parameter, which th= e compiler cannot infer // through method resolution and associated-ty= pe projections alone. #[allow(unreachable_code)] - let _ =3D || $func(dev, unreachable!(), unreac= hable!()); + let _ =3D || $func(dev, unreachable!(), unreac= hable!(), unreachable!()); =20 - let Some(_guard) =3D dev.unbind_guard() else { + let Some(guard) =3D dev.unbind_guard() else { return $crate::error::code::ENODEV.to_errn= o(); }; // SAFETY: The ioctl argument has size `_IOC_S= IZE(cmd)`, which we @@ -162,7 +163,7 @@ macro_rules! declare_drm_ioctls { // SAFETY: This is just the DRM file structure let file =3D unsafe { $crate::drm::File::from_= raw(raw_file) }; =20 - match $func(dev, data, file) { + match $func(dev, &*guard, data, file) { Err(e) =3D> e.to_errno(), Ok(i) =3D> i.try_into() .unwrap_or($crate::error::code= ::ERANGE.to_errno()), --=20 2.54.0 From nobody Mon Jun 8 06:36:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 4BC34346AF1; Wed, 3 Jun 2026 01:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450104; cv=none; b=B8o2ynyNjOCCzdYz1uu3Akd//EgH9SnIKAaS+MKtLDwE1fPbo0PdepaoxQwlr4lQSP8MBmy1LKiEBvLEdlsnTxWPYd6pm/LRwYF+4saajnIVvRBv3riJMadz4iH2xw69LzBj+bsjm/w7DfuqmNXjD6jFVAo+d9rqk8ghcqccr/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450104; c=relaxed/simple; bh=ig/GeSYEA36vavfqXbKTP6Vij1DIY0FrbE111dI3JOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wh0dGyCqPfm3nm/HHqY3Q3Zc21joVVTpMRIPchOTInIqFcWiqBwiSogR2UiwwzThsQnm+4O1rEZyABXdMr9e0nNwfydNl9Rr6r0bx827tl7cW010pMxIL51yD1+EtaicSGcJ+IBpC/tNF/vVMyXevG+CSn3ESxE1rn3jhgvFB9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QKA7bQlt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QKA7bQlt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7582E1F00893; Wed, 3 Jun 2026 01:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780450103; bh=hRinYvXRXA4hFT5GQKiVH1LPW6fzeLKqdFLtLzEGSO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QKA7bQlti5voVN9YQMzeqRevAT3ae8HEvEdB6OpYEMd5lRZffFQtgxqaVXmZlf6RH /zMa8zVzCAtcN5yTfss1IfA2zALnMH3jKwley4CAmirX57gkqp9hPkJ2xwOyKt0yYf 4pX7meXJZjBTcmgE/kfj/DpTb/4Od9oLVUtWGMRvOwzsANcO3o29Cun40aQZ8mAvCM BXcVTgWKbbVA+q2YwIfibVzHkE+OIjot2j4+On3E34DDoPdt0cAhs+sYoTulZamVqU dXo8r/5p6Ni4tzq9ujlrRqZb1NiPf3/wotxKme/BTN2jdlzN6VqXTf8q5Dh5VEI4Ay vxchtgDRUX/MA== From: Danilo Krummrich To: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, acourbot@nvidia.com, ecourtney@nvidia.com, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, deborah.brouwer@collabora.com, boris.brezillon@collabora.com Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org Subject: [PATCH v2 6/7] rust: drm: Pass registration data to ioctl handlers Date: Wed, 3 Jun 2026 03:15:48 +0200 Message-ID: <20260603011711.2077361-7-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603011711.2077361-1-dakr@kernel.org> References: <20260603011711.2077361-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass registration data to ioctl handlers via UnbindGuard::registration_data_with(). The closure's HRTB ties the lifetime to the closure scope, and ForLt::cast_ref_unchecked shortens it from 'static internally. The reference is valid for the duration of the drm_dev_enter/exit critical section held by UnbindGuard. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nova/file.rs | 3 +++ drivers/gpu/drm/tyr/file.rs | 1 + rust/kernel/drm/ioctl.rs | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs index d43f92ee181d..df9760947d58 100644 --- a/drivers/gpu/drm/nova/file.rs +++ b/drivers/gpu/drm/nova/file.rs @@ -27,6 +27,7 @@ impl File { pub(crate) fn get_param( dev: &NovaDevice, _adev: &auxiliary::Device, + _reg_data: &(), getparam: &mut uapi::drm_nova_getparam, _file: &drm::File, ) -> Result { @@ -48,6 +49,7 @@ pub(crate) fn get_param( pub(crate) fn gem_create( dev: &NovaDevice, _adev: &auxiliary::Device, + _reg_data: &(), req: &mut uapi::drm_nova_gem_create, file: &drm::File, ) -> Result { @@ -62,6 +64,7 @@ pub(crate) fn gem_create( pub(crate) fn gem_info( _dev: &NovaDevice, _adev: &auxiliary::Device, + _reg_data: &(), req: &mut uapi::drm_nova_gem_info, file: &drm::File, ) -> Result { diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs index 181475f18c18..9f53da7633ab 100644 --- a/drivers/gpu/drm/tyr/file.rs +++ b/drivers/gpu/drm/tyr/file.rs @@ -32,6 +32,7 @@ impl TyrDrmFileData { pub(crate) fn dev_query( ddev: &TyrDrmDevice, _pdev: &platform::Device, + _reg_data: &(), devquery: &mut uapi::drm_panthor_dev_query, _file: &TyrDrmFile, ) -> Result { diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs index 2229dc55764b..773683da7d6a 100644 --- a/rust/kernel/drm/ioctl.rs +++ b/rust/kernel/drm/ioctl.rs @@ -84,6 +84,7 @@ pub mod internal { /// ```ignore /// fn foo(device: &kernel::drm::Device, /// parent: &Self::ParentDevice, +/// reg_data: &::Of= <'_>, /// data: &mut uapi::argument_type, /// file: &kernel::drm::File, /// ) -> Result @@ -146,7 +147,15 @@ macro_rules! declare_drm_ioctls { // type to `$func`'s first parameter, which th= e compiler cannot infer // through method resolution and associated-ty= pe projections alone. #[allow(unreachable_code)] - let _ =3D || $func(dev, unreachable!(), unreac= hable!(), unreachable!()); + let _ =3D || { + $func( + dev, + unreachable!(), + unreachable!(), + unreachable!(), + unreachable!(), + ) + }; =20 let Some(guard) =3D dev.unbind_guard() else { return $crate::error::code::ENODEV.to_errn= o(); @@ -163,7 +172,9 @@ macro_rules! declare_drm_ioctls { // SAFETY: This is just the DRM file structure let file =3D unsafe { $crate::drm::File::from_= raw(raw_file) }; =20 - match $func(dev, &*guard, data, file) { + match guard.registration_data_with(|parent, re= g_data| { + $func(dev, parent, reg_data, data, file) + }) { Err(e) =3D> e.to_errno(), Ok(i) =3D> i.try_into() .unwrap_or($crate::error::code= ::ERANGE.to_errno()), --=20 2.54.0 From nobody Mon Jun 8 06:36:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 AEC22346AF1; Wed, 3 Jun 2026 01:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450108; cv=none; b=nDQ/DBmGtdeLLP2167wta/jRt+I/b0RAI/Vzkpr2F/ONNU1307M+pWepDeudgIwT0SFl5U/2Gx2G9ZQf5Q8ar7oc1uDK39O7ylhac5aKpH0Y07QEGNxuuA5PLKoHjepX+LVzQebmhKID+Lfmm1uC0fGf1t/srxgoSFDpb0CvbNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780450108; c=relaxed/simple; bh=54L6GUHynzmZ8CHl+zaBOGuki6LSuSU6JhQzxeOkM4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ATjNwuXlGJz/KZDfcz+RooqtumKp13LYrHOvXcE1f31INJNrFhv6tvdHwL2yEFXyEUOPjbgcfgdDmug5uxKCv7/nOdVgWPJk1yhub5jZ9ww8pMUUWQm4Ab/3CippLqwlah4tIyLPZ9ov2Rz2/N6QtPm5anxKZfxSgiR64sIFOBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RaMoqAwd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RaMoqAwd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F4AD1F00898; Wed, 3 Jun 2026 01:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780450107; bh=/Uzv2Gm7jENTbbTq3bRLEhLW5ARZCqwdxuR6ti+4xL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RaMoqAwdveFJ4vYzNN1wBZroIwEH6ImX18p4Inr8AyFxK0RPPqwkpRdgls9kTn7h0 2d89Ohk9QIPYsPqQ6ua6h3hxZC7umNU6EFLAnZDJDKQOzRIo1l/tVQD/j++Tm2HEsK 3RBkSO5Xk3RGob6+Iivcos6RJmYVD9qhFhRnyCHTbxPKvf9xYVL2qM4IKz9/o3XSX2 ZeVxmY5/JK/O5UvKMh/9oVCTbYRfr107hzX/iPJzwvUzYYQiQE06HKbxME0C5Xh8Eg vKcpklwLFfsA9Ges+q8PJApcTcsi2M7ka4iBAobvyR6OMRMKmfeSJ0lJ/nkYkvlsHK XDPS4b5HY4FcA== From: Danilo Krummrich To: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, acourbot@nvidia.com, ecourtney@nvidia.com, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, deborah.brouwer@collabora.com, boris.brezillon@collabora.com Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org Subject: [PATCH v2 7/7] drm: nova: convert to use DRM registration data Date: Wed, 3 Jun 2026 03:15:49 +0200 Message-ID: <20260603011711.2077361-8-dakr@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603011711.2077361-1-dakr@kernel.org> References: <20260603011711.2077361-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the auxiliary device reference from drm::Device data into RegistrationData, replacing the ARef with a borrowed &'bound auxiliary::Device. This makes the data lifetime-aware and exercises the registration data path through the ioctl handlers. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nova/driver.rs | 20 ++++++++++---------- drivers/gpu/drm/nova/file.rs | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs index 4267e6e6dbb4..f46d7ff6fee3 100644 --- a/drivers/gpu/drm/nova/driver.rs +++ b/drivers/gpu/drm/nova/driver.rs @@ -3,6 +3,7 @@ use kernel::{ auxiliary, device::{ + Bound, Core, DeviceContext, // }, @@ -13,7 +14,7 @@ }, prelude::*, sync::aref::ARef, - types::ForLt, // + types::CovariantForLt, // }; =20 use crate::file::File; @@ -30,9 +31,8 @@ pub(crate) struct Nova<'bound> { /// Convienence type alias for the DRM device type for this driver pub(crate) type NovaDevice =3D drm::Device; =20 -#[pin_data] -pub(crate) struct NovaData { - pub(crate) adev: ARef, +pub(crate) struct NovaData<'bound> { + pub(crate) adev: &'bound auxiliary::Device, } =20 const INFO: drm::DriverInfo =3D drm::DriverInfo { @@ -65,10 +65,10 @@ fn probe<'bound>( adev: &'bound auxiliary::Device>, _info: &'bound Self::IdInfo, ) -> impl PinInit, Error> + 'bound { - let data =3D try_pin_init!(NovaData { adev: adev.into() }); - - let drm =3D drm::UnregisteredDevice::::new(adev, data)?; - let reg =3D drm::Registration::new(adev.as_ref(), drm, (), 0)?; + let drm =3D drm::UnregisteredDevice::::new(adev, Ok(()))?; + let reg_data =3D NovaData { adev }; + // SAFETY: We never bypass the destructor of `reg`. + let reg =3D unsafe { drm::Registration::new_with_lt(adev.as_ref(),= drm, reg_data, 0)? }; =20 Ok(Nova { drm: reg.device().into(), @@ -79,8 +79,8 @@ fn probe<'bound>( =20 #[vtable] impl drm::Driver for NovaDriver { - type Data =3D NovaData; - type RegistrationData =3D ForLt!(()); + type Data =3D (); + type RegistrationData =3D CovariantForLt!(NovaData<'_>); type File =3D File; type Object =3D gem::Object; type ParentDevice =3D auxiliary::Device; diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs index df9760947d58..cd6c37b01e22 100644 --- a/drivers/gpu/drm/nova/file.rs +++ b/drivers/gpu/drm/nova/file.rs @@ -1,6 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 =20 -use crate::driver::{NovaDevice, NovaDriver}; +use crate::driver::{ + NovaData, + NovaDevice, + NovaDriver, // +}; use crate::gem::NovaObject; use kernel::{ alloc::flags::*, @@ -25,15 +29,14 @@ fn open(_dev: &NovaDevice) -> Result>> { impl File { /// IOCTL: get_param: Query GPU / driver metadata. pub(crate) fn get_param( - dev: &NovaDevice, + _dev: &NovaDevice, _adev: &auxiliary::Device, - _reg_data: &(), + reg_data: &NovaData<'_>, getparam: &mut uapi::drm_nova_getparam, _file: &drm::File, ) -> Result { - let adev =3D &dev.adev; - let parent =3D adev.parent(); - let pdev: &pci::Device =3D parent.try_into()?; + let parent =3D reg_data.adev.parent(); + let pdev: &pci::Device =3D parent.try_into()?; =20 let value =3D match getparam.param as u32 { uapi::NOVA_GETPARAM_VRAM_BAR_SIZE =3D> pdev.resource_len(1)?, @@ -49,7 +52,7 @@ pub(crate) fn get_param( pub(crate) fn gem_create( dev: &NovaDevice, _adev: &auxiliary::Device, - _reg_data: &(), + _reg_data: &NovaData<'_>, req: &mut uapi::drm_nova_gem_create, file: &drm::File, ) -> Result { @@ -64,7 +67,7 @@ pub(crate) fn gem_create( pub(crate) fn gem_info( _dev: &NovaDevice, _adev: &auxiliary::Device, - _reg_data: &(), + _reg_data: &NovaData<'_>, req: &mut uapi::drm_nova_gem_info, file: &drm::File, ) -> Result { --=20 2.54.0