Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe: Fix and re-enable xe_print_blob_ascii85()

Commit 70fb86a85dc9 ("drm/xe: Revert some changes that break a mesa
debug tool") partially reverted some changes to workaround breakage
caused to mesa tools. However, in doing so it also broke fetching the
GuC log via debugfs since xe_print_blob_ascii85() simply bails out.

The fix is to avoid the extra newlines: the devcoredump interface is
line-oriented and adding random newlines in the middle breaks it. If a
tool is able to parse it by looking at the data and checking for chars
that are out of the ascii85 space, it can still do so. A format change
that breaks the line-oriented output on devcoredump however needs better
coordination with existing tools.

v2: Add suffix description comment
v3: Reword explanation of xe_print_blob_ascii85() calling drm_puts()
in a loop

Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Cc: John Harrison <John.C.Harrison@Intel.com>
Cc: Julia Filipchuk <julia.filipchuk@intel.com>
Cc: José Roberto de Souza <jose.souza@intel.com>
Cc: stable@vger.kernel.org
Fixes: 70fb86a85dc9 ("drm/xe: Revert some changes that break a mesa debug tool")
Fixes: ec1455ce7e35 ("drm/xe/devcoredump: Add ASCII85 dump helper function")
Link: https://patchwork.freedesktop.org/patch/msgid/20250123202307.95103-2-jose.souza@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
(cherry picked from commit 2c95bbf5002776117a69caed3b31c10bf7341bec)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Lucas De Marchi and committed by
Rodrigo Vivi
a9ab6591 042c48b7

+20 -25
+14 -22
drivers/gpu/drm/xe/xe_devcoredump.c
··· 391 391 /** 392 392 * xe_print_blob_ascii85 - print a BLOB to some useful location in ASCII85 393 393 * 394 - * The output is split to multiple lines because some print targets, e.g. dmesg 395 - * cannot handle arbitrarily long lines. Note also that printing to dmesg in 396 - * piece-meal fashion is not possible, each separate call to drm_puts() has a 397 - * line-feed automatically added! Therefore, the entire output line must be 398 - * constructed in a local buffer first, then printed in one atomic output call. 394 + * The output is split into multiple calls to drm_puts() because some print 395 + * targets, e.g. dmesg, cannot handle arbitrarily long lines. These targets may 396 + * add newlines, as is the case with dmesg: each drm_puts() call creates a 397 + * separate line. 399 398 * 400 399 * There is also a scheduler yield call to prevent the 'task has been stuck for 401 400 * 120s' kernel hang check feature from firing when printing to a slow target 402 401 * such as dmesg over a serial port. 403 402 * 404 - * TODO: Add compression prior to the ASCII85 encoding to shrink huge buffers down. 405 - * 406 403 * @p: the printer object to output to 407 404 * @prefix: optional prefix to add to output string 405 + * @suffix: optional suffix to add at the end. 0 disables it and is 406 + * not added to the output, which is useful when using multiple calls 407 + * to dump data to @p 408 408 * @blob: the Binary Large OBject to dump out 409 409 * @offset: offset in bytes to skip from the front of the BLOB, must be a multiple of sizeof(u32) 410 410 * @size: the size in bytes of the BLOB, must be a multiple of sizeof(u32) 411 411 */ 412 - void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix, 412 + void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix, char suffix, 413 413 const void *blob, size_t offset, size_t size) 414 414 { 415 415 const u32 *blob32 = (const u32 *)blob; 416 416 char buff[ASCII85_BUFSZ], *line_buff; 417 417 size_t line_pos = 0; 418 418 419 - /* 420 - * Splitting blobs across multiple lines is not compatible with the mesa 421 - * debug decoder tool. Note that even dropping the explicit '\n' below 422 - * doesn't help because the GuC log is so big some underlying implementation 423 - * still splits the lines at 512K characters. So just bail completely for 424 - * the moment. 425 - */ 426 - return; 427 - 428 419 #define DMESG_MAX_LINE_LEN 800 429 - #define MIN_SPACE (ASCII85_BUFSZ + 2) /* 85 + "\n\0" */ 420 + /* Always leave space for the suffix char and the \0 */ 421 + #define MIN_SPACE (ASCII85_BUFSZ + 2) /* 85 + "<suffix>\0" */ 430 422 431 423 if (size & 3) 432 424 drm_printf(p, "Size not word aligned: %zu", size); ··· 450 458 line_pos += strlen(line_buff + line_pos); 451 459 452 460 if ((line_pos + MIN_SPACE) >= DMESG_MAX_LINE_LEN) { 453 - line_buff[line_pos++] = '\n'; 454 461 line_buff[line_pos++] = 0; 455 462 456 463 drm_puts(p, line_buff); ··· 461 470 } 462 471 } 463 472 464 - if (line_pos) { 465 - line_buff[line_pos++] = '\n'; 466 - line_buff[line_pos++] = 0; 473 + if (suffix) 474 + line_buff[line_pos++] = suffix; 467 475 476 + if (line_pos) { 477 + line_buff[line_pos++] = 0; 468 478 drm_puts(p, line_buff); 469 479 } 470 480
+1 -1
drivers/gpu/drm/xe/xe_devcoredump.h
··· 29 29 } 30 30 #endif 31 31 32 - void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix, 32 + void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix, char suffix, 33 33 const void *blob, size_t offset, size_t size); 34 34 35 35 #endif
+2 -1
drivers/gpu/drm/xe/xe_guc_ct.c
··· 1724 1724 snapshot->g2h_outstanding); 1725 1725 1726 1726 if (snapshot->ctb) 1727 - xe_print_blob_ascii85(p, "CTB data", snapshot->ctb, 0, snapshot->ctb_size); 1727 + xe_print_blob_ascii85(p, "CTB data", '\n', 1728 + snapshot->ctb, 0, snapshot->ctb_size); 1728 1729 } else { 1729 1730 drm_puts(p, "CT disabled\n"); 1730 1731 }
+3 -1
drivers/gpu/drm/xe/xe_guc_log.c
··· 211 211 remain = snapshot->size; 212 212 for (i = 0; i < snapshot->num_chunks; i++) { 213 213 size_t size = min(GUC_LOG_CHUNK_SIZE, remain); 214 + const char *prefix = i ? NULL : "Log data"; 215 + char suffix = i == snapshot->num_chunks - 1 ? '\n' : 0; 214 216 215 - xe_print_blob_ascii85(p, i ? NULL : "Log data", snapshot->copy[i], 0, size); 217 + xe_print_blob_ascii85(p, prefix, suffix, snapshot->copy[i], 0, size); 216 218 remain -= size; 217 219 } 218 220 }