All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Tom St Denis <tom.stdenis-5C7GfCeVMHo@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH] drm/amdgpu: replace iova debugfs file with iomem (v2)
Date: Fri, 9 Feb 2018 19:17:24 +0100	[thread overview]
Message-ID: <50edcafc-23dd-3c44-021f-cf5989d06dc2@gmail.com> (raw)
In-Reply-To: <4708aad9-9ff0-d09f-9bb6-453c01c848a4-5C7GfCeVMHo@public.gmane.org>

Am 09.02.2018 um 18:28 schrieb Tom St Denis:
> On 09/02/18 12:27 PM, Tom St Denis wrote:
>> From: Christian König <ckoenig.leichtzumerken@gmail.com>
>
> Oops, I'll remove this from the commit message before pushing :-)
>
> I did give you credit below though.

The patch before this one isn't merged yet because I'm still not sure if 
that works under all circumstances or not.

Could you give it some extended testing? Especially if it work with 
eviction.

Christian.

>
> Tom
>
>>
>> This allows access to pages allocated through the driver with optional
>> IOMMU mapping.
>>
>> v2: Fix number of bytes copied and add write method
>>
>> Original-by: Christian König <christian.koenig@amd.com>
>> Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 110 
>> ++++++++++++++++++++++++++------
>>   1 file changed, 89 insertions(+), 21 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> index b372d8d650a5..d6c56b001a2c 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> @@ -1929,38 +1929,106 @@ 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;
>> +
>> +        bytes = bytes < size ? bytes : size;
>> +
>> +        addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
>> +
>> +        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;
>> +
>> +        ptr = kmap(p);
>> +        if (ptr) {
>> +            r = copy_to_user(buf, ptr, bytes);
>> +            kunmap(p);
>> +            if (r)
>> +                return -EFAULT;
>> +        } else {
>> +            return -EFAULT;
>> +        }
>> +
>> +        size -= bytes;
>> +        *pos += bytes;
>> +        result += bytes;
>> +    }
>> +
>> +    return result;
>> +}
>> +
>> +static ssize_t amdgpu_iomem_write(struct file *f, const char __user 
>> *buf,
>> +                 size_t size, loff_t *pos)
>> +{
>> +    struct amdgpu_device *adev = file_inode(f)->i_private;
>> +    struct iommu_domain *dom;
>> +    ssize_t result = 0;
>> +    int r;
>>         dom = iommu_get_domain_for_dev(adev->dev);
>> -    if (dom)
>> -        phys = iommu_iova_to_phys(dom, *pos);
>> -    else
>> -        phys = *pos;
>>   -    r = copy_to_user(buf, &phys, 8);
>> -    if (r)
>> -        return -EFAULT;
>> +    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;
>> +
>> +        bytes = bytes < size ? bytes : size;
>> +
>> +        addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
>>   -    return 8;
>> +        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;
>> +
>> +        ptr = kmap(p);
>> +        if (ptr) {
>> +            r = copy_from_user(ptr, buf, bytes);
>> +            kunmap(p);
>> +            if (r)
>> +                return -EFAULT;
>> +        } else {
>> +            return -EFAULT;
>> +        }
>> +
>> +        size -= bytes;
>> +        *pos += bytes;
>> +        result += bytes;
>> +    }
>> +
>> +    return result;
>>   }
>>   -static const struct file_operations amdgpu_ttm_iova_fops = {
>> +static const struct file_operations amdgpu_ttm_iomem_fops = {
>>       .owner = THIS_MODULE,
>> -    .read = amdgpu_iova_to_phys_read,
>> +    .read = amdgpu_iomem_read,
>> +    .write = amdgpu_iomem_write,
>>       .llseek = default_llseek
>>   };
>>   @@ -1973,7 +2041,7 @@ static const struct {
>>   #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
>>       { "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT },
>>   #endif
>> -    { "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM },
>> +    { "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
>>   };
>>     #endif
>>
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-02-09 18:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-09 17:27 [PATCH] drm/amdgpu: replace iova debugfs file with iomem (v2) Tom St Denis
     [not found] ` <20180209172750.15675-1-tom.stdenis-5C7GfCeVMHo@public.gmane.org>
2018-02-09 17:28   ` Tom St Denis
     [not found]     ` <4708aad9-9ff0-d09f-9bb6-453c01c848a4-5C7GfCeVMHo@public.gmane.org>
2018-02-09 18:17       ` Christian König [this message]
     [not found]         ` <50edcafc-23dd-3c44-021f-cf5989d06dc2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-02-09 18:19           ` Tom St Denis
2018-02-09 18:44             ` Christian König
     [not found]               ` <50cdbb8f-3b64-bed3-322c-bcce05b39370-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-02-12 16:40                 ` Tom St Denis
2018-02-12 17:16                   ` Christian König
     [not found]                     ` <8c42ceb6-4c95-d82f-d347-37ee793855a6-5C7GfCeVMHo@public.gmane.org>
2018-02-12 19:08                       ` Tom St Denis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50edcafc-23dd-3c44-021f-cf5989d06dc2@gmail.com \
    --to=ckoenig.leichtzumerken-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=christian.koenig-5C7GfCeVMHo@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=tom.stdenis-5C7GfCeVMHo@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.