mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] gpu: nova-core: use Init for firmware initialization
@ 2026-11-22 17:13 Danilo Krummrich
  0 siblings, 0 replies; only message in thread
From: Danilo Krummrich @ 2026-11-22 17:13 UTC (permalink / raw)
  To: dakr, acourbot; +Cc: nova-gpu, dri-devel, rust-for-linux, linux-kernel

Now that SGTable no longer requires pinning, move Radix3 and GspFirmware
from PinInit to Init.

In an x86-64 build, GspFirmware is 312 bytes, including its 216-byte
Radix3. This is reasonable for the stack, but returning it by value
increases boot()'s local stack reservation from 432 to 1040 bytes.

On TU102 for instance, the nested hal.boot() call reserves another 1128
bytes for locals.

Thus, keep the KBox allocation and in-place initialization.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
Changes in v2:
  - Convert to impl Init to not increase the overall stack usage.
---
 drivers/gpu/nova-core/firmware/gsp.rs    |  8 ++-
 drivers/gpu/nova-core/firmware/radix3.rs | 67 +++++++++++-------------
 drivers/gpu/nova-core/gsp/boot.rs        |  3 +-
 3 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 341a8b19aa38..1cf17d0fb36b 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -25,10 +25,8 @@
 };
 
 /// The GSP firmware image, its signatures, and the GSP bootloader.
-#[pin_data]
 pub(crate) struct GspFirmware<'a> {
     /// The firmware image and the radix3 table that maps it.
-    #[pin]
     radix3: Radix3<'a>,
     /// Device-mapped GSP signatures matching the GPU's [`Chipset`].
     pub(crate) signatures: Coherent<'a, [u8]>,
@@ -42,8 +40,8 @@ impl<'a> GspFirmware<'a> {
     pub(crate) fn new(
         dev: &'a device::Device<device::Bound>,
         chipset: Chipset,
-    ) -> impl PinInit<Self, Error> + 'a {
-        pin_init::pin_init_scope(move || {
+    ) -> impl Init<Self, Error> + 'a {
+        pin_init::init_scope(move || {
             let firmware = request_tlv(dev, chipset, "gsp")?;
             let tlv = Tlv::new(firmware.data())?;
             dev_dbg!(dev, "loaded gsp firmware v{}\n", tlv.get_string(b"VERS")?);
@@ -58,7 +56,7 @@ pub(crate) fn new(
 
             let signatures = Coherent::from_slice(dev, tlv.get_bytes(b"SIGN")?, GFP_KERNEL)?;
 
-            Ok(try_pin_init!(Self {
+            Ok(try_init!(Self {
                 radix3 <- Radix3::new(dev, fw_vvec),
                 signatures,
                 bootloader: {
diff --git a/drivers/gpu/nova-core/firmware/radix3.rs b/drivers/gpu/nova-core/firmware/radix3.rs
index a3e43fc8ec86..b17d1363e48f 100644
--- a/drivers/gpu/nova-core/firmware/radix3.rs
+++ b/drivers/gpu/nova-core/firmware/radix3.rs
@@ -32,7 +32,6 @@
 };
 
 /// A radix3 page table and the data it maps.
-#[pin_data]
 pub(crate) struct Radix3<'a> {
     /// The mapped data.
     data: SGTable<Owned<'a, VVec<u8>>>,
@@ -51,41 +50,37 @@ impl<'a> Radix3<'a> {
     pub(crate) fn new(
         dev: &'a device::Device<device::Bound>,
         data: VVec<u8>,
-    ) -> impl PinInit<Self, Error> + 'a {
-        let size = data.len();
-
-        pin_init::pin_init_scope(move || {
-            Ok(try_pin_init!(Self {
-                data: SGTable::new(dev, data, DataDirection::ToDevice, GFP_KERNEL)?,
-                level2: {
-                    let l2 = build_lvl(data)?;
-                    SGTable::new(dev, l2, DataDirection::ToDevice, GFP_KERNEL)?
-                },
-                level1: {
-                    let l1 = build_lvl(level2)?;
-                    SGTable::new(dev, l1, DataDirection::ToDevice, GFP_KERNEL)?
-                },
-                level0: {
-                    // Allocate the level 0 page table as a device-visible DMA object, and map the
-                    // level 1 page table onto it.
-
-                    // Fill level 1 page entry.
-                    let level1_entry = level1.iter().next().ok_or(EINVAL)?;
-                    let level1_entry_addr = level1_entry.dma_address();
-
-                    // Create level 0 page table data and fill its first entry with the level 1
-                    // table.
-                    let mut level0 = CoherentBox::<'_, [u64]>::zeroed_slice(
-                        dev,
-                        GSP_PAGE_SIZE / size_of::<u64>(),
-                        GFP_KERNEL,
-                    )?;
-                    level0[0] = level1_entry_addr.to_le();
-
-                    level0.into()
-                },
-                size,
-            }))
+    ) -> impl Init<Self, Error> + 'a {
+        try_init!(Self {
+            size: data.len(),
+            data: SGTable::new(dev, data, DataDirection::ToDevice, GFP_KERNEL)?,
+            level2: {
+                let l2 = build_lvl(data)?;
+                SGTable::new(dev, l2, DataDirection::ToDevice, GFP_KERNEL)?
+            },
+            level1: {
+                let l1 = build_lvl(level2)?;
+                SGTable::new(dev, l1, DataDirection::ToDevice, GFP_KERNEL)?
+            },
+            level0: {
+                // Allocate the level 0 page table as a device-visible DMA object, and map the
+                // level 1 page table onto it.
+
+                // Fill level 1 page entry.
+                let level1_entry = level1.iter().next().ok_or(EINVAL)?;
+                let level1_entry_addr = level1_entry.dma_address();
+
+                // Create level 0 page table data and fill its first entry with the level 1
+                // table.
+                let mut level0 = CoherentBox::<'_, [u64]>::zeroed_slice(
+                    dev,
+                    GSP_PAGE_SIZE / size_of::<u64>(),
+                    GFP_KERNEL,
+                )?;
+                level0[0] = level1_entry_addr.to_le();
+
+                level0.into()
+            },
         })
     }
 
diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
index 4fb1b69ac9d5..defe1f331918 100644
--- a/drivers/gpu/nova-core/gsp/boot.rs
+++ b/drivers/gpu/nova-core/gsp/boot.rs
@@ -40,7 +40,8 @@ pub(crate) fn boot(
         let dev = pdev.as_ref();
         let hal = super::hal::gsp_hal(chipset);
 
-        let gsp_fw = KBox::pin_init(GspFirmware::new(dev, chipset), GFP_KERNEL)?;
+        // Initialize the firmware in place to limit stack usage during boot.
+        let gsp_fw = KBox::init(GspFirmware::new(dev, chipset), GFP_KERNEL)?;
 
         self.cmdq
             .send_command_no_wait(commands::SetSystemInfo::new(pdev, chipset))?;

base-commit: 0504beeb95d1be229d7cce00a12033468f5ac50b
-- 
2.56.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-22 17:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 17:13 [PATCH v2] gpu: nova-core: use Init for firmware initialization Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®