Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4236761rwb; Tue, 6 Sep 2022 04:52:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR5XlIndGkVu+cea6abaDxyDnsjozcJiWYW9PZbg0aV3/jXeO6iRwuNtZT7xy02lAWAtgOKH X-Received: by 2002:a17:90b:1b10:b0:200:934b:741f with SMTP id nu16-20020a17090b1b1000b00200934b741fmr4604885pjb.212.1662465166089; Tue, 06 Sep 2022 04:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662465166; cv=none; d=google.com; s=arc-20160816; b=rvU9nPKBuk2kiCd7oIdDECWk4ilj7BbFvltvbVjWiLhxGjRtkElVTzYw2Yum++sxHk I0Q4oXuRZou3tat9+ToT/VRUA/FM+q7SR8pAnJDAPGPoTv7mU7UKai7N/VHHqq7qAi86 GzViVjma/gBH0o0UV4RewyJS/UovNCXZeTDVKxJIBqXKMthTelZfsyW11a7S7KFF4ewP A/j78xbt5INx6u6LNZ8tSUjw2rTmIvT1+GlYeoy98hTKk9fJ9QGbpQC+22/O4qyHWNmx wmoMM9vsD02fTgz84QBdKasPcUUH4P1FPWYEYdZvpnWG2kdnuwMsDKdulNYOIj9sYz05 GD9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:references:to:from:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=sudkR7dBehiCxaBsmHOtXjmzeaZTXIxuXNHALihpQLk=; b=RpCKFe0/GLLYOlLuxL8vpqYzolWiUGVeGq1rjHvwmD75meyNbERGeAI/49vRiQwxNh uDnOHna6To2m25GgkCzWmTAOfJAogfLBaaJZSvIxjlzQzv5g8zb3rkGb7TL+szUMin3o ahkFVXqI4eTjtTSu/VEn+sm2iYclcHDMkGgy4q+pluI7i4xrwyenTzj0iZil/L0xOkJV mYIpqaxC+uKa6/eoNaaPcxLQc1D3pu1DVeDYwgF+AGmKunRvZPtuz26qHlQgYRWK6DJG C4n25VVRiXCWhB/raxP3PJOyq2mljIQUDovhnDPsR2tAorhkAdt0cl4Ww9ZkTftrEGnI 6h3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QW4szLyI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020a6551c3000000b004346fb165f3si2531569pgq.813.2022.09.06.04.52.34; Tue, 06 Sep 2022 04:52:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QW4szLyI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232209AbiIFLiu (ORCPT + 99 others); Tue, 6 Sep 2022 07:38:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbiIFLis (ORCPT ); Tue, 6 Sep 2022 07:38:48 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1402D76477; Tue, 6 Sep 2022 04:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662464327; x=1694000327; h=message-id:date:mime-version:subject:from:to:references: in-reply-to:content-transfer-encoding; bh=VEJTkGxx44JImk6B2IUdv9204swC+QuEhIl64y3Z40U=; b=QW4szLyIGO6f17I+w7BhxyLNxumUIze+BAxJMRJKL7TJe1Ezc434Dgic 2pJvvg2vlPFag16OEumqfxpjiju/SWvvzCvzJA53hGIXf9HIwqqDZyIoE smcQlYp6BCT/tNqo4sTVQ5GOT8SBOcXAXYLxjk7GRU1lZog0FN/g8JVEx Y/flP2rfGy84wqPvfGOqINpYqzFrV8VgIACMDfG3eFyC9m9FOodOkovHJ nQtYy69SDDupgltT21INCHFHnVI0cIfcKtcrcHhDq5xUGwPMR3VpljiPq RflUzjsxL0j4eRta2QYS56LyIbfxo6qSGP/YqZh6+ys8c/7hh4KlDehbw Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10461"; a="295304850" X-IronPort-AV: E=Sophos;i="5.93,294,1654585200"; d="scan'208";a="295304850" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2022 04:38:46 -0700 X-IronPort-AV: E=Sophos;i="5.93,294,1654585200"; d="scan'208";a="644137416" Received: from holmesda-mobl.ger.corp.intel.com (HELO [10.213.204.21]) ([10.213.204.21]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2022 04:38:43 -0700 Message-ID: Date: Tue, 6 Sep 2022 12:38:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH v2 4/4] dma-buf: Check status of enable-signaling bit on debug Content-Language: en-US From: Tvrtko Ursulin To: =?UTF-8?Q?Christian_K=c3=b6nig?= , Arvind Yadav , andrey.grodzovsky@amd.com, shashank.sharma@amd.com, amaranath.somalapuram@amd.com, Arunpravin.PaneerSelvam@amd.com, sumit.semwal@linaro.org, gustavo@padovan.org, airlied@linux.ie, daniel@ffwll.ch, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org References: <20220905163502.4032-1-Arvind.Yadav@amd.com> <20220905163502.4032-5-Arvind.Yadav@amd.com> <691e636f-07d6-f4d3-6d83-29a3834ac1a2@linux.intel.com> Organization: Intel Corporation UK Plc In-Reply-To: <691e636f-07d6-f4d3-6d83-29a3834ac1a2@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, NICE_REPLY_A,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/09/2022 12:21, Tvrtko Ursulin wrote: > > On 06/09/2022 11:43, Christian König wrote: >> Am 06.09.22 um 12:20 schrieb Tvrtko Ursulin: >>> >>> On 06/09/2022 09:39, Christian König wrote: >>>> Am 05.09.22 um 18:35 schrieb Arvind Yadav: >>>>> The core DMA-buf framework needs to enable signaling >>>>> before the fence is signaled. The core DMA-buf framework >>>>> can forget to enable signaling before the fence is signaled. >>>> >>>> This sentence is a bit confusing. I'm not a native speaker of >>>> English either, but I suggest something like: >>>> >>>> "Fence signaling must be enable to make sure that the >>>> dma_fence_is_signaled() function ever returns true." >>>> >>>>> To avoid this scenario on the debug kernel, check the >>>>> DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT status bit before checking >>>>> the signaling bit status to confirm that enable_signaling >>>>> is enabled. >>>> >>>> This describes the implementation, but we should rather describe the >>>> background of the change. The implementation should be obvious. >>>> Something like this maybe: >>>> >>>> " >>>> Since drivers and implementations sometimes mess this up enforce >>>> correct behavior when DEBUG_WW_MUTEX_SLOWPATH is used during debugging. >>>> >>>> This should make any implementations bugs resulting in not signaled >>>> fences much more obvious. >>>> " >>> >>> I think I follow the idea but am not sure coupling (well "coupling".. >>> not really, but cross-contaminating in a way) dma-fence.c with a >>> foreign and effectively unrelated concept of a ww mutex is the best way. >>> >>> Instead, how about a dma-buf specific debug kconfig option? >> >> Yeah, I was thinking about that as well. > > Cool, lets see about the specifics below and then decide. > >> The slowpath config option was just at hand because when you want to >> test the slowpath you want to test this here as well. >> >>> >>> Condition would then be, according to my understanding of the rules >>> and expectations, along the lines of: >>> >>> diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h >>> index 775cdc0b4f24..147a9df2c9d0 100644 >>> --- a/include/linux/dma-fence.h >>> +++ b/include/linux/dma-fence.h >>> @@ -428,6 +428,17 @@ dma_fence_is_signaled_locked(struct dma_fence >>> *fence) >>>  static inline bool >>>  dma_fence_is_signaled(struct dma_fence *fence) >>>  { >>> +#ifdef CONFIG_DEBUG_DMAFENCE >>> +       /* >>> +        * Implementations not providing the enable_signaling >>> callback are >>> +        * required to always have signaling enabled or fences are not >>> +        * guaranteed to ever signal. >>> +        */ >> >> Well that comment is a bit misleading. The intention of the extra >> check is to find bugs in the frontend and not the backend. > > By backend you mean drivers/dma-buf/dma-fence.c and by front end driver > specific implementations? Or simply users for dma-fence? > > Could be that I got confused.. I was reading these two: > > >      * This callback is optional. If this callback is not present, then > the >      * driver must always have signaling enabled. >      */ >     bool (*enable_signaling)(struct dma_fence *fence); > > And dma_fence_is_signaled: > >  * Returns true if the fence was already signaled, false if not. Since > this >  * function doesn't enable signaling, it is not guaranteed to ever return >  * true if dma_fence_add_callback(), dma_fence_wait() or >  * dma_fence_enable_sw_signaling() haven't been called before. > > Right, I think I did get confused, apologies. What I was thinking was > probably two separate conditions: > >  static inline bool >  dma_fence_is_signaled(struct dma_fence *fence) >  { > +#ifdef CONFIG_DEBUG_DMAFENCE > +       if (WARN_ON_ONCE(!fence->ops->enable_signaling && > +                        !test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, > &fence->flags))) > +               return false; > + > +       if (!test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) > +               return false; > +#endif > + Or simpler OFC: if (!test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) { WARN_ON_ONCE(!fence->ops->enable_signaling); return false; } You could also run this core change past i915 CI to see if it catches anything. Just send to our trybot and see what happens? With the debug option enabled of course. Hope it won't be painful. Regards, Tvrtko >         if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) >                 return true; > > Not sure "is signaled" is the best place for the first one or that it > should definitely be added. > > Regards, > > Tvrtko > >> In other words somewhere in the drm_syncobj code we have a >> dma_fence_is_signaled() call without matching >> dma_fence_enable_sw_signaling(). >> >> Regards, >> Christian. >> >>> + if (!fence->ops->enable_signaling && >>> +           !test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) >>> +               return false; >>> +#endif >>> + >>>         if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) >>>                 return true; >>> >>> Thoughts? >>> >>> Regards, >>> >>> Tvrtko >>> >>>> >>>>> >>>>> Signed-off-by: Arvind Yadav >>>> >>>> With the improved commit message this patch is Reviewed-by: >>>> Christian König >>>> >>>> Regards, >>>> Christian. >>>> >>>>> --- >>>>> >>>>> Changes in v1 : >>>>> 1- Addressing Christian's comment to replace >>>>> CONFIG_DEBUG_WW_MUTEX_SLOWPATH instead of CONFIG_DEBUG_FS. >>>>> 2- As per Christian's comment moving this patch at last so >>>>> The version of this patch is also changed and previously >>>>> it was [PATCH 1/4] >>>>> >>>>> >>>>> --- >>>>>   include/linux/dma-fence.h | 5 +++++ >>>>>   1 file changed, 5 insertions(+) >>>>> >>>>> diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h >>>>> index 775cdc0b4f24..ba1ddc14c5d4 100644 >>>>> --- a/include/linux/dma-fence.h >>>>> +++ b/include/linux/dma-fence.h >>>>> @@ -428,6 +428,11 @@ dma_fence_is_signaled_locked(struct dma_fence >>>>> *fence) >>>>>   static inline bool >>>>>   dma_fence_is_signaled(struct dma_fence *fence) >>>>>   { >>>>> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH >>>>> +    if (!test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) >>>>> +        return false; >>>>> +#endif >>>>> + >>>>>       if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) >>>>>           return true; >>>> >>