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 4FA2D282FB for ; Wed, 7 Aug 2024 14:07:36 +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=1723039656; cv=none; b=DTOs4dNrH2SRmBEPrDlaeabVr7uy4q00wb+2U6yBhdniMohQ+Wi5WDmWMnQ1+mB3JApn+iqh5lppX7oCSwYXjGN0yaFWI1O8VxFyWQpw8uyCrIgxPJncKGfKoqZ6iRzoCVCQtu12h6bQWUv39YLSs+ADX9DXdzw5K+n0CdlPJF0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723039656; c=relaxed/simple; bh=es2H1aScCbtuLMZbYb7HM3Q1dmV+Ya/oMdBdiof3gyU=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=tcfjuj5Do4UQn36bXAtqBXMqbbeBEk47OY2idhSIBIMSd2oElsL4AMrhD5BOd5euTqzE+QBVZL3OZGyLBQLjyGQrBbam7My/J61Co+0mRVVYBz7KME5VaiYOXc2ZNa6h/Nqyl1oXZMjrtJ4NH+KipBGr8GDw3kCzT7bQkenstQs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UkWLNab/; 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="UkWLNab/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2B28C32781; Wed, 7 Aug 2024 14:07:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723039656; bh=es2H1aScCbtuLMZbYb7HM3Q1dmV+Ya/oMdBdiof3gyU=; h=Subject:To:Cc:From:Date:From; b=UkWLNab/MUqzmc1P802D5spwOdKImZO1N7/MXvP30xR8yTXFTjoFQAypHyjZ7kd4e qBXYGUvgmEBCZE4FNG/pc2HKY37Q/Kx/aYLWJo0ea6nC6MZXUiaflpURGyzOMdHlyZ InRYHhrzZtWGQbUyQt7AKKJIWoEkSbG/nE8MRwjQ= Subject: FAILED: patch "[PATCH] drm/vmwgfx: Fix a deadlock in dma buf fence polling" failed to apply to 5.4-stable tree To: zack.rusin@broadcom.com,bcm-kernel-feedback-list@broadcom.com,maaz.mombasawala@broadcom.com,martin.krastev@broadcom.com,stable@vger.kernel.org Cc: From: Date: Wed, 07 Aug 2024 16:07:24 +0200 Message-ID: <2024080724-activator-freeware-804d@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.4-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.4.y git checkout FETCH_HEAD git cherry-pick -x e58337100721f3cc0c7424a18730e4f39844934f # git commit -s git send-email --to '' --in-reply-to '2024080724-activator-freeware-804d@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^.. Possible dependencies: e58337100721 ("drm/vmwgfx: Fix a deadlock in dma buf fence polling") c6771b6338c8 ("drm/vmwgfx/vmwgfx_fence: Add, remove and demote various documentation params/headers") be4f77ac6884 ("drm/vmwgfx: Cleanup fifo mmio handling") 840462e6872d ("drm/vmwgfx: Remove references to struct drm_device.pdev") 36891da8de98 ("drm/vmwgfx: Call vmw_driver_{load,unload}() before registering device") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From e58337100721f3cc0c7424a18730e4f39844934f Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 22 Jul 2024 14:41:13 -0400 Subject: [PATCH] drm/vmwgfx: Fix a deadlock in dma buf fence polling Introduce a version of the fence ops that on release doesn't remove the fence from the pending list, and thus doesn't require a lock to fix poll->fence wait->fence unref deadlocks. vmwgfx overwrites the wait callback to iterate over the list of all fences and update their status, to do that it holds a lock to prevent the list modifcations from other threads. The fence destroy callback both deletes the fence and removes it from the list of pending fences, for which it holds a lock. dma buf polling cb unrefs a fence after it's been signaled: so the poll calls the wait, which signals the fences, which are being destroyed. The destruction tries to acquire the lock on the pending fences list which it can never get because it's held by the wait from which it was called. Old bug, but not a lot of userspace apps were using dma-buf polling interfaces. Fix those, in particular this fixes KDE stalls/deadlock. Signed-off-by: Zack Rusin Fixes: 2298e804e96e ("drm/vmwgfx: rework to new fence interface, v2") Cc: Broadcom internal kernel review list Cc: dri-devel@lists.freedesktop.org Cc: # v6.2+ Reviewed-by: Maaz Mombasawala Reviewed-by: Martin Krastev Link: https://patchwork.freedesktop.org/patch/msgid/20240722184313.181318-2-zack.rusin@broadcom.com diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c index 5efc6a766f64..588d50ababf6 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c @@ -32,7 +32,6 @@ #define VMW_FENCE_WRAP (1 << 31) struct vmw_fence_manager { - int num_fence_objects; struct vmw_private *dev_priv; spinlock_t lock; struct list_head fence_list; @@ -124,13 +123,13 @@ static void vmw_fence_obj_destroy(struct dma_fence *f) { struct vmw_fence_obj *fence = container_of(f, struct vmw_fence_obj, base); - struct vmw_fence_manager *fman = fman_from_fence(fence); - spin_lock(&fman->lock); - list_del_init(&fence->head); - --fman->num_fence_objects; - spin_unlock(&fman->lock); + if (!list_empty(&fence->head)) { + spin_lock(&fman->lock); + list_del_init(&fence->head); + spin_unlock(&fman->lock); + } fence->destroy(fence); } @@ -257,7 +256,6 @@ static const struct dma_fence_ops vmw_fence_ops = { .release = vmw_fence_obj_destroy, }; - /* * Execute signal actions on fences recently signaled. * This is done from a workqueue so we don't have to execute @@ -355,7 +353,6 @@ static int vmw_fence_obj_init(struct vmw_fence_manager *fman, goto out_unlock; } list_add_tail(&fence->head, &fman->fence_list); - ++fman->num_fence_objects; out_unlock: spin_unlock(&fman->lock); @@ -403,7 +400,7 @@ static bool vmw_fence_goal_new_locked(struct vmw_fence_manager *fman, u32 passed_seqno) { u32 goal_seqno; - struct vmw_fence_obj *fence; + struct vmw_fence_obj *fence, *next_fence; if (likely(!fman->seqno_valid)) return false; @@ -413,7 +410,7 @@ static bool vmw_fence_goal_new_locked(struct vmw_fence_manager *fman, return false; fman->seqno_valid = false; - list_for_each_entry(fence, &fman->fence_list, head) { + list_for_each_entry_safe(fence, next_fence, &fman->fence_list, head) { if (!list_empty(&fence->seq_passed_actions)) { fman->seqno_valid = true; vmw_fence_goal_write(fman->dev_priv,