Skip to content

Commit c60b93c

Browse files
icklerodrigovivi
authored andcommitted
drm/i915: Avoid mixing integer types during batch copies
Be consistent and use unsigned long throughout the chunk copies to avoid the inherent clumsiness of mixing integer types of different widths and signs. Failing to take acount of a wider unsigned type when using min_t can lead to treating it as a negative, only for it flip back to a large unsigned value after passing a boundary check. Fixes: ed13033 ("drm/i915/cmdparser: Only cache the dst vmap") Testcase: igt/gen9_exec_parse/bb-large Reported-by: "Candelaria, Jared" <[email protected]> Signed-off-by: Chris Wilson <[email protected]> Cc: Mika Kuoppala <[email protected]> Cc: Joonas Lahtinen <[email protected]> Cc: "Candelaria, Jared" <[email protected]> Cc: "Bloomfield, Jon" <[email protected]> Cc: <[email protected]> # v4.9+ Reviewed-by: Mika Kuoppala <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit b7eeb2b) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 651dabe commit c60b93c

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,8 +2267,8 @@ struct eb_parse_work {
22672267
struct i915_vma *batch;
22682268
struct i915_vma *shadow;
22692269
struct i915_vma *trampoline;
2270-
unsigned int batch_offset;
2271-
unsigned int batch_length;
2270+
unsigned long batch_offset;
2271+
unsigned long batch_length;
22722272
};
22732273

22742274
static int __eb_parse(struct dma_fence_work *work)
@@ -2338,6 +2338,9 @@ static int eb_parse_pipeline(struct i915_execbuffer *eb,
23382338
struct eb_parse_work *pw;
23392339
int err;
23402340

2341+
GEM_BUG_ON(overflows_type(eb->batch_start_offset, pw->batch_offset));
2342+
GEM_BUG_ON(overflows_type(eb->batch_len, pw->batch_length));
2343+
23412344
pw = kzalloc(sizeof(*pw), GFP_KERNEL);
23422345
if (!pw)
23432346
return -ENOMEM;

drivers/gpu/drm/i915/i915_cmd_parser.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ find_reg(const struct intel_engine_cs *engine, u32 addr)
11361136
/* Returns a vmap'd pointer to dst_obj, which the caller must unmap */
11371137
static u32 *copy_batch(struct drm_i915_gem_object *dst_obj,
11381138
struct drm_i915_gem_object *src_obj,
1139-
u32 offset, u32 length)
1139+
unsigned long offset, unsigned long length)
11401140
{
11411141
bool needs_clflush;
11421142
void *dst, *src;
@@ -1166,8 +1166,8 @@ static u32 *copy_batch(struct drm_i915_gem_object *dst_obj,
11661166
}
11671167
}
11681168
if (IS_ERR(src)) {
1169+
unsigned long x, n;
11691170
void *ptr;
1170-
int x, n;
11711171

11721172
/*
11731173
* We can avoid clflushing partial cachelines before the write
@@ -1184,7 +1184,7 @@ static u32 *copy_batch(struct drm_i915_gem_object *dst_obj,
11841184
ptr = dst;
11851185
x = offset_in_page(offset);
11861186
for (n = offset >> PAGE_SHIFT; length; n++) {
1187-
int len = min_t(int, length, PAGE_SIZE - x);
1187+
int len = min(length, PAGE_SIZE - x);
11881188

11891189
src = kmap_atomic(i915_gem_object_get_page(src_obj, n));
11901190
if (needs_clflush)
@@ -1414,8 +1414,8 @@ static bool shadow_needs_clflush(struct drm_i915_gem_object *obj)
14141414
*/
14151415
int intel_engine_cmd_parser(struct intel_engine_cs *engine,
14161416
struct i915_vma *batch,
1417-
u32 batch_offset,
1418-
u32 batch_length,
1417+
unsigned long batch_offset,
1418+
unsigned long batch_length,
14191419
struct i915_vma *shadow,
14201420
bool trampoline)
14211421
{

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,8 @@ void intel_engine_init_cmd_parser(struct intel_engine_cs *engine);
19491949
void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine);
19501950
int intel_engine_cmd_parser(struct intel_engine_cs *engine,
19511951
struct i915_vma *batch,
1952-
u32 batch_offset,
1953-
u32 batch_length,
1952+
unsigned long batch_offset,
1953+
unsigned long batch_length,
19541954
struct i915_vma *shadow,
19551955
bool trampoline);
19561956
#define I915_CMD_PARSER_TRAMPOLINE_SIZE 8

0 commit comments

Comments
 (0)