[PATCH] drm/amdkfd: fix double free device pgmap resource

Felix Kuehling felix.kuehling at amd.com
Mon Apr 26 18:46:09 UTC 2021


Am 2021-04-26 um 2:41 p.m. schrieb Philip Yang:
> Use devm_memunmap_pages instead of memunmap_pages to release pgmap
> and remove pgmap from device action, to avoid double free pgmap when
> unloading driver module.
>
> Release device memory region if failed to create device memory pages
> structure.
>
> Signed-off-by: Philip Yang <Philip.Yang at amd.com>

Reviewed-by: Felix Kuehling <Felix.Kuehling at amd.com>


> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> index a66b67083d83..6b810863f6ba 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> @@ -912,6 +912,8 @@ int svm_migrate_init(struct amdgpu_device *adev)
>  	r = devm_memremap_pages(adev->dev, pgmap);
>  	if (IS_ERR(r)) {
>  		pr_err("failed to register HMM device memory\n");
> +		devm_release_mem_region(adev->dev, res->start,
> +					res->end - res->start + 1);
>  		return PTR_ERR(r);
>  	}
>  
> @@ -927,5 +929,9 @@ int svm_migrate_init(struct amdgpu_device *adev)
>  
>  void svm_migrate_fini(struct amdgpu_device *adev)
>  {
> -	memunmap_pages(&adev->kfd.dev->pgmap);
> +	struct dev_pagemap *pgmap = &adev->kfd.dev->pgmap;
> +
> +	devm_memunmap_pages(adev->dev, pgmap);
> +	devm_release_mem_region(adev->dev, pgmap->range.start,
> +				pgmap->range.end - pgmap->range.start + 1);
>  }


More information about the amd-gfx mailing list