From nobody Wed Sep 10 01:54:43 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 97D0131C58B for ; Mon, 8 Sep 2025 18:53:01 +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=1757357584; cv=none; b=M5h4p0/QNAnFgkonL+pQEuFDp/cv3ykc/PQwxDD3FksYlZexr3Vv7GuduxSqq93q5SWyNGv2yQnRJ/q4iyddAb23B2PMCbTMBRa69q+Ba5OHhjEEUvakUNc5cP3xQ8guZg/6lSfcnCvkoFUlylN4NfuLXByDT6uD5Wb05Ry/Qok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757357584; c=relaxed/simple; bh=eVSoTsQp3yFCMYYNCxpwK17TY0tP08a+zC/Nz6PrZSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D+IkiXKSFqkkc5uq3tUmca2ukmxCWfCFq9hTCXSTwUZOMqigb/m2sT9gzK99noSnebIWoyY//uAZI4Rpa98vouDAHugSMw+hSHjfjXZ0qRGvyr66nz1IskAxcubmoEr8m1MCHpKaOuKQX9oxXeIzdYCSscuwvibaeIvHN3TgHkY= 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=WluMYyEU; 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="WluMYyEU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757357580; 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=qPQdxCXlJ3BtdYSxtBqdEdPnLwMmTLtCh9wXHQctdug=; b=WluMYyEU2tdarkVT3N46qJ5amgaSVhQP3XC0F5iJNa+fXTH8S3yzmjUS6UG8gCdND2dJ6F cuA2nZ/Sp69HWKMYAcSbhYFK40++NneqYYLsx44EeK2SkNNYrK4TifAXypgJasqlc4RBUc qUB9NHq+SLoiYo62xQBxOpYJEmNIlN4= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-6dw4KfkwNn-1aVtyN_z8gA-1; Mon, 08 Sep 2025 14:52:56 -0400 X-MC-Unique: 6dw4KfkwNn-1aVtyN_z8gA-1 X-Mimecast-MFC-AGG-ID: 6dw4KfkwNn-1aVtyN_z8gA_1757357574 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6B0A71800350; Mon, 8 Sep 2025 18:52:53 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.64.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7A8E718003FC; Mon, 8 Sep 2025 18:52:48 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Cc: Daniel Almeida , Danilo Krummrich , 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 , Trevor Gross , Asahi Lina , nouveau@lists.freedesktop.org (open list:DRM DRIVER FOR NVIDIA GPUS [RUST]) Subject: [PATCH v4 1/3] rust: drm: gem: Simplify use of generics Date: Mon, 8 Sep 2025 14:46:36 -0400 Message-ID: <20250908185239.135849-2-lyude@redhat.com> In-Reply-To: <20250908185239.135849-1-lyude@redhat.com> References: <20250908185239.135849-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.4.1 on 10.30.177.93 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 * Add AllocImpl::Driver, which we can use as a binding to figure out the correct File type for BaseObject 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 Reviewed-by: Daniel Almeida Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl --- 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. V3: * Fix nova compilation * Also, add an associated driver type to AllocImpl - as we still need the current driver accessible from BaseObject so that we can use the driver's various associated types, like File * Add missing Object =3D Self constraint to type bounds for create_handle, lookup_handle. I forgot that if drivers can have private gem objects with a different data layout, we can only guarantee gem objects with handles are of the same gem object type as the main one in use by the driver. V4: * Add to DriverFile bounds for create_handle(), lookup_handle() drivers/gpu/drm/nova/gem.rs | 8 ++-- rust/kernel/drm/driver.rs | 3 ++ rust/kernel/drm/gem/mod.rs | 77 ++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/nova/gem.rs b/drivers/gpu/drm/nova/gem.rs index cd82773dab92c..2760ba4f3450b 100644 --- a/drivers/gpu/drm/nova/gem.rs +++ b/drivers/gpu/drm/nova/gem.rs @@ -16,16 +16,14 @@ #[pin_data] pub(crate) struct NovaObject {} =20 -impl gem::BaseDriverObject> for NovaObject { +impl gem::DriverObject for NovaObject { + type Driver =3D NovaDriver; + fn new(_dev: &NovaDevice, _size: usize) -> impl PinInit { try_pin_init!(NovaObject {}) } } =20 -impl gem::DriverObject for NovaObject { - type Driver =3D NovaDriver; -} - impl NovaObject { /// Create a new DRM GEM object. pub(crate) fn new(dev: &NovaDevice, size: usize) -> Result>> { diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index fe7e8d06961aa..dae0f4d1bbe3c 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -86,6 +86,9 @@ pub struct AllocOps { =20 /// Trait for memory manager implementations. Implemented internally. pub trait AllocImpl: super::private::Sealed + drm::gem::IntoGEMObject { + /// The [`Driver`] implementation for this [`AllocImpl`]. + type Driver: drm::Driver; + /// The C callback operations for this memory manager. const ALLOC_OPS: AllocOps; } diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index b71821cfb5eaa..f5b19865d7453 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 DriverObject: 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>::= from_raw(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>::from_raw(raw_obj) - }; + let file =3D unsafe { drm::File::<::File>::f= rom_raw(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>::from_raw(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>::= from_raw(raw_file) - }; + let file =3D unsafe { drm::File::<::File>::f= rom_raw(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>::from_raw(raw_obj) - }; + let obj =3D unsafe { <::Object as IntoGEMObj= ect>::from_raw(raw_obj) }; =20 T::close(obj, file); } =20 impl IntoGEMObject for Object { - type Driver =3D T::Driver; - fn as_raw(&self) -> *mut bindings::drm_gem_object { self.obj.get() } @@ -141,10 +126,12 @@ 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) -> Result + where + Self: AllocImpl, + D: drm::Driver, + F: drm::file::DriverFile, + { let mut handle: u32 =3D 0; // SAFETY: The arguments are all valid per the type invariants. to_result(unsafe { @@ -154,10 +141,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>, - handle: u32, - ) -> Result> { + fn lookup_handle(file: &drm::File, handle: u32) -> Result> + where + Self: AllocImpl, + D: drm::Driver, + F: drm::file::DriverFile, + { // 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() { @@ -212,8 +201,8 @@ impl Object { =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, @@ -296,6 +285,8 @@ fn deref(&self) -> &Self::Target { } =20 impl AllocImpl for Object { + type Driver =3D T::Driver; + const ALLOC_OPS: AllocOps =3D AllocOps { gem_create_object: None, prime_handle_to_fd: None, --=20 2.51.0 From nobody Wed Sep 10 01:54:43 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 2C0573218CE for ; Mon, 8 Sep 2025 18:53:08 +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=1757357590; cv=none; b=D4GyUAli9lY1DCT+eui12+UcRMoa1LOYCYk7kZNAFZOwnyYVnR/drYGMARV2PeThgONKs/FIkmsRn15TWCBC0p71vxQCKmub9U2IqjXIB2zX6vQzN90z64S1gtoENVX21ddCC48N0QPDWHsyFpXDiuo+4Xio3J1BpZj0VTNmVKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757357590; c=relaxed/simple; bh=H/FSWL63xIZKSCywlgkiG5ai9QZb7obJazmxalID+Eg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PEDXO9LuYpQkNIPToIuQm+8rBtaK/8FMPIwYHrhDjE6w/il8clHkFJLx4af2VztlXY9oIZ7xCdkZELSzZlYOHbtqMJyDYocifUZwRt/TJDz+I72gdYzMIb1C0U4fsXaRt8smStcNOnyXfXr9IHZVsNNzEgPclLoPIHFYQ1psZrg= 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=QmWqxyUz; 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="QmWqxyUz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757357588; 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=opAGkIhbvhKIewW0fRaLtnVMRxdcOzp+hJRom4X2iRs=; b=QmWqxyUzp9NB8yIIVciia7dXgA3XcUGK1JH+d88ms88GXybwFquGPqMC3j33v/9Rox7d7C CU67RxTxgY5WwLWovrVvBmK0XWc17yW0X3hobAdZm+tcI6nfLk/wQjWhkLmun/ia7yF8Su 9Gm5ua56nYZx5WSx4vo8j9mvBLw4hGA= 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-614-0w0UybFCMcy3QK-zazC4fA-1; Mon, 08 Sep 2025 14:53:04 -0400 X-MC-Unique: 0w0UybFCMcy3QK-zazC4fA-1 X-Mimecast-MFC-AGG-ID: 0w0UybFCMcy3QK-zazC4fA_1757357582 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 183B0195609F; Mon, 8 Sep 2025 18:53:02 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.64.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 116BB1800446; Mon, 8 Sep 2025 18:52:56 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Cc: Daniel Almeida , 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 , Trevor Gross , Danilo Krummrich , Asahi Lina Subject: [PATCH v4 2/3] rust: drm: gem: Add DriverFile type alias Date: Mon, 8 Sep 2025 14:46:37 -0400 Message-ID: <20250908185239.135849-3-lyude@redhat.com> In-Reply-To: <20250908185239.135849-1-lyude@redhat.com> References: <20250908185239.135849-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.4.1 on 10.30.177.93 Just to reduce the clutter with the File<=E2=80=A6> types in gem.rs. Signed-off-by: Lyude Paul Reviewed-by: Daniel Almeida Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl --- V3: * Rename ObjectFile to DriverFile rust/kernel/drm/gem/mod.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index f5b19865d7453..ead723980b276 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -14,6 +14,13 @@ }; use core::{mem, ops::Deref, ptr::NonNull}; =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 DriverFile =3D drm::File<<::Driver as drm::= Driver>::File>; + /// GEM object functions, which must be implemented by drivers. pub trait DriverObject: Sync + Send + Sized { /// Parent `Driver` for this object. @@ -23,19 +30,12 @@ pub trait DriverObject: 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: &::Object, - _file: &drm::File<::File>, - ) -> Result { + fn open(_obj: &::Object, _file: &DriverFi= le) -> 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: &::Object, _file: &DriverF= ile) {} } =20 /// Trait that represents a GEM object subtype @@ -79,7 +79,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>::f= rom_raw(raw_file) }; + let file =3D unsafe { DriverFile::::from_raw(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>::from_raw(raw_obj) }; @@ -95,7 +96,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>::f= rom_raw(raw_file) }; + let file =3D unsafe { DriverFile::::from_raw(raw_file) }; =20 // SAFETY: `close_callback` is specified in the AllocOps structure for= `Object`, ensuring // that `raw_obj` is indeed contained within a `Object`. --=20 2.51.0 From nobody Wed Sep 10 01:54:43 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 C6B1E31C599 for ; Mon, 8 Sep 2025 18:53:19 +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=1757357601; cv=none; b=c2N9QQFtBKbP+rKr8D8DawQ+lMPTNlvi4UBJ/RKJwHo14LpLWtKlEe3GqHb5VUGiKaI5/awNN/D/BOSbhMCtldaYg7gM4Uw+sE/Xta7jvPtA2ezjhovs5Iaug/CVmklU1W1nqOdAVBExSzTPnTFXY4vaxoMd/ykD7bSedVp//Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757357601; c=relaxed/simple; bh=t0DySZDoZrCvAVH1zss8yS+r/+N0+AJYcWf53CpQ91o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qENtdtEkdiRFSKElmcliH/Bqml958xwr5nYaWuIA4hsjNtQTBLyZ2R4XMCvnLSXp5qoCwvdqkb4Qxt8FbTSufs0Zs6QRO5UB6i2Ps1hBUwDjSuQw+Ylmo8Q1DLRHP504NvL+vh2hl4z5bdug/F764RH63GsnLJd8x8DB7+6ZnsA= 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=FchzLYEV; 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="FchzLYEV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757357598; 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=Yth/iNP2a9kIBqrpNP1SCw4ew99ds4JSecEtwRjN4t4=; b=FchzLYEVM/T1VBJO39xc5Kk1iVoxGGvKre28I6TN2bb05pZl/CUYIMEN0CHvudIv/hgBB6 cvZ/k/LDduPRG3+ZcKOoLTyAM+taM5D1N7TKyy9uoLQILbmKJDTstXC5HpXafIcoJLPw19 v0r3hnXcrUhcQo8WnAel25p+xQCjbcY= 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-517-JUvqPGVbPMWXH18TqaEzhw-1; Mon, 08 Sep 2025 14:53:13 -0400 X-MC-Unique: JUvqPGVbPMWXH18TqaEzhw-1 X-Mimecast-MFC-AGG-ID: JUvqPGVbPMWXH18TqaEzhw_1757357590 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 B66A319560B7; Mon, 8 Sep 2025 18:53:10 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.64.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BC4AE1800446; Mon, 8 Sep 2025 18:53:05 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Cc: Danilo Krummrich , Daniel Almeida , 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 , Trevor Gross , Asahi Lina Subject: [PATCH v4 3/3] rust: drm: gem: Drop Object::SIZE Date: Mon, 8 Sep 2025 14:46:38 -0400 Message-ID: <20250908185239.135849-4-lyude@redhat.com> In-Reply-To: <20250908185239.135849-1-lyude@redhat.com> References: <20250908185239.135849-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.4.1 on 10.30.177.93 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 Reviewed-by: Daniel Almeida Reviewed-by: Alice Ryhl --- 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 ead723980b276..fd872de3b6695 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 retrieving a [`Driver`]s [`DriverFile`] implementatio= n from its /// [`DriverObject`] implementation. @@ -197,9 +197,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.51.0