@@ -1820,15 +1820,19 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
1820
1820
if (!IS_ALIGNED (len , XE_CACHELINE_BYTES ) ||
1821
1821
!IS_ALIGNED ((unsigned long )buf + offset , XE_CACHELINE_BYTES )) {
1822
1822
int buf_offset = 0 ;
1823
+ void * bounce ;
1824
+ int err ;
1825
+
1826
+ BUILD_BUG_ON (!is_power_of_2 (XE_CACHELINE_BYTES ));
1827
+ bounce = kmalloc (XE_CACHELINE_BYTES , GFP_KERNEL );
1828
+ if (!bounce )
1829
+ return - ENOMEM ;
1823
1830
1824
1831
/*
1825
1832
* Less than ideal for large unaligned access but this should be
1826
1833
* fairly rare, can fixup if this becomes common.
1827
1834
*/
1828
1835
do {
1829
- u8 bounce [XE_CACHELINE_BYTES ];
1830
- void * ptr = (void * )bounce ;
1831
- int err ;
1832
1836
int copy_bytes = min_t (int , bytes_left ,
1833
1837
XE_CACHELINE_BYTES -
1834
1838
(offset & XE_CACHELINE_MASK ));
@@ -1837,22 +1841,22 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
1837
1841
err = xe_migrate_access_memory (m , bo ,
1838
1842
offset &
1839
1843
~XE_CACHELINE_MASK ,
1840
- ( void * ) ptr ,
1841
- sizeof ( bounce ) , 0 );
1844
+ bounce ,
1845
+ XE_CACHELINE_BYTES , 0 );
1842
1846
if (err )
1843
- return err ;
1847
+ break ;
1844
1848
1845
1849
if (write ) {
1846
- memcpy (ptr + ptr_offset , buf + buf_offset , copy_bytes );
1850
+ memcpy (bounce + ptr_offset , buf + buf_offset , copy_bytes );
1847
1851
1848
1852
err = xe_migrate_access_memory (m , bo ,
1849
1853
offset & ~XE_CACHELINE_MASK ,
1850
- ( void * ) ptr ,
1851
- sizeof ( bounce ) , write );
1854
+ bounce ,
1855
+ XE_CACHELINE_BYTES , write );
1852
1856
if (err )
1853
- return err ;
1857
+ break ;
1854
1858
} else {
1855
- memcpy (buf + buf_offset , ptr + ptr_offset ,
1859
+ memcpy (buf + buf_offset , bounce + ptr_offset ,
1856
1860
copy_bytes );
1857
1861
}
1858
1862
@@ -1861,7 +1865,8 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
1861
1865
offset += copy_bytes ;
1862
1866
} while (bytes_left );
1863
1867
1864
- return 0 ;
1868
+ kfree (bounce );
1869
+ return err ;
1865
1870
}
1866
1871
1867
1872
dma_addr = xe_migrate_dma_map (xe , buf , len + page_offset , write );
@@ -1882,8 +1887,11 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
1882
1887
else
1883
1888
current_bytes = min_t (int , bytes_left , cursor .size );
1884
1889
1885
- if (fence )
1886
- dma_fence_put (fence );
1890
+ if (current_bytes & ~PAGE_MASK ) {
1891
+ int pitch = 4 ;
1892
+
1893
+ current_bytes = min_t (int , current_bytes , S16_MAX * pitch );
1894
+ }
1887
1895
1888
1896
__fence = xe_migrate_vram (m , current_bytes ,
1889
1897
(unsigned long )buf & ~PAGE_MASK ,
@@ -1892,11 +1900,15 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
1892
1900
XE_MIGRATE_COPY_TO_VRAM :
1893
1901
XE_MIGRATE_COPY_TO_SRAM );
1894
1902
if (IS_ERR (__fence )) {
1895
- if (fence )
1903
+ if (fence ) {
1896
1904
dma_fence_wait (fence , false);
1905
+ dma_fence_put (fence );
1906
+ }
1897
1907
fence = __fence ;
1898
1908
goto out_err ;
1899
1909
}
1910
+
1911
+ dma_fence_put (fence );
1900
1912
fence = __fence ;
1901
1913
1902
1914
buf += current_bytes ;
0 commit comments