Skip to contentSkip to conversation

TLB Invalidation

PATCH In review Rodrigo Vivi 3 participants 31 messages Feb 3, 2023 – Feb 17, 2023

Subsystems (2)
lore
Share & tools
lore

Rodrigo Vivi

author maintainer
#0 lore raw

cover TLB Invalidation

Let's just confirm the reviews on this patch and get them merged to drm-xe-next.

Matthew Brost (22):
drm/xe: Don't process TLB invalidation done in CT fast-path drm/xe: Break of TLB invalidation into its own file drm/xe: Move TLB invalidation variable to own sub-structure in GT drm/xe: Add TLB invalidation fence
drm/xe: Invalidate TLB after unbind is complete
drm/xe: Kernel doc GT TLB invalidations
drm/xe: Add TLB invalidation fence ftrace
drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
drm/xe: Add TDR for invalidation fence timeout cleanup drm/xe: Only set VM->asid for platforms that support a ASID drm/xe: Delete debugfs entry to issue TLB invalidation drm/xe: Add has_range_tlb_invalidation device attribute drm/xe: Add range based TLB invalidations
drm/xe: Propagate error from bind operations to async fence drm/xe: Use GuC to do GGTT invalidations for the GuC firmware drm/xe: Coalesce GGTT invalidations
drm/xe: Lock GGTT on when restoring kernel BOs
drm/xe: Propagate VM unbind error to invalidation fence drm/xe: Signal invalidation fence immediately if CT send fails drm/xe: Add has_asid to device info
drm/xe: Add TLB invalidation fence after rebinds issued from execs drm/xe: Drop TLB invalidation from ring operations

 drivers/gpu/drm/xe/Makefile                   |   1 +
 drivers/gpu/drm/xe/xe_bo_evict.c              |   5 +-
 drivers/gpu/drm/xe/xe_device.c                |  14 +
 drivers/gpu/drm/xe/xe_device_types.h          |   4 +
 drivers/gpu/drm/xe/xe_ggtt.c                  |  23 +-
 drivers/gpu/drm/xe/xe_ggtt_types.h            |   2 +
 drivers/gpu/drm/xe/xe_gt.c                    |  19 +
 drivers/gpu/drm/xe/xe_gt.h                    |   1 +
 drivers/gpu/drm/xe/xe_gt_debugfs.c            |  21 --
 drivers/gpu/drm/xe/xe_gt_pagefault.c          | 104 +-----
 drivers/gpu/drm/xe/xe_gt_pagefault.h          |   3 -
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c   | 342 ++++++++++++++++++
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h   |  26 ++
 .../gpu/drm/xe/xe_gt_tlb_invalidation_types.h |  28 ++
 drivers/gpu/drm/xe/xe_gt_types.h              |  41 ++-
 drivers/gpu/drm/xe/xe_guc.c                   |   2 +
 drivers/gpu/drm/xe/xe_guc_ct.c                |  10 +-
 drivers/gpu/drm/xe/xe_guc_types.h             |   2 +
 drivers/gpu/drm/xe/xe_lrc.c                   |   4 +-
 drivers/gpu/drm/xe/xe_pci.c                   |   7 +
 drivers/gpu/drm/xe/xe_pt.c                    | 130 +++++++
 drivers/gpu/drm/xe/xe_ring_ops.c              |  40 +-
 drivers/gpu/drm/xe/xe_trace.h                 |  55 +++
 drivers/gpu/drm/xe/xe_uc.c                    |   9 +-
 drivers/gpu/drm/xe/xe_uc.h                    |   1 +
 drivers/gpu/drm/xe/xe_vm.c                    |  42 ++-
 26 files changed, 736 insertions(+), 200 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c
 create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h
 create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h
Signature · 1 line
2.39.1
author maintainer
#1 lore raw

PATCH 1/22 drm/xe: Don't process TLB invalidation done in CT fast-path

From: Matthew Brost <[email protected]>

We can't currently do this due to TLB invalidation done handler expecting the seqno being received in-order, with the fast-path a TLB invalidation done could pass one being processed in the slow-path in an extreme corner case. Remove TLB invalidation done from the fast-path for now and in a follow up reenable this once the TLB invalidation done handler can deal with out of order seqno.

Cc Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/xe_guc_ct.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_guc_ct.c +8 -1
index f48eb01847ef..6e25c1d5d43e 100644
@@ -966,7 +966,14 @@ static int g2h_read(struct xe_guc_ct *ct, u32 *msg, bool fast_path)
 			return 0;
 
 		switch (FIELD_GET(GUC_HXG_EVENT_MSG_0_ACTION, msg[1])) {
-		case XE_GUC_ACTION_TLB_INVALIDATION_DONE:
+		/*
+		 * FIXME: We really should process
+		 * XE_GUC_ACTION_TLB_INVALIDATION_DONE here in the fast-path as
+		 * these critical for page fault performance. We currently can't
+		 * due to TLB invalidation done algorithm expecting the seqno
+		 * returned in-order. With some small changes to the algorithm
+		 * and locking we should be able to support out-of-order seqno.
+		 */
 		case XE_GUC_ACTION_REPORT_PAGE_FAULT_REQ_DESC:
 			break;	/* Process these in fast-path */
 		default:
Signature · 1 line
2.39.1
author maintainer
#2 lore raw

PATCH 2/22 drm/xe: Break of TLB invalidation into its own file

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

TLB invalidation is used by more than USM (page faults) so break this code out into its own file.

Cc Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/Makefile                 |   1 +
 drivers/gpu/drm/xe/xe_gt.c                  |   5 +
 drivers/gpu/drm/xe/xe_gt_pagefault.c        |  99 +----------------
 drivers/gpu/drm/xe/xe_gt_pagefault.h        |   3 -
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 115 ++++++++++++++++++++
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h |  19 ++++
 drivers/gpu/drm/xe/xe_guc_ct.c              |   1 +
 drivers/gpu/drm/xe/xe_vm.c                  |   1 +
 8 files changed, 145 insertions(+), 99 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c
 create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h
drivers/gpu/drm/xe/Makefile +1 -0
index 74fa741b1937..d36d0b12f6ff 100644
@@ -56,6 +56,7 @@ xe-y += xe_bb.o \
 	xe_gt_mcr.o \
 	xe_gt_pagefault.o \
 	xe_gt_sysfs.o \
+	xe_gt_tlb_invalidation.o \
 	xe_gt_topology.o \
 	xe_guc.o \
 	xe_guc_ads.o \
drivers/gpu/drm/xe/xe_gt.c +5 -0
index 8a26b01e7d9b..1eb280c4f5f4 100644
@@ -19,6 +19,7 @@
 #include "xe_gt_mcr.h"
 #include "xe_gt_pagefault.h"
 #include "xe_gt_sysfs.h"
+#include "xe_gt_tlb_invalidation.h"
 #include "xe_gt_topology.h"
 #include "xe_hw_fence.h"
 #include "xe_irq.h"
@@ -571,6 +572,10 @@ int xe_gt_init(struct xe_gt *gt)
 		xe_hw_fence_irq_init(&gt->fence_irq[i]);
 	}
 
+	err = xe_gt_tlb_invalidation_init(gt);
+	if (err)
+		return err;
+
 	err = xe_gt_pagefault_init(gt);
 	if (err)
 		return err;
drivers/gpu/drm/xe/xe_gt_pagefault.c +3 -96

131 lines not on this page · raw message

drivers/gpu/drm/xe/xe_gt_pagefault.h +0 -3
index 35f68027cc9c..839c065a5e4c 100644
@@ -13,10 +13,7 @@ struct xe_guc;
 
 int xe_gt_pagefault_init(struct xe_gt *gt);
 void xe_gt_pagefault_reset(struct xe_gt *gt);
-int xe_gt_tlb_invalidation(struct xe_gt *gt);
-int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno);
 int xe_guc_pagefault_handler(struct xe_guc *guc, u32 *msg, u32 len);
-int xe_guc_tlb_invalidation_done_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_tlb_invalidation.c new file +115 -0

115 lines not on this page · raw message

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h new file +19 -0
new file mode 100644
index 000000000000..f1c3b34b1993
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef _XE_GT_TLB_INVALIDATION_H_
+#define _XE_GT_TLB_INVALIDATION_H_
+
+#include <linux/types.h>
+
+struct xe_gt;
+struct xe_guc;
+
+int xe_gt_tlb_invalidation_init(struct xe_gt *gt);
+int xe_gt_tlb_invalidation(struct xe_gt *gt);
+int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno);
+int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len);
+
+#endif	/* _XE_GT_TLB_INVALIDATION_ */
drivers/gpu/drm/xe/xe_guc_ct.c +1 -0
index 6e25c1d5d43e..84d4302d4e72 100644
@@ -15,6 +15,7 @@
 #include "xe_guc.h"
 #include "xe_guc_ct.h"
 #include "xe_gt_pagefault.h"
+#include "xe_gt_tlb_invalidation.h"
 #include "xe_guc_submit.h"
 #include "xe_map.h"
 #include "xe_trace.h"
drivers/gpu/drm/xe/xe_vm.c +1 -0
index e999b3aafb09..92ecc7fc55b6 100644
@@ -19,6 +19,7 @@
 #include "xe_engine.h"
 #include "xe_gt.h"
 #include "xe_gt_pagefault.h"
+#include "xe_gt_tlb_invalidation.h"
 #include "xe_migrate.h"
 #include "xe_pm.h"
 #include "xe_preempt_fence.h"
Signature · 1 line
2.39.1
author maintainer
#3 lore raw

PATCH 3/22 drm/xe: Move TLB invalidation variable to own sub-structure in GT

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

TLB invalidations no longer just restricted to USM, move the variables to own sub-structure.

Cc Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 20 +++++++++----------
 drivers/gpu/drm/xe/xe_gt_types.h            | 22 ++++++++++-----------
 2 files changed, 21 insertions(+), 21 deletions(-)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +10 -10
index fea7a557d213..a39a2fb163ae 100644
@@ -16,7 +16,7 @@ guc_to_gt(struct xe_guc *guc)
 
 int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 {
-	gt->usm.tlb_invalidation_seqno = 1;
+	gt->tlb_invalidation.seqno = 1;
 
 	return 0;
 }
@@ -40,12 +40,12 @@ static int send_tlb_invalidation(struct xe_guc *guc)
 	 * need to be updated.
 	 */
 	mutex_lock(&guc->ct.lock);
-	seqno = gt->usm.tlb_invalidation_seqno;
+	seqno = gt->tlb_invalidation.seqno;
 	action[1] = seqno;
-	gt->usm.tlb_invalidation_seqno = (gt->usm.tlb_invalidation_seqno + 1) %
+	gt->tlb_invalidation.seqno = (gt->tlb_invalidation.seqno + 1) %
 		TLB_INVALIDATION_SEQNO_MAX;
-	if (!gt->usm.tlb_invalidation_seqno)
-		gt->usm.tlb_invalidation_seqno = 1;
+	if (!gt->tlb_invalidation.seqno)
+		gt->tlb_invalidation.seqno = 1;
 	ret = xe_guc_ct_send_locked(&guc->ct, action, ARRAY_SIZE(action),
 				    G2H_LEN_DW_TLB_INVALIDATE, 1);
 	if (!ret)
@@ -62,10 +62,10 @@ int xe_gt_tlb_invalidation(struct xe_gt *gt)
 
 static bool tlb_invalidation_seqno_past(struct xe_gt *gt, int seqno)
 {
-	if (gt->usm.tlb_invalidation_seqno_recv >= seqno)
+	if (gt->tlb_invalidation.seqno_recv >= seqno)
 		return true;
 
-	if (seqno - gt->usm.tlb_invalidation_seqno_recv >
+	if (seqno - gt->tlb_invalidation.seqno_recv >
 	    (TLB_INVALIDATION_SEQNO_MAX / 2))
 		return true;
 
@@ -87,7 +87,7 @@ int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 				 HZ / 5);
 	if (!ret) {
 		drm_err(&xe->drm, "TLB invalidation time'd out, seqno=%d, recv=%d\n",
-			seqno, gt->usm.tlb_invalidation_seqno_recv);
+			seqno, gt->tlb_invalidation.seqno_recv);
 		return -ETIME;
 	}
 
@@ -103,11 +103,11 @@ int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len)
 		return -EPROTO;
 
 	/* Sanity check on seqno */
-	expected_seqno = (gt->usm.tlb_invalidation_seqno_recv + 1) %
+	expected_seqno = (gt->tlb_invalidation.seqno_recv + 1) %
 		TLB_INVALIDATION_SEQNO_MAX;
 	XE_WARN_ON(expected_seqno != msg[0]);
 
-	gt->usm.tlb_invalidation_seqno_recv = msg[0];
+	gt->tlb_invalidation.seqno_recv = msg[0];
 	smp_wmb();
 	wake_up_all(&guc->ct.wq);
 
drivers/gpu/drm/xe/xe_gt_types.h +11 -11
index 2dbc8cedd630..3bfce7abe857 100644
@@ -160,6 +160,17 @@ struct xe_gt {
 		struct work_struct worker;
 	} reset;
 
+	/** @tlb_invalidation: TLB invalidation state */
+	struct {
+		/** @seqno: TLB invalidation seqno, protected by CT lock */
+#define TLB_INVALIDATION_SEQNO_MAX	0x100000
+		int seqno;
+		/**
+		 * @seqno_recv: last received TLB invalidation seqno, protected by CT lock
+		 */
+		int seqno_recv;
+	} tlb_invalidation;
+
 	/** @usm: unified shared memory state */
 	struct {
 		/**
@@ -175,17 +186,6 @@ struct xe_gt {
 		 * operations (e.g. mmigrations, fixing page tables)
 		 */
 		u16 reserved_bcs_instance;
-		/**
-		 * @tlb_invalidation_seqno: TLB invalidation seqno, protected by
-		 * CT lock
-		 */
-#define TLB_INVALIDATION_SEQNO_MAX	0x100000
-		int tlb_invalidation_seqno;
-		/**
-		 * @tlb_invalidation_seqno_recv: last received TLB invalidation
-		 * seqno, protected by CT lock
-		 */
-		int tlb_invalidation_seqno_recv;
 		/** @pf_wq: page fault work queue, unbound, high priority */
 		struct workqueue_struct *pf_wq;
 		/** @acc_wq: access counter work queue, unbound, high priority */
Signature · 1 line
2.39.1
author maintainer
#4 lore raw

PATCH 4/22 drm/xe: Add TLB invalidation fence

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Fence will be signaled when TLB invalidation completion.

---
 drivers/gpu/drm/xe/xe_gt.c                    |  1 +
 drivers/gpu/drm/xe/xe_gt_debugfs.c            |  2 +-
 drivers/gpu/drm/xe/xe_gt_pagefault.c          |  2 +-
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c   | 43 +++++++++++++++++--
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h   |  6 ++-
 .../gpu/drm/xe/xe_gt_tlb_invalidation_types.h | 26 +++++++++++
 drivers/gpu/drm/xe/xe_gt_types.h              |  5 +++
 drivers/gpu/drm/xe/xe_vm.c                    |  2 +-
 8 files changed, 80 insertions(+), 7 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h
drivers/gpu/drm/xe/xe_gt.c +1 -0
index 1eb280c4f5f4..0be75f8afe4b 100644
@@ -668,6 +668,7 @@ static int gt_reset(struct xe_gt *gt)
 
 	xe_uc_stop_prepare(&gt->uc);
 	xe_gt_pagefault_reset(gt);
+	xe_gt_tlb_invalidation_reset(gt);
 
 	err = xe_uc_stop(&gt->uc);
 	if (err)
drivers/gpu/drm/xe/xe_gt_debugfs.c +1 -1
index cd1888784141..30058c6100ab 100644
@@ -96,7 +96,7 @@ static int invalidate_tlb(struct seq_file *m, void *data)
 	int seqno;
 	int ret = 0;
 
-	seqno = xe_gt_tlb_invalidation(gt);
+	seqno = xe_gt_tlb_invalidation(gt, NULL);
 	XE_WARN_ON(seqno < 0);
 	if (seqno > 0)
 		ret = xe_gt_tlb_invalidation_wait(gt, seqno);
drivers/gpu/drm/xe/xe_gt_pagefault.c +1 -1
index 93a8efe5d0a0..705093cb63d7 100644
@@ -245,7 +245,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 		 * defer TLB invalidate + fault response to a callback of fence
 		 * too
 		 */
-		ret = xe_gt_tlb_invalidation(gt);
+		ret = xe_gt_tlb_invalidation(gt, NULL);
 		if (ret >= 0)
 			ret = 0;
 	}
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +40 -3

79 lines not on this page · raw message

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h +5 -1
index f1c3b34b1993..7e6fbf46f0e3 100644
@@ -8,11 +8,15 @@
 
 #include <linux/types.h>
 
+#include "xe_gt_tlb_invalidation_types.h"
+
 struct xe_gt;
 struct xe_guc;
 
 int xe_gt_tlb_invalidation_init(struct xe_gt *gt);
-int xe_gt_tlb_invalidation(struct xe_gt *gt);
+void xe_gt_tlb_invalidation_reset(struct xe_gt *gt);
+int xe_gt_tlb_invalidation(struct xe_gt *gt,
+			   struct xe_gt_tlb_invalidation_fence *fence);
 int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno);
 int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len);
 
drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h new file +26 -0
new file mode 100644
index 000000000000..ab57c14c6d14
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef _XE_GT_TLB_INVALIDATION_TYPES_H_
+#define _XE_GT_TLB_INVALIDATION_TYPES_H_
+
+#include <linux/dma-fence.h>
+
+/**
+ * struct xe_gt_tlb_invalidation_fence - XE GT TLB invalidation fence
+ *
+ * Optionally passed to xe_gt_tlb_invalidation and will be signaled upon TLB
+ * invalidation completion.
+ */
+struct xe_gt_tlb_invalidation_fence {
+	/** @base: dma fence base */
+	struct dma_fence base;
+	/** @link: link into list of pending tlb fences */
+	struct list_head link;
+	/** @seqno: seqno of TLB invalidation to signal fence one */
+	int seqno;
+};
+
+#endif
drivers/gpu/drm/xe/xe_gt_types.h +5 -0
index 3bfce7abe857..a755e3a86552 100644
@@ -169,6 +169,11 @@ struct xe_gt {
 		 * @seqno_recv: last received TLB invalidation seqno, protected by CT lock
 		 */
 		int seqno_recv;
+		/**
+		 * @pending_fences: list of pending fences waiting TLB
+		 * invaliations, protected by CT lock
+		 */
+		struct list_head pending_fences;
 	} tlb_invalidation;
 
 	/** @usm: unified shared memory state */
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 92ecc7fc55b6..4c0080d081f3 100644
@@ -3321,7 +3321,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
 		if (xe_pt_zap_ptes(gt, vma)) {
 			gt_needs_invalidate |= BIT(id);
 			xe_device_wmb(xe);
-			seqno[id] = xe_gt_tlb_invalidation(gt);
+			seqno[id] = xe_gt_tlb_invalidation(gt, NULL);
 			if (seqno[id] < 0)
 				return seqno[id];
 		}
Signature · 1 line
2.39.1
author maintainer
#5 lore raw

PATCH 5/22 drm/xe: Invalidate TLB after unbind is complete

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

This gets tricky as we can't do the TLB invalidation until the unbind operation is done on the hardware and we can't signal the unbind as complete until the TLB invalidation is done. To work around this we create an unbind fence which does a TLB invalidation after unbind is done on the hardware, signals on TLB invalidation completion, and this fence is installed in the BO dma-resv slot and installed in out-syncs for the unbind operation.

---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c |  2 +
 drivers/gpu/drm/xe/xe_gt_types.h            |  9 ++
 drivers/gpu/drm/xe/xe_pt.c                  | 96 +++++++++++++++++++++
 3 files changed, 107 insertions(+)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +2 -0
index 0058a155eeb9..23094d364583 100644
@@ -18,6 +18,8 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 {
 	gt->tlb_invalidation.seqno = 1;
 	INIT_LIST_HEAD(&gt->tlb_invalidation.pending_fences);
+	spin_lock_init(&gt->tlb_invalidation.lock);
+	gt->tlb_invalidation.fence_context = dma_fence_context_alloc(1);
 
 	return 0;
 }
drivers/gpu/drm/xe/xe_gt_types.h +9 -0
index a755e3a86552..3b2d9842add7 100644
@@ -174,6 +174,15 @@ struct xe_gt {
 		 * invaliations, protected by CT lock
 		 */
 		struct list_head pending_fences;
+		/** @fence_context: context for TLB invalidation fences */
+		u64 fence_context;
+		/**
+		 * @fence_seqno: seqno to TLB invalidation fences, protected by
+		 * tlb_invalidation.lock
+		 */
+		u32 fence_seqno;
+		/** @lock: protects TLB invalidation fences */
+		spinlock_t lock;
 	} tlb_invalidation;
 
 	/** @usm: unified shared memory state */
drivers/gpu/drm/xe/xe_pt.c +96 -0

132 lines not on this page · raw message

Signature · 1 line
2.39.1
author maintainer
#6 lore raw

PATCH 6/22 drm/xe: Kernel doc GT TLB invalidations

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Document all exported functions.

Cc Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 52 ++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +51 -1
index 23094d364583..1cb4d3a6bc57 100644
@@ -14,6 +14,15 @@ guc_to_gt(struct xe_guc *guc)
 	return container_of(guc, struct xe_gt, uc.guc);
 }
 
+/**
+ * xe_gt_tlb_invalidation_init - Initialize GT TLB invalidation state
+ * @gt: graphics tile
+ *
+ * Initialize GT TLB invalidation state, purely software initialization, should
+ * be called once during driver load.
+ *
+ * Return: 0 on success, negative error code on error.
+ */
 int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 {
 	gt->tlb_invalidation.seqno = 1;
@@ -24,7 +33,13 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 	return 0;
 }
 
-void xe_gt_tlb_invalidation_reset(struct xe_gt *gt)
+/**
+ * xe_gt_tlb_invalidation_reset - Initialize GT TLB invalidation reset
+ * @gt: graphics tile
+ *
+ * Signal any pending invalidation fences, should be called during a GT reset
+ */
+ void xe_gt_tlb_invalidation_reset(struct xe_gt *gt)
 {
 	struct xe_gt_tlb_invalidation_fence *fence, *next;
 
@@ -82,6 +97,19 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 	return ret;
 }
 
+/**
+ * xe_gt_tlb_invalidation - Issue a TLB invalidation on this GT
+ * @gt: graphics tile
+ * @fence: invalidation fence which will be signal on TLB invalidation
+ * completion, can be NULL
+ *
+ * Issue a full TLB invalidation on the GT. Completion of TLB is asynchronous
+ * and caller can either use the invalidation fence or seqno +
+ * xe_gt_tlb_invalidation_wait to wait for completion.
+ *
+ * Return: Seqno which can be passed to xe_gt_tlb_invalidation_wait on success,
+ * negative error code on error.
+ */
 int xe_gt_tlb_invalidation(struct xe_gt *gt,
 			   struct xe_gt_tlb_invalidation_fence *fence)
 {
@@ -100,6 +128,16 @@ static bool tlb_invalidation_seqno_past(struct xe_gt *gt, int seqno)
 	return false;
 }
 
+/**
+ * xe_gt_tlb_invalidation_wait - Wait for TLB to complete
+ * @gt: graphics tile
+ * @seqno: seqno to wait which was returned from xe_gt_tlb_invalidation
+ *
+ * Wait for 200ms for a TLB invalidation to complete, in practice we always
+ * should receive the TLB invalidation within 200ms.
+ *
+ * Return: 0 on success, -ETIME on TLB invalidation timeout
+ */
 int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 {
 	struct xe_device *xe = gt_to_xe(gt);
@@ -122,6 +160,18 @@ int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 	return 0;
 }
 
+/**
+ * xe_guc_tlb_invalidation_done_handler - TLB invalidation done handler
+ * @guc: guc
+ * @msg: message indicating TLB invalidation done
+ * @len: length of message
+ *
+ * Parse seqno of TLB invalidation, wake any waiters for seqno, and signal any
+ * invalidation fences for seqno. Algorithm for this depends on seqno being
+ * received in-order and asserts this assumption.
+ *
+ * Return: 0 on success, -EPROTO for malformed messages.
+ */
 int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len)
 {
 	struct xe_gt *gt = guc_to_gt(guc);
Signature · 1 line
2.39.1
#7 lore raw

Re: [Intel-xe] [PATCH 06/22] drm/xe: Kernel doc GT TLB invalidations

Quoted 32 lines · Rodrigo Vivi

From: Matthew Brost <[email protected]>

Document all exported functions.

Cc Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 52 ++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +9 -0
index 23094d364583..1cb4d3a6bc57 100644
@@ -14,6 +14,15 @@ guc_to_gt(struct xe_guc *guc)
 	return container_of(guc, struct xe_gt, uc.guc);
 }
 
+/**
+ * xe_gt_tlb_invalidation_init - Initialize GT TLB invalidation state
+ * @gt: graphics tile
+ *
+ * Initialize GT TLB invalidation state, purely software initialization, should
+ * be called once during driver load.
+ *
+ * Return: 0 on success, negative error code on error.
+ */
 int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 {
 	gt->tlb_invalidation.seqno = 1;

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c int xe_gt_tlb_invalidation_init(struct xe_gt *gt) · line 37

Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +2 -1
@@ -24,7 +33,13 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 	return 0;
 }
 
-void xe_gt_tlb_invalidation_reset(struct xe_gt *gt)
+/**
+ * xe_gt_tlb_invalidation_reset - Initialize GT TLB invalidation reset

The description here is confusing. We're not really "initializing" anything here.

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c int xe_gt_tlb_invalidation_init(struct xe_gt *gt) · line 40

Quoted 3 lines
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +3 -0
+ * @gt: graphics tile
+ *
+ * Signal any pending invalidation fences, should be called during a GT reset

Is it confirmed that a GDRST-initiated reset implicitly invalidates all the engine TLBs (and thus just signalling all the fences is sufficient)? Or does the GuC take care of this itself while it is being (re)initialized? I know there are a lot of parts of the GT that don't actually get reset when requesting GRDOM_FULL, but it's never been very well documented exactly what those are.

Matt

Quoted 64 lines
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +37 -0
+ */
+ void xe_gt_tlb_invalidation_reset(struct xe_gt *gt)
 {
 	struct xe_gt_tlb_invalidation_fence *fence, *next;
 
@@ -82,6 +97,19 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 	return ret;
 }
 
+/**
+ * xe_gt_tlb_invalidation - Issue a TLB invalidation on this GT
+ * @gt: graphics tile
+ * @fence: invalidation fence which will be signal on TLB invalidation
+ * completion, can be NULL
+ *
+ * Issue a full TLB invalidation on the GT. Completion of TLB is asynchronous
+ * and caller can either use the invalidation fence or seqno +
+ * xe_gt_tlb_invalidation_wait to wait for completion.
+ *
+ * Return: Seqno which can be passed to xe_gt_tlb_invalidation_wait on success,
+ * negative error code on error.
+ */
 int xe_gt_tlb_invalidation(struct xe_gt *gt,
 			   struct xe_gt_tlb_invalidation_fence *fence)
 {
@@ -100,6 +128,16 @@ static bool tlb_invalidation_seqno_past(struct xe_gt *gt, int seqno)
 	return false;
 }
 
+/**
+ * xe_gt_tlb_invalidation_wait - Wait for TLB to complete
+ * @gt: graphics tile
+ * @seqno: seqno to wait which was returned from xe_gt_tlb_invalidation
+ *
+ * Wait for 200ms for a TLB invalidation to complete, in practice we always
+ * should receive the TLB invalidation within 200ms.
+ *
+ * Return: 0 on success, -ETIME on TLB invalidation timeout
+ */
 int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 {
 	struct xe_device *xe = gt_to_xe(gt);
@@ -122,6 +160,18 @@ int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 	return 0;
 }
 
+/**
+ * xe_guc_tlb_invalidation_done_handler - TLB invalidation done handler
+ * @guc: guc
+ * @msg: message indicating TLB invalidation done
+ * @len: length of message
+ *
+ * Parse seqno of TLB invalidation, wake any waiters for seqno, and signal any
+ * invalidation fences for seqno. Algorithm for this depends on seqno being
+ * received in-order and asserts this assumption.
+ *
+ * Return: 0 on success, -EPROTO for malformed messages.
+ */
 int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len)
 {
 	struct xe_gt *gt = guc_to_gt(guc);
Signature · 1 line
2.39.1
Signature · 4 lines
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation
author maintainer
#8 lore raw

Re: [Intel-xe] [PATCH 06/22] drm/xe: Kernel doc GT TLB invalidations

Quoted 47 lines · Matt Roper
Quoted 32 lines · Rodrigo Vivi

From: Matthew Brost <[email protected]>

Document all exported functions.

Cc Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 52 ++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +9 -0
index 23094d364583..1cb4d3a6bc57 100644
@@ -14,6 +14,15 @@ guc_to_gt(struct xe_guc *guc)
 	return container_of(guc, struct xe_gt, uc.guc);
 }
 
+/**
+ * xe_gt_tlb_invalidation_init - Initialize GT TLB invalidation state
+ * @gt: graphics tile
+ *
+ * Initialize GT TLB invalidation state, purely software initialization, should
+ * be called once during driver load.
+ *
+ * Return: 0 on success, negative error code on error.
+ */
 int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 {
 	gt->tlb_invalidation.seqno = 1;

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c int xe_gt_tlb_invalidation_init(struct xe_gt *gt) · line 37

Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +2 -1
@@ -24,7 +33,13 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 	return 0;
 }
 
-void xe_gt_tlb_invalidation_reset(struct xe_gt *gt)
+/**
+ * xe_gt_tlb_invalidation_reset - Initialize GT TLB invalidation reset

The description here is confusing. We're not really "initializing" anything here.

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c int xe_gt_tlb_invalidation_init(struct xe_gt *gt) · line 40

Quoted 3 lines
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +3 -0
+ * @gt: graphics tile
+ *
+ * Signal any pending invalidation fences, should be called during a GT reset
Quoted 6 lines

Is it confirmed that a GDRST-initiated reset implicitly invalidates all the engine TLBs (and thus just signalling all the fences is sufficient)? Or does the GuC take care of this itself while it is being (re)initialized? I know there are a lot of parts of the GT that don't actually get reset when requesting GRDOM_FULL, but it's never been very well documented exactly what those are.

Since I'm trying to avoid more rebases with these already reviewed and merged patches, I created an issue to track the changes needed and to ensure that you get the answers here:

https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/212

Quoted 74 lines

Matt

Quoted 64 lines
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +37 -0
+ */
+ void xe_gt_tlb_invalidation_reset(struct xe_gt *gt)
 {
 	struct xe_gt_tlb_invalidation_fence *fence, *next;
 
@@ -82,6 +97,19 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 	return ret;
 }
 
+/**
+ * xe_gt_tlb_invalidation - Issue a TLB invalidation on this GT
+ * @gt: graphics tile
+ * @fence: invalidation fence which will be signal on TLB invalidation
+ * completion, can be NULL
+ *
+ * Issue a full TLB invalidation on the GT. Completion of TLB is asynchronous
+ * and caller can either use the invalidation fence or seqno +
+ * xe_gt_tlb_invalidation_wait to wait for completion.
+ *
+ * Return: Seqno which can be passed to xe_gt_tlb_invalidation_wait on success,
+ * negative error code on error.
+ */
 int xe_gt_tlb_invalidation(struct xe_gt *gt,
 			   struct xe_gt_tlb_invalidation_fence *fence)
 {
@@ -100,6 +128,16 @@ static bool tlb_invalidation_seqno_past(struct xe_gt *gt, int seqno)
 	return false;
 }
 
+/**
+ * xe_gt_tlb_invalidation_wait - Wait for TLB to complete
+ * @gt: graphics tile
+ * @seqno: seqno to wait which was returned from xe_gt_tlb_invalidation
+ *
+ * Wait for 200ms for a TLB invalidation to complete, in practice we always
+ * should receive the TLB invalidation within 200ms.
+ *
+ * Return: 0 on success, -ETIME on TLB invalidation timeout
+ */
 int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 {
 	struct xe_device *xe = gt_to_xe(gt);
@@ -122,6 +160,18 @@ int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 	return 0;
 }
 
+/**
+ * xe_guc_tlb_invalidation_done_handler - TLB invalidation done handler
+ * @guc: guc
+ * @msg: message indicating TLB invalidation done
+ * @len: length of message
+ *
+ * Parse seqno of TLB invalidation, wake any waiters for seqno, and signal any
+ * invalidation fences for seqno. Algorithm for this depends on seqno being
+ * received in-order and asserts this assumption.
+ *
+ * Return: 0 on success, -EPROTO for malformed messages.
+ */
 int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len)
 {
 	struct xe_gt *gt = guc_to_gt(guc);
Signature · 1 line
2.39.1
Signature · 4 lines
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation
author maintainer
#9 lore raw

PATCH 7/22 drm/xe: Add TLB invalidation fence ftrace

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

This will help debug issues with TLB invalidation fences.

Cc Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c |  5 +++
 drivers/gpu/drm/xe/xe_pt.c                  |  5 +++
 drivers/gpu/drm/xe/xe_trace.h               | 50 +++++++++++++++++++++
 3 files changed, 60 insertions(+)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +5 -0
index 1cb4d3a6bc57..4d179357ce65 100644
@@ -7,6 +7,7 @@
 #include "xe_gt_tlb_invalidation.h"
 #include "xe_guc.h"
 #include "xe_guc_ct.h"
+#include "xe_trace.h"
 
 static struct xe_gt *
 guc_to_gt(struct xe_guc *guc)
@@ -82,6 +83,7 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 		fence->seqno = seqno;
 		list_add_tail(&fence->link,
 			      &gt->tlb_invalidation.pending_fences);
+		trace_xe_gt_tlb_invalidation_fence_send(fence);
 	}
 	action[1] = seqno;
 	gt->tlb_invalidation.seqno = (gt->tlb_invalidation.seqno + 1) %
@@ -194,7 +196,10 @@ int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len)
 
 	fence = list_first_entry_or_null(&gt->tlb_invalidation.pending_fences,
 					 typeof(*fence), link);
+	if (fence)
+		trace_xe_gt_tlb_invalidation_fence_recv(fence);
 	if (fence && tlb_invalidation_seqno_past(gt, fence->seqno)) {
+		trace_xe_gt_tlb_invalidation_fence_signal(fence);
 		list_del(&fence->link);
 		dma_fence_signal(&fence->base);
 		dma_fence_put(&fence->base);
drivers/gpu/drm/xe/xe_pt.c +5 -0
index 3a1a7145effc..2e33d9eaf550 100644
@@ -14,6 +14,7 @@
 #include "xe_pt_types.h"
 #include "xe_vm.h"
 #include "xe_res_cursor.h"
+#include "xe_trace.h"
 #include "xe_ttm_stolen_mgr.h"
 
 struct xe_pt_dir {
@@ -1497,6 +1498,7 @@ static void invalidation_fence_cb(struct dma_fence *fence,
 	struct invalidation_fence *ifence =
 		container_of(cb, struct invalidation_fence, cb);
 
+	trace_xe_gt_tlb_invalidation_fence_cb(&ifence->base);
 	queue_work(system_wq, &ifence->work);
 	dma_fence_put(ifence->fence);
 }
@@ -1506,6 +1508,7 @@ static void invalidation_fence_work_func(struct work_struct *w)
 	struct invalidation_fence *ifence =
 		container_of(w, struct invalidation_fence, work);
 
+	trace_xe_gt_tlb_invalidation_fence_work_func(&ifence->base);
 	xe_gt_tlb_invalidation(ifence->gt, &ifence->base);
 }
 
@@ -1515,6 +1518,8 @@ static int invalidation_fence_init(struct xe_gt *gt,
 {
 	int ret;
 
+	trace_xe_gt_tlb_invalidation_fence_create(&ifence->base);
+
 	spin_lock_irq(&gt->tlb_invalidation.lock);
 	dma_fence_init(&ifence->base.base, &invalidation_fence_ops,
 		       &gt->tlb_invalidation.lock,
drivers/gpu/drm/xe/xe_trace.h +50 -0

60 lines not on this page · raw message

Signature · 1 line
2.39.1
author maintainer
#10 lore raw

PATCH 8/22 drm/xe: Fix build for CONFIG_DRM_XE_DEBUG

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

GT TLB invalidation functions are now in header xe_gt_tlb_invalidation.h, include that file in xe_gt_debugfs.c if CONFIG_DRM_XE_DEBUG is set.

---
 drivers/gpu/drm/xe/xe_gt_debugfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_debugfs.c +4 -1
index 30058c6100ab..946398f08bb5 100644
@@ -11,12 +11,15 @@
 #include "xe_gt.h"
 #include "xe_gt_debugfs.h"
 #include "xe_gt_mcr.h"
-#include "xe_gt_pagefault.h"
 #include "xe_gt_topology.h"
 #include "xe_hw_engine.h"
 #include "xe_macros.h"
 #include "xe_uc_debugfs.h"
 
+#ifdef CONFIG_DRM_XE_DEBUG
+#include "xe_gt_tlb_invalidation.h"
+#endif
+
 static struct xe_gt *node_to_gt(struct drm_info_node *node)
 {
 	return node->info_ent->data;
Signature · 1 line
2.39.1
#11 lore raw

Re: [Intel-xe] [PATCH 08/22] drm/xe: Fix build for CONFIG_DRM_XE_DEBUG

Quoted 8 lines · Rodrigo Vivi

From: Matthew Brost <[email protected]>

GT TLB invalidation functions are now in header xe_gt_tlb_invalidation.h, include that file in xe_gt_debugfs.c if CONFIG_DRM_XE_DEBUG is set.

Should this be squashed into patch #2?

Matt

Quoted 28 lines
---
 drivers/gpu/drm/xe/xe_gt_debugfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_debugfs.c +4 -1
index 30058c6100ab..946398f08bb5 100644
@@ -11,12 +11,15 @@
 #include "xe_gt.h"
 #include "xe_gt_debugfs.h"
 #include "xe_gt_mcr.h"
-#include "xe_gt_pagefault.h"
 #include "xe_gt_topology.h"
 #include "xe_hw_engine.h"
 #include "xe_macros.h"
 #include "xe_uc_debugfs.h"
 
+#ifdef CONFIG_DRM_XE_DEBUG
+#include "xe_gt_tlb_invalidation.h"
+#endif
+
 static struct xe_gt *node_to_gt(struct drm_info_node *node)
 {
 	return node->info_ent->data;
Signature · 1 line
2.39.1
Signature · 4 lines
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation
author maintainer
#12 lore raw

Re: [Intel-xe] [PATCH 08/22] drm/xe: Fix build for CONFIG_DRM_XE_DEBUG

Quoted 11 lines · Matt Roper
Quoted 8 lines · Rodrigo Vivi

From: Matthew Brost <[email protected]>

GT TLB invalidation functions are now in header xe_gt_tlb_invalidation.h, include that file in xe_gt_debugfs.c if CONFIG_DRM_XE_DEBUG is set.

Should this be squashed into patch #2?

It would be better indeed.., I'm trying to avoid the changes in these merged patches right now. But I will keep in mind for the next rebase on upstream.

Thanks,
Rodrigo.

Quoted 38 lines

Matt

Quoted 28 lines
---
 drivers/gpu/drm/xe/xe_gt_debugfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_debugfs.c +4 -1
index 30058c6100ab..946398f08bb5 100644
@@ -11,12 +11,15 @@
 #include "xe_gt.h"
 #include "xe_gt_debugfs.h"
 #include "xe_gt_mcr.h"
-#include "xe_gt_pagefault.h"
 #include "xe_gt_topology.h"
 #include "xe_hw_engine.h"
 #include "xe_macros.h"
 #include "xe_uc_debugfs.h"
 
+#ifdef CONFIG_DRM_XE_DEBUG
+#include "xe_gt_tlb_invalidation.h"
+#endif
+
 static struct xe_gt *node_to_gt(struct drm_info_node *node)
 {
 	return node->info_ent->data;
Signature · 1 line
2.39.1
Signature · 4 lines
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation
author maintainer
#13 lore raw

PATCH 9/22 drm/xe: Add TDR for invalidation fence timeout cleanup

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Endless fences are not good, add a TDR to cleanup any invalidation fences which have not received an invalidation message within a timeout period.

---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c   | 58 +++++++++++++++++--
 .../gpu/drm/xe/xe_gt_tlb_invalidation_types.h |  2 +
 drivers/gpu/drm/xe/xe_gt_types.h              |  5 ++
 drivers/gpu/drm/xe/xe_trace.h                 |  5 ++
 4 files changed, 65 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +53 -5
index 4d179357ce65..9e026fd0a45d 100644
@@ -9,12 +9,45 @@
 #include "xe_guc_ct.h"
 #include "xe_trace.h"
 
+#define TLB_TIMEOUT	(HZ / 4)
+
 static struct xe_gt *
 guc_to_gt(struct xe_guc *guc)
 {
 	return container_of(guc, struct xe_gt, uc.guc);
 }
 
+static void xe_gt_tlb_fence_timeout(struct work_struct *work)
+{
+	struct xe_gt *gt = container_of(work, struct xe_gt,
+					tlb_invalidation.fence_tdr.work);
+	struct xe_gt_tlb_invalidation_fence *fence, *next;
+
+	mutex_lock(&gt->uc.guc.ct.lock);
+	list_for_each_entry_safe(fence, next,
+				 &gt->tlb_invalidation.pending_fences, link) {
+		s64 since_inval_ms = ktime_ms_delta(ktime_get(),
+						    fence->invalidation_time);
+
+		if (msecs_to_jiffies(since_inval_ms) < TLB_TIMEOUT)
+			break;
+
+		trace_xe_gt_tlb_invalidation_fence_timeout(fence);
+		drm_err(&gt_to_xe(gt)->drm, "TLB invalidation fence timeout, seqno=%d",
+			fence->seqno);
+
+		list_del(&fence->link);
+		fence->base.error = -ETIME;
+		dma_fence_signal(&fence->base);
+		dma_fence_put(&fence->base);
+	}
+	if (!list_empty(&gt->tlb_invalidation.pending_fences))
+		queue_delayed_work(system_wq,
+				   &gt->tlb_invalidation.fence_tdr,
+				   TLB_TIMEOUT);
+	mutex_unlock(&gt->uc.guc.ct.lock);
+}
+
 /**
  * xe_gt_tlb_invalidation_init - Initialize GT TLB invalidation state
  * @gt: graphics tile
@@ -30,6 +63,8 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 	INIT_LIST_HEAD(&gt->tlb_invalidation.pending_fences);
 	spin_lock_init(&gt->tlb_invalidation.lock);
 	gt->tlb_invalidation.fence_context = dma_fence_context_alloc(1);
+	INIT_DELAYED_WORK(&gt->tlb_invalidation.fence_tdr,
+			  xe_gt_tlb_fence_timeout);
 
 	return 0;
 }
@@ -44,6 +79,8 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 {
 	struct xe_gt_tlb_invalidation_fence *fence, *next;
 
+	cancel_delayed_work(&gt->tlb_invalidation.fence_tdr);
+
 	mutex_lock(&gt->uc.guc.ct.lock);
 	list_for_each_entry_safe(fence, next,
 				 &gt->tlb_invalidation.pending_fences, link) {
@@ -67,6 +104,7 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 	};
 	int seqno;
 	int ret;
+	bool queue_work;
 
 	/*
 	 * XXX: The seqno algorithm relies on TLB invalidation being processed
@@ -76,10 +114,7 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 	mutex_lock(&guc->ct.lock);
 	seqno = gt->tlb_invalidation.seqno;
 	if (fence) {
-		/*
-		 * FIXME: How to deal TLB invalidation timeout, right now we
-		 * just have an endless fence which isn't ideal.
-		 */
+		queue_work = list_empty(&gt->tlb_invalidation.pending_fences);
 		fence->seqno = seqno;
 		list_add_tail(&fence->link,
 			      &gt->tlb_invalidation.pending_fences);
@@ -92,6 +127,13 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 		gt->tlb_invalidation.seqno = 1;
 	ret = xe_guc_ct_send_locked(&guc->ct, action, ARRAY_SIZE(action),
 				    G2H_LEN_DW_TLB_INVALIDATE, 1);
+	if (!ret && fence) {
+		fence->invalidation_time = ktime_get();
+		if (queue_work)
+			queue_delayed_work(system_wq,
+					   &gt->tlb_invalidation.fence_tdr,
+					   TLB_TIMEOUT);
+	}
 	if (!ret)
 		ret = seqno;
 	mutex_unlock(&guc->ct.lock);
@@ -152,7 +194,7 @@ int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno)
 	 */
 	ret = wait_event_timeout(guc->ct.wq,
 				 tlb_invalidation_seqno_past(gt, seqno),
-				 HZ / 5);
+				 TLB_TIMEOUT);
 	if (!ret) {
 		drm_err(&xe->drm, "TLB invalidation time'd out, seqno=%d, recv=%d\n",
 			seqno, gt->tlb_invalidation.seqno_recv);
@@ -201,6 +243,12 @@ int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len)
 	if (fence && tlb_invalidation_seqno_past(gt, fence->seqno)) {
 		trace_xe_gt_tlb_invalidation_fence_signal(fence);
 		list_del(&fence->link);
+		if (!list_empty(&gt->tlb_invalidation.pending_fences))
+			mod_delayed_work(system_wq,
+					 &gt->tlb_invalidation.fence_tdr,
+					 TLB_TIMEOUT);
+		else
+			cancel_delayed_work(&gt->tlb_invalidation.fence_tdr);
 		dma_fence_signal(&fence->base);
 		dma_fence_put(&fence->base);
 	}
drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h +2 -0
index ab57c14c6d14..934c828efe31 100644
@@ -21,6 +21,8 @@ struct xe_gt_tlb_invalidation_fence {
 	struct list_head link;
 	/** @seqno: seqno of TLB invalidation to signal fence one */
 	int seqno;
+	/** @invalidation_time: time of TLB invalidation */
+	ktime_t invalidation_time;
 };
 
 #endif
drivers/gpu/drm/xe/xe_gt_types.h +5 -0
index 3b2d9842add7..a40fab262ac9 100644
@@ -174,6 +174,11 @@ struct xe_gt {
 		 * invaliations, protected by CT lock
 		 */
 		struct list_head pending_fences;
+		/**
+		 * @fence_tdr: schedules a delayed call to
+		 * xe_gt_tlb_fence_timeout after the timeut interval is over.
+		 */
+		struct delayed_work fence_tdr;
 		/** @fence_context: context for TLB invalidation fences */
 		u64 fence_context;
 		/**
drivers/gpu/drm/xe/xe_trace.h +5 -0
index 373b0825ec79..1774658b18b7 100644
@@ -69,6 +69,11 @@ DEFINE_EVENT(xe_gt_tlb_invalidation_fence, xe_gt_tlb_invalidation_fence_signal,
 	     TP_ARGS(fence)
 );
 
+DEFINE_EVENT(xe_gt_tlb_invalidation_fence, xe_gt_tlb_invalidation_fence_timeout,
+	     TP_PROTO(struct xe_gt_tlb_invalidation_fence *fence),
+	     TP_ARGS(fence)
+);
+
 DECLARE_EVENT_CLASS(xe_bo,
 		    TP_PROTO(struct xe_bo *bo),
 		    TP_ARGS(bo),
Signature · 1 line
2.39.1
author maintainer
#14 lore raw

PATCH 10/22 drm/xe: Only set VM->asid for platforms that support a ASID

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

This will help with TLB invalidation as the ASID in TLB invalidate should be zero for platforms that do not support a ASID.

---
 drivers/gpu/drm/xe/xe_vm.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +17 -13
index 4c0080d081f3..2b1e79e65dbf 100644
@@ -1371,10 +1371,12 @@ static void vm_destroy_work_func(struct work_struct *w)
 		xe_device_mem_access_put(xe);
 		xe_pm_runtime_put(xe);
 
-		mutex_lock(&xe->usm.lock);
-		lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid);
-		XE_WARN_ON(lookup != vm);
-		mutex_unlock(&xe->usm.lock);
+		if (xe->info.supports_usm) {
+			mutex_lock(&xe->usm.lock);
+			lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid);
+			XE_WARN_ON(lookup != vm);
+			mutex_unlock(&xe->usm.lock);
+		}
 	}
 
 	/*
@@ -1859,16 +1861,18 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
 		return err;
 	}
 
-	mutex_lock(&xe->usm.lock);
-	err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
-			      XA_LIMIT(0, XE_MAX_ASID - 1),
-			      &xe->usm.next_asid, GFP_KERNEL);
-	mutex_unlock(&xe->usm.lock);
-	if (err) {
-		xe_vm_close_and_put(vm);
-		return err;
+	if (xe->info.supports_usm) {
+		mutex_lock(&xe->usm.lock);
+		err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
+				      XA_LIMIT(0, XE_MAX_ASID - 1),
+				      &xe->usm.next_asid, GFP_KERNEL);
+		mutex_unlock(&xe->usm.lock);
+		if (err) {
+			xe_vm_close_and_put(vm);
+			return err;
+		}
+		vm->usm.asid = asid;
 	}
-	vm->usm.asid = asid;
 
 	args->vm_id = id;
 
Signature · 1 line
2.39.1
author maintainer
#15 lore raw

PATCH 11/22 drm/xe: Delete debugfs entry to issue TLB invalidation

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Not used, let's remove this.

---
 drivers/gpu/drm/xe/xe_gt_debugfs.c | 24 ------------------------
 1 file changed, 24 deletions(-)
drivers/gpu/drm/xe/xe_gt_debugfs.c +0 -24
index 946398f08bb5..daae42d3ab3b 100644
@@ -16,10 +16,6 @@
 #include "xe_macros.h"
 #include "xe_uc_debugfs.h"
 
-#ifdef CONFIG_DRM_XE_DEBUG
-#include "xe_gt_tlb_invalidation.h"
-#endif
-
 static struct xe_gt *node_to_gt(struct drm_info_node *node)
 {
 	return node->info_ent->data;
@@ -92,32 +88,12 @@ static int steering(struct seq_file *m, void *data)
 	return 0;
 }
 
-#ifdef CONFIG_DRM_XE_DEBUG
-static int invalidate_tlb(struct seq_file *m, void *data)
-{
-	struct xe_gt *gt = node_to_gt(m->private);
-	int seqno;
-	int ret = 0;
-
-	seqno = xe_gt_tlb_invalidation(gt, NULL);
-	XE_WARN_ON(seqno < 0);
-	if (seqno > 0)
-		ret = xe_gt_tlb_invalidation_wait(gt, seqno);
-	XE_WARN_ON(ret < 0);
-
-	return 0;
-}
-#endif
-
 static const struct drm_info_list debugfs_list[] = {
 	{"hw_engines", hw_engines, 0},
 	{"force_reset", force_reset, 0},
 	{"sa_info", sa_info, 0},
 	{"topology", topology, 0},
 	{"steering", steering, 0},
-#ifdef CONFIG_DRM_XE_DEBUG
-	{"invalidate_tlb", invalidate_tlb, 0},
-#endif
 };
 
 void xe_gt_debugfs_register(struct xe_gt *gt)
Signature · 1 line
2.39.1
author maintainer
#16 lore raw

PATCH 12/22 drm/xe: Add has_range_tlb_invalidation device attribute

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

This will help implementing range based TLB invalidations.

---
 drivers/gpu/drm/xe/xe_device_types.h | 2 ++
 drivers/gpu/drm/xe/xe_pci.c          | 4 ++++
 2 files changed, 6 insertions(+)
drivers/gpu/drm/xe/xe_device_types.h +2 -0
index eba224236c86..6d13587bfa7b 100644
@@ -92,6 +92,8 @@ struct xe_device {
 		bool has_flat_ccs;
 		/** @has_4tile: Whether tile-4 tiling is supported */
 		bool has_4tile;
+		/** @has_range_tlb_invalidation: Has range based TLB invalidations */
+		bool has_range_tlb_invalidation;
 
 		struct xe_device_display_info {
 			u8 ver;
drivers/gpu/drm/xe/xe_pci.c +4 -0
index a96004aa34aa..53e87b27fcde 100644
@@ -77,6 +77,7 @@ struct xe_device_desc {
 	bool supports_usm;
 	bool has_flat_ccs;
 	bool has_4tile;
+	bool has_range_tlb_invalidation;
 };
 
 #define PLATFORM(x)		\
@@ -213,6 +214,7 @@ static const struct xe_device_desc dg1_desc = {
 	.require_force_probe = true, \
 	.graphics_ver = 12, \
 	.graphics_rel = 50, \
+	.has_range_tlb_invalidation = true, \
 	.has_flat_ccs = true, \
 	.dma_mask_size = 46, \
 	.max_tiles = 1, \
@@ -332,6 +334,7 @@ static const struct xe_device_desc mtl_desc = {
 	.max_tiles = 2,
 	.vm_max_level = 3,
 	.media_ver = 13,
+	.has_range_tlb_invalidation = true,
 	PLATFORM(XE_METEORLAKE),
 	.extra_gts = xelpmp_gts,
 	.platform_engine_mask = MTL_MAIN_ENGINES,
@@ -496,6 +499,7 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	xe->info.has_flat_ccs = desc->has_flat_ccs;
 	xe->info.has_4tile = desc->has_4tile;
 	xe->info.display = desc->display;
+	xe->info.has_range_tlb_invalidation = desc->has_range_tlb_invalidation;
 
 	spd = subplatform_get(xe, desc);
 	xe->info.subplatform = spd ? spd->subplatform : XE_SUBPLATFORM_NONE;
Signature · 1 line
2.39.1
author maintainer
#17 lore raw

PATCH 13/22 drm/xe: Add range based TLB invalidations

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

If the platform supports range based TLB invalidations use them. Hide these details in the xe_gt_tlb_invalidation layer.

---
 drivers/gpu/drm/xe/xe_gt_pagefault.c        |  7 +-
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 87 +++++++++++++++++----
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h |  4 +-
 drivers/gpu/drm/xe/xe_pt.c                  |  9 ++-
 drivers/gpu/drm/xe/xe_vm.c                  |  2 +-
 5 files changed, 84 insertions(+), 25 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +1 -6
index 705093cb63d7..e1a5a3a70c92 100644
@@ -240,12 +240,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 		goto retry_userptr;
 
 	if (!ret) {
-		/*
-		 * FIXME: Doing a full TLB invalidation for now, likely could
-		 * defer TLB invalidate + fault response to a callback of fence
-		 * too
-		 */
-		ret = xe_gt_tlb_invalidation(gt, NULL);
+		ret = xe_gt_tlb_invalidation(gt, NULL, vma);
 		if (ret >= 0)
 			ret = 0;
 	}
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +73 -14

114 lines not on this page · raw message

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h +3 -1
index 7e6fbf46f0e3..b4c4f717bc8a 100644
@@ -12,11 +12,13 @@
 
 struct xe_gt;
 struct xe_guc;
+struct xe_vma;
 
 int xe_gt_tlb_invalidation_init(struct xe_gt *gt);
 void xe_gt_tlb_invalidation_reset(struct xe_gt *gt);
 int xe_gt_tlb_invalidation(struct xe_gt *gt,
-			   struct xe_gt_tlb_invalidation_fence *fence);
+			   struct xe_gt_tlb_invalidation_fence *fence,
+			   struct xe_vma *vma);
 int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno);
 int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len);
 
drivers/gpu/drm/xe/xe_pt.c +6 -3
index 2e33d9eaf550..5a3a0ca224e9 100644
@@ -1470,6 +1470,7 @@ static const struct xe_migrate_pt_update_ops userptr_unbind_ops = {
 struct invalidation_fence {
 	struct xe_gt_tlb_invalidation_fence base;
 	struct xe_gt *gt;
+	struct xe_vma *vma;
 	struct dma_fence *fence;
 	struct dma_fence_cb cb;
 	struct work_struct work;
@@ -1509,12 +1510,13 @@ static void invalidation_fence_work_func(struct work_struct *w)
 		container_of(w, struct invalidation_fence, work);
 
 	trace_xe_gt_tlb_invalidation_fence_work_func(&ifence->base);
-	xe_gt_tlb_invalidation(ifence->gt, &ifence->base);
+	xe_gt_tlb_invalidation(ifence->gt, &ifence->base, ifence->vma);
 }
 
 static int invalidation_fence_init(struct xe_gt *gt,
 				   struct invalidation_fence *ifence,
-				   struct dma_fence *fence)
+				   struct dma_fence *fence,
+				   struct xe_vma *vma)
 {
 	int ret;
 
@@ -1532,6 +1534,7 @@ static int invalidation_fence_init(struct xe_gt *gt,
 	dma_fence_get(&ifence->base.base);	/* Ref for caller */
 	ifence->fence = fence;
 	ifence->gt = gt;
+	ifence->vma = vma;
 
 	INIT_WORK(&ifence->work, invalidation_fence_work_func);
 	ret = dma_fence_add_callback(fence, &ifence->cb, invalidation_fence_cb);
@@ -1618,7 +1621,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 		int err;
 
 		/* TLB invalidation must be done before signaling unbind */
-		err = invalidation_fence_init(gt, ifence, fence);
+		err = invalidation_fence_init(gt, ifence, fence, vma);
 		if (err) {
 			dma_fence_put(fence);
 			kfree(ifence);
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 2b1e79e65dbf..ca2f7d084ceb 100644
@@ -3325,7 +3325,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
 		if (xe_pt_zap_ptes(gt, vma)) {
 			gt_needs_invalidate |= BIT(id);
 			xe_device_wmb(xe);
-			seqno[id] = xe_gt_tlb_invalidation(gt, NULL);
+			seqno[id] = xe_gt_tlb_invalidation(gt, NULL, vma);
 			if (seqno[id] < 0)
 				return seqno[id];
 		}
Signature · 1 line
2.39.1
author maintainer
#18 lore raw

PATCH 14/22 drm/xe: Propagate error from bind operations to async fence

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

If an bind operation fails we need to report it via the async fence.

---
 drivers/gpu/drm/xe/xe_vm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_vm.c +8 -1
index ca2f7d084ceb..1bc680cdc249 100644
@@ -1583,6 +1583,7 @@ xe_vm_bind_vma(struct xe_vma *vma, struct xe_engine *e,
 
 struct async_op_fence {
 	struct dma_fence fence;
+	struct dma_fence *wait_fence;
 	struct dma_fence_cb cb;
 	struct xe_vm *vm;
 	wait_queue_head_t wq;
@@ -1610,8 +1611,10 @@ static void async_op_fence_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
 	struct async_op_fence *afence =
 		container_of(cb, struct async_op_fence, cb);
 
+	afence->fence.error = afence->wait_fence->error;
 	dma_fence_signal(&afence->fence);
 	xe_vm_put(afence->vm);
+	dma_fence_put(afence->wait_fence);
 	dma_fence_put(&afence->fence);
 }
 
@@ -1627,13 +1630,17 @@ static void add_async_op_fence_cb(struct xe_vm *vm,
 		wake_up_all(&afence->wq);
 	}
 
+	afence->wait_fence = dma_fence_get(fence);
 	afence->vm = xe_vm_get(vm);
 	dma_fence_get(&afence->fence);
 	ret = dma_fence_add_callback(fence, &afence->cb, async_op_fence_cb);
-	if (ret == -ENOENT)
+	if (ret == -ENOENT) {
+		afence->fence.error = afence->wait_fence->error;
 		dma_fence_signal(&afence->fence);
+	}
 	if (ret) {
 		xe_vm_put(vm);
+		dma_fence_put(afence->wait_fence);
 		dma_fence_put(&afence->fence);
 	}
 	XE_WARN_ON(ret && ret != -ENOENT);
Signature · 1 line
2.39.1
author maintainer
#19 lore raw

PATCH 15/22 drm/xe: Use GuC to do GGTT invalidations for the GuC firmware

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Only the GuC should be issuing TLB invalidations if it is enabled. Part of this patch is sanitize the device on driver unload to ensure we do not send GuC based TLB invalidations during driver unload.

---
 drivers/gpu/drm/xe/xe_device.c              | 14 +++++++
 drivers/gpu/drm/xe/xe_ggtt.c                | 12 +++++-
 drivers/gpu/drm/xe/xe_gt.c                  | 13 +++++++
 drivers/gpu/drm/xe/xe_gt.h                  |  1 +
 drivers/gpu/drm/xe/xe_gt_pagefault.c        |  2 +-
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 43 +++++++++++++++------
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h |  7 ++--
 drivers/gpu/drm/xe/xe_guc.c                 |  2 +
 drivers/gpu/drm/xe/xe_guc_types.h           |  2 +
 drivers/gpu/drm/xe/xe_pt.c                  |  2 +-
 drivers/gpu/drm/xe/xe_uc.c                  |  9 ++++-
 drivers/gpu/drm/xe/xe_uc.h                  |  1 +
 drivers/gpu/drm/xe/xe_vm.c                  |  2 +-
 13 files changed, 89 insertions(+), 21 deletions(-)
drivers/gpu/drm/xe/xe_device.c +14 -0
index d7b2b41bc7a8..62f54b4806dc 100644
@@ -380,6 +380,16 @@ static void xe_device_unlink_display(struct xe_device *xe)
 #endif
 }
 
+static void xe_device_sanitize(struct drm_device *drm, void *arg)
+{
+	struct xe_device *xe = arg;
+	struct xe_gt *gt;
+	u8 id;
+
+	for_each_gt(gt, xe, id)
+		xe_gt_sanitize(gt);
+}
+
 int xe_device_probe(struct xe_device *xe)
 {
 	struct xe_gt *gt;
@@ -466,6 +476,10 @@ int xe_device_probe(struct xe_device *xe)
 
 	xe_debugfs_register(xe);
 
+	err = drmm_add_action_or_reset(&xe->drm, xe_device_sanitize, xe);
+	if (err)
+		return err;
+
 	return 0;
 
 err_fini_display:
drivers/gpu/drm/xe/xe_ggtt.c +10 -2
index baa080cd1133..20450ed8400b 100644
@@ -13,6 +13,7 @@
 #include "xe_device.h"
 #include "xe_bo.h"
 #include "xe_gt.h"
+#include "xe_gt_tlb_invalidation.h"
 #include "xe_map.h"
 #include "xe_mmio.h"
 #include "xe_wopcm.h"
@@ -200,10 +201,17 @@ void xe_ggtt_invalidate(struct xe_gt *gt)
 	 * therefore flushing WC buffers.  Is that really true here?
 	 */
 	xe_mmio_write32(gt, GFX_FLSH_CNTL_GEN6.reg, GFX_FLSH_CNTL_EN);
-	if (xe_device_guc_submission_enabled(gt_to_xe(gt))) {
+
+	if (gt->uc.guc.submission_state.enabled) {
+		int seqno;
+
+		seqno = xe_gt_tlb_invalidation_guc(gt);
+		XE_WARN_ON(seqno <= 0);
+		if (seqno > 0)
+			xe_gt_tlb_invalidation_wait(gt, seqno);
+	} else if (xe_device_guc_submission_enabled(gt_to_xe(gt))) {
 		struct xe_device *xe = gt_to_xe(gt);
 
-		/* TODO: also use vfunc here */
 		if (xe->info.platform == XE_PVC) {
 			xe_mmio_write32(gt, PVC_GUC_TLB_INV_DESC1.reg,
 					PVC_GUC_TLB_INV_DESC1_INVALIDATE);
drivers/gpu/drm/xe/xe_gt.c +13 -0
index 0be75f8afe4b..36b5da2c5977 100644
@@ -196,6 +196,15 @@ static int gt_ttm_mgr_init(struct xe_gt *gt)
 	return 0;
 }
 
+void xe_gt_sanitize(struct xe_gt *gt)
+{
+	/*
+	 * FIXME: if xe_uc_sanitize is called here, on TGL driver will not
+	 * reload
+	 */
+	gt->uc.guc.submission_state.enabled = false;
+}
+
 static void gt_fini(struct drm_device *drm, void *arg)
 {
 	struct xe_gt *gt = arg;
@@ -661,6 +670,8 @@ static int gt_reset(struct xe_gt *gt)
 
 	drm_info(&xe->drm, "GT reset started\n");
 
+	xe_gt_sanitize(gt);
+
 	xe_device_mem_access_get(gt_to_xe(gt));
 	err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
 	if (err)
@@ -741,6 +752,8 @@ int xe_gt_suspend(struct xe_gt *gt)
 	if (!xe_device_guc_submission_enabled(gt_to_xe(gt)))
 		return -ENODEV;
 
+	xe_gt_sanitize(gt);
+
 	xe_device_mem_access_get(gt_to_xe(gt));
 	err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
 	if (err)
drivers/gpu/drm/xe/xe_gt.h +1 -0
index 5dc08a993cfe..5635f2803170 100644
@@ -26,6 +26,7 @@ int xe_gt_suspend(struct xe_gt *gt);
 int xe_gt_resume(struct xe_gt *gt);
 void xe_gt_reset_async(struct xe_gt *gt);
 void xe_gt_migrate_wait(struct xe_gt *gt);
+void xe_gt_sanitize(struct xe_gt *gt);
 
 struct xe_gt *xe_find_full_gt(struct xe_gt *gt);
 
drivers/gpu/drm/xe/xe_gt_pagefault.c +1 -1
index e1a5a3a70c92..ce79eb48feb8 100644
@@ -240,7 +240,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 		goto retry_userptr;
 
 	if (!ret) {
-		ret = xe_gt_tlb_invalidation(gt, NULL, vma);
+		ret = xe_gt_tlb_invalidation_vma(gt, NULL, vma);
 		if (ret >= 0)
 			ret = 0;
 	}
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +32 -11

69 lines not on this page · raw message

drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h +4 -3
index b4c4f717bc8a..b333c1709397 100644
@@ -16,9 +16,10 @@ struct xe_vma;
 
 int xe_gt_tlb_invalidation_init(struct xe_gt *gt);
 void xe_gt_tlb_invalidation_reset(struct xe_gt *gt);
-int xe_gt_tlb_invalidation(struct xe_gt *gt,
-			   struct xe_gt_tlb_invalidation_fence *fence,
-			   struct xe_vma *vma);
+int xe_gt_tlb_invalidation_guc(struct xe_gt *gt);
+int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,
+			       struct xe_gt_tlb_invalidation_fence *fence,
+			       struct xe_vma *vma);
 int xe_gt_tlb_invalidation_wait(struct xe_gt *gt, int seqno);
 int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len);
 
drivers/gpu/drm/xe/xe_guc.c +2 -0
index 88a3a96da084..5cdfdfd0de40 100644
@@ -309,6 +309,7 @@ int xe_guc_init_post_hwconfig(struct xe_guc *guc)
 int xe_guc_post_load_init(struct xe_guc *guc)
 {
 	xe_guc_ads_populate_post_load(&guc->ads);
+	guc->submission_state.enabled = true;
 
 	return 0;
 }
@@ -795,6 +796,7 @@ void xe_guc_sanitize(struct xe_guc *guc)
 {
 	xe_uc_fw_change_status(&guc->fw, XE_UC_FIRMWARE_LOADABLE);
 	xe_guc_ct_disable(&guc->ct);
+	guc->submission_state.enabled = false;
 }
 
 int xe_guc_reset_prepare(struct xe_guc *guc)
drivers/gpu/drm/xe/xe_guc_types.h +2 -0
index c2a484282ef2..ac7eec28934d 100644
@@ -60,6 +60,8 @@ struct xe_guc {
 			/** @patch: patch version of GuC submission */
 			u32 patch;
 		} version;
+		/** @enabled: submission is enabled */
+		bool enabled;
 	} submission_state;
 	/** @hwconfig: Hardware config state */
 	struct {
drivers/gpu/drm/xe/xe_pt.c +1 -1
index 5a3a0ca224e9..9da5ee4b31f8 100644
@@ -1510,7 +1510,7 @@ static void invalidation_fence_work_func(struct work_struct *w)
 		container_of(w, struct invalidation_fence, work);
 
 	trace_xe_gt_tlb_invalidation_fence_work_func(&ifence->base);
-	xe_gt_tlb_invalidation(ifence->gt, &ifence->base, ifence->vma);
+	xe_gt_tlb_invalidation_vma(ifence->gt, &ifence->base, ifence->vma);
 }
 
 static int invalidation_fence_init(struct xe_gt *gt,
drivers/gpu/drm/xe/xe_uc.c +7 -2
index 938d14698003..7886c8b85397 100644
@@ -88,10 +88,15 @@ static int uc_reset(struct xe_uc *uc)
 	return 0;
 }
 
-static int uc_sanitize(struct xe_uc *uc)
+void xe_uc_sanitize(struct xe_uc *uc)
 {
 	xe_huc_sanitize(&uc->huc);
 	xe_guc_sanitize(&uc->guc);
+}
+
+static int xe_uc_sanitize_reset(struct xe_uc *uc)
+{
+	xe_uc_sanitize(uc);
 
 	return uc_reset(uc);
 }
@@ -129,7 +134,7 @@ int xe_uc_init_hw(struct xe_uc *uc)
 	if (!xe_device_guc_submission_enabled(uc_to_xe(uc)))
 		return 0;
 
-	ret = uc_sanitize(uc);
+	ret = xe_uc_sanitize_reset(uc);
 	if (ret)
 		return ret;
 
drivers/gpu/drm/xe/xe_uc.h +1 -0
index 380e722f95fc..d6efc9ef00d3 100644
@@ -17,5 +17,6 @@ void xe_uc_stop_prepare(struct xe_uc *uc);
 int xe_uc_stop(struct xe_uc *uc);
 int xe_uc_start(struct xe_uc *uc);
 int xe_uc_suspend(struct xe_uc *uc);
+void xe_uc_sanitize(struct xe_uc *uc);
 
 #endif
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 1bc680cdc249..541629293683 100644
@@ -3332,7 +3332,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
 		if (xe_pt_zap_ptes(gt, vma)) {
 			gt_needs_invalidate |= BIT(id);
 			xe_device_wmb(xe);
-			seqno[id] = xe_gt_tlb_invalidation(gt, NULL, vma);
+			seqno[id] = xe_gt_tlb_invalidation_vma(gt, NULL, vma);
 			if (seqno[id] < 0)
 				return seqno[id];
 		}
Signature · 1 line
2.39.1
author maintainer
#20 lore raw

PATCH 16/22 drm/xe: Coalesce GGTT invalidations

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

No need to invalidate the GGTT on every allocation / deallocation, rather just invalidate the GGTT on an allocation after a deallocation.

---
 drivers/gpu/drm/xe/xe_ggtt.c       | 11 +++++++++--
 drivers/gpu/drm/xe/xe_ggtt_types.h |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_ggtt.c +9 -2
index 20450ed8400b..81c7eb68bc46 100644
@@ -264,15 +264,22 @@ int xe_ggtt_insert_special_node(struct xe_ggtt *ggtt, struct drm_mm_node *node,
 
 void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_bo *bo)
 {
+	struct xe_device *xe = gt_to_xe(ggtt->gt);
 	u64 start = bo->ggtt_node.start;
 	u64 offset, pte;
 
+	lockdep_assert_held(&ggtt->lock);
+
 	for (offset = 0; offset < bo->size; offset += GEN8_PAGE_SIZE) {
 		pte = xe_ggtt_pte_encode(bo, offset);
 		xe_ggtt_set_pte(ggtt, start + offset, pte);
 	}
 
-	xe_ggtt_invalidate(ggtt->gt);
+	/* XXX: Without doing this everytime on integrated driver load fails */
+	if (ggtt->invalidate || !IS_DGFX(xe)) {
+		xe_ggtt_invalidate(ggtt->gt);
+		ggtt->invalidate = false;
+	}
 }
 
 static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
@@ -330,7 +337,7 @@ void xe_ggtt_remove_node(struct xe_ggtt *ggtt, struct drm_mm_node *node)
 	drm_mm_remove_node(node);
 	node->size = 0;
 
-	xe_ggtt_invalidate(ggtt->gt);
+	ggtt->invalidate = true;
 
 	mutex_unlock(&ggtt->lock);
 }
drivers/gpu/drm/xe/xe_ggtt_types.h +2 -0
index ea70aaef4b31..8198aa784654 100644
@@ -26,6 +26,8 @@ struct xe_ggtt {
 	u64 __iomem *gsm;
 
 	struct drm_mm mm;
+
+	bool invalidate;
 };
 
 #endif
Signature · 1 line
2.39.1
author maintainer
#21 lore raw

PATCH 17/22 drm/xe: Lock GGTT on when restoring kernel BOs

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Make lockdep happy as we required to hold the GGTT when calling xe_ggtt_map_bo.

---
 drivers/gpu/drm/xe/xe_bo_evict.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_bo_evict.c +4 -1
index 7046dc203138..3fb3c8c77efa 100644
@@ -147,8 +147,11 @@ int xe_bo_restore_kernel(struct xe_device *xe)
 			return ret;
 		}
 
-		if (bo->flags & XE_BO_CREATE_GGTT_BIT)
+		if (bo->flags & XE_BO_CREATE_GGTT_BIT) {
+			mutex_lock(&bo->gt->mem.ggtt->lock);
 			xe_ggtt_map_bo(bo->gt->mem.ggtt, bo);
+			mutex_unlock(&bo->gt->mem.ggtt->lock);
+		}
 
 		/*
 		 * We expect validate to trigger a move VRAM and our move code
Signature · 1 line
2.39.1
author maintainer
#22 lore raw

PATCH 18/22 drm/xe: Propagate VM unbind error to invalidation fence

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

If a VM unbind hits an error, do not issue a TLB invalidation and propagate the error the invalidation fence.

---
 drivers/gpu/drm/xe/xe_pt.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_pt.c +7 -1
index 9da5ee4b31f8..0c2cc9d772fa 100644
@@ -1500,7 +1500,13 @@ static void invalidation_fence_cb(struct dma_fence *fence,
 		container_of(cb, struct invalidation_fence, cb);
 
 	trace_xe_gt_tlb_invalidation_fence_cb(&ifence->base);
-	queue_work(system_wq, &ifence->work);
+	if (!ifence->fence->error) {
+		queue_work(system_wq, &ifence->work);
+	} else {
+		ifence->base.base.error = ifence->fence->error;
+		dma_fence_signal(&ifence->base.base);
+		dma_fence_put(&ifence->base.base);
+	}
 	dma_fence_put(ifence->fence);
 }
 
Signature · 1 line
2.39.1
author maintainer
#23 lore raw

PATCH 19/22 drm/xe: Signal invalidation fence immediately if CT send fails

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

This means we are in the middle of a GT reset and no need to do TLB invalidation so just signal invalidation fence immediately.

---
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 23 +++++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +14 -9
index f6a2dd26cad4..2521c8a65690 100644
@@ -69,6 +69,15 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 	return 0;
 }
 
+static void
+invalidation_fence_signal(struct xe_gt_tlb_invalidation_fence *fence)
+{
+	trace_xe_gt_tlb_invalidation_fence_signal(fence);
+	list_del(&fence->link);
+	dma_fence_signal(&fence->base);
+	dma_fence_put(&fence->base);
+}
+
 /**
  * xe_gt_tlb_invalidation_reset - Initialize GT TLB invalidation reset
  * @gt: graphics tile
@@ -83,11 +92,8 @@ int xe_gt_tlb_invalidation_init(struct xe_gt *gt)
 
 	mutex_lock(&gt->uc.guc.ct.lock);
 	list_for_each_entry_safe(fence, next,
-				 &gt->tlb_invalidation.pending_fences, link) {
-		list_del(&fence->link);
-		dma_fence_signal(&fence->base);
-		dma_fence_put(&fence->base);
-	}
+				 &gt->tlb_invalidation.pending_fences, link)
+		invalidation_fence_signal(fence);
 	mutex_unlock(&gt->uc.guc.ct.lock);
 }
 
@@ -130,6 +136,8 @@ static int send_tlb_invalidation(struct xe_guc *guc,
 	}
 	if (!ret)
 		ret = seqno;
+	if (ret < 0 && fence)
+		invalidation_fence_signal(fence);
 	mutex_unlock(&guc->ct.lock);
 
 	return ret;
@@ -321,16 +329,13 @@ int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len)
 	if (fence)
 		trace_xe_gt_tlb_invalidation_fence_recv(fence);
 	if (fence && tlb_invalidation_seqno_past(gt, fence->seqno)) {
-		trace_xe_gt_tlb_invalidation_fence_signal(fence);
-		list_del(&fence->link);
+		invalidation_fence_signal(fence);
 		if (!list_empty(&gt->tlb_invalidation.pending_fences))
 			mod_delayed_work(system_wq,
 					 &gt->tlb_invalidation.fence_tdr,
 					 TLB_TIMEOUT);
 		else
 			cancel_delayed_work(&gt->tlb_invalidation.fence_tdr);
-		dma_fence_signal(&fence->base);
-		dma_fence_put(&fence->base);
 	}
 
 	return 0;
Signature · 1 line
2.39.1
author maintainer
#24 lore raw

PATCH 20/22 drm/xe: Add has_asid to device info

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Rather than alias supports_usm to ASIS support, add an explicit variable to indicate ASID support.

---
 drivers/gpu/drm/xe/xe_device_types.h | 2 ++
 drivers/gpu/drm/xe/xe_lrc.c          | 4 ++--
 drivers/gpu/drm/xe/xe_pci.c          | 3 +++
 drivers/gpu/drm/xe/xe_vm.c           | 4 ++--
 4 files changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_device_types.h +2 -0
index 6d13587bfa7b..a8d48987b2d8 100644
@@ -86,6 +86,8 @@ struct xe_device {
 		u8 media_ver;
 		/** @supports_usm: Supports unified shared memory */
 		bool supports_usm;
+		/** @has_asid: Has address space ID */
+		bool has_asid;
 		/** @enable_guc: GuC submission enabled */
 		bool enable_guc;
 		/** @has_flat_ccs: Whether flat CCS metadata is used */
drivers/gpu/drm/xe/xe_lrc.c +2 -2
index 056c2c5a0b81..347ff9b34494 100644
@@ -682,14 +682,14 @@ int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 	xe_lrc_write_ctx_reg(lrc, CTX_RING_TAIL, lrc->ring.tail);
 	xe_lrc_write_ctx_reg(lrc, CTX_RING_CTL,
 			     RING_CTL_SIZE(lrc->ring.size) | RING_VALID);
-	if (xe->info.supports_usm && vm) {
+	if (xe->info.has_asid && vm)
 		xe_lrc_write_ctx_reg(lrc, PVC_CTX_ASID,
 				     (e->usm.acc_granularity <<
 				      ACC_GRANULARITY_S) | vm->usm.asid);
+	if (xe->info.supports_usm && vm)
 		xe_lrc_write_ctx_reg(lrc, PVC_CTX_ACC_CTR_THOLD,
 				     (e->usm.acc_notify << ACC_NOTIFY_S) |
 				     e->usm.acc_trigger);
-	}
 
 	lrc->desc = GEN8_CTX_VALID;
 	lrc->desc |= INTEL_LEGACY_64B_CONTEXT << GEN8_CTX_ADDRESSING_MODE_SHIFT;
drivers/gpu/drm/xe/xe_pci.c +3 -0
index 53e87b27fcde..927a050f3b8f 100644
@@ -78,6 +78,7 @@ struct xe_device_desc {
 	bool has_flat_ccs;
 	bool has_4tile;
 	bool has_range_tlb_invalidation;
+	bool has_asid;
 };
 
 #define PLATFORM(x)		\
@@ -302,6 +303,7 @@ static const struct xe_device_desc pvc_desc = {
 	.max_tiles = 2,
 	.vm_max_level = 4,
 	.supports_usm = true,
+	.has_asid = true,
 };
 
 #define MTL_MEDIA_ENGINES \
@@ -496,6 +498,7 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	xe->info.vm_max_level = desc->vm_max_level;
 	xe->info.media_ver = desc->media_ver;
 	xe->info.supports_usm = desc->supports_usm;
+	xe->info.has_asid = desc->has_asid;
 	xe->info.has_flat_ccs = desc->has_flat_ccs;
 	xe->info.has_4tile = desc->has_4tile;
 	xe->info.display = desc->display;
drivers/gpu/drm/xe/xe_vm.c +2 -2
index 541629293683..7276a375e2e0 100644
@@ -1371,7 +1371,7 @@ static void vm_destroy_work_func(struct work_struct *w)
 		xe_device_mem_access_put(xe);
 		xe_pm_runtime_put(xe);
 
-		if (xe->info.supports_usm) {
+		if (xe->info.has_asid) {
 			mutex_lock(&xe->usm.lock);
 			lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid);
 			XE_WARN_ON(lookup != vm);
@@ -1868,7 +1868,7 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
 		return err;
 	}
 
-	if (xe->info.supports_usm) {
+	if (xe->info.has_asid) {
 		mutex_lock(&xe->usm.lock);
 		err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
 				      XA_LIMIT(0, XE_MAX_ASID - 1),
Signature · 1 line
2.39.1
author maintainer
#25 lore raw

PATCH 21/22 drm/xe: Add TLB invalidation fence after rebinds issued from execs

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

If we add an TLB invalidation fence for rebinds issued from execs we should be able to drop the TLB invalidation from the ring operations.

---
 drivers/gpu/drm/xe/xe_pt.c | 200 ++++++++++++++++++++-----------------
 1 file changed, 110 insertions(+), 90 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +110 -90
index 0c2cc9d772fa..435cc30d88c9 100644
@@ -1160,6 +1160,96 @@ static const struct xe_migrate_pt_update_ops userptr_bind_ops = {
 	.pre_commit = xe_pt_userptr_pre_commit,
 };
 
+struct invalidation_fence {
+	struct xe_gt_tlb_invalidation_fence base;
+	struct xe_gt *gt;
+	struct xe_vma *vma;
+	struct dma_fence *fence;
+	struct dma_fence_cb cb;
+	struct work_struct work;
+};
+
+static const char *
+invalidation_fence_get_driver_name(struct dma_fence *dma_fence)
+{
+	return "xe";
+}
+
+static const char *
+invalidation_fence_get_timeline_name(struct dma_fence *dma_fence)
+{
+	return "invalidation_fence";
+}
+
+static const struct dma_fence_ops invalidation_fence_ops = {
+	.get_driver_name = invalidation_fence_get_driver_name,
+	.get_timeline_name = invalidation_fence_get_timeline_name,
+};
+
+static void invalidation_fence_cb(struct dma_fence *fence,
+				  struct dma_fence_cb *cb)
+{
+	struct invalidation_fence *ifence =
+		container_of(cb, struct invalidation_fence, cb);
+
+	trace_xe_gt_tlb_invalidation_fence_cb(&ifence->base);
+	if (!ifence->fence->error) {
+		queue_work(system_wq, &ifence->work);
+	} else {
+		ifence->base.base.error = ifence->fence->error;
+		dma_fence_signal(&ifence->base.base);
+		dma_fence_put(&ifence->base.base);
+	}
+	dma_fence_put(ifence->fence);
+}
+
+static void invalidation_fence_work_func(struct work_struct *w)
+{
+	struct invalidation_fence *ifence =
+		container_of(w, struct invalidation_fence, work);
+
+	trace_xe_gt_tlb_invalidation_fence_work_func(&ifence->base);
+	xe_gt_tlb_invalidation_vma(ifence->gt, &ifence->base, ifence->vma);
+}
+
+static int invalidation_fence_init(struct xe_gt *gt,
+				   struct invalidation_fence *ifence,
+				   struct dma_fence *fence,
+				   struct xe_vma *vma)
+{
+	int ret;
+
+	trace_xe_gt_tlb_invalidation_fence_create(&ifence->base);
+
+	spin_lock_irq(&gt->tlb_invalidation.lock);
+	dma_fence_init(&ifence->base.base, &invalidation_fence_ops,
+		       &gt->tlb_invalidation.lock,
+		       gt->tlb_invalidation.fence_context,
+		       ++gt->tlb_invalidation.fence_seqno);
+	spin_unlock_irq(&gt->tlb_invalidation.lock);
+
+	INIT_LIST_HEAD(&ifence->base.link);
+
+	dma_fence_get(&ifence->base.base);	/* Ref for caller */
+	ifence->fence = fence;
+	ifence->gt = gt;
+	ifence->vma = vma;
+
+	INIT_WORK(&ifence->work, invalidation_fence_work_func);
+	ret = dma_fence_add_callback(fence, &ifence->cb, invalidation_fence_cb);
+	if (ret == -ENOENT) {
+		dma_fence_put(ifence->fence);	/* Usually dropped in CB */
+		invalidation_fence_work_func(&ifence->work);
+	} else if (ret) {
+		dma_fence_put(&ifence->base.base);	/* Caller ref */
+		dma_fence_put(&ifence->base.base);	/* Creation ref */
+	}
+
+	XE_WARN_ON(ret && ret != -ENOENT);
+
+	return ret && ret != -ENOENT ? ret : 0;
+}
+
 /**
  * __xe_pt_bind_vma() - Build and connect a page-table tree for the vma
  * address range.
@@ -1198,6 +1288,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	struct xe_vm *vm = vma->vm;
 	u32 num_entries;
 	struct dma_fence *fence;
+	struct invalidation_fence *ifence = NULL;
 	int err;
 
 	bind_pt_update.locked = false;
@@ -1216,6 +1307,12 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 
 	xe_vm_dbg_print_entries(gt_to_xe(gt), entries, num_entries);
 
+	if (rebind && !xe_vm_no_dma_fences(vma->vm)) {
+		ifence = kzalloc(sizeof(*ifence), GFP_KERNEL);
+		if (!ifence)
+			return ERR_PTR(-ENOMEM);
+	}
+
 	fence = xe_migrate_update_pgtables(gt->migrate,
 					   vm, vma->bo,
 					   e ? e : vm->eng[gt->info.id],
@@ -1225,6 +1322,18 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	if (!IS_ERR(fence)) {
 		LLIST_HEAD(deferred);
 
+		/* TLB invalidation must be done before signaling rebind */
+		if (rebind && !xe_vm_no_dma_fences(vma->vm)) {
+			int err = invalidation_fence_init(gt, ifence, fence,
+							  vma);
+			if (err) {
+				dma_fence_put(fence);
+				kfree(ifence);
+				return ERR_PTR(err);
+			}
+			fence = &ifence->base.base;
+		}
+
 		/* add shared fence now for pagetable delayed destroy */
 		dma_resv_add_fence(&vm->resv, fence, !rebind &&
 				   vma->last_munmap_rebind ?
@@ -1250,6 +1359,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 			queue_work(vm->xe->ordered_wq,
 				   &vm->preempt.rebind_work);
 	} else {
+		kfree(ifence);
 		if (bind_pt_update.locked)
 			up_read(&vm->userptr.notifier_lock);
 		xe_pt_abort_bind(vma, entries, num_entries);
@@ -1467,96 +1577,6 @@ static const struct xe_migrate_pt_update_ops userptr_unbind_ops = {
 	.pre_commit = xe_pt_userptr_pre_commit,
 };
 
-struct invalidation_fence {
-	struct xe_gt_tlb_invalidation_fence base;
-	struct xe_gt *gt;
-	struct xe_vma *vma;
-	struct dma_fence *fence;
-	struct dma_fence_cb cb;
-	struct work_struct work;
-};
-
-static const char *
-invalidation_fence_get_driver_name(struct dma_fence *dma_fence)
-{
-	return "xe";
-}
-
-static const char *
-invalidation_fence_get_timeline_name(struct dma_fence *dma_fence)
-{
-	return "invalidation_fence";
-}
-
-static const struct dma_fence_ops invalidation_fence_ops = {
-	.get_driver_name = invalidation_fence_get_driver_name,
-	.get_timeline_name = invalidation_fence_get_timeline_name,
-};
-
-static void invalidation_fence_cb(struct dma_fence *fence,
-				  struct dma_fence_cb *cb)
-{
-	struct invalidation_fence *ifence =
-		container_of(cb, struct invalidation_fence, cb);
-
-	trace_xe_gt_tlb_invalidation_fence_cb(&ifence->base);
-	if (!ifence->fence->error) {
-		queue_work(system_wq, &ifence->work);
-	} else {
-		ifence->base.base.error = ifence->fence->error;
-		dma_fence_signal(&ifence->base.base);
-		dma_fence_put(&ifence->base.base);
-	}
-	dma_fence_put(ifence->fence);
-}
-
-static void invalidation_fence_work_func(struct work_struct *w)
-{
-	struct invalidation_fence *ifence =
-		container_of(w, struct invalidation_fence, work);
-
-	trace_xe_gt_tlb_invalidation_fence_work_func(&ifence->base);
-	xe_gt_tlb_invalidation_vma(ifence->gt, &ifence->base, ifence->vma);
-}
-
-static int invalidation_fence_init(struct xe_gt *gt,
-				   struct invalidation_fence *ifence,
-				   struct dma_fence *fence,
-				   struct xe_vma *vma)
-{
-	int ret;
-
-	trace_xe_gt_tlb_invalidation_fence_create(&ifence->base);
-
-	spin_lock_irq(&gt->tlb_invalidation.lock);
-	dma_fence_init(&ifence->base.base, &invalidation_fence_ops,
-		       &gt->tlb_invalidation.lock,
-		       gt->tlb_invalidation.fence_context,
-		       ++gt->tlb_invalidation.fence_seqno);
-	spin_unlock_irq(&gt->tlb_invalidation.lock);
-
-	INIT_LIST_HEAD(&ifence->base.link);
-
-	dma_fence_get(&ifence->base.base);	/* Ref for caller */
-	ifence->fence = fence;
-	ifence->gt = gt;
-	ifence->vma = vma;
-
-	INIT_WORK(&ifence->work, invalidation_fence_work_func);
-	ret = dma_fence_add_callback(fence, &ifence->cb, invalidation_fence_cb);
-	if (ret == -ENOENT) {
-		dma_fence_put(ifence->fence);	/* Usually dropped in CB */
-		invalidation_fence_work_func(&ifence->work);
-	} else if (ret) {
-		dma_fence_put(&ifence->base.base);	/* Caller ref */
-		dma_fence_put(&ifence->base.base);	/* Creation ref */
-	}
-
-	XE_WARN_ON(ret && ret != -ENOENT);
-
-	return ret && ret != -ENOENT ? ret : 0;
-}
-
 /**
  * __xe_pt_unbind_vma() - Disconnect and free a page-table tree for the vma
  * address range.
Signature · 1 line
2.39.1
author maintainer
#26 lore raw

PATCH 22/22 drm/xe: Drop TLB invalidation from ring operations

In reply to Rodrigo Vivi

From: Matthew Brost <[email protected]>

Now that we issue TLB invalidations on unbinds and rebind from execs we no longer need to issue TLB invalidations from the ring operations.

---
 drivers/gpu/drm/xe/xe_ring_ops.c | 40 +-------------------------------
 1 file changed, 1 insertion(+), 39 deletions(-)
drivers/gpu/drm/xe/xe_ring_ops.c +1 -39
index d08f50e53649..370ab1e729fa 100644
@@ -83,31 +83,6 @@ static int emit_flush_invalidate(u32 flag, u32 *dw, int i)
 	return i;
 }
 
-static int emit_pipe_invalidate(u32 mask_flags, u32 *dw, int i)
-{
-	u32 flags = PIPE_CONTROL_CS_STALL |
-		PIPE_CONTROL_COMMAND_CACHE_INVALIDATE |
-		PIPE_CONTROL_TLB_INVALIDATE |
-		PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
-		PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
-		PIPE_CONTROL_VF_CACHE_INVALIDATE |
-		PIPE_CONTROL_CONST_CACHE_INVALIDATE |
-		PIPE_CONTROL_STATE_CACHE_INVALIDATE |
-		PIPE_CONTROL_QW_WRITE |
-		PIPE_CONTROL_STORE_DATA_INDEX;
-
-	flags &= ~mask_flags;
-
-	dw[i++] = GFX_OP_PIPE_CONTROL(6);
-	dw[i++] = flags;
-	dw[i++] = LRC_PPHWSP_SCRATCH_ADDR;
-	dw[i++] = 0;
-	dw[i++] = 0;
-	dw[i++] = 0;
-
-	return i;
-}
-
 #define MI_STORE_QWORD_IMM_GEN8_POSTED (MI_INSTR(0x20, 3) | (1 << 21))
 
 static int emit_store_imm_ppgtt_posted(u64 addr, u64 value,
@@ -148,11 +123,6 @@ static void __emit_job_gen12_copy(struct xe_sched_job *job, struct xe_lrc *lrc,
 	u32 dw[MAX_JOB_SIZE_DW], i = 0;
 	u32 ppgtt_flag = get_ppgtt_flag(job);
 
-	/* XXX: Conditional flushing possible */
-	dw[i++] = preparser_disable(true);
-	i = emit_flush_invalidate(0, dw, i);
-	dw[i++] = preparser_disable(false);
-
 	i = emit_store_imm_ggtt(xe_lrc_start_seqno_ggtt_addr(lrc),
 				seqno, dw, i);
 
@@ -181,9 +151,7 @@ static void __emit_job_gen12_video(struct xe_sched_job *job, struct xe_lrc *lrc,
 	struct xe_device *xe = gt_to_xe(gt);
 	bool decode = job->engine->class == XE_ENGINE_CLASS_VIDEO_DECODE;
 
-	/* XXX: Conditional flushing possible */
 	dw[i++] = preparser_disable(true);
-	i = emit_flush_invalidate(decode ? MI_INVALIDATE_BSD : 0, dw, i);
 	/* Wa_1809175790 */
 	if (!xe->info.has_flat_ccs) {
 		if (decode)
@@ -244,15 +212,8 @@ static void __emit_job_gen12_render_compute(struct xe_sched_job *job,
 	struct xe_gt *gt = job->engine->gt;
 	struct xe_device *xe = gt_to_xe(gt);
 	bool pvc = xe->info.platform == XE_PVC;
-	u32 mask_flags = 0;
 
-	/* XXX: Conditional flushing possible */
 	dw[i++] = preparser_disable(true);
-	if (pvc)
-		mask_flags = PIPE_CONTROL_3D_ARCH_FLAGS;
-	else if (job->engine->class == XE_ENGINE_CLASS_COMPUTE)
-		mask_flags = PIPE_CONTROL_3D_ENGINE_FLAGS;
-	i = emit_pipe_invalidate(mask_flags, dw, i);
 	/* Wa_1809175790 */
 	if (!xe->info.has_flat_ccs)
 		i = emit_aux_table_inv(gt, GEN12_GFX_CCS_AUX_NV.reg, dw, i);
@@ -287,6 +248,7 @@ static void emit_migration_job_gen12(struct xe_sched_job *job,
 
 	i = emit_bb_start(job->batch_addr[0], BIT(8), dw, i);
 
+	/* XXX: Do we need this? Leaving for now. */
 	dw[i++] = preparser_disable(true);
 	i = emit_flush_invalidate(0, dw, i);
 	dw[i++] = preparser_disable(false);
Signature · 1 line
2.39.1
Reviewed-by on the v1 series
#27 lore raw
In reply to Rodrigo Vivi
Quoted 18 lines · Rodrigo Vivi

Let's just confirm the reviews on this patch and get them merged to drm-xe-next.

Matthew Brost (22):
drm/xe: Don't process TLB invalidation done in CT fast-path drm/xe: Break of TLB invalidation into its own file drm/xe: Move TLB invalidation variable to own sub-structure in GT drm/xe: Add TLB invalidation fence
drm/xe: Invalidate TLB after unbind is complete drm/xe: Kernel doc GT TLB invalidations
drm/xe: Add TLB invalidation fence ftrace
drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
drm/xe: Add TDR for invalidation fence timeout cleanup drm/xe: Only set VM->asid for platforms that support a ASID drm/xe: Delete debugfs entry to issue TLB invalidation drm/xe: Add has_range_tlb_invalidation device attribute drm/xe: Add range based TLB invalidations
drm/xe: Propagate error from bind operations to async fence

Quoted 9 lines

drm/xe: Use GuC to do GGTT invalidations for the GuC firmware drm/xe: Coalesce GGTT invalidations
drm/xe: Lock GGTT on when restoring kernel BOs
drm/xe: Propagate VM unbind error to invalidation fence drm/xe: Signal invalidation fence immediately if CT send fails drm/xe: Add has_asid to device info
drm/xe: Add TLB invalidation fence after rebinds issued from execs drm/xe: Drop TLB invalidation from ring operations

Looks good to me.
Some minor comments on patch ordering.
Patch #8 can be merged with #10
Patch #10 can be simplified if we move #20 before patch #10 Patch #17 should probably put ahead of #16

In any case,

Quoted 34 lines
drivers/gpu/drm/xe/Makefile                   |   1 +
drivers/gpu/drm/xe/xe_bo_evict.c              |   5 +-
drivers/gpu/drm/xe/xe_device.c                |  14 +
drivers/gpu/drm/xe/xe_device_types.h          |   4 +
drivers/gpu/drm/xe/xe_ggtt.c                  |  23 +-
drivers/gpu/drm/xe/xe_ggtt_types.h            |   2 +
drivers/gpu/drm/xe/xe_gt.c                    |  19 +
drivers/gpu/drm/xe/xe_gt.h                    |   1 +
drivers/gpu/drm/xe/xe_gt_debugfs.c            |  21 --
drivers/gpu/drm/xe/xe_gt_pagefault.c          | 104 +-----
drivers/gpu/drm/xe/xe_gt_pagefault.h          |   3 -
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c   | 342 ++++++++++++++++++
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h   |  26 ++
.../gpu/drm/xe/xe_gt_tlb_invalidation_types.h |  28 ++
drivers/gpu/drm/xe/xe_gt_types.h              |  41 ++-
drivers/gpu/drm/xe/xe_guc.c                   |   2 +
drivers/gpu/drm/xe/xe_guc_ct.c                |  10 +-
drivers/gpu/drm/xe/xe_guc_types.h             |   2 +
drivers/gpu/drm/xe/xe_lrc.c                   |   4 +-
drivers/gpu/drm/xe/xe_pci.c                   |   7 +
drivers/gpu/drm/xe/xe_pt.c                    | 130 +++++++
drivers/gpu/drm/xe/xe_ring_ops.c              |  40 +-
drivers/gpu/drm/xe/xe_trace.h                 |  55 +++
drivers/gpu/drm/xe/xe_uc.c                    |   9 +-
drivers/gpu/drm/xe/xe_uc.h                    |   1 +
drivers/gpu/drm/xe/xe_vm.c                    |  42 ++-
26 files changed, 736 insertions(+), 200 deletions(-)

create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h

Signature · 1 line
2.39.1
author maintainer
#28 lore raw
Quoted 29 lines · Niranjana Vishwanathapura
Quoted 18 lines · Rodrigo Vivi

Let's just confirm the reviews on this patch and get them merged to drm-xe-next.

Matthew Brost (22):
drm/xe: Don't process TLB invalidation done in CT fast-path drm/xe: Break of TLB invalidation into its own file drm/xe: Move TLB invalidation variable to own sub-structure in GT drm/xe: Add TLB invalidation fence
drm/xe: Invalidate TLB after unbind is complete drm/xe: Kernel doc GT TLB invalidations
drm/xe: Add TLB invalidation fence ftrace
drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
drm/xe: Add TDR for invalidation fence timeout cleanup drm/xe: Only set VM->asid for platforms that support a ASID drm/xe: Delete debugfs entry to issue TLB invalidation drm/xe: Add has_range_tlb_invalidation device attribute drm/xe: Add range based TLB invalidations
drm/xe: Propagate error from bind operations to async fence

Quoted 9 lines

drm/xe: Use GuC to do GGTT invalidations for the GuC firmware drm/xe: Coalesce GGTT invalidations
drm/xe: Lock GGTT on when restoring kernel BOs
drm/xe: Propagate VM unbind error to invalidation fence drm/xe: Signal invalidation fence immediately if CT send fails drm/xe: Add has_asid to device info
drm/xe: Add TLB invalidation fence after rebinds issued from execs drm/xe: Drop TLB invalidation from ring operations

Quoted 3 lines

Looks good to me.
Some minor comments on patch ordering.
Patch #8 can be merged with #10

did you mean squashed together?
but why 8 and 10? 8 is a build fix, so I'd assume the issue happened in a previous patch, not in patch 10.

08 - drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
10 - drm/xe: Only set VM->asid for platforms that support a ASID

Quoted 1 line

Patch #10 can be simplified if we move #20 before patch #10

indeed, but at this point I prefer to not touch them...

Quoted 1 line

Patch #17 should probably put ahead of #16

maybe a squash? but I will probably just leave it as is...

Quoted 3 lines

In any case,

Thanks you so much

Quoted 36 lines
Quoted 36 lines

drivers/gpu/drm/xe/Makefile                   |   1 +
drivers/gpu/drm/xe/xe_bo_evict.c              |   5 +-
drivers/gpu/drm/xe/xe_device.c                |  14 +
drivers/gpu/drm/xe/xe_device_types.h          |   4 +
drivers/gpu/drm/xe/xe_ggtt.c                  |  23 +-
drivers/gpu/drm/xe/xe_ggtt_types.h            |   2 +
drivers/gpu/drm/xe/xe_gt.c                    |  19 +
drivers/gpu/drm/xe/xe_gt.h                    |   1 +
drivers/gpu/drm/xe/xe_gt_debugfs.c            |  21 --
drivers/gpu/drm/xe/xe_gt_pagefault.c          | 104 +-----
drivers/gpu/drm/xe/xe_gt_pagefault.h          |   3 -
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c   | 342 ++++++++++++++++++
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h   |  26 ++
.../gpu/drm/xe/xe_gt_tlb_invalidation_types.h |  28 ++
drivers/gpu/drm/xe/xe_gt_types.h              |  41 ++-
drivers/gpu/drm/xe/xe_guc.c                   |   2 +
drivers/gpu/drm/xe/xe_guc_ct.c                |  10 +-
drivers/gpu/drm/xe/xe_guc_types.h             |   2 +
drivers/gpu/drm/xe/xe_lrc.c                   |   4 +-
drivers/gpu/drm/xe/xe_pci.c                   |   7 +
drivers/gpu/drm/xe/xe_pt.c                    | 130 +++++++
drivers/gpu/drm/xe/xe_ring_ops.c              |  40 +-
drivers/gpu/drm/xe/xe_trace.h                 |  55 +++
drivers/gpu/drm/xe/xe_uc.c                    |   9 +-
drivers/gpu/drm/xe/xe_uc.h                    |   1 +
drivers/gpu/drm/xe/xe_vm.c                    |  42 ++-
26 files changed, 736 insertions(+), 200 deletions(-)

create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h

Signature · 1 line
2.39.1
#29 lore raw
Quoted 34 lines · Rodrigo Vivi
Quoted 29 lines · Niranjana Vishwanathapura
Quoted 18 lines · Rodrigo Vivi

Let's just confirm the reviews on this patch and get them merged to drm-xe-next.

Matthew Brost (22):
drm/xe: Don't process TLB invalidation done in CT fast-path drm/xe: Break of TLB invalidation into its own file drm/xe: Move TLB invalidation variable to own sub-structure in GT drm/xe: Add TLB invalidation fence
drm/xe: Invalidate TLB after unbind is complete drm/xe: Kernel doc GT TLB invalidations
drm/xe: Add TLB invalidation fence ftrace
drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
drm/xe: Add TDR for invalidation fence timeout cleanup drm/xe: Only set VM->asid for platforms that support a ASID drm/xe: Delete debugfs entry to issue TLB invalidation drm/xe: Add has_range_tlb_invalidation device attribute drm/xe: Add range based TLB invalidations
drm/xe: Propagate error from bind operations to async fence

Quoted 9 lines

drm/xe: Use GuC to do GGTT invalidations for the GuC firmware drm/xe: Coalesce GGTT invalidations
drm/xe: Lock GGTT on when restoring kernel BOs
drm/xe: Propagate VM unbind error to invalidation fence drm/xe: Signal invalidation fence immediately if CT send fails drm/xe: Add has_asid to device info
drm/xe: Add TLB invalidation fence after rebinds issued from execs drm/xe: Drop TLB invalidation from ring operations

Quoted 3 lines

Looks good to me.
Some minor comments on patch ordering.
Patch #8 can be merged with #10

Quoted 7 lines

did you mean squashed together?
but why 8 and 10? 8 is a build fix, so I'd assume the issue happened in a previous patch, not in patch 10.

08 - drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
10 - drm/xe: Only set VM->asid for platforms that support a ASID

Sorry, I meant #8 and #11. Most of the change in #8 is removed by patch #11. So, #8 can be squashed with #11.

Quoted 8 lines
Quoted 1 line

Patch #10 can be simplified if we move #20 before patch #10

indeed, but at this point I prefer to not touch them...

Quoted 1 line

Patch #17 should probably put ahead of #16

maybe a squash? but I will probably just leave it as is...

Ok,
Niranjana

Quoted 42 lines
Quoted 3 lines

In any case,

Thanks you so much

Quoted 36 lines
Quoted 36 lines

drivers/gpu/drm/xe/Makefile                   |   1 +
drivers/gpu/drm/xe/xe_bo_evict.c              |   5 +-
drivers/gpu/drm/xe/xe_device.c                |  14 +
drivers/gpu/drm/xe/xe_device_types.h          |   4 +
drivers/gpu/drm/xe/xe_ggtt.c                  |  23 +-
drivers/gpu/drm/xe/xe_ggtt_types.h            |   2 +
drivers/gpu/drm/xe/xe_gt.c                    |  19 +
drivers/gpu/drm/xe/xe_gt.h                    |   1 +
drivers/gpu/drm/xe/xe_gt_debugfs.c            |  21 --
drivers/gpu/drm/xe/xe_gt_pagefault.c          | 104 +-----
drivers/gpu/drm/xe/xe_gt_pagefault.h          |   3 -
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c   | 342 ++++++++++++++++++
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h   |  26 ++
.../gpu/drm/xe/xe_gt_tlb_invalidation_types.h |  28 ++
drivers/gpu/drm/xe/xe_gt_types.h              |  41 ++-
drivers/gpu/drm/xe/xe_guc.c                   |   2 +
drivers/gpu/drm/xe/xe_guc_ct.c                |  10 +-
drivers/gpu/drm/xe/xe_guc_types.h             |   2 +
drivers/gpu/drm/xe/xe_lrc.c                   |   4 +-
drivers/gpu/drm/xe/xe_pci.c                   |   7 +
drivers/gpu/drm/xe/xe_pt.c                    | 130 +++++++
drivers/gpu/drm/xe/xe_ring_ops.c              |  40 +-
drivers/gpu/drm/xe/xe_trace.h                 |  55 +++
drivers/gpu/drm/xe/xe_uc.c                    |   9 +-
drivers/gpu/drm/xe/xe_uc.h                    |   1 +
drivers/gpu/drm/xe/xe_vm.c                    |  42 ++-
26 files changed, 736 insertions(+), 200 deletions(-)

create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h

--
2.39.1

#30 lore raw
Quoted 39 lines · Niranjana Vishwanathapura
Quoted 38 lines · Rodrigo Vivi
Quoted 29 lines · Niranjana Vishwanathapura
Quoted 18 lines · Rodrigo Vivi

Let's just confirm the reviews on this patch and get them merged to drm-xe-next.

Matthew Brost (22):
drm/xe: Don't process TLB invalidation done in CT fast-path drm/xe: Break of TLB invalidation into its own file drm/xe: Move TLB invalidation variable to own sub-structure in GT drm/xe: Add TLB invalidation fence
drm/xe: Invalidate TLB after unbind is complete drm/xe: Kernel doc GT TLB invalidations
drm/xe: Add TLB invalidation fence ftrace
drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
drm/xe: Add TDR for invalidation fence timeout cleanup drm/xe: Only set VM->asid for platforms that support a ASID drm/xe: Delete debugfs entry to issue TLB invalidation drm/xe: Add has_range_tlb_invalidation device attribute drm/xe: Add range based TLB invalidations
drm/xe: Propagate error from bind operations to async fence

Quoted 9 lines

drm/xe: Use GuC to do GGTT invalidations for the GuC firmware drm/xe: Coalesce GGTT invalidations
drm/xe: Lock GGTT on when restoring kernel BOs
drm/xe: Propagate VM unbind error to invalidation fence drm/xe: Signal invalidation fence immediately if CT send fails drm/xe: Add has_asid to device info
drm/xe: Add TLB invalidation fence after rebinds issued from execs drm/xe: Drop TLB invalidation from ring operations

Quoted 3 lines

Looks good to me.
Some minor comments on patch ordering.
Patch #8 can be merged with #10

did you mean squashed together?
but why 8 and 10? 8 is a build fix, so I'd assume the issue happened in a previous patch, not in patch 10.

Quoted 15 lines
Quoted 3 lines

08 - drm/xe: Fix build for CONFIG_DRM_XE_DEBUG
10 - drm/xe: Only set VM->asid for platforms that support a ASID

Sorry, I meant #8 and #11. Most of the change in #8 is removed by patch #11. So, #8 can be squashed with #11.

Quoted 8 lines
Quoted 1 line

Patch #10 can be simplified if we move #20 before patch #10

indeed, but at this point I prefer to not touch them...

Quoted 1 line

Patch #17 should probably put ahead of #16

maybe a squash? but I will probably just leave it as is...

Actually, in patch #16, we are adding a lockdep assert in xe_ggtt_map_bo(), but lock is taken in patch #17. Hence the comment. But it should be fine as it is a functional dependency and not a compile dependency.

Quoted 46 lines

Ok,
Niranjana

Quoted 42 lines
Quoted 3 lines

In any case,

Thanks you so much

Quoted 36 lines
Quoted 36 lines

drivers/gpu/drm/xe/Makefile                   |   1 +
drivers/gpu/drm/xe/xe_bo_evict.c              |   5 +-
drivers/gpu/drm/xe/xe_device.c                |  14 +
drivers/gpu/drm/xe/xe_device_types.h          |   4 +
drivers/gpu/drm/xe/xe_ggtt.c                  |  23 +-
drivers/gpu/drm/xe/xe_ggtt_types.h            |   2 +
drivers/gpu/drm/xe/xe_gt.c                    |  19 +
drivers/gpu/drm/xe/xe_gt.h                    |   1 +
drivers/gpu/drm/xe/xe_gt_debugfs.c            |  21 --
drivers/gpu/drm/xe/xe_gt_pagefault.c          | 104 +-----
drivers/gpu/drm/xe/xe_gt_pagefault.h          |   3 -
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c   | 342 ++++++++++++++++++
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h   |  26 ++
.../gpu/drm/xe/xe_gt_tlb_invalidation_types.h |  28 ++
drivers/gpu/drm/xe/xe_gt_types.h              |  41 ++-
drivers/gpu/drm/xe/xe_guc.c                   |   2 +
drivers/gpu/drm/xe/xe_guc_ct.c                |  10 +-
drivers/gpu/drm/xe/xe_guc_types.h             |   2 +
drivers/gpu/drm/xe/xe_lrc.c                   |   4 +-
drivers/gpu/drm/xe/xe_pci.c                   |   7 +
drivers/gpu/drm/xe/xe_pt.c                    | 130 +++++++
drivers/gpu/drm/xe/xe_ring_ops.c              |  40 +-
drivers/gpu/drm/xe/xe_trace.h                 |  55 +++
drivers/gpu/drm/xe/xe_uc.c                    |   9 +-
drivers/gpu/drm/xe/xe_uc.h                    |   1 +
drivers/gpu/drm/xe/xe_vm.c                    |  42 ++-
26 files changed, 736 insertions(+), 200 deletions(-)

create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h create mode 100644 drivers/gpu/drm/xe/xe_gt_tlb_invalidation_types.h

--
2.39.1