Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp280365pxf; Thu, 8 Apr 2021 03:00:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynS3QXt3SHsixYebdbifGpHR08FxIe+AL7wg2GfMnxRwPKniipONE2pTyQA82fg7GUCy4l X-Received: by 2002:a17:90b:3444:: with SMTP id lj4mr7601505pjb.12.1617876057326; Thu, 08 Apr 2021 03:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617876057; cv=none; d=google.com; s=arc-20160816; b=Tg+qJQRxuBwM5f0IlJpg9E4uk5wHP4javb9UUap1aIiuqPl6q2AE8O7Xwa3STMK8WT yc4ciZxaJLvQY3z3Da3BJ1oyTVVukdedGpaFXrvwNg2jlkCluzpxWC00dkb8RMQSjyxS xAYur5T1zdYzYHEQ1Q4fx8IMvKGo+MhfkLKcVgT1wa6vctsNmPmtCxtWOYZJ4d3Suz0a 394EDay+g12X2P/JEdS0kv6shhFJH1R+feVbIjZr4qrKx5bAP5U3+REYpXUHTIH8miCk ZMkK7TWvel+WdQ5xMhfnIAfXTy3IOilkGQXS7SgXsSfc6y6oNeoZg+oPBlUnO6UKLV5P 9l1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=TjMXPxgdcWLwg3HHxfz7xUxG8qs2PWdH8nXM2CLjB+o=; b=KnFic6HbS9rzTr3soFZGOTBnZGdOlpGWn4BVw+fLhyJja2VYSl1YQsVsJubdScewGI InwnoSrWMlBWx6P6t0tjNdvzhiwb5+7XAU0JnTe28yd9c8UCFaHjyorhgjq8m+afng7A kMYiSyX2XPOwv8t8VUKjZWyVZ/dB913UZ+tOu72mm+8zpFv4ETwlOQkKxCr2M3hzHFTT ZrDqiKB76AvailXEuRljeWyViQ24ph0MZDg3QSPrpx0Kj42lvLwB22k9wA/83dysLS/w 2Odtd26F6bAm8yC8wqMpPB1kZlfhSZhHK3/viwPAgz/1bs7e8/oAUmGUfG5bIlbuPtTl 7kEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gMg1WWlw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si26455187pgt.408.2021.04.08.03.00.44; Thu, 08 Apr 2021 03:00:57 -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=@chromium.org header.s=google header.b=gMg1WWlw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbhDHKAR (ORCPT + 99 others); Thu, 8 Apr 2021 06:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbhDHKAQ (ORCPT ); Thu, 8 Apr 2021 06:00:16 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 445EDC061761 for ; Thu, 8 Apr 2021 03:00:05 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id q3so1506453qkq.12 for ; Thu, 08 Apr 2021 03:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=TjMXPxgdcWLwg3HHxfz7xUxG8qs2PWdH8nXM2CLjB+o=; b=gMg1WWlwvL/P1OTnrl6+6JpkrxhoO/PiyHdKo9peBiI09ZW3TEVzuVXZpZg2vYBioS PfYZMgTHRRMMXrv0DRG63sU6Ei/j3p03EGaIlLS4/29rS3l4UhdkKn0HJmxmt+wKoDQ9 ayPQOBNw9f7Z2CKEc6TOjro7NGUyqm1RTgXxU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TjMXPxgdcWLwg3HHxfz7xUxG8qs2PWdH8nXM2CLjB+o=; b=B7tt9mWQoOjfHUZkuiWbO4r8dFaKTj6EjaFSnPGeMEZy/3mIHIbi0w7N1ZZwL+U8r6 r4qlJ4V6Ff0lG2kIik012+Anc6pfDd9gM8yn0eIHgjTWN4ClCl/DGJltvOQo4tDuUZ28 33ofjWyyDvK9d4SY9KDGNtGhXTP9BNX9D6SAOTneYjX4CPCg1pkN4SU0mjMk1d8+GFy6 mxIIviD4ZcQ9CH408s3oWN3YurVFPaoUOS0Xsg7uhyOKnbP8zISzbhwUbjr4RZbbdRj0 TdC09wTcrRLznBV6h/aF5DvN+iDMEeNXd4DNe61MQxBtJv1hxmqiRokkHTrCZ+MAHq6c l8uA== X-Gm-Message-State: AOAM532VE7AfprM/FP+iYzF84cLDTmsbhOYm+drIgn7E6mEI/yoghge0 LMPxeyTTYyz59e4ZmZZJzQXgdCEFBG2h9rumS95M0w== X-Received: by 2002:a05:620a:2190:: with SMTP id g16mr7476782qka.241.1617876004539; Thu, 08 Apr 2021 03:00:04 -0700 (PDT) MIME-Version: 1.0 References: <20210408095428.3983055-1-stevensd@google.com> In-Reply-To: From: David Stevens Date: Thu, 8 Apr 2021 18:59:54 +0900 Message-ID: Subject: Re: [PATCH v3] drm/syncobj: use newly allocated stub fences To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Sumit Semwal , ML dri-devel , open list , Linux Media Mailing List , "moderated list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pushing to drm-misc-next works for me. Thanks for the quick responses. -David On Thu, Apr 8, 2021 at 6:56 PM Christian K=C3=B6nig wrote: > > Am 08.04.21 um 11:54 schrieb David Stevens: > > 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 o= f > > 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 > > Reviewed-by: Christian K=C3=B6nig > > Should I push this to drm-misc-next or how do you want to upstream it? > > Thanks, > Christian. > > > --- > > v2 -> v3: > > - reuse the static stub spinlock > > v1 -> v2: > > - checkpatch style fixes > > > > drivers/dma-buf/dma-fence.c | 27 ++++++++++++++++++++++++++- > > drivers/gpu/drm/drm_syncobj.c | 25 +++++++++++++++++++------ > > include/linux/dma-fence.h | 1 + > > 3 files changed, 46 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c > > index d64fc03929be..ce0f5eff575d 100644 > > --- a/drivers/dma-buf/dma-fence.c > > +++ b/drivers/dma-buf/dma-fence.c > > @@ -123,7 +123,9 @@ static const struct dma_fence_ops dma_fence_stub_op= s =3D { > > /** > > * 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 +143,29 @@ 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 dma_fence *fence; > > + > > + fence =3D kzalloc(sizeof(*fence), GFP_KERNEL); > > + if (fence =3D=3D NULL) > > + return ERR_PTR(-ENOMEM); > > + > > + dma_fence_init(fence, > > + &dma_fence_stub_ops, > > + &dma_fence_stub_lock, > > + 0, 0); > > + dma_fence_signal(fence); > > + > > + return fence; > > +} > > +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_syncob= j.c > > index 349146049849..a54aa850d143 100644 > > --- a/drivers/gpu/drm/drm_syncobj.c > > +++ b/drivers/gpu/drm/drm_syncobj.c > > @@ -350,12 +350,16 @@ 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 =3D dma_fence_get_stub(); > > + struct dma_fence *fence =3D dma_fence_allocate_private_stub(); > > + > > + if (IS_ERR(fence)) > > + return PTR_ERR(fence); > > > > drm_syncobj_replace_fence(syncobj, fence); > > dma_fence_put(fence); > > + return 0; > > } > > > > /* 5s default for wait submission */ > > @@ -469,6 +473,7 @@ EXPORT_SYMBOL(drm_syncobj_free); > > int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t fla= gs, > > struct dma_fence *fence) > > { > > + int ret; > > struct drm_syncobj *syncobj; > > > > syncobj =3D kzalloc(sizeof(struct drm_syncobj), GFP_KERNEL); > > @@ -479,8 +484,13 @@ int drm_syncobj_create(struct drm_syncobj **out_sy= ncobj, 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 =3D 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 +1332,11 @@ drm_syncobj_signal_ioctl(struct drm_device *dev,= void *data, > > if (ret < 0) > > return ret; > > > > - for (i =3D 0; i < args->count_handles; i++) > > - drm_syncobj_assign_null_handle(syncobjs[i]); > > + for (i =3D 0; i < args->count_handles; i++) { > > + ret =3D 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...) \ >