From patchwork Thu Aug 8 19:00:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 2841344 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B94E59F294 for ; Thu, 8 Aug 2013 19:05:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4815F20117 for ; Thu, 8 Aug 2013 19:05:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 98FFB2010E for ; Thu, 8 Aug 2013 19:05:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 79F99E6248 for ; Thu, 8 Aug 2013 12:05:09 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (s16502780.onlinehome-server.info [87.106.93.118]) by gabe.freedesktop.org (Postfix) with ESMTP id 63D1BE5F92 for ; Thu, 8 Aug 2013 12:00:44 -0700 (PDT) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.73.22; Received: from haswell.alporthouse.com (unverified [78.156.73.22]) by fireflyinternet.com (Firefly Internet (M2)) with ESMTP id 12483917-1500048 for multiple; Thu, 08 Aug 2013 20:00:48 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 8 Aug 2013 20:00:26 +0100 Message-Id: <1375988426-4713-2-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 1.8.4.rc1 In-Reply-To: <1375988426-4713-1-git-send-email-chris@chris-wilson.co.uk> References: <20130808171205.GB12344@bwidawsk.net> <1375988426-4713-1-git-send-email-chris@chris-wilson.co.uk> X-Originating-IP: 78.156.73.22 Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 2/2] drm/i915: Prevent loading of uninitialized context garbage X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 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+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The extended state bits are stored in the LCA register and affect all updates to the LCA register - i.e. the state on the old context is saved when SAVE_EX_STATE_EN is currently set in the old context address before the update, and the new context is restored when RESTORE_EX_STATE_EN is set in the new context address. This is irrespective of the RESTORE_INHIBIT flag in the MI_SET_CONTEXT. Hence, upon initial loading the contents of the extended state is read from uninitialised data. To workaround this, on first load we do a dummy load without the mandatory RESTORE_EX_STATE_EN bit so that the real load causes us to initialise the extended state of the context before it is then loaded by the LCA update. v2: Split out the introduction of the variable length MI_SET_CONTEXT command sequence. References: https://bugs.freedesktop.org/show_bug.cgi?id=64073 Signed-off-by: Chris Wilson Cc: Ben Widawsky Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/i915/i915_gem_context.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 8a7b61e..a57d49a 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -367,6 +367,8 @@ mi_set_context(struct intel_ring_buffer *ring, case 5: len += 2; break; } + if (!new_context->is_initialized) + len += 2; ret = intel_ring_begin(ring, len); if (ret) @@ -382,6 +384,22 @@ mi_set_context(struct intel_ring_buffer *ring, break; } + if (!new_context->is_initialized) { + /* The GPU tries to restore the extended state irrespective + * of RestoreInhibit (since it is part of the LCA switch + * itself rather than the MI_SET_CONTEXT command). + * Since the initial contents may be garbage we do a dummy + * load first then set the mandatory flag for any future + * ring context switches. + */ + intel_ring_emit(ring, MI_SET_CONTEXT); + intel_ring_emit(ring, + i915_gem_obj_ggtt_offset(new_context->obj) | + MI_MM_SPACE_GTT | + MI_SAVE_EXT_STATE_EN | + hw_flags); + } + intel_ring_emit(ring, MI_NOOP); intel_ring_emit(ring, MI_SET_CONTEXT); intel_ring_emit(ring, i915_gem_obj_ggtt_offset(new_context->obj) |