Skip to contentSkip to conversation

AubCrash

RFC PATCH In review Oscar Mateo 4 participants 26 messages Oct 27, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover AubCrash

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Oscar Mateo (12):
drm/i915: New define for the number of PDPEs per PDP in a 4-level walk drm/i915: Move the context switch status reason bits to the header drm/i915: Store the GGTT Stolen Memory base physical address drm/i915: Capture some extra small details in the GPU error state drm/i915: Capture the renderstate batchbuffer
drm/i915: Provide a way to write binary data to the error dump file drm/i915: Skeleton for AubCrash
drm/i915: Capture the PPGTT pagetables on a GPU crash drm/i915: Store PTE information together with the error object pages drm/i915: Always add BOs to capture list if AubCrash is enabled drm/i915: Add an AUB file format writer
drm/i915: Actually write the AUB file

 drivers/gpu/drm/i915/Kconfig                   |   8 +
 drivers/gpu/drm/i915/Makefile                  |   1 +
 drivers/gpu/drm/i915/i915_aubcrash.c           | 436 ++++++++++++++++
 drivers/gpu/drm/i915/i915_aubcrash.h           |  79 +++
 drivers/gpu/drm/i915/i915_aubmemtrace.c        | 665 +++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_aubmemtrace.h        |  76 +++
 drivers/gpu/drm/i915/i915_aubmemtrace_format.h | 359 +++++++++++++
 drivers/gpu/drm/i915/i915_debugfs.c            |  49 +-
 drivers/gpu/drm/i915/i915_drv.h                |  20 +-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c     |   4 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c            |   1 +
 drivers/gpu/drm/i915/i915_gem_gtt.h            |   4 +-
 drivers/gpu/drm/i915/i915_gem_render_state.c   |  11 +
 drivers/gpu/drm/i915/i915_gem_render_state.h   |   1 +
 drivers/gpu/drm/i915/i915_gpu_error.c          |  89 +++-
 drivers/gpu/drm/i915/i915_sysfs.c              |  54 +-
 drivers/gpu/drm/i915/intel_lrc.c               |  12 -
 drivers/gpu/drm/i915/intel_lrc.h               |  14 +
 18 files changed, 1833 insertions(+), 50 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_aubcrash.c
 create mode 100644 drivers/gpu/drm/i915/i915_aubcrash.h
 create mode 100644 drivers/gpu/drm/i915/i915_aubmemtrace.c
 create mode 100644 drivers/gpu/drm/i915/i915_aubmemtrace.h
 create mode 100644 drivers/gpu/drm/i915/i915_aubmemtrace_format.h
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

RFC PATCH 1/12 drm/i915: New define for the number of PDPEs per PDP in a 4-level walk

The number of PML4Es per PML4 and the number of PDPEs per PDP should not be confused (even if the amount, 512, is indeed the same).

Cc Mika Kuoppala <[email protected]>
Cc Chris Wilson <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_gtt.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_gtt.h +2 -1
index 93211a9..717bbd6 100644
@@ -124,6 +124,7 @@
  * 47:39 | 38:30 | 29:21 | 20:12 |  11:0
  * PML4E | PDPE  |  PDE  |  PTE  | offset
  */
+#define GEN8_4LVL_PDPES			512
 #define GEN8_PML4ES_PER_PML4		512
 #define GEN8_PML4E_SHIFT		39
 #define GEN8_PML4E_MASK			(GEN8_PML4ES_PER_PML4 - 1)
@@ -488,7 +489,7 @@ static inline u32 gen6_pde_index(u32 addr)
 i915_pdpes_per_pdp(const struct i915_address_space *vm)
 {
 	if (i915_vm_is_48bit(vm))
-		return GEN8_PML4ES_PER_PML4;
+		return GEN8_4LVL_PDPES;
 
 	return GEN8_3LVL_PDPES;
 }
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

RFC PATCH 2/12 drm/i915: Move the context switch status reason bits to the header

In reply to Oscar Mateo

I am planning on using them in AubCrash. While at it, define the mask and shift for the Last Context Switch Reason field inside the Execlist Status register.

Cc Mika Kuoppala <[email protected]>
Cc Chris Wilson <[email protected]>
---
 drivers/gpu/drm/i915/intel_lrc.c | 12 ------------
 drivers/gpu/drm/i915/intel_lrc.h | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_lrc.c +0 -12
index e821c1e..f4a3516 100644
@@ -145,18 +145,6 @@
 #define RING_EXECLIST1_ACTIVE		(1 << 0x11)
 #define RING_EXECLIST0_ACTIVE		(1 << 0x12)
 
-#define GEN8_CTX_STATUS_IDLE_ACTIVE	(1 << 0)
-#define GEN8_CTX_STATUS_PREEMPTED	(1 << 1)
-#define GEN8_CTX_STATUS_ELEMENT_SWITCH	(1 << 2)
-#define GEN8_CTX_STATUS_ACTIVE_IDLE	(1 << 3)
-#define GEN8_CTX_STATUS_COMPLETE	(1 << 4)
-#define GEN8_CTX_STATUS_LITE_RESTORE	(1 << 15)
-
-#define GEN8_CTX_STATUS_COMPLETED_MASK \
-	 (GEN8_CTX_STATUS_ACTIVE_IDLE | \
-	  GEN8_CTX_STATUS_PREEMPTED | \
-	  GEN8_CTX_STATUS_ELEMENT_SWITCH)
-
 #define CTX_LRI_HEADER_0		0x01
 #define CTX_CONTEXT_CONTROL		0x02
 #define CTX_RING_HEAD			0x04
drivers/gpu/drm/i915/intel_lrc.h +14 -0
index 689fde1..7da2809 100644
@@ -32,6 +32,8 @@
 /* Execlists regs */
 #define RING_ELSP(engine)			_MMIO((engine)->mmio_base + 0x230)
 #define RING_EXECLIST_STATUS_LO(engine)		_MMIO((engine)->mmio_base + 0x234)
+#define   EL_STATUS_LAST_CTX_SWITCH_SHIFT	5
+#define   EL_STATUS_LAST_CTX_SWITCH_MASK	(0x1ff << EL_STAT_LAST_CTX_SWITCH_REASON_SHIFT)
 #define RING_EXECLIST_STATUS_HI(engine)		_MMIO((engine)->mmio_base + 0x234 + 4)
 #define RING_CONTEXT_CONTROL(engine)		_MMIO((engine)->mmio_base + 0x244)
 #define	  CTX_CTRL_INHIBIT_SYN_CTX_SWITCH	(1 << 3)
@@ -42,6 +44,18 @@
 #define RING_CONTEXT_STATUS_BUF_HI(engine, i)	_MMIO((engine)->mmio_base + 0x370 + (i) * 8 + 4)
 #define RING_CONTEXT_STATUS_PTR(engine)		_MMIO((engine)->mmio_base + 0x3a0)
 
+/* Context switch status */
+#define GEN8_CTX_STATUS_IDLE_ACTIVE	(1 << 0)
+#define GEN8_CTX_STATUS_PREEMPTED	(1 << 1)
+#define GEN8_CTX_STATUS_ELEMENT_SWITCH	(1 << 2)
+#define GEN8_CTX_STATUS_ACTIVE_IDLE	(1 << 3)
+#define GEN8_CTX_STATUS_COMPLETE	(1 << 4)
+#define GEN8_CTX_STATUS_LITE_RESTORE	(1 << 15)
+#define GEN8_CTX_STATUS_COMPLETED_MASK \
+	 (GEN8_CTX_STATUS_ACTIVE_IDLE | \
+	  GEN8_CTX_STATUS_PREEMPTED | \
+	  GEN8_CTX_STATUS_ELEMENT_SWITCH)
+
 /* The docs specify that the write pointer wraps around after 5h, "After status
  * is written out to the last available status QW at offset 5h, this pointer
  * wraps to 0."
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

RFC PATCH 3/12 drm/i915: Store the GGTT Stolen Memory base physical address

In reply to Oscar Mateo

I'm planning on using it later for AubCrash.

Cc Mika Kuoppala <[email protected]>
Cc Chris Wilson <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 1 +
 drivers/gpu/drm/i915/i915_gem_gtt.h | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -0
index 5eaa689..c5b5892 100644
@@ -2974,6 +2974,7 @@ static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size)
 
 	/* For Modern GENs the PTEs and register space are split in the BAR */
 	phys_addr = pci_resource_start(pdev, 0) + pci_resource_len(pdev, 0) / 2;
+	ggtt->gsm_paddr = phys_addr;
 
 	/*
 	 * On BXT+/CNL+ writes larger than 64 bit to the GTT pagetable range
drivers/gpu/drm/i915/i915_gem_gtt.h +1 -0
index 717bbd6..c64fce1 100644
@@ -388,6 +388,7 @@ struct i915_ggtt {
 	u32 stolen_reserved_size;
 
 	/** "Graphics Stolen Memory" holds the global PTEs */
+	phys_addr_t gsm_paddr;
 	void __iomem *gsm;
 	void (*invalidate)(struct drm_i915_private *dev_priv);
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

RFC PATCH 4/12 drm/i915: Capture some extra small details in the GPU error state

In reply to Oscar Mateo

Namely:
- Capture tiling per drm_i915_error_object
- Capture the LRC descriptor per active request
- Capture the wa_batchbuffer unconditionally
- Capture the GAM_ECOCHK register for all GENs

They don't increase the size greatly, and they can be useful even in the existing GPU error dump (but I will need them for sure in AubCrash).

---
 drivers/gpu/drm/i915/i915_drv.h       |  2 ++
 drivers/gpu/drm/i915/i915_gpu_error.c | 25 +++++++++++++++----------
 2 files changed, 17 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 366ba74..f64871b 100644
@@ -992,6 +992,7 @@ struct i915_gpu_state {
 		struct drm_i915_error_object {
 			u64 gtt_offset;
 			u64 gtt_size;
+			u32 tiling:2;
 			int page_count;
 			int unused;
 			u32 *pages[0];
@@ -1006,6 +1007,7 @@ struct i915_gpu_state {
 			long jiffies;
 			pid_t pid;
 			u32 context;
+			u64 lrc_desc;
 			int priority;
 			int ban_score;
 			u32 seqno;
drivers/gpu/drm/i915/i915_gpu_error.c +15 -10
index 653fb69..befd17c 100644
@@ -897,6 +897,7 @@ void __i915_gpu_state_free(struct kref *error_ref)
 
 	dst->gtt_offset = vma->node.start;
 	dst->gtt_size = vma->node.size;
+	dst->tiling = i915_gem_object_get_tiling(vma->obj);
 	dst->page_count = 0;
 	dst->unused = 0;
 
@@ -1270,16 +1271,21 @@ static void error_record_engine_registers(struct i915_gpu_state *error,
 static void record_request(struct drm_i915_gem_request *request,
 			   struct drm_i915_error_request *erq)
 {
-	erq->context = request->ctx->hw_id;
+	struct i915_gem_context *ctx = request->ctx;
+	struct intel_engine_cs *engine = request->engine;
+	struct intel_context *ce = &ctx->engine[engine->id];
+
+	erq->context = ctx->hw_id;
+	erq->lrc_desc = ce->lrc_desc;
 	erq->priority = request->priotree.priority;
-	erq->ban_score = atomic_read(&request->ctx->ban_score);
+	erq->ban_score = atomic_read(&ctx->ban_score);
 	erq->seqno = request->global_seqno;
 	erq->jiffies = request->emitted_jiffies;
 	erq->head = request->head;
 	erq->tail = request->tail;
 
 	rcu_read_lock();
-	erq->pid = request->ctx->pid ? pid_nr(request->ctx->pid) : 0;
+	erq->pid = ctx->pid ? pid_nr(ctx->pid) : 0;
 	rcu_read_unlock();
 }
 
@@ -1442,10 +1448,10 @@ static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
 				i915_error_object_create(dev_priv,
 							 request->batch);
 
-			if (HAS_BROKEN_CS_TLB(dev_priv))
-				ee->wa_batchbuffer =
-					i915_error_object_create(dev_priv,
-								 engine->scratch);
+			ee->wa_batchbuffer =
+				i915_error_object_create(dev_priv,
+							 engine->scratch);
+
 			request_record_user_bo(request, ee);
 
 			ee->ctx =
@@ -1619,10 +1625,8 @@ static void i915_capture_reg_state(struct drm_i915_private *dev_priv,
 		error->ccid = I915_READ(CCID);
 
 	/* 3: Feature specific registers */
-	if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
-		error->gam_ecochk = I915_READ(GAM_ECOCHK);
+	if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv))
 		error->gac_eco = I915_READ(GAC_ECO_BITS);
-	}
 
 	/* 4: Everything else */
 	if (INTEL_GEN(dev_priv) >= 8) {
@@ -1641,6 +1645,7 @@ static void i915_capture_reg_state(struct drm_i915_private *dev_priv,
 	}
 	error->eir = I915_READ(EIR);
 	error->pgtbl_er = I915_READ(PGTBL_ER);
+	error->gam_ecochk = I915_READ(GAM_ECOCHK);
 }
 
 static void i915_error_capture_msg(struct drm_i915_private *dev_priv,
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

Re: [RFC PATCH 04/12] drm/i915: Capture some extra small details in the GPU error state

Quoting Oscar Mateo (2017-10-27 19:01:07)

Quoted 2 lines

Namely:
- Capture tiling per drm_i915_error_object

tiling isn't that useful as it only relates to fences and not userspace.

Quoted 1 line

- Capture the LRC descriptor per active request

Context details.

Quoted 2 lines

- Capture the wa_batchbuffer unconditionally
- Capture the GAM_ECOCHK register for all GENs

4 different items in the changelog...

Simple rule: every and is a new patch.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

RFC PATCH 5/12 drm/i915: Capture the renderstate batchbuffer

In reply to Oscar Mateo

It can be useful if it's in play at the time of the crash, and I will be needing it in AubCrash.

Cc Mika Kuoppala <[email protected]>
Cc Chris Wilson <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.h              |  3 ++-
 drivers/gpu/drm/i915/i915_gem_render_state.c | 11 +++++++++++
 drivers/gpu/drm/i915/i915_gem_render_state.h |  1 +
 drivers/gpu/drm/i915/i915_gpu_error.c        | 13 +++++++++++++
 4 files changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -1
index f64871b..23d746b 100644
@@ -996,7 +996,8 @@ struct i915_gpu_state {
 			int page_count;
 			int unused;
 			u32 *pages[0];
-		} *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
+		} *ringbuffer, *batchbuffer, *wa_batchbuffer,
+		  *renderstate, *ctx, *hws_page;
 
 		struct drm_i915_error_object **user_bo;
 		long user_bo_count;
drivers/gpu/drm/i915/i915_gem_render_state.c +11 -0
index 3703dc9..47454fb 100644
@@ -266,6 +266,17 @@ int i915_gem_render_state_emit(struct drm_i915_gem_request *req)
 	return ret;
 }
 
+struct i915_vma *i915_gem_render_state_get(struct intel_engine_cs *engine)
+{
+	struct intel_render_state *so;
+
+	so = engine->render_state;
+	if (!so)
+		return NULL;
+
+	return so->vma;
+}
+
 void i915_gem_render_state_fini(struct intel_engine_cs *engine)
 {
 	struct intel_render_state *so;
drivers/gpu/drm/i915/i915_gem_render_state.h +1 -0
index 8748184..c760cf9 100644
@@ -28,6 +28,7 @@
 
 int i915_gem_render_state_init(struct intel_engine_cs *engine);
 int i915_gem_render_state_emit(struct drm_i915_gem_request *req);
+struct i915_vma *i915_gem_render_state_get(struct intel_engine_cs *engine);
 void i915_gem_render_state_fini(struct intel_engine_cs *engine);
 
 #endif /* _I915_GEM_RENDER_STATE_H_ */
drivers/gpu/drm/i915/i915_gpu_error.c +13 -0
index befd17c..a14aa29 100644
@@ -755,6 +755,9 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
 				"HW context", ee->ctx);
 
 		print_error_obj(m, dev_priv->engine[i],
+				"Renderstate", ee->renderstate);
+
+		print_error_obj(m, dev_priv->engine[i],
 				"WA context", ee->wa_ctx);
 
 		print_error_obj(m, dev_priv->engine[i],
@@ -850,6 +853,7 @@ void __i915_gpu_state_free(struct kref *error_ref)
 		i915_error_object_free(ee->hws_page);
 		i915_error_object_free(ee->ctx);
 		i915_error_object_free(ee->wa_ctx);
+		i915_error_object_free(ee->renderstate);
 
 		kfree(ee->requests);
 		if (!IS_ERR_OR_NULL(ee->waiters))
@@ -1434,6 +1438,7 @@ static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
 		request = i915_gem_find_active_request(engine);
 		if (request) {
 			struct intel_ring *ring;
+			struct i915_vma *renderstate_vma;
 
 			ee->vm = request->ctx->ppgtt ?
 				&request->ctx->ppgtt->base : &ggtt->base;
@@ -1454,6 +1459,14 @@ static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
 
 			request_record_user_bo(request, ee);
 
+			renderstate_vma = i915_gem_render_state_get(engine);
+			if (renderstate_vma &&
+			    i915_vma_is_active(renderstate_vma)) {
+				ee->renderstate =
+					i915_error_object_create(dev_priv,
+								 renderstate_vma);
+			}
+
 			ee->ctx =
 				i915_error_object_create(dev_priv,
 							 request->ctx->engine[i].state);
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

Re: [RFC PATCH 05/12] drm/i915: Capture the renderstate batchbuffer

Quoting Oscar Mateo (2017-10-27 19:01:08)

Quoted 2 lines

It can be useful if it's in play at the time of the crash, and I will be needing it in AubCrash.

Ambiguous pronoun.

Just add it to the error-state unconditionally. Active is used very loosely here.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

RFC PATCH 6/12 drm/i915: Provide a way to write binary data to the error dump file

In reply to Oscar Mateo

i915_error_puts becomes an specialization of the more general case. Also, make it publicly accesible (since I will be using it inside AubCrash).

---
 drivers/gpu/drm/i915/i915_drv.h       |  2 ++
 drivers/gpu/drm/i915/i915_gpu_error.c | 19 +++++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 23d746b..ae3c8b1 100644
@@ -3937,6 +3937,8 @@ static inline void intel_display_crc_init(struct drm_i915_private *dev_priv) {}
 
 __printf(2, 3)
 void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
+void i915_error_binary_write(struct drm_i915_error_state_buf *e,
+			     const void *data, size_t len);
 int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
 			    const struct i915_gpu_state *gpu);
 int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
drivers/gpu/drm/i915/i915_gpu_error.c +11 -8
index a14aa29..e71d2c8 100644
@@ -149,17 +149,13 @@ static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
 	__i915_error_advance(e, len);
 }
 
-static void i915_error_puts(struct drm_i915_error_state_buf *e,
-			    const char *str)
+void i915_error_binary_write(struct drm_i915_error_state_buf *e,
+			     const void *data, size_t len)
 {
-	unsigned len;
-
 	if (!__i915_error_ok(e))
 		return;
 
-	len = strlen(str);
-
-	/* Seek the first printf which is hits start position */
+	/* Seek the first printf which hits start position */
 	if (e->pos < e->start) {
 		if (!__i915_error_seek(e, len))
 			return;
@@ -167,11 +163,18 @@ static void i915_error_puts(struct drm_i915_error_state_buf *e,
 
 	if (len >= e->size - e->bytes)
 		len = e->size - e->bytes - 1;
-	memcpy(e->buf + e->bytes, str, len);
+	memcpy(e->buf + e->bytes, data, len);
 
 	__i915_error_advance(e, len);
 }
 
+static void i915_error_puts(struct drm_i915_error_state_buf *e, const char *str)
+{
+	size_t len = strlen(str);
+
+	i915_error_binary_write(e, str, len);
+}
+
 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
 #define err_puts(e, s) i915_error_puts(e, s)
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

RFC PATCH 7/12 drm/i915: Skeleton for AubCrash

In reply to Oscar Mateo

Includes some documentation on what AubCrash is supposed to achieve.

---
 drivers/gpu/drm/i915/Kconfig         |  8 ++++++
 drivers/gpu/drm/i915/Makefile        |  1 +
 drivers/gpu/drm/i915/i915_aubcrash.c | 47 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_aubcrash.h | 42 ++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_debugfs.c  | 49 +++++++++++++++++++++++++++++---
 drivers/gpu/drm/i915/i915_sysfs.c    | 54 +++++++++++++++++++++++++++++++++---
 6 files changed, 193 insertions(+), 8 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_aubcrash.c
 create mode 100644 drivers/gpu/drm/i915/i915_aubcrash.h
drivers/gpu/drm/i915/Kconfig +8 -0
index dfd9588..176e53e 100644
@@ -70,6 +70,14 @@ config DRM_I915_CAPTURE_ERROR
 
 	  If in doubt, say "Y".
 
+config DRM_I915_AUB_CRASH_DUMP
+        bool "Capture GPU error state in the form of an AUB file"
+        depends on DRM_I915_CAPTURE_ERROR
+        default n
+        help
+          Choose this option to allow the driver to dump a memtrace file (AUB)
+          with the GPU state when a hang is detected.
+
 config DRM_I915_COMPRESS_ERROR
 	bool "Compress GPU error state"
 	depends on DRM_I915_CAPTURE_ERROR
drivers/gpu/drm/i915/Makefile +1 -0
index 6c3b048..04956c7 100644
@@ -124,6 +124,7 @@ i915-y += dvo_ch7017.o \
 
 # Post-mortem debug and GPU hang state capture
 i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
+i915-$(CONFIG_DRM_I915_AUB_CRASH_DUMP) += i915_aubcrash.o
 i915-$(CONFIG_DRM_I915_SELFTEST) += \
 	selftests/i915_random.o \
 	selftests/i915_selftest.o
drivers/gpu/drm/i915/i915_aubcrash.c new file +47 -0

47 lines not on this page · raw message

drivers/gpu/drm/i915/i915_aubcrash.h new file +42 -0

42 lines not on this page · raw message

drivers/gpu/drm/i915/i915_debugfs.c +45 -4

95 lines not on this page · raw message

drivers/gpu/drm/i915/i915_sysfs.c +50 -4

101 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw

RFC PATCH 8/12 drm/i915: Capture the PPGTT pagetables on a GPU crash

In reply to Oscar Mateo

Or, at least, the first thee levels (PML4, PDPs, PDs). We'll deal with the PTs later, at the same time we record actual physical pages with data.

We only do this when AubCrash is enabled, to save space, but we could also do it unconditionally and maybe dump it in text mode when in the legacy crash dump.

c: Chris Wilson <[email protected]>

---
 drivers/gpu/drm/i915/i915_aubcrash.c  | 169 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_aubcrash.h  |  14 +++
 drivers/gpu/drm/i915/i915_drv.h       |   6 ++
 drivers/gpu/drm/i915/i915_gpu_error.c |   8 ++
 4 files changed, 197 insertions(+)
drivers/gpu/drm/i915/i915_aubcrash.c +169 -0
index 95b75ab..1b613e4 100644
@@ -40,6 +40,175 @@
  *
  */
 
+#define COPY_PX_ENTRIES(px, storage) do { \
+	u64 *vaddr; \
+	if (!storage) \
+		return -ENOMEM; \
+	vaddr = kmap_atomic(px_base(px)->page); \
+	memcpy(storage, vaddr, PAGE_SIZE); \
+	kunmap_atomic(vaddr); \
+} while (0)
+
+int record_pml4(struct drm_i915_error_pagemap_lvl *e_pml4,
+		struct i915_pml4 *pml4,
+		struct i915_page_directory_pointer *scratch_pdp,
+		bool is_48bit)
+{
+	int l3;
+
+	if (is_48bit) {
+		e_pml4->paddr = px_dma(pml4);
+		e_pml4->storage = (u64 *)__get_free_page(GFP_ATOMIC | __GFP_NOWARN);
+		COPY_PX_ENTRIES(pml4, e_pml4->storage);
+		for (l3 = 0; l3 < GEN8_PML4ES_PER_PML4; l3++)
+			if (pml4->pdps[l3] != scratch_pdp)
+				e_pml4->nxt_lvl_count++;
+	} else
+		e_pml4->nxt_lvl_count = 1;
+
+	e_pml4->nxt_lvl = kcalloc(e_pml4->nxt_lvl_count,
+				  sizeof(*e_pml4->nxt_lvl), GFP_ATOMIC);
+	if (!e_pml4->nxt_lvl) {
+		e_pml4->nxt_lvl_count = 0;
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+int record_pdp(struct drm_i915_error_pagemap_lvl *e_pdp,
+	       struct i915_page_directory_pointer *pdp,
+	       bool is_48bit)
+{
+	if (is_48bit) {
+		e_pdp->paddr = px_dma(pdp);
+		e_pdp->storage = (u64 *)__get_free_page(GFP_ATOMIC | __GFP_NOWARN);
+		COPY_PX_ENTRIES(pdp, e_pdp->storage);
+	}
+
+	e_pdp->nxt_lvl_count = pdp->used_pdpes;
+	e_pdp->nxt_lvl = kcalloc(e_pdp->nxt_lvl_count,
+				  sizeof(*e_pdp->nxt_lvl), GFP_ATOMIC);
+	if (!e_pdp->nxt_lvl) {
+		e_pdp->nxt_lvl_count = 0;
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+int record_pd(struct drm_i915_error_pagemap_lvl *e_pd,
+	      struct i915_page_directory *pd)
+{
+	e_pd->paddr = px_dma(pd);
+	e_pd->storage = (u64 *)__get_free_page(GFP_ATOMIC | __GFP_NOWARN);
+	COPY_PX_ENTRIES(pd, e_pd->storage);
+
+	e_pd->nxt_lvl_count = pd->used_pdes;
+	e_pd->nxt_lvl = kcalloc(e_pd->nxt_lvl_count,
+				sizeof(*e_pd->nxt_lvl), GFP_ATOMIC);
+	if (!e_pd->nxt_lvl) {
+		e_pd->nxt_lvl_count = 0;
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+void i915_error_record_ppgtt(struct i915_gpu_state *error,
+			     struct i915_address_space *vm,
+			     int idx)
+{
+	struct i915_hw_ppgtt *ppgtt;
+	struct drm_i915_error_pagemap_lvl *e_pml4;
+	struct i915_pml4 *pml4;
+	int l3, l2, max_lvl3, max_lvl2, i, j;
+	bool is_48bit;
+	int ret;
+
+	if (i915_is_ggtt(vm))
+		return;
+
+	ppgtt = i915_vm_to_ppgtt(vm);
+	is_48bit = i915_vm_is_48bit(&ppgtt->base);
+	if (is_48bit) {
+		max_lvl3 = GEN8_PML4ES_PER_PML4;
+		max_lvl2 = GEN8_4LVL_PDPES;
+	} else {
+		max_lvl3 = 1;
+		max_lvl2 = GEN8_3LVL_PDPES;
+	}
+
+	/* PML4 */
+	pml4 = is_48bit? &ppgtt->pml4 : NULL;
+	e_pml4 = &error->ppgtt_pml4[idx];
+	ret = record_pml4(e_pml4, pml4, vm->scratch_pdp, is_48bit);
+	if (ret < 0)
+		return;
+
+	/* PDP */
+	for (l3 = 0, i = 0; l3 < max_lvl3; l3++) {
+		struct drm_i915_error_pagemap_lvl *e_pdp;
+		struct i915_page_directory_pointer *pdp;
+
+		pdp = is_48bit? pml4->pdps[l3] : &ppgtt->pdp;
+		if (pdp == vm->scratch_pdp)
+			continue;
+
+		e_pdp = &e_pml4->nxt_lvl[i];
+		ret = record_pdp(e_pdp, pdp, is_48bit);
+		if (ret < 0)
+			return;
+
+		/* PD */
+		for (l2 = 0, j = 0; l2 < max_lvl2; l2++) {
+			struct drm_i915_error_pagemap_lvl *e_pd;
+			struct i915_page_directory *pd;
+
+			pd = pdp->page_directory[l2];
+			if (pd == vm->scratch_pd)
+				continue;
+
+			e_pd = &e_pdp->nxt_lvl[j];
+			ret = record_pd(e_pd, pd);
+			if (ret < 0)
+				return;
+
+			if (++j == e_pdp->nxt_lvl_count)
+				break;
+		}
+
+		if (++i == e_pml4->nxt_lvl_count)
+			break;
+
+	}
+
+	/* XXX: Do I want to dump the scratch pdp/pd/pt/page? */
+	/* TODO: Support huge pages */
+}
+
+void i915_error_free_ppgtt(struct i915_gpu_state *error, int idx)
+{
+	struct drm_i915_error_pagemap_lvl *e_pml4 = &error->ppgtt_pml4[idx];
+	int i, j;
+
+	for (i = e_pml4->nxt_lvl_count - 1; i >= 0; i--) {
+		struct drm_i915_error_pagemap_lvl *e_pdp =
+			&e_pml4->nxt_lvl[i];
+
+		for (j = e_pdp->nxt_lvl_count - 1; j >= 0; j--) {
+			struct drm_i915_error_pagemap_lvl *e_pd =
+				&e_pdp->nxt_lvl[j];
+
+			free_page((unsigned long)e_pd->storage);
+			kfree(e_pd);
+		}
+		free_page((unsigned long)e_pdp->storage);
+		kfree(e_pdp);
+	}
+	free_page((unsigned long)e_pml4->storage);
+}
+
 int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
 			    const struct i915_gpu_state *error)
 {
drivers/gpu/drm/i915/i915_aubcrash.h +14 -0
index bab1953..af7d42e 100644
@@ -26,11 +26,25 @@
 
 #if IS_ENABLED(CONFIG_DRM_I915_AUB_CRASH_DUMP)
 
+void i915_error_record_ppgtt(struct i915_gpu_state *error,
+			     struct i915_address_space *vm,
+			     int idx);
+void i915_error_free_ppgtt(struct i915_gpu_state *error, int idx);
 int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
                             const struct i915_gpu_state *error);
 
 #else
 
+static inline void i915_error_record_ppgtt(struct i915_gpu_state *error,
+					   struct i915_address_space *vm,
+					   int idx)
+{
+}
+
+static inline void i915_error_free_ppgtt(struct i915_gpu_state *error, int idx)
+{
+}
+
 static inline int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
 					  const struct i915_gpu_state *error)
 {
drivers/gpu/drm/i915/i915_drv.h +6 -0
index ae3c8b1..9b2539a 100644
@@ -1048,6 +1048,12 @@ struct i915_gpu_state {
 		u32 cache_level:3;
 	} *active_bo[I915_NUM_ENGINES], *pinned_bo;
 	u32 active_bo_count[I915_NUM_ENGINES], pinned_bo_count;
+	struct drm_i915_error_pagemap_lvl {
+		phys_addr_t paddr;
+		u64 *storage;
+		struct drm_i915_error_pagemap_lvl *nxt_lvl;
+		uint nxt_lvl_count;
+	} ppgtt_pml4[I915_NUM_ENGINES];
 	struct i915_address_space *active_vm[I915_NUM_ENGINES];
 };
 
drivers/gpu/drm/i915/i915_gpu_error.c +8 -0
index e71d2c8..39b69d8 100644
@@ -31,6 +31,7 @@
 #include <linux/stop_machine.h>
 #include <linux/zlib.h>
 #include "i915_drv.h"
+#include "i915_aubcrash.h"
 
 static const char *engine_str(int engine)
 {
@@ -866,6 +867,9 @@ void __i915_gpu_state_free(struct kref *error_ref)
 	i915_error_object_free(error->semaphore);
 	i915_error_object_free(error->guc_log);
 
+	for (i = 0; i < ARRAY_SIZE(error->ppgtt_pml4); i++)
+		i915_error_free_ppgtt(error, i);
+
 	for (i = 0; i < ARRAY_SIZE(error->active_bo); i++)
 		kfree(error->active_bo[i]);
 	kfree(error->pinned_bo);
@@ -1520,6 +1524,9 @@ static void i915_gem_capture_vm(struct drm_i915_private *dev_priv,
 	else
 		count = 0;
 
+	if (INTEL_GEN(dev_priv) >= 8)
+		i915_error_record_ppgtt(error, vm, idx);
+
 	error->active_vm[idx] = vm;
 	error->active_bo[idx] = active_bo;
 	error->active_bo_count[idx] = count;
@@ -1533,6 +1540,7 @@ static void i915_capture_active_buffers(struct drm_i915_private *dev_priv,
 	BUILD_BUG_ON(ARRAY_SIZE(error->engine) > ARRAY_SIZE(error->active_bo));
 	BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_vm));
 	BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_bo_count));
+	BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->ppgtt_pml4));
 
 	/* Scan each engine looking for unique active contexts/vm */
 	for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw

RFC PATCH 9/12 drm/i915: Store PTE information together with the error object pages

In reply to Oscar Mateo

With every page of physical data we store: its physical address, the PTE that points to it and the physical address of the PTE itself. We will be using all this information later.

---
 drivers/gpu/drm/i915/i915_aubcrash.c  | 46 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_aubcrash.h  | 11 +++++++++
 drivers/gpu/drm/i915/i915_drv.h       |  7 +++++-
 drivers/gpu/drm/i915/i915_gpu_error.c | 24 ++++++++++++------
 4 files changed, 79 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_aubcrash.c +46 -0
index 1b613e4..ebdbf09 100644
@@ -209,6 +209,52 @@ void i915_error_free_ppgtt(struct i915_gpu_state *error, int idx)
 	free_page((unsigned long)e_pml4->storage);
 }
 
+void i915_error_page_walk(struct i915_address_space *vm,
+			  u64 offset,
+			  gen8_pte_t *entry,
+			  phys_addr_t *paddr)
+{
+	if (i915_is_ggtt(vm)) {
+		struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
+		uint index = offset >> PAGE_SHIFT;
+
+		gen8_pte_t __iomem *pte =
+			(gen8_pte_t __iomem *)ggtt->gsm + index;
+
+		*entry = readq(pte);
+		*paddr = ggtt->gsm_paddr + index * sizeof(u64);
+	} else {
+		struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm);
+		struct i915_pml4 *pml4;
+		struct i915_page_directory_pointer *pdp;
+		struct i915_page_directory *pd;
+		struct i915_page_table *pt;
+		u32 pml4e, pdpe, pde, pte;
+		u64 *vaddr;
+
+		pml4e = gen8_pml4e_index(offset);
+		if (i915_vm_is_48bit(&ppgtt->base)) {
+			pml4 = &ppgtt->pml4;
+			pdp = pml4->pdps[pml4e];
+		} else {
+			GEM_BUG_ON(pml4e != 0);
+			pdp = &ppgtt->pdp;
+		}
+
+		pdpe = gen8_pdpe_index(offset);
+		pd = pdp->page_directory[pdpe];
+
+		pde = gen8_pde_index(offset);
+		pt = pd->page_table[pde];
+
+		pte = gen8_pte_index(offset);
+		vaddr = kmap_atomic(px_base(pt)->page);
+		*entry = vaddr[pte];
+		kunmap_atomic(vaddr);
+		*paddr = px_dma(pt) + pte * sizeof(u64);
+	}
+}
+
 int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
 			    const struct i915_gpu_state *error)
 {
drivers/gpu/drm/i915/i915_aubcrash.h +11 -0
index af7d42e..2eed388 100644
@@ -30,6 +30,10 @@ void i915_error_record_ppgtt(struct i915_gpu_state *error,
 			     struct i915_address_space *vm,
 			     int idx);
 void i915_error_free_ppgtt(struct i915_gpu_state *error, int idx);
+void i915_error_page_walk(struct i915_address_space *vm,
+			  u64 offset,
+			  gen8_pte_t *entry,
+			  phys_addr_t *paddr);
 int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
                             const struct i915_gpu_state *error);
 
@@ -45,6 +49,13 @@ static inline void i915_error_free_ppgtt(struct i915_gpu_state *error, int idx)
 {
 }
 
+static inline void i915_error_page_walk(struct i915_address_space *vm,
+					u64 offset,
+					gen8_pte_t *entry,
+					phys_addr_t *paddr)
+{
+}
+
 static inline int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
 					  const struct i915_gpu_state *error)
 {
drivers/gpu/drm/i915/i915_drv.h +6 -1
index 9b2539a..6db4f96 100644
@@ -995,7 +995,12 @@ struct i915_gpu_state {
 			u32 tiling:2;
 			int page_count;
 			int unused;
-			u32 *pages[0];
+			struct drm_i915_error_page {
+				phys_addr_t pte_paddr;
+				gen8_pte_t pte;
+				phys_addr_t paddr;
+				u32 *storage;
+			} pages[0];
 		} *ringbuffer, *batchbuffer, *wa_batchbuffer,
 		  *renderstate, *ctx, *hws_page;
 
drivers/gpu/drm/i915/i915_gpu_error.c +16 -8
index 39b69d8..924691d2 100644
@@ -179,7 +179,7 @@ static void i915_error_puts(struct drm_i915_error_state_buf *e, const char *str)
 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
 #define err_puts(e, s) i915_error_puts(e, s)
 
-#ifdef CONFIG_DRM_I915_COMPRESS_ERROR
+#if defined(CONFIG_DRM_I915_COMPRESS_ERROR) && !defined(CONFIG_DRM_I915_AUB_CRASH_DUMP)
 
 struct compress {
 	struct z_stream_s zstream;
@@ -227,7 +227,7 @@ static int compress_page(struct compress *c,
 			if (!page)
 				return -ENOMEM;
 
-			dst->pages[dst->page_count++] = (void *)page;
+			dst->pages[dst->page_count++].storage = (void *)page;
 
 			zstream->next_out = (void *)page;
 			zstream->avail_out = PAGE_SIZE;
@@ -290,7 +290,7 @@ static int compress_page(struct compress *c,
 	ptr = (void *)page;
 	if (!i915_memcpy_from_wc(ptr, src, PAGE_SIZE))
 		memcpy(ptr, src, PAGE_SIZE);
-	dst->pages[dst->page_count++] = ptr;
+	dst->pages[dst->page_count++].storage = ptr;
 
 	return 0;
 }
@@ -539,7 +539,7 @@ static void print_error_obj(struct drm_i915_error_state_buf *m,
 		len = ascii85_encode_len(len);
 
 		for (i = 0; i < len; i++) {
-			if (ascii85_encode(obj->pages[page][i], out))
+			if (ascii85_encode(obj->pages[page].storage[i], out))
 				err_puts(m, out);
 			else
 				err_puts(m, "z");
@@ -827,7 +827,7 @@ static void i915_error_object_free(struct drm_i915_error_object *obj)
 		return;
 
 	for (page = 0; page < obj->page_count; page++)
-		free_page((unsigned long)obj->pages[page]);
+		free_page((unsigned long)obj->pages[page].storage);
 
 	kfree(obj);
 }
@@ -901,7 +901,7 @@ void __i915_gpu_state_free(struct kref *error_ref)
 
 	num_pages = min_t(u64, vma->size, vma->obj->base.size) >> PAGE_SHIFT;
 	num_pages = DIV_ROUND_UP(10 * num_pages, 8); /* worstcase zlib growth */
-	dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *),
+	dst = kmalloc(sizeof(*dst) + num_pages * sizeof(*dst->pages),
 		      GFP_ATOMIC | __GFP_NOWARN);
 	if (!dst)
 		return NULL;
@@ -924,6 +924,14 @@ void __i915_gpu_state_free(struct kref *error_ref)
 		ggtt->base.insert_page(&ggtt->base, dma, slot,
 				       I915_CACHE_NONE, 0);
 
+		if (INTEL_GEN(i915) >= 8) {
+			dst->pages[dst->page_count].paddr = dma;
+			i915_error_page_walk(vma->vm, dst->gtt_offset +
+					     dst->page_count * PAGE_SIZE,
+					     &dst->pages[dst->page_count].pte,
+					     &dst->pages[dst->page_count].pte_paddr);
+		}
+
 		s = io_mapping_map_atomic_wc(&ggtt->mappable, slot);
 		ret = compress_page(&compress, (void  __force *)s, dst);
 		io_mapping_unmap_atomic(s);
@@ -935,7 +943,7 @@ void __i915_gpu_state_free(struct kref *error_ref)
 
 unwind:
 	while (dst->page_count--)
-		free_page((unsigned long)dst->pages[dst->page_count]);
+		free_page((unsigned long)dst->pages[dst->page_count].storage);
 	kfree(dst);
 	dst = NULL;
 
@@ -1104,7 +1112,7 @@ static void gen8_record_semaphore_state(struct i915_gpu_state *error,
 
 		signal_offset =
 			(GEN8_SIGNAL_OFFSET(engine, id) & (PAGE_SIZE - 1)) / 4;
-		tmp = error->semaphore->pages[0];
+		tmp = error->semaphore->pages[0].storage;
 		idx = gen8_engine_sync_index(engine, to);
 
 		ee->semaphore_mboxes[idx] = tmp[signal_offset];
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

Re: [RFC PATCH 09/12] drm/i915: Store PTE information together with the error object pages

Quoting Oscar Mateo (2017-10-27 19:01:12)

Quoted 3 lines

With every page of physical data we store: its physical address, the PTE that points to it and the physical address of the PTE itself. We will be using all this information later.

But then you've stuck it in the error_object.pages which doesn't relate at all to the vma. Separate out the capture of the object contents, with capturing of the phys/dma addresses.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#14 lore raw

RFC PATCH 10/12 drm/i915: Always add BOs to capture list if AubCrash is enabled

In reply to Oscar Mateo

If we want the AUB file to be complete (and, therefore, more useful) we need to capture all BOs in use, we cannot leave that to the UMD as before.

---
 drivers/gpu/drm/i915/i915_aubcrash.h       | 12 ++++++++++++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  4 +++-
 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_aubcrash.h +12 -0
index 2eed388..b42307e 100644
@@ -37,6 +37,12 @@ void i915_error_page_walk(struct i915_address_space *vm,
 int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
                             const struct i915_gpu_state *error);
 
+static inline bool i915_error_state_should_capture(struct i915_vma *vma,
+						   struct i915_vma *batch)
+{
+	return ((INTEL_GEN(vma->vm->i915) >= 8) && (vma != batch));
+}
+
 #else
 
 static inline void i915_error_record_ppgtt(struct i915_gpu_state *error,
@@ -62,6 +68,12 @@ static inline int i915_error_state_to_aub(struct drm_i915_error_state_buf *m,
 	return 0;
 }
 
+static inline bool i915_error_state_should_capture(struct i915_vma *vma,
+						   struct i915_vma *batch)
+{
+	return false;
+}
+
 #endif
 
 #endif
drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 -1
index 3d71907..47559a4 100644
@@ -38,6 +38,7 @@
 #include "i915_drv.h"
 #include "i915_gem_clflush.h"
 #include "i915_trace.h"
+#include "i915_aubcrash.h"
 #include "intel_drv.h"
 #include "intel_frontbuffer.h"
 
@@ -1758,7 +1759,8 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb)
 		struct i915_vma *vma = eb->vma[i];
 		struct drm_i915_gem_object *obj = vma->obj;
 
-		if (flags & EXEC_OBJECT_CAPTURE) {
+		if ((flags & EXEC_OBJECT_CAPTURE) ||
+		    i915_error_state_should_capture(vma, eb->batch)) {
 			struct i915_gem_capture_list *capture;
 
 			capture = kmalloc(sizeof(*capture), GFP_KERNEL);
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#15 lore raw

Re: [RFC PATCH 10/12] drm/i915: Always add BOs to capture list if AubCrash is enabled

Quoting Oscar Mateo (2017-10-27 19:01:13)

Quoted 3 lines

If we want the AUB file to be complete (and, therefore, more useful) we need to capture all BOs in use, we cannot leave that to the UMD as before.

There's a very good reason why we don't try to capture the entirety of mem from within the error capture. So no. There's no way we are selling that as absolutely necessary use of GFP_ATOMIC and stop_machine. -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw

RFC PATCH 11/12 drm/i915: Add an AUB file format writer

In reply to Oscar Mateo

This is where the magic happens. For the moment, this will be used by AubCrash to output a correctly-formatted AUB file of GPU error information.

In the future, it could be used by other modules to generate all kinds of AUB files. D.g. a running AUB capture of everything a given userspace application ends up sending to the hardware (like i-g-t's intel_aubdump tool, but at the kernel level).

---
 drivers/gpu/drm/i915/i915_aubmemtrace.c        | 665 +++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_aubmemtrace.h        |  76 +++
 drivers/gpu/drm/i915/i915_aubmemtrace_format.h | 359 +++++++++++++
 3 files changed, 1100 insertions(+)
 create mode 100644 drivers/gpu/drm/i915/i915_aubmemtrace.c
 create mode 100644 drivers/gpu/drm/i915/i915_aubmemtrace.h
 create mode 100644 drivers/gpu/drm/i915/i915_aubmemtrace_format.h
drivers/gpu/drm/i915/i915_aubmemtrace.c new file +665 -0
new file mode 100644
index 0000000..61b1392
@@ -0,0 +1,665 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Author:
+ *    Oscar Mateo <[email protected]>
+ *
+ */
+
+#include "intel_drv.h"
+#include "i915_aubmemtrace.h"
+#include "i915_aubmemtrace_format.h"
+
+/**
+ * DOC: AUB Memtrace
+ *
+ * The "AUB" memtrace file format provides a way to log GPU workloads in the
+ * same (or a very similar) form as they would be sent to the Intel Graphics
+ * Hardware. These logs are then provided to the user, who can use them for
+ * multiple purposes. For example: to easily browse the workload in order to
+ * find HW programming errors or to replay the workload using a GPU simulator or
+ * emulator.
+ *
+ * Technically, the format is the same used by intel_aubdump (a userspace tool
+ * that you can find in intel-gpu-tools) but by writing AUB files from the KMD
+ * we can log information that a userspace tool by itself cannot. E.g.: real GPU
+ * virtual addresses, pagetables, GPU contexts, workaround batchbuffers, etc...
+ *
+ * Trivia:
+ * In case the reader was wondering, AUB is a shorthand for "Auburn", the
+ * code name of the Intel740™ Graphics Accelerator (also known as the i740).
+ * We maintain the name of the file format for historical reasons.
+ *
+ */
+
+#define AUB_TOOL_VERSION_MAJOR 0
+#define AUB_TOOL_VERSION_MINOR 1
+
+#define AUB_WRITE(data, len) do { \
+	aub->write(aub->priv, data, len); \
+} while (0)
+
+#define PADDING(x) ((4 - ((x) & 3)) & 3)
+
+static inline void aub_write_padding(struct intel_aub *aub, u32 bytes)
+{
+	u32 zero = 0;
+
+	if (GEM_WARN_ON(bytes > 3))
+		return;
+
+	AUB_WRITE(&zero, bytes);
+}
+
+static inline void aub_header_fill(struct aub_cmd_hdr *header, u32 type,
+				   u32 opcode, u32 sub_opcode,
+				   u32 dword_count)
+{
+	header->type = type;
+	header->opcode = opcode;
+	header->sub_opcode = sub_opcode;
+	header->dword_count = dword_count;
+}
+
+struct aub_chip_revision {
+	uint rev_id;
+	uint stepping;
+	uint metal;
+};
+
+static const struct aub_chip_revision bdw_revs[] = {
+	{ 0, STEP_A, 0 },
+};
+
+static const struct aub_chip_revision chv_revs[] = {
+	{ 0, STEP_A, 0 },
+};
+
+static const struct aub_chip_revision skl_revs[] = {
+	{ SKL_REVID_A0, STEP_A, 0 },
+	{ SKL_REVID_B0, STEP_B, 0 },
+	{ SKL_REVID_C0, STEP_C, 0 },
+	{ SKL_REVID_D0, STEP_D, 0 },
+	{ SKL_REVID_E0, STEP_E, 0 },
+	{ SKL_REVID_F0, STEP_E, 0 },
+	{ SKL_REVID_G0, STEP_G, 0 },
+	{ SKL_REVID_H0, STEP_H, 0 },
+};
+
+static const struct aub_chip_revision bxt_revs[] = {
+	{ BXT_REVID_A0,     STEP_A, 0 },
+	{ BXT_REVID_A1,     STEP_A, 1 },
+	{ BXT_REVID_B0,     STEP_B, 0 },
+	{ BXT_REVID_B_LAST, STEP_B, 1 },
+	{ BXT_REVID_C0,     STEP_C, 0 },
+};
+
+static const struct aub_chip_revision kbl_revs[] = {
+	{ KBL_REVID_A0, STEP_A, 0 },
+	{ KBL_REVID_B0, STEP_B, 0 },
+	{ KBL_REVID_C0, STEP_C, 0 },
+	{ KBL_REVID_D0, STEP_D, 0 },
+	{ KBL_REVID_E0, STEP_E, 0 },
+};
+
+static const struct aub_chip_revision glk_revs[] = {
+	{ GLK_REVID_A0, STEP_A, 0 },
+	{ GLK_REVID_A1, STEP_A, 1 },
+};
+
+static const struct aub_chip_revision cnl_revs[] = {
+	{ CNL_REVID_A0, STEP_A, 0 },
+	{ CNL_REVID_B0, STEP_B, 0 },
+	{ CNL_REVID_C0, STEP_C, 0 },
+};
+
+struct aub_platforms_table {
+	uint platform_id;
+	uint device;
+	const struct aub_chip_revision *table;
+	uint count;
+};
+
+static const struct aub_platforms_table platforms[] = {
+	{ INTEL_BROADWELL,  DEV_BDW, bdw_revs, ARRAY_SIZE(bdw_revs) },
+	{ INTEL_CHERRYVIEW, DEV_CHV, chv_revs, ARRAY_SIZE(chv_revs) },
+	{ INTEL_SKYLAKE,    DEV_SKL, skl_revs, ARRAY_SIZE(skl_revs) },
+	{ INTEL_BROXTON,    DEV_BXT, bxt_revs, ARRAY_SIZE(bxt_revs) },
+	{ INTEL_KABYLAKE,   DEV_KBL, kbl_revs, ARRAY_SIZE(kbl_revs) },
+	{ INTEL_GEMINILAKE, DEV_GLK, glk_revs, ARRAY_SIZE(glk_revs) },
+	{ INTEL_CANNONLAKE, DEV_CNL, cnl_revs, ARRAY_SIZE(cnl_revs) },
+};
+
+static int aub_write_version_packet(struct intel_aub *aub,
+				    enum intel_platform platform,
+				    u8 revision, const char *message)
+{
+	u32 length, padding;
+	struct cmd_memtrace_version cmd;
+	char *buf = (char *)aub->scratch;
+	bool rev_warning = false;
+	int i, j;
+
+	memset(&cmd, 0, sizeof(cmd));
+	aub_header_fill(&cmd.header, CMD_TYPE_AUB, CMD_OPC_MEMTRACE,
+			CMD_SUBOPC_MEMTRACE_VERSION, sizeof(cmd) / 4 - 2);
+
+	cmd.memtrace_file_version = AUB_FILE_FORMAT_VERSION;
+	cmd.swizzling = SWIZZLING_DISABLED;
+	cmd.recording_method = METHOD_PHY;
+	cmd.pch = PCH_DEFAULT;
+	cmd.capture_tool = CAPTURE_TOOL_KMD;
+
+	for (i = 0; i < ARRAY_SIZE(platforms); i++) {
+		if (platform == platforms[i].platform_id) {
+			const struct aub_chip_revision *table =
+				platforms[i].table;
+			uint count = platforms[i].count;
+			cmd.device = platforms[i].device;
+
+			for (j = 0; j < count; j++) {
+				if (revision == table[j].rev_id) {
+					cmd.stepping = table[j].stepping;
+					cmd.metal = table[j].metal;
+				}
+			}
+
+			if (j == count) {
+				rev_warning = true;
+				cmd.stepping = table[count - 1].stepping;
+				cmd.metal = table[count - 1].metal;
+			}
+
+			break;
+		}
+
+		if (i == ARRAY_SIZE(platforms)) {
+			DRM_ERROR("Unsupported platform 0x%x\n", platform);
+			return -ENODEV;
+		}
+	}
+
+	cmd.tool_primary_version = AUB_TOOL_VERSION_MAJOR;
+	cmd.tool_secondary_version = AUB_TOOL_VERSION_MINOR;
+
+	snprintf(buf, AUB_COMMENT_MAX_LENGTH, message);
+	length = strlen(buf);
+	padding = PADDING(length);
+	cmd.header.dword_count += (length + padding) / 4;
+
+	AUB_WRITE(&cmd, sizeof(cmd) - 4);
+	AUB_WRITE(buf, length);
+	aub_write_padding(aub, padding);
+
+	if (rev_warning)
+		i915_aub_comment(aub,
+				 "Unknown revid 0x%x. Using last known step/metal",
+				 revision);
+
+	return 0;
+}
+
+static void aub_write_comment_packet(struct intel_aub *aub, const char *comment)
+{
+	struct cmd_memtrace_comment cmd;
+	const char preface[] = "AUB: ";
+	uint preface_len = strlen(preface);
+	uint comment_len = strlen(comment) + 1;
+	uint padding = PADDING(comment_len + preface_len);
+
+	memset(&cmd, 0, sizeof(cmd));
+	aub_header_fill(&cmd.header, CMD_TYPE_AUB, CMD_OPC_MEMTRACE,
+			CMD_SUBOPC_MEMTRACE_COMMENT, sizeof(cmd) / 4 - 2);
+	cmd.header.dword_count += (preface_len + comment_len + padding) / 4;
+
+	AUB_WRITE(&cmd, sizeof(cmd) - 4);
+	AUB_WRITE(preface, preface_len);
+	AUB_WRITE(comment, comment_len);
+	aub_write_padding(aub, padding);
+}
+
+static int aub_write_mem_packet(struct intel_aub *aub,
+				enum tiling_values tiling,
+				enum data_type_values type,
+				enum address_space_values space,
+				u64 address,
+				const void *data,
+				u32 bytes)
+{
+	struct cmd_memtrace_memwrite cmd;
+	uint max_bytes = 4 * (0xffff - (sizeof(cmd) / 4 - 2));
+	uint padding = PADDING(bytes);
+	uint num_dwords = (bytes + padding) / 4;
+
+	if (bytes > max_bytes)
+		return -E2BIG;
+
+	memset(&cmd, 0, sizeof(cmd));
+	aub_header_fill(&cmd.header, CMD_TYPE_AUB, CMD_OPC_MEMTRACE,
+			CMD_SUBOPC_MEMTRACE_MEMORY_WRITE, sizeof(cmd) / 4 - 2);
+	cmd.header.dword_count += num_dwords;
+
+	cmd.address = address;
+	cmd.tiling = tiling;
+	cmd.data_type_hint = type;
+	cmd.address_space = space;
+	cmd.data_size = bytes;
+
+	AUB_WRITE(&cmd, sizeof(cmd) - 4);
+	AUB_WRITE(data, bytes);
+	aub_write_padding(aub, padding);
+
+	return bytes;
+}
+
+static int aub_write_mem_discon_packet(struct intel_aub *aub,
+				       enum tiling_values tiling,
+				       enum data_type_values type,
+				       enum address_space_values space,
+				       const struct memwrite_element *elements,
+				       const void **data,
+				       uint count)
+{
+	struct aub_cmd_hdr header;
+	struct aub_cmd_memwrite_discon_opts cmd_opts;
+	uint cmd_size = sizeof(struct cmd_memtrace_memwrite_discon);
+	uint max_bytes = 4 * (0xffff - (cmd_size / 4 - 2));
+	uint total_bytes = 0;
+	uint padding;
+	uint num_dwords;
+	int i;
+
+	if (count > DISCONTIGUOUS_WRITE_MAX_ELEMENTS)
+		return -E2BIG;
+
+	for (i = 0; i < count; i++)
+		total_bytes += elements[i].data_size;
+
+	padding = PADDING(total_bytes);
+	num_dwords = (total_bytes + padding) / 4;
+
+	if (total_bytes > max_bytes)
+		return -E2BIG;
+
+	memset(&header, 0, sizeof(header));
+	aub_header_fill(&header, CMD_TYPE_AUB, CMD_OPC_MEMTRACE,
+			CMD_SUBOPC_MEMTRACE_MEMORY_WRITE_DISCONTIGUOUS,
+			cmd_size / 4 - 2);
+	header.dword_count += num_dwords;
+
+	memset(&cmd_opts, 0, sizeof(cmd_opts));
+	cmd_opts.tiling = tiling;
+	cmd_opts.data_type_hint = type;
+	cmd_opts.address_space = space;
+	cmd_opts.number_of_elements = count;
+
+	AUB_WRITE(&header, sizeof(header));
+	AUB_WRITE(&cmd_opts, sizeof(cmd_opts));
+
+	AUB_WRITE(elements, count * sizeof(*elements));
+	for (i = count; i < DISCONTIGUOUS_WRITE_MAX_ELEMENTS; i++) {
+		struct memwrite_element zero = {0, 0};
+		AUB_WRITE(&zero, sizeof(zero));
+	}
+
+	for (i = 0; i < count; i++)
+		AUB_WRITE(data[i], elements[i].data_size);
+
+	aub_write_padding(aub, padding);
+
+	return total_bytes;
+}
+
+static void aub_write_register_packet(struct intel_aub *aub, i915_reg_t reg,
+				      u32 value)
+{
+	struct cmd_memtrace_register_write cmd;
+
+	memset(&cmd, 0, sizeof(cmd));
+	aub_header_fill(&cmd.header, CMD_TYPE_AUB, CMD_OPC_MEMTRACE,
+			CMD_SUBOPC_MEMTRACE_REGISTER_WRITE, sizeof(cmd) / 4 - 1);
+	cmd.message_source = SOURCE_IA;
+	cmd.register_size = SIZE_DWORD;
+	cmd.register_space = SPACE_MMIO;
+	cmd.write_mask_low = 0xffffffff;
+	cmd.write_mask_high = 0x0;
+
+	cmd.register_offset = i915_mmio_reg_offset(reg);
+	cmd.data[0] = value;
+
+	AUB_WRITE(&cmd, sizeof(cmd));
+}
+
+static void aub_write_pci_register_packet(struct intel_aub *aub, u16 bus,
+					  u8 device, u8 function,
+					  u32 offset, u32 value)
+{
+	struct cmd_memtrace_register_write cmd;
+
+	memset(&cmd, 0, sizeof(cmd));
+	aub_header_fill(&cmd.header, CMD_TYPE_AUB, CMD_OPC_MEMTRACE,
+			CMD_SUBOPC_MEMTRACE_REGISTER_WRITE, sizeof(cmd) / 4 - 1);
+	cmd.message_source = SOURCE_IA;
+	cmd.register_size = SIZE_DWORD;
+	cmd.register_space = SPACE_PCI;
+	cmd.write_mask_low = 0xffffffff;
+	cmd.write_mask_high = 0x0;
+
+	cmd.bus = bus;
+	cmd.device = device;
+	cmd.function = function;
+	cmd.offset = offset;
+	cmd.data[0] = value;
+
+	AUB_WRITE(&cmd, sizeof(cmd));
+}
+
+static void aub_write_regpoll_packet(struct intel_aub *aub, i915_reg_t reg,
+				     u32 mask, u32 value)
+{
+	struct cmd_memtrace_register_poll cmd;
+
+	memset(&cmd, 0, sizeof(cmd));
+	aub_header_fill(&cmd.header, CMD_TYPE_AUB, CMD_OPC_MEMTRACE,
+			CMD_SUBOPC_MEMTRACE_REGISTER_POLL, sizeof(cmd) / 4 - 1);
+	cmd.abort_on_timeout = 1;
+	cmd.poll_not_equal = 0;
+	cmd.operation_type = OPERATION_TYPE_NORMAL;
+	cmd.register_size = SIZE_DWORD;
+	cmd.register_space = SPACE_MMIO;
+
+	cmd.poll_mask_low = mask;
+	cmd.register_offset = i915_mmio_reg_offset(reg);
+	cmd.data[0] = value;
+
+	AUB_WRITE(&cmd, sizeof(cmd));
+}
+
+static inline phys_addr_t adjust_gsm_paddr(struct intel_aub *aub,
+					   bool global_gtt,
+					   phys_addr_t pte_paddr)
+{
+	if (global_gtt) {
+		/*
+		 * We already told the other end about the base
+		 * of the GGTT stolen memory, so treat it here
+		 * as if it was 0x0
+		 */
+		return (pte_paddr - aub->gsm_paddr);
+	} else
+		return pte_paddr;
+}
+
+static int aub_write_discon_pages(struct intel_aub *aub,
+				  bool global_gtt,
+				  enum tiling_values tiling,
+				  enum data_type_values type,
+				  enum address_space_values space,
+				  const struct drm_i915_error_page *pages,
+				  uint count)
+{
+	enum address_space_values pte_space;
+	uint count_left = count;
+	const struct drm_i915_error_page *pages_left = pages;
+	struct memwrite_element *elements =
+		(struct memwrite_element *)aub->scratch;
+	const void **data =
+		(const void **)(elements + DISCONTIGUOUS_WRITE_MAX_ELEMENTS);
+	int ret;
+	int i;
+
+	BUILD_BUG_ON(sizeof(aub->scratch) <
+		     DISCONTIGUOUS_WRITE_MAX_ELEMENTS * sizeof(*elements) +
+		     DISCONTIGUOUS_WRITE_MAX_ELEMENTS * sizeof(*data));
+
+	pte_space = global_gtt ? ADDRESS_SPACE_GTT_ENTRY :
+				 ADDRESS_SPACE_PPGTT_ENTRY;
+
+	while (count_left) {
+		uint c = min(count_left, (uint)DISCONTIGUOUS_WRITE_MAX_ELEMENTS);
+
+		if (c == 1) {
+			const gen8_pte_t *pte = &pages_left[0].pte;
+			phys_addr_t pte_paddr =
+				adjust_gsm_paddr(aub, global_gtt,
+						 pages_left[0].pte_paddr);
+
+			ret = aub_write_mem_packet(aub, TILING_NONE, TYPE_NOTYPE,
+						   pte_space, pte_paddr, pte,
+						   sizeof(u64));
+		} else {
+			for (i = 0; i < c; i++) {
+				elements[i].address =
+					adjust_gsm_paddr(aub, global_gtt,
+							 pages_left[i].pte_paddr);
+				elements[i].data_size = sizeof(u64);
+				data[i] = &pages_left[i].pte;
+			}
+
+			ret = aub_write_mem_discon_packet(aub, TILING_NONE,
+							  TYPE_NOTYPE, pte_space,
+							  elements,
+							  data, c);
+		}
+		if (ret < 0)
+			return ret;
+
+		if (c == 1) {
+			ret = aub_write_mem_packet(aub, tiling, type, space,
+						   pages_left[0].paddr,
+						   pages_left[0].storage,
+						   PAGE_SIZE);
+		} else {
+			for (i = 0; i < c; i++) {
+				elements[i].address = pages_left[i].paddr;
+				elements[i].data_size = PAGE_SIZE;
+				data[i] = pages_left[i].storage;
+			}
+
+			ret = aub_write_mem_discon_packet(aub, tiling, type,
+							  space, elements,
+							  data, c);
+		}
+		if (ret < 0)
+			return ret;
+
+		count_left -= c;
+		pages_left += c;
+	}
+
+	return 0;
+}
+
+struct intel_aub *i915_aub_start(struct drm_i915_private *i915,
+				 write_aub_fn write_function,
+				 void *private_data,
+				 const char *message,
+				 bool verbose)
+{
+	struct i915_ggtt *ggtt = &i915->ggtt;
+	struct intel_aub *aub;
+	int ret;
+
+	aub = kmalloc(sizeof(*aub), GFP_KERNEL);
+	if (!aub)
+		return ERR_PTR(-ENOMEM);
+
+	aub->write = write_function;
+	aub->priv = private_data;
+	aub->platform = i915->info.platform;
+	aub->revision = INTEL_REVID(i915);
+	aub->gsm_paddr = ggtt->gsm_paddr;
+	aub->verbose = verbose;
+
+	ret = aub_write_version_packet(aub, aub->platform,
+				       aub->revision, message);
+	if (ret < 0) {
+		kfree(aub);
+		return ERR_PTR(ret);
+	}
+
+	/* Tell the other end about the physical GGTT location */
+	GEM_BUG_ON(upper_32_bits(aub->gsm_paddr));
+	aub_write_pci_register_packet(aub, 0, 0, 0, 0xb4,
+				      lower_32_bits(aub->gsm_paddr));
+
+	return aub;
+}
+
+void i915_aub_comment(struct intel_aub *aub, const char *format, ...)
+{
+	va_list args;
+	char *buf = (char *)aub->scratch;
+	BUILD_BUG_ON(sizeof(aub->scratch) < AUB_COMMENT_MAX_LENGTH);
+
+	if (!aub->verbose)
+		return;
+
+	va_start(args, format);
+	vsnprintf(buf, AUB_COMMENT_MAX_LENGTH, format, args);
+	va_end(args);
+
+	aub_write_comment_packet(aub, buf);
+}
+
+void i915_aub_register(struct intel_aub *aub, i915_reg_t reg, u32 value)
+{
+	aub_write_register_packet(aub, reg, value);
+}
+
+void i915_aub_gtt(struct intel_aub *aub, enum pagemap_level lvl,
+		  phys_addr_t paddr, const u64 *entries, uint count)
+{
+	enum address_space_values space;
+	uint max_count = PAGE_SIZE / sizeof(*entries);
+	uint c = min(count, max_count);
+
+	switch (lvl) {
+	default:
+		MISSING_CASE(lvl);
+	case PPGTT_LEVEL4:
+		space = ADDRESS_SPACE_PPGTT_PML4_ENTRY;
+		break;
+	case PPGTT_LEVEL3:
+		space = ADDRESS_SPACE_PPGTT_PDP_ENTRY;
+		break;
+	case PPGTT_LEVEL2:
+		space = ADDRESS_SPACE_PPGTT_PD_ENTRY;
+		break;
+	case PPGTT_LEVEL1:
+		space = ADDRESS_SPACE_PPGTT_ENTRY;
+		break;
+	case GGTT_LEVEL1:
+		space = ADDRESS_SPACE_GTT_ENTRY;
+		paddr = adjust_gsm_paddr(aub, true, paddr);
+		break;
+	}
+
+	aub_write_mem_packet(aub, TILING_NONE, TYPE_NOTYPE, space, paddr,
+			     entries, c * sizeof(*entries));
+}
+
+void i915_aub_context(struct intel_aub *aub, u8 class,
+		      const struct drm_i915_error_page *pages, uint count)
+{
+	enum data_type_values type;
+
+	switch (class) {
+	default:
+		MISSING_CASE(class);
+	case OTHER_CLASS:
+	case RENDER_CLASS:
+		type = TYPE_LOGICAL_RING_CONTEXT_RCS;
+		break;
+	case VIDEO_DECODE_CLASS:
+		type = TYPE_LOGICAL_RING_CONTEXT_VCS;
+		break;
+	case VIDEO_ENHANCEMENT_CLASS:
+		type = TYPE_LOGICAL_RING_CONTEXT_VECS;
+		break;
+	case COPY_ENGINE_CLASS:
+		type = TYPE_LOGICAL_RING_CONTEXT_BCS;
+		break;
+	}
+
+	aub_write_discon_pages(aub, true, TILING_NONE, type,
+			       ADDRESS_SPACE_PHYSICAL, pages, count);
+}
+
+void i915_aub_batchbuffer(struct intel_aub *aub, bool global_gtt,
+			  const struct drm_i915_error_page *pages, uint count)
+{
+	aub_write_discon_pages(aub, global_gtt, TILING_NONE, TYPE_BATCH_BUFFER,
+			       ADDRESS_SPACE_PHYSICAL, pages, count);
+}
+
+void i915_aub_buffer(struct intel_aub *aub, bool global_gtt, int tiling_mode,
+		     const struct drm_i915_error_page *pages, uint count)
+{
+	enum tiling_values tiling;
+
+	switch (tiling_mode) {
+	default:
+		MISSING_CASE(tiling_mode);
+	case I915_TILING_NONE:
+		tiling = TILING_NONE;
+		break;
+	case I915_TILING_X:
+		tiling = TILING_X;
+		break;
+	case I915_TILING_Y:
+		tiling = TILING_Y;
+		break;
+	}
+
+	aub_write_discon_pages(aub, global_gtt, tiling, TYPE_NOTYPE,
+			       ADDRESS_SPACE_PHYSICAL, pages, count);
+}
+
+void i915_aub_elsp_submit(struct intel_aub *aub, struct intel_engine_cs *engine,
+			  u64 desc)
+{
+	i915_reg_t elsp = RING_ELSP(engine);
+	i915_reg_t elsp_status = RING_EXECLIST_STATUS_LO(engine);
+	u32 value;
+
+	aub_write_register_packet(aub, elsp, 0x0);
+	aub_write_register_packet(aub, elsp, 0x0);
+	aub_write_register_packet(aub, elsp, upper_32_bits(desc));
+	aub_write_register_packet(aub, elsp, lower_32_bits(desc));
+
+	/*
+	 * Due to the nature of the AUB file (no timing information), we cannot
+	 * use it to model asynchronous things like Lite Restores or Preemption.
+	 * This is the reason we use this "fake" ELSP submission with just one
+	 * element at a time instead of just capturing the real submission. And
+	 * also the reason why here we force the other end to wait until the HW
+	 * becomes idle again.
+	 */
+	value = GEN8_CTX_STATUS_ACTIVE_IDLE << EL_STATUS_LAST_CTX_SWITCH_SHIFT;
+	aub_write_regpoll_packet(aub, elsp_status, value, value);
+}
+
+void i915_aub_stop(struct intel_aub *aub)
+{
+	kfree(aub);
+}
drivers/gpu/drm/i915/i915_aubmemtrace.h new file +76 -0

76 lines not on this page · raw message

drivers/gpu/drm/i915/i915_aubmemtrace_format.h new file +359 -0

359 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw

RFC PATCH 12/12 drm/i915: Actually write the AUB file

In reply to Oscar Mateo

Use all the information previously recorded in the GPU error state to write an AUB file.

TODO: output an already compressed file?

---
 drivers/gpu/drm/i915/Makefile        |   2 +-
 drivers/gpu/drm/i915/i915_aubcrash.c | 174 +++++++++++++++++++++++++++++++++++
 2 files changed, 175 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/Makefile +1 -1
index 04956c7..f958291 100644
@@ -124,7 +124,7 @@ i915-y += dvo_ch7017.o \
 
 # Post-mortem debug and GPU hang state capture
 i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
-i915-$(CONFIG_DRM_I915_AUB_CRASH_DUMP) += i915_aubcrash.o
+i915-$(CONFIG_DRM_I915_AUB_CRASH_DUMP) += i915_aubmemtrace.o i915_aubcrash.o
 i915-$(CONFIG_DRM_I915_SELFTEST) += \
 	selftests/i915_random.o \
 	selftests/i915_selftest.o
drivers/gpu/drm/i915/i915_aubcrash.c +174 -0

188 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw
In reply to Oscar Mateo

Quoting Oscar Mateo (2017-10-27 19:01:03)

Quoted 6 lines

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Serious question: why both? If the aub is useful for pm debugging, it should be either a replacement for sysfs/error or an addendum.

I expect tools to use the new format as well.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#19 lore raw
Quoted 7 lines · Chris Wilson

Quoting Oscar Mateo (2017-10-27 19:01:03)

Quoted 6 lines

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Quoted 5 lines

Serious question: why both? If the aub is useful for pm debugging, it should be either a replacement for sysfs/error or an addendum.

I expect tools to use the new format as well.
-Chris

Looks like the solution we were looking for :)
Thanks!
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#20 lore raw
In reply to Chris Wilson
Quoted 7 lines · Chris Wilson

Quoting Oscar Mateo (2017-10-27 19:01:03)

Quoted 6 lines

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Quoted 5 lines

Serious question: why both? If the aub is useful for pm debugging, it should be either a replacement for sysfs/error or an addendum.

I expect tools to use the new format as well.
-Chris

That's why I sent this as an RFC, to get suggestions :)

There are things an AUB file cannot replace (fences, seqnos, error registers, etc...). It could still be used as an addendum, where the things that go into the AUB do not go into sysfs/error anymore (maybe with a message to look for the rest in the AUB file?). Or even better: I could try to provide the remaining text inside the AUB as comments, so that only one file is required...

As for tools, I still need to test how compatible Mesas's Aubinator is at the moment. There a number of non-opensource tools as well, but I have to discover which ones are publicly available outside of Intel before I provide a list here.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#21 lore raw
Quoted 13 lines · Oscar Mateo
Quoted 10 lines · Chris Wilson

Quoting Oscar Mateo (2017-10-27 19:01:03)

Quoted 6 lines

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Serious question: why both? If the aub is useful for pm debugging, it should be either a replacement for sysfs/error or an addendum.

Quoted 8 lines
Quoted 2 lines

I expect tools to use the new format as well.
-Chris

That's why I sent this as an RFC, to get suggestions :)

There are things an AUB file cannot replace (fences, seqnos, error registers, etc...). It could still be used as an addendum, where the things that go into the AUB do not go into sysfs/error anymore (maybe with a message to look for the rest in the AUB file?). Or even better: I could try to provide the remaining text inside the AUB as comments, so that only one file is required...

As for tools, I still need to test how compatible Mesas's Aubinator is at the moment. There a number of non-opensource tools as well, but I have to discover which ones are publicly available outside of Intel before I provide a list here.

I don't think there is any problem having yet another tool for a new format as long as it brings some interesting bits. When aubinator_error_decode was introduced Chris actually brought up the idea of a new format to make parsing of the error state a bit easier.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#22 lore raw
In reply to Oscar Mateo

Quoting Oscar Mateo (2017-10-27 19:01:03)

Quoted 6 lines

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Since it is capture everything in progress, but only the kernel side of it, why put it in the kernel? Is this absolutely required for post-mortem debugging, or should we focus on capturing the death throes of userspace much better (an aubcapture flight-data-recorder, plus client annotations more akin to apitrace)?

Sell me with the bugzilla references.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#23 lore raw
Quoted 7 lines · Chris Wilson

Quoting Oscar Mateo (2017-10-27 19:01:03)

Quoted 6 lines

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Quoted 8 lines

Since it is capture everything in progress, but only the kernel side of it, why put it in the kernel? Is this absolutely required for post-mortem debugging, or should we focus on capturing the death throes of userspace much better (an aubcapture flight-data-recorder, plus client annotations more akin to apitrace)?

Sell me with the bugzilla references.
-Chris

An aubcapture flight-data-recorder is the next logical step. Like i-g-t's intel_aubdump tool, but at the kernel level, so that it includes everything: contexts, WA BBs, virtual GPU addresses, pagetables, etc... The trojan horse for that is "drm/i915: Add an AUB file format writer". Now you only have to add a couple of debugfs entries (one for start/stop the capture, one to retrieve the AUB file as it gets created via 'relay channel') and a number of hooks around i915 to capture everything that can be interesting.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#24 lore raw

Quoting Oscar Mateo (2017-10-27 19:45:39)

Quoted 19 lines · Chris Wilson
Quoted 7 lines

Quoting Oscar Mateo (2017-10-27 19:01:03)

Quoted 6 lines

AubCrash is a companion to i915_gpu_error. It gives us the possibility to dump an AUB file that describes the state of the system at the point of the crash (GTTs, contexts, BBs, BOs, etc...). Being an AUB file, it can be used by a number of already existing tools (graphical AUB file browsers, simulators, emulators, etc...) that facilitate debugging (an improvement over the current text-based crash dump).

Quoted 8 lines

Since it is capture everything in progress, but only the kernel side of it, why put it in the kernel? Is this absolutely required for post-mortem debugging, or should we focus on capturing the death throes of userspace much better (an aubcapture flight-data-recorder, plus client annotations more akin to apitrace)?

Sell me with the bugzilla references.
-Chris

Quoted 8 lines

An aubcapture flight-data-recorder is the next logical step. Like i-g-t's intel_aubdump tool, but at the kernel level, so that it includes
everything: contexts, WA BBs, virtual GPU addresses, pagetables, etc... The trojan horse for that is "drm/i915: Add an AUB file format writer". Now you only have to add a couple of debugfs entries (one for start/stop the capture, one to retrieve the AUB file as it gets created via 'relay channel') and a number of hooks around i915 to capture everything that can be interesting.

But we don't need to do that at the kernel level, as the ioctl interface is the defining uABI. The only thing we can't snoop are the real phys addresses but afaik for the replay aspect you don't need real, just consistent.

Don't do anything in the kernel that can be done in userspace, because we can never get it out again. We really do need compelling arguments as to why it is impossible to do what needs to be done from userspace. And however we put it, we can't just leak physical addressess or other lowlevel information that opens ourselves to abuse, or snooping of one client on another. At least not without a very good defense to hide behind when it is spotted. The argument has to be really compelling if you want us to maintain this for all platforms for the next decade+.

One suggestion is that we put all the dodgy stuff in an auxiliary module, not even just hiding behind a module option. Of course that makes the post-mortem aspect impossible.

(I'm not saying I have the answers, just that that its a high bar we have to pass.)
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#25 lore raw

✗ Fi.CI.BAT: failure for AubCrash

In reply to Oscar Mateo
== Series Details ==

== Series Details ==

Series: AubCrash
URL : https://patchwork.freedesktop.org/series/32774/
State : failure

== Summary ==

Series 32774v1 AubCrash
https://patchwork.freedesktop.org/api/1.0/series/32774/revisions/1/mbox/

Test gem_exec_reloc:

        Subgroup basic-cpu-active:
                pass       -> FAIL       (fi-gdg-551) fdo#102582 +5
Test kms_frontbuffer_tracking:
        Subgroup basic:
                fail       -> PASS       (fi-glk-dsi) fdo#103167
Test kms_psr_sink_crc:
        Subgroup psr_basic:
                pass       -> INCOMPLETE (fi-cnl-y)

fdo#102582 https://bugs.freedesktop.org/show_bug.cgi?id=102582
fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167

fi-bdw-5557u     total:289  pass:268  dwarn:0   dfail:0   fail:0   skip:21  time:441s
fi-bdw-gvtdvm    total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:447s
fi-blb-e6850     total:289  pass:223  dwarn:1   dfail:0   fail:0   skip:65  time:377s
fi-bsw-n3050     total:289  pass:243  dwarn:0   dfail:0   fail:0   skip:46  time:522s
fi-bwr-2160      total:289  pass:183  dwarn:0   dfail:0   fail:0   skip:106 time:265s
fi-bxt-dsi       total:289  pass:259  dwarn:0   dfail:0   fail:0   skip:30  time:500s
fi-bxt-j4205     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:489s
fi-byt-j1900     total:289  pass:253  dwarn:1   dfail:0   fail:0   skip:35  time:490s
fi-byt-n2820     total:289  pass:249  dwarn:1   dfail:0   fail:0   skip:39  time:479s
fi-cnl-y         total:248  pass:223  dwarn:0   dfail:0   fail:0   skip:24 
fi-elk-e7500     total:289  pass:229  dwarn:0   dfail:0   fail:0   skip:60  time:429s
fi-gdg-551       total:289  pass:172  dwarn:1   dfail:0   fail:7   skip:109 time:250s
fi-glk-1         total:289  pass:261  dwarn:0   dfail:0   fail:0   skip:28  time:578s
fi-glk-dsi       total:289  pass:259  dwarn:0   dfail:0   fail:0   skip:30  time:486s
fi-hsw-4770      total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:429s
fi-hsw-4770r     total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:426s
fi-ilk-650       total:289  pass:228  dwarn:0   dfail:0   fail:0   skip:61  time:420s
fi-ivb-3520m     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:494s
fi-ivb-3770      total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:456s
fi-kbl-7500u     total:289  pass:264  dwarn:1   dfail:0   fail:0   skip:24  time:490s
fi-kbl-7560u     total:289  pass:270  dwarn:0   dfail:0   fail:0   skip:19  time:574s
fi-kbl-7567u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:479s
fi-kbl-r         total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:585s
fi-pnv-d510      total:289  pass:222  dwarn:1   dfail:0   fail:0   skip:66  time:547s
fi-skl-6260u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:453s
fi-skl-6600u     total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:593s
fi-skl-6700hq    total:289  pass:263  dwarn:0   dfail:0   fail:0   skip:26  time:649s
fi-skl-6700k     total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:521s
fi-skl-6770hq    total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:500s
fi-skl-gvtdvm    total:289  pass:266  dwarn:0   dfail:0   fail:0   skip:23  time:453s
fi-snb-2520m     total:289  pass:250  dwarn:0   dfail:0   fail:0   skip:39  time:559s
fi-snb-2600      total:289  pass:249  dwarn:0   dfail:0   fail:0   skip:40  time:416s

4efa630855362c267af94785e50948bb60615bfe drm-tip: 2017y-10m-27d-15h-25m-04s UTC integration manifest 416c8c57c9bb drm/i915: Actually write the AUB file
1ea0352e77e3 drm/i915: Add an AUB file format writer
d8a58aff43a5 drm/i915: Always add BOs to capture list if AubCrash is enabled d4152742ee77 drm/i915: Store PTE information together with the error object pages 4459f7f0556e drm/i915: Capture the PPGTT pagetables on a GPU crash
124d5a4ca4b3 drm/i915: Skeleton for AubCrash
23e8583c734b drm/i915: Provide a way to write binary data to the error dump file 61e441a891a2 drm/i915: Capture the renderstate batchbuffer
3c7f9f42415a drm/i915: Capture some extra small details in the GPU error state ec56735df5fb drm/i915: Store the GGTT Stolen Memory base physical address da7f505480c4 drm/i915: Move the context switch status reason bits to the header 34a4870dbf5a drm/i915: New define for the number of PDPEs per PDP in a 4-level walk

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_6245/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx