From patchwork Mon May 2 16:37:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834405 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 AD6E7C433EF for ; Mon, 2 May 2022 16:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243212AbiEBQlT (ORCPT ); Mon, 2 May 2022 12:41:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243296AbiEBQlO (ORCPT ); Mon, 2 May 2022 12:41:14 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32A1410FF3 for ; Mon, 2 May 2022 09:37:30 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id d5so20238895wrb.6 for ; Mon, 02 May 2022 09:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ztozpp4Hd7P88p5EylObdLnFFM2e9No0uy0uVps0Q4o=; b=l8cnH0/oWnlGs4iC9nSE0GWCX5g6JqtmjJMCjqSOAwOlKROP5Dav+7qr2vV22I5AyR P29H9FiZL0l2XMAOD39ti1qK7CTYjhCfhB/1+yXOLeBeRWny9/cVyMmgwWfoI/s/Irld ZRtRAzcb0kVhafr3YK4q7sAqJH9N878z6sN9gTuvwmb5v79Q5utfbdU/1lMGWZC9QQFQ UNgGqrfbGFfgl4WqqTb8n9jL+C74NUCcdbKkwWbHWD8HODMIuK3SPi81YaAuOHrXN9cS 2i0O0Ls4YIs41WHjk2OSpRFoFPhhX0T09C3YwERYz33I3c2eqkXCNeI1/XrcKaWKZgfC uTWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ztozpp4Hd7P88p5EylObdLnFFM2e9No0uy0uVps0Q4o=; b=dDPwiDJvWLGs0FwYYAtApgA8tVrIC/nAqqMVjQwGzqN1Iq2XkgNc4Sz1GnahaCWqpQ wsf6BGnJqMkRMbu0kgwYphoCb2nPsjxpI3NxQTwj8PiIsRRDVW9J1ntUSS/u5b07CoQ5 paxfYFYbDKiMDZObUoBo6q5gSbROXKKHBu+5MRkuZI6f4dFXJ16Up7RcHJKi2qRCody4 U88/F5UYk1xR0UG8Tq6PvSnEfT/60heQ7e27gkm3lfPNl/g5QUoJWWf3ghuznYwcBGu+ HkeeSuk6ojKIxXNFbpRtzBfAhmPThrcvI4BLIGTcxoH2Z1XXSdFQTNmRgEMbI3MvUPwa F72Q== X-Gm-Message-State: AOAM530yGTJw/159xNVZnhMO134z0Im8uX8Gdo3FWhe0yG3KW4q3NcAi om0CwtZXJLfCYaes1xxfwBM= X-Google-Smtp-Source: ABdhPJz2JXWWJflLQjuCGIgmn7WtX7jC1WTxfxIIZ7Mwf9txYB3Hit3CNEpghfRADVo4PLGr1oZzVg== X-Received: by 2002:a05:6000:c:b0:20a:df2e:2c38 with SMTP id h12-20020a056000000c00b0020adf2e2c38mr9823627wrx.481.1651509448873; Mon, 02 May 2022 09:37:28 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:28 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 01/15] dma-buf: rename DMA_FENCE_FLAG_USER_BITS to _DEVICE Date: Mon, 2 May 2022 18:37:08 +0200 Message-Id: <20220502163722.3957-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This is supposed to be used by device drivers. Signed-off-by: Christian König --- drivers/gpu/drm/i915/i915_request.h | 2 +- drivers/gpu/drm/i915/i915_sw_fence_work.h | 2 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 4 ++-- include/linux/dma-fence.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_request.h b/drivers/gpu/drm/i915/i915_request.h index 28b1f9db5487..716c8c413cc4 100644 --- a/drivers/gpu/drm/i915/i915_request.h +++ b/drivers/gpu/drm/i915/i915_request.h @@ -80,7 +80,7 @@ enum { * * See i915_request_is_active() */ - I915_FENCE_FLAG_ACTIVE = DMA_FENCE_FLAG_USER_BITS, + I915_FENCE_FLAG_ACTIVE = DMA_FENCE_FLAG_DRIVER, /* * I915_FENCE_FLAG_PQUEUE - this request is ready for execution diff --git a/drivers/gpu/drm/i915/i915_sw_fence_work.h b/drivers/gpu/drm/i915/i915_sw_fence_work.h index d56806918d13..ece0a06e598c 100644 --- a/drivers/gpu/drm/i915/i915_sw_fence_work.h +++ b/drivers/gpu/drm/i915/i915_sw_fence_work.h @@ -33,7 +33,7 @@ struct dma_fence_work { }; enum { - DMA_FENCE_WORK_IMM = DMA_FENCE_FLAG_USER_BITS, + DMA_FENCE_WORK_IMM = DMA_FENCE_FLAG_DRIVER, }; void dma_fence_work_init(struct dma_fence_work *f, diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c index 7f01dcf81fab..e2f61b34cc1e 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c @@ -61,7 +61,7 @@ nouveau_fence_signal(struct nouveau_fence *fence) list_del(&fence->head); rcu_assign_pointer(fence->channel, NULL); - if (test_bit(DMA_FENCE_FLAG_USER_BITS, &fence->base.flags)) { + if (test_bit(DMA_FENCE_FLAG_DRIVER, &fence->base.flags)) { struct nouveau_fence_chan *fctx = nouveau_fctx(fence); if (!--fctx->notify_ref) @@ -510,7 +510,7 @@ static bool nouveau_fence_enable_signaling(struct dma_fence *f) ret = nouveau_fence_no_signaling(f); if (ret) - set_bit(DMA_FENCE_FLAG_USER_BITS, &fence->base.flags); + set_bit(DMA_FENCE_FLAG_DRIVER, &fence->base.flags); else if (!--fctx->notify_ref) nvif_notify_put(&fctx->notify); diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 775cdc0b4f24..afea82ec5946 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -49,7 +49,7 @@ struct dma_fence_cb; * DMA_FENCE_FLAG_SIGNALED_BIT - fence is already signaled * DMA_FENCE_FLAG_TIMESTAMP_BIT - timestamp recorded for fence signaling * DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT - enable_signaling might have been called - * DMA_FENCE_FLAG_USER_BITS - start of the unused bits, can be used by the + * DMA_FENCE_FLAG_DRIVER - start of the unused bits, can be used by the * implementer of the fence for its own purposes. Can be used in different * ways by different fence implementers, so do not rely on this. * @@ -99,7 +99,7 @@ enum dma_fence_flag_bits { DMA_FENCE_FLAG_SIGNALED_BIT, DMA_FENCE_FLAG_TIMESTAMP_BIT, DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, - DMA_FENCE_FLAG_USER_BITS, /* must always be last member */ + DMA_FENCE_FLAG_DRIVER, /* must always be last member */ }; typedef void (*dma_fence_func_t)(struct dma_fence *fence, From patchwork Mon May 2 16:37:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834406 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 12BCAC433FE for ; Mon, 2 May 2022 16:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243119AbiEBQlU (ORCPT ); Mon, 2 May 2022 12:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386342AbiEBQlO (ORCPT ); Mon, 2 May 2022 12:41:14 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53C3C11151 for ; Mon, 2 May 2022 09:37:32 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id e2so20240036wrh.7 for ; Mon, 02 May 2022 09:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IWKemcOrL+b0gDAZZafa8ch1M5o7lnyn/o46hmmWygU=; b=R03rLumujGEAhM8SwniCLQoHPy6kFAqVrw+ARLriiv2g9paPKv1HJ+UXOxaEV6Rmya IryHyZomNBs+p6BJAqENBZ6yG2HnabhAsecgLf4OBThsEKurj0EnP+v6ax9tjg6zbCDH /RFB4DiUPMaj7jS9K9VUN9mN79W5bEcNxBIzk13pjkyHGhT5dvm6oTg1kVYLioM6aPTP C9jPXj5uX5mAaxIzWIcLGHzK2OEuA8hSe9u2oSp3J5I4xEXnKCh9DV7IUFhJ3u4pbwPu lPZ8N8EApdAw+tvjkVgX3a/YY+EILJdse1eiuD/pNi0Etd6+jZ7NAe6IkF1ftEPAnrLD LBmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IWKemcOrL+b0gDAZZafa8ch1M5o7lnyn/o46hmmWygU=; b=Xt8x++Fostm6xT2F89OsvZetUjFHgYxkCjeXnhU5bhfrN6YXEYBvV1a1cy90gKUATD KXU95YaOBNRdVz/AMJgKJ1ia/zpIrdCd8H2FtV1S2pcoCG7xcReY8UX/NkrxfZBEns7p KY79hFytyMBVDC1kifo4+icEPeljrh2OzZZOIRO4saY+uP1w2YI7yd++6Z8CDTI2tQtS VXflB4kHJC/xKUDcx2of0WGZVZ4tCbpUG/jYLBoafy8DJCD8r9bymH4D3B+GjAJl9LeN UHIhUJa/Gk8fzXfh5qiSw6iuHKZc10SQa0yluzCrmvCBvjMWKOm9i2g9GpjkmQsZIhcK Rubg== X-Gm-Message-State: AOAM533MBz7TZXBcax2SUkD8aWk03wSaT+Z2yKFRflPbyiPjsMrWFGo0 TkK9QLSVbx3lJ44tEIb7JsQ= X-Google-Smtp-Source: ABdhPJysH2Ctla10lLPUFGhMcYiY1T7Y2hl8wvbRHgqL7XSe78IEd9IooYntpUrILEjkqAF5FaqAlw== X-Received: by 2002:a5d:4989:0:b0:20a:c907:2110 with SMTP id r9-20020a5d4989000000b0020ac9072110mr9936120wrq.476.1651509450429; Mon, 02 May 2022 09:37:30 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:29 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 02/15] dma-buf: introduce user fence support Date: Mon, 2 May 2022 18:37:09 +0200 Message-Id: <20220502163722.3957-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Start introducing a new part of the framework for handling user fences. In strict opposition to normal fences user fences don't reliable finish in a fixed amount of time and therefore can't be used as dependency in memory management. Because of this user fences are marked with DMA_FENCE_FLAG_USER. Lockdep is checked that we can at least fault user pages when we check them for signaling. This patch also adds a flag to dma_fence_get_stub() so that we can retrieve a signaled user fence. This can be used together with lockdep to test the handling in code path supporting user fences. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-unwrap.c | 4 +-- drivers/dma-buf/dma-fence.c | 31 ++++++++++++------- drivers/dma-buf/st-dma-fence.c | 2 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 +-- drivers/gpu/drm/drm_syncobj.c | 10 +++--- include/linux/dma-fence.h | 17 +++++++++- 9 files changed, 49 insertions(+), 25 deletions(-) diff --git a/drivers/dma-buf/dma-fence-unwrap.c b/drivers/dma-buf/dma-fence-unwrap.c index c9becc74896d..87ee2efced10 100644 --- a/drivers/dma-buf/dma-fence-unwrap.c +++ b/drivers/dma-buf/dma-fence-unwrap.c @@ -76,7 +76,7 @@ struct dma_fence *__dma_fence_merge(unsigned int num_fences, } if (count == 0) - return dma_fence_get_stub(); + return dma_fence_get_stub(false); if (count > INT_MAX) return NULL; @@ -129,7 +129,7 @@ struct dma_fence *__dma_fence_merge(unsigned int num_fences, } while (tmp); if (count == 0) { - tmp = dma_fence_get_stub(); + tmp = dma_fence_get_stub(false); goto return_tmp; } diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 066400ed8841..52873f5eaeba 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -26,6 +26,7 @@ EXPORT_TRACEPOINT_SYMBOL(dma_fence_signaled); static DEFINE_SPINLOCK(dma_fence_stub_lock); static struct dma_fence dma_fence_stub; +static struct dma_fence dma_fence_user_stub; /* * fence context counter: each execution context should have its own @@ -123,24 +124,28 @@ static const struct dma_fence_ops dma_fence_stub_ops = { /** * dma_fence_get_stub - return a signaled fence + * @user: if true the returned fence is an user fence * - * Return a stub fence which is already signaled. The fence's - * timestamp corresponds to the first time after boot this - * function is called. + * Return a stub fence which is already signaled. The fence's timestamp + * corresponds to the first time after boot this function is called. If @user is + * true an user fence is returned which can be used with lockdep to test user + * fence saveness in a code path. */ -struct dma_fence *dma_fence_get_stub(void) +struct dma_fence *dma_fence_get_stub(bool user) { + struct dma_fence *fence = user ? &dma_fence_stub : &dma_fence_user_stub; + spin_lock(&dma_fence_stub_lock); - if (!dma_fence_stub.ops) { - dma_fence_init(&dma_fence_stub, - &dma_fence_stub_ops, - &dma_fence_stub_lock, + if (!fence->ops) { + dma_fence_init(fence, &dma_fence_stub_ops, &dma_fence_stub_lock, 0, 0); - dma_fence_signal_locked(&dma_fence_stub); + if (user) + set_bit(DMA_FENCE_FLAG_USER, &fence->flags); + dma_fence_signal_locked(fence); } spin_unlock(&dma_fence_stub_lock); - return dma_fence_get(&dma_fence_stub); + return dma_fence_get(fence); } EXPORT_SYMBOL(dma_fence_get_stub); @@ -497,8 +502,9 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout) return -EINVAL; might_sleep(); - __dma_fence_might_wait(); + if (test_bit(DMA_FENCE_FLAG_USER, &fence->flags)) + might_fault(); trace_dma_fence_wait_start(fence); if (fence->ops->wait) @@ -870,6 +876,9 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, for (i = 0; i < count; ++i) { struct dma_fence *fence = fences[i]; + if (test_bit(DMA_FENCE_FLAG_USER, &fence->flags)) + might_fault(); + cb[i].task = current; if (dma_fence_add_callback(fence, &cb[i].base, dma_fence_default_wait_cb)) { diff --git a/drivers/dma-buf/st-dma-fence.c b/drivers/dma-buf/st-dma-fence.c index c8a12d7ad71a..50f757f75645 100644 --- a/drivers/dma-buf/st-dma-fence.c +++ b/drivers/dma-buf/st-dma-fence.c @@ -412,7 +412,7 @@ static int test_stub(void *arg) int i; for (i = 0; i < ARRAY_SIZE(f); i++) { - f[i] = dma_fence_get_stub(); + f[i] = dma_fence_get_stub((i % 2) == 1); if (!dma_fence_is_signaled(f[i])) { pr_err("Obtained unsignaled stub fence!\n"); goto err; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 64ac4f8f49be..541c59635c34 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -263,7 +263,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, /* TODO: Instead of block before we should use the fence of the page * table update and TLB flush here directly. */ - replacement = dma_fence_get_stub(); + replacement = dma_fence_get_stub(false); dma_resv_replace_fences(bo->tbo.base.resv, ef->base.context, replacement, DMA_RESV_USAGE_READ); dma_fence_put(replacement); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index a28b7947a034..95eeab527ca9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1399,7 +1399,7 @@ int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data, return PTR_ERR(fence); if (!fence) - fence = dma_fence_get_stub(); + fence = dma_fence_get_stub(false); switch (info->in.what) { case AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ: diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c index 7f33ae87cb41..73165f387f3b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c @@ -193,7 +193,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, adev->rings[ring->idx] = ring; ring->num_hw_submission = sched_hw_submission; ring->sched_score = sched_score; - ring->vmid_wait = dma_fence_get_stub(); + ring->vmid_wait = dma_fence_get_stub(false); r = amdgpu_fence_driver_init_ring(ring); if (r) return r; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 7e5cc8323329..e5c8e72a9485 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -1689,7 +1689,7 @@ int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, } if (!unlocked && !dma_fence_is_signaled(vm->last_unlocked)) { - struct dma_fence *tmp = dma_fence_get_stub(); + struct dma_fence *tmp = dma_fence_get_stub(false); amdgpu_bo_fence(vm->root.bo, vm->last_unlocked, true); swap(vm->last_unlocked, tmp); @@ -2905,7 +2905,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm) else vm->update_funcs = &amdgpu_vm_sdma_funcs; vm->last_update = NULL; - vm->last_unlocked = dma_fence_get_stub(); + vm->last_unlocked = dma_fence_get_stub(false); mutex_init(&vm->eviction_lock); vm->evicting = false; diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 7e48dcd1bee4..5a961ea90a35 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -255,7 +255,7 @@ static void drm_syncobj_fence_add_wait(struct drm_syncobj *syncobj, dma_fence_put(fence); list_add_tail(&wait->node, &syncobj->cb_list); } else if (!fence) { - wait->fence = dma_fence_get_stub(); + wait->fence = dma_fence_get_stub(false); } else { wait->fence = fence; } @@ -411,7 +411,7 @@ int drm_syncobj_find_fence(struct drm_file *file_private, * signalled, use a new fence instead. */ if (!*fence) - *fence = dma_fence_get_stub(); + *fence = dma_fence_get_stub(false); goto out; } @@ -1000,7 +1000,7 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj, dma_fence_put(fence); return; } else if (!fence) { - wait->fence = dma_fence_get_stub(); + wait->fence = dma_fence_get_stub(false); } else { wait->fence = fence; } @@ -1067,7 +1067,7 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, if (fence) entries[i].fence = fence; else - entries[i].fence = dma_fence_get_stub(); + entries[i].fence = dma_fence_get_stub(false); if ((flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE) || dma_fence_is_signaled(entries[i].fence)) { @@ -1472,7 +1472,7 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data, } for (i = 0; i < args->count_handles; i++) { - struct dma_fence *fence = dma_fence_get_stub(); + struct dma_fence *fence = dma_fence_get_stub(false); drm_syncobj_add_point(syncobjs[i], chains[i], fence, points[i]); diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index afea82ec5946..be96687d31d8 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -99,6 +99,16 @@ enum dma_fence_flag_bits { DMA_FENCE_FLAG_SIGNALED_BIT, DMA_FENCE_FLAG_TIMESTAMP_BIT, DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, + + /** + * @DMA_FENCE_FLAG_USER: + * + * Indicates an user fence. User fences are not guaranteed to signal in + * a finite amount of time. Because of this it is not allowed to wait for user + * fences with any lock held nor depend the signaling of none user + * fences on them. + */ + DMA_FENCE_FLAG_USER, DMA_FENCE_FLAG_DRIVER, /* must always be last member */ }; @@ -398,6 +408,8 @@ void dma_fence_enable_sw_signaling(struct dma_fence *fence); static inline bool dma_fence_is_signaled_locked(struct dma_fence *fence) { + WARN_ON(test_bit(DMA_FENCE_FLAG_USER, &fence->flags)); + if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) return true; @@ -428,6 +440,9 @@ dma_fence_is_signaled_locked(struct dma_fence *fence) static inline bool dma_fence_is_signaled(struct dma_fence *fence) { + if (test_bit(DMA_FENCE_FLAG_USER, &fence->flags)) + might_fault(); + if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) return true; @@ -583,7 +598,7 @@ static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr) return ret < 0 ? ret : 0; } -struct dma_fence *dma_fence_get_stub(void); +struct dma_fence *dma_fence_get_stub(bool user); struct dma_fence *dma_fence_allocate_private_stub(void); u64 dma_fence_context_alloc(unsigned num); From patchwork Mon May 2 16:37:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834407 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 EE25FC433F5 for ; Mon, 2 May 2022 16:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386312AbiEBQlW (ORCPT ); Mon, 2 May 2022 12:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386343AbiEBQlO (ORCPT ); Mon, 2 May 2022 12:41:14 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7909E1115F for ; Mon, 2 May 2022 09:37:33 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id ay11-20020a05600c1e0b00b0038eb92fa965so11115024wmb.4 for ; Mon, 02 May 2022 09:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jUPHAg5HbOj5ZN0WpYBsRJzMWzX/NFrcan6CKY2q7Ro=; b=K7kMi4HoE2Uh2vRrakSayQJE7aYVhjY9a5nwoadZ3BkU27oHo0Jx+EH8p9F1l+bwgN ougnq1m4Szq7vMRihB5chu9Z+ZAhMYo31EpJpgiEkXEFpJhONW9SJpvbLVTAB5PwPVI3 gbJU1+PbvJ+nchom3hU+DdengngN/5Bt+DlU/qbiM1NW0su5lLTtTrUHRHaesf3vGLSc UOhd7WzqMspEwHYiwLE4lMMhu+ZuVlV3H03VpVIVwDWGktR9kADp5GtEhgNmI0j9NHYG 5rZXer7PFDQr0n34gDRy9kaG7Q1lojECDnwbVLXefC9iMs89qUCExq9fJ6BQxKyi4Or3 ziwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jUPHAg5HbOj5ZN0WpYBsRJzMWzX/NFrcan6CKY2q7Ro=; b=JHIZTL50iSgTud+DVSze2l3ZobsBcYk8kbnlzZTPyHPIH2gPJ4HBw5XSOnCpq+5Smg 2029mhLzKzni67Z3KXNVH0XprPC5viKf8HHFFQe2RLzPGKGwpexwxFT/2zgSGXDz6uq2 vBWPgeonZSp5+jQkcvXbd9w3YAzXEpTB+PgUBkfwHbDuGoGSAsvAvqNjc933HBELU0ti wTZIE6y4XrtFNb6BWb2DsjfuUhlsuqQA2MW0CFvOXi5o7JEkM3XGewq8fbB0Nf0G8Fp/ wb/I57B8h/wrVNe6Hyvjkmp1E5N/2hTFB4zXPQfwfgfNgqeEl5E4dfaU9Fo9NVXWUhYg Ny0Q== X-Gm-Message-State: AOAM532YR3zu27eKz53bcrem1pWJnkM98yka8rmtXvohwEkziBbZpgxf oXRg6AU+h4lH/J4KCqlgG9c= X-Google-Smtp-Source: ABdhPJzPFdaPya/zgXl5sjQHQZoAs93P8c4u5VO/8cqCZV7P/ZBXkmF61G4yVvAvs5c6L70nsPZecg== X-Received: by 2002:a7b:c4d8:0:b0:393:fecd:2718 with SMTP id g24-20020a7bc4d8000000b00393fecd2718mr11612189wmk.23.1651509451818; Mon, 02 May 2022 09:37:31 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:31 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 03/15] dma-buf: add user fence support to dma_fence_array Date: Mon, 2 May 2022 18:37:10 +0200 Message-Id: <20220502163722.3957-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When any of the fences inside the array is an user fence the whole array is considered to be an user fence as well. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-array.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index 5c8a7084577b..de196b07d36d 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -189,8 +189,13 @@ struct dma_fence_array *dma_fence_array_create(int num_fences, * Enforce this here by checking that we don't create a dma_fence_array * with any container inside. */ - while (num_fences--) - WARN_ON(dma_fence_is_container(fences[num_fences])); + while (num_fences--) { + struct dma_fence *f = fences[num_fences]; + + WARN_ON(dma_fence_is_container(f)); + if (test_bit(DMA_FENCE_FLAG_USER, &f->flags)) + set_bit(DMA_FENCE_FLAG_USER, &array->base.flags); + } return array; } From patchwork Mon May 2 16:37:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834408 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 062DCC4332F for ; Mon, 2 May 2022 16:37:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346065AbiEBQlX (ORCPT ); Mon, 2 May 2022 12:41:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386352AbiEBQlP (ORCPT ); Mon, 2 May 2022 12:41:15 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 400A8BF74 for ; Mon, 2 May 2022 09:37:34 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id j15so20283686wrb.2 for ; Mon, 02 May 2022 09:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BrOnJQ5GVd5xSufoaIbn+bREEyd4T5ZXHXrgSKz+378=; b=okpkvKiRl915tZRV+tKO2JUIHBSt+lEHdvyw8bY6TfdI5VooUsa0uko0GD2XuRtY6D ib2FOcZyu81uirrOQztEbyC13epUQrx7siG4pmRnHYF/yHr+iQUxw2oWRk7l7JpZPy2q EuePeHUY3wNFGxhM6ImJ5oulTkzYDCRCHjor0Ey1yXxucVzqfL9H9R7q2oT6ACV7MMeZ QUArRl0gIsFxN1ixLavUYobBb6oLoqTou2giIWUCQjleu4SgzBSL/dH8TdU1uwbG34lt 0iroKwnZw4OoPgDqonqH6AQZ/Oy+sNlN2fP9I7HfH4hZi4oxsJXFtU4sJvElHNoANYcc fnbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BrOnJQ5GVd5xSufoaIbn+bREEyd4T5ZXHXrgSKz+378=; b=T/GuhJWAYMckhDjshKgrqKIURyxfn72qX9EqEQya/HT+HFaFRIP5aE20VbQ5j/JOb3 GB//ghu8NHV2SvHUjvUGJ4qG4pk9ZDSDl8YY7zcbozhTec28jrAgaZeWwE8Yp7r4Xzg3 TQQd05FbNAx86lY22XbdNwgdDRaxOopt0upCyqQVSmogPnl2JFL+xthtiGybjTtg4PGN r1VjFzlAwZMqfCnOsXk4JIFOfXQSvNr8cfBxmzTmSwALObTweWAKMCjviYCAmjHiIt0B QdvQ9R9hpPKJuxx1stwkHw6sA+RhtJ+TFOB7EpVQOWocrYinJ4xNOLtqUjecx57Ry42A B92A== X-Gm-Message-State: AOAM532f2qBu1pfK9swFegTQ6/O39g3GVRax8H55DCkylsUrkulp4h+Q xelEJLD328j4qdcECcqknoE= X-Google-Smtp-Source: ABdhPJwsgT2uBu8jt40/OL4SbaktGz3QRHu++Q4skOI7kiUNv4O32wAoOAtOasCXMjvp7kYjRaqe4g== X-Received: by 2002:a05:6000:1ac8:b0:20c:6ed8:403 with SMTP id i8-20020a0560001ac800b0020c6ed80403mr1907892wry.247.1651509453268; Mon, 02 May 2022 09:37:33 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:32 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 04/15] dma-buf: add user fence support to dma_fence_chain Date: Mon, 2 May 2022 18:37:11 +0200 Message-Id: <20220502163722.3957-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If either the previous fence or the newly chained on is an user fence the dma_fence chain node is considered an user fence as well. This way the user fence status propagates through the chain. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-chain.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index 06f8ef97c6e8..421241607ac2 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -253,6 +253,10 @@ void dma_fence_chain_init(struct dma_fence_chain *chain, dma_fence_init(&chain->base, &dma_fence_chain_ops, &chain->lock, context, seqno); + if ((prev && test_bit(DMA_FENCE_FLAG_USER, &prev->flags)) || + test_bit(DMA_FENCE_FLAG_USER, &fence->flags)) + set_bit(DMA_FENCE_FLAG_USER, &chain->base.flags); + /* * Chaining dma_fence_chain container together is only allowed through * the prev fence and not through the contained fence. From patchwork Mon May 2 16:37:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834409 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 7E406C43217 for ; Mon, 2 May 2022 16:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380317AbiEBQlY (ORCPT ); Mon, 2 May 2022 12:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386327AbiEBQlQ (ORCPT ); Mon, 2 May 2022 12:41:16 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581C511A0D for ; Mon, 2 May 2022 09:37:36 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id c190-20020a1c35c7000000b0038e37907b5bso11136335wma.0 for ; Mon, 02 May 2022 09:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5B4Auy7jd8jQDW0N9881N8dXhobh36tEV/4wwMqA4v8=; b=C1UJgSKx6J52Qk7ZHhgTZrjjmTWFmby49NUiKkboiTEraCCWRXYvZtNkrR74WwmRvx BooWzQecxcEmr5/HIDzo41n9T8ESUdyawEMnem2KN+OdULadriLP1LSAEGGD6Jn1qWl2 DuVCL8R9tIvgDzo9vCxLyO9rxqSjpdET3CezqwfuDM1QG+IZ/7rNifqSHNCoChYuRDiu INNq5rSbOOWNeZHkW0C9bJb69MvvEcKFWsEOYnDZBUOwcin94PqcS8qq3IqmyfHyEmFh BFE+n22wd/pZnZeQadDBSG1OBiIbegR3FkhnRPqGqAKTGC6TGpbQWQDukJoF910Og1st 0bRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5B4Auy7jd8jQDW0N9881N8dXhobh36tEV/4wwMqA4v8=; b=t+yN+NAJcYzNMS6hNPensK7NiUcvNP8zM0VHaN9d42NwaAS3JTAPOiRj6or5+aBMPC RXp42iIkxRO7xG61EqeP9FW285rdGHyISo4LKRJlZqaM/yC5SsrEZv9sExir06uP0l9e SuRFhRfsCXAqinoTA+knCEt9ngNTGb5gW0zAW8qyN1PI1mWZL17hueszwIL6O6grL9qj vBXdJA3TG3gz9HE9xVyHxg84ebkd8n01+QpBhe+tziFDpD8CGQP0dQrwsHhuFI+bcHPg V+shDNqX69Kus3pP122BTEKaERuLGXBZRMjatoJVzBsG/qBvgI5jXgN+fBFZaPMYG9Zy w2QA== X-Gm-Message-State: AOAM532dVJOv26u2aODDswh4z/gDHkpvY9haUixpiRZIb6p8+XOsw5Ba u6JRp4xOY6Ox8tnq37qMUVA= X-Google-Smtp-Source: ABdhPJyaATORD6OjT4IsmnRnb38/vqPmuN7LAymrKwYEI0Npk0PJ/NXtoYiC6u1vxAvmWCAKyDK3pw== X-Received: by 2002:a05:600c:354f:b0:394:3bd4:c747 with SMTP id i15-20020a05600c354f00b003943bd4c747mr1164wmq.142.1651509454747; Mon, 02 May 2022 09:37:34 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:34 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 05/15] dma-buf: add user fence support to dma_resv Date: Mon, 2 May 2022 18:37:12 +0200 Message-Id: <20220502163722.3957-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch adds the new DMA_RESV_USAGE_USER flag to the dma_resv object which must be used with user fence objects. In opposite to the other usage flags this one doesn't automatically return other lower classes. So when user fences are requested from the dma_resv object only user fences are returned. Lockdep is used to enforce that user fences can only be queried while the dma_resv object is not locked. Additional to that waiting for the user fences inside a dma_resv object requires not other lock to be held. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 62 +++++++++++++++++++++++--------------- include/linux/dma-resv.h | 23 ++++++++++++-- 2 files changed, 58 insertions(+), 27 deletions(-) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index 0cce6e4ec946..da667c21ad55 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -58,7 +58,7 @@ DEFINE_WD_CLASS(reservation_ww_class); EXPORT_SYMBOL(reservation_ww_class); /* Mask for the lower fence pointer bits */ -#define DMA_RESV_LIST_MASK 0x3 +#define DMA_RESV_LIST_MASK 0x7 struct dma_resv_list { struct rcu_head rcu; @@ -288,6 +288,10 @@ void dma_resv_add_fence(struct dma_resv *obj, struct dma_fence *fence, */ WARN_ON(dma_fence_is_container(fence)); + /* User fences must be added using DMA_RESV_USAGE_USER */ + WARN_ON(test_bit(DMA_FENCE_FLAG_USER, &fence->flags) != + (usage == DMA_RESV_USAGE_USER)); + fobj = dma_resv_fences_list(obj); count = fobj->num_fences; @@ -349,6 +353,15 @@ void dma_resv_replace_fences(struct dma_resv *obj, uint64_t context, } EXPORT_SYMBOL(dma_resv_replace_fences); +/* Matches requested usage with the fence usage for iterators */ +static bool dma_resv_iter_match_usage(struct dma_resv_iter *cursor) +{ + if (cursor->usage == DMA_RESV_USAGE_USER) + return cursor->fence_usage == DMA_RESV_USAGE_USER; + + return cursor->usage >= cursor->fence_usage; +} + /* Restart the unlocked iteration by initializing the cursor object. */ static void dma_resv_iter_restart_unlocked(struct dma_resv_iter *cursor) { @@ -385,8 +398,7 @@ static void dma_resv_iter_walk_unlocked(struct dma_resv_iter *cursor) continue; } - if (!dma_fence_is_signaled(cursor->fence) && - cursor->usage >= cursor->fence_usage) + if (dma_resv_iter_match_usage(cursor)) break; } while (true); } @@ -405,14 +417,9 @@ static void dma_resv_iter_walk_unlocked(struct dma_resv_iter *cursor) */ struct dma_fence *dma_resv_iter_first_unlocked(struct dma_resv_iter *cursor) { - rcu_read_lock(); - do { - dma_resv_iter_restart_unlocked(cursor); - dma_resv_iter_walk_unlocked(cursor); - } while (dma_resv_fences_list(cursor->obj) != cursor->fences); - rcu_read_unlock(); - - return cursor->fence; + /* Force a restart */ + cursor->fences = NULL; + return dma_resv_iter_next_unlocked(cursor); } EXPORT_SYMBOL(dma_resv_iter_first_unlocked); @@ -428,18 +435,21 @@ EXPORT_SYMBOL(dma_resv_iter_first_unlocked); */ struct dma_fence *dma_resv_iter_next_unlocked(struct dma_resv_iter *cursor) { - bool restart; - - rcu_read_lock(); cursor->is_restarted = false; - restart = dma_resv_fences_list(cursor->obj) != cursor->fences; do { - if (restart) - dma_resv_iter_restart_unlocked(cursor); - dma_resv_iter_walk_unlocked(cursor); - restart = true; - } while (dma_resv_fences_list(cursor->obj) != cursor->fences); - rcu_read_unlock(); + bool restart; + + rcu_read_lock(); + restart = dma_resv_fences_list(cursor->obj) != cursor->fences; + do { + if (restart) + dma_resv_iter_restart_unlocked(cursor); + dma_resv_iter_walk_unlocked(cursor); + restart = true; + } while (dma_resv_fences_list(cursor->obj) != cursor->fences); + rcu_read_unlock(); + + } while (cursor->fence && dma_fence_is_signaled(cursor->fence)); return cursor->fence; } @@ -491,7 +501,7 @@ struct dma_fence *dma_resv_iter_next(struct dma_resv_iter *cursor) dma_resv_list_entry(cursor->fences, cursor->index++, cursor->obj, &fence, &cursor->fence_usage); - } while (cursor->fence_usage > cursor->usage); + } while (!dma_resv_iter_match_usage(cursor)); return fence; } @@ -663,6 +673,9 @@ long dma_resv_wait_timeout(struct dma_resv *obj, enum dma_resv_usage usage, struct dma_resv_iter cursor; struct dma_fence *fence; + if (usage == DMA_RESV_USAGE_USER) + lockdep_assert_none_held_once(); + dma_resv_iter_begin(&cursor, obj, usage); dma_resv_for_each_fence_unlocked(&cursor, fence) { @@ -678,7 +691,6 @@ long dma_resv_wait_timeout(struct dma_resv *obj, enum dma_resv_usage usage, } EXPORT_SYMBOL_GPL(dma_resv_wait_timeout); - /** * dma_resv_test_signaled - Test if a reservation object's fences have been * signaled. @@ -717,7 +729,9 @@ EXPORT_SYMBOL_GPL(dma_resv_test_signaled); */ void dma_resv_describe(struct dma_resv *obj, struct seq_file *seq) { - static const char *usage[] = { "kernel", "write", "read", "bookkeep" }; + static const char *usage[] = { + "kernel", "write", "read", "bookkeep", "user" + }; struct dma_resv_iter cursor; struct dma_fence *fence; diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h index c8ccbc94d5d2..81a9ca32cc69 100644 --- a/include/linux/dma-resv.h +++ b/include/linux/dma-resv.h @@ -42,7 +42,6 @@ #include #include #include -#include #include extern struct ww_class reservation_ww_class; @@ -57,11 +56,15 @@ struct dma_resv_list; * * An important fact is that there is the order KERNELlock.base); + cursor->obj = obj; cursor->usage = usage; cursor->fence = NULL; From patchwork Mon May 2 16:37:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834410 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 924CFC433F5 for ; Mon, 2 May 2022 16:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386324AbiEBQlZ (ORCPT ); Mon, 2 May 2022 12:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386360AbiEBQlQ (ORCPT ); Mon, 2 May 2022 12:41:16 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABC1911A1B for ; Mon, 2 May 2022 09:37:37 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id p189so8550670wmp.3 for ; Mon, 02 May 2022 09:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PRrPoRHHMVUrb5lC6MPjlnCl9PCZ8HWYoNk/YFcFCiA=; b=OFQtewjT9fUvoHtYhMh7ANDq7xj4P0vsSbip4Q75b1Jkvyrxh/SM6AfiC/QKQHlypQ BX3BabqqMqdEzeYcj/nmpBY8Qxda0a9wsD8qsf2abkJ9mVB3r/rb+a7ICk3TaZcsRmnL dQKrmgE86iyIPqEuj8wwM0OXSjKut2YO2B5QqjhlFueiv4aJPmMENk3j6XyH7ujbFMEv OH81rUOKEhpDhUw+i9TE0Srq5nIIY6RYcRHGA9C9StT0gyacz6dqsNe0apbB5sffIyR1 fT64bVj5tN0+FlGD0PPb34H5aCF853+ixTuYl2rpgHw5gNGfz3AIPbSZ57U2W5UpWxFP WBzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PRrPoRHHMVUrb5lC6MPjlnCl9PCZ8HWYoNk/YFcFCiA=; b=R6gbaAPY70TUjnZPikKwv8Mfz0ExqYU40kZBSn798IklJUJvhJqB+zzjEYp+ken0PA RaJ2qez9mPJmiIFJgQlaNlYMy0eSeweXssPtTxBZQcJYqfX8Mm03DURzbpGNiSSeDIOB uzMTcPHec3TOOUj7R8zc/yBLTGSu3X+ib/4t/Ge7Z+HRBH1rD9HaitdgKaHH9Sb9GuZp ZEgkO30qblmBcDkyMGyimv0vVxgvSIKkF20iU//CM1auNVLBp7oWOYEFRNh2+whjrGrr elOHSAfGZSO3bR8yfLfzcSPAP7mzZ0dJ7rNjN0dVjpPOihR33flYsX5Lvh34A0nXFkTn df2w== X-Gm-Message-State: AOAM5317d86akbGx6ggeusiqqOihbWIHZLCy413F/sgdMIs36nDP3Aad k76CoD8+SI0JR7p7A7zvVLs= X-Google-Smtp-Source: ABdhPJyEr5vbAcRX0+Jtvnnc+Wf7OKzoanJfhrmTHwUjGX/+TujJY43ARrVlFK4RKL5kjt6QWDMlHQ== X-Received: by 2002:a05:600c:4eca:b0:394:1e7d:af41 with SMTP id g10-20020a05600c4eca00b003941e7daf41mr15271560wmq.151.1651509456178; Mon, 02 May 2022 09:37:36 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:35 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 06/15] dma-buf: add user fence support to dma_fence_merge() Date: Mon, 2 May 2022 18:37:13 +0200 Message-Id: <20220502163722.3957-7-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Just make sure that we forward the user fence status to the output whenever any of the inputs are an user fence. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-unwrap.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/dma-fence-unwrap.c b/drivers/dma-buf/dma-fence-unwrap.c index 87ee2efced10..dd3c43aba8f1 100644 --- a/drivers/dma-buf/dma-fence-unwrap.c +++ b/drivers/dma-buf/dma-fence-unwrap.c @@ -66,17 +66,19 @@ struct dma_fence *__dma_fence_merge(unsigned int num_fences, { struct dma_fence_array *result; struct dma_fence *tmp, **array; + bool user_fence = false; unsigned int i, count; count = 0; for (i = 0; i < num_fences; ++i) { + user_fence |= test_bit(DMA_FENCE_FLAG_USER, &fences[i]->flags); dma_fence_unwrap_for_each(tmp, &iter[i], fences[i]) if (!dma_fence_is_signaled(tmp)) ++count; } if (count == 0) - return dma_fence_get_stub(false); + return dma_fence_get_stub(user_fence); if (count > INT_MAX) return NULL; @@ -129,11 +131,12 @@ struct dma_fence *__dma_fence_merge(unsigned int num_fences, } while (tmp); if (count == 0) { - tmp = dma_fence_get_stub(false); + tmp = dma_fence_get_stub(user_fence); goto return_tmp; } - if (count == 1) { + if (count == 1 && + test_bit(DMA_FENCE_FLAG_USER, &array[0]->flags) == user_fence) { tmp = array[0]; goto return_tmp; } @@ -145,6 +148,8 @@ struct dma_fence *__dma_fence_merge(unsigned int num_fences, tmp = NULL; goto return_tmp; } + if (user_fence) + set_bit(DMA_FENCE_FLAG_USER, &result->base.flags); return &result->base; return_tmp: From patchwork Mon May 2 16:37:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834416 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 354C8C433EF for ; Mon, 2 May 2022 16:38:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386321AbiEBQla (ORCPT ); Mon, 2 May 2022 12:41:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386332AbiEBQlQ (ORCPT ); Mon, 2 May 2022 12:41:16 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26DB511A26 for ; Mon, 2 May 2022 09:37:39 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id p189so8550700wmp.3 for ; Mon, 02 May 2022 09:37:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8ZMKLCUiF3qKPGX/LGoVOBpR7s+bcNprDSVbEKMvDkc=; b=Jp7rT8vS95BqwTwX7NsyZ5WkldjBFw8Wz1EkLvh1Kl2SA7MHWkTMAB/rlyQ3KG3v4n buaPRJHFD0KPGI8tMR5ZQmAJny9w7VO31u5URg4N9aYxcHt3yYR2stvowos66Dafzc2R 3vTOVGi+0LX1bRYlQACKn/Zv6gGPcd0zBwNjLgreQSpTZ1cJcFxMV1L2ezXr9Bp+hAbF CYYeoR+j4rklzzf+0vktNuMIo08df2EbJ8QT/EMWxsB2gNQ1450/d8uKroUbIuTT72TR GKK30kzV7V6ez2UkLqtwV66X4u7OoxdVRtBdcSmSgG25aLXPkCDOg4oINsKYw8CZSnQM hWZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ZMKLCUiF3qKPGX/LGoVOBpR7s+bcNprDSVbEKMvDkc=; b=foUqiy7u+2U9wpu4gHzRWXqIpVi86RptNj1shyZ+NdMsjk3edMmbx8L6Ij/1zvz2tV xuI0nc+5O2grCIpSEwaiZzYZCoN057ARTUzs14LmiCJ6/q4LL6BdW416NJ3RFi2b5OBJ 8IWqKhVJ6cSCJ3sH/WXkBstpDfkmGpyKJBcFUXPi9/DsTvzST+pjjIf6aaU/5v24H/xq TQaDu18pM+S72bbMpVxmxuquCWhZMAf18TRLWH/bfA6RNkG5ey3yie4tjq2pOGPZUhj3 nja7ommcp47zdLY00P6KL0jydaJAqxgwsjqIc7qhJGsw2uHp24vicWuebuuSb5YtqWOf KY+w== X-Gm-Message-State: AOAM530J6b1sK6elMD7dHdKx4wAmOkA/2ZV9NNuos+IhiG5OhSJG9aUF XMYZd17qgZ9GzZcZD8fTdrI= X-Google-Smtp-Source: ABdhPJxHqWm8EIEp8tsJmKMJ1X16WfhjsyQ0RVhMr8rBHA2/S+1qvIoC83uW/mXOKYOKnHyqwvoRpQ== X-Received: by 2002:a1c:5459:0:b0:394:1191:a1ff with SMTP id p25-20020a1c5459000000b003941191a1ffmr7038wmi.96.1651509457676; Mon, 02 May 2022 09:37:37 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:37 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 07/15] dma-buf: add user fence utility functions Date: Mon, 2 May 2022 18:37:14 +0200 Message-Id: <20220502163722.3957-8-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Allows to filter user fences from a dma_fence_chain and wait for user fences in containers. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-unwrap.c | 47 ++++++++++++++++++++++++++++++ include/linux/dma-fence-unwrap.h | 3 ++ 2 files changed, 50 insertions(+) diff --git a/drivers/dma-buf/dma-fence-unwrap.c b/drivers/dma-buf/dma-fence-unwrap.c index dd3c43aba8f1..4e9eda0b65c5 100644 --- a/drivers/dma-buf/dma-fence-unwrap.c +++ b/drivers/dma-buf/dma-fence-unwrap.c @@ -157,3 +157,50 @@ struct dma_fence *__dma_fence_merge(unsigned int num_fences, return tmp; } EXPORT_SYMBOL_GPL(__dma_fence_merge); + +/** + * dma_fence_filter_user - filter user fences + * @fence: entry point into the chain + * + * Check @fence and if it's a dma_fence_chain advance it until it doesn't depend + * on any user fence any more. + * + * Returns the advanced fence or NULL if no none user fence could be found. + */ +struct dma_fence *dma_fence_filter_user(struct dma_fence *fence) +{ + + while (fence && test_bit(DMA_FENCE_FLAG_USER, &fence->flags)) + fence = dma_fence_chain_walk(fence); + + return fence; +} +EXPORT_SYMBOL(dma_fence_filter_user); + +/** + * dma_fence_wait_user - wait for all user fences to signal + * @fence: entry point + * @timeout: timeout for the wait + * + * Unwrap the potential container in @fence and wait for all the user fences to + * signal. + * Returns: Either negative error code or the remaining timeout. + */ +long dma_fence_wait_user(struct dma_fence *fence, unsigned long timeout) +{ + struct dma_fence_unwrap iter; + long res; + + dma_fence_unwrap_for_each(fence, &iter, fence) { + if (!test_bit(DMA_FENCE_FLAG_USER, &fence->flags)) + continue; + + res = dma_fence_wait(fence, timeout); + if (res <= 0) + return res; + if (timeout) + timeout = res; + } + return timeout; +} +EXPORT_SYMBOL(dma_fence_wait_user); diff --git a/include/linux/dma-fence-unwrap.h b/include/linux/dma-fence-unwrap.h index 7c0fab318301..2a786f5a7819 100644 --- a/include/linux/dma-fence-unwrap.h +++ b/include/linux/dma-fence-unwrap.h @@ -72,4 +72,7 @@ struct dma_fence *__dma_fence_merge(unsigned int num_fences, __dma_fence_merge(ARRAY_SIZE(__f), __f, __c); \ }) +struct dma_fence *dma_fence_filter_user(struct dma_fence *fence); +long dma_fence_wait_user(struct dma_fence *fence, unsigned long timeout); + #endif From patchwork Mon May 2 16:37:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834414 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 A54C6C433F5 for ; Mon, 2 May 2022 16:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384381AbiEBQl3 (ORCPT ); Mon, 2 May 2022 12:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386367AbiEBQlQ (ORCPT ); Mon, 2 May 2022 12:41:16 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C540111A28 for ; Mon, 2 May 2022 09:37:40 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id x18so20291201wrc.0 for ; Mon, 02 May 2022 09:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DjepyRyvA6mLg/4EFB+VBQwNzCxlgFJd+rSnwBXcAo4=; b=b9McOF0QAQ4Vl1Xixqh+MWtgKhqJVwn5xVup/ay+JwJWOdF4F9BUxMavHOaj/8S6Nh SdIUTeOUydNZ784Hwl1hjbrRa1iqlF3EFIu4jhNFxYHXtpm5gsCt7Z0dmwrog09TcyS9 4D4sPCjynN1qp0m9VCtpp65oWPw1bE/QlKzw3oBmWsZyplJoEgktlSMI4ajRWnzURzVA CTiCssh6TAoEfw8Iz5ncjHIrKdoor3k9KKkcKIP9Lj2NEwvU09NeDBsHTJbf9rDSsUQa oZ+zLrz0fzr8Bc6PaKdaxIlWzjQtg5fEaVfv4ygePTgY8+nMUziiXz1JL3rb5oMuvpa5 qYJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DjepyRyvA6mLg/4EFB+VBQwNzCxlgFJd+rSnwBXcAo4=; b=J1in8zqA3y0EH4DBdSKr5IE0jy/7UtoVneR2VdPIsrSD7EUpBFiAv3qaPweDKCT1sv lPnZEe9Ps2Vh7KI9V+wEUoG0KQ+9IRpzkVhEDc+sEyg91O06oBMTg7EbFuPvE+GFBJ9S 5MCXqxNzCIkCzAp1qAlj+9gUjOxjmKic6++Rgkajzx0xcqHw3VUbvz/m6s6FHYFc01Nw yyFkUQIrwHYm8aWQZs2Vn3qSGPsd47LJQ6m7Fxwv0L99qZjjqlT967l3SAW4qo2jjXhU W9rSBniYhCV2C8qdMDXmUxpN8VYkrkbWfU7RP10+3sFo+TSbb6W23ab/VjC7RVB1+IOF 8iFg== X-Gm-Message-State: AOAM533X+UVq1ZRjV0wtzlXZwCXN6Ku+Sz8bVfKJxxdvDrr/0kQFc/eF PAiPWQtEpoqa1Ksm9SPnvbo= X-Google-Smtp-Source: ABdhPJybrPRxtci7aY1OOebXO27jsS5DQk+XuP1Q+hwI5bUFAaGVwmOUHoqt5uQuXpdTVJ383HXw2A== X-Received: by 2002:a5d:4205:0:b0:20a:e23c:a7f4 with SMTP id n5-20020a5d4205000000b0020ae23ca7f4mr10196022wrq.576.1651509459141; Mon, 02 May 2022 09:37:39 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:38 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 08/15] dma-buf: add support for polling on user fences Date: Mon, 2 May 2022 18:37:15 +0200 Message-Id: <20220502163722.3957-9-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Just also wait for user fences to signal when we wait for write fences. Signed-off-by: Christian König --- drivers/dma-buf/dma-buf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 79795857be3e..5558f4e555f8 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -225,6 +225,16 @@ static bool dma_buf_poll_add_cb(struct dma_resv *resv, bool write, dma_fence_put(fence); } + if (!write) + return false; + + dma_resv_for_each_fence(&cursor, resv, DMA_RESV_USAGE_USER, fence) { + dma_fence_get(fence); + r = dma_fence_add_callback(fence, &dcb->cb, dma_buf_poll_cb); + if (!r) + return true; + dma_fence_put(fence); + } return false; } From patchwork Mon May 2 16:37:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834412 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 A1648C433FE for ; Mon, 2 May 2022 16:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348468AbiEBQl2 (ORCPT ); Mon, 2 May 2022 12:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386376AbiEBQlR (ORCPT ); Mon, 2 May 2022 12:41:17 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C0711A37 for ; Mon, 2 May 2022 09:37:42 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id v12so20216751wrv.10 for ; Mon, 02 May 2022 09:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=luXkB4nWXeAscrwTivcA3+3hC+4sNV5dGxBhEUAh3ZU=; b=k0XTUm0RlYmuvq1Vpcu2zWJ5tdQzQuOA+T08xmE0ef/5Dyc0xYC6BQAX34i28BS1Z8 6XGRhh7G2F22HV+0FPj/JcbDmACUCgXPkrEdo3I9NWjw4bA29u96MPyVvSoRzYdx1rBX gSWXdr9puipmo5tWtuIreVuPGd8eYr+NO6ZdUxIRuDfe4piN9qo4yhufC0sCs6VtwARK tYH/gsiPCBMv8t8xXv2T8wRxDCKJnpAk6UnCuya2Mu/feqUYuoJeALg8waJFYxAjBFWX iVqkjS9lxfi2YWQEE4sgHujeMU83XQ+HkhOs3s66prDHuhTyV2B0iquM7AXw+g3L66z2 +Dqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=luXkB4nWXeAscrwTivcA3+3hC+4sNV5dGxBhEUAh3ZU=; b=2Q2hl2LzITdZs4vk9SR0sk/U6M/cEGZXmmO/BBYz/Lt1W6ywK+V4av/gL8zeq7ySPB pf1cJxF/mfJOyRHvoYUGkEnMI0ApAWNE+vl26kuqIHqvkgVgLaobC4JwopF/Fkoubly3 SmXuq73U6/BH3otYs7OUZ04T6p2qU/w85lDuJj/WVLSU9wvtayskJAni98VMqPmhQKo/ C3RAc7kCZPm9fi3EjLdmN79gAgfxFIrLhBmjPg4EK+oadLrgGg7vMi1pvArRGZ+sGU5d r9Li/XQqUzo5MJY8M4Sf/pDDAtvO120wdAvLSQLlo8XF5J4TJ7epYoownZKCCvddg5jk hnjQ== X-Gm-Message-State: AOAM531/8Ylm3CP97WjvtKPMRnunQkoIq8SbuHhzdQnjmuU5iGOhWbd0 feSTyPK/1GRLDGOgvIb3BfM= X-Google-Smtp-Source: ABdhPJwFAgphDT678QEW7VWXj8k6i1GwEjBCaYDNGAPv6oGS3glcX9En450Rka0fCDvCp7Ve13HMwA== X-Received: by 2002:adf:d1e9:0:b0:20c:6c76:14d5 with SMTP id g9-20020adfd1e9000000b0020c6c7614d5mr2360003wrd.375.1651509460622; Mon, 02 May 2022 09:37:40 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:40 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 09/15] dma-buf/sync_file: add user fence support Date: Mon, 2 May 2022 18:37:16 +0200 Message-Id: <20220502163722.3957-10-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Keep user fences separate from normal fences. Signed-off-by: Christian König --- drivers/dma-buf/sync_file.c | 82 +++++++++++++++++++++++++++++++++---- include/linux/sync_file.h | 4 +- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index fe149d7e3ce2..630472d79dc1 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -70,7 +70,13 @@ struct sync_file *sync_file_create(struct dma_fence *fence) if (!sync_file) return NULL; - sync_file->fence = dma_fence_get(fence); + if (test_bit(DMA_FENCE_FLAG_USER, &fence->flags)) { + sync_file->fence = dma_fence_get_stub(false); + sync_file->user_fence = dma_fence_get(fence); + } else { + sync_file->fence = dma_fence_get(fence); + sync_file->user_fence = dma_fence_get_stub(true); + } return sync_file; } @@ -116,6 +122,28 @@ struct dma_fence *sync_file_get_fence(int fd) } EXPORT_SYMBOL(sync_file_get_fence); +/** + * sync_file_get_user_fence - get user fence related to the sync_file fd + * @fd: sync_file fd to get the fence from + * + * Ensures @fd references a valid sync_file and returns an user fence reference + * which represents all fence in the sync_file. On error NULL is returned. + */ +struct dma_fence *sync_file_get_user_fence(int fd) +{ + struct sync_file *sync_file; + struct dma_fence *fence; + + sync_file = sync_file_fdget(fd); + if (!sync_file) + return NULL; + + fence = dma_fence_merge(sync_file->fence, sync_file->user_fence); + fput(sync_file->file); + return fence; +} +EXPORT_SYMBOL(sync_file_get_user_fence); + /** * sync_file_get_name - get the name of the sync_file * @sync_file: sync_file to get the fence from @@ -136,6 +164,9 @@ char *sync_file_get_name(struct sync_file *sync_file, char *buf, int len) } else { struct dma_fence *fence = sync_file->fence; + if (dma_fence_is_signaled(fence)) + fence = sync_file->user_fence; + snprintf(buf, len, "%s-%s%llu-%lld", fence->ops->get_driver_name(fence), fence->ops->get_timeline_name(fence), @@ -159,21 +190,32 @@ char *sync_file_get_name(struct sync_file *sync_file, char *buf, int len) static struct sync_file *sync_file_merge(const char *name, struct sync_file *a, struct sync_file *b) { + struct dma_fence *fence, *user_fence; struct sync_file *sync_file; - struct dma_fence *fence; sync_file = sync_file_alloc(); if (!sync_file) return NULL; fence = dma_fence_merge(a->fence, b->fence); - if (!fence) { - fput(sync_file->file); - return NULL; - } + if (!fence) + goto error_fput; + + user_fence = dma_fence_merge(a->user_fence, b->user_fence); + if (!user_fence) + goto error_put_fence; + sync_file->fence = fence; + sync_file->user_fence = user_fence; strlcpy(sync_file->user_name, name, sizeof(sync_file->user_name)); return sync_file; + +error_put_fence: + dma_fence_put(fence); + +error_fput: + fput(sync_file->file); + return NULL; } static int sync_file_release(struct inode *inode, struct file *file) @@ -183,6 +225,7 @@ static int sync_file_release(struct inode *inode, struct file *file) if (test_bit(POLL_ENABLED, &sync_file->flags)) dma_fence_remove_callback(sync_file->fence, &sync_file->cb); dma_fence_put(sync_file->fence); + dma_fence_put(sync_file->user_fence); kfree(sync_file); return 0; @@ -191,17 +234,25 @@ static int sync_file_release(struct inode *inode, struct file *file) static __poll_t sync_file_poll(struct file *file, poll_table *wait) { struct sync_file *sync_file = file->private_data; + int ret; poll_wait(file, &sync_file->wq, wait); if (list_empty(&sync_file->cb.node) && !test_and_set_bit(POLL_ENABLED, &sync_file->flags)) { - if (dma_fence_add_callback(sync_file->fence, &sync_file->cb, - fence_check_cb_func) < 0) + ret = dma_fence_add_callback(sync_file->fence, &sync_file->cb, + fence_check_cb_func); + if (ret) { + ret = dma_fence_add_callback(sync_file->user_fence, + &sync_file->cb, + fence_check_cb_func); + } + if (ret) wake_up_all(&sync_file->wq); } - return dma_fence_is_signaled(sync_file->fence) ? EPOLLIN : 0; + return (dma_fence_is_signaled(sync_file->fence) && + dma_fence_is_signaled(sync_file->user_fence)) ? EPOLLIN : 0; } static long sync_file_ioctl_merge(struct sync_file *sync_file, @@ -299,6 +350,8 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, num_fences = 0; dma_fence_unwrap_for_each(fence, &iter, sync_file->fence) ++num_fences; + dma_fence_unwrap_for_each(fence, &iter, sync_file->user_fence) + ++num_fences; /* * Passing num_fences = 0 means that userspace doesn't want to @@ -307,7 +360,12 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, * info->num_fences. */ if (!info.num_fences) { + int status; + info.status = dma_fence_get_status(sync_file->fence); + status = dma_fence_get_status(sync_file->user_fence); + if (!info.status) + info.status = status; goto no_fences; } else { info.status = 1; @@ -328,6 +386,12 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, status = sync_fill_fence_info(fence, &fence_info[num_fences++]); info.status = info.status <= 0 ? info.status : status; } + dma_fence_unwrap_for_each(fence, &iter, sync_file->user_fence) { + int status; + + status = sync_fill_fence_info(fence, &fence_info[num_fences++]); + info.status = info.status <= 0 ? info.status : status; + } if (copy_to_user(u64_to_user_ptr(info.sync_fence_info), fence_info, size)) { diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h index 790ca021203a..14aff1a4ee75 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -50,13 +50,15 @@ struct sync_file { unsigned long flags; struct dma_fence *fence; - struct dma_fence_cb cb; + struct dma_fence *user_fence; + struct dma_fence_cb cb; }; #define POLL_ENABLED 0 struct sync_file *sync_file_create(struct dma_fence *fence); struct dma_fence *sync_file_get_fence(int fd); +struct dma_fence *sync_file_get_user_fence(int fd); char *sync_file_get_name(struct sync_file *sync_file, char *buf, int len); #endif /* _LINUX_SYNC_H */ From patchwork Mon May 2 16:37:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834411 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 131EDC433EF for ; Mon, 2 May 2022 16:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245618AbiEBQl1 (ORCPT ); Mon, 2 May 2022 12:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386375AbiEBQlR (ORCPT ); Mon, 2 May 2022 12:41:17 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BE4811A3F for ; Mon, 2 May 2022 09:37:43 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id k2so20242252wrd.5 for ; Mon, 02 May 2022 09:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RsppMnZlvpz/PS1/TtGolLScNmUL2porbiCTAL7nvFU=; b=a8nOHOjENFk8Xqwt3xRBWqsEDbDkcxAnWu2DgN6ZDlTrGJ1q3k5MN1DjOQ2zViSQg4 /pvQDUerSXJhjlxEWeERMaolbCrzCoqr56pyfb2TEL7vg+B7hOdMEIVTyYgxNOqqRQiV muLLlNRxADbcJZC0Xo7s+vNAzrLICHoUlxYFy64xxzxl8U7CmD+wchoGiqZyArMJGYyf m6y8dFfXLwy6xUJ3j6HJ9GsJN24zFxv3tC2YmECdIRGZlHnwRRNeMCFzeycRNMjZc5Rd FWhd8+2d5xbZspsYRjuRbwCa1ZanS8BMkagr654IsvWoWehrdkQCdAGIrfrQ0XnLSjlb NjGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RsppMnZlvpz/PS1/TtGolLScNmUL2porbiCTAL7nvFU=; b=KxC/l1eFbPYwLoYkY8rsSy4EWw/JBUX4Szfs4SDa5EXOQMNkuMJFUD5DJy6rlprJsj /pIotq5Kvb/HpD/k3rFuX9GxMRWV+Z7t40F4aqkkMBstEr/gA5CFfKUgtaQvSAwcYGPZ 2zM/2YhhrGpfskFpd/tjTl+zsIvobhuw0zal/Ac9SC3eglsaECVBVWVQP1C1ZKJCOvft asd4hkbhb8K4ZVifx5Z11a1ON1ZenfGRi5EviqaTjq8E/3L0+Wprzns0mMfLUNEQDzxA 0go1UzUWJD6gBcSmKaSCQeRqpZrx0Go1+PjKW49etw3vme3cuOhRzS7Shhgsb8hXUrbV EeLQ== X-Gm-Message-State: AOAM530vISCmZDPN5/6NSoOM09h/TvMbrxmE4kg3XxUiX9er0h8t8ZOB jYmUBgqSaxmfj/Giq20gJAM= X-Google-Smtp-Source: ABdhPJyTPKUM05Y+tnsze0dzaZtqnYwBQZsZfdgYGdtgR2xVTDvcPZhlwnNrXn5ccgWpn6iPCc00wA== X-Received: by 2002:a5d:5228:0:b0:20a:d7e9:7ed8 with SMTP id i8-20020a5d5228000000b0020ad7e97ed8mr9472997wra.687.1651509462037; Mon, 02 May 2022 09:37:42 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:41 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 10/15] drm: add user fence support for atomic out fences Date: Mon, 2 May 2022 18:37:17 +0200 Message-Id: <20220502163722.3957-11-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a new driver flag indicating support for user fences. This flag is then used when creating out fences for atomic mode setting, indicating that the mode set might depend on an user fence. Signed-off-by: Christian König --- drivers/gpu/drm/drm_atomic_uapi.c | 8 ++++++++ include/drm/drm_drv.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 434f3d4cb8a2..e2112c10569b 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -1111,6 +1111,7 @@ static int prepare_signaling(struct drm_device *dev, struct drm_out_fence_state **fence_state, unsigned int *num_fences) { + bool use_user_fence = drm_core_check_feature(dev, DRIVER_USER_FENCE); struct drm_crtc *crtc; struct drm_crtc_state *crtc_state; struct drm_connector *conn; @@ -1120,6 +1121,7 @@ static int prepare_signaling(struct drm_device *dev, if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) return 0; + for_each_new_crtc_in_state(state, crtc, crtc_state, i) { s32 __user *fence_ptr; @@ -1168,6 +1170,9 @@ static int prepare_signaling(struct drm_device *dev, if (!fence) return -ENOMEM; + if (use_user_fence) + set_bit(DMA_FENCE_FLAG_USER, &fence->flags); + ret = setup_out_fence(&f[(*num_fences)++], fence); if (ret) { dma_fence_put(fence); @@ -1208,6 +1213,9 @@ static int prepare_signaling(struct drm_device *dev, if (!fence) return -ENOMEM; + if (use_user_fence) + set_bit(DMA_FENCE_FLAG_USER, &fence->flags); + ret = setup_out_fence(&f[(*num_fences)++], fence); if (ret) { dma_fence_put(fence); diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index f6159acb8856..b2b8ea8d4a9e 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -94,6 +94,13 @@ enum drm_driver_feature { * synchronization of command submission. */ DRIVER_SYNCOBJ_TIMELINE = BIT(6), + /** + * @DRIVER_USER_FENCE: + * + * Drivers supports user fences and waiting for the before command + * submission. + */ + DRIVER_USER_FENCE = BIT(7), /* IMPORTANT: Below are all the legacy flags, add new ones above. */ From patchwork Mon May 2 16:37:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834413 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 2D2A6C4332F for ; Mon, 2 May 2022 16:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380588AbiEBQl2 (ORCPT ); Mon, 2 May 2022 12:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386380AbiEBQlR (ORCPT ); Mon, 2 May 2022 12:41:17 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E05F911C0B for ; Mon, 2 May 2022 09:37:44 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id i5so20218853wrc.13 for ; Mon, 02 May 2022 09:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KjkQ0JRQZyD+wsFR0t4oPn4rUlqhN8HCr5sJCzpjRmE=; b=XRFyPBX826gX+6Sf6EdgjzVcDAEC57cWAnpTUJSiNbTAuYlcDJqotYTXcL4OCIZhKK rGrruKwqySetpI5UYY3c8MrVsrYSkCQLOpxEzdboo9Q3r0Nlqe0Xu6KecryhvSGhaa53 /ALxzRnKwxCTsSUwi/t+VQAtFWy5YxseyD5HM/82srioDn+fYu6wEihksTJo4ja5Ahyt 5aTJtt+xiPZ1jQwB/Z137YFORgQkslcu+pdrKfbC5AEvSmvA5ShFJfsbwdOD6aix9GVg 9jwEfBxqiry31YlDKCDDNUjfPrZyXALr1nE9yv5ntYzzHvYbRz3QDLkMwnTv7gCUSx6V q1+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KjkQ0JRQZyD+wsFR0t4oPn4rUlqhN8HCr5sJCzpjRmE=; b=NYaovfUiABphkH57HY5D+nDx35mO+33K8pScAhzoL+29RWb+/Z4AtrIDg7GxAyIjwD uR6+K3iCA7pRoebIp/6kF2acaGQXcRq0x4V54KHcK0TKYnXnZDSLcmU0tkesfmEQeV5k 135KUME04iGvg97qa+0R7CFKWYA4IV6AvdI/4xFefZnO6AXjtl+k5MHx4ign6mzsdaJn Ga22n/TWf1ZLXanS/ZW7rcU5lZmeUCkc5gjyFln/+M8Bm0+M+c1JlGG9rm2r+FIu9PdR HMqgPfjh5BGLMDOxSdvyRzF4SGJfGLxwvjffjdzMyo2xBmoity/HXXnu2figuepgad+g qzQw== X-Gm-Message-State: AOAM533nkZfaSFOK/HiO8mMFz+xVyI/e2c+yR6HMvsB63XKwxU5Jz+1D animEHEZ8bdJe8k2hvnVTL8= X-Google-Smtp-Source: ABdhPJwIO4JMf3a/FHinF4NCDxZum5bVjIfSGJInrAQPVDJEyndnzfd420zGEtBXfAqSUovvsyyOEg== X-Received: by 2002:a05:6000:2c9:b0:20c:64c9:4b7a with SMTP id o9-20020a05600002c900b0020c64c94b7amr3727596wry.325.1651509463426; Mon, 02 May 2022 09:37:43 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:42 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 11/15] drm: add user fence support for atomic in fences Date: Mon, 2 May 2022 18:37:18 +0200 Message-Id: <20220502163722.3957-12-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When the DRIVER_USER_FENCE flag is set we grab the user fence from the sync file instead of the normal one. Signed-off-by: Christian König --- drivers/gpu/drm/drm_atomic_uapi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index e2112c10569b..d1b13657e2ae 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -517,7 +517,10 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane, if (U642I64(val) == -1) return 0; - state->fence = sync_file_get_fence(val); + if (drm_core_check_feature(dev, DRIVER_USER_FENCE)) + state->fence = sync_file_get_user_fence(val); + else + state->fence = sync_file_get_fence(val); if (!state->fence) return -EINVAL; From patchwork Mon May 2 16:37:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834415 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 797E3C43217 for ; Mon, 2 May 2022 16:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386305AbiEBQla (ORCPT ); Mon, 2 May 2022 12:41:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386321AbiEBQlR (ORCPT ); Mon, 2 May 2022 12:41:17 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E671DEC3 for ; Mon, 2 May 2022 09:37:46 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id d5so20239707wrb.6 for ; Mon, 02 May 2022 09:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ANagkIapfhSoILXgRSazGJNpDPTeoeZ/i/DcazZHEZQ=; b=bTOuNbcCcpWCjHPdLC317BrGpkkTWG9yauH9kogTYDUS11gKUb/mgOriNiNu5FbMvh LAemZaOirJJUTzK3l2TFLtT8rRLpJvT7BZfdmi8xJtNUvDM/vFRM8b5haRUFr6Y1+4MC qCKqOvdTddBF7iTIx2hrrK3YFoDENFIjRM7SFF17g1uVfGU//XWTc8I0OyxhXUnfX96I 8uHIPUuJmFcLDSrWHLzz2KRoGB52or1JhX5W0KPckcLJO6LOVnmxfQCirdxkWAXiCOoS b2OuUlzj4WKBC2Mr8e27FrWEEW5t0RhonknV7AExdcqkeJi7rBjBtbm8ey43b2ZNpyHP lxGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ANagkIapfhSoILXgRSazGJNpDPTeoeZ/i/DcazZHEZQ=; b=oWgP0Sxk4Ul/m6mNTkBSY3y+Uszf781rASsvGSuQnANHCNdGA41a4x+A44aDGegmIc wJAnJ5BmrgBTTLbJSNUSUlN13G7xiLJkFJVTf7xqbprhN12HKxLUmYqFPyCP4+LjMKyy CIwUP7lRODqik6uURERoFJ3qKfWryeb2dApA7ty4BiO7UEDGynneeZKYxYJESmyB+ji0 c6vdg61ZJxII30syw3dOaqt9qE3yK3ygt9TjfqVYus0AYUbqj9FKwEVhV41Efg8nZSKA DN2IgLLd4dBq/8wvC/UB7+q0VhfXg/0O5g5mNBb7jLdJMaLeCbMxVjqwhs3BfDJ/xoIf OXfA== X-Gm-Message-State: AOAM532WRmQoObvnEJ1qwmIOI1zbBFXOxUKr8xHsmqIW84aTXLlllXgZ eY1U4pDuksE6b1apRup+8qs= X-Google-Smtp-Source: ABdhPJxUDlk3kbTFRN1X2D1q1vvW3bPqNNYNXQ7eHBEpgoyEe35FHldqGH1tFKFmx0FwRPQczX4rgA== X-Received: by 2002:a5d:5749:0:b0:20a:ce36:b29 with SMTP id q9-20020a5d5749000000b0020ace360b29mr9849647wrw.559.1651509464807; Mon, 02 May 2022 09:37:44 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:44 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 12/15] drm: add user fence support to drm_gem_plane_helper_prepare_fb Date: Mon, 2 May 2022 18:37:19 +0200 Message-Id: <20220502163722.3957-13-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Just handle them the same way as fences with the DMA_RESV_USAGE_WRITE flag when the DRIVER_USER_FENCE flag is set. Signed-off-by: Christian König --- drivers/gpu/drm/drm_gem_atomic_helper.c | 68 ++++++++++++++++--------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_atomic_helper.c b/drivers/gpu/drm/drm_gem_atomic_helper.c index a5026f617739..75d04333ff2e 100644 --- a/drivers/gpu/drm/drm_gem_atomic_helper.c +++ b/drivers/gpu/drm/drm_gem_atomic_helper.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -121,6 +122,40 @@ * Plane Helpers */ +static int chain_fb_fences(struct drm_framebuffer *fb, + enum dma_resv_usage usage, + struct dma_fence **fence) +{ + size_t i; + int ret; + + for (i = 0; i < fb->format->num_planes; ++i) { + struct drm_gem_object *obj = drm_gem_fb_get_obj(fb, i); + struct dma_fence *new; + + if (WARN_ON_ONCE(!obj)) + continue; + + ret = dma_resv_get_singleton(obj->resv, usage, &new); + if (ret) + return ret; + + if (new && *fence) { + struct dma_fence_chain *chain = dma_fence_chain_alloc(); + + if (!chain) + return -ENOMEM; + + dma_fence_chain_init(chain, *fence, new, 1); + *fence = &chain->base; + + } else if (new) { + *fence = new; + } + } + return 0; +} + /** * drm_gem_plane_helper_prepare_fb() - Prepare a GEM backed framebuffer * @plane: Plane @@ -143,8 +178,6 @@ int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state) { struct dma_fence *fence = dma_fence_get(state->fence); - enum dma_resv_usage usage; - size_t i; int ret; if (!state->fb) @@ -163,32 +196,21 @@ int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, * obeys both implicit and explicit fences for plane updates, then it * will break all the benefits of explicit fencing. */ - usage = fence ? DMA_RESV_USAGE_KERNEL : DMA_RESV_USAGE_WRITE; - - for (i = 0; i < state->fb->format->num_planes; ++i) { - struct drm_gem_object *obj = drm_gem_fb_get_obj(state->fb, i); - struct dma_fence *new; - - if (WARN_ON_ONCE(!obj)) - continue; - - ret = dma_resv_get_singleton(obj->resv, usage, &new); + if (fence) { + ret = chain_fb_fences(state->fb, DMA_RESV_USAGE_KERNEL, &fence); if (ret) goto error; - if (new && fence) { - struct dma_fence_chain *chain = dma_fence_chain_alloc(); + } else { + ret = chain_fb_fences(state->fb, DMA_RESV_USAGE_WRITE, &fence); + if (ret) + goto error; - if (!chain) { - ret = -ENOMEM; + if (drm_core_check_feature(plane->dev, DRIVER_USER_FENCE)) { + ret = chain_fb_fences(state->fb, DMA_RESV_USAGE_USER, + &fence); + if (ret) goto error; - } - - dma_fence_chain_init(chain, fence, new, 1); - fence = &chain->base; - - } else if (new) { - fence = new; } } From patchwork Mon May 2 16:37:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834418 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 E0406C433F5 for ; Mon, 2 May 2022 16:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386325AbiEBQld (ORCPT ); Mon, 2 May 2022 12:41:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386389AbiEBQlS (ORCPT ); Mon, 2 May 2022 12:41:18 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B212EB86A for ; Mon, 2 May 2022 09:37:47 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id r1-20020a1c2b01000000b00394398c5d51so1819352wmr.2 for ; Mon, 02 May 2022 09:37:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JJ3syRLZRf5cDZllRXn7Ii6fAdy4TAhne+oUq4LR8JM=; b=EJuFYyX/onL0HJ4JSG09ScoRSS3raya0MlgJRdQTgbH3rpOwp1ndohsJQHAJ6vQKFk uJ/DryMLrBrEgbCEvYEL2tZvd1i2sCSFCUGQFW5CAyUM0bavc3zeOKOUnCQsvVGyUcO9 yWXrJmVXaxLV+Tqqg6PYxhaWB3inavH2X6ocugBjq/Vspv1DB+XzoV8vtJg7ZbcjBkLf WnCHUyKoZVrkAR6WdIki9mb7GjswsNdFEa4m0612subrl2ukwHVtqP1Upjs87+NW5aUs saU9wTuWvQjwqY6pVnlNsN0Q7jvICgBmsVa3FCWbHqSLvmfnFfJEIP2+9bKSZTfPwQii 1cTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JJ3syRLZRf5cDZllRXn7Ii6fAdy4TAhne+oUq4LR8JM=; b=qjt0e3vg+XomWYHhD4JZYISqH3S+PgFl6BjCLQBw/x+DnoZGU0DL4QohK2rcGZb7LV HT+4WaAT9ziRCFFjXqqet9BqHs56uVQb6fxbgdIS1FE/EdCvNYOt++xUio+duIcm3f1A fs1pswdZ45vtcvDsSba6jEVzcyrWqk2Q0cxk4nv5FJpzhVk+cyv4y+lJPwk8UWXD/fTl easHUh2zOk1u+Iw0Yws5Dl6AHbFUaNr4tyjGhINzZbhUmLBUWuAouUTPATdH1as4Qgf5 7U02amwH/VEhl1NUIFABQBZFrqRA08M+pguQ2ZaHAhxDfrvFFQbpKQe10F7+BnlYonJr 8lCA== X-Gm-Message-State: AOAM5329yrdYe9Og6w20Hl3ol2gclrKv8WXq/0YzevvO0jnIsRVPZyJF miMF59yGLiwQFBxSqW1yVmA= X-Google-Smtp-Source: ABdhPJxYRvcNEnBAIcm2IwUgbnbX3g7RWLKbs5dcfFuCkBVefhGVaJWd+oqaJeeDM2lCNNoP6SCyMg== X-Received: by 2002:a05:600c:190d:b0:393:ee55:5686 with SMTP id j13-20020a05600c190d00b00393ee555686mr2328wmq.126.1651509466306; Mon, 02 May 2022 09:37:46 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:45 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 13/15] drm: add user fence support to drm_syncobj Date: Mon, 2 May 2022 18:37:20 +0200 Message-Id: <20220502163722.3957-14-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org For now just filter or wait for user fences. Signed-off-by: Christian König --- drivers/gpu/drm/drm_syncobj.c | 15 ++++++++++++--- include/drm/drm_syncobj.h | 25 +++++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 5a961ea90a35..8d25a2dd107b 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -386,7 +386,7 @@ int drm_syncobj_find_fence(struct drm_file *file_private, struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); struct syncobj_wait_entry wait; u64 timeout = nsecs_to_jiffies64(DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT); - int ret; + long ret; if (!syncobj) return -ENOENT; @@ -398,10 +398,19 @@ int drm_syncobj_find_fence(struct drm_file *file_private, if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) { might_sleep(); lockdep_assert_none_held_once(); + *fence = drm_syncobj_user_fence_get(syncobj); + if (*fence) { + ret = dma_fence_wait_user(*fence, timeout); + if (ret < 0) + return ret; + if (ret == 0) + return -ETIME; + timeout = ret; + } + } else { + *fence = drm_syncobj_fence_get(syncobj); } - *fence = drm_syncobj_fence_get(syncobj); - if (*fence) { ret = dma_fence_chain_find_seqno(fence, point); if (!ret) { diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h index 6cf7243a1dc5..acc3979815eb 100644 --- a/include/drm/drm_syncobj.h +++ b/include/drm/drm_syncobj.h @@ -28,6 +28,7 @@ #include #include +#include struct drm_file; @@ -89,18 +90,18 @@ drm_syncobj_put(struct drm_syncobj *obj) } /** - * drm_syncobj_fence_get - get a reference to a fence in a sync object + * drm_syncobj_user_fence_get - get an user fence from a sync object * @syncobj: sync object. * * This acquires additional reference to &drm_syncobj.fence contained in @obj, - * if not NULL. It is illegal to call this without already holding a reference. - * No locks required. + * if not NULL. It is illegal to call this without holding a reference to the + * syncobj. No locks required. * * Returns: * Either the fence of @obj or NULL if there's none. */ static inline struct dma_fence * -drm_syncobj_fence_get(struct drm_syncobj *syncobj) +drm_syncobj_user_fence_get(struct drm_syncobj *syncobj) { struct dma_fence *fence; @@ -111,6 +112,22 @@ drm_syncobj_fence_get(struct drm_syncobj *syncobj) return fence; } +/** + * drm_syncobj_fence_get - get a reference to a fence in a sync object + * @syncobj: sync object. + * + * Same functionality as drm_syncobj_user_fence_get(), but user fences are + * filtered out. + * + * Returns: + * Either the fence of @obj or NULL if there's none. + */ +static inline struct dma_fence * +drm_syncobj_fence_get(struct drm_syncobj *syncobj) +{ + return dma_fence_filter_user(drm_syncobj_user_fence_get(syncobj)); +} + struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private, u32 handle); void drm_syncobj_add_point(struct drm_syncobj *syncobj, From patchwork Mon May 2 16:37:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834419 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 7C178C4332F for ; Mon, 2 May 2022 16:38:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386331AbiEBQle (ORCPT ); Mon, 2 May 2022 12:41:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386338AbiEBQlS (ORCPT ); Mon, 2 May 2022 12:41:18 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 515FDDFA6 for ; Mon, 2 May 2022 09:37:49 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 129so8583527wmz.0 for ; Mon, 02 May 2022 09:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=paocEfPgSqu67n8KLHsQSQJ/DJyKOx4pTU1l0q+u0sU=; b=VlkS5sgarlYWn0MnwUTY3aeqE4Snozzu8nEzmHLBPm4YKIU7G+YGuHGBpdnwVjenim IisHP/2UQFKrjOj9yR1h4U8zH81F6bicVL0O6wZ1Rl+PebVe7A33GUHVGWHfdEt0fGHL 50SHMe3EyX1yoojUuwDJKaCiAxz6xAL+d4np6qFo0GrAZQB1yRIrmlaEwFAaxc1PdM/w O5Jn5KOZeJhmgH6SJPjXshycuGRsZS2IvvtN8/kob74SDdniTfz+W8ix+Tzle84Aonfu If2W70R4KzP2rCZrk7cux5qY36dYnqm6OniYOzgEoSNHZPPeyYENMnS8L9lxJ+6LG9EM wXOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=paocEfPgSqu67n8KLHsQSQJ/DJyKOx4pTU1l0q+u0sU=; b=QA/YSsK+QCG6mKSin4FR48n0ZKi/tIy4SPp19p4DI05FzhdazygPlPfBqzZnmtDlPC hURMtIlTW9t2hCFqxiKAFANMJoEViUgGM1Ra08uoMpiDNuscgn8/eYoqEDgqc7G8mmGM Me9acWOXEys8f37O4XqcQsf2IBquBtrZ1jQBPm1ft97bm5Ji1a2v2XOObxwhIVkhcuDv qttFDsBFk/dbRAWMjphqxA9CMbvKbFeNe+il7lf5IuJwgDv6sMtT7Bd5EszvtGqqx/Tj QQ0JG53u/vZVDSb9TkMKFEKP25WIQQ3bNayZc5f6MaNvKlCrbEFEjFfJN0h7t10+xzxC spzA== X-Gm-Message-State: AOAM531bShIxIBcXVpQaKb/RkMXebAE66uNHl9T9ZSJonsz1J41e2psT hCo6VmM0Z88V6bu24Z1DnDE= X-Google-Smtp-Source: ABdhPJxl04mnJLBE6tuBmOzv32rWsrcZLRuHOgfEtMeSpdmfs0QlfaGTPzlaUDTFvluVRH+0hWC5CQ== X-Received: by 2002:a1c:f415:0:b0:37f:ab4d:1df2 with SMTP id z21-20020a1cf415000000b0037fab4d1df2mr15431594wma.75.1651509467952; Mon, 02 May 2022 09:37:47 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:47 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= , Harry Wentland , Nicholas Kazlauskas , Roman Li , Qingqing Zhuo , Jude Shih , Wayne Lin , Rodrigo Siqueira Subject: [PATCH 14/15] drm/amdgpu: switch DM to atomic fence helpers Date: Mon, 2 May 2022 18:37:21 +0200 Message-Id: <20220502163722.3957-15-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This gives us the standard atomic implicit and explicit fencing rules. Signed-off-by: Christian König Cc: Harry Wentland Cc: Nicholas Kazlauskas Cc: Roman Li Cc: Qingqing Zhuo Cc: Jude Shih Cc: Wayne Lin Cc: Rodrigo Siqueira --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 2ade82cfb1ac..c5b2417adcc6 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -83,6 +83,7 @@ #include #include #include +#include #if defined(CONFIG_DRM_AMD_DC_DCN) #include "ivsrcid/dcn/irqsrcs_dcn_1_0.h" @@ -7627,6 +7628,10 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane, goto error_unpin; } + r = drm_gem_plane_helper_prepare_fb(plane, new_state); + if (unlikely(r != 0)) + goto error_unpin; + amdgpu_bo_unreserve(rbo); afb->address = amdgpu_bo_gpu_offset(rbo); @@ -9160,7 +9165,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dm_crtc_state *dm_old_crtc_state = to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc)); int planes_count = 0, vpos, hpos; - long r; unsigned long flags; struct amdgpu_bo *abo; uint32_t target_vblank, last_flip_vblank; @@ -9173,6 +9177,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_flip_addrs flip_addrs[MAX_SURFACES]; struct dc_stream_update stream_update; } *bundle; + int r; bundle = kzalloc(sizeof(*bundle), GFP_KERNEL); @@ -9181,6 +9186,10 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, goto cleanup; } + r = drm_atomic_helper_wait_for_fences(dev, state, false); + if (unlikely(r)) + DRM_ERROR("Waiting for fences timed out!"); + /* * Disable the cursor first if we're disabling all the planes. * It'll remain on the screen after the planes are re-enabled @@ -9235,18 +9244,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, } abo = gem_to_amdgpu_bo(fb->obj[0]); - - /* - * Wait for all fences on this FB. Do limited wait to avoid - * deadlock during GPU reset when this fence will not signal - * but we hold reservation lock for the BO. - */ - r = dma_resv_wait_timeout(abo->tbo.base.resv, - DMA_RESV_USAGE_WRITE, false, - msecs_to_jiffies(5000)); - if (unlikely(r <= 0)) - DRM_ERROR("Waiting for fences timed out!"); - fill_dc_plane_info_and_addr( dm->adev, new_plane_state, afb->tiling_flags, From patchwork Mon May 2 16:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12834417 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 98EFCC433FE for ; Mon, 2 May 2022 16:38:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386333AbiEBQlc (ORCPT ); Mon, 2 May 2022 12:41:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381117AbiEBQlU (ORCPT ); Mon, 2 May 2022 12:41:20 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2281DF9D for ; Mon, 2 May 2022 09:37:50 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m2-20020a1ca302000000b003943bc63f98so1641701wme.4 for ; Mon, 02 May 2022 09:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JaejlDfj0uy9dkJeeagJEWX0/Sis0ZiAGo/I1Cyla8w=; b=WJ14jFIJZIdqObfgPXjsBsWmhqzPN5JNkavdyclcrjJvsiZMlKFrcxW82UKBOKg1Kt +FyDEMWQJLDovDeCeOC7uNufANhJwlQ3HGaAmUM8PD8QWue6I5FD2dl2byPzAYnQlbZT 1cFPbuBXiU+xID11jsSFtSTxaemQaed+J9VZrU7HrUImIBhc0ZWXbAwlimB4YDWbYXAZ BIqdUTzQvGbtjWRv1nOZTP8ZrA2jOBZt2ADK+xok8RzzOzmtHyvCAsgiYiOLK9IAOuex G6KX9NjweCQ+WmEDsvJ3zeqmrC5ueLUwluvFRCmkoAhT411SV3lUfs3KI3mu03Opg0B4 du0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JaejlDfj0uy9dkJeeagJEWX0/Sis0ZiAGo/I1Cyla8w=; b=chZNj8D96bX1pZhZMdI/JqpsTL9iBH0/TiIlQQGCRKJiLTaufhBde8SRZOzBSb8i1i p29LCa5/5sVRxNI+wq53C4RZVtwHXFWBzBv9bFhZFojDmEHNn/SQY5uEtSMJ249LN2Ss 5fOZc1/skcPjD/QL3S1pjRvJUyahI9/mD/YB+a49Z1ImQkdCYQE5OJ8XDaT6yjmY7V4q sXnN23OkMojO7WsVbGhE2tIxzADhtO1J5yqDQ4ZrfHeZKX5Fe2Wq3ptmID9mg7IszBiZ jadDk8hdVIBPi9t/rnpCTuN+6thxqnrqvASk0jnLofPUiY69U3tcuF05fVBcj+griNum wn5w== X-Gm-Message-State: AOAM530ToOFjANFvRF0UBzhvJFVbQNce71Ari/TCmZvO4UbfxzJrQctV E6JWMvJ+LAOotxtIctSPz/g= X-Google-Smtp-Source: ABdhPJynMfTwX3SfWHMTUt/qZtPV8EjvjXV8D1iGxBM93doCrtHO7arJvRfSWJC8eKAagR1WU/LPWA== X-Received: by 2002:a05:600c:25d2:b0:394:2db5:bc32 with SMTP id 18-20020a05600c25d200b003942db5bc32mr10549461wml.39.1651509469475; Mon, 02 May 2022 09:37:49 -0700 (PDT) Received: from able.fritz.box (p57b0b9e1.dip0.t-ipconnect.de. [87.176.185.225]) by smtp.gmail.com with ESMTPSA id p14-20020adfaa0e000000b0020c5253d8f6sm7294694wrd.66.2022.05.02.09.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:37:48 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, jason@jlekstrand.net, daniels@collabora.com, skhawaja@google.com, maad.aldabagh@amd.com, sergemetral@google.com, sumit.semwal@linaro.org, gustavo@padovan.org, Felix.Kuehling@amd.com, alexander.deucher@amd.com, tzimmermann@suse.de, tvrtko.ursulin@linux.intel.com, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Cc: =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 15/15] drm/amdgpu: user fence proof of concept Date: Mon, 2 May 2022 18:37:22 +0200 Message-Id: <20220502163722.3957-16-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220502163722.3957-1-christian.koenig@amd.com> References: <20220502163722.3957-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Just some hack to test the functionality, not a real implementation of the interface. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 28 ++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 9 ++++-- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index da667c21ad55..e18efb21c452 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -286,7 +286,8 @@ void dma_resv_add_fence(struct dma_resv *obj, struct dma_fence *fence, /* Drivers should not add containers here, instead add each fence * individually. */ - WARN_ON(dma_fence_is_container(fence)); + //WARN_ON(dma_fence_is_container(fence)); + /* User fences must be added using DMA_RESV_USAGE_USER */ WARN_ON(test_bit(DMA_FENCE_FLAG_USER, &fence->flags) != diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 95eeab527ca9..299ab8e50c42 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -453,6 +453,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, struct amdgpu_vm *vm = &fpriv->vm; struct amdgpu_bo_list_entry *e; struct drm_gem_object *obj; + long timeout = HZ / 10; struct amdgpu_bo *gds; struct amdgpu_bo *gws; struct amdgpu_bo *oa; @@ -476,6 +477,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, return r; } + amdgpu_bo_list_for_each_entry(e, p->bo_list) { + struct dma_resv *resv = e->bo->tbo.base.resv; + + timeout = dma_resv_wait_timeout(resv, DMA_RESV_USAGE_USER, + true, timeout); + if (unlikely(timeout < 0)) + return timeout; + if (unlikely(timeout == 0)) + return -ETIME; + } + /* Get userptr backing pages. If pages are updated after registered * in amdgpu_gem_userptr_ioctl(), amdgpu_cs_list_validate() will do * amdgpu_ttm_backend_bind() to flush and invalidate new pages @@ -516,7 +528,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, return r; amdgpu_bo_list_for_each_entry(e, p->bo_list) { - r = drm_exec_prepare_obj(&p->exec, &e->bo->tbo.base, 2); + r = drm_exec_prepare_obj(&p->exec, &e->bo->tbo.base, 3); drm_exec_break_on_contention(&p->exec); if (unlikely(r)) return r; @@ -527,7 +539,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, if (p->uf_bo) { r = drm_exec_prepare_obj(&p->exec, &p->uf_bo->tbo.base, - 2); + 3); drm_exec_continue_on_contention(&p->exec); if (unlikely(r)) return r; @@ -1160,6 +1172,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, struct drm_sched_entity *entity = p->entity; struct amdgpu_bo_list_entry *e; struct drm_gem_object *gobj; + struct dma_fence *dummy; struct amdgpu_job *job; unsigned long index; uint64_t seq; @@ -1191,6 +1204,11 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, } p->fence = dma_fence_get(&job->base.s_fence->finished); + dummy = dma_fence_merge(p->fence, dma_fence_get_stub(true)); + if (!dummy) { + r = -ENOMEM; + goto error_abort; + } amdgpu_ctx_add_fence(p->ctx, entity, p->fence, &seq); amdgpu_cs_post_dependencies(p); @@ -1214,11 +1232,13 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, drm_exec_for_each_duplicate_object(&p->exec, index, gobj) { ttm_bo_move_to_lru_tail_unlocked(&gem_to_amdgpu_bo(gobj)->tbo); - dma_resv_add_fence(gobj->resv, p->fence, DMA_RESV_USAGE_WRITE); + dma_resv_add_fence(gobj->resv, p->fence, DMA_RESV_USAGE_KERNEL); + dma_resv_add_fence(gobj->resv, dummy, DMA_RESV_USAGE_USER); } drm_exec_for_each_locked_object(&p->exec, index, gobj) { ttm_bo_move_to_lru_tail_unlocked(&gem_to_amdgpu_bo(gobj)->tbo); - dma_resv_add_fence(gobj->resv, p->fence, DMA_RESV_USAGE_WRITE); + dma_resv_add_fence(gobj->resv, p->fence, DMA_RESV_USAGE_KERNEL); + dma_resv_add_fence(gobj->resv, dummy, DMA_RESV_USAGE_USER); } mutex_unlock(&p->adev->notifier_lock); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index b03663f42cc9..bd334f5fd64f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2655,7 +2655,7 @@ static const struct drm_driver amdgpu_kms_driver = { DRIVER_ATOMIC | DRIVER_GEM | DRIVER_RENDER | DRIVER_MODESET | DRIVER_SYNCOBJ | - DRIVER_SYNCOBJ_TIMELINE, + DRIVER_SYNCOBJ_TIMELINE | DRIVER_USER_FENCE, .open = amdgpu_driver_open_kms, .postclose = amdgpu_driver_postclose_kms, .lastclose = amdgpu_driver_lastclose_kms, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index e5c8e72a9485..6705287887e9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -628,7 +628,7 @@ static void amdgpu_vm_pt_next_dfs(struct amdgpu_device *adev, */ int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec) { - return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base, 4); + return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base, 5); } /** diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index c5b2417adcc6..2e0f059b9d12 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -7627,12 +7627,11 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane, DRM_ERROR("%p bind failed\n", rbo); goto error_unpin; } + amdgpu_bo_unreserve(rbo); r = drm_gem_plane_helper_prepare_fb(plane, new_state); if (unlikely(r != 0)) - goto error_unpin; - - amdgpu_bo_unreserve(rbo); + goto error_reserve; afb->address = amdgpu_bo_gpu_offset(rbo); @@ -7665,6 +7664,10 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane, return 0; +error_reserve: + if (WARN_ON(amdgpu_bo_reserve(rbo, true))) + return r; + error_unpin: amdgpu_bo_unpin(rbo);