Large devcoredump file support
Subsystems (2)
Matthew Brost
maintainercover Large devcoredump file support
Devcoredump were truncated at 2G, remove this restriction. While here, add support for GPU copies of BOs to increase devcoredump speed.
Matthew Brost (2):
drm/xe: Add devcoredump chunking
drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access
drivers/gpu/drm/xe/xe_bo.c | 15 +- drivers/gpu/drm/xe/xe_devcoredump.c | 59 ++++-- drivers/gpu/drm/xe/xe_devcoredump_types.h | 2 + drivers/gpu/drm/xe/xe_guc_hwconfig.c | 2 +- drivers/gpu/drm/xe/xe_migrate.c | 219 ++++++++++++++++++++-- drivers/gpu/drm/xe/xe_migrate.h | 4 + 6 files changed, 271 insertions(+), 30 deletions(-)
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 1/2 drm/xe: Add devcoredump chunking
Chunk devcoredump into 1.5G pieces to avoid hitting the kvmalloc limit of 2G. Simple algorithm reads 1.5G at time in xe_devcoredump_read callback as needed.
--- drivers/gpu/drm/xe/xe_devcoredump.c | 59 ++++++++++++++++++----- drivers/gpu/drm/xe/xe_devcoredump_types.h | 2 + drivers/gpu/drm/xe/xe_guc_hwconfig.c | 2 +- 3 files changed, 50 insertions(+), 13 deletions(-)
drivers/gpu/drm/xe/xe_devcoredump.c +47 -12
@@ -80,7 +80,8 @@ static struct xe_guc *exec_queue_to_guc(struct xe_exec_queue *q)return &q->gt->uc.guc; } -static ssize_t __xe_devcoredump_read (char *buffer,size_t count, +static ssize_t __xe_devcoredump_read (char *buffer,ssize_t count, +ssize_t start,struct xe_devcoredump *coredump) {struct xe_device *xe;
@@ -94,7 +95,7 @@ static ssize_t __xe_devcoredump_read(char *buffer, size_t count, ss = &coredump->snapshot; iter.data = buffer; - iter.start =0 ; + iter.start = start; iter.remain = count; p =drm_coredump_printer (&iter);
@@ -168,6 +169,8 @@ static void xe_devcoredump_snapshot_free(struct xe_devcoredump_snapshot *ss) ss->vm =NULL ; } +#define XE_DEVCOREDUMP_CHUNK_MAX (SZ_512M + SZ_1G) +static ssize_t xe_devcoredump_read (char *buffer,loff_t offset,size_t count,void *data,size_t datalen) {
@@ -183,6 +186,9 @@ static ssize_t xe_devcoredump_read(char *buffer, loff_t offset,/* Ensure delayed work is captured before continuing */ flush_work (&ss->work); +if (ss->read.size >XE_DEVCOREDUMP_CHUNK_MAX ) +xe_pm_runtime_get (gt_to_xe (ss->gt)); +mutex_lock (&coredump->lock);if (!ss->read.buffer) {
@@ -195,12 +201,26 @@ static ssize_t xe_devcoredump_read(char *buffer, loff_t offset,return 0 ; } +if (offset >= ss->read.chunk_position +XE_DEVCOREDUMP_CHUNK_MAX || + offset < ss->read.chunk_position) { + ss->read.chunk_position = +ALIGN_DOWN (offset,XE_DEVCOREDUMP_CHUNK_MAX ); + +__xe_devcoredump_read (ss->read.buffer, +XE_DEVCOREDUMP_CHUNK_MAX , + ss->read.chunk_position, coredump); + } + byte_copied = count < ss->read.size - offset ? count : ss->read.size - offset; -memcpy (buffer, ss->read.buffer + offset, byte_copied); +memcpy (buffer, ss->read.buffer + + (offset %XE_DEVCOREDUMP_CHUNK_MAX ), byte_copied);mutex_unlock (&coredump->lock); +if (ss->read.size >XE_DEVCOREDUMP_CHUNK_MAX ) +xe_pm_runtime_put (gt_to_xe (ss->gt)); +return byte_copied; }
@@ -254,17 +274,32 @@ static void xe_devcoredump_deferred_snap_work(struct work_struct *work)xe_guc_exec_queue_snapshot_capture_delayed (ss->ge);xe_force_wake_put (gt_to_fw (ss->gt), fw_ref); -xe_pm_runtime_put (xe); + ss->read.chunk_position =0 ;/* Calculate devcoredump size */ - ss->read.size =__xe_devcoredump_read (NULL ,INT_MAX , coredump); - - ss->read.buffer =kvmalloc (ss->read.size,GFP_USER ); -if (!ss->read.buffer) -return ; + ss->read.size =__xe_devcoredump_read (NULL ,LONG_MAX ,0 , coredump); + +if (ss->read.size >XE_DEVCOREDUMP_CHUNK_MAX ) { + ss->read.buffer =kvmalloc (XE_DEVCOREDUMP_CHUNK_MAX , +GFP_USER ); +if (!ss->read.buffer) + goto put_pm; + +__xe_devcoredump_read (ss->read.buffer, +XE_DEVCOREDUMP_CHUNK_MAX , +0 , coredump); + }else { + ss->read.buffer =kvmalloc (ss->read.size,GFP_USER ); +if (!ss->read.buffer) + goto put_pm; + +__xe_devcoredump_read (ss->read.buffer, ss->read.size,0 , + coredump); +xe_devcoredump_snapshot_free (ss); + } -__xe_devcoredump_read (ss->read.buffer, ss->read.size, coredump); -xe_devcoredump_snapshot_free (ss); +put_pm: +xe_pm_runtime_put (xe); } static void devcoredump_snapshot(struct xe_devcoredump *coredump,
@@ -425,7 +460,7 @@ void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix, char suffiif (offset &3 )drm_printf (p,"Offset not word aligned: %zu" , offset); - line_buff =kzalloc (DMESG_MAX_LINE_LEN ,GFP_KERNEL ); + line_buff =kzalloc (DMESG_MAX_LINE_LEN ,GFP_ATOMIC );if (!line_buff) {drm_printf (p,"Failed to allocate line buffer\n" );return ;
drivers/gpu/drm/xe/xe_devcoredump_types.h +2 -0
@@ -66,6 +66,8 @@ struct xe_devcoredump_snapshot {struct {/** @read.size: size of devcoredump in human readable format */ ssize_t size; +/** @read.chunk_position: position of devcoredump chunk */ +ssize_t chunk_position;/** @read.buffer: buffer of devcoredump in human readable format */ char *buffer; } read;
drivers/gpu/drm/xe/xe_guc_hwconfig.c +1 -1
@@ -175,7 +175,7 @@ int xe_guc_hwconfig_lookup_u32(struct xe_guc *guc, u32 attribute, u32 *val)if (num_dw ==0 )return -EINVAL ; - hwconfig =kzalloc (size,GFP_KERNEL ); + hwconfig =kzalloc (size,GFP_ATOMIC );if (!hwconfig)return -ENOMEM ;
Signature · 1 line
2.34.1
Matthew Brost
maintainerRe: [PATCH 1/2] drm/xe: Add devcoredump chunking
Quoted 5 lines · Matthew Brost
Chunk devcoredump into 1.5G pieces to avoid hitting the kvmalloc limit of 2G. Simple algorithm reads 1.5G at time in
xe_devcoredump_readcallback as needed.Signed-off-by Matthew Brost <[email protected]>
Worth noting with this, we still have some O(N^2) characteristics within the xe_devcoredump_read callback so large devcoredump, say 6G, take about 1.5 minutes to read out on BMG. We could move this to snap worker by allocating multiple buffers via kvalloc - it would take the same amount of time but would be in the worker. The readout would be faster then once the worker completes. Easy to make this change if we decide on that direction.
Matt
Quoted 155 lines
--- drivers/gpu/drm/xe/xe_devcoredump.c | 59 ++++++++++++++++++----- drivers/gpu/drm/xe/xe_devcoredump_types.h | 2 + drivers/gpu/drm/xe/xe_guc_hwconfig.c | 2 +- 3 files changed, 50 insertions(+), 13 deletions(-)drivers/gpu/drm/xe/xe_devcoredump.c +47
-12@@ -80,7 +80,8 @@ static struct xe_guc *exec_queue_to_guc(struct xe_exec_queue *q)return &q->gt->uc.guc; } -static ssize_t __xe_devcoredump_read (char *buffer,size_t count, +static ssize_t __xe_devcoredump_read (char *buffer,ssize_t count, +ssize_t start,struct xe_devcoredump *coredump) {struct xe_device *xe;@@ -94,7 +95,7 @@ static ssize_t __xe_devcoredump_read(char *buffer, size_t count, ss = &coredump->snapshot; iter.data = buffer; - iter.start =0 ; + iter.start = start; iter.remain = count; p =drm_coredump_printer (&iter);@@ -168,6 +169,8 @@ static void xe_devcoredump_snapshot_free(struct xe_devcoredump_snapshot *ss) ss->vm =NULL ; } +#define XE_DEVCOREDUMP_CHUNK_MAX (SZ_512M + SZ_1G) +static ssize_t xe_devcoredump_read (char *buffer,loff_t offset,size_t count,void *data,size_t datalen) {@@ -183,6 +186,9 @@ static ssize_t xe_devcoredump_read(char *buffer, loff_t offset,/* Ensure delayed work is captured before continuing */ flush_work (&ss->work); +if (ss->read.size >XE_DEVCOREDUMP_CHUNK_MAX ) +xe_pm_runtime_get (gt_to_xe (ss->gt)); +mutex_lock (&coredump->lock);if (!ss->read.buffer) {@@ -195,12 +201,26 @@ static ssize_t xe_devcoredump_read(char *buffer, loff_t offset,return 0 ; } +if (offset >= ss->read.chunk_position +XE_DEVCOREDUMP_CHUNK_MAX || + offset < ss->read.chunk_position) { + ss->read.chunk_position = +ALIGN_DOWN (offset,XE_DEVCOREDUMP_CHUNK_MAX ); + +__xe_devcoredump_read (ss->read.buffer, +XE_DEVCOREDUMP_CHUNK_MAX , + ss->read.chunk_position, coredump); + } + byte_copied = count < ss->read.size - offset ? count : ss->read.size - offset; -memcpy (buffer, ss->read.buffer + offset, byte_copied); +memcpy (buffer, ss->read.buffer + + (offset %XE_DEVCOREDUMP_CHUNK_MAX ), byte_copied);mutex_unlock (&coredump->lock); +if (ss->read.size >XE_DEVCOREDUMP_CHUNK_MAX ) +xe_pm_runtime_put (gt_to_xe (ss->gt)); +return byte_copied; }@@ -254,17 +274,32 @@ static void xe_devcoredump_deferred_snap_work(struct work_struct *work)xe_guc_exec_queue_snapshot_capture_delayed (ss->ge);xe_force_wake_put (gt_to_fw (ss->gt), fw_ref); -xe_pm_runtime_put (xe); + ss->read.chunk_position =0 ;/* Calculate devcoredump size */ - ss->read.size =__xe_devcoredump_read (NULL ,INT_MAX , coredump); - - ss->read.buffer =kvmalloc (ss->read.size,GFP_USER ); -if (!ss->read.buffer) -return ; + ss->read.size =__xe_devcoredump_read (NULL ,LONG_MAX ,0 , coredump); + +if (ss->read.size >XE_DEVCOREDUMP_CHUNK_MAX ) { + ss->read.buffer =kvmalloc (XE_DEVCOREDUMP_CHUNK_MAX , +GFP_USER ); +if (!ss->read.buffer) + goto put_pm; + +__xe_devcoredump_read (ss->read.buffer, +XE_DEVCOREDUMP_CHUNK_MAX , +0 , coredump); + }else { + ss->read.buffer =kvmalloc (ss->read.size,GFP_USER ); +if (!ss->read.buffer) + goto put_pm; + +__xe_devcoredump_read (ss->read.buffer, ss->read.size,0 , + coredump); +xe_devcoredump_snapshot_free (ss); + } -__xe_devcoredump_read (ss->read.buffer, ss->read.size, coredump); -xe_devcoredump_snapshot_free (ss); +put_pm: +xe_pm_runtime_put (xe); } static void devcoredump_snapshot(struct xe_devcoredump *coredump,@@ -425,7 +460,7 @@ void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix, char suffiif (offset &3 )drm_printf (p,"Offset not word aligned: %zu" , offset); - line_buff =kzalloc (DMESG_MAX_LINE_LEN ,GFP_KERNEL ); + line_buff =kzalloc (DMESG_MAX_LINE_LEN ,GFP_ATOMIC );if (!line_buff) {drm_printf (p,"Failed to allocate line buffer\n" );return ;drivers/gpu/drm/xe/xe_devcoredump_types.h +2
-0@@ -66,6 +66,8 @@ struct xe_devcoredump_snapshot {struct {/** @read.size: size of devcoredump in human readable format */ ssize_t size; +/** @read.chunk_position: position of devcoredump chunk */ +ssize_t chunk_position;/** @read.buffer: buffer of devcoredump in human readable format */ char *buffer; } read;drivers/gpu/drm/xe/xe_guc_hwconfig.c +1
-1@@ -175,7 +175,7 @@ int xe_guc_hwconfig_lookup_u32(struct xe_guc *guc, u32 attribute, u32 *val)if (num_dw ==0 )return -EINVAL ; - hwconfig =kzalloc (size,GFP_KERNEL ); + hwconfig =kzalloc (size,GFP_ATOMIC );if (!hwconfig)return -ENOMEM ;Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 2/2 drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access
In reply to Matthew BrostAdd migrate layer functions to access VRAM and update xe_ttm_access_memory to use for non-visible access and large (more than 16k) BO access. 8G devcoreump on BMG observed 3 minute CPU copy time vs. 3s GPU copy time.
v4:
- Fix non-page aligned accesses
- Add support for small / unaligned access
- Update commit message indicating migrate used for large accesses (Auld)
- Fix warning in xe_res_cursor for non-zero offset
v5:
- Fix 32 bit build (CI)
v6:
- Rebase and use SVM migration copy functions
--- drivers/gpu/drm/xe/xe_bo.c | 15 ++- drivers/gpu/drm/xe/xe_migrate.c | 219 ++++++++++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_migrate.h | 4 + 3 files changed, 221 insertions(+), 17 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +11 -4
@@ -1414,6 +1414,7 @@ static int xe_ttm_access_memory(struct ttm_buffer_object *ttm_bo,struct xe_res_cursor cursor;struct xe_vram_region *vram;int bytes_left = len; +int err =0 ;xe_bo_assert_held (bo);xe_device_assert_mem_access (xe);
@@ -1421,9 +1422,14 @@ static int xe_ttm_access_memory(struct ttm_buffer_object *ttm_bo,if (!mem_type_is_vram (ttm_bo->resource->mem_type))return -EIO ; -/* FIXME: Use GPU for non-visible VRAM */ -if (!xe_ttm_resource_visible (ttm_bo->resource)) -return -EIO ; +if (!xe_ttm_resource_visible (ttm_bo->resource) || len >=SZ_16K ) { +struct xe_migrate *migrate = +mem_type_to_migrate (xe, ttm_bo->resource->mem_type); + + err =xe_migrate_access_memory (migrate, bo, offset, buf, len, + write); + goto out; + } vram =res_to_mem_region (ttm_bo->resource); xe_res_first(ttm_bo->resource, offset & PAGE_MASK,
@@ -1447,7 +1453,8 @@ static int xe_ttm_access_memory(struct ttm_buffer_object *ttm_bo,xe_res_next (&cursor,PAGE_SIZE ); }while (bytes_left); -return len; +out: +return err ?: len; }const struct ttm_device_funcs xe_ttm_funcs = {
drivers/gpu/drm/xe/xe_migrate.c +206 -13
278 lines not on this page · raw message
drivers/gpu/drm/xe/xe_migrate.h +4 -0
@@ -112,6 +112,10 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,struct ttm_resource *dst, bool copy_only_ccs); +int xe_migrate_access_memory (struct xe_migrate *m,struct xe_bo *bo, +unsigned long offset,void *buf,int len, +int write); +#define XE_MIGRATE_CLEAR_FLAG_BO_DATA BIT(0)#define XE_MIGRATE_CLEAR_FLAG_CCS_DATA BIT(1)#define XE_MIGRATE_CLEAR_FLAG_FULL (XE_MIGRATE_CLEAR_FLAG_BO_DATA | \
Signature · 1 line
2.34.1
Patchwork
CI✓ CI.Patch_applied: success for Large devcoredump file support
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: Large devcoredump file support
URL : https://patchwork.freedesktop.org/series/147085/
State : success
== Summary ==
=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 2dda6162c8d9 drm-tip: 2025y-04m-01d-20h-22m-36s UTC integration manifest === git am output follows ===
Applying: drm/xe: Add devcoredump chunking
Applying: drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access
Patchwork
CI✓ CI.checkpatch: success for Large devcoredump file support
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: Large devcoredump file support
URL : https://patchwork.freedesktop.org/series/147085/
State : success
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 99e5a866b5e13f134e606a3e29d9508d97826fb3
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit b1b8be18d6473f947deba912f8b7f3f461a1de06
Author: Matthew Brost <[email protected]> Date: Tue Apr 1 13:43:51 2025 -0700
drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access
Add migrate layer functions to access VRAM and update xe_ttm_access_memory to use for non-visible access and large (more than 16k) BO access. 8G devcoreump on BMG observed 3 minute CPU copy time vs. 3s GPU copy time.
v4:
- Fix non-page aligned accesses
- Add support for small / unaligned access
- Update commit message indicating migrate used for large accesses (Auld)
- Fix warning in xe_res_cursor for non-zero offset
v5:
- Fix 32 bit build (CI)
v6:
- Rebase and use SVM migration copy functions
+ /mt/dim checkpatch 2dda6162c8d942406173d92a4cd3f23ea8a45696 drm-intel 054b7afbea46 drm/xe: Add devcoredump chunkingb1b8be18d647 drm/xe: Update xe_ttm_access_memory to use GPU for non-visible access
Patchwork
CI✗ CI.KUnit: failure for Large devcoredump file support
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: Large devcoredump file support
URL : https://patchwork.freedesktop.org/series/147085/
State : failure
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../drivers/gpu/drm/xe/xe_migrate.c: In function ‘xe_migrate_access_memory’:../drivers/gpu/drm/xe/xe_migrate.c:1819:19: error: ‘CACHELINE_MASK’ undeclared (first use in this function)
1819 | if (len & CACHELINE_MASK || ((uintptr_t)buf | offset) & CACHELINE_MASK) {
| ^~~~~~~~~~~~~~
../drivers/gpu/drm/xe/xe_migrate.c:1819:19: note: each undeclared identifier is reported only once for each function it appears in
../drivers/gpu/drm/xe/xe_migrate.c:1827:35: error: ‘CACHELINE_BYTES’ undeclared (first use in this function)
1827 | u8 bounce[CACHELINE_BYTES];
| ^~~~~~~~~~~~~~~../drivers/gpu/drm/xe/xe_migrate.c:1827:28: warning: unused variable ‘bounce’ [-Wunused-variable]
1827 | u8 bounce[CACHELINE_BYTES];
| ^~~~~~../drivers/gpu/drm/xe/xe_migrate.c:1886:27: error: implicit declaration of function ‘xe_migrate_vram’; did you mean ‘xe_migrate_to_vram’? [-Werror=implicit-function-declaration]
1886 | __fence = xe_migrate_vram(m, current_bytes,
| ^~~~~~~~~~~~~~~
| xe_migrate_to_vram
../drivers/gpu/drm/xe/xe_migrate.c:1890:43: error: ‘XE_MIGRATE_COPY_TO_VRAM’ undeclared (first use in this function)
1890 | XE_MIGRATE_COPY_TO_VRAM :
| ^~~~~~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/xe_migrate.c:1891:43: error: ‘XE_MIGRATE_COPY_TO_SRAM’ undeclared (first use in this function)
1891 | XE_MIGRATE_COPY_TO_SRAM);
| ^~~~~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
make[7]: *** [../scripts/Makefile.build:207: drivers/gpu/drm/xe/xe_migrate.o] Error 1 make[7]: *** Waiting for unfinished jobs....../lib/iomap.c:156:5: warning: no previous prototype for ‘ioread64_lo_hi’ [-Wmissing-prototypes]
156 | u64 ioread64_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:163:5: warning: no previous prototype for ‘ioread64_hi_lo’ [-Wmissing-prototypes]
163 | u64 ioread64_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:170:5: warning: no previous prototype for ‘ioread64be_lo_hi’ [-Wmissing-prototypes]
170 | u64 ioread64be_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:178:5: warning: no previous prototype for ‘ioread64be_hi_lo’ [-Wmissing-prototypes]
178 | u64 ioread64be_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:264:6: warning: no previous prototype for ‘iowrite64_lo_hi’ [-Wmissing-prototypes]
264 | void iowrite64_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:272:6: warning: no previous prototype for ‘iowrite64_hi_lo’ [-Wmissing-prototypes]
272 | void iowrite64_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:280:6: warning: no previous prototype for ‘iowrite64be_lo_hi’ [-Wmissing-prototypes]
280 | void iowrite64be_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
../lib/iomap.c:288:6: warning: no previous prototype for ‘iowrite64be_hi_lo’ [-Wmissing-prototypes]
288 | void iowrite64be_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~make[6]: *** [../scripts/Makefile.build:465: drivers/gpu/drm/xe] Error 2 make[6]: *** Waiting for unfinished jobs....
make[5]: *** [../scripts/Makefile.build:465: drivers/gpu/drm] Error 2 make[4]: *** [../scripts/Makefile.build:465: drivers/gpu] Error 2 make[3]: *** [../scripts/Makefile.build:465: drivers] Error 2 make[2]: *** [/kernel/Makefile:1994: .] Error 2
make[1]: *** [/kernel/Makefile:251: __sub-make] Error 2
make: *** [Makefile:251: __sub-make] Error 2
[20:48:05] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [20:48:09] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel