Skip to contentSkip to conversation

drm/amdgpu: Init zone device and drm client after mode-1 reset on reload

PATCH Superseded Ahmad Rehman 2 participants 4 messages Mar 4, 2024 – Mar 5, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Init zone device and drm client after mode-1 reset on reload

In passthrough environment, when amdgpu is reloaded after unload, mode-1 is triggered after initializing the necessary IPs, That init does not include KFD, and KFD init waits until the reset is completed. KFD init is called in the reset handler, but in this case, the zone device and drm client is not initialized, causing app to create kernel panic.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -1
index 15b188aaf681..80b9642f2bc4 100644
@@ -2479,8 +2479,11 @@ static void amdgpu_drv_delayed_reset_work_handler(struct work_struct *work)
 	}
 	for (i = 0; i < mgpu_info.num_dgpu; i++) {
 		adev = mgpu_info.gpu_ins[i].adev;
-		if (!adev->kfd.init_complete)
+		if (!adev->kfd.init_complete) {
+			kgd2kfd_init_zone_device(adev);
 			amdgpu_amdkfd_device_init(adev);
+			amdgpu_amdkfd_drm_client_create(adev);
+		}
 		amdgpu_ttm_set_buffer_funcs_status(adev, true);
 	}
 }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Ahmad Rehman

In passthrough environment, when amdgpu is reloaded after unload, mode-1 is triggered after initializing the necessary IPs, That init does not include KFD, and KFD init waits until the reset is completed. KFD init is called in the reset handler, but in this case, the zone device and drm client is not initialized, causing app to create kernel panic.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -0
index 15b188aaf681..80b9642f2bc4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static void amdgpu_drv_delayed_reset_work_handler(struct work_struct *work) · line 2485

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -1
@@ -2479,8 +2479,11 @@ static void amdgpu_drv_delayed_reset_work_handler(struct work_struct *work)
  	}
  	for (i = 0; i < mgpu_info.num_dgpu; i++) {
  		adev = mgpu_info.gpu_ins[i].adev;
-		if (!adev->kfd.init_complete)
+		if (!adev->kfd.init_complete) {
+			kgd2kfd_init_zone_device(adev);
  			amdgpu_amdkfd_device_init(adev);
+			amdgpu_amdkfd_drm_client_create(adev);

I don't see what's preventing the DRM client initialization in the reset-on-driver-load case. It only needs to be created once and that happens in amdgpu_pci_probe. Am I missing anything?

Regards,
  Felix

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
+		}
  		amdgpu_ttm_set_buffer_funcs_status(adev, true);
  	}
  }
#2 lore raw

[AMD Official Use Only - General]

Hey,

Due to mode-1 reset (pending_reset), the amdgpu_amdkfd_device_init will not be called and hence adev->kfd.init_complete will not be set. The function amdgpu_amdkfd_drm_client_create has condition:
if (!adev->kfd.init_complete)

                return 0;

So, in probe function, when we return from device_init the KFD is not initialized and amdgpu_amdkfd_drm_client_create returns without doing anything.

Thanks,
Ahmad

________________________________
From: Kuehling, Felix <[email protected]>
Sent: Monday, March 4, 2024 6:39 PM
To: Rehman, Ahmad <[email protected]>; [email protected] <[email protected]>
Cc: Wan, Gavin <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Init zone device and drm client after mode-1 reset on reload

Quoted 16 lines · Ahmad Rehman

In passthrough environment, when amdgpu is reloaded after unload, mode-1 is triggered after initializing the necessary IPs, That init does not include KFD, and KFD init waits until the reset is completed. KFD init is called in the reset handler, but in this case, the zone device and drm client is not initialized, causing app to create kernel panic.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -0
index 15b188aaf681..80b9642f2bc4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static void amdgpu_drv_delayed_reset_work_handler(struct work_struct *work) · line 2485

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -1
@@ -2479,8 +2479,11 @@ static void amdgpu_drv_delayed_reset_work_handler(struct work_struct *work)
       }
       for (i = 0; i < mgpu_info.num_dgpu; i++) {
               adev = mgpu_info.gpu_ins[i].adev;
-             if (!adev->kfd.init_complete)
+             if (!adev->kfd.init_complete) {
+                     kgd2kfd_init_zone_device(adev);
                       amdgpu_amdkfd_device_init(adev);
+                     amdgpu_amdkfd_drm_client_create(adev);

I don't see what's preventing the DRM client initialization in the reset-on-driver-load case. It only needs to be created once and that happens in amdgpu_pci_probe. Am I missing anything?

Regards,
Felix

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
+             }
               amdgpu_ttm_set_buffer_funcs_status(adev, true);
       }
  }
#3 lore raw
Quoted 11 lines · Ahmad

[AMD Official Use Only - General]

Hey,

Due to mode-1 reset (pending_reset), the amdgpu_amdkfd_device_init will not be called and hence adev->kfd.init_complete will not be set. The function amdgpu_amdkfd_drm_client_create has condition:
if (!adev->kfd.init_complete)
              return 0;
So, in probe function, when we return from device_init the KFD is not initialized and amdgpu_amdkfd_drm_client_create returns without doing anything.

I think your change could result in calling amdgpu_amdkfd_drm_client_create multiple times. IIRC, one purpose of moving the call to amdgpu_pci_probe was to ensure that it is only called once, because it only gets unregistered once when the driver is unloaded. Maybe it would be better to remove the if (!adev->kfd.init_complete) condition from amdgpu_amdkfd_drm_client_create. That way we would always create the client at probe and it would be ready when it's needed after the GPU reset.

There is a chance that the client would get created unnecessarily if KFD init never succeeds. But that should be rare, and it's not a big resource waste.

There were some comments on a previous code review, that creating the DRM client too early could cause problems. But I don't understand what that problem could be. As I understand it, the adev->kfd.client is just a place to put GEM handles for KFD BOs that we don't want to expose to user mode. I see no harm in creating this client too early or when it's not needed.

Regards,
  Felix

Quoted 50 lines

Thanks,
Ahmad

------------------------------------------------------------------------
*From:* Kuehling, Felix <[email protected]>
*Sent:* Monday, March 4, 2024 6:39 PM
*To:* Rehman, Ahmad <[email protected]>; [email protected] <[email protected]> *Cc:* Wan, Gavin <[email protected]>
*Subject:* Re: [PATCH] drm/amdgpu: Init zone device and drm client after mode-1 reset on reload

Quoted 6 lines · Ahmad Rehman

In passthrough environment, when amdgpu is reloaded after unload, mode-1 is triggered after initializing the necessary IPs, That init does not include KFD, and KFD init waits until the reset is completed. KFD init is called in the reset handler, but in this case, the zone device and drm client is not initialized, causing app to create kernel panic.

Review

Quoted 6 lines

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 5 ++++-

   1 file changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static void

Quoted 4 lines

index 15b188aaf681..80b9642f2bc4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -0
@@ -2479,8 +2479,11 @@ static void 

amdgpu_drv_delayed_reset_work_handler(struct work_struct *work)

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static void amdgpu_drv_delayed_reset_work_handler(struct work_struct *work) · line 2485

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -1
         }
         for (i = 0; i < mgpu_info.num_dgpu; i++) {
                 adev = mgpu_info.gpu_ins[i].adev;
-             if (!adev->kfd.init_complete)
+             if (!adev->kfd.init_complete) {
+                     kgd2kfd_init_zone_device(adev);
                         amdgpu_amdkfd_device_init(adev);
+ amdgpu_amdkfd_drm_client_create(adev);

I don't see what's preventing the DRM client initialization in the reset-on-driver-load case. It only needs to be created once and that happens in amdgpu_pci_probe. Am I missing anything?

Regards,
   Felix

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
+             }
                 amdgpu_ttm_set_buffer_funcs_status(adev, true);
         }
    }