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-golden-piculet-of-wholeness-04b4a0@houat>
Date: Fri, 14 Mar 2025 13:21:43 +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 19/33] rust: drm/kms: Add DriverCrtc::atomic_check()

On Wed, Mar 05, 2025 at 05:59:35PM -0500, Lyude Paul wrote:
> An optional trait method for implementing a CRTC's atomic state check.
> 
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> 
> ---
> V3:
> * Document uses of ManuallyDrop
> 
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
>  rust/kernel/drm/kms/atomic.rs |  1 -
>  rust/kernel/drm/kms/crtc.rs   | 55 +++++++++++++++++++++++++++++++++--
>  2 files changed, 52 insertions(+), 4 deletions(-)
> 
> diff --git a/rust/kernel/drm/kms/atomic.rs b/rust/kernel/drm/kms/atomic.rs
> index 3d5c70dbc4274..e0a1b5b860d6f 100644
> --- a/rust/kernel/drm/kms/atomic.rs
> +++ b/rust/kernel/drm/kms/atomic.rs
> @@ -274,7 +274,6 @@ impl<T: KmsDriver> AtomicStateComposer<T> {
>      /// # Safety
>      ///
>      /// The caller guarantees that `ptr` points to a valid instance of `drm_atomic_state`.
> -    #[allow(dead_code)]
>      pub(crate) unsafe fn new(ptr: NonNull<bindings::drm_atomic_state>) -> Self {
>          // SAFETY: see `AtomicStateMutator::from_raw()`
>          Self(unsafe { AtomicStateMutator::new(ptr) })
> diff --git a/rust/kernel/drm/kms/crtc.rs b/rust/kernel/drm/kms/crtc.rs
> index 3b9c9d97fcf24..50f5b68f4a3fe 100644
> --- a/rust/kernel/drm/kms/crtc.rs
> +++ b/rust/kernel/drm/kms/crtc.rs
> @@ -12,7 +12,7 @@
>      alloc::KBox,
>      bindings,
>      drm::device::Device,
> -    error::to_result,
> +    error::{from_result, to_result},
>      init::Zeroable,
>      prelude::*,
>      private::Sealed,
> @@ -21,7 +21,7 @@
>  use core::{
>      cell::{Cell, UnsafeCell},
>      marker::*,
> -    mem,
> +    mem::{self, ManuallyDrop},
>      ops::{Deref, DerefMut},
>      ptr::{addr_of_mut, null, null_mut, NonNull},
>  };
> @@ -78,7 +78,11 @@ pub trait DriverCrtc: Send + Sync + Sized {
>          helper_funcs: bindings::drm_crtc_helper_funcs {
>              atomic_disable: None,
>              atomic_enable: None,
> -            atomic_check: None,
> +            atomic_check: if Self::HAS_ATOMIC_CHECK {
> +                Some(atomic_check_callback::<Self>)
> +            } else {
> +                None
> +            },
>              dpms: None,
>              commit: None,
>              prepare: None,
> @@ -113,6 +117,21 @@ pub trait DriverCrtc: Send + Sync + Sized {
>      ///
>      /// Drivers may use this to instantiate their [`DriverCrtc`] object.
>      fn new(device: &Device<Self::Driver>, args: &Self::Args) -> impl PinInit<Self, Error>;
> +
> +    /// The optional [`drm_crtc_helper_funcs.atomic_check`] hook for this crtc.
> +    ///
> +    /// Drivers may use this to customize the atomic check phase of their [`Crtc`] objects. The
> +    /// result of this function determines whether the atomic check passed or failed.
> +    ///
> +    /// [`drm_crtc_helper_funcs.atomic_check`]: srctree/include/drm/drm_modeset_helper_vtables.h
> +    fn atomic_check(
> +        _crtc: &Crtc<Self>,
> +        _old_state: &CrtcState<Self::State>,
> +        _new_state: CrtcStateMutator<'_, CrtcState<Self::State>>,
> +        _state: &AtomicStateComposer<Self::Driver>,
> +    ) -> Result {
> +        build_error::build_error("This should not be reachable")
> +    }

We've spent an awful lot of time trying to get rid of
old_state/new_state in the atomic hooks, so I'd prefer to not
reintroduce them again in Rust, even more so if you have accessors to go
from AtomicStateComposer to CrtcStateMutator, which I think you do.

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