From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8D522E8893; Tue, 15 Jul 2025 13:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752586195; cv=none; b=T6E5qTa7hXL4pXZ1T67k2TDx/XoggdMxVEoK93cXAtmNr02/zVmky2lq2YaMK3xCvCAdbzABi8u1gsCEzKiGq310VLBWa+X+Qd8wdgotC8/DxXYhGcu+4QU6tL71qt0OguxXoo5nfKq66X7hHf0vy/Qv2ayNRK3AmDCfKBBfhjA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752586195; c=relaxed/simple; bh=beeD5m0tCqm/1iHKlhJxxKaSZiV9vWlafxiX+rcY1Ao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FDQVm6DB4gsmT5dZDwHl3hZX+Xa7P6g3cU4Hbe5t1ODBoV34hgtizVoD0fz+l2unYi+h+fqemSSwBWf4dhakra2LaUABzCxhxMJYLHOaEO3k5i6ERIbz25Z0QZB3e0mBpnKIQ9fOHNsmLCl8HxFGBfa0/0FnYf3wh6tdbrPTFBQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sWAkcxHe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sWAkcxHe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A867C4CEF8; Tue, 15 Jul 2025 13:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1752586194; bh=beeD5m0tCqm/1iHKlhJxxKaSZiV9vWlafxiX+rcY1Ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sWAkcxHeGxBoJz1odkizLispnh5IF3KECsadf675G/9S6ry0NIbiTAcLyItF+6zTI I/Gd2Caif7zwqWTZLd3QQDIwl8yDW8Cazsdkhz+Nw/QgwysGZ7AxD7MX40Qhad08Y2 /dxOOK5LSg4z6r4RVfeyIQzluyIFZlGWxg81uTuQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter , Sasha Levin Subject: [PATCH 5.15 51/77] dma-buf: use new iterator in dma_resv_wait_timeout Date: Tue, 15 Jul 2025 15:13:50 +0200 Message-ID: <20250715130753.774312356@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250715130751.668489382@linuxfoundation.org> References: <20250715130751.668489382@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian König [ Upstream commit ada5c48b11a3df814701daa9cd11305a75a5f1a5 ] This makes the function much simpler since the complex retry logic is now handled elsewhere. Signed-off-by: Christian König Reviewed-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20211005113742.1101-7-christian.koenig@amd.com Stable-dep-of: 2b95a7db6e0f ("dma-buf: fix timeout handling in dma_resv_wait_timeout v2") Signed-off-by: Sasha Levin --- drivers/dma-buf/dma-resv.c | 69 +++++--------------------------------- 1 file changed, 8 insertions(+), 61 deletions(-) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index c747b19c3be16..8db368c7d35c3 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -613,74 +613,21 @@ 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_iter 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; - - if (dma_fence_is_signaled(fence)) { - dma_fence_put(fence); - fence = NULL; - } - - } 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; - } + dma_resv_iter_begin(&cursor, obj, wait_all); + dma_resv_for_each_fence_unlocked(&cursor, fence) { - fence = lfence; - break; + ret = dma_fence_wait_timeout(fence, intr, ret); + if (ret <= 0) { + dma_resv_iter_end(&cursor); + return ret; } } + dma_resv_iter_end(&cursor); - 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); -- 2.39.5