i915_gpu_error.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  1. /*
  2. * Copyright (c) 2008 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. * Keith Packard <keithp@keithp.com>
  26. * Mika Kuoppala <mika.kuoppala@intel.com>
  27. *
  28. */
  29. #include <generated/utsrelease.h>
  30. #include <linux/stop_machine.h>
  31. #include <linux/zlib.h>
  32. #include <drm/drm_print.h>
  33. #include "i915_drv.h"
  34. static inline const struct intel_engine_cs *
  35. engine_lookup(const struct drm_i915_private *i915, unsigned int id)
  36. {
  37. if (id >= I915_NUM_ENGINES)
  38. return NULL;
  39. return i915->engine[id];
  40. }
  41. static inline const char *
  42. __engine_name(const struct intel_engine_cs *engine)
  43. {
  44. return engine ? engine->name : "";
  45. }
  46. static const char *
  47. engine_name(const struct drm_i915_private *i915, unsigned int id)
  48. {
  49. return __engine_name(engine_lookup(i915, id));
  50. }
  51. static const char *tiling_flag(int tiling)
  52. {
  53. switch (tiling) {
  54. default:
  55. case I915_TILING_NONE: return "";
  56. case I915_TILING_X: return " X";
  57. case I915_TILING_Y: return " Y";
  58. }
  59. }
  60. static const char *dirty_flag(int dirty)
  61. {
  62. return dirty ? " dirty" : "";
  63. }
  64. static const char *purgeable_flag(int purgeable)
  65. {
  66. return purgeable ? " purgeable" : "";
  67. }
  68. static bool __i915_error_ok(struct drm_i915_error_state_buf *e)
  69. {
  70. if (!e->err && WARN(e->bytes > (e->size - 1), "overflow")) {
  71. e->err = -ENOSPC;
  72. return false;
  73. }
  74. if (e->bytes == e->size - 1 || e->err)
  75. return false;
  76. return true;
  77. }
  78. static bool __i915_error_seek(struct drm_i915_error_state_buf *e,
  79. unsigned len)
  80. {
  81. if (e->pos + len <= e->start) {
  82. e->pos += len;
  83. return false;
  84. }
  85. /* First vsnprintf needs to fit in its entirety for memmove */
  86. if (len >= e->size) {
  87. e->err = -EIO;
  88. return false;
  89. }
  90. return true;
  91. }
  92. static void __i915_error_advance(struct drm_i915_error_state_buf *e,
  93. unsigned len)
  94. {
  95. /* If this is first printf in this window, adjust it so that
  96. * start position matches start of the buffer
  97. */
  98. if (e->pos < e->start) {
  99. const size_t off = e->start - e->pos;
  100. /* Should not happen but be paranoid */
  101. if (off > len || e->bytes) {
  102. e->err = -EIO;
  103. return;
  104. }
  105. memmove(e->buf, e->buf + off, len - off);
  106. e->bytes = len - off;
  107. e->pos = e->start;
  108. return;
  109. }
  110. e->bytes += len;
  111. e->pos += len;
  112. }
  113. __printf(2, 0)
  114. static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
  115. const char *f, va_list args)
  116. {
  117. unsigned len;
  118. if (!__i915_error_ok(e))
  119. return;
  120. /* Seek the first printf which is hits start position */
  121. if (e->pos < e->start) {
  122. va_list tmp;
  123. va_copy(tmp, args);
  124. len = vsnprintf(NULL, 0, f, tmp);
  125. va_end(tmp);
  126. if (!__i915_error_seek(e, len))
  127. return;
  128. }
  129. len = vsnprintf(e->buf + e->bytes, e->size - e->bytes, f, args);
  130. if (len >= e->size - e->bytes)
  131. len = e->size - e->bytes - 1;
  132. __i915_error_advance(e, len);
  133. }
  134. static void i915_error_puts(struct drm_i915_error_state_buf *e,
  135. const char *str)
  136. {
  137. unsigned len;
  138. if (!__i915_error_ok(e))
  139. return;
  140. len = strlen(str);
  141. /* Seek the first printf which is hits start position */
  142. if (e->pos < e->start) {
  143. if (!__i915_error_seek(e, len))
  144. return;
  145. }
  146. if (len >= e->size - e->bytes)
  147. len = e->size - e->bytes - 1;
  148. memcpy(e->buf + e->bytes, str, len);
  149. __i915_error_advance(e, len);
  150. }
  151. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  152. #define err_puts(e, s) i915_error_puts(e, s)
  153. static void __i915_printfn_error(struct drm_printer *p, struct va_format *vaf)
  154. {
  155. i915_error_vprintf(p->arg, vaf->fmt, *vaf->va);
  156. }
  157. static inline struct drm_printer
  158. i915_error_printer(struct drm_i915_error_state_buf *e)
  159. {
  160. struct drm_printer p = {
  161. .printfn = __i915_printfn_error,
  162. .arg = e,
  163. };
  164. return p;
  165. }
  166. #ifdef CONFIG_DRM_I915_COMPRESS_ERROR
  167. struct compress {
  168. struct z_stream_s zstream;
  169. void *tmp;
  170. };
  171. static bool compress_init(struct compress *c)
  172. {
  173. struct z_stream_s *zstream = memset(&c->zstream, 0, sizeof(c->zstream));
  174. zstream->workspace =
  175. kmalloc(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
  176. GFP_ATOMIC | __GFP_NOWARN);
  177. if (!zstream->workspace)
  178. return false;
  179. if (zlib_deflateInit(zstream, Z_DEFAULT_COMPRESSION) != Z_OK) {
  180. kfree(zstream->workspace);
  181. return false;
  182. }
  183. c->tmp = NULL;
  184. if (i915_has_memcpy_from_wc())
  185. c->tmp = (void *)__get_free_page(GFP_ATOMIC | __GFP_NOWARN);
  186. return true;
  187. }
  188. static int compress_page(struct compress *c,
  189. void *src,
  190. struct drm_i915_error_object *dst)
  191. {
  192. struct z_stream_s *zstream = &c->zstream;
  193. zstream->next_in = src;
  194. if (c->tmp && i915_memcpy_from_wc(c->tmp, src, PAGE_SIZE))
  195. zstream->next_in = c->tmp;
  196. zstream->avail_in = PAGE_SIZE;
  197. do {
  198. if (zstream->avail_out == 0) {
  199. unsigned long page;
  200. page = __get_free_page(GFP_ATOMIC | __GFP_NOWARN);
  201. if (!page)
  202. return -ENOMEM;
  203. dst->pages[dst->page_count++] = (void *)page;
  204. zstream->next_out = (void *)page;
  205. zstream->avail_out = PAGE_SIZE;
  206. }
  207. if (zlib_deflate(zstream, Z_SYNC_FLUSH) != Z_OK)
  208. return -EIO;
  209. } while (zstream->avail_in);
  210. /* Fallback to uncompressed if we increase size? */
  211. if (0 && zstream->total_out > zstream->total_in)
  212. return -E2BIG;
  213. return 0;
  214. }
  215. static void compress_fini(struct compress *c,
  216. struct drm_i915_error_object *dst)
  217. {
  218. struct z_stream_s *zstream = &c->zstream;
  219. if (dst) {
  220. zlib_deflate(zstream, Z_FINISH);
  221. dst->unused = zstream->avail_out;
  222. }
  223. zlib_deflateEnd(zstream);
  224. kfree(zstream->workspace);
  225. if (c->tmp)
  226. free_page((unsigned long)c->tmp);
  227. }
  228. static void err_compression_marker(struct drm_i915_error_state_buf *m)
  229. {
  230. err_puts(m, ":");
  231. }
  232. #else
  233. struct compress {
  234. };
  235. static bool compress_init(struct compress *c)
  236. {
  237. return true;
  238. }
  239. static int compress_page(struct compress *c,
  240. void *src,
  241. struct drm_i915_error_object *dst)
  242. {
  243. unsigned long page;
  244. void *ptr;
  245. page = __get_free_page(GFP_ATOMIC | __GFP_NOWARN);
  246. if (!page)
  247. return -ENOMEM;
  248. ptr = (void *)page;
  249. if (!i915_memcpy_from_wc(ptr, src, PAGE_SIZE))
  250. memcpy(ptr, src, PAGE_SIZE);
  251. dst->pages[dst->page_count++] = ptr;
  252. return 0;
  253. }
  254. static void compress_fini(struct compress *c,
  255. struct drm_i915_error_object *dst)
  256. {
  257. }
  258. static void err_compression_marker(struct drm_i915_error_state_buf *m)
  259. {
  260. err_puts(m, "~");
  261. }
  262. #endif
  263. static void print_error_buffers(struct drm_i915_error_state_buf *m,
  264. const char *name,
  265. struct drm_i915_error_buffer *err,
  266. int count)
  267. {
  268. int i;
  269. err_printf(m, "%s [%d]:\n", name, count);
  270. while (count--) {
  271. err_printf(m, " %08x_%08x %8u %02x %02x [ ",
  272. upper_32_bits(err->gtt_offset),
  273. lower_32_bits(err->gtt_offset),
  274. err->size,
  275. err->read_domains,
  276. err->write_domain);
  277. for (i = 0; i < I915_NUM_ENGINES; i++)
  278. err_printf(m, "%02x ", err->rseqno[i]);
  279. err_printf(m, "] %02x", err->wseqno);
  280. err_puts(m, tiling_flag(err->tiling));
  281. err_puts(m, dirty_flag(err->dirty));
  282. err_puts(m, purgeable_flag(err->purgeable));
  283. err_puts(m, err->userptr ? " userptr" : "");
  284. err_puts(m, err->engine != -1 ? " " : "");
  285. err_puts(m, engine_name(m->i915, err->engine));
  286. err_puts(m, i915_cache_level_str(m->i915, err->cache_level));
  287. if (err->name)
  288. err_printf(m, " (name: %d)", err->name);
  289. if (err->fence_reg != I915_FENCE_REG_NONE)
  290. err_printf(m, " (fence: %d)", err->fence_reg);
  291. err_puts(m, "\n");
  292. err++;
  293. }
  294. }
  295. static void error_print_instdone(struct drm_i915_error_state_buf *m,
  296. const struct drm_i915_error_engine *ee)
  297. {
  298. int slice;
  299. int subslice;
  300. err_printf(m, " INSTDONE: 0x%08x\n",
  301. ee->instdone.instdone);
  302. if (ee->engine_id != RCS || INTEL_GEN(m->i915) <= 3)
  303. return;
  304. err_printf(m, " SC_INSTDONE: 0x%08x\n",
  305. ee->instdone.slice_common);
  306. if (INTEL_GEN(m->i915) <= 6)
  307. return;
  308. for_each_instdone_slice_subslice(m->i915, slice, subslice)
  309. err_printf(m, " SAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
  310. slice, subslice,
  311. ee->instdone.sampler[slice][subslice]);
  312. for_each_instdone_slice_subslice(m->i915, slice, subslice)
  313. err_printf(m, " ROW_INSTDONE[%d][%d]: 0x%08x\n",
  314. slice, subslice,
  315. ee->instdone.row[slice][subslice]);
  316. }
  317. static const char *bannable(const struct drm_i915_error_context *ctx)
  318. {
  319. return ctx->bannable ? "" : " (unbannable)";
  320. }
  321. static void error_print_request(struct drm_i915_error_state_buf *m,
  322. const char *prefix,
  323. const struct drm_i915_error_request *erq)
  324. {
  325. if (!erq->seqno)
  326. return;
  327. err_printf(m, "%s pid %d, ban score %d, seqno %8x:%08x, prio %d, emitted %dms ago, head %08x, tail %08x\n",
  328. prefix, erq->pid, erq->ban_score,
  329. erq->context, erq->seqno, erq->priority,
  330. jiffies_to_msecs(jiffies - erq->jiffies),
  331. erq->head, erq->tail);
  332. }
  333. static void error_print_context(struct drm_i915_error_state_buf *m,
  334. const char *header,
  335. const struct drm_i915_error_context *ctx)
  336. {
  337. err_printf(m, "%s%s[%d] user_handle %d hw_id %d, prio %d, ban score %d%s guilty %d active %d\n",
  338. header, ctx->comm, ctx->pid, ctx->handle, ctx->hw_id,
  339. ctx->priority, ctx->ban_score, bannable(ctx),
  340. ctx->guilty, ctx->active);
  341. }
  342. static void error_print_engine(struct drm_i915_error_state_buf *m,
  343. const struct drm_i915_error_engine *ee)
  344. {
  345. int n;
  346. err_printf(m, "%s command stream:\n",
  347. engine_name(m->i915, ee->engine_id));
  348. err_printf(m, " IDLE?: %s\n", yesno(ee->idle));
  349. err_printf(m, " START: 0x%08x\n", ee->start);
  350. err_printf(m, " HEAD: 0x%08x [0x%08x]\n", ee->head, ee->rq_head);
  351. err_printf(m, " TAIL: 0x%08x [0x%08x, 0x%08x]\n",
  352. ee->tail, ee->rq_post, ee->rq_tail);
  353. err_printf(m, " CTL: 0x%08x\n", ee->ctl);
  354. err_printf(m, " MODE: 0x%08x\n", ee->mode);
  355. err_printf(m, " HWS: 0x%08x\n", ee->hws);
  356. err_printf(m, " ACTHD: 0x%08x %08x\n",
  357. (u32)(ee->acthd>>32), (u32)ee->acthd);
  358. err_printf(m, " IPEIR: 0x%08x\n", ee->ipeir);
  359. err_printf(m, " IPEHR: 0x%08x\n", ee->ipehr);
  360. error_print_instdone(m, ee);
  361. if (ee->batchbuffer) {
  362. u64 start = ee->batchbuffer->gtt_offset;
  363. u64 end = start + ee->batchbuffer->gtt_size;
  364. err_printf(m, " batch: [0x%08x_%08x, 0x%08x_%08x]\n",
  365. upper_32_bits(start), lower_32_bits(start),
  366. upper_32_bits(end), lower_32_bits(end));
  367. }
  368. if (INTEL_GEN(m->i915) >= 4) {
  369. err_printf(m, " BBADDR: 0x%08x_%08x\n",
  370. (u32)(ee->bbaddr>>32), (u32)ee->bbaddr);
  371. err_printf(m, " BB_STATE: 0x%08x\n", ee->bbstate);
  372. err_printf(m, " INSTPS: 0x%08x\n", ee->instps);
  373. }
  374. err_printf(m, " INSTPM: 0x%08x\n", ee->instpm);
  375. err_printf(m, " FADDR: 0x%08x %08x\n", upper_32_bits(ee->faddr),
  376. lower_32_bits(ee->faddr));
  377. if (INTEL_GEN(m->i915) >= 6) {
  378. err_printf(m, " RC PSMI: 0x%08x\n", ee->rc_psmi);
  379. err_printf(m, " FAULT_REG: 0x%08x\n", ee->fault_reg);
  380. err_printf(m, " SYNC_0: 0x%08x\n",
  381. ee->semaphore_mboxes[0]);
  382. err_printf(m, " SYNC_1: 0x%08x\n",
  383. ee->semaphore_mboxes[1]);
  384. if (HAS_VEBOX(m->i915))
  385. err_printf(m, " SYNC_2: 0x%08x\n",
  386. ee->semaphore_mboxes[2]);
  387. }
  388. if (USES_PPGTT(m->i915)) {
  389. err_printf(m, " GFX_MODE: 0x%08x\n", ee->vm_info.gfx_mode);
  390. if (INTEL_GEN(m->i915) >= 8) {
  391. int i;
  392. for (i = 0; i < 4; i++)
  393. err_printf(m, " PDP%d: 0x%016llx\n",
  394. i, ee->vm_info.pdp[i]);
  395. } else {
  396. err_printf(m, " PP_DIR_BASE: 0x%08x\n",
  397. ee->vm_info.pp_dir_base);
  398. }
  399. }
  400. err_printf(m, " seqno: 0x%08x\n", ee->seqno);
  401. err_printf(m, " last_seqno: 0x%08x\n", ee->last_seqno);
  402. err_printf(m, " waiting: %s\n", yesno(ee->waiting));
  403. err_printf(m, " ring->head: 0x%08x\n", ee->cpu_ring_head);
  404. err_printf(m, " ring->tail: 0x%08x\n", ee->cpu_ring_tail);
  405. err_printf(m, " hangcheck stall: %s\n", yesno(ee->hangcheck_stalled));
  406. err_printf(m, " hangcheck action: %s\n",
  407. hangcheck_action_to_str(ee->hangcheck_action));
  408. err_printf(m, " hangcheck action timestamp: %lu, %u ms ago\n",
  409. ee->hangcheck_timestamp,
  410. jiffies_to_msecs(jiffies - ee->hangcheck_timestamp));
  411. err_printf(m, " engine reset count: %u\n", ee->reset_count);
  412. for (n = 0; n < ee->num_ports; n++) {
  413. err_printf(m, " ELSP[%d]:", n);
  414. error_print_request(m, " ", &ee->execlist[n]);
  415. }
  416. error_print_context(m, " Active context: ", &ee->context);
  417. }
  418. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
  419. {
  420. va_list args;
  421. va_start(args, f);
  422. i915_error_vprintf(e, f, args);
  423. va_end(args);
  424. }
  425. static int
  426. ascii85_encode_len(int len)
  427. {
  428. return DIV_ROUND_UP(len, 4);
  429. }
  430. static bool
  431. ascii85_encode(u32 in, char *out)
  432. {
  433. int i;
  434. if (in == 0)
  435. return false;
  436. out[5] = '\0';
  437. for (i = 5; i--; ) {
  438. out[i] = '!' + in % 85;
  439. in /= 85;
  440. }
  441. return true;
  442. }
  443. static void print_error_obj(struct drm_i915_error_state_buf *m,
  444. struct intel_engine_cs *engine,
  445. const char *name,
  446. struct drm_i915_error_object *obj)
  447. {
  448. char out[6];
  449. int page;
  450. if (!obj)
  451. return;
  452. if (name) {
  453. err_printf(m, "%s --- %s = 0x%08x %08x\n",
  454. engine ? engine->name : "global", name,
  455. upper_32_bits(obj->gtt_offset),
  456. lower_32_bits(obj->gtt_offset));
  457. }
  458. err_compression_marker(m);
  459. for (page = 0; page < obj->page_count; page++) {
  460. int i, len;
  461. len = PAGE_SIZE;
  462. if (page == obj->page_count - 1)
  463. len -= obj->unused;
  464. len = ascii85_encode_len(len);
  465. for (i = 0; i < len; i++) {
  466. if (ascii85_encode(obj->pages[page][i], out))
  467. err_puts(m, out);
  468. else
  469. err_puts(m, "z");
  470. }
  471. }
  472. err_puts(m, "\n");
  473. }
  474. static void err_print_capabilities(struct drm_i915_error_state_buf *m,
  475. const struct intel_device_info *info,
  476. const struct intel_driver_caps *caps)
  477. {
  478. struct drm_printer p = i915_error_printer(m);
  479. intel_device_info_dump_flags(info, &p);
  480. intel_driver_caps_print(caps, &p);
  481. intel_device_info_dump_topology(&info->sseu, &p);
  482. }
  483. static void err_print_params(struct drm_i915_error_state_buf *m,
  484. const struct i915_params *params)
  485. {
  486. struct drm_printer p = i915_error_printer(m);
  487. i915_params_dump(params, &p);
  488. }
  489. static void err_print_pciid(struct drm_i915_error_state_buf *m,
  490. struct drm_i915_private *i915)
  491. {
  492. struct pci_dev *pdev = i915->drm.pdev;
  493. err_printf(m, "PCI ID: 0x%04x\n", pdev->device);
  494. err_printf(m, "PCI Revision: 0x%02x\n", pdev->revision);
  495. err_printf(m, "PCI Subsystem: %04x:%04x\n",
  496. pdev->subsystem_vendor,
  497. pdev->subsystem_device);
  498. }
  499. static void err_print_uc(struct drm_i915_error_state_buf *m,
  500. const struct i915_error_uc *error_uc)
  501. {
  502. struct drm_printer p = i915_error_printer(m);
  503. const struct i915_gpu_state *error =
  504. container_of(error_uc, typeof(*error), uc);
  505. if (!error->device_info.has_guc)
  506. return;
  507. intel_uc_fw_dump(&error_uc->guc_fw, &p);
  508. intel_uc_fw_dump(&error_uc->huc_fw, &p);
  509. print_error_obj(m, NULL, "GuC log buffer", error_uc->guc_log);
  510. }
  511. int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
  512. const struct i915_gpu_state *error)
  513. {
  514. struct drm_i915_private *dev_priv = m->i915;
  515. struct drm_i915_error_object *obj;
  516. struct timespec64 ts;
  517. int i, j;
  518. if (!error) {
  519. err_printf(m, "No error state collected\n");
  520. return 0;
  521. }
  522. if (*error->error_msg)
  523. err_printf(m, "%s\n", error->error_msg);
  524. err_printf(m, "Kernel: " UTS_RELEASE "\n");
  525. ts = ktime_to_timespec64(error->time);
  526. err_printf(m, "Time: %lld s %ld us\n",
  527. (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC);
  528. ts = ktime_to_timespec64(error->boottime);
  529. err_printf(m, "Boottime: %lld s %ld us\n",
  530. (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC);
  531. ts = ktime_to_timespec64(error->uptime);
  532. err_printf(m, "Uptime: %lld s %ld us\n",
  533. (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC);
  534. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  535. if (error->engine[i].hangcheck_stalled &&
  536. error->engine[i].context.pid) {
  537. err_printf(m, "Active process (on ring %s): %s [%d], score %d%s\n",
  538. engine_name(m->i915, i),
  539. error->engine[i].context.comm,
  540. error->engine[i].context.pid,
  541. error->engine[i].context.ban_score,
  542. bannable(&error->engine[i].context));
  543. }
  544. }
  545. err_printf(m, "Reset count: %u\n", error->reset_count);
  546. err_printf(m, "Suspend count: %u\n", error->suspend_count);
  547. err_printf(m, "Platform: %s\n", intel_platform_name(error->device_info.platform));
  548. err_print_pciid(m, error->i915);
  549. err_printf(m, "IOMMU enabled?: %d\n", error->iommu);
  550. if (HAS_CSR(dev_priv)) {
  551. struct intel_csr *csr = &dev_priv->csr;
  552. err_printf(m, "DMC loaded: %s\n",
  553. yesno(csr->dmc_payload != NULL));
  554. err_printf(m, "DMC fw version: %d.%d\n",
  555. CSR_VERSION_MAJOR(csr->version),
  556. CSR_VERSION_MINOR(csr->version));
  557. }
  558. err_printf(m, "GT awake: %s\n", yesno(error->awake));
  559. err_printf(m, "RPM wakelock: %s\n", yesno(error->wakelock));
  560. err_printf(m, "PM suspended: %s\n", yesno(error->suspended));
  561. err_printf(m, "EIR: 0x%08x\n", error->eir);
  562. err_printf(m, "IER: 0x%08x\n", error->ier);
  563. for (i = 0; i < error->ngtier; i++)
  564. err_printf(m, "GTIER[%d]: 0x%08x\n", i, error->gtier[i]);
  565. err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
  566. err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
  567. err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
  568. err_printf(m, "CCID: 0x%08x\n", error->ccid);
  569. err_printf(m, "Missed interrupts: 0x%08lx\n", dev_priv->gpu_error.missed_irq_rings);
  570. for (i = 0; i < error->nfence; i++)
  571. err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
  572. if (INTEL_GEN(dev_priv) >= 6) {
  573. err_printf(m, "ERROR: 0x%08x\n", error->error);
  574. if (INTEL_GEN(dev_priv) >= 8)
  575. err_printf(m, "FAULT_TLB_DATA: 0x%08x 0x%08x\n",
  576. error->fault_data1, error->fault_data0);
  577. err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
  578. }
  579. if (IS_GEN7(dev_priv))
  580. err_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
  581. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  582. if (error->engine[i].engine_id != -1)
  583. error_print_engine(m, &error->engine[i]);
  584. }
  585. for (i = 0; i < ARRAY_SIZE(error->active_vm); i++) {
  586. char buf[128];
  587. int len, first = 1;
  588. if (!error->active_vm[i])
  589. break;
  590. len = scnprintf(buf, sizeof(buf), "Active (");
  591. for (j = 0; j < ARRAY_SIZE(error->engine); j++) {
  592. if (error->engine[j].vm != error->active_vm[i])
  593. continue;
  594. len += scnprintf(buf + len, sizeof(buf), "%s%s",
  595. first ? "" : ", ",
  596. dev_priv->engine[j]->name);
  597. first = 0;
  598. }
  599. scnprintf(buf + len, sizeof(buf), ")");
  600. print_error_buffers(m, buf,
  601. error->active_bo[i],
  602. error->active_bo_count[i]);
  603. }
  604. print_error_buffers(m, "Pinned (global)",
  605. error->pinned_bo,
  606. error->pinned_bo_count);
  607. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  608. const struct drm_i915_error_engine *ee = &error->engine[i];
  609. obj = ee->batchbuffer;
  610. if (obj) {
  611. err_puts(m, dev_priv->engine[i]->name);
  612. if (ee->context.pid)
  613. err_printf(m, " (submitted by %s [%d], ctx %d [%d], score %d%s)",
  614. ee->context.comm,
  615. ee->context.pid,
  616. ee->context.handle,
  617. ee->context.hw_id,
  618. ee->context.ban_score,
  619. bannable(&ee->context));
  620. err_printf(m, " --- gtt_offset = 0x%08x %08x\n",
  621. upper_32_bits(obj->gtt_offset),
  622. lower_32_bits(obj->gtt_offset));
  623. print_error_obj(m, dev_priv->engine[i], NULL, obj);
  624. }
  625. for (j = 0; j < ee->user_bo_count; j++)
  626. print_error_obj(m, dev_priv->engine[i],
  627. "user", ee->user_bo[j]);
  628. if (ee->num_requests) {
  629. err_printf(m, "%s --- %d requests\n",
  630. dev_priv->engine[i]->name,
  631. ee->num_requests);
  632. for (j = 0; j < ee->num_requests; j++)
  633. error_print_request(m, " ", &ee->requests[j]);
  634. }
  635. if (IS_ERR(ee->waiters)) {
  636. err_printf(m, "%s --- ? waiters [unable to acquire spinlock]\n",
  637. dev_priv->engine[i]->name);
  638. } else if (ee->num_waiters) {
  639. err_printf(m, "%s --- %d waiters\n",
  640. dev_priv->engine[i]->name,
  641. ee->num_waiters);
  642. for (j = 0; j < ee->num_waiters; j++) {
  643. err_printf(m, " seqno 0x%08x for %s [%d]\n",
  644. ee->waiters[j].seqno,
  645. ee->waiters[j].comm,
  646. ee->waiters[j].pid);
  647. }
  648. }
  649. print_error_obj(m, dev_priv->engine[i],
  650. "ringbuffer", ee->ringbuffer);
  651. print_error_obj(m, dev_priv->engine[i],
  652. "HW Status", ee->hws_page);
  653. print_error_obj(m, dev_priv->engine[i],
  654. "HW context", ee->ctx);
  655. print_error_obj(m, dev_priv->engine[i],
  656. "WA context", ee->wa_ctx);
  657. print_error_obj(m, dev_priv->engine[i],
  658. "WA batchbuffer", ee->wa_batchbuffer);
  659. print_error_obj(m, dev_priv->engine[i],
  660. "NULL context", ee->default_state);
  661. }
  662. if (error->overlay)
  663. intel_overlay_print_error_state(m, error->overlay);
  664. if (error->display)
  665. intel_display_print_error_state(m, error->display);
  666. err_print_capabilities(m, &error->device_info, &error->driver_caps);
  667. err_print_params(m, &error->params);
  668. err_print_uc(m, &error->uc);
  669. if (m->bytes == 0 && m->err)
  670. return m->err;
  671. return 0;
  672. }
  673. int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
  674. struct drm_i915_private *i915,
  675. size_t count, loff_t pos)
  676. {
  677. memset(ebuf, 0, sizeof(*ebuf));
  678. ebuf->i915 = i915;
  679. /* We need to have enough room to store any i915_error_state printf
  680. * so that we can move it to start position.
  681. */
  682. ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
  683. ebuf->buf = kmalloc(ebuf->size,
  684. GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
  685. if (ebuf->buf == NULL) {
  686. ebuf->size = PAGE_SIZE;
  687. ebuf->buf = kmalloc(ebuf->size, GFP_KERNEL);
  688. }
  689. if (ebuf->buf == NULL) {
  690. ebuf->size = 128;
  691. ebuf->buf = kmalloc(ebuf->size, GFP_KERNEL);
  692. }
  693. if (ebuf->buf == NULL)
  694. return -ENOMEM;
  695. ebuf->start = pos;
  696. return 0;
  697. }
  698. static void i915_error_object_free(struct drm_i915_error_object *obj)
  699. {
  700. int page;
  701. if (obj == NULL)
  702. return;
  703. for (page = 0; page < obj->page_count; page++)
  704. free_page((unsigned long)obj->pages[page]);
  705. kfree(obj);
  706. }
  707. static __always_inline void free_param(const char *type, void *x)
  708. {
  709. if (!__builtin_strcmp(type, "char *"))
  710. kfree(*(void **)x);
  711. }
  712. static void cleanup_params(struct i915_gpu_state *error)
  713. {
  714. #define FREE(T, x, ...) free_param(#T, &error->params.x);
  715. I915_PARAMS_FOR_EACH(FREE);
  716. #undef FREE
  717. }
  718. static void cleanup_uc_state(struct i915_gpu_state *error)
  719. {
  720. struct i915_error_uc *error_uc = &error->uc;
  721. kfree(error_uc->guc_fw.path);
  722. kfree(error_uc->huc_fw.path);
  723. i915_error_object_free(error_uc->guc_log);
  724. }
  725. void __i915_gpu_state_free(struct kref *error_ref)
  726. {
  727. struct i915_gpu_state *error =
  728. container_of(error_ref, typeof(*error), ref);
  729. long i, j;
  730. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  731. struct drm_i915_error_engine *ee = &error->engine[i];
  732. for (j = 0; j < ee->user_bo_count; j++)
  733. i915_error_object_free(ee->user_bo[j]);
  734. kfree(ee->user_bo);
  735. i915_error_object_free(ee->batchbuffer);
  736. i915_error_object_free(ee->wa_batchbuffer);
  737. i915_error_object_free(ee->ringbuffer);
  738. i915_error_object_free(ee->hws_page);
  739. i915_error_object_free(ee->ctx);
  740. i915_error_object_free(ee->wa_ctx);
  741. kfree(ee->requests);
  742. if (!IS_ERR_OR_NULL(ee->waiters))
  743. kfree(ee->waiters);
  744. }
  745. for (i = 0; i < ARRAY_SIZE(error->active_bo); i++)
  746. kfree(error->active_bo[i]);
  747. kfree(error->pinned_bo);
  748. kfree(error->overlay);
  749. kfree(error->display);
  750. cleanup_params(error);
  751. cleanup_uc_state(error);
  752. kfree(error);
  753. }
  754. static struct drm_i915_error_object *
  755. i915_error_object_create(struct drm_i915_private *i915,
  756. struct i915_vma *vma)
  757. {
  758. struct i915_ggtt *ggtt = &i915->ggtt;
  759. const u64 slot = ggtt->error_capture.start;
  760. struct drm_i915_error_object *dst;
  761. struct compress compress;
  762. unsigned long num_pages;
  763. struct sgt_iter iter;
  764. dma_addr_t dma;
  765. if (!vma)
  766. return NULL;
  767. num_pages = min_t(u64, vma->size, vma->obj->base.size) >> PAGE_SHIFT;
  768. num_pages = DIV_ROUND_UP(10 * num_pages, 8); /* worstcase zlib growth */
  769. dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *),
  770. GFP_ATOMIC | __GFP_NOWARN);
  771. if (!dst)
  772. return NULL;
  773. dst->gtt_offset = vma->node.start;
  774. dst->gtt_size = vma->node.size;
  775. dst->page_count = 0;
  776. dst->unused = 0;
  777. if (!compress_init(&compress)) {
  778. kfree(dst);
  779. return NULL;
  780. }
  781. for_each_sgt_dma(dma, iter, vma->pages) {
  782. void __iomem *s;
  783. int ret;
  784. ggtt->base.insert_page(&ggtt->base, dma, slot,
  785. I915_CACHE_NONE, 0);
  786. s = io_mapping_map_atomic_wc(&ggtt->iomap, slot);
  787. ret = compress_page(&compress, (void __force *)s, dst);
  788. io_mapping_unmap_atomic(s);
  789. if (ret)
  790. goto unwind;
  791. }
  792. goto out;
  793. unwind:
  794. while (dst->page_count--)
  795. free_page((unsigned long)dst->pages[dst->page_count]);
  796. kfree(dst);
  797. dst = NULL;
  798. out:
  799. compress_fini(&compress, dst);
  800. ggtt->base.clear_range(&ggtt->base, slot, PAGE_SIZE);
  801. return dst;
  802. }
  803. /* The error capture is special as tries to run underneath the normal
  804. * locking rules - so we use the raw version of the i915_gem_active lookup.
  805. */
  806. static inline uint32_t
  807. __active_get_seqno(struct i915_gem_active *active)
  808. {
  809. struct i915_request *request;
  810. request = __i915_gem_active_peek(active);
  811. return request ? request->global_seqno : 0;
  812. }
  813. static inline int
  814. __active_get_engine_id(struct i915_gem_active *active)
  815. {
  816. struct i915_request *request;
  817. request = __i915_gem_active_peek(active);
  818. return request ? request->engine->id : -1;
  819. }
  820. static void capture_bo(struct drm_i915_error_buffer *err,
  821. struct i915_vma *vma)
  822. {
  823. struct drm_i915_gem_object *obj = vma->obj;
  824. int i;
  825. err->size = obj->base.size;
  826. err->name = obj->base.name;
  827. for (i = 0; i < I915_NUM_ENGINES; i++)
  828. err->rseqno[i] = __active_get_seqno(&vma->last_read[i]);
  829. err->wseqno = __active_get_seqno(&obj->frontbuffer_write);
  830. err->engine = __active_get_engine_id(&obj->frontbuffer_write);
  831. err->gtt_offset = vma->node.start;
  832. err->read_domains = obj->read_domains;
  833. err->write_domain = obj->write_domain;
  834. err->fence_reg = vma->fence ? vma->fence->id : -1;
  835. err->tiling = i915_gem_object_get_tiling(obj);
  836. err->dirty = obj->mm.dirty;
  837. err->purgeable = obj->mm.madv != I915_MADV_WILLNEED;
  838. err->userptr = obj->userptr.mm != NULL;
  839. err->cache_level = obj->cache_level;
  840. }
  841. static u32 capture_error_bo(struct drm_i915_error_buffer *err,
  842. int count, struct list_head *head,
  843. bool pinned_only)
  844. {
  845. struct i915_vma *vma;
  846. int i = 0;
  847. list_for_each_entry(vma, head, vm_link) {
  848. if (pinned_only && !i915_vma_is_pinned(vma))
  849. continue;
  850. capture_bo(err++, vma);
  851. if (++i == count)
  852. break;
  853. }
  854. return i;
  855. }
  856. /* Generate a semi-unique error code. The code is not meant to have meaning, The
  857. * code's only purpose is to try to prevent false duplicated bug reports by
  858. * grossly estimating a GPU error state.
  859. *
  860. * TODO Ideally, hashing the batchbuffer would be a very nice way to determine
  861. * the hang if we could strip the GTT offset information from it.
  862. *
  863. * It's only a small step better than a random number in its current form.
  864. */
  865. static uint32_t i915_error_generate_code(struct drm_i915_private *dev_priv,
  866. struct i915_gpu_state *error,
  867. int *engine_id)
  868. {
  869. uint32_t error_code = 0;
  870. int i;
  871. /* IPEHR would be an ideal way to detect errors, as it's the gross
  872. * measure of "the command that hung." However, has some very common
  873. * synchronization commands which almost always appear in the case
  874. * strictly a client bug. Use instdone to differentiate those some.
  875. */
  876. for (i = 0; i < I915_NUM_ENGINES; i++) {
  877. if (error->engine[i].hangcheck_stalled) {
  878. if (engine_id)
  879. *engine_id = i;
  880. return error->engine[i].ipehr ^
  881. error->engine[i].instdone.instdone;
  882. }
  883. }
  884. return error_code;
  885. }
  886. static void gem_record_fences(struct i915_gpu_state *error)
  887. {
  888. struct drm_i915_private *dev_priv = error->i915;
  889. int i;
  890. if (INTEL_GEN(dev_priv) >= 6) {
  891. for (i = 0; i < dev_priv->num_fence_regs; i++)
  892. error->fence[i] = I915_READ64(FENCE_REG_GEN6_LO(i));
  893. } else if (INTEL_GEN(dev_priv) >= 4) {
  894. for (i = 0; i < dev_priv->num_fence_regs; i++)
  895. error->fence[i] = I915_READ64(FENCE_REG_965_LO(i));
  896. } else {
  897. for (i = 0; i < dev_priv->num_fence_regs; i++)
  898. error->fence[i] = I915_READ(FENCE_REG(i));
  899. }
  900. error->nfence = i;
  901. }
  902. static void gen6_record_semaphore_state(struct intel_engine_cs *engine,
  903. struct drm_i915_error_engine *ee)
  904. {
  905. struct drm_i915_private *dev_priv = engine->i915;
  906. ee->semaphore_mboxes[0] = I915_READ(RING_SYNC_0(engine->mmio_base));
  907. ee->semaphore_mboxes[1] = I915_READ(RING_SYNC_1(engine->mmio_base));
  908. if (HAS_VEBOX(dev_priv))
  909. ee->semaphore_mboxes[2] =
  910. I915_READ(RING_SYNC_2(engine->mmio_base));
  911. }
  912. static void error_record_engine_waiters(struct intel_engine_cs *engine,
  913. struct drm_i915_error_engine *ee)
  914. {
  915. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  916. struct drm_i915_error_waiter *waiter;
  917. struct rb_node *rb;
  918. int count;
  919. ee->num_waiters = 0;
  920. ee->waiters = NULL;
  921. if (RB_EMPTY_ROOT(&b->waiters))
  922. return;
  923. if (!spin_trylock_irq(&b->rb_lock)) {
  924. ee->waiters = ERR_PTR(-EDEADLK);
  925. return;
  926. }
  927. count = 0;
  928. for (rb = rb_first(&b->waiters); rb != NULL; rb = rb_next(rb))
  929. count++;
  930. spin_unlock_irq(&b->rb_lock);
  931. waiter = NULL;
  932. if (count)
  933. waiter = kmalloc_array(count,
  934. sizeof(struct drm_i915_error_waiter),
  935. GFP_ATOMIC);
  936. if (!waiter)
  937. return;
  938. if (!spin_trylock_irq(&b->rb_lock)) {
  939. kfree(waiter);
  940. ee->waiters = ERR_PTR(-EDEADLK);
  941. return;
  942. }
  943. ee->waiters = waiter;
  944. for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
  945. struct intel_wait *w = rb_entry(rb, typeof(*w), node);
  946. strcpy(waiter->comm, w->tsk->comm);
  947. waiter->pid = w->tsk->pid;
  948. waiter->seqno = w->seqno;
  949. waiter++;
  950. if (++ee->num_waiters == count)
  951. break;
  952. }
  953. spin_unlock_irq(&b->rb_lock);
  954. }
  955. static void error_record_engine_registers(struct i915_gpu_state *error,
  956. struct intel_engine_cs *engine,
  957. struct drm_i915_error_engine *ee)
  958. {
  959. struct drm_i915_private *dev_priv = engine->i915;
  960. if (INTEL_GEN(dev_priv) >= 6) {
  961. ee->rc_psmi = I915_READ(RING_PSMI_CTL(engine->mmio_base));
  962. if (INTEL_GEN(dev_priv) >= 8) {
  963. ee->fault_reg = I915_READ(GEN8_RING_FAULT_REG);
  964. } else {
  965. gen6_record_semaphore_state(engine, ee);
  966. ee->fault_reg = I915_READ(RING_FAULT_REG(engine));
  967. }
  968. }
  969. if (INTEL_GEN(dev_priv) >= 4) {
  970. ee->faddr = I915_READ(RING_DMA_FADD(engine->mmio_base));
  971. ee->ipeir = I915_READ(RING_IPEIR(engine->mmio_base));
  972. ee->ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
  973. ee->instps = I915_READ(RING_INSTPS(engine->mmio_base));
  974. ee->bbaddr = I915_READ(RING_BBADDR(engine->mmio_base));
  975. if (INTEL_GEN(dev_priv) >= 8) {
  976. ee->faddr |= (u64) I915_READ(RING_DMA_FADD_UDW(engine->mmio_base)) << 32;
  977. ee->bbaddr |= (u64) I915_READ(RING_BBADDR_UDW(engine->mmio_base)) << 32;
  978. }
  979. ee->bbstate = I915_READ(RING_BBSTATE(engine->mmio_base));
  980. } else {
  981. ee->faddr = I915_READ(DMA_FADD_I8XX);
  982. ee->ipeir = I915_READ(IPEIR);
  983. ee->ipehr = I915_READ(IPEHR);
  984. }
  985. intel_engine_get_instdone(engine, &ee->instdone);
  986. ee->waiting = intel_engine_has_waiter(engine);
  987. ee->instpm = I915_READ(RING_INSTPM(engine->mmio_base));
  988. ee->acthd = intel_engine_get_active_head(engine);
  989. ee->seqno = intel_engine_get_seqno(engine);
  990. ee->last_seqno = intel_engine_last_submit(engine);
  991. ee->start = I915_READ_START(engine);
  992. ee->head = I915_READ_HEAD(engine);
  993. ee->tail = I915_READ_TAIL(engine);
  994. ee->ctl = I915_READ_CTL(engine);
  995. if (INTEL_GEN(dev_priv) > 2)
  996. ee->mode = I915_READ_MODE(engine);
  997. if (!HWS_NEEDS_PHYSICAL(dev_priv)) {
  998. i915_reg_t mmio;
  999. if (IS_GEN7(dev_priv)) {
  1000. switch (engine->id) {
  1001. default:
  1002. case RCS:
  1003. mmio = RENDER_HWS_PGA_GEN7;
  1004. break;
  1005. case BCS:
  1006. mmio = BLT_HWS_PGA_GEN7;
  1007. break;
  1008. case VCS:
  1009. mmio = BSD_HWS_PGA_GEN7;
  1010. break;
  1011. case VECS:
  1012. mmio = VEBOX_HWS_PGA_GEN7;
  1013. break;
  1014. }
  1015. } else if (IS_GEN6(engine->i915)) {
  1016. mmio = RING_HWS_PGA_GEN6(engine->mmio_base);
  1017. } else {
  1018. /* XXX: gen8 returns to sanity */
  1019. mmio = RING_HWS_PGA(engine->mmio_base);
  1020. }
  1021. ee->hws = I915_READ(mmio);
  1022. }
  1023. ee->idle = intel_engine_is_idle(engine);
  1024. ee->hangcheck_timestamp = engine->hangcheck.action_timestamp;
  1025. ee->hangcheck_action = engine->hangcheck.action;
  1026. ee->hangcheck_stalled = engine->hangcheck.stalled;
  1027. ee->reset_count = i915_reset_engine_count(&dev_priv->gpu_error,
  1028. engine);
  1029. if (USES_PPGTT(dev_priv)) {
  1030. int i;
  1031. ee->vm_info.gfx_mode = I915_READ(RING_MODE_GEN7(engine));
  1032. if (IS_GEN6(dev_priv))
  1033. ee->vm_info.pp_dir_base =
  1034. I915_READ(RING_PP_DIR_BASE_READ(engine));
  1035. else if (IS_GEN7(dev_priv))
  1036. ee->vm_info.pp_dir_base =
  1037. I915_READ(RING_PP_DIR_BASE(engine));
  1038. else if (INTEL_GEN(dev_priv) >= 8)
  1039. for (i = 0; i < 4; i++) {
  1040. ee->vm_info.pdp[i] =
  1041. I915_READ(GEN8_RING_PDP_UDW(engine, i));
  1042. ee->vm_info.pdp[i] <<= 32;
  1043. ee->vm_info.pdp[i] |=
  1044. I915_READ(GEN8_RING_PDP_LDW(engine, i));
  1045. }
  1046. }
  1047. }
  1048. static void record_request(struct i915_request *request,
  1049. struct drm_i915_error_request *erq)
  1050. {
  1051. erq->context = request->ctx->hw_id;
  1052. erq->priority = request->priotree.priority;
  1053. erq->ban_score = atomic_read(&request->ctx->ban_score);
  1054. erq->seqno = request->global_seqno;
  1055. erq->jiffies = request->emitted_jiffies;
  1056. erq->head = request->head;
  1057. erq->tail = request->tail;
  1058. rcu_read_lock();
  1059. erq->pid = request->ctx->pid ? pid_nr(request->ctx->pid) : 0;
  1060. rcu_read_unlock();
  1061. }
  1062. static void engine_record_requests(struct intel_engine_cs *engine,
  1063. struct i915_request *first,
  1064. struct drm_i915_error_engine *ee)
  1065. {
  1066. struct i915_request *request;
  1067. int count;
  1068. count = 0;
  1069. request = first;
  1070. list_for_each_entry_from(request, &engine->timeline->requests, link)
  1071. count++;
  1072. if (!count)
  1073. return;
  1074. ee->requests = kcalloc(count, sizeof(*ee->requests), GFP_ATOMIC);
  1075. if (!ee->requests)
  1076. return;
  1077. ee->num_requests = count;
  1078. count = 0;
  1079. request = first;
  1080. list_for_each_entry_from(request, &engine->timeline->requests, link) {
  1081. if (count >= ee->num_requests) {
  1082. /*
  1083. * If the ring request list was changed in
  1084. * between the point where the error request
  1085. * list was created and dimensioned and this
  1086. * point then just exit early to avoid crashes.
  1087. *
  1088. * We don't need to communicate that the
  1089. * request list changed state during error
  1090. * state capture and that the error state is
  1091. * slightly incorrect as a consequence since we
  1092. * are typically only interested in the request
  1093. * list state at the point of error state
  1094. * capture, not in any changes happening during
  1095. * the capture.
  1096. */
  1097. break;
  1098. }
  1099. record_request(request, &ee->requests[count++]);
  1100. }
  1101. ee->num_requests = count;
  1102. }
  1103. static void error_record_engine_execlists(struct intel_engine_cs *engine,
  1104. struct drm_i915_error_engine *ee)
  1105. {
  1106. const struct intel_engine_execlists * const execlists = &engine->execlists;
  1107. unsigned int n;
  1108. for (n = 0; n < execlists_num_ports(execlists); n++) {
  1109. struct i915_request *rq = port_request(&execlists->port[n]);
  1110. if (!rq)
  1111. break;
  1112. record_request(rq, &ee->execlist[n]);
  1113. }
  1114. ee->num_ports = n;
  1115. }
  1116. static void record_context(struct drm_i915_error_context *e,
  1117. struct i915_gem_context *ctx)
  1118. {
  1119. if (ctx->pid) {
  1120. struct task_struct *task;
  1121. rcu_read_lock();
  1122. task = pid_task(ctx->pid, PIDTYPE_PID);
  1123. if (task) {
  1124. strcpy(e->comm, task->comm);
  1125. e->pid = task->pid;
  1126. }
  1127. rcu_read_unlock();
  1128. }
  1129. e->handle = ctx->user_handle;
  1130. e->hw_id = ctx->hw_id;
  1131. e->priority = ctx->priority;
  1132. e->ban_score = atomic_read(&ctx->ban_score);
  1133. e->bannable = i915_gem_context_is_bannable(ctx);
  1134. e->guilty = atomic_read(&ctx->guilty_count);
  1135. e->active = atomic_read(&ctx->active_count);
  1136. }
  1137. static void request_record_user_bo(struct i915_request *request,
  1138. struct drm_i915_error_engine *ee)
  1139. {
  1140. struct i915_capture_list *c;
  1141. struct drm_i915_error_object **bo;
  1142. long count;
  1143. count = 0;
  1144. for (c = request->capture_list; c; c = c->next)
  1145. count++;
  1146. bo = NULL;
  1147. if (count)
  1148. bo = kcalloc(count, sizeof(*bo), GFP_ATOMIC);
  1149. if (!bo)
  1150. return;
  1151. count = 0;
  1152. for (c = request->capture_list; c; c = c->next) {
  1153. bo[count] = i915_error_object_create(request->i915, c->vma);
  1154. if (!bo[count])
  1155. break;
  1156. count++;
  1157. }
  1158. ee->user_bo = bo;
  1159. ee->user_bo_count = count;
  1160. }
  1161. static struct drm_i915_error_object *
  1162. capture_object(struct drm_i915_private *dev_priv,
  1163. struct drm_i915_gem_object *obj)
  1164. {
  1165. if (obj && i915_gem_object_has_pages(obj)) {
  1166. struct i915_vma fake = {
  1167. .node = { .start = U64_MAX, .size = obj->base.size },
  1168. .size = obj->base.size,
  1169. .pages = obj->mm.pages,
  1170. .obj = obj,
  1171. };
  1172. return i915_error_object_create(dev_priv, &fake);
  1173. } else {
  1174. return NULL;
  1175. }
  1176. }
  1177. static void gem_record_rings(struct i915_gpu_state *error)
  1178. {
  1179. struct drm_i915_private *i915 = error->i915;
  1180. struct i915_ggtt *ggtt = &i915->ggtt;
  1181. int i;
  1182. for (i = 0; i < I915_NUM_ENGINES; i++) {
  1183. struct intel_engine_cs *engine = i915->engine[i];
  1184. struct drm_i915_error_engine *ee = &error->engine[i];
  1185. struct i915_request *request;
  1186. ee->engine_id = -1;
  1187. if (!engine)
  1188. continue;
  1189. ee->engine_id = i;
  1190. error_record_engine_registers(error, engine, ee);
  1191. error_record_engine_waiters(engine, ee);
  1192. error_record_engine_execlists(engine, ee);
  1193. request = i915_gem_find_active_request(engine);
  1194. if (request) {
  1195. struct intel_ring *ring;
  1196. ee->vm = request->ctx->ppgtt ?
  1197. &request->ctx->ppgtt->base : &ggtt->base;
  1198. record_context(&ee->context, request->ctx);
  1199. /* We need to copy these to an anonymous buffer
  1200. * as the simplest method to avoid being overwritten
  1201. * by userspace.
  1202. */
  1203. ee->batchbuffer =
  1204. i915_error_object_create(i915, request->batch);
  1205. if (HAS_BROKEN_CS_TLB(i915))
  1206. ee->wa_batchbuffer =
  1207. i915_error_object_create(i915,
  1208. engine->scratch);
  1209. request_record_user_bo(request, ee);
  1210. ee->ctx =
  1211. i915_error_object_create(i915,
  1212. request->ctx->engine[i].state);
  1213. error->simulated |=
  1214. i915_gem_context_no_error_capture(request->ctx);
  1215. ee->rq_head = request->head;
  1216. ee->rq_post = request->postfix;
  1217. ee->rq_tail = request->tail;
  1218. ring = request->ring;
  1219. ee->cpu_ring_head = ring->head;
  1220. ee->cpu_ring_tail = ring->tail;
  1221. ee->ringbuffer =
  1222. i915_error_object_create(i915, ring->vma);
  1223. engine_record_requests(engine, request, ee);
  1224. }
  1225. ee->hws_page =
  1226. i915_error_object_create(i915,
  1227. engine->status_page.vma);
  1228. ee->wa_ctx = i915_error_object_create(i915, engine->wa_ctx.vma);
  1229. ee->default_state = capture_object(i915, engine->default_state);
  1230. }
  1231. }
  1232. static void gem_capture_vm(struct i915_gpu_state *error,
  1233. struct i915_address_space *vm,
  1234. int idx)
  1235. {
  1236. struct drm_i915_error_buffer *active_bo;
  1237. struct i915_vma *vma;
  1238. int count;
  1239. count = 0;
  1240. list_for_each_entry(vma, &vm->active_list, vm_link)
  1241. count++;
  1242. active_bo = NULL;
  1243. if (count)
  1244. active_bo = kcalloc(count, sizeof(*active_bo), GFP_ATOMIC);
  1245. if (active_bo)
  1246. count = capture_error_bo(active_bo, count, &vm->active_list, false);
  1247. else
  1248. count = 0;
  1249. error->active_vm[idx] = vm;
  1250. error->active_bo[idx] = active_bo;
  1251. error->active_bo_count[idx] = count;
  1252. }
  1253. static void capture_active_buffers(struct i915_gpu_state *error)
  1254. {
  1255. int cnt = 0, i, j;
  1256. BUILD_BUG_ON(ARRAY_SIZE(error->engine) > ARRAY_SIZE(error->active_bo));
  1257. BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_vm));
  1258. BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_bo_count));
  1259. /* Scan each engine looking for unique active contexts/vm */
  1260. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  1261. struct drm_i915_error_engine *ee = &error->engine[i];
  1262. bool found;
  1263. if (!ee->vm)
  1264. continue;
  1265. found = false;
  1266. for (j = 0; j < i && !found; j++)
  1267. found = error->engine[j].vm == ee->vm;
  1268. if (!found)
  1269. gem_capture_vm(error, ee->vm, cnt++);
  1270. }
  1271. }
  1272. static void capture_pinned_buffers(struct i915_gpu_state *error)
  1273. {
  1274. struct i915_address_space *vm = &error->i915->ggtt.base;
  1275. struct drm_i915_error_buffer *bo;
  1276. struct i915_vma *vma;
  1277. int count_inactive, count_active;
  1278. count_inactive = 0;
  1279. list_for_each_entry(vma, &vm->active_list, vm_link)
  1280. count_inactive++;
  1281. count_active = 0;
  1282. list_for_each_entry(vma, &vm->inactive_list, vm_link)
  1283. count_active++;
  1284. bo = NULL;
  1285. if (count_inactive + count_active)
  1286. bo = kcalloc(count_inactive + count_active,
  1287. sizeof(*bo), GFP_ATOMIC);
  1288. if (!bo)
  1289. return;
  1290. count_inactive = capture_error_bo(bo, count_inactive,
  1291. &vm->active_list, true);
  1292. count_active = capture_error_bo(bo + count_inactive, count_active,
  1293. &vm->inactive_list, true);
  1294. error->pinned_bo_count = count_inactive + count_active;
  1295. error->pinned_bo = bo;
  1296. }
  1297. static void capture_uc_state(struct i915_gpu_state *error)
  1298. {
  1299. struct drm_i915_private *i915 = error->i915;
  1300. struct i915_error_uc *error_uc = &error->uc;
  1301. /* Capturing uC state won't be useful if there is no GuC */
  1302. if (!error->device_info.has_guc)
  1303. return;
  1304. error_uc->guc_fw = i915->guc.fw;
  1305. error_uc->huc_fw = i915->huc.fw;
  1306. /* Non-default firmware paths will be specified by the modparam.
  1307. * As modparams are generally accesible from the userspace make
  1308. * explicit copies of the firmware paths.
  1309. */
  1310. error_uc->guc_fw.path = kstrdup(i915->guc.fw.path, GFP_ATOMIC);
  1311. error_uc->huc_fw.path = kstrdup(i915->huc.fw.path, GFP_ATOMIC);
  1312. error_uc->guc_log = i915_error_object_create(i915, i915->guc.log.vma);
  1313. }
  1314. /* Capture all registers which don't fit into another category. */
  1315. static void capture_reg_state(struct i915_gpu_state *error)
  1316. {
  1317. struct drm_i915_private *dev_priv = error->i915;
  1318. int i;
  1319. /* General organization
  1320. * 1. Registers specific to a single generation
  1321. * 2. Registers which belong to multiple generations
  1322. * 3. Feature specific registers.
  1323. * 4. Everything else
  1324. * Please try to follow the order.
  1325. */
  1326. /* 1: Registers specific to a single generation */
  1327. if (IS_VALLEYVIEW(dev_priv)) {
  1328. error->gtier[0] = I915_READ(GTIER);
  1329. error->ier = I915_READ(VLV_IER);
  1330. error->forcewake = I915_READ_FW(FORCEWAKE_VLV);
  1331. }
  1332. if (IS_GEN7(dev_priv))
  1333. error->err_int = I915_READ(GEN7_ERR_INT);
  1334. if (INTEL_GEN(dev_priv) >= 8) {
  1335. error->fault_data0 = I915_READ(GEN8_FAULT_TLB_DATA0);
  1336. error->fault_data1 = I915_READ(GEN8_FAULT_TLB_DATA1);
  1337. }
  1338. if (IS_GEN6(dev_priv)) {
  1339. error->forcewake = I915_READ_FW(FORCEWAKE);
  1340. error->gab_ctl = I915_READ(GAB_CTL);
  1341. error->gfx_mode = I915_READ(GFX_MODE);
  1342. }
  1343. /* 2: Registers which belong to multiple generations */
  1344. if (INTEL_GEN(dev_priv) >= 7)
  1345. error->forcewake = I915_READ_FW(FORCEWAKE_MT);
  1346. if (INTEL_GEN(dev_priv) >= 6) {
  1347. error->derrmr = I915_READ(DERRMR);
  1348. error->error = I915_READ(ERROR_GEN6);
  1349. error->done_reg = I915_READ(DONE_REG);
  1350. }
  1351. if (INTEL_GEN(dev_priv) >= 5)
  1352. error->ccid = I915_READ(CCID);
  1353. /* 3: Feature specific registers */
  1354. if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
  1355. error->gam_ecochk = I915_READ(GAM_ECOCHK);
  1356. error->gac_eco = I915_READ(GAC_ECO_BITS);
  1357. }
  1358. /* 4: Everything else */
  1359. if (INTEL_GEN(dev_priv) >= 8) {
  1360. error->ier = I915_READ(GEN8_DE_MISC_IER);
  1361. for (i = 0; i < 4; i++)
  1362. error->gtier[i] = I915_READ(GEN8_GT_IER(i));
  1363. error->ngtier = 4;
  1364. } else if (HAS_PCH_SPLIT(dev_priv)) {
  1365. error->ier = I915_READ(DEIER);
  1366. error->gtier[0] = I915_READ(GTIER);
  1367. error->ngtier = 1;
  1368. } else if (IS_GEN2(dev_priv)) {
  1369. error->ier = I915_READ16(IER);
  1370. } else if (!IS_VALLEYVIEW(dev_priv)) {
  1371. error->ier = I915_READ(IER);
  1372. }
  1373. error->eir = I915_READ(EIR);
  1374. error->pgtbl_er = I915_READ(PGTBL_ER);
  1375. }
  1376. static void i915_error_capture_msg(struct drm_i915_private *dev_priv,
  1377. struct i915_gpu_state *error,
  1378. u32 engine_mask,
  1379. const char *error_msg)
  1380. {
  1381. u32 ecode;
  1382. int engine_id = -1, len;
  1383. ecode = i915_error_generate_code(dev_priv, error, &engine_id);
  1384. len = scnprintf(error->error_msg, sizeof(error->error_msg),
  1385. "GPU HANG: ecode %d:%d:0x%08x",
  1386. INTEL_GEN(dev_priv), engine_id, ecode);
  1387. if (engine_id != -1 && error->engine[engine_id].context.pid)
  1388. len += scnprintf(error->error_msg + len,
  1389. sizeof(error->error_msg) - len,
  1390. ", in %s [%d]",
  1391. error->engine[engine_id].context.comm,
  1392. error->engine[engine_id].context.pid);
  1393. scnprintf(error->error_msg + len, sizeof(error->error_msg) - len,
  1394. ", reason: %s, action: %s",
  1395. error_msg,
  1396. engine_mask ? "reset" : "continue");
  1397. }
  1398. static void capture_gen_state(struct i915_gpu_state *error)
  1399. {
  1400. struct drm_i915_private *i915 = error->i915;
  1401. error->awake = i915->gt.awake;
  1402. error->wakelock = atomic_read(&i915->runtime_pm.wakeref_count);
  1403. error->suspended = i915->runtime_pm.suspended;
  1404. error->iommu = -1;
  1405. #ifdef CONFIG_INTEL_IOMMU
  1406. error->iommu = intel_iommu_gfx_mapped;
  1407. #endif
  1408. error->reset_count = i915_reset_count(&i915->gpu_error);
  1409. error->suspend_count = i915->suspend_count;
  1410. memcpy(&error->device_info,
  1411. INTEL_INFO(i915),
  1412. sizeof(error->device_info));
  1413. error->driver_caps = i915->caps;
  1414. }
  1415. static __always_inline void dup_param(const char *type, void *x)
  1416. {
  1417. if (!__builtin_strcmp(type, "char *"))
  1418. *(void **)x = kstrdup(*(void **)x, GFP_ATOMIC);
  1419. }
  1420. static void capture_params(struct i915_gpu_state *error)
  1421. {
  1422. error->params = i915_modparams;
  1423. #define DUP(T, x, ...) dup_param(#T, &error->params.x);
  1424. I915_PARAMS_FOR_EACH(DUP);
  1425. #undef DUP
  1426. }
  1427. static int capture(void *data)
  1428. {
  1429. struct i915_gpu_state *error = data;
  1430. error->time = ktime_get_real();
  1431. error->boottime = ktime_get_boottime();
  1432. error->uptime = ktime_sub(ktime_get(),
  1433. error->i915->gt.last_init_time);
  1434. capture_params(error);
  1435. capture_gen_state(error);
  1436. capture_uc_state(error);
  1437. capture_reg_state(error);
  1438. gem_record_fences(error);
  1439. gem_record_rings(error);
  1440. capture_active_buffers(error);
  1441. capture_pinned_buffers(error);
  1442. error->overlay = intel_overlay_capture_error_state(error->i915);
  1443. error->display = intel_display_capture_error_state(error->i915);
  1444. return 0;
  1445. }
  1446. #define DAY_AS_SECONDS(x) (24 * 60 * 60 * (x))
  1447. struct i915_gpu_state *
  1448. i915_capture_gpu_state(struct drm_i915_private *i915)
  1449. {
  1450. struct i915_gpu_state *error;
  1451. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  1452. if (!error)
  1453. return NULL;
  1454. kref_init(&error->ref);
  1455. error->i915 = i915;
  1456. stop_machine(capture, error, NULL);
  1457. return error;
  1458. }
  1459. /**
  1460. * i915_capture_error_state - capture an error record for later analysis
  1461. * @i915: i915 device
  1462. * @engine_mask: the mask of engines triggering the hang
  1463. * @error_msg: a message to insert into the error capture header
  1464. *
  1465. * Should be called when an error is detected (either a hang or an error
  1466. * interrupt) to capture error state from the time of the error. Fills
  1467. * out a structure which becomes available in debugfs for user level tools
  1468. * to pick up.
  1469. */
  1470. void i915_capture_error_state(struct drm_i915_private *i915,
  1471. u32 engine_mask,
  1472. const char *error_msg)
  1473. {
  1474. static bool warned;
  1475. struct i915_gpu_state *error;
  1476. unsigned long flags;
  1477. if (!i915_modparams.error_capture)
  1478. return;
  1479. if (READ_ONCE(i915->gpu_error.first_error))
  1480. return;
  1481. error = i915_capture_gpu_state(i915);
  1482. if (!error) {
  1483. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  1484. return;
  1485. }
  1486. i915_error_capture_msg(i915, error, engine_mask, error_msg);
  1487. DRM_INFO("%s\n", error->error_msg);
  1488. if (!error->simulated) {
  1489. spin_lock_irqsave(&i915->gpu_error.lock, flags);
  1490. if (!i915->gpu_error.first_error) {
  1491. i915->gpu_error.first_error = error;
  1492. error = NULL;
  1493. }
  1494. spin_unlock_irqrestore(&i915->gpu_error.lock, flags);
  1495. }
  1496. if (error) {
  1497. __i915_gpu_state_free(&error->ref);
  1498. return;
  1499. }
  1500. if (!warned &&
  1501. ktime_get_real_seconds() - DRIVER_TIMESTAMP < DAY_AS_SECONDS(180)) {
  1502. DRM_INFO("GPU hangs can indicate a bug anywhere in the entire gfx stack, including userspace.\n");
  1503. DRM_INFO("Please file a _new_ bug report on bugs.freedesktop.org against DRI -> DRM/Intel\n");
  1504. DRM_INFO("drm/i915 developers can then reassign to the right component if it's not a kernel issue.\n");
  1505. DRM_INFO("The gpu crash dump is required to analyze gpu hangs, so please always attach it.\n");
  1506. DRM_INFO("GPU crash dump saved to /sys/class/drm/card%d/error\n",
  1507. i915->drm.primary->index);
  1508. warned = true;
  1509. }
  1510. }
  1511. struct i915_gpu_state *
  1512. i915_first_error_state(struct drm_i915_private *i915)
  1513. {
  1514. struct i915_gpu_state *error;
  1515. spin_lock_irq(&i915->gpu_error.lock);
  1516. error = i915->gpu_error.first_error;
  1517. if (error)
  1518. i915_gpu_state_get(error);
  1519. spin_unlock_irq(&i915->gpu_error.lock);
  1520. return error;
  1521. }
  1522. void i915_reset_error_state(struct drm_i915_private *i915)
  1523. {
  1524. struct i915_gpu_state *error;
  1525. spin_lock_irq(&i915->gpu_error.lock);
  1526. error = i915->gpu_error.first_error;
  1527. i915->gpu_error.first_error = NULL;
  1528. spin_unlock_irq(&i915->gpu_error.lock);
  1529. i915_gpu_state_put(error);
  1530. }