From: Felix Kuehling <felix.kuehling@amd.com>
To: Philip Yang <Philip.Yang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/3] amd/amdkfd: Unmap range from GPUs based on granularity
Date: Mon, 2 Oct 2023 15:27:34 -0400 [thread overview]
Message-ID: <3c56e437-b901-4d93-a3bb-1b788d1aba18@amd.com> (raw)
In-Reply-To: <20230929141115.10016-2-Philip.Yang@amd.com>
[-- Attachment #1: Type: text/plain, Size: 3007 bytes --]
On 2023-09-29 10:11, Philip Yang wrote:
> Align unmap range start and last address to granularity boundary.
> Skip unmap if range is already unmapped from GPUs.
This only handles unmap due to MMU notifiers with XNACK on. What about
svm_range_unmap_from_cpu?
Regards,
Felix
>
> This also solve the rocgdb CWSR migration related issue.
>
> Signed-off-by: Philip Yang<Philip.Yang@amd.com>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 35 ++++++++++++++++++++++++----
> 1 file changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> index 626e0dd4ec79..ac65bf25c685 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> @@ -2004,6 +2004,26 @@ static void svm_range_restore_work(struct work_struct *work)
> mmput(mm);
> }
>
> +static unsigned long
> +svm_range_align_start(struct svm_range *prange, unsigned long start)
> +{
> + unsigned long start_align;
> +
> + start_align = ALIGN_DOWN(start, 1UL << prange->granularity);
> + start_align = max_t(unsigned long, start_align, prange->start);
> + return start_align;
> +}
> +
> +static unsigned long
> +svm_range_align_last(struct svm_range *prange, unsigned long last)
> +{
> + unsigned long last_align;
> +
> + last_align = ALIGN(last, 1UL << prange->granularity) - 1;
I think this should be
last_align = ALIGN(last + 1, 1UL << prange->granularity) - 1;
Otherwise you're off by one granule when (last & (1UL <<
prange->granularity)) == 0.
> + last_align = min_t(unsigned long, last_align, prange->last);
> + return last_align;
> +}
> +
> /**
> * svm_range_evict - evict svm range
> * @prange: svm range structure
> @@ -2078,6 +2098,12 @@ svm_range_evict(struct svm_range *prange, struct mm_struct *mm,
> unsigned long s, l;
> uint32_t trigger;
>
> + if (!svm_range_partial_mapped(prange, start, last)) {
> + pr_debug("svms 0x%p [0x%lx 0x%lx] unmapped already\n",
> + prange->svms, start, last);
> + return 0;
> + }
> +
> if (event == MMU_NOTIFY_MIGRATE)
> trigger = KFD_SVM_UNMAP_TRIGGER_MMU_NOTIFY_MIGRATE;
> else
> @@ -2085,16 +2111,17 @@ svm_range_evict(struct svm_range *prange, struct mm_struct *mm,
>
> pr_debug("invalidate unmap svms 0x%p [0x%lx 0x%lx] from GPUs\n",
> prange->svms, start, last);
> +
> list_for_each_entry(pchild, &prange->child_list, child_list) {
> mutex_lock_nested(&pchild->lock, 1);
> - s = max(start, pchild->start);
> - l = min(last, pchild->last);
> + s = svm_range_align_start(pchild, start);
> + l = svm_range_align_last(pchild, last);
> if (l >= s)
> svm_range_unmap_from_gpus(pchild, s, l, trigger);
> mutex_unlock(&pchild->lock);
> }
> - s = max(start, prange->start);
> - l = min(last, prange->last);
> + s = svm_range_align_start(prange, start);
> + l = svm_range_align_last(prange, last);
> if (l >= s)
> svm_range_unmap_from_gpus(prange, s, l, trigger);
> }
[-- Attachment #2: Type: text/html, Size: 3784 bytes --]
next prev parent reply other threads:[~2023-10-02 19:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 14:11 [PATCH 1/3] amd/amdkfd: Add granularity bitmap mapped to gpu flag Philip Yang
2023-09-29 14:11 ` [PATCH 2/3] amd/amdkfd: Unmap range from GPUs based on granularity Philip Yang
2023-10-02 17:06 ` Chen, Xiaogang
2023-10-05 19:33 ` Philip Yang
2023-10-02 19:27 ` Felix Kuehling [this message]
2023-10-05 19:36 ` Philip Yang
2023-09-29 14:11 ` [PATCH 3/3] drm/amdkfd: Check bitmap_mapped flag to skip retry fault Philip Yang
2023-10-02 17:08 ` Chen, Xiaogang
2023-10-05 19:42 ` Philip Yang
2023-10-02 19:29 ` Felix Kuehling
2023-10-02 17:02 ` [PATCH 1/3] amd/amdkfd: Add granularity bitmap mapped to gpu flag Chen, Xiaogang
2023-10-05 18:25 ` Philip Yang
2023-10-02 18:35 ` Felix Kuehling
2023-10-05 19:28 ` Philip Yang
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=3c56e437-b901-4d93-a3bb-1b788d1aba18@amd.com \
--to=felix.kuehling@amd.com \
--cc=Philip.Yang@amd.com \
--cc=amd-gfx@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox