Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp353650pxf; Thu, 8 Apr 2021 04:41:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8UdEo1WYsFOdvKKJ8WCiYHEQJ0iLjwf1XwGiucOVUkul/2IxZDO5EzN3XiAh18lOcExw/ X-Received: by 2002:a17:907:3f22:: with SMTP id hq34mr1268837ejc.535.1617882104849; Thu, 08 Apr 2021 04:41:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617882104; cv=none; d=google.com; s=arc-20160816; b=OGiDulcjjvmRuldvELp9BXEgqwmVIXJhyNLIR1rBkoKEAGq7fWNOZOT41xucBjpeN6 K3rtswXUyQC1GSKgJsrOcsJm5iUSTI1+eZrnu9CEI4EylJWgTcQChbIv7MnJrL1/KIVE H9VJhbButdXn3ahj4Pedj+QButtW2qzzbCIUsP3BYP/3Y7MckzMuKVDF6WkM21vueq5G /Y9KfYYKFEOpyeSRIqxwrWyAZCpn8lposib2GhzHlbT/wO5plHBRbY/+WUNkIk6YmKnp BUnvw9Vxvi9wZVpSedrJlkANhYpn9mzVnPkU0Wo/rFsEkvnkR3qkV4+9SjjU8QKbxVBY 4Kqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=FzJ5ukUAxMTdvYbU0dY36FSLXhgIfuX6wIMsxJm4zCk=; b=qT1SeKCVQy05C3eVVNar09pN7PA0ys6Pj6LK2xNEBchs70mkIMA75oLAYNXeaZhn4D h6SioMJWMQvSVCIhah0FlDTTHCDuDScMnClgJkPnxXdGnkYdNZrmy0COScQXbftNqkXR GUiaGJdbYs1Fmd+RxaQ2mmg+2tnSIunXgu1om3dDDoSuDoRsua29vBcjanzPUGIj56SC kQNny8VEOBzkW4uEwtYPrHzhdv1+bGbHOZ1OPsUIkt2I98nnI46RbgP2XdNVUwSzKw3y GFjRinnG8fkrGwDG8rXqKVNO8er5vHXzZA8Rryte05HGalEpW+5Khd8B7R4yg1+tRL/r Wvug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=D6vM216d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si8536451edx.600.2021.04.08.04.41.21; Thu, 08 Apr 2021 04:41:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=D6vM216d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbhDHLkn (ORCPT + 99 others); Thu, 8 Apr 2021 07:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbhDHLkm (ORCPT ); Thu, 8 Apr 2021 07:40:42 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDD34C061760 for ; Thu, 8 Apr 2021 04:40:30 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id p19so1048408wmq.1 for ; Thu, 08 Apr 2021 04:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=FzJ5ukUAxMTdvYbU0dY36FSLXhgIfuX6wIMsxJm4zCk=; b=D6vM216dt5Jl0WDf/SC04ZRKghV1KWZRChfBgm0QtNf9Q5QItQU7F5BdCtI5smfPMW UKgJuvdpnNlHwF0e+RzCANvdJ//IQct2iMAlU94kwJIiTkyxmaj6BMYNn6aJ/B/3Lvfo GD8YySotn1IwUwmP6vC0plhdhzT2OmFGcIzkI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=FzJ5ukUAxMTdvYbU0dY36FSLXhgIfuX6wIMsxJm4zCk=; b=CI8scNU3SpNIXS4/xwA+h0o7Lphd2D499JO1Jr4yhB0Ph+nzH4I7w8QtAPwf5DPFSF qBGYfUAUteO5jGLN+3sCpAbtxi6Mtn5yUSLNv/RYx2lGaNcNRKkc4Orl7D0x0CDulb/X u0mcHFIUqE9xPGYhXFh1TjHJxNzJPsfuBndEntFvCZFQHWo8XLruP6MF1/GYhQri0c/2 JC0sLjYE33BuSuS/457+aZz8Wsv0G+ovVrK4BlhfPX11rA9lADxW5FegnbYgNBCx9lsp xs0j/hWvH/ERuowR6HDbEumBDs4fjydLUzOQ7bxqYPlcholWKK4fgqm9WFVxCE+GTwwl iAdg== X-Gm-Message-State: AOAM533sPPtV4DLNCuP2R6tWCaYy1M9+RKbcDrXwecRep2pegXbva+aS uCHVVPLQGHmTBCSU+GDw5tGVrg== X-Received: by 2002:a1c:b689:: with SMTP id g131mr7717312wmf.138.1617882029495; Thu, 08 Apr 2021 04:40:29 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id e13sm51100126wrg.72.2021.04.08.04.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 04:40:28 -0700 (PDT) Date: Thu, 8 Apr 2021 13:40:26 +0200 From: Daniel Vetter To: David Stevens Cc: Christian =?iso-8859-1?Q?K=F6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Sumit Semwal , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: Re: [PATCH] drm/syncobj: use newly allocated stub fences Message-ID: Mail-Followup-To: David Stevens , Christian =?iso-8859-1?Q?K=F6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Sumit Semwal , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org References: <20210408093448.3897988-1-stevensd@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210408093448.3897988-1-stevensd@google.com> X-Operating-System: Linux phenom 5.7.0-1-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 08, 2021 at 06:34:48PM +0900, David Stevens wrote: > From: David Stevens > > Allocate a new private stub fence in drm_syncobj_assign_null_handle, > instead of using a static stub fence. > > When userspace creates a fence with DRM_SYNCOBJ_CREATE_SIGNALED or when > userspace signals a fence via DRM_IOCTL_SYNCOBJ_SIGNAL, the timestamp > obtained when the fence is exported and queried with SYNC_IOC_FILE_INFO > should match when the fence's status was changed from the perspective of > userspace, which is during the respective ioctl. > > When a static stub fence started being used in by these ioctls, this > behavior changed. Instead, the timestamp returned by SYNC_IOC_FILE_INFO > became the first time anything used the static stub fence, which has no > meaning to userspace. > > Signed-off-by: David Stevens Is there also an igt patch to enforce this in the drm_syncobj testcases? Would be really good to have that too. -Daniel > --- > drivers/dma-buf/dma-fence.c | 33 ++++++++++++++++++++++++++++++++- > drivers/gpu/drm/drm_syncobj.c | 28 ++++++++++++++++++++-------- > include/linux/dma-fence.h | 1 + > 3 files changed, 53 insertions(+), 9 deletions(-) > > diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c > index d64fc03929be..6081eb962490 100644 > --- a/drivers/dma-buf/dma-fence.c > +++ b/drivers/dma-buf/dma-fence.c > @@ -26,6 +26,11 @@ EXPORT_TRACEPOINT_SYMBOL(dma_fence_signaled); > static DEFINE_SPINLOCK(dma_fence_stub_lock); > static struct dma_fence dma_fence_stub; > > +struct drm_fence_private_stub { > + struct dma_fence base; > + spinlock_t lock; > +}; > + > /* > * fence context counter: each execution context should have its own > * fence context, this allows checking if fences belong to the same > @@ -123,7 +128,9 @@ static const struct dma_fence_ops dma_fence_stub_ops = { > /** > * dma_fence_get_stub - return a signaled fence > * > - * Return a stub fence which is already signaled. > + * Return a stub fence which is already signaled. The fence's > + * timestamp corresponds to the first time after boot this > + * function is called. > */ > struct dma_fence *dma_fence_get_stub(void) > { > @@ -141,6 +148,30 @@ struct dma_fence *dma_fence_get_stub(void) > } > EXPORT_SYMBOL(dma_fence_get_stub); > > +/** > + * dma_fence_allocate_private_stub - return a private, signaled fence > + * > + * Return a newly allocated and signaled stub fence. > + */ > +struct dma_fence *dma_fence_allocate_private_stub(void) > +{ > + struct drm_fence_private_stub *fence; > + > + fence = kzalloc(sizeof(*fence), GFP_KERNEL); > + if (fence == NULL) > + return ERR_PTR(-ENOMEM); > + > + spin_lock_init(&fence->lock); > + dma_fence_init(&fence->base, > + &dma_fence_stub_ops, > + &fence->lock, > + 0, 0); > + dma_fence_signal(&fence->base); > + > + return &fence->base; > +} > +EXPORT_SYMBOL(dma_fence_allocate_private_stub); > + > /** > * dma_fence_context_alloc - allocate an array of fence contexts > * @num: amount of contexts to allocate > diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c > index 349146049849..c6125e57ae37 100644 > --- a/drivers/gpu/drm/drm_syncobj.c > +++ b/drivers/gpu/drm/drm_syncobj.c > @@ -350,12 +350,15 @@ EXPORT_SYMBOL(drm_syncobj_replace_fence); > * > * Assign a already signaled stub fence to the sync object. > */ > -static void drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) > +static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) > { > - struct dma_fence *fence = dma_fence_get_stub(); > + struct dma_fence *fence = dma_fence_allocate_private_stub(); > + if (IS_ERR(fence)) > + return PTR_ERR(fence); > > - drm_syncobj_replace_fence(syncobj, fence); > - dma_fence_put(fence); > + drm_syncobj_replace_fence(syncobj, fence); > + dma_fence_put(fence); > + return 0; > } > > /* 5s default for wait submission */ > @@ -469,6 +472,7 @@ EXPORT_SYMBOL(drm_syncobj_free); > int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, > struct dma_fence *fence) > { > + int ret; > struct drm_syncobj *syncobj; > > syncobj = kzalloc(sizeof(struct drm_syncobj), GFP_KERNEL); > @@ -479,8 +483,13 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, > INIT_LIST_HEAD(&syncobj->cb_list); > spin_lock_init(&syncobj->lock); > > - if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) > - drm_syncobj_assign_null_handle(syncobj); > + if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { > + ret = drm_syncobj_assign_null_handle(syncobj); > + if (ret < 0) { > + drm_syncobj_put(syncobj); > + return ret; > + } > + } > > if (fence) > drm_syncobj_replace_fence(syncobj, fence); > @@ -1322,8 +1331,11 @@ drm_syncobj_signal_ioctl(struct drm_device *dev, void *data, > if (ret < 0) > return ret; > > - for (i = 0; i < args->count_handles; i++) > - drm_syncobj_assign_null_handle(syncobjs[i]); > + for (i = 0; i < args->count_handles; i++) { > + ret = drm_syncobj_assign_null_handle(syncobjs[i]); > + if (ret < 0) > + break; > + } > > drm_syncobj_array_free(syncobjs, args->count_handles); > > diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h > index 9f12efaaa93a..6ffb4b2c6371 100644 > --- a/include/linux/dma-fence.h > +++ b/include/linux/dma-fence.h > @@ -587,6 +587,7 @@ static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr) > } > > struct dma_fence *dma_fence_get_stub(void); > +struct dma_fence *dma_fence_allocate_private_stub(void); > u64 dma_fence_context_alloc(unsigned num); > > #define DMA_FENCE_TRACE(f, fmt, args...) \ > -- > 2.31.0.208.g409f899ff0-goog > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch