Skip to content

Commit ced7866

Browse files
matt-auldrodrigovivi
authored andcommitted
drm/i915/ttm: fix 32b build
Since segment_pages is no longer a compile time constant, it looks the DIV_ROUND_UP(node->size, segment_pages) breaks the 32b build. Simplest is just to use the ULL variant, but really we should need not need more than u32 for the page alignment (also we are limited by that due to the sg->length type), so also make it all u32. Reported-by: Ville Syrjälä <[email protected]> Fixes: aff1e0b ("drm/i915/ttm: fix sg_table construction") Signed-off-by: Matthew Auld <[email protected]> Cc: Nirmoy Das <[email protected]> Reviewed-by: Nirmoy Das <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 9306b2b) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 333991c commit ced7866

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ __i915_gem_object_create_region(struct intel_memory_region *mem,
6060
if (page_size)
6161
default_page_size = page_size;
6262

63+
/* We should be able to fit a page within an sg entry */
64+
GEM_BUG_ON(overflows_type(default_page_size, u32));
6365
GEM_BUG_ON(!is_power_of_2_u64(default_page_size));
6466
GEM_BUG_ON(default_page_size < PAGE_SIZE);
6567

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
620620
struct ttm_resource *res)
621621
{
622622
struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
623-
u64 page_alignment;
623+
u32 page_alignment;
624624

625625
if (!i915_ttm_gtt_binds_lmem(res))
626626
return i915_ttm_tt_get_st(bo->ttm);

drivers/gpu/drm/i915/i915_scatterlist.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ void i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size)
7979
*/
8080
struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
8181
u64 region_start,
82-
u64 page_alignment)
82+
u32 page_alignment)
8383
{
84-
const u64 max_segment = round_down(UINT_MAX, page_alignment);
85-
u64 segment_pages = max_segment >> PAGE_SHIFT;
84+
const u32 max_segment = round_down(UINT_MAX, page_alignment);
85+
const u32 segment_pages = max_segment >> PAGE_SHIFT;
8686
u64 block_size, offset, prev_end;
8787
struct i915_refct_sgt *rsgt;
8888
struct sg_table *st;
@@ -96,7 +96,7 @@ struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
9696

9797
i915_refct_sgt_init(rsgt, node->size << PAGE_SHIFT);
9898
st = &rsgt->table;
99-
if (sg_alloc_table(st, DIV_ROUND_UP(node->size, segment_pages),
99+
if (sg_alloc_table(st, DIV_ROUND_UP_ULL(node->size, segment_pages),
100100
GFP_KERNEL)) {
101101
i915_refct_sgt_put(rsgt);
102102
return ERR_PTR(-ENOMEM);
@@ -123,7 +123,7 @@ struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
123123
st->nents++;
124124
}
125125

126-
len = min(block_size, max_segment - sg->length);
126+
len = min_t(u64, block_size, max_segment - sg->length);
127127
sg->length += len;
128128
sg_dma_len(sg) += len;
129129

@@ -155,11 +155,11 @@ struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
155155
*/
156156
struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
157157
u64 region_start,
158-
u64 page_alignment)
158+
u32 page_alignment)
159159
{
160160
struct i915_ttm_buddy_resource *bman_res = to_ttm_buddy_resource(res);
161161
const u64 size = res->num_pages << PAGE_SHIFT;
162-
const u64 max_segment = round_down(UINT_MAX, page_alignment);
162+
const u32 max_segment = round_down(UINT_MAX, page_alignment);
163163
struct drm_buddy *mm = bman_res->mm;
164164
struct list_head *blocks = &bman_res->blocks;
165165
struct drm_buddy_block *block;
@@ -207,7 +207,7 @@ struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
207207
st->nents++;
208208
}
209209

210-
len = min(block_size, max_segment - sg->length);
210+
len = min_t(u64, block_size, max_segment - sg->length);
211211
sg->length += len;
212212
sg_dma_len(sg) += len;
213213

drivers/gpu/drm/i915/i915_scatterlist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ void i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size);
214214

215215
struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node,
216216
u64 region_start,
217-
u64 page_alignment);
217+
u32 page_alignment);
218218

219219
struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
220220
u64 region_start,
221-
u64 page_alignment);
221+
u32 page_alignment);
222222

223223
#endif

drivers/gpu/drm/i915/intel_region_ttm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int intel_region_ttm_fini(struct intel_memory_region *mem)
163163
struct i915_refct_sgt *
164164
intel_region_ttm_resource_to_rsgt(struct intel_memory_region *mem,
165165
struct ttm_resource *res,
166-
u64 page_alignment)
166+
u32 page_alignment)
167167
{
168168
if (mem->is_range_manager) {
169169
struct ttm_range_mgr_node *range_node =

drivers/gpu/drm/i915/intel_region_ttm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int intel_region_ttm_fini(struct intel_memory_region *mem);
2525
struct i915_refct_sgt *
2626
intel_region_ttm_resource_to_rsgt(struct intel_memory_region *mem,
2727
struct ttm_resource *res,
28-
u64 page_alignment);
28+
u32 page_alignment);
2929

3030
void intel_region_ttm_resource_free(struct intel_memory_region *mem,
3131
struct ttm_resource *res);

0 commit comments

Comments
 (0)