lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250314-meteoric-flounder-of-success-f9c9e1@houat>
Date: Fri, 14 Mar 2025 13:04:20 +0100
From: Maxime Ripard <mripard@...nel.org>
To: Lyude Paul <lyude@...hat.com>
Cc: dri-devel@...ts.freedesktop.org, rust-for-linux@...r.kernel.org, 
	Danilo Krummrich <dakr@...nel.org>, mcanal@...lia.com, Alice Ryhl <aliceryhl@...gle.com>, 
	Simona Vetter <sima@...ll.ch>, Daniel Almeida <daniel.almeida@...labora.com>, 
	Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, 
	Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, 
	Björn Roy Baron <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>, 
	Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>, 
	open list <linux-kernel@...r.kernel.org>
Subject: Re: [RFC v3 12/33] rust: drm/kms: Add RawConnector and
 RawConnectorState

On Wed, Mar 05, 2025 at 05:59:28PM -0500, Lyude Paul wrote:
> Now that we have more then one way to refer to connectors, we also want to
> ensure that any methods which are common to any kind of connector type can
> be used on all connector representations. This is where RawConnector and
> RawConnectorState come in: we implement these traits for any type which
> implements AsRawConnector or AsRawConnectorState respectively.
> 
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
>  rust/kernel/drm/kms/connector.rs | 35 ++++++++++++++++++++++++++++++++
>  rust/kernel/drm/kms/crtc.rs      | 26 ++++++++++++++++++++++--
>  2 files changed, 59 insertions(+), 2 deletions(-)
> 
> diff --git a/rust/kernel/drm/kms/connector.rs b/rust/kernel/drm/kms/connector.rs
> index 244db1cfdc552..0cfe346b4760e 100644
> --- a/rust/kernel/drm/kms/connector.rs
> +++ b/rust/kernel/drm/kms/connector.rs
> @@ -397,6 +397,27 @@ pub fn attach_encoder(&self, encoder: &impl AsRawEncoder) -> Result {
>      }
>  }
>  
> +/// Common methods available on any type which implements [`AsRawConnector`].
> +///
> +/// This is implemented internally by DRM, and provides many of the basic methods for working with
> +/// connectors.
> +pub trait RawConnector: AsRawConnector {
> +    /// Return the index of this DRM connector
> +    #[inline]
> +    fn index(&self) -> u32 {
> +        // SAFETY: The index is initialized by the time we expose DRM connector objects to users,
> +        // and is invariant throughout the lifetime of the connector
> +        unsafe { (*self.as_raw()).index }
> +    }
> +
> +    /// Return the bitmask derived from this DRM connector's index
> +    #[inline]
> +    fn mask(&self) -> u32 {
> +        1 << self.index()
> +    }
> +}
> +impl<T: AsRawConnector> RawConnector for T {}
> +
>  unsafe extern "C" fn connector_destroy_callback<T: DriverConnector>(
>      connector: *mut bindings::drm_connector,
>  ) {
> @@ -536,6 +557,20 @@ pub trait FromRawConnectorState: AsRawConnectorState {
>      unsafe fn from_raw_mut<'a>(ptr: *mut bindings::drm_connector_state) -> &'a mut Self;
>  }
>  
> +/// Common methods available on any type which implements [`AsRawConnectorState`].
> +///
> +/// This is implemented internally by DRM, and provides many of the basic methods for working with
> +/// the atomic state of [`Connector`]s.
> +pub trait RawConnectorState: AsRawConnectorState {
> +    /// Return the connector that this atomic state belongs to.
> +    fn connector(&self) -> &Self::Connector {
> +        // SAFETY: This is guaranteed safe by type invariance, and we're guaranteed by DRM that
> +        // `self.state.connector` points to a valid instance of a `Connector<T>`
> +        unsafe { Self::Connector::from_raw((*self.as_raw()).connector) }
> +    }
> +}
> +impl<T: AsRawConnectorState> RawConnectorState for T {}
> +
>  /// The main interface for a [`struct drm_connector_state`].
>  ///
>  /// This type is the main interface for dealing with the atomic state of DRM connectors. In
> diff --git a/rust/kernel/drm/kms/crtc.rs b/rust/kernel/drm/kms/crtc.rs
> index 95c79ffb584cd..9950b09754072 100644
> --- a/rust/kernel/drm/kms/crtc.rs
> +++ b/rust/kernel/drm/kms/crtc.rs
> @@ -341,6 +341,26 @@ pub unsafe trait ModesettableCrtc: AsRawCrtc {
>      /// The type that should be returned for a CRTC state acquired using this CRTC interface
>      type State: FromRawCrtcState;
>  }
> +
> +/// Common methods available on any type which implements [`AsRawCrtc`].
> +///
> +/// This is implemented internally by DRM, and provides many of the basic methods for working with
> +/// CRTCs.
> +pub trait RawCrtc: AsRawCrtc {
> +    /// Return the index of this CRTC.
> +    fn index(&self) -> u32 {
> +        // SAFETY: The index is initialized by the time we expose Crtc objects to users, and is
> +        // invariant throughout the lifetime of the Crtc
> +        unsafe { (*self.as_raw()).index }
> +    }
> +
> +    /// Return the index of this DRM CRTC in the form of a bitmask.
> +    fn mask(&self) -> u32 {
> +        1 << self.index()
> +    }
> +}
> +impl<T: AsRawCrtc> RawCrtc for T {}
> +
>  unsafe impl Zeroable for bindings::drm_crtc_state {}
>  
>  impl<T: DriverCrtcState> Sealed for CrtcState<T> {}
> @@ -432,8 +452,10 @@ pub trait AsRawCrtcState {
>      }
>  }
>  
> -/// A trait for providing common methods which can be used on any type that can be used as an atomic
> -/// CRTC state.
> +/// Common methods available on any type which implements [`AsRawCrtcState`].
> +///
> +/// This is implemented internally by DRM, and provides many of the basic methods for working with
> +/// the atomic state of [`Crtc`]s.
>  pub trait RawCrtcState: AsRawCrtcState {
>      /// Return the CRTC that owns this state.
>      fn crtc(&self) -> &Self::Crtc {

This looks like unrelated changes, or at least it's not mentioned in the commit log at all.

Maxime

Download attachment "signature.asc" of type "application/pgp-signature" (274 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ