From patchwork Thu Jun 17 11:15:43 2021 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: 463425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 208FFC48BE5 for ; Thu, 17 Jun 2021 11:16:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0544561369 for ; Thu, 17 Jun 2021 11:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232443AbhFQLSL (ORCPT ); Thu, 17 Jun 2021 07:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbhFQLSL (ORCPT ); Thu, 17 Jun 2021 07:18:11 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BBDAC061574 for ; Thu, 17 Jun 2021 04:16:03 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id i13so3441380edb.9 for ; Thu, 17 Jun 2021 04:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZR9DlJa3jlukpGNrraw8yl0uJdk87bmE6IiDxI/ezGM=; b=Rvqg5t1b2ghztUpefu+Xpb7xWdN1tRGvggXMLtfNyvzBRZPxTntXSwG+P+igS+o9bc MIZHnC7uLTBiAv2yYB8Hn/4AA2jqDoihqf9NDsQj5INmrXLc6dBlcRi+ElRDlqY6/nEQ JN5o7fuEqg7t12BvtAu/bBfp+7zAhELZOaPbxDIr7e/uaFT28oo6/HDyEm1WbPIX3+wx 39tTdCejlNQ9x70j/t9uMMKMIPubNzLRFFw0D/0YlZFdOtzUEVUTsSHeuH7Tryhf9loq pkn5k2agWoQwGxTW3RMt2WkbNm+s4D0W70iOZiIksVPcXof7olY8+GzLRqCr8ou5EwJs VNDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZR9DlJa3jlukpGNrraw8yl0uJdk87bmE6IiDxI/ezGM=; b=NYrO+GdKrjK3UtLAkbsJw6bYFOd82zqmL3PIGXg2HpwnRPeSWySgipfbiPnz2CqIqj 0T5lJYF4DdJiC9660afmLqAOXVTimB7iHbvzQlXgeCHuzeLSfHUV/4FLUKEFCSpMrlJR bb0gDeR4byMBUhjBnMAaelKCFmFETWJxcBStIlD7MwV2xLErFQK5nN38qVy+5RbyqkRC S0pMFxL0Y/LHP9yzqFT8eWi+qAS4LOooTn51QfC4OgHtkPakng/QWHJ6jSyNib1druVp kgiP0NwFu8irz1wzVXppxKE/B6p2nCcPAfv1U1BE1/fZYOcv2BX4i8nJKxJAC4uXi+wu bvJg== X-Gm-Message-State: AOAM53333e/mCnzZUMLlYMEml06lYbqbrRR6bKArGJzHE5aFBdoUDzAh 0eN9nXK9W3Gr+is8uY8NlQs= X-Google-Smtp-Source: ABdhPJwKPCwc0R12QImmoQJvrnKhDadPnsB2pyM5lsSXsdeqz0r1qYYgIq3dN7S8mvjIoEwCsL9eqA== X-Received: by 2002:aa7:d818:: with SMTP id v24mr5717557edq.22.1623928562097; Thu, 17 Jun 2021 04:16:02 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:01 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 01/16] dma-buf: add dma_resv_for_each_fence_unlocked Date: Thu, 17 Jun 2021 13:15:43 +0200 Message-Id: <20210617111558.28486-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Abstract the complexity of iterating over all the fences in a dma_resv object. The new loop handles the whole RCU and retry dance and returns only fences where we can be sure we grabbed the right one. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 63 ++++++++++++++++++++++++++++++++++++++ include/linux/dma-resv.h | 36 ++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index 18dd5a6ca06c..d8da8a914b07 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -316,6 +316,69 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence) } EXPORT_SYMBOL(dma_resv_add_excl_fence); +/** + * dma_resv_walk_unlocked - walk over fences in a dma_resv obj + * @obj: the dma_resv object + * @cursor: cursor to record the current position + * @all_fences: true returns also the shared fences + * @first: if we should start over + * + * Return all the fences in the dma_resv object which are not yet signaled. + * The returned fence has an extra local reference so will stay alive. + * If a concurrent modify is detected the whole iterator is started over again. + */ +struct dma_fence *dma_resv_walk_unlocked(struct dma_resv *obj, + struct dma_resv_cursor *cursor, + bool all_fences, bool first) +{ + struct dma_fence *fence = NULL; + + do { + /* Drop the reference from the previous round */ + dma_fence_put(fence); + + cursor->is_first = first; + if (first) { + cursor->seq = read_seqcount_begin(&obj->seq); + cursor->index = -1; + cursor->fences = dma_resv_shared_list(obj); + cursor->is_exclusive = true; + + fence = dma_resv_excl_fence(obj); + if (fence && test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, + &fence->flags)) + fence = NULL; + } else { + fence = NULL; + } + + if (fence) { + fence = dma_fence_get_rcu(fence); + } else if (all_fences && cursor->fences) { + struct dma_resv_list *fences = cursor->fences; + + cursor->is_exclusive = false; + while (++cursor->index < fences->shared_count) { + fence = rcu_dereference(fences->shared[ + cursor->index]); + if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, + &fence->flags)) + break; + } + if (cursor->index < fences->shared_count) + fence = dma_fence_get_rcu(fence); + else + fence = NULL; + } + + /* For the eventually next round */ + first = true; + } while (read_seqcount_retry(&obj->seq, cursor->seq)); + + return fence; +} +EXPORT_SYMBOL_GPL(dma_resv_walk_unlocked); + /** * dma_resv_copy_fences - Copy all fences from src to dst. * @dst: the destination reservation object diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h index 562b885cf9c3..74775f2cb679 100644 --- a/include/linux/dma-resv.h +++ b/include/linux/dma-resv.h @@ -75,6 +75,39 @@ struct dma_resv { struct dma_resv_list __rcu *fence; }; +/** + * struct dma_resv_cursor - current position into the dma_resv fences + * @seq: sequence number to check + * @index: index into the shared fences + * @shared: the shared fences + * @is_first: true if this is the first returned fence + * @is_exclusive: if the current fence is the exclusive one + */ +struct dma_resv_cursor { + unsigned int seq; + unsigned int index; + struct dma_resv_list *fences; + bool is_first; + bool is_exclusive; +}; + +/** + * dma_resv_for_each_fence_unlocked - fence iterator + * @obj: a dma_resv object pointer + * @cursor: a struct dma_resv_cursor pointer + * @all_fences: true if all fences should be returned + * @fence: the current fence + * + * Iterate over the fences in a struct dma_resv object without holding the + * dma_resv::lock. The RCU read side lock must be hold when using this, but can + * be dropped and re-taken as necessary inside the loop. @all_fences controls + * if the shared fences are returned as well. + */ +#define dma_resv_for_each_fence_unlocked(obj, cursor, all_fences, fence) \ + for (fence = dma_resv_walk_unlocked(obj, cursor, all_fences, true); \ + fence; dma_fence_put(fence), \ + fence = dma_resv_walk_unlocked(obj, cursor, all_fences, false)) + #define dma_resv_held(obj) lockdep_is_held(&(obj)->lock.base) #define dma_resv_assert_held(obj) lockdep_assert_held(&(obj)->lock.base) @@ -272,6 +305,9 @@ void dma_resv_fini(struct dma_resv *obj); int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences); void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence); void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence); +struct dma_fence *dma_resv_walk_unlocked(struct dma_resv *obj, + struct dma_resv_cursor *cursor, + bool first, bool all_fences); int dma_resv_get_fences(struct dma_resv *obj, struct dma_fence **pfence_excl, unsigned *pshared_count, struct dma_fence ***pshared); int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src); From patchwork Thu Jun 17 11:15:44 2021 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: 462531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79C77C49EA2 for ; Thu, 17 Jun 2021 11:16:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5597C61209 for ; Thu, 17 Jun 2021 11:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232445AbhFQLSM (ORCPT ); Thu, 17 Jun 2021 07:18:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbhFQLSL (ORCPT ); Thu, 17 Jun 2021 07:18:11 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F218C06175F for ; Thu, 17 Jun 2021 04:16:04 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id i13so3441417edb.9 for ; Thu, 17 Jun 2021 04:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=QwbcxXanDdJ2d4Tkh7MSwWgLm8MXgHEgQcVtF2+fnXw=; b=VYiAdSUpabrYQxf/5Q9T9pzoosNfxKvvcYCOU4N8CAnT20jv3liLa6tXKxAWjn+3mf R3B6EhnU3ZmJuBekc3jgyDFtLzhTToIALdmCxhSGuElsXa6UMaG+WmnDbW97yHjCAHvy vXKWiJAH2r8MMubZsa1j2raBZwiq3NaGcGHgYD3TPYZ+CJI63DkgRziX2d5SnWg1XCUC RpolG01ErVrQyhLwONH6/nHD+v4mpjaTfbhq9g1rnN1QZYITrBz/J2SY/IQ/S3n+gJm/ PPnMVi/UrpOFoV6bMwkSej5QEouZS5Wjc/4FKOiuW6oH9Dr/8IXuNdasW5C3/j3ng9tu WHxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QwbcxXanDdJ2d4Tkh7MSwWgLm8MXgHEgQcVtF2+fnXw=; b=qf4x0mUygM2WiwFCYcpdIIu9PWHwpZRD+B9BFYN88No0Vohzv7vqlmakThDIeJL7rT xhwz29+I0A9UKED/cdy0hd75y2+Aza0bSYg9g/cEtqp7Fk2TVEZodDW+M95ATL93Wi7N M+UClpSRfW9OHocI4MI0xdHCZbI02N+lTVmFyZtwh01nvf5pKL4fwEjT3NSyMeeDphhD 4fHv8+iflppMrPfzuSaBckBnmmmHxblXvUv47QDmdMQGoja/5JbsrTBOpXqquKBCf3Yb 7YHemUtpYDcJ64czX0tDZO4XVvP0IB9iF1VikawEe11FuQT60ZCOcXvE7VF+eLfq0jGs pNTg== X-Gm-Message-State: AOAM532soFskb7yQp//GV54j2g143CJbIJuMK2DWv8z1j0zAgApa0GKV j5NdH79CBLf+gkdLW+FyhRc= X-Google-Smtp-Source: ABdhPJxsAeGOMGrsWEzYAP//DCSm6c2fQOCh4HCYpn8G3v0EwED6DXWAj+I/4zQHTmQdWvI14JPyOA== X-Received: by 2002:a05:6402:11d3:: with SMTP id j19mr5782846edw.247.1623928562743; Thu, 17 Jun 2021 04:16:02 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:02 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 02/16] dma-buf: add dma_resv_for_each_fence Date: Thu, 17 Jun 2021 13:15:44 +0200 Message-Id: <20210617111558.28486-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org A simpler version of the iterator to be used when the dma_resv object is locked. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/dma-resv.h | 18 ++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index d8da8a914b07..a0386cf5824c 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -316,6 +316,44 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence) } EXPORT_SYMBOL(dma_resv_add_excl_fence); +/** + * dma_resv_walk - walk over fences in a dma_resv obj + * @obj: the dma_resv object + * @cursor: cursor to record the current position + * @all_fences: true returns also the shared fences + * @first: if we should start over + * + * Return all the fences in the dma_resv object while holding the + * dma_resv::lock. + */ +struct dma_fence *dma_resv_walk(struct dma_resv *obj, + struct dma_resv_cursor *cursor, + bool all_fences, bool first) +{ + dma_resv_assert_held(obj); + + cursor->is_first = first; + if (first) { + struct dma_fence *fence; + + cursor->index = -1; + cursor->fences = dma_resv_shared_list(obj); + cursor->is_exclusive = true; + + fence = dma_resv_excl_fence(obj); + if (fence) + return fence; + } + + if (!all_fences || !cursor->fences || + ++cursor->index >= cursor->fences->shared_count) + return NULL; + + return rcu_dereference_protected(cursor->fences->shared[cursor->index], + dma_resv_held(obj)); +} +EXPORT_SYMBOL_GPL(dma_resv_walk); + /** * dma_resv_walk_unlocked - walk over fences in a dma_resv obj * @obj: the dma_resv object diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h index 74775f2cb679..84de4dff4ecc 100644 --- a/include/linux/dma-resv.h +++ b/include/linux/dma-resv.h @@ -91,6 +91,21 @@ struct dma_resv_cursor { bool is_exclusive; }; +/** + * dma_resv_for_each_fence - fence iterator + * @obj: a dma_resv object pointer + * @cursor: a struct dma_resv_cursor pointer + * @all_fences: true if all fences should be returned + * @fence: the current fence + * + * Iterate over the fences in a struct dma_resv object while holding the + * dma_resv::lock. @all_fences controls if the shared fences are returned as + * well. + */ +#define dma_resv_for_each_fence(obj, cursor, all_fences, fence) \ + for (fence = dma_resv_walk(obj, cursor, all_fences, true); fence; \ + fence = dma_resv_walk(obj, cursor, all_fences, false)) + /** * dma_resv_for_each_fence_unlocked - fence iterator * @obj: a dma_resv object pointer @@ -305,6 +320,9 @@ void dma_resv_fini(struct dma_resv *obj); int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences); void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence); void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence); +struct dma_fence *dma_resv_walk(struct dma_resv *obj, + struct dma_resv_cursor *cursor, + bool first, bool all_fences); struct dma_fence *dma_resv_walk_unlocked(struct dma_resv *obj, struct dma_resv_cursor *cursor, bool first, bool all_fences); From patchwork Thu Jun 17 11:15:45 2021 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: 462530 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 060D3C2B9F4 for ; Thu, 17 Jun 2021 11:16:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEB6461209 for ; Thu, 17 Jun 2021 11:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232447AbhFQLSN (ORCPT ); Thu, 17 Jun 2021 07:18:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbhFQLSN (ORCPT ); Thu, 17 Jun 2021 07:18:13 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD6E5C061574 for ; Thu, 17 Jun 2021 04:16:04 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id w21so3473387edv.3 for ; Thu, 17 Jun 2021 04:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=thDZm3ZMnxOybSBKCCgjDJLbNH7DHkurPeY4zB9jEVg=; b=cyDqD1gQpG82BNxwVh+3FajMfT5FObhHoNTdmMC0AqI8hETHw5EzZJzFAvJZ2tFuEb RK+ojeFZ4PgYaq7tr+j83tjrxs7wf2gkTo7BGg4TX5yAr3cl+cf2nA96igE/SpvurK6M PmTIyWbF5uIGtJ+y6otkw2nwnQcnf9FMwR6rMDCCn+Lhkjeoutvv3npbhdNGSa0NP6Ws d7urZss7tHqTWkifYYKKz1w6DCqmAQYrQXJVPLXxdiSIzroTN7SJ0ytqw9/7nAUmQzo7 9sgJK7J8nMizqx43x8o5u3DK7/7qYhFlVDM8dnIu7oEcVpRJ2tfn9TgVUjpWc2KOxOZO elEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=thDZm3ZMnxOybSBKCCgjDJLbNH7DHkurPeY4zB9jEVg=; b=bUVFo6U/fFF5MHeaxLKkCxo/kdFUkL14huS+vAKUBZXbylLskqIgM9c0ykWUrAwLWd pZ+r72uW3fq0jLiIaNuxt1nfqG0aEFQzqzIKmvWVuFESsCzeKNXgGw1sPB4tG1CuObP9 7u/3sii8v01aEguJ00AM5STbR5ldGNNAg+jwwm1dEd7QyCw7NdsLqfiZ5CUPt2vP+PvO MnvvSBOALg52AfWgfkhunqdHNjFGDXGRtzcoUzUTuPeCRmrJPdY1Y/LDNz2XFuB+pYiu nuAjPRCSbQLl9RqO8l7f8g6pTttYHhM+nIRaySiMDpU2+m7z8HblLTf8wGhht4+fdCV6 3pMg== X-Gm-Message-State: AOAM531tQApCIWhH0a3MkYgo1+aawEGK3DpLOsg+SP+uMwdd4jldaSl7 FDjMbZLQynye91FcdVEiPGbLb1nJKnQ= X-Google-Smtp-Source: ABdhPJxI2Dk3zAw97Ki69S2yppKm6wBN1DhrBhwSDQiUtkfGkjyNfAMOMv0fZTc6YyphFlmJO56WNQ== X-Received: by 2002:a05:6402:419:: with SMTP id q25mr5732702edv.331.1623928563438; Thu, 17 Jun 2021 04:16:03 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:03 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 03/16] dma-buf: use new iterator in dma_resv_copy_fences Date: Thu, 17 Jun 2021 13:15:45 +0200 Message-Id: <20210617111558.28486-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This makes the function much simpler since the complex retry logic is now handled else where. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 81 +++++++++++++++----------------------- 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index a0386cf5824c..a5d78bf401b5 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -426,74 +426,57 @@ EXPORT_SYMBOL_GPL(dma_resv_walk_unlocked); */ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) { - struct dma_resv_list *src_list, *dst_list; - struct dma_fence *old, *new; - unsigned int i; + struct dma_resv_cursor cursor; + struct dma_resv_list *list; + struct dma_fence *f, *excl; dma_resv_assert_held(dst); - rcu_read_lock(); - src_list = dma_resv_shared_list(src); + list = NULL; + excl = NULL; -retry: - if (src_list) { - unsigned int shared_count = src_list->shared_count; + rcu_read_lock(); + dma_resv_for_each_fence_unlocked(dst, &cursor, true, f) { - rcu_read_unlock(); + if (cursor.is_first) { + dma_resv_list_free(list); + dma_fence_put(excl); - dst_list = dma_resv_list_alloc(shared_count); - if (!dst_list) - return -ENOMEM; + if (cursor.fences) { + unsigned int cnt = cursor.fences->shared_count; - rcu_read_lock(); - src_list = dma_resv_shared_list(src); - if (!src_list || src_list->shared_count > shared_count) { - kfree(dst_list); - goto retry; - } + rcu_read_unlock(); + list = dma_resv_list_alloc(cnt); + if (!list) + return -ENOMEM; - dst_list->shared_count = 0; - for (i = 0; i < src_list->shared_count; ++i) { - struct dma_fence __rcu **dst; - struct dma_fence *fence; + list->shared_count = 0; + rcu_read_lock(); - fence = rcu_dereference(src_list->shared[i]); - if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, - &fence->flags)) - continue; - - if (!dma_fence_get_rcu(fence)) { - dma_resv_list_free(dst_list); - src_list = dma_resv_shared_list(src); - goto retry; + } else { + list = NULL; } + excl = NULL; + } - if (dma_fence_is_signaled(fence)) { - dma_fence_put(fence); - continue; - } + if (cursor.is_exclusive) + excl = f; + else + RCU_INIT_POINTER(list->shared[list->shared_count++], f); - dst = &dst_list->shared[dst_list->shared_count++]; - rcu_assign_pointer(*dst, fence); - } - } else { - dst_list = NULL; + /* Don't drop the reference */ + f = NULL; } - new = dma_fence_get_rcu_safe(&src->fence_excl); rcu_read_unlock(); - src_list = dma_resv_shared_list(dst); - old = dma_resv_excl_fence(dst); - write_seqcount_begin(&dst->seq); - /* write_seqcount_begin provides the necessary memory barrier */ - RCU_INIT_POINTER(dst->fence_excl, new); - RCU_INIT_POINTER(dst->fence, dst_list); + excl = rcu_replace_pointer(dst->fence_excl, excl, dma_resv_held(dst)); + list = rcu_replace_pointer(dst->fence, list, dma_resv_held(dst)); write_seqcount_end(&dst->seq); - dma_resv_list_free(src_list); - dma_fence_put(old); + dma_resv_list_free(list); + dma_fence_put(excl); return 0; } From patchwork Thu Jun 17 11:15:46 2021 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: 462529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BC3CC49EA3 for ; Thu, 17 Jun 2021 11:16:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B2CA61209 for ; Thu, 17 Jun 2021 11:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232450AbhFQLSO (ORCPT ); Thu, 17 Jun 2021 07:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231661AbhFQLSN (ORCPT ); Thu, 17 Jun 2021 07:18:13 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78AAAC06175F for ; Thu, 17 Jun 2021 04:16:05 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id i13so3441511edb.9 for ; Thu, 17 Jun 2021 04:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lLXrCyq505g6km4qhQf/vGJa05DrxTvpnpKRUMRAvpc=; b=XGtZK5xYCuwAprrbgPE1Fy0sborX5AJhSD4DchxUWFwhJ2SAeD/FZQoFzhGUF5EK4c AHx/pGcgYZDIuU2x/XELWJRJSvL6UfLPFb6/CttNQmPy1attYnpa1nd/1NXXMdc4ETLt 3eaCjQ3DslfJSxMD5Wsvydzbx9BZc19E2FSHHhBd8xCN2GRK2UjExVpXJdVI2IKz4XCQ NKxkEUXQwc2ZgKXJZOYZrjz+vBfnhXKsjnIXmOtEyI4HbE5uRp9Y4AjFc4uum94ZlniV oY9zmjkhtqenbBFr30dnUsLa2Gc+D7fd5uwxOF46u1U9+Quzu1LRiNg+/hHpNjp1M1W9 bPfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lLXrCyq505g6km4qhQf/vGJa05DrxTvpnpKRUMRAvpc=; b=J/v10XAHnWHdQwEbMSnjsPGTT8YSVNzknHjOE0BNZUXroTLKZqGO2D2JEB+7kAG2e9 9pvvRonmxBtlQVZ2NWSL6MG8RsyBC4lGb4g5q2Gf/jcqg44xVJwSLQhIyJkP8yAuWmAs XPgK89JjuCWUtc6Yb/a7HTBBQNIKd0Li/P9lUmFQSDpcHpmo/v2YcQtfW/2rvUCBi1pJ z69zvcyVlNQ2GszCWYbb9aSntc4l0UwhQBhIBfzyjZ9y6v6eQOYFad22nXagzY244EM5 L+sIBmWvFEtnZlQbW6ZGYSUVUmHcBG1KEHmHht1bi+TbjwC0XzHhvbFmTitqxn6a2m1G G60Q== X-Gm-Message-State: AOAM532JMgfzgYcPU3+8W+bCwr1fox8nbxI4qRCQrx6fVGtHcY/XcwXS Kv8PJ0vDRUnbhe//LA1X1d+62oH7TK8= X-Google-Smtp-Source: ABdhPJyVkHEfyieNGPqpKK4GumqUK2OI/OWpE8p33ZvKU144WvZIK9enpZidGXxO6/KnBkmIUQGnJQ== X-Received: by 2002:a50:eb8f:: with SMTP id y15mr5733269edr.285.1623928564138; Thu, 17 Jun 2021 04:16:04 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:03 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 04/16] dma-buf: use new iterator in dma_resv_get_fences Date: Thu, 17 Jun 2021 13:15:46 +0200 Message-Id: <20210617111558.28486-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This makes the function much simpler since the complex retry logic is now handled elsewhere. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 110 +++++++++++++------------------------ 1 file changed, 37 insertions(+), 73 deletions(-) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index a5d78bf401b5..b77bf46c0f48 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -486,99 +486,63 @@ EXPORT_SYMBOL(dma_resv_copy_fences); * dma_resv_get_fences - Get an object's shared and exclusive * fences without update side lock held * @obj: the reservation object - * @pfence_excl: the returned exclusive fence (or NULL) - * @pshared_count: the number of shared fences returned - * @pshared: the array of shared fence ptrs returned (array is krealloc'd to + * @fence_excl: the returned exclusive fence (or NULL) + * @shared_count: the number of shared fences returned + * @shared: the array of shared fence ptrs returned (array is krealloc'd to * the required size, and must be freed by caller) * * Retrieve all fences from the reservation object. If the pointer for the * exclusive fence is not specified the fence is put into the array of the * shared fences as well. Returns either zero or -ENOMEM. */ -int dma_resv_get_fences(struct dma_resv *obj, struct dma_fence **pfence_excl, - unsigned int *pshared_count, - struct dma_fence ***pshared) +int dma_resv_get_fences(struct dma_resv *obj, struct dma_fence **fence_excl, + unsigned int *shared_count, struct dma_fence ***shared) { - struct dma_fence **shared = NULL; - struct dma_fence *fence_excl; - unsigned int shared_count; - int ret = 1; - - do { - struct dma_resv_list *fobj; - unsigned int i, seq; - size_t sz = 0; - - shared_count = i = 0; - - rcu_read_lock(); - seq = read_seqcount_begin(&obj->seq); - - fence_excl = dma_resv_excl_fence(obj); - if (fence_excl && !dma_fence_get_rcu(fence_excl)) - goto unlock; + struct dma_resv_cursor cursor; + struct dma_fence *fence; - fobj = dma_resv_shared_list(obj); - if (fobj) - sz += sizeof(*shared) * fobj->shared_max; + *shared_count = 0; + *shared = NULL; - if (!pfence_excl && fence_excl) - sz += sizeof(*shared); + if (fence_excl) + *fence_excl = NULL; - if (sz) { - struct dma_fence **nshared; + rcu_read_lock(); + dma_resv_for_each_fence_unlocked(obj, &cursor, true, fence) { - nshared = krealloc(shared, sz, - GFP_NOWAIT | __GFP_NOWARN); - if (!nshared) { - rcu_read_unlock(); + if (cursor.is_first) { + unsigned int count; - dma_fence_put(fence_excl); - fence_excl = NULL; + while (*shared_count) + dma_fence_put((*shared)[--(*shared_count)]); - nshared = krealloc(shared, sz, GFP_KERNEL); - if (nshared) { - shared = nshared; - continue; - } + if (fence_excl) + dma_fence_put(*fence_excl); - ret = -ENOMEM; - break; - } - shared = nshared; - shared_count = fobj ? fobj->shared_count : 0; - for (i = 0; i < shared_count; ++i) { - shared[i] = rcu_dereference(fobj->shared[i]); - if (!dma_fence_get_rcu(shared[i])) - break; - } - } + count = cursor.fences ? cursor.fences->shared_count : 0; + count += fence_excl ? 0 : 1; + rcu_read_unlock(); - if (i != shared_count || read_seqcount_retry(&obj->seq, seq)) { - while (i--) - dma_fence_put(shared[i]); - dma_fence_put(fence_excl); - goto unlock; + /* Eventually re-allocate the array */ + *shared = krealloc_array(*shared, count, + sizeof(*shared), + GFP_KERNEL); + if (count && !*shared) + return -ENOMEM; + rcu_read_lock(); } - ret = 0; -unlock: - rcu_read_unlock(); - } while (ret); - - if (pfence_excl) - *pfence_excl = fence_excl; - else if (fence_excl) - shared[shared_count++] = fence_excl; + if (cursor.is_exclusive && fence_excl) + *fence_excl = fence; + else + (*shared)[(*shared_count)++] = fence; - if (!shared_count) { - kfree(shared); - shared = NULL; + /* Don't drop the reference */ + fence = NULL; } + rcu_read_unlock(); - *pshared_count = shared_count; - *pshared = shared; - return ret; + return 0; } EXPORT_SYMBOL_GPL(dma_resv_get_fences); From patchwork Thu Jun 17 11:15:47 2021 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: 463424 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACA51C49361 for ; Thu, 17 Jun 2021 11:16:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9483F613B9 for ; Thu, 17 Jun 2021 11:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbhFQLSO (ORCPT ); Thu, 17 Jun 2021 07:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbhFQLSN (ORCPT ); Thu, 17 Jun 2021 07:18:13 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B185C061760 for ; Thu, 17 Jun 2021 04:16:06 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id z12so3500997edc.1 for ; Thu, 17 Jun 2021 04:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=f39rGZT5veqFjxPrNuWB2TiXiQPmiaT54Z6hZqWOR7o=; b=RNe0rSmGaU+5s+VrIHUQqg4naOJSdYobgxmh7WvqRqImdOpANraMgE5pu/oy4P8pYT M9zK4r41DUTtvR0QXRj0RanQYmkhu22PvsweGK4dPehIuBZ3ns+fzANw46807M+d7SpY GTtclYSaKX1Sp7dcLITRI2MvZVdQ2/cOo1M32uYF13zwvEv9XBjPycR0nUIzvE+wRMo+ IishIVHeVMElBcs3PrPppAxpaoClrphTrgInFhNwL+cFAdOce3ddFuE/ROgqzY+dT2W9 JWDY6fvVKR/JgWStdtSQrdYXTw4doKPqXEOrGzZ/SwYCNReYAEFlhTg+8GuEZcWF9UOo dXHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f39rGZT5veqFjxPrNuWB2TiXiQPmiaT54Z6hZqWOR7o=; b=RPM34uKI3xa70aLKkWdYf035BB2OUZvRf7F5iqO0WxOBEdBXsa1N4+r2kQSImJTpEb iixfB+1Ju8a8/e2g6NBu+cYlFPyVVWKnF90RslH5YxTeAZhhRdDxvS61m4ObdZDZL14O CCPOou1P8E3Xdjqu7cCrFPfpbpyxOtmLrwOZtDNbEe5Qw7SnBgaZ8aP9kF7F/Q2HfbL2 x44yboBfVRFyvp8l5+yQhHOEnT2ZWt+xvB3ssgCtUnLM1siOI0kjJBan+sogmZ4bQfLn 9KBCTd2ZxxBPHbGBPSgu1YU7yDarWzPLWfjZpQFWILhSAkW7oyLQWq3LzlkW/Pe9cAGr PjJw== X-Gm-Message-State: AOAM532bpWDGOKpUVjUT8txmLZr7YvxYjAGEQLMSnDhP3t3TProMIZny M/hMWamHUAHWgqlzdZBGxek= X-Google-Smtp-Source: ABdhPJzAxNQq7o0c8Az9z4kWtTT6sk40psjeZ0p7jq+xVfK4Wgh4poK36RFnx2T6ZmZk0Jy7KIbgzw== X-Received: by 2002:a05:6402:190a:: with SMTP id e10mr5759983edz.160.1623928564796; Thu, 17 Jun 2021 04:16:04 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:04 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 05/16] dma-buf: use new iterator in dma_resv_wait_timeout Date: Thu, 17 Jun 2021 13:15:47 +0200 Message-Id: <20210617111558.28486-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This makes the function much simpler since the complex retry logic is now handled elsewhere. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 64 +++++--------------------------------- 1 file changed, 7 insertions(+), 57 deletions(-) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index b77bf46c0f48..5192cf4271ac 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -564,74 +564,24 @@ long dma_resv_wait_timeout(struct dma_resv *obj, bool wait_all, bool intr, unsigned long timeout) { long ret = timeout ? timeout : 1; - unsigned int seq, shared_count; + struct dma_resv_cursor cursor; struct dma_fence *fence; - int i; -retry: - shared_count = 0; - seq = read_seqcount_begin(&obj->seq); rcu_read_lock(); - i = -1; - - fence = dma_resv_excl_fence(obj); - if (fence && !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { - if (!dma_fence_get_rcu(fence)) - goto unlock_retry; + dma_resv_for_each_fence_unlocked(obj, &cursor, wait_all, fence) { + rcu_read_unlock(); - if (dma_fence_is_signaled(fence)) { + ret = dma_fence_wait_timeout(fence, intr, ret); + if (ret <= 0) { dma_fence_put(fence); - fence = NULL; + return ret; } - } else { - fence = NULL; - } - - if (wait_all) { - struct dma_resv_list *fobj = dma_resv_shared_list(obj); - - if (fobj) - shared_count = fobj->shared_count; - - for (i = 0; !fence && i < shared_count; ++i) { - struct dma_fence *lfence; - - lfence = rcu_dereference(fobj->shared[i]); - if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, - &lfence->flags)) - continue; - - if (!dma_fence_get_rcu(lfence)) - goto unlock_retry; - - if (dma_fence_is_signaled(lfence)) { - dma_fence_put(lfence); - continue; - } - - fence = lfence; - break; - } + rcu_read_lock(); } - rcu_read_unlock(); - if (fence) { - if (read_seqcount_retry(&obj->seq, seq)) { - dma_fence_put(fence); - goto retry; - } - ret = dma_fence_wait_timeout(fence, intr, ret); - dma_fence_put(fence); - if (ret > 0 && wait_all && (i + 1 < shared_count)) - goto retry; - } return ret; - -unlock_retry: - rcu_read_unlock(); - goto retry; } EXPORT_SYMBOL_GPL(dma_resv_wait_timeout); From patchwork Thu Jun 17 11:15:48 2021 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: 462528 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC627C2B9F4 for ; Thu, 17 Jun 2021 11:16:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D519161369 for ; Thu, 17 Jun 2021 11:16:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232457AbhFQLSQ (ORCPT ); Thu, 17 Jun 2021 07:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232453AbhFQLSP (ORCPT ); Thu, 17 Jun 2021 07:18:15 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0F95C061574 for ; Thu, 17 Jun 2021 04:16:06 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id s6so3427149edu.10 for ; Thu, 17 Jun 2021 04:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Xa2i71Ri2eK/e91UCCTXEAoquyui6jF43BKEv04gN4g=; b=J4G7oyFYVe/U+4ZAFn6M8m4z7Y24tHmXJPLZkUlymA1ekUAOM4VnvwV19yW7Txo/C/ QyY271dLeV6GK7cz/0wNgveeMKZFxeAZQrV06VU2lAkmNimfAEpwfO+VlsNHaQDGi12X AgXYTEEOUY/JngrYoedtySNu2ZdWifo4EEkT9FLZmdDORsDbYui0QKIwJ6P5ACcRJj4i TVddfMXrm+Y9dBDb0TWnfAmB1LcWfUhYkKsUlUekwaEZpNVH5v6z7vUxMq4+S9P9kx2i rP/SD+UDsKrOr6Xgr3Y2g/U+4w735YyPIZOho+WV5a9e0TphJPeR2PrLciTY1cGZ060a etwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xa2i71Ri2eK/e91UCCTXEAoquyui6jF43BKEv04gN4g=; b=Q/SNGbEYXH24F7eyokwhIaegb0Udilmq93pjV4BgpCp3Gx1N3mThmeBLP/QtQS7f1s T3b+GtXV4WXblfUuA9L188LgsWB2eycVUvhZbLdNCpWTSbxPVF4cr+SEGFJGWwUWrdPc FDGXrCWyDpW4go7g3x/oFdLpoc2R8siy9fnqVj12kuvgAoMDCmkNQ89uv8t1w7ClfTHZ LqqsJKIsCXdV9NOo0X5Nh6wmkLQBK25B/s5i6Zz+GmZiL6LNowjA39JOq75+Yp0GIOnc Jp1Wy5CpXOyacJKVXOFFQtyp1ONTxO3Ow8pyEuPFHcfthDKjdvIvm5hE5egFBo4ZtLLV lRYg== X-Gm-Message-State: AOAM530b5Q3uMEtYjSmVRXdIJf6LxRh/zPylTP4hcey5jDBC5xE+jUy2 RjK8cYziagFlH6Ikh4JUqBI= X-Google-Smtp-Source: ABdhPJwtK+PmMG0EvZiApB5Ui9GYadZi0QPgMNTTpHdQN5LAPkkC9DhaLZn5j6xJ1lZxbulacF4yYQ== X-Received: by 2002:aa7:ce03:: with SMTP id d3mr5732594edv.360.1623928565462; Thu, 17 Jun 2021 04:16:05 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:05 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 06/16] dma-buf: use new iterator in dma_resv_test_signaled Date: Thu, 17 Jun 2021 13:15:48 +0200 Message-Id: <20210617111558.28486-7-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This makes the function much simpler since the complex retry logic is now handled elsewhere. Signed-off-by: Christian König --- drivers/dma-buf/dma-resv.c | 54 +++++--------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index 5192cf4271ac..85e07becdb93 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -586,22 +586,6 @@ long dma_resv_wait_timeout(struct dma_resv *obj, bool wait_all, bool intr, EXPORT_SYMBOL_GPL(dma_resv_wait_timeout); -static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence) -{ - struct dma_fence *fence, *lfence = passed_fence; - int ret = 1; - - if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &lfence->flags)) { - fence = dma_fence_get_rcu(lfence); - if (!fence) - return -1; - - ret = !!dma_fence_is_signaled(fence); - dma_fence_put(fence); - } - return ret; -} - /** * dma_resv_test_signaled - Test if a reservation object's fences have been * signaled. @@ -616,43 +600,19 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence) */ bool dma_resv_test_signaled(struct dma_resv *obj, bool test_all) { + struct dma_resv_cursor cursor; struct dma_fence *fence; - unsigned int seq; - int ret; rcu_read_lock(); -retry: - ret = true; - seq = read_seqcount_begin(&obj->seq); - - if (test_all) { - struct dma_resv_list *fobj = dma_resv_shared_list(obj); - unsigned int i, shared_count; - - shared_count = fobj ? fobj->shared_count : 0; - for (i = 0; i < shared_count; ++i) { - fence = rcu_dereference(fobj->shared[i]); - ret = dma_resv_test_signaled_single(fence); - if (ret < 0) - goto retry; - else if (!ret) - break; + dma_resv_for_each_fence_unlocked(obj, &cursor, test_all, fence) { + if (!dma_fence_is_signaled(fence)) { + rcu_read_unlock(); + dma_fence_put(fence); + return false; } } - - fence = dma_resv_excl_fence(obj); - if (ret && fence) { - ret = dma_resv_test_signaled_single(fence); - if (ret < 0) - goto retry; - - } - - if (read_seqcount_retry(&obj->seq, seq)) - goto retry; - rcu_read_unlock(); - return ret; + return true; } EXPORT_SYMBOL_GPL(dma_resv_test_signaled); From patchwork Thu Jun 17 11:15:49 2021 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: 463423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9D2CC49EA4 for ; Thu, 17 Jun 2021 11:16:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C31D1613B9 for ; Thu, 17 Jun 2021 11:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232455AbhFQLSP (ORCPT ); Thu, 17 Jun 2021 07:18:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbhFQLSP (ORCPT ); Thu, 17 Jun 2021 07:18:15 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7725BC06175F for ; Thu, 17 Jun 2021 04:16:07 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id r7so3418915edv.12 for ; Thu, 17 Jun 2021 04:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xl1Z5pt8CfNzK8P+30y9KR+Njohg46PKrHJ0MHxGVhM=; b=RUZspJerSlauoLqeCHoGlNOOWVujbPNfqudZ0ORdCINHOxId84sz9H/GQYZjYx2BGm WPSE5JXHXhbDHpYHVHjepznWbfKU8oGcM4eSCMXaSGCkbDJPAsFErqd0pYlkq2Fe3Fzs Ru1OLtoRZd8MB1u9zSj05A3jh0LMWZA6fqQcqJFncYN6r1iKZXJnHqInNp0giTqKcEW3 eqvNuoSWp1fGRTZ/3qMHf+QnM57GGXIAg9ZTKcPVKycYCw8+srNVykEIwAhndZVjExFy QMFdivUzyagRrLAu3Ycis+/DvfLDJVApipfIF8o9l5AYEs18rpRpzIOZuL0nkw29oIj1 VEog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xl1Z5pt8CfNzK8P+30y9KR+Njohg46PKrHJ0MHxGVhM=; b=bDjFu9SFbmN9k3QZBzvP97vJNK3bsx+hkkvMpFYSMwu0/5zFvREIczbJ+EyahL/lSh lmx72idNLfG+rLfyp737wec5TJmwQnNg8rDDWke9A3ZcwsakEz8VMME8iYoXkQJ2PRRk fWAglhvAJBJPnV7doMW8uIDBLzBQITaNucS3gtKMvpdeZxeID9ucmcodmiOmnXGeocOV 0MP2JuFgCmlYWU0gHPtdzNYjBVdFyzQ9r3caE57bCZe8Nfbf8jS03AMWJKEp6QBrC58T R8lyMwi61QJJwQA+GM7f95i6C1Pl2KB7fK0hOpFxzQkghgmw2YTum61bwHda4MMptlNt waEA== X-Gm-Message-State: AOAM530vYiLBPISboEyHZAZhQXaa3Wyk3XVd1KqdgRv5cX/SAGhyGr46 6Eu4MKucd+ohJrx5FhfEaxRP2u24ddU= X-Google-Smtp-Source: ABdhPJzeDo2Tbf1vXUedAei37ItrPOvsfX320YeV5SkZ+q9uzU8nEo9TjkFZ62EcQZbfm+g0w5OyVw== X-Received: by 2002:aa7:d892:: with SMTP id u18mr5878105edq.196.1623928566110; Thu, 17 Jun 2021 04:16:06 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:05 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 07/16] dma-buf: use new iterator in dma_buf_poll Date: Thu, 17 Jun 2021 13:15:49 +0200 Message-Id: <20210617111558.28486-8-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This makes the function much simpler since the complex retry logic is now handled elsewhere. Signed-off-by: Christian König --- drivers/dma-buf/dma-buf.c | 49 ++++----------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index b67fbf4e3705..4173f1f70ac1 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -207,15 +207,13 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb) static __poll_t dma_buf_poll(struct file *file, poll_table *poll) { + struct dma_resv_cursor cursor; struct dma_buf_poll_cb_t *dcb; struct dma_buf *dmabuf; struct dma_resv *resv; - struct dma_resv_list *fobj; - struct dma_fence *fence_excl; - unsigned shared_count, seq; struct dma_fence *fence; __poll_t events; - int r, i; + int r; dmabuf = file->private_data; if (!dmabuf || !dmabuf->resv) @@ -241,53 +239,14 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) if (!events) return 0; -retry: - seq = read_seqcount_begin(&resv->seq); - rcu_read_lock(); - - fobj = rcu_dereference(resv->fence); - if (fobj && events & EPOLLOUT) - shared_count = fobj->shared_count; - else - shared_count = 0; - - for (i = 0; i < shared_count; ++i) { - fence = rcu_dereference(fobj->shared[i]); - fence = dma_fence_get_rcu(fence); - if (!fence || read_seqcount_retry(&resv->seq, seq)) { - /* Concurrent modify detected, force re-check */ - dma_fence_put(fence); - rcu_read_unlock(); - goto retry; - } - - r = dma_fence_add_callback(fence, &dcb->cb, dma_buf_poll_cb); - if (!r) { - /* Callback queued */ - events = 0; - goto out; - } - dma_fence_put(fence); - } - - fence = dma_resv_excl_fence(resv); - if (fence) { - fence = dma_fence_get_rcu(fence); - if (!fence || read_seqcount_retry(&resv->seq, seq)) { - /* Concurrent modify detected, force re-check */ - dma_fence_put(fence); - rcu_read_unlock(); - goto retry; - - } - + dma_resv_for_each_fence_unlocked(resv, &cursor, events & EPOLLOUT, + fence) { r = dma_fence_add_callback(fence, &dcb->cb, dma_buf_poll_cb); if (!r) { /* Callback queued */ events = 0; goto out; } - dma_fence_put(fence_excl); } /* No callback queued, wake up any additional waiters. */ From patchwork Thu Jun 17 11:15:50 2021 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: 463422 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85CEAC49361 for ; Thu, 17 Jun 2021 11:16:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74E6861209 for ; Thu, 17 Jun 2021 11:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232460AbhFQLSQ (ORCPT ); Thu, 17 Jun 2021 07:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232456AbhFQLSP (ORCPT ); Thu, 17 Jun 2021 07:18:15 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 218AEC061574 for ; Thu, 17 Jun 2021 04:16:08 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id s6so3427230edu.10 for ; Thu, 17 Jun 2021 04:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=byLSDqjdKi3+cE2IMMDe/R3eVJ9OpfF5t0/Jijtn6q0=; b=sOQGBXqPZYb4VhHiZysul1mv0Y5S+MhCCItbz9UHtXicp3kUgp/stG1N3WEDg0WQNA KuX+kWiSQcyHtd+4Q3yVKARfSprDU5SoZya210yjZ+7yxgF472bhYHycnphV0w17aEmG cl/w93GKuJUqiPTDj78CNuPHdSmnWgrvFEeb3nHdfcN9j7kiP402JJsocFKh7gawRlVf F4jfa+uvDDSOQ/3a4A675gYsIYpd3q2aJ5Yhp+qGdcYgJrohoHSxXL6YNEisPGWS0PgT +7e0clwZ6uX0erSLNWWG9pQLaPg7eBt7DNTTXQ9KuAt6xohb5sh6m1AC5RGGNAn/KKpg bjNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=byLSDqjdKi3+cE2IMMDe/R3eVJ9OpfF5t0/Jijtn6q0=; b=AkOP4c/NbgphBR0VFtjx8n181cDIJ1cN8+iX9pPDDDQRjFewQPIFMjgBqcdq6OrxV/ zFcwYsHIZCWIiqHe2GOywI9q+exE3p/4IH3U4D+oDp2L1t/hoglnrvuwD9lYCPrtMS1B W7LFETpltaufTGD1GL/TSlqyzfzLXup6KHSfXd6M6IjpxnumBwQJ2G4GJwoIuVA4GShL 6HwP8v8/Ekno+4tNjya17x6gLPKtY6iCRdRlaD6A4fjiDraFn05iQ02d0YJez8SHIIe8 j7RFmzKIKciq9YGXAmhJMv6VkZGw2ltYSPbXuKqwwVxPQQ/h3g66slW0Jq4bgtCRTK5m LZ9w== X-Gm-Message-State: AOAM531wSllV03dEOUu7+//Igzcgse/wF7omBobducrYyVxns6N8ITve CAgxKyQQndIBESneIhJ0J4PonKuMiqE= X-Google-Smtp-Source: ABdhPJxPES9M3EFm+goK97aBV/aqBmulWsvrxZXDpmswFtsIKGYgZSrLa6HNl26BpQgDFlDZEnIjWw== X-Received: by 2002:a05:6402:27c9:: with SMTP id c9mr5838983ede.371.1623928566809; Thu, 17 Jun 2021 04:16:06 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:06 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 08/16] drm/i915: use the new iterator in i915_gem_busy_ioctl Date: Thu, 17 Jun 2021 13:15:50 +0200 Message-Id: <20210617111558.28486-9-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This makes the function much simpler since the complex retry logic is now handled else where. Signed-off-by: Christian König --- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 30 +++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_busy.c b/drivers/gpu/drm/i915/gem/i915_gem_busy.c index 6234e17259c1..c6c6d747b33e 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_busy.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_busy.c @@ -82,8 +82,8 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, { struct drm_i915_gem_busy *args = data; struct drm_i915_gem_object *obj; - struct dma_resv_list *list; - unsigned int seq; + struct dma_resv_cursor cursor; + struct dma_fence *fence; int err; err = -ENOENT; @@ -109,28 +109,16 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, * to report the overall busyness. This is what the wait-ioctl does. * */ -retry: - seq = raw_read_seqcount(&obj->base.resv->seq); - - /* Translate the exclusive fence to the READ *and* WRITE engine */ - args->busy = busy_check_writer(dma_resv_excl_fence(obj->base.resv)); - - /* Translate shared fences to READ set of engines */ - list = dma_resv_shared_list(obj->base.resv); - if (list) { - unsigned int shared_count = list->shared_count, i; - - for (i = 0; i < shared_count; ++i) { - struct dma_fence *fence = - rcu_dereference(list->shared[i]); - + args->busy = false; + dma_resv_for_each_fence_unlocked(obj->base.resv, &cursor, true, fence) { + if (cursor.is_exclusive) + /* Translate the exclusive fence to the READ *and* WRITE engine */ + args->busy = busy_check_writer(fence); + else + /* Translate shared fences to READ set of engines */ args->busy |= busy_check_reader(fence); - } } - if (args->busy && read_seqcount_retry(&obj->base.resv->seq, seq)) - goto retry; - err = 0; out: rcu_read_unlock(); From patchwork Thu Jun 17 11:15:51 2021 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: 462527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33638C49EA3 for ; Thu, 17 Jun 2021 11:16:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D0F6613B9 for ; Thu, 17 Jun 2021 11:16:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232459AbhFQLSR (ORCPT ); Thu, 17 Jun 2021 07:18:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232453AbhFQLSQ (ORCPT ); Thu, 17 Jun 2021 07:18:16 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE518C061574 for ; Thu, 17 Jun 2021 04:16:08 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id t7so3449011edd.5 for ; Thu, 17 Jun 2021 04:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0rYVC8GXBvPHta5OQekqQaFTSxF/VrC5pz+9u8ViMZg=; b=Zm8qe0yqyJBtIYxx3yuZlWXCq7HjCj79xa6qOLkjBQ0ny6jlNUSeRumUFr5yLlW/eP t9MIUL1gtlbyyxx5LXxBlTZxfwwCCCRJwLlMmyObBGpNu3dVMAIFP6DFnEN1umkjFLk1 qfBqYYLAaTa6qXninH7jyFhqCqABPSCaTAKpLqKJWduNzIApctuezdpbHyUBe7ESPOc1 IsXe8/WJgv+CmJpRPzoGj5hr+paO4xWKnrd9GSqdBWGnPVXC5LP4uSSZ06djxIz4Ax6w qRhm2Urf5kYXD64HOixSMCdg+hXtC8lsvFXkkW+9u2EIz3pftnahDxTTUGp45qwQP1Bl TdxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0rYVC8GXBvPHta5OQekqQaFTSxF/VrC5pz+9u8ViMZg=; b=H9pzGrmAMPQ85mYZPGC+feOu2Gf3ElOJZvAmD6vu/Y14rQ1TpClos6tP19TrmoukUK 3UlbprfgwezBnnAeYqko2iq4FxdcXbOXyyImBwP/fpEXtnw6fuZmGjwf8EcBVgawPJQO acZydgCoMTy/XeZFIAFIH/qhx5iEHxTPHs1xHwF8/ZYn5G5X4EczoMN8wZXwDI/IiKXw tL401xZVyhycIMlgufGKZUlY5yvGugorAg4dL3yLtkLT+agiwD/h0sUXS1oSDJGTma5s UMQhhQLLqIOuUDWzDOaW/kYALx5nSgDFQUyKNu+A+vtV/G/N7ZfpBzpdOo4BQsQWtwnH Y1Dg== X-Gm-Message-State: AOAM5317d8ry5A0v2PBeEDWej1OEWogejXMOk8BfF2nLkMPQFct02x8S T+/qcMyX8lEvHpWcHIrnyBU= X-Google-Smtp-Source: ABdhPJwMPY8wEtDDMVVnoIX7OfvIzuomuMkBFiT0fIuMQDUKJLRIJm09Yp32F0OTRw91VHHDmWIhVw== X-Received: by 2002:a05:6402:1713:: with SMTP id y19mr5689376edu.346.1623928567467; Thu, 17 Jun 2021 04:16:07 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:07 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 09/16] drm/ttm: use the new iterator in ttm_bo_flush_all_fences Date: Thu, 17 Jun 2021 13:15:51 +0200 Message-Id: <20210617111558.28486-10-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This is probably a fix since we didn't even grabed a reference to the fences. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index db53fecca696..15edb308e5a9 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -256,19 +256,11 @@ static int ttm_bo_individualize_resv(struct ttm_buffer_object *bo) static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo) { struct dma_resv *resv = &bo->base._resv; - struct dma_resv_list *fobj; + struct dma_resv_cursor cursor; struct dma_fence *fence; - int i; rcu_read_lock(); - fobj = dma_resv_shared_list(resv); - fence = dma_resv_excl_fence(resv); - if (fence && !fence->ops->signaled) - dma_fence_enable_sw_signaling(fence); - - for (i = 0; fobj && i < fobj->shared_count; ++i) { - fence = rcu_dereference(fobj->shared[i]); - + dma_resv_for_each_fence_unlocked(resv, &cursor, true, fence) { if (!fence->ops->signaled) dma_fence_enable_sw_signaling(fence); } From patchwork Thu Jun 17 11:15:52 2021 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: 463421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ACDCC48BE5 for ; Thu, 17 Jun 2021 11:16:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1782661209 for ; Thu, 17 Jun 2021 11:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232466AbhFQLSS (ORCPT ); Thu, 17 Jun 2021 07:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232462AbhFQLSR (ORCPT ); Thu, 17 Jun 2021 07:18:17 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CEAAC06175F for ; Thu, 17 Jun 2021 04:16:09 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id g8so9292971ejx.1 for ; Thu, 17 Jun 2021 04:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Y/imVMS+E7ZynWw7iSiIjDs1SxBWXyWjuW715+Mfo5c=; b=M2EfIXDhNhQGfnqZeXtxmNfwHZoQaW2MTVa3UzNYhdb2fsMUXtcdPuWkWBrGvEWEp9 sDzydRS9HenKK/Y5oenkwtBngqHPZOEk1hYGnQcqYOfDW+JdluHZyfgpXR2DKVeYlOq+ k/brasQwC83W9K83wlbEsSexWGzNhSHlavnvMoz0pj2IxjrQFD/EVPJ9HG3LKfY9nUg/ Cnmuujua6BAvCTBE/nJOIP/+2mSp4qi2A1F+99Nwy53hzXnB6w/pnT0lkPjUPVfgJJVV wWebCzXZQ9+bl1u6+aK7nvKJDR7cRxPrcwUG01ob7hSLxVWgigrBvaJznD2ytWqOwcRT 68ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y/imVMS+E7ZynWw7iSiIjDs1SxBWXyWjuW715+Mfo5c=; b=jGT4sVFyfN1MnR2k6E82NHZrjX9/faFXnK+v1LmFrjzHjWSg5PPUygfygwQNlQBy/B DrztM0T6NlKhQQcnv7x4bTHOxLtq4mC4bQ5hQ+VNVyzgG2pL93Jvp10zmbSvYP3HAyme TL7JsIw6cfmOpqtzxYd5J3Dv3ZSqozBmlLHM0Ww72+7DYR9sR+uAbdCTiUNtC6KNJLCH 46gpbhRwAf9qGlEa1rDYNvYwG1VqAI/GDmpmMSQe/f/TN9kyJogZS0JH/61P33012ig4 nekhsR7wJDGD8mD2IVKWd6K+ntrDdvpJqkHZECHaL49D1Fixr8tHc+NplWZoK0ijf4GA ieHA== X-Gm-Message-State: AOAM530FCpOvoxN7ocl0aMSrgTcSVN9TYHq+A0GlXfnGpNmtzRSt6+dT eykX4tzmrU1G7f7ntlLpXGChIEQjrtM= X-Google-Smtp-Source: ABdhPJxtONqJjTKNIkmenxgCWwIo2UFCZPig/Nqaq0PPK0Qw8TAhJetxxVTpxyIT5mpgKNhpreu58A== X-Received: by 2002:a17:906:f6d7:: with SMTP id jo23mr4756958ejb.302.1623928568108; Thu, 17 Jun 2021 04:16:08 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:07 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 10/16] drm/etnaviv: use new iterator in etnaviv_gem_describe Date: Thu, 17 Jun 2021 13:15:52 +0200 Message-Id: <20210617111558.28486-11-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Instead of hand rolling the logic. Signed-off-by: Christian König --- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index b8fa6ed3dd73..6808dbef5c79 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -437,19 +437,17 @@ int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj, static void etnaviv_gem_describe_fence(struct dma_fence *fence, const char *type, struct seq_file *m) { - if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) - seq_printf(m, "\t%9s: %s %s seq %llu\n", - type, - fence->ops->get_driver_name(fence), - fence->ops->get_timeline_name(fence), - fence->seqno); + seq_printf(m, "\t%9s: %s %s seq %llu\n", type, + fence->ops->get_driver_name(fence), + fence->ops->get_timeline_name(fence), + fence->seqno); } static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) { struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); struct dma_resv *robj = obj->resv; - struct dma_resv_list *fobj; + struct dma_resv_cursor cursor; struct dma_fence *fence; unsigned long off = drm_vma_node_start(&obj->vma_node); @@ -459,19 +457,12 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) off, etnaviv_obj->vaddr, obj->size); rcu_read_lock(); - fobj = dma_resv_shared_list(robj); - if (fobj) { - unsigned int i, shared_count = fobj->shared_count; - - for (i = 0; i < shared_count; i++) { - fence = rcu_dereference(fobj->shared[i]); + dma_resv_for_each_fence_unlocked(robj, &cursor, true, fence) { + if (cursor.is_exclusive) + etnaviv_gem_describe_fence(fence, "Exclusive", m); + else etnaviv_gem_describe_fence(fence, "Shared", m); - } } - - fence = dma_resv_excl_fence(robj); - if (fence) - etnaviv_gem_describe_fence(fence, "Exclusive", m); rcu_read_unlock(); } From patchwork Thu Jun 17 11:15:53 2021 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: 462526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE347C49361 for ; Thu, 17 Jun 2021 11:16:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A5C0613BF for ; Thu, 17 Jun 2021 11:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232467AbhFQLST (ORCPT ); Thu, 17 Jun 2021 07:18:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232453AbhFQLSS (ORCPT ); Thu, 17 Jun 2021 07:18:18 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DF4FC061574 for ; Thu, 17 Jun 2021 04:16:10 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id df12so975552edb.2 for ; Thu, 17 Jun 2021 04:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=hvNXqtq5mdZJpJK7jpCUZ+hsh9G2TDoGYYpRx9Mul74=; b=RIin5nZI/rpjSAo5R/hPF0Y/Mqr8Yq4tPJjB9KCgi1NwScGxumI9QfNhDpG/ocMPlL V7hyyE1Ne0mYBRkKYqDLJqQ49roJLNg12GRTc1V/jLkh5BFfQ+jkoD4unN0oWK/yOGAd PHI7FvSo4kzHBf30s/Bi/pVIkUaoSRle68FxqzlpGnpscWmkKNiGyfzMewTAOpBLjGYT yItfwLjrITYcM5owdPmOyrInM6mVSDokQr4zOWs/AGvg/Bzjl+ufk39yZtsvOxk4qRkj BLA3zb7Shrql6XGErODXjemVG5dWF3rolFdDfJSX3qPyLYLHmgqDgj05csKa2J/0ZTfq SI+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hvNXqtq5mdZJpJK7jpCUZ+hsh9G2TDoGYYpRx9Mul74=; b=NjyIWzkhkjCZzRmzYdmpYYg1Q441LI7QkccDUZa/6goI+EuKBGBg2Xw4dPoWnqsX10 qks76g2e5dnjzh5Xr1eQP75TUB481zSlFs0hkajOApxqwZyoT3lAFdG15MSnJYTG7OPj Xl3oJQoAlOvnaT9rDNQz+i5D/9JsvfPwdUXqWwaXlMfLpu5/l0CtZDbQGry7GSTo5par 1x8KBivNm2+nlgQ6rQilTXkzMTcxQdZXcOzWkuzg71MXVwt7RBNUOy+uEsmK/CsRJz0B oyHEI5wzVenbNqM7S2HS/ZgAYPUDWS5iN+mG06K9FY+qc4uDn4MjfsHgUzebyphPjC4Y xxSg== X-Gm-Message-State: AOAM533vBo6xcoCBE9BaqYRvrHVTvB5ifhxR+rIszf49Se2zUIqMFZ7/ 4OOtrM39vzpidmPnbv80Acw= X-Google-Smtp-Source: ABdhPJxdqm0xly694XIcLjrbZ9A76Y59S2aejU4bGXP1xl8mBcHQH3xduN5/LfUZEksy/oiQuJIoCA== X-Received: by 2002:a05:6402:51:: with SMTP id f17mr5633820edu.359.1623928568856; Thu, 17 Jun 2021 04:16:08 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:08 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 11/16] drm/amdgpu: use the new iterator in amdgpu_sync_resv Date: Thu, 17 Jun 2021 13:15:53 +0200 Message-Id: <20210617111558.28486-12-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Simplifying the code a bit. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 44 ++++++++---------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c index 862eb3c1c4c5..031ba20debb9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c @@ -252,41 +252,25 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, struct dma_resv *resv, enum amdgpu_sync_mode mode, void *owner) { - struct dma_resv_list *flist; + struct dma_resv_cursor cursor; struct dma_fence *f; - unsigned i; - int r = 0; + int r; if (resv == NULL) return -EINVAL; - /* always sync to the exclusive fence */ - f = dma_resv_excl_fence(resv); - dma_fence_chain_for_each(f, f) { - struct dma_fence_chain *chain = to_dma_fence_chain(f); - - if (amdgpu_sync_test_fence(adev, mode, owner, chain ? - chain->fence : f)) { - r = amdgpu_sync_fence(sync, f); - dma_fence_put(f); - if (r) - return r; - break; - } - } - - flist = dma_resv_shared_list(resv); - if (!flist) - return 0; - - for (i = 0; i < flist->shared_count; ++i) { - f = rcu_dereference_protected(flist->shared[i], - dma_resv_held(resv)); - - if (amdgpu_sync_test_fence(adev, mode, owner, f)) { - r = amdgpu_sync_fence(sync, f); - if (r) - return r; + dma_resv_for_each_fence(resv, &cursor, true, f) { + dma_fence_chain_for_each(f, f) { + struct dma_fence_chain *chain = to_dma_fence_chain(f); + + if (amdgpu_sync_test_fence(adev, mode, owner, chain ? + chain->fence : f)) { + r = amdgpu_sync_fence(sync, f); + dma_fence_put(f); + if (r) + return r; + break; + } } } return 0; From patchwork Thu Jun 17 11:15:54 2021 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: 463420 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7931BC49EA3 for ; Thu, 17 Jun 2021 11:16:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6318261369 for ; Thu, 17 Jun 2021 11:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232469AbhFQLST (ORCPT ); Thu, 17 Jun 2021 07:18:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232465AbhFQLSS (ORCPT ); Thu, 17 Jun 2021 07:18:18 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF248C061760 for ; Thu, 17 Jun 2021 04:16:10 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id nb6so9157052ejc.10 for ; Thu, 17 Jun 2021 04:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=f1nM/lpdSyfhiokJoYKLwhEgbv1/4gmOk1Dy2ivEHic=; b=A/XrqU2+MWOuAkqSgZ6QRPi/OX8NnlSLG59pLX7MWTJdq/uJfCYBGgj1uNqm7KnshJ ONHeTwD04CBs29Zlu+QbB018Sjbj1EbD2PRqZl9cKBh9SMmhDZBsCQ46OxPgp1o8Qq3w pms9himFZh0TiGjmbDTagV+cT2IlGLWj033t58n/sVW92evl7E/bIIeKVakNk8213Kzl UTL+AemGi/lA9fyKp0bn74Khf/YY4mATHujl7EeUiZ+n3ts5rQ09gb7MWWAyOeljamEW VF9NakYitalSgDIqNGl7UvP+t0K2cS4irujtjxI07D3cwQaBxKs0atuYZ9O1iAdeGK0k 9j6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f1nM/lpdSyfhiokJoYKLwhEgbv1/4gmOk1Dy2ivEHic=; b=LP+V1k4dxqosBAwvD2j/lELfzK0NBg2SXu15x+XJVTBuzmKwuO/ehOYSz8BKAlZKXb NyjEorUFwWk7KVUHHNGbdgP+n3J1ffciXAZvZwuJHuqBDCIbvd5z5/BzQwcZBHcjyzZK vsqFWWow44lax0uAt4ZkVqP30kF/cZn/rfr1zooy09QA0S6tZsQWhPHuMofSoiTQU1HE IzH7tP8hY4QzvX/AltyDJkRzTi5L2FVV5e27Of9kXKaqKS2f2eVKCXzTRTQ+SRT4Hpz3 McR4O39eArizMNNwLcI3MwKPCX2i+d5+Cb8hOQRdg7Xx+eGQEElTIeKHudofU3QdfPtC Rmbw== X-Gm-Message-State: AOAM533cfSasqbNzSON+FuVl7BAC8hkbea5nOOyzDXNpdu3Ws/iTM83i i0GVQDlNuGUQInABFSdolgg= X-Google-Smtp-Source: ABdhPJwpl+Y35NzWtOSjv3T8c0k5bgUp2ObFD77ixFfDk+LP3QdJI72JcZJK2ppOJ0uA8hoXgx4CfQ== X-Received: by 2002:a17:906:86cc:: with SMTP id j12mr4762643ejy.548.1623928569570; Thu, 17 Jun 2021 04:16:09 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:09 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 12/16] drm/amdgpu: use new iterator in amdgpu_ttm_bo_eviction_valuable Date: Thu, 17 Jun 2021 13:15:54 +0200 Message-Id: <20210617111558.28486-13-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Simplifying the code a bit. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 80dff29f2bc7..d86b0cbff889 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1334,10 +1334,9 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, const struct ttm_place *place) { unsigned long num_pages = bo->resource->num_pages; + struct dma_resv_cursor resv_cursor; struct amdgpu_res_cursor cursor; - struct dma_resv_list *flist; struct dma_fence *f; - int i; /* Swapout? */ if (bo->resource->mem_type == TTM_PL_SYSTEM) @@ -1351,14 +1350,9 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, * If true, then return false as any KFD process needs all its BOs to * be resident to run successfully */ - flist = dma_resv_shared_list(bo->base.resv); - if (flist) { - for (i = 0; i < flist->shared_count; ++i) { - f = rcu_dereference_protected(flist->shared[i], - dma_resv_held(bo->base.resv)); - if (amdkfd_fence_check_mm(f, current->mm)) - return false; - } + dma_resv_for_each_fence(bo->base.resv, &resv_cursor, true, f) { + if (amdkfd_fence_check_mm(f, current->mm)) + return false; } switch (bo->resource->mem_type) { From patchwork Thu Jun 17 11:15:55 2021 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: 462525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDB1FC48BE5 for ; Thu, 17 Jun 2021 11:16:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA9F9613B9 for ; Thu, 17 Jun 2021 11:16:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232470AbhFQLSU (ORCPT ); Thu, 17 Jun 2021 07:18:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232468AbhFQLST (ORCPT ); Thu, 17 Jun 2021 07:18:19 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A63C061574 for ; Thu, 17 Jun 2021 04:16:11 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id s15so3422605edt.13 for ; Thu, 17 Jun 2021 04:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=vA0rvCYA+88SSxxA+oXw2xjoeTV7dLie4dtS+00yakw=; b=uN5Zx0cBca5DbQUlMYKzChSxSUBt3pn1rgGuo0oxUeskZlsiUgrLTk1HaliRHo0Vt/ jUyRiJx13d8nIltoW1+jfOTmrJpVeFCXq/T/GcF0juZQtkb11l7QNLmy9OsowxL5qPFY BnZfkZ81GDkhMR/fI9SUrwMou7NIVlD+9wtooYY3QmRvCgkOIesuMSZ1l0GHZp102i9g t4jbSCh/PkxMqnR1n80TUyGonzXFsP9dr42hODlxnNdrdDo4046NaEixY5Z/nPernKeW dhby/aGpuFR8ksEB0/1yv4/tRhKhPkT6BEaxVIKLR5TWRqaQX1KbtqMPOiF/JFr5Cff8 oGeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vA0rvCYA+88SSxxA+oXw2xjoeTV7dLie4dtS+00yakw=; b=bk/y0F05xmzdDmwGcbDbKknQUryDVbWoIt4ufaumygZN2SVoZpYzHj9Cg1Lv3VZKLV NLp+yPbUmreI6iO/gwBw2lUz0eGGhUwKGTibXpFtDHe3z1TPP/wR2uPXcc/AOKyHdBYt RNBbD9A1IqMdP5u5KmUjOVO3q1Hw2IPZUwncx58IeldG24yPyo3yQ6/WWBzAhvcxM9DV zfemrjFwZaELu23eNtNkQnU8OVxjyKulDTzm35N4LBCiiHtNd1yMvRn18XGrfCts8bBD YptwtZM0BJVR+xoElW5Qkz+nQVxOV1kNX2fF7791wya64QBikUfseIdDJPstCOUSk+ub dEaA== X-Gm-Message-State: AOAM530oQNmWNwFObndPKp7UJMGEutdKyhcfh8bAWnBzdJ24V4aKtyGT KGrjJb0eveHh9kjkNl+EbaoCw2MMqXY= X-Google-Smtp-Source: ABdhPJxdliDVqYsrZ036wK0ckaoMVPasvaJSER1iToDyEGkiVZdtlysHJiBnomX9yz33uPLT55iTRg== X-Received: by 2002:a05:6402:885:: with SMTP id e5mr5889036edy.248.1623928570233; Thu, 17 Jun 2021 04:16:10 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:09 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 13/16] drm/msm: use new iterator in msm_gem_sync_object Date: Thu, 17 Jun 2021 13:15:55 +0200 Message-Id: <20210617111558.28486-14-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Simplifying the code a bit. Untested since I can't get the driver to compile on !ARM. Signed-off-by: Christian König --- drivers/gpu/drm/msm/msm_gem.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 72a07e311de3..24f8c0603385 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -813,25 +813,11 @@ void msm_gem_vunmap(struct drm_gem_object *obj) int msm_gem_sync_object(struct drm_gem_object *obj, struct msm_fence_context *fctx, bool exclusive) { - struct dma_resv_list *fobj; + struct dma_resv_cursor cursor; struct dma_fence *fence; - int i, ret; - - fence = dma_resv_excl_fence(obj->resv); - /* don't need to wait on our own fences, since ring is fifo */ - if (fence && (fence->context != fctx->context)) { - ret = dma_fence_wait(fence, true); - if (ret) - return ret; - } - - fobj = dma_resv_shared_list(obj->resv); - if (!exclusive || !fobj) - return 0; + int ret; - for (i = 0; i < fobj->shared_count; i++) { - fence = rcu_dereference_protected(fobj->shared[i], - dma_resv_held(obj->resv)); + dma_resv_for_each_fence(obj->resv, &cursor, exclusive, fence) { if (fence->context != fctx->context) { ret = dma_fence_wait(fence, true); if (ret) From patchwork Thu Jun 17 11:15:56 2021 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: 463419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C2EEC49EA3 for ; Thu, 17 Jun 2021 11:16:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5714D613B9 for ; Thu, 17 Jun 2021 11:16:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232476AbhFQLSW (ORCPT ); Thu, 17 Jun 2021 07:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbhFQLSU (ORCPT ); Thu, 17 Jun 2021 07:18:20 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D3A2C06175F for ; Thu, 17 Jun 2021 04:16:12 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id n20so3452696edv.8 for ; Thu, 17 Jun 2021 04:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5RG0PthxUb2OXPV5l0/m18up/y1qESMs7WFmfpY8Xt0=; b=g+D3W4qMWgyEia6rgQELJge+SQQ2NVfYP2PuA5e0o92VM1hYGbeR4uefcSN1UEmoa0 TyxVqAWIkKZT5a4Z+JnAXK8BzshUnD//UGDEXFwfnATj6IyJGF9aQYSXsSOwwnBgMovU HLMKsAPe1hGChok41/dl/BnkoiN6AOT4/qQMvyPCQXQ+ia0AFlKPeQ3saDEtSSAku3pP NS7Yyiieq+IfcO3utB0CcogeAzl1skgQaiP8PuspAUdUcEu+z0IjDFaODExWGb9hqPam 8eYKw5TVI1MFS5m/0c6z2I07hNbMq1lc0DUOPSMnxA+TATcaeecC+UWTiWQCaT81NlaH oiYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5RG0PthxUb2OXPV5l0/m18up/y1qESMs7WFmfpY8Xt0=; b=j55+2+/JAaeD8H6aBo6cxrLYGFxhSXfP6Xzt2xOqgqRJKkJGXD6hLKSKrfKn8Rf83L JNjCCigCJ6U93GMy1SNqzO/K6ISScNU+jSM/0SWi2O7mJE6Q1ehH8a5aCLIm/hWb3/Ip 8+0TkA+hnKXM9ilPIRxIBm7J/GEmERhCoPvlr+HhSUOY6HIiMTb+XOXB3gBA5YIAcj5Y 20CvvKLXRGbfAdSCG3kqyePJxBvPXeTkWNktoUcNhq8AJc7jnE4f061dx07CwGDWUxY9 3jM3r15RikhJiiFgEFfQWr8c8uc53KaNl+em93TrnhSimr9a/vP9pbbH5vgM8oRs187F +i7w== X-Gm-Message-State: AOAM531ZAFbyXKBYwIheGqZYpA8a8bHKwKbWMOTy8M8WUO7MDcE4qSCc zQCxNKXEZY/nXX2PCLt0Muw= X-Google-Smtp-Source: ABdhPJxubHT7YLEEdz8ShaZB+VV9F9nfP2H/mn5NXRPMIM+yC4zBGh3VpVEM8t/+ZflUd4FZZM1Tww== X-Received: by 2002:a50:8dc6:: with SMTP id s6mr5789974edh.50.1623928570919; Thu, 17 Jun 2021 04:16:10 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:10 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 14/16] drm/msm: use new iterator in msm_gem_describe Date: Thu, 17 Jun 2021 13:15:56 +0200 Message-Id: <20210617111558.28486-15-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Simplifying the code a bit. Also drop the RCU read side lock since the object is locked anyway. Untested since I can't get the driver to compile on !ARM. Signed-off-by: Christian König --- drivers/gpu/drm/msm/msm_gem.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 24f8c0603385..8b10d82b5d7b 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -932,7 +932,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, { struct msm_gem_object *msm_obj = to_msm_bo(obj); struct dma_resv *robj = obj->resv; - struct dma_resv_list *fobj; + struct dma_resv_cursor cursor; struct dma_fence *fence; struct msm_gem_vma *vma; uint64_t off = drm_vma_node_start(&obj->vma_node); @@ -1007,22 +1007,13 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, seq_puts(m, "\n"); } - rcu_read_lock(); - fobj = dma_resv_shared_list(robj); - if (fobj) { - unsigned int i, shared_count = fobj->shared_count; - - for (i = 0; i < shared_count; i++) { - fence = rcu_dereference(fobj->shared[i]); + dma_resv_for_each_fence(robj, &cursor, true, fence) { + if (cursor.is_exclusive) + describe_fence(fence, "Exclusive", m); + else describe_fence(fence, "Shared", m); - } } - fence = dma_resv_excl_fence(robj); - if (fence) - describe_fence(fence, "Exclusive", m); - rcu_read_unlock(); - msm_gem_unlock(obj); } From patchwork Thu Jun 17 11:15:57 2021 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: 462524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B80BBC49361 for ; Thu, 17 Jun 2021 11:16:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B905613B9 for ; Thu, 17 Jun 2021 11:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbhFQLSW (ORCPT ); Thu, 17 Jun 2021 07:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232473AbhFQLSU (ORCPT ); Thu, 17 Jun 2021 07:18:20 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FE24C061574 for ; Thu, 17 Jun 2021 04:16:13 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id my49so9189883ejc.7 for ; Thu, 17 Jun 2021 04:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=aaz1/XKVq6nri9Uw2UQQseQfjyJkmrID5vYRDnEleeE=; b=aHbD1drE9FbjEyitAtdun/cQ3QyTanLaK+Y3bCT4fKCTIR1PW3W0pDZm1VyNa4MchY UHbjP+Vc4GfVwUbmH5SjvBJy8Tcy3t9PfEyqdPVDWzv53NDA2H7q3MauZcUyJFaf3EO4 tDUmoCFv+cGdLDcG+/qRhmeK6NgN5HvSpG0O8SO3Fgc518ut9tY6DR8Se8bVv/GFjZ8y 3ZrnuqclHm/x0QdgrXwv4D1uG0vYGia2mgjevoWFppjq8bPFcCWN71PDWzC5SP3Y+bhG Ue/Bk8A57XcjO8PzTNgxZfc/10yl9mozKfHv+sIOJhuSev6jgqstGh3JUKAwbFq6BQYx 8pYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aaz1/XKVq6nri9Uw2UQQseQfjyJkmrID5vYRDnEleeE=; b=qKVGYCoHqIlemISAByxzYcRHGpAFSZqtbVFyHTMnnmLvMZ5Kyu0sTI12EYJzEZkWEv Vj2ZhQ8P3O5HlZ69M9HsOOrCtYenrmszfFLPLPcUbDWfApvb8SvrEC+QNvk57leKFKmn W/6Si27/ZyJqXY4UOPKmJ7rcJ04N8Q8rkg8n3ehXU/iO21pA7SSXX/9+ERq8Dq4rORZg P66T07sp71vaq+p+ARH7olgk5cwNJbYVosFCzWMfvJoTFTrb/hHVEer9vzm2P9/la+xI 5wBIdm2aIp2zArvfaDF7orCR89XcMA5L6Kodoiu0MjiTaLVn/ZdmXucfVxlZz7ygrq6t Sl3w== X-Gm-Message-State: AOAM53372q6TwHa9KWA+jT+OUpNyXAr2/6+BQOqK5cpEHYjMdihqnCVC rsgdfDugnoNCazN3b7cy/Ho= X-Google-Smtp-Source: ABdhPJwoYJMNnGPh7pQmMwrYk0Y7Rh5oWm9rnGO6B3+1nHi8CA4dRJA2EJOwZaRm1RPhr6RMumZCeQ== X-Received: by 2002:a17:906:a95:: with SMTP id y21mr4725045ejf.522.1623928571596; Thu, 17 Jun 2021 04:16:11 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:11 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 15/16] drm/nouveau: use the new iterator in nouveau_fence_sync Date: Thu, 17 Jun 2021 13:15:57 +0200 Message-Id: <20210617111558.28486-16-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Simplifying the code a bit. Signed-off-by: Christian König --- drivers/gpu/drm/nouveau/nouveau_fence.c | 48 +++++++------------------ 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c index 05d0b3eb3690..dc8d7ca1e239 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c @@ -339,14 +339,15 @@ nouveau_fence_wait(struct nouveau_fence *fence, bool lazy, bool intr) } int -nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool exclusive, bool intr) +nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, + bool exclusive, bool intr) { struct nouveau_fence_chan *fctx = chan->fence; - struct dma_fence *fence; struct dma_resv *resv = nvbo->bo.base.resv; - struct dma_resv_list *fobj; + struct dma_resv_cursor cursor; + struct dma_fence *fence; struct nouveau_fence *f; - int ret = 0, i; + int ret; if (!exclusive) { ret = dma_resv_reserve_shared(resv, 1); @@ -355,10 +356,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e return ret; } - fobj = dma_resv_shared_list(resv); - fence = dma_resv_excl_fence(resv); - - if (fence) { + dma_resv_for_each_fence(resv, &cursor, exclusive, fence) { struct nouveau_channel *prev = NULL; bool must_wait = true; @@ -366,41 +364,19 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e if (f) { rcu_read_lock(); prev = rcu_dereference(f->channel); - if (prev && (prev == chan || fctx->sync(f, prev, chan) == 0)) + if (prev && (prev == chan || + fctx->sync(f, prev, chan) == 0)) must_wait = false; rcu_read_unlock(); } - if (must_wait) + if (must_wait) { ret = dma_fence_wait(fence, intr); - - return ret; - } - - if (!exclusive || !fobj) - return ret; - - for (i = 0; i < fobj->shared_count && !ret; ++i) { - struct nouveau_channel *prev = NULL; - bool must_wait = true; - - fence = rcu_dereference_protected(fobj->shared[i], - dma_resv_held(resv)); - - f = nouveau_local_fence(fence, chan->drm); - if (f) { - rcu_read_lock(); - prev = rcu_dereference(f->channel); - if (prev && (prev == chan || fctx->sync(f, prev, chan) == 0)) - must_wait = false; - rcu_read_unlock(); + if (ret) + return ret; } - - if (must_wait) - ret = dma_fence_wait(fence, intr); } - - return ret; + return 0; } void From patchwork Thu Jun 17 11:15:58 2021 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: 463418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F76EC48BE5 for ; Thu, 17 Jun 2021 11:16:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DDD8613BF for ; Thu, 17 Jun 2021 11:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbhFQLSX (ORCPT ); Thu, 17 Jun 2021 07:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232477AbhFQLSX (ORCPT ); Thu, 17 Jun 2021 07:18:23 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6CECC061760 for ; Thu, 17 Jun 2021 04:16:13 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id nd37so9263477ejc.3 for ; Thu, 17 Jun 2021 04:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=R6hl7Kj0yqQ18nUKlg1tjNnt1DaG6v6UQcKSpcEHFSE=; b=JGK01UuNZMIEIDibVS0nyIINaWe1LD8WZSd2MzqqM2c1KEb2oA3W9tigP/K49EqQW8 HZxCrrioSf1JPwkEFtuGmZZRBoArktZT6ohdSForRUjBj23LLhDX3yQPRXYyLMozPX7e l/t6i/bxYWFoVNcLTK5HgX2RtfTcooCVtxNCp2D/9SEn52xJiDUO84QtRapdt+IJlEok CJ/lmWyy/U6dbXa2Wniz6V7zBH0SdBaNv+4HPtws7b0i6j4yuu/SCwo2rT0oVh2DOaju TJzNFPmCQnAbO6g6e6nPuoZt4kam7XNW4A0fqhl+bNthPPPtHRZpXfuD5m1sNVTOBZlL O/PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R6hl7Kj0yqQ18nUKlg1tjNnt1DaG6v6UQcKSpcEHFSE=; b=FAXy5b/HZ4cN9jiNHoxwdZsvSh8vwPrJ2CKL8Sgz2dWpvt+6EJlPXnmuPXibE10o0i G6XoG7cHsbqo6LEmR+as02HiAuR/EYReYoYL/nvbmZDch+xEiw0oAIxGxn2x38x/WIj/ ViawR8dtHYy0U+EWr5Qu4dwG9BBp/mhuyzYFXETRgmLQ2XCMgBvXDwoIXvSXsY8STj1M uLQek6tDkVgQ4ydZ8N27fmit1Yt71GBWIODv9ap7bkSjqsWhIC3oPnEI2ePZ335dyKQP wXjMxHPWCfcsnRnDv9Ig7ADm6Rbbt8QrGdeL4/R4RfrCfG+1rZiuv3AQSoPGIcJ0WyQM yiqQ== X-Gm-Message-State: AOAM531IYcUL5ult3TamTByihTLlXFwAm7sknkB1/iOB5xwqcqYc+YWd jyWYfAVg3/N/AHt1dmJMulU= X-Google-Smtp-Source: ABdhPJzM+36tYqZqJ/QN7yQ4BXU4PIysQ1XlwHkj9hQ3HC1RgavOExt7bDD1K7FT+NqCLwr8YaMZWQ== X-Received: by 2002:a17:907:20ee:: with SMTP id rh14mr4645376ejb.461.1623928572354; Thu, 17 Jun 2021 04:16:12 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:8534:5e76:1ee5:f3ad]) by smtp.gmail.com with ESMTPSA id y10sm3531353ejm.76.2021.06.17.04.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:16:12 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [PATCH 16/16] drm/radeon: use new iterator in radeon_sync_resv Date: Thu, 17 Jun 2021 13:15:58 +0200 Message-Id: <20210617111558.28486-17-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210617111558.28486-1-christian.koenig@amd.com> References: <20210617111558.28486-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Simplifying the code a bit. Signed-off-by: Christian König --- drivers/gpu/drm/radeon/radeon_sync.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_sync.c b/drivers/gpu/drm/radeon/radeon_sync.c index 9257b60144c4..14a4d8135bad 100644 --- a/drivers/gpu/drm/radeon/radeon_sync.c +++ b/drivers/gpu/drm/radeon/radeon_sync.c @@ -91,33 +91,17 @@ int radeon_sync_resv(struct radeon_device *rdev, struct dma_resv *resv, bool shared) { - struct dma_resv_list *flist; - struct dma_fence *f; + struct dma_resv_cursor cursor; struct radeon_fence *fence; - unsigned i; + struct dma_fence *f; int r = 0; - /* always sync to the exclusive fence */ - f = dma_resv_excl_fence(resv); - fence = f ? to_radeon_fence(f) : NULL; - if (fence && fence->rdev == rdev) - radeon_sync_fence(sync, fence); - else if (f) - r = dma_fence_wait(f, true); - - flist = dma_resv_shared_list(resv); - if (shared || !flist || r) - return r; - - for (i = 0; i < flist->shared_count; ++i) { - f = rcu_dereference_protected(flist->shared[i], - dma_resv_held(resv)); + dma_resv_for_each_fence(resv, &cursor, shared, f) { fence = to_radeon_fence(f); if (fence && fence->rdev == rdev) radeon_sync_fence(sync, fence); else r = dma_fence_wait(f, true); - if (r) break; }