From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: stuart.summers@intel.com, francois.dugast@intel.com
Subject: [PATCH v3 4/7] drm/xe: Implement xe_pagefault_handler
Date: Mon, 27 Oct 2025 20:58:40 -0700 [thread overview]
Message-ID: <20251028035843.2488613-5-matthew.brost@intel.com> (raw)
In-Reply-To: <20251028035843.2488613-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 f86c1eff0f4d..6a4f34328d3c 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"
@@ -158,6 +160,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
@@ -170,6 +180,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
next prev parent reply other threads:[~2025-10-28 3:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 3:58 [PATCH v3 0/7] Pagefault refactor Matthew Brost
2025-10-28 3:58 ` [PATCH v3 1/7] drm/xe: Stub out new pagefault layer Matthew Brost
2025-10-31 13:33 ` Francois Dugast
2025-10-31 16:41 ` Matthew Brost
2025-10-28 3:58 ` [PATCH v3 2/7] drm/xe: Implement xe_pagefault_init Matthew Brost
2025-10-31 13:40 ` Francois Dugast
2025-10-31 16:40 ` Matthew Brost
2025-10-28 3:58 ` [PATCH v3 3/7] drm/xe: Implement xe_pagefault_reset Matthew Brost
2025-10-28 3:58 ` Matthew Brost [this message]
2025-10-28 3:58 ` [PATCH v3 5/7] drm/xe: Implement xe_pagefault_queue_work Matthew Brost
2025-10-28 3:58 ` [PATCH v3 6/7] drm/xe: Add xe_guc_pagefault layer Matthew Brost
2025-10-28 3:58 ` [PATCH v3 7/7] drm/xe: Remove unused GT page fault code Matthew Brost
2025-10-28 4:05 ` ✗ CI.checkpatch: warning for Pagefault refactor (rev2) Patchwork
2025-10-28 4:06 ` ✓ CI.KUnit: success " Patchwork
2025-10-28 4:46 ` ✗ Xe.CI.BAT: failure " Patchwork
2025-10-28 9:30 ` ✗ Xe.CI.Full: " 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=20251028035843.2488613-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