Commit eaa1281bfa2c ("drm/amdgpu: add an option to allow gpu partition
allocate all available memory") added creation of the
compute_partition_mem_alloc_mode sysfs file in amdgpu_gfx_sysfs_xcp_init()
but did not add the corresponding removal in amdgpu_gfx_sysfs_xcp_fini().

This causes a sysfs duplicate filename error on module reload
(modprobe -r amdgpu && modprobe amdgpu), since the file from the
previous load was never cleaned up. The sysfs_create_file_ns() call
returns -EEXIST (-17), which propagates through gfx_v9_4_3_sw_init()
and causes a fatal GPU init failure:

  sysfs: cannot create duplicate filename
    'devices/pci0000:00/.../compute_partition_mem_alloc_mode'
  amdgpu: failed to create xcp sysfs files
  amdgpu: sw_init of IP block <gfx_v9_4_3> failed -17
  amdgpu: Fatal error during GPU init

Add the missing device_remove_file() call for
dev_attr_compute_partition_mem_alloc_mode in amdgpu_gfx_sysfs_xcp_fini().

Fixes: eaa1281bfa2c ("drm/amdgpu: add an option to allow gpu partition allocate 
all available memory")
Signed-off-by: Chengjun Yao <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 2956e45c9254..bb2bcfb33823 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -2012,6 +2012,7 @@ static void amdgpu_gfx_sysfs_xcp_fini(struct 
amdgpu_device *adev)
        xcp_switch_supported =
                (xcp_mgr->funcs && xcp_mgr->funcs->switch_partition_mode);
        device_remove_file(adev->dev, &dev_attr_current_compute_partition);
+       device_remove_file(adev->dev, 
&dev_attr_compute_partition_mem_alloc_mode);
 
        if (xcp_switch_supported)
                device_remove_file(adev->dev,
-- 
2.43.0

Reply via email to