From patchwork Fri Aug 6 20:18:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 12423801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C26DBC4338F for ; Fri, 6 Aug 2021 20:19:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ED65D610E7 for ; Fri, 6 Aug 2021 20:19:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ED65D610E7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 218AF6EC2F; Fri, 6 Aug 2021 20:19:01 +0000 (UTC) Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2ED216EC2C for ; Fri, 6 Aug 2021 20:19:00 +0000 (UTC) Received: by mail-wm1-x329.google.com with SMTP id m28-20020a05600c3b1cb02902b5a8c22575so6701497wms.0 for ; Fri, 06 Aug 2021 13:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JzNYMrnlk25kaqg3GJt4v8XpQcz3cvah8/eHxHOAK/c=; b=jEeWJ7CW+Kl28i/SOQgNmEI2KT/qFMPFChEsk/2Myvg6SmCnkGuj5YhwjT81eMvzsJ Dh5brCjb1blAVcaHnfFmbVeLUPoLUZpcWFbGnVTzztXWYSiHPQ7v2yzr6ldTzExptYvd YSAIdvmeUGcYmvccYIC1HYZvsfSzQtXHyHlm0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JzNYMrnlk25kaqg3GJt4v8XpQcz3cvah8/eHxHOAK/c=; b=mePQzrx8U6WG6jYPkR6LJ7NtFcUXhrR1hSzgzy9PO7UcIvAyhzLOuEIjZKWYeIPndG VU7EKVnz5qbNXw/OtWAig+Shwg1FStorWJ74wkaISdCdab0988S17WD48y4PnGgZHzDX vyRns29ZWVvr8j1hQqfBCALXSO56SxRHGbArWGt0EHuBTNJ5gtiI2QXxiMqWDEx7ulNW +H4xBoKNn3oqURHpDq0BKynrb9EfYcSBc9xaSGlvaBqLuRh60qntDFRU06tWLKwn7pwE Fj2VE2jn8QJ5ICio28DCEWWrxKTlBCWqH4d05XLvCoQurCMZfPxl0tm375DZN0hNMfMj 2cbw== X-Gm-Message-State: AOAM533atPUqryoDyDp5TTcgyauMflR+ymA+xt9s290V5Izjk0HYszWj k8Zz7yZUyEsHwqmdSj6eR4zwOu0n9j7g5w== X-Google-Smtp-Source: ABdhPJx444izl8xf50OEfuubagJ0v+nHguK+/zcJR6dQ7UGhYt7upiwuRFnlDjRZk32suzg5QgyNeQ== X-Received: by 2002:a05:600c:1ca7:: with SMTP id k39mr4964799wms.162.1628281138700; Fri, 06 Aug 2021 13:18:58 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 19sm12888354wmj.48.2021.08.06.13.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Aug 2021 13:18:58 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Cc: DRI Development , Daniel Vetter , Daniel Vetter , Jason Ekstrand , Chris Wilson , Tvrtko Ursulin , Joonas Lahtinen , Matthew Brost , Matthew Auld , Maarten Lankhorst , =?utf-8?q?Thomas_Hel?= =?utf-8?q?lstr=C3=B6m?= , Lionel Landwerlin , Dave Airlie Date: Fri, 6 Aug 2021 22:18:52 +0200 Message-Id: <20210806201852.1345184-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] drm/i915: Release ctx->syncobj on final put, not on ctx close X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" gem context refcounting is another exercise in least locking design it seems, where most things get destroyed upon context closure (which can race with anything really). Only the actual memory allocation and the locks survive while holding a reference. This tripped up Jason when reimplementing the single timeline feature in commit 00dae4d3d35d4f526929633b76e00b0ab4d3970d Author: Jason Ekstrand Date: Thu Jul 8 10:48:12 2021 -0500 drm/i915: Implement SINGLE_TIMELINE with a syncobj (v4) We could fix the bug by holding ctx->mutex, but it's cleaner to just make the context object actually invariant over its _entire_ lifetime. Signed-off-by: Daniel Vetter Fixes: 00dae4d3d35d ("drm/i915: Implement SINGLE_TIMELINE with a syncobj (v4)") Cc: Jason Ekstrand Cc: Chris Wilson Cc: Tvrtko Ursulin Cc: Joonas Lahtinen Cc: Matthew Brost Cc: Matthew Auld Cc: Maarten Lankhorst Cc: "Thomas Hellström" Cc: Lionel Landwerlin Cc: Dave Airlie --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 754b9b8d4981..93ba0197d70a 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -940,6 +940,9 @@ void i915_gem_context_release(struct kref *ref) trace_i915_context_free(ctx); GEM_BUG_ON(!i915_gem_context_is_closed(ctx)); + if (ctx->syncobj) + drm_syncobj_put(ctx->syncobj); + mutex_destroy(&ctx->engines_mutex); mutex_destroy(&ctx->lut_mutex); @@ -1159,9 +1162,6 @@ static void context_close(struct i915_gem_context *ctx) if (vm) i915_vm_close(vm); - if (ctx->syncobj) - drm_syncobj_put(ctx->syncobj); - ctx->file_priv = ERR_PTR(-EBADF); /*