From patchwork Thu Jul 27 19:03:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9867465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E08456038F for ; Thu, 27 Jul 2017 19:04:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2FC52885F for ; Thu, 27 Jul 2017 19:04:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7D7C28862; Thu, 27 Jul 2017 19:04:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.4 required=2.0 tests=BAYES_00, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9A7912885F for ; Thu, 27 Jul 2017 19:04:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B65F6EEB6; Thu, 27 Jul 2017 19:04:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by gabe.freedesktop.org (Postfix) with ESMTPS id A839C6EEB6 for ; Thu, 27 Jul 2017 19:04:01 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id q66so19167823qki.1 for ; Thu, 27 Jul 2017 12:04:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=phI4LAZGOdhVrBrrbJt9gy12VjFI3YBaYA1Ieg6OP38=; b=SYW9A3T7dZdWXhC1n333agRSVXs/xvYVLmz5EyHVOfpnEIvvVOSFRlruVobRicYc6H gVF83oZ5M+KwKbL6hr+5Ed4DhzZLryh1MoB4blajOzDtwXB6MiOD91UTBlrvXry4O5e0 wq0iqS/iHjJPZ09O42eNI2AFdFownrfl29eqCm43vgB1xbV8xxARfvNHTuMeeVonZYZ2 q1GrifFwe7NMc110fKirMTTCY78Wf4txffMtafTRG7Oyfs7QHYnqohbp3uB93JxukO4z T12bouNy4m3IqVfY1Hq5aiDiJjLyiGQjJMINkccst/wiuxZRo/oEy6YmSN4PGpr1/6GD EAYA== X-Gm-Message-State: AIVw111x2No3KuQqGE8ZsPlP92BpWB1mWgHni30EqjJ/hAaoMCAFRAti /sRyBV4uYGWVao24uE4= X-Received: by 10.55.66.23 with SMTP id p23mr6975939qka.270.1501182240643; Thu, 27 Jul 2017 12:04:00 -0700 (PDT) Received: from localhost.localdomain ([187.35.198.81]) by smtp.gmail.com with ESMTPSA id z192sm13668292qka.46.2017.07.27.12.03.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jul 2017 12:03:59 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH] dma-buf/sw_sync: hold a fence reference when check if it signaled Date: Thu, 27 Jul 2017 16:03:53 -0300 Message-Id: <20170727190353.3353-1-gustavo@padovan.org> X-Mailer: git-send-email 2.9.4 Cc: Gustavo Padovan X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan If userspace already dropped its own reference by closing the sw_sync fence fd we might end up in a deadlock where dma_fence_is_signaled_locked() will trigger the release of the fence a thus try to hold the lock to remove the fence from the list. We need to grab a reference to the fence before calling into this chain if we want to avoid this issue. Cc: Chris Wilson Signed-off-by: Gustavo Padovan --- drivers/dma-buf/sw_sync.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c index af1bc84..8291434 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c @@ -144,11 +144,16 @@ static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc) obj->value += inc; list_for_each_entry_safe(pt, next, &obj->pt_list, link) { - if (!dma_fence_is_signaled_locked(&pt->base)) + dma_fence_get(&pt->base); + if (!dma_fence_is_signaled_locked(&pt->base)) { + dma_fence_put(&pt->base); break; + } list_del_init(&pt->link); rb_erase(&pt->node, &obj->pt_tree); + + dma_fence_put(&pt->base); } spin_unlock_irq(&obj->lock);