From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC5C02882DE for ; Fri, 3 Jul 2026 03:01:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783047702; cv=none; b=jlEknr3w1nESHEJ0PZ4dyYDNbV9Ih9hCKFpDTZ3DzIkuErQtt+V7cdXBLyNQBi2JrKhFbdv5rdMy4u5q9eZeY2MEyXDBKBHFxmUiEFD3+7Pp601UXZbiFK/tUIRYu2AlKS2y3+zaZwSJXEzCXJdX06my7k1z0CS3LLgk/+MnmV8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783047702; c=relaxed/simple; bh=FGwV/fEV+NMA3Nek9ItcBPqyhi0uH3abcptvhxi9OQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UFeowrOW0L58XedukyKdUHzTwheFPWxOhoBOaGgHCWG41czHKKfgHSzAMYAX+Uf8P+hE91BvmBIfVFhvNbRW64n5UR/MwMLWxx6Jf8v9bp3VYO3o0YoM2Ed6pz6OOrR+GszNGaXI2mWOudO4RMq5QngwHrrTuA9RHx5qC14alyc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fireburn.co.uk; spf=none smtp.mailfrom=fireburn.co.uk; dkim=pass (2048-bit key) header.d=fireburn-co-uk.20251104.gappssmtp.com header.i=@fireburn-co-uk.20251104.gappssmtp.com header.b=SjZkTblf; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fireburn.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=fireburn.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fireburn-co-uk.20251104.gappssmtp.com header.i=@fireburn-co-uk.20251104.gappssmtp.com header.b="SjZkTblf" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-493be1b9564so291955e9.2 for ; Thu, 02 Jul 2026 20:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fireburn-co-uk.20251104.gappssmtp.com; s=20251104; t=1783047698; x=1783652498; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=P/nbseqGkYcWLUDS4YgM1HcuWcHd/PeuOx3gHx4QCk0=; b=SjZkTblffX/4nC403l0/FZxoP5zHVgb/g4UdG1NFcbZMrfsnR9yXgaUNERs01PtAVi 8A5ynQ1lHBwhbXh+NK3lkMUZ0nwya+vORJV07xWWd2dEtfftQWvJKBNrddthohJYEBum Z5kkEVrPqj8hwfH7xTCEMcLwf+K8PhHS1HduwYfDS/pmI2zzpL3JT6m9MvjE+lnPtjIy EMYuv7pMBvEBNAMqo+427q8qTN6xEH1V4460u6jk8ED3qWS4f1MtWXd8be85iKEiBqsE YRkPZhMlsOSv6h7USm0/l/bBtajAEGJOJprJj+HHhqWV+PGqz3OplqPFwuCVABDsvONx wXwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783047698; x=1783652498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=P/nbseqGkYcWLUDS4YgM1HcuWcHd/PeuOx3gHx4QCk0=; b=Zy+PR5lMErHiQE5wWQeg3ZDNXH5C9XIG/j/obTl70Jclz3cOdX4Go20ATrpzG0JTQz rpEXC0+G5ouESmNtm/D1Xs7Q60Le0ImFVd0DgUYXx6FKpzjJ2cw9ERAZDZgJb9wHc+yK MuUgIWggZj90PIOTUCOGIAT0Z42BW7n3E6A+XleeKDV1AEQCZNEQwyDabwCcFwqVw5ae ncQ/KQ9F9ewYJGbQS0EMNraUVHr3B6GsjGMJ/C4lkEFKASWtJ7gv7Tf5DTVk104V7qCJ +E18REeaiv4JqYI/AjeI1snXk1Etc5wrty5DibWfOXR0+jlEsOtNIpZCkoMM1GEavj65 sYXQ== X-Gm-Message-State: AOJu0YzAZwyaqkxzUyOIvAv73yWiuOeLQJB22L5bxwvWYEddfmZPDkYO nnM7140lazaVpSobtSFMbN84Zx71SmUDHEVMDDLwfv4kFxVDdO3OBT32f7Xjg8Wtq6PyMSVzL+Q EieTX6ldG X-Gm-Gg: AfdE7cm61T3ZQs2mBLRvR4Q0mEgUIjHouFrc8MDduL7Dl0lpUSezD3J5y72faJwWbXH XCzwnLWBckwrv4x7nnacPnwNmD+rNsMAcB9KnKUafcW8XLC8iaNV4iTP5jIk2WsMA5Nu39tKgX+ ZVUGXcbpJKgfL7M23GJH0FqnRmHIzfzc6VYRVolV/PCS8c3TDK5hwVMwjbmOKtMkXiFsxhP4FoB /QyVXb6Wy0t1xMdyi61AEY0rN9ATnM4IsmjYzjBF6i+uiECkrRwLTd4HLF5L6i2lldzavRLq409 mJ0Uih1R//SDE9apg0g1o8gX61qG+/TTecazbWLz32qS+C/L0mkAav1T4gO3XEbqDZ7ocoX18OF WfCLKmZLNZe8B+mxV/GcUCu0yvg8J9oD3FJH7wb3A+30ZW8kdvJYK/CwzHf+agSCr0IiV4KcOTt VgZSNSsMWZqdO61dxJmin7R5sZVkVO3vPOzI0vJRBE+6dHVfizC/qytfoM X-Received: by 2002:a05:600c:5391:b0:490:c032:ae92 with SMTP id 5b1f17b1804b1-493c3df2b42mr101737415e9.33.1783047698330; Thu, 02 Jul 2026 20:01:38 -0700 (PDT) Received: from axion.fireburn.co.uk ([137.220.119.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-477db3dbacbsm14466500f8f.4.2026.07.02.20.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jul 2026 20:01:37 -0700 (PDT) From: Mike Lothian To: rust-for-linux@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, David Airlie , Simona Vetter , Danilo Krummrich , Lyude Paul , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , linux-kernel@vger.kernel.org, Mike Lothian Subject: [RFC PATCH v2 03/18] rust: drm: kms: break the Driver* trait well-formedness cycle Date: Fri, 3 Jul 2026 04:00:50 +0100 Message-ID: <20260703030123.2814-4-mike@fireburn.co.uk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260703030123.2814-1-mike@fireburn.co.uk> References: <20260617150232.2210-1-mike@fireburn.co.uk> <20260703030123.2814-1-mike@fireburn.co.uk> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The ported mode-object trait web (KmsDriver / DriverConnector / DriverConnectorState / VblankImpl, ...) is mutually recursive: a Modesettable* impl for Crtc needs ::Crtc: DriverCrtc, which needs ::Crtc, and so on -- an infinite projection regress the trait solver can't terminate on unless the associated-state types are pinned to State. Pin them, add the where-clauses the *StateMutator Deref/DerefMut impls now need once callers pass through the pinned types, and fix a from_opaque copy-paste bug in CrtcStateMutator that was reading Plane's fields instead of Crtc's. This still doesn't build clean: pinning trades the projection regress for a coinductive cycle in the from_opaque-on-state impls, which the current (non-next-gen) trait solver exhausts memory on instead of resolving. See the following commit. Signed-off-by: Mike Lothian Assisted-by: Claude:claude-sonnet-5 [Claude-Code] --- rust/kernel/drm/kms.rs | 28 +++++++++++++--------------- rust/kernel/drm/kms/connector.rs | 27 ++++++++++++++++++++------- rust/kernel/drm/kms/crtc.rs | 31 +++++++++++++++++++++---------- rust/kernel/drm/kms/plane.rs | 27 ++++++++++++++++++++------- rust/kernel/drm/kms/vblank.rs | 5 +++-- 5 files changed, 77 insertions(+), 41 deletions(-) diff --git a/rust/kernel/drm/kms.rs b/rust/kernel/drm/kms.rs index a147276b3412..d07389fd510c 100644 --- a/rust/kernel/drm/kms.rs +++ b/rust/kernel/drm/kms.rs @@ -122,25 +122,23 @@ fn deref(&self) -> &Self::Target { /// [`PhantomData`]: PhantomData #[vtable] pub trait KmsDriver: Driver { - /// The driver's [`DriverConnector`](connector::DriverConnector) implementation. - /// - /// TODO: This will be unneeded once we support multiple `DriverConnector` implementations. - type Connector: connector::DriverConnector; + // The driver's mode-object implementations. Left *unbounded* to break a trait + // well-formedness cycle: the natural bound (`type Crtc: DriverCrtc`, etc.) + // makes every `T: KmsDriver` obligation pull in the mutually-recursive Driver* web, which + // the compiler cannot evaluate (it loops in obligation processing and exhausts memory). The + // `DriverConnector`/`DriverCrtc`/... bounds are required at the use sites as `where`-clauses + // instead (an assumption, not an eagerly WF-checked trait-definition obligation). + // + // TODO: unneeded once we support multiple `Driver*` implementations per driver. + /// The driver's [`DriverConnector`](connector::DriverConnector) implementation. + type Connector; /// The driver's [`DriverPlane`](plane::DriverPlane) implementation. - /// - /// TODO: This will be unneeded once we support multiple `DriverPlane` implementations. - type Plane: plane::DriverPlane; - + type Plane; /// The driver's [`DriverCrtc`](crtc::DriverCrtc) implementation. - /// - /// TODO: This will be unneeded once we support multiple `DriverCrtc` implementations. - type Crtc: crtc::DriverCrtc; - + type Crtc; /// The driver's [`DriverEncoder`](encoder::DriverEncoder) implementation. - /// - /// TODO: This will be unneeded once we support multiple `DriverEncoder` implementations. - type Encoder: encoder::DriverEncoder; + type Encoder; /// Return a [`ModeConfigInfo`] structure for this [`device::Device`]. fn mode_config_info(dev: &Device) -> Result diff --git a/rust/kernel/drm/kms/connector.rs b/rust/kernel/drm/kms/connector.rs index 05ec64cf6fa2..aca7be50e583 100644 --- a/rust/kernel/drm/kms/connector.rs +++ b/rust/kernel/drm/kms/connector.rs @@ -139,7 +139,7 @@ pub trait DriverConnector: Send + Sync + Sized { /// The [`DriverConnectorState`] implementation for this [`DriverConnector`]. /// /// See [`DriverConnectorState`] for more info. - type State: DriverConnectorState; + type State: DriverConnectorState; /// The constructor for creating a [`Connector`] using this [`DriverConnector`] implementation. /// @@ -700,13 +700,17 @@ pub struct ConnectorState { /// [`struct drm_connector`]: srctree/include/drm_connector.h /// [`struct drm_connector_state`]: srctree/include/drm_connector.h pub trait DriverConnectorState: Clone + Default + Sized { - /// The parent [`DriverConnector`]. - type Connector: DriverConnector; + /// The parent [`DriverConnector`]. Unbounded to break the trait WF cycle; the + /// `DriverConnector` bound is required at use sites instead. + type Connector; } impl Sealed for ConnectorState {} -impl AsRawConnectorState for ConnectorState { +impl AsRawConnectorState for ConnectorState +where + T::Connector: DriverConnector, +{ type Connector = Connector; } @@ -720,7 +724,10 @@ unsafe fn as_raw_mut(&mut self) -> &mut bindings::drm_connector_state { } } -impl FromRawConnectorState for ConnectorState { +impl FromRawConnectorState for ConnectorState +where + T::Connector: DriverConnector, +{ unsafe fn from_raw<'a>(ptr: *const bindings::drm_connector_state) -> &'a Self { // Our data layout starts with `bindings::drm_connector_state`. let ptr: *const Self = ptr.cast(); @@ -859,7 +866,10 @@ pub(super) fn new( } } -impl<'a, T: DriverConnectorState> Deref for ConnectorStateMutator<'a, ConnectorState> { +impl<'a, T: DriverConnectorState> Deref for ConnectorStateMutator<'a, ConnectorState> +where + T::Connector: DriverConnector, +{ type Target = T; fn deref(&self) -> &Self::Target { @@ -867,7 +877,10 @@ fn deref(&self) -> &Self::Target { } } -impl<'a, T: DriverConnectorState> DerefMut for ConnectorStateMutator<'a, ConnectorState> { +impl<'a, T: DriverConnectorState> DerefMut for ConnectorStateMutator<'a, ConnectorState> +where + T::Connector: DriverConnector, +{ fn deref_mut(&mut self) -> &mut Self::Target { &mut self.state.inner } diff --git a/rust/kernel/drm/kms/crtc.rs b/rust/kernel/drm/kms/crtc.rs index 0f579dc4ec75..4c6cb6bbdcb8 100644 --- a/rust/kernel/drm/kms/crtc.rs +++ b/rust/kernel/drm/kms/crtc.rs @@ -124,7 +124,7 @@ pub trait DriverCrtc: Send + Sync + Sized { /// The [`DriverCrtcState`] implementation for this [`DriverCrtc`]. /// /// See [`DriverCrtcState`] for more info. - type State: DriverCrtcState; + type State: DriverCrtcState; /// The driver's optional hardware vblank implementation /// @@ -561,10 +561,9 @@ impl Sealed for CrtcState {} /// [`struct drm_crtc`]: srctree/include/drm_crtc.h /// [`struct drm_crtc_state`]: srctree/include/drm_crtc.h pub trait DriverCrtcState: Clone + Default + Unpin { - /// The parent CRTC driver for this CRTC state - type Crtc: DriverCrtc - where - Self: Sized; + /// The parent CRTC driver for this CRTC state. Unbounded to break the trait WF cycle; + /// the `DriverCrtc` bound is required at use sites instead. + type Crtc; } /// The main interface for a [`struct drm_crtc_state`]. @@ -702,11 +701,17 @@ fn as_raw(&self) -> *mut bindings::drm_crtc_state { } } -impl AsRawCrtcState for CrtcState { +impl AsRawCrtcState for CrtcState +where + T::Crtc: DriverCrtc, +{ type Crtc = Crtc; } -impl FromRawCrtcState for CrtcState { +impl FromRawCrtcState for CrtcState +where + T::Crtc: DriverCrtc, +{ unsafe fn from_raw<'a>(ptr: *const bindings::drm_crtc_state) -> &'a Self { // SAFETY: Our data layout starts with `bindings::drm_crtc_state` unsafe { &*(ptr.cast()) } @@ -800,7 +805,7 @@ fn (CrtcStateMutator<'a, OpaqueCrtcState>) -> Self where T: DriverCrtcState; use - T as DriverCrtc, + C as DriverCrtc, D as KmsDriver } } @@ -813,7 +818,10 @@ fn drop(&mut self) { } } -impl<'a, T: DriverCrtcState> Deref for CrtcStateMutator<'a, CrtcState> { +impl<'a, T: DriverCrtcState> Deref for CrtcStateMutator<'a, CrtcState> +where + T::Crtc: DriverCrtc, +{ type Target = T; fn deref(&self) -> &Self::Target { @@ -823,7 +831,10 @@ fn deref(&self) -> &Self::Target { } } -impl<'a, T: DriverCrtcState> DerefMut for CrtcStateMutator<'a, CrtcState> { +impl<'a, T: DriverCrtcState> DerefMut for CrtcStateMutator<'a, CrtcState> +where + T::Crtc: DriverCrtc, +{ fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: Our interface ensures that `self.state.inner` follows rust's data-aliasing rules, // so this is safe diff --git a/rust/kernel/drm/kms/plane.rs b/rust/kernel/drm/kms/plane.rs index 6f547adcfdc9..47e05fe6bee1 100644 --- a/rust/kernel/drm/kms/plane.rs +++ b/rust/kernel/drm/kms/plane.rs @@ -98,7 +98,7 @@ pub trait DriverPlane: Send + Sync + Sized { /// The [`DriverPlaneState`] implementation for this [`DriverPlane`]. /// /// See [`DriverPlaneState`] for more info. - type State: DriverPlaneState; + type State: DriverPlaneState; /// The constructor for creating a [`Plane`] using this [`DriverPlane`] implementation. /// @@ -689,13 +689,17 @@ pub struct PlaneState { /// [`struct drm_plane`]: srctree/include/drm_plane.h /// [`struct drm_plane_state`]: srctree/include/drm_plane.h pub trait DriverPlaneState: Clone + Default + Sized { - /// The type for this driver's drm_plane implementation - type Plane: DriverPlane; + /// The type for this driver's drm_plane implementation. Unbounded to break the trait WF + /// cycle; the `DriverPlane` bound is required at use sites instead. + type Plane; } impl Sealed for PlaneState {} -impl AsRawPlaneState for PlaneState { +impl AsRawPlaneState for PlaneState +where + T::Plane: DriverPlane, +{ type Plane = Plane; } @@ -709,7 +713,10 @@ unsafe fn as_raw_mut(&mut self) -> &mut bindings::drm_plane_state { } } -impl FromRawPlaneState for PlaneState { +impl FromRawPlaneState for PlaneState +where + T::Plane: DriverPlane, +{ unsafe fn from_raw<'a>(ptr: *const bindings::drm_plane_state) -> &'a Self { // Our data layout starts with `bindings::drm_plane_state`. let ptr: *const Self = ptr.cast(); @@ -885,7 +892,10 @@ unsafe fn as_raw_mut(&mut self) -> &mut bindings::drm_plane_state { impl<'a, T: FromRawPlaneState> Sealed for PlaneStateMutator<'a, T> {} -impl<'a, T: DriverPlaneState> Deref for PlaneStateMutator<'a, PlaneState> { +impl<'a, T: DriverPlaneState> Deref for PlaneStateMutator<'a, PlaneState> +where + T::Plane: DriverPlane, +{ type Target = T; fn deref(&self) -> &Self::Target { @@ -893,7 +903,10 @@ fn deref(&self) -> &Self::Target { } } -impl<'a, T: DriverPlaneState> DerefMut for PlaneStateMutator<'a, PlaneState> { +impl<'a, T: DriverPlaneState> DerefMut for PlaneStateMutator<'a, PlaneState> +where + T::Plane: DriverPlane, +{ fn deref_mut(&mut self) -> &mut Self::Target { &mut self.state.inner } diff --git a/rust/kernel/drm/kms/vblank.rs b/rust/kernel/drm/kms/vblank.rs index dc34e02e8ccb..534fd18f63b4 100644 --- a/rust/kernel/drm/kms/vblank.rs +++ b/rust/kernel/drm/kms/vblank.rs @@ -62,8 +62,9 @@ fn get_vblank_timestamp( /// Drivers interested in implementing vblank support should refer to [`VblankSupport`], drivers /// that don't have vblank support can use [`PhantomData`]. pub trait VblankImpl { - /// The parent [`DriverCrtc`]. - type Crtc: DriverCrtc; + /// The parent [`DriverCrtc`]. Unbounded to break the trait WF cycle; the `DriverCrtc` + /// bound is required at use sites instead. + type Crtc; /// The generated [`VblankOps`]. const VBLANK_OPS: VblankOps; -- 2.55.0