drm/amdgpu: remove gfx sysfs files on device unbind
Subsystems (2)
PATCH 1/1 drm/amdgpu: remove gfx sysfs files on device unbind
Fix another sysfs duplication error when reinitializing the device:
sysfs: cannot create duplicate filename '.../enforce_isolation'
Fix this by:
- improve amdgpu_gfx_sysfs_init error unwinding so partially-created gfx sysfs files are removed on registration failure.
- added adev->gfx.sysfs_registered tracking so gfx sysfs cleanup is idempotent when harware teardown runs before the existing software teardown cleanup path.
- calling amdgpu_gfx_sysfs_fini from amdgpu_device_fini_hw before the general device sysfs cleanup.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 32 +++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 ++ 3 files changed, 28 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -4242,6 +4242,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) }amdgpu_fence_driver_hw_fini (adev); +amdgpu_gfx_sysfs_fini (adev);amdgpu_device_sys_interface_fini (adev);/* disable ras feature must before hw fini */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +25 -7
@@ -2195,6 +2195,8 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) {int r; + adev->gfx.sysfs_registered = false; + r =amdgpu_gfx_sysfs_xcp_init (adev);if (r) {dev_err (adev->dev,"failed to create xcp sysfs files" );
@@ -2202,23 +2204,39 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) } r =amdgpu_gfx_sysfs_isolation_shader_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create isolation sysfs files" ); + goto err_isolation_shader; + } r =amdgpu_gfx_sysfs_reset_mask_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create reset mask sysfs files" ); + goto err_reset_mask; + } + adev->gfx.sysfs_registered = true; + +return 0 ; + +err_reset_mask: +amdgpu_gfx_sysfs_reset_mask_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +err_isolation_shader: +amdgpu_gfx_sysfs_xcp_fini (adev);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { -if (adev->dev->kobj.sd) { -amdgpu_gfx_sysfs_xcp_fini (adev); -amdgpu_gfx_sysfs_isolation_shader_fini (adev); -amdgpu_gfx_sysfs_reset_mask_fini (adev); - } +if (!adev->gfx.sysfs_registered) +return ; + +amdgpu_gfx_sysfs_xcp_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +amdgpu_gfx_sysfs_reset_mask_fini (adev); + + adev->gfx.sysfs_registered = false; } static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -0
@@ -477,6 +477,8 @@ struct amdgpu_gfx {struct amdgpu_irq_src rlc_poison_irq;struct sq_work sq_work; +bool sysfs_registered; +/* gfx status */ uint32_t gfx_current_status;/* ce ram size*/
--
2.43.0
PATCH v2 1/1 drm/amdgpu: remove gfx sysfs files on device unbind
Fix more sysfs file duplication errors when reinitializing the device:
sysfs: cannot create duplicate filename '.../enforce_isolation'
sysfs: cannot create duplicate filename '.../sdma_reset_mask'
sysfs: cannot create duplicate filename '.../vcn_reset_mask'
sysfs: cannot create duplicate filename '.../jpeg_reset_mask'
sysfs: cannot create duplicate filename '.../vpe_reset_mask'
sysfs: cannot create duplicate filename '.../current_memory_partition'
sysfs: cannot create duplicate filename '.../available_memory_partition'
Fix this by:
- improve amdgpu_gfx_sysfs_init error unwinding so partially-created gfx sysfs files are removed on registration failure.
- added adev->gfx.sysfs_registered tracking so gfx sysfs cleanup is idempotent when harware teardown runs before the existing software teardown cleanup path.
- calling amdgpu_gfx_sysfs_fini, amdgpu_sdma_sysfs_reset_mask_fini, amdgpu_vcn_sysfs_reset_mask_fini, amdgpu_jpeg_sysfs_reset_mask_fini, amdgpu_vpe_sysfs_reset_mask_fini and amdgpu_gmc_sysfs_fini from amdgpu_device_sys_interface_fini
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 32 +++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 ++ 3 files changed, 35 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
@@ -3674,6 +3674,14 @@ static int amdgpu_device_sys_interface_init(struct amdgpu_device *adev)static void amdgpu_device_sys_interface_fini (struct amdgpu_device *adev) { +amdgpu_gfx_sysfs_fini (adev); +amdgpu_sdma_sysfs_reset_mask_fini (adev); +amdgpu_vcn_sysfs_reset_mask_fini (adev); +amdgpu_jpeg_sysfs_reset_mask_fini (adev); +amdgpu_vpe_sysfs_reset_mask_fini (adev); +if (amdgpu_is_multi_aid (adev)) +amdgpu_gmc_sysfs_fini (adev); +if (adev->pm.sysfs_initialized)amdgpu_pm_sysfs_fini (adev);if (adev->ucode_sysfs_en)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +25 -7
@@ -2175,6 +2175,8 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) {int r; + adev->gfx.sysfs_registered = false; + r =amdgpu_gfx_sysfs_xcp_init (adev);if (r) {dev_err (adev->dev,"failed to create xcp sysfs files" );
@@ -2182,23 +2184,39 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) } r =amdgpu_gfx_sysfs_isolation_shader_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create isolation sysfs files" ); + goto err_isolation_shader; + } r =amdgpu_gfx_sysfs_reset_mask_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create reset mask sysfs files" ); + goto err_reset_mask; + } + adev->gfx.sysfs_registered = true; + +return 0 ; + +err_reset_mask: +amdgpu_gfx_sysfs_reset_mask_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +err_isolation_shader: +amdgpu_gfx_sysfs_xcp_fini (adev);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { -if (adev->dev->kobj.sd) { -amdgpu_gfx_sysfs_xcp_fini (adev); -amdgpu_gfx_sysfs_isolation_shader_fini (adev); -amdgpu_gfx_sysfs_reset_mask_fini (adev); - } +if (!adev->gfx.sysfs_registered) +return ; + +amdgpu_gfx_sysfs_xcp_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +amdgpu_gfx_sysfs_reset_mask_fini (adev); + + adev->gfx.sysfs_registered = false; } static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -0
@@ -477,6 +477,8 @@ struct amdgpu_gfx {struct amdgpu_irq_src rlc_poison_irq;struct sq_work sq_work; +bool sysfs_registered; +/* gfx status */ uint32_t gfx_current_status;/* ce ram size*/
Signature · 1 line
2.43.0
Christian König
maintainerQuoted 21 lines · Geoffrey McRae
Fix more sysfs file duplication errors when reinitializing the device:
sysfs: cannot create duplicate filename '.../enforce_isolation'
sysfs: cannot create duplicate filename '.../sdma_reset_mask'
sysfs: cannot create duplicate filename '.../vcn_reset_mask'
sysfs: cannot create duplicate filename '.../jpeg_reset_mask'
sysfs: cannot create duplicate filename '.../vpe_reset_mask'
sysfs: cannot create duplicate filename '.../current_memory_partition'
sysfs: cannot create duplicate filename '.../available_memory_partition'Fix this by:
- improveamdgpu_gfx_sysfs_initerror unwinding so partially-created gfx sysfs files are removed on registration failure.
- addedadev->gfx.sysfs_registeredtracking so gfx sysfs cleanup is idempotent when harware teardown runs before the existing software teardown cleanup path.
- callingamdgpu_gfx_sysfs_fini,amdgpu_sdma_sysfs_reset_mask_fini,amdgpu_vcn_sysfs_reset_mask_fini,amdgpu_jpeg_sysfs_reset_mask_fini,amdgpu_vpe_sysfs_reset_mask_finiandamdgpu_gmc_sysfs_finifromamdgpu_device_sys_interface_fini
Quoted 3 lines
Signed-off-by Geoffrey McRae <[email protected]>Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>
Alex can you take a look at this?
In general the coding seems correct, but Greg usually insists that we use the managed sysfs functions which remove stuff automatically on driver unbind.
But if I'm not completely mistaken that doesn't work here because the device structure is not released before all userspace refs drop.
If the device is re-created before that happens we run into the error above.
Regards,
Christian.
Quoted 98 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 32 +++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 ++ 3 files changed, 35 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-0@@ -3674,6 +3674,14 @@ static int amdgpu_device_sys_interface_init(struct amdgpu_device *adev)static void amdgpu_device_sys_interface_fini (struct amdgpu_device *adev) { +amdgpu_gfx_sysfs_fini (adev); +amdgpu_sdma_sysfs_reset_mask_fini (adev); +amdgpu_vcn_sysfs_reset_mask_fini (adev); +amdgpu_jpeg_sysfs_reset_mask_fini (adev); +amdgpu_vpe_sysfs_reset_mask_fini (adev); +if (amdgpu_is_multi_aid (adev)) +amdgpu_gmc_sysfs_fini (adev); +if (adev->pm.sysfs_initialized)amdgpu_pm_sysfs_fini (adev);if (adev->ucode_sysfs_en)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +25
-7@@ -2175,6 +2175,8 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) {int r; + adev->gfx.sysfs_registered = false; + r =amdgpu_gfx_sysfs_xcp_init (adev);if (r) {dev_err (adev->dev,"failed to create xcp sysfs files" );@@ -2182,23 +2184,39 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) } r =amdgpu_gfx_sysfs_isolation_shader_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create isolation sysfs files" ); + goto err_isolation_shader; + } r =amdgpu_gfx_sysfs_reset_mask_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create reset mask sysfs files" ); + goto err_reset_mask; + } + adev->gfx.sysfs_registered = true; + +return 0 ; + +err_reset_mask: +amdgpu_gfx_sysfs_reset_mask_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +err_isolation_shader: +amdgpu_gfx_sysfs_xcp_fini (adev);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { -if (adev->dev->kobj.sd) { -amdgpu_gfx_sysfs_xcp_fini (adev); -amdgpu_gfx_sysfs_isolation_shader_fini (adev); -amdgpu_gfx_sysfs_reset_mask_fini (adev); - } +if (!adev->gfx.sysfs_registered) +return ; + +amdgpu_gfx_sysfs_xcp_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +amdgpu_gfx_sysfs_reset_mask_fini (adev); + + adev->gfx.sysfs_registered = false; } static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2
-0@@ -477,6 +477,8 @@ struct amdgpu_gfx {struct amdgpu_irq_src rlc_poison_irq;struct sq_work sq_work; +bool sysfs_registered; +/* gfx status */ uint32_t gfx_current_status;/* ce ram size*/
Quoted 27 lines · Christian König
Quoted 21 lines · Geoffrey McRae
Fix more sysfs file duplication errors when reinitializing the device:
sysfs: cannot create duplicate filename '.../enforce_isolation'
sysfs: cannot create duplicate filename '.../sdma_reset_mask'
sysfs: cannot create duplicate filename '.../vcn_reset_mask'
sysfs: cannot create duplicate filename '.../jpeg_reset_mask'
sysfs: cannot create duplicate filename '.../vpe_reset_mask'
sysfs: cannot create duplicate filename '.../current_memory_partition'
sysfs: cannot create duplicate filename '.../available_memory_partition'Fix this by:
- improveamdgpu_gfx_sysfs_initerror unwinding so partially-created gfx sysfs files are removed on registration failure.
- addedadev->gfx.sysfs_registeredtracking so gfx sysfs cleanup is idempotent when harware teardown runs before the existing software teardown cleanup path.
- callingamdgpu_gfx_sysfs_fini,amdgpu_sdma_sysfs_reset_mask_fini,amdgpu_vcn_sysfs_reset_mask_fini,amdgpu_jpeg_sysfs_reset_mask_fini,amdgpu_vpe_sysfs_reset_mask_finiandamdgpu_gmc_sysfs_finifromamdgpu_device_sys_interface_finiQuoted 3 lines
Signed-off-by Geoffrey McRae <[email protected]>Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>
Quoted 7 lines
Alex can you take a look at this?
In general the coding seems correct, but Greg usually insists that we use the managed sysfs functions which remove stuff automatically on driver unbind.
But if I'm not completely mistaken that doesn't work here because the device structure is not released before all userspace refs drop.
If the device is re-created before that happens we run into the error above.
I think the proper fix for this is to properly unwind in amdgpu_device_ip_init(). If sw_init() fails, we should goto a proper unwind loop which calls sw_fini() for all IPs where status.sw == true, etc.
Alex
Quoted 104 lines
Regards,
Christian.Quoted 98 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 32 +++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 ++ 3 files changed, 35 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-0@@ -3674,6 +3674,14 @@ static int amdgpu_device_sys_interface_init(struct amdgpu_device *adev)static void amdgpu_device_sys_interface_fini (struct amdgpu_device *adev) { +amdgpu_gfx_sysfs_fini (adev); +amdgpu_sdma_sysfs_reset_mask_fini (adev); +amdgpu_vcn_sysfs_reset_mask_fini (adev); +amdgpu_jpeg_sysfs_reset_mask_fini (adev); +amdgpu_vpe_sysfs_reset_mask_fini (adev); +if (amdgpu_is_multi_aid (adev)) +amdgpu_gmc_sysfs_fini (adev); +if (adev->pm.sysfs_initialized)amdgpu_pm_sysfs_fini (adev);if (adev->ucode_sysfs_en)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +25
-7@@ -2175,6 +2175,8 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) {int r; + adev->gfx.sysfs_registered = false; + r =amdgpu_gfx_sysfs_xcp_init (adev);if (r) {dev_err (adev->dev,"failed to create xcp sysfs files" );@@ -2182,23 +2184,39 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) } r =amdgpu_gfx_sysfs_isolation_shader_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create isolation sysfs files" ); + goto err_isolation_shader; + } r =amdgpu_gfx_sysfs_reset_mask_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create reset mask sysfs files" ); + goto err_reset_mask; + } + adev->gfx.sysfs_registered = true; + +return 0 ; + +err_reset_mask: +amdgpu_gfx_sysfs_reset_mask_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +err_isolation_shader: +amdgpu_gfx_sysfs_xcp_fini (adev);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { -if (adev->dev->kobj.sd) { -amdgpu_gfx_sysfs_xcp_fini (adev); -amdgpu_gfx_sysfs_isolation_shader_fini (adev); -amdgpu_gfx_sysfs_reset_mask_fini (adev); - } +if (!adev->gfx.sysfs_registered) +return ; + +amdgpu_gfx_sysfs_xcp_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +amdgpu_gfx_sysfs_reset_mask_fini (adev); + + adev->gfx.sysfs_registered = false; } static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2
-0@@ -477,6 +477,8 @@ struct amdgpu_gfx {struct amdgpu_irq_src rlc_poison_irq;struct sq_work sq_work; +bool sysfs_registered; +/* gfx status */ uint32_t gfx_current_status;/* ce ram size*/
PATCH v2 1/1 drm/amdgpu: fix sysfs duplicate errors and incomplete unwind in ip_init
When amdgpu_device_ip_init() fails partway through, IP blocks that had completed sw_init() were never unwound, leaving sysfs files registered. On the next device init attempt this produced duplicate filename errors:
sysfs: cannot create duplicate filename '.../enforce_isolation'
sysfs: cannot create duplicate filename '.../sdma_reset_mask'
sysfs: cannot create duplicate filename '.../vcn_reset_mask'
sysfs: cannot create duplicate filename '.../jpeg_reset_mask'
sysfs: cannot create duplicate filename '.../vpe_reset_mask'
sysfs: cannot create duplicate filename '.../current_memory_partition'
sysfs: cannot create duplicate filename '.../available_memory_partition'
Fix the init_failed unwind path in amdgpu_device_ip_init() to properly reverse all initialisation performed by the function:
- Call sw_fini() in reverse order for all IP blocks where status.sw is true, mirroring amdgpu_device_ip_fini().
- For the GMC block, free the resources allocated during its early hw_init phase in the correct reverse order: seq64, static CSA, writeback buffer, and mem scratch page.
- Free resources initialised after the IP block loop: ucode BO, IB pool, KFD device, TTM buffer funcs, and the SRIOV vf2pf data exchange work item.
Additionally, fix amdgpu_gfx_sysfs_init() to properly unwind partially registered gfx sysfs files on registration failure, and drop the now-unnecessary kobj.sd liveness guard from amdgpu_gfx_sysfs_fini() since device_remove_file() is safe to call during sysfs teardown.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 21 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 23 +++++++++++++++------- 2 files changed, 37 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +21 -0
@@ -2491,6 +2491,27 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev) r =amdgpu_cper_init (adev); init_failed: +if (r) { +amdgpu_amdkfd_device_fini_sw (adev); +amdgpu_ttm_disable_buffer_funcs (adev); +if (amdgpu_sriov_vf (adev)) +amdgpu_virt_fini_data_exchange (adev); +amdgpu_ucode_free_bo (adev); +amdgpu_ib_pool_fini (adev); +for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) { +if (!adev->ip_blocks[i].status.sw) +continue ; +if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_GMC ) { +amdgpu_seq64_fini (adev); +amdgpu_free_static_csa (&adev->virt.csa_obj); +amdgpu_device_wb_fini (adev); +amdgpu_device_mem_scratch_fini (adev); + } +if (adev->ip_blocks[i].version->funcs->sw_fini) + adev->ip_blocks[i].version->funcs->sw_fini (&adev->ip_blocks[i]); + adev->ip_blocks[i].status.sw = false; + } + }return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +16 -7
@@ -2182,23 +2182,32 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) } r =amdgpu_gfx_sysfs_isolation_shader_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create isolation sysfs files" ); + goto err_isolation_shader; + } r =amdgpu_gfx_sysfs_reset_mask_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create reset mask sysfs files" ); + goto err_reset_mask; + } + +return 0 ; +err_reset_mask: +amdgpu_gfx_sysfs_reset_mask_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +err_isolation_shader: +amdgpu_gfx_sysfs_xcp_fini (adev);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { -if (adev->dev->kobj.sd) { -amdgpu_gfx_sysfs_xcp_fini (adev); -amdgpu_gfx_sysfs_isolation_shader_fini (adev); -amdgpu_gfx_sysfs_reset_mask_fini (adev); - } +amdgpu_gfx_sysfs_xcp_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +amdgpu_gfx_sysfs_reset_mask_fini (adev); } static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device *adev,
Signature · 1 line
2.43.0
Deucher, Alexander
maintainerRE: [PATCH v2] drm/amdgpu: fix sysfs duplicate errors and incomplete unwind in ip_init
Public
Quoted 81 lines
-----Original Message-----
From: McRae, Geoffrey <[email protected]>
Sent: Thursday, July 9, 2026 12:53 AM
To: Deucher, Alexander <[email protected]>
Cc: Koenig, Christian <[email protected]>; amd- [email protected]; McRae, Geoffrey <[email protected]>
Subject: [PATCH v2] drm/amdgpu: fix sysfs duplicate errors and incomplete unwind inip_initWhen
amdgpu_device_ip_init()fails partway through, IP blocks that had completedsw_init()were never unwound, leaving sysfs files registered. On the next device init attempt this produced duplicate filename errors:sysfs: cannot create duplicate filename '.../enforce_isolation'
sysfs: cannot create duplicate filename '.../sdma_reset_mask'
sysfs: cannot create duplicate filename '.../vcn_reset_mask'
sysfs: cannot create duplicate filename '.../jpeg_reset_mask'
sysfs: cannot create duplicate filename '.../vpe_reset_mask'
sysfs: cannot create duplicate filename '.../current_memory_partition'
sysfs: cannot create duplicate filename '.../available_memory_partition'Fix the
init_failedunwind path inamdgpu_device_ip_init()to properly reverse all initialisation performed by the function:- Call
sw_fini()in reverse order for all IP blocks where status.sw is true, mirroringamdgpu_device_ip_fini().- For the GMC block, free the resources allocated during its early
hw_initphase in the correct reverse order: seq64, static CSA, writeback buffer, and mem scratch page.- Free resources initialised after the IP block loop: ucode BO, IB pool, KFD device, TTM buffer funcs, and the SRIOV vf2pf data exchange work item.
Additionally, fix
amdgpu_gfx_sysfs_init()to properly unwind partially registered gfx sysfs files on registration failure, and drop the now-unnecessary kobj.sd liveness guard fromamdgpu_gfx_sysfs_fini()sincedevice_remove_file()is safe to call during sysfs teardown.Signed-off-by Geoffrey McRae <[email protected]>Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 21 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 23 +++++++++++++++----- -- 2 files changed, 37 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18
-0@@ -2491,6 +2491,27 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev) r =amdgpu_cper_init (adev); init_failed: +if (r) { +amdgpu_amdkfd_device_fini_sw (adev); +amdgpu_ttm_disable_buffer_funcs (adev); +if (amdgpu_sriov_vf (adev)) +amdgpu_virt_fini_data_exchange (adev); +amdgpu_ucode_free_bo (adev); +amdgpu_ib_pool_fini (adev); +for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) { +if (!adev->ip_blocks[i].status.sw) +continue ; +if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_GMC ) { +amdgpu_seq64_fini (adev); +amdgpu_free_static_csa (&adev- >virt.csa_obj); +amdgpu_device_wb_fini (adev); +amdgpu_device_mem_scratch_fini (adev); + } +if (adev->ip_blocks[i].version->funcs->sw_fini) + adev->ip_blocks[i].version->funcs-Quoted 1 line
sw_fini(&adev->ip_blocks[i]);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0+ adev->ip_blocks[i].status.sw = false; + }
Also need to unwind all of the other stuff in that function (hw_init(), ucode bo allocation, etc.). Might be easier to call amdgpu_device_ip_fini() instead to cover all of the unwinding properly.
Alex
Quoted 52 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0+ }return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +16
-7@@ -2182,23 +2182,32 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) } r =amdgpu_gfx_sysfs_isolation_shader_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create isolation sysfs files" ); + goto err_isolation_shader; + } r =amdgpu_gfx_sysfs_reset_mask_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create reset mask sysfs files" ); + goto err_reset_mask; + } + +return 0 ; +err_reset_mask: +amdgpu_gfx_sysfs_reset_mask_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +err_isolation_shader: +amdgpu_gfx_sysfs_xcp_fini (adev);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { -if (adev->dev->kobj.sd) { -amdgpu_gfx_sysfs_xcp_fini (adev); -amdgpu_gfx_sysfs_isolation_shader_fini (adev); -amdgpu_gfx_sysfs_reset_mask_fini (adev); - } +amdgpu_gfx_sysfs_xcp_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +amdgpu_gfx_sysfs_reset_mask_fini (adev); } static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device*adev,
--
2.43.0
Re: [PATCH v2] drm/amdgpu: fix sysfs duplicate errors and incomplete unwind in ip_init
Public
Quoted 89 lines
________________________________________
From: Deucher, Alexander <[email protected]>
Sent: Saturday, 11 July 2026 5:52 AM
To: McRae, Geoffrey
Cc: Koenig, Christian; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: fix sysfs duplicate errors and incomplete unwind inip_initPublic
Quoted 80 lines
-----Original Message-----
From: McRae, Geoffrey <[email protected]>
Sent: Thursday, July 9, 2026 12:53 AM
To: Deucher, Alexander <[email protected]>
Cc: Koenig, Christian <[email protected]>; amd- [email protected]; McRae, Geoffrey <[email protected]>
Subject: [PATCH v2] drm/amdgpu: fix sysfs duplicate errors and incomplete unwind inip_initWhen
amdgpu_device_ip_init()fails partway through, IP blocks that had completedsw_init()were never unwound, leaving sysfs files registered. On the next device init attempt this produced duplicate filename errors:sysfs: cannot create duplicate filename '.../enforce_isolation'
sysfs: cannot create duplicate filename '.../sdma_reset_mask'
sysfs: cannot create duplicate filename '.../vcn_reset_mask'
sysfs: cannot create duplicate filename '.../jpeg_reset_mask'
sysfs: cannot create duplicate filename '.../vpe_reset_mask'
sysfs: cannot create duplicate filename '.../current_memory_partition'
sysfs: cannot create duplicate filename '.../available_memory_partition'Fix the
init_failedunwind path inamdgpu_device_ip_init()to properly reverse all initialisation performed by the function:- Call
sw_fini()in reverse order for all IP blocks where status.sw is true, mirroringamdgpu_device_ip_fini().- For the GMC block, free the resources allocated during its early
hw_initphase in the correct reverse order: seq64, static CSA, writeback buffer, and mem scratch page.- Free resources initialised after the IP block loop: ucode BO, IB pool, KFD device, TTM buffer funcs, and the SRIOV vf2pf data exchange work item.
Additionally, fix
amdgpu_gfx_sysfs_init()to properly unwind partially registered gfx sysfs files on registration failure, and drop the now-unnecessary kobj.sd liveness guard fromamdgpu_gfx_sysfs_fini()sincedevice_remove_file()is safe to call during sysfs teardown.Signed-off-by Geoffrey McRae <[email protected]>Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 21 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 23 +++++++++++++++----- -- 2 files changed, 37 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18
-0@@ -2491,6 +2491,27 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev) r =amdgpu_cper_init (adev); init_failed: +if (r) { +amdgpu_amdkfd_device_fini_sw (adev); +amdgpu_ttm_disable_buffer_funcs (adev); +if (amdgpu_sriov_vf (adev)) +amdgpu_virt_fini_data_exchange (adev); +amdgpu_ucode_free_bo (adev); +amdgpu_ib_pool_fini (adev); +for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) { +if (!adev->ip_blocks[i].status.sw) +continue ; +if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_GMC ) { +amdgpu_seq64_fini (adev); +amdgpu_free_static_csa (&adev- >virt.csa_obj); +amdgpu_device_wb_fini (adev); +amdgpu_device_mem_scratch_fini (adev); + } +if (adev->ip_blocks[i].version->funcs->sw_fini) + adev->ip_blocks[i].version->funcs-
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
Quoted 3 lines
Quoted 1 line
sw_fini(&adev->ip_blocks[i]);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0+ adev->ip_blocks[i].status.sw = false; + }Also need to unwind all of the other stuff in that function (
hw_init(), ucode bo allocation, etc.). Might be easier to callamdgpu_device_ip_fini()instead to cover all of the unwinding properly.Alex
ip_fini_early() and ip_fini() make assumptions about device state that don't hold for a partially initialised device, for example, ip_fini() calls amdgpu_doorbell_fini() from the GMC block, but doorbells are owned by the outer amdgpu_device_init() and would be double-freed. The init_failed unwind is the correct approach, we already handle sw_fini for all IP blocks, and the associated resources (ucode BO, IB pool, WB, mem scratch, seq64, CSA, KFD, TTM buffer funcs) are all properly torn down.
Geoff
Quoted 53 lines
Quoted 53 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0+ }return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +16
-7@@ -2182,23 +2182,32 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev) } r =amdgpu_gfx_sysfs_isolation_shader_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create isolation sysfs files" ); + goto err_isolation_shader; + } r =amdgpu_gfx_sysfs_reset_mask_init (adev); -if (r) +if (r) {dev_err (adev->dev,"failed to create reset mask sysfs files" ); + goto err_reset_mask; + } + +return 0 ; +err_reset_mask: +amdgpu_gfx_sysfs_reset_mask_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +err_isolation_shader: +amdgpu_gfx_sysfs_xcp_fini (adev);return r; }void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev) { -if (adev->dev->kobj.sd) { -amdgpu_gfx_sysfs_xcp_fini (adev); -amdgpu_gfx_sysfs_isolation_shader_fini (adev); -amdgpu_gfx_sysfs_reset_mask_fini (adev); - } +amdgpu_gfx_sysfs_xcp_fini (adev); +amdgpu_gfx_sysfs_isolation_shader_fini (adev); +amdgpu_gfx_sysfs_reset_mask_fini (adev); } static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device*adev,
--
2.43.0