[PATCH 3/6] drm/amdgpu: Wait for all user clients

Christian König ckoenig.leichtzumerken at gmail.com
Mon May 11 06:57:40 UTC 2020


A commit message would be nice, apart from that the patch looks clean to me.

But question for Daniel and others: Is that in general the right approach?

It can happen that device removal is delayed indefinitely if userspace 
doesn't close the file descriptors.

Regards,
Christian.

Am 09.05.20 um 20:51 schrieb Andrey Grodzovsky:
> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 2 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 2 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 4 ++++
>   4 files changed, 11 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index bc1e0fd..79274d5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -990,6 +990,8 @@ struct amdgpu_device {
>   	char				product_number[16];
>   	char				product_name[32];
>   	char				serial[16];
> +
> +	wait_queue_head_t		user_clients_done;
>   };
>   
>   static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 4da52b7..3bd67cf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -3271,6 +3271,9 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>   	if (r)
>   		dev_err(adev->dev, "amdgpu_pmu_init failed\n");
>   
> +
> +	init_waitqueue_head(&adev->user_clients_done);
> +
>   	return 0;
>   
>   failed:
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index ea2b47e..0531727 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -1141,10 +1141,12 @@ static void
>   amdgpu_pci_remove(struct pci_dev *pdev)
>   {
>   	struct drm_device *dev = pci_get_drvdata(pdev);
> +	struct amdgpu_device *adev = dev->dev_private;
>   
>   	drm_dev_unplug(dev);
>   
>   	amdgpu_force_unmap_user_space_mappings(dev);
> +	wait_event(adev->user_clients_done, (dev->open_count == 0));
>   
>   	amdgpu_driver_unload_kms(dev);
>   	pci_disable_device(pdev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 61fb2ef..d8fc775 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -957,8 +957,12 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
>    */
>   void amdgpu_driver_lastclose_kms(struct drm_device *dev)
>   {
> +	struct amdgpu_device *adev = dev->dev_private;
> +
>   	drm_fb_helper_lastclose(dev);
>   	vga_switcheroo_process_delayed_switch();
> +
> +	wake_up(&adev->user_clients_done);
>   }
>   
>   /**



More information about the amd-gfx mailing list