Skip to content

Commit 2f5945b

Browse files
ickledanvet
authored andcommitted
drm/i915: Kill DRI1 cliprects
Passing cliprects into the kernel for it to re-execute the batch buffer with different CMD_DRAWRECT died out long ago. As DRI1 support has been removed from the kernel, we can now simply reject any execbuf trying to use this "feature". To keep Daniel happy with the prospect of being able to reuse these fields in the next decade, continue to ensure that current userspace is not passing garbage in through the dead fields. v2: Fix the cliprects_ptr check Signed-off-by: Chris Wilson <[email protected]> Cc: Daniel Vetter <[email protected]> Reviewed-by: Tvrtko Ursulin <[email protected]> Reviewed-by: Dave Gordon <[email protected]> Signed-off-by: Daniel Vetter <[email protected]>
1 parent 5763ff0 commit 2f5945b

File tree

2 files changed

+31
-138
lines changed

2 files changed

+31
-138
lines changed

drivers/gpu/drm/i915/i915_gem_execbuffer.c

Lines changed: 31 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,21 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
945945
if (exec->flags & __I915_EXEC_UNKNOWN_FLAGS)
946946
return false;
947947

948-
return ((exec->batch_start_offset | exec->batch_len) & 0x7) == 0;
948+
/* Kernel clipping was a DRI1 misfeature */
949+
if (exec->num_cliprects || exec->cliprects_ptr)
950+
return false;
951+
952+
if (exec->DR4 == 0xffffffff) {
953+
DRM_DEBUG("UXA submitting garbage DR4, fixing up\n");
954+
exec->DR4 = 0;
955+
}
956+
if (exec->DR1 || exec->DR4)
957+
return false;
958+
959+
if ((exec->batch_start_offset | exec->batch_len) & 0x7)
960+
return false;
961+
962+
return true;
949963
}
950964

951965
static int
@@ -1109,47 +1123,6 @@ i915_reset_gen7_sol_offsets(struct drm_device *dev,
11091123
return 0;
11101124
}
11111125

1112-
static int
1113-
i915_emit_box(struct drm_i915_gem_request *req,
1114-
struct drm_clip_rect *box,
1115-
int DR1, int DR4)
1116-
{
1117-
struct intel_engine_cs *ring = req->ring;
1118-
int ret;
1119-
1120-
if (box->y2 <= box->y1 || box->x2 <= box->x1 ||
1121-
box->y2 <= 0 || box->x2 <= 0) {
1122-
DRM_ERROR("Bad box %d,%d..%d,%d\n",
1123-
box->x1, box->y1, box->x2, box->y2);
1124-
return -EINVAL;
1125-
}
1126-
1127-
if (INTEL_INFO(ring->dev)->gen >= 4) {
1128-
ret = intel_ring_begin(req, 4);
1129-
if (ret)
1130-
return ret;
1131-
1132-
intel_ring_emit(ring, GFX_OP_DRAWRECT_INFO_I965);
1133-
intel_ring_emit(ring, (box->x1 & 0xffff) | box->y1 << 16);
1134-
intel_ring_emit(ring, ((box->x2 - 1) & 0xffff) | (box->y2 - 1) << 16);
1135-
intel_ring_emit(ring, DR4);
1136-
} else {
1137-
ret = intel_ring_begin(req, 6);
1138-
if (ret)
1139-
return ret;
1140-
1141-
intel_ring_emit(ring, GFX_OP_DRAWRECT_INFO);
1142-
intel_ring_emit(ring, DR1);
1143-
intel_ring_emit(ring, (box->x1 & 0xffff) | box->y1 << 16);
1144-
intel_ring_emit(ring, ((box->x2 - 1) & 0xffff) | (box->y2 - 1) << 16);
1145-
intel_ring_emit(ring, DR4);
1146-
intel_ring_emit(ring, 0);
1147-
}
1148-
intel_ring_advance(ring);
1149-
1150-
return 0;
1151-
}
1152-
11531126
static struct drm_i915_gem_object*
11541127
i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
11551128
struct drm_i915_gem_exec_object2 *shadow_exec_entry,
@@ -1208,65 +1181,21 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
12081181
struct drm_i915_gem_execbuffer2 *args,
12091182
struct list_head *vmas)
12101183
{
1211-
struct drm_clip_rect *cliprects = NULL;
12121184
struct drm_device *dev = params->dev;
12131185
struct intel_engine_cs *ring = params->ring;
12141186
struct drm_i915_private *dev_priv = dev->dev_private;
12151187
u64 exec_start, exec_len;
12161188
int instp_mode;
12171189
u32 instp_mask;
1218-
int i, ret = 0;
1219-
1220-
if (args->num_cliprects != 0) {
1221-
if (ring != &dev_priv->ring[RCS]) {
1222-
DRM_DEBUG("clip rectangles are only valid with the render ring\n");
1223-
return -EINVAL;
1224-
}
1225-
1226-
if (INTEL_INFO(dev)->gen >= 5) {
1227-
DRM_DEBUG("clip rectangles are only valid on pre-gen5\n");
1228-
return -EINVAL;
1229-
}
1230-
1231-
if (args->num_cliprects > UINT_MAX / sizeof(*cliprects)) {
1232-
DRM_DEBUG("execbuf with %u cliprects\n",
1233-
args->num_cliprects);
1234-
return -EINVAL;
1235-
}
1236-
1237-
cliprects = kcalloc(args->num_cliprects,
1238-
sizeof(*cliprects),
1239-
GFP_KERNEL);
1240-
if (cliprects == NULL) {
1241-
ret = -ENOMEM;
1242-
goto error;
1243-
}
1244-
1245-
if (copy_from_user(cliprects,
1246-
to_user_ptr(args->cliprects_ptr),
1247-
sizeof(*cliprects)*args->num_cliprects)) {
1248-
ret = -EFAULT;
1249-
goto error;
1250-
}
1251-
} else {
1252-
if (args->DR4 == 0xffffffff) {
1253-
DRM_DEBUG("UXA submitting garbage DR4, fixing up\n");
1254-
args->DR4 = 0;
1255-
}
1256-
1257-
if (args->DR1 || args->DR4 || args->cliprects_ptr) {
1258-
DRM_DEBUG("0 cliprects but dirt in cliprects fields\n");
1259-
return -EINVAL;
1260-
}
1261-
}
1190+
int ret;
12621191

12631192
ret = i915_gem_execbuffer_move_to_gpu(params->request, vmas);
12641193
if (ret)
1265-
goto error;
1194+
return ret;
12661195

12671196
ret = i915_switch_context(params->request);
12681197
if (ret)
1269-
goto error;
1198+
return ret;
12701199

12711200
WARN(params->ctx->ppgtt && params->ctx->ppgtt->pd_dirty_rings & (1<<ring->id),
12721201
"%s didn't clear reload\n", ring->name);
@@ -1279,22 +1208,19 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
12791208
case I915_EXEC_CONSTANTS_REL_SURFACE:
12801209
if (instp_mode != 0 && ring != &dev_priv->ring[RCS]) {
12811210
DRM_DEBUG("non-0 rel constants mode on non-RCS\n");
1282-
ret = -EINVAL;
1283-
goto error;
1211+
return -EINVAL;
12841212
}
12851213

12861214
if (instp_mode != dev_priv->relative_constants_mode) {
12871215
if (INTEL_INFO(dev)->gen < 4) {
12881216
DRM_DEBUG("no rel constants on pre-gen4\n");
1289-
ret = -EINVAL;
1290-
goto error;
1217+
return -EINVAL;
12911218
}
12921219

12931220
if (INTEL_INFO(dev)->gen > 5 &&
12941221
instp_mode == I915_EXEC_CONSTANTS_REL_SURFACE) {
12951222
DRM_DEBUG("rel surface constants mode invalid on gen5+\n");
1296-
ret = -EINVAL;
1297-
goto error;
1223+
return -EINVAL;
12981224
}
12991225

13001226
/* The HW changed the meaning on this bit on gen6 */
@@ -1304,15 +1230,14 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
13041230
break;
13051231
default:
13061232
DRM_DEBUG("execbuf with unknown constants: %d\n", instp_mode);
1307-
ret = -EINVAL;
1308-
goto error;
1233+
return -EINVAL;
13091234
}
13101235

13111236
if (ring == &dev_priv->ring[RCS] &&
1312-
instp_mode != dev_priv->relative_constants_mode) {
1237+
instp_mode != dev_priv->relative_constants_mode) {
13131238
ret = intel_ring_begin(params->request, 4);
13141239
if (ret)
1315-
goto error;
1240+
return ret;
13161241

13171242
intel_ring_emit(ring, MI_NOOP);
13181243
intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
@@ -1326,42 +1251,25 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
13261251
if (args->flags & I915_EXEC_GEN7_SOL_RESET) {
13271252
ret = i915_reset_gen7_sol_offsets(dev, params->request);
13281253
if (ret)
1329-
goto error;
1254+
return ret;
13301255
}
13311256

13321257
exec_len = args->batch_len;
13331258
exec_start = params->batch_obj_vm_offset +
13341259
params->args_batch_start_offset;
13351260

1336-
if (cliprects) {
1337-
for (i = 0; i < args->num_cliprects; i++) {
1338-
ret = i915_emit_box(params->request, &cliprects[i],
1339-
args->DR1, args->DR4);
1340-
if (ret)
1341-
goto error;
1342-
1343-
ret = ring->dispatch_execbuffer(params->request,
1344-
exec_start, exec_len,
1345-
params->dispatch_flags);
1346-
if (ret)
1347-
goto error;
1348-
}
1349-
} else {
1350-
ret = ring->dispatch_execbuffer(params->request,
1351-
exec_start, exec_len,
1352-
params->dispatch_flags);
1353-
if (ret)
1354-
return ret;
1355-
}
1261+
ret = ring->dispatch_execbuffer(params->request,
1262+
exec_start, exec_len,
1263+
params->dispatch_flags);
1264+
if (ret)
1265+
return ret;
13561266

13571267
trace_i915_gem_ring_dispatch(params->request, params->dispatch_flags);
13581268

13591269
i915_gem_execbuffer_move_to_active(vmas, params->request);
13601270
i915_gem_execbuffer_retire_commands(params);
13611271

1362-
error:
1363-
kfree(cliprects);
1364-
return ret;
1272+
return 0;
13651273
}
13661274

13671275
/**

drivers/gpu/drm/i915/intel_lrc.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -902,21 +902,6 @@ int intel_execlists_submission(struct i915_execbuffer_params *params,
902902
return -EINVAL;
903903
}
904904

905-
if (args->num_cliprects != 0) {
906-
DRM_DEBUG("clip rectangles are only valid on pre-gen5\n");
907-
return -EINVAL;
908-
} else {
909-
if (args->DR4 == 0xffffffff) {
910-
DRM_DEBUG("UXA submitting garbage DR4, fixing up\n");
911-
args->DR4 = 0;
912-
}
913-
914-
if (args->DR1 || args->DR4 || args->cliprects_ptr) {
915-
DRM_DEBUG("0 cliprects but dirt in cliprects fields\n");
916-
return -EINVAL;
917-
}
918-
}
919-
920905
if (args->flags & I915_EXEC_GEN7_SOL_RESET) {
921906
DRM_DEBUG("sol reset is gen7 only\n");
922907
return -EINVAL;

0 commit comments

Comments
 (0)