@@ -100,6 +100,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
100
100
st -> nents = 0 ;
101
101
for (i = 0 ; i < page_count ; i ++ ) {
102
102
struct folio * folio ;
103
+ unsigned long nr_pages ;
103
104
const unsigned int shrink [] = {
104
105
I915_SHRINK_BOUND | I915_SHRINK_UNBOUND ,
105
106
0 ,
@@ -150,20 +151,22 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
150
151
}
151
152
} while (1 );
152
153
154
+ nr_pages = min_t (unsigned long ,
155
+ folio_nr_pages (folio ), page_count - i );
153
156
if (!i ||
154
157
sg -> length >= max_segment ||
155
158
folio_pfn (folio ) != next_pfn ) {
156
159
if (i )
157
160
sg = sg_next (sg );
158
161
159
162
st -> nents ++ ;
160
- sg_set_folio (sg , folio , folio_size ( folio ) , 0 );
163
+ sg_set_folio (sg , folio , nr_pages * PAGE_SIZE , 0 );
161
164
} else {
162
165
/* XXX: could overflow? */
163
- sg -> length += folio_size ( folio ) ;
166
+ sg -> length += nr_pages * PAGE_SIZE ;
164
167
}
165
- next_pfn = folio_pfn (folio ) + folio_nr_pages ( folio ) ;
166
- i += folio_nr_pages ( folio ) - 1 ;
168
+ next_pfn = folio_pfn (folio ) + nr_pages ;
169
+ i += nr_pages - 1 ;
167
170
168
171
/* Check that the i965g/gm workaround works. */
169
172
GEM_BUG_ON (gfp & __GFP_DMA32 && next_pfn >= 0x00100000UL );
0 commit comments