i915_gpu_error.c 49 KB

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