From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: gpu: nova-core: fix stack overflow in GSP memory allocation Date: Tue, 10 Mar 2026 12:10:29 +1000 Message-ID: In-Reply-To: <20260309-drm-rust-next-v4-4-4ef485b19a4c@proton.me> References: <20260309-drm-rust-next-v4-0-4ef485b19a4c@proton.me> <20260309-drm-rust-next-v4-4-4ef485b19a4c@proton.me> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review This is the actual bug fix. The `PteArray` was `[u64; NUM_PAGES]= ` on the stack, which for typical GSP page sizes resulted in 8216+ bytes of= stack usage, causing overflow. **cmdq.rs changes** =E2=80=94 Uses the projection macro to write PTEs one-b= y-one: ```rust for i in 0..NUM_PTES { dma_write!( gsp_mem, [0]?.ptes.0[i], PteArray::::entry(start, i)? ); } ``` The use of infallible `[i]` (not `[i]?`) for the inner array index is inter= esting. This relies on the compiler (LLVM) proving that `i < NUM_PTES` from= the `0..NUM_PTES` loop bound, so `build_error!()` is eliminated as dead co= de. If the optimizer cannot prove this, compilation will fail, which acts a= s a safety net. This is acceptable but somewhat fragile =E2=80=94 if future= changes complicate the loop, it could become a compile error. Using `[i]?`= would be safer and essentially free at runtime. **gsp.rs LogBuffer::new changes** =E2=80=94 Does NOT use the projection mac= ro or `PteArray::entry()`: ```rust let pte_region =3D unsafe { obj.0 .as_slice_mut(size_of::(), NUM_PAGES * size_of::())? }; for (i, chunk) in pte_region.chunks_exact_mut(size_of::()).enumerate()= { let pte_value =3D start_addr .checked_add(num::usize_as_u64(i) << GSP_PAGE_SHIFT) .ok_or(EOVERFLOW)?; chunk.copy_from_slice(&pte_value.to_ne_bytes()); } ``` **Issue: Code duplication** =E2=80=94 The PTE value calculation here (`star= t_addr.checked_add(...)`) duplicates the logic of the newly added `PteArray= ::entry()` method. The `entry()` method was added in the same patch but is = only called from `cmdq.rs`. The `gsp.rs` path should use it too: ```rust let pte_value =3D PteArray::::entry(start_addr, i)?; ``` This would reduce duplication and keep the PTE calculation logic in one pla= ce. **Issue: Inconsistent approaches** =E2=80=94 The two call sites use fundame= ntally different strategies: `cmdq.rs` uses `dma_write!` with projection, w= hile `gsp.rs` uses raw `as_slice_mut` + `chunks_exact_mut` + manual byte co= pying. This is understandable since `LogBuffer` wraps `CoherentAllocation` (byte-level access) while `DmaGspMem` wraps `CoherentAllocation= ` (typed access), but a brief comment in `gsp.rs` explaining why the projec= tion approach isn't used here would help future readers. **Minor style nit**: The comment at line 295 has a double space: ```rust // This is a one by one GSP Page write to the memory ``` Overall the fix is correct and achieves the goal of eliminating the stack o= verflow. The inconsistency between the two call sites and the unused `PteAr= ray::entry()` in `gsp.rs` are the main items worth addressing before merge. --- Generated by Claude Code Patch Reviewer