[PATCH 2/3] drm/amdgpu: release exclusive mode after hw_init if no kfd

Felix Kuehling felix.kuehling at amd.com
Fri Nov 3 19:00:17 UTC 2017


On 2017-11-01 11:16 PM, Pixel Ding wrote:
> From: pding <Pixel.Ding at amd.com>
>
> KFD device init requires exclusive mode. Driver can release
> exclusive mode after hw_init if KFD is not enabled.
>
> Signed-off-by: pding <Pixel.Ding at amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 5 +++--
>  2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 809e656..dc1d1af 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -1716,6 +1716,9 @@ static int amdgpu_init(struct amdgpu_device *adev)
>  		adev->ip_blocks[i].status.hw = true;
>  	}
>  
> +	if (amdgpu_sriov_vf(adev) && !adev->kfd)
> +		amdgpu_virt_release_full_gpu(adev, true);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index acdb010..589b41f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -130,6 +130,7 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
>  
>  	dev->dev_private = (void *)adev;
>  
> +	amdgpu_amdkfd_device_probe(adev);
>  	/* amdgpu_device_init should report only fatal error
>  	 * like memory allocation failure or iomapping failure,
>  	 * or memory manager initialization failure, it must
> @@ -141,6 +142,7 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
>  		adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
>  		adev->virt.ops = NULL;
>  		amdgpu_device_fini(adev);
> +		kfree(adev->kfd);

This is assuming that adev->kfd was allocated by kmalloc, and that
nothing else needs to be released. It would be safer (fewer assumptions)
to call amdgpu_amdkfd_device_fini instead, which will call
kgd2kfd->device_exit. It should be safe even without having done the
device_init yet.

Regards,
  Felix

>  		kfree(adev);
>  		dev->dev_private = NULL;
>  		/* Don't request EX mode too frequently which is attacking */
> @@ -162,7 +164,6 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
>  				"Error during ACPI methods call\n");
>  	}
>  
> -	amdgpu_amdkfd_device_probe(adev);
>  	amdgpu_amdkfd_device_init(adev);
>  
>  	if (amdgpu_device_is_px(dev)) {
> @@ -174,7 +175,7 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
>  		pm_runtime_put_autosuspend(dev->dev);
>  	}
>  
> -	if (amdgpu_sriov_vf(adev))
> +	if (amdgpu_sriov_vf(adev) && adev->kfd)
>  		amdgpu_virt_release_full_gpu(adev, true);
>  
>  out:



More information about the amd-gfx mailing list