On Thu Dec 18, 2025 at 10:39 AM JST, Timur Tabi wrote:
> From: Alexandre Courbot <[email protected]>
>
> `LogBuffer` is the entity we ultimately want to dump through debugfs.
> Provide a simple implementation of `BinaryWriter` for it, albeit it
> might not cut the safety requirements.
>
> Signed-off-by: Alexandre Courbot <[email protected]>
> Signed-off-by: Timur Tabi <[email protected]>
> ---
>  drivers/gpu/nova-core/gsp.rs | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
> index fb6f74797178..860674dac31e 100644
> --- a/drivers/gpu/nova-core/gsp.rs
> +++ b/drivers/gpu/nova-core/gsp.rs
> @@ -3,6 +3,7 @@
>  mod boot;
>  
>  use kernel::{
> +    debugfs,
>      device,
>      dma::{
>          CoherentAllocation,
> @@ -117,6 +118,29 @@ pub(crate) struct Gsp {
>      rmargs: CoherentAllocation<GspArgumentsCached>,
>  }
>  
> +impl debugfs::BinaryWriter for LogBuffer {
> +    fn write_to_slice(
> +        &self,
> +        writer: &mut kernel::uaccess::UserSliceWriter,
> +        offset: &mut kernel::fs::file::Offset,
> +    ) -> Result<usize> {
> +        // SAFETY: This is a debug log buffer. GSP may write concurrently, 
> so the
> +        // snapshot may contain partially-written entries. This is 
> acceptable for
> +        // debugging purposes - users should be aware logs may be slightly 
> garbled
> +        // if read while GSP is actively logging.
> +        let slice = unsafe { self.0.as_slice(0, self.0.count()) }?;
> +
> +        writer.write_slice_file(slice, offset)
> +    }
> +}
> +
> +// SAFETY: `LogBuffer` only provides shared access to the underlying 
> `CoherentAllocation`.
> +// GSP may write to the buffer concurrently regardless of CPU access, so 
> concurrent reads
> +// from multiple CPU threads do not introduce any additional races beyond 
> what already
> +// exists with the device. Reads may observe partially-written log entries, 
> which is
> +// acceptable for debug logging purposes.
> +unsafe impl Sync for LogBuffer {}
> +

Did I actually write all this? I don't have any recollection of
submitting such a patch (and the safety comments don't look like my
style).

Reply via email to