From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B7A6AD6D230 for ; Thu, 18 Dec 2025 14:55:47 +0000 (UTC) Received: from kara.freedesktop.org (unknown [131.252.210.166]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8FDD710EA3B; Thu, 18 Dec 2025 14:55:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="Y/THVjnM"; dkim-atps=neutral Received: from kara.freedesktop.org (localhost [127.0.0.1]) by kara.freedesktop.org (Postfix) with ESMTP id A79AE4562F; Thu, 18 Dec 2025 14:48:16 +0000 (UTC) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=lists.freedesktop.org; s=20240201; t=1766069296; b=qzYfi7JqFrlqRyIqm55diN7RjketbpyfjMwXituu36i6+1ng08O3wTik67gT+QJMCzSCH txs5i3x4CPUDswIzYNAom4193aQAGhQ1GEhx2zi049vC1mejPBcj9FH52rwQkgRSgXWjIp2 jAAjwbP6ouT7cU5NT0wEpGyBaHC9xsDzGPSy23BjPF9Zl72z0OMpyMtsdqy+FUWuZGRGe6w UkP9mGiWevLVhyFWWlhkZUTxhUlyq1W+T1/wUf+cqPhlVsf8E2pzrugFcTzkzC4DYfeG1AP qpDn4cVIoIUZXCapo3nwT/CmWMCL7f9Skf4fOFOC00KEJZ47rVluu2trEKLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.freedesktop.org; s=20240201; t=1766069296; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=xfZOi1vmhtXMCOEPZBKzPiDA4Vj87I28C4MuvUCCDv4=; b=xf1yVJMt89UKFxxj5ZhM/Oj0sgaZOWcpNokEk+v1gHSqwkvfcWY9LU339+ML3P6np/8MB ZTbEUGD5rUnCxJNCtvHo3D0ftJtDM2fO/D3t+mQCl8iaZZ+PFHmgjdGDEVwcCs5XSbah0+K 5LWkG7p7OXyD/dLU7/igDHKSQezMEq+olFXuLIAsj+vUoHh79QQy6CddeEKWg3D3A0i4cWA PaD5rFLfNWZUnM2SfWIU/8aiwbHDtBWFPxxIkO8XiOGmMHRvjCA/dHDLUhrLH0Ez/O6N5NW 7qjiSoqPzqK0T0Rrl1IUk5kbcceUxVfTwnnOYynzI+LPgyGdaaGx4DZdYegA== ARC-Authentication-Results: i=1; mail.freedesktop.org; dkim=pass header.d=kernel.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=kernel.org policy.dmarc=quarantine Authentication-Results: mail.freedesktop.org; dkim=pass header.d=kernel.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=kernel.org policy.dmarc=quarantine Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by kara.freedesktop.org (Postfix) with ESMTPS id 0C4E345687 for ; Thu, 18 Dec 2025 10:11:02 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5E09310E3A4 for ; Thu, 18 Dec 2025 10:18:32 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id F1B9A40BB4; Thu, 18 Dec 2025 10:18:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56396C4CEFB; Thu, 18 Dec 2025 10:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766053111; bh=I/6kvKM9p8XY3+0CKtKDEdvBP+NxnC4Rq9qspP9kerk=; h=Date:To:From:Subject:Cc:References:In-Reply-To:From; b=Y/THVjnM1abEaJR+U1aTdEdX6K+6AeFV/du+Aq+CHT8c4CoEXDkcm9Cf+PPuz3rJ9 5B9eL9CTda38tTo++OYWq1sW1R3wemxZgUw/WqAsats/psF7yQx8F85pxfo8pXLyJ6 WLvCsdMVHluBfiiFMpOhk2X9jh96oBfWYU+xw8v/cxesibp7OEOAc1Ssdo5WcdTte2 keTw0LWLTIQMt6Sqes/2SirtQyuT6tyMuQKkwz7PjFO/sxx/9mNneI5xH87FBBivUy a+g2rLs4k45DiTXqcSQLMBbs4b6tMDicQCcP0/W6EX8ZjrXlQSFFE4M4tuikdro2H8 yiGHFbJU4m/Wg== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 18 Dec 2025 11:18:28 +0100 Message-Id: To: "Timur Tabi" From: "Danilo Krummrich" Subject: Re: [PATCH v3 7/9] gpu: nova-core: implement BinaryWriter for LogBuffer References: <20251218013910.459045-1-ttabi@nvidia.com> <20251218013910.459045-8-ttabi@nvidia.com> In-Reply-To: <20251218013910.459045-8-ttabi@nvidia.com> X-MailFrom: dakr@kernel.org X-Mailman-Rule-Hits: implicit-dest X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header Message-ID-Hash: ZC465HFREFFLKLBJ75URF6TZAYL2RHF2 X-Message-ID-Hash: ZC465HFREFFLKLBJ75URF6TZAYL2RHF2 X-Mailman-Approved-At: Thu, 18 Dec 2025 14:48:10 +0000 CC: Gary Guo , rust-for-linux@vger.kernel.org, Joel Fernandes , Alexandre Courbot , nouveau@lists.freedesktop.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: Nouveau development list Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu Dec 18, 2025 at 2:39 AM CET, Timur Tabi wrote: > From: Alexandre Courbot > > `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 > Signed-off-by: Timur Tabi > --- > 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; > =20 > use kernel::{ > + debugfs, > device, > dma::{ > CoherentAllocation, > @@ -117,6 +118,29 @@ pub(crate) struct Gsp { > rmargs: CoherentAllocation, > } > =20 > +impl debugfs::BinaryWriter for LogBuffer { > + fn write_to_slice( > + &self, > + writer: &mut kernel::uaccess::UserSliceWriter, > + offset: &mut kernel::fs::file::Offset, > + ) -> Result { > + // SAFETY: This is a debug log buffer. GSP may write concurrentl= y, so the > + // snapshot may contain partially-written entries. This is accep= table for > + // debugging purposes - users should be aware logs may be slight= ly garbled > + // if read while GSP is actively logging. > + let slice =3D unsafe { self.0.as_slice(0, self.0.count()) }?; Unfortunately, it's still undefined behavior to create a slice when the bac= king 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 `Co= herentAllocation`. > +// GSP may write to the buffer concurrently regardless of CPU access, so= concurrent reads > +// from multiple CPU threads do not introduce any additional races beyon= d what already > +// exists with the device. Reads may observe partially-written log entri= es, 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) -> Result> { > --=20 > 2.52.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F1853446BB for ; Thu, 18 Dec 2025 10:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766053112; cv=none; b=FuIO/+StQFHqQd1YZNC0MYA011+oRb5qj5d2zSA7hvSgrIwQRWtaPwSwb65ZLBggD+YfCE1A479w00p2+j8SV5IQxlDwULXWz4hUGT4OAqY7GiN9M3p79CbwPhL+DRXcDg66hIPHuzvxeHLZcFes6Hi89vaZoyAsg+2Ko1MUBqY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766053112; c=relaxed/simple; bh=I/6kvKM9p8XY3+0CKtKDEdvBP+NxnC4Rq9qspP9kerk=; h=Mime-Version:Content-Type:Date:Message-Id:To:From:Subject:Cc: References:In-Reply-To; b=EkNFZMP3/qQYzfh+Mw+VTu5h3EvmQuvMb+ndqrUiKuc2XiMKDNaNs1AeqNfTN//9Qq/Slv8eBTRMxmQVl+EIoBqMT77NknRGkNhw8K41abVwCakISwc4ijwsC9FNubKJXylSSCl/2qFfzophth/85J0kr+OB6T3YNbjiuIliKAo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y/THVjnM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Y/THVjnM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56396C4CEFB; Thu, 18 Dec 2025 10:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766053111; bh=I/6kvKM9p8XY3+0CKtKDEdvBP+NxnC4Rq9qspP9kerk=; h=Date:To:From:Subject:Cc:References:In-Reply-To:From; b=Y/THVjnM1abEaJR+U1aTdEdX6K+6AeFV/du+Aq+CHT8c4CoEXDkcm9Cf+PPuz3rJ9 5B9eL9CTda38tTo++OYWq1sW1R3wemxZgUw/WqAsats/psF7yQx8F85pxfo8pXLyJ6 WLvCsdMVHluBfiiFMpOhk2X9jh96oBfWYU+xw8v/cxesibp7OEOAc1Ssdo5WcdTte2 keTw0LWLTIQMt6Sqes/2SirtQyuT6tyMuQKkwz7PjFO/sxx/9mNneI5xH87FBBivUy a+g2rLs4k45DiTXqcSQLMBbs4b6tMDicQCcP0/W6EX8ZjrXlQSFFE4M4tuikdro2H8 yiGHFbJU4m/Wg== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 18 Dec 2025 11:18:28 +0100 Message-Id: To: "Timur Tabi" From: "Danilo Krummrich" Subject: Re: [PATCH v3 7/9] gpu: nova-core: implement BinaryWriter for LogBuffer Cc: "Gary Guo" , , "John Hubbard" , "Joel Fernandes" , "Alexandre Courbot" , "Lyude Paul" , References: <20251218013910.459045-1-ttabi@nvidia.com> <20251218013910.459045-8-ttabi@nvidia.com> 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 > > `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 > Signed-off-by: Timur Tabi > --- > 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; > =20 > use kernel::{ > + debugfs, > device, > dma::{ > CoherentAllocation, > @@ -117,6 +118,29 @@ pub(crate) struct Gsp { > rmargs: CoherentAllocation, > } > =20 > +impl debugfs::BinaryWriter for LogBuffer { > + fn write_to_slice( > + &self, > + writer: &mut kernel::uaccess::UserSliceWriter, > + offset: &mut kernel::fs::file::Offset, > + ) -> Result { > + // SAFETY: This is a debug log buffer. GSP may write concurrentl= y, so the > + // snapshot may contain partially-written entries. This is accep= table for > + // debugging purposes - users should be aware logs may be slight= ly garbled > + // if read while GSP is actively logging. > + let slice =3D unsafe { self.0.as_slice(0, self.0.count()) }?; Unfortunately, it's still undefined behavior to create a slice when the bac= king 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 `Co= herentAllocation`. > +// GSP may write to the buffer concurrently regardless of CPU access, so= concurrent reads > +// from multiple CPU threads do not introduce any additional races beyon= d what already > +// exists with the device. Reads may observe partially-written log entri= es, 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) -> Result> { > --=20 > 2.52.0