Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10854864imu; Thu, 6 Dec 2018 07:49:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/UEsfr6+D5zQUhz+Dtgdp3O7f102yjO56gR7mTUwdhcCQcEA95zlnOGiw07vJtQOhlQvind X-Received: by 2002:a65:4142:: with SMTP id x2mr23892226pgp.356.1544111394393; Thu, 06 Dec 2018 07:49:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544111394; cv=none; d=google.com; s=arc-20160816; b=n2nLlLIdxRhFYH3t9lfJQc3cR2TigJ9H1WuO/dNYJD6O7gCbilzGMJw/n/N4ubzFzg 1+BQLzw+9a/tmaopVa/8AXyej/zX3hDviDxl/z3JgEtiQM0hp+eqs4WoUhv+CNx7V8O2 wUiO3SCY7yTc3pd1XE4jsrUjWW8u6X3gOJIOZENSmq+E9z5UX8X6m8B+jVghkKJcBOxq EUqZZmFcRaLRPBgWkOSkhgHkUEuZ6S68BdpQz/E/woQ1BEg1aa+2PJT4hIZqP4aVag+E Y3t/xCT/tctGAUodHn9eUTJmDOZQbKKfi9HNOkKGtMqjIl1hwc7Xn+h7hJhiQWbx0hIM MBMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=2LaRue42fr2I/T+kUKmlw/oWur7llrlMp5Kw6w6oftk=; b=umTOkBT12VpnxBlvuuOVVz4y0gnTd5tGf4y3y0XiKWXCSPnyqfMEAHmvP12ih1VCy8 e232YYRtL56f4CZc8PMDkp3j1ikDjh/XWe1/DtiDSu+zz8CbQLLKjbu75+kXqIbnrP6N KRwNRsBoWdTIUb32oNiTrNGlh417vUiSILfLORbM2gu9ixAdnaF9cLsG0F5X+2HhskMI hrOFS2seWeR+golz7yoVHeDP9E50FjTBBbqB+kbZ70ZHbwbo89T/gjtCmULkfJRQsTPq +ADF0aLo5JPcEtUDnAqUat7bs53j1q2QfWZcPyRWdOr9MTJGrIjfznYzSuvz4GX8/5TO 8zGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6si494829pgd.292.2018.12.06.07.49.30; Thu, 06 Dec 2018 07:49:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726121AbeLFPrP (ORCPT + 99 others); Thu, 6 Dec 2018 10:47:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48666 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725908AbeLFPrO (ORCPT ); Thu, 6 Dec 2018 10:47:14 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72E57307D85A; Thu, 6 Dec 2018 15:47:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-122-74.rdu2.redhat.com [10.10.122.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98D251057074; Thu, 6 Dec 2018 15:47:11 +0000 (UTC) From: jglisse@redhat.com To: linux-kernel@vger.kernel.org Cc: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter , Sumit Semwal , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, =?UTF-8?q?St=C3=A9phane=20Marchesin?= , stable@vger.kernel.org Subject: [PATCH] dma-buf: fix debugfs versus rcu and fence dumping v2 Date: Thu, 6 Dec 2018 10:47:04 -0500 Message-Id: <20181206154704.5366-1-jglisse@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 06 Dec 2018 15:47:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jérôme Glisse The debugfs take reference on fence without dropping them. Also the rcu section are not well balance. Fix all that ... Changed since v1: - moved fobj logic around to be rcu safe Signed-off-by: Jérôme Glisse Cc: Christian König Cc: Daniel Vetter Cc: Sumit Semwal Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Cc: Stéphane Marchesin Cc: stable@vger.kernel.org --- drivers/dma-buf/dma-buf.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 13884474d158..9688d99894d6 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1048,27 +1048,38 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) while (true) { seq = read_seqcount_begin(&robj->seq); rcu_read_lock(); - fobj = rcu_dereference(robj->fence); - shared_count = fobj ? fobj->shared_count : 0; fence = rcu_dereference(robj->fence_excl); + fence = dma_fence_get_rcu(fence); if (!read_seqcount_retry(&robj->seq, seq)) break; rcu_read_unlock(); } - - if (fence) + if (fence) { seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n", fence->ops->get_driver_name(fence), fence->ops->get_timeline_name(fence), dma_fence_is_signaled(fence) ? "" : "un"); - for (i = 0; i < shared_count; i++) { + dma_fence_put(fence); + } + + rcu_read_lock(); + fobj = rcu_dereference(robj->fence); + shared_count = fobj ? fobj->shared_count : 0; + for (i = 0, fence = NULL; i < shared_count; i++) { fence = rcu_dereference(fobj->shared[i]); if (!dma_fence_get_rcu(fence)) continue; + rcu_read_unlock(); + seq_printf(s, "\tShared fence: %s %s %ssignalled\n", fence->ops->get_driver_name(fence), fence->ops->get_timeline_name(fence), dma_fence_is_signaled(fence) ? "" : "un"); + dma_fence_put(fence); + + rcu_read_lock(); + fobj = rcu_dereference(robj->fence); + shared_count = fobj ? fobj->shared_count : 0; } rcu_read_unlock(); -- 2.17.2