From patchwork Fri Nov 2 09:15:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10665193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AD9813B5 for ; Fri, 2 Nov 2018 09:15:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0868D2BA63 for ; Fri, 2 Nov 2018 09:15:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F01D42BA84; Fri, 2 Nov 2018 09:15:53 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 9358B2BA63 for ; Fri, 2 Nov 2018 09:15:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 076716E550; Fri, 2 Nov 2018 09:15:53 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id D27216E550 for ; Fri, 2 Nov 2018 09:15:50 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id h21-v6so841552edq.9 for ; Fri, 02 Nov 2018 02:15:50 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v/nJvkO8BlzHVYuslWZiocYbN0/cuXO3PIU87c+u8Bg=; b=rWZwh/k1GUPRdMRdkHJ+9DduYBK6l2wY6jDVw0LCRm3DdaOJS9OxxRwUttOaisM+28 /xgYOLh6s9eCGprwScaPAYk947TJwa46k+Geyv18s0+zPVEm2puecAsx7je2cPaqZQPG 81+aYNC5zGS5OGVVEQh9S5v++Sm8i5lDKaKY2cFiQA1QogryiNR0RfZPS6oswxUVVeru y6kmMY+5IDYbkH+zzqXxyoXPPXtLaBlBDkrUZ8RUhtbdXp1PNKcKHg7vRQQyuPpBNigT 9cz8C468mVUb/e8nJVakSU7zCrejxjhxx+qTXuubAedN3poZwYcjzMV3Ym11ao7GI1Cp mjYg== X-Gm-Message-State: AGRZ1gJdRm/PG+uQArhW50ht5NMLd03k0+S0QZHNq3wFJI8VGPtSDJWR NAxl9pUJh59NUwnDVrW06f5iBcHnlfY= X-Google-Smtp-Source: AJdET5ddRfP0LuxewCLHTU2VlC9zzUWiY3vdyOcu6wj8W8Wt1T8PC8t/OfPVGRO4VFts78C0Q0TFfw== X-Received: by 2002:a17:906:4d41:: with SMTP id b1-v6mr6035514ejv.171.1541150149089; Fri, 02 Nov 2018 02:15:49 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id p19-v6sm5658103ejw.69.2018.11.02.02.15.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Nov 2018 02:15:48 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Date: Fri, 2 Nov 2018 10:15:27 +0100 Message-Id: <20181102091531.7775-8-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102091531.7775-1-daniel.vetter@ffwll.ch> References: <20181102091531.7775-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 08/12] dma-fence: cross-release annotations X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP dma-fence is a completion on steriods, which also allows hardware to directly sync work among each another. It's supposed to be deadlock free, so let's try to make sure that holds at least for the cpu-only interactions and waits. It's a bit much #ifdef, but I figured for the single case it's not worth it to pull it all out. Also, the single global lockdep map is intentional: dma_fences are supposed to be shared, we need all drivers to be compatible to each another in their locking hierarchy. v2: - handle #idef mess cleaner - also annotate dma_fence_signal() v3: - Add a dma_fence_might_wait() function to annotate fastpaths - Put it all into headers for other code to use Cc: Sumit Semwal Cc: Gustavo Padovan Cc: linux-media@vger.kernel.org Cc: linaro-mm-sig@lists.linaro.org Signed-off-by: Daniel Vetter --- drivers/dma-buf/dma-fence.c | 14 ++++++++++++++ include/linux/dma-fence.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 1551ca7df394..7d56d8b48624 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -30,6 +30,13 @@ EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit); EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal); + +#ifdef CONFIG_LOCKDEP_CROSSRELEASE +struct lockdep_map_cross dma_fence_wait_map = + STATIC_CROSS_LOCKDEP_MAP_INIT("dma_fence_signal", &dma_fence_wait_map); +EXPORT_SYMBOL(dma_fence_wait_map); +#endif + /* * fence context counter: each execution context should have its own * fence context, this allows checking if fences belong to the same @@ -106,6 +113,8 @@ int dma_fence_signal_locked(struct dma_fence *fence) lockdep_assert_held(fence->lock); + dma_fence_wait_release_commit(); + if (WARN_ON(!fence)) return -EINVAL; @@ -153,6 +162,8 @@ int dma_fence_signal(struct dma_fence *fence) if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) return -EINVAL; + dma_fence_wait_release_commit(); + fence->timestamp = ktime_get(); set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags); trace_dma_fence_signaled(fence); @@ -197,12 +208,15 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout) if (WARN_ON(timeout < 0)) return -EINVAL; + dma_fence_wait_acquire(); trace_dma_fence_wait_start(fence); if (fence->ops->wait) ret = fence->ops->wait(fence, intr, timeout); else ret = dma_fence_default_wait(fence, intr, timeout); trace_dma_fence_wait_end(fence); + dma_fence_wait_release(); + return ret; } EXPORT_SYMBOL(dma_fence_wait_timeout); diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 02dba8cd033d..8a045334a207 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -34,6 +34,34 @@ struct dma_fence; struct dma_fence_ops; struct dma_fence_cb; +#ifdef CONFIG_LOCKDEP_CROSSRELEASE +#include +extern struct lockdep_map_cross dma_fence_wait_map; + +static inline void dma_fence_wait_acquire(void) +{ + lock_acquire_exclusive(&dma_fence_wait_map.map, 0, 0, NULL, _RET_IP_); +} +static inline void dma_fence_wait_release(void) +{ + lock_release(&dma_fence_wait_map.map, 0, _RET_IP_); +} +static inline void dma_fence_wait_release_commit(void) +{ + lock_commit_crosslock(&dma_fence_wait_map.map); +} +#else +static inline void dma_fence_wait_acquire(void) {} +static inline void dma_fence_wait_release(void) {} +static inline void dma_fence_wait_release_commit(void) {} +#endif + +static inline void dma_fence_might_wait(void) +{ + dma_fence_wait_acquire(); + dma_fence_wait_release(); +} + /** * struct dma_fence - software synchronization primitive * @refcount: refcount for this fence