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 1CB87F01825 for ; Fri, 6 Mar 2026 11:03:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 81ADA10ECDE; Fri, 6 Mar 2026 11:03:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="RTDbKOpx"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 622C010ECDE; Fri, 6 Mar 2026 11:03:35 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id E820043EE2; Fri, 6 Mar 2026 11:03:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C08BC2BCB3; Fri, 6 Mar 2026 11:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772795014; bh=9kYhONNOuHNdTnEFXcExgHi8n0fGbiUgRAaTDCbIcqI=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=RTDbKOpxoF1J+0YGsIe4inkKZkkELNb0sZAhBcxnObYCNGFEcQIeMcIAwm7nGM99n GSijIOczN3ZbGAJxa6xwXdRUPU8cNCMuweonYby9//8PlSIedpowNvgceKpjNcD4DU bk6s5STkAeZM7mV2YnotGvhjQX9F7gOTNI7a5HQzKHL2T4634gdn5IFGGFm81v4LwW VsdnjLAFAZHGvlRBFhbWoEGoqjRpXdOQvuaLZ9e8Eg10daSLpEuVOBg3gCTj4wvuuM 3Looy0HT6EdabLHJQ1Ywd23hygCGXPL7+fACrTlouGML20s1c8hs7kdbuzD/5r/AKf Ph1n6uuXgCRrQ== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 06 Mar 2026 12:03:28 +0100 Message-Id: Subject: Re: [PATCH v5 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue Cc: "Eliot Courtney" , "Alice Ryhl" , "David Airlie" , "Simona Vetter" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Trevor Gross" , "Zhi Wang" , "John Hubbard" , "Alistair Popple" , "Joel Fernandes" , "Timur Tabi" , , , , , "dri-devel" To: "Alexandre Courbot" From: "Danilo Krummrich" References: <20260304-cmdq-continuation-v5-0-3f19d759ed93@nvidia.com> <20260304-cmdq-continuation-v5-2-3f19d759ed93@nvidia.com> In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Fri Mar 6, 2026 at 1:48 AM CET, Alexandre Courbot wrote: > On Thu Mar 5, 2026 at 8:16 PM JST, Danilo Krummrich wrote: >> @Alex: It also seems that this is based on broken code, i.e. I noticed h= ow the >> DMA read is done in this case in e.g. gsp_read_ptr(). >> >> fn cpu_read_ptr(&self) -> u32 { >> let gsp_mem =3D self.0.start_ptr(); >> =09 >> // SAFETY: >> // - The ['CoherentAllocation'] contains at least one object. >> // - By the invariants of CoherentAllocation the pointer is valid. >> (unsafe { (*gsp_mem).cpuq.rx.read_ptr() } % MSGQ_NUM_PAGES) >> } >> >> Why isn't this using dma_read!()? I think creating this reference is UB. > > We can't - technically we would have to have the `dma_read` in `cmdq.rs` > so it can access the `CoherentAllocation` (and do an unwrap in the > process): > > dma_read!(self.0, 0, .gspq.rx.0.readPtr).unwrap() > > ... but that cannot be done as `MsgqRxHeader` is part of the bindings > (i.e. in `fw.rs`) and thus its internal fields are not visible to > `cmdq.rs`, as per our policy of making the bindigns opaque. We can have a helpers for doing such dma_read!() calls in gsp/fw.rs instead= , and just forward from the actual methods. fn cpu_read_ptr(&self) -> u32 { fw:gsp_mem::cpu_rx_ptr(self) % MSGQ_NUM_PAGES } > This can probably be done better with I/O projections, but for now we hav= e to > do the read_volatile by ourselves. Not necessarily, see above. > What makes this reference UB btw? Gary explained this in another reply already; I think fixing this with Opaq= ue or passing raw pointers instead involves even more unsafe. Whereas the simple indirection from above is fully safe and can easily replaced with I/O projections once we have them.