amdgpu_init() registers the ATPX handler before it detects the ACPI XCC/NUMA info, and amdgpu_exit() also unregisters the handler first. The two do not depend on each other, so swap them to release in the reverse order of initialization, which is also the order the error path of amdgpu_init() is going to use.
KFD and the PCI driver keep their order: KFD is initialized before the PCI driver is registered and is also torn down first. That is not an oversight. A primary KFD context can outlive its /dev/kfd file, and amdgpu_amdkfd_fini() releases such contexts while the devices still exist, whereas removing the devices first can send SIGBUS to their processes and wait for the KFD state to be released. Add a comment so that this is not "fixed" later. No functional change intended. Signed-off-by: Jiaming Fan <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 72b3710..564dc24 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -3238,10 +3238,18 @@ error_fini_sync: static void __exit amdgpu_exit(void) { + /* + * Undo amdgpu_init() in reverse order, except that KFD goes before + * the PCI driver. A primary KFD context can outlive its /dev/kfd file + * until the mm of its process goes away, and amdgpu_amdkfd_fini() + * releases what is left while the devices still exist. Removing the + * devices first can instead send SIGBUS to those processes and wait + * for their KFD state to be released. + */ amdgpu_amdkfd_fini(); pci_unregister_driver(&amdgpu_kms_pci_driver); - amdgpu_unregister_atpx_handler(); amdgpu_acpi_release(); + amdgpu_unregister_atpx_handler(); amdgpu_sync_fini(); mmu_notifier_synchronize(); amdgpu_xcp_drv_release(); -- 2.56.0
