Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C46F8C05027 for ; Mon, 6 Feb 2023 09:36:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229861AbjBFJgD (ORCPT ); Mon, 6 Feb 2023 04:36:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjBFJgA (ORCPT ); Mon, 6 Feb 2023 04:36:00 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2FA312F3D for ; Mon, 6 Feb 2023 01:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675676159; x=1707212159; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=OV4hu9Cv4oGEnss556qD7ZX4r/ehOr4vxxDxMa+/ABo=; b=Wfbjp2AIM3/y2oVw5ILHnF1Kq8tZ5DhZAScTXfT05edJthfId7wChJ7S G96AVGMw+a1U1W3SoZQ/xvKSpuU0PkSUFr726Zqudz+c6UIN8OXP2Wnif gqUa5l72c32TjHE6daTlIDUPst4rkiZ94NN0IYIJ2Om4BalBOB1vjjhyn Zsxx+zitbsnOtJKjj6hntXjN8MH4hbAv2pJdiaO/5MSib1Ej40DxLAFyL EXiGXBRfzqYmgwduB84WeCzTvnEaGBXbru08ZTE60pkf2H+qxygVTNpLY 9ahguB4wap75to8vwKea3rTZjQ7wZ6Rm2qkkbJY04b+cXyCrgZa7MM5vU A==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="330458340" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="330458340" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 01:35:59 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="668360569" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="668360569" Received: from vastrong-mobl.amr.corp.intel.com (HELO [10.213.203.226]) ([10.213.203.226]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 01:35:54 -0800 Message-ID: Date: Mon, 6 Feb 2023 09:35:52 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] drm/i915: Move fd_install after last use of fence Content-Language: en-US To: Rob Clark , dri-devel@lists.freedesktop.org, Matthew Brost Cc: Tvrtko Ursulin , Rob Clark , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , Matthew Auld , Andrzej Hajda , Niranjana Vishwanathapura , Maarten Lankhorst , Nirmoy Das , "Jason A. Donenfeld" , =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= , intel-gfx@lists.freedesktop.org, open list , jason.ekstrand@collabora.com References: <20230203164937.4035503-1-robdclark@gmail.com> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/02/2023 18:15, Rob Clark wrote: > On Fri, Feb 3, 2023 at 8:49 AM Rob Clark wrote: >> >> From: Rob Clark >> >> Because eb_composite_fence_create() drops the fence_array reference >> after creation of the sync_file, only the sync_file holds a ref to the >> fence. But fd_install() makes that reference visable to userspace, so >> it must be the last thing we do with the fence. >> > > Fixes: 00dae4d3d35d ("drm/i915: Implement SINGLE_TIMELINE with a syncobj (v4)") This is correct and the fix looks good to me. Reviewed-by: Tvrtko Ursulin CI is green so I will merge it, thanks again for a fix Rob! Followup up question for Matthew Brost however is whether the composite fence flow could be simplified. This block here comes late in i915_gem_do_execbuffer and may mislead the user the composite fence is held to the end of the function: if (!out_fence && eb.composite_fence) dma_fence_put(eb.composite_fence); Question is would it work to remove the !out_fence condition from here, and remove "consumption" of the reference from eb_composite_fence_create success path. Regards, Tvrtko >> Signed-off-by: Rob Clark >> --- >> drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 14 +++++++------- >> 1 file changed, 7 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c >> index f266b68cf012..0f2e056c02dd 100644 >> --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c >> +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c >> @@ -3476,38 +3476,38 @@ i915_gem_do_execbuffer(struct drm_device *dev, >> >> err_request: >> eb_requests_get(&eb); >> err = eb_requests_add(&eb, err); >> >> if (eb.fences) >> signal_fence_array(&eb, eb.composite_fence ? >> eb.composite_fence : >> &eb.requests[0]->fence); >> >> + if (unlikely(eb.gem_context->syncobj)) { >> + drm_syncobj_replace_fence(eb.gem_context->syncobj, >> + eb.composite_fence ? >> + eb.composite_fence : >> + &eb.requests[0]->fence); >> + } >> + >> if (out_fence) { >> if (err == 0) { >> fd_install(out_fence_fd, out_fence->file); >> args->rsvd2 &= GENMASK_ULL(31, 0); /* keep in-fence */ >> args->rsvd2 |= (u64)out_fence_fd << 32; >> out_fence_fd = -1; >> } else { >> fput(out_fence->file); >> } >> } >> >> - if (unlikely(eb.gem_context->syncobj)) { >> - drm_syncobj_replace_fence(eb.gem_context->syncobj, >> - eb.composite_fence ? >> - eb.composite_fence : >> - &eb.requests[0]->fence); >> - } >> - >> if (!out_fence && eb.composite_fence) >> dma_fence_put(eb.composite_fence); >> >> eb_requests_put(&eb); >> >> err_vma: >> eb_release_vmas(&eb, true); >> WARN_ON(err == -EDEADLK); >> i915_gem_ww_ctx_fini(&eb.ww); >> >> -- >> 2.38.1 >>