Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: stuart.summers@intel.com, francois.dugast@intel.com
Subject: [PATCH v4 4/7] drm/xe: Implement xe_pagefault_handler
Date: Fri, 31 Oct 2025 09:54:13 -0700	[thread overview]
Message-ID: <20251031165416.2871503-5-matthew.brost@intel.com> (raw)
In-Reply-To: <20251031165416.2871503-1-matthew.brost@intel.com>

Enqueue (copy) the input struct xe_pagefault into a queue (i.e., into a
memory buffer) and schedule a worker to service it.

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Francois Dugast <francois.dugast@intel.com>
---
 drivers/gpu/drm/xe/xe_pagefault.c | 32 +++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_pagefault.c b/drivers/gpu/drm/xe/xe_pagefault.c
index eedd31120175..194e647a8af6 100644
--- a/drivers/gpu/drm/xe/xe_pagefault.c
+++ b/drivers/gpu/drm/xe/xe_pagefault.c
@@ -3,6 +3,8 @@
  * Copyright © 2025 Intel Corporation
  */
 
+#include <linux/circ_buf.h>
+
 #include <drm/drm_managed.h>
 
 #include "xe_device.h"
@@ -162,6 +164,14 @@ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt)
 		xe_pagefault_queue_reset(xe, gt, xe->usm.pf_queue + i);
 }
 
+static bool xe_pagefault_queue_full(struct xe_pagefault_queue *pf_queue)
+{
+	lockdep_assert_held(&pf_queue->lock);
+
+	return CIRC_SPACE(pf_queue->head, pf_queue->tail, pf_queue->size) <=
+		xe_pagefault_entry_size();
+}
+
 /**
  * xe_pagefault_handler() - Page fault handler
  * @xe: xe device instance
@@ -174,6 +184,24 @@ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt)
  */
 int xe_pagefault_handler(struct xe_device *xe, struct xe_pagefault *pf)
 {
-	/* TODO - implement */
-	return 0;
+	struct xe_pagefault_queue *pf_queue = xe->usm.pf_queue +
+		(pf->consumer.asid % XE_PAGEFAULT_QUEUE_COUNT);
+	unsigned long flags;
+	bool full;
+
+	spin_lock_irqsave(&pf_queue->lock, flags);
+	full = xe_pagefault_queue_full(pf_queue);
+	if (!full) {
+		memcpy(pf_queue->data + pf_queue->head, pf, sizeof(*pf));
+		pf_queue->head = (pf_queue->head + xe_pagefault_entry_size()) %
+			pf_queue->size;
+		queue_work(xe->usm.pf_wq, &pf_queue->worker);
+	} else {
+		drm_warn(&xe->drm,
+			 "PageFault Queue (%d) full, shouldn't be possible\n",
+			 pf->consumer.asid % XE_PAGEFAULT_QUEUE_COUNT);
+	}
+	spin_unlock_irqrestore(&pf_queue->lock, flags);
+
+	return full ? -ENOSPC : 0;
 }
-- 
2.34.1


  parent reply	other threads:[~2025-10-31 16:55 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-31 16:54 [PATCH v4 0/7] Pagefault refactor Matthew Brost
2025-10-31 16:54 ` [PATCH v4 1/7] drm/xe: Stub out new pagefault layer Matthew Brost
2025-11-04  3:57   ` Lucas De Marchi
2025-10-31 16:54 ` [PATCH v4 2/7] drm/xe: Implement xe_pagefault_init Matthew Brost
2025-11-03 13:22   ` Francois Dugast
2025-11-03 17:07     ` Matthew Brost
2025-10-31 16:54 ` [PATCH v4 3/7] drm/xe: Implement xe_pagefault_reset Matthew Brost
2025-11-04  4:02   ` Lucas De Marchi
2025-10-31 16:54 ` Matthew Brost [this message]
2025-10-31 16:54 ` [PATCH v4 5/7] drm/xe: Implement xe_pagefault_queue_work Matthew Brost
2025-11-04 15:01   ` Lucas De Marchi
2025-11-04 15:50     ` Matthew Brost
2025-10-31 16:54 ` [PATCH v4 6/7] drm/xe: Add xe_guc_pagefault layer Matthew Brost
2025-11-03 18:28   ` Lucas De Marchi
2025-11-03 18:56     ` Matthew Brost
2025-11-03 19:11       ` Lucas De Marchi
2025-11-03 19:15         ` Matthew Brost
2025-11-04 16:12           ` Lucas De Marchi
2025-10-31 16:54 ` [PATCH v4 7/7] drm/xe: Remove unused GT page fault code Matthew Brost
2025-11-04 16:13   ` Lucas De Marchi
2025-10-31 18:00 ` ✗ CI.checkpatch: warning for Pagefault refactor (rev3) Patchwork
2025-10-31 18:01 ` ✓ CI.KUnit: success " Patchwork
2025-10-31 19:04 ` ✓ Xe.CI.BAT: " Patchwork
2025-11-01  6:59 ` ✗ Xe.CI.Full: failure " Patchwork
2025-11-04 16:24 ` [PATCH v4 0/7] Pagefault refactor Francois Dugast

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=20251031165416.2871503-5-matthew.brost@intel.com \
    --to=matthew.brost@intel.com \
    --cc=francois.dugast@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --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