From nobody Fri Dec 19 18:42:00 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 527A226D4D0 for ; Fri, 16 May 2025 17:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415455; cv=none; b=j6ZyV/+V58xSpxfS9gjTH0TRJX581+asFuOUMPKxkqA4BtsIR5IhniP7AQoRaLjQejkbuT1RZRolNStQqdm+DaZ15YLodH+drdO6TAuRlg1S7FTgpSHLIRejAxlMCFlVoCRiX1gyACWeKSNEChGrj5/AFZ51LswAU4eUygnKh40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415455; c=relaxed/simple; bh=Y6EHCil8ccnaWkK3aix5VIS9rec8Tw8EPOi9EorOhwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hUtnRJgr6V5nPgJCCsOkk0g3BpZLykCx8Pdfu4RmaDnhubybwoSl1S32VStVJrcemZsh9v5ua1XhZ8sPJZaTeVCNdD66nedLI5BEKK1oQsR+4MbN2XQZcO9PPxUMQy1pO5ZNhUDCyL/n3dBJf2YhCW2iUxAJk4GiEWxK7l4j21o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ux1hyISt; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ux1hyISt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747415452; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Z0I9jrZU5atM1qUoNE/ouzYqO6Z+EgWgOrezkMsmh0=; b=Ux1hyIStAgjeSaz4JlNhHR4Zv6hEgGBHrBsM/UKPKNVs3vjh28coIMXayhmMVBs0/bjCBk OomeW7uHfJAzH8BGbYqvOmrbUa53ZmXb+smse0/6zvGXI3pLEmeKRkSOgqLT01RoqXaBCq 9ktSyFfPX+oa9UdgrfaDmE5vXaYpsxI= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-671-URD6NkHuNkmhRlGioqmafg-1; Fri, 16 May 2025 13:10:47 -0400 X-MC-Unique: URD6NkHuNkmhRlGioqmafg-1 X-Mimecast-MFC-AGG-ID: URD6NkHuNkmhRlGioqmafg_1747415444 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 89E5A19560A2; Fri, 16 May 2025 17:10:43 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.82.40]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB54C19560AF; Fri, 16 May 2025 17:10:38 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Alyssa Rosenzweig , Asahi Lina Subject: [PATCH v2 1/4] rust: drm: gem: Simplify use of generics Date: Fri, 16 May 2025 13:09:16 -0400 Message-ID: <20250516171030.776924-2-lyude@redhat.com> In-Reply-To: <20250516171030.776924-1-lyude@redhat.com> References: <20250516171030.776924-1-lyude@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Now that my rust skills have been honed, I noticed that there's a lot of generics in our gem bindings that don't actually need to be here. Currently the hierarchy of traits in our gem bindings looks like this: * Drivers implement: * BaseDriverObject (has the callbacks) * DriverObject (has the drm::Driver type) * Crate implements: * IntoGEMObject for Object where T: DriverObject Handles conversion to/from raw object pointers * BaseObject for T where T: IntoGEMObject Provides methods common to all gem interfaces Also of note, this leaves us with two different drm::Driver associated types: * DriverObject::Driver * IntoGEMObject::Driver I'm not entirely sure of the original intent here unfortunately (if anyone is, please let me know!), but my guess is that the idea would be that some objects can implement IntoGEMObject using a different ::Driver than DriverObject - presumably to enable the usage of gem objects from different drivers. A reasonable usecase of course. However - if I'm not mistaken, I don't think that this is actually how things would go in practice. Driver implementations are of course implemented by their associated drivers, and generally drivers are not linked to each-other when building the kernel. Which is to say that even in a situation where we would theoretically deal with gem objects from another driver, we still wouldn't have access to its drm::driver::Driver implementation. It's more likely we would simply want a variant of gem objects in such a situation that have no association with a drm::driver::Driver type. Taking that into consideration, we can assume the following: * Anything that implements BaseDriverObject will implement DriverObject In other words, all BaseDriverObjects indirectly have an associated ::Driver type - so the two traits can be combined into one with no generics. * Not everything that implements IntoGEMObject will have an associated ::Driver, and that's OK. And with this, we now can do quite a bit of cleanup with the use of generics here. As such, this commit: * Removes the generics on BaseDriverObject * Moves DriverObject::Driver into BaseDriverObject * Removes DriverObject * Removes IntoGEMObject::Driver, and require BaseDriverObject be implemented for any methods in BaseObject that need an associated driver. Leaving us with a simpler trait hierarchy that now looks like this: * Drivers implement: BaseDriverObject * Crate implements: * IntoGEMObject for Object where T: DriverObject * BaseObject for T where T: IntoGEMObject Which makes the code a lot easier to understand and build on :). Signed-off-by: Lyude Paul --- V2: * Don't refer to Object in callbacks, as this would result in drivers getting the wrong gem object type for shmem gem objects once we add support for those. Instead, we'll just add a type alias to clean this part up. Signed-off-by: Lyude Paul --- rust/kernel/drm/gem/mod.rs | 82 ++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index d8765e61c6c25..f0455cc2aff2d 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -15,31 +15,31 @@ use core::{mem, ops::Deref, ptr::NonNull}; =20 /// GEM object functions, which must be implemented by drivers. -pub trait BaseDriverObject: Sync + Send + Sized { +pub trait BaseDriverObject: Sync + Send + Sized { + /// Parent `Driver` for this object. + type Driver: drm::Driver; + /// Create a new driver data object for a GEM object of a given size. - fn new(dev: &drm::Device, size: usize) -> impl PinInit; + fn new(dev: &drm::Device, size: usize) -> impl PinInit; =20 /// Open a new handle to an existing object, associated with a File. fn open( - _obj: &<::Driver as drm::Driver>::Object, - _file: &drm::File<<::Driver as drm::Driver>::F= ile>, + _obj: &::Object, + _file: &drm::File<::File>, ) -> Result { Ok(()) } =20 /// Close a handle to an existing object, associated with a File. fn close( - _obj: &<::Driver as drm::Driver>::Object, - _file: &drm::File<<::Driver as drm::Driver>::F= ile>, + _obj: &::Object, + _file: &drm::File<::File>, ) { } } =20 /// Trait that represents a GEM object subtype pub trait IntoGEMObject: Sized + super::private::Sealed + AlwaysRefCounted= { - /// Owning driver for this type - type Driver: drm::Driver; - /// Returns a reference to the raw `drm_gem_object` structure, which m= ust be valid as long as /// this owning object is valid. fn as_raw(&self) -> *mut bindings::drm_gem_object; @@ -74,25 +74,15 @@ unsafe fn dec_ref(obj: NonNull) { } } =20 -/// Trait which must be implemented by drivers using base GEM objects. -pub trait DriverObject: BaseDriverObject> { - /// Parent `Driver` for this object. - type Driver: drm::Driver; -} - -extern "C" fn open_callback, U: BaseObject>( +extern "C" fn open_callback( raw_obj: *mut bindings::drm_gem_object, raw_file: *mut bindings::drm_file, ) -> core::ffi::c_int { // SAFETY: `open_callback` is only ever called with a valid pointer to= a `struct drm_file`. - let file =3D unsafe { - drm::File::<<::Driver as drm::Driver>::File>::= as_ref(raw_file) - }; - // SAFETY: `open_callback` is specified in the AllocOps structure for = `Object`, ensuring that - // `raw_obj` is indeed contained within a `Object`. - let obj =3D unsafe { - <<::Driver as drm::Driver>::Object as IntoGEMO= bject>::as_ref(raw_obj) - }; + let file =3D unsafe { drm::File::<::File>::a= s_ref(raw_file) }; + // SAFETY: `open_callback` is specified in the AllocOps structure for = `DriverObject`, + // ensuring that `raw_obj` is contained within a `DriverObject` + let obj =3D unsafe { <::Object as IntoGEMObj= ect>::as_ref(raw_obj) }; =20 match T::open(obj, file) { Err(e) =3D> e.to_errno(), @@ -100,26 +90,21 @@ extern "C" fn open_callback, U:= BaseObject>( } } =20 -extern "C" fn close_callback, U: BaseObject>( +extern "C" fn close_callback( raw_obj: *mut bindings::drm_gem_object, raw_file: *mut bindings::drm_file, ) { // SAFETY: `open_callback` is only ever called with a valid pointer to= a `struct drm_file`. - let file =3D unsafe { - drm::File::<<::Driver as drm::Driver>::File>::= as_ref(raw_file) - }; + let file =3D unsafe { drm::File::<::File>::a= s_ref(raw_file) }; + // SAFETY: `close_callback` is specified in the AllocOps structure for= `Object`, ensuring // that `raw_obj` is indeed contained within a `Object`. - let obj =3D unsafe { - <<::Driver as drm::Driver>::Object as IntoGEMO= bject>::as_ref(raw_obj) - }; + let obj =3D unsafe { <::Object as IntoGEMObj= ect>::as_ref(raw_obj) }; =20 T::close(obj, file); } =20 -impl IntoGEMObject for Object { - type Driver =3D T::Driver; - +impl IntoGEMObject for Object { fn as_raw(&self) -> *mut bindings::drm_gem_object { self.obj.get() } @@ -141,10 +126,10 @@ fn size(&self) -> usize { =20 /// Creates a new handle for the object associated with a given `File` /// (or returns an existing one). - fn create_handle( - &self, - file: &drm::File<<::Driver as drm::Driver>:= :File>, - ) -> Result { + fn create_handle(&self, file: &drm::File<= ::File>) -> Result + where + Self: BaseDriverObject, + { let mut handle: u32 =3D 0; // SAFETY: The arguments are all valid per the type invariants. to_result(unsafe { @@ -155,9 +140,12 @@ fn create_handle( =20 /// Looks up an object by its handle for a given `File`. fn lookup_handle( - file: &drm::File<<::Driver as drm::Driver>:= :File>, + file: &drm::File<::File>, handle: u32, - ) -> Result> { + ) -> Result> + where + Self: BaseDriverObject, + { // SAFETY: The arguments are all valid per the type invariants. let ptr =3D unsafe { bindings::drm_gem_object_lookup(file.as_raw()= .cast(), handle) }; if ptr.is_null() { @@ -199,21 +187,21 @@ impl BaseObject for T {} /// - `self.dev` is always a valid pointer to a `struct drm_device`. #[repr(C)] #[pin_data] -pub struct Object { +pub struct Object { obj: Opaque, dev: NonNull>, #[pin] data: T, } =20 -impl Object { +impl Object { /// The size of this object's structure. pub const SIZE: usize =3D mem::size_of::(); =20 const OBJECT_FUNCS: bindings::drm_gem_object_funcs =3D bindings::drm_g= em_object_funcs { free: Some(Self::free_callback), - open: Some(open_callback::>), - close: Some(close_callback::>), + open: Some(open_callback::), + close: Some(close_callback::), print_info: None, export: None, pin: None, @@ -283,9 +271,9 @@ extern "C" fn free_callback(obj: *mut bindings::drm_gem= _object) { } } =20 -impl super::private::Sealed for Object {} +impl super::private::Sealed for Object {} =20 -impl Deref for Object { +impl Deref for Object { type Target =3D T; =20 fn deref(&self) -> &Self::Target { @@ -293,7 +281,7 @@ fn deref(&self) -> &Self::Target { } } =20 -impl AllocImpl for Object { +impl AllocImpl for Object { const ALLOC_OPS: AllocOps =3D AllocOps { gem_create_object: None, prime_handle_to_fd: None, --=20 2.49.0 From nobody Fri Dec 19 18:42:00 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 E3EDA26D4D0 for ; Fri, 16 May 2025 17:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415462; cv=none; b=iZNT1myJBOhHfmTnB40xFse8S/Px1ZoVzYnwloGh5OGVdhddT8dqti5VV+6T/iMdX+lnUBJ4mlb+6m17KtcT+CxzTsunD+Jp4x8hTli0GOXEBPd4+ovlLwKEjMZi36SnQ8v0ZyHiO8u6TEYWPMsPb815VjDr8NFC3+CudMSrfdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415462; c=relaxed/simple; bh=GsSp7CFVeu8zzsF3uZLc5tYEaNZFpTnOe6qGcvHvQR4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OzFVgIcxwgREgTcDqGOLEq9IrMbx9eDm/PJT1vWGtXdrA5TqU/etfCirterrStXrcriphDZGiM6NXurwv4e1IDfkrAmbKzJqd+vkjMCgGmBeofv1ip0HR1wWqMbG9d3+vFhkZCyrLiQ6JoI+Z0EgJdfA/CaOGcDLkaaBYY/e7ts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=abQgOwpP; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="abQgOwpP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747415459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zsCGIYqEtmWNiDyyK2E4AEh2cY6xEg1Ay56+xO7ycmE=; b=abQgOwpPBktnEdW00TMieL5nUIjroxBZYFOGyoiYLS4M6PJQ7/+AjrFw+iYyouljxnHCq7 zFyh9WlNZ2MtlMVrqMivqOq3CkVF+RrcIYTNpk7TlR08j8EnmXm0t36y+Opu4EJbZ4RMR6 kNNPYga/nRw4fXlOaL1riXjYxb/SffQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-275-KNAcHhlNOQi2VTioV2gkmg-1; Fri, 16 May 2025 13:10:55 -0400 X-MC-Unique: KNAcHhlNOQi2VTioV2gkmg-1 X-Mimecast-MFC-AGG-ID: KNAcHhlNOQi2VTioV2gkmg_1747415453 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C1130195608B; Fri, 16 May 2025 17:10:52 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.82.40]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9327419560AE; Fri, 16 May 2025 17:10:46 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Alyssa Rosenzweig , Asahi Lina Subject: [PATCH v2 2/4] rust: drm: gem: Add DriverObject type alias Date: Fri, 16 May 2025 13:09:17 -0400 Message-ID: <20250516171030.776924-3-lyude@redhat.com> In-Reply-To: <20250516171030.776924-1-lyude@redhat.com> References: <20250516171030.776924-1-lyude@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Now that we've cleaned up the generics for gem objects a bit, we're still left with a bit of generic soup around referring to the Object implementation for a given driver. Let's clean this up a bit by re-using the DriverObject identifier we just freed up and turning it into a type alias for referring to a driver's gem object implementation. Signed-off-by: Lyude Paul Reviewed-by: Danilo Krummrich --- rust/kernel/drm/gem/mod.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index f0455cc2aff2d..c17b36948bae3 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -14,6 +14,9 @@ }; use core::{mem, ops::Deref, ptr::NonNull}; =20 +/// A type alias for the Object type in use by a [`drm::Driver`]. +pub type DriverObject =3D <::Driver as drm::Driv= er>::Object; + /// GEM object functions, which must be implemented by drivers. pub trait BaseDriverObject: Sync + Send + Sized { /// Parent `Driver` for this object. @@ -24,18 +27,14 @@ pub trait BaseDriverObject: Sync + Send + Sized { =20 /// Open a new handle to an existing object, associated with a File. fn open( - _obj: &::Object, + _obj: &DriverObject, _file: &drm::File<::File>, ) -> Result { Ok(()) } =20 /// Close a handle to an existing object, associated with a File. - fn close( - _obj: &::Object, - _file: &drm::File<::File>, - ) { - } + fn close(_obj: &DriverObject, _file: &drm::File<::File>) {} } =20 /// Trait that represents a GEM object subtype @@ -82,7 +81,7 @@ extern "C" fn open_callback( let file =3D unsafe { drm::File::<::File>::a= s_ref(raw_file) }; // SAFETY: `open_callback` is specified in the AllocOps structure for = `DriverObject`, // ensuring that `raw_obj` is contained within a `DriverObject` - let obj =3D unsafe { <::Object as IntoGEMObj= ect>::as_ref(raw_obj) }; + let obj =3D unsafe { DriverObject::::as_ref(raw_obj) }; =20 match T::open(obj, file) { Err(e) =3D> e.to_errno(), @@ -99,7 +98,7 @@ extern "C" fn close_callback( =20 // SAFETY: `close_callback` is specified in the AllocOps structure for= `Object`, ensuring // that `raw_obj` is indeed contained within a `Object`. - let obj =3D unsafe { <::Object as IntoGEMObj= ect>::as_ref(raw_obj) }; + let obj =3D unsafe { DriverObject::::as_ref(raw_obj) }; =20 T::close(obj, file); } --=20 2.49.0 From nobody Fri Dec 19 18:42:00 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 779CA2750F9 for ; Fri, 16 May 2025 17:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415473; cv=none; b=ONwW0C4gdpX9RJ/MMWYY1ItGjHzKWw6sTHeuhQsjC8Ix600wsxwrj5wv1kSoYPxGBGlM6i2D8meqXGCbttXUsQjSc94QBL/MMrnLx5+XnCCgVk5+oa4jpuCf1mtXGHbhIyCwJCccjQzCyoFl3kLHmeL0UIupA5jDbXTg7pAbMcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415473; c=relaxed/simple; bh=n8gQ3ci7/HccJRaQ1YFW2NrrriSROfbDAOvRcFPN1jg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EaVhs7gD7zq4UoWkyR+yx49E1c/BROWI/UIwoFZIYMwMqC8zLubQ1Y7gDxK/OQCOGIfSYwSTHWtL7uvdfzrL2UnVobZCwI/D5x76BJDwP308Eqb9ldVnBcs5RMn2241pxOk4EOKcTIrwvYPFPtFXQBJkkNrBzLu/g0515bCFvDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HXnvrgfU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HXnvrgfU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747415469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BurJjKs9pzCfRcZrN7FMvrlgbm4PDmTtPhaZqqv4ewc=; b=HXnvrgfUp+OAbzU4TQwKNoNvwSfq2Gf1EwES8n6eotsNFRxu5ukrVozUrO67/a8B5GBymN HdsfljTaPffNlsSncu82TBOiansE298q1SNNMyVxCj3ZeKpliSw9WLhy/8y0Hu8DiM2dMT jQFTLcW56Jg4JqUrhpEnQJCQkb/gf78= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-444-EtoQMW1HOhuyezN1Q6cgpg-1; Fri, 16 May 2025 13:11:03 -0400 X-MC-Unique: EtoQMW1HOhuyezN1Q6cgpg-1 X-Mimecast-MFC-AGG-ID: EtoQMW1HOhuyezN1Q6cgpg_1747415460 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6FF69195608E; Fri, 16 May 2025 17:11:00 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.82.40]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1178419560B2; Fri, 16 May 2025 17:10:55 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Asahi Lina , Alyssa Rosenzweig Subject: [PATCH v2 3/4] rust: drm: gem: Add ObjectFile type alias Date: Fri, 16 May 2025 13:09:18 -0400 Message-ID: <20250516171030.776924-4-lyude@redhat.com> In-Reply-To: <20250516171030.776924-1-lyude@redhat.com> References: <20250516171030.776924-1-lyude@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Just to reduce the clutter with the File<=E2=80=A6> types in gem.rs. Signed-off-by: Lyude Paul --- rust/kernel/drm/gem/mod.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index c17b36948bae3..2b81298d29765 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -17,6 +17,13 @@ /// A type alias for the Object type in use by a [`drm::Driver`]. pub type DriverObject =3D <::Driver as drm::Driv= er>::Object; =20 +/// A type alias for retrieving a [`Driver`]s [`DriverFile`] implementatio= n from its +/// [`DriverObject`] implementation. +/// +/// [`Driver`]: drm::Driver +/// [`DriverFile`]: drm::file::DriverFile +pub type ObjectFile =3D drm::File<<::Driver as d= rm::Driver>::File>; + /// GEM object functions, which must be implemented by drivers. pub trait BaseDriverObject: Sync + Send + Sized { /// Parent `Driver` for this object. @@ -26,15 +33,12 @@ pub trait BaseDriverObject: Sync + Send + Sized { fn new(dev: &drm::Device, size: usize) -> impl PinInit; =20 /// Open a new handle to an existing object, associated with a File. - fn open( - _obj: &DriverObject, - _file: &drm::File<::File>, - ) -> Result { + fn open(_obj: &DriverObject, _file: &ObjectFile) -> Result= { Ok(()) } =20 /// Close a handle to an existing object, associated with a File. - fn close(_obj: &DriverObject, _file: &drm::File<::File>) {} + fn close(_obj: &DriverObject, _file: &ObjectFile) {} } =20 /// Trait that represents a GEM object subtype @@ -78,7 +82,8 @@ extern "C" fn open_callback( raw_file: *mut bindings::drm_file, ) -> core::ffi::c_int { // SAFETY: `open_callback` is only ever called with a valid pointer to= a `struct drm_file`. - let file =3D unsafe { drm::File::<::File>::a= s_ref(raw_file) }; + let file =3D unsafe { ObjectFile::::as_ref(raw_file) }; + // SAFETY: `open_callback` is specified in the AllocOps structure for = `DriverObject`, // ensuring that `raw_obj` is contained within a `DriverObject` let obj =3D unsafe { DriverObject::::as_ref(raw_obj) }; @@ -94,7 +99,7 @@ extern "C" fn close_callback( raw_file: *mut bindings::drm_file, ) { // SAFETY: `open_callback` is only ever called with a valid pointer to= a `struct drm_file`. - let file =3D unsafe { drm::File::<::File>::a= s_ref(raw_file) }; + let file =3D unsafe { ObjectFile::::as_ref(raw_file) }; =20 // SAFETY: `close_callback` is specified in the AllocOps structure for= `Object`, ensuring // that `raw_obj` is indeed contained within a `Object`. @@ -125,7 +130,7 @@ fn size(&self) -> usize { =20 /// Creates a new handle for the object associated with a given `File` /// (or returns an existing one). - fn create_handle(&self, file: &drm::File<= ::File>) -> Result + fn create_handle(&self, file: &ObjectFile) -> Result where Self: BaseDriverObject, { @@ -138,10 +143,7 @@ fn create_handle(&self, file: &drm::File<::File>) - } =20 /// Looks up an object by its handle for a given `File`. - fn lookup_handle( - file: &drm::File<::File>, - handle: u32, - ) -> Result> + fn lookup_handle(file: &ObjectFile, handle: u32) -> Result> where Self: BaseDriverObject, { --=20 2.49.0 From nobody Fri Dec 19 18:42:00 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 76996274650 for ; Fri, 16 May 2025 17:11:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415478; cv=none; b=t+w9dxaLWgvu5y80pqw+zWkE3OEpmzpPWs6RQbiGSbD3cT1sZ397HZDvgaYMXJjPXS0dwkdN0vKbqMbpLX2ZB0FdxkL9U1YD4m3YKJP+OX1Vtq4XJfd1KZ0ak6tZh3z3Du435KQFOZCVN06vKfhJlLbBWmf/K18QVabnujSo5bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747415478; c=relaxed/simple; bh=++Sn/E/ERyIr2ZHwWqCrCG0HJR81HJ7AfG16tP+/cHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pWfNoYWpuNXc1yYsvg/WSycdWwCtlcNoznOSk1fj0jtLycmXA52a6Tx9CiPZrZ9EW0xVFHF2wPIgCcXDLKjeyaNeig530BCB3cE2PUSHPYYItcFbzo3zKTRq2ApPp/UYvQs25UDPlHL8m/TOhEYhZ7iLOr6RIaAIeAzcwEgn0OM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UUPuTtGK; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UUPuTtGK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747415474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z0Nr+NnfMtMkinmvD4MzEi3V4QHubCSKas4B2jlH/C4=; b=UUPuTtGKWPvbJzjKp3R+6UK4taiywyMIcBpJvqT+fTaiXlZQi04+HFycRipdJ+VsqX9G5z oMmWU5/QFvbs3q6Vp9wYU1e7aVwnVr8F4efn7bDcwMCiT2QTGTUaKh6PIRwwG/e0Mm4mqe ymtRbO+3dquDI+rYtc+e3bWGjG5FDXw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-164-PGDqqXnxMWK2D4ipsJeS-A-1; Fri, 16 May 2025 13:11:11 -0400 X-MC-Unique: PGDqqXnxMWK2D4ipsJeS-A-1 X-Mimecast-MFC-AGG-ID: PGDqqXnxMWK2D4ipsJeS-A_1747415468 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0932619560A3; Fri, 16 May 2025 17:11:08 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.82.40]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 79D2719560AE; Fri, 16 May 2025 17:11:03 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Asahi Lina , Alyssa Rosenzweig Subject: [PATCH v2 4/4] rust: drm: gem: Drop Object::SIZE Date: Fri, 16 May 2025 13:09:19 -0400 Message-ID: <20250516171030.776924-5-lyude@redhat.com> In-Reply-To: <20250516171030.776924-1-lyude@redhat.com> References: <20250516171030.776924-1-lyude@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Drive-by fix, it doesn't seem like anything actually uses this constant anymore. Signed-off-by: Lyude Paul Reviewed-by: Danilo Krummrich --- rust/kernel/drm/gem/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index 2b81298d29765..d0f8da54f49ec 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -12,7 +12,7 @@ prelude::*, types::{ARef, AlwaysRefCounted, Opaque}, }; -use core::{mem, ops::Deref, ptr::NonNull}; +use core::{ops::Deref, ptr::NonNull}; =20 /// A type alias for the Object type in use by a [`drm::Driver`]. pub type DriverObject =3D <::Driver as drm::Driv= er>::Object; @@ -196,9 +196,6 @@ pub struct Object { } =20 impl Object { - /// The size of this object's structure. - pub const SIZE: usize =3D mem::size_of::(); - const OBJECT_FUNCS: bindings::drm_gem_object_funcs =3D bindings::drm_g= em_object_funcs { free: Some(Self::free_callback), open: Some(open_callback::), --=20 2.49.0