[PATCH 3/3] drm/amdkfd: pass kgd to kfd inside device_init

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


Christian just removed radeon_kfd.c. You'll need to rebase your patch.

I'd also change the order of the patches. Put this patch before your
patch 2, so that we never have a case that an uninitialized adev is
passed to KFD.

Other than that, this patch is Reviewed-by: Felix Kuehling
<Felix.Kuehling at amd.com>.

Regards,
  Felix


On 2017-11-01 11:16 PM, Pixel Ding wrote:
> From: pding <Pixel.Ding at amd.com>
>
> KGD is possible not fully initialised in probe phase, so it's not
> safe to pass it in if kfd code tries to refer KGD here.
>
> Signed-off-by: pding <Pixel.Ding at amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c      | 6 +++---
>  drivers/gpu/drm/amd/amdkfd/kfd_device.c         | 8 ++++----
>  drivers/gpu/drm/amd/amdkfd/kfd_priv.h           | 6 +++---
>  drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 4 ++--
>  drivers/gpu/drm/radeon/radeon_kfd.c             | 6 +++---
>  5 files changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> index c70cda0..f2de9b8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> @@ -89,8 +89,7 @@ void amdgpu_amdkfd_device_probe(struct amdgpu_device *adev)
>  		return;
>  	}
>  
> -	adev->kfd = kgd2kfd->probe((struct kgd_dev *)adev,
> -				   adev->pdev, kfd2kgd);
> +	adev->kfd = kgd2kfd->probe(adev->pdev, kfd2kgd);
>  }
>  
>  void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
> @@ -131,7 +130,8 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
>  				&gpu_resources.doorbell_aperture_size,
>  				&gpu_resources.doorbell_start_offset);
>  
> -		kgd2kfd->device_init(adev->kfd, &gpu_resources);
> +		kgd2kfd->device_init((struct kgd_dev *)adev, adev->kfd,
> +				     &gpu_resources);
>  	}
>  }
>  
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> index 5df12b2..84a5067 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> @@ -109,8 +109,8 @@ static const struct kfd_device_info *lookup_device_info(unsigned short did)
>  	return NULL;
>  }
>  
> -struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd,
> -	struct pci_dev *pdev, const struct kfd2kgd_calls *f2g)
> +struct kfd_dev *kgd2kfd_probe(struct pci_dev *pdev,
> +			      const struct kfd2kgd_calls *f2g)
>  {
>  	struct kfd_dev *kfd;
>  
> @@ -126,7 +126,6 @@ struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd,
>  	if (!kfd)
>  		return NULL;
>  
> -	kfd->kgd = kgd;
>  	kfd->device_info = device_info;
>  	kfd->pdev = pdev;
>  	kfd->init_complete = false;
> @@ -217,11 +216,12 @@ static int iommu_invalid_ppr_cb(struct pci_dev *pdev, int pasid,
>  	return AMD_IOMMU_INV_PRI_RSP_INVALID;
>  }
>  
> -bool kgd2kfd_device_init(struct kfd_dev *kfd,
> +bool kgd2kfd_device_init(struct kgd_dev *kgd, struct kfd_dev *kfd,
>  			 const struct kgd2kfd_shared_resources *gpu_resources)
>  {
>  	unsigned int size;
>  
> +	kfd->kgd = kgd;
>  	kfd->shared_resources = *gpu_resources;
>  
>  	/* calculate max size of mqds needed for queues */
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index 4cb90f5..a64d772 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -200,9 +200,9 @@ struct kfd_dev {
>  
>  /* KGD2KFD callbacks */
>  void kgd2kfd_exit(void);
> -struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd,
> -			struct pci_dev *pdev, const struct kfd2kgd_calls *f2g);
> -bool kgd2kfd_device_init(struct kfd_dev *kfd,
> +struct kfd_dev *kgd2kfd_probe(struct pci_dev *pdev,
> +			      const struct kfd2kgd_calls *f2g);
> +bool kgd2kfd_device_init(struct kgd_dev *kgd, struct kfd_dev *kfd,
>  			const struct kgd2kfd_shared_resources *gpu_resources);
>  void kgd2kfd_device_exit(struct kfd_dev *kfd);
>  
> diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> index f516fd1..af814f7 100644
> --- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> +++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> @@ -248,9 +248,9 @@ struct kfd2kgd_calls {
>   */
>  struct kgd2kfd_calls {
>  	void (*exit)(void);
> -	struct kfd_dev* (*probe)(struct kgd_dev *kgd, struct pci_dev *pdev,
> +	struct kfd_dev* (*probe)(struct pci_dev *pdev,
>  		const struct kfd2kgd_calls *f2g);
> -	bool (*device_init)(struct kfd_dev *kfd,
> +	bool (*device_init)(struct kgd_dev *kgd, struct kfd_dev *kfd,
>  			const struct kgd2kfd_shared_resources *gpu_resources);
>  	void (*device_exit)(struct kfd_dev *kfd);
>  	void (*interrupt)(struct kfd_dev *kfd, const void *ih_ring_entry);
> diff --git a/drivers/gpu/drm/radeon/radeon_kfd.c b/drivers/gpu/drm/radeon/radeon_kfd.c
> index 385b4d7..ac85400 100644
> --- a/drivers/gpu/drm/radeon/radeon_kfd.c
> +++ b/drivers/gpu/drm/radeon/radeon_kfd.c
> @@ -181,8 +181,7 @@ void radeon_kfd_fini(void)
>  void radeon_kfd_device_probe(struct radeon_device *rdev)
>  {
>  	if (kgd2kfd)
> -		rdev->kfd = kgd2kfd->probe((struct kgd_dev *)rdev,
> -			rdev->pdev, &kfd2kgd);
> +		rdev->kfd = kgd2kfd->probe(rdev->pdev, &kfd2kgd);
>  }
>  
>  void radeon_kfd_device_init(struct radeon_device *rdev)
> @@ -214,7 +213,8 @@ void radeon_kfd_device_init(struct radeon_device *rdev)
>  				&gpu_resources.doorbell_aperture_size,
>  				&gpu_resources.doorbell_start_offset);
>  
> -		kgd2kfd->device_init(rdev->kfd, &gpu_resources);
> +		kgd2kfd->device_init((struct kgd_dev *)rdev,
> +				     rdev->kfd, &gpu_resources);
>  	}
>  }
>  



More information about the amd-gfx mailing list