From patchwork Thu Apr 21 14:57:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8901621 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5DAF6BF4C7 for ; Thu, 21 Apr 2016 14:59:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61A2D202EB for ; Thu, 21 Apr 2016 14:59:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4DA3F202F8 for ; Thu, 21 Apr 2016 14:59:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 544246ECE9; Thu, 21 Apr 2016 14:59:44 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 056096ECDD for ; Thu, 21 Apr 2016 14:57:56 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id r12so10433234wme.0 for ; Thu, 21 Apr 2016 07:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=c1wU/1qRRu3QytRwaNTJwvduAlGDBL5VkZ9Srlki4w0=; b=KyKLwWZOLCCSbDZKGocjZjSWqbLXYO0lVC0fBfUTnSNZThaiERurdbj4i0qtIrxzKm /bFwl94TTyiBgIGK45nCdARpX+qvsxBtWBDcqGr5J8xMOL4DpI18MpSqiYjaoQhzlPQC /bX7aBqj+N+McGwSApv+7VQylA+4yknwbPVW6FcWJ8gvxodc1RcuhO10g1mL/aWkkfQk OMtVD+IB/B6C8Y0yGSY05+q76vXgZFKJv4jBd5Y7QLrK73GvytfYlE8fARjVZv7ii28n YIz//hNgcJpTAe2smIzsDcIBbvgZYMXYYYw5cKLBPx4q1HFOOrWV0cKAFfd3oILl2OqH 4Bdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=c1wU/1qRRu3QytRwaNTJwvduAlGDBL5VkZ9Srlki4w0=; b=Ezon4k5Kzag56tKrJSnMRh1XPJEx6mguaOpPWsIJ43VhDBKwLOLXqe72hlfQnzueZX oixzTWlm1471AGIdDiJzza0ntCEJrgX/0GZ7X4IE0/FCn9N5zEggFe49ClADPlTC4T5u kh7kN36Xy7NnhBbXEJSJfTSagtc7eP2OmC/o6SfnX5B86l0VutYPvpXs/X4fe65Bs0WH rqGO75osykXo/HqGqIKyD/8EoqhgxU7pIAjlPZFgBBQFsq59+iCn/aA6PV0H05ZkrEuE e9xtsKxjxbFeEV1a78MPl61aF8N67KO02lA0jDn7HrnANGxiX18TJa3C7T2AwsM699hN HOOQ== X-Gm-Message-State: AOPr4FWg58V7IXpAWVaImYXa/7vDYMJL4lFcPu/nQbxFNxqNB73lsvMfZKHD/wzuNJfSTw== X-Received: by 10.194.133.161 with SMTP id pd1mr17185515wjb.66.1461250673940; Thu, 21 Apr 2016 07:57:53 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id by7sm3261506wjc.18.2016.04.21.07.57.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Apr 2016 07:57:52 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 21 Apr 2016 15:57:25 +0100 Message-Id: <1461250647-7738-18-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1461250647-7738-1-git-send-email-chris@chris-wilson.co.uk> References: <1461250647-7738-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 17/19] drm/i915: Track the previous pinned context inside the request X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 As the contexts are accessed by the hardware until the switch is completed to a new context, the hardware may still be writing to the context object after the breadcrumb is visible. We must not unpin/unbind/prune that object whilst still active and so we keep the previous context pinned until the following request. We can generalise the tracking we already do via the engine->last_context and move it to the request so that it works equally for execlists and GuC. v2: Drop the execlists double pin as that exposes a race inside the lrc irq handler as it tries to access the context after it may be retired. Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_drv.h | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem.c | 8 ++++---- drivers/gpu/drm/i915/intel_lrc.c | 14 ++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index a26a026ef8e2..515b8badce61 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2302,6 +2302,17 @@ struct drm_i915_gem_request { struct intel_context *ctx; struct intel_ringbuffer *ringbuf; + /** + * Context related to the previous request. + * As the contexts are accessed by the hardware until the switch is + * completed to a new context, the hardware may still be writing + * to the context object after the breadcrumb is visible. We must + * not unpin/unbind/prune that object whilst still active and so + * we keep the previous context pinned until the following (this) + * request is retired. + */ + struct intel_context *previous_context; + /** Batch buffer related to this request if any (used for error state dump only) */ struct drm_i915_gem_object *batch_obj; diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 7793f0086523..d16680b77e13 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1413,13 +1413,13 @@ static void i915_gem_request_retire(struct drm_i915_gem_request *request) list_del_init(&request->list); i915_gem_request_remove_from_client(request); - if (request->ctx) { + if (request->previous_context) { if (i915.enable_execlists) - intel_lr_context_unpin(request->ctx, request->engine); - - i915_gem_context_unreference(request->ctx); + intel_lr_context_unpin(request->previous_context, + request->engine); } + i915_gem_context_unreference(request->ctx); i915_gem_request_unreference(request); } diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index 23bc5fca6595..3293dd29e274 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -798,12 +798,14 @@ intel_logical_ring_advance_and_submit(struct drm_i915_gem_request *request) if (intel_engine_stopped(engine)) return 0; - if (engine->last_context != request->ctx) { - if (engine->last_context) - intel_lr_context_unpin(engine->last_context, engine); - intel_lr_context_pin(request->ctx, engine); - engine->last_context = request->ctx; - } + /* We keep the previous context alive until we retire the following + * request. This ensures that any the context object is still pinned + * for any residual writes the HW makes into it on the context switch + * into the next object following the breadcrumb. Otherwise, we may + * retire the context too early. + */ + request->previous_context = engine->last_context; + engine->last_context = request->ctx; if (dev_priv->guc.execbuf_client) i915_guc_submit(dev_priv->guc.execbuf_client, request);