From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796177078; b=27+mBQAItBnju3JWR8J3fCa2WLB0n+52FyD6QIWAXnUqioO9pqXmeG44kgUMYvg7VGwO Fe3g10Ej/aWa5Ncqk0qdr8BRwl+bDkllDtkeI9RKQC5wLoUU6YlW2ezxynhaI45AXNOyr 6q/dqbK0f9IK29nxbTO6G56J2Eh6wxa486WhjdsfCBD/CfrH7ML0LqzBYRG6bYxVRaZ+v 9xHxAb1GTZAmRr7rnO4hn2p4hJEYNq4tAzr5bUmmztJ9+pZKFBmcvBu8lFHgLJr99lUo+ PZJxqI3r6kE+pyCQ3dr7qDLZOkoZcg1VDqGMvjW+drTxzV2CT6qMi30rjkiyMwfZG7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796177078; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=jx0ehDyqHBC8IyC1buIDXpSIshJvSsOT0NJ6aAkujUY=; b=3G9gGKQhGlFMG5ZNfMR2uRng254Sav7hlYlr5WypOQlYkJQurxwUJ6SAiEkqSafUPMMd XcF6+PaxopaAsi1gfjKclB7/CGOWTPB4scjcI3fl0eOM33plMn9+7CwbgaU/JDxIPQlKM vjUFGnuXjlXNYDyMqoLj4lfv21yc8fkD4D2hhrCMxXzPSkY9J5VnJGaZSszewKugNoxHf xR0l5RWLRQrhJTNtWte5aVJWP2zYt/4hN7gH6LhpOJCbav+cwZP6o3YSk7q8lzlxlg0P2 KJqC5v6OYHjIP1SjBmZjWr6MX7AZPSg6WgMoqfMXpApMccQA39kQOEm/ApMtebchFRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UhUnkUj5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D79D5606A322 for ; Wed, 2 Dec 2026 02:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UhUnkUj5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D18D1F00893; Wed, 2 Dec 2026 02:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796177078; bh=jx0ehDyqHBC8IyC1buIDXpSIshJvSsOT0NJ6aAkujUY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UhUnkUj50e5IS2FlJcTx8OlLz6osHt2q0livGhR5tb2xYAaRUiCVyWcoKgWnXkCzt PLBTXQjInB1Jh32rZF9LYFQ05Gj5p0mz2MuLBrhQKCgdbyi2Died1yIiYoE7xJyfDz Qm6TOlWPFfyVFKOr5j9BMKL35UEXYoh56t4XEfiYdhi6afgwjvHUTis/B9j+Qb796W 3QyEj0pKIlCxdqh3Of46YZQ5glrwibIUuq73Vdk1/INp0NgCQqSH6lmJ21lMwEC1Dx jV0hxwb4fu6zrGr1uaoVIkYwquxLk4aabT2q1XqI+xDxCH21Bf0/oJyZ24zxw/8Zrl 2PQ0VdulXs5gA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH] gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?QWd1c3TDrW4gUGVyZWlyYQ==?= , "Danilo Krummrich" , "Alexandre Courbot" , "Alice Ryhl" , "David Airlie" , "Simona Vetter" Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, ojeda@kernel.org, gary@garyguo.net In-Reply-To: <20261202015304.152927-1-agustin.pereira.ro@gmail.com> References: <20261202015304.152927-1-agustin.pereira.ro@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 02:04:37 +0000 X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] gpu: nova-core: unaligned stack slice in PmuLogBuffer::capture_event() - [Medium] gpu: nova-core: RETAINED_LOGS KVec memory leak in DebugfsRootGuard::drop() -- commit de98d34f69a2abc89f1f11708b2ef5d8075d83df Author: Agust=C3=ADn Pereira gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu This commit moves GSP-RM logging into a dedicated gsp::logs module, captures PMU UCODE_LIBOS_PRINT events into a debugfs logpmu buffer, and adds a keep_gsp_logging module parameter to snapshot and retain non-empty log buffers in debugfs across probe failures or device unbind. > diff --git a/drivers/gpu/nova-core/gsp/logs.rs b/drivers/gpu/nova-core/gs= p/logs.rs > new file mode 100644 > index 0000000000000..9044315f18db9 > --- /dev/null > +++ b/drivers/gpu/nova-core/gsp/logs.rs > @@ -0,0 +1,450 @@ [ ... ] > + pub(crate) fn capture_event(&self, contents: (&[u8], &[u8])) -> Resu= lt { > + let total_len =3D contents.0.len().saturating_add(contents.1.len= ()); > + let header_len =3D size_of::(); > + if total_len < header_len { > + return Err(EINVAL); > + } > + > + let mut sbuf =3D SBufferIter::new_reader([contents.0, contents.1= ]); > + let mut hdr_bytes =3D [0u8; size_of::()]; > + sbuf.read_exact(&mut hdr_bytes)?; > + > + let hdr =3D UcodeLibOsPrintHeader::from_bytes(&hdr_bytes).ok_or(= EIO)?; [Severity: Medium] Can UcodeLibOsPrintHeader::from_bytes(&hdr_bytes) fail with Err(EIO) on valid events because hdr_bytes is only 1-byte aligned? UcodeLibOsPrintHeader wraps rpc_ucode_libos_print_v1e_08, which contains u32 fields and requires 4-byte alignment, while FromBytes::from_bytes() returns None when slice_ptr.is_aligned() is false. Whenever the compiler places hdr_bytes on an address not divisible by 4, capture_event() rejects valid PMU print events and fails the KUnit tests. Using UcodeLibOsPrintHeader::from_bytes_copy(&hdr_bytes) avoids the alignment requirement. > diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/n= ova_core.rs > index a8f6dc22057be..028e368f1b831 100644 > --- a/drivers/gpu/nova-core/nova_core.rs > +++ b/drivers/gpu/nova-core/nova_core.rs > @@ -35,11 +35,52 @@ > // TODO: Move this into per-module data once that exists. > static mut DEBUGFS_ROOT: Option =3D None; > =20 > -/// Guard that clears `DEBUGFS_ROOT` when dropped. > +kernel::sync::global_lock! { > + // SAFETY: Initialized once in `NovaCoreModule::init` before driver = registration > + // and cleared in `DebugfsRootGuard::drop` after driver unregistrati= on. > + unsafe(uninit) static RETAINED_LOGS: Mutex> =3D KVec::new(); > +} [ ... ] > +/// Guard that clears retained logs and `DEBUGFS_ROOT` when dropped. > struct DebugfsRootGuard; > =20 > impl Drop for DebugfsRootGuard { > fn drop(&mut self) { > + // Drop retained `debugfs` scopes before removing `DEBUGFS_ROOT`. > + RETAINED_LOGS.lock().clear(); > + > // SAFETY: This guard is dropped after `_driver` (due to field o= rder), > // so the driver is unregistered and no probe() can be running. > unsafe { DEBUGFS_ROOT =3D None }; [Severity: Medium] Does RETAINED_LOGS.lock().clear() leak the KVec backing buffer on module unload? KVec::clear() truncates the vector to length 0 and drops its elements in place, but keeps the Kmalloc capacity allocation. Because RETAINED_LOGS is a static item, its Drop implementation never runs when the module is unloaded. In addition, because NovaCoreModule drops _driver before _debugfs_guard, unloading the module with keep_gsp_logging=3Dtrue unbinds a= ll active devices and snapshots their logs into RETAINED_LOGS right before DebugfsRootGuard::drop() clears them and leaks the vector buffer. Replacing the vector with *RETAINED_LOGS.lock() =3D KVec::new() will drop t= he old KVec and free its backing memory. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202015304.1529= 27-1-agustin.pereira.ro@gmail.com?part=3D1