Skip to content

Commit 757a939

Browse files
icklejlahtine-intel
authored andcommitted
drm/i915/gem: Avoid iterating an empty list
Our __sgt_iter assumes that the scattergather list has at least one element. But during construction we may fail in allocating the first page, and so mark the first element as the terminator. This is unexpected! [22555.524752] RIP: 0010:shmem_get_pages+0x506/0x710 [i915] [22555.524759] Code: 49 8b 2c 24 31 c0 66 89 44 24 40 48 85 ed 0f 84 62 01 00 00 4c 8b 75 00 8b 5d 08 44 8b 7d 0c 48 8b 0d 7e 34 07 e2 49 83 e6 fc <49> 8b 16 41 01 df 48 89 cf 48 89 d0 48 c1 e8 2d 48 85 c9 0f 84 c8 [22555.524765] RSP: 0018:ffffc9000053f9d0 EFLAGS: 00010246 [22555.524770] RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffff8881ffffa000 [22555.524774] RDX: fffffffffffffff4 RSI: ffffffffffffffff RDI: ffffffff821efe00 [22555.524778] RBP: ffff8881b099ab00 R08: 0000000000000000 R09: 00000000fffffff4 [22555.524782] R10: 0000000000000002 R11: 00000000ffec0a02 R12: ffff8881cd3c8d60 [22555.524786] R13: 00000000fffffff4 R14: 0000000000000000 R15: 0000000000000000 [22555.524790] FS: 00007f4fbeb9b9c0(0000) GS:ffff8881f8580000(0000) knlGS:0000000000000000 [22555.524795] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [22555.524799] CR2: 0000000000000000 CR3: 00000001ec7f0004 CR4: 00000000001606e0 [22555.524803] Call Trace: [22555.524919] __i915_gem_object_get_pages+0x4f/0x60 [i915] Fixes: 85d1225 ("drm/i915: Introduce & use new lightweight SGL iterators") Signed-off-by: Chris Wilson <[email protected]> Cc: Matthew Auld <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Cc: <[email protected]> # v4.8+ Reviewed-by: Matthew Auld <[email protected]> Reviewed-by: Maciej Patelczyk <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 957ad9a) Signed-off-by: Joonas Lahtinen <[email protected]>
1 parent ef29440 commit 757a939

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/gpu/drm/i915/gem/i915_gem_shmem.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj)
3939
unsigned long last_pfn = 0; /* suppress gcc warning */
4040
unsigned int max_segment = i915_sg_segment_size();
4141
unsigned int sg_page_sizes;
42-
struct pagevec pvec;
4342
gfp_t noreclaim;
4443
int ret;
4544

@@ -192,13 +191,17 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj)
192191
sg_mark_end(sg);
193192
err_pages:
194193
mapping_clear_unevictable(mapping);
195-
pagevec_init(&pvec);
196-
for_each_sgt_page(page, sgt_iter, st) {
197-
if (!pagevec_add(&pvec, page))
194+
if (sg != st->sgl) {
195+
struct pagevec pvec;
196+
197+
pagevec_init(&pvec);
198+
for_each_sgt_page(page, sgt_iter, st) {
199+
if (!pagevec_add(&pvec, page))
200+
check_release_pagevec(&pvec);
201+
}
202+
if (pagevec_count(&pvec))
198203
check_release_pagevec(&pvec);
199204
}
200-
if (pagevec_count(&pvec))
201-
check_release_pagevec(&pvec);
202205
sg_free_table(st);
203206
kfree(st);
204207

0 commit comments

Comments
 (0)