From patchwork Sun Apr 24 07:31:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8920071 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C74629F6FA for ; Sun, 24 Apr 2016 07:32:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C7E9620219 for ; Sun, 24 Apr 2016 07:32:31 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9EEDF2024F for ; Sun, 24 Apr 2016 07:32:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6C0366E30C; Sun, 24 Apr 2016 07:32:19 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9366F6E159 for ; Sun, 24 Apr 2016 07:32:15 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id r12so14279311wme.0 for ; Sun, 24 Apr 2016 00:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=c1wU/1qRRu3QytRwaNTJwvduAlGDBL5VkZ9Srlki4w0=; b=w5BDVqUPvX2AGayZE+x44hAh2QXybZ6kYguGoxZE32v/ggads91Lb43Pp0kS6DmNMH rx5Oftb/ZaEEXAXn5Mhe/IyVC0Bz03KttBBNj0J/BVGJLDhqb1gQsuSw9lmKeZ7IQ+7J yNzr8WHylIUt/M2rSn/Kh1M+YPLi8oNILoiJvR+bEfTO6z1Hbf09CWUpAdRvYewaEIFH PbIhi0J0JEtoYKVRz8yE2WAWITJae3ma3i4kGI5xnJIu35iWqn0NdukTDcrKPzB9bJ9U RfzBowImmG2BGrDZmiC9w1Rjh9FJeR1U1ciFAi8TWNTvQKeag1uArEu/SyoSDq8AG9ux xKiw== 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:cc:subject:date:message-id :in-reply-to:references; bh=c1wU/1qRRu3QytRwaNTJwvduAlGDBL5VkZ9Srlki4w0=; b=QexT5UHw8yC6fUug/MKeBhvMm/0udndtTCsg9a3zJscyu4NlxXByXGW8kppqzV60nj cJjnleb16+PcWZvq14yhZ/SOTX4Ogk1CoZnTkyv6Fe1ZbsGNXjRT1hDy5/oHqKOFClSu E5OPVk4UhlbZs9h/LeEhJOdJn3vKV5nJF+SU3e5iPYUi2V1XFHxTScClWFQZQsxrseTw VGpxjuE06rTFn2MHSjmPVm/4ey41N6wJBK7z8l14Zi3VqgSVRLRMVgIwvicf7AJwsEJO FRCJr2LoKrisRbVuDXc2csAmrdQqebboXdwtphdD4n+6o3Pu+nEwYh49/yiD8Rsrx1Z5 YPzg== X-Gm-Message-State: AOPr4FVLYOwfFdLx9D4nF4Oy4vtV2WjOoDnuM6CgyOmX0zrAYc4Upln0Fll9dRBHD+OnbQ== X-Received: by 10.28.223.136 with SMTP id w130mr5547340wmg.4.1461483134098; Sun, 24 Apr 2016 00:32:14 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id c4sm16964833wjm.24.2016.04.24.00.32.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 24 Apr 2016 00:32:13 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Sun, 24 Apr 2016 08:31:38 +0100 Message-Id: <1461483101-10618-18-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1461483101-10618-1-git-send-email-chris@chris-wilson.co.uk> References: <1461483101-10618-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH v2 18/21] 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);