drm/amdkfd: cleanup device pointer dereference chains
Subsystems (3)
PATCH 1/2 drm/amdkfd: cleanup device pointer dereference chains
Pull out some duplicated dereference chains into variables, and in some cases grab struct device pointer directly from amdgpu_device instead of via drm_device.
--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +18 -14
@@ -1051,6 +1051,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i]; +struct amdgpu_device *adev = pdd->dev->adev;pr_debug ("Releasing pdd (topology id %d) for process (pasid 0x%x)\n" , pdd->dev->id, p->pasid);
@@ -1059,8 +1060,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)kfd_process_device_destroy_ib_mem (pdd);if (pdd->drm_file) { -amdgpu_amdkfd_gpuvm_release_process_vm ( - pdd->dev->adev, pdd->drm_priv); +amdgpu_amdkfd_gpuvm_release_process_vm (adev, + pdd->drm_priv);fput (pdd->drm_file); }
@@ -1073,15 +1074,14 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)kfd_free_process_doorbells (pdd->dev->kfd, pdd);if (pdd->dev->kfd->shared_resources.enable_mes) -amdgpu_amdkfd_free_gtt_mem (pdd->dev->adev, - &pdd->proc_ctx_bo); +amdgpu_amdkfd_free_gtt_mem (adev, &pdd->proc_ctx_bo);/* * before destroying pdd, make sure to report availability * for auto suspend */ if (pdd->runtime_inuse) { -pm_runtime_mark_last_busy (adev_to_drm (pdd->dev->adev)->dev); -pm_runtime_put_autosuspend (adev_to_drm (pdd->dev->adev)->dev); +pm_runtime_mark_last_busy (adev->dev); +pm_runtime_put_autosuspend (adev->dev); pdd->runtime_inuse = false; }
@@ -1606,6 +1606,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd =NULL ; +struct amdgpu_device *adev = dev->adev; +struct device *bdev = adev->dev;int retval =0 ;if (WARN_ON_ONCE (p->n_pdds >=MAX_GPU_INSTANCE ))
@@ -1631,14 +1633,17 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,atomic64_set (&pdd->evict_duration_counter,0 );if (dev->kfd->shared_resources.enable_mes) { - retval =amdgpu_amdkfd_alloc_gtt_mem (dev->adev, + retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); + retval =amdgpu_amdkfd_alloc_gtt_mem ( + adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, + &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false);if (retval) { -dev_err (dev->adev->dev, +dev_err (bdev,"failed to allocate process context bo\n" ); goto err_free_pdd; }
@@ -1647,10 +1652,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, p->pdds[p->n_pdds++] = pdd;if (kfd_dbg_is_per_vmid_supported (pdd->dev)) - pdd->spi_dbg_override = pdd->dev->kfd2kgd->disable_debug_trap ( - pdd->dev->adev, - false, -0 ); + pdd->spi_dbg_override = + pdd->dev->kfd2kgd->disable_debug_trap (adev, false,0 );/* Init idr used for memory handle translation */ idr_init (&pdd->alloc_idr);
@@ -1750,11 +1753,12 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd; +struct device *bdev = dev->adev->dev;int err; pdd =kfd_get_process_device_data (dev, p);if (!pdd) { -dev_err (dev->adev->dev,"Process device data doesn't exist\n" ); +dev_err (bdev,"Process device data doesn't exist\n" );return ERR_PTR (-ENOMEM ); }
@@ -1767,7 +1771,7 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,* pdd is destroyed. */ if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (adev_to_drm (dev->adev)->dev); + err =pm_runtime_get_sync (bdev);if (err <0 ) {pm_runtime_put_autosuspend (adev_to_drm (dev->adev)->dev);return ERR_PTR (err);
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdkfd: pause autosuspend when creating pdd
When using MES creating a pdd will require talking to the GPU to setup the relevant context. The code here forgot to wake up the GPU in case it was in suspend, this causes KVM to EFAULT for passthrough GPU for example.
Also, change the other place where we pause suspend to use the cleaner pm_runtime_resume_and_get helper.
---
It is unclear to me if kfd_process_destroy_pdds also have this problem, or is freeing gtt mem guaranteed to succeed even with the GPU in suspend.
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +9 -4
@@ -1633,6 +1633,11 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,atomic64_set (&pdd->evict_duration_counter,0 );if (dev->kfd->shared_resources.enable_mes) { + retval =pm_runtime_resume_and_get (bdev); +if (retval <0 ) { +pr_err ("failed to stop autosuspend\n" ); + goto err_free_pdd; + } retval = amdgpu_amdkfd_alloc_gtt_mem(adev, AMDGPU_MES_PROC_CTX_SIZE, &pdd->proc_ctx_bo,
@@ -1642,6 +1647,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, retval =amdgpu_amdkfd_alloc_gtt_mem ( adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); +pm_runtime_mark_last_busy (bdev); +pm_runtime_put_autosuspend (bdev);if (retval) {dev_err (bdev,"failed to allocate process context bo\n" );
@@ -1771,11 +1778,9 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,* pdd is destroyed. */ if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (bdev); -if (err <0 ) { -pm_runtime_put_autosuspend (adev_to_drm (dev->adev)->dev); + err =pm_runtime_resume_and_get (bdev); +if (err <0 )return ERR_PTR (err); - } }/*
Signature · 1 line
2.34.1
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 92 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Yunxiang Li
Sent: Thursday, October 10, 2024 11:19 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>
Subject: [PATCH 1/2] drm/amdkfd: cleanup device pointer dereference chainsPull out some duplicated dereference chains into variables, and in some cases grab struct device pointer directly from
amdgpu_deviceinstead of viadrm_device.Signed-off-by Yunxiang Li <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0@@ -1051,6 +1051,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i]; +struct amdgpu_device *adev = pdd->dev->adev; pr_debug("Releasing pdd (topology id %d) for process (pasid0x%x)\n",
pdd->dev->id, p->pasid);drivers/gpu/drm/amd/amdkfd/kfd_process.c +5
-6@@ -1059,8 +1060,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)kfd_process_device_destroy_ib_mem (pdd );if (pdd->drm_file) { -amdgpu_amdkfd_gpuvm_release_process_vm ( - pdd->dev->adev, pdd->drm_priv); +amdgpu_amdkfd_gpuvm_release_process_vm (adev, + pdd->drm_priv);fput (pdd->drm_file); }@@ -1073,15 +1074,14 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) kfd_free_process_doorbells(pdd->dev->kfd, pdd);if (pdd->dev->kfd->shared_resources.enable_mes) -amdgpu_amdkfd_free_gtt_mem (pdd->dev->adev, - &pdd->proc_ctx_bo); +amdgpu_amdkfd_free_gtt_mem (adev, &pdd->proc_ctx_bo);/* * before destroying pdd, make sure to report availability * for auto suspend */ if (pdd->runtime_inuse) { -pm_runtime_mark_last_busy (adev_to_drm (pdd->dev- >adev)->dev); -pm_runtime_put_autosuspend (adev_to_drm (pdd->dev- >adev)->dev); +pm_runtime_mark_last_busy (adev->dev); +pm_runtime_put_autosuspend (adev->dev);pdd->runtime_inuse = false; }drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-0@@ -1606,6 +1606,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd =NULL ; +struct amdgpu_device *adev = dev->adev; +struct device *bdev = adev->dev;int retval =0 ;if (WARN_ON_ONCE(p->n_pdds >= MAX_GPU_INSTANCE)) @@ - 1631,14 +1633,17 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, atomic64_set(&pdd->evict_duration_counter, 0); if (dev->kfd->shared_resources.enable_mes) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-1- retval =amdgpu_amdkfd_alloc_gtt_mem (dev->adev, + retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); + retval = amdgpu_amdkfd_alloc_gtt_mem( + adev, AMDGPU_MES_PROC_CTX_SIZE, &pdd-Quoted 1 line
proc_ctx_bo,
Quoted 1 line
+
&pdd->proc_ctx_gpu_addr,&pdd->proc_ctx_cpu_ptr, false);
Looks like you are duplicating the amdgpu_amdkfd_alloc_gtt_mem call here.
Regards,
Mukul
Quoted 48 lines
if (retval) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-5-dev_err (dev->adev->dev, +dev_err (bdev,"failed to allocate process context bo\n" ); goto err_free_pdd; }@@ -1647,10 +1652,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, p->pdds[p->n_pdds++] = pdd;if (kfd_dbg_is_per_vmid_supported (pdd->dev)) - pdd->spi_dbg_override = pdd->dev->kfd2kgd->disable_debug_trap ( - pdd->dev->adev, - false, -0 ); + pdd->spi_dbg_override = + pdd->dev->kfd2kgd->disable_debug_trap (adev, false,0 );/* Init idr used for memory handle translation */ idr_init(&pdd->alloc_idr);drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-2@@ -1750,11 +1753,12 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd; +struct device *bdev = dev->adev->dev;int err; pdd =kfd_get_process_device_data (dev, p);if (!pdd) { -dev_err (dev->adev->dev,"Process device data doesn't exist\n" ); +dev_err (bdev,"Process device data doesn't exist\n" );return ERR_PTR (-ENOMEM ); }@@ -1767,7 +1771,7 @@ struct kfd_process_device*kfd_bind_process_to_device(struct kfd_node *dev, * pdd is destroyed. */ if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (adev_to_drm (dev->adev)->dev); + err =pm_runtime_get_sync (bdev);if (err <0 ) { pm_runtime_put_autosuspend(adev_to_drm(dev->adev)-Quoted 1 line
dev);
return ERR_PTR(err);--
2.34.1
[AMD Official Use Only - AMD Internal Distribution Only]
Oops, lemme fix that real quick...
Quoted 166 lines
-----Original Message-----
From: Joshi, Mukul <[email protected]>
Sent: Thursday, October 10, 2024 11:46
To: Li, Yunxiang (Teddy) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>
Subject: RE: [PATCH 1/2] drm/amdkfd: cleanup device pointer dereference chains[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 11 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Yunxiang Li
Sent: Thursday, October 10, 2024 11:19 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>
Subject: [PATCH 1/2] drm/amdkfd: cleanup device pointer dereference chainsQuoted 2 lines
Pull out some duplicated dereference chains into variables, and in some cases grab struct device pointer directly from
amdgpu_deviceinstead of via
drm_device.Quoted 82 lines
Signed-off-by Yunxiang Li <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0@@ -1051,6 +1051,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i]; +struct amdgpu_device *adev = pdd->dev->adev; pr_debug("Releasing pdd (topology id %d) for process(pasid 0x%x)\n",
pdd->dev->id, p->pasid); @@ -1059,8 +1060,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) kfd_process_device_destroy_ib_mem(pdd); if (pdd->drm_file) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +9
-6-amdgpu_amdkfd_gpuvm_release_process_vm ( - pdd->dev->adev, pdd->drm_priv); +amdgpu_amdkfd_gpuvm_release_process_vm (adev, + + pdd->drm_priv);fput (pdd->drm_file); }@@ -1073,15 +1074,14 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) kfd_free_process_doorbells(pdd->dev->kfd, pdd);if (pdd->dev->kfd->shared_resources.enable_mes) -amdgpu_amdkfd_free_gtt_mem (pdd->dev->adev, - &pdd->proc_ctx_bo); +amdgpu_amdkfd_free_gtt_mem (adev, + &pdd->proc_ctx_bo);/* * before destroying pdd, make sure to report availability * for auto suspend */ if (pdd->runtime_inuse) { -pm_runtime_mark_last_busy (adev_to_drm (pdd->dev- >adev)->dev); -pm_runtime_put_autosuspend (adev_to_drm (pdd->dev- >adev)->dev); +pm_runtime_mark_last_busy (adev->dev); +pm_runtime_put_autosuspend (adev->dev); pdd->runtime_inuse = false; }@@ -1606,6 +1606,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd =NULL ; +struct amdgpu_device *adev = dev->adev; +struct device *bdev = adev->dev;int retval =0 ;if (WARN_ON_ONCE(p->n_pdds >= MAX_GPU_INSTANCE)) @@ - 1631,14 +1633,17 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, atomic64_set(&pdd->evict_duration_counter, 0); if (dev->kfd->shared_resources.enable_mes) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-1- retval =amdgpu_amdkfd_alloc_gtt_mem (dev->adev, + retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); + retval = amdgpu_amdkfd_alloc_gtt_mem( + adev, AMDGPU_MES_PROC_CTX_SIZE, &pdd-Quoted 1 line
proc_ctx_bo,Quoted 2 lines
+
&pdd->proc_ctx_gpu_addr,&pdd->proc_ctx_cpu_ptr,
+ false);Looks like you are duplicating the
amdgpu_amdkfd_alloc_gtt_memcall here.Regards,
MukulQuoted 50 lines
if (retval) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +7
-7-dev_err (dev->adev->dev, +dev_err (bdev,"failed to allocate process context bo\n" ); goto err_free_pdd; }@@ -1647,10 +1652,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, p->pdds[p->n_pdds++] = pdd;if (kfd_dbg_is_per_vmid_supported (pdd->dev)) - pdd->spi_dbg_override = pdd->dev->kfd2kgd->disable_debug_trap ( - pdd->dev->adev, - false, -0 ); + pdd->spi_dbg_override = + pdd->dev->kfd2kgd->disable_debug_trap (adev, + false,0 );/* Init idr used for memory handle translation */ idr_init (&pdd->alloc_idr);@@ -1750,11 +1753,12 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd; +struct device *bdev = dev->adev->dev;int err; pdd =kfd_get_process_device_data (dev, p);if (!pdd) { -dev_err (dev->adev->dev,"Process device data doesn't exist\n" ); +dev_err (bdev,"Process device data doesn't exist\n" );return ERR_PTR (-ENOMEM ); }@@ -1767,7 +1771,7 @@ struct kfd_process_device*kfd_bind_process_to_device(struct kfd_node *dev, * pdd is destroyed. */ if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (adev_to_drm (dev->adev)->dev); + err =pm_runtime_get_sync (bdev);if (err <0 ) {pm_runtime_put_autosuspend(adev_to_drm(dev->adev)-
Quoted 1 line
dev);
return ERR_PTR(err);--
2.34.1
PATCH v2 1/2 drm/amdkfd: cleanup device pointer dereference chains
In reply to Yunxiang LiPull out some duplicated dereference chains into variables, and in some cases grab struct device pointer directly from amdgpu_device instead of via drm_device.
--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +15 -14
@@ -1051,6 +1051,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i]; +struct amdgpu_device *adev = pdd->dev->adev;pr_debug ("Releasing pdd (topology id %d) for process (pasid 0x%x)\n" , pdd->dev->id, p->pasid);
@@ -1059,8 +1060,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)kfd_process_device_destroy_ib_mem (pdd);if (pdd->drm_file) { -amdgpu_amdkfd_gpuvm_release_process_vm ( - pdd->dev->adev, pdd->drm_priv); +amdgpu_amdkfd_gpuvm_release_process_vm (adev, + pdd->drm_priv);fput (pdd->drm_file); }
@@ -1073,15 +1074,14 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)kfd_free_process_doorbells (pdd->dev->kfd, pdd);if (pdd->dev->kfd->shared_resources.enable_mes) -amdgpu_amdkfd_free_gtt_mem (pdd->dev->adev, - &pdd->proc_ctx_bo); +amdgpu_amdkfd_free_gtt_mem (adev, &pdd->proc_ctx_bo);/* * before destroying pdd, make sure to report availability * for auto suspend */ if (pdd->runtime_inuse) { -pm_runtime_mark_last_busy (adev_to_drm (pdd->dev->adev)->dev); -pm_runtime_put_autosuspend (adev_to_drm (pdd->dev->adev)->dev); +pm_runtime_mark_last_busy (adev->dev); +pm_runtime_put_autosuspend (adev->dev); pdd->runtime_inuse = false; }
@@ -1606,6 +1606,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd =NULL ; +struct amdgpu_device *adev = dev->adev; +struct device *bdev = adev->dev;int retval =0 ;if (WARN_ON_ONCE (p->n_pdds >=MAX_GPU_INSTANCE ))
@@ -1631,14 +1633,14 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,atomic64_set (&pdd->evict_duration_counter,0 );if (dev->kfd->shared_resources.enable_mes) { - retval =amdgpu_amdkfd_alloc_gtt_mem (dev->adev, + retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false);if (retval) { -dev_err (dev->adev->dev, +dev_err (bdev,"failed to allocate process context bo\n" ); goto err_free_pdd; }
@@ -1647,10 +1649,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, p->pdds[p->n_pdds++] = pdd;if (kfd_dbg_is_per_vmid_supported (pdd->dev)) - pdd->spi_dbg_override = pdd->dev->kfd2kgd->disable_debug_trap ( - pdd->dev->adev, - false, -0 ); + pdd->spi_dbg_override = + pdd->dev->kfd2kgd->disable_debug_trap (adev, false,0 );/* Init idr used for memory handle translation */ idr_init (&pdd->alloc_idr);
@@ -1750,11 +1750,12 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd; +struct device *bdev = dev->adev->dev;int err; pdd =kfd_get_process_device_data (dev, p);if (!pdd) { -dev_err (dev->adev->dev,"Process device data doesn't exist\n" ); +dev_err (bdev,"Process device data doesn't exist\n" );return ERR_PTR (-ENOMEM ); }
@@ -1767,7 +1768,7 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,* pdd is destroyed. */ if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (adev_to_drm (dev->adev)->dev); + err =pm_runtime_get_sync (bdev);if (err <0 ) {pm_runtime_put_autosuspend (adev_to_drm (dev->adev)->dev);return ERR_PTR (err);
Signature · 1 line
2.34.1
PATCH v2 2/2 drm/amdkfd: pause autosuspend when creating pdd
When using MES creating a pdd will require talking to the GPU to setup the relevant context. The code here forgot to wake up the GPU in case it was in suspend, this causes KVM to EFAULT for passthrough GPU for example.
Also, change the other place where we pause suspend to use the cleaner pm_runtime_resume_and_get helper.
---
It is unclear to me if kfd_process_destroy_pdds also have this problem, or is freeing gtt mem guaranteed to succeed even with the GPU in suspend.
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +9 -4
@@ -1633,12 +1633,19 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,atomic64_set (&pdd->evict_duration_counter,0 );if (dev->kfd->shared_resources.enable_mes) { + retval =pm_runtime_resume_and_get (bdev); +if (retval <0 ) { +pr_err ("failed to stop autosuspend\n" ); + goto err_free_pdd; + } retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); +pm_runtime_mark_last_busy (bdev); +pm_runtime_put_autosuspend (bdev);if (retval) {dev_err (bdev,"failed to allocate process context bo\n" );
@@ -1768,11 +1775,9 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,* pdd is destroyed. */ if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (bdev); -if (err <0 ) { -pm_runtime_put_autosuspend (adev_to_drm (dev->adev)->dev); + err =pm_runtime_resume_and_get (bdev); +if (err <0 )return ERR_PTR (err); - } }/*
Signature · 1 line
2.34.1
RE: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pdd
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 33 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Yunxiang Li
Sent: Thursday, October 10, 2024 12:18 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>
Subject: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pddWhen using MES creating a pdd will require talking to the GPU to setup the relevant context. The code here forgot to wake up the GPU in case it was in suspend, this causes KVM to EFAULT for passthrough GPU for example.
Also, change the other place where we pause suspend to use the cleaner
pm_runtime_resume_and_gethelper.Fixes cc009e613de6 ("drm/amdkfd: Add KFD support for soc21 v3")Signed-off-by Yunxiang Li <[email protected]>---
It is unclear to me if
kfd_process_destroy_pddsalso have this problem, or is freeing gtt mem guaranteed to succeed even with the GPU in suspend.drivers/gpu/drm/amd/amdkfd/kfd_process.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_process.c struct kfd_process_device · line 1641
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +5
-0@@ -1633,12 +1633,19 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, atomic64_set(&pdd->evict_duration_counter, 0);if (dev->kfd->shared_resources.enable_mes) { + retval =pm_runtime_resume_and_get (bdev); +if (retval <0 ) { +pr_err ("failed to stop autosuspend\n" ); + goto err_free_pdd; + }
I am not 100% sure if it makes sense to resume here and then put it back on suspend queue after the allocation. And then again call pm_runtime_resume in kfd_bind_process_to_device().
Maybe you can set pdd->runtime_inuse = true here itself and not call the pm_runtime_put_autosuspend here.
I will probably let @Kuehling, Felix comment on this.
Regards,
Mukul
Quoted 29 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-0retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); +pm_runtime_mark_last_busy (bdev); +pm_runtime_put_autosuspend (bdev);if (retval) { dev_err(bdev,"failed to allocate process context bo\n"); @@ -
1768,11 +1775,9 @@ structkfd_process_device*kfd_bind_process_to_device(structkfd_node*dev,* pdd is destroyed. */ if (!pdd->runtime_inuse) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-3- err =pm_runtime_get_sync (bdev); -if (err <0 ) { - pm_runtime_put_autosuspend(adev_to_drm(dev->adev)-Quoted 1 line
dev);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-2+ err =pm_runtime_resume_and_get (bdev); +if (err <0 )return ERR_PTR (err); - } }/* -- 2.34.1
Felix Kuehling
maintainerRe: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pdd
Quoted 49 lines · Mukul
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 33 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Yunxiang Li
Sent: Thursday, October 10, 2024 12:18 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>
Subject: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pddWhen using MES creating a pdd will require talking to the GPU to setup the relevant context. The code here forgot to wake up the GPU in case it was in suspend, this causes KVM to EFAULT for passthrough GPU for example.
Also, change the other place where we pause suspend to use the cleaner
pm_runtime_resume_and_gethelper.Fixes cc009e613de6 ("drm/amdkfd: Add KFD support for soc21 v3")Signed-off-by Yunxiang Li <[email protected]>---
It is unclear to me if
kfd_process_destroy_pddsalso have this problem, or is freeing gtt mem guaranteed to succeed even with the GPU in suspend.drivers/gpu/drm/amd/amdkfd/kfd_process.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0drivers/gpu/drm/amd/amdkfd/kfd_process.c struct kfd_process_device · line 1641
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +5
-0@@ -1633,12 +1633,19 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, atomic64_set(&pdd->evict_duration_counter, 0);if (dev->kfd->shared_resources.enable_mes) { + retval =pm_runtime_resume_and_get (bdev); +if (retval <0 ) { +pr_err ("failed to stop autosuspend\n" ); + goto err_free_pdd; + }I am not 100% sure if it makes sense to resume here and then put it back on suspend queue after the allocation. And then again call
pm_runtime_resumeinkfd_bind_process_to_device().
Maybe you can setpdd->runtime_inuse= true here itself and not call thepm_runtime_put_autosuspendhere.
Quoted 1 line
I will probably let @Kuehling, Felix comment on this.
I don't think we want to set pdd->runtime_inuse here. That would make all GPUs like they're always in use, no matter if the application is actually using them. I think this part of the change is OK.
Quoted 25 lines
Regards,
MukulQuoted 21 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-0retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); +pm_runtime_mark_last_busy (bdev); +pm_runtime_put_autosuspend (bdev);if (retval) { dev_err(bdev,"failed to allocate process context bo\n"); @@ -
1768,11 +1775,9 @@ structkfd_process_device*kfd_bind_process_to_device(structkfd_node*dev,* pdd is destroyed. */ if (!pdd->runtime_inuse) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-3- err =pm_runtime_get_sync (bdev); -if (err <0 ) { - pm_runtime_put_autosuspend(adev_to_drm(dev->adev)-Quoted 1 line
dev);
+ err =
pm_runtime_resume_and_get(bdev);
I got confused here, looking at the number of interfaces available in the pm_runtime header file. There seem to be many ways to do the same thing. There may be subtle difference between them. It's not obvious to me that this change is correct or harmless.
Regards,
Felix
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-2+if (err <0 )return ERR_PTR (err); - } }/* -- 2.34.1
RE: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pdd
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, my understanding is that autosuspend happens after a timeout, so it would only go into suspend if the pdd is not used for a while after it's created.
Teddy
RE: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pdd
In reply to Felix Kuehling[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 63 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Friday, October 11, 2024 11:17 AM
To: Joshi, Mukul <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>
Subject: Re: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pddQuoted 17 lines · Mukul
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 15 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Yunxiang Li
Sent: Thursday, October 10, 2024 12:18 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>; Li, Yunxiang
(Teddy) <[email protected]>
Subject: [PATCH v2 2/2] drm/amdkfd: pause autosuspend when creating pddWhen using MES creating a pdd will require talking to the GPU to setup the relevant context. The code here forgot to wake up the GPU in case it was in suspend, this causes KVM to EFAULT for passthrough GPU
for example.
Quoted 10 lines
Quoted 10 lines
Also, change the other place where we pause suspend to use the cleaner
pm_runtime_resume_and_gethelper.Fixes cc009e613de6 ("drm/amdkfd: Add KFD support for soc21 v3")Signed-off-by Yunxiang Li <[email protected]>---
It is unclear to me if
kfd_process_destroy_pddsalso have this problem, or is freeing gtt mem guaranteed to succeed even with the GPU insuspend.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0@@ -1633,12 +1633,19 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, atomic64_set(&pdd->evict_duration_counter, 0);Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, · line 1640
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +5
-0if (dev->kfd->shared_resources.enable_mes) { + retval =pm_runtime_resume_and_get (bdev); +if (retval <0 ) { +pr_err ("failed to stop autosuspend\n" ); + goto err_free_pdd; + }I am not 100% sure if it makes sense to resume here and then put it back on suspend queue after the allocation. And then again call
pm_runtime_resumeinkfd_bind_process_to_device().
Quoted 9 lines
Quoted 1 line
Maybe you can set
pdd->runtime_inuse= true here itself and not call the
pm_runtime_put_autosuspendhere.Quoted 2 lines
I will probably let @Kuehling, Felix comment on this.
I don't think we want to set
pdd->runtime_inusehere. That would make all GPUs like they're always in use, no matter if the application is actually using them. I think this part of the change is OK.
Ok thanks. I got confused and thought we would call kfd_bind_to_process() everytime. But that’s not the case.
Quoted 24 lines
Quoted 24 lines
Regards,
MukulQuoted 20 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-0retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false); +pm_runtime_mark_last_busy (bdev); +pm_runtime_put_autosuspend (bdev);if (retval) { dev_err(bdev,"failed to allocate process context
bo\n"); @@ -
1768,11 +1775,9 @@ structkfd_process_device*kfd_bind_process_to_device(structkfd_node*dev,* pdd is destroyed. */ if (!pdd->runtime_inuse) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-3- err =pm_runtime_get_sync (bdev); -if (err <0 ) { - pm_runtime_put_autosuspend(adev_to_drm(dev->adev)-
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
dev);
+ err =
pm_runtime_resume_and_get(bdev);I got confused here, looking at the number of interfaces available in the
pm_runtimeheader file. There seem to be many ways to do the same thing. There may be subtle difference between them. It's not obvious to me that this change is correct or harmless.
I think it is OK. The function description above pm_runtime_get_sync() says to consider using pm_runtime_resume_and_get() instead.
Regards,
Mukul
Quoted 13 lines
Regards,
FelixQuoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-2+if (err <0 )return ERR_PTR (err); - } }/* -- 2.34.1
[AMD Official Use Only - AMD Internal Distribution Only]
This patch is:
Quoted 137 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Yunxiang Li
Sent: Thursday, October 10, 2024 12:17 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Gui, Jack <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>
Subject: [PATCH v2 1/2] drm/amdkfd: cleanup device pointer dereference chainsPull out some duplicated dereference chains into variables, and in some cases grab struct device pointer directly from
amdgpu_deviceinstead of viadrm_device.Signed-off-by Yunxiang Li <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0@@ -1051,6 +1051,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)for (i =0 ; i < p->n_pdds; i++) {struct kfd_process_device *pdd = p->pdds[i]; +struct amdgpu_device *adev = pdd->dev->adev; pr_debug("Releasing pdd (topology id %d) for process (pasid0x%x)\n",
pdd->dev->id, p->pasid);drivers/gpu/drm/amd/amdkfd/kfd_process.c +5
-6@@ -1059,8 +1060,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)kfd_process_device_destroy_ib_mem (pdd );if (pdd->drm_file) { -amdgpu_amdkfd_gpuvm_release_process_vm ( - pdd->dev->adev, pdd->drm_priv); +amdgpu_amdkfd_gpuvm_release_process_vm (adev, + pdd->drm_priv);fput (pdd->drm_file); }@@ -1073,15 +1074,14 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) kfd_free_process_doorbells(pdd->dev->kfd, pdd);if (pdd->dev->kfd->shared_resources.enable_mes) -amdgpu_amdkfd_free_gtt_mem (pdd->dev->adev, - &pdd->proc_ctx_bo); +amdgpu_amdkfd_free_gtt_mem (adev, &pdd->proc_ctx_bo);/* * before destroying pdd, make sure to report availability * for auto suspend */ if (pdd->runtime_inuse) { -pm_runtime_mark_last_busy (adev_to_drm (pdd->dev- >adev)->dev); -pm_runtime_put_autosuspend (adev_to_drm (pdd->dev- >adev)->dev); +pm_runtime_mark_last_busy (adev->dev); +pm_runtime_put_autosuspend (adev->dev);pdd->runtime_inuse = false; }drivers/gpu/drm/amd/amdkfd/kfd_process.c +2
-0@@ -1606,6 +1606,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd =NULL ; +struct amdgpu_device *adev = dev->adev; +struct device *bdev = adev->dev;int retval =0 ;if (WARN_ON_ONCE(p->n_pdds >= MAX_GPU_INSTANCE)) @@ - 1631,14 +1633,14 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, atomic64_set(&pdd->evict_duration_counter, 0); if (dev->kfd->shared_resources.enable_mes) {drivers/gpu/drm/amd/amdkfd/kfd_process.c +4
-6- retval =amdgpu_amdkfd_alloc_gtt_mem (dev->adev, + retval =amdgpu_amdkfd_alloc_gtt_mem (adev,AMDGPU_MES_PROC_CTX_SIZE , &pdd->proc_ctx_bo, &pdd->proc_ctx_gpu_addr, &pdd->proc_ctx_cpu_ptr, false);if (retval) { -dev_err (dev->adev->dev, +dev_err (bdev,"failed to allocate process context bo\n" ); goto err_free_pdd; }@@ -1647,10 +1649,8 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, p->pdds[p->n_pdds++] = pdd;if (kfd_dbg_is_per_vmid_supported (pdd->dev)) - pdd->spi_dbg_override = pdd->dev->kfd2kgd->disable_debug_trap ( - pdd->dev->adev, - false, -0 ); + pdd->spi_dbg_override = + pdd->dev->kfd2kgd->disable_debug_trap (adev, false,0 );/* Init idr used for memory handle translation */ idr_init(&pdd->alloc_idr);drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-2@@ -1750,11 +1750,12 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev, struct kfd_process *p) {struct kfd_process_device *pdd; +struct device *bdev = dev->adev->dev;int err; pdd =kfd_get_process_device_data (dev, p);if (!pdd) { -dev_err (dev->adev->dev,"Process device data doesn't exist\n" ); +dev_err (bdev,"Process device data doesn't exist\n" );return ERR_PTR (-ENOMEM ); }@@ -1767,7 +1768,7 @@ struct kfd_process_device*kfd_bind_process_to_device(struct kfd_node *dev, * pdd is destroyed. */ if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (adev_to_drm (dev->adev)->dev); + err =pm_runtime_get_sync (bdev);if (err <0 ) { pm_runtime_put_autosuspend(adev_to_drm(dev->adev)-Quoted 1 line
dev);
return ERR_PTR(err);--
2.34.1