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=1796304196; b=DfYF1LH9M6F6tqLyhtdvyVkwAIA3r3LXZUBPrPTFRuZOHD+fY75f5u/swAHkNP4iAaMt LXqzs/svGZ3QzHDCKx7SRIuHYKWtesKo61pkJcJe/qk131ryd9A4XbhAgCglbkj2SluWQ cp9Q/vPtJ4KOkjjDTw6BN1HomK8GdVLvF4ENlihnZsQWSmdXx/duIAM5OkguJAINS6M4K AQu5OZDDqR2F3WJhFqNKheXsH6+Pz132U0A4yEbxzsFArEeNXkYdzDFQNUJkcmtaLixVM F2m6lJPr7ziFTyji7EBkNCYD7X3vPtUbCa9RrfqcGgky6M2c0nU95sIaKP8pFbM8kFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304196; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=uFEcd3WiC+munrFJLAnrD1alGkYc9GF/Gp/+d+nYIUM=; b=sNgv0DyENZI+phYA6qeTx1E2A4Yq96lnvDAmnPyLq+gtbzk8ENhudrjOLwXc1rpZqZP/ XASiyo3D6YNHgfmJY3VqrjAzWnqPbGWYZ760+GOUhZjtF0OhcAwGT0ku8mmT+MrSIxOdm hQPRhjkH0kQj9z99zdueFcUp6gVmtR+dNidXTJ1F0CNaLqDz66OET3yQEZXXyZ+unMrlE 1k6mEEVO4aqAIWAMt7AQNmS2WmrHlcNjHe4gr1wZ5FoV6jq3Rmrlf49i55urHXGHZKLmo TrDP4T8lVP0evPDqOSfzS0oyb432V14/hBDnfkAGzXGVfFeRj6RvBLwVW92nEnQNaHQ== 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=RT26OWIQ; 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 77B51606A322 for ; Thu, 3 Dec 2026 13:23:16 +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=RT26OWIQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id D06661F000C1; Thu, 3 Dec 2026 13:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796304196; bh=uFEcd3WiC+munrFJLAnrD1alGkYc9GF/Gp/+d+nYIUM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=RT26OWIQ3t1B2g9fyh9G70RrgJyyNcpEFghTs/RNefMyhPSFOh06rNTg9/wUlLRAS BDVep+ArMF9JZSB9iSFZnK0T0eu02LpJ/iYVKXq1oPrPJOjqySEDIx8hZ5xJ8shiHv KuQU3DMvIIu4N0A8kGWsjWAu+pC/SrkM4stqSjzZE0hkR21D1o9QOoKr0ERmwV5zL3 Li3SxRy4Uhccx4IgccF4HP39fF8Fdl9T9CZfUn3NCFQEWJioIULA09zcigLq2YCUoX IX/WBQ9WMvH9+uW2nIBYfKD32Hchkavq9JrQVDWm+jJj2aj28KMJIG+jU67atEDR86 bnczPfwvTsA7g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 12/15] gpu: nova-core: switch to the r000 GSP firmware Reply-To: sashiko-reviews@lists.linux.dev To: "Alexandre Courbot" , "Danilo Krummrich" , "Alice Ryhl" , "David Airlie" , "Simona Vetter" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?b?QmrDtnJuIFJveSBCYXJvbg==?= , "Benno Lossin" , "Andreas Hindborg" , "Trevor Gross" , "Daniel Almeida" , "Tamir Duberstein" , =?utf-8?b?T251ciDDlnprYW4=?= , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , "Jonathan Corbet" , "Shuah Khan" , "Randy Dunlap" Cc: "John Hubbard" , "Alistair Popple" , "Timur Tabi" , "Eliot Courtney" , "Zhi Wang" , "Alok Kumar" , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org In-Reply-To: <20261203-b4-r000-switch-v1-12-b1463ec6dae2@nvidia.com> References: <20261203-b4-r000-switch-v1-0-b1463ec6dae2@nvidia.com> <20261203-b4-r000-switch-v1-12-b1463ec6dae2@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 13:23:14 +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 5 potential issues to consider: - [High] nova-core: missing element_len check in wait_for_msg() causes panic - [Medium] gpu: nova-core: 1us BAR0 MMIO busy-wait polling storm in cmdq - [Medium] nova-core: wait_for_msg() does not bound element_len() against readable area - [Medium] gpu: nova-core: unfulfilled expect(dead_code) in nvkv/encode.rs - [Low] gpu: nova-core: dma_mb(Full) used instead of mb(Full) for MMIO ordering -- commit b84d5985668cf177648c64b977c82247b207c333 Author: John Hubbard gpu: nova-core: switch to the r000 GSP firmware This commit switches nova-core's GSP bindings, message queue transport, boot sequence, and shutdown path from the r570 firmware interface to r000, moving queue pointers to BAR0 registers and replacing the r570 boot and shutdown RPC commands with GMC commands. > diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gs= p/boot.rs > index fb474e5984a80..763dbe1f8fdb4 100644 > --- a/drivers/gpu/nova-core/gsp/boot.rs > +++ b/drivers/gpu/nova-core/gsp/boot.rs [ ... ] > @@ -82,14 +85,19 @@ pub(crate) fn boot( > =20 > dev_dbg!(pdev, "RISC-V active? {}\n", gsp_falcon.is_riscv_active= (),); > =20 > - hal.post_boot(&self, ctx, &gsp_fw)?; > - > - // Wait until GSP is fully initialized. > - commands::rpc::wait_gsp_init_done(&self.cmdq)?; > - > + // GSP-RM answers `GSP_INIT` once it has finished starting, whic= h includes the > + // load-and-execute events that it raises along the way. > + let libos_dma_address =3D self.libos.dma_address(); > + let bootloader_app_version =3D gsp_fw.bootloader.app_version; > let static_info =3D self > .cmdq > - .send_rpc_command(commands::rpc::GetGspStaticInfo)?; > + .send_gmc_command(GspInit::new(pdev, chipset, ctx.vgpu.state= ())?, |event| { > + ctx.handle_load_exec_event(libos_dma_address, bootloader= _app_version, event) > + })? [Severity: Medium] Does calling GspInit::new() here make all non-test items in drivers/gpu/nova-core/gsp/nvkv/encode.rs live, leaving its module-level #![cfg_attr(not(CONFIG_KUNIT =3D "y"), expect(dead_code))] attribute unfulfilled? When CONFIG_KUNIT is n or m (including allmodconfig), rustc emits an unfulfilled_lint_expectations warning that fails the build under CONFIG_WERROR=3Dy. Removing that attribute from nvkv/encode.rs resolves it. > diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gs= p/cmdq.rs > index 10f6ddcf3eb52..f6bede6a77e7a 100644 > --- a/drivers/gpu/nova-core/gsp/cmdq.rs > +++ b/drivers/gpu/nova-core/gsp/cmdq.rs [ ... ] > @@ -328,76 +332,73 @@ fn allocate_command(&mut self, size: usize, timeout= : Delta) -> Result }) > } > =20 > - // Returns the index of the memory page the GSP will write the next = message to. > - // > - // # Invariants > - // > - // - The returned value is within `0..MSGQ_NUM_PAGES`. > + /// Returns the GSP's count of posted messages. > fn gsp_write_ptr(&self) -> u32 { > - let ptr =3D MsgqTxHeader::write_ptr(io_project!(self.mem, .gspq.= tx)) % MSGQ_NUM_PAGES; > + // ORDERING: `readl` ends in a read barrier, which orders this r= ead before the data reads > + // that follow it. > + let ptr =3D u32::from(self.bar.read(regs::NV_PGSP_MSGQ_HEAD::at(= 0)).val()); > =20 > - // ORDERING: LOAD->LOAD ordering needed to order `gsp_write_ptr`= read before data read. > - dma_mb(Read); > + // Ignore out-of-range reads (e.g. a register zeroed while GSP-R= M is suspended). > + if ptr.wrapping_sub(self.cpu_read_ptr) > MSGQ_NUM_PAGES { > + return self.last_gsp_write_ptr.get(); > + } > =20 > + self.last_gsp_write_ptr.set(ptr); > ptr > } [Severity: Medium] Does moving gsp_write_ptr() and gsp_read_ptr() from coherent RAM to BAR0 MMIO reads turn the 1-microsecond read_poll_timeout() loops in wait_for_msg() and allocate_command() into a non-sleeping MMIO polling storm? fsleep() uses udelay() for intervals up to 10 microseconds, so Delta::from_micros(1) busy-spins without yielding while issuing non-posted BAR0 readl() transactions for up to 15 seconds during GspInit boot and 5 seconds on other waits. On PREEMPT_NONE or PREEMPT_VOLUNTARY kernels this pegs the calling CPU at 100% while flooding the GPU BAR0 interface. In addition, allocate_command() calls driver_write_area() immediately after read_poll_timeout() succeeds on driver_write_area_size(), issuing a redundant BAR0 read and barrier on every command send. > + /// Returns the GSP's count of consumed commands. > fn gsp_read_ptr(&self) -> u32 { > - let ptr =3D MsgqRxHeader::read_ptr(io_project!(self.mem, .gspq.r= x)) % MSGQ_NUM_PAGES; > + let ptr =3D u32::from(self.bar.read(regs::NV_PGSP_QUEUE_TAIL::at= (0)).address()); > =20 > - // ORDERING: LOAD->STORE ordering needed to order `gsp_read_ptr`= read before data write. > + // ORDERING: the data writes that follow must not pass this read= . `readl` orders only the > + // reads that follow it, so the writes need a full barrier. > dma_mb(Full); [ ... ] > + /// Releases `elem_count` more elements of the message queue to the = GSP. > fn advance_cpu_read_ptr(&mut self, elem_count: u32) { > - // ORDERING: LOAD->STORE ordering needed to order `cpu_read_ptr`= write after data read. > - dma_mb(Full); > + self.cpu_read_ptr =3D self.cpu_read_ptr.wrapping_add(elem_count); > =20 > - let rx =3D io_project!(self.mem, .cpuq.rx); > - let rptr =3D MsgqRxHeader::read_ptr(rx).wrapping_add(elem_count)= % MSGQ_NUM_PAGES; > - MsgqRxHeader::set_read_ptr(rx, rptr) > - } > + // ORDERING: the data reads must complete before this write rele= ases the slots to the GSP. > + // `writel` orders only the writes before it, so the reads need = a full barrier. > + dma_mb(Full); > =20 > - // Returns the index of the memory page the CPU can write the next c= ommand to. > - // > - // # Invariants > - // > - // - The returned value is within `0..MSGQ_NUM_PAGES`. > - fn cpu_write_ptr(&self) -> u32 { > - MsgqTxHeader::write_ptr(io_project!(self.mem, .cpuq.tx)) % MSGQ_= NUM_PAGES > + self.bar.write( > + Array::at(0), > + regs::NV_PGSP_MSGQ_TAIL::zeroed().with_val(self.cpu_read_ptr= ), > + ); > } [Severity: Low] Should gsp_read_ptr() and advance_cpu_read_ptr() use mb(Full) instead of dma_mb(Full) now that the pointers live in BAR0 MMIO registers? Per Documentation/memory-barriers.txt, dma_*() barriers do not guarantee ordering with MMIO accesses. While dma_mb() currently falls back to mb() or an equivalent barrier on supported architectures, using mb(Full) matches the kernel barrier contract. [ ... ] > @@ -643,23 +618,23 @@ fn wait_for_msg(&self, timeout: Delta) -> Result> { > } > .map(|(slice_1, slice_2)| (slice_1.as_flattened(), slice_2.as_fl= attened()))?; > =20 > - // Extract the `GspMsgElement`. > - let (header, slice_1) =3D GspMsgElement::from_bytes_prefix(slice= _1).ok_or(EIO)?; > - > - // Validate checksum after truncating the message to its exact l= ength. > - if Cmdq::calculate_checksum( > - SBufferIter::new_reader([header.as_bytes(), slice_1, slice_2= ]) > - .take(header.msg_length()), > - ) !=3D 0 > - { > - dev_err!(&self.dev, "GSP receive: bad checksum\n"); > - return Err(EIO); > - } > + // Extract the `QueueElementHeader`. > + let (header, slice_1) =3D QueueElementHeader::ref_from_prefix(sl= ice_1).map_err(|_| EIO)?; > =20 > - Ok(GspMessage { > - header, > - contents: (slice_1, slice_2), > - }) > + header.validate().inspect_err(|_| { > + dev_err!(&self.dev, "GSP receive: bad queue element header\n= "); > + })?; > + > + // Cut the message slices down to the length that the queue elem= ent header declares. > + let contents =3D > + trim_message_slice((slice_1, slice_2), header.message_len())= .inspect_err(|_| { > + dev_err!( > + &self.dev, > + "GSP receive: read area shorter than the message\n" > + ); > + })?; > + > + Ok(GspMessage { header, contents }) > } [Severity: High] Can a GSP queue element whose mctp_payload_size spans more slots than are currently readable panic the kernel in driver_read_area()? QueueElementHeader::validate() allows element_len() to exceed size_of::() + message_len() up to 16 pages, and wait_for_msg() only bounds message_len() via trim_message_slice(). If 1 slot is readable (NV_PGSP_MSGQ_HEAD =3D=3D 1) and a message has nvdm_payload_size =3D=3D 64 with mctp_payload_size =3D=3D 8192 (element_cou= nt() =3D=3D 2), consume_element() advances cpu_read_ptr to 2 past both NV_PGSP_MSGQ_HEAD and last_gsp_write_ptr. On the next driver_read_area() call, gsp_write_ptr() sees the wrapped difference exceed MSGQ_NUM_PAGES and falls back to last_gsp_write_ptr (1), so gspq_readable_slots() underflows to u32::MAX and io_project!(self.mem, .gspq.msgq.data[panic: ..before_len]) panics out of bounds. Verifying that header.element_len() fits in the readable area in wait_for_msg() prevents this. [ ... ] > @@ -683,14 +659,25 @@ fn consume_element( > f: impl FnOnce(GspParsedMessage<'_>) -> R, > ) -> Result { > let message =3D self.wait_for_msg(timeout)?; > - let elem_count =3D u32::try_from(message.header.msg_length().div= _ceil(GSP_PAGE_SIZE)) > - .map_err(|_| { > - dev_err!(&self.dev, "GSP receive: message length overflo= w\n"); > - EIO > - })?; > + let elem_count =3D message.header.element_count(); [Severity: Medium] Can advancing cpu_read_ptr by element_count() here without first checking element_len() against the readable slots underflow gspq_readable_slots() and panic in driver_read_area() instead of returning EIO? Because wait_for_msg() only validates message_len() against the readable slices and QueueElementHeader is borrowed in place from coherent DMA memory via ref_from_prefix() across validate(), message_len(), element_count(), and nvdm_type(), a misframed or concurrently modified header can cause advance_cpu_read_ptr() to overtake last_gsp_write_ptr. Copying the 24-byte QueueElementHeader by value, validating element_len() against the readable area, and clamping gspq_readable_slots() to MSGQ_NUM_PAGES eliminates this panic path. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-b4-r000-sw= itch-v1-0-b1463ec6dae2@nvidia.com?part=3D12