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 766fd9905358..9b73c96fbd3a 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 {} + impl Gsp { // Creates an in-place initializer for a `Gsp` manager for `pdev`. pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error> + '_ { -- 2.52.0
