From: Felix Kuehling <Felix.Kuehling@amd.com>
To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: Alex Sierra <alex.sierra@amd.com>, Philip Yang <Philip.Yang@amd.com>
Subject: [PATCH 20/34] drm/amdkfd: invalidate tables on page retry fault
Date: Thu, 1 Apr 2021 00:22:14 -0400 [thread overview]
Message-ID: <20210401042228.1423-21-Felix.Kuehling@amd.com> (raw)
In-Reply-To: <20210401042228.1423-1-Felix.Kuehling@amd.com>
GPU page tables are invalidated by unmapping prange directly at
the mmu notifier, when page fault retry is enabled through
amdgpu_noretry global parameter. The restore page table is
performed at the page fault handler.
If xnack is on, we update GPU mappings after migration to avoid
unnecessary GPUVM faults.
Signed-off-by: Alex Sierra <alex.sierra@amd.com>
Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 6 +-
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 79 +++++++++++++++++++-----
drivers/gpu/drm/amd/amdkfd/kfd_svm.h | 4 +-
3 files changed, 72 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
index 81bae0adc0cf..552c4f656e2d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
@@ -807,7 +807,11 @@ static vm_fault_t svm_migrate_to_ram(struct vm_fault *vmf)
pr_debug("failed %d migrate 0x%p [0x%lx 0x%lx] to ram\n", r,
prange, prange->start, prange->last);
- op = SVM_OP_UPDATE_RANGE_NOTIFIER;
+ /* xnack on, update mapping on GPUs with ACCESS_IN_PLACE */
+ if (p->xnack_enabled && parent == prange)
+ op = SVM_OP_UPDATE_RANGE_NOTIFIER_AND_MAP;
+ else
+ op = SVM_OP_UPDATE_RANGE_NOTIFIER;
svm_range_add_list_work(&p->svms, parent, mm, op);
schedule_deferred_list_work(&p->svms);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index a83a7242c760..7da58a4214c0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -912,6 +912,13 @@ svm_range_split_by_granularity(struct kfd_process *p, struct mm_struct *mm,
svm_range_add_child(parent, mm, tail, SVM_OP_ADD_RANGE);
}
+ /* xnack on, update mapping on GPUs with ACCESS_IN_PLACE */
+ if (p->xnack_enabled && prange->work_item.op == SVM_OP_ADD_RANGE) {
+ prange->work_item.op = SVM_OP_ADD_RANGE_AND_MAP;
+ pr_debug("change prange 0x%p [0x%lx 0x%lx] op %d\n",
+ prange, prange->start, prange->last,
+ SVM_OP_ADD_RANGE_AND_MAP);
+ }
return 0;
}
@@ -1418,25 +1425,54 @@ svm_range_evict(struct svm_range *prange, struct mm_struct *mm,
unsigned long start, unsigned long last)
{
struct svm_range_list *svms = prange->svms;
- int invalid, evicted_ranges;
+ struct kfd_process *p;
int r = 0;
- invalid = atomic_inc_return(&prange->invalid);
- evicted_ranges = atomic_inc_return(&svms->evicted_ranges);
- if (evicted_ranges != 1)
- return r;
+ p = container_of(svms, struct kfd_process, svms);
- pr_debug("evicting svms 0x%p range [0x%lx 0x%lx]\n",
- prange->svms, prange->start, prange->last);
+ pr_debug("invalidate svms 0x%p prange [0x%lx 0x%lx] [0x%lx 0x%lx]\n",
+ svms, prange->start, prange->last, start, last);
- /* First eviction, stop the queues */
- r = kgd2kfd_quiesce_mm(mm);
- if (r)
- pr_debug("failed to quiesce KFD\n");
+ if (!p->xnack_enabled) {
+ int invalid, evicted_ranges;
- pr_debug("schedule to restore svm %p ranges\n", svms);
- schedule_delayed_work(&svms->restore_work,
- msecs_to_jiffies(AMDGPU_SVM_RANGE_RESTORE_DELAY_MS));
+ invalid = atomic_inc_return(&prange->invalid);
+ evicted_ranges = atomic_inc_return(&svms->evicted_ranges);
+ if (evicted_ranges != 1)
+ return r;
+
+ pr_debug("evicting svms 0x%p range [0x%lx 0x%lx]\n",
+ prange->svms, prange->start, prange->last);
+
+ /* First eviction, stop the queues */
+ r = kgd2kfd_quiesce_mm(mm);
+ if (r)
+ pr_debug("failed to quiesce KFD\n");
+
+ pr_debug("schedule to restore svm %p ranges\n", svms);
+ schedule_delayed_work(&svms->restore_work,
+ msecs_to_jiffies(AMDGPU_SVM_RANGE_RESTORE_DELAY_MS));
+ } else {
+ struct svm_range *pchild;
+ unsigned long s, l;
+
+ pr_debug("invalidate unmap svms 0x%p [0x%lx 0x%lx] from GPUs\n",
+ prange->svms, start, last);
+ svm_range_lock(prange);
+ 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);
+ if (l >= s)
+ svm_range_unmap_from_gpus(pchild, s, l);
+ mutex_unlock(&pchild->lock);
+ }
+ s = max(start, prange->start);
+ l = min(last, prange->last);
+ if (l >= s)
+ svm_range_unmap_from_gpus(prange, s, l);
+ svm_range_unlock(prange);
+ }
return r;
}
@@ -1639,12 +1675,25 @@ svm_range_handle_list_op(struct svm_range_list *svms, struct svm_range *prange)
svms, prange, prange->start, prange->last);
svm_range_update_notifier_and_interval_tree(mm, prange);
break;
+ case SVM_OP_UPDATE_RANGE_NOTIFIER_AND_MAP:
+ pr_debug("update and map 0x%p prange 0x%p [0x%lx 0x%lx]\n",
+ svms, prange, prange->start, prange->last);
+ svm_range_update_notifier_and_interval_tree(mm, prange);
+ /* TODO: implement deferred validation and mapping */
+ break;
case SVM_OP_ADD_RANGE:
pr_debug("add 0x%p prange 0x%p [0x%lx 0x%lx]\n", svms, prange,
prange->start, prange->last);
svm_range_add_to_svms(prange);
svm_range_add_notifier_locked(mm, prange);
break;
+ case SVM_OP_ADD_RANGE_AND_MAP:
+ pr_debug("add and map 0x%p prange 0x%p [0x%lx 0x%lx]\n", svms,
+ prange, prange->start, prange->last);
+ svm_range_add_to_svms(prange);
+ svm_range_add_notifier_locked(mm, prange);
+ /* TODO: implement deferred validation and mapping */
+ break;
default:
WARN_ONCE(1, "Unknown prange 0x%p work op %d\n", prange,
prange->work_item.op);
@@ -2263,7 +2312,7 @@ svm_range_set_attr(struct kfd_process *p, uint64_t start, uint64_t size,
if (r)
goto out_unlock_range;
- if (migrated) {
+ if (migrated && !p->xnack_enabled) {
pr_debug("restore_work will update mappings of GPUs\n");
mutex_unlock(&prange->migrate_mutex);
continue;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
index 32c87957aa43..6cc12de8d76a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
@@ -43,7 +43,9 @@ enum svm_work_list_ops {
SVM_OP_NULL,
SVM_OP_UNMAP_RANGE,
SVM_OP_UPDATE_RANGE_NOTIFIER,
- SVM_OP_ADD_RANGE
+ SVM_OP_UPDATE_RANGE_NOTIFIER_AND_MAP,
+ SVM_OP_ADD_RANGE,
+ SVM_OP_ADD_RANGE_AND_MAP
};
struct svm_work_list_item {
--
2.31.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2021-04-01 4:23 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-01 4:21 [PATCH 00/34] Add HMM-based SVM memory manager to KFD v3 Felix Kuehling
2021-04-01 4:21 ` [PATCH 01/34] drm/amdkfd: helper to convert gpu id and idx Felix Kuehling
2021-04-01 4:21 ` [PATCH 02/34] drm/amdkfd: add svm ioctl API Felix Kuehling
2021-04-01 4:21 ` [PATCH 03/34] drm/amdkfd: register svm range Felix Kuehling
2021-04-01 10:04 ` kernel test robot
2021-04-01 4:21 ` [PATCH 04/34] drm/amdkfd: add svm ioctl GET_ATTR op Felix Kuehling
2021-04-01 4:21 ` [PATCH 05/34] drm/amdgpu: add common HMM get pages function Felix Kuehling
2021-04-01 4:22 ` [PATCH 06/34] drm/amdkfd: validate svm range system memory Felix Kuehling
2021-04-01 4:22 ` [PATCH 07/34] drm/amdkfd: deregister svm range Felix Kuehling
2021-04-01 11:48 ` kernel test robot
2021-04-01 4:22 ` [PATCH 08/34] drm/amdgpu: export vm update mapping interface Felix Kuehling
2021-04-01 4:22 ` [PATCH 09/34] drm/amdkfd: map svm range to GPUs Felix Kuehling
2021-04-01 13:28 ` kernel test robot
2021-04-01 4:22 ` [PATCH 10/34] drm/amdkfd: svm range eviction and restore Felix Kuehling
2021-04-01 15:19 ` kernel test robot
2021-04-01 4:22 ` [PATCH 11/34] drm/amdgpu: Enable retry faults unconditionally on Aldebaran Felix Kuehling
2021-04-01 4:22 ` [PATCH 12/34] drm/amdkfd: add xnack enabled flag to kfd_process Felix Kuehling
2021-04-01 4:22 ` [PATCH 13/34] drm/amdkfd: add ioctl to configure and query xnack retries Felix Kuehling
2021-04-01 4:22 ` [PATCH 14/34] drm/amdkfd: register HMM device private zone Felix Kuehling
2021-04-01 19:38 ` kernel test robot
2021-04-01 4:22 ` [PATCH 15/34] drm/amdkfd: validate vram svm range from TTM Felix Kuehling
2021-04-01 4:22 ` [PATCH 16/34] drm/amdkfd: support xgmi same hive mapping Felix Kuehling
2021-04-01 4:22 ` [PATCH 17/34] drm/amdkfd: copy memory through gart table Felix Kuehling
2021-04-01 4:22 ` [PATCH 18/34] drm/amdkfd: HMM migrate ram to vram Felix Kuehling
2021-04-01 4:22 ` [PATCH 19/34] drm/amdkfd: HMM migrate vram to ram Felix Kuehling
2021-04-01 22:37 ` kernel test robot
2021-04-01 4:22 ` Felix Kuehling [this message]
2021-04-01 4:22 ` [PATCH 21/34] drm/amdgpu: enable 48-bit IH timestamp counter Felix Kuehling
2021-04-01 4:22 ` [PATCH 22/34] drm/amdkfd: page table restore through svm API Felix Kuehling
2021-04-01 4:22 ` [PATCH 23/34] drm/amdkfd: SVM API call to restore page tables Felix Kuehling
2021-04-01 4:22 ` [PATCH 24/34] drm/amdkfd: add svm_bo reference for eviction fence Felix Kuehling
2021-04-01 4:22 ` [PATCH 25/34] drm/amdgpu: add param bit flag to create SVM BOs Felix Kuehling
2021-04-01 4:22 ` [PATCH 26/34] drm/amdkfd: add svm_bo eviction mechanism support Felix Kuehling
2021-04-01 4:22 ` [PATCH 27/34] drm/amdgpu: svm bo enable_signal call condition Felix Kuehling
2021-04-01 4:22 ` [PATCH 28/34] drm/amdgpu: add svm_bo eviction to enable_signal cb Felix Kuehling
2021-04-01 4:22 ` [PATCH 29/34] drm/amdgpu: reserve fence slot to update page table Felix Kuehling
2021-04-01 4:22 ` [PATCH 30/34] drm/amdkfd: refine migration policy with xnack on Felix Kuehling
2021-04-01 4:22 ` [PATCH 31/34] drm/amdkfd: add svm range validate timestamp Felix Kuehling
2021-04-01 4:22 ` [PATCH 32/34] drm/amdkfd: multiple gpu migrate vram to vram Felix Kuehling
2021-04-01 4:22 ` [PATCH 33/34] drm/amdkfd: Add SVM API support capability bits Felix Kuehling
2021-04-01 4:22 ` [PATCH 34/34] drm/amdkfd: Add CONFIG_HSA_AMD_SVM Felix Kuehling
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=20210401042228.1423-21-Felix.Kuehling@amd.com \
--to=felix.kuehling@amd.com \
--cc=Philip.Yang@amd.com \
--cc=alex.sierra@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@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;
as well as URLs for NNTP newsgroup(s).