From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Eliot Courtney" <ecourtney@nvidia.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>, "Zhi Wang" <zhiw@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
dri-devel <dri-devel-bounces@lists.freedesktop.org>
Subject: Re: [PATCH v5 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue
Date: Fri, 06 Mar 2026 12:03:28 +0100 [thread overview]
Message-ID: <DGVNDRM96OTJ.1RD1IGZ4QV5VF@kernel.org> (raw)
In-Reply-To: <DGVAB40GKAYG.3MX3IZQO1816A@nvidia.com>
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 how the
>> DMA read is done in this case in e.g. gsp_read_ptr().
>>
>> fn cpu_read_ptr(&self) -> u32 {
>> let gsp_mem = self.0.start_ptr();
>>
>> // 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 have 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 Opaque 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.
WARNING: multiple messages have this Message-ID (diff)
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Eliot Courtney" <ecourtney@nvidia.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>, "Zhi Wang" <zhiw@nvidia.com>,
"John Hubbard" <jhubbard@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
dri-devel <dri-devel-bounces@lists.freedesktop.org>
Subject: Re: [PATCH v5 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue
Date: Fri, 06 Mar 2026 12:03:28 +0100 [thread overview]
Message-ID: <DGVNDRM96OTJ.1RD1IGZ4QV5VF@kernel.org> (raw)
In-Reply-To: <DGVAB40GKAYG.3MX3IZQO1816A@nvidia.com>
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 how the
>> DMA read is done in this case in e.g. gsp_read_ptr().
>>
>> fn cpu_read_ptr(&self) -> u32 {
>> let gsp_mem = self.0.start_ptr();
>>
>> // 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 have 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 Opaque 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.
next prev parent reply other threads:[~2026-03-06 11:03 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 1:42 [PATCH v5 0/9] gpu: nova-core: gsp: add continuation record support Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 1/9] gpu: nova-core: gsp: sort `MsgFunction` variants alphabetically Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 11:39 ` Danilo Krummrich
2026-03-04 11:39 ` Danilo Krummrich
2026-03-05 7:37 ` Eliot Courtney
2026-03-05 7:37 ` Eliot Courtney
2026-03-05 7:50 ` John Hubbard
2026-03-05 7:50 ` John Hubbard
2026-03-05 8:01 ` Eliot Courtney
2026-03-05 8:01 ` Eliot Courtney
2026-03-05 10:38 ` Alexandre Courbot
2026-03-05 10:38 ` Alexandre Courbot
2026-03-05 11:16 ` Danilo Krummrich
2026-03-05 11:16 ` Danilo Krummrich
2026-03-06 0:48 ` Alexandre Courbot
2026-03-06 0:48 ` Alexandre Courbot
2026-03-06 1:46 ` Gary Guo
2026-03-06 1:46 ` Gary Guo
2026-03-06 11:03 ` Danilo Krummrich [this message]
2026-03-06 11:03 ` Danilo Krummrich
2026-03-06 5:21 ` Alexandre Courbot
2026-03-06 5:21 ` Alexandre Courbot
2026-03-04 1:42 ` [PATCH v5 3/9] rust: add EMSGSIZE error code Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 4/9] gpu: nova-core: gsp: add checking oversized commands Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 5/9] gpu: nova-core: gsp: clarify invariant on command queue Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 6/9] gpu: nova-core: gsp: unconditionally call variable payload handling Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 7/9] gpu: nova-core: gsp: add `size_in_bytes` helper to `CommandToGsp` Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 2:53 ` Alexandre Courbot
2026-03-04 2:53 ` Alexandre Courbot
2026-03-04 3:10 ` Eliot Courtney
2026-03-04 3:10 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 8/9] gpu: nova-core: gsp: support large RPCs via continuation record Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
2026-03-04 1:42 ` [PATCH v5 9/9] gpu: nova-core: gsp: add tests for continuation records Eliot Courtney
2026-03-04 1:42 ` Eliot Courtney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DGVNDRM96OTJ.1RD1IGZ4QV5VF@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dri-devel-bounces@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.