AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Felix Kuehling <felix.kuehling@amd.com>,
	Prike Liang <Prike.Liang@amd.com>,
	amd-gfx@lists.freedesktop.org
Cc: Alexander.Deucher@amd.com, Harish.Kasiviswanathan@amd.com
Subject: Re: [PATCH] drm/amdkfd: correct the SVM DMA device unmap direction
Date: Wed, 6 Nov 2024 13:24:14 +0100	[thread overview]
Message-ID: <02ddce81-b7fc-4b72-8fa6-1aee9346edbc@amd.com> (raw)
In-Reply-To: <3e8ece68-d9e7-4037-bc99-d3f9b78128b5@amd.com>

Am 05.11.24 um 17:34 schrieb Felix Kuehling:
> On 2024-11-05 06:04, Christian König wrote:
>> Am 05.11.24 um 03:33 schrieb Prike Liang:
>>> The SVM DMA device unmap direction should be same as
>>> the DMA map process.
>>
>> At least of hand that looks like it's only papering over a major 
>> problem.
>>
>> Why are DMA ranges for SVM mapped with a direction in the first 
>> place? That is usually not something we should do.
>
> These are DMA mappings of system memory pages. I guess we're creating 
> DMA mappings only for the access required for the migration, which is 
> not bidirectional. I see we do something similar for userptr mappings 
> depending on whether the GPU mapping is read-only or read-write. Is 
> that wrong for userptrs as well?

I think so, yes. The DMA directions are there to make explicit CPU cache 
management and bounce buffers possible.

Since we shouldn't need or even want either for a cache coherent PCIe 
device we should probably always use BIDIRECTIONAL.

Regards,
Christian.

>
> Regards,
>   Felix
>
>
>>
>> Regards,
>> Christian.
>>
>>>
>>> Signed-off-by: Prike Liang <Prike.Liang@amd.com>
>>> ---
>>>   drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 4 ++--
>>>   drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 6 +++---
>>>   drivers/gpu/drm/amd/amdkfd/kfd_svm.h     | 3 ++-
>>>   3 files changed, 7 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c 
>>> b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
>>> index eacfeb32f35d..9d83bb9dd004 100644
>>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
>>> @@ -445,7 +445,7 @@ svm_migrate_vma_to_vram(struct kfd_node *node, 
>>> struct svm_range *prange,
>>>       pr_debug("successful/cpages/npages 0x%lx/0x%lx/0x%lx\n",
>>>                mpages, cpages, migrate.npages);
>>>   -    svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages);
>>> +    svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages, 
>>> DMA_TO_DEVICE);
>>>     out_free:
>>>       kvfree(buf);
>>> @@ -750,7 +750,7 @@ svm_migrate_vma_to_ram(struct kfd_node *node, 
>>> struct svm_range *prange,
>>>       svm_migrate_copy_done(adev, mfence);
>>>       migrate_vma_finalize(&migrate);
>>>   -    svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages);
>>> +    svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages, 
>>> DMA_FROM_DEVICE);
>>>     out_free:
>>>       kvfree(buf);
>>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
>>> b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
>>> index 3e2911895c74..c21485fe6cbb 100644
>>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
>>> @@ -233,9 +233,9 @@ svm_range_dma_map(struct svm_range *prange, 
>>> unsigned long *bitmap,
>>>   }
>>>     void svm_range_dma_unmap_dev(struct device *dev, dma_addr_t 
>>> *dma_addr,
>>> -             unsigned long offset, unsigned long npages)
>>> +             unsigned long offset, unsigned long npages,
>>> +                enum dma_data_direction dir)
>>>   {
>>> -    enum dma_data_direction dir = DMA_BIDIRECTIONAL;
>>>       int i;
>>>         if (!dma_addr)
>>> @@ -272,7 +272,7 @@ void svm_range_dma_unmap(struct svm_range *prange)
>>>           }
>>>           dev = &pdd->dev->adev->pdev->dev;
>>>   -        svm_range_dma_unmap_dev(dev, dma_addr, 0, prange->npages);
>>> +        svm_range_dma_unmap_dev(dev, dma_addr, 0, prange->npages, 
>>> DMA_BIDIRECTIONAL);
>>>       }
>>>   }
>>>   diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h 
>>> b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
>>> index bddd24f04669..5370d68bc5b2 100644
>>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
>>> @@ -182,7 +182,8 @@ void svm_range_add_list_work(struct 
>>> svm_range_list *svms,
>>>                    enum svm_work_list_ops op);
>>>   void schedule_deferred_list_work(struct svm_range_list *svms);
>>>   void svm_range_dma_unmap_dev(struct device *dev, dma_addr_t 
>>> *dma_addr,
>>> -             unsigned long offset, unsigned long npages);
>>> +             unsigned long offset, unsigned long npages,
>>> +             enum dma_data_direction dir);
>>>   void svm_range_dma_unmap(struct svm_range *prange);
>>>   int svm_range_get_info(struct kfd_process *p, uint32_t 
>>> *num_svm_ranges,
>>>                  uint64_t *svm_priv_data_size);
>>


  reply	other threads:[~2024-11-06 12:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05  2:33 [PATCH] drm/amdkfd: correct the SVM DMA device unmap direction Prike Liang
2024-11-05 11:04 ` Christian König
2024-11-05 16:34   ` Felix Kuehling
2024-11-06 12:24     ` Christian König [this message]
2024-11-08  9:15       ` Liang, Prike
2024-11-08  9:39         ` Christian König
2024-11-11  3:06           ` Liang, Prike
2024-11-12 13:42             ` Christian König
2024-12-02  7:32               ` Liang, Prike

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=02ddce81-b7fc-4b72-8fa6-1aee9346edbc@amd.com \
    --to=christian.koenig@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Harish.Kasiviswanathan@amd.com \
    --cc=Prike.Liang@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=felix.kuehling@amd.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox