[PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Tom St Denis tom.stdenis at amd.com
Fri Feb 9 13:32:34 UTC 2018


On 02/02/18 02:09 PM, Christian König wrote:
> This allows access to pages allocated through the driver with optional
> IOMMU mapping.
> 
> Signed-off-by: Christian König <christian.koenig at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++-------------
>   1 file changed, 35 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 648c449aaa79..795ceaeb82d5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1929,38 +1929,51 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
>   
>   #endif
>   
> -static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
> -				   size_t size, loff_t *pos)
> +static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
> +				 size_t size, loff_t *pos)
>   {
>   	struct amdgpu_device *adev = file_inode(f)->i_private;
> -	int r;
> -	uint64_t phys;
>   	struct iommu_domain *dom;
> +	ssize_t result = 0;
> +	int r;
>   
> -	// always return 8 bytes
> -	if (size != 8)
> -		return -EINVAL;
> +	dom = iommu_get_domain_for_dev(adev->dev);
>   
> -	// only accept page addresses
> -	if (*pos & 0xFFF)
> -		return -EINVAL;
> +	while (size) {
> +		phys_addr_t addr = *pos & PAGE_MASK;
> +		loff_t off = *pos & ~PAGE_MASK;
> +		size_t bytes = PAGE_SIZE - off;
> +		unsigned long pfn;
> +		struct page *p;
> +		void *ptr;
>   
> -	dom = iommu_get_domain_for_dev(adev->dev);
> -	if (dom)
> -		phys = iommu_iova_to_phys(dom, *pos);
> -	else
> -		phys = *pos;
> +		addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
>   
> -	r = copy_to_user(buf, &phys, 8);
> -	if (r)
> -		return -EFAULT;
> +		pfn = addr >> PAGE_SHIFT;
> +		if (!pfn_valid(pfn))
> +			return -EPERM;
> +
> +		p = pfn_to_page(pfn);
> +		if (p->mapping != adev->mman.bdev.dev_mapping)
> +			return -EPERM;

This comparison fails for both IOMMU and non-IOMMU devices in my 
carrizo+polaris10 box.

The address being read from is what the VM decodes to (checked with strace).

Tom


More information about the amd-gfx mailing list