public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Alexandre Courbot" <acourbot@nvidia.com>, "Gary Guo" <gary@garyguo.net>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
	"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, "Zhi Wang" <zhiw@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] gpu: nova-core: firmware: riscv: use dma::Coherent
Date: Mon, 23 Mar 2026 13:05:25 +0000	[thread overview]
Message-ID: <DHA6MEL4AXAQ.3ICB81V0D9FNX@garyguo.net> (raw)
In-Reply-To: <DH9XWWNM1GY4.1W6N89W6UCYDW@nvidia.com>

On Mon Mar 23, 2026 at 6:15 AM GMT, Alexandre Courbot wrote:
> On Sat Mar 21, 2026 at 11:58 PM JST, Gary Guo wrote:
>> On Sat Mar 21, 2026 at 1:36 PM GMT, Alexandre Courbot wrote:
>>> Replace the nova-core local `DmaObject` with a `Coherent` that can
>>> fulfill the same role.
>>>
>>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>>> ---
>>>  drivers/gpu/nova-core/firmware/riscv.rs | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/gpu/nova-core/firmware/riscv.rs b/drivers/gpu/nova-core/firmware/riscv.rs
>>> index 14aad2f0ee8a..2afa7f36404e 100644
>>> --- a/drivers/gpu/nova-core/firmware/riscv.rs
>>> +++ b/drivers/gpu/nova-core/firmware/riscv.rs
>>> @@ -5,13 +5,13 @@
>>>  
>>>  use kernel::{
>>>      device,
>>> +    dma::Coherent,
>>>      firmware::Firmware,
>>>      prelude::*,
>>>      transmute::FromBytes, //
>>>  };
>>>  
>>>  use crate::{
>>> -    dma::DmaObject,
>>>      firmware::BinFirmware,
>>>      num::FromSafeCast, //
>>>  };
>>> @@ -66,7 +66,7 @@ pub(crate) struct RiscvFirmware {
>>>      /// Application version.
>>>      pub(crate) app_version: u32,
>>>      /// Device-mapped firmware image.
>>> -    pub(crate) ucode: DmaObject,
>>> +    pub(crate) ucode: Coherent<[u8]>,
>>>  }
>>>  
>>>  impl RiscvFirmware {
>>> @@ -81,7 +81,7 @@ pub(crate) fn new(dev: &device::Device<device::Bound>, fw: &Firmware) -> Result<
>>>              let len = usize::from_safe_cast(bin_fw.hdr.data_size);
>>>              let end = start.checked_add(len).ok_or(EINVAL)?;
>>>  
>>> -            DmaObject::from_data(dev, fw.data().get(start..end).ok_or(EINVAL)?)?
>>> +            Coherent::from_slice(dev, fw.data().get(start..end).ok_or(EINVAL)?, GFP_KERNEL)?
>>
>> `DmaObject` rounds the data up to be page-sized, while this new API doesn't.
>>
>> It has impact on alignment, as the allocator aligns things to the largest
>> power-of-two exponent of the allocated size.
>
> Doesn't `dma_alloc_coherent` always allocate from the page pool and thus
> returns page-aligned memory though?

Oh you're right, this is not from DMA pool, so allocations are page-aligned
indeed.

I brought this up because I got bite by this size adjustment behaviour
because in the `from_data` I initially put

    unsafe { dma_obj.as_mut().copy_from_slice(data) };

but that doesn't work due to the size being aligned up so dma_obj.len() !=
data.len().

But if this behaviour is not needed it does simplify things quite a bit.

> I'm not sure why `DmaObject` was doing that but it was redundant I think.

A question for yourself I guess? :-)

https://lore.kernel.org/all/20250619-nova-frts-v6-13-ecf41ef99252@nvidia.com/

Best,
Gary

  reply	other threads:[~2026-03-23 13:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-21 13:36 [PATCH 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
2026-03-21 13:36 ` [PATCH 1/7] rust: dma: add from-slice constructors for Coherent and CoherentBox Alexandre Courbot
2026-03-23 16:55   ` Gary Guo
2026-03-26 14:59     ` Alexandre Courbot
2026-03-26 15:02       ` Danilo Krummrich
2026-03-27 10:39       ` Miguel Ojeda
2026-03-24 14:29   ` Andreas Hindborg
2026-03-21 13:36 ` [PATCH 2/7] gpu: nova-core: firmware: riscv: use dma::Coherent Alexandre Courbot
2026-03-21 14:58   ` Gary Guo
2026-03-23  6:15     ` Alexandre Courbot
2026-03-23 13:05       ` Gary Guo [this message]
2026-03-23 14:33         ` Alexandre Courbot
2026-03-21 13:36 ` [PATCH 3/7] gpu: nova-core: firmware: fwsec: " Alexandre Courbot
2026-03-21 13:36 ` [PATCH 4/7] gpu: nova-core: falcon: " Alexandre Courbot
2026-03-25  2:14   ` Eliot Courtney
2026-03-26 15:04     ` Alexandre Courbot
2026-03-26 15:35       ` Gary Guo
2026-03-28 13:03         ` Alexandre Courbot
2026-03-21 13:36 ` [PATCH 5/7] gpu: nova-core: fb: " Alexandre Courbot
2026-03-21 13:36 ` [PATCH 6/7] gpu: nova-core: firmware: gsp: use dma::Coherent for signatures Alexandre Courbot
2026-03-21 13:36 ` [PATCH 7/7] gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table Alexandre Courbot
2026-03-23 17:01 ` [PATCH 0/7] rust: dma: add from-slice constructors and use them in nova-core Gary Guo

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=DHA6MEL4AXAQ.3ICB81V0D9FNX@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=abdiel.janulgue@gmail.com \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=driver-core@lists.linux.dev \
    --cc=ecourtney@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox