Skip to content

Commit d766ef5

Browse files
committed
drm/i915: Fallback to single PAGE_SIZE segments for DMA remapping
If we at first do not succeed with attempting to remap our physical pages using a coalesced scattergather list, try again with one scattergather entry per page. This should help with swiotlb as it uses a limited buffer size and only searches for contiguous chunks within its buffer aligned up to the next boundary - i.e. we may prematurely cause a failure as we are unable to utilize the unused space between large chunks and trigger an error such as: i915 0000:00:02.0: swiotlb buffer is full (sz: 1630208 bytes) Reported-by: Juergen Gross <jgross@suse.com> Tested-by: Juergen Gross <jgross@suse.com> Fixes: 871dfbd ("drm/i915: Allow compaction upto SWIOTLB max segment size") Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Imre Deak <imre.deak@intel.com> Cc: <drm-intel-fixes@lists.freedesktop.org> Link: http://patchwork.freedesktop.org/patch/msgid/20161219124346.550-1-chris@chris-wilson.co.uk Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent d856786 commit d766ef5

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,8 @@ static struct sg_table *
23432343
i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
23442344
{
23452345
struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
2346-
int page_count, i;
2346+
const unsigned long page_count = obj->base.size / PAGE_SIZE;
2347+
unsigned long i;
23472348
struct address_space *mapping;
23482349
struct sg_table *st;
23492350
struct scatterlist *sg;
@@ -2369,7 +2370,7 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
23692370
if (st == NULL)
23702371
return ERR_PTR(-ENOMEM);
23712372

2372-
page_count = obj->base.size / PAGE_SIZE;
2373+
rebuild_st:
23732374
if (sg_alloc_table(st, page_count, GFP_KERNEL)) {
23742375
kfree(st);
23752376
return ERR_PTR(-ENOMEM);
@@ -2428,8 +2429,25 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
24282429
i915_sg_trim(st);
24292430

24302431
ret = i915_gem_gtt_prepare_pages(obj, st);
2431-
if (ret)
2432-
goto err_pages;
2432+
if (ret) {
2433+
/* DMA remapping failed? One possible cause is that
2434+
* it could not reserve enough large entries, asking
2435+
* for PAGE_SIZE chunks instead may be helpful.
2436+
*/
2437+
if (max_segment > PAGE_SIZE) {
2438+
for_each_sgt_page(page, sgt_iter, st)
2439+
put_page(page);
2440+
sg_free_table(st);
2441+
2442+
max_segment = PAGE_SIZE;
2443+
goto rebuild_st;
2444+
} else {
2445+
dev_warn(&dev_priv->drm.pdev->dev,
2446+
"Failed to DMA remap %lu pages\n",
2447+
page_count);
2448+
goto err_pages;
2449+
}
2450+
}
24332451

24342452
if (i915_gem_object_needs_bit17_swizzle(obj))
24352453
i915_gem_object_do_bit_17_swizzle(obj, st);

0 commit comments

Comments
 (0)