Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp277315pxf; Thu, 8 Apr 2021 02:55:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKyKWrEYpUGBJLTr6Z69g6tFgAM2zZTf9CqcfQeeC8C7tDXDEm25L9B9IcBsQhpaSfo9eJ X-Received: by 2002:a05:6402:48c:: with SMTP id k12mr10141953edv.237.1617875757779; Thu, 08 Apr 2021 02:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617875757; cv=none; d=google.com; s=arc-20160816; b=Gsc3fKOaJsab9j+Cvy6ERfT31aQw3X6Y+JMJImjYlqOmNqb4AYSQIwuZdKYjSmrfua /Yzt9SCI0GpTqaOFrvOBvwazkrpkdVj3vzm6Jf22y1zrBGOuT4e/1GvSihFvw1gQaOTv LgH2SYOnhdd8aSWfxCgJSIlyPWMPgjzgQl7vjUOQ3grgJOzunc0jI4hrtCejwcsRngfn wufzAQUOdm7MRg+fG6UOqYh2nH8P1Ow27HtQ/V6nKrJ8Shok5P1SjrbjZ7Nim2gOAlYs 2GqktrfrDkKDszeELsz0yfHsqj7g8qgkf9JzAdqcRFPcE5az/qO7Dm8WFDVjD5O+93Zf m7rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=F06Z1RXUI5OZQHllx6yIelYubQ59fvVFVd2c1q8aYFo=; b=lwCQiv+4vqU0n+8rypvC3KvDG98dRRIKbQSFQYC/uEqfd2QEtw6Zn+eOtfSaXLJ9tk 5qjhDIccd6NcvJ0AOwks7ZrpPzU8uCTnYY4wj7RNqi9m/GS/wAx1yF73pRDId/+7NB0A 3N++iWoGTekW5peS868dC04Ta3Iv+noE3Opf0Z6SLG0s0lzqaiTzasSHhXraWjoExy6c 9mT/GRQBs84p6uuAjyfjAWqwwnFQaaaHkZLarToh0+m8yqlUENXGBvKSR6z1mwcFFStn zs4M4oXVg0upok2LPVLS0tgsoAYmZjgQKPnulBDQLu+Kn7u30G31VjeC4yHtiQKOX6eU r73w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lFey3WOV; 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 m13si9962476ejc.676.2021.04.08.02.55.34; Thu, 08 Apr 2021 02:55: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=lFey3WOV; 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 S231132AbhDHJyv (ORCPT + 99 others); Thu, 8 Apr 2021 05:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbhDHJyu (ORCPT ); Thu, 8 Apr 2021 05:54:50 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 302F6C061760 for ; Thu, 8 Apr 2021 02:54:40 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id l123so1406252pfl.8 for ; Thu, 08 Apr 2021 02:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F06Z1RXUI5OZQHllx6yIelYubQ59fvVFVd2c1q8aYFo=; b=lFey3WOVaEoUGK+gffnBEpyZ85Q8vR72KNL7iQWslR0Dsuw+Qfd9pWdCFEMJN0S2Lf lDfiSrMZ0bvyr9HpQ1mdr0wOzq6x7HAf4Ltx7i6kZuMn22oHwfvSly1Sw5P23rSLVzCc Eiij/wKY6lESQsif5OiYrqsXIGqyONMMct5mk= 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=F06Z1RXUI5OZQHllx6yIelYubQ59fvVFVd2c1q8aYFo=; b=d17UVVhP8DZvaQxmtEXZ5Rt5B4jPzSs+jaRAL9gAb6eqAZfJpbByCIKac6Mmo879KG O3sGxxBHZEdqZLUCNb/zgdp/Sb8lTO14CZIBFSVTJU0j+C6YxsODveltH3I7c9wuA0XR y3yliPcbeCaGVI0qq81Mo1J7Di50VBR5FWc9jBDvHcLDclGRA/TDYh7Z1qO5pZ3uiJ9V D8RDxWLMIMGlauuTjw4PeWMU/Ar3QCYjjQA7pwxgCzF70OlgcZQexb5NTaObmrfbXjg6 Nyc4OV5w8cbk/lV0XzW/1sV9fv7zuxXUqQ1T+84a08vrKqMU+GUCGj+ztnQ8WwOT45ih eFZA== X-Gm-Message-State: AOAM532qVj2QJo24vb6IXM2nyb8HKIa5co9r/mmjlF1RDsxIrnuSygUy jX4YqaVi5FeneKpizasqErwtIw== X-Received: by 2002:a63:f056:: with SMTP id s22mr7279239pgj.369.1617875679652; Thu, 08 Apr 2021 02:54:39 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:25d8:8458:73e8:75ac]) by smtp.gmail.com with UTF8SMTPSA id js16sm7528068pjb.21.2021.04.08.02.54.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Apr 2021 02:54:39 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: 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, David Stevens Subject: [PATCH v3] drm/syncobj: use newly allocated stub fences Date: Thu, 8 Apr 2021 18:54:28 +0900 Message-Id: <20210408095428.3983055-1-stevensd@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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_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 +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 = kzalloc(sizeof(*fence), GFP_KERNEL); + if (fence == 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_syncobj.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 = 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); + 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 flags, struct dma_fence *fence) { + int ret; struct drm_syncobj *syncobj; syncobj = kzalloc(sizeof(struct drm_syncobj), GFP_KERNEL); @@ -479,8 +484,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 +1332,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