From: Andrzej Hajda <andrzej.hajda@intel.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: Andrzej Hajda <andrzej.hajda@intel.com>,
intel-xe@lists.freedesktop.org,
Mika Kuoppala <mika.kuoppala@linux.intel.com>,
Jonathan Cavitt <jonathan.cavitt@intel.com>
Subject: [PATCH 2/2] drm/xe/eudebug: implement userptr_vma access
Date: Mon, 28 Oct 2024 17:19:27 +0100 [thread overview]
Message-ID: <20241028161927.1157426-2-andrzej.hajda@intel.com> (raw)
In-Reply-To: <ZxviLOv75ISykjK8@DUT025-TGLU.fm.intel.com>
Debugger needs to read/write program's vmas including userptr_vma.
Since hmm_range_fault is used to pin userptr vmas, it is possible
to map those vmas from debugger context.
v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes work with iommu enabled
- s/xe_uvma_access/xe_vm_uvma_access/ (Matt)
v4: use xe_userptr->pages, instead of sg to access pages (Matt)
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
---
drivers/gpu/drm/xe/xe_eudebug.c | 2 +-
drivers/gpu/drm/xe/xe_vm.c | 52 +++++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_vm.h | 3 ++
3 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_eudebug.c b/drivers/gpu/drm/xe/xe_eudebug.c
index 1bff0a2cfaa1..569c8d0b2ef8 100644
--- a/drivers/gpu/drm/xe/xe_eudebug.c
+++ b/drivers/gpu/drm/xe/xe_eudebug.c
@@ -3049,7 +3049,7 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset,
return ret;
}
- return -EINVAL;
+ return xe_vm_userptr_access(to_userptr_vma(vma), offset, buf, bytes, write);
}
static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index e76a6df1eba1..8fd9eed41fe1 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -3412,3 +3412,55 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot *snap)
}
kvfree(snap);
}
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+ void *buf, u64 len, bool write)
+{
+ struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+ struct xe_userptr *up = &uvma->userptr;
+ struct page **page;
+ u64 left = len;
+ int ret = 0;
+
+ while (true) {
+ down_read(&vm->userptr.notifier_lock);
+ if (!xe_vma_userptr_check_repin(uvma))
+ break;
+
+ spin_lock(&vm->userptr.invalidated_lock);
+ list_del_init(&uvma->userptr.invalidate_link);
+ spin_unlock(&vm->userptr.invalidated_lock);
+
+ up_read(&vm->userptr.notifier_lock);
+ ret = xe_vma_userptr_pin_pages(uvma);
+ if (ret)
+ return ret;
+ }
+
+ if (!up->sg) {
+ ret = -EINVAL;
+ goto out_unlock_notifier;
+ }
+
+ page = &up->pages[offset >> PAGE_SHIFT];
+ offset &= ~PAGE_MASK;
+ for (;left > 0; ++page) {
+ u64 cur_len = min(PAGE_SIZE - offset, left);
+ void *ptr = kmap_local_page(page[0]);
+
+ if (write)
+ memcpy(ptr + offset, buf, cur_len);
+ else
+ memcpy(buf, ptr + offset, cur_len);
+ kunmap_local(ptr);
+ buf += cur_len;
+ left -= cur_len;
+ offset = 0;
+ }
+
+ ret = len;
+
+out_unlock_notifier:
+ up_read(&vm->userptr.notifier_lock);
+ return ret;
+}
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index c864dba35e1d..165eab494d59 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -281,3 +281,6 @@ struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+ void *buf, u64 len, bool write);
--
2.34.1
next prev parent reply other threads:[~2024-10-28 16:20 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 14:42 [PATCH 00/18] GPU debug support (eudebug) v2 Mika Kuoppala
2024-10-01 14:42 ` [PATCH 01/18] ptrace: export ptrace_may_access Mika Kuoppala
2024-10-01 14:42 ` [PATCH 02/18] drm/xe/eudebug: Introduce eudebug support Mika Kuoppala
2024-10-01 14:42 ` [PATCH 03/18] drm/xe/eudebug: Introduce discovery for resources Mika Kuoppala
2024-10-03 0:41 ` Matthew Brost
2024-10-03 7:27 ` Mika Kuoppala
2024-10-03 16:32 ` Matthew Brost
2024-10-01 14:42 ` [PATCH 04/18] drm/xe/eudebug: Introduce exec_queue events Mika Kuoppala
2024-10-01 14:42 ` [PATCH 05/18] drm/xe/eudebug: hw enablement for eudebug Mika Kuoppala
2024-10-01 14:42 ` [PATCH 06/18] drm/xe: Add EUDEBUG_ENABLE exec queue property Mika Kuoppala
2024-10-01 14:42 ` [PATCH 07/18] drm/xe/eudebug: Introduce per device attention scan worker Mika Kuoppala
2024-10-01 14:42 ` [PATCH 08/18] drm/xe/eudebug: Introduce EU control interface Mika Kuoppala
2024-10-01 14:42 ` [PATCH 09/18] drm/xe/eudebug: Add vm bind and vm bind ops Mika Kuoppala
2024-10-01 14:42 ` [PATCH 10/18] drm/xe/eudebug: Add UFENCE events with acks Mika Kuoppala
2024-10-01 14:42 ` [PATCH 11/18] drm/xe/eudebug: vm open/pread/pwrite Mika Kuoppala
2024-10-01 14:43 ` [PATCH 12/18] drm/xe/eudebug: implement userptr_vma access Mika Kuoppala
2024-10-05 3:48 ` Matthew Brost
2024-10-12 2:39 ` Matthew Brost
2024-10-12 2:55 ` Matthew Brost
2024-10-20 18:16 ` Matthew Brost
2024-10-21 9:54 ` Hajda, Andrzej
2024-10-21 22:34 ` Matthew Brost
2024-10-23 11:32 ` Hajda, Andrzej
2024-10-24 16:06 ` Matthew Brost
2024-10-25 13:20 ` Hajda, Andrzej
2024-10-25 18:23 ` Matthew Brost
2024-10-28 16:19 ` [PATCH 1/2] drm/xe: keep list of system pages in xe_userptr Andrzej Hajda
2024-10-28 16:19 ` Andrzej Hajda [this message]
2024-10-28 16:55 ` [PATCH 2/2] drm/xe/eudebug: implement userptr_vma access Hajda, Andrzej
2024-10-01 14:43 ` [PATCH 13/18] drm/xe: Debug metadata create/destroy ioctls Mika Kuoppala
2024-10-01 16:25 ` Matthew Auld
2024-10-02 13:59 ` Grzegorzek, Dominik
2024-10-01 14:43 ` [PATCH 14/18] drm/xe: Attach debug metadata to vma Mika Kuoppala
2024-10-01 14:43 ` [PATCH 15/18] drm/xe/eudebug: Add debug metadata support for xe_eudebug Mika Kuoppala
2024-10-01 14:43 ` [PATCH 16/18] drm/xe/eudebug: Implement vm_bind_op discovery Mika Kuoppala
2024-10-01 14:43 ` [PATCH 17/18] drm/xe/eudebug: Dynamically toggle debugger functionality Mika Kuoppala
2024-10-01 14:43 ` [PATCH 18/18] drm/xe/eudebug_test: Introduce xe_eudebug wa kunit test Mika Kuoppala
2024-10-01 15:02 ` ✓ CI.Patch_applied: success for GPU debug support (eudebug) (rev2) Patchwork
2024-10-01 15:03 ` ✗ CI.checkpatch: warning " Patchwork
2024-10-01 15:03 ` ✗ CI.KUnit: failure " Patchwork
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=20241028161927.1157426-2-andrzej.hajda@intel.com \
--to=andrzej.hajda@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=jonathan.cavitt@intel.com \
--cc=matthew.brost@intel.com \
--cc=mika.kuoppala@linux.intel.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