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: <94CA8996-2993-434F-AE98-989D346461FF@collabora.com>
Date: Thu, 28 Nov 2024 10:37:13 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Lyude Paul <lyude@...hat.com>
Cc: dri-devel@...ts.freedesktop.org,
 rust-for-linux@...r.kernel.org,
 Asahi Lina <lina@...hilina.net>,
 Danilo Krummrich <dakr@...nel.org>,
 mcanal@...lia.com,
 airlied@...hat.com,
 zhiw@...dia.com,
 cjia@...dia.com,
 jhubbard@...dia.com,
 Miguel Ojeda <ojeda@...nel.org>,
 Alex Gaynor <alex.gaynor@...il.com>,
 Wedson Almeida Filho <wedsonaf@...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@...sung.com>,
 Alice Ryhl <aliceryhl@...gle.com>,
 Trevor Gross <tmgross@...ch.edu>,
 open list <linux-kernel@...r.kernel.org>
Subject: Re: [WIP RFC v2 21/35] rust: drm/kms: Introduce
 DriverCrtc::atomic_check()

Hi Lyude,

> On 30 Sep 2024, at 20:10, Lyude Paul <lyude@...hat.com> wrote:
> 
> An optional trait method for implementing a CRTC's atomic state check.

A more thorough explanation like you had in your last patch would be nice here.

By `atomic state check` you mean after the state has been duplicated, and mutated, right?

So it’s the stage where we check whether the hardware can accept the new parameters?


> 
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
> rust/kernel/drm/kms/crtc.rs | 46 +++++++++++++++++++++++++++++++++++--
> 1 file changed, 44 insertions(+), 2 deletions(-)
> 
> diff --git a/rust/kernel/drm/kms/crtc.rs b/rust/kernel/drm/kms/crtc.rs
> index 7864540705f76..43c7264402b07 100644
> --- a/rust/kernel/drm/kms/crtc.rs
> +++ b/rust/kernel/drm/kms/crtc.rs
> @@ -27,7 +27,7 @@
>     marker::*,
>     ptr::{NonNull, null, null_mut, addr_of_mut, self},
>     ops::{Deref, DerefMut},
> -    mem,
> +    mem::{self, ManuallyDrop},
> };
> use macros::vtable;
> 
> @@ -82,7 +82,7 @@ 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,
> @@ -117,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: BorrowedCrtcState<'_, CrtcState<Self::State>>,
> +        state: &AtomicStateComposer<Self::Driver>
> +    ) -> Result {
> +        build_error::build_error("This should not be reachable")
> +    }
> }
> 

I am confused. If this is optional, why do we have a default implementation with a build_error ?

> /// The generated C vtable for a [`DriverCrtc`].
> @@ -726,3 +741,30 @@ fn as_raw(&self) -> *mut bindings::drm_crtc_state {
>         )
>     };
> }
> +
> +unsafe extern "C" fn atomic_check_callback<T: DriverCrtc>(
> +    crtc: *mut bindings::drm_crtc,
> +    state: *mut bindings::drm_atomic_state,
> +) -> i32 {
> +    // SAFETY:
> +    // * We're guaranteed `crtc` is of type `Crtc<T>` via type invariants.
> +    // * We're guaranteed by DRM that `crtc` is pointing to a valid initialized state.
> +    let crtc = unsafe { Crtc::from_raw(crtc) };
> +
> +    // SAFETY: DRM guarantees `state` points to a valid `drm_atomic_state`
> +    let state = unsafe {
> +        ManuallyDrop::new(AtomicStateComposer::new(NonNull::new_unchecked(state)))
> +    };
> +

Some comments on why ManuallyDrop is required here would also be useful. Is it related to the
use of ManuallyDrop in the preceding patch?

> +    // SAFETY: Since we are in the atomic update callback, we're guaranteed by DRM that both the old
> +    // and new atomic state are present within `state`
> +    let (old_state, new_state) = unsafe {(
> +        state.get_old_crtc_state(crtc).unwrap_unchecked(),
> +        state.get_new_crtc_state(crtc).unwrap_unchecked(),
> +    )};
> +
> +    from_result(|| {
> +        T::atomic_check(crtc, old_state, new_state, &state)?;
> +        Ok(0)
> +    })
> +}
> -- 
> 2.46.1
> 

— Daniel


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ