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

drm/xe/migrate: rework size restrictions for sram pte emit

We allow the input size to not be aligned to PAGE_SIZE, which leads to
various bugs in build_pt_update_batch_sram() for PAGE_SIZE > 4K systems.
For example if ptes is exactly one gpu_page_size then the chunk size is
rounded down to zero. The simplest fix looks to be forcing PAGE_SIZE
aligned inputs.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20251022163836.191405-3-matthew.auld@intel.com

+8 -5
+8 -5
drivers/gpu/drm/xe/xe_migrate.c
··· 1798 1798 u32 ptes; 1799 1799 int i = 0; 1800 1800 1801 + xe_tile_assert(m->tile, PAGE_ALIGNED(size)); 1802 + 1801 1803 ptes = DIV_ROUND_UP(size, gpu_page_size); 1802 1804 while (ptes) { 1803 1805 u32 chunk = min(MAX_PTE_PER_SDI, ptes); ··· 1813 1811 ptes -= chunk; 1814 1812 1815 1813 while (chunk--) { 1816 - u64 addr = sram_addr[i].addr & ~(gpu_page_size - 1); 1817 - u64 pte, orig_addr = addr; 1814 + u64 addr = sram_addr[i].addr; 1815 + u64 pte; 1818 1816 1819 1817 xe_tile_assert(m->tile, sram_addr[i].proto == 1820 1818 DRM_INTERCONNECT_SYSTEM); 1821 1819 xe_tile_assert(m->tile, addr); 1820 + xe_tile_assert(m->tile, PAGE_ALIGNED(addr)); 1822 1821 1823 1822 again: 1824 1823 pte = m->q->vm->pt_ops->pte_encode_addr(m->tile->xe, ··· 1830 1827 1831 1828 if (gpu_page_size < PAGE_SIZE) { 1832 1829 addr += XE_PAGE_SIZE; 1833 - if (orig_addr + PAGE_SIZE != addr) { 1830 + if (!PAGE_ALIGNED(addr)) { 1834 1831 chunk--; 1835 1832 goto again; 1836 1833 } ··· 1921 1918 1922 1919 if (use_pde) 1923 1920 build_pt_update_batch_sram(m, bb, m->large_page_copy_pdes, 1924 - sram_addr, len + sram_offset, 1); 1921 + sram_addr, npages << PAGE_SHIFT, 1); 1925 1922 else 1926 1923 build_pt_update_batch_sram(m, bb, pt_slot * XE_PAGE_SIZE, 1927 - sram_addr, len + sram_offset, 0); 1924 + sram_addr, npages << PAGE_SHIFT, 0); 1928 1925 1929 1926 if (dir == XE_MIGRATE_COPY_TO_VRAM) { 1930 1927 if (use_pde)