Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: nirmoy.das@intel.com, matthew.brost@intel.com,
	stuart.summers@intel.com, christoph.manszewski@intel.com,
	mika.kuoppala@linux.intel.com, dominik.grzegorzek@intel.com,
	andrzej.hajda@intel.com, maciej.patelczyk@intel.com
Subject: [RFC 12/19] drm/xe/eudebug: implement userptr_vma access
Date: Mon, 21 Oct 2024 12:58:51 +0300	[thread overview]
Message-ID: <20241021095904.439555-13-gwan-gyeong.mun@intel.com> (raw)
In-Reply-To: <20241021095904.439555-1-gwan-gyeong.mun@intel.com>

From: Andrzej Hajda <andrzej.hajda@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)

Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
Signed-off-by: Maciej Patelczyk <maciej.patelczyk@intel.com>
Signed-off-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Signed-off-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
---
 drivers/gpu/drm/xe/xe_eudebug.c |  2 +-
 drivers/gpu/drm/xe/xe_vm.c      | 47 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vm.h      |  3 +++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_eudebug.c b/drivers/gpu/drm/xe/xe_eudebug.c
index 309358b575d6..9802347258d0 100644
--- a/drivers/gpu/drm/xe/xe_eudebug.c
+++ b/drivers/gpu/drm/xe/xe_eudebug.c
@@ -3024,7 +3024,7 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset,
 		return ret;
 	}
 
-	return -EINVAL;
+	return xe_uvma_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 dad407840379..69fe582d6517 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -3417,3 +3417,50 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot *snap)
 	}
 	kvfree(snap);
 }
+
+int xe_uvma_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 xe_res_cursor cur = {};
+	int cur_len, 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;
+	}
+
+	for (xe_res_first_sg(up->sg, offset, len, &cur); cur.remaining;
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) + cur.start;
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	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..99b9a9b011de 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_uvma_access(struct xe_userptr_vma *uvma, u64 offset,
+		   void *buf, u64 len, bool write);
-- 
2.46.1


  parent reply	other threads:[~2024-10-21  9:59 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21  9:58 [RFC 00/19] Support EU online debug on pagefault Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 01/19] ptrace: export ptrace_may_access Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 02/19] drm/xe/eudebug: Introduce eudebug support Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 03/19] drm/xe/eudebug: Introduce discovery for resources Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 04/19] drm/xe/eudebug: Introduce exec_queue events Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 05/19] drm/xe/eudebug: hw enablement for eudebug Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 06/19] drm/xe: Add EUDEBUG_ENABLE exec queue property Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 07/19] drm/xe/eudebug: Introduce per device attention scan worker Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 08/19] drm/xe/eudebug: Introduce EU control interface Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 09/19] drm/xe/eudebug: Add vm bind and vm bind ops Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 10/19] drm/xe/eudebug: Add UFENCE events with acks Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 11/19] drm/xe/eudebug: vm open/pread/pwrite Gwan-gyeong Mun
2024-10-21  9:58 ` Gwan-gyeong Mun [this message]
2024-10-21  9:58 ` [RFC 13/19] drm/xe: Debug metadata create/destroy ioctls Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 14/19] drm/xe: Attach debug metadata to vma Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 15/19] drm/xe/eudebug: Add debug metadata support for xe_eudebug Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 16/19] drm/xe/eudebug: Implement vm_bind_op discovery Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 17/19] drm/xe/eudebug: Dynamically toggle debugger functionality Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 18/19] drm/xe/eudebug_test: Introduce xe_eudebug wa kunit test Gwan-gyeong Mun
2024-10-21  9:58 ` [RFC 19/19] drm/xe/eudebug: Support EU online debug on pagefault Gwan-gyeong Mun
2024-10-24 14:24   ` Nirmoy Das
2024-10-21 10:07 ` ✓ CI.Patch_applied: success for " Patchwork
2024-10-21 10:08 ` ✗ CI.checkpatch: warning " Patchwork
2024-10-21 10:09 ` ✓ CI.KUnit: success " Patchwork
2024-10-21 10:21 ` ✓ CI.Build: " Patchwork
2024-10-21 10:23 ` ✗ CI.Hooks: failure " Patchwork
2024-10-21 10:25 ` ✓ CI.checksparse: success " Patchwork
2024-10-21 10:45 ` ✓ CI.BAT: " 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=20241021095904.439555-13-gwan-gyeong.mun@intel.com \
    --to=gwan-gyeong.mun@intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=christoph.manszewski@intel.com \
    --cc=dominik.grzegorzek@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=maciej.patelczyk@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=mika.kuoppala@linux.intel.com \
    --cc=nirmoy.das@intel.com \
    --cc=stuart.summers@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