From patchwork Thu Mar 11 21:43:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Owain Ainsworth X-Patchwork-Id: 85096 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2BLhJdR018208 for ; Thu, 11 Mar 2010 21:43:55 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F11BD9EF58; Thu, 11 Mar 2010 13:43:18 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-bw0-f215.google.com (mail-bw0-f215.google.com [209.85.218.215]) by gabe.freedesktop.org (Postfix) with ESMTP id 2CF4E9EE8C for ; Thu, 11 Mar 2010 13:43:16 -0800 (PST) Received: by bwz7 with SMTP id 7so434672bwz.24 for ; Thu, 11 Mar 2010 13:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:received:from:to:cc:subject :date:message-id:x-mailer; bh=H4SKVN1B5oPBFE7kadNOP1QIf6I79IMZjFbLSweB0YA=; b=SW3p/7sMPej68wAU2qVJfmwoISbdpBLecHlFaLrY5PoWrxzB/tcFcL2zmY2enH4Z81 ETaRKJey/I5Qc611CpyvYoeR77f8fKz4xRsL9f7k8C9VogO+3n7ZB0imdTjunCxtGjT8 tOQQTfWVO0+fx9TVbaJGHqwlzt1SZXOIy92g0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=bSs0Xr1nDxyfPUaEkSTqe2vvs3Reh/TVmZhVFgwPi4MeGwpGSPS72nIum8HmTTNTPz Vj+auidaw3pGtfJ1PkIHVSPdupCSrN7OS8VhNlvxEX3fgvn8X1P2lYYRH+titdYefvP/ F13fiwwbJ5SWZxXf+GZMDLkcUO/TFTcLGgpxs= Received: by 10.204.16.194 with SMTP id p2mr607051bka.32.1268343795828; Thu, 11 Mar 2010 13:43:15 -0800 (PST) Received: from stephanie.nicotinebsd.org (ns1.nicotinebsd.org [93.97.176.184]) by mx.google.com with ESMTPS id a11sm1708681bkc.15.2010.03.11.13.43.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 11 Mar 2010 13:43:15 -0800 (PST) Received: from localhost (1000@localhost [IPv6:::1]) by stephanie.nicotinebsd.org (OpenSMTPD) with ESMTP id 1268343792.q7OJ2n47E7XSH71L; Thu, 11 Mar 2010 21:43:13 +0000 (GMT) From: "Owain G. Ainsworth" To: intel-gfx@lists.freedesktop.org Date: Thu, 11 Mar 2010 21:43:01 +0000 Message-Id: <1268343781-13757-1-git-send-email-oga@openbsd.org> X-Mailer: git-send-email 1.6.5.7 Cc: "Owain G. Ainsworth" Subject: [Intel-gfx] [PATCH] drm/i915: check execbuffer for validity earlier to save on work. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 11 Mar 2010 21:43:55 +0000 (UTC) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index e52a277..c4e89e8 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -3653,23 +3653,6 @@ err: return ret; } -static int -i915_gem_check_execbuffer (struct drm_i915_gem_execbuffer2 *exec, - uint64_t exec_offset) -{ - uint32_t exec_start, exec_len; - - exec_start = (uint32_t) exec_offset + exec->batch_start_offset; - exec_len = (uint32_t) exec->batch_len; - - if ((exec_start | exec_len) & 0x7) - return -EINVAL; - - if (!exec_start) - return -EINVAL; - - return 0; -} static int i915_gem_wait_for_pending_flip(struct drm_device *dev, @@ -3727,6 +3710,13 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, DRM_INFO("buffers_ptr %d buffer_count %d len %08x\n", (int) args->buffers_ptr, args->buffer_count, args->batch_len); #endif + /* + * check for valid execbuffer offset. We can do this early because + * bound objects are always page aligned, so only the start offset + * matters. + */ + if ((args->batch_start_offset | args->batch_len) & 0x7) + return -EINVAL; if (args->buffer_count < 1) { DRM_ERROR("execbuf with %d buffers\n", args->buffer_count); @@ -3875,6 +3865,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, ret = -EINVAL; goto err; } + if (args->batch_len > batch_obj->size) { + DRM_ERROR("batchbuffer shorter than program length\n"); + ret = EINVAL; + goto err; + } batch_obj->pending_read_domains |= I915_GEM_DOMAIN_COMMAND; /* Sanity check the batch buffer, prior to moving objects */