From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 21E7DD7788E for ; Fri, 23 Jan 2026 17:09:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 818AA10E2E1; Fri, 23 Jan 2026 17:09:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="pCkq1BVR"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 874B310EB62; Fri, 23 Jan 2026 17:09:29 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 450C6442C5; Fri, 23 Jan 2026 17:09:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B204BC4CEF1; Fri, 23 Jan 2026 17:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769188169; bh=f+5R3JjKS78CLRcPp/zk8EZGYV2IyAlDbob41E0jGxM=; h=Date:Cc:To:From:Subject:References:In-Reply-To:From; b=pCkq1BVRkt6UcdQekae22ylsavZ31j2jTyO8zTmWNTofhT5FduLMCzTiSC/wlIOQd tVo4GSmp0pl1zQWgFpAcUSRKyJzs+gYg5VWzDeXcx/2eg1o/YaAX1tzPO78SwlATzj eq5//FZKCyWVbxmRLlsofp7Le3K/wSIWkEssD6vw9ybk60joiOZDrCDeCivtf3leN/ 413W+uG6Siydgo67ZqfGwNECbm6XRX/qANShby5hxZIobEAZ5rHaL3n+L0zAdbPNxN 2czIooc9BJcrFR44ZdSGjd+S+vBpNixHcOG1cFDQSUBv8BBm56jb3/rIOz+clV+zD5 c4sgFJQ/r15Jg== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 23 Jan 2026 18:09:24 +0100 Message-Id: Cc: , , , , "Miguel Ojeda" , "Simona Vetter" , "Alice Ryhl" , "Shankari Anand" , "David Airlie" , "Benno Lossin" , "Asahi Lina" , "Daniel Almeida" To: "Lyude Paul" From: "Danilo Krummrich" Subject: Re: [PATCH v3 1/3] rust/drm: Introduce DeviceContext References: <20260122225057.3589500-1-lyude@redhat.com> <20260122225057.3589500-2-lyude@redhat.com> In-Reply-To: <20260122225057.3589500-2-lyude@redhat.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Thu Jan 22, 2026 at 11:46 PM CET, Lyude Paul wrote: > diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver= .rs > index b1af0a099551d..99d6841b69cbc 100644 > --- a/drivers/gpu/drm/nova/driver.rs > +++ b/drivers/gpu/drm/nova/driver.rs > @@ -21,7 +21,7 @@ pub(crate) struct NovaDriver { > } > =20 > /// Convienence type alias for the DRM device type for this driver > -pub(crate) type NovaDevice =3D drm::Device; > +pub(crate) type NovaDevice =3D drm::Device; Nothing for this patch (series), but I think we should get rid of this type alias, I think it's confusing. > +/// A typed DRM device with a specific [`drm::Driver`] implementation an= d [`DeviceContext`]. > +/// > +/// Since DRM devices can be used before being fully initialized and reg= istered with userspace, `C` > +/// represents the furthest [`DeviceContext`] we can guarantee that this= [`Device`] has reached. > +/// > +/// Keep in mind: this means that an unregistered device can still have = the registration state > +/// [`Registered`] as long as it was registered with userspace once in t= he past, and that the > +/// behavior of such a device is still well-defined. In such a situation= , the behavior of any > +/// functions which interact with userspace will simply be no-ops. Addit= ionally, a device with the This is still not correct, the are not guaranteed to be no-ops. We can stil= l have callbacks from userspace after the DRM device is unregistered. > +/// registration state [`Uninit`] simply does not have a guaranteed regi= stration state at compile > +/// time, and could be either registered or unregistered. Since there is= no way to guarantee a > +/// long-lived reference to an unregistered device would remain unregist= ered, we do not provide a > +/// [`DeviceContext`] for this. > +/// > +/// # Invariants > +/// > +/// * `self.dev` is a valid instance of a `struct device`. > +/// * The data layout of `Self` remains the same across all implementati= ons of `C`. > +/// * Any invariants for `C` also apply. > +#[repr(C)] > +pub struct Device { > + dev: Opaque, > + data: T::Data, > + _ctx: PhantomData, > +} > - /// Registers a new [`Device`](drm::Device) with userspace. > + /// Registers a new [`UnregisteredDevice`](drm::UnregisteredDevice) = with userspace. > /// > /// Ownership of the [`Registration`] object is passed to [`devres::= register`]. > - pub fn new_foreign_owned( > - drm: &drm::Device, > - dev: &device::Device, > + pub fn new_foreign_owned<'a>( > + drm: drm::UnregisteredDevice, > + dev: &'a device::Device, > flags: usize, > - ) -> Result > + ) -> Result<&'a drm::Device> > where > T: 'static, > { > - if drm.as_ref().as_raw() !=3D dev.as_raw() { > + let this_dev: &device::Device =3D drm.as_ref(); > + if this_dev.as_raw() !=3D dev.as_raw() { I still think this change is unnecessary and the name 'this_dev' is mislead= ing, as it actually is the parent device. > return Err(EINVAL); > } > =20 > let reg =3D Registration::::new(drm, flags)?; > + let drm =3D NonNull::from(reg.device()); > + > + devres::register(dev, reg, GFP_KERNEL)?; > =20 > - devres::register(dev, reg, GFP_KERNEL) > + // SAFETY: Since `reg` was passed to devres::register(), the dev= ice now owns the lifetime > + // of the DRM registration - ensuring that this references lives= for at least as long as 'a. > + Ok(unsafe { drm.as_ref() }) > }