From patchwork Mon Jan 29 15:40:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 10189857 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 5ED5660388 for ; Mon, 29 Jan 2018 15:37:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 485A7223A0 for ; Mon, 29 Jan 2018 15:37:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C91E2838F; Mon, 29 Jan 2018 15:37:56 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham 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 CCC03223A0 for ; Mon, 29 Jan 2018 15:37:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5766788E53; Mon, 29 Jan 2018 15:37:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3D9B588E53 for ; Mon, 29 Jan 2018 15:37:52 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id w50so7711608wrc.2 for ; Mon, 29 Jan 2018 07:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=QG42lEx6epzlzTKxgzwl22DE9P5NrS5HhQCY3Jb61PA=; b=Zz0WgpPxE10FDDB5GechZ2DrFDSKKy/iB4XoDtry3YTwFNy+S52qZYlkryO08nrXDc JYmVrtrPzVd+9+amicqNb06GqYYeUlkj6Gl6Sb7hojSkFJZ6iqYebfFmIqA3HcHM8+9U rtHSkuFekdYqKI7Thpck5PXu71DGmQzVGSf1LeF10EBIxJjm1dMD5DlOCtIMrdexQzq5 bq3tuc70PrsNuUNQdIzNX2UKZi+Xu12wW9U8PAvEZBOjI8Ud7HPvZKjLyO97xRIeykOa z8xWFhSJiwFWzeDgDWj/wwTYTg4qfBTcQJqznpZEEYXN7tipIfEMyT7efvXeHAdFjzj/ m7XA== 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; bh=QG42lEx6epzlzTKxgzwl22DE9P5NrS5HhQCY3Jb61PA=; b=bHy6B869PSUJwl5ikYstDP1z9PPtH/0LT1aLchHrCxhEq6Up1jrBZ5xlx4+zpEkNWP TxXQiXZ3SXZjCnmholmctx6imOUJb+vfcpAGrSTgWBOhgdWcDUSgewxaHVaPtIG0GPkX miWcA/84AFvor8at2tJzukGcN6DZV1joAipxMrcr/5cJHOT8T+Kjj6HHi0yWa/appwP9 n4xvTmS6lIwrZb4F4S93ZCdnC6eI8FKLGzE/tJjxYBA8z3pugo8/5myXgHZxAP3a2hkw htDcIe6a0k9RKxUDT2y5AjAaNq9JIl3+arbOhAE/VCD41/FxmQcpMufdMd8oq0mXULya Tzcg== X-Gm-Message-State: AKwxytdHNxGdp68ZiWGHeCkza3HFw8tia6+louKdDfx90t32qrgepu4P Wpr2mXDl14EjWoinndpYKSPCjUJz X-Google-Smtp-Source: AH8x226n8p8/aI+q13BNA9H0O33vQOhZAZ4Nj9AVKv/DP7e5uwbEHFxsAL3ZyIQLy3llSW0HsafYHA== X-Received: by 10.223.193.71 with SMTP id w7mr21529595wre.88.1517240270841; Mon, 29 Jan 2018 07:37:50 -0800 (PST) Received: from odedg-x270.habana-labs.com ([31.154.181.186]) by smtp.gmail.com with ESMTPSA id 5sm12948615wre.35.2018.01.29.07.37.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jan 2018 07:37:50 -0800 (PST) From: Oded Gabbay To: maarten.lankhorst@canonical.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, robdclark@gmail.com Subject: [PATCH] dma-fence: add comment for WARN_ON in dma_fence_release() Date: Mon, 29 Jan 2018 17:40:02 +0200 Message-Id: <20180129154002.3287-1-oded.gabbay@gmail.com> X-Mailer: git-send-email 2.14.3 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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 In dma_fence_release() there is a WARN_ON which could be triggered by several cases of wrong dma-fence usage. This patch adds a comment to explain two use-cases to help driver developers that use dma-fence and trigger that WARN_ON to better understand the reasons for it. Signed-off-by: Oded Gabbay Reviewed-by: Daniel Vetter --- drivers/dma-buf/dma-fence.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 5d101c4053e0..a7170ab23ec0 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -171,6 +171,39 @@ void dma_fence_release(struct kref *kref) trace_dma_fence_destroy(fence); + /* + * If the WARN_ON below is triggered it could be because the dma fence + * was not signaled and therefore, the cb list is still not empty + * because the cb functions were not called. + * + * A more subtle case is where the fence got signaled by a thread that + * didn't hold a ref to the fence. The following describes the scenario: + * + * Thread A Thread B + *-------------------------- -------------------------- + * calls dma_fence_signal() { + * set signal bit + * + * scheduled out + * ---------------------------> calls dma_fence_wait_timeout() and + * returns immediately + * + * calls dma_fence_put() + * | + * |thread A doesn't hold ref + * |to fence so ref goes to 0 + * |and release is called + * | + * -> dma_fence_release() + * | + * -> WARN_ON triggered + * + * go over CB list, + * call each CB and remove it + * } + * + * + */ WARN_ON(!list_empty(&fence->cb_list)); if (fence->ops->release)