]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe/userptr: Fix an incorrect assert
authorThomas Hellström <thomas.hellstrom@linux.intel.com>
Fri, 7 Mar 2025 10:01:09 +0000 (11:01 +0100)
committerThomas Hellström <thomas.hellstrom@linux.intel.com>
Sat, 8 Mar 2025 11:43:05 +0000 (12:43 +0100)
The assert incorrectly checks the total length processed which
can in fact be greater than the number of pages. Fix.

Fixes: ea3e66d280ce ("drm/xe/hmm: Don't dereference struct page pointers without notifier lock")
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250307100109.21397-1-thomas.hellstrom@linux.intel.com
drivers/gpu/drm/xe/xe_hmm.c

index 392102515f3d8f7dae6c2af4d7876a7211da7823..c3cc0fa105e84add4f8767415c4f961b490a668a 100644 (file)
@@ -138,13 +138,17 @@ static int xe_build_sg(struct xe_device *xe, struct hmm_range *range,
                i += size;
 
                if (unlikely(j == st->nents - 1)) {
+                       xe_assert(xe, i >= npages);
                        if (i > npages)
                                size -= (i - npages);
+
                        sg_mark_end(sgl);
+               } else {
+                       xe_assert(xe, i < npages);
                }
+
                sg_set_page(sgl, page, size << PAGE_SHIFT, 0);
        }
-       xe_assert(xe, i == npages);
 
        return dma_map_sgtable(dev, st, write ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE,
                               DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_NO_KERNEL_MAPPING);