From: "Danilo Krummrich" <dakr@kernel.org>
To: "Timur Tabi" <ttabi@nvidia.com>
Cc: Gary Guo <gary@garyguo.net>,
rust-for-linux@vger.kernel.org,
Joel Fernandes <joelagnelf@nvidia.com>,
Alexandre Courbot <acourbot@nvidia.com>,
nouveau@lists.freedesktop.org
Subject: Re: [PATCH v3 7/9] gpu: nova-core: implement BinaryWriter for LogBuffer
Date: Thu, 18 Dec 2025 11:18:28 +0100 [thread overview]
Message-ID: <DF19KTQTKOS9.33N1KT9WNLAUO@kernel.org> (raw)
In-Reply-To: <20251218013910.459045-8-ttabi@nvidia.com>
On Thu Dec 18, 2025 at 2:39 AM CET, Timur Tabi wrote:
> From: Alexandre Courbot <acourbot@nvidia.com>
>
> `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 <acourbot@nvidia.com>
> Signed-off-by: Timur Tabi <ttabi@nvidia.com>
> ---
> 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()) }?;
Unfortunately, it's still undefined behavior to create a slice when the backing
buffer can change unexpectedly.
You can use UserSliceWriter::write() instead or add an unsafe method to
UserSliceWriter that takes a raw pointer, length and offset.
Given the context of a debug log buffer, I suggest the former.
> + 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>) -> Result<impl PinInit<Self, Error>> {
> --
> 2.52.0
WARNING: multiple messages have this Message-ID (diff)
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Timur Tabi" <ttabi@nvidia.com>
Cc: "Gary Guo" <gary@garyguo.net>, <rust-for-linux@vger.kernel.org>,
"John Hubbard" <jhubbard@nvidia.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Lyude Paul" <lyude@redhat.com>, <nouveau@lists.freedesktop.org>
Subject: Re: [PATCH v3 7/9] gpu: nova-core: implement BinaryWriter for LogBuffer
Date: Thu, 18 Dec 2025 11:18:28 +0100 [thread overview]
Message-ID: <DF19KTQTKOS9.33N1KT9WNLAUO@kernel.org> (raw)
In-Reply-To: <20251218013910.459045-8-ttabi@nvidia.com>
On Thu Dec 18, 2025 at 2:39 AM CET, Timur Tabi wrote:
> From: Alexandre Courbot <acourbot@nvidia.com>
>
> `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 <acourbot@nvidia.com>
> Signed-off-by: Timur Tabi <ttabi@nvidia.com>
> ---
> 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()) }?;
Unfortunately, it's still undefined behavior to create a slice when the backing
buffer can change unexpectedly.
You can use UserSliceWriter::write() instead or add an unsafe method to
UserSliceWriter that takes a raw pointer, length and offset.
Given the context of a debug log buffer, I suggest the former.
> + 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>) -> Result<impl PinInit<Self, Error>> {
> --
> 2.52.0
next prev parent reply other threads:[~2025-12-18 14:55 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 1:39 [PATCH v3 0/9] gpu: nova-core: expose the logging buffers via debugfs Timur Tabi
2025-12-18 1:39 ` [PATCH v3 1/9] rust: pci: add PCI device name method Timur Tabi
2025-12-18 8:05 ` Alice Ryhl
2025-12-18 8:05 ` Alice Ryhl
2025-12-18 8:55 ` Danilo Krummrich
2025-12-18 8:55 ` Danilo Krummrich
2025-12-18 10:09 ` Miguel Ojeda
2025-12-18 10:09 ` Miguel Ojeda
2025-12-18 1:39 ` [PATCH v3 2/9] rust: debugfs: add lookup contructor Timur Tabi
2025-12-18 9:40 ` Danilo Krummrich
2025-12-18 9:40 ` Danilo Krummrich
2025-12-18 18:00 ` Matthew Maurer
2025-12-18 18:00 ` Matthew Maurer
2025-12-18 1:39 ` [PATCH v3 3/9] rust: debugfs: add Dir::empty() for no-op directory handle Timur Tabi
2025-12-18 1:39 ` [PATCH v3 4/9] rust: debugfs: fix Dir::scope() to not borrow self for returned lifetime Timur Tabi
2025-12-18 17:55 ` Matthew Maurer
2025-12-18 17:55 ` Matthew Maurer
2025-12-18 1:39 ` [PATCH v3 5/9] gpu: nova-core: Replace module_pci_driver! with explicit module init Timur Tabi
2025-12-18 9:01 ` Danilo Krummrich
2025-12-18 9:01 ` Danilo Krummrich
2025-12-18 1:39 ` [PATCH v3 6/9] gpu: nova-core: create debugfs root when driver loads Timur Tabi
2025-12-18 10:10 ` Danilo Krummrich
2025-12-18 10:10 ` Danilo Krummrich
2025-12-18 1:39 ` [PATCH v3 7/9] gpu: nova-core: implement BinaryWriter for LogBuffer Timur Tabi
2025-12-18 10:18 ` Danilo Krummrich [this message]
2025-12-18 10:18 ` Danilo Krummrich
2025-12-18 11:14 ` Alexandre Courbot
2025-12-18 1:39 ` [PATCH v3 8/9] gpu: nova-core: use pin projection in method boot() Timur Tabi
2025-12-18 1:39 ` [PATCH v3 9/9] gpu: nova-core: create GSP-RM logging buffers debugfs entries Timur Tabi
2025-12-21 10:05 ` kernel test robot
2025-12-18 8:07 ` [PATCH v3 0/9] gpu: nova-core: expose the logging buffers via debugfs Alice Ryhl
2025-12-18 8:07 ` Alice Ryhl
2025-12-18 8:44 ` Danilo Krummrich
2025-12-18 8:44 ` Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DF19KTQTKOS9.33N1KT9WNLAUO@kernel.org \
--to=dakr@kernel.org \
--cc=acourbot@nvidia.com \
--cc=gary@garyguo.net \
--cc=joelagnelf@nvidia.com \
--cc=nouveau@lists.freedesktop.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=ttabi@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.