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

drm/xe/userptr: Fix an incorrect assert

The assert incorrectly checks the total length processed which
can in fact be greater than the number of pages. Fix.

Fixes: 0a98219bcc96 ("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
(cherry picked from commit 70e5043ba85eae199b232e39921abd706b5c1fa4)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Thomas Hellström and committed by
Rodrigo Vivi
9106713b 10c79884

+5 -1
+5 -1
drivers/gpu/drm/xe/xe_hmm.c
··· 138 138 i += size; 139 139 140 140 if (unlikely(j == st->nents - 1)) { 141 + xe_assert(xe, i >= npages); 141 142 if (i > npages) 142 143 size -= (i - npages); 144 + 143 145 sg_mark_end(sgl); 146 + } else { 147 + xe_assert(xe, i < npages); 144 148 } 149 + 145 150 sg_set_page(sgl, page, size << PAGE_SHIFT, 0); 146 151 } 147 - xe_assert(xe, i == npages); 148 152 149 153 return dma_map_sgtable(dev, st, write ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE, 150 154 DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_NO_KERNEL_MAPPING);