From patchwork Sat Aug 24 13:58:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11112999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D64381399 for ; Sat, 24 Aug 2019 13:59:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B65F02082F for ; Sat, 24 Aug 2019 13:59:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B65F02082F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 305B36E0C8; Sat, 24 Aug 2019 13:59:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3C44E6E0C8; Sat, 24 Aug 2019 13:59:01 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 18250946-1500050 for multiple; Sat, 24 Aug 2019 14:58:50 +0100 From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH] dma-buf: Give dma-fence-array distinct lockclasses Date: Sat, 24 Aug 2019 14:58:48 +0100 Message-Id: <20190824135848.8571-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 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: , Cc: intel-gfx@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In order to allow dma-fence-array as a generic container for fences, we need to allow for it to contain other dma-fence-arrays. By giving each dma-fence-array construction their own lockclass, we allow different types of dma-fence-array to nest, but still do not allow on class of dma-fence-array to contain itself (even though they have distinct locks). In practice, this means that each subsystem gets its own dma-fence-array class and we can freely use dma-fence-arrays as containers within the dmabuf core without angering lockdep. Signed-off-by: Chris Wilson Cc: Christian König Cc: Daniel Vetter --- drivers/dma-buf/dma-fence-array.c | 13 ++++++++----- include/linux/dma-fence-array.h | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index d3fbd950be94..d9bcdbb66d46 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -147,10 +147,11 @@ EXPORT_SYMBOL(dma_fence_array_ops); * If @signal_on_any is true the fence array signals if any fence in the array * signals, otherwise it signals when all fences in the array signal. */ -struct dma_fence_array *dma_fence_array_create(int num_fences, - struct dma_fence **fences, - u64 context, unsigned seqno, - bool signal_on_any) +struct dma_fence_array *__dma_fence_array_create(int num_fences, + struct dma_fence **fences, + u64 context, unsigned seqno, + bool signal_on_any, + struct lock_class_key *key) { struct dma_fence_array *array; size_t size = sizeof(*array); @@ -162,6 +163,8 @@ struct dma_fence_array *dma_fence_array_create(int num_fences, return NULL; spin_lock_init(&array->lock); + lockdep_set_class(&array->lock, key); + dma_fence_init(&array->base, &dma_fence_array_ops, &array->lock, context, seqno); init_irq_work(&array->work, irq_dma_fence_array_work); @@ -174,7 +177,7 @@ struct dma_fence_array *dma_fence_array_create(int num_fences, return array; } -EXPORT_SYMBOL(dma_fence_array_create); +EXPORT_SYMBOL(__dma_fence_array_create); /** * dma_fence_match_context - Check if all fences are from the given context diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h index 303dd712220f..1395f9428cdb 100644 --- a/include/linux/dma-fence-array.h +++ b/include/linux/dma-fence-array.h @@ -74,10 +74,18 @@ to_dma_fence_array(struct dma_fence *fence) return container_of(fence, struct dma_fence_array, base); } -struct dma_fence_array *dma_fence_array_create(int num_fences, - struct dma_fence **fences, - u64 context, unsigned seqno, - bool signal_on_any); +#define dma_fence_array_create(num, fences, context, seqno, any) ({ \ + static struct lock_class_key __key; \ + \ + __dma_fence_array_create((num), (fences), (context), (seqno), (any), \ + &__key); \ +}) + +struct dma_fence_array *__dma_fence_array_create(int num_fences, + struct dma_fence **fences, + u64 context, unsigned seqno, + bool signal_on_any, + struct lock_class_key *key); bool dma_fence_match_context(struct dma_fence *fence, u64 context);