Skip to contentSkip to conversation

gpu: nova-core: run unload sequence upon unbinding

PATCH Superseded Alexandre Courbot 5 participants 15 messages Apr 22 – May 15

Subsystems (5)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Alexandre Courbot

author maintainer
#0 lore raw

v3 cover gpu: nova-core: run unload sequence upon unbinding

Currently the GSP is left running and the WPR2 memory region untouched when the driver is unbound. This is obviously not ideal for at least two reasons:

- Probing requires setting up the WPR2 region, which cannot be done if there is already one in place. Hence the current requirement to reset the GPU (using e.g. echo 1 >/sys/bus/pci/devices/.../reset) before the driver can be probed again after removal.
- The running GSP may still attempt to access shared memory regions which the kernel might recycle.

On top of that, there is a nasty bug in the Blackwell VBIOS that sometimes borks the GPU upon PCI reset, requiring a reboot. So relying on the PCI reset to unload/reload Nova is really not practical here.

This series does what is needed to leave the GPU in a clean state after unbind, for all currently supported GPUs. Blackwell support is trivial and will be added alongside the Blackwell series [1] if this can be merged first.

The first patch adds a warn_on_err utility macro to the kernel crate as it is useful to warn on failures in the driver unbind path, but I can remove it if it is not deemed useful.

This series applies cleanly on master as of today.

[1] https://lore.kernel.org/all/[email protected]/

---
Changes in v3:
- Disambiguate doccomment for warn_on_err.
- Test the correct bit instead of the whole register value to determine that the GSP has stopped.
- Use an enum instead of a boolean to encode the power level when
shutting down the GSP.
- Add missing newline to dev_err.
- Add missing doccomments for new types.
- Use values from bindings instead of magic numbers.
- Remove the redundant get_gsp_info function.
- Better document Booter Unloader mailbox sentinel value, and check the value of mbox0 upon return.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Rebase on top of master and remove unneeded/obsolete preparatory patches.
- Tidy up the imports of commands from the fw module in the gsp module.
- Link to v1: https://patch.msgid.link/[email protected]

---
Alexandre Courbot (6):
rust: add warn_on_err macro
gpu: nova-core: use warn_on_err macro
gpu: nova-core: remove unneeded get_gsp_info proxy function
gpu: nova-core: do not import firmware commands into GSP command module
gpu: nova-core: send UNLOADING_GUEST_DRIVER GSP command upon unloading
gpu: nova-core: run Booter Unloader and FWSEC-SB upon unbinding

 drivers/gpu/nova-core/firmware/booter.rs          |   1 -
 drivers/gpu/nova-core/firmware/fwsec.rs           |   1 -
 drivers/gpu/nova-core/gpu.rs                      |  21 +++--
 drivers/gpu/nova-core/gsp/boot.rs                 | 100 +++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/commands.rs             |  69 +++++++++++----
 drivers/gpu/nova-core/gsp/fw.rs                   |   4 +
 drivers/gpu/nova-core/gsp/fw/commands.rs          |  44 ++++++++++
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs |  11 +++
 drivers/gpu/nova-core/regs.rs                     |   5 ++
 rust/kernel/bug.rs                                |  10 +++
 10 files changed, 241 insertions(+), 25 deletions(-)

---
base-commit: b4e07588e743c989499ca24d49e752c074924a9a
change-id: 20251216-nova-unload-4029b3b76950

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>
author maintainer
#1 lore raw

PATCH v3 1/6 rust: add warn_on_err macro

While we already have the warn_on macro, a common usage pattern in Rust is to check whether a Result is an error. Add a helper macro that allows this.

---
 rust/kernel/bug.rs | 10 ++++++++++
 1 file changed, 10 insertions(+)
rust/kernel/bug.rs +10 -0
index ed943960f851..c5809c554da7 100644
@@ -130,3 +130,13 @@ macro_rules! warn_on {
         cond
     }};
 }
+
+/// Report a warning if `res` is an error and return `res` unmodified.
+#[macro_export]
+macro_rules! warn_on_err {
+    ($res:expr) => {{
+        let res = $res;
+        let _ = $crate::warn_on!(res.is_err());
+        res
+    }};
+}
Signature · 1 line
2.53.0
author maintainer
#6 lore raw

PATCH v3 2/6 gpu: nova-core: use warn_on_err macro

In reply to Alexandre Courbot

Use the warn_on_err macro in the unbind sequence, and refactor it to early-exit on the failure path as we will need to use the bar for other purposes.

---
 drivers/gpu/nova-core/gpu.rs | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/nova-core/gpu.rs +5 -5
index 0f6fe9a1b955..1701c2600538 100644
@@ -279,10 +279,10 @@ pub(crate) fn new<'a>(
     ///
     /// Note: This method must only be called from `Driver::unbind`.
     pub(crate) fn unbind(&self, dev: &device::Device<device::Core>) {
-        kernel::warn_on!(self
-            .bar
-            .access(dev)
-            .inspect(|bar| self.sysmem_flush.unregister(bar))
-            .is_err());
+        let Ok(bar) = kernel::warn_on_err!(self.bar.access(dev)) else {
+            return;
+        };
+
+        self.sysmem_flush.unregister(bar);
     }
 }
Signature · 1 line
2.53.0
author maintainer
#7 lore raw

PATCH v3 3/6 gpu: nova-core: remove unneeded get_gsp_info proxy function

In reply to Alexandre Courbot

This function was useful before the generic command-queue send methods got merged, but it is just boilerplate now. Replace it with the correct sequence to queue the GetGspStaticInfo command directly.

---
 drivers/gpu/nova-core/gsp/boot.rs     | 2 +-
 drivers/gpu/nova-core/gsp/commands.rs | 8 +-------
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +1 -1
index 18f356c9178e..9b6f349d3339 100644
@@ -229,7 +229,7 @@ pub(crate) fn boot(
         commands::wait_gsp_init_done(&self.cmdq)?;
 
         // Obtain and display basic GPU information.
-        let info = commands::get_gsp_info(&self.cmdq, bar)?;
+        let info = self.cmdq.send_command(bar, commands::GetGspStaticInfo)?;
         match info.gpu_name() {
             Ok(name) => dev_info!(pdev, "GPU name: {}\n", name),
             Err(e) => dev_warn!(pdev, "GPU name unavailable: {:?}\n", e),
drivers/gpu/nova-core/gsp/commands.rs +1 -7
index c89c7b57a751..e81a865050e0 100644
@@ -18,7 +18,6 @@
 };
 
 use crate::{
-    driver::Bar0,
     gsp::{
         cmdq::{
             Cmdq,
@@ -176,7 +175,7 @@ pub(crate) fn wait_gsp_init_done(cmdq: &Cmdq) -> Result {
 }
 
 /// The `GetGspStaticInfo` command.
-struct GetGspStaticInfo;
+pub(crate) struct GetGspStaticInfo;
 
 impl CommandToGsp for GetGspStaticInfo {
     const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo;
@@ -232,8 +231,3 @@ pub(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> {
             .map_err(GpuNameError::InvalidUtf8)
     }
 }
-
-/// Send the [`GetGspInfo`] command and awaits for its reply.
-pub(crate) fn get_gsp_info(cmdq: &Cmdq, bar: &Bar0) -> Result<GetGspStaticInfoReply> {
-    cmdq.send_command(bar, GetGspStaticInfo)
-}
Signature · 1 line
2.53.0
author maintainer
#9 lore raw

PATCH v3 4/6 gpu: nova-core: do not import firmware commands into GSP command module

In reply to Alexandre Courbot

Importing all the firmware commands like we did is a bit confusing, as the layer of a command type (fw or GSP) cannot be inferred from looking at its name alone. Furthermore it makes it impossible to create commands that have the same name as their firmware command.

Thus, stop importing all commands and refer to them from the fw module instead.

---
 drivers/gpu/nova-core/gsp/commands.rs | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/gpu/nova-core/gsp/commands.rs +12 -12
index e81a865050e0..484aeb7dfd39 100644
@@ -26,7 +26,7 @@
             NoReply, //
         },
         fw::{
-            commands::*,
+            self,
             MsgFunction, //
         },
     },
@@ -47,12 +47,12 @@ pub(crate) fn new(pdev: &'a pci::Device<device::Bound>) -> Self {
 
 impl<'a> CommandToGsp for SetSystemInfo<'a> {
     const FUNCTION: MsgFunction = MsgFunction::GspSetSystemInfo;
-    type Command = GspSetSystemInfo;
+    type Command = fw::commands::GspSetSystemInfo;
     type Reply = NoReply;
     type InitError = Error;
 
     fn init(&self) -> impl Init<Self::Command, Self::InitError> {
-        GspSetSystemInfo::init(self.pdev)
+        Self::Command::init(self.pdev)
     }
 }
 
@@ -99,12 +99,12 @@ pub(crate) fn new() -> Self {
 
 impl CommandToGsp for SetRegistry {
     const FUNCTION: MsgFunction = MsgFunction::SetRegistry;
-    type Command = PackedRegistryTable;
+    type Command = fw::commands::PackedRegistryTable;
     type Reply = NoReply;
     type InitError = Infallible;
 
     fn init(&self) -> impl Init<Self::Command, Self::InitError> {
-        PackedRegistryTable::init(Self::NUM_ENTRIES as u32, self.variable_payload_len() as u32)
+        Self::Command::init(Self::NUM_ENTRIES as u32, self.variable_payload_len() as u32)
     }
 
     fn variable_payload_len(&self) -> usize {
@@ -112,22 +112,22 @@ fn variable_payload_len(&self) -> usize {
         for i in 0..Self::NUM_ENTRIES {
             key_size += self.entries[i].key.len() + 1; // +1 for NULL terminator
         }
-        Self::NUM_ENTRIES * size_of::<PackedRegistryEntry>() + key_size
+        Self::NUM_ENTRIES * size_of::<fw::commands::PackedRegistryEntry>() + key_size
     }
 
     fn init_variable_payload(
         &self,
         dst: &mut SBufferIter<core::array::IntoIter<&mut [u8], 2>>,
     ) -> Result {
-        let string_data_start_offset =
-            size_of::<PackedRegistryTable>() + Self::NUM_ENTRIES * size_of::<PackedRegistryEntry>();
+        let string_data_start_offset = size_of::<Self::Command>()
+            + Self::NUM_ENTRIES * size_of::<fw::commands::PackedRegistryEntry>();
 
         // Array for string data.
         let mut string_data = KVec::new();
 
         for entry in self.entries.iter().take(Self::NUM_ENTRIES) {
             dst.write_all(
-                PackedRegistryEntry::new(
+                fw::commands::PackedRegistryEntry::new(
                     (string_data_start_offset + string_data.len()) as u32,
                     entry.value,
                 )
@@ -179,12 +179,12 @@ pub(crate) fn wait_gsp_init_done(cmdq: &Cmdq) -> Result {
 
 impl CommandToGsp for GetGspStaticInfo {
     const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo;
-    type Command = GspStaticConfigInfo;
+    type Command = fw::commands::GspStaticConfigInfo;
     type Reply = GetGspStaticInfoReply;
     type InitError = Infallible;
 
     fn init(&self) -> impl Init<Self::Command, Self::InitError> {
-        GspStaticConfigInfo::init_zeroed()
+        Self::Command::init_zeroed()
     }
 }
 
@@ -195,7 +195,7 @@ pub(crate) struct GetGspStaticInfoReply {
 
 impl MessageFromGsp for GetGspStaticInfoReply {
     const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo;
-    type Message = GspStaticConfigInfo;
+    type Message = fw::commands::GspStaticConfigInfo;
     type InitError = Infallible;
 
     fn read(
Signature · 1 line
2.53.0
author maintainer
#10 lore raw

PATCH v3 5/6 gpu: nova-core: send UNLOADING_GUEST_DRIVER GSP command upon unloading

In reply to Alexandre Courbot

Currently, the GSP is left running after the driver is unbound. This is not great for several reasons, notably that it can still access shared memory areas that the kernel will now reclaim (especially problematic on setups without an IOMMU).

Fix this by sending the UNLOADING_GUEST_DRIVER GSP command when unbinding. This stops the GSP and lets us proceed with the rest of the unbind sequence in the next patch.

---
 drivers/gpu/nova-core/gpu.rs                      |  5 +++
 drivers/gpu/nova-core/gsp/boot.rs                 | 45 +++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/commands.rs             | 41 +++++++++++++++++++++
 drivers/gpu/nova-core/gsp/fw.rs                   |  4 ++
 drivers/gpu/nova-core/gsp/fw/commands.rs          | 44 ++++++++++++++++++++++
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 11 ++++++
 6 files changed, 150 insertions(+)
drivers/gpu/nova-core/gpu.rs +5 -0
index 1701c2600538..8f2ae9e8a519 100644
@@ -277,12 +277,17 @@ pub(crate) fn new<'a>(
 
     /// Called when the corresponding [`Device`](device::Device) is unbound.
     ///
+    /// Prepares the GPU for unbinding by shutting down the GSP and unregistering the sysmem flush
+    /// memory page.
+    ///
     /// Note: This method must only be called from `Driver::unbind`.
     pub(crate) fn unbind(&self, dev: &device::Device<device::Core>) {
         let Ok(bar) = kernel::warn_on_err!(self.bar.access(dev)) else {
             return;
         };
 
+        let _ = kernel::warn_on_err!(self.gsp.unload(dev, bar, &self.gsp_falcon));
+
         self.sysmem_flush.unregister(bar);
     }
 }
drivers/gpu/nova-core/gsp/boot.rs +45 -0

61 lines not on this page · raw message

drivers/gpu/nova-core/gsp/commands.rs +41 -0

44 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw.rs +4 -0
index 0c8a74f0e8ac..59b4c4883185 100644
@@ -278,6 +278,7 @@ pub(crate) enum MsgFunction {
     Nop = bindings::NV_VGPU_MSG_FUNCTION_NOP,
     SetGuestSystemInfo = bindings::NV_VGPU_MSG_FUNCTION_SET_GUEST_SYSTEM_INFO,
     SetRegistry = bindings::NV_VGPU_MSG_FUNCTION_SET_REGISTRY,
+    UnloadingGuestDriver = bindings::NV_VGPU_MSG_FUNCTION_UNLOADING_GUEST_DRIVER,
 
     // Event codes
     GspInitDone = bindings::NV_VGPU_MSG_EVENT_GSP_INIT_DONE,
@@ -322,6 +323,9 @@ fn try_from(value: u32) -> Result<MsgFunction> {
                 Ok(MsgFunction::SetGuestSystemInfo)
             }
             bindings::NV_VGPU_MSG_FUNCTION_SET_REGISTRY => Ok(MsgFunction::SetRegistry),
+            bindings::NV_VGPU_MSG_FUNCTION_UNLOADING_GUEST_DRIVER => {
+                Ok(MsgFunction::UnloadingGuestDriver)
+            }
 
             // Event codes
             bindings::NV_VGPU_MSG_EVENT_GSP_INIT_DONE => Ok(MsgFunction::GspInitDone),
drivers/gpu/nova-core/gsp/fw/commands.rs +44 -0

47 lines not on this page · raw message

drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +11 -0
index 334e8be5fde8..f82ed097b283 100644
@@ -30,6 +30,9 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
         fmt.write_str("__IncompleteArrayField")
     }
 }
+pub const NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_0: u32 = 0;
+pub const NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_3: u32 = 3;
+pub const NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_7: u32 = 7;
 pub const NV_VGPU_MSG_SIGNATURE_VALID: u32 = 1129337430;
 pub const GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2: u32 = 0;
 pub const GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS3_BAREMETAL: u32 = 23068672;
@@ -880,6 +883,14 @@ fn default() -> Self {
     }
 }
 #[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct rpc_unloading_guest_driver_v1F_07 {
+    pub bInPMTransition: u8_,
+    pub bGc6Entering: u8_,
+    pub __bindgen_padding_0: [u8; 2usize],
+    pub newLevel: u32_,
+}
+#[repr(C)]
 #[derive(Debug, Default, MaybeZeroable)]
 pub struct rpc_run_cpu_sequencer_v17_00 {
     pub bufferSizeDWord: u32_,
Signature · 1 line
2.53.0
author maintainer
#12 lore raw

PATCH v3 6/6 gpu: nova-core: run Booter Unloader and FWSEC-SB upon unbinding

In reply to Alexandre Courbot

When probing the driver, the FWSEC-FRTS firmware creates a WPR2 secure memory region to store the GSP firmware, and the Booter Loader loads and starts that firmware into the GSP, making it run in RISC-V mode.

These operations need to be reverted upon unloading, particularly the WPR2 secure region creation, as its presence prevents the driver from subsequently probing.

Thus, load and run the Booter Unloader and FWSEC-SB firmwares at unbind time to put the GPU into a state where it can be probed again.

---
 drivers/gpu/nova-core/firmware/booter.rs |  1 -
 drivers/gpu/nova-core/firmware/fwsec.rs  |  1 -
 drivers/gpu/nova-core/gpu.rs             |  8 ++++-
 drivers/gpu/nova-core/gsp/boot.rs        | 53 ++++++++++++++++++++++++++++++++
 drivers/gpu/nova-core/regs.rs            |  5 +++
 5 files changed, 65 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/firmware/booter.rs +0 -1
index de2a4536b532..771b018ba580 100644
@@ -280,7 +280,6 @@ fn new_booter(data: &[u8]) -> Result<Self> {
 #[derive(Copy, Clone, Debug, PartialEq)]
 pub(crate) enum BooterKind {
     Loader,
-    #[expect(unused)]
     Unloader,
 }
 
drivers/gpu/nova-core/firmware/fwsec.rs +0 -1
index 8810cb49db67..4108f28cd338 100644
@@ -144,7 +144,6 @@ pub(crate) enum FwsecCommand {
     /// image into it.
     Frts { frts_addr: u64, frts_size: u64 },
     /// Asks [`FwsecFirmware`] to load pre-OS apps on the PMU.
-    #[expect(dead_code)]
     Sb,
 }
 
drivers/gpu/nova-core/gpu.rs +7 -1
index 8f2ae9e8a519..37d0e4587ed3 100644
@@ -286,7 +286,13 @@ pub(crate) fn unbind(&self, dev: &device::Device<device::Core>) {
             return;
         };
 
-        let _ = kernel::warn_on_err!(self.gsp.unload(dev, bar, &self.gsp_falcon));
+        let _ = kernel::warn_on_err!(self.gsp.unload(
+            dev,
+            bar,
+            self.spec.chipset,
+            &self.gsp_falcon,
+            &self.sec2_falcon,
+        ));
 
         self.sysmem_flush.unregister(bar);
     }
drivers/gpu/nova-core/gsp/boot.rs +53 -0

66 lines not on this page · raw message

drivers/gpu/nova-core/regs.rs +5 -0
index 2f171a4ff9ba..21ff5d15f648 100644
@@ -176,6 +176,11 @@ impl NV_PFB_PRI_MMU_WPR2_ADDR_HI {
     pub(crate) fn higher_bound(self) -> u64 {
         u64::from(self.hi_val()) << 12
     }
+
+    /// Returns whether the WPR2 region is currently set.
+    pub(crate) fn is_wpr2_set(self) -> bool {
+        self.hi_val() != 0
+    }
 }
 
 // PGSP
Signature · 1 line
2.53.0
Reviewed-by on v3 3/6
#8 lore raw

Re: [PATCH v3 3/6] gpu: nova-core: remove unneeded get_gsp_info proxy function

In reply to Alexandre Courbot
Quoted 6 lines · Alexandre Courbot

This function was useful before the generic command-queue send methods got merged, but it is just boilerplate now. Replace it with the correct sequence to queue the GetGspStaticInfo command directly.

---

Reviewed-by on v3 5/6
#11 lore raw

Re: [PATCH v3 5/6] gpu: nova-core: send UNLOADING_GUEST_DRIVER GSP command upon unloading

In reply to Alexandre Courbot
Quoted 11 lines · Alexandre Courbot

Currently, the GSP is left running after the driver is unbound. This is not great for several reasons, notably that it can still access shared memory areas that the kernel will now reclaim (especially problematic on setups without an IOMMU).

Fix this by sending the UNLOADING_GUEST_DRIVER GSP command when unbinding. This stops the GSP and lets us proceed with the rest of the unbind sequence in the next patch.

---

Acked-by on v3 1/6
#2 lore raw

Re: [PATCH v3 1/6] rust: add warn_on_err macro

In reply to Alexandre Courbot
Quoted 7 lines · Alexandre Courbot

While we already have the warn_on macro, a common usage pattern in Rust is to check whether a Result is an error. Add a helper macro that allows this.

I saw the discussion with Gary in v2 -- not sure if you are still putting this in. If so, and assuming Gary is OK with it, I guess it is fine as-is for now, but we should probably create at least a (good first?) issue:

Not sure about Sashiko's report -- it may be nice to make the macro more transparent, even if it would be rare to use it with expressions where it would matter.

Thanks!

Cheers,
Miguel

author maintainer
#3 lore raw

Re: [PATCH v3 1/6] rust: add warn_on_err macro

Quoted 9 lines · Miguel Ojeda
Quoted 7 lines · Alexandre Courbot

While we already have the warn_on macro, a common usage pattern in Rust is to check whether a Result is an error. Add a helper macro that allows this.

Quoted 6 lines

I saw the discussion with Gary in v2 -- not sure if you are still putting this in. If so, and assuming Gary is OK with it, I guess it is fine as-is for now, but we should probably create at least a (good first?) issue:

Thanks - I will send a separate patch for this shortly, and take it alongside the Nova unload series if it can be reviewed quickly.

Quoted 4 lines

Not sure about Sashiko's report -- it may be nice to make the macro more transparent, even if it would be rare to use it with expressions where it would matter.

Gary's proposal [1] looked good, so I think we can use just that.

[1] https://lore.kernel.org/all/[email protected]/

maintainer
#4 lore raw

Re: [PATCH v3 1/6] rust: add warn_on_err macro

Quoted 2 lines · Alexandre Courbot

Thanks - I will send a separate patch for this shortly, and take it alongside the Nova unload series if it can be reviewed quickly.

Do we still need this? It goes away with the lifetime series.

author maintainer
#5 lore raw

Re: [PATCH v3 1/6] rust: add warn_on_err macro

Quoted 4 lines · Danilo Krummrich
Quoted 2 lines · Alexandre Courbot

Thanks - I will send a separate patch for this shortly, and take it alongside the Nova unload series if it can be reviewed quickly.

Do we still need this? It goes away with the lifetime series.

Even after the lifetime series we still have this bit:

    let _ = self
        .gsp
        .unload(pdev.as_ref(), self.bar, &self.gsp_falcon, &self.sec2_falcon)
        .inspect_err(|e| dev_err!(pdev, "failed to unload GSP: {:?}\n", e));

where warn_on_err could apply, but it is definitely less essential.

However, since that pattern is likely to be common, I'd say it still makes sense to merge it (albeit outside of this series).

#13 lore raw
In reply to Alexandre Courbot
Quoted 3 lines · Alexandre Courbot

Currently the GSP is left running and the WPR2 memory region untouched when the driver is unbound. This is obviously not ideal for at least two reasons:

Hi,

Is this ready to merge, or are you looking for more reviews?

thanks,

Signature · 1 line
John Hubbard
Quoted 74 lines

- Probing requires setting up the WPR2 region, which cannot be done if there is already one in place. Hence the current requirement to reset the GPU (using e.g. echo 1 >/sys/bus/pci/devices/.../reset) before the driver can be probed again after removal.
- The running GSP may still attempt to access shared memory regions which the kernel might recycle.

On top of that, there is a nasty bug in the Blackwell VBIOS that sometimes borks the GPU upon PCI reset, requiring a reboot. So relying on the PCI reset to unload/reload Nova is really not practical here.

This series does what is needed to leave the GPU in a clean state after unbind, for all currently supported GPUs. Blackwell support is trivial and will be added alongside the Blackwell series [1] if this can be merged first.

The first patch adds a warn_on_err utility macro to the kernel crate as it is useful to warn on failures in the driver unbind path, but I can remove it if it is not deemed useful.

This series applies cleanly on master as of today.

[1] https://lore.kernel.org/all/[email protected]/

---
Changes in v3:
- Disambiguate doccomment for warn_on_err.
- Test the correct bit instead of the whole register value to determine that the GSP has stopped.
- Use an enum instead of a boolean to encode the power level when
shutting down the GSP.
- Add missing newline to dev_err.
- Add missing doccomments for new types.
- Use values from bindings instead of magic numbers.
- Remove the redundant get_gsp_info function.
- Better document Booter Unloader mailbox sentinel value, and check the value of mbox0 upon return.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Rebase on top of master and remove unneeded/obsolete preparatory patches.
- Tidy up the imports of commands from the fw module in the gsp module.
- Link to v1: https://patch.msgid.link/[email protected]

---
Alexandre Courbot (6):
rust: add warn_on_err macro
gpu: nova-core: use warn_on_err macro
gpu: nova-core: remove unneeded get_gsp_info proxy function
gpu: nova-core: do not import firmware commands into GSP command module
gpu: nova-core: send UNLOADING_GUEST_DRIVER GSP command upon unloading
gpu: nova-core: run Booter Unloader and FWSEC-SB upon unbinding

 drivers/gpu/nova-core/firmware/booter.rs          |   1 -
 drivers/gpu/nova-core/firmware/fwsec.rs           |   1 -
 drivers/gpu/nova-core/gpu.rs                      |  21 +++--
 drivers/gpu/nova-core/gsp/boot.rs                 | 100 +++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/commands.rs             |  69 +++++++++++----
 drivers/gpu/nova-core/gsp/fw.rs                   |   4 +
 drivers/gpu/nova-core/gsp/fw/commands.rs          |  44 ++++++++++
 drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs |  11 +++
 drivers/gpu/nova-core/regs.rs                     |   5 ++
 rust/kernel/bug.rs                                |  10 +++
 10 files changed, 241 insertions(+), 25 deletions(-)

---
base-commit: b4e07588e743c989499ca24d49e752c074924a9a
change-id: 20251216-nova-unload-4029b3b76950

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>
author maintainer
#14 lore raw
Quoted 8 lines · John Hubbard
Quoted 3 lines · Alexandre Courbot

Currently the GSP is left running and the WPR2 memory region untouched when the driver is unbound. This is obviously not ideal for at least two reasons:

Hi,

Is this ready to merge, or are you looking for more reviews?

This needs to be rebased (and applied after) the Device HRT series. I will try to post a v5 today that does that.