Pagefault refactor, fine grained fault locking, threaded prefetch
Subsystems (2)
Matthew Brost
maintainercover Pagefault refactor, fine grained fault locking, threaded prefetch
We likely need multiple page fault producers feeding into a common consumer backend. Additionally, our current page fault work queue design—being per-GT rather than per-device—makes little sense. Clean this up ahead of upcoming changes that introduce fine-grained fault locking and threaded prefetching.
Fine-grained fault locking provides immediate benefits: it allows page faults from the same VM to be processed in parallel (unless they target the same range) and enables a sane multi-threaded prefetch implementation. Longer term, it should help transition GPU SVM from a per-VM model to a per-MM model, which scales better across multiple VMs or devices.
Lastly, threaded prefetching enables efficient usage of copy engines.
Matt
Matthew Brost (11):
drm/xe: Stub out new pagefault layer
drm/xe: Implement xe_pagefault_init
drm/xe: Implement xe_pagefault_reset
drm/xe: Implement xe_pagefault_handler
drm/xe: Implement xe_pagefault_queue_work
drm/xe: Add xe_guc_pagefault layer
drm/xe: Remove unused GT page fault code
drm/xe: Fine grained page fault locking
drm/xe: Allow prefetch-only VM bind IOCTLs to use VM read lock drm/xe: Thread prefetch of SVM ranges
drm/xe: Add num_pf_queue modparam
drivers/gpu/drm/xe/Makefile | 3 +- drivers/gpu/drm/xe/xe_device.c | 20 +- drivers/gpu/drm/xe/xe_device_types.h | 10 + drivers/gpu/drm/xe/xe_gt.c | 8 +- drivers/gpu/drm/xe/xe_gt_pagefault.c | 691 ------------------------ drivers/gpu/drm/xe/xe_gt_pagefault.h | 19 - drivers/gpu/drm/xe/xe_gt_types.h | 65 --- drivers/gpu/drm/xe/xe_guc_ct.c | 6 +- drivers/gpu/drm/xe/xe_guc_pagefault.c | 94 ++++ drivers/gpu/drm/xe/xe_guc_pagefault.h | 13 + drivers/gpu/drm/xe/xe_hmm.c | 4 +- drivers/gpu/drm/xe/xe_module.c | 5 + drivers/gpu/drm/xe/xe_module.h | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 480 ++++++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 + drivers/gpu/drm/xe/xe_pagefault_types.h | 125 +++++ drivers/gpu/drm/xe/xe_svm.c | 114 ++-- drivers/gpu/drm/xe/xe_svm.h | 38 ++ drivers/gpu/drm/xe/xe_vm.c | 261 +++++++-- drivers/gpu/drm/xe/xe_vm.h | 2 + drivers/gpu/drm/xe/xe_vm_types.h | 28 +- 21 files changed, 1131 insertions(+), 875 deletions(-) delete mode 100644 drivers/gpu/drm/xe/xe_gt_pagefault.c delete mode 100644 drivers/gpu/drm/xe/xe_gt_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault_types.h
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 1/11 drm/xe: Stub out new pagefault layer
Stub out the new page fault layer and add kernel documentation. This is intended as a replacement for the GT page fault layer, enabling multiple producers to hook into a shared page fault consumer interface.
--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++ drivers/gpu/drm/xe/xe_pagefault_types.h | 125 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault_types.h
drivers/gpu/drm/xe/Makefile +1 -0
@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \
drivers/gpu/drm/xe/xe_pagefault.c new file +63 -0
63 lines not on this page · raw message
drivers/gpu/drm/xe/xe_pagefault.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf); + +#endif
drivers/gpu/drm/xe/xe_pagefault_types.h new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Few basic comments below to start. I personally would rather this be brought over from the existing fault handler rather than creating something entirely new and then clobbering the older stuff - just so the review of message format requests/replies is easier to review and where we're deviating from the existing external interfaces (HW/FW/GuC/etc). You already have this here though so not a huge deal. I think most of this was in the giant blob of patches that got merged with the initial driver, so I guess the counter argument is we can have easy to reference historical reviews now.
Quoted 148 lines · Matthew Brost
Stub out the new page fault layer and add kernel documentation. This is
intended as a replacement for the GT page fault layer, enabling multiple
producers to hook into a shared page fault consumer interface.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++drivers/gpu/drm/xe/xe_pagefault_types.h| 125
++++++++++++++++++++++++4 files changed, 208 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_pagefault.hcreate mode 100644drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with
+ * hardware or firmware to receive and parse faults into structxe_pagefault,
+ * then forwards them to the consumer. The consumer layer services the faults
+ * (e.g., memory migration, page table updates) and acknowledges the result back
+ * to the producer, which then forwards the results to the hardware or firmware.
+ * The consumer uses a page fault queue sized to absorb all potential faults and
+ * a multi-threaded worker to process them. Multiple producers are supported,
+ * with a single shared consumer.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +21
-0+ +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ + /* TODO - implement */ + return 0; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on
+ * the GT.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +11
-0+void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ + /* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to
+ * service it. Safe to be called from IRQ or process context. Reclaim safe.
+ *
+ * Return: 0 on success, errno on failure
+ */
+intxe_pagefault_handler(struct xe_device *xe, struct xe_pagefault *pf)drivers/gpu/drm/xe/xe_pagefault.c new file +4
-0+{ + /* TODO - implement */ + return 0; +}drivers/gpu/drm/xe/xe_pagefault.h new file +17
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler(struct xe_device *xe, struct xe_pagefault*pf);
drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/*
drivers/gpu/drm/xe/xe_pagefault_types.h line 12
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_ +#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault ; +struct xe_gt ;
Nit: Maybe reverse these structs to be in alphabetical order
Quoted 16 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +16
-0+ +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write access
Quoted 4 lines
violation */
+ XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1,
+ /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */
XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION ->XE_PAGEFAULT_ACCESS_TYPE_ATOMIC
Quoted 32 lines
+ XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2,
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** +* @ack_fault: Ack fault +* @pf: Page fault +* @err: Error state of fault +* +* Page fault producer receives acknowledgment from the consumer and
+ * sends the result to the HW/FW interface. + */
+ void (*ack_fault)(structxe_pagefault*pf, int err);drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** +* struct xe_pagefault - Xe page fault +* +* Generic page fault structure for communication between producer and consumer.
+ * Carefully sized to be 64 bytes.
+ */
+structxe_pagefault{
+ /**
+ * @gt: GT of fault
+ *
+ * XXX: We may want to decouple the GT from individual faults, as it's
+ * unclear whether future platforms will always have a GT for all page
Quoted 8 lines
+ * fault producers. Internally, the GT is used for stats, identifying
+ * the appropriate VRAM region, and locating the migration queue.
+ * Leaving this as-is for now, but we can revisit later to see if we
+ * can convert it to use the Xe device pointer instead. + */
What if instead of assuming the GT stays static and we eventually remove if we have some new HW abstraction layer that isn't a GT but still uses the page fault, we instead push to have said theoretical abstraction layer overload the GT here like we're doing with primary and media today. Then we can keep the interface here simple and just leave this in there, or change in the future if that doesn't make sense without the suggestive comment?
Quoted 6 lines
+ struct
xe_gt*gt;
+ /**
+ * @consumer: State for the software handling the fault. Populated by
+ * the producer and may be modified by the consumer to communicate
Quoted 8 lines
+ * information back to the producer upon fault acknowledgment.
+ */
+ struct {
+ /** @consumer.page_addr: address of page fault */ + u64page_addr;
+ /** @consumer.asid: address space ID */ + u32 asid;
Can we just call this an ID instead of a pasid or asid? I.e. the ID could be anything, not strictly process-bound.
Quoted 5 lines
+ /** @consumer.access_type: access type */ + u8
access_type;
+ /** @consumer.fault_type: fault type */ + u8fault_type;
+#define XE_PAGEFAULT_LEVEL_NACK 0xff /* Producer
Quoted 8 lines
indicates nack fault */
+ /** @consumer.fault_level: fault level */ + u8fault_level;
+ /** @consumer.engine_class: engine class */ + u8engine_class;
+ /** consumer.reserved: reserved bits for future expansion */
+ u64 reserved;
What about engine instance? Or is that going to overload reserved here?
Thanks,
Stuart
Quoted 47 lines
+ } consumer;
+ /**
+ * @producer: State for the producer (i.e., HW/FW interface). Populated
+ * by the producer and should not be modified—or even inspected—by the
+ * consumer, except for calling operations.
+ */
+ struct {
+ /** @producer.private: private pointer */ + void *private;
+ /** @producer.ops: operations */
+ const structxe_pagefault_ops*ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4
+ /**
+ * producer.msg: page fault message, used by producer in fault
+ * acknowledgement to formulate response to HW/FW interface.
+ */
+ u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW]; + } producer;drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { + /** +* @data: Data in queue containing struct xe_pagefault, protected by
+ * @lock
+ */
+ void *data;
+ /** @size: Size of queue in bytes */
+ u32 size;
+ /** @head: Head pointer in bytes, moved by producer, protected by @lock */
+ u32 head;
+ /** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
+ u32 tail;
+ /** @lock: protects page fault queue */
+ spinlock_t lock;
+ /** @worker: to process page faults */
+ structwork_structworker;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +#endif
Matthew Brost
maintainerRe: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 10 lines · Stuart
Few basic comments below to start. I personally would rather this be brought over from the existing fault handler rather than creating something entirely new and then clobbering the older stuff - just so the review of message format requests/replies is easier to review and where we're deviating from the existing external interfaces (HW/FW/GuC/etc). You already have this here though so not a huge deal. I think most of this was in the giant blob of patches that got merged with the initial driver, so I guess the counter argument is we can have easy to reference historical reviews now.
Yes, page fault code is largely just a big blob from the original Xe patch that wasn't the most well thought out code. We still have that history in the tree, just git blame won't work, so you'd need to know where to look if want that.
I don't think there is a great way to pull this over, unless patches 2-7 are squashed into a single patch + a couple of 'git mv' are used.
Quoted 153 lines · Matthew Brost
Quoted 152 lines
Stub out the new page fault layer and add kernel documentation. This is
intended as a replacement for the GT page fault layer, enabling multiple
producers to hook into a shared page fault consumer interface.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++drivers/gpu/drm/xe/xe_pagefault_types.h| 125
++++++++++++++++++++++++4 files changed, 208 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_pagefault.hcreate mode 100644drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with
+ * hardware or firmware to receive and parse faults into structxe_pagefault,
+ * then forwards them to the consumer. The consumer layer services the faults
+ * (e.g., memory migration, page table updates) and acknowledges the result back
+ * to the producer, which then forwards the results to the hardware or firmware.
+ * The consumer uses a page fault queue sized to absorb all potential faults and
+ * a multi-threaded worker to process them. Multiple producers are supported,
+ * with a single shared consumer.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +21
-0+ +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ + /* TODO - implement */ + return 0; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on
+ * the GT.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +11
-0+void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ + /* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to
+ * service it. Safe to be called from IRQ or process context. Reclaim safe.
+ *
+ * Return: 0 on success, errno on failure
+ */
+intxe_pagefault_handler(struct xe_device *xe, struct xe_pagefault *pf)drivers/gpu/drm/xe/xe_pagefault.c new file +4
-0+{ + /* TODO - implement */ + return 0; +}drivers/gpu/drm/xe/xe_pagefault.h new file +17
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler(struct xe_device *xe, struct xe_pagefault*pf);
drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 12
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault ; +struct xe_gt ;Nit: Maybe reverse these structs to be in alphabetical order
Yes, that is the preferred style. Will fix.
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +15
-0+ +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0,
Quoted 9 lines
Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +1
-0+ /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write accessviolation */
+ XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1,
+ /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */
XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION->XE_PAGEFAULT_ACCESS_TYPE_ATOMIC
The intended prefix here is 'XE_PAGEFAULT_TYPE_' to normalize the naming with 'enum xe_pagefault_type'.
Quoted 41 lines
Quoted 32 lines
+ XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2,
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** +* @ack_fault: Ack fault +* @pf: Page fault +* @err: Error state of fault +* +* Page fault producer receives acknowledgment from the consumer and
+ * sends the result to the HW/FW interface. + */
+ void (*ack_fault)(structxe_pagefault*pf, int err);drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** +* struct xe_pagefault - Xe page fault +* +* Generic page fault structure for communication between producer and consumer.
+ * Carefully sized to be 64 bytes.
+ */
+structxe_pagefault{
+ /**
+ * @gt: GT of fault
+ *
+ * XXX: We may want to decouple the GT from individual faults, as it's
+ * unclear whether future platforms will always have a GT for all pageQuoted 8 lines
+ * fault producers. Internally, the GT is used for stats, identifying
+ * the appropriate VRAM region, and locating the migration queue.
+ * Leaving this as-is for now, but we can revisit later to see if we
+ * can convert it to use the Xe device pointer instead. + */
Quoted 8 lines
What if instead of assuming the GT stays static and we eventually remove if we have some new HW abstraction layer that isn't a GT but still uses the page fault, we instead push to have said theoretical abstraction layer overload the GT here like we're doing with primary and media today. Then we can keep the interface here simple and just leave this in there, or change in the future if that doesn't make sense without the suggestive comment?
I can remove this comment, as it adds some confusion. Hopefully, we always have a GT. I was just speculating about future cases where we might not have one. From a purely interface perspective, it would be ideal to completely decouple the GT here.
Quoted 15 lines
Quoted 6 lines
+ struct
xe_gt*gt;
+ /**
+ * @consumer: State for the software handling the fault. Populated by
+ * the producer and may be modified by the consumer to communicateQuoted 8 lines
+ * information back to the producer upon fault acknowledgment.
+ */
+ struct {
+ /** @consumer.page_addr: address of page fault */ + u64page_addr;
+ /** @consumer.asid: address space ID */ + u32 asid;
Quoted 3 lines
Can we just call this an ID instead of a pasid or asid? I.e. the ID could be anything, not strictly process-bound.
I think the idea here is that this serves as the ID for our reverse VM lookup mechanism in the KMD. We call it ASID throughout the codebase today, so we’re stuck with the name—though it may or may not have any actual meaning in hardware, depending on the producer. For example, if the producer receives a fault based on a queue ID, we’d look up the queue and then pass in q->vm.asid.
We could even have the producer look up the VM directly, if preferred, and just pass that over. However, that would require a few more bits here and might introduce lifetime issues—for example, we’d have to refcount the VM.
Quoted 14 lines
Quoted 5 lines
+ /** @consumer.access_type: access type */ + u8
access_type;
+ /** @consumer.fault_type: fault type */ + u8fault_type;
+#define XE_PAGEFAULT_LEVEL_NACK 0xff /* ProducerQuoted 8 lines
indicates nack fault */
+ /** @consumer.fault_level: fault level */ + u8fault_level;
+ /** @consumer.engine_class: engine class */ + u8engine_class;
+ /** consumer.reserved: reserved bits for future expansion */
+ u64 reserved;
Quoted 2 lines
What about engine instance? Or is that going to overload reserved here?
reserved could be used to include 'engine instance' if required, is there for future expansion and also to have structure sized to 64 bytes.
I include fault_level, engine_class as I though both were used by [1] but now that I looked again only fault level is used so I guess engine_class can be pulled out too unless we want to keep for the only place in which it is used (debug messages).
Matt
[1] https://patchwork.freedesktop.org/series/148727/
Quoted 51 lines
Thanks,
StuartQuoted 47 lines
+ } consumer;
+ /**
+ * @producer: State for the producer (i.e., HW/FW interface). Populated
+ * by the producer and should not be modified—or even inspected—by the
+ * consumer, except for calling operations.
+ */
+ struct {
+ /** @producer.private: private pointer */ + void *private;
+ /** @producer.ops: operations */
+ const structxe_pagefault_ops*ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4
+ /**
+ * producer.msg: page fault message, used by producer in fault
+ * acknowledgement to formulate response to HW/FW interface.
+ */
+ u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW]; + } producer;drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { + /** +* @data: Data in queue containing struct xe_pagefault, protected by
+ * @lock
+ */
+ void *data;
+ /** @size: Size of queue in bytes */
+ u32 size;
+ /** @head: Head pointer in bytes, moved by producer, protected by @lock */
+ u32 head;
+ /** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
+ u32 tail;
+ /** @lock: protects page fault queue */
+ spinlock_t lock;
+ /** @worker: to process page faults */
+ structwork_structworker;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +#endif
Re: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 18 lines · Matthew Brost
Quoted 7 lines · Stuart
Few basic comments below to start. I personally would rather this be
brought over from the existing fault handler rather than creating something entirely new and then clobbering the older stuff - just so
the review of message format requests/replies is easier to review andQuoted 9 lines
where we're deviating from the existing external interfaces (HW/FW/GuC/etc). You already have this here though so not a huge deal.
I think most of this was in the giant blob of patches that got merged
with the initial driver, so I guess the counter argument is we can have
easy to reference historical reviews now.
Quoted 8 lines
Yes, page fault code is largely just a big blob from the original Xe patch that wasn't the most well thought out code. We still have that history in the tree, just git blame won't work, so you'd need to know where to look if want that.
I don't think there is a great way to pull this over, unless patches 2-7
are squashed into a single patch + a couple of 'git mv' are used.
No definitely don't think that's worth it. Let's just review as-is.
Quoted 203 lines
Quoted 163 lines · Matthew Brost
Quoted 161 lines
Stub out the new page fault layer and add kernel documentation. This
is
intended as a replacement for the GT page fault layer, enabling multiple
producers to hook into a shared page fault consumer interface.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++drivers/gpu/drm/xe/xe_pagefault_types.h| 125
++++++++++++++++++++++++4 files changed, 208 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_pagefault.hcreate mode 100644drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with
+ * hardware or firmware to receive and parse faults into structxe_pagefault,
+ * then forwards them to the consumer. The consumer layer services
the faults
+ * (e.g., memory migration, page table updates) and acknowledges the
result back
+ * to the producer, which then forwards the results to the hardware
or firmware.
+ * The consumer uses a page fault queue sized to absorb all potential faults and
+ * a multi-threaded worker to process them. Multiple producers are
supported,
+ * with a single shared consumer.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +6
-0+ +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses.
+ *
+ * Return: 0 on Success, errno on failure
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0+int xe_pagefault_init (struct xe_device *xe) +{ + /* TODO - implement */ + return 0; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on
+ * the GT.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +11
-0+void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ + /* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue
a worker to
+ * service it. Safe to be called from IRQ or process context. Reclaim safe.
+ *
+ * Return: 0 on success, errno on failure
+ */
+int xe_pagefault_handler(structxe_device*xe, structxe_pagefault
*pf)drivers/gpu/drm/xe/xe_pagefault.c new file +4
-0+{ + /* TODO - implement */ + return 0; +}drivers/gpu/drm/xe/xe_pagefault.h new file +17
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler(struct xe_device *xe, struct
xe_pagefault
*pf);drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 12
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault ; +struct xe_gt ;Nit: Maybe reverse these structs to be in alphabetical order
Yes, that is the preferred style. Will fix.
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +8
-0+ +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type*/
+ XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2,drivers/gpu/drm/xe/xe_pagefault_types.h new file +7
-0+}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Writeaccess
Quoted 9 lines
Quoted 5 lines
violation */
+ XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access
violation */
XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION->XE_PAGEFAULT_ACCESS_TYPE_ATOMIC
Quoted 3 lines
The intended prefix here is '
XE_PAGEFAULT_TYPE_' to normalize the naming
with 'enumxe_pagefault_type'.
Ah sorry you're right. I also should have been more specific that I meant this should be ATOMIC access vs WRITE access, so:XE_PAGEFAULT_TYPE_ATOMIC_ACCESS_VIOLATION
Quoted 91 lines
Quoted 48 lines
Quoted 37 lines
+ XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2,
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** +* @ack_fault: Ack fault +* @pf: Page fault +* @err: Error state of fault +* +* Page fault producer receives acknowledgment from the consumer and
+ * sends the result to the HW/FW interface. + */
+ void (*ack_fault)(structxe_pagefault*pf, int err);drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** +* struct xe_pagefault - Xe page fault +* +* Generic page fault structure for communication between producer
and consumer.
+ * Carefully sized to be 64 bytes.
+ */
+structxe_pagefault{
+ /**
+ * @gt: GT of fault
+ *
+ * XXX: We may want to decouple the GT from individual faults, as it's
+ * unclear whether future platforms will always have a GT for
all page
+ * fault producers. Internally, the GT is used for stats, identifyingQuoted 8 lines
+ * the appropriate VRAM region, and locating the migration
queue.
+ * Leaving this as-is for now, but we can revisit later to
see if we
+ * can convert it to use the Xe device pointer instead. + */What if instead of assuming the GT stays static and we eventually remove if we have some new HW abstraction layer that isn't a GT but
Quoted 9 lines
still uses the page fault, we instead push to have said theoretical abstraction layer overload the GT here like we're doing with primary
and media today. Then we can keep the interface here simple and just
leave this in there, or change in the future if that doesn't make sense
without the suggestive comment?I can remove this comment, as it adds some confusion. Hopefully, we always have a GT. I was just speculating about future cases where we might not have one. From a purely interface perspective, it would be ideal to completely decouple the GT here.
Quoted 15 lines
Quoted 6 lines
+ struct
xe_gt*gt;
+ /**
+ * @consumer: State for the software handling the fault. Populated by
+ * the producer and may be modified by the consumer to communicateQuoted 8 lines
+ * information back to the producer upon fault acknowledgment.
+ */
+ struct {
+ /** @consumer.page_addr: address of page fault */ + u64page_addr;
+ /** @consumer.asid: address space ID */ + u32 asid;Quoted 3 lines
Can we just call this an ID instead of a pasid or asid? I.e. the ID could be anything, not strictly process-bound.
I think the idea here is that this serves as the ID for our reverse VM
lookup mechanism in the KMD. We call it ASID throughout the codebase today, so we’re stuck with the name—though it may or may not have any actual meaning in hardware, depending on the producer. For example, if
the producer receives a fault based on a queue ID, we’d look up the queue and then pass inq->vm.asid.
Quoted 5 lines
We could even have the producer look up the VM directly, if preferred,
and just pass that over. However, that would require a few more bits here and might introduce lifetime issues—for example, we’d have to refcount the VM.
Yeah I mean some of those problems we can solve if they come up later. Just thinking having something more generic here would be nice. But I agree on the cross-KMD usage. We can keep this and change it more broadly if that makes sense later.
Quoted 24 lines
Quoted 16 lines
Quoted 15 lines
+ /** @consumer.access_type: access type */ + u8
access_type;
+ /** @consumer.fault_type: fault type */ + u8fault_type;
+#define XE_PAGEFAULT_LEVEL_NACK 0xff /* Producer
indicates nack fault */
+ /** @consumer.fault_level: fault level */ + u8fault_level;
+ /** @consumer.engine_class: engine class */ + u8engine_class;
+ /** consumer.reserved: reserved bits for future expansion */
+ u64 reserved;Quoted 3 lines
What about engine instance? Or is that going to overload reserved here?
reserved could be used to include 'engine instance' if required, is there for future expansion and also to have structure sized to 64 bytes.
Quoted 5 lines
I include
fault_level,engine_classas I though both were used by [1] but now that I looked again only fault level is used so I guessengine_classcan be pulled out too unless we want to keep for the only
place in which it is used (debug messages).
I think today hardware/GuC provides both engine class and engine instance which is why I mentioned. We can ignore those fields if we don't feel they are valuable/relevant, but at least today we are reading those and printing them out.
Thanks,
Stuart
Quoted 58 lines
Matt
[1] https://patchwork.freedesktop.org/series/148727/
Quoted 53 lines
Thanks,
StuartQuoted 49 lines
+ } consumer;
+ /**
+ * @producer: State for the producer (i.e., HW/FW interface).
Populated
+ * by the producer and should not be modified—or even inspected—by the
+ * consumer, except for calling operations.
+ */
+ struct {
+ /** @producer.private: private pointer */ + void *private;
+ /** @producer.ops: operations */
+ const structxe_pagefault_ops*ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4
+ /**
+ * producer.msg: page fault message, used by producer
in fault
+ * acknowledgement to formulate response to HW/FW interface.
+ */
+ u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW]; + } producer;drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { + /** +* @data: Data in queue containing struct xe_pagefault, protected by
+ * @lock
+ */
+ void *data;
+ /** @size: Size of queue in bytes */
+ u32 size;
+ /** @head: Head pointer in bytes, moved by producer, protected by @lock */
+ u32 head;
+ /** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
+ u32 tail;
+ /** @lock: protects page fault queue */
+ spinlock_t lock;
+ /** @worker: to process page faults */
+ structwork_structworker;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +#endif
Matthew Brost
maintainerRe: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 338 lines · Stuart
Quoted 18 lines · Matthew Brost
Quoted 7 lines · Stuart
Few basic comments below to start. I personally would rather this be
brought over from the existing fault handler rather than creating something entirely new and then clobbering the older stuff - just so
the review of message format requests/replies is easier to review andQuoted 9 lines
where we're deviating from the existing external interfaces (HW/FW/GuC/etc). You already have this here though so not a huge deal.
I think most of this was in the giant blob of patches that got merged
with the initial driver, so I guess the counter argument is we can have
easy to reference historical reviews now.Quoted 8 lines
Yes, page fault code is largely just a big blob from the original Xe patch that wasn't the most well thought out code. We still have that history in the tree, just git blame won't work, so you'd need to know where to look if want that.
I don't think there is a great way to pull this over, unless patches 2-7
are squashed into a single patch + a couple of 'git mv' are used.No definitely don't think that's worth it. Let's just review as-is.
Quoted 203 lines
Quoted 163 lines · Matthew Brost
Quoted 161 lines
Stub out the new page fault layer and add kernel documentation. This
is
intended as a replacement for the GT page fault layer, enabling multiple
producers to hook into a shared page fault consumer interface.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++drivers/gpu/drm/xe/xe_pagefault_types.h| 125
++++++++++++++++++++++++4 files changed, 208 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_pagefault.hcreate mode 100644drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with
+ * hardware or firmware to receive and parse faults into structxe_pagefault,
+ * then forwards them to the consumer. The consumer layer services
the faults
+ * (e.g., memory migration, page table updates) and acknowledges the
result back
+ * to the producer, which then forwards the results to the hardware
or firmware.
+ * The consumer uses a page fault queue sized to absorb all potential faults and
+ * a multi-threaded worker to process them. Multiple producers are
supported,
+ * with a single shared consumer.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +6
-0+ +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses.
+ *
+ * Return: 0 on Success, errno on failure
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0+int xe_pagefault_init (struct xe_device *xe) +{ + /* TODO - implement */ + return 0; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on
+ * the GT.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +11
-0+void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ + /* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue
a worker to
+ * service it. Safe to be called from IRQ or process context. Reclaim safe.
+ *
+ * Return: 0 on success, errno on failure
+ */
+int xe_pagefault_handler(structxe_device*xe, structxe_pagefault
*pf)drivers/gpu/drm/xe/xe_pagefault.c new file +4
-0+{ + /* TODO - implement */ + return 0; +}drivers/gpu/drm/xe/xe_pagefault.h new file +17
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler(struct xe_device *xe, struct
xe_pagefault
*pf);drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 12
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault ; +struct xe_gt ;Nit: Maybe reverse these structs to be in alphabetical order
Yes, that is the preferred style. Will fix.
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +8
-0+ +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type*/
+ XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2,drivers/gpu/drm/xe/xe_pagefault_types.h new file +7
-0+}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Writeaccess
Quoted 9 lines
Quoted 5 lines
violation */
+ XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access
violation */
XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION->XE_PAGEFAULT_ACCESS_TYPE_ATOMICQuoted 3 lines
The intended prefix here is '
XE_PAGEFAULT_TYPE_' to normalize the naming
with 'enumxe_pagefault_type'.Ah sorry you're right. I also should have been more specific that I meant this should be ATOMIC access vs WRITE access, so:
XE_PAGEFAULT_TYPE_ATOMIC_ACCESS_VIOLATIONQuoted 91 lines
Quoted 48 lines
Quoted 37 lines
+ XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2,
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** +* @ack_fault: Ack fault +* @pf: Page fault +* @err: Error state of fault +* +* Page fault producer receives acknowledgment from the consumer and
+ * sends the result to the HW/FW interface. + */
+ void (*ack_fault)(structxe_pagefault*pf, int err);drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** +* struct xe_pagefault - Xe page fault +* +* Generic page fault structure for communication between producer
and consumer.
+ * Carefully sized to be 64 bytes.
+ */
+structxe_pagefault{
+ /**
+ * @gt: GT of fault
+ *
+ * XXX: We may want to decouple the GT from individual faults, as it's
+ * unclear whether future platforms will always have a GT for
all page
+ * fault producers. Internally, the GT is used for stats, identifyingQuoted 8 lines
+ * the appropriate VRAM region, and locating the migration
queue.
+ * Leaving this as-is for now, but we can revisit later to
see if we
+ * can convert it to use the Xe device pointer instead. + */What if instead of assuming the GT stays static and we eventually remove if we have some new HW abstraction layer that isn't a GT but
Quoted 9 lines
still uses the page fault, we instead push to have said theoretical abstraction layer overload the GT here like we're doing with primary
and media today. Then we can keep the interface here simple and just
leave this in there, or change in the future if that doesn't make sense
without the suggestive comment?I can remove this comment, as it adds some confusion. Hopefully, we always have a GT. I was just speculating about future cases where we might not have one. From a purely interface perspective, it would be ideal to completely decouple the GT here.
Quoted 15 lines
Quoted 6 lines
+ struct
xe_gt*gt;
+ /**
+ * @consumer: State for the software handling the fault. Populated by
+ * the producer and may be modified by the consumer to communicateQuoted 8 lines
+ * information back to the producer upon fault acknowledgment.
+ */
+ struct {
+ /** @consumer.page_addr: address of page fault */ + u64page_addr;
+ /** @consumer.asid: address space ID */ + u32 asid;Quoted 3 lines
Can we just call this an ID instead of a pasid or asid? I.e. the ID could be anything, not strictly process-bound.
I think the idea here is that this serves as the ID for our reverse VM
lookup mechanism in the KMD. We call it ASID throughout the codebase today, so we’re stuck with the name—though it may or may not have any actual meaning in hardware, depending on the producer. For example, if
the producer receives a fault based on a queue ID, we’d look up the queue and then pass inq->vm.asid.Quoted 5 lines
We could even have the producer look up the VM directly, if preferred,
and just pass that over. However, that would require a few more bits here and might introduce lifetime issues—for example, we’d have to refcount the VM.
Quoted 5 lines
Yeah I mean some of those problems we can solve if they come up later. Just thinking having something more generic here would be nice. But I agree on the cross-KMD usage. We can keep this and change it more broadly if that makes sense later.
I think the point here is we are always going to have a VM which is required by the consumer to service the fault, the producer side needs parse the fault and figure out a known value in the KMD which corresponds to a VM and pass it over. We call this value asid today (also the name of hardware interface + what we program into the LRC) but could rename this everywhere in KMD if that makes sense. e.g., kmd_vm_id (vm_id is a user space name / value which means something different).
Quoted 30 lines
Quoted 24 lines
Quoted 16 lines
Quoted 15 lines
+ /** @consumer.access_type: access type */ + u8
access_type;
+ /** @consumer.fault_type: fault type */ + u8fault_type;
+#define XE_PAGEFAULT_LEVEL_NACK 0xff /* Producer
indicates nack fault */
+ /** @consumer.fault_level: fault level */ + u8fault_level;
+ /** @consumer.engine_class: engine class */ + u8engine_class;
+ /** consumer.reserved: reserved bits for future expansion */
+ u64 reserved;Quoted 3 lines
What about engine instance? Or is that going to overload reserved here?
reserved could be used to include 'engine instance' if required, is there for future expansion and also to have structure sized to 64 bytes.
Quoted 5 lines
I include
fault_level,engine_classas I though both were used by [1] but now that I looked again only fault level is used so I guessengine_classcan be pulled out too unless we want to keep for the only
place in which it is used (debug messages).
Quoted 5 lines
I think today hardware/GuC provides both engine class and engine instance which is why I mentioned. We can ignore those fields if we don't feel they are valuable/relevant, but at least today we are reading those and printing them out.
Yes, the debug message drops engine instance due to not passing this value over. I think that is ok, engine class typically all we care about anyways.
Matt
Quoted 62 lines
Thanks,
StuartQuoted 58 lines
Matt
[1] https://patchwork.freedesktop.org/series/148727/
Quoted 53 lines
Thanks,
StuartQuoted 49 lines
+ } consumer;
+ /**
+ * @producer: State for the producer (i.e., HW/FW interface).
Populated
+ * by the producer and should not be modified—or even inspected—by the
+ * consumer, except for calling operations.
+ */
+ struct {
+ /** @producer.private: private pointer */ + void *private;
+ /** @producer.ops: operations */
+ const structxe_pagefault_ops*ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4
+ /**
+ * producer.msg: page fault message, used by producer
in fault
+ * acknowledgement to formulate response to HW/FW interface.
+ */
+ u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW]; + } producer;drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { + /** +* @data: Data in queue containing struct xe_pagefault, protected by
+ * @lock
+ */
+ void *data;
+ /** @size: Size of queue in bytes */
+ u32 size;
+ /** @head: Head pointer in bytes, moved by producer, protected by @lock */
+ u32 head;
+ /** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
+ u32 tail;
+ /** @lock: protects page fault queue */
+ spinlock_t lock;
+ /** @worker: to process page faults */
+ structwork_structworker;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +#endif
Re: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 398 lines · Matthew Brost
Quoted 389 lines · Stuart
Quoted 32 lines · Matthew Brost
Quoted 13 lines · Stuart
Few basic comments below to start. I personally would rather this
be
brought over from the existing fault handler rather than creating
something entirely new and then clobbering the older stuff - just
so
the review of message format requests/replies is easier to review
and
where we're deviating from the existing external interfaces (HW/FW/GuC/etc). You already have this here though so not aQuoted 9 lines
huge
deal.
I think most of this was in the giant blob of patches that got merged
with the initial driver, so I guess the counter argument is we can
have
easy to reference historical reviews now.Yes, page fault code is largely just a big blob from the original Xe
patch that wasn't the most well thought out code. We still have that
history in the tree, just git blame won't work, so you'd need to know
where to look if want that.Quoted 4 lines
I don't think there is a great way to pull this over, unless patches
2-7
are squashed into a single patch + a couple of 'git mv' are used.No definitely don't think that's worth it. Let's just review as-is.
Quoted 220 lines
Quoted 176 lines · Matthew Brost
Quoted 174 lines
Stub out the new page fault layer and add kernel documentation.
This
is
intended as a replacement for the GT page fault layer, enabling
multiple
producers to hook into a shared page fault consumer interface.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++drivers/gpu/drm/xe/xe_pagefault_types.h| 125
++++++++++++++++++++++++4 files changed, 208 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_pagefault.hcreate mode 100644drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer
interacts with
+ * hardware or firmware to receive and parse faults into structxe_pagefault,
+ * then forwards them to the consumer. The consumer layer services
the faults
+ * (e.g., memory migration, page table updates) and acknowledges
the
result back
+ * to the producer, which then forwards the results to the hardware
or firmware.
+ * The consumer uses a page fault queue sized to absorb all potential faults and
+ * a multi-threaded worker to process them. Multiple producers
are
supported,
+ * with a single shared consumer.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +6
-0+ +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading
fuses.
+ *
+ * Return: 0 on Success, errno on failure
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0+int xe_pagefault_init (struct xe_device *xe) +{ + /* TODO - implement */ + return 0; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any
pending faults on
+ * the GT.
+ */
+voidxe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt)drivers/gpu/drm/xe/xe_pagefault.c new file +10
-0+{ + /* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and
queue
a worker to
+ * service it. Safe to be called from IRQ or process context.
Reclaim safe.
+ *
+ * Return: 0 on success, errno on failure
+ */
+int xe_pagefault_handler(structxe_device*xe, structxe_pagefault
*pf)drivers/gpu/drm/xe/xe_pagefault.c new file +4
-0+{ + /* TODO - implement */ + return 0; +}drivers/gpu/drm/xe/xe_pagefault.h new file +15
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset(struct xe_device *xe, struct xe_gt*gt);
drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +int xe_pagefault_handler(struct xe_device *xe, struct
xe_pagefault
*pf);drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 12
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault ; +struct xe_gt ;Nit: Maybe reverse these structs to be in alphabetical order
Yes, that is the preferred style. Will fix.
Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+ +/** enum xe_pagefault_access_type - Xe page fault access type */
+enumxe_pagefault_access_type{
+ /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */
+ XE_PAGEFAULT_ACCESS_TYPE_READ = 0,
+ /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */
+ XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1,
+ /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type
*/
+ XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2,drivers/gpu/drm/xe/xe_pagefault_types.h new file +7
-0+}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Writeaccess
Quoted 9 lines
Quoted 5 lines
violation */
+ XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access
violation */
XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION->XE_PAGEFAULT_ACCESS_TYPE_ATOMICQuoted 3 lines
The intended prefix here is '
XE_PAGEFAULT_TYPE_' to normalize the naming
with 'enumxe_pagefault_type'.Ah sorry you're right. I also should have been more specific that I meant this should be ATOMIC access vs WRITE access, so:
XE_PAGEFAULT_TYPE_ATOMIC_ACCESS_VIOLATIONQuoted 113 lines
Quoted 58 lines
Quoted 43 lines
+ XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2,
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** +* @ack_fault: Ack fault +* @pf: Page fault +* @err: Error state of fault +* +* Page fault producer receives acknowledgment from the
consumer and
+ * sends the result to the HW/FW interface. + */
+ void (*ack_fault)(structxe_pagefault*pf, int err);drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** +* struct xe_pagefault - Xe page fault +* +* Generic page fault structure for communication between producer
and consumer.
+ * Carefully sized to be 64 bytes.
+ */
+structxe_pagefault{
+ /**
+ * @gt: GT of fault
+ *
+ * XXX: We may want to decouple the GT from individual
faults, as it's
+ * unclear whether future platforms will always have a GT
for
all page
+ * fault producers. Internally, the GT is used for stats,
identifying
+ * the appropriate VRAM region, and locating the migrationQuoted 8 lines
queue.
+ * Leaving this as-is for now, but we can revisit later
to
see if we
+ * can convert it to use the Xe device pointer instead.
+ */What if instead of assuming the GT stays static and we eventually
remove if we have some new HW abstraction layer that isn't a GT but
still uses the page fault, we instead push to have said theoreticalQuoted 9 lines
abstraction layer overload the GT here like we're doing with primary
and media today. Then we can keep the interface here simple and just
leave this in there, or change in the future if that doesn't make
sense
without the suggestive comment?I can remove this comment, as it adds some confusion. Hopefully, we
always have a GT. I was just speculating about future cases where we
might not have one. From a purely interface perspective, it would be
ideal to completely decouple the GT here.Quoted 18 lines
Quoted 9 lines
+ struct
xe_gt*gt;
+ /**
+ * @consumer: State for the software handling the fault.
Populated by
+ * the producer and may be modified by the consumer to
communicate
+ * information back to the producer upon faultQuoted 8 lines
acknowledgment.
+ */
+ struct {
+ /** @consumer.page_addr: address of page fault */
+ u64page_addr;
+ /** @consumer.asid: address space ID */ + u32 asid;Quoted 4 lines
Can we just call this an ID instead of a pasid or asid? I.e. the ID
could be anything, not strictly process-bound.I think the idea here is that this serves as the ID for our reverse
VM
lookup mechanism in the KMD. We call it ASID throughout the codebase
today, so we’re stuck with the name—though it may or may not have any
actual meaning in hardware, depending on the producer. For example,
if
the producer receives a fault based on a queue ID, we’d look up the
queue and then pass inq->vm.asid.Quoted 7 lines
We could even have the producer look up the VM directly, if preferred,
and just pass that over. However, that would require a few more bits
here and might introduce lifetime issues—for example, we’d have to
refcount the VM.Quoted 7 lines
Yeah I mean some of those problems we can solve if they come up later.
Just thinking having something more generic here would be nice. But I
agree on the cross-KMD usage. We can keep this and change it more broadly if that makes sense later.
Quoted 10 lines
I think the point here is we are always going to have a VM which is required by the consumer to service the fault, the producer side needs
parse the fault and figure out a known value in the KMD which corresponds to a VM and pass it over. We call this value asid today (also the name of hardware interface + what we program into the LRC) but
could rename this everywhere in KMD if that makes sense. e.g.,kmd_vm_id(vm_idis a user space name / value which means something different).
Ok for now no problem. I agree this is consistent in the driver anyway so better to make a more holistic change if we do that. I do like the idea of having this more generic to allow all types of fault originators. We can look later though.
Quoted 41 lines
Quoted 35 lines
Quoted 28 lines
Quoted 18 lines
Quoted 17 lines
+ /** @consumer.access_type: access type */ + u8
access_type;
+ /** @consumer.fault_type: fault type */ + u8fault_type;
+#define XE_PAGEFAULT_LEVEL_NACK 0xff /* Producer
indicates nack fault */
+ /** @consumer.fault_level: fault level */ + u8fault_level;
+ /** @consumer.engine_class: engine class */ + u8engine_class;
+ /** consumer.reserved: reserved bits for future
expansion */
+ u64 reserved;Quoted 4 lines
What about engine instance? Or is that going to overload reserved
here?reserved could be used to include 'engine instance' if required, is
there for future expansion and also to have structure sized to 64 bytes.Quoted 6 lines
I include
fault_level,engine_classas I though both were used by
[1]
but now that I looked again only fault level is used so I guessengine_classcan be pulled out too unless we want to keep for the only
place in which it is used (debug messages).Quoted 5 lines
I think today hardware/GuC provides both engine class and engine instance which is why I mentioned. We can ignore those fields if we don't feel they are valuable/relevant, but at least today we are reading those and printing them out.
Quoted 4 lines
Yes, the debug message drops engine instance due to not passing this value over. I think that is ok, engine class typically all we care about
anyways.
I'd actually disagree here. I think it is valueable to print out all of the fields we receive from hardware for debug puroses - i.e. if we get a fault to a non-existant engine instance or to the wrong one, it could help us narrow down issues in that area. At the very least we should have a way to print and decode these even if we only actually store the class.
Thanks,
Stuart
Quoted 68 lines
Matt
Quoted 65 lines
Thanks,
StuartQuoted 61 lines
Matt
[1] https://patchwork.freedesktop.org/series/148727/
Quoted 56 lines
Thanks,
StuartQuoted 52 lines
+ } consumer;
+ /**
+ * @producer: State for the producer (i.e., HW/FW interface).
Populated
+ * by the producer and should not be modified—or even inspected—by the
+ * consumer, except for calling operations. + */
+ struct {
+ /** @producer.private: private pointer */ + void *private;
+ /** @producer.ops: operations */
+ const structxe_pagefault_ops*ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4
+ /**
+ * producer.msg: page fault message, used by producer
in fault
+ * acknowledgement to formulate response to HW/FW
interface.
+ */
+ u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW]; + } producer;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */
+structxe_pagefault_queue{
+ /**
+ * @data: Data in queue containing structxe_pagefault,
protected by
+ * @lock
+ */
+ void *data;
+ /** @size: Size of queue in bytes */
+ u32 size;
+ /** @head: Head pointer in bytes, moved by producer, protected by @lock */
+ u32 head;
+ /** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
+ u32 tail;
+ /** @lock: protects page fault queue */
+ spinlock_t lock;
+ /** @worker: to process page faults */
+ structwork_structworker;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +#endif
Matthew Brost
maintainerRe: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 461 lines · Stuart
Quoted 398 lines · Matthew Brost
Quoted 389 lines · Stuart
Quoted 32 lines · Matthew Brost
Quoted 13 lines · Stuart
Few basic comments below to start. I personally would rather this
be
brought over from the existing fault handler rather than creating
something entirely new and then clobbering the older stuff - just
so
the review of message format requests/replies is easier to review
and
where we're deviating from the existing external interfaces (HW/FW/GuC/etc). You already have this here though so not aQuoted 9 lines
huge
deal.
I think most of this was in the giant blob of patches that got merged
with the initial driver, so I guess the counter argument is we can
have
easy to reference historical reviews now.Yes, page fault code is largely just a big blob from the original Xe
patch that wasn't the most well thought out code. We still have that
history in the tree, just git blame won't work, so you'd need to know
where to look if want that.Quoted 4 lines
I don't think there is a great way to pull this over, unless patches
2-7
are squashed into a single patch + a couple of 'git mv' are used.No definitely don't think that's worth it. Let's just review as-is.
Quoted 220 lines
Quoted 176 lines · Matthew Brost
Quoted 174 lines
Stub out the new page fault layer and add kernel documentation.
This
is
intended as a replacement for the GT page fault layer, enabling
multiple
producers to hook into a shared page fault consumer interface.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++drivers/gpu/drm/xe/xe_pagefault_types.h| 125
++++++++++++++++++++++++4 files changed, 208 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_pagefault.hcreate mode 100644drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer
interacts with
+ * hardware or firmware to receive and parse faults into structxe_pagefault,
+ * then forwards them to the consumer. The consumer layer services
the faults
+ * (e.g., memory migration, page table updates) and acknowledges
the
result back
+ * to the producer, which then forwards the results to the hardware
or firmware.
+ * The consumer uses a page fault queue sized to absorb all potential faults and
+ * a multi-threaded worker to process them. Multiple producers
are
supported,
+ * with a single shared consumer.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +6
-0+ +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading
fuses.
+ *
+ * Return: 0 on Success, errno on failure
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0+int xe_pagefault_init (struct xe_device *xe) +{ + /* TODO - implement */ + return 0; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any
pending faults on
+ * the GT.
+ */
+voidxe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt)drivers/gpu/drm/xe/xe_pagefault.c new file +10
-0+{ + /* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and
queue
a worker to
+ * service it. Safe to be called from IRQ or process context.
Reclaim safe.
+ *
+ * Return: 0 on success, errno on failure
+ */
+int xe_pagefault_handler(structxe_device*xe, structxe_pagefault
*pf)drivers/gpu/drm/xe/xe_pagefault.c new file +4
-0+{ + /* TODO - implement */ + return 0; +}drivers/gpu/drm/xe/xe_pagefault.h new file +15
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset(struct xe_device *xe, struct xe_gt*gt);
drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +int xe_pagefault_handler(struct xe_device *xe, struct
xe_pagefault
*pf);drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 12
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault ; +struct xe_gt ;Nit: Maybe reverse these structs to be in alphabetical order
Yes, that is the preferred style. Will fix.
Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+ +/** enum xe_pagefault_access_type - Xe page fault access type */
+enumxe_pagefault_access_type{
+ /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */
+ XE_PAGEFAULT_ACCESS_TYPE_READ = 0,
+ /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */
+ XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1,
+ /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type
*/
+ XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2,drivers/gpu/drm/xe/xe_pagefault_types.h new file +7
-0+}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Writeaccess
Quoted 9 lines
Quoted 5 lines
violation */
+ XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access
violation */
XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION->XE_PAGEFAULT_ACCESS_TYPE_ATOMICQuoted 3 lines
The intended prefix here is '
XE_PAGEFAULT_TYPE_' to normalize the naming
with 'enumxe_pagefault_type'.Ah sorry you're right. I also should have been more specific that I meant this should be ATOMIC access vs WRITE access, so:
XE_PAGEFAULT_TYPE_ATOMIC_ACCESS_VIOLATIONQuoted 113 lines
Quoted 58 lines
Quoted 43 lines
+ XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2,
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** +* @ack_fault: Ack fault +* @pf: Page fault +* @err: Error state of fault +* +* Page fault producer receives acknowledgment from the
consumer and
+ * sends the result to the HW/FW interface. + */
+ void (*ack_fault)(structxe_pagefault*pf, int err);drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** +* struct xe_pagefault - Xe page fault +* +* Generic page fault structure for communication between producer
and consumer.
+ * Carefully sized to be 64 bytes.
+ */
+structxe_pagefault{
+ /**
+ * @gt: GT of fault
+ *
+ * XXX: We may want to decouple the GT from individual
faults, as it's
+ * unclear whether future platforms will always have a GT
for
all page
+ * fault producers. Internally, the GT is used for stats,
identifying
+ * the appropriate VRAM region, and locating the migrationQuoted 8 lines
queue.
+ * Leaving this as-is for now, but we can revisit later
to
see if we
+ * can convert it to use the Xe device pointer instead.
+ */What if instead of assuming the GT stays static and we eventually
remove if we have some new HW abstraction layer that isn't a GT but
still uses the page fault, we instead push to have said theoreticalQuoted 9 lines
abstraction layer overload the GT here like we're doing with primary
and media today. Then we can keep the interface here simple and just
leave this in there, or change in the future if that doesn't make
sense
without the suggestive comment?I can remove this comment, as it adds some confusion. Hopefully, we
always have a GT. I was just speculating about future cases where we
might not have one. From a purely interface perspective, it would be
ideal to completely decouple the GT here.Quoted 18 lines
Quoted 9 lines
+ struct
xe_gt*gt;
+ /**
+ * @consumer: State for the software handling the fault.
Populated by
+ * the producer and may be modified by the consumer to
communicate
+ * information back to the producer upon faultQuoted 8 lines
acknowledgment.
+ */
+ struct {
+ /** @consumer.page_addr: address of page fault */
+ u64page_addr;
+ /** @consumer.asid: address space ID */ + u32 asid;Quoted 4 lines
Can we just call this an ID instead of a pasid or asid? I.e. the ID
could be anything, not strictly process-bound.I think the idea here is that this serves as the ID for our reverse
VM
lookup mechanism in the KMD. We call it ASID throughout the codebase
today, so we’re stuck with the name—though it may or may not have any
actual meaning in hardware, depending on the producer. For example,
if
the producer receives a fault based on a queue ID, we’d look up the
queue and then pass inq->vm.asid.Quoted 7 lines
We could even have the producer look up the VM directly, if preferred,
and just pass that over. However, that would require a few more bits
here and might introduce lifetime issues—for example, we’d have to
refcount the VM.Quoted 7 lines
Yeah I mean some of those problems we can solve if they come up later.
Just thinking having something more generic here would be nice. But I
agree on the cross-KMD usage. We can keep this and change it more broadly if that makes sense later.Quoted 10 lines
I think the point here is we are always going to have a VM which is required by the consumer to service the fault, the producer side needs
parse the fault and figure out a known value in the KMD which corresponds to a VM and pass it over. We call this value asid today (also the name of hardware interface + what we program into the LRC) but
could rename this everywhere in KMD if that makes sense. e.g.,kmd_vm_id(vm_idis a user space name / value which means something different).Ok for now no problem. I agree this is consistent in the driver anyway so better to make a more holistic change if we do that. I do like the idea of having this more generic to allow all types of fault originators. We can look later though.
Quoted 41 lines
Quoted 35 lines
Quoted 28 lines
Quoted 18 lines
Quoted 17 lines
+ /** @consumer.access_type: access type */ + u8
access_type;
+ /** @consumer.fault_type: fault type */ + u8fault_type;
+#define XE_PAGEFAULT_LEVEL_NACK 0xff /* Producer
indicates nack fault */
+ /** @consumer.fault_level: fault level */ + u8fault_level;
+ /** @consumer.engine_class: engine class */ + u8engine_class;
+ /** consumer.reserved: reserved bits for future
expansion */
+ u64 reserved;Quoted 4 lines
What about engine instance? Or is that going to overload reserved
here?reserved could be used to include 'engine instance' if required, is
there for future expansion and also to have structure sized to 64 bytes.Quoted 6 lines
I include
fault_level,engine_classas I though both were used by
[1]
but now that I looked again only fault level is used so I guessengine_classcan be pulled out too unless we want to keep for the only
place in which it is used (debug messages).Quoted 5 lines
I think today hardware/GuC provides both engine class and engine instance which is why I mentioned. We can ignore those fields if we don't feel they are valuable/relevant, but at least today we are reading those and printing them out.
Quoted 4 lines
Yes, the debug message drops engine instance due to not passing this value over. I think that is ok, engine class typically all we care about
anyways.
Quoted 7 lines
I'd actually disagree here. I think it is valueable to print out all of the fields we receive from hardware for debug puroses - i.e. if we get a fault to a non-existant engine instance or to the wrong one, it could help us narrow down issues in that area. At the very least we should have a way to print and decode these even if we only actually store the class.
Ok, since we have the extra bits, I'll include bring this back in and ensure we retain all information in the current debug message.
Matt
Quoted 72 lines
Thanks,
StuartQuoted 68 lines
Matt
Quoted 65 lines
Thanks,
StuartQuoted 61 lines
Matt
[1] https://patchwork.freedesktop.org/series/148727/
Quoted 56 lines
Thanks,
StuartQuoted 52 lines
+ } consumer;
+ /**
+ * @producer: State for the producer (i.e., HW/FW interface).
Populated
+ * by the producer and should not be modified—or even inspected—by the
+ * consumer, except for calling operations. + */
+ struct {
+ /** @producer.private: private pointer */ + void *private;
+ /** @producer.ops: operations */
+ const structxe_pagefault_ops*ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4
+ /**
+ * producer.msg: page fault message, used by producer
in fault
+ * acknowledgement to formulate response to HW/FW
interface.
+ */
+ u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW]; + } producer;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */
+structxe_pagefault_queue{
+ /**
+ * @data: Data in queue containing structxe_pagefault,
protected by
+ * @lock
+ */
+ void *data;
+ /** @size: Size of queue in bytes */
+ u32 size;
+ /** @head: Head pointer in bytes, moved by producer, protected by @lock */
+ u32 head;
+ /** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
+ u32 tail;
+ /** @lock: protects page fault queue */
+ spinlock_t lock;
+ /** @worker: to process page faults */
+ structwork_structworker;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +#endif
Re: [PATCH 01/11] drm/xe: Stub out new pagefault layer
In reply to Matthew BrostQuoted 42 lines · Matthew Brost
Stub out the new page fault layer and add kernel documentation. This is intended as a replacement for the GT page fault layer, enabling multiple producers to hook into a shared page fault consumer interface.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++ drivers/gpu/drm/xe/xe_pagefault_types.h | 125 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +9
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/**
drivers/gpu/drm/xe/xe_pagefault.c line 19
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +10
-0+* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with +* hardware or firmware to receive and parse faults into struct xe_pagefault, +* then forwards them to the consumer. The consumer layer services the faults +* (e.g., memory migration, page table updates) and acknowledges the result back +* to the producer, which then forwards the results to the hardware or firmware. +* The consumer uses a page fault queue sized to absorb all potential faults and +* a multi-threaded worker to process them. Multiple producers are supported, +* with a single shared consumer.
I am not through with the series yet but xe_pagefault seems to be the consumer code only, while the producer code will be located elsewhere such as in xe_guc*. If so, might be good to write it here or in the functions below.
Quoted 141 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +44
-0+*/ + +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ +/* TODO - implement */ +return 0 ; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on +* the GT. +*/ +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ +/* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to +* service it. Safe to be called from IRQ or process context. Reclaim safe. +* +* Return: 0 on success, errno on failure +*/ +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf) +{ +/* TODO - implement */ +return 0 ; +}drivers/gpu/drm/xe/xe_pagefault.h new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf); + +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +66
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_ +#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault; +struct xe_gt; + +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write access violation */ + XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */ + XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2, +}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** + * @ack_fault: Ack fault + * @pf: Page fault + * @err: Error state of fault + * + * Page fault producer receives acknowledgment from the consumer and + * sends the result to the HW/FW interface. + */ + void (*ack_fault)(struct xe_pagefault *pf, int err); +}; + +/** + * struct xe_pagefault - Xe page fault + * + * Generic page fault structure for communication between producer and consumer. + * Carefully sized to be 64 bytes. + */ +struct xe_pagefault { + /** + * @gt: GT of fault + * + * XXX: We may want to decouple the GT from individual faults, as it's + * unclear whether future platforms will always have a GT for all page + * fault producers. Internally, the GT is used for stats, identifying + * the appropriate VRAM region, and locating the migration queue. + * Leaving this as-is for now, but we can revisit later to see if we + * can convert it to use the Xe device pointer instead. + */ + struct xe_gt *gt; + /** + * @consumer: State for the software handling the fault. Populated by
drivers/gpu/drm/xe/xe_pagefault_types.h line 76
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+* the producer and may be modified by the consumer to communicate +* information back to the producer upon fault acknowledgment. +*/ +struct { +/** @consumer.page_addr: address of page fault */ +u64 page_addr; +/** @consumer.asid: address space ID */ +u32 asid; +/** @consumer.access_type: access type */ +u8 access_type;
For type safety we shoud use enum xe_pagefault_access_type instead of u8.
drivers/gpu/drm/xe/xe_pagefault_types.h line 78
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+/** @consumer.fault_type: fault type */ +u8 fault_type;
Same here with enum xe_pagefault_type instead of u8.
Quoted 11 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +11
-0+#define XE_PAGEFAULT_LEVEL_NACK 0xff/* Producer indicates nack fault */ +/** @consumer.fault_level: fault level */ +u8 fault_level; +/** @consumer.engine_class: engine class */ +u8 engine_class; +/** consumer.reserved: reserved bits for future expansion */ +u64 reserved; + } consumer; +/** +* @producer: State for the producer (i.e., HW/FW interface). Populated +* by the producer and should not be modified—or even inspected—by the
drivers/gpu/drm/xe/xe_pagefault_types.h line 99
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+* consumer, except for calling operations. +*/ +struct { +/** @producer.private: private pointer */ +void *private; +/** @producer.ops: operations */ +const struct xe_pagefault_ops *ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4 +/** +* producer.msg: page fault message, used by producer in fault
s/producer.msg/@producer.msg/
drivers/gpu/drm/xe/xe_pagefault_types.h line 100
Quoted 1 line
drivers/gpu/drm/xe/xe_pagefault_types.h new file +1
-0+* acknowledgement to formulate response to HW/FW interface.
s/acknowledgement/acknowledgment/
drivers/gpu/drm/xe/xe_pagefault_types.h line 102
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+*/ +u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW ];
It is clear from patch #6 why it is more convenient to have this in struct xe_pagefault rather than local to the producer but this seems to go a bit against the elegant abstraction provided by this new page fault layers. producer.private could store a struct with {guc,msg} but that is probably overengineering so up to you.
Francois
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +23
-0+ } producer; +}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { +/** +* @data: Data in queue containing struct xe_pagefault, protected by +* @lock +*/ +void *data; +/** @size: Size of queue in bytes */ +u32 size; +/** @head: Head pointer in bytes, moved by producer, protected by @lock */ +u32 head; +/** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */ +u32 tail; +/** @lock: protects page fault queue */ +spinlock_t lock; +/** @worker: to process page faults */ +struct work_struct worker; +}; + +#endif Signature · 1 line
2.34.1
Matthew Brost
maintainerRe: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 50 lines · Francois Dugast
Quoted 49 lines · Matthew Brost
Stub out the new page fault layer and add kernel documentation. This is intended as a replacement for the GT page fault layer, enabling multiple producers to hook into a shared page fault consumer interface.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++ drivers/gpu/drm/xe/xe_pagefault_types.h | 125 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +16
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with +* hardware or firmware to receive and parse faults into struct xe_pagefault, +* then forwards them to the consumer. The consumer layer services the faults +* (e.g., memory migration, page table updates) and acknowledges the result back +* to the producer, which then forwards the results to the hardware or firmware.
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault.c line 19
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +3
-0+* The consumer uses a page fault queue sized to absorb all potential faults and +* a multi-threaded worker to process them. Multiple producers are supported, +* with a single shared consumer. I am not through with the series yet but
xe_pagefaultseems to be the consumer code only, while the producer code will be located elsewhere such as in xe_guc*. If so, might be good to write it here or in the functions below.
I didn't want to mention the GuC specifically as it is intended to be generic. The GuC is a firmware, which is called out as potenial producers.
Quoted 154 lines
Quoted 141 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +44
-0+*/ + +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ +/* TODO - implement */ +return 0 ; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on +* the GT. +*/ +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ +/* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to +* service it. Safe to be called from IRQ or process context. Reclaim safe. +* +* Return: 0 on success, errno on failure +*/ +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf) +{ +/* TODO - implement */ +return 0 ; +}drivers/gpu/drm/xe/xe_pagefault.h new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf); + +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +66
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_ +#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault; +struct xe_gt; + +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write access violation */ + XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */ + XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2, +}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** + * @ack_fault: Ack fault + * @pf: Page fault + * @err: Error state of fault + * + * Page fault producer receives acknowledgment from the consumer and + * sends the result to the HW/FW interface. + */ + void (*ack_fault)(struct xe_pagefault *pf, int err); +}; + +/** + * struct xe_pagefault - Xe page fault + * + * Generic page fault structure for communication between producer and consumer. + * Carefully sized to be 64 bytes. + */ +struct xe_pagefault { + /** + * @gt: GT of fault + * + * XXX: We may want to decouple the GT from individual faults, as it's + * unclear whether future platforms will always have a GT for all page + * fault producers. Internally, the GT is used for stats, identifying + * the appropriate VRAM region, and locating the migration queue. + * Leaving this as-is for now, but we can revisit later to see if we + * can convert it to use the Xe device pointer instead. + */ + struct xe_gt *gt; + /** + * @consumer: State for the software handling the fault. Populated bydrivers/gpu/drm/xe/xe_pagefault_types.h line 76
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+* the producer and may be modified by the consumer to communicate +* information back to the producer upon fault acknowledgment. +*/ +struct { +/** @consumer.page_addr: address of page fault */ +u64 page_addr; +/** @consumer.asid: address space ID */ +u32 asid; +/** @consumer.access_type: access type */ +u8 access_type;For type safety we shoud use enum
xe_pagefault_access_typeinstead of u8.
Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 78
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+/** @consumer.fault_type: fault type */ +u8 fault_type;Same here with enum
xe_pagefault_typeinstead of u8.
This structure is carefully sized to 64 bytes. Unsure if using enums here will throw off that sizing. I'll check on this, but I suspect it will, if it does I think u8 is the correct choice.
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +15
-0+#define XE_PAGEFAULT_LEVEL_NACK 0xff/* Producer indicates nack fault */ +/** @consumer.fault_level: fault level */ +u8 fault_level; +/** @consumer.engine_class: engine class */ +u8 engine_class; +/** consumer.reserved: reserved bits for future expansion */ +u64 reserved; + } consumer; +/** +* @producer: State for the producer (i.e., HW/FW interface). Populated +* by the producer and should not be modified—or even inspected—by the +* consumer, except for calling operations. +*/ +struct { +/** @producer.private: private pointer */
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 99
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+void *private; +/** @producer.ops: operations */ +const struct xe_pagefault_ops *ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4 +/** +* producer.msg: page fault message, used by producer in fault s/producer.msg/@producer.msg/
+1
Quoted 4 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 100
Quoted 1 line
drivers/gpu/drm/xe/xe_pagefault_types.h new file +1
-0+* acknowledgement to formulate response to HW/FW interface. s/acknowledgement/acknowledgment/
+1
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 102
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+*/ +u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW ];It is clear from patch #6 why it is more convenient to have this in struct
xe_pagefaultrather than local to the producer but this seems to go a bit against the elegant abstraction provided by this new page fault layers. producer.private could store a struct with {guc,msg} but that is probably overengineering so up to you.
You can't malloc (with GFP_KERNEL) the producer path, at least for the GuC as we are either in softIRQ context or under the CT lock which is the path of reclaim. The only option is have these fields populated in the stack xe_pagefault structure in the producer which then is copied into a preallocated page fault queue, sized to sink all possible faults on the device, on the consumer size. I can add kernel doc explaining this.
Matt
Quoted 28 lines
Francois
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +23
-0+ } producer; +}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { +/** +* @data: Data in queue containing struct xe_pagefault, protected by +* @lock +*/ +void *data; +/** @size: Size of queue in bytes */ +u32 size; +/** @head: Head pointer in bytes, moved by producer, protected by @lock */ +u32 head; +/** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */ +u32 tail; +/** @lock: protects page fault queue */ +spinlock_t lock; +/** @worker: to process page faults */ +struct work_struct worker; +}; + +#endif Signature · 1 line
2.34.1
Re: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 61 lines · Matthew Brost
Quoted 50 lines · Francois Dugast
Quoted 49 lines · Matthew Brost
Stub out the new page fault layer and add kernel documentation. This is intended as a replacement for the GT page fault layer, enabling multiple producers to hook into a shared page fault consumer interface.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++ drivers/gpu/drm/xe/xe_pagefault_types.h | 125 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +16
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with +* hardware or firmware to receive and parse faults into struct xe_pagefault, +* then forwards them to the consumer. The consumer layer services the faults +* (e.g., memory migration, page table updates) and acknowledges the result back +* to the producer, which then forwards the results to the hardware or firmware. Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault.c line 19
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +3
-0+* The consumer uses a page fault queue sized to absorb all potential faults and +* a multi-threaded worker to process them. Multiple producers are supported, +* with a single shared consumer. I am not through with the series yet but
xe_pagefaultseems to be the consumer code only, while the producer code will be located elsewhere such as in xe_guc*. If so, might be good to write it here or in the functions below.
Quoted 3 lines
I didn't want to mention the GuC specifically as it is intended to be generic. The GuC is a firmware, which is called out as potenial producers.
Sure, sorry for the confusion, I did not mean to name the producer here but rather to add something like: "This file contains the consumer code." to link the doc and the functions below.
Quoted 209 lines
Quoted 155 lines
Quoted 142 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +44
-0+*/ + +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ +/* TODO - implement */ +return 0 ; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on +* the GT. +*/ +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ +/* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to +* service it. Safe to be called from IRQ or process context. Reclaim safe. +* +* Return: 0 on success, errno on failure +*/ +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf) +{ +/* TODO - implement */ +return 0 ; +}drivers/gpu/drm/xe/xe_pagefault.h new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf); + +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +66
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_ +#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault; +struct xe_gt; + +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write access violation */ + XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */ + XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2, +}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** + * @ack_fault: Ack fault + * @pf: Page fault + * @err: Error state of fault + * + * Page fault producer receives acknowledgment from the consumer and + * sends the result to the HW/FW interface. + */ + void (*ack_fault)(struct xe_pagefault *pf, int err); +}; + +/** + * struct xe_pagefault - Xe page fault + * + * Generic page fault structure for communication between producer and consumer. + * Carefully sized to be 64 bytes. + */ +struct xe_pagefault { + /** + * @gt: GT of fault + * + * XXX: We may want to decouple the GT from individual faults, as it's + * unclear whether future platforms will always have a GT for all page + * fault producers. Internally, the GT is used for stats, identifying + * the appropriate VRAM region, and locating the migration queue. + * Leaving this as-is for now, but we can revisit later to see if we + * can convert it to use the Xe device pointer instead. + */ + struct xe_gt *gt; + /** + * @consumer: State for the software handling the fault. Populated bydrivers/gpu/drm/xe/xe_pagefault_types.h line 76
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+* the producer and may be modified by the consumer to communicate +* information back to the producer upon fault acknowledgment. +*/ +struct { +/** @consumer.page_addr: address of page fault */ +u64 page_addr; +/** @consumer.asid: address space ID */ +u32 asid; +/** @consumer.access_type: access type */ +u8 access_type;For type safety we shoud use enum
xe_pagefault_access_typeinstead of u8.Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 78
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+/** @consumer.fault_type: fault type */ +u8 fault_type;Same here with enum
xe_pagefault_typeinstead of u8.This structure is carefully sized to 64 bytes. Unsure if using enums here will throw off that sizing. I'll check on this, but I suspect it will, if it does I think u8 is the correct choice.
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +15
-0+#define XE_PAGEFAULT_LEVEL_NACK 0xff/* Producer indicates nack fault */ +/** @consumer.fault_level: fault level */ +u8 fault_level; +/** @consumer.engine_class: engine class */ +u8 engine_class; +/** consumer.reserved: reserved bits for future expansion */ +u64 reserved; + } consumer; +/** +* @producer: State for the producer (i.e., HW/FW interface). Populated +* by the producer and should not be modified—or even inspected—by the +* consumer, except for calling operations. +*/ +struct { +/** @producer.private: private pointer */ Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 99
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+void *private; +/** @producer.ops: operations */ +const struct xe_pagefault_ops *ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4 +/** +* producer.msg: page fault message, used by producer in fault s/producer.msg/@producer.msg/
+1
Quoted 4 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 100
Quoted 1 line
drivers/gpu/drm/xe/xe_pagefault_types.h new file +1
-0+* acknowledgement to formulate response to HW/FW interface. s/acknowledgement/acknowledgment/
+1
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 102
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+*/ +u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW ];It is clear from patch #6 why it is more convenient to have this in struct
xe_pagefaultrather than local to the producer but this seems to go a bit against the elegant abstraction provided by this new page fault layers. producer.private could store a struct with {guc,msg} but that is probably overengineering so up to you.
Quoted 7 lines
You can't malloc (with
GFP_KERNEL) the producer path, at least for the GuC as we are either in softIRQ context or under the CT lock which is the path of reclaim. The only option is have these fields populated in the stackxe_pagefaultstructure in the producer which then is copied into a preallocated page fault queue, sized to sink all possible faults on the device, on the consumer size. I can add kernel doc explaining this.
Thanks for the explanation, would be helpful as kernel doc indeed.
Francois
Quoted 31 lines
Matt
Quoted 28 lines
Francois
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +23
-0+ } producer; +}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { +/** +* @data: Data in queue containing struct xe_pagefault, protected by +* @lock +*/ +void *data; +/** @size: Size of queue in bytes */ +u32 size; +/** @head: Head pointer in bytes, moved by producer, protected by @lock */ +u32 head; +/** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */ +u32 tail; +/** @lock: protects page fault queue */ +spinlock_t lock; +/** @worker: to process page faults */ +struct work_struct worker; +}; + +#endif Signature · 1 line
2.34.1
Matthew Brost
maintainerRe: [PATCH 01/11] drm/xe: Stub out new pagefault layer
Quoted 62 lines · Francois Dugast
Quoted 61 lines · Matthew Brost
Quoted 59 lines · Francois Dugast
Quoted 42 lines · Matthew Brost
Stub out the new page fault layer and add kernel documentation. This is intended as a replacement for the GT page fault layer, enabling multiple producers to hook into a shared page fault consumer interface.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++ drivers/gpu/drm/xe/xe_pagefault_types.h | 125 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +9
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** drivers/gpu/drm/xe/xe_pagefault.c line 19
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +10
-0+* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with +* hardware or firmware to receive and parse faults into struct xe_pagefault, +* then forwards them to the consumer. The consumer layer services the faults +* (e.g., memory migration, page table updates) and acknowledges the result back +* to the producer, which then forwards the results to the hardware or firmware. +* The consumer uses a page fault queue sized to absorb all potential faults and +* a multi-threaded worker to process them. Multiple producers are supported, +* with a single shared consumer. I am not through with the series yet but
xe_pagefaultseems to be the consumer code only, while the producer code will be located elsewhere such as in xe_guc*. If so, might be good to write it here or in the functions below.
Quoted 8 lines
Quoted 3 lines
I didn't want to mention the GuC specifically as it is intended to be generic. The GuC is a firmware, which is called out as potenial producers.
Sure, sorry for the confusion, I did not mean to name the producer here but rather to add something like: "This file contains the consumer code." to link the doc and the functions below.
Ah, yes. Will add.
Matt
Quoted 252 lines
Quoted 209 lines
Quoted 155 lines
Quoted 142 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +44
-0+*/ + +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ +/* TODO - implement */ +return 0 ; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on +* the GT. +*/ +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ +/* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to +* service it. Safe to be called from IRQ or process context. Reclaim safe. +* +* Return: 0 on success, errno on failure +*/ +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf) +{ +/* TODO - implement */ +return 0 ; +}drivers/gpu/drm/xe/xe_pagefault.h new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf); + +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +66
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_ +#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault; +struct xe_gt; + +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write access violation */ + XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */ + XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2, +}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** + * @ack_fault: Ack fault + * @pf: Page fault + * @err: Error state of fault + * + * Page fault producer receives acknowledgment from the consumer and + * sends the result to the HW/FW interface. + */ + void (*ack_fault)(struct xe_pagefault *pf, int err); +}; + +/** + * struct xe_pagefault - Xe page fault + * + * Generic page fault structure for communication between producer and consumer. + * Carefully sized to be 64 bytes. + */ +struct xe_pagefault { + /** + * @gt: GT of fault + * + * XXX: We may want to decouple the GT from individual faults, as it's + * unclear whether future platforms will always have a GT for all page + * fault producers. Internally, the GT is used for stats, identifying + * the appropriate VRAM region, and locating the migration queue. + * Leaving this as-is for now, but we can revisit later to see if we + * can convert it to use the Xe device pointer instead. + */ + struct xe_gt *gt; + /** + * @consumer: State for the software handling the fault. Populated bydrivers/gpu/drm/xe/xe_pagefault_types.h line 76
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+* the producer and may be modified by the consumer to communicate +* information back to the producer upon fault acknowledgment. +*/ +struct { +/** @consumer.page_addr: address of page fault */ +u64 page_addr; +/** @consumer.asid: address space ID */ +u32 asid; +/** @consumer.access_type: access type */ +u8 access_type;For type safety we shoud use enum
xe_pagefault_access_typeinstead of u8.Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 78
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+/** @consumer.fault_type: fault type */ +u8 fault_type;Same here with enum
xe_pagefault_typeinstead of u8.This structure is carefully sized to 64 bytes. Unsure if using enums here will throw off that sizing. I'll check on this, but I suspect it will, if it does I think u8 is the correct choice.
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +15
-0+#define XE_PAGEFAULT_LEVEL_NACK 0xff/* Producer indicates nack fault */ +/** @consumer.fault_level: fault level */ +u8 fault_level; +/** @consumer.engine_class: engine class */ +u8 engine_class; +/** consumer.reserved: reserved bits for future expansion */ +u64 reserved; + } consumer; +/** +* @producer: State for the producer (i.e., HW/FW interface). Populated +* by the producer and should not be modified—or even inspected—by the +* consumer, except for calling operations. +*/ +struct { +/** @producer.private: private pointer */ Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 99
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+void *private; +/** @producer.ops: operations */ +const struct xe_pagefault_ops *ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4 +/** +* producer.msg: page fault message, used by producer in fault s/producer.msg/@producer.msg/
+1
Quoted 4 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 100
Quoted 1 line
drivers/gpu/drm/xe/xe_pagefault_types.h new file +1
-0+* acknowledgement to formulate response to HW/FW interface. s/acknowledgement/acknowledgment/
+1
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 102
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+*/ +u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW ];It is clear from patch #6 why it is more convenient to have this in struct
xe_pagefaultrather than local to the producer but this seems to go a bit against the elegant abstraction provided by this new page fault layers. producer.private could store a struct with {guc,msg} but that is probably overengineering so up to you.Quoted 7 lines
You can't malloc (with
GFP_KERNEL) the producer path, at least for the GuC as we are either in softIRQ context or under the CT lock which is the path of reclaim. The only option is have these fields populated in the stackxe_pagefaultstructure in the producer which then is copied into a preallocated page fault queue, sized to sink all possible faults on the device, on the consumer size. I can add kernel doc explaining this.Thanks for the explanation, would be helpful as kernel doc indeed.
Francois
Quoted 31 lines
Matt
Quoted 28 lines
Francois
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +23
-0+ } producer; +}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { +/** +* @data: Data in queue containing struct xe_pagefault, protected by +* @lock +*/ +void *data; +/** @size: Size of queue in bytes */ +u32 size; +/** @head: Head pointer in bytes, moved by producer, protected by @lock */ +u32 head; +/** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */ +u32 tail; +/** @lock: protects page fault queue */ +spinlock_t lock; +/** @worker: to process page faults */ +struct work_struct worker; +}; + +#endif Signature · 1 line
2.34.1
Matthew Brost
maintainerRe: [PATCH 01/11] drm/xe: Stub out new pagefault layer
In reply to Matthew BrostQuoted 225 lines · Matthew Brost
Quoted 50 lines · Francois Dugast
Quoted 49 lines · Matthew Brost
Stub out the new page fault layer and add kernel documentation. This is intended as a replacement for the GT page fault layer, enabling multiple producers to hook into a shared page fault consumer interface.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++ drivers/gpu/drm/xe/xe_pagefault_types.h | 125 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_pagefault.h create mode 100644 drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +16
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with +* hardware or firmware to receive and parse faults into struct xe_pagefault, +* then forwards them to the consumer. The consumer layer services the faults +* (e.g., memory migration, page table updates) and acknowledges the result back +* to the producer, which then forwards the results to the hardware or firmware. Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault.c line 19
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +3
-0+* The consumer uses a page fault queue sized to absorb all potential faults and +* a multi-threaded worker to process them. Multiple producers are supported, +* with a single shared consumer. I am not through with the series yet but
xe_pagefaultseems to be the consumer code only, while the producer code will be located elsewhere such as in xe_guc*. If so, might be good to write it here or in the functions below.I didn't want to mention the GuC specifically as it is intended to be generic. The GuC is a firmware, which is called out as potenial producers.
Quoted 154 lines
Quoted 141 lines
drivers/gpu/drm/xe/xe_pagefault.c new file +44
-0+*/ + +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ +/* TODO - implement */ +return 0 ; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on +* the GT. +*/ +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ +/* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to +* service it. Safe to be called from IRQ or process context. Reclaim safe. +* +* Return: 0 on success, errno on failure +*/ +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf) +{ +/* TODO - implement */ +return 0 ; +}drivers/gpu/drm/xe/xe_pagefault.h new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf); + +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +66
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_ +#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault; +struct xe_gt; + +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write access violation */ + XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */ + XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2, +}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** + * @ack_fault: Ack fault + * @pf: Page fault + * @err: Error state of fault + * + * Page fault producer receives acknowledgment from the consumer and + * sends the result to the HW/FW interface. + */ + void (*ack_fault)(struct xe_pagefault *pf, int err); +}; + +/** + * struct xe_pagefault - Xe page fault + * + * Generic page fault structure for communication between producer and consumer. + * Carefully sized to be 64 bytes. + */ +struct xe_pagefault { + /** + * @gt: GT of fault + * + * XXX: We may want to decouple the GT from individual faults, as it's + * unclear whether future platforms will always have a GT for all page + * fault producers. Internally, the GT is used for stats, identifying + * the appropriate VRAM region, and locating the migration queue. + * Leaving this as-is for now, but we can revisit later to see if we + * can convert it to use the Xe device pointer instead. + */ + struct xe_gt *gt; + /** + * @consumer: State for the software handling the fault. Populated bydrivers/gpu/drm/xe/xe_pagefault_types.h line 76
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+* the producer and may be modified by the consumer to communicate +* information back to the producer upon fault acknowledgment. +*/ +struct { +/** @consumer.page_addr: address of page fault */ +u64 page_addr; +/** @consumer.asid: address space ID */ +u32 asid; +/** @consumer.access_type: access type */ +u8 access_type;For type safety we shoud use enum
xe_pagefault_access_typeinstead of u8.Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 78
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+/** @consumer.fault_type: fault type */ +u8 fault_type;Same here with enum
xe_pagefault_typeinstead of u8.
Quoted 4 lines
This structure is carefully sized to 64 bytes. Unsure if using enums here will throw off that sizing. I'll check on this, but I suspect it will, if it does I think u8 is the correct choice.
Using an enum increases the size of structure. The page fault queue aligns size to a pow2 so we go from 64 bytes to 128 bytes increasing page fault queue size. I can add a comment around this too.
Matt
Quoted 82 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +15
-0+#define XE_PAGEFAULT_LEVEL_NACK 0xff/* Producer indicates nack fault */ +/** @consumer.fault_level: fault level */ +u8 fault_level; +/** @consumer.engine_class: engine class */ +u8 engine_class; +/** consumer.reserved: reserved bits for future expansion */ +u64 reserved; + } consumer; +/** +* @producer: State for the producer (i.e., HW/FW interface). Populated +* by the producer and should not be modified—or even inspected—by the +* consumer, except for calling operations. +*/ +struct { +/** @producer.private: private pointer */ Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 99
Quoted 6 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+void *private; +/** @producer.ops: operations */ +const struct xe_pagefault_ops *ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4 +/** +* producer.msg: page fault message, used by producer in fault s/producer.msg/@producer.msg/
+1
Quoted 4 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 100
Quoted 1 line
drivers/gpu/drm/xe/xe_pagefault_types.h new file +1
-0+* acknowledgement to formulate response to HW/FW interface. s/acknowledgement/acknowledgment/
+1
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault_types.h line 102
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +2
-0+*/ +u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW ];It is clear from patch #6 why it is more convenient to have this in struct
xe_pagefaultrather than local to the producer but this seems to go a bit against the elegant abstraction provided by this new page fault layers. producer.private could store a struct with {guc,msg} but that is probably overengineering so up to you.You can't malloc (with
GFP_KERNEL) the producer path, at least for the GuC as we are either in softIRQ context or under the CT lock which is the path of reclaim. The only option is have these fields populated in the stackxe_pagefaultstructure in the producer which then is copied into a preallocated page fault queue, sized to sink all possible faults on the device, on the consumer size. I can add kernel doc explaining this.Matt
Quoted 28 lines
Francois
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault_types.h new file +23
-0+ } producer; +}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { +/** +* @data: Data in queue containing struct xe_pagefault, protected by +* @lock +*/ +void *data; +/** @size: Size of queue in bytes */ +u32 size; +/** @head: Head pointer in bytes, moved by producer, protected by @lock */ +u32 head; +/** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */ +u32 tail; +/** @lock: protects page fault queue */ +spinlock_t lock; +/** @worker: to process page faults */ +struct work_struct worker; +}; + +#endif Signature · 1 line
2.34.1
Re: [PATCH 01/11] drm/xe: Stub out new pagefault layer
In reply to Matthew BrostQuoted 199 lines · Matthew Brost
Stub out the new page fault layer and add kernel documentation. This is
intended as a replacement for the GT page fault layer, enabling multiple
producers to hook into a shared page fault consumer interface.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 63 ++++++++++++ drivers/gpu/drm/xe/xe_pagefault.h | 19 ++++drivers/gpu/drm/xe/xe_pagefault_types.h| 125
++++++++++++++++++++++++4 files changed, 208 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_pagefault.hcreate mode 100644drivers/gpu/drm/xe/xe_pagefault_types.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -93,6 +93,7 @@ xe-y += xe_bb.o \ xe_nvm.o \ xe_oa.o \ xe_observation.o \ + xe_pagefault.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_pagefault.c new file +12
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "xe_pagefault.h" +#include "xe_pagefault_types.h" + +/** +* DOC: Xe page faults +* +* Xe page faults are handled in two layers. The producer layer interacts with
+ * hardware or firmware to receive and parse faults into structxe_pagefault,
+ * then forwards them to the consumer. The consumer layer services the faults
+ * (e.g., memory migration, page table updates) and acknowledges the result back
+ * to the producer, which then forwards the results to the hardware or firmware.
+ * The consumer uses a page fault queue sized to absorb all potential faults and
+ * a multi-threaded worker to process them. Multiple producers are supported,
+ * with a single shared consumer.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +21
-0+ +/** +* xe_pagefault_init() - Page fault init +* @xe: xe device instance +* +* Initialize Xe page fault state. Must be done after reading fuses. +* +* Return: 0 on Success, errno on failure +*/ +int xe_pagefault_init (struct xe_device *xe) +{ + /* TODO - implement */ + return 0; +} + +/** +* xe_pagefault_reset() - Page fault reset for a GT +* @xe: xe device instance +* @gt: GT being reset +* +* Reset the Xe page fault state for a GT; that is, squash any pending faults on
+ * the GT.
+ */drivers/gpu/drm/xe/xe_pagefault.c new file +11
-0+void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) +{ + /* TODO - implement */ +} + +/** +* xe_pagefault_handler() - Page fault handler +* @xe: xe device instance +* @pf: Page fault +* +* Sink the page fault to a queue (i.e., a memory buffer) and queue a worker to
+ * service it. Safe to be called from IRQ or process context. Reclaim safe.
+ *
+ * Return: 0 on success, errno on failure
+ */
+intxe_pagefault_handler(struct xe_device *xe, struct xe_pagefault *pf)drivers/gpu/drm/xe/xe_pagefault.c new file +4
-0+{ + /* TODO - implement */ + return 0; +}drivers/gpu/drm/xe/xe_pagefault.h new file +17
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_H_ +#define _XE_PAGEFAULT_H_ + +struct xe_device ; +struct xe_gt ; +struct xe_pagefault ; + +int xe_pagefault_init (struct xe_device *xe); + +void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt); + +int xe_pagefault_handler(struct xe_device *xe, struct xe_pagefault*pf);
drivers/gpu/drm/xe/xe_pagefault.h new file +2
-0+ +#endif drivers/gpu/drm/xe/xe_pagefault_types.h new file +28
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_PAGEFAULT_TYPES_H_ +#define _XE_PAGEFAULT_TYPES_H_ + +#include <linux/workqueue.h> + +struct xe_pagefault; +struct xe_gt; + +/** enum xe_pagefault_access_type - Xe page fault access type */ +enum xe_pagefault_access_type { + /** @XE_PAGEFAULT_ACCESS_TYPE_READ: Read access type */ + XE_PAGEFAULT_ACCESS_TYPE_READ = 0, + /** @XE_PAGEFAULT_ACCESS_TYPE_WRITE: Write access type */ + XE_PAGEFAULT_ACCESS_TYPE_WRITE = 1, + /** @XE_PAGEFAULT_ACCESS_TYPE_ATOMIC: Atomic access type */ + XE_PAGEFAULT_ACCESS_TYPE_ATOMIC = 2, +}; + +/** enum xe_pagefault_type - Xe page fault type */ +enum xe_pagefault_type { + /** @XE_PAGEFAULT_TYPE_NOT_PRESENT: Not present */ + XE_PAGEFAULT_TYPE_NOT_PRESENT = 0, + /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Write accessviolation */
+ XE_PAGEFAULT_WRITE_ACCESS_VIOLATION = 1,
+ /** @XE_PAGEFAULT_TYPE_WRITE_ACCESS_VIOLATION: Atomic access violation */
+ XE_PAGEFAULT_ATOMIC_ACCESS_VIOLATION = 2,drivers/gpu/drm/xe/xe_pagefault_types.h new file +10
-0+}; + +/** struct xe_pagefault_ops - Xe pagefault ops (producer) */ +struct xe_pagefault_ops { + /** +* @ack_fault: Ack fault +* @pf: Page fault +* @err: Error state of fault +* +* Page fault producer receives acknowledgment from the consumer and
+ * sends the result to the HW/FW interface. + */
+ void (*ack_fault)(structxe_pagefault*pf, int err);drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** +* struct xe_pagefault - Xe page fault +* +* Generic page fault structure for communication between producer
Quoted 2 lines
and consumer.
+ * Carefully sized to be 64 bytes.
Can you expand this slightly to:
Carefully sized to be 64 bytes to align with hardware requests
Since this also came up later in the series in the enum discussion.
Quoted 37 lines
+ */
+structxe_pagefault{
+ /**
+ * @gt: GT of fault
+ *
+ * XXX: We may want to decouple the GT from individual faults, as it's
+ * unclear whether future platforms will always have a GT for all page
+ * fault producers. Internally, the GT is used for stats, identifying
+ * the appropriate VRAM region, and locating the migration queue.
+ * Leaving this as-is for now, but we can revisit later to see if we
+ * can convert it to use the Xe device pointer instead. + */
+ structxe_gt*gt;
+ /**
+ * @consumer: State for the software handling the fault. Populated by
+ * the producer and may be modified by the consumer to communicate
+ * information back to the producer upon fault acknowledgment.
+ */
+ struct {
+ /** @consumer.page_addr: address of page fault */ + u64page_addr;
+ /** @consumer.asid: address space ID */
+ u32 asid;
+ /** @consumer.access_type: access type */ + u8access_type;
+ /** @consumer.fault_type: fault type */
+ u8fault_type;
+#define XE_PAGEFAULT_LEVEL_NACK 0xff /* Producer indicates nack fault */
Quoted 8 lines
+ /** @consumer.fault_level: fault level */ + u8
fault_level;
+ /** @consumer.engine_class: engine class */ + u8engine_class;
+ /** consumer.reserved: reserved bits for future expansion */
+ u64 reserved;
+ } consumer;
Do we want this packed?
Thanks,
Stuart
Quoted 46 lines
+ /**
+ * @producer: State for the producer (i.e., HW/FW interface). Populated
+ * by the producer and should not be modified—or even inspected—by the
+ * consumer, except for calling operations.
+ */
+ struct {
+ /** @producer.private: private pointer */ + void *private;
+ /** @producer.ops: operations */
+ const structxe_pagefault_ops*ops; +#define XE_PAGEFAULT_PRODUCER_MSG_LEN_DW 4
+ /**
+ * producer.msg: page fault message, used by producer in fault
+ * acknowledgement to formulate response to HW/FW interface.
+ */
+ u32 msg[XE_PAGEFAULT_PRODUCER_MSG_LEN_DW]; + } producer;drivers/gpu/drm/xe/xe_pagefault_types.h new file +6
-0+}; + +/** struct xe_pagefault_queue: Xe pagefault queue (consumer) */ +struct xe_pagefault_queue { + /** +* @data: Data in queue containing struct xe_pagefault, protected by
+ * @lock
+ */
+ void *data;
+ /** @size: Size of queue in bytes */
+ u32 size;
+ /** @head: Head pointer in bytes, moved by producer, protected by @lock */
+ u32 head;
+ /** @tail: Tail pointer in bytes, moved by consumer, protected by @lock */
+ u32 tail;
+ /** @lock: protects page fault queue */
+ spinlock_t lock;
+ /** @worker: to process page faults */
+ structwork_structworker;drivers/gpu/drm/xe/xe_pagefault_types.h new file +3
-0+}; + +#endif
Matthew Brost
maintainerPATCH 2/11 drm/xe: Implement xe_pagefault_init
In reply to Matthew BrostCreate pagefault queues and initialize them.
--- drivers/gpu/drm/xe/xe_device.c | 5 ++ drivers/gpu/drm/xe/xe_device_types.h | 6 ++ drivers/gpu/drm/xe/xe_pagefault.c | 93 +++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_device.c +5 -0
@@ -50,6 +50,7 @@#include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h"
@@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe)if (err)return err; + err =xe_pagefault_init (xe); +if (err) +return err; +xe_nvm_init (xe); err =xe_heci_gsc_init (xe);
drivers/gpu/drm/xe/xe_device_types.h +6 -0
@@ -17,6 +17,7 @@#include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"
@@ -394,6 +395,11 @@ struct xe_device {u32 next_asid;/** @usm.lock: protects UM state */ struct rw_semaphore lock; +/** @usm.pf_wq: page fault work queue, unbound, high priority */ +struct workqueue_struct *pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4 +/** @pf_queue: Page fault queues */ +struct xe_pagefault_queue pf_queue[XE_PAGEFAULT_QUEUE_COUNT ]; } usm;/** @pinned: pinned BO state */
drivers/gpu/drm/xe/xe_pagefault.c +91 -2
111 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
Quoted 81 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 ++
drivers/gpu/drm/xe/xe_device_types.h | 6 ++
drivers/gpu/drm/xe/xe_pagefault.c | 93
+++++++++++++++++++++++++++-3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-0@@ -50,6 +50,7 @@ #include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h"@@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe) if (err) return err;
+ err =xe_pagefault_init(xe);
+ if (err)
+ return err;
+
xe_nvm_init(xe);
err =xe_heci_gsc_init(xe);drivers/gpu/drm/xe/xe_device_types.h +2
-0@@ -17,6 +17,7 @@ #include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"@@ -394,6 +395,11 @@ struct xe_device { u32 next_asid; /** @usm.lock: protects UM state */ struct rw_semaphore lock; + /** @usm.pf_wq: page fault work queue, unbound, highpriority */
+ structworkqueue_struct*pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4
+ /** @pf_queue: Page fault queues */ + structxe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_COUNT];
} usm;
/** @pinned: pinned BO state */drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -19,6 +23,71 @@* with a single shared consumer. */
drivers/gpu/drm/xe/xe_pagefault.c line 28
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c +3
-0+static int xe_pagefault_entry_size (void ) +{ + return roundup_pow_of_two(sizeof(struct xe_pagefault));
Nice thanks!
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault.c +9
-0+} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ + /* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, + struct xe_pagefault_queue
*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +11
-0+{ + struct xe_gt *gt; + int total_num_eus = 0; + u8 id; + + for_each_gt(gt, xe, id) { + xe_dss_mask_t all_dss; + int num_dss, num_eus; + + bitmap_or(all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,
XE_MAX_DSS_FUSE_BITS);
+
+ num_dss = bitmap_weight(all_dss,XE_MAX_DSS_FUSE_BITS);
+ num_eus = bitmap_weight(gt-
Quoted 5 lines
Quoted 1 line
fuse_topo.eu_mask_per_dss,
+ XE_MAX_EU_FUSE_BITS) *
num_dss;
+
+ total_num_eus +=num_eus;
I'm behind on that patch I had posted a while back to update this algorithm :(. Want to pull that calculation in here directly so we can remove the PF_MULTIPLIER you have below?
See https://patchwork.freedesktop.org/patch/651415/?series=148523&rev=1
I can also rework that on top of this if you'd prefer, either way is fine with me.
Thanks,
Stuart
Quoted 76 lines
+ }
drivers/gpu/drm/xe/xe_pagefault.c +7
-0+ + xe_assert(xe, total_num_eus); + + /* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors
+ * without it. Follow on why this multiplier is required. + */drivers/gpu/drm/xe/xe_pagefault.c +7
-0+#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus + XE_NUM_HW_ENGINES) * + xe_pagefault_entry_size() * PF_MULTIPLIER; + pf_queue->size = roundup_pow_of_two(pf_queue->size); +#undef PF_MULTIPLIER + + drm_dbg(&xe->drm, "xe_pagefault_entry_size=%d,total_num_eus=%d, pf_queue->size=%u",
+ xe_pagefault_entry_size(),total_num_eus, pf_queue-Quoted 1 line
size);
+
+ pf_queue->data =devm_kzalloc(xe->drm.dev, pf_queue->size, GFP_KERNEL);
+ if (!pf_queue->data)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + spin_lock_init(&pf_queue->lock); + INIT_WORK(&pf_queue->worker, xe_pagefault_queue_work); + + return 0; +} + +static void xe_pagefault_fini (void *arg) +{ + struct xe_device *xe = arg; + + destroy_workqueue(xe->usm.pf_wq); +} +/**
*xe_pagefault_init()- Page fault init
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +22
-2@@ -29,8 +98,28 @@*/ int xe_pagefault_init(struct xe_device *xe) { - /* TODO - implement */ - return 0; + int err, i; + + if (!xe->info.has_usm) + return 0; + + xe->usm.pf_wq = alloc_workqueue("xe_page_fault_work_queue", + WQ_UNBOUND | WQ_HIGHPRI, + XE_PAGEFAULT_QUEUE_COUNT); + if (!xe->usm.pf_wq) + return -ENOMEM; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) { + err = xe_pagefault_queue_init(xe, xe->usm.pf_queue + i); + if (err) + goto err_out; + } + + return devm_add_action_or_reset(xe->drm.dev, xe_pagefault_fini, xe); + +err_out: + destroy_workqueue(xe->usm.pf_wq); + return err; }
/**
Matthew Brost
maintainerRe: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
Quoted 120 lines · Stuart
Quoted 81 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 ++
drivers/gpu/drm/xe/xe_device_types.h | 6 ++
drivers/gpu/drm/xe/xe_pagefault.c | 93
+++++++++++++++++++++++++++-3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-0@@ -50,6 +50,7 @@ #include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h"@@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe) if (err) return err;
+ err =xe_pagefault_init(xe);
+ if (err)
+ return err;
+
xe_nvm_init(xe);
err =xe_heci_gsc_init(xe);drivers/gpu/drm/xe/xe_device_types.h +2
-0@@ -17,6 +17,7 @@ #include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"@@ -394,6 +395,11 @@ struct xe_device { u32 next_asid; /** @usm.lock: protects UM state */ struct rw_semaphore lock; + /** @usm.pf_wq: page fault work queue, unbound, highpriority */
+ structworkqueue_struct*pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4
+ /** @pf_queue: Page fault queues */ + structxe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_COUNT];
} usm;
/** @pinned: pinned BO state */drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -19,6 +23,71 @@* with a single shared consumer. */ drivers/gpu/drm/xe/xe_pagefault.c line 28
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c +3
-0+static int xe_pagefault_entry_size (void ) +{ + return roundup_pow_of_two(sizeof(struct xe_pagefault));Nice thanks!
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault.c +9
-0+} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ + /* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, + struct xe_pagefault_queue
*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +11
-0+{ + struct xe_gt *gt; + int total_num_eus = 0; + u8 id; + + for_each_gt(gt, xe, id) { + xe_dss_mask_t all_dss; + int num_dss, num_eus; + + bitmap_or(all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,
XE_MAX_DSS_FUSE_BITS);
+
+ num_dss = bitmap_weight(all_dss,XE_MAX_DSS_FUSE_BITS);
+ num_eus = bitmap_weight(gt-Quoted 5 lines
Quoted 1 line
fuse_topo.eu_mask_per_dss,
+ XE_MAX_EU_FUSE_BITS) *
num_dss;
+
+ total_num_eus +=num_eus;
Quoted 9 lines
I'm behind on that patch I had posted a while back to update this algorithm :(. Want to pull that calculation in here directly so we can remove the
PF_MULTIPLIERyou have below?See https://patchwork.freedesktop.org/patch/651415/?series=148523&rev=1
I can also rework that on top of this if you'd prefer, either way is fine with me.
Either way works for me. If you get this one in ahead of me, no issuing picking it up in a rebase or ofc if lands first you can post on top of this. If you are concerned about history, then the later might be better.
Matt
Quoted 80 lines
Thanks,
StuartQuoted 76 lines
+ }
drivers/gpu/drm/xe/xe_pagefault.c +7
-0+ + xe_assert(xe, total_num_eus); + + /* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors
+ * without it. Follow on why this multiplier is required. + */drivers/gpu/drm/xe/xe_pagefault.c +7
-0+#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus + XE_NUM_HW_ENGINES) * + xe_pagefault_entry_size() * PF_MULTIPLIER; + pf_queue->size = roundup_pow_of_two(pf_queue->size); +#undef PF_MULTIPLIER + + drm_dbg(&xe->drm, "xe_pagefault_entry_size=%d,total_num_eus=%d, pf_queue->size=%u",
+ xe_pagefault_entry_size(),total_num_eus, pf_queue-Quoted 1 line
size);
+
+ pf_queue->data =devm_kzalloc(xe->drm.dev, pf_queue->size, GFP_KERNEL);
+ if (!pf_queue->data)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + spin_lock_init(&pf_queue->lock); + INIT_WORK(&pf_queue->worker, xe_pagefault_queue_work); + + return 0; +} + +static void xe_pagefault_fini (void *arg) +{ + struct xe_device *xe = arg; + + destroy_workqueue(xe->usm.pf_wq); +} +/**
*xe_pagefault_init()- Page fault init
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +22
-2@@ -29,8 +98,28 @@*/ int xe_pagefault_init(struct xe_device *xe) { - /* TODO - implement */ - return 0; + int err, i; + + if (!xe->info.has_usm) + return 0; + + xe->usm.pf_wq = alloc_workqueue("xe_page_fault_work_queue", + WQ_UNBOUND | WQ_HIGHPRI, + XE_PAGEFAULT_QUEUE_COUNT); + if (!xe->usm.pf_wq) + return -ENOMEM; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) { + err = xe_pagefault_queue_init(xe, xe->usm.pf_queue + i); + if (err) + goto err_out; + } + + return devm_add_action_or_reset(xe->drm.dev, xe_pagefault_fini, xe); + +err_out: + destroy_workqueue(xe->usm.pf_wq); + return err; }
/**
Re: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
Quoted 135 lines · Matthew Brost
Quoted 126 lines · Stuart
Quoted 82 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 ++
drivers/gpu/drm/xe/xe_device_types.h | 6 ++
drivers/gpu/drm/xe/xe_pagefault.c | 93
+++++++++++++++++++++++++++-3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-0@@ -50,6 +50,7 @@ #include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h"@@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe) if (err) return err;
+ err =xe_pagefault_init(xe);
+ if (err)
+ return err;
+
xe_nvm_init(xe);
err =xe_heci_gsc_init(xe);drivers/gpu/drm/xe/xe_device_types.h +2
-0@@ -17,6 +17,7 @@ #include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"@@ -394,6 +395,11 @@ struct xe_device { u32 next_asid; /** @usm.lock: protects UM state */ struct rw_semaphore lock; + /** @usm.pf_wq: page fault work queue, unbound,high
priority */
+ structworkqueue_struct*pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4
+ /** @pf_queue: Page fault queues */ + structxe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_COUNT];
} usm;
/** @pinned: pinned BO state */drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -19,6 +23,71 @@* with a single shared consumer. */ drivers/gpu/drm/xe/xe_pagefault.c line 28
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c +3
-0+static int xe_pagefault_entry_size (void ) +{ + return roundup_pow_of_two(sizeof(struct xe_pagefault));Nice thanks!
Quoted 26 lines
drivers/gpu/drm/xe/xe_pagefault.c +9
-0+} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ + /* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, + struct xe_pagefault_queue
*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +11
-0+{ + struct xe_gt *gt; + int total_num_eus = 0; + u8 id; + + for_each_gt(gt, xe, id) { + xe_dss_mask_t all_dss; + int num_dss, num_eus; + + bitmap_or(all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,
XE_MAX_DSS_FUSE_BITS);
+
+ num_dss = bitmap_weight(all_dss,XE_MAX_DSS_FUSE_BITS);
+ num_eus = bitmap_weight(gt-Quoted 5 lines
Quoted 1 line
fuse_topo.eu_mask_per_dss,
+ XE_MAX_EU_FUSE_BITS) *
num_dss;
+
+ total_num_eus +=num_eus;I'm behind on that patch I had posted a while back to update this algorithm :(. Want to pull that calculation in here directly so we can
remove thePF_MULTIPLIERyou have below?Quoted 7 lines
See
https://patchwork.freedesktop.org/patch/651415/?series=148523&rev=1I can also rework that on top of this if you'd prefer, either way is
fine with me.
Quoted 6 lines
Either way works for me. If you get this one in ahead of me, no issuing
picking it up in a rebase or ofc if lands first you can post on top of
this. If you are concerned about history, then the later might be better.
Ok I'll hold off pushing mine back to the list until you're done. I was also suggesting you could just pull my changes into your patch if you wanted, although maybe that complicates what is mostly an internal interface update here with more functional-focused changes. But if you decide not to do that I'll just wait until yours land and pull it in on top.
Thanks,
Stuart
Quoted 88 lines
Matt
Quoted 85 lines
Thanks,
StuartQuoted 81 lines
+ }
drivers/gpu/drm/xe/xe_pagefault.c +7
-0+ + xe_assert(xe, total_num_eus); + + /* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors
+ * without it. Follow on why this multiplier is required. + */drivers/gpu/drm/xe/xe_pagefault.c +7
-0+#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus + XE_NUM_HW_ENGINES) * + xe_pagefault_entry_size() * PF_MULTIPLIER; + pf_queue->size = roundup_pow_of_two(pf_queue->size); +#undef PF_MULTIPLIER + + drm_dbg(&xe->drm, "xe_pagefault_entry_size=%d,total_num_eus=%d, pf_queue->size=%u",
+ xe_pagefault_entry_size(),total_num_eus, pf_queue-Quoted 1 line
size);
+
+ pf_queue->data = devm_kzalloc(xe->drm.dev, pf_queue-Quoted 1 line
size,
GFP_KERNEL);
+ if (!pf_queue->data)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + spin_lock_init(&pf_queue->lock); + INIT_WORK(&pf_queue->worker, xe_pagefault_queue_work); + + return 0; +} + +static void xe_pagefault_fini (void *arg) +{ + struct xe_device *xe = arg; + + destroy_workqueue(xe->usm.pf_wq); +} +/**
*xe_pagefault_init()- Page fault init
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +13
-2@@ -29,8 +98,28 @@*/ int xe_pagefault_init(struct xe_device *xe) { - /* TODO - implement */ - return 0; + int err, i; + + if (!xe->info.has_usm) + return 0; + + xe->usm.pf_wq =alloc_workqueue ("xe_page_fault_work_queue" , + WQ_UNBOUND | WQ_HIGHPRI, + XE_PAGEFAULT_QUEUE_COUNT) ; + if (!xe->usm.pf_wq) + return -ENOMEM; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) { + err = xe_pagefault_queue_init(xe, xe-Quoted 1 line
usm.pf_queue +
i);
+ if (err)
+ gotoerr_out;
+ }
+
+ returndevm_add_action_or_reset(xe->drm.dev, xe_pagefault_fini, xe);drivers/gpu/drm/xe/xe_pagefault.c +4
-0+ +err_out: + destroy_workqueue(xe->usm.pf_wq); + return err;}
/**
Re: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
In reply to Matthew BrostQuoted 45 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/xe_device.c | 5 ++ drivers/gpu/drm/xe/xe_device_types.h | 6 ++ drivers/gpu/drm/xe/xe_pagefault.c | 93 +++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +5
-0@@ -50,6 +50,7 @@#include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h" @@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe)if (err)return err; + err =xe_pagefault_init (xe); +if (err) +return err; +xe_nvm_init (xe); err =xe_heci_gsc_init (xe);drivers/gpu/drm/xe/xe_device_types.h +1
-0@@ -17,6 +17,7 @@#include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"
drivers/gpu/drm/xe/xe_device_types.h struct xe_device { · line 400
Quoted 6 lines
drivers/gpu/drm/xe/xe_device_types.h +3
-0@@ -394,6 +395,11 @@ struct xe_device {u32 next_asid;/** @usm.lock: protects UM state */ struct rw_semaphore lock; +/** @usm.pf_wq: page fault work queue, unbound, high priority */ +struct workqueue_struct *pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4
Could we add a comment why value is 4?
drivers/gpu/drm/xe/xe_device_types.h struct xe_device { · line 401
Quoted 1 line
drivers/gpu/drm/xe/xe_device_types.h +1
-0+/** @pf_queue: Page fault queues */
s/@pf_queue/@usm.pf_queue/
Rest LGTM.
Francois
Quoted 125 lines
drivers/gpu/drm/xe/xe_device_types.h +1
-0+struct xe_pagefault_queue pf_queue[XE_PAGEFAULT_QUEUE_COUNT ]; } usm;/** @pinned: pinned BO state */ drivers/gpu/drm/xe/xe_pagefault.c +91
-2@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ +#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "xe_pagefault.h" #include "xe_pagefault_types.h" @@ -19,6 +23,71 @@* with a single shared consumer. */ +static int xe_pagefault_entry_size (void ) +{ +return roundup_pow_of_two (sizeof (struct xe_pagefault )); +} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ +/* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, +struct xe_pagefault_queue *pf_queue) +{ +struct xe_gt *gt; +int total_num_eus =0 ; +u8 id; + +for_each_gt (gt, xe, id) { +xe_dss_mask_t all_dss; +int num_dss, num_eus; + +bitmap_or (all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,XE_MAX_DSS_FUSE_BITS ); + + num_dss =bitmap_weight (all_dss,XE_MAX_DSS_FUSE_BITS ); + num_eus =bitmap_weight (gt->fuse_topo.eu_mask_per_dss, +XE_MAX_EU_FUSE_BITS ) * num_dss; + + total_num_eus += num_eus; + } + +xe_assert (xe, total_num_eus); + +/* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors +* without it. Follow on why this multiplier is required. +*/ +#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus +XE_NUM_HW_ENGINES ) * +xe_pagefault_entry_size () *PF_MULTIPLIER ; + pf_queue->size =roundup_pow_of_two (pf_queue->size); +#undef PF_MULTIPLIER + +drm_dbg (&xe->drm,"xe_pagefault_entry_size=%d, total_num_eus=%d, pf_queue->size=%u" , +xe_pagefault_entry_size (), total_num_eus, pf_queue->size); + + pf_queue->data =devm_kzalloc (xe->drm.dev, pf_queue->size,GFP_KERNEL ); +if (!pf_queue->data) +return -ENOMEM ; + +spin_lock_init (&pf_queue->lock); +INIT_WORK (&pf_queue->worker, xe_pagefault_queue_work); + +return 0 ; +} + +static void xe_pagefault_fini (void *arg) +{ +struct xe_device *xe = arg; + +destroy_workqueue (xe->usm.pf_wq); +} +/** * xe_pagefault_init() - Page fault init * @xe: xe device instance @@ -29,8 +98,28 @@*/ int xe_pagefault_init (struct xe_device *xe) { -/* TODO - implement */ -return 0 ; +int err, i; + +if (!xe->info.has_usm) +return 0 ; + + xe->usm.pf_wq =alloc_workqueue ("xe_page_fault_work_queue" , +WQ_UNBOUND |WQ_HIGHPRI , +XE_PAGEFAULT_QUEUE_COUNT ); +if (!xe->usm.pf_wq) +return -ENOMEM ; + +for (i =0 ; i <XE_PAGEFAULT_QUEUE_COUNT ; ++i) { + err =xe_pagefault_queue_init (xe, xe->usm.pf_queue + i); +if (err) + goto err_out; + } + +return devm_add_action_or_reset (xe->drm.dev, xe_pagefault_fini, xe); + +err_out: +destroy_workqueue (xe->usm.pf_wq); +return err; }/** Signature · 1 line
2.34.1
Matthew Brost
maintainerRe: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
Quoted 46 lines · Francois Dugast
Quoted 45 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/xe_device.c | 5 ++ drivers/gpu/drm/xe/xe_device_types.h | 6 ++ drivers/gpu/drm/xe/xe_pagefault.c | 93 +++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +5
-0@@ -50,6 +50,7 @@#include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h" @@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe)if (err)return err; + err =xe_pagefault_init (xe); +if (err) +return err; +xe_nvm_init (xe); err =xe_heci_gsc_init (xe);drivers/gpu/drm/xe/xe_device_types.h +1
-0@@ -17,6 +17,7 @@#include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h" @@ -394,6 +395,11 @@ struct xe_device {
Quoted 9 lines
drivers/gpu/drm/xe/xe_device_types.h struct xe_device { · line 400
Quoted 6 lines
drivers/gpu/drm/xe/xe_device_types.h +3
-0u32 next_asid;/** @usm.lock: protects UM state */ struct rw_semaphore lock; +/** @usm.pf_wq: page fault work queue, unbound, high priority */ +struct workqueue_struct *pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4Could we add a comment why value is 4?
Sure. 4 was sweet spot for performance with the current implementation to get good bandwidth ultization on BMG. Once the THP device pages lands, this can be reduced to 2.
Matt
Quoted 133 lines
drivers/gpu/drm/xe/xe_device_types.h struct xe_device { · line 401
Quoted 1 line
drivers/gpu/drm/xe/xe_device_types.h +1
-0+/** @pf_queue: Page fault queues */ s/@pf_queue/@usm.pf_queue/
Rest LGTM.
Francois
Quoted 125 lines
drivers/gpu/drm/xe/xe_device_types.h +1
-0+struct xe_pagefault_queue pf_queue[XE_PAGEFAULT_QUEUE_COUNT ]; } usm;/** @pinned: pinned BO state */ drivers/gpu/drm/xe/xe_pagefault.c +91
-2@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ +#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "xe_pagefault.h" #include "xe_pagefault_types.h" @@ -19,6 +23,71 @@* with a single shared consumer. */ +static int xe_pagefault_entry_size (void ) +{ +return roundup_pow_of_two (sizeof (struct xe_pagefault )); +} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ +/* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, +struct xe_pagefault_queue *pf_queue) +{ +struct xe_gt *gt; +int total_num_eus =0 ; +u8 id; + +for_each_gt (gt, xe, id) { +xe_dss_mask_t all_dss; +int num_dss, num_eus; + +bitmap_or (all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,XE_MAX_DSS_FUSE_BITS ); + + num_dss =bitmap_weight (all_dss,XE_MAX_DSS_FUSE_BITS ); + num_eus =bitmap_weight (gt->fuse_topo.eu_mask_per_dss, +XE_MAX_EU_FUSE_BITS ) * num_dss; + + total_num_eus += num_eus; + } + +xe_assert (xe, total_num_eus); + +/* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors +* without it. Follow on why this multiplier is required. +*/ +#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus +XE_NUM_HW_ENGINES ) * +xe_pagefault_entry_size () *PF_MULTIPLIER ; + pf_queue->size =roundup_pow_of_two (pf_queue->size); +#undef PF_MULTIPLIER + +drm_dbg (&xe->drm,"xe_pagefault_entry_size=%d, total_num_eus=%d, pf_queue->size=%u" , +xe_pagefault_entry_size (), total_num_eus, pf_queue->size); + + pf_queue->data =devm_kzalloc (xe->drm.dev, pf_queue->size,GFP_KERNEL ); +if (!pf_queue->data) +return -ENOMEM ; + +spin_lock_init (&pf_queue->lock); +INIT_WORK (&pf_queue->worker, xe_pagefault_queue_work); + +return 0 ; +} + +static void xe_pagefault_fini (void *arg) +{ +struct xe_device *xe = arg; + +destroy_workqueue (xe->usm.pf_wq); +} +/** * xe_pagefault_init() - Page fault init * @xe: xe device instance @@ -29,8 +98,28 @@*/ int xe_pagefault_init (struct xe_device *xe) { -/* TODO - implement */ -return 0 ; +int err, i; + +if (!xe->info.has_usm) +return 0 ; + + xe->usm.pf_wq =alloc_workqueue ("xe_page_fault_work_queue" , +WQ_UNBOUND |WQ_HIGHPRI , +XE_PAGEFAULT_QUEUE_COUNT ); +if (!xe->usm.pf_wq) +return -ENOMEM ; + +for (i =0 ; i <XE_PAGEFAULT_QUEUE_COUNT ; ++i) { + err =xe_pagefault_queue_init (xe, xe->usm.pf_queue + i); +if (err) + goto err_out; + } + +return devm_add_action_or_reset (xe->drm.dev, xe_pagefault_fini, xe); + +err_out: +destroy_workqueue (xe->usm.pf_wq); +return err; }/** Signature · 1 line
2.34.1
Re: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
In reply to Matthew BrostQuoted 81 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 ++
drivers/gpu/drm/xe/xe_device_types.h | 6 ++
drivers/gpu/drm/xe/xe_pagefault.c | 93
+++++++++++++++++++++++++++-3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-0@@ -50,6 +50,7 @@ #include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h"@@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe) if (err) return err;
+ err =xe_pagefault_init(xe);
+ if (err)
+ return err;
+
xe_nvm_init(xe);
err =xe_heci_gsc_init(xe);drivers/gpu/drm/xe/xe_device_types.h +2
-0@@ -17,6 +17,7 @@ #include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"@@ -394,6 +395,11 @@ struct xe_device { u32 next_asid; /** @usm.lock: protects UM state */ struct rw_semaphore lock; + /** @usm.pf_wq: page fault work queue, unbound, highpriority */
+ structworkqueue_struct*pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4
+ /** @pf_queue: Page fault queues */ + structxe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_COUNT];
} usm;
/** @pinned: pinned BO state */drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -19,6 +23,71 @@* with a single shared consumer. */
drivers/gpu/drm/xe/xe_pagefault.c line 28
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c +3
-0+static int xe_pagefault_entry_size (void ) +{ + return roundup_pow_of_two(sizeof(struct xe_pagefault));
And here, it would be nice if you could add a brief comment that this assumes the size of struct xe_pagefault aligns to the hardware requirements.
Thanks,
Stuart
Quoted 107 lines
drivers/gpu/drm/xe/xe_pagefault.c +9
-0+} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ + /* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, + struct xe_pagefault_queue
*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +11
-0+{ + struct xe_gt *gt; + int total_num_eus = 0; + u8 id; + + for_each_gt(gt, xe, id) { + xe_dss_mask_t all_dss; + int num_dss, num_eus; + + bitmap_or(all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,
XE_MAX_DSS_FUSE_BITS);
+
+ num_dss = bitmap_weight(all_dss,XE_MAX_DSS_FUSE_BITS);
+ num_eus = bitmap_weight(gt-Quoted 1 line
fuse_topo.eu_mask_per_dss,
+ XE_MAX_EU_FUSE_BITS) *
num_dss;drivers/gpu/drm/xe/xe_pagefault.c +10
-0+ + total_num_eus += num_eus; + } + + xe_assert(xe, total_num_eus); + + /* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors
+ * without it. Follow on why this multiplier is required. + */drivers/gpu/drm/xe/xe_pagefault.c +7
-0+#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus + XE_NUM_HW_ENGINES) * + xe_pagefault_entry_size() * PF_MULTIPLIER; + pf_queue->size = roundup_pow_of_two(pf_queue->size); +#undef PF_MULTIPLIER + + drm_dbg(&xe->drm, "xe_pagefault_entry_size=%d,total_num_eus=%d, pf_queue->size=%u",
+ xe_pagefault_entry_size(),total_num_eus, pf_queue-Quoted 1 line
size);
+
+ pf_queue->data =devm_kzalloc(xe->drm.dev, pf_queue->size, GFP_KERNEL);
+ if (!pf_queue->data)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + spin_lock_init(&pf_queue->lock); + INIT_WORK(&pf_queue->worker, xe_pagefault_queue_work); + + return 0; +} + +static void xe_pagefault_fini (void *arg) +{ + struct xe_device *xe = arg; + + destroy_workqueue(xe->usm.pf_wq); +} +/**
*xe_pagefault_init()- Page fault init
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +22
-2@@ -29,8 +98,28 @@*/ int xe_pagefault_init(struct xe_device *xe) { - /* TODO - implement */ - return 0; + int err, i; + + if (!xe->info.has_usm) + return 0; + + xe->usm.pf_wq = alloc_workqueue("xe_page_fault_work_queue", + WQ_UNBOUND | WQ_HIGHPRI, + XE_PAGEFAULT_QUEUE_COUNT); + if (!xe->usm.pf_wq) + return -ENOMEM; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) { + err = xe_pagefault_queue_init(xe, xe->usm.pf_queue + i); + if (err) + goto err_out; + } + + return devm_add_action_or_reset(xe->drm.dev, xe_pagefault_fini, xe); + +err_out: + destroy_workqueue(xe->usm.pf_wq); + return err; }
/**
Matthew Brost
maintainerRe: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
Quoted 81 lines · Stuart
Quoted 80 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 ++
drivers/gpu/drm/xe/xe_device_types.h | 6 ++
drivers/gpu/drm/xe/xe_pagefault.c | 93
+++++++++++++++++++++++++++-3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-0@@ -50,6 +50,7 @@ #include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h"@@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe) if (err) return err;
+ err =xe_pagefault_init(xe);
+ if (err)
+ return err;
+
xe_nvm_init(xe);
err =xe_heci_gsc_init(xe);drivers/gpu/drm/xe/xe_device_types.h +2
-0@@ -17,6 +17,7 @@ #include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"@@ -394,6 +395,11 @@ struct xe_device { u32 next_asid; /** @usm.lock: protects UM state */ struct rw_semaphore lock; + /** @usm.pf_wq: page fault work queue, unbound, highpriority */
+ structworkqueue_struct*pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4
+ /** @pf_queue: Page fault queues */ + structxe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_COUNT];
} usm;
/** @pinned: pinned BO state */drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -19,6 +23,71 @@* with a single shared consumer. */
Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault.c line 28
Quoted 4 lines
drivers/gpu/drm/xe/xe_pagefault.c +3
-0+static int xe_pagefault_entry_size (void ) +{ + return roundup_pow_of_two(sizeof(struct xe_pagefault));And here, it would be nice if you could add a brief comment that this assumes the size of struct
xe_pagefaultaligns to the hardware requirements.
It is actually not a hardware thing, it the pagefault queue management code (software) where the logic breaks if we are not doing everything on pow2 boundaries. Ofc, this isn't a strick requirement, rather it just makes the code simplier.
I can add a comment around this.
Matt
Quoted 111 lines
Thanks,
StuartQuoted 107 lines
drivers/gpu/drm/xe/xe_pagefault.c +9
-0+} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ + /* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, + struct xe_pagefault_queue
*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +11
-0+{ + struct xe_gt *gt; + int total_num_eus = 0; + u8 id; + + for_each_gt(gt, xe, id) { + xe_dss_mask_t all_dss; + int num_dss, num_eus; + + bitmap_or(all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,
XE_MAX_DSS_FUSE_BITS);
+
+ num_dss = bitmap_weight(all_dss,XE_MAX_DSS_FUSE_BITS);
+ num_eus = bitmap_weight(gt-Quoted 1 line
fuse_topo.eu_mask_per_dss,
+ XE_MAX_EU_FUSE_BITS) *
num_dss;drivers/gpu/drm/xe/xe_pagefault.c +10
-0+ + total_num_eus += num_eus; + } + + xe_assert(xe, total_num_eus); + + /* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors
+ * without it. Follow on why this multiplier is required. + */drivers/gpu/drm/xe/xe_pagefault.c +7
-0+#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus + XE_NUM_HW_ENGINES) * + xe_pagefault_entry_size() * PF_MULTIPLIER; + pf_queue->size = roundup_pow_of_two(pf_queue->size); +#undef PF_MULTIPLIER + + drm_dbg(&xe->drm, "xe_pagefault_entry_size=%d,total_num_eus=%d, pf_queue->size=%u",
+ xe_pagefault_entry_size(),total_num_eus, pf_queue-Quoted 1 line
size);
+
+ pf_queue->data =devm_kzalloc(xe->drm.dev, pf_queue->size, GFP_KERNEL);
+ if (!pf_queue->data)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + spin_lock_init(&pf_queue->lock); + INIT_WORK(&pf_queue->worker, xe_pagefault_queue_work); + + return 0; +} + +static void xe_pagefault_fini (void *arg) +{ + struct xe_device *xe = arg; + + destroy_workqueue(xe->usm.pf_wq); +} +/**
*xe_pagefault_init()- Page fault init
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +22
-2@@ -29,8 +98,28 @@*/ int xe_pagefault_init(struct xe_device *xe) { - /* TODO - implement */ - return 0; + int err, i; + + if (!xe->info.has_usm) + return 0; + + xe->usm.pf_wq = alloc_workqueue("xe_page_fault_work_queue", + WQ_UNBOUND | WQ_HIGHPRI, + XE_PAGEFAULT_QUEUE_COUNT); + if (!xe->usm.pf_wq) + return -ENOMEM; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) { + err = xe_pagefault_queue_init(xe, xe->usm.pf_queue + i); + if (err) + goto err_out; + } + + return devm_add_action_or_reset(xe->drm.dev, xe_pagefault_fini, xe); + +err_out: + destroy_workqueue(xe->usm.pf_wq); + return err; }
/**
Re: [PATCH 02/11] drm/xe: Implement xe_pagefault_init
Quoted 94 lines · Matthew Brost
Quoted 83 lines · Stuart
Quoted 82 lines · Matthew Brost
Create pagefault queues and initialize them.
Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 ++
drivers/gpu/drm/xe/xe_device_types.h | 6 ++
drivers/gpu/drm/xe/xe_pagefault.c | 93
+++++++++++++++++++++++++++-3 files changed, 102 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-0@@ -50,6 +50,7 @@ #include "xe_nvm.h" #include "xe_oa.h" #include "xe_observation.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pcode.h" #include "xe_pm.h"@@ -890,6 +891,10 @@ int xe_device_probe(struct xe_device *xe) if (err) return err;
+ err =xe_pagefault_init(xe);
+ if (err)
+ return err;
+
xe_nvm_init(xe);
err =xe_heci_gsc_init(xe);drivers/gpu/drm/xe/xe_device_types.h +2
-0@@ -17,6 +17,7 @@ #include "xe_lmtt_types.h" #include "xe_memirq_types.h" #include "xe_oa_types.h" +#include "xe_pagefault_types.h" #include "xe_platform_types.h" #include "xe_pmu_types.h" #include "xe_pt_types.h"@@ -394,6 +395,11 @@ struct xe_device { u32 next_asid; /** @usm.lock: protects UM state */ struct rw_semaphore lock; + /** @usm.pf_wq: page fault work queue, unbound,high
priority */
+ structworkqueue_struct*pf_wq; +#define XE_PAGEFAULT_QUEUE_COUNT 4
+ /** @pf_queue: Page fault queues */ + structxe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_COUNT];
} usm;
/** @pinned: pinned BO state */drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -3,6 +3,10 @@* Copyright © 2025 Intel Corporation */ drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include <drm/drm_managed.h> + +#include "xe_device.h" +#include "xe_gt_types.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -19,6 +23,71 @@* with a single shared consumer. */ Quoted 9 lines
drivers/gpu/drm/xe/xe_pagefault.c line 28
Quoted 3 lines
drivers/gpu/drm/xe/xe_pagefault.c +3
-0+static int xe_pagefault_entry_size (void ) +{ + return roundup_pow_of_two(sizeof(struct xe_pagefault));And here, it would be nice if you could add a brief comment that this
assumes the size of structxe_pagefaultaligns to the hardware requirements.
Quoted 8 lines
It is actually not a hardware thing, it the pagefault queue management
code (software) where the logic breaks if we are not doing everything on
pow2 boundaries. Ofc, this isn't a strick requirement, rather it just makes the code simplier.I can add a comment around this.
Ok got it. Yeah that would be helpful here I agree.
Thanks,
Stuart
Quoted 119 lines
Matt
Quoted 116 lines
Thanks,
StuartQuoted 112 lines
drivers/gpu/drm/xe/xe_pagefault.c +9
-0+} + +static void xe_pagefault_queue_work (struct work_struct *w) +{ + /* TODO: Implement */ +} + +static int xe_pagefault_queue_init (struct xe_device *xe, + struct xe_pagefault_queue
*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +11
-0+{ + struct xe_gt *gt; + int total_num_eus = 0; + u8 id; + + for_each_gt(gt, xe, id) { + xe_dss_mask_t all_dss; + int num_dss, num_eus; + + bitmap_or(all_dss, gt->fuse_topo.g_dss_mask, + gt->fuse_topo.c_dss_mask,
XE_MAX_DSS_FUSE_BITS);
+
+ num_dss = bitmap_weight(all_dss,XE_MAX_DSS_FUSE_BITS);
+ num_eus = bitmap_weight(gt-Quoted 1 line
fuse_topo.eu_mask_per_dss,
+ XE_MAX_EU_FUSE_BITS) *
num_dss;drivers/gpu/drm/xe/xe_pagefault.c +10
-0+ + total_num_eus += num_eus; + } + + xe_assert(xe, total_num_eus); + + /* +* user can issue separate page faults per EU and per CS +* +* XXX: Multiplier required as compute UMD are getting PF queue errors
+ * without it. Follow on why this multiplier is required. + */drivers/gpu/drm/xe/xe_pagefault.c +7
-0+#define PF_MULTIPLIER 8 + pf_queue->size = (total_num_eus + XE_NUM_HW_ENGINES) * + xe_pagefault_entry_size() * PF_MULTIPLIER; + pf_queue->size = roundup_pow_of_two(pf_queue->size); +#undef PF_MULTIPLIER + + drm_dbg(&xe->drm, "xe_pagefault_entry_size=%d,total_num_eus=%d, pf_queue->size=%u",
+ xe_pagefault_entry_size(),total_num_eus, pf_queue-Quoted 1 line
size);
+
+ pf_queue->data = devm_kzalloc(xe->drm.dev, pf_queue-Quoted 1 line
size,
GFP_KERNEL);
+ if (!pf_queue->data)
+ return-ENOMEM;drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + spin_lock_init(&pf_queue->lock); + INIT_WORK(&pf_queue->worker, xe_pagefault_queue_work); + + return 0; +} + +static void xe_pagefault_fini (void *arg) +{ + struct xe_device *xe = arg; + + destroy_workqueue(xe->usm.pf_wq); +} +/**
*xe_pagefault_init()- Page fault init
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +13
-2@@ -29,8 +98,28 @@*/ int xe_pagefault_init(struct xe_device *xe) { - /* TODO - implement */ - return 0; + int err, i; + + if (!xe->info.has_usm) + return 0; + + xe->usm.pf_wq =alloc_workqueue ("xe_page_fault_work_queue" , + WQ_UNBOUND | WQ_HIGHPRI, + XE_PAGEFAULT_QUEUE_COUNT) ; + if (!xe->usm.pf_wq) + return -ENOMEM; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) { + err = xe_pagefault_queue_init(xe, xe-Quoted 1 line
usm.pf_queue +
i);
+ if (err)
+ gotoerr_out;
+ }
+
+ returndevm_add_action_or_reset(xe->drm.dev, xe_pagefault_fini, xe);drivers/gpu/drm/xe/xe_pagefault.c +4
-0+ +err_out: + destroy_workqueue(xe->usm.pf_wq); + return err;}
/**
Matthew Brost
maintainerPATCH 3/11 drm/xe: Implement xe_pagefault_reset
In reply to Matthew BrostSquash any pending faults on the GT being reset by setting the GT field in struct xe_pagefault to NULL.
--- drivers/gpu/drm/xe/xe_gt.c | 2 ++ drivers/gpu/drm/xe/xe_pagefault.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt.c +2 -0
@@ -50,6 +50,7 @@#include "xe_map.h" #include "xe_migrate.h" #include "xe_mmio.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pm.h" #include "xe_mocs.h"
@@ -846,6 +847,7 @@ static int gt_reset(struct xe_gt *gt)xe_uc_gucrc_disable (>->uc);xe_uc_stop_prepare (>->uc); +xe_pagefault_reset (gt_to_xe (gt), gt);xe_gt_pagefault_reset (gt);xe_uc_stop (>->uc);
drivers/gpu/drm/xe/xe_pagefault.c +22 -1
@@ -122,6 +122,24 @@ int xe_pagefault_init(struct xe_device *xe)return err; } +static void xe_pagefault_queue_reset (struct xe_device *xe,struct xe_gt *gt, +struct xe_pagefault_queue *pf_queue) +{ +u32 i; + +/* Squash all pending faults on the GT */ + +spin_lock_irq (&pf_queue->lock); +for (i = pf_queue->tail; i != pf_queue->head; + i = (i +xe_pagefault_entry_size ()) % pf_queue->size) { +struct xe_pagefault *pf = pf_queue->data + i; + +if (pf->gt == gt) + pf->gt =NULL ; + } +spin_unlock_irq (&pf_queue->lock); +} +/** * xe_pagefault_reset() - Page fault reset for a GT * @xe: xe device instance
@@ -132,7 +150,10 @@ int xe_pagefault_init(struct xe_device *xe)*/ void xe_pagefault_reset (struct xe_device *xe,struct xe_gt *gt) { -/* TODO - implement */ +int i; + +for (i =0 ; i <XE_PAGEFAULT_QUEUE_COUNT ; ++i) +xe_pagefault_queue_reset (xe, gt, xe->usm.pf_queue + i); }/**
Signature · 1 line
2.34.1
Re: [PATCH 03/11] drm/xe: Implement xe_pagefault_reset
Quoted 23 lines · Matthew Brost
Squash any pending faults on the GT being reset by setting the GT field
in structxe_pagefaultto NULL.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_gt.c | 2 ++drivers/gpu/drm/xe/xe_pagefault.c| 23 ++++++++++++++++++++++-2 files changed, 24 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_gt.c +1
-0@@ -50,6 +50,7 @@ #include "xe_map.h" #include "xe_migrate.h" #include "xe_mmio.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pm.h" #include "xe_mocs.h"@@ -846,6 +847,7 @@ static int gt_reset(struct xe_gt *gt)
Quoted 4 lines
xe_uc_gucrc_disable(>->uc);
xe_uc_stop_prepare(>->uc);
+ xe_pagefault_reset(gt_to_xe(gt), gt);
Can we just pass the GT in here and then extrapolate xe from there? I realize you're thinking of dropping the GT piece, but maybe we can change the parameters around at that time. Just feels weird passing these both in at this point.
Quoted 16 lines
xe_gt_pagefault_reset(gt);
xe_uc_stop(>->uc);drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -122,6 +122,24 @@ int xe_pagefault_init(struct xe_device *xe) return err; }
+static void xe_pagefault_queue_reset(structxe_device*xe, structxe_gt*gt,
+ structxe_pagefault_queue*pf_queue)
drivers/gpu/drm/xe/xe_pagefault.c int xe_pagefault_init(struct xe_device *xe) · line 134
Quoted 8 lines
drivers/gpu/drm/xe/xe_pagefault.c +8
-0+{ + u32 i; + + /* Squash all pending faults on the GT */ + + spin_lock_irq(&pf_queue->lock); + for (i = pf_queue->tail; i != pf_queue->head; + i = (i + xe_pagefault_entry_size()) % pf_queue->size) {
Should we add a check in here that pf_queue->head is some multiple of xe_pagefault_entry_size and pf_queue->size is aligned to xe_pagefault_entry_size()?
Quoted 4 lines
+ struct
xe_pagefault*pf =pf_queue->data+ i; +
+ if (pf->gt== gt)
+ pf->gt = NULL;
Not sure I fully get the intent here... so we loop back around from TAIL to HEAD and clear all of the GTs in pf_queue->data for each one? Is the expectation that each entry in the pf_queue has the same GT or is NULL? And then setting to NULL is a way we can abstract out the GT?
Still getting through the series, so appologize if this is also answered later in the series...
Thanks,
Stuart
Quoted 20 lines
+ }
+ spin_unlock_irq(&pf_queue->lock);drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +/**
*xe_pagefault_reset()- Page fault reset for a GT
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +4
-1@@ -132,7 +150,10 @@ int xe_pagefault_init(struct xe_device *xe)*/ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt) { - /* TODO - implement */ + int i; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) + xe_pagefault_queue_reset(xe, gt, xe->usm.pf_queue + i); }
/**
Matthew Brost
maintainerRe: [PATCH 03/11] drm/xe: Implement xe_pagefault_reset
Quoted 25 lines · Stuart
Quoted 24 lines · Matthew Brost
Squash any pending faults on the GT being reset by setting the GT field
in structxe_pagefaultto NULL.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_gt.c | 2 ++drivers/gpu/drm/xe/xe_pagefault.c| 23 ++++++++++++++++++++++-2 files changed, 24 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_gt.c +1
-0@@ -50,6 +50,7 @@ #include "xe_map.h" #include "xe_migrate.h" #include "xe_mmio.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pm.h" #include "xe_mocs.h"@@ -846,6 +847,7 @@ static int gt_reset(struct xe_gt *gt)
Quoted 9 lines
Quoted 3 lines
xe_uc_gucrc_disable(>->uc);
xe_uc_stop_prepare(>->uc);
+ xe_pagefault_reset(gt_to_xe(gt), gt);Can we just pass the GT in here and then extrapolate xe from there? I realize you're thinking of dropping the GT piece, but maybe we can change the parameters around at that time. Just feels weird passing these both in at this point.
I think the style is generally layer accepts the main argument first exported function. ofc we don't actually do that everywhere in Xe though. Here the main argument for the layer 'xe'.
Can drop if you prefer, I don't really have strong opinion.
Quoted 20 lines
Quoted 20 lines
xe_gt_pagefault_reset(gt);
xe_uc_stop(>->uc);drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -122,6 +122,24 @@ int xe_pagefault_init(struct xe_device *xe) return err; }
+static void xe_pagefault_queue_reset(structxe_device*xe, structxe_gt*gt,
+ structxe_pagefault_queue*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +4
-0+{ + u32 i; + + /* Squash all pending faults on the GT */
Quoted 9 lines
Quoted 4 lines
+
+ spin_lock_irq(&pf_queue->lock);
+ for (i =pf_queue->tail; i !=pf_queue->head;
+ i = (i +xe_pagefault_entry_size()) %pf_queue->size) {Should we add a check in here that
pf_queue->headis some multiple ofxe_pagefault_entry_sizeandpf_queue->sizeis aligned toxe_pagefault_entry_size()?
We can add some asserts, still would get an infinite loop but at least CI we catch a bug quickly we introduced somewhere.
Quoted 10 lines
Quoted 4 lines
+ struct
xe_pagefault*pf =pf_queue->data+ i; +
+ if (pf->gt== gt)
+ pf->gt = NULL;Not sure I fully get the intent here... so we loop back around from TAIL to HEAD and clear all of the GTs in
pf_queue->datafor each one? Is the expectation that each entry in thepf_queuehas the same GT or is NULL? And then setting to NULL is a way we can abstract out the GT?
This patch [1] moves the page faults queue from the GT to the device as having a thread pool per GT makes little sense - want our thread pool to be per device and enough threads to hit CPU<->GPU peak bus bandwidth in what we'd expect to be common prefetch / page faults cases (e.g., 2M SVM migrations).
When the fault queues were per GT, reset were easy, just reset all the queues on the GT but now sense they are shared on the device and individual GTs can reset, we squash all faults on the GT by setting the GT to NULL. This patch [2] ignores any fault with a NULL GT in the function xe_pagefault_queue_work.
Matt
[1] https://patchwork.freedesktop.org/patch/667318/?series=152565&rev=1
[2] https://patchwork.freedesktop.org/patch/667323/?series=152565&rev=1
Quoted 27 lines
Still getting through the series, so appologize if this is also answered later in the series...
Thanks,
StuartQuoted 20 lines
+ }
+ spin_unlock_irq(&pf_queue->lock);drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +/**
*xe_pagefault_reset()- Page fault reset for a GT
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +4
-1@@ -132,7 +150,10 @@ int xe_pagefault_init(struct xe_device *xe)*/ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt) { - /* TODO - implement */ + int i; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) + xe_pagefault_queue_reset(xe, gt, xe->usm.pf_queue + i); }
/**
Re: [PATCH 03/11] drm/xe: Implement xe_pagefault_reset
Quoted 38 lines · Matthew Brost
Quoted 27 lines · Stuart
Quoted 26 lines · Matthew Brost
Squash any pending faults on the GT being reset by setting the GT field
in structxe_pagefaultto NULL.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_gt.c | 2 ++drivers/gpu/drm/xe/xe_pagefault.c| 23 ++++++++++++++++++++++-2 files changed, 24 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_gt.c +1
-0@@ -50,6 +50,7 @@ #include "xe_map.h" #include "xe_migrate.h" #include "xe_mmio.h" +#include "xe_pagefault.h" #include "xe_pat.h" #include "xe_pm.h" #include "xe_mocs.h"@@ -846,6 +847,7 @@ static int gt_reset(struct xe_gt *gt)
xe_uc_gucrc_disable(>->uc);Quoted 9 lines
Quoted 2 lines
xe_uc_stop_prepare(>->uc);
+ xe_pagefault_reset(gt_to_xe(gt), gt);Can we just pass the GT in here and then extrapolate xe from there? I
realize you're thinking of dropping the GT piece, but maybe we can change the parameters around at that time. Just feels weird passing these both in at this point.
Quoted 5 lines
I think the style is generally layer accepts the main argument first exported function. ofc we don't actually do that everywhere in Xe though. Here the main argument for the layer 'xe'.
Can drop if you prefer, I don't really have strong opinion.
Yeah ok makes sense. Let's leave it the way you have it here.
Quoted 35 lines
Quoted 27 lines
Quoted 27 lines
xe_gt_pagefault_reset(gt);
xe_uc_stop(>->uc);drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -122,6 +122,24 @@ int xe_pagefault_init(struct xe_device *xe) return err; }
+static void xe_pagefault_queue_reset(structxe_device*xe, structxe_gt*gt,
+ structxe_pagefault_queue*pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +8
-0+{ + u32 i; + + /* Squash all pending faults on the GT */ + + spin_lock_irq(&pf_queue->lock); + for (i = pf_queue->tail; i != pf_queue->head; + i = (i + xe_pagefault_entry_size()) % pf_queue-Quoted 7 lines
Quoted 1 line
Quoted 1 line
size) {
Should we add a check in here that
pf_queue->headis some multiple ofxe_pagefault_entry_sizeandpf_queue->sizeis aligned toxe_pagefault_entry_size()?
Quoted 3 lines
We can add some asserts, still would get an infinite loop but at least
CI we catch a bug quickly we introduced somewhere.
Yeah asserts is all I was thinking. Just to give us a way to detect regressions in this area easily.
Quoted 25 lines
Quoted 6 lines
Quoted 5 lines
+ struct
xe_pagefault*pf =pf_queue->data+ i; +
+ if (pf->gt== gt)
+ pf->gt = NULL;Quoted 8 lines
Not sure I fully get the intent here... so we loop back around from TAIL to HEAD and clear all of the GTs in
pf_queue->datafor each one?
Is the expectation that each entry in thepf_queuehas the same GT or
is NULL? And then setting to NULL is a way we can abstract out the GT?This patch [1] moves the page faults queue from the GT to the device as
having a thread pool per GT makes little sense - want our thread pool to
be per device and enough threads to hit CPU<->GPU peak bus bandwidth in
what we'd expect to be common prefetch / page faults cases (e.g., 2M SVM
migrations).
Quoted 7 lines
When the fault queues were per GT, reset were easy, just reset all the
queues on the GT but now sense they are shared on the device and individual GTs can reset, we squash all faults on the GT by setting the
GT to NULL. This patch [2] ignores any fault with a NULL GT in the functionxe_pagefault_queue_work.
Ok thanks for the explanation here. I also am still working through those later patches, just an initial comment here. Let me read through those other in detail and I'll get back if I still have questions there.
Thanks,
Stuart
Quoted 36 lines
Matt
[1]
https://patchwork.freedesktop.org/patch/667318/?series=152565&rev=1
[2]
https://patchwork.freedesktop.org/patch/667323/?series=152565&rev=1Quoted 28 lines
Still getting through the series, so appologize if this is also answered later in the series...
Thanks,
StuartQuoted 21 lines
+ }
+ spin_unlock_irq(&pf_queue->lock);drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +/**
*xe_pagefault_reset()- Page fault reset for a GT
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +5
-1@@ -132,7 +150,10 @@ int xe_pagefault_init(struct xe_device *xe)*/ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt) { - /* TODO - implement */ + int i; + + for (i = 0; i < XE_PAGEFAULT_QUEUE_COUNT; ++i) + xe_pagefault_queue_reset(xe, gt, xe->usm.pf_queue + i); }
/**
Matthew Brost
maintainerPATCH 4/11 drm/xe: Implement xe_pagefault_handler
In reply to Matthew BrostEnqueue (copy) the input struct xe_pagefault into a queue (i.e., into a memory buffer) and schedule a worker to service it.
--- drivers/gpu/drm/xe/xe_pagefault.c | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_pagefault.c +30 -2
@@ -3,6 +3,8 @@* Copyright © 2025 Intel Corporation */ +#include <linux/circ_buf.h> +#include <drm/drm_managed.h> #include "xe_device.h"
@@ -156,6 +158,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
@@ -168,6 +178,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 ; }
Signature · 1 line
2.34.1
Re: [PATCH 04/11] drm/xe: Implement xe_pagefault_handler
Quoted 4 lines · Matthew Brost
Enqueue (copy) the input struct
xe_pagefaultinto a queue (i.e., into a memory buffer) and schedule a worker to service it.Signed-off-by Matthew Brost <[email protected]>
Quoted 62 lines
--- drivers/gpu/drm/xe/xe_pagefault.c | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_pagefault.c +30
-2@@ -3,6 +3,8 @@* Copyright © 2025 Intel Corporation */ +#include <linux/circ_buf.h> +#include <drm/drm_managed.h> #include "xe_device.h" @@ -156,6 +158,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 @@ -168,6 +178,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 ; }Signature · 1 line
2.34.1
Re: [PATCH 04/11] drm/xe: Implement xe_pagefault_handler
In reply to Matthew BrostQuoted 61 lines · Matthew Brost
Enqueue (copy) the input struct
xe_pagefaultinto a queue (i.e., into a
memory buffer) and schedule a worker to service it.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_pagefault.c | 32
+++++++++++++++++++++++++++++--1 file changed, 30 insertions(+), 2 deletions(-)drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -3,6 +3,8 @@* Copyright © 2025 Intel Corporation */ drivers/gpu/drm/xe/xe_pagefault.c +2
-0+#include <linux/circ_buf.h> +#include <
drm/drm_managed.h>
#include "xe_device.h"drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -156,6 +158,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 boolxe_pagefault_queue_full(struct xe_pagefault_queue *pf_queue)drivers/gpu/drm/xe/xe_pagefault.c +4
-0+{ + lockdep_assert_held(&pf_queue->lock); + + return CIRC_SPACE(pf_queue->head, pf_queue->tail, pf_queue-Quoted 1 line
size) <=
+ xe_pagefault_entry_size();
drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +/**
*xe_pagefault_handler()- Page fault handler
* @xe: xe device instancedrivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -168,6 +178,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;
+ structxe_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));
Quoted 8 lines
+ 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",
Actually, does it make sense to drop the "shouldn't be possible" part? We already have this as a warn and we have a history now of calculations here. It also could be that some future hardware changes this somehow and we want to know that the calculation isn't right, but that would be a legitimate bug in that case (and even so on existing hardware where we have a bug in the calculation).
Thanks,
Stuart
Quoted 7 lines
+
pf->consumer.asid%XE_PAGEFAULT_QUEUE_COUNT);
+ }
+ spin_unlock_irqrestore(&pf_queue->lock, flags); +
+ return full ?-ENOSPC: 0;
}
Matthew Brost
maintainerPATCH 5/11 drm/xe: Implement xe_pagefault_queue_work
In reply to Matthew BrostImplement a worker that services page faults, using the same implementation as in xe_gt_pagefault.c.
--- drivers/gpu/drm/xe/xe_pagefault.c | 240 +++++++++++++++++++++++++++++- 1 file changed, 239 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_pagefault.c +239 -1
@@ -5,12 +5,20 @@#include <linux/circ_buf.h> +#include <drm/drm_exec.h> #include <drm/drm_managed.h> +#include "xe_bo.h" #include "xe_device.h" +#include "xe_gt_printk.h" #include "xe_gt_types.h" +#include "xe_gt_stats.h" +#include "xe_hw_engine.h" #include "xe_pagefault.h" #include "xe_pagefault_types.h" +#include "xe_svm.h" +#include "xe_trace_bo.h" +#include "xe_vm.h" /** * DOC: Xe page faults
@@ -30,9 +38,239 @@ static int xe_pagefault_entry_size(void)return roundup_pow_of_two (sizeof (struct xe_pagefault )); } +static int xe_pagefault_begin (struct drm_exec *exec,struct xe_vma *vma, +bool atomic,unsigned int id) +{ +struct xe_bo *bo =xe_vma_bo (vma); +struct xe_vm *vm =xe_vma_vm (vma); +int err; + + err =xe_vm_lock_vma (exec, vma); +if (err) +return err; + +if (atomic &&IS_DGFX (vm->xe)) { +if (xe_vma_is_userptr (vma)) { + err = -EACCES ; +return err; + } + +/* Migrate to VRAM, move should invalidate the VMA first */ + err =xe_bo_migrate (bo,XE_PL_VRAM0 + id); +if (err) +return err; + }else if (bo) { +/* Create backing store if needed */ + err =xe_bo_validate (bo, vm, true); +if (err) +return err; + } + +return 0 ; +} + +static int xe_pagefault_handle_vma (struct xe_gt *gt,struct xe_vma *vma, +bool atomic) +{ +struct xe_vm *vm =xe_vma_vm (vma); +struct xe_tile *tile =gt_to_tile (gt); +struct drm_exec exec; +struct dma_fence *fence; +ktime_t end =0 ; +int err; + +lockdep_assert_held_write (&vm->lock); + +xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT ,1 ); +xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_KB , +xe_vma_size (vma) /SZ_1K ); + +trace_xe_vma_pagefault (vma); + +/* Check if VMA is valid, opportunistic check only */ +if (xe_vm_has_valid_gpu_mapping (tile, vma->tile_present, + vma->tile_invalidated) && !atomic) +return 0 ; + +retry_userptr: +if (xe_vma_is_userptr (vma) && +xe_vma_userptr_check_repin (to_userptr_vma (vma))) { +struct xe_userptr_vma *uvma =to_userptr_vma (vma); + + err =xe_vma_userptr_pin_pages (uvma); +if (err) +return err; + } + +/* Lock VM and BOs dma-resv */ +drm_exec_init (&exec,0 ,0 ); + drm_exec_until_all_locked(&exec) { + err =xe_pagefault_begin (&exec, vma, atomic, tile->id); +drm_exec_retry_on_contention (&exec); +if (xe_vm_validate_should_retry (&exec, err, &end)) + err = -EAGAIN ; +if (err) + goto unlock_dma_resv; + +/* Bind VMA only to the GT that has faulted */ +trace_xe_vma_pf_bind (vma); + fence =xe_vma_rebind (vm, vma,BIT (tile->id)); +if (IS_ERR (fence)) { + err =PTR_ERR (fence); +if (xe_vm_validate_should_retry (&exec, err, &end)) + err = -EAGAIN ; + goto unlock_dma_resv; + } + } + +dma_fence_wait (fence, false); +dma_fence_put (fence); + +unlock_dma_resv: +drm_exec_fini (&exec); +if (err == -EAGAIN ) + goto retry_userptr; + +return err; +} + +static bool +xe_pagefault_access_is_atomic (enum xe_pagefault_access_type access_type) +{ +return access_type ==XE_PAGEFAULT_ACCESS_TYPE_ATOMIC ; +} + +static struct xe_vm *xe_pagefault_asid_to_vm (struct xe_device *xe,u32 asid) +{ +struct xe_vm *vm; + +down_read (&xe->usm.lock); + vm =xa_load (&xe->usm.asid_to_vm, asid); +if (vm &&xe_vm_in_fault_mode (vm)) +xe_vm_get (vm); +else + vm =ERR_PTR (-EINVAL ); +up_read (&xe->usm.lock); + +return vm; +} + +static int xe_pagefault_service (struct xe_pagefault *pf) +{ +struct xe_gt *gt = pf->gt; +struct xe_device *xe =gt_to_xe (gt); +struct xe_vm *vm; +struct xe_vma *vma =NULL ; +int err; +bool atomic; + +/* Producer flagged this fault to be nacked */ +if (pf->consumer.fault_level ==XE_PAGEFAULT_LEVEL_NACK ) +return -EFAULT ; + + vm =xe_pagefault_asid_to_vm (xe, pf->consumer.asid); +if (IS_ERR (vm)) +return PTR_ERR (vm); + +/* +* TODO: Change to read lock? Using write lock for simplicity. +*/ +down_write (&vm->lock); + +if (xe_vm_is_closed (vm)) { + err = -ENOENT ; + goto unlock_vm; + } + + vma =xe_vm_find_vma_by_addr (vm, pf->consumer.page_addr); +if (!vma) { + err = -EINVAL ; + goto unlock_vm; + } + + atomic =xe_pagefault_access_is_atomic (pf->consumer.access_type); + +if (xe_vma_is_cpu_addr_mirror (vma)) + err =xe_svm_handle_pagefault (vm, vma, gt, + pf->consumer.page_addr, atomic); +else + err =xe_pagefault_handle_vma (gt, vma, atomic); + +unlock_vm: +if (!err) + vm->usm.last_fault_vma = vma; +up_write (&vm->lock); +xe_vm_put (vm); + +return err; +} + +static bool xe_pagefault_queue_pop (struct xe_pagefault_queue *pf_queue, +struct xe_pagefault *pf) +{ +bool found_fault = false; + +spin_lock_irq (&pf_queue->lock); +if (pf_queue->tail != pf_queue->head) { +memcpy (pf, pf_queue->data + pf_queue->tail,sizeof (*pf)); + pf_queue->tail = (pf_queue->tail +xe_pagefault_entry_size ()) % + pf_queue->size; + found_fault = true; + } +spin_unlock_irq (&pf_queue->lock); + +return found_fault; +} + +static void xe_pagefault_print (struct xe_pagefault *pf) +{ +xe_gt_dbg (pf->gt,"\n\tASID: %d\n" +"\tFaulted Address: 0x%08x%08x\n" +"\tFaultType: %d\n" +"\tAccessType: %d\n" +"\tFaultLevel: %d\n" +"\tEngineClass: %d %s\n" , + pf->consumer.asid, +upper_32_bits (pf->consumer.page_addr), +lower_32_bits (pf->consumer.page_addr), + pf->consumer.fault_type, + pf->consumer.access_type, + pf->consumer.fault_level, + pf->consumer.engine_class, +xe_hw_engine_class_to_str (pf->consumer.engine_class)); +} +static void xe_pagefault_queue_work (struct work_struct *w) { -/* TODO: Implement */ +struct xe_pagefault_queue *pf_queue = +container_of (w,typeof (*pf_queue), worker); +struct xe_pagefault pf; +unsigned long threshold; + +#define USM_QUEUE_MAX_RUNTIME_MS 20 + threshold = jiffies +msecs_to_jiffies (USM_QUEUE_MAX_RUNTIME_MS ); + +while (xe_pagefault_queue_pop (pf_queue, &pf)) { +int err; + +if (!pf.gt)/* Fault squashed during reset */ +continue ; + + err =xe_pagefault_service (&pf); +if (err) { +xe_pagefault_print (&pf); +xe_gt_dbg (pf.gt,"Fault response: Unsuccessful %pe\n" , +ERR_PTR (err)); + } + + pf.producer.ops->ack_fault (&pf, err); + +if (time_after (jiffies, threshold)) { +queue_work (gt_to_xe (pf.gt)->usm.pf_wq, w); +break ; + } + } +#undef USM_QUEUE_MAX_RUNTIME_MS } static int xe_pagefault_queue_init(struct xe_device *xe,
Signature · 1 line
2.34.1
Re: [PATCH 05/11] drm/xe: Implement xe_pagefault_queue_work
Quoted 2 lines · Matthew Brost
Implement a worker that services page faults, using the same implementation as in
xe_gt_pagefault.c.
Also the minor refactoring and cleanup along the way helps readability.
A few nits below.
Quoted 12 lines
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/xe_pagefault.c | 240 +++++++++++++++++++++++++++++- 1 file changed, 239 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -5,12 +5,20 @@
drivers/gpu/drm/xe/xe_pagefault.c line 15
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault.c +4
-0#include <linux/circ_buf.h> +#include <drm/drm_exec.h> #include <drm/drm_managed.h> +#include "xe_bo.h" #include "xe_device.h" +#include "xe_gt_printk.h" #include "xe_gt_types.h" +#include "xe_gt_stats.h"
Move up to maintain alphabetically ordered.
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include "xe_hw_engine.h" #include "xe_pagefault.h" #include "xe_pagefault_types.h" +#include "xe_svm.h" +#include "xe_trace_bo.h" +#include "xe_vm.h" /** * DOC: Xe page faults
drivers/gpu/drm/xe/xe_pagefault.c static int xe_pagefault_entry_size(void) · line 42
Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault.c +2
-0@@ -30,9 +38,239 @@ static int xe_pagefault_entry_size(void)return roundup_pow_of_two (sizeof (struct xe_pagefault )); } +static int xe_pagefault_begin (struct drm_exec *exec,struct xe_vma *vma, +bool atomic,unsigned int id)
Please rename id to tile_id for clarity.
Francois
Quoted 238 lines
drivers/gpu/drm/xe/xe_pagefault.c +229
-1+{ +struct xe_bo *bo =xe_vma_bo (vma); +struct xe_vm *vm =xe_vma_vm (vma); +int err; + + err =xe_vm_lock_vma (exec, vma); +if (err) +return err; + +if (atomic &&IS_DGFX (vm->xe)) { +if (xe_vma_is_userptr (vma)) { + err = -EACCES ; +return err; + } + +/* Migrate to VRAM, move should invalidate the VMA first */ + err =xe_bo_migrate (bo,XE_PL_VRAM0 + id); +if (err) +return err; + }else if (bo) { +/* Create backing store if needed */ + err =xe_bo_validate (bo, vm, true); +if (err) +return err; + } + +return 0 ; +} + +static int xe_pagefault_handle_vma (struct xe_gt *gt,struct xe_vma *vma, +bool atomic) +{ +struct xe_vm *vm =xe_vma_vm (vma); +struct xe_tile *tile =gt_to_tile (gt); +struct drm_exec exec; +struct dma_fence *fence; +ktime_t end =0 ; +int err; + +lockdep_assert_held_write (&vm->lock); + +xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT ,1 ); +xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_KB , +xe_vma_size (vma) /SZ_1K ); + +trace_xe_vma_pagefault (vma); + +/* Check if VMA is valid, opportunistic check only */ +if (xe_vm_has_valid_gpu_mapping (tile, vma->tile_present, + vma->tile_invalidated) && !atomic) +return 0 ; + +retry_userptr: +if (xe_vma_is_userptr (vma) && +xe_vma_userptr_check_repin (to_userptr_vma (vma))) { +struct xe_userptr_vma *uvma =to_userptr_vma (vma); + + err =xe_vma_userptr_pin_pages (uvma); +if (err) +return err; + } + +/* Lock VM and BOs dma-resv */ +drm_exec_init (&exec,0 ,0 ); + drm_exec_until_all_locked(&exec) { + err =xe_pagefault_begin (&exec, vma, atomic, tile->id); +drm_exec_retry_on_contention (&exec); +if (xe_vm_validate_should_retry (&exec, err, &end)) + err = -EAGAIN ; +if (err) + goto unlock_dma_resv; + +/* Bind VMA only to the GT that has faulted */ +trace_xe_vma_pf_bind (vma); + fence =xe_vma_rebind (vm, vma,BIT (tile->id)); +if (IS_ERR (fence)) { + err =PTR_ERR (fence); +if (xe_vm_validate_should_retry (&exec, err, &end)) + err = -EAGAIN ; + goto unlock_dma_resv; + } + } + +dma_fence_wait (fence, false); +dma_fence_put (fence); + +unlock_dma_resv: +drm_exec_fini (&exec); +if (err == -EAGAIN ) + goto retry_userptr; + +return err; +} + +static bool +xe_pagefault_access_is_atomic (enum xe_pagefault_access_type access_type) +{ +return access_type ==XE_PAGEFAULT_ACCESS_TYPE_ATOMIC ; +} + +static struct xe_vm *xe_pagefault_asid_to_vm (struct xe_device *xe,u32 asid) +{ +struct xe_vm *vm; + +down_read (&xe->usm.lock); + vm =xa_load (&xe->usm.asid_to_vm, asid); +if (vm &&xe_vm_in_fault_mode (vm)) +xe_vm_get (vm); +else + vm =ERR_PTR (-EINVAL ); +up_read (&xe->usm.lock); + +return vm; +} + +static int xe_pagefault_service (struct xe_pagefault *pf) +{ +struct xe_gt *gt = pf->gt; +struct xe_device *xe =gt_to_xe (gt); +struct xe_vm *vm; +struct xe_vma *vma =NULL ; +int err; +bool atomic; + +/* Producer flagged this fault to be nacked */ +if (pf->consumer.fault_level ==XE_PAGEFAULT_LEVEL_NACK ) +return -EFAULT ; + + vm =xe_pagefault_asid_to_vm (xe, pf->consumer.asid); +if (IS_ERR (vm)) +return PTR_ERR (vm); + +/* +* TODO: Change to read lock? Using write lock for simplicity. +*/ +down_write (&vm->lock); + +if (xe_vm_is_closed (vm)) { + err = -ENOENT ; + goto unlock_vm; + } + + vma =xe_vm_find_vma_by_addr (vm, pf->consumer.page_addr); +if (!vma) { + err = -EINVAL ; + goto unlock_vm; + } + + atomic =xe_pagefault_access_is_atomic (pf->consumer.access_type); + +if (xe_vma_is_cpu_addr_mirror (vma)) + err =xe_svm_handle_pagefault (vm, vma, gt, + pf->consumer.page_addr, atomic); +else + err =xe_pagefault_handle_vma (gt, vma, atomic); + +unlock_vm: +if (!err) + vm->usm.last_fault_vma = vma; +up_write (&vm->lock); +xe_vm_put (vm); + +return err; +} + +static bool xe_pagefault_queue_pop (struct xe_pagefault_queue *pf_queue, +struct xe_pagefault *pf) +{ +bool found_fault = false; + +spin_lock_irq (&pf_queue->lock); +if (pf_queue->tail != pf_queue->head) { +memcpy (pf, pf_queue->data + pf_queue->tail,sizeof (*pf)); + pf_queue->tail = (pf_queue->tail +xe_pagefault_entry_size ()) % + pf_queue->size; + found_fault = true; + } +spin_unlock_irq (&pf_queue->lock); + +return found_fault; +} + +static void xe_pagefault_print (struct xe_pagefault *pf) +{ +xe_gt_dbg (pf->gt,"\n\tASID: %d\n" +"\tFaulted Address: 0x%08x%08x\n" +"\tFaultType: %d\n" +"\tAccessType: %d\n" +"\tFaultLevel: %d\n" +"\tEngineClass: %d %s\n" , + pf->consumer.asid, +upper_32_bits (pf->consumer.page_addr), +lower_32_bits (pf->consumer.page_addr), + pf->consumer.fault_type, + pf->consumer.access_type, + pf->consumer.fault_level, + pf->consumer.engine_class, +xe_hw_engine_class_to_str (pf->consumer.engine_class)); +} +static void xe_pagefault_queue_work (struct work_struct *w) { -/* TODO: Implement */ +struct xe_pagefault_queue *pf_queue = +container_of (w,typeof (*pf_queue), worker); +struct xe_pagefault pf; +unsigned long threshold; + +#define USM_QUEUE_MAX_RUNTIME_MS 20 + threshold = jiffies +msecs_to_jiffies (USM_QUEUE_MAX_RUNTIME_MS ); + +while (xe_pagefault_queue_pop (pf_queue, &pf)) { +int err; + +if (!pf.gt)/* Fault squashed during reset */ +continue ; + + err =xe_pagefault_service (&pf); +if (err) { +xe_pagefault_print (&pf); +xe_gt_dbg (pf.gt,"Fault response: Unsuccessful %pe\n" , +ERR_PTR (err)); + } + + pf.producer.ops->ack_fault (&pf, err); + +if (time_after (jiffies, threshold)) { +queue_work (gt_to_xe (pf.gt)->usm.pf_wq, w); +break ; + } + } +#undef USM_QUEUE_MAX_RUNTIME_MS } static int xe_pagefault_queue_init(struct xe_device *xe,Signature · 1 line
2.34.1
Matthew Brost
maintainerRe: [PATCH 05/11] drm/xe: Implement xe_pagefault_queue_work
Quoted 25 lines · Francois Dugast
Quoted 2 lines · Matthew Brost
Implement a worker that services page faults, using the same implementation as in
xe_gt_pagefault.c.Also the minor refactoring and cleanup along the way helps readability.
A few nits below.
Quoted 17 lines
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/xe/xe_pagefault.c | 240 +++++++++++++++++++++++++++++- 1 file changed, 239 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_pagefault.c +1
-0@@ -5,12 +5,20 @@#include <linux/circ_buf.h> +#include <drm/drm_exec.h> #include <drm/drm_managed.h>
Quoted 8 lines
drivers/gpu/drm/xe/xe_pagefault.c line 15
Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault.c +3
-0+#include "xe_bo.h" #include "xe_device.h" +#include "xe_gt_printk.h" #include "xe_gt_types.h" +#include "xe_gt_stats.h" Move up to maintain alphabetically ordered.
Yes, will do.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/xe/xe_pagefault.c +4
-0+#include "xe_hw_engine.h" #include "xe_pagefault.h" #include "xe_pagefault_types.h" +#include "xe_svm.h" +#include "xe_trace_bo.h" +#include "xe_vm.h" /** * DOC: Xe page faults @@ -30,9 +38,239 @@ static int xe_pagefault_entry_size(void)return roundup_pow_of_two (sizeof (struct xe_pagefault )); }
Quoted 5 lines
drivers/gpu/drm/xe/xe_pagefault.c static int xe_pagefault_entry_size(void) · line 42
Quoted 2 lines
drivers/gpu/drm/xe/xe_pagefault.c +2
-0+static int xe_pagefault_begin (struct drm_exec *exec,struct xe_vma *vma, +bool atomic,unsigned int id)Please rename id to
tile_idfor clarity.
Yep. Will change.
Matt
Quoted 240 lines
Francois
Quoted 238 lines
drivers/gpu/drm/xe/xe_pagefault.c +229
-1+{ +struct xe_bo *bo =xe_vma_bo (vma); +struct xe_vm *vm =xe_vma_vm (vma); +int err; + + err =xe_vm_lock_vma (exec, vma); +if (err) +return err; + +if (atomic &&IS_DGFX (vm->xe)) { +if (xe_vma_is_userptr (vma)) { + err = -EACCES ; +return err; + } + +/* Migrate to VRAM, move should invalidate the VMA first */ + err =xe_bo_migrate (bo,XE_PL_VRAM0 + id); +if (err) +return err; + }else if (bo) { +/* Create backing store if needed */ + err =xe_bo_validate (bo, vm, true); +if (err) +return err; + } + +return 0 ; +} + +static int xe_pagefault_handle_vma (struct xe_gt *gt,struct xe_vma *vma, +bool atomic) +{ +struct xe_vm *vm =xe_vma_vm (vma); +struct xe_tile *tile =gt_to_tile (gt); +struct drm_exec exec; +struct dma_fence *fence; +ktime_t end =0 ; +int err; + +lockdep_assert_held_write (&vm->lock); + +xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT ,1 ); +xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_KB , +xe_vma_size (vma) /SZ_1K ); + +trace_xe_vma_pagefault (vma); + +/* Check if VMA is valid, opportunistic check only */ +if (xe_vm_has_valid_gpu_mapping (tile, vma->tile_present, + vma->tile_invalidated) && !atomic) +return 0 ; + +retry_userptr: +if (xe_vma_is_userptr (vma) && +xe_vma_userptr_check_repin (to_userptr_vma (vma))) { +struct xe_userptr_vma *uvma =to_userptr_vma (vma); + + err =xe_vma_userptr_pin_pages (uvma); +if (err) +return err; + } + +/* Lock VM and BOs dma-resv */ +drm_exec_init (&exec,0 ,0 ); + drm_exec_until_all_locked(&exec) { + err =xe_pagefault_begin (&exec, vma, atomic, tile->id); +drm_exec_retry_on_contention (&exec); +if (xe_vm_validate_should_retry (&exec, err, &end)) + err = -EAGAIN ; +if (err) + goto unlock_dma_resv; + +/* Bind VMA only to the GT that has faulted */ +trace_xe_vma_pf_bind (vma); + fence =xe_vma_rebind (vm, vma,BIT (tile->id)); +if (IS_ERR (fence)) { + err =PTR_ERR (fence); +if (xe_vm_validate_should_retry (&exec, err, &end)) + err = -EAGAIN ; + goto unlock_dma_resv; + } + } + +dma_fence_wait (fence, false); +dma_fence_put (fence); + +unlock_dma_resv: +drm_exec_fini (&exec); +if (err == -EAGAIN ) + goto retry_userptr; + +return err; +} + +static bool +xe_pagefault_access_is_atomic (enum xe_pagefault_access_type access_type) +{ +return access_type ==XE_PAGEFAULT_ACCESS_TYPE_ATOMIC ; +} + +static struct xe_vm *xe_pagefault_asid_to_vm (struct xe_device *xe,u32 asid) +{ +struct xe_vm *vm; + +down_read (&xe->usm.lock); + vm =xa_load (&xe->usm.asid_to_vm, asid); +if (vm &&xe_vm_in_fault_mode (vm)) +xe_vm_get (vm); +else + vm =ERR_PTR (-EINVAL ); +up_read (&xe->usm.lock); + +return vm; +} + +static int xe_pagefault_service (struct xe_pagefault *pf) +{ +struct xe_gt *gt = pf->gt; +struct xe_device *xe =gt_to_xe (gt); +struct xe_vm *vm; +struct xe_vma *vma =NULL ; +int err; +bool atomic; + +/* Producer flagged this fault to be nacked */ +if (pf->consumer.fault_level ==XE_PAGEFAULT_LEVEL_NACK ) +return -EFAULT ; + + vm =xe_pagefault_asid_to_vm (xe, pf->consumer.asid); +if (IS_ERR (vm)) +return PTR_ERR (vm); + +/* +* TODO: Change to read lock? Using write lock for simplicity. +*/ +down_write (&vm->lock); + +if (xe_vm_is_closed (vm)) { + err = -ENOENT ; + goto unlock_vm; + } + + vma =xe_vm_find_vma_by_addr (vm, pf->consumer.page_addr); +if (!vma) { + err = -EINVAL ; + goto unlock_vm; + } + + atomic =xe_pagefault_access_is_atomic (pf->consumer.access_type); + +if (xe_vma_is_cpu_addr_mirror (vma)) + err =xe_svm_handle_pagefault (vm, vma, gt, + pf->consumer.page_addr, atomic); +else + err =xe_pagefault_handle_vma (gt, vma, atomic); + +unlock_vm: +if (!err) + vm->usm.last_fault_vma = vma; +up_write (&vm->lock); +xe_vm_put (vm); + +return err; +} + +static bool xe_pagefault_queue_pop (struct xe_pagefault_queue *pf_queue, +struct xe_pagefault *pf) +{ +bool found_fault = false; + +spin_lock_irq (&pf_queue->lock); +if (pf_queue->tail != pf_queue->head) { +memcpy (pf, pf_queue->data + pf_queue->tail,sizeof (*pf)); + pf_queue->tail = (pf_queue->tail +xe_pagefault_entry_size ()) % + pf_queue->size; + found_fault = true; + } +spin_unlock_irq (&pf_queue->lock); + +return found_fault; +} + +static void xe_pagefault_print (struct xe_pagefault *pf) +{ +xe_gt_dbg (pf->gt,"\n\tASID: %d\n" +"\tFaulted Address: 0x%08x%08x\n" +"\tFaultType: %d\n" +"\tAccessType: %d\n" +"\tFaultLevel: %d\n" +"\tEngineClass: %d %s\n" , + pf->consumer.asid, +upper_32_bits (pf->consumer.page_addr), +lower_32_bits (pf->consumer.page_addr), + pf->consumer.fault_type, + pf->consumer.access_type, + pf->consumer.fault_level, + pf->consumer.engine_class, +xe_hw_engine_class_to_str (pf->consumer.engine_class)); +} +static void xe_pagefault_queue_work (struct work_struct *w) { -/* TODO: Implement */ +struct xe_pagefault_queue *pf_queue = +container_of (w,typeof (*pf_queue), worker); +struct xe_pagefault pf; +unsigned long threshold; + +#define USM_QUEUE_MAX_RUNTIME_MS 20 + threshold = jiffies +msecs_to_jiffies (USM_QUEUE_MAX_RUNTIME_MS ); + +while (xe_pagefault_queue_pop (pf_queue, &pf)) { +int err; + +if (!pf.gt)/* Fault squashed during reset */ +continue ; + + err =xe_pagefault_service (&pf); +if (err) { +xe_pagefault_print (&pf); +xe_gt_dbg (pf.gt,"Fault response: Unsuccessful %pe\n" , +ERR_PTR (err)); + } + + pf.producer.ops->ack_fault (&pf, err); + +if (time_after (jiffies, threshold)) { +queue_work (gt_to_xe (pf.gt)->usm.pf_wq, w); +break ; + } + } +#undef USM_QUEUE_MAX_RUNTIME_MS } static int xe_pagefault_queue_init(struct xe_device *xe,Signature · 1 line
2.34.1
Re: [PATCH 05/11] drm/xe: Implement xe_pagefault_queue_work
In reply to Matthew BrostQuoted 267 lines · Matthew Brost
Implement a worker that services page faults, using the same implementation as in
xe_gt_pagefault.c.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_pagefault.c | 240
+++++++++++++++++++++++++++++-1 file changed, 239 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -5,12 +5,20 @@
#include <linux/circ_buf.h>
+#include <drm/drm_exec.h>
#include <drm/drm_managed.h>
+#include "xe_bo.h"
#include "xe_device.h"
+#include "xe_gt_printk.h"
#include "xe_gt_types.h"drivers/gpu/drm/xe/xe_pagefault.c +2
-0+#include "xe_gt_stats.h" +#include "xe_hw_engine.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +3
-0+#include "xe_svm.h" +#include "xe_trace_bo.h" +#include "xe_vm.h"
/**
* DOC: Xe page faultsdrivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -30,9 +38,239 @@ static int xe_pagefault_entry_size(void) return roundup_pow_of_two(sizeof(struct xe_pagefault)); }
+static int xe_pagefault_begin(structdrm_exec*exec, structxe_vma*vma,
+ bool atomic, unsigned int id)drivers/gpu/drm/xe/xe_pagefault.c +16
-0+{ + struct xe_bo *bo = xe_vma_bo(vma); + struct xe_vm *vm = xe_vma_vm(vma); + int err; + + err = xe_vm_lock_vma(exec, vma); + if (err) + return err; + + if (atomic && IS_DGFX(vm->xe)) { + if (xe_vma_is_userptr(vma)) { + err = -EACCES; + return err; + } + + /* Migrate to VRAM, move should invalidate the VMAfirst */
+ err =xe_bo_migrate(bo, XE_PL_VRAM0 + id); + if (err)
+ return err;
+ } else if (bo) {
+ /* Create backing store if needed */ + err =xe_bo_validate(bo, vm, true); + if (err)
+ return err;
+ }drivers/gpu/drm/xe/xe_pagefault.c +5
-0+ + return 0; +} + +static int xe_pagefault_handle_vma(struct xe_gt *gt, struct xe_vma*vma,
+ bool atomic)drivers/gpu/drm/xe/xe_pagefault.c +19
-0+{ + struct xe_vm *vm = xe_vma_vm(vma); + struct xe_tile *tile = gt_to_tile(gt); + struct drm_exec exec; + struct dma_fence *fence; + ktime_t end = 0; + int err; + + lockdep_assert_held_write(&vm->lock); + + xe_gt_stats_incr(gt, XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT, 1); + xe_gt_stats_incr(gt, XE_GT_STATS_ID_VMA_PAGEFAULT_KB, + xe_vma_size(vma) / SZ_1K); + + trace_xe_vma_pagefault(vma); + + /* Check if VMA is valid, opportunistic check only */ + if (xe_vm_has_valid_gpu_mapping(tile, vma->tile_present, + vma->tile_invalidated) &&!atomic)
+ return 0;drivers/gpu/drm/xe/xe_pagefault.c +15
-0+ +retry_userptr: + if (xe_vma_is_userptr(vma) && + xe_vma_userptr_check_repin(to_userptr_vma(vma))) { + struct xe_userptr_vma *uvma = to_userptr_vma(vma); + + err = xe_vma_userptr_pin_pages(uvma); + if (err) + return err; + } + + /* Lock VM and BOs dma-resv */ + drm_exec_init(&exec, 0, 0); + drm_exec_until_all_locked(&exec) { + err = xe_pagefault_begin(&exec, vma, atomic, tile-Quoted 1 line
id);
+ drm_exec_retry_on_contention(&exec);
+ if (xe_vm_validate_should_retry(&exec, err, &end)) + err =-EAGAIN;
+ if (err)
+ gotounlock_dma_resv;
+
+ /* Bind VMA only to the GT that has faulted */ + trace_xe_vma_pf_bind(vma);
+ fence =xe_vma_rebind(vm, vma, BIT(tile->id)); + if (IS_ERR(fence)) {
+ err =PTR_ERR(fence);
+ if (xe_vm_validate_should_retry(&exec, err, &end))
+ err =-EAGAIN;
+ gotounlock_dma_resv;
+ }
+ }drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + dma_fence_wait(fence, false); + dma_fence_put(fence); + +unlock_dma_resv: + drm_exec_fini(&exec); + if (err == -EAGAIN) + goto retry_userptr; + + return err; +} + +static bool +xe_pagefault_access_is_atomic(enum xe_pagefault_access_type
access_type)drivers/gpu/drm/xe/xe_pagefault.c +5
-0+{ + return access_type == XE_PAGEFAULT_ACCESS_TYPE_ATOMIC; +} + +static struct xe_vm *xe_pagefault_asid_to_vm(struct xe_device *xe,u32 asid)
drivers/gpu/drm/xe/xe_pagefault.c +33
-0+{ + struct xe_vm *vm; + + down_read(&xe->usm.lock); + vm = xa_load(&xe->usm.asid_to_vm, asid); + if (vm && xe_vm_in_fault_mode(vm)) + xe_vm_get(vm); + else + vm = ERR_PTR(-EINVAL); + up_read(&xe->usm.lock); + + return vm; +} + +static int xe_pagefault_service (struct xe_pagefault *pf) +{ + struct xe_gt *gt = pf->gt; + struct xe_device *xe = gt_to_xe(gt); + struct xe_vm *vm; + struct xe_vma *vma = NULL; + int err; + bool atomic; + + /* Producer flagged this fault to be nacked */ + if (pf->consumer.fault_level == XE_PAGEFAULT_LEVEL_NACK) + return -EFAULT; + + vm = xe_pagefault_asid_to_vm(xe, pf->consumer.asid); + if (IS_ERR(vm)) + return PTR_ERR(vm); + + /* +* TODO: Change to read lock? Using write lock for simplicity.
+ */
+ down_write(&vm->lock);drivers/gpu/drm/xe/xe_pagefault.c +13
-0+ + if (xe_vm_is_closed(vm)) { + err = -ENOENT; + goto unlock_vm; + } + + vma = xe_vm_find_vma_by_addr(vm, pf->consumer.page_addr); + if (!vma) { + err = -EINVAL; + goto unlock_vm; + } + + atomic = xe_pagefault_access_is_atomic(pf-Quoted 1 line
consumer.access_type);
+
+ if (xe_vma_is_cpu_addr_mirror(vma))
+ err = xe_svm_handle_pagefault(vm, vma, gt, +pf->consumer.page_addr, atomic);
+ else
+ err =xe_pagefault_handle_vma(gt, vma, atomic);drivers/gpu/drm/xe/xe_pagefault.c +11
-0+ +unlock_vm: + if (!err) + vm->usm.last_fault_vma = vma; + up_write(&vm->lock); + xe_vm_put(vm); + + return err; +} + +static bool xe_pagefault_queue_pop(struct xe_pagefault_queue
*pf_queue,
+ structxe_pagefault*pf)drivers/gpu/drm/xe/xe_pagefault.c +6
-0+{ + bool found_fault = false; + + spin_lock_irq(&pf_queue->lock); + if (pf_queue->tail != pf_queue->head) { + memcpy(pf, pf_queue->data + pf_queue->tail,
sizeof(*pf));
+ pf_queue->tail = (pf_queue->tail+xe_pagefault_entry_size()) %
+ pf_queue->size;
+ found_fault = true;
+ }
+ spin_unlock_irq(&pf_queue->lock);drivers/gpu/drm/xe/xe_pagefault.c +20
-0+ + return found_fault; +} + +static void xe_pagefault_print (struct xe_pagefault *pf) +{ + xe_gt_dbg(pf->gt, "\n\tASID: %d\n" + "\tFaulted Address: 0x%08x%08x\n" + "\tFaultType: %d\n" + "\tAccessType: %d\n" + "\tFaultLevel: %d\n" + "\tEngineClass: %d %s\n", + pf->consumer.asid, + upper_32_bits(pf->consumer.page_addr), + lower_32_bits(pf->consumer.page_addr), + pf->consumer.fault_type, + pf->consumer.access_type, + pf->consumer.fault_level, + pf->consumer.engine_class, + xe_hw_engine_class_to_str(pf-Quoted 1 line
consumer.engine_class));
drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +static void
xe_pagefault_queue_work(struct work_struct *w){
- /* TODO: Implement */
+ structxe_pagefault_queue*pf_queue=
+ container_of(w,typeof(*pf_queue), worker); + structxe_pagefaultpf;
+ unsigned long threshold;drivers/gpu/drm/xe/xe_pagefault.c +3
-0+ +#define USM_QUEUE_MAX_RUNTIME_MS 20 + threshold = jiffies +
msecs_to_jiffies(USM_QUEUE_MAX_RUNTIME_MS);
drivers/gpu/drm/xe/xe_pagefault.c static int xe_pagefault_entry_size(void) · line 261
Quoted 10 lines
drivers/gpu/drm/xe/xe_pagefault.c +10
-0+ + while (xe_pagefault_queue_pop(pf_queue, &pf)) { + int err; + + if (!pf.gt) /* Fault squashed during reset */ + continue; + + err = xe_pagefault_service(&pf); + if (err) { + xe_pagefault_print(&pf);
I realize you're just copying over the existing functionality here. Since this is already, but should we change this to an info and use dbg to just print all incoming faults?
Anyway even if we do want to do this, not really applicable here since this is just copying as mentioned.
With the changes Francois suggested in place:
Thanks,
Stuart
Quoted 16 lines
+ xe_gt_dbg(pf.gt, "Fault response:
Unsuccessful %pe\n",
+ERR_PTR(err)); + }drivers/gpu/drm/xe/xe_pagefault.c +9
-0+ + pf.producer.ops->ack_fault(&pf, err); + + if (time_after(jiffies, threshold)) { + queue_work(gt_to_xe(pf.gt)->usm.pf_wq, w); + break; + } + } +#undef USM_QUEUE_MAX_RUNTIME_MS}
static int xe_pagefault_queue_init(structxe_device*xe,
Matthew Brost
maintainerRe: [PATCH 05/11] drm/xe: Implement xe_pagefault_queue_work
Quoted 274 lines · Stuart
Quoted 273 lines · Matthew Brost
Implement a worker that services page faults, using the same implementation as in
xe_gt_pagefault.c.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_pagefault.c | 240
+++++++++++++++++++++++++++++-1 file changed, 239 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -5,12 +5,20 @@
#include <linux/circ_buf.h>
+#include <drm/drm_exec.h>
#include <drm/drm_managed.h>
+#include "xe_bo.h"
#include "xe_device.h"
+#include "xe_gt_printk.h"
#include "xe_gt_types.h"drivers/gpu/drm/xe/xe_pagefault.c +2
-0+#include "xe_gt_stats.h" +#include "xe_hw_engine.h" #include "
xe_pagefault.h"
#include "xe_pagefault_types.h"drivers/gpu/drm/xe/xe_pagefault.c +3
-0+#include "xe_svm.h" +#include "xe_trace_bo.h" +#include "xe_vm.h"
/**
* DOC: Xe page faultsdrivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -30,9 +38,239 @@ static int xe_pagefault_entry_size(void) return roundup_pow_of_two(sizeof(struct xe_pagefault)); }
+static int xe_pagefault_begin(structdrm_exec*exec, structxe_vma*vma,
+ bool atomic, unsigned int id)drivers/gpu/drm/xe/xe_pagefault.c +16
-0+{ + struct xe_bo *bo = xe_vma_bo(vma); + struct xe_vm *vm = xe_vma_vm(vma); + int err; + + err = xe_vm_lock_vma(exec, vma); + if (err) + return err; + + if (atomic && IS_DGFX(vm->xe)) { + if (xe_vma_is_userptr(vma)) { + err = -EACCES; + return err; + } + + /* Migrate to VRAM, move should invalidate the VMAfirst */
+ err =xe_bo_migrate(bo, XE_PL_VRAM0 + id); + if (err)
+ return err;
+ } else if (bo) {
+ /* Create backing store if needed */ + err =xe_bo_validate(bo, vm, true); + if (err)
+ return err;
+ }drivers/gpu/drm/xe/xe_pagefault.c +5
-0+ + return 0; +} + +static int xe_pagefault_handle_vma(struct xe_gt *gt, struct xe_vma*vma,
+ bool atomic)drivers/gpu/drm/xe/xe_pagefault.c +19
-0+{ + struct xe_vm *vm = xe_vma_vm(vma); + struct xe_tile *tile = gt_to_tile(gt); + struct drm_exec exec; + struct dma_fence *fence; + ktime_t end = 0; + int err; + + lockdep_assert_held_write(&vm->lock); + + xe_gt_stats_incr(gt, XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT, 1); + xe_gt_stats_incr(gt, XE_GT_STATS_ID_VMA_PAGEFAULT_KB, + xe_vma_size(vma) / SZ_1K); + + trace_xe_vma_pagefault(vma); + + /* Check if VMA is valid, opportunistic check only */ + if (xe_vm_has_valid_gpu_mapping(tile, vma->tile_present, + vma->tile_invalidated) &&!atomic)
+ return 0;drivers/gpu/drm/xe/xe_pagefault.c +15
-0+ +retry_userptr: + if (xe_vma_is_userptr(vma) && + xe_vma_userptr_check_repin(to_userptr_vma(vma))) { + struct xe_userptr_vma *uvma = to_userptr_vma(vma); + + err = xe_vma_userptr_pin_pages(uvma); + if (err) + return err; + } + + /* Lock VM and BOs dma-resv */ + drm_exec_init(&exec, 0, 0); + drm_exec_until_all_locked(&exec) { + err = xe_pagefault_begin(&exec, vma, atomic, tile-Quoted 1 line
id);
+ drm_exec_retry_on_contention(&exec);
+ if (xe_vm_validate_should_retry(&exec, err, &end)) + err =-EAGAIN;
+ if (err)
+ gotounlock_dma_resv;
+
+ /* Bind VMA only to the GT that has faulted */ + trace_xe_vma_pf_bind(vma);
+ fence =xe_vma_rebind(vm, vma, BIT(tile->id)); + if (IS_ERR(fence)) {
+ err =PTR_ERR(fence);
+ if (xe_vm_validate_should_retry(&exec, err, &end))
+ err =-EAGAIN;
+ gotounlock_dma_resv;
+ }
+ }drivers/gpu/drm/xe/xe_pagefault.c +14
-0+ + dma_fence_wait(fence, false); + dma_fence_put(fence); + +unlock_dma_resv: + drm_exec_fini(&exec); + if (err == -EAGAIN) + goto retry_userptr; + + return err; +} + +static bool +xe_pagefault_access_is_atomic(enum xe_pagefault_access_type
access_type)drivers/gpu/drm/xe/xe_pagefault.c +5
-0+{ + return access_type == XE_PAGEFAULT_ACCESS_TYPE_ATOMIC; +} + +static struct xe_vm *xe_pagefault_asid_to_vm(struct xe_device *xe,u32 asid)
drivers/gpu/drm/xe/xe_pagefault.c +33
-0+{ + struct xe_vm *vm; + + down_read(&xe->usm.lock); + vm = xa_load(&xe->usm.asid_to_vm, asid); + if (vm && xe_vm_in_fault_mode(vm)) + xe_vm_get(vm); + else + vm = ERR_PTR(-EINVAL); + up_read(&xe->usm.lock); + + return vm; +} + +static int xe_pagefault_service (struct xe_pagefault *pf) +{ + struct xe_gt *gt = pf->gt; + struct xe_device *xe = gt_to_xe(gt); + struct xe_vm *vm; + struct xe_vma *vma = NULL; + int err; + bool atomic; + + /* Producer flagged this fault to be nacked */ + if (pf->consumer.fault_level == XE_PAGEFAULT_LEVEL_NACK) + return -EFAULT; + + vm = xe_pagefault_asid_to_vm(xe, pf->consumer.asid); + if (IS_ERR(vm)) + return PTR_ERR(vm); + + /* +* TODO: Change to read lock? Using write lock for simplicity.
+ */
+ down_write(&vm->lock);drivers/gpu/drm/xe/xe_pagefault.c +13
-0+ + if (xe_vm_is_closed(vm)) { + err = -ENOENT; + goto unlock_vm; + } + + vma = xe_vm_find_vma_by_addr(vm, pf->consumer.page_addr); + if (!vma) { + err = -EINVAL; + goto unlock_vm; + } + + atomic = xe_pagefault_access_is_atomic(pf-Quoted 1 line
consumer.access_type);
+
+ if (xe_vma_is_cpu_addr_mirror(vma))
+ err = xe_svm_handle_pagefault(vm, vma, gt, +pf->consumer.page_addr, atomic);
+ else
+ err =xe_pagefault_handle_vma(gt, vma, atomic);drivers/gpu/drm/xe/xe_pagefault.c +11
-0+ +unlock_vm: + if (!err) + vm->usm.last_fault_vma = vma; + up_write(&vm->lock); + xe_vm_put(vm); + + return err; +} + +static bool xe_pagefault_queue_pop(struct xe_pagefault_queue
*pf_queue,
+ structxe_pagefault*pf)drivers/gpu/drm/xe/xe_pagefault.c +6
-0+{ + bool found_fault = false; + + spin_lock_irq(&pf_queue->lock); + if (pf_queue->tail != pf_queue->head) { + memcpy(pf, pf_queue->data + pf_queue->tail,
sizeof(*pf));
+ pf_queue->tail = (pf_queue->tail+xe_pagefault_entry_size()) %
+ pf_queue->size;
+ found_fault = true;
+ }
+ spin_unlock_irq(&pf_queue->lock);drivers/gpu/drm/xe/xe_pagefault.c +20
-0+ + return found_fault; +} + +static void xe_pagefault_print (struct xe_pagefault *pf) +{ + xe_gt_dbg(pf->gt, "\n\tASID: %d\n" + "\tFaulted Address: 0x%08x%08x\n" + "\tFaultType: %d\n" + "\tAccessType: %d\n" + "\tFaultLevel: %d\n" + "\tEngineClass: %d %s\n", + pf->consumer.asid, + upper_32_bits(pf->consumer.page_addr), + lower_32_bits(pf->consumer.page_addr), + pf->consumer.fault_type, + pf->consumer.access_type, + pf->consumer.fault_level, + pf->consumer.engine_class, + xe_hw_engine_class_to_str(pf-Quoted 1 line
consumer.engine_class));
drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +static void
xe_pagefault_queue_work(struct work_struct *w){
- /* TODO: Implement */
+ structxe_pagefault_queue*pf_queue=
+ container_of(w,typeof(*pf_queue), worker); + structxe_pagefaultpf;
+ unsigned long threshold;drivers/gpu/drm/xe/xe_pagefault.c +3
-0+ +#define USM_QUEUE_MAX_RUNTIME_MS 20 + threshold = jiffies +
msecs_to_jiffies(USM_QUEUE_MAX_RUNTIME_MS);drivers/gpu/drm/xe/xe_pagefault.c +6
-0+ + while (xe_pagefault_queue_pop(pf_queue, &pf)) { + int err; + + if (!pf.gt) /* Fault squashed during reset */ + continue;
Quoted 9 lines
Quoted 4 lines
+
+ err =xe_pagefault_service(&pf);
+ if (err) {
+ xe_pagefault_print(&pf);I realize you're just copying over the existing functionality here. Since this is already, but should we change this to an info and use dbg to just print all incoming faults?
That spam you'd get would be enormous. Every section of xe_exec_system_alloc trigger 100s, if not 1000s of faults. We already have ftrace points for faults if you really want that information.
Matt
Quoted 26 lines
Anyway even if we do want to do this, not really applicable here since this is just copying as mentioned.
With the changes Francois suggested in place:
Reviewed-by Stuart Summers <[email protected]>Thanks,
StuartQuoted 16 lines
+ xe_gt_dbg(pf.gt, "Fault response:
Unsuccessful %pe\n",
+ERR_PTR(err)); + }drivers/gpu/drm/xe/xe_pagefault.c +9
-0+ + pf.producer.ops->ack_fault(&pf, err); + + if (time_after(jiffies, threshold)) { + queue_work(gt_to_xe(pf.gt)->usm.pf_wq, w); + break; + } + } +#undef USM_QUEUE_MAX_RUNTIME_MS}
static int xe_pagefault_queue_init(structxe_device*xe,
Matthew Brost
maintainerPATCH 6/11 drm/xe: Add xe_guc_pagefault layer
In reply to Matthew BrostAdd xe_guc_pagefault layer (producer) which parses G2H fault messages messages into struct xe_pagefault, forwards them to the page fault layer (consumer) for servicing, and provides a vfunc to acknowledge faults to the GuC upon completion. Replace the old (and incorrect) GT page fault layer with this new layer throughout the driver.
Signed-off-bt: Matthew Brost <[email protected]>
--- drivers/gpu/drm/xe/Makefile | 2 +- drivers/gpu/drm/xe/xe_gt.c | 6 -- drivers/gpu/drm/xe/xe_guc_ct.c | 6 +- drivers/gpu/drm/xe/xe_guc_pagefault.c | 94 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_guc_pagefault.h | 13 ++++ drivers/gpu/drm/xe/xe_svm.c | 3 +- drivers/gpu/drm/xe/xe_vm.c | 1 - 7 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.h
drivers/gpu/drm/xe/Makefile +1 -1
@@ -58,7 +58,6 @@ xe-y += xe_bb.o \ xe_gt_freq.o \ xe_gt_idle.o \ xe_gt_mcr.o \ - xe_gt_pagefault.o \ xe_gt_sysfs.o \ xe_gt_throttle.o \ xe_gt_tlb_invalidation.o \
@@ -75,6 +74,7 @@ xe-y += xe_bb.o \ xe_guc_id_mgr.o \ xe_guc_klv_helpers.o \ xe_guc_log.o \ + xe_guc_pagefault.o \ xe_guc_pc.o \ xe_guc_submit.o \ xe_heci_gsc.o \
drivers/gpu/drm/xe/xe_gt.c +0 -6
@@ -32,7 +32,6 @@#include "xe_gt_freq.h" #include "xe_gt_idle.h" #include "xe_gt_mcr.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_vf.h"
@@ -634,10 +633,6 @@ int xe_gt_init(struct xe_gt *gt)if (err)return err; - err =xe_gt_pagefault_init (gt); -if (err) -return err; - err =xe_gt_idle_init (>->gtidle);if (err)return err;
@@ -848,7 +843,6 @@ static int gt_reset(struct xe_gt *gt)xe_uc_gucrc_disable (>->uc);xe_uc_stop_prepare (>->uc);xe_pagefault_reset (gt_to_xe (gt), gt); -xe_gt_pagefault_reset (gt);xe_uc_stop (>->uc);
drivers/gpu/drm/xe/xe_guc_ct.c +1 -5
@@ -21,7 +21,6 @@#include "xe_devcoredump.h" #include "xe_device.h" #include "xe_gt.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_monitor.h"
@@ -29,6 +28,7 @@#include "xe_gt_tlb_invalidation.h" #include "xe_guc.h" #include "xe_guc_log.h" +#include "xe_guc_pagefault.h" #include "xe_guc_relay.h" #include "xe_guc_submit.h" #include "xe_map.h"
@@ -1419,10 +1419,6 @@ static int process_g2h_msg(struct xe_guc_ct *ct, u32 *msg, u32 len) ret =xe_guc_tlb_invalidation_done_handler (guc, payload, adj_len);break ; -case XE_GUC_ACTION_ACCESS_COUNTER_NOTIFY : - ret =xe_guc_access_counter_notify_handler (guc, payload, - adj_len); -break ;case XE_GUC_ACTION_GUC2PF_RELAY_FROM_VF : ret =xe_guc_relay_process_guc2pf (&guc->relay, hxg, hxg_len);break ;
drivers/gpu/drm/xe/xe_guc_pagefault.c new file +94 -0
94 lines not on this page · raw message
drivers/gpu/drm/xe/xe_guc_pagefault.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_GUC_PAGEFAULT_H_ +#define _XE_GUC_PAGEFAULT_H_ + +#include <linux/types.h> + +int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len); + +#endif
drivers/gpu/drm/xe/xe_svm.c +1 -2
@@ -109,8 +109,7 @@ xe_svm_garbage_collector_add_range(struct xe_vm *vm, struct xe_svm_range *range, &vm->svm.garbage_collector.range_list);spin_unlock (&vm->svm.garbage_collector.lock); -queue_work (xe_device_get_root_tile (xe)->primary_gt->usm.pf_wq, - &vm->svm.garbage_collector.work); +queue_work (xe->usm.pf_wq, &vm->svm.garbage_collector.work); } static u8
drivers/gpu/drm/xe/xe_vm.c +0 -1
@@ -27,7 +27,6 @@#include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h" -#include "xe_gt_pagefault.h" #include "xe_gt_tlb_invalidation.h" #include "xe_migrate.h" #include "xe_pat.h"
Signature · 1 line
2.34.1
Re: [PATCH 06/11] drm/xe: Add xe_guc_pagefault layer
Quoted 207 lines · Matthew Brost
Add
xe_guc_pagefaultlayer (producer) which parses G2H fault messages messages into structxe_pagefault, forwards them to the page fault layer (consumer) for servicing, and provides a vfunc to acknowledge faults to the GuC upon completion. Replace the old (and incorrect) GT page fault layer with this new layer throughout the driver.Signed-off-bt: Matthew Brost <[email protected]>
--- drivers/gpu/drm/xe/Makefile | 2 +- drivers/gpu/drm/xe/xe_gt.c | 6 -- drivers/gpu/drm/xe/xe_guc_ct.c | 6 +- drivers/gpu/drm/xe/xe_guc_pagefault.c | 94 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_guc_pagefault.h | 13 ++++ drivers/gpu/drm/xe/xe_svm.c | 3 +- drivers/gpu/drm/xe/xe_vm.c | 1 - 7 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.hdrivers/gpu/drm/xe/Makefile +1
-1@@ -58,7 +58,6 @@ xe-y += xe_bb.o \ xe_gt_freq.o \ xe_gt_idle.o \ xe_gt_mcr.o \ - xe_gt_pagefault.o \ xe_gt_sysfs.o \ xe_gt_throttle.o \ xe_gt_tlb_invalidation.o \@@ -75,6 +74,7 @@ xe-y += xe_bb.o \ xe_guc_id_mgr.o \ xe_guc_klv_helpers.o \ xe_guc_log.o \ + xe_guc_pagefault.o \ xe_guc_pc.o \ xe_guc_submit.o \ xe_heci_gsc.o \drivers/gpu/drm/xe/xe_gt.c +0
-6@@ -32,7 +32,6 @@#include "xe_gt_freq.h" #include "xe_gt_idle.h" #include "xe_gt_mcr.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_vf.h" @@ -634,10 +633,6 @@ int xe_gt_init(struct xe_gt *gt)if (err)return err; - err =xe_gt_pagefault_init (gt); -if (err) -return err; - err =xe_gt_idle_init (>->gtidle);if (err)return err;@@ -848,7 +843,6 @@ static int gt_reset(struct xe_gt *gt)xe_uc_gucrc_disable (>->uc);xe_uc_stop_prepare (>->uc);xe_pagefault_reset (gt_to_xe (gt), gt); -xe_gt_pagefault_reset (gt);xe_uc_stop (>->uc);drivers/gpu/drm/xe/xe_guc_ct.c +1
-5@@ -21,7 +21,6 @@#include "xe_devcoredump.h" #include "xe_device.h" #include "xe_gt.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_monitor.h" @@ -29,6 +28,7 @@#include "xe_gt_tlb_invalidation.h" #include "xe_guc.h" #include "xe_guc_log.h" +#include "xe_guc_pagefault.h" #include "xe_guc_relay.h" #include "xe_guc_submit.h" #include "xe_map.h" @@ -1419,10 +1419,6 @@ static int process_g2h_msg(struct xe_guc_ct *ct, u32 *msg, u32 len) ret =xe_guc_tlb_invalidation_done_handler (guc, payload, adj_len);break ; -case XE_GUC_ACTION_ACCESS_COUNTER_NOTIFY : - ret =xe_guc_access_counter_notify_handler (guc, payload, - adj_len); -break ;case XE_GUC_ACTION_GUC2PF_RELAY_FROM_VF : ret =xe_guc_relay_process_guc2pf (&guc->relay, hxg, hxg_len);break ;drivers/gpu/drm/xe/xe_guc_pagefault.c new file +94
-0@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "abi/guc_actions_abi.h" +#include "xe_guc.h" +#include "xe_guc_ct.h" +#include "xe_guc_pagefault.h" +#include "xe_pagefault.h" + +static void guc_ack_fault (struct xe_pagefault *pf,int err) +{ +u32 vfid =FIELD_GET (PFD_VFID , pf->producer.msg[2 ]); +u32 engine_instance =FIELD_GET (PFD_ENG_INSTANCE , pf->producer.msg[0 ]); +u32 engine_class =FIELD_GET (PFD_ENG_CLASS , pf->producer.msg[0 ]); +u32 pdata =FIELD_GET (PFD_PDATA_LO , pf->producer.msg[0 ]) | + (FIELD_GET (PFD_PDATA_HI , pf->producer.msg[1 ]) << +PFD_PDATA_HI_SHIFT ); +u32 action[] = { +XE_GUC_ACTION_PAGE_FAULT_RES_DESC , + +FIELD_PREP (PFR_VALID ,1 ) | +FIELD_PREP (PFR_SUCCESS , !!err) | +FIELD_PREP (PFR_REPLY ,PFR_ACCESS ) | +FIELD_PREP (PFR_DESC_TYPE ,FAULT_RESPONSE_DESC ) | +FIELD_PREP (PFR_ASID , pf->consumer.asid), + +FIELD_PREP (PFR_VFID , vfid) | +FIELD_PREP (PFR_ENG_INSTANCE , engine_instance) | +FIELD_PREP (PFR_ENG_CLASS , engine_class) | +FIELD_PREP (PFR_PDATA , pdata), + }; +struct xe_guc *guc = pf->producer.private; + +xe_guc_ct_send (&guc->ct, action,ARRAY_SIZE (action),0 ,0 ); +} + +static const struct xe_pagefault_ops guc_pagefault_ops = { + .ack_fault = guc_ack_fault, +}; + +/** +* xe_guc_pagefault_handler() - G2H page fault handler +* @guc: GuC object +* @msg: G2H message +* @len: Length of G2H message +* +* Parse GuC to host (G2H) message into a struct xe_pagefault and forward onto +* the Xe page fault layer. +* +* Return: 0 on success, errno on failure +*/ +int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len) +{ +struct xe_pagefault pf; +int i; + +#define GUC_PF_MSG_LEN_DW \ + (sizeof(struct xe_guc_pagefault_desc) / sizeof(u32)) + +BUILD_BUG_ON (GUC_PF_MSG_LEN_DW >XE_PAGEFAULT_PRODUCER_MSG_LEN_DW ); + +if (len !=GUC_PF_MSG_LEN_DW ) +return -EPROTO ; + + pf.gt =guc_to_gt (guc); + +/* +* XXX: These values happen to match the enum in xe_pagefault_types.h. +* If that changes, we’ll need to remap them here. +*/ + pf.consumer.page_addr = (u64)(FIELD_GET (PFD_VIRTUAL_ADDR_HI , msg[3 ]) + <<PFD_VIRTUAL_ADDR_HI_SHIFT ) | + (FIELD_GET (PFD_VIRTUAL_ADDR_LO , msg[2 ]) << +PFD_VIRTUAL_ADDR_LO_SHIFT ); + pf.consumer.asid =FIELD_GET (PFD_ASID , msg[1 ]); + pf.consumer.access_type =FIELD_GET (PFD_ACCESS_TYPE , msg[2 ]);; + pf.consumer.fault_type =FIELD_GET (PFD_FAULT_TYPE , msg[2 ]); +if (FIELD_GET (XE2_PFD_TRVA_FAULT , msg[0 ])) + pf.consumer.fault_level =XE_PAGEFAULT_LEVEL_NACK ; +else + pf.consumer.fault_level =FIELD_GET (PFD_FAULT_LEVEL , msg[0 ]); + pf.consumer.engine_class =FIELD_GET (PFD_ENG_CLASS , msg[0 ]); + + pf.producer.private = guc; + pf.producer.ops = &guc_pagefault_ops; +for (i =0 ; i <GUC_PF_MSG_LEN_DW ; ++i) + pf.producer.msg[i] = msg[i]; + +#undef GUC_PF_MSG_LEN_DW + +return xe_pagefault_handler (guc_to_xe (guc), &pf); +}drivers/gpu/drm/xe/xe_guc_pagefault.h new file +0
-0
drivers/gpu/drm/xe/xe_guc_pagefault.h line 9
Quoted 9 lines
drivers/gpu/drm/xe/xe_guc_pagefault.h new file +9
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_GUC_PAGEFAULT_H_ +#define _XE_GUC_PAGEFAULT_H_ + +#include <linux/types.h>
For this to compile we are missing:
struct xe_guc;
Francois
Quoted 33 lines
drivers/gpu/drm/xe/xe_guc_pagefault.h new file +4
-0+ +int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len); + +#endif drivers/gpu/drm/xe/xe_svm.c +1
-2@@ -109,8 +109,7 @@ xe_svm_garbage_collector_add_range(struct xe_vm *vm, struct xe_svm_range *range, &vm->svm.garbage_collector.range_list);spin_unlock (&vm->svm.garbage_collector.lock); -queue_work (xe_device_get_root_tile (xe)->primary_gt->usm.pf_wq, - &vm->svm.garbage_collector.work); +queue_work (xe->usm.pf_wq, &vm->svm.garbage_collector.work); } static u8drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -27,7 +27,6 @@#include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h" -#include "xe_gt_pagefault.h" #include "xe_gt_tlb_invalidation.h" #include "xe_migrate.h" #include "xe_pat.h" Signature · 1 line
2.34.1
Matthew Brost
maintainerRe: [PATCH 06/11] drm/xe: Add xe_guc_pagefault layer
Quoted 220 lines · Francois Dugast
Quoted 207 lines · Matthew Brost
Add
xe_guc_pagefaultlayer (producer) which parses G2H fault messages messages into structxe_pagefault, forwards them to the page fault layer (consumer) for servicing, and provides a vfunc to acknowledge faults to the GuC upon completion. Replace the old (and incorrect) GT page fault layer with this new layer throughout the driver.Signed-off-bt: Matthew Brost <[email protected]>
--- drivers/gpu/drm/xe/Makefile | 2 +- drivers/gpu/drm/xe/xe_gt.c | 6 -- drivers/gpu/drm/xe/xe_guc_ct.c | 6 +- drivers/gpu/drm/xe/xe_guc_pagefault.c | 94 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_guc_pagefault.h | 13 ++++ drivers/gpu/drm/xe/xe_svm.c | 3 +- drivers/gpu/drm/xe/xe_vm.c | 1 - 7 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.c create mode 100644 drivers/gpu/drm/xe/xe_guc_pagefault.hdrivers/gpu/drm/xe/Makefile +1
-1@@ -58,7 +58,6 @@ xe-y += xe_bb.o \ xe_gt_freq.o \ xe_gt_idle.o \ xe_gt_mcr.o \ - xe_gt_pagefault.o \ xe_gt_sysfs.o \ xe_gt_throttle.o \ xe_gt_tlb_invalidation.o \@@ -75,6 +74,7 @@ xe-y += xe_bb.o \ xe_guc_id_mgr.o \ xe_guc_klv_helpers.o \ xe_guc_log.o \ + xe_guc_pagefault.o \ xe_guc_pc.o \ xe_guc_submit.o \ xe_heci_gsc.o \drivers/gpu/drm/xe/xe_gt.c +0
-6@@ -32,7 +32,6 @@#include "xe_gt_freq.h" #include "xe_gt_idle.h" #include "xe_gt_mcr.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_vf.h" @@ -634,10 +633,6 @@ int xe_gt_init(struct xe_gt *gt)if (err)return err; - err =xe_gt_pagefault_init (gt); -if (err) -return err; - err =xe_gt_idle_init (>->gtidle);if (err)return err;@@ -848,7 +843,6 @@ static int gt_reset(struct xe_gt *gt)xe_uc_gucrc_disable (>->uc);xe_uc_stop_prepare (>->uc);xe_pagefault_reset (gt_to_xe (gt), gt); -xe_gt_pagefault_reset (gt);xe_uc_stop (>->uc);drivers/gpu/drm/xe/xe_guc_ct.c +1
-5@@ -21,7 +21,6 @@#include "xe_devcoredump.h" #include "xe_device.h" #include "xe_gt.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_monitor.h" @@ -29,6 +28,7 @@#include "xe_gt_tlb_invalidation.h" #include "xe_guc.h" #include "xe_guc_log.h" +#include "xe_guc_pagefault.h" #include "xe_guc_relay.h" #include "xe_guc_submit.h" #include "xe_map.h" @@ -1419,10 +1419,6 @@ static int process_g2h_msg(struct xe_guc_ct *ct, u32 *msg, u32 len) ret =xe_guc_tlb_invalidation_done_handler (guc, payload, adj_len);break ; -case XE_GUC_ACTION_ACCESS_COUNTER_NOTIFY : - ret =xe_guc_access_counter_notify_handler (guc, payload, - adj_len); -break ;case XE_GUC_ACTION_GUC2PF_RELAY_FROM_VF : ret =xe_guc_relay_process_guc2pf (&guc->relay, hxg, hxg_len);break ;drivers/gpu/drm/xe/xe_guc_pagefault.c new file +94
-0@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "abi/guc_actions_abi.h" +#include "xe_guc.h" +#include "xe_guc_ct.h" +#include "xe_guc_pagefault.h" +#include "xe_pagefault.h" + +static void guc_ack_fault (struct xe_pagefault *pf,int err) +{ +u32 vfid =FIELD_GET (PFD_VFID , pf->producer.msg[2 ]); +u32 engine_instance =FIELD_GET (PFD_ENG_INSTANCE , pf->producer.msg[0 ]); +u32 engine_class =FIELD_GET (PFD_ENG_CLASS , pf->producer.msg[0 ]); +u32 pdata =FIELD_GET (PFD_PDATA_LO , pf->producer.msg[0 ]) | + (FIELD_GET (PFD_PDATA_HI , pf->producer.msg[1 ]) << +PFD_PDATA_HI_SHIFT ); +u32 action[] = { +XE_GUC_ACTION_PAGE_FAULT_RES_DESC , + +FIELD_PREP (PFR_VALID ,1 ) | +FIELD_PREP (PFR_SUCCESS , !!err) | +FIELD_PREP (PFR_REPLY ,PFR_ACCESS ) | +FIELD_PREP (PFR_DESC_TYPE ,FAULT_RESPONSE_DESC ) | +FIELD_PREP (PFR_ASID , pf->consumer.asid), + +FIELD_PREP (PFR_VFID , vfid) | +FIELD_PREP (PFR_ENG_INSTANCE , engine_instance) | +FIELD_PREP (PFR_ENG_CLASS , engine_class) | +FIELD_PREP (PFR_PDATA , pdata), + }; +struct xe_guc *guc = pf->producer.private; + +xe_guc_ct_send (&guc->ct, action,ARRAY_SIZE (action),0 ,0 ); +} + +static const struct xe_pagefault_ops guc_pagefault_ops = { + .ack_fault = guc_ack_fault, +}; + +/** +* xe_guc_pagefault_handler() - G2H page fault handler +* @guc: GuC object +* @msg: G2H message +* @len: Length of G2H message +* +* Parse GuC to host (G2H) message into a struct xe_pagefault and forward onto +* the Xe page fault layer. +* +* Return: 0 on success, errno on failure +*/ +int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len) +{ +struct xe_pagefault pf; +int i; + +#define GUC_PF_MSG_LEN_DW \ + (sizeof(struct xe_guc_pagefault_desc) / sizeof(u32)) + +BUILD_BUG_ON (GUC_PF_MSG_LEN_DW >XE_PAGEFAULT_PRODUCER_MSG_LEN_DW ); + +if (len !=GUC_PF_MSG_LEN_DW ) +return -EPROTO ; + + pf.gt =guc_to_gt (guc); + +/* +* XXX: These values happen to match the enum in xe_pagefault_types.h. +* If that changes, we’ll need to remap them here. +*/ + pf.consumer.page_addr = (u64)(FIELD_GET (PFD_VIRTUAL_ADDR_HI , msg[3 ]) + <<PFD_VIRTUAL_ADDR_HI_SHIFT ) | + (FIELD_GET (PFD_VIRTUAL_ADDR_LO , msg[2 ]) << +PFD_VIRTUAL_ADDR_LO_SHIFT ); + pf.consumer.asid =FIELD_GET (PFD_ASID , msg[1 ]); + pf.consumer.access_type =FIELD_GET (PFD_ACCESS_TYPE , msg[2 ]);; + pf.consumer.fault_type =FIELD_GET (PFD_FAULT_TYPE , msg[2 ]); +if (FIELD_GET (XE2_PFD_TRVA_FAULT , msg[0 ])) + pf.consumer.fault_level =XE_PAGEFAULT_LEVEL_NACK ; +else + pf.consumer.fault_level =FIELD_GET (PFD_FAULT_LEVEL , msg[0 ]); + pf.consumer.engine_class =FIELD_GET (PFD_ENG_CLASS , msg[0 ]); + + pf.producer.private = guc; + pf.producer.ops = &guc_pagefault_ops; +for (i =0 ; i <GUC_PF_MSG_LEN_DW ; ++i) + pf.producer.msg[i] = msg[i]; + +#undef GUC_PF_MSG_LEN_DW + +return xe_pagefault_handler (guc_to_xe (guc), &pf); +}drivers/gpu/drm/xe/xe_guc_pagefault.h new file +0
-0drivers/gpu/drm/xe/xe_guc_pagefault.h line 9
Quoted 9 lines
drivers/gpu/drm/xe/xe_guc_pagefault.h new file +9
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_GUC_PAGEFAULT_H_ +#define _XE_GUC_PAGEFAULT_H_ + +#include <linux/types.h> For this to compile we are missing:
Quoted 2 lines
struct xe_guc;
Yes. This was compiling on my machine without this but something recently changed and this is required. Will fix.
Quoted 35 lines
Francois
Quoted 33 lines
drivers/gpu/drm/xe/xe_guc_pagefault.h new file +4
-0+ +int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len); + +#endif drivers/gpu/drm/xe/xe_svm.c +1
-2@@ -109,8 +109,7 @@ xe_svm_garbage_collector_add_range(struct xe_vm *vm, struct xe_svm_range *range, &vm->svm.garbage_collector.range_list);spin_unlock (&vm->svm.garbage_collector.lock); -queue_work (xe_device_get_root_tile (xe)->primary_gt->usm.pf_wq, - &vm->svm.garbage_collector.work); +queue_work (xe->usm.pf_wq, &vm->svm.garbage_collector.work); } static u8drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -27,7 +27,6 @@#include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h" -#include "xe_gt_pagefault.h" #include "xe_gt_tlb_invalidation.h" #include "xe_migrate.h" #include "xe_pat.h" Signature · 1 line
2.34.1
Re: [PATCH 06/11] drm/xe: Add xe_guc_pagefault layer
In reply to Matthew BrostQuoted 198 lines · Matthew Brost
Add
xe_guc_pagefaultlayer (producer) which parses G2H fault messages messages into structxe_pagefault, forwards them to the page fault layer
(consumer) for servicing, and provides a vfunc to acknowledge faults to
the GuC upon completion. Replace the old (and incorrect) GT page fault
layer with this new layer throughout the driver.Signed-off-bt: Matthew Brost <[email protected]>
---
drivers/gpu/drm/xe/Makefile | 2 +- drivers/gpu/drm/xe/xe_gt.c | 6 -- drivers/gpu/drm/xe/xe_guc_ct.c | 6 +-drivers/gpu/drm/xe/xe_guc_pagefault.c| 94
+++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_guc_pagefault.h | 13 ++++ drivers/gpu/drm/xe/xe_svm.c | 3 +- drivers/gpu/drm/xe/xe_vm.c | 1 -7 files changed, 110 insertions(+), 15 deletions(-)create mode 100644
drivers/gpu/drm/xe/xe_guc_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_guc_pagefault.hdrivers/gpu/drm/xe/Makefile +1
-1@@ -58,7 +58,6 @@ xe-y += xe_bb.o \ xe_gt_freq.o \ xe_gt_idle.o \ xe_gt_mcr.o \ - xe_gt_pagefault.o \ xe_gt_sysfs.o \ xe_gt_throttle.o \ xe_gt_tlb_invalidation.o \@@ -75,6 +74,7 @@ xe-y += xe_bb.o \ xe_guc_id_mgr.o \ xe_guc_klv_helpers.o \ xe_guc_log.o \ + xe_guc_pagefault.o \ xe_guc_pc.o \ xe_guc_submit.o \ xe_heci_gsc.o \drivers/gpu/drm/xe/xe_gt.c +0
-1@@ -32,7 +32,6 @@ #include "xe_gt_freq.h" #include "xe_gt_idle.h" #include "xe_gt_mcr.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_vf.h"@@ -634,10 +633,6 @@ int xe_gt_init(struct xe_gt *gt) if (err) return err;
- err =xe_gt_pagefault_init(gt);
- if (err)
- return err;
-
err =xe_gt_idle_init(>->gtidle);
if (err)
return err;drivers/gpu/drm/xe/xe_gt.c +0
-1@@ -848,7 +843,6 @@ static int gt_reset(struct xe_gt *gt) xe_uc_gucrc_disable(>->uc); xe_uc_stop_prepare(>->uc); xe_pagefault_reset(gt_to_xe(gt), gt); - xe_gt_pagefault_reset(gt);
xe_uc_stop(>->uc);drivers/gpu/drm/xe/xe_guc_ct.c +1
-5@@ -21,7 +21,6 @@ #include "xe_devcoredump.h" #include "xe_device.h" #include "xe_gt.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_monitor.h"@@ -29,6 +28,7 @@ #include "xe_gt_tlb_invalidation.h" #include "xe_guc.h" #include "xe_guc_log.h" +#include "xe_guc_pagefault.h" #include "xe_guc_relay.h" #include "xe_guc_submit.h" #include "xe_map.h"@@ -1419,10 +1419,6 @@ static int process_g2h_msg(struct xe_guc_ct *ct, u32 *msg, u32 len) ret = xe_guc_tlb_invalidation_done_handler(guc, payload, adj_len); break; - case XE_GUC_ACTION_ACCESS_COUNTER_NOTIFY: - ret = xe_guc_access_counter_notify_handler(guc, payload, - adj_len); - break;case
XE_GUC_ACTION_GUC2PF_RELAY_FROM_VF:
ret =xe_guc_relay_process_guc2pf(&guc->relay, hxg, hxg_len);
break;drivers/gpu/drm/xe/xe_guc_pagefault.c new file +15
-0@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "abi/guc_actions_abi.h" +#include "xe_guc.h" +#include "xe_guc_ct.h" +#include "xe_guc_pagefault.h" +#include "xe_pagefault.h" + +static void guc_ack_fault (struct xe_pagefault *pf,int err) +{ + u32 vfid = FIELD_GET(PFD_VFID, pf->producer.msg[2]); + u32 engine_instance = FIELD_GET(PFD_ENG_INSTANCE, pf-Quoted 1 line
producer.msg[0]);
+ u32
engine_class= FIELD_GET(PFD_ENG_CLASS, pf-Quoted 1 line
producer.msg[0]);
+ u32 pdata =
FIELD_GET(PFD_PDATA_LO, pf->producer.msg[0])| + (FIELD_GET(PFD_PDATA_HI, pf->producer.msg[1]) << +PFD_PDATA_HI_SHIFT);
+ u32 action[] = {
+ XE_GUC_ACTION_PAGE_FAULT_RES_DESC,drivers/gpu/drm/xe/xe_guc_pagefault.c new file +28
-0+ + FIELD_PREP(PFR_VALID, 1) | + FIELD_PREP(PFR_SUCCESS, !!err) | + FIELD_PREP(PFR_REPLY, PFR_ACCESS) | + FIELD_PREP(PFR_DESC_TYPE, FAULT_RESPONSE_DESC) | + FIELD_PREP(PFR_ASID, pf->consumer.asid), + + FIELD_PREP(PFR_VFID, vfid) | + FIELD_PREP(PFR_ENG_INSTANCE, engine_instance) | + FIELD_PREP(PFR_ENG_CLASS, engine_class) | + FIELD_PREP(PFR_PDATA, pdata), + }; + struct xe_guc *guc = pf->producer.private; + + xe_guc_ct_send(&guc->ct, action, ARRAY_SIZE(action), 0, 0); +} + +static const struct xe_pagefault_ops guc_pagefault_ops = { + .ack_fault = guc_ack_fault, +}; + +/** +* xe_guc_pagefault_handler() - G2H page fault handler +* @guc: GuC object +* @msg: G2H message +* @len: Length of G2H message +* +* Parse GuC to host (G2H) message into a struct xe_pagefault and forward onto
+ * the Xe page fault layer.
+ *
+ * Return: 0 on success, errno on failure
+ */drivers/gpu/drm/xe/xe_guc_pagefault.c new file +9
-0+int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len) +{ + struct xe_pagefault pf; + int i; + +#define GUC_PF_MSG_LEN_DW \ + (sizeof(struct xe_guc_pagefault_desc) / sizeof(u32)) + + BUILD_BUG_ON(GUC_PF_MSG_LEN_DW >
XE_PAGEFAULT_PRODUCER_MSG_LEN_DW);drivers/gpu/drm/xe/xe_guc_pagefault.c new file +8
-0+ + if (len != GUC_PF_MSG_LEN_DW) + return -EPROTO; + + pf.gt = guc_to_gt(guc); + + /* +* XXX: These values happen to match the enum in
xe_pagefault_types.h.
+ * If that changes, we’ll need to remap them here. + */
+ pf.consumer.page_addr = (u64)(FIELD_GET(PFD_VIRTUAL_ADDR_HI, msg[3])
+ <<PFD_VIRTUAL_ADDR_HI_SHIFT) |
Quoted 8 lines
+ (FIELD_GET(PFD_VIRTUAL_ADDR_LO, msg[2]) << +
PFD_VIRTUAL_ADDR_LO_SHIFT);
+ pf.consumer.asid =FIELD_GET(PFD_ASID, msg[1]); + pf.consumer.access_type =FIELD_GET(PFD_ACCESS_TYPE, msg[2]);;
+ pf.consumer.fault_type =FIELD_GET(PFD_FAULT_TYPE, msg[2]); + if (FIELD_GET(XE2_PFD_TRVA_FAULT, msg[0]))
+ pf.consumer.fault_level =XE_PAGEFAULT_LEVEL_NACK;
We have a comment in the current implementation that says "sw isn't expected to handle trtt faults". At a minimum it would be nice to keep that here.
But really it would be nice to have a little documentation here as to *why* we don't care about these types of faults. Should we print something if this shows up, at least for debug?
Quoted 4 lines
+ else
+ pf.consumer.fault_level =FIELD_GET(PFD_FAULT_LEVEL, msg[0]);
+ pf.consumer.engine_class =FIELD_GET(PFD_ENG_CLASS, msg[0]);
Again I think we should log the instance here as well.
Thanks,
Stuart
Quoted 59 lines
drivers/gpu/drm/xe/xe_guc_pagefault.c new file +10
-0+ + pf.producer.private = guc; + pf.producer.ops = &guc_pagefault_ops; + for (i = 0; i < GUC_PF_MSG_LEN_DW; ++i) + pf.producer.msg[i] = msg[i]; + +#undef GUC_PF_MSG_LEN_DW + + return xe_pagefault_handler(guc_to_xe(guc), &pf); +}drivers/gpu/drm/xe/xe_guc_pagefault.h new file +13
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_GUC_PAGEFAULT_H_ +#define _XE_GUC_PAGEFAULT_H_ + +#include <linux/types.h> + +int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len); + +#endif drivers/gpu/drm/xe/xe_svm.c +0
-0@@ -109,8 +109,7 @@ xe_svm_garbage_collector_add_range(struct xe_vm *vm, struct xe_svm_range *range, &vm->svm.garbage_collector.range_list); spin_unlock(&vm->svm.garbage_collector.lock);
- queue_work(xe_device_get_root_tile(xe)->primary_gt-Quoted 1 line
usm.pf_wq,
-
&vm->svm.garbage_collector.work);
+ queue_work(xe->usm.pf_wq,&vm->svm.garbage_collector.work); }
static u8drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -27,7 +27,6 @@ #include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h" -#include "xe_gt_pagefault.h" #include "xe_gt_tlb_invalidation.h" #include "xe_migrate.h" #include "xe_pat.h"
Matthew Brost
maintainerRe: [PATCH 06/11] drm/xe: Add xe_guc_pagefault layer
Quoted 212 lines · Stuart
Quoted 198 lines · Matthew Brost
Add
xe_guc_pagefaultlayer (producer) which parses G2H fault messages messages into structxe_pagefault, forwards them to the page fault layer
(consumer) for servicing, and provides a vfunc to acknowledge faults to
the GuC upon completion. Replace the old (and incorrect) GT page fault
layer with this new layer throughout the driver.Signed-off-bt: Matthew Brost <[email protected]>
---
drivers/gpu/drm/xe/Makefile | 2 +- drivers/gpu/drm/xe/xe_gt.c | 6 -- drivers/gpu/drm/xe/xe_guc_ct.c | 6 +-drivers/gpu/drm/xe/xe_guc_pagefault.c| 94
+++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_guc_pagefault.h | 13 ++++ drivers/gpu/drm/xe/xe_svm.c | 3 +- drivers/gpu/drm/xe/xe_vm.c | 1 -7 files changed, 110 insertions(+), 15 deletions(-)create mode 100644
drivers/gpu/drm/xe/xe_guc_pagefault.ccreate mode 100644drivers/gpu/drm/xe/xe_guc_pagefault.hdrivers/gpu/drm/xe/Makefile +1
-1@@ -58,7 +58,6 @@ xe-y += xe_bb.o \ xe_gt_freq.o \ xe_gt_idle.o \ xe_gt_mcr.o \ - xe_gt_pagefault.o \ xe_gt_sysfs.o \ xe_gt_throttle.o \ xe_gt_tlb_invalidation.o \@@ -75,6 +74,7 @@ xe-y += xe_bb.o \ xe_guc_id_mgr.o \ xe_guc_klv_helpers.o \ xe_guc_log.o \ + xe_guc_pagefault.o \ xe_guc_pc.o \ xe_guc_submit.o \ xe_heci_gsc.o \drivers/gpu/drm/xe/xe_gt.c +0
-1@@ -32,7 +32,6 @@ #include "xe_gt_freq.h" #include "xe_gt_idle.h" #include "xe_gt_mcr.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_vf.h"@@ -634,10 +633,6 @@ int xe_gt_init(struct xe_gt *gt) if (err) return err;
- err =xe_gt_pagefault_init(gt);
- if (err)
- return err;
-
err =xe_gt_idle_init(>->gtidle);
if (err)
return err;drivers/gpu/drm/xe/xe_gt.c +0
-1@@ -848,7 +843,6 @@ static int gt_reset(struct xe_gt *gt) xe_uc_gucrc_disable(>->uc); xe_uc_stop_prepare(>->uc); xe_pagefault_reset(gt_to_xe(gt), gt); - xe_gt_pagefault_reset(gt);
xe_uc_stop(>->uc);drivers/gpu/drm/xe/xe_guc_ct.c +1
-5@@ -21,7 +21,6 @@ #include "xe_devcoredump.h" #include "xe_device.h" #include "xe_gt.h" -#include "xe_gt_pagefault.h" #include "xe_gt_printk.h" #include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_monitor.h"@@ -29,6 +28,7 @@ #include "xe_gt_tlb_invalidation.h" #include "xe_guc.h" #include "xe_guc_log.h" +#include "xe_guc_pagefault.h" #include "xe_guc_relay.h" #include "xe_guc_submit.h" #include "xe_map.h"@@ -1419,10 +1419,6 @@ static int process_g2h_msg(struct xe_guc_ct *ct, u32 *msg, u32 len) ret = xe_guc_tlb_invalidation_done_handler(guc, payload, adj_len); break; - case XE_GUC_ACTION_ACCESS_COUNTER_NOTIFY: - ret = xe_guc_access_counter_notify_handler(guc, payload, - adj_len); - break;case
XE_GUC_ACTION_GUC2PF_RELAY_FROM_VF:
ret =xe_guc_relay_process_guc2pf(&guc->relay, hxg, hxg_len);
break;drivers/gpu/drm/xe/xe_guc_pagefault.c new file +15
-0@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2025 Intel Corporation +*/ + +#include "abi/guc_actions_abi.h" +#include "xe_guc.h" +#include "xe_guc_ct.h" +#include "xe_guc_pagefault.h" +#include "xe_pagefault.h" + +static void guc_ack_fault (struct xe_pagefault *pf,int err) +{ + u32 vfid = FIELD_GET(PFD_VFID, pf->producer.msg[2]); + u32 engine_instance = FIELD_GET(PFD_ENG_INSTANCE, pf-Quoted 1 line
producer.msg[0]);
+ u32
engine_class= FIELD_GET(PFD_ENG_CLASS, pf-Quoted 1 line
producer.msg[0]);
+ u32 pdata =
FIELD_GET(PFD_PDATA_LO, pf->producer.msg[0])| + (FIELD_GET(PFD_PDATA_HI, pf->producer.msg[1]) << +PFD_PDATA_HI_SHIFT);
+ u32 action[] = {
+ XE_GUC_ACTION_PAGE_FAULT_RES_DESC,drivers/gpu/drm/xe/xe_guc_pagefault.c new file +28
-0+ + FIELD_PREP(PFR_VALID, 1) | + FIELD_PREP(PFR_SUCCESS, !!err) | + FIELD_PREP(PFR_REPLY, PFR_ACCESS) | + FIELD_PREP(PFR_DESC_TYPE, FAULT_RESPONSE_DESC) | + FIELD_PREP(PFR_ASID, pf->consumer.asid), + + FIELD_PREP(PFR_VFID, vfid) | + FIELD_PREP(PFR_ENG_INSTANCE, engine_instance) | + FIELD_PREP(PFR_ENG_CLASS, engine_class) | + FIELD_PREP(PFR_PDATA, pdata), + }; + struct xe_guc *guc = pf->producer.private; + + xe_guc_ct_send(&guc->ct, action, ARRAY_SIZE(action), 0, 0); +} + +static const struct xe_pagefault_ops guc_pagefault_ops = { + .ack_fault = guc_ack_fault, +}; + +/** +* xe_guc_pagefault_handler() - G2H page fault handler +* @guc: GuC object +* @msg: G2H message +* @len: Length of G2H message +* +* Parse GuC to host (G2H) message into a struct xe_pagefault and forward onto
+ * the Xe page fault layer.
+ *
+ * Return: 0 on success, errno on failure
+ */drivers/gpu/drm/xe/xe_guc_pagefault.c new file +9
-0+int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len) +{ + struct xe_pagefault pf; + int i; + +#define GUC_PF_MSG_LEN_DW \ + (sizeof(struct xe_guc_pagefault_desc) / sizeof(u32)) + + BUILD_BUG_ON(GUC_PF_MSG_LEN_DW >
XE_PAGEFAULT_PRODUCER_MSG_LEN_DW);drivers/gpu/drm/xe/xe_guc_pagefault.c new file +8
-0+ + if (len != GUC_PF_MSG_LEN_DW) + return -EPROTO; + + pf.gt = guc_to_gt(guc); + + /* +* XXX: These values happen to match the enum in
xe_pagefault_types.h.
+ * If that changes, we’ll need to remap them here. + */
+ pf.consumer.page_addr = (u64)(FIELD_GET(PFD_VIRTUAL_ADDR_HI, msg[3])
+ <<PFD_VIRTUAL_ADDR_HI_SHIFT) |Quoted 8 lines
+ (FIELD_GET(PFD_VIRTUAL_ADDR_LO, msg[2]) << +
PFD_VIRTUAL_ADDR_LO_SHIFT);
+ pf.consumer.asid =FIELD_GET(PFD_ASID, msg[1]); + pf.consumer.access_type =FIELD_GET(PFD_ACCESS_TYPE, msg[2]);;
+ pf.consumer.fault_type =FIELD_GET(PFD_FAULT_TYPE, msg[2]); + if (FIELD_GET(XE2_PFD_TRVA_FAULT, msg[0]))
+ pf.consumer.fault_level =XE_PAGEFAULT_LEVEL_NACK;We have a comment in the current implementation that says "sw isn't expected to handle trtt faults". At a minimum it would be nice to keep that here.
Quoted 4 lines
But really it would be nice to have a little documentation here as to *why* we don't care about these types of faults. Should we print something if this shows up, at least for debug?
I can add a comment but why we don't expect these faults, I really have no idea. I believe I copied this code from the i915 without any real thought.
Quoted 7 lines
Quoted 4 lines
+ else
+ pf.consumer.fault_level =FIELD_GET(PFD_FAULT_LEVEL, msg[0]);
+ pf.consumer.engine_class =FIELD_GET(PFD_ENG_CLASS, msg[0]);Again I think we should log the instance here as well.
Sure.
Matt
Quoted 64 lines
Thanks,
StuartQuoted 59 lines
drivers/gpu/drm/xe/xe_guc_pagefault.c new file +10
-0+ + pf.producer.private = guc; + pf.producer.ops = &guc_pagefault_ops; + for (i = 0; i < GUC_PF_MSG_LEN_DW; ++i) + pf.producer.msg[i] = msg[i]; + +#undef GUC_PF_MSG_LEN_DW + + return xe_pagefault_handler(guc_to_xe(guc), &pf); +}drivers/gpu/drm/xe/xe_guc_pagefault.h new file +13
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_GUC_PAGEFAULT_H_ +#define _XE_GUC_PAGEFAULT_H_ + +#include <linux/types.h> + +int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len); + +#endif drivers/gpu/drm/xe/xe_svm.c +0
-0@@ -109,8 +109,7 @@ xe_svm_garbage_collector_add_range(struct xe_vm *vm, struct xe_svm_range *range, &vm->svm.garbage_collector.range_list); spin_unlock(&vm->svm.garbage_collector.lock);
- queue_work(xe_device_get_root_tile(xe)->primary_gt-Quoted 1 line
usm.pf_wq,
-
&vm->svm.garbage_collector.work);
+ queue_work(xe->usm.pf_wq,&vm->svm.garbage_collector.work); }
static u8drivers/gpu/drm/xe/xe_vm.c +0
-1@@ -27,7 +27,6 @@ #include "xe_device.h" #include "xe_drm_client.h" #include "xe_exec_queue.h" -#include "xe_gt_pagefault.h" #include "xe_gt_tlb_invalidation.h" #include "xe_migrate.h" #include "xe_pat.h"
Matthew Brost
maintainerPATCH 7/11 drm/xe: Remove unused GT page fault code
In reply to Matthew BrostWith the Xe page fault layer and GuC page layer in place, this is now dead code and can be removed. ACC code is also removed, but this was dead code.
--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 691 --------------------------- drivers/gpu/drm/xe/xe_gt_pagefault.h | 19 - drivers/gpu/drm/xe/xe_gt_types.h | 65 --- 3 files changed, 775 deletions(-) delete mode 100644 drivers/gpu/drm/xe/xe_gt_pagefault.c delete mode 100644 drivers/gpu/drm/xe/xe_gt_pagefault.h
drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0 -691
@@ -1,691 +0,0 @@ -// SPDX-License-Identifier: MIT -/* -* Copyright © 2022 Intel Corporation -*/ - -#include "xe_gt_pagefault.h" - -#include <linux/bitfield.h> -#include <linux/circ_buf.h> - -#include <drm/drm_exec.h> -#include <drm/drm_managed.h> - -#include "abi/guc_actions_abi.h" -#include "xe_bo.h" -#include "xe_gt.h" -#include "xe_gt_printk.h" -#include "xe_gt_stats.h" -#include "xe_gt_tlb_invalidation.h" -#include "xe_guc.h" -#include "xe_guc_ct.h" -#include "xe_migrate.h" -#include "xe_svm.h" -#include "xe_trace_bo.h" -#include "xe_vm.h" -#include "xe_vram_types.h" - -struct pagefault { -u64 page_addr; -u32 asid; -u16 pdata; -u8 vfid; -u8 access_type; -u8 fault_type; -u8 fault_level; -u8 engine_class; -u8 engine_instance; -u8 fault_unsuccessful; -bool trva_fault; -}; - -enum access_type { -ACCESS_TYPE_READ =0 , -ACCESS_TYPE_WRITE =1 , -ACCESS_TYPE_ATOMIC =2 , -ACCESS_TYPE_RESERVED =3 , -}; - -enum fault_type { -NOT_PRESENT =0 , -WRITE_ACCESS_VIOLATION =1 , -ATOMIC_ACCESS_VIOLATION =2 , -}; - -struct acc { -u64 va_range_base; -u32 asid; -u32 sub_granularity; -u8 granularity; -u8 vfid; -u8 access_type; -u8 engine_class; -u8 engine_instance; -}; - -static bool access_is_atomic (enum access_type access_type) -{ -return access_type ==ACCESS_TYPE_ATOMIC ; -} - -static bool vma_is_valid (struct xe_tile *tile,struct xe_vma *vma) -{ -return xe_vm_has_valid_gpu_mapping (tile, vma->tile_present, - vma->tile_invalidated); -} - -static int xe_pf_begin (struct drm_exec *exec,struct xe_vma *vma, -bool atomic,struct xe_vram_region *vram) -{ -struct xe_bo *bo =xe_vma_bo (vma); -struct xe_vm *vm =xe_vma_vm (vma); -int err; - - err =xe_vm_lock_vma (exec, vma); -if (err) -return err; - -if (atomic && vram) { -xe_assert (vm->xe,IS_DGFX (vm->xe)); - -if (xe_vma_is_userptr (vma)) { - err = -EACCES ; -return err; - } - -/* Migrate to VRAM, move should invalidate the VMA first */ - err =xe_bo_migrate (bo, vram->placement); -if (err) -return err; - }else if (bo) { -/* Create backing store if needed */ - err =xe_bo_validate (bo, vm, true); -if (err) -return err; - } - -return 0 ; -} - -static int handle_vma_pagefault (struct xe_gt *gt,struct xe_vma *vma, -bool atomic) -{ -struct xe_vm *vm =xe_vma_vm (vma); -struct xe_tile *tile =gt_to_tile (gt); -struct drm_exec exec; -struct dma_fence *fence; -ktime_t end =0 ; -int err; - -lockdep_assert_held_write (&vm->lock); - -xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT ,1 ); -xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_KB ,xe_vma_size (vma) /1024 ); - -trace_xe_vma_pagefault (vma); - -/* Check if VMA is valid, opportunistic check only */ -if (vma_is_valid (tile, vma) && !atomic) -return 0 ; - -retry_userptr: -if (xe_vma_is_userptr (vma) && -xe_vma_userptr_check_repin (to_userptr_vma (vma))) { -struct xe_userptr_vma *uvma =to_userptr_vma (vma); - - err =xe_vma_userptr_pin_pages (uvma); -if (err) -return err; - } - -/* Lock VM and BOs dma-resv */ -drm_exec_init (&exec,0 ,0 ); - drm_exec_until_all_locked(&exec) { - err =xe_pf_begin (&exec, vma, atomic, tile->mem.vram); -drm_exec_retry_on_contention (&exec); -if (xe_vm_validate_should_retry (&exec, err, &end)) - err = -EAGAIN ; -if (err) - goto unlock_dma_resv; - -/* Bind VMA only to the GT that has faulted */ -trace_xe_vma_pf_bind (vma); - fence =xe_vma_rebind (vm, vma,BIT (tile->id)); -if (IS_ERR (fence)) { - err =PTR_ERR (fence); -if (xe_vm_validate_should_retry (&exec, err, &end)) - err = -EAGAIN ; - goto unlock_dma_resv; - } - } - -dma_fence_wait (fence, false); -dma_fence_put (fence); - -unlock_dma_resv: -drm_exec_fini (&exec); -if (err == -EAGAIN ) - goto retry_userptr; - -return err; -} - -static struct xe_vm *asid_to_vm (struct xe_device *xe,u32 asid) -{ -struct xe_vm *vm; - -down_read (&xe->usm.lock); - vm =xa_load (&xe->usm.asid_to_vm, asid); -if (vm &&xe_vm_in_fault_mode (vm)) -xe_vm_get (vm); -else - vm =ERR_PTR (-EINVAL ); -up_read (&xe->usm.lock); - -return vm; -} - -static int handle_pagefault (struct xe_gt *gt,struct pagefault *pf) -{ -struct xe_device *xe =gt_to_xe (gt); -struct xe_vm *vm; -struct xe_vma *vma =NULL ; -int err; -bool atomic; - -/* SW isn't expected to handle TRTT faults */ -if (pf->trva_fault) -return -EFAULT ; - - vm =asid_to_vm (xe, pf->asid); -if (IS_ERR (vm)) -return PTR_ERR (vm); - -/* -* TODO: Change to read lock? Using write lock for simplicity. -*/ -down_write (&vm->lock); - -if (xe_vm_is_closed (vm)) { - err = -ENOENT ; - goto unlock_vm; - } - - vma =xe_vm_find_vma_by_addr (vm, pf->page_addr); -if (!vma) { - err = -EINVAL ; - goto unlock_vm; - } - - atomic =access_is_atomic (pf->access_type); - -if (xe_vma_is_cpu_addr_mirror (vma)) - err =xe_svm_handle_pagefault (vm, vma, gt, - pf->page_addr, atomic); -else - err =handle_vma_pagefault (gt, vma, atomic); - -unlock_vm: -if (!err) - vm->usm.last_fault_vma = vma; -up_write (&vm->lock); -xe_vm_put (vm); - -return err; -} - -static int send_pagefault_reply (struct xe_guc *guc, -struct xe_guc_pagefault_reply *reply) -{ -u32 action[] = { -XE_GUC_ACTION_PAGE_FAULT_RES_DESC , - reply->dw0, - reply->dw1, - }; - -return xe_guc_ct_send (&guc->ct, action,ARRAY_SIZE (action),0 ,0 ); -} - -static void print_pagefault (struct xe_gt *gt,struct pagefault *pf) -{ -xe_gt_dbg (gt,"\n\tASID: %d\n" -"\tVFID: %d\n" -"\tPDATA: 0x%04x\n" -"\tFaulted Address: 0x%08x%08x\n" -"\tFaultType: %d\n" -"\tAccessType: %d\n" -"\tFaultLevel: %d\n" -"\tEngineClass: %d %s\n" -"\tEngineInstance: %d\n" , - pf->asid, pf->vfid, pf->pdata,upper_32_bits (pf->page_addr), -lower_32_bits (pf->page_addr), - pf->fault_type, pf->access_type, pf->fault_level, - pf->engine_class,xe_hw_engine_class_to_str (pf->engine_class), - pf->engine_instance); -} - -#define PF_MSG_LEN_DW 4 - -static bool get_pagefault (struct pf_queue *pf_queue,struct pagefault *pf) -{ -const struct xe_guc_pagefault_desc *desc; -bool ret = false; - -spin_lock_irq (&pf_queue->lock); -if (pf_queue->tail != pf_queue->head) { - desc = (const struct xe_guc_pagefault_desc *) - (pf_queue->data + pf_queue->tail); - - pf->fault_level =FIELD_GET (PFD_FAULT_LEVEL , desc->dw0); - pf->trva_fault =FIELD_GET (XE2_PFD_TRVA_FAULT , desc->dw0); - pf->engine_class =FIELD_GET (PFD_ENG_CLASS , desc->dw0); - pf->engine_instance =FIELD_GET (PFD_ENG_INSTANCE , desc->dw0); - pf->pdata =FIELD_GET (PFD_PDATA_HI , desc->dw1) << -PFD_PDATA_HI_SHIFT ; - pf->pdata |=FIELD_GET (PFD_PDATA_LO , desc->dw0); - pf->asid =FIELD_GET (PFD_ASID , desc->dw1); - pf->vfid =FIELD_GET (PFD_VFID , desc->dw2); - pf->access_type =FIELD_GET (PFD_ACCESS_TYPE , desc->dw2); - pf->fault_type =FIELD_GET (PFD_FAULT_TYPE , desc->dw2); - pf->page_addr = (u64)(FIELD_GET (PFD_VIRTUAL_ADDR_HI , desc->dw3)) << -PFD_VIRTUAL_ADDR_HI_SHIFT ; - pf->page_addr |=FIELD_GET (PFD_VIRTUAL_ADDR_LO , desc->dw2) << -PFD_VIRTUAL_ADDR_LO_SHIFT ; - - pf_queue->tail = (pf_queue->tail +PF_MSG_LEN_DW ) % - pf_queue->num_dw; - ret = true; - } -spin_unlock_irq (&pf_queue->lock); - -return ret; -} - -static bool pf_queue_full (struct pf_queue *pf_queue) -{ -lockdep_assert_held (&pf_queue->lock); - -return CIRC_SPACE (pf_queue->head, pf_queue->tail, - pf_queue->num_dw) <= -PF_MSG_LEN_DW ; -} - -int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len) -{ -struct xe_gt *gt =guc_to_gt (guc); -struct pf_queue *pf_queue; -unsigned long flags; -u32 asid; -bool full; - -if (unlikely (len !=PF_MSG_LEN_DW )) -return -EPROTO ; - - asid =FIELD_GET (PFD_ASID , msg[1 ]); - pf_queue = gt->usm.pf_queue + (asid %NUM_PF_QUEUE ); - -/* -* The below logic doesn't work unless PF_QUEUE_NUM_DW % PF_MSG_LEN_DW == 0 -*/ -xe_gt_assert (gt, !(pf_queue->num_dw %PF_MSG_LEN_DW )); - -spin_lock_irqsave (&pf_queue->lock, flags); - full =pf_queue_full (pf_queue); -if (!full) { -memcpy (pf_queue->data + pf_queue->head, msg, len *sizeof (u32)); - pf_queue->head = (pf_queue->head + len) % - pf_queue->num_dw; -queue_work (gt->usm.pf_wq, &pf_queue->worker); - }else { -xe_gt_warn (gt,"PageFault Queue full, shouldn't be possible\n" ); - } -spin_unlock_irqrestore (&pf_queue->lock, flags); - -return full ? -ENOSPC :0 ; -} - -#define USM_QUEUE_MAX_RUNTIME_MS 20 - -static void pf_queue_work_func (struct work_struct *w) -{ - struct pf_queue *pf_queue = container_of(w, struct pf_queue, worker); -struct xe_gt *gt = pf_queue->gt; -struct xe_guc_pagefault_reply reply = {}; -struct pagefault pf = {}; -unsigned long threshold; -int ret; - - threshold = jiffies +msecs_to_jiffies (USM_QUEUE_MAX_RUNTIME_MS ); - -while (get_pagefault (pf_queue, &pf)) { - ret =handle_pagefault (gt, &pf); -if (unlikely (ret)) { -print_pagefault (gt, &pf); - pf.fault_unsuccessful =1 ; -xe_gt_dbg (gt,"Fault response: Unsuccessful %pe\n" ,ERR_PTR (ret)); - } - - reply.dw0 =FIELD_PREP (PFR_VALID ,1 ) | -FIELD_PREP (PFR_SUCCESS , pf.fault_unsuccessful) | -FIELD_PREP (PFR_REPLY ,PFR_ACCESS ) | -FIELD_PREP (PFR_DESC_TYPE ,FAULT_RESPONSE_DESC ) | -FIELD_PREP (PFR_ASID , pf.asid); - - reply.dw1 =FIELD_PREP (PFR_VFID , pf.vfid) | -FIELD_PREP (PFR_ENG_INSTANCE , pf.engine_instance) | -FIELD_PREP (PFR_ENG_CLASS , pf.engine_class) | -FIELD_PREP (PFR_PDATA , pf.pdata); - -send_pagefault_reply (>->uc.guc, &reply); - -if (time_after (jiffies, threshold) && - pf_queue->tail != pf_queue->head) { -queue_work (gt->usm.pf_wq, w); -break ; - } - } -} - -static void acc_queue_work_func (struct work_struct *w); - -static void pagefault_fini (void *arg) -{ -struct xe_gt *gt = arg; -struct xe_device *xe =gt_to_xe (gt); - -if (!xe->info.has_usm) -return ; - -destroy_workqueue (gt->usm.acc_wq); -destroy_workqueue (gt->usm.pf_wq); -} - -static int xe_alloc_pf_queue (struct xe_gt *gt,struct pf_queue *pf_queue) -{ -struct xe_device *xe =gt_to_xe (gt); -xe_dss_mask_t all_dss; -int num_dss, num_eus; - -bitmap_or (all_dss, gt->fuse_topo.g_dss_mask, gt->fuse_topo.c_dss_mask, -XE_MAX_DSS_FUSE_BITS ); - - num_dss =bitmap_weight (all_dss,XE_MAX_DSS_FUSE_BITS ); - num_eus =bitmap_weight (gt->fuse_topo.eu_mask_per_dss, -XE_MAX_EU_FUSE_BITS ) * num_dss; - -/* -* user can issue separate page faults per EU and per CS -* -* XXX: Multiplier required as compute UMD are getting PF queue errors -* without it. Follow on why this multiplier is required. -*/ -#define PF_MULTIPLIER 8 - pf_queue->num_dw = - (num_eus +XE_NUM_HW_ENGINES ) *PF_MSG_LEN_DW *PF_MULTIPLIER ; - pf_queue->num_dw =roundup_pow_of_two (pf_queue->num_dw); -#undef PF_MULTIPLIER - - pf_queue->gt = gt; - pf_queue->data =devm_kcalloc (xe->drm.dev, pf_queue->num_dw, -sizeof (u32),GFP_KERNEL ); -if (!pf_queue->data) -return -ENOMEM ; - -spin_lock_init (&pf_queue->lock); -INIT_WORK (&pf_queue->worker, pf_queue_work_func); - -return 0 ; -} - -int xe_gt_pagefault_init (struct xe_gt *gt) -{ -struct xe_device *xe =gt_to_xe (gt); -int i, ret =0 ; - -if (!xe->info.has_usm) -return 0 ; - -for (i =0 ; i <NUM_PF_QUEUE ; ++i) { - ret =xe_alloc_pf_queue (gt, >->usm.pf_queue[i]); -if (ret) -return ret; - } -for (i =0 ; i <NUM_ACC_QUEUE ; ++i) { - gt->usm.acc_queue[i].gt = gt; -spin_lock_init (>->usm.acc_queue[i].lock); -INIT_WORK (>->usm.acc_queue[i].worker, acc_queue_work_func); - } - - gt->usm.pf_wq =alloc_workqueue ("xe_gt_page_fault_work_queue" , -WQ_UNBOUND |WQ_HIGHPRI ,NUM_PF_QUEUE ); -if (!gt->usm.pf_wq) -return -ENOMEM ; - - gt->usm.acc_wq =alloc_workqueue ("xe_gt_access_counter_work_queue" , -WQ_UNBOUND |WQ_HIGHPRI , -NUM_ACC_QUEUE ); -if (!gt->usm.acc_wq) { -destroy_workqueue (gt->usm.pf_wq); -return -ENOMEM ; - } - -return devm_add_action_or_reset (xe->drm.dev, pagefault_fini, gt); -} - -void xe_gt_pagefault_reset (struct xe_gt *gt) -{ -struct xe_device *xe =gt_to_xe (gt); -int i; - -if (!xe->info.has_usm) -return ; - -for (i =0 ; i <NUM_PF_QUEUE ; ++i) { -spin_lock_irq (>->usm.pf_queue[i].lock); - gt->usm.pf_queue[i].head =0 ; - gt->usm.pf_queue[i].tail =0 ; -spin_unlock_irq (>->usm.pf_queue[i].lock); - } - -for (i =0 ; i <NUM_ACC_QUEUE ; ++i) { -spin_lock (>->usm.acc_queue[i].lock); - gt->usm.acc_queue[i].head =0 ; - gt->usm.acc_queue[i].tail =0 ; -spin_unlock (>->usm.acc_queue[i].lock); - } -} - -static int granularity_in_byte (int val) -{ -switch (val) { -case 0 : -return SZ_128K ; -case 1 : -return SZ_2M ; -case 2 : -return SZ_16M ; -case 3 : -return SZ_64M ; -default : -return 0 ; - } -} - -static int sub_granularity_in_byte (int val) -{ -return (granularity_in_byte (val) /32 ); -} - -static void print_acc (struct xe_gt *gt,struct acc *acc) -{ -xe_gt_warn (gt,"Access counter request:\n" -"\tType: %s\n" -"\tASID: %d\n" -"\tVFID: %d\n" -"\tEngine: %d:%d\n" -"\tGranularity: 0x%x KB Region/ %d KB sub-granularity\n" -"\tSub_Granularity Vector: 0x%08x\n" -"\tVA Range base: 0x%016llx\n" , - acc->access_type ?"AC_NTFY_VAL" :"AC_TRIG_VAL" , - acc->asid, acc->vfid, acc->engine_class, acc->engine_instance, -granularity_in_byte (acc->granularity) /SZ_1K , -sub_granularity_in_byte (acc->granularity) /SZ_1K , - acc->sub_granularity, acc->va_range_base); -} - -static struct xe_vma *get_acc_vma (struct xe_vm *vm,struct acc *acc) -{ -u64 page_va = acc->va_range_base + (ffs (acc->sub_granularity) -1 ) * -sub_granularity_in_byte (acc->granularity); - -return xe_vm_find_overlapping_vma (vm, page_va,SZ_4K ); -} - -static int handle_acc (struct xe_gt *gt,struct acc *acc) -{ -struct xe_device *xe =gt_to_xe (gt); -struct xe_tile *tile =gt_to_tile (gt); -struct drm_exec exec; -struct xe_vm *vm; -struct xe_vma *vma; -int ret =0 ; - -/* We only support ACC_TRIGGER at the moment */ -if (acc->access_type !=ACC_TRIGGER ) -return -EINVAL ; - - vm =asid_to_vm (xe, acc->asid); -if (IS_ERR (vm)) -return PTR_ERR (vm); - -down_read (&vm->lock); - -/* Lookup VMA */ - vma =get_acc_vma (vm, acc); -if (!vma) { - ret = -EINVAL ; - goto unlock_vm; - } - -trace_xe_vma_acc (vma); - -/* Userptr or null can't be migrated, nothing to do */ -if (xe_vma_has_no_bo (vma)) - goto unlock_vm; - -/* Lock VM and BOs dma-resv */ -drm_exec_init (&exec,0 ,0 ); - drm_exec_until_all_locked(&exec) { - ret =xe_pf_begin (&exec, vma, true, tile->mem.vram); -drm_exec_retry_on_contention (&exec); -if (ret) -break ; - } - -drm_exec_fini (&exec); -unlock_vm: -up_read (&vm->lock); -xe_vm_put (vm); - -return ret; -} - -#define make_u64 (hi__, low__) ((u64)(hi__) << 32 | (u64)(low__)) - -#define ACC_MSG_LEN_DW 4 - -static bool get_acc (struct acc_queue *acc_queue,struct acc *acc) -{ -const struct xe_guc_acc_desc *desc; -bool ret = false; - -spin_lock (&acc_queue->lock); -if (acc_queue->tail != acc_queue->head) { - desc = (const struct xe_guc_acc_desc *) - (acc_queue->data + acc_queue->tail); - - acc->granularity =FIELD_GET (ACC_GRANULARITY , desc->dw2); - acc->sub_granularity =FIELD_GET (ACC_SUBG_HI , desc->dw1) <<31 | -FIELD_GET (ACC_SUBG_LO , desc->dw0); - acc->engine_class =FIELD_GET (ACC_ENG_CLASS , desc->dw1); - acc->engine_instance =FIELD_GET (ACC_ENG_INSTANCE , desc->dw1); - acc->asid =FIELD_GET (ACC_ASID , desc->dw1); - acc->vfid =FIELD_GET (ACC_VFID , desc->dw2); - acc->access_type =FIELD_GET (ACC_TYPE , desc->dw0); - acc->va_range_base =make_u64 (desc->dw3 &ACC_VIRTUAL_ADDR_RANGE_HI , - desc->dw2 &ACC_VIRTUAL_ADDR_RANGE_LO ); - - acc_queue->tail = (acc_queue->tail +ACC_MSG_LEN_DW ) % -ACC_QUEUE_NUM_DW ; - ret = true; - } -spin_unlock (&acc_queue->lock); - -return ret; -} - -static void acc_queue_work_func (struct work_struct *w) -{ - struct acc_queue *acc_queue = container_of(w, struct acc_queue, worker); -struct xe_gt *gt = acc_queue->gt; -struct acc acc = {}; -unsigned long threshold; -int ret; - - threshold = jiffies +msecs_to_jiffies (USM_QUEUE_MAX_RUNTIME_MS ); - -while (get_acc (acc_queue, &acc)) { - ret =handle_acc (gt, &acc); -if (unlikely (ret)) { -print_acc (gt, &acc); -xe_gt_warn (gt,"ACC: Unsuccessful %pe\n" ,ERR_PTR (ret)); - } - -if (time_after (jiffies, threshold) && - acc_queue->tail != acc_queue->head) { -queue_work (gt->usm.acc_wq, w); -break ; - } - } -} - -static bool acc_queue_full (struct acc_queue *acc_queue) -{ -lockdep_assert_held (&acc_queue->lock); - -return CIRC_SPACE (acc_queue->head, acc_queue->tail,ACC_QUEUE_NUM_DW ) <= -ACC_MSG_LEN_DW ; -} - -int xe_guc_access_counter_notify_handler (struct xe_guc *guc,u32 *msg,u32 len) -{ -struct xe_gt *gt =guc_to_gt (guc); -struct acc_queue *acc_queue; -u32 asid; -bool full; - -/* -* The below logic doesn't work unless ACC_QUEUE_NUM_DW % ACC_MSG_LEN_DW == 0 -*/ -BUILD_BUG_ON (ACC_QUEUE_NUM_DW %ACC_MSG_LEN_DW ); - -if (unlikely (len !=ACC_MSG_LEN_DW )) -return -EPROTO ; - - asid =FIELD_GET (ACC_ASID , msg[1 ]); - acc_queue = >->usm.acc_queue[asid %NUM_ACC_QUEUE ]; - -spin_lock (&acc_queue->lock); - full =acc_queue_full (acc_queue); -if (!full) { -memcpy (acc_queue->data + acc_queue->head, msg, - len *sizeof (u32)); - acc_queue->head = (acc_queue->head + len) %ACC_QUEUE_NUM_DW ; -queue_work (gt->usm.acc_wq, &acc_queue->worker); - }else { -xe_gt_warn (gt,"ACC Queue full, dropping ACC\n" ); - } -spin_unlock (&acc_queue->lock); - -return full ? -ENOSPC :0 ; -}
drivers/gpu/drm/xe/xe_gt_pagefault.h deleted +0 -19
@@ -1,19 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* -* Copyright © 2022 Intel Corporation -*/ - -#ifndef _XE_GT_PAGEFAULT_H_ -#define _XE_GT_PAGEFAULT_H_ - -#include <linux/types.h> - -struct xe_gt ; -struct xe_guc ; - -int xe_gt_pagefault_init (struct xe_gt *gt); -void xe_gt_pagefault_reset (struct xe_gt *gt); -int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len); -int xe_guc_access_counter_notify_handler (struct xe_guc *guc,u32 *msg,u32 len); - -#endif /* _XE_GT_PAGEFAULT_ */
drivers/gpu/drm/xe/xe_gt_types.h +0 -65
71 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 07/11] drm/xe: Remove unused GT page fault code
Quoted 3 lines · Matthew Brost
With the Xe page fault layer and GuC page layer in place, this is now dead code and can be removed. ACC code is also removed, but this was dead code.
Ok so I was planning on posting some UAPI ideas around access counters here - which of course needs buy-in from the compute UMD. Maybe we can merge this first and I'll build the reintegration on top of what you have here. Let me know if you had another plan there...
Thanks,
Stuart
Quoted 886 lines
Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_gt_pagefault.c | 691 ------------------------- --
drivers/gpu/drm/xe/xe_gt_pagefault.h | 19 - drivers/gpu/drm/xe/xe_gt_types.h | 65 ---3 files changed, 775 deletions(-)delete mode 100644
drivers/gpu/drm/xe/xe_gt_pagefault.cdelete mode 100644drivers/gpu/drm/xe/xe_gt_pagefault.hdrivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-96@@ -1,691 +0,0 @@ -// SPDX-License-Identifier: MIT -/* -* Copyright © 2022 Intel Corporation -*/ - -#include "xe_gt_pagefault.h" - -#include <linux/bitfield.h> -#include <linux/circ_buf.h> - -#include <drm/drm_exec.h> -#include <drm/drm_managed.h> - -#include "abi/guc_actions_abi.h" -#include "xe_bo.h" -#include "xe_gt.h" -#include "xe_gt_printk.h" -#include "xe_gt_stats.h" -#include "xe_gt_tlb_invalidation.h" -#include "xe_guc.h" -#include "xe_guc_ct.h" -#include "xe_migrate.h" -#include "xe_svm.h" -#include "xe_trace_bo.h" -#include "xe_vm.h" -#include "xe_vram_types.h" - -struct pagefault { - u64 page_addr; - u32 asid; - u16 pdata; - u8 vfid; - u8 access_type; - u8 fault_type; - u8 fault_level; - u8 engine_class; - u8 engine_instance; - u8 fault_unsuccessful; - bool trva_fault; -}; - -enum access_type { - ACCESS_TYPE_READ = 0, - ACCESS_TYPE_WRITE = 1, - ACCESS_TYPE_ATOMIC = 2, - ACCESS_TYPE_RESERVED = 3, -}; - -enum fault_type { - NOT_PRESENT = 0, - WRITE_ACCESS_VIOLATION = 1, - ATOMIC_ACCESS_VIOLATION = 2, -}; - -struct acc { - u64 va_range_base; - u32 asid; - u32 sub_granularity; - u8 granularity; - u8 vfid; - u8 access_type; - u8 engine_class; - u8 engine_instance; -}; - -static bool access_is_atomic (enum access_type access_type) -{ - return access_type == ACCESS_TYPE_ATOMIC; -} - -static bool vma_is_valid (struct xe_tile *tile,struct xe_vma *vma) -{ - return xe_vm_has_valid_gpu_mapping(tile, vma->tile_present, - vma->tile_invalidated); -} - -static int xe_pf_begin (struct drm_exec *exec,struct xe_vma *vma, - bool atomic, struct xe_vram_region *vram) -{ - struct xe_bo *bo = xe_vma_bo(vma); - struct xe_vm *vm = xe_vma_vm(vma); - int err; - - err = xe_vm_lock_vma(exec, vma); - if (err) - return err; - - if (atomic && vram) { - xe_assert(vm->xe, IS_DGFX(vm->xe)); - - if (xe_vma_is_userptr(vma)) { - err = -EACCES; - return err; - } - - /* Migrate to VRAM, move should invalidate the VMAfirst */
- err =xe_bo_migrate(bo, vram->placement); - if (err)
- return err;
- } else if (bo) {
- /* Create backing store if needed */ - err =xe_bo_validate(bo, vm, true); - if (err)
- return err;
- }drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-5- - return 0; -} - -static int handle_vma_pagefault(struct xe_gt *gt, struct xe_vma*vma,
- bool atomic)drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-12-{ - struct xe_vm *vm = xe_vma_vm(vma); - struct xe_tile *tile = gt_to_tile(gt); - struct drm_exec exec; - struct dma_fence *fence; - ktime_t end = 0; - int err; - - lockdep_assert_held_write(&vm->lock); - - xe_gt_stats_incr(gt, XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT, 1); - xe_gt_stats_incr(gt, XE_GT_STATS_ID_VMA_PAGEFAULT_KB,
xe_vma_size(vma)/ 1024);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-21- - trace_xe_vma_pagefault(vma); - - /* Check if VMA is valid, opportunistic check only */ - if (vma_is_valid(tile, vma) && !atomic) - return 0; - -retry_userptr: - if (xe_vma_is_userptr(vma) && - xe_vma_userptr_check_repin(to_userptr_vma(vma))) { - struct xe_userptr_vma *uvma = to_userptr_vma(vma); - - err = xe_vma_userptr_pin_pages(uvma); - if (err) - return err; - } - - /* Lock VM and BOs dma-resv */ - drm_exec_init(&exec, 0, 0); - drm_exec_until_all_locked(&exec) { - err = xe_pf_begin(&exec, vma, atomic, tile-Quoted 1 line
mem.vram);
- drm_exec_retry_on_contention(&exec);
- if (xe_vm_validate_should_retry(&exec, err, &end)) - err =-EAGAIN;
- if (err)
- gotounlock_dma_resv;
-
- /* Bind VMA only to the GT that has faulted */ - trace_xe_vma_pf_bind(vma);
- fence =xe_vma_rebind(vm, vma, BIT(tile->id)); - if (IS_ERR(fence)) {
- err =PTR_ERR(fence);
- if (xe_vm_validate_should_retry(&exec, err, &end))
- err =-EAGAIN;
- gotounlock_dma_resv;
- }
- }drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-45- - dma_fence_wait(fence, false); - dma_fence_put(fence); - -unlock_dma_resv: - drm_exec_fini(&exec); - if (err == -EAGAIN) - goto retry_userptr; - - return err; -} - -static struct xe_vm *asid_to_vm (struct xe_device *xe,u32 asid) -{ - struct xe_vm *vm; - - down_read(&xe->usm.lock); - vm = xa_load(&xe->usm.asid_to_vm, asid); - if (vm && xe_vm_in_fault_mode(vm)) - xe_vm_get(vm); - else - vm = ERR_PTR(-EINVAL); - up_read(&xe->usm.lock); - - return vm; -} - -static int handle_pagefault (struct xe_gt *gt,struct pagefault *pf) -{ - struct xe_device *xe = gt_to_xe(gt); - struct xe_vm *vm; - struct xe_vma *vma = NULL; - int err; - bool atomic; - - /* SW isn't expected to handle TRTT faults */ - if (pf->trva_fault) - return -EFAULT; - - vm = asid_to_vm(xe, pf->asid); - if (IS_ERR(vm)) - return PTR_ERR(vm); - - /* -* TODO: Change to read lock? Using write lock for simplicity.
- */
- down_write(&vm->lock);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-39- - if (xe_vm_is_closed(vm)) { - err = -ENOENT; - goto unlock_vm; - } - - vma = xe_vm_find_vma_by_addr(vm, pf->page_addr); - if (!vma) { - err = -EINVAL; - goto unlock_vm; - } - - atomic = access_is_atomic(pf->access_type); - - if (xe_vma_is_cpu_addr_mirror(vma)) - err = xe_svm_handle_pagefault(vm, vma, gt, - pf->page_addr, atomic); - else - err = handle_vma_pagefault(gt, vma, atomic); - -unlock_vm: - if (!err) - vm->usm.last_fault_vma = vma; - up_write(&vm->lock); - xe_vm_put(vm); - - return err; -} - -static int send_pagefault_reply (struct xe_guc *guc, - struct xe_guc_pagefault_reply *reply) -{ - u32 action[] = { - XE_GUC_ACTION_PAGE_FAULT_RES_DESC, - reply->dw0, - reply->dw1, - }; - - return xe_guc_ct_send(&guc->ct, action, ARRAY_SIZE(action),0, 0);
drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-14-} - -static void print_pagefault (struct xe_gt *gt,struct pagefault *pf) -{ - xe_gt_dbg(gt, "\n\tASID: %d\n" - "\tVFID: %d\n" - "\tPDATA: 0x%04x\n" - "\tFaulted Address: 0x%08x%08x\n" - "\tFaultType: %d\n" - "\tAccessType: %d\n" - "\tFaultLevel: %d\n" - "\tEngineClass: %d %s\n" - "\tEngineInstance: %d\n", - pf->asid, pf->vfid, pf->pdata, upper_32_bits(pf-Quoted 1 line
page_addr),-
lower_32_bits(pf->page_addr),
-pf->fault_type,pf->access_type,pf->fault_level, -pf->engine_class, xe_hw_engine_class_to_str(pf-Quoted 1 line
engine_class),-
pf->engine_instance);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-5-} - -#define PF_MSG_LEN_DW 4 - -static bool get_pagefault(struct pf_queue *pf_queue, structpagefault *pf)
drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-10-{ - const struct xe_guc_pagefault_desc *desc; - bool ret = false; - - spin_lock_irq(&pf_queue->lock); - if (pf_queue->tail != pf_queue->head) { - desc = (const struct xe_guc_pagefault_desc *) - (pf_queue->data + pf_queue->tail); - - pf->fault_level = FIELD_GET(PFD_FAULT_LEVEL, desc-Quoted 1 line
dw0);
- pf->trva_fault = FIELD_GET(XE2_PFD_TRVA_FAULT, desc-
Quoted 1 line
dw0);
- pf->engine_class = FIELD_GET(PFD_ENG_CLASS, desc-
Quoted 1 line
dw0);
- pf->engine_instance =
FIELD_GET(PFD_ENG_INSTANCE, desc->dw0);
- pf->pdata =FIELD_GET(PFD_PDATA_HI, desc->dw1)<< - PFD_PDATA_HI_SHIFT;
- pf->pdata |=FIELD_GET(PFD_PDATA_LO, desc->dw0); - pf->asid =FIELD_GET(PFD_ASID, desc->dw1); - pf->vfid =FIELD_GET(PFD_VFID, desc->dw2); - pf->access_type = FIELD_GET(PFD_ACCESS_TYPE, desc-Quoted 1 line
dw2);
- pf->fault_type = FIELD_GET(PFD_FAULT_TYPE, desc-
Quoted 1 line
dw2);
- pf->page_addr = (u64)(FIELD_GET(PFD_VIRTUAL_ADDR_HI,
desc->dw3)) <<
- PFD_VIRTUAL_ADDR_HI_SHIFT;
- pf->page_addr |= FIELD_GET(PFD_VIRTUAL_ADDR_LO, desc-Quoted 1 line
dw2) <<
- PFD_VIRTUAL_ADDR_LO_SHIFT;
drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-35- - pf_queue->tail = (pf_queue->tail + PF_MSG_LEN_DW) % - pf_queue->num_dw; - ret = true; - } - spin_unlock_irq(&pf_queue->lock); - - return ret; -} - -static bool pf_queue_full (struct pf_queue *pf_queue) -{ - lockdep_assert_held(&pf_queue->lock); - - return CIRC_SPACE(pf_queue->head, pf_queue->tail, - pf_queue->num_dw) <= - PF_MSG_LEN_DW; -} - -int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len) -{ - struct xe_gt *gt = guc_to_gt(guc); - struct pf_queue *pf_queue; - unsigned long flags; - u32 asid; - bool full; - - if (unlikely(len != PF_MSG_LEN_DW)) - return -EPROTO; - - asid = FIELD_GET(PFD_ASID, msg[1]); - pf_queue = gt->usm.pf_queue + (asid % NUM_PF_QUEUE); - - /* -* The below logic doesn't work unless PF_QUEUE_NUM_DW %
PF_MSG_LEN_DW== 0
- */
- xe_gt_assert(gt, !(pf_queue->num_dw %PF_MSG_LEN_DW)); -
- spin_lock_irqsave(&pf_queue->lock, flags);
- full =pf_queue_full(pf_queue);
- if (!full) {
- memcpy(pf_queue->data +pf_queue->head, msg, len * sizeof(u32));
- pf_queue->head = (pf_queue->head+ len) % - pf_queue->num_dw;
- queue_work(gt->usm.pf_wq,&pf_queue->worker); - } else {
- xe_gt_warn(gt, "PageFault Queue full, shouldn't be possible\n");
- }
- spin_unlock_irqrestore(&pf_queue->lock, flags);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-9- - return full ? -ENOSPC : 0; -} - -#define USM_QUEUE_MAX_RUNTIME_MS 20 - -static void pf_queue_work_func (struct work_struct *w) -{ - struct pf_queue *pf_queue = container_of(w, struct pf_queue,worker);
- structxe_gt*gt =pf_queue->gt;
- structxe_guc_pagefault_replyreply = {};
- struct pagefault pf = {};
- unsigned long threshold;
- int ret;
-
- threshold = jiffies +msecs_to_jiffies(USM_QUEUE_MAX_RUNTIME_MS);
-
- while (get_pagefault(pf_queue, &pf)) {
- ret =handle_pagefault(gt, &pf);
- if (unlikely(ret)) {
- print_pagefault(gt, &pf);
- pf.fault_unsuccessful = 1;
- xe_gt_dbg(gt, "Fault response: Unsuccessful %pe\n",ERR_PTR(ret));
- }
-
- reply.dw0 =FIELD_PREP(PFR_VALID, 1)|
- FIELD_PREP(PFR_SUCCESS, pf.fault_unsuccessful) |
- FIELD_PREP(PFR_REPLY,PFR_ACCESS) | - FIELD_PREP(PFR_DESC_TYPE,FAULT_RESPONSE_DESC) |
- FIELD_PREP(PFR_ASID, pf.asid);
-
- reply.dw1 =FIELD_PREP(PFR_VFID, pf.vfid)| - FIELD_PREP(PFR_ENG_INSTANCE, pf.engine_instance) |
- FIELD_PREP(PFR_ENG_CLASS, pf.engine_class) | - FIELD_PREP(PFR_PDATA, pf.pdata);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-26- - send_pagefault_reply(>->uc.guc, &reply); - - if (time_after(jiffies, threshold) && - pf_queue->tail != pf_queue->head) { - queue_work(gt->usm.pf_wq, w); - break; - } - } -} - -static void acc_queue_work_func (struct work_struct *w); - -static void pagefault_fini (void *arg) -{ - struct xe_gt *gt = arg; - struct xe_device *xe = gt_to_xe(gt); - - if (!xe->info.has_usm) - return; - - destroy_workqueue(gt->usm.acc_wq); - destroy_workqueue(gt->usm.pf_wq); -} - -static int xe_alloc_pf_queue(struct xe_gt *gt, struct pf_queue
*pf_queue)drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-6-{ - struct xe_device *xe = gt_to_xe(gt); - xe_dss_mask_t all_dss; - int num_dss, num_eus; - - bitmap_or(all_dss, gt->fuse_topo.g_dss_mask, gt-Quoted 1 line
fuse_topo.c_dss_mask,
-
XE_MAX_DSS_FUSE_BITS);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-9- - num_dss = bitmap_weight(all_dss, XE_MAX_DSS_FUSE_BITS); - num_eus = bitmap_weight(gt->fuse_topo.eu_mask_per_dss, - XE_MAX_EU_FUSE_BITS) * num_dss; - - /* -* user can issue separate page faults per EU and per CS -* -* XXX: Multiplier required as compute UMD are getting PF queue errors
- * without it. Follow on why this multiplier is required. - */
-#define PF_MULTIPLIER 8
- pf_queue->num_dw =
- (num_eus +XE_NUM_HW_ENGINES) *PF_MSG_LEN_DW*PF_MULTIPLIER;
- pf_queue->num_dw =roundup_pow_of_two(pf_queue->num_dw);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-31-#undef PF_MULTIPLIER - - pf_queue->gt = gt; - pf_queue->data = devm_kcalloc(xe->drm.dev, pf_queue->num_dw, - sizeof(u32), GFP_KERNEL); - if (!pf_queue->data) - return -ENOMEM; - - spin_lock_init(&pf_queue->lock); - INIT_WORK(&pf_queue->worker, pf_queue_work_func); - - return 0; -} - -int xe_gt_pagefault_init (struct xe_gt *gt) -{ - struct xe_device *xe = gt_to_xe(gt); - int i, ret = 0; - - if (!xe->info.has_usm) - return 0; - - for (i = 0; i < NUM_PF_QUEUE; ++i) { - ret = xe_alloc_pf_queue(gt, >->usm.pf_queue[i]); - if (ret) - return ret; - } - for (i = 0; i < NUM_ACC_QUEUE; ++i) { - gt->usm.acc_queue[i].gt = gt; - spin_lock_init(>->usm.acc_queue[i].lock); - INIT_WORK(>->usm.acc_queue[i].worker,
acc_queue_work_func);
- }
-
- gt->usm.pf_wq = alloc_workqueue("xe_gt_page_fault_work_queue",
- WQ_UNBOUND |WQ_HIGHPRI,NUM_PF_QUEUE);
- if (!gt->usm.pf_wq)
- return-ENOMEM;
-
- gt->usm.acc_wq = alloc_workqueue("xe_gt_access_counter_work_queue",
-WQ_UNBOUND|WQ_HIGHPRI, -NUM_ACC_QUEUE); - if (!gt->usm.acc_wq) {
- destroy_workqueue(gt->usm.pf_wq);
- return-ENOMEM;
- }
-
- returndevm_add_action_or_reset(xe->drm.dev, pagefault_fini, gt);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-54-} - -void xe_gt_pagefault_reset (struct xe_gt *gt) -{ - struct xe_device *xe = gt_to_xe(gt); - int i; - - if (!xe->info.has_usm) - return; - - for (i = 0; i < NUM_PF_QUEUE; ++i) { - spin_lock_irq(>->usm.pf_queue[i].lock); - gt->usm.pf_queue[i].head = 0; - gt->usm.pf_queue[i].tail = 0; - spin_unlock_irq(>->usm.pf_queue[i].lock); - } - - for (i = 0; i < NUM_ACC_QUEUE; ++i) { - spin_lock(>->usm.acc_queue[i].lock); - gt->usm.acc_queue[i].head = 0; - gt->usm.acc_queue[i].tail = 0; - spin_unlock(>->usm.acc_queue[i].lock); - } -} - -static int granularity_in_byte (int val) -{ - switch (val) { - case 0: - return SZ_128K; - case 1: - return SZ_2M; - case 2: - return SZ_16M; - case 3: - return SZ_64M; - default: - return 0; - } -} - -static int sub_granularity_in_byte (int val) -{ - return (granularity_in_byte(val) / 32); -} - -static void print_acc(struct xe_gt *gt, struct acc *acc) -{ - xe_gt_warn(gt, "Access counter request:\n" - "\tType: %s\n" - "\tASID: %d\n" - "\tVFID: %d\n" - "\tEngine: %d:%d\n" - "\tGranularity: 0x%x KB Region/ %d KB sub-granularity\n"
- "\tSub_Granularity Vector: 0x%08x\n"
- "\tVA Range base: 0x%016llx\n",
-acc->access_type? "AC_NTFY_VAL" : "AC_TRIG_VAL", -acc->asid,acc->vfid,acc->engine_class, acc-Quoted 1 line
engine_instance,-
granularity_in_byte(acc->granularity)/SZ_1K, -sub_granularity_in_byte(acc->granularity)/SZ_1K, -acc->sub_granularity,acc->va_range_base);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-75-} - -static struct xe_vma *get_acc_vma (struct xe_vm *vm,struct acc *acc) -{ - u64 page_va = acc->va_range_base + (ffs(acc->sub_granularity) - 1) * - sub_granularity_in_byte(acc->granularity); - - return xe_vm_find_overlapping_vma(vm, page_va, SZ_4K); -} - -static int handle_acc (struct xe_gt *gt,struct acc *acc) -{ - struct xe_device *xe = gt_to_xe(gt); - struct xe_tile *tile = gt_to_tile(gt); - struct drm_exec exec; - struct xe_vm *vm; - struct xe_vma *vma; - int ret = 0; - - /* We only support ACC_TRIGGER at the moment */ - if (acc->access_type != ACC_TRIGGER) - return -EINVAL; - - vm = asid_to_vm(xe, acc->asid); - if (IS_ERR(vm)) - return PTR_ERR(vm); - - down_read(&vm->lock); - - /* Lookup VMA */ - vma = get_acc_vma(vm, acc); - if (!vma) { - ret = -EINVAL; - goto unlock_vm; - } - - trace_xe_vma_acc(vma); - - /* Userptr or null can't be migrated, nothing to do */ - if (xe_vma_has_no_bo(vma)) - goto unlock_vm; - - /* Lock VM and BOs dma-resv */ - drm_exec_init(&exec, 0, 0); - drm_exec_until_all_locked(&exec) { - ret = xe_pf_begin(&exec, vma, true, tile->mem.vram); - drm_exec_retry_on_contention(&exec); - if (ret) - break; - } - - drm_exec_fini(&exec); -unlock_vm: - up_read(&vm->lock); - xe_vm_put(vm); - - return ret; -} - -#define make_u64 (hi__, low__) ((u64)(hi__) << 32 | (u64)(low__)) - -#define ACC_MSG_LEN_DW 4 - -static bool get_acc (struct acc_queue *acc_queue,struct acc *acc) -{ - const struct xe_guc_acc_desc *desc; - bool ret = false; - - spin_lock(&acc_queue->lock); - if (acc_queue->tail != acc_queue->head) { - desc = (const struct xe_guc_acc_desc *) - (acc_queue->data + acc_queue->tail); - - acc->granularity = FIELD_GET(ACC_GRANULARITY, desc-Quoted 1 line
dw2);
- acc->sub_granularity = FIELD_GET(ACC_SUBG_HI, desc-
Quoted 1 line
dw1) << 31 |
- FIELD_GET(ACC_SUBG_LO,
desc->dw0); - acc->engine_class = FIELD_GET(ACC_ENG_CLASS, desc-Quoted 1 line
dw1);
- acc->engine_instance =
FIELD_GET(ACC_ENG_INSTANCE, desc->dw1);
- acc->asid =FIELD_GET(ACC_ASID, desc->dw1); - acc->vfid =FIELD_GET(ACC_VFID, desc->dw2); - acc->access_type =FIELD_GET(ACC_TYPE, desc->dw0); - acc->va_range_base = make_u64(desc->dw3 &ACC_VIRTUAL_ADDR_RANGE_HI,
-desc->dw2&ACC_VIRTUAL_ADDR_RANGE_LO);
-
- acc_queue->tail = (acc_queue->tail+ACC_MSG_LEN_DW) %
-ACC_QUEUE_NUM_DW;
- ret = true;
- }
- spin_unlock(&acc_queue->lock);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-7- - return ret; -} - -static void acc_queue_work_func (struct work_struct *w) -{ - struct acc_queue *acc_queue = container_of(w, struct
acc_queue, worker);
- structxe_gt*gt =acc_queue->gt;
- struct acc acc = {};
- unsigned long threshold;
- int ret;
-
- threshold = jiffies +msecs_to_jiffies(USM_QUEUE_MAX_RUNTIME_MS);
-
- while (get_acc(acc_queue, &acc)) {
- ret =handle_acc(gt, &acc);
- if (unlikely(ret)) {
- print_acc(gt, &acc);
- xe_gt_warn(gt, "ACC: Unsuccessful %pe\n",ERR_PTR(ret));
- }drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-14- - if (time_after(jiffies, threshold) && - acc_queue->tail != acc_queue->head) { - queue_work(gt->usm.acc_wq, w); - break; - } - } -} - -static bool acc_queue_full (struct acc_queue *acc_queue) -{ - lockdep_assert_held(&acc_queue->lock); - - return CIRC_SPACE(acc_queue->head, acc_queue->tail,
ACC_QUEUE_NUM_DW) <=
- ACC_MSG_LEN_DW;drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-3-} - -int xe_guc_access_counter_notify_handler(struct xe_guc *guc, u32*msg, u32 len)
drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-8-{ - struct xe_gt *gt = guc_to_gt(guc); - struct acc_queue *acc_queue; - u32 asid; - bool full; - - /* -* The below logic doesn't work unless ACC_QUEUE_NUM_DW %
ACC_MSG_LEN_DW== 0
- */
- BUILD_BUG_ON(ACC_QUEUE_NUM_DW %ACC_MSG_LEN_DW);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-13- - if (unlikely(len != ACC_MSG_LEN_DW)) - return -EPROTO; - - asid = FIELD_GET(ACC_ASID, msg[1]); - acc_queue = >->usm.acc_queue[asid % NUM_ACC_QUEUE]; - - spin_lock(&acc_queue->lock); - full = acc_queue_full(acc_queue); - if (!full) { - memcpy(acc_queue->data + acc_queue->head, msg, - len * sizeof(u32)); - acc_queue->head = (acc_queue->head + len) %
ACC_QUEUE_NUM_DW;
- queue_work(gt->usm.acc_wq,&acc_queue->worker); - } else {
- xe_gt_warn(gt, "ACC Queue full, dropping ACC\n"); - }
- spin_unlock(&acc_queue->lock);drivers/gpu/drm/xe/xe_gt_pagefault.c deleted +0
-3- - return full ? -ENOSPC : 0; -}drivers/gpu/drm/xe/xe_gt_pagefault.h deleted +0
-17@@ -1,19 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* -* Copyright © 2022 Intel Corporation -*/ - -#ifndef _XE_GT_PAGEFAULT_H_ -#define _XE_GT_PAGEFAULT_H_ - -#include <linux/types.h> - -struct xe_gt ; -struct xe_guc ; - -int xe_gt_pagefault_init (struct xe_gt *gt); -void xe_gt_pagefault_reset (struct xe_gt *gt); -int xe_guc_pagefault_handler (struct xe_guc *guc,u32 *msg,u32 len); -int xe_guc_access_counter_notify_handler(struct xe_guc *guc, u32*msg, u32 len);
drivers/gpu/drm/xe/xe_gt_pagefault.h deleted +0
-2- -#endif /* _XE_GT_PAGEFAULT_ */drivers/gpu/drm/xe/xe_gt_types.h +0
-1@@ -239,71 +239,6 @@ struct xe_gt {* operations (e.g. mmigrations, fixing page tables) */ u16 reserved_bcs_instance; - /** @usm.pf_wq: page fault work queue, unbound, highpriority */
- structworkqueue_struct*pf_wq;
- /** @usm.acc_wq: access counter work queue, unbound, high priority */
- structworkqueue_struct*acc_wq;
- /**
- * @usm.pf_queue: Page fault queue used to sync faults so faults can
- * be processed not under the GuC CT lock. The queue is sized so
- * it can sync all possible faults (1 per physical engine).
- * Multiple queues exists for page faults from different VMs are
- * be processed in parallel.
- */
- structpf_queue{
- /** @usm.pf_queue.gt: back pointer to GT */ - structxe_gt*gt;
- /** @usm.pf_queue.data: data in the page fault queue */
- u32 *data;
- /**
- * @usm.pf_queue.num_dw: number of DWORDS in the page
- * fault queue. Dynamically calculated based on the number
- * of compute resources available. - */
- u32num_dw;
- /**
- * @usm.pf_queue.tail: tail pointer in DWs for page fault queue,
- * moved by worker which processes faults (consumer).
- */
- u16 tail;
- /**
- * @usm.pf_queue.head: head pointer in DWs for page fault queue,
- * moved by G2H handler (producer). - */
- u16 head;
- /** @usm.pf_queue.lock: protects page fault queue */
- spinlock_t lock;
- /** @usm.pf_queue.worker: to process page faults */
- structwork_structworker; -#define NUM_PF_QUEUE 4
- } pf_queue[NUM_PF_QUEUE];
- /**
- * @usm.acc_queue: Same as page fault queue, cannot process access
- * counters under CT lock.
- */
- structacc_queue{
- /** @usm.acc_queue.gt: back pointer to GT */ - structxe_gt*gt;
-#define ACC_QUEUE_NUM_DW 128
- /** @usm.acc_queue.data: data in the page fault queue */
- u32 data[ACC_QUEUE_NUM_DW];
- /**
- * @usm.acc_queue.tail: tail pointer in DWs for access counter queue,
- * moved by worker which processes counters - * (consumer).
- */
- u16 tail;
- /**
- * @usm.acc_queue.head: head pointer in DWs for access counter queue,
- * moved by G2H handler (producer). - */
- u16 head;
- /** @usm.acc_queue.lock: protects page fault queue */
- spinlock_t lock;
- /** @usm.acc_queue.worker: to process access counters */
- structwork_structworker; -#define NUM_ACC_QUEUE 4
- } acc_queue[NUM_ACC_QUEUE];
} usm;
/** @ordered_wq: used to serialize GT resets and TDRs */
Matthew Brost
maintainerPATCH 8/11 drm/xe: Fine grained page fault locking
In reply to Matthew BrostEnable page faults to be serviced while holding vm->lock in read mode.
Introduce additional locks to:
- Ensure only one page fault thread services a given range or VMA
- Serialize SVM garbage collection
- Protect SVM range insertion and removal
While these locks may contend during page faults, expensive operations like migration can now run in parallel within a single VM.
In addition to new locking, ranges must be reference-counted after lookup, as another thread could immediately remove them from the GPU SVM tree, potentially dropping the last reference.
Lastly, decouple the VM’s ASID from the page fault queue selection to allow parallel page fault handling within the same VM.
Lays the groundwork for prefetch IOCTLs to use threaded migration too.
--- drivers/gpu/drm/xe/xe_device_types.h | 2 + drivers/gpu/drm/xe/xe_hmm.c | 4 +- drivers/gpu/drm/xe/xe_pagefault.c | 33 +++++++--- drivers/gpu/drm/xe/xe_svm.c | 96 +++++++++++++++++++--------- drivers/gpu/drm/xe/xe_svm.h | 38 +++++++++++ drivers/gpu/drm/xe/xe_vm.c | 88 +++++++++++++++++++++---- drivers/gpu/drm/xe/xe_vm.h | 2 + drivers/gpu/drm/xe/xe_vm_types.h | 24 ++++++- 8 files changed, 230 insertions(+), 57 deletions(-)
drivers/gpu/drm/xe/xe_device_types.h +2 -0
@@ -393,6 +393,8 @@ struct xe_device {struct xarray asid_to_vm;/** @usm.next_asid: next ASID, used to cyclical alloc asids */ u32 next_asid; +/** @usm.current_pf_queue: current page fault queue */ +u32 current_pf_queue;/** @usm.lock: protects UM state */ struct rw_semaphore lock;/** @usm.pf_wq: page fault work queue, unbound, high priority */
drivers/gpu/drm/xe/xe_hmm.c +2 -2
@@ -136,7 +136,7 @@ static void xe_hmm_userptr_set_mapped(struct xe_userptr_vma *uvma)struct xe_userptr *userptr = &uvma->userptr;struct xe_vm *vm =xe_vma_vm (&uvma->vma); -lockdep_assert_held_write (&vm->lock); +lockdep_assert (xe_vma_userptr_lockdep (uvma));lockdep_assert_held (&vm->userptr.notifier_lock);mutex_lock (&userptr->unmap_mutex);
@@ -154,7 +154,7 @@ void xe_hmm_userptr_unmap(struct xe_userptr_vma *uvma)struct xe_device *xe = vm->xe;if (!lockdep_is_held_type (&vm->userptr.notifier_lock,0 ) && - !lockdep_is_held_type (&vm->lock,0 ) && + !xe_vma_userptr_lockdep (uvma) && !(vma->gpuva.flags &XE_VMA_DESTROYED )) {/* Don't unmap in exec critical section. */ xe_vm_assert_held (vm);
drivers/gpu/drm/xe/xe_pagefault.c +24 -9
@@ -79,7 +79,7 @@ static int xe_pagefault_handle_vma(struct xe_gt *gt, struct xe_vma *vma,ktime_t end =0 ;int err; -lockdep_assert_held_write (&vm->lock); +lockdep_assert_held (&vm->lock);xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT ,1 ); xe_gt_stats_incr(gt, XE_GT_STATS_ID_VMA_PAGEFAULT_KB,
@@ -87,6 +87,8 @@ static int xe_pagefault_handle_vma(struct xe_gt *gt, struct xe_vma *vma,trace_xe_vma_pagefault (vma); +guard (mutex)(&vma->fault_lock); +/* Check if VMA is valid, opportunistic check only */ if (xe_vm_has_valid_gpu_mapping (tile, vma->tile_present, vma->tile_invalidated) && !atomic)
@@ -122,10 +124,13 @@ static int xe_pagefault_handle_vma(struct xe_gt *gt, struct xe_vma *vma, goto unlock_dma_resv; } } +drm_exec_fini (&exec);dma_fence_wait (fence, false);dma_fence_put (fence); +return err; + unlock_dma_resv:drm_exec_fini (&exec);if (err == -EAGAIN )
@@ -172,10 +177,7 @@ static int xe_pagefault_service(struct xe_pagefault *pf)if (IS_ERR (vm))return PTR_ERR (vm); -/* -* TODO: Change to read lock? Using write lock for simplicity. -*/ -down_write (&vm->lock); +down_read (&vm->lock);if (xe_vm_is_closed (vm)) { err = -ENOENT ;
@@ -199,7 +201,7 @@ static int xe_pagefault_service(struct xe_pagefault *pf) unlock_vm:if (!err) vm->usm.last_fault_vma = vma; -up_write (&vm->lock); +up_read (&vm->lock);xe_vm_put (vm);return err;
@@ -404,6 +406,19 @@ static bool xe_pagefault_queue_full(struct xe_pagefault_queue *pf_queue)xe_pagefault_entry_size (); } +/* +* This function can race with multiple page fault producers, but worst case we +* stick a page fault on the same queue for consumption. +*/ +static int xe_pagefault_queue_index (struct xe_device *xe) +{ +u32 old_pf_queue =READ_ONCE (xe->usm.current_pf_queue); + +WRITE_ONCE (xe->usm.current_pf_queue, (old_pf_queue +1 )); + +return old_pf_queue %XE_PAGEFAULT_QUEUE_COUNT ; +} +/** * xe_pagefault_handler() - Page fault handler * @xe: xe device instance
@@ -416,8 +431,8 @@ static bool xe_pagefault_queue_full(struct xe_pagefault_queue *pf_queue)*/ int xe_pagefault_handler (struct xe_device *xe,struct xe_pagefault *pf) { -struct xe_pagefault_queue *pf_queue = xe->usm.pf_queue + - (pf->consumer.asid %XE_PAGEFAULT_QUEUE_COUNT ); +int queue_index =xe_pagefault_queue_index (xe); +struct xe_pagefault_queue *pf_queue = xe->usm.pf_queue + queue_index;unsigned long flags;bool full;
@@ -431,7 +446,7 @@ int xe_pagefault_handler(struct xe_device *xe, struct xe_pagefault *pf) }else {drm_warn (&xe->drm,"PageFault Queue (%d) full, shouldn't be possible\n" , - pf->consumer.asid %XE_PAGEFAULT_QUEUE_COUNT ); + queue_index); }spin_unlock_irqrestore (&pf_queue->lock, flags);
drivers/gpu/drm/xe/xe_svm.c +66 -30
230 lines not on this page · raw message
drivers/gpu/drm/xe/xe_svm.h +38 -0
@@ -29,6 +29,13 @@ struct xe_svm_range {* list. Protected by VM's garbage collect lock. */ struct list_head garbage_collector_link; +/** +* @lock: Protects fault handler, garbage collector, and prefetch +* critical sections, ensuring only one thread operates on a range at a +* time. Locking order: inside vm->lock and garbage collector, outside +* dma-resv locks, vm->svm.range_lock. +*/ +struct mutex lock;/** * @tile_present: Tile mask of binding is present for this range. * Protected by GPU SVM notifier lock.
@@ -39,8 +46,22 @@ struct xe_svm_range {* range. Protected by GPU SVM notifier lock. */ u8 tile_invalidated; +/** +* @removed: Range has been removed from GPU SVM tree, protected by +* @lock. +*/ +bool removed; }; +/** +* xe_svm_range_put() - SVM range put +* @range: SVM range +*/ +static inline void xe_svm_range_put (struct xe_svm_range *range) +{ +drm_gpusvm_range_put (&range->base); +} +/** * xe_svm_range_pages_valid() - SVM range pages valid * @range: SVM range
@@ -102,6 +123,19 @@ static inline bool xe_svm_range_has_dma_mapping(struct xe_svm_range *range)return range->base.flags.has_dma_mapping; } +/** +* xe_svm_range_is_removed() - SVM range is removed from GPU SVM tree +* @range: SVM range +* +* Return: True if SVM range is removed from GPU SVM tree, False otherwise +*/ +static inline bool xe_svm_range_is_removed (struct xe_svm_range *range) +{ +lockdep_assert_held (&range->lock); + +return range->removed; +} +/** * to_xe_range - Convert a drm_gpusvm_range pointer to a xe_svm_range * @r: Pointer to the drm_gpusvm_range structure
@@ -184,6 +218,10 @@ struct xe_svm_range {u32 tile_invalidated; }; +static inline void xe_svm_range_put (struct xe_svm_range *range) +{ +} +static inline bool xe_svm_range_pages_valid (struct xe_svm_range *range) {return false;
drivers/gpu/drm/xe/xe_vm.c +74 -14
192 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +2 -0
@@ -262,6 +262,8 @@ int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma);int xe_vma_userptr_check_repin (struct xe_userptr_vma *uvma); +bool xe_vma_userptr_lockdep (struct xe_userptr_vma *uvma); +bool xe_vm_validate_should_retry (struct drm_exec *exec,int err,ktime_t *end);int xe_vm_lock_vma (struct drm_exec *exec,struct xe_vma *vma);
drivers/gpu/drm/xe/xe_vm_types.h +22 -2
@@ -100,6 +100,12 @@ struct xe_vma {struct work_struct destroy_work; }; +/** +* @fault_lock: Synchronizes fault processing. Locking order: inside +* vm->lock, outside dma-resv. +*/ +struct mutex fault_lock; +/** * @tile_invalidated: Tile mask of binding are invalidated for this VMA. * protected by BO's resv and for userptrs, vm->userptr.notifier_lock in
@@ -157,13 +163,27 @@ struct xe_vm {struct {/** @svm.gpusvm: base GPUSVM used to track fault allocations */ struct drm_gpusvm gpusvm; +/** +* @svm.range_lock: Protects insertion and removal of ranges +* from GPU SVM tree. +*/ +struct mutex range_lock;/** * @svm.garbage_collector: Garbage collector which is used unmap * SVM range's GPU bindings and destroy the ranges. */ struct { -/** @svm.garbage_collector.lock: Protect's range list */ -spinlock_t lock; +/** +* @svm.garbage_collector.lock: Ensures only one thread +* runs the garbage collector at a time. Locking order: +* inside vm->lock, outside range->lock and dma-resv. +*/ +struct mutex lock; +/** +* @svm.garbage_collector.list_lock: Protect's range +* list +*/ +spinlock_t list_lock;/** * @svm.garbage_collector.range_list: List of SVM ranges * in the garbage collector.
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 9/11 drm/xe: Allow prefetch-only VM bind IOCTLs to use VM read lock
In reply to Matthew BrostPrefetch-only VM bind IOCTLs do not modify VMAs after pinning userptr pages. Downgrade vm->lock to read mode once pinning is complete.
Lays the groundwork for prefetch IOCTLs to use threaded migration.
--- drivers/gpu/drm/xe/xe_vm.c | 41 ++++++++++++++++++++++++++++---- drivers/gpu/drm/xe/xe_vm_types.h | 4 +++- 2 files changed, 39 insertions(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +36 -5
@@ -1763,6 +1763,12 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags) err =xe_svm_init (vm);if (err) goto err_no_resv; + }else { +/* +* Avoid lockdep explosions in +* xe_vm_assert_write_mode_or_garbage_collector +*/ +mutex_init (&vm->svm.garbage_collector.lock); } vm_resv_obj =drm_gpuvm_resv_object_alloc (&xe->drm);
@@ -1996,6 +2002,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)if (xe_vm_in_fault_mode (vm))xe_svm_fini (vm); +else +mutex_destroy (&vm->svm.garbage_collector.lock);up_write (&vm->lock);
@@ -2365,10 +2373,12 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_vma_ops *vops,switch (operation) {case DRM_XE_VM_BIND_OP_MAP :case DRM_XE_VM_BIND_OP_MAP_USERPTR : + vops->flags |=XE_VMA_OPS_FLAG_MODIFIES_GPUVA ; ops =drm_gpuvm_sm_map_ops_create (&vm->gpuvm, addr, range, obj, bo_offset_or_userptr);break ;case DRM_XE_VM_BIND_OP_UNMAP : + vops->flags |=XE_VMA_OPS_FLAG_MODIFIES_GPUVA ; ops =drm_gpuvm_sm_unmap_ops_create (&vm->gpuvm, addr, range);break ;case DRM_XE_VM_BIND_OP_PREFETCH :
@@ -2377,6 +2387,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_vma_ops *vops,case DRM_XE_VM_BIND_OP_UNMAP_ALL :xe_assert (vm->xe, bo); + vops->flags |=XE_VMA_OPS_FLAG_MODIFIES_GPUVA ; err =xe_bo_lock (bo, true);if (err)return ERR_PTR (err);
@@ -2584,10 +2595,12 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op) {int err =0 ; -xe_vm_assert_write_mode_or_garbage_collector (vm); +lockdep_assert_held (&vm->lock);switch (op->base.op) {case DRM_GPUVA_OP_MAP : +xe_vm_assert_write_mode_or_garbage_collector (vm); + err |=xe_vm_insert_vma (vm, op->map.vma);if (!err) op->flags |=XE_VMA_OP_COMMITTED ;
@@ -2597,6 +2610,8 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op)u8 tile_present =gpuva_to_vma (op->base.remap.unmap->va)->tile_present; +xe_vm_assert_write_mode_or_garbage_collector (vm); +prep_vma_destroy (vm,gpuva_to_vma (op->base.remap.unmap->va), true); op->flags |=XE_VMA_OP_COMMITTED ;
@@ -2630,6 +2645,8 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op)break ; }case DRM_GPUVA_OP_UNMAP : +xe_vm_assert_write_mode_or_garbage_collector (vm); +prep_vma_destroy (vm,gpuva_to_vma (op->base.unmap.va), true); op->flags |=XE_VMA_OP_COMMITTED ;break ;
@@ -2831,10 +2848,12 @@ static void xe_vma_op_unwind(struct xe_vm *vm, struct xe_vma_op *op, bool post_commit, bool prev_post_commit, bool next_post_commit) { -xe_vm_assert_write_mode_or_garbage_collector (vm ); + lockdep_assert_held(&vm->lock);switch (op->base.op) {case DRM_GPUVA_OP_MAP : +xe_vm_assert_write_mode_or_garbage_collector (vm); +if (op->map.vma) {prep_vma_destroy (vm, op->map.vma, post_commit);xe_vma_destroy_unlocked (op->map.vma);
@@ -2844,6 +2863,8 @@ static void xe_vma_op_unwind(struct xe_vm *vm, struct xe_vma_op *op, {struct xe_vma *vma =gpuva_to_vma (op->base.unmap.va); +xe_vm_assert_write_mode_or_garbage_collector (vm); +if (vma) {down_read (&vm->userptr.notifier_lock); vma->gpuva.flags &= ~XE_VMA_DESTROYED ;
@@ -2857,6 +2878,8 @@ static void xe_vma_op_unwind(struct xe_vm *vm, struct xe_vma_op *op, {struct xe_vma *vma =gpuva_to_vma (op->base.remap.unmap->va); +xe_vm_assert_write_mode_or_garbage_collector (vm); +if (op->remap.prev) {prep_vma_destroy (vm, op->remap.prev, prev_post_commit);xe_vma_destroy_unlocked (op->remap.prev);
@@ -3313,7 +3336,7 @@ static struct dma_fence *vm_bind_ioctl_ops_execute(struct xe_vm *vm,struct dma_fence *fence;int err; -lockdep_assert_held_write (&vm->lock); +lockdep_assert_held (&vm->lock);drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT |DRM_EXEC_IGNORE_DUPLICATES ,0 );
@@ -3587,7 +3610,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)u32 num_syncs, num_ufence =0 ;struct xe_sync_entry *syncs =NULL ;struct drm_xe_vm_bind_op *bind_ops; -struct xe_vma_ops vops; +struct xe_vma_ops vops = { .flags =0 };struct dma_fence *fence;int err;int i;
@@ -3753,6 +3776,11 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) goto unwind_ops; } +if (!(vops.flags &XE_VMA_OPS_FLAG_MODIFIES_GPUVA )) { + vops.flags |=XE_VMA_OPS_FLAG_DOWNGRADE_LOCK ; +downgrade_write (&vm->lock); + } + err =xe_vma_ops_alloc (&vops, args->num_binds >1 );if (err) goto unwind_ops;
@@ -3785,7 +3813,10 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)for (i =0 ; i < args->num_binds; ++i)xe_bo_put (bos[i]); release_vm_lock: -up_write (&vm->lock); +if (vops.flags &XE_VMA_OPS_FLAG_DOWNGRADE_LOCK ) +up_read (&vm->lock); +else +up_write (&vm->lock); put_exec_queue:if (q)xe_exec_queue_put (q);
drivers/gpu/drm/xe/xe_vm_types.h +3 -1
@@ -481,7 +481,9 @@ struct xe_vma_ops {/** @pt_update_ops: page table update operations */ struct xe_vm_pgtable_update_ops pt_update_ops[XE_MAX_TILES_PER_DEVICE ];/** @flag: signify the properties within xe_vma_ops*/ -#define XE_VMA_OPS_FLAG_HAS_SVM_PREFETCH BIT(0) +#define XE_VMA_OPS_FLAG_HAS_SVM_PREFETCH BIT(0) +#define XE_VMA_OPS_FLAG_MODIFIES_GPUVA BIT(1) +#define XE_VMA_OPS_FLAG_DOWNGRADE_LOCK BIT(2)u32 flags;#ifdef TEST_VM_OPS_ERROR /** @inject_error: inject error to test error handling */
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 10/11 drm/xe: Thread prefetch of SVM ranges
In reply to Matthew BrostThe migrate_vma_* functions are very CPU-intensive; as a result, prefetching SVM ranges is limited by CPU performance rather than paging copy engine bandwidth. To accelerate SVM range prefetching, the step that calls migrate_vma_* is now threaded. Reuses the page fault work queue for threading.
Running xe_exec_system_allocator --r prefetch-benchmark, which tests 64MB prefetches, shows an increase from ~4.35 GB/s to 12.25 GB/s with this patch on drm-tip. Enabling high SLPC further increases throughput to ~15.25 GB/s, and combining SLPC with ULLS raises it to ~16 GB/s. Both of these optimizations are upcoming.
v2:
- Use dedicated prefetch workqueue
- Pick dedicated prefetch thread count based on profiling
- Skip threaded prefetch for only 1 range or if prefetching to SRAM
- Fully tested
v3:
- Use page fault work queue
--- drivers/gpu/drm/xe/xe_pagefault.c | 30 ++++++- drivers/gpu/drm/xe/xe_svm.c | 17 +++- drivers/gpu/drm/xe/xe_vm.c | 144 +++++++++++++++++++++++------- 3 files changed, 152 insertions(+), 39 deletions(-)
drivers/gpu/drm/xe/xe_pagefault.c +28 -2
@@ -177,7 +177,17 @@ static int xe_pagefault_service(struct xe_pagefault *pf)if (IS_ERR (vm))return PTR_ERR (vm); -down_read (&vm->lock); +/* +* We can't block threaded prefetches from completing. down_read() can +* block on a pending down_write(), so without a trylock here, we could +* deadlock, since the page fault workqueue is shared with prefetches, +* prefetches flush work items onto the same workqueue, and a +* down_write() could be pending. +*/ +if (!down_read_trylock (&vm->lock)) { + err = -EAGAIN ; + goto put_vm; + }if (xe_vm_is_closed (vm)) { err = -ENOENT ;
@@ -202,11 +212,23 @@ static int xe_pagefault_service(struct xe_pagefault *pf)if (!err) vm->usm.last_fault_vma = vma;up_read (&vm->lock); +put_vm:xe_vm_put (vm);return err; } +static void xe_pagefault_queue_retry (struct xe_pagefault_queue *pf_queue, +struct xe_pagefault *pf) +{ +spin_lock_irq (&pf_queue->lock); +if (!pf_queue->tail) + pf_queue->tail = pf_queue->size -xe_pagefault_entry_size (); +else + pf_queue->tail -=xe_pagefault_entry_size (); +spin_unlock_irq (&pf_queue->lock); +} +static bool xe_pagefault_queue_pop (struct xe_pagefault_queue *pf_queue,struct xe_pagefault *pf) {
@@ -259,7 +281,11 @@ static void xe_pagefault_queue_work(struct work_struct *w)continue ; err =xe_pagefault_service (&pf); -if (err) { +if (err == -EAGAIN ) { +xe_pagefault_queue_retry (pf_queue, &pf); +queue_work (gt_to_xe (pf.gt)->usm.pf_wq, w); +break ; + }else if (err) {xe_pagefault_print (&pf);xe_gt_dbg (pf.gt,"Fault response: Unsuccessful %pe\n" ,ERR_PTR (err));
drivers/gpu/drm/xe/xe_svm.c +14 -3
@@ -306,8 +306,19 @@ static void xe_svm_garbage_collector_work_func(struct work_struct *w) struct xe_vm *vm = container_of(w, struct xe_vm, svm.garbage_collector.work); -guard (rwsem_read)(&vm->lock); -xe_svm_garbage_collector (vm); +/* +* We can't block threaded prefetches from completing. down_read() can +* block on a pending down_write(), so without a trylock here, we could +* deadlock, since the page fault workqueue is shared with prefetches, +* prefetches flush work items onto the same workqueue, and a +* down_write() could be pending. +*/ +if (down_read_trylock (&vm->lock)) { +xe_svm_garbage_collector (vm); +up_read (&vm->lock); + }else { +queue_work (vm->xe->usm.pf_wq, &vm->svm.garbage_collector.work); + } }#if IS_ENABLED (CONFIG_DRM_XE_PAGEMAP )
@@ -1148,5 +1159,5 @@ int xe_devm_add(struct xe_tile *tile, struct xe_vram_region *vr)void xe_svm_flush (struct xe_vm *vm) {if (xe_vm_in_fault_mode (vm)) -flush_work (&vm->svm.garbage_collector.work); +__flush_workqueue (vm->xe->usm.pf_wq); }
drivers/gpu/drm/xe/xe_vm.c +110 -34
181 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 10/11] drm/xe: Thread prefetch of SVM ranges
Quoted 240 lines · Matthew Brost
The migrate_vma_* functions are very CPU-intensive; as a result, prefetching SVM ranges is limited by CPU performance rather than paging
copy engine bandwidth. To accelerate SVM range prefetching, the step that calls migrate_vma_* is now threaded. Reuses the page fault work queue for threading.Running
xe_exec_system_allocator--r prefetch-benchmark, which tests 64MB prefetches, shows an increase from ~4.35 GB/s to 12.25 GB/s with this patch on drm-tip. Enabling high SLPC further increases throughput
to ~15.25 GB/s, and combining SLPC with ULLS raises it to ~16 GB/s. Both
of these optimizations are upcoming.v2:
- Use dedicated prefetch workqueue
- Pick dedicated prefetch thread count based on profiling
- Skip threaded prefetch for only 1 range or if prefetching to SRAM
- Fully tested
v3:
- Use page fault work queueCc Thomas Hellström <[email protected]>Cc Himal Prasad Ghimiray <[email protected]>Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_pagefault.c | 30 ++++++- drivers/gpu/drm/xe/xe_svm.c | 17 +++- drivers/gpu/drm/xe/xe_vm.c | 144 +++++++++++++++++++++++----- --3 files changed, 152 insertions(+), 39 deletions(-)drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -177,7 +177,17 @@ static int xe_pagefault_service(struct xe_pagefault *pf) if (IS_ERR(vm)) return PTR_ERR(vm);
- down_read(&vm->lock);
+ /*
+ * We can't block threaded prefetches from completing.down_read()can
+ * block on a pendingdown_write(), so without a trylock here, we could
+ * deadlock, since the page fault workqueue is shared with prefetches,
+ * prefetches flush work items onto the same workqueue, and a + *down_write()could be pending.
+ */
+ if (!down_read_trylock(&vm->lock)) {
+ err =-EAGAIN;
+ gotoput_vm;
+ }
if (xe_vm_is_closed(vm)) {
err =-ENOENT;drivers/gpu/drm/xe/xe_pagefault.c +1
-0@@ -202,11 +212,23 @@ static int xe_pagefault_service(struct xe_pagefault *pf) if (!err) vm->usm.last_fault_vma = vma; up_read(&vm->lock); +put_vm: xe_vm_put(vm);
return err;
}
+static void xe_pagefault_queue_retry(structxe_pagefault_queue*pf_queue,
+ structxe_pagefault*pf) +{
+ spin_lock_irq(&pf_queue->lock);
+ if (!pf_queue->tail)
+ pf_queue->tail =pf_queue->size-xe_pagefault_entry_size();
+ else
+ pf_queue->tail -=xe_pagefault_entry_size(); + spin_unlock_irq(&pf_queue->lock);drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +static bool xe_pagefault_queue_pop(struct
xe_pagefault_queue*pf_queue,
structxe_pagefault*pf) {drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -259,7 +281,11 @@ static void xe_pagefault_queue_work(struct work_struct *w) continue;
err =xe_pagefault_service(&pf);
- if (err) {
+ if (err ==-EAGAIN) {
+ xe_pagefault_queue_retry(pf_queue, &pf); + queue_work(gt_to_xe(pf.gt)->usm.pf_wq, w); + break;
+ } else if (err) {xe_pagefault_print(&pf); xe_gt_dbg(pf.gt, "Fault response:
Unsuccessful %pe\n",
ERR_PTR(err));drivers/gpu/drm/xe/xe_svm.c +0
-0@@ -306,8 +306,19 @@ static void xe_svm_garbage_collector_work_func(struct work_struct *w) struct xe_vm *vm = container_of(w, struct xe_vm, svm.garbage_collector.work);
- guard(rwsem_read)(&vm->lock);
- xe_svm_garbage_collector(vm);
+ /*
+ * We can't block threaded prefetches from completing.down_read()can
+ * block on a pendingdown_write(), so without a trylock here, we could
+ * deadlock, since the page fault workqueue is shared with prefetches,
+ * prefetches flush work items onto the same workqueue, and a + *down_write()could be pending.
+ */
+ if (down_read_trylock(&vm->lock)) {
+ xe_svm_garbage_collector(vm);
+ up_read(&vm->lock);
+ } else {
+ queue_work(vm->xe->usm.pf_wq, &vm-Quoted 1 line
svm.garbage_collector.work);
+ }
}
#ifIS_ENABLED(CONFIG_DRM_XE_PAGEMAP)drivers/gpu/drm/xe/xe_svm.c +1
-1@@ -1148,5 +1159,5 @@ int xe_devm_add(struct xe_tile *tile, struct xe_vram_region *vr) void xe_svm_flush(struct xe_vm *vm) { if (xe_vm_in_fault_mode(vm)) - flush_work(&vm->svm.garbage_collector.work); + __flush_workqueue(vm->xe->usm.pf_wq);}
drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2962,57 +2962,132 @@ static int check_ufence(struct xe_vma *vma) return 0; }drivers/gpu/drm/xe/xe_vm.c +11
-1-static int prefetch_ranges (struct xe_vm *vm,struct xe_vma_op *op) +struct prefetch_thread { + struct work_struct work; + struct drm_gpusvm_ctx *ctx; + struct xe_vma *vma; + struct xe_svm_range *svm_range; + struct xe_tile *tile; + u32 region; + int err; +}; + +static void prefetch_thread_func (struct prefetch_thread *thread){
- booldevmem_possible=IS_DGFX(vm->xe)&&IS_ENABLED(CONFIG_DRM_XE_PAGEMAP);
- structxe_vma*vma =gpuva_to_vma(op->base.prefetch.va); + structxe_vma*vma =thread->vma;
+ structxe_vm*vm =xe_vma_vm(vma);
+ structxe_svm_range*svm_range=thread->svm_range; + u32 region =thread->region;
+ structxe_tile*tile =thread->tile;
int err = 0;
- structxe_svm_range*svm_range;
+ guard(mutex)(&svm_range->lock);drivers/gpu/drm/xe/xe_vm.c +9
-0+ + if (xe_svm_range_is_removed(svm_range)) { + thread->err = -ENODATA; + return; + } + + if (!region) { + xe_svm_range_migrate_to_smem(vm, svm_range); + } else if (xe_svm_range_needs_migrate_to_vram(svm_range, vma,region)) {
+ err = xe_svm_alloc_vram(tile,svm_range, thread-Quoted 1 line
ctx);
+ if (err) {
+ drm_dbg(&vm->xe->drm,
+ "VRAM allocation failed, retry from userspace, asid=%u, gpusvm=%p, errno=%pe\n",
+ vm->usm.asid,&vm->svm.gpusvm,ERR_PTR(err));
+ thread->err =-ENODATA;
+ return;
+ }
+ xe_svm_range_debug(svm_range, "PREFETCH - RANGE MIGRATED TO VRAM");
+ }
+
+ err =xe_svm_range_get_pages(vm, svm_range, thread->ctx); + if (err) {
+ drm_dbg(&vm->xe->drm, "Get pages failed, asid=%u, gpusvm=%p, errno=%pe\n",
+ vm->usm.asid,&vm->svm.gpusvm,ERR_PTR(err)); + if (err ==-EOPNOTSUPP|| err ==-EFAULT|| err == - EPERM)
+ err =-ENODATA;
+ thread->err = err;
+ return;
+ }
+
+ xe_svm_range_debug(svm_range, "PREFETCH - RANGE GET PAGES DONE");drivers/gpu/drm/xe/xe_vm.c +11
-0+} + +static void prefetch_work_func (struct work_struct *w) +{ + struct prefetch_thread *thread = + container_of(w, struct prefetch_thread, work); + + prefetch_thread_func(thread); +} + +static int prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops*vops,
+ structxe_vma_op*op)
+{
+ structxe_vma*vma =gpuva_to_vma(op->base.prefetch.va); + u32 region =op->prefetch_range.region;
structdrm_gpusvm_ctxctx = {};
- structxe_tile*tile;
+ structprefetch_threadstack_thread;
+ structxe_svm_range*svm_range;
+ structprefetch_thread*prefetches;
+ bool sram = region_to_mem_type[region] ==XE_PL_TT; + structxe_tile*tile = sram ?xe_device_get_root_tile(vm->xe):
Quoted 8 lines
+ &vm->xe->tiles[region_to_mem_type[region] -
XE_PL_VRAM0];
unsigned long i;
- u32 region;
+ booldevmem_possible=IS_DGFX(vm->xe)&&
+ IS_ENABLED(CONFIG_DRM_XE_PAGEMAP);
+ boolskip_threads=op->prefetch_range.ranges_count== 1 || sram ||
Starting to work through these.. shouldn't we also allow the user to opportunistically skip this (cgroup/sysfs/etc)? I realize the microbenchmark shows some improvement, but some of the workloads might also be much more heavy on the CPU side and we don't want to throttle that with the extra kernel threads if they aren't heavy on the fault side.
Thanks,
Stuart
Quoted 114 lines
+ !(vops->flags &
XE_VMA_OPS_FLAG_DOWNGRADE_LOCK); + structprefetch_thread*thread =skip_threads?&stack_thread: NULL;
+ int err = 0, idx = 0;
if (!xe_vma_is_cpu_addr_mirror(vma))
return 0;
- region =op->prefetch_range.region;
+ if (!skip_threads) {
+ prefetches = kvmalloc_array(op-Quoted 1 line
prefetch_range.ranges_count,
+
sizeof(*prefetches),GFP_KERNEL);
+ if (!prefetches)
+ return-ENOMEM;
+ }
ctx.read_only =xe_vma_read_only(vma); ctx.devmem_possible =devmem_possible; ctx.check_pages_threshold =devmem_possible?SZ_64K: 0;
- /* TODO: Threading the migration */xa_for_each(&op->prefetch_range.range, i, svm_range){ - guard(mutex)(&svm_range->lock);drivers/gpu/drm/xe/xe_vm.c +4
-6- - if (xe_svm_range_is_removed(svm_range)) - return -ENODATA; - - if (!region) - xe_svm_range_migrate_to_smem(vm, svm_range); + if (!skip_threads) { + thread = prefetches + idx++; + INIT_WORK(&thread->work, prefetch_work_func); + }
- if (xe_svm_range_needs_migrate_to_vram(svm_range, vma, region)) {
- tile = &vm->xe-Quoted 1 line
tiles[region_to_mem_type[region] -
XE_PL_VRAM0];- err =
xe_svm_alloc_vram(tile, svm_range, &ctx);
- if (err) {
- drm_dbg(&vm->xe->drm, "VRAM allocation failed, retry from userspace, asid=%u, gpusvm=%p, errno=%pe\n",
- vm->usm.asid, &vm-Quoted 1 line
svm.gpusvm,
ERR_PTR(err));- return
-ENODATA;
- }
- xe_svm_range_debug(svm_range, "PREFETCH - RANGE MIGRATED TO VRAM");
+ thread->ctx = &ctx;
+ thread->vma = vma;
+ thread->svm_range =svm_range;
+ thread->tile = tile;
+ thread->region = region;
+ thread->err = 0;
+
+ if (skip_threads) {
+ prefetch_thread_func(thread);
+ if (thread->err)
+ returnthread->err;
+ } else {
+ queue_work(vm->xe->usm.pf_wq,&thread->work); }
+ }
- err =xe_svm_range_get_pages(vm, svm_range, &ctx); - if (err) {
- drm_dbg(&vm->xe->drm, "Get pages failed, asid=%u, gpusvm=%p, errno=%pe\n",
- vm->usm.asid,&vm->svm.gpusvm,ERR_PTR(err));
- if (err ==-EOPNOTSUPP|| err ==-EFAULT|| err ==-EPERM)
- err =-ENODATA;
- return err;
+ if (!skip_threads) {
+ for (i = 0; i < idx; ++i) {
+ thread = prefetches + i;
+
+ flush_work(&thread->work);
+ if (thread->err&& (!err || err ==-ENODATA)) + err =thread->err;
}
- xe_svm_range_debug(svm_range, "PREFETCH - RANGE GET PAGES DONE");
+ kvfree(prefetches);
}
return err;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3079,7 +3154,8 @@ static int op_lock_and_prep(struct drm_exec *exec, struct xe_vm *vm, return err; }
-static intvm_bind_ioctl_ops_prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops *vops)
+static int vm_bind_ioctl_ops_prefetch_ranges(structxe_vm*vm, + structxe_vma_ops*vops) {
structxe_vma_op*op;
int err;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3089,7 +3165,7 @@ static intvm_bind_ioctl_ops_prefetch_ranges(struct
xe_vm*vm, structxe_vma_ops
list_for_each_entry(op,&vops->list, link) {
if (op->base.op ==DRM_GPUVA_OP_PREFETCH) { - err =prefetch_ranges(vm, op);
+ err =prefetch_ranges(vm, vops, op); if (err)
return err;
}
Matthew Brost
maintainerRe: [PATCH 10/11] drm/xe: Thread prefetch of SVM ranges
Quoted 245 lines · Stuart
Quoted 244 lines · Matthew Brost
The migrate_vma_* functions are very CPU-intensive; as a result, prefetching SVM ranges is limited by CPU performance rather than paging
copy engine bandwidth. To accelerate SVM range prefetching, the step that calls migrate_vma_* is now threaded. Reuses the page fault work queue for threading.Running
xe_exec_system_allocator--r prefetch-benchmark, which tests 64MB prefetches, shows an increase from ~4.35 GB/s to 12.25 GB/s with this patch on drm-tip. Enabling high SLPC further increases throughput
to ~15.25 GB/s, and combining SLPC with ULLS raises it to ~16 GB/s. Both
of these optimizations are upcoming.v2:
- Use dedicated prefetch workqueue
- Pick dedicated prefetch thread count based on profiling
- Skip threaded prefetch for only 1 range or if prefetching to SRAM
- Fully tested
v3:
- Use page fault work queueCc Thomas Hellström <[email protected]>Cc Himal Prasad Ghimiray <[email protected]>Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_pagefault.c | 30 ++++++- drivers/gpu/drm/xe/xe_svm.c | 17 +++- drivers/gpu/drm/xe/xe_vm.c | 144 +++++++++++++++++++++++----- --3 files changed, 152 insertions(+), 39 deletions(-)drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -177,7 +177,17 @@ static int xe_pagefault_service(struct xe_pagefault *pf) if (IS_ERR(vm)) return PTR_ERR(vm);
- down_read(&vm->lock);
+ /*
+ * We can't block threaded prefetches from completing.down_read()can
+ * block on a pendingdown_write(), so without a trylock here, we could
+ * deadlock, since the page fault workqueue is shared with prefetches,
+ * prefetches flush work items onto the same workqueue, and a + *down_write()could be pending.
+ */
+ if (!down_read_trylock(&vm->lock)) {
+ err =-EAGAIN;
+ gotoput_vm;
+ }
if (xe_vm_is_closed(vm)) {
err =-ENOENT;drivers/gpu/drm/xe/xe_pagefault.c +1
-0@@ -202,11 +212,23 @@ static int xe_pagefault_service(struct xe_pagefault *pf) if (!err) vm->usm.last_fault_vma = vma; up_read(&vm->lock); +put_vm: xe_vm_put(vm);
return err;
}
+static void xe_pagefault_queue_retry(structxe_pagefault_queue*pf_queue,
+ structxe_pagefault*pf) +{
+ spin_lock_irq(&pf_queue->lock);
+ if (!pf_queue->tail)
+ pf_queue->tail =pf_queue->size-xe_pagefault_entry_size();
+ else
+ pf_queue->tail -=xe_pagefault_entry_size(); + spin_unlock_irq(&pf_queue->lock);drivers/gpu/drm/xe/xe_pagefault.c +2
-0+} +static bool xe_pagefault_queue_pop(struct
xe_pagefault_queue*pf_queue,
structxe_pagefault*pf) {drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -259,7 +281,11 @@ static void xe_pagefault_queue_work(struct work_struct *w) continue;
err =xe_pagefault_service(&pf);
- if (err) {
+ if (err ==-EAGAIN) {
+ xe_pagefault_queue_retry(pf_queue, &pf); + queue_work(gt_to_xe(pf.gt)->usm.pf_wq, w); + break;
+ } else if (err) {xe_pagefault_print(&pf); xe_gt_dbg(pf.gt, "Fault response:
Unsuccessful %pe\n",
ERR_PTR(err));drivers/gpu/drm/xe/xe_svm.c +0
-0@@ -306,8 +306,19 @@ static void xe_svm_garbage_collector_work_func(struct work_struct *w) struct xe_vm *vm = container_of(w, struct xe_vm, svm.garbage_collector.work);
- guard(rwsem_read)(&vm->lock);
- xe_svm_garbage_collector(vm);
+ /*
+ * We can't block threaded prefetches from completing.down_read()can
+ * block on a pendingdown_write(), so without a trylock here, we could
+ * deadlock, since the page fault workqueue is shared with prefetches,
+ * prefetches flush work items onto the same workqueue, and a + *down_write()could be pending.
+ */
+ if (down_read_trylock(&vm->lock)) {
+ xe_svm_garbage_collector(vm);
+ up_read(&vm->lock);
+ } else {
+ queue_work(vm->xe->usm.pf_wq, &vm-Quoted 1 line
svm.garbage_collector.work);
+ }
}
#ifIS_ENABLED(CONFIG_DRM_XE_PAGEMAP)drivers/gpu/drm/xe/xe_svm.c +1
-1@@ -1148,5 +1159,5 @@ int xe_devm_add(struct xe_tile *tile, struct xe_vram_region *vr) void xe_svm_flush(struct xe_vm *vm) { if (xe_vm_in_fault_mode(vm)) - flush_work(&vm->svm.garbage_collector.work); + __flush_workqueue(vm->xe->usm.pf_wq);}
drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2962,57 +2962,132 @@ static int check_ufence(struct xe_vma *vma) return 0; }drivers/gpu/drm/xe/xe_vm.c +11
-1-static int prefetch_ranges (struct xe_vm *vm,struct xe_vma_op *op) +struct prefetch_thread { + struct work_struct work; + struct drm_gpusvm_ctx *ctx; + struct xe_vma *vma; + struct xe_svm_range *svm_range; + struct xe_tile *tile; + u32 region; + int err; +}; + +static void prefetch_thread_func (struct prefetch_thread *thread){
- booldevmem_possible=IS_DGFX(vm->xe)&&IS_ENABLED(CONFIG_DRM_XE_PAGEMAP);
- structxe_vma*vma =gpuva_to_vma(op->base.prefetch.va); + structxe_vma*vma =thread->vma;
+ structxe_vm*vm =xe_vma_vm(vma);
+ structxe_svm_range*svm_range=thread->svm_range; + u32 region =thread->region;
+ structxe_tile*tile =thread->tile;
int err = 0;
- structxe_svm_range*svm_range;
+ guard(mutex)(&svm_range->lock);drivers/gpu/drm/xe/xe_vm.c +9
-0+ + if (xe_svm_range_is_removed(svm_range)) { + thread->err = -ENODATA; + return; + } + + if (!region) { + xe_svm_range_migrate_to_smem(vm, svm_range); + } else if (xe_svm_range_needs_migrate_to_vram(svm_range, vma,region)) {
+ err = xe_svm_alloc_vram(tile,svm_range, thread-Quoted 1 line
ctx);
+ if (err) {
+ drm_dbg(&vm->xe->drm,
+ "VRAM allocation failed, retry from userspace, asid=%u, gpusvm=%p, errno=%pe\n",
+ vm->usm.asid,&vm->svm.gpusvm,ERR_PTR(err));
+ thread->err =-ENODATA;
+ return;
+ }
+ xe_svm_range_debug(svm_range, "PREFETCH - RANGE MIGRATED TO VRAM");
+ }
+
+ err =xe_svm_range_get_pages(vm, svm_range, thread->ctx); + if (err) {
+ drm_dbg(&vm->xe->drm, "Get pages failed, asid=%u, gpusvm=%p, errno=%pe\n",
+ vm->usm.asid,&vm->svm.gpusvm,ERR_PTR(err)); + if (err ==-EOPNOTSUPP|| err ==-EFAULT|| err == - EPERM)
+ err =-ENODATA;
+ thread->err = err;
+ return;
+ }
+
+ xe_svm_range_debug(svm_range, "PREFETCH - RANGE GET PAGES DONE");drivers/gpu/drm/xe/xe_vm.c +11
-0+} + +static void prefetch_work_func (struct work_struct *w) +{ + struct prefetch_thread *thread = + container_of(w, struct prefetch_thread, work); + + prefetch_thread_func(thread); +} + +static int prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops*vops,
+ structxe_vma_op*op)
+{
+ structxe_vma*vma =gpuva_to_vma(op->base.prefetch.va); + u32 region =op->prefetch_range.region;
structdrm_gpusvm_ctxctx = {};
- structxe_tile*tile;
+ structprefetch_threadstack_thread;
+ structxe_svm_range*svm_range;
+ structprefetch_thread*prefetches;
+ bool sram = region_to_mem_type[region] ==XE_PL_TT; + structxe_tile*tile = sram ?xe_device_get_root_tile(vm->xe):
+ &vm->xe->tiles[region_to_mem_type[region] -XE_PL_VRAM0];
unsigned long i;
- u32 region;
Quoted 8 lines
Quoted 4 lines
+ bool
devmem_possible=IS_DGFX(vm->xe)&&
+ IS_ENABLED(CONFIG_DRM_XE_PAGEMAP);
+ boolskip_threads=op->prefetch_range.ranges_count== 1 || sram ||Starting to work through these.. shouldn't we also allow the user to opportunistically skip this (cgroup/sysfs/etc)? I realize the microbenchmark shows some improvement, but some of the workloads might
Prefetch without this on tip is so slow, no one would ever use it.
Quoted 4 lines
also be much more heavy on the CPU side and we don't want to throttle that with the extra kernel threads if they aren't heavy on the fault side.
The next patch adds this, via debugfs. We could make it a bit more offical via sysfs or configfs eventually.
Also once we land THP device pages, all we need is 2 threads on BMG as the CPU time of a 2M prefetch goes from ~350us to 10us. This should scale to a CPU <-> GPU bus 8x faster - by scale I mean we can hit peak bandwidth on the bus. Also once THP device pages land, most of what prefetch threads are doing is just sleeping waiting for the copy to complete, so CPU is free to do other things. Hopefully we that in 6.19 timeframe.
Matt
Quoted 118 lines
Thanks,
StuartQuoted 114 lines
+ !(vops->flags &
XE_VMA_OPS_FLAG_DOWNGRADE_LOCK); + structprefetch_thread*thread =skip_threads?&stack_thread: NULL;
+ int err = 0, idx = 0;
if (!xe_vma_is_cpu_addr_mirror(vma))
return 0;
- region =op->prefetch_range.region;
+ if (!skip_threads) {
+ prefetches = kvmalloc_array(op-Quoted 1 line
prefetch_range.ranges_count,
+
sizeof(*prefetches),GFP_KERNEL);
+ if (!prefetches)
+ return-ENOMEM;
+ }
ctx.read_only =xe_vma_read_only(vma); ctx.devmem_possible =devmem_possible; ctx.check_pages_threshold =devmem_possible?SZ_64K: 0;
- /* TODO: Threading the migration */xa_for_each(&op->prefetch_range.range, i, svm_range){ - guard(mutex)(&svm_range->lock);drivers/gpu/drm/xe/xe_vm.c +4
-6- - if (xe_svm_range_is_removed(svm_range)) - return -ENODATA; - - if (!region) - xe_svm_range_migrate_to_smem(vm, svm_range); + if (!skip_threads) { + thread = prefetches + idx++; + INIT_WORK(&thread->work, prefetch_work_func); + }
- if (xe_svm_range_needs_migrate_to_vram(svm_range, vma, region)) {
- tile = &vm->xe-Quoted 1 line
tiles[region_to_mem_type[region] -
XE_PL_VRAM0];- err =
xe_svm_alloc_vram(tile, svm_range, &ctx);
- if (err) {
- drm_dbg(&vm->xe->drm, "VRAM allocation failed, retry from userspace, asid=%u, gpusvm=%p, errno=%pe\n",
- vm->usm.asid, &vm-Quoted 1 line
svm.gpusvm,
ERR_PTR(err));- return
-ENODATA;
- }
- xe_svm_range_debug(svm_range, "PREFETCH - RANGE MIGRATED TO VRAM");
+ thread->ctx = &ctx;
+ thread->vma = vma;
+ thread->svm_range =svm_range;
+ thread->tile = tile;
+ thread->region = region;
+ thread->err = 0;
+
+ if (skip_threads) {
+ prefetch_thread_func(thread);
+ if (thread->err)
+ returnthread->err;
+ } else {
+ queue_work(vm->xe->usm.pf_wq,&thread->work); }
+ }
- err =xe_svm_range_get_pages(vm, svm_range, &ctx); - if (err) {
- drm_dbg(&vm->xe->drm, "Get pages failed, asid=%u, gpusvm=%p, errno=%pe\n",
- vm->usm.asid,&vm->svm.gpusvm,ERR_PTR(err));
- if (err ==-EOPNOTSUPP|| err ==-EFAULT|| err ==-EPERM)
- err =-ENODATA;
- return err;
+ if (!skip_threads) {
+ for (i = 0; i < idx; ++i) {
+ thread = prefetches + i;
+
+ flush_work(&thread->work);
+ if (thread->err&& (!err || err ==-ENODATA)) + err =thread->err;
}
- xe_svm_range_debug(svm_range, "PREFETCH - RANGE GET PAGES DONE");
+ kvfree(prefetches);
}
return err;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3079,7 +3154,8 @@ static int op_lock_and_prep(struct drm_exec *exec, struct xe_vm *vm, return err; }
-static intvm_bind_ioctl_ops_prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops *vops)
+static int vm_bind_ioctl_ops_prefetch_ranges(structxe_vm*vm, + structxe_vma_ops*vops) {
structxe_vma_op*op;
int err;drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3089,7 +3165,7 @@ static intvm_bind_ioctl_ops_prefetch_ranges(struct
xe_vm*vm, structxe_vma_ops
list_for_each_entry(op,&vops->list, link) {
if (op->base.op ==DRM_GPUVA_OP_PREFETCH) { - err =prefetch_ranges(vm, op);
+ err =prefetch_ranges(vm, vops, op); if (err)
return err;
}
Matthew Brost
maintainerPATCH 11/11 drm/xe: Add num_pf_queue modparam
In reply to Matthew BrostEnable quick experiment to see how number of page fault queues affects performance.
--- drivers/gpu/drm/xe/xe_device.c | 15 +++++++++++++-- drivers/gpu/drm/xe/xe_device_types.h | 6 ++++-- drivers/gpu/drm/xe/xe_module.c | 5 +++++ drivers/gpu/drm/xe/xe_module.h | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 8 ++++---- drivers/gpu/drm/xe/xe_vm.c | 3 ++- 6 files changed, 29 insertions(+), 9 deletions(-)
drivers/gpu/drm/xe/xe_device.c +13 -2
@@ -413,6 +413,17 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)ttm_device_fini (&xe->ttm); } +static void xe_device_parse_modparame (struct xe_device *xe) +{ + xe->info.force_execlist = xe_modparam.force_execlist; + xe->info.num_pf_queue = xe_modparam.num_pf_queue; +if (xe->info.num_pf_queue <1 ) + xe->info.num_pf_queue =1 ; +else if (xe->info.num_pf_queue >XE_PAGEFAULT_QUEUE_MAX ) + xe->info.num_pf_queue =XE_PAGEFAULT_QUEUE_MAX ; + xe->atomic_svm_timeslice_ms =5 ; +} +struct xe_device *xe_device_create (struct pci_dev *pdev,const struct pci_device_id *ent) {
@@ -446,8 +457,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev, xe->info.devid = pdev->device; xe->info.revid = pdev->revision; - xe->info.force_execlist = xe_modparam.force_execlist; - xe->atomic_svm_timeslice_ms =5 ; + +xe_device_parse_modparame (xe); err =xe_irq_init (xe);if (err)
drivers/gpu/drm/xe/xe_device_types.h +4 -2
@@ -243,6 +243,8 @@ struct xe_device {u8 revid;/** @info.step: stepping information for each IP */ struct xe_step_info step; +/** @info.num_pf_queue: Number of page fault queues */ +int num_pf_queue;/** @info.dma_mask_size: DMA address bits */ u8 dma_mask_size;/** @info.vram_flags: Vram flags */
@@ -399,9 +401,9 @@ struct xe_device {struct rw_semaphore lock;/** @usm.pf_wq: page fault work queue, unbound, high priority */ struct workqueue_struct *pf_wq; -#define XE_PAGEFAULT_QUEUE_COUNT 4 +#define XE_PAGEFAULT_QUEUE_MAX 8/** @pf_queue: Page fault queues */ -struct xe_pagefault_queue pf_queue[XE_PAGEFAULT_QUEUE_COUNT ]; +struct xe_pagefault_queue pf_queue[XE_PAGEFAULT_QUEUE_MAX ]; } usm;/** @pinned: pinned BO state */
drivers/gpu/drm/xe/xe_module.c +5 -0
@@ -27,6 +27,7 @@#define DEFAULT_PROBE_DISPLAY true#define DEFAULT_VRAM_BAR_SIZE 0#define DEFAULT_FORCE_PROBE CONFIG_DRM_XE_FORCE_PROBE +#define DEFAULT_NUM_PF_QUEUE 4#define DEFAULT_MAX_VFS ~0#define DEFAULT_MAX_VFS_STR "unlimited"#define DEFAULT_WEDGED_MODE 1
@@ -40,6 +41,7 @@ struct xe_modparam xe_modparam = { .max_vfs = DEFAULT_MAX_VFS, #endif .wedged_mode = DEFAULT_WEDGED_MODE, + .num_pf_queue = DEFAULT_NUM_PF_QUEUE, .svm_notifier_size = DEFAULT_SVM_NOTIFIER_SIZE, /* the rest are 0 by default */ };
@@ -93,6 +95,9 @@ MODULE_PARM_DESC(wedged_mode,"Module's default policy for the wedged mode (0=never, 1=upon-critical-errors, 2=upon-any-hang " "[default=" __stringify(DEFAULT_WEDGED_MODE) "])"); +module_param_named (num_pf_queue, xe_modparam.num_pf_queue, int,0600 ); +MODULE_PARM_DESC (num_pf_queue,"Number of page fault queue, default=4, min=1, max=8" ); +static int xe_check_nomodeset (void ) {if (drm_firmware_drivers_only ())
drivers/gpu/drm/xe/xe_module.h +1 -0
@@ -22,6 +22,7 @@ struct xe_modparam {unsigned int max_vfs;#endif int wedged_mode; +int num_pf_queue;u32 svm_notifier_size; };
drivers/gpu/drm/xe/xe_pagefault.c +4 -4
@@ -373,11 +373,11 @@ int xe_pagefault_init(struct xe_device *xe) xe->usm.pf_wq =alloc_workqueue ("xe_page_fault_work_queue" ,WQ_UNBOUND |WQ_HIGHPRI , -XE_PAGEFAULT_QUEUE_COUNT ); + xe->info.num_pf_queue);if (!xe->usm.pf_wq)return -ENOMEM ; -for (i =0 ; i <XE_PAGEFAULT_QUEUE_COUNT ; ++i) { +for (i =0 ; i < xe->info.num_pf_queue; ++i) { err =xe_pagefault_queue_init (xe, xe->usm.pf_queue + i);if (err) goto err_out;
@@ -420,7 +420,7 @@ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt) {int i; -for (i =0 ; i <XE_PAGEFAULT_QUEUE_COUNT ; ++i) +for (i =0 ; i < xe->info.num_pf_queue; ++i)xe_pagefault_queue_reset (xe, gt, xe->usm.pf_queue + i); }
@@ -442,7 +442,7 @@ static int xe_pagefault_queue_index(struct xe_device *xe)WRITE_ONCE (xe->usm.current_pf_queue, (old_pf_queue +1 )); -return old_pf_queue %XE_PAGEFAULT_QUEUE_COUNT ; +return old_pf_queue % xe->info.num_pf_queue; }/**
drivers/gpu/drm/xe/xe_vm.c +2 -1
@@ -3039,7 +3039,8 @@ static int prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops *vops,bool devmem_possible =IS_DGFX (vm->xe) &&IS_ENABLED (CONFIG_DRM_XE_PAGEMAP );bool skip_threads = op->prefetch_range.ranges_count ==1 || sram || - !(vops->flags &XE_VMA_OPS_FLAG_DOWNGRADE_LOCK ); + !(vops->flags &XE_VMA_OPS_FLAG_DOWNGRADE_LOCK ) || + vm->xe->info.num_pf_queue ==1 ;struct prefetch_thread *thread = skip_threads ? &stack_thread :NULL ;int err =0 , idx =0 ;
Signature · 1 line
2.34.1
Re: [PATCH 11/11] drm/xe: Add num_pf_queue modparam
Quoted 174 lines · Matthew Brost
Enable quick experiment to see how number of page fault queues affects
performance.Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 15 +++++++++++++--drivers/gpu/drm/xe/xe_device_types.h| 6 ++++-- drivers/gpu/drm/xe/xe_module.c | 5 +++++ drivers/gpu/drm/xe/xe_module.h | 1 + drivers/gpu/drm/xe/xe_pagefault.c | 8 ++++---- drivers/gpu/drm/xe/xe_vm.c | 3 ++-6 files changed, 29 insertions(+), 9 deletions(-)drivers/gpu/drm/xe/xe_device.c +0
-0@@ -413,6 +413,17 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy) ttm_device_fini(&xe->ttm); }drivers/gpu/drm/xe/xe_device.c +11
-0+static void xe_device_parse_modparame (struct xe_device *xe) +{ + xe->info.force_execlist = xe_modparam.force_execlist; + xe->info.num_pf_queue = xe_modparam.num_pf_queue; + if (xe->info.num_pf_queue < 1) + xe->info.num_pf_queue = 1; + else if (xe->info.num_pf_queue > XE_PAGEFAULT_QUEUE_MAX) + xe->info.num_pf_queue = XE_PAGEFAULT_QUEUE_MAX; + xe->atomic_svm_timeslice_ms = 5; +} +struct
xe_device*xe_device_create(structpci_dev*pdev, const structpci_device_id*ent) {drivers/gpu/drm/xe/xe_device.c +0
-0@@ -446,8 +457,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
xe->info.devid =pdev->device;xe->info.revid=pdev->revision;
- xe->info.force_execlist = xe_modparam.force_execlist; - xe->atomic_svm_timeslice_ms = 5;
+
+ xe_device_parse_modparame(xe);
err =xe_irq_init(xe);
if (err)drivers/gpu/drm/xe/xe_device_types.h +2
-0@@ -243,6 +243,8 @@ struct xe_device { u8 revid; /** @info.step: stepping information for each IP */ struct xe_step_info step; + /** @info.num_pf_queue: Number of page fault queues */ + int num_pf_queue; /** @info.dma_mask_size: DMA address bits */ u8 dma_mask_size;/** @info.vram_flags: Vram flags */
drivers/gpu/drm/xe/xe_device_types.h +0
-0@@ -399,9 +401,9 @@ struct xe_device { struct rw_semaphore lock; /** @usm.pf_wq: page fault work queue, unbound, highpriority */
structworkqueue_struct*pf_wq;drivers/gpu/drm/xe/xe_device_types.h +1
-1-#define XE_PAGEFAULT_QUEUE_COUNT 4 +#define XE_PAGEFAULT_QUEUE_MAX 8/** @pf_queue: Page fault queues */ - struct
xe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_COUNT];
+ structxe_pagefault_queuepf_queue[XE_PAGEFAULT_QUEUE_MAX];
} usm;
/** @pinned: pinned BO state */drivers/gpu/drm/xe/xe_module.c +2
-0@@ -27,6 +27,7 @@ #define DEFAULT_PROBE_DISPLAY true #define DEFAULT_VRAM_BAR_SIZE 0 #define DEFAULT_FORCE_PROBE CONFIG_DRM_XE_FORCE_PROBE +#define DEFAULT_NUM_PF_QUEUE 4 #define DEFAULT_MAX_VFS ~0 #define DEFAULT_MAX_VFS_STR "unlimited" #define DEFAULT_WEDGED_MODE 1@@ -40,6 +41,7 @@ struct xe_modparam xe_modparam = { .max_vfs = DEFAULT_MAX_VFS, #endif .wedged_mode = DEFAULT_WEDGED_MODE, + .num_pf_queue = DEFAULT_NUM_PF_QUEUE, .svm_notifier_size = DEFAULT_SVM_NOTIFIER_SIZE, /* the rest are 0 by default */ };@@ -93,6 +95,9 @@ MODULE_PARM_DESC(wedged_mode,"Module's default policy for the wedged mode (0=never, 1=upon-critical-errors, 2=upon-any-hang " "[default="
__stringify(DEFAULT_WEDGED_MODE)"])");
+module_param_named(num_pf_queue, xe_modparam.num_pf_queue, int, 0600);
+MODULE_PARM_DESC(num_pf_queue, "Number of page fault queue, default=4, min=1, max=8");
+
static intxe_check_nomodeset(void)
{
if (drm_firmware_drivers_only())drivers/gpu/drm/xe/xe_module.h +1
-0@@ -22,6 +22,7 @@ struct xe_modparam { unsigned int max_vfs; #endif int wedged_mode; + int num_pf_queue; u32 svm_notifier_size; };drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -373,11 +373,11 @@ int xe_pagefault_init(struct xe_device *xe)
xe->usm.pf_wq = alloc_workqueue("xe_page_fault_work_queue",WQ_UNBOUND|WQ_HIGHPRI, - XE_PAGEFAULT_QUEUE_COUNT); + xe->info.num_pf_queue); if (!xe->usm.pf_wq)
return-ENOMEM;
- for (i = 0; i <XE_PAGEFAULT_QUEUE_COUNT; ++i) { + for (i = 0; i <xe->info.num_pf_queue; ++i) {
err =xe_pagefault_queue_init(xe, xe->usm.pf_queue + i);
if (err)
gotoerr_out;drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -420,7 +420,7 @@ void xe_pagefault_reset(struct xe_device *xe, struct xe_gt *gt) { int i;
- for (i = 0; i <XE_PAGEFAULT_QUEUE_COUNT; ++i)
+ for (i = 0; i <xe->info.num_pf_queue; ++i)xe_pagefault_queue_reset(xe, gt, xe->usm.pf_queue + i);
}drivers/gpu/drm/xe/xe_pagefault.c +0
-0@@ -442,7 +442,7 @@ static int xe_pagefault_queue_index(struct xe_device *xe)
WRITE_ONCE(xe->usm.current_pf_queue, (old_pf_queue+ 1));
- returnold_pf_queue%XE_PAGEFAULT_QUEUE_COUNT; + returnold_pf_queue%xe->info.num_pf_queue;
}
/**drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -3039,7 +3039,8 @@ static int prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops *vops,
Quoted 7 lines
bool
devmem_possible=IS_DGFX(vm->xe)&&IS_ENABLED(CONFIG_DRM_XE_PAGEMAP);
boolskip_threads=op->prefetch_range.ranges_count== 1 || sram ||
- !(vops->flags &XE_VMA_OPS_FLAG_DOWNGRADE_LOCK); + !(vops->flags &XE_VMA_OPS_FLAG_DOWNGRADE_LOCK) || + vm->xe->info.num_pf_queue == 1;
Ah ok well this does add that, but we still might want to skip but with the default number of queues (4).
Also, should we make this a configfs to allow the users to configure this per device for more fine tuning? I understand you have this just for local debug right now...
Thanks,
Stuart
Quoted 4 lines
struct
prefetch_thread*thread =skip_threads?&stack_thread: NULL;
int err = 0, idx = 0;
Patchwork
CI✗ CI.checkpatch: warning for Pagefault refactor, fine grained fault locking, threaded prefetch
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: Pagefault refactor, fine grained fault locking, threaded prefetch
URL : https://patchwork.freedesktop.org/series/152565/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master c298eac5978c38dcc62a70c0d73c91765e7cc296
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 7ee7c0e5458c479b4896cf904e810b14b1953536
Author: Matthew Brost <[email protected]> Date: Tue Aug 5 23:22:42 2025 -0700
drm/xe: Add num_pf_queue modparam
Enable quick experiment to see how number of page fault queues affects performance.
+ /mt/dim checkpatch d636513f71664d86e9205b92a45bd8b21ea67a2b drm-intel f491b29a011e drm/xe: Stub out new pagefault layer
-:25: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #25:
new file mode 100644
-:223: WARNING:TYPO_SPELLING: 'acknowledgement' may be misspelled - perhaps 'acknowledgment'? #223: FILE: drivers/gpu/drm/xe/xe_pagefault_types.h:100:
+ * acknowledgement to formulate response to HW/FW interface.
^^^^^^^^^^^^^^^
total: 0 errors, 2 warnings, 0 checks, 214 lines checkeda506cb47dffa drm/xe: Implement xe_pagefault_init5e7c9be76dc1 drm/xe: Implement xe_pagefault_reset0789190d741c drm/xe: Implement xe_pagefault_handler99c1fae0ffc3 drm/xe: Implement xe_pagefault_queue_work90f57ccf361e drm/xe: Add xe_guc_pagefault layer
-:97: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #97:
new file mode 100644
-:179: WARNING:ONE_SEMICOLON: Statements terminations use 1 semicolon #179: FILE: drivers/gpu/drm/xe/xe_guc_pagefault.c:78:
+ pf.consumer.access_type = FIELD_GET(PFD_ACCESS_TYPE, msg[2]);;
-:240: ERROR:MISSING_SIGN_OFF: Missing Signed-off-by: line(s)
total: 1 errors, 2 warnings, 0 checks, 185 lines checkeda9748a3e20af drm/xe: Remove unused GT page fault code
-:13: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
deleted file mode 100644
total: 0 errors, 1 warnings, 0 checks, 71 lines checkeddf42d2ed34f0 drm/xe: Fine grained page fault locking
-:752: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: Matthew Brost <[email protected]>' != 'Signed-off-by: Matthew Brost <[email protected]>'
total: 0 errors, 1 warnings, 0 checks, 644 lines checked b90179a168fb drm/xe: Allow prefetch-only VM bind IOCTLs to use VM read lock 78b8cb96d86e drm/xe: Thread prefetch of SVM ranges7ee7c0e5458c drm/xe: Add num_pf_queue modparam
Patchwork
CI✗ CI.KUnit: failure for Pagefault refactor, fine grained fault locking, threaded prefetch
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: Pagefault refactor, fine grained fault locking, threaded prefetch
URL : https://patchwork.freedesktop.org/series/152565/
State : failure
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig
ERROR:root:../drivers/gpu/drm/xe/xe_vm.c: In function ‘prefetch_thread_func’:../drivers/gpu/drm/xe/xe_vm.c:2984:32: error: ‘struct xe_svm_range’ has no member named ‘lock’
2984 | guard(mutex)(&svm_range->lock);
| ^~../drivers/gpu/drm/xe/xe_vm.c:2986:13: error: implicit declaration of function ‘xe_svm_range_is_removed’; did you mean ‘xe_svm_range_size’? [-Werror=implicit-function-declaration]
2986 | if (xe_svm_range_is_removed(svm_range)) {
| ^~~~~~~~~~~~~~~~~~~~~~~
| xe_svm_range_sizecc1: some warnings being treated as errors
make[7]: *** [../scripts/Makefile.build:287: drivers/gpu/drm/xe/xe_vm.o] Error 1 make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:555: drivers/gpu/drm/xe] Error 2 make[5]: *** [../scripts/Makefile.build:555: drivers/gpu/drm] Error 2 make[4]: *** [../scripts/Makefile.build:555: drivers/gpu] Error 2 make[3]: *** [../scripts/Makefile.build:555: drivers] Error 2 make[2]: *** [/kernel/Makefile:2003: .] Error 2
make[1]: *** [/kernel/Makefile:248: __sub-make] Error 2
make: *** [Makefile:248: __sub-make] Error 2
[06:36:19] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [06:36:23] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel