From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com> To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org, "Thomas Hellström" <thomas.hellstrom@linux.intel.com>, matthew.auld@intel.com, "Christian König" <christian.koenig@amd.com> Subject: [RFC PATCH 2/2] dma-fence: Avoid excessive recursive fence locking from enable_signaling() callbacks Date: Tue, 30 Nov 2021 13:19:36 +0100 [thread overview] Message-ID: <20211130121936.586031-3-thomas.hellstrom@linux.intel.com> (raw) In-Reply-To: <20211130121936.586031-1-thomas.hellstrom@linux.intel.com> Some dma-fence containers lock other fence's locks from their enable_signaling() callbacks. We allow one level of nesting from the dma_fence_add_callback_nested() function, but we would also like to allow for example dma_fence_chain to point to a dma_fence_array and vice versa, even though that would create additional levels of nesting. To do that we need to break longer recursive chains of fence locking and we can do that either by deferring dma_fence_add_callback_nested() to a worker for affected fences or to call enable_signaling() early on affected fences. Opt for the latter, and define a DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT for fence classes that takes fence locks recursively from within their enable_signaling() callback. Note that a user could of course also call enable_signaling() manually on these fences before publishing them, but this solution attempts to do that only when necessary. Cc: Christian König <christian.koenig@amd.com> Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> --- drivers/dma-buf/dma-fence-array.c | 12 +++++++++++- drivers/dma-buf/dma-fence-chain.c | 9 +++++++++ include/linux/dma-fence.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index 0322b92909fe..63ae9909bcfa 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -178,8 +178,18 @@ struct dma_fence_array *dma_fence_array_create(int num_fences, fence->error = PENDING_ERROR; - if (signal_on_any) + set_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &fence->flags); + + if (signal_on_any) { dma_fence_enable_sw_signaling(fence); + } else { + int i; + + for (i = 0; i < num_fences; i++, fences++) + if (test_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, + &(*fences)->flags)) + dma_fence_enable_sw_signaling(*fences); + } return array; } diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index 0518e53880f6..b4012dbef0c9 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -255,5 +255,14 @@ void dma_fence_chain_init(struct dma_fence_chain *chain, dma_fence_init(&chain->base, &dma_fence_chain_ops, &chain->lock, context, seqno); + + set_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &chain->base.flags); + if (test_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &fence->flags)) { + /* + * Disable further calls into @fence's enable_signaling + * To prohibit further recursive locking + */ + dma_fence_enable_sw_signaling(fence); + } } EXPORT_SYMBOL(dma_fence_chain_init); diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 405cd83936f6..48bf5e14636e 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -99,6 +99,7 @@ enum dma_fence_flag_bits { DMA_FENCE_FLAG_SIGNALED_BIT, DMA_FENCE_FLAG_TIMESTAMP_BIT, DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, + DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, DMA_FENCE_FLAG_USER_BITS, /* must always be last member */ }; -- 2.31.1
WARNING: multiple messages have this Message-ID (diff)
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com> To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org, "Thomas Hellström" <thomas.hellstrom@linux.intel.com>, matthew.auld@intel.com, "Christian König" <christian.koenig@amd.com> Subject: [Intel-gfx] [RFC PATCH 2/2] dma-fence: Avoid excessive recursive fence locking from enable_signaling() callbacks Date: Tue, 30 Nov 2021 13:19:36 +0100 [thread overview] Message-ID: <20211130121936.586031-3-thomas.hellstrom@linux.intel.com> (raw) In-Reply-To: <20211130121936.586031-1-thomas.hellstrom@linux.intel.com> Some dma-fence containers lock other fence's locks from their enable_signaling() callbacks. We allow one level of nesting from the dma_fence_add_callback_nested() function, but we would also like to allow for example dma_fence_chain to point to a dma_fence_array and vice versa, even though that would create additional levels of nesting. To do that we need to break longer recursive chains of fence locking and we can do that either by deferring dma_fence_add_callback_nested() to a worker for affected fences or to call enable_signaling() early on affected fences. Opt for the latter, and define a DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT for fence classes that takes fence locks recursively from within their enable_signaling() callback. Note that a user could of course also call enable_signaling() manually on these fences before publishing them, but this solution attempts to do that only when necessary. Cc: Christian König <christian.koenig@amd.com> Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> --- drivers/dma-buf/dma-fence-array.c | 12 +++++++++++- drivers/dma-buf/dma-fence-chain.c | 9 +++++++++ include/linux/dma-fence.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index 0322b92909fe..63ae9909bcfa 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -178,8 +178,18 @@ struct dma_fence_array *dma_fence_array_create(int num_fences, fence->error = PENDING_ERROR; - if (signal_on_any) + set_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &fence->flags); + + if (signal_on_any) { dma_fence_enable_sw_signaling(fence); + } else { + int i; + + for (i = 0; i < num_fences; i++, fences++) + if (test_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, + &(*fences)->flags)) + dma_fence_enable_sw_signaling(*fences); + } return array; } diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index 0518e53880f6..b4012dbef0c9 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -255,5 +255,14 @@ void dma_fence_chain_init(struct dma_fence_chain *chain, dma_fence_init(&chain->base, &dma_fence_chain_ops, &chain->lock, context, seqno); + + set_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &chain->base.flags); + if (test_bit(DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, &fence->flags)) { + /* + * Disable further calls into @fence's enable_signaling + * To prohibit further recursive locking + */ + dma_fence_enable_sw_signaling(fence); + } } EXPORT_SYMBOL(dma_fence_chain_init); diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 405cd83936f6..48bf5e14636e 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -99,6 +99,7 @@ enum dma_fence_flag_bits { DMA_FENCE_FLAG_SIGNALED_BIT, DMA_FENCE_FLAG_TIMESTAMP_BIT, DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, + DMA_FENCE_FLAG_LOCK_RECURSIVE_BIT, DMA_FENCE_FLAG_USER_BITS, /* must always be last member */ }; -- 2.31.1
next prev parent reply other threads:[~2021-11-30 12:20 UTC|newest] Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-30 12:19 [RFC PATCH 0/2] Attempt to avoid dma-fence-[chain|array] lockdep splats Thomas Hellström 2021-11-30 12:19 ` [Intel-gfx] " Thomas Hellström 2021-11-30 12:19 ` [RFC PATCH 1/2] dma-fence: Avoid establishing a locking order between fence classes Thomas Hellström 2021-11-30 12:19 ` [Intel-gfx] " Thomas Hellström 2021-11-30 12:25 ` Maarten Lankhorst 2021-11-30 12:25 ` [Intel-gfx] " Maarten Lankhorst 2021-11-30 12:31 ` Thomas Hellström 2021-11-30 12:31 ` [Intel-gfx] " Thomas Hellström 2021-11-30 12:42 ` Christian König 2021-11-30 12:42 ` [Intel-gfx] " Christian König 2021-11-30 12:56 ` Thomas Hellström 2021-11-30 12:56 ` [Intel-gfx] " Thomas Hellström 2021-11-30 13:26 ` Christian König 2021-11-30 13:26 ` [Intel-gfx] " Christian König 2021-11-30 14:35 ` Thomas Hellström 2021-11-30 14:35 ` [Intel-gfx] " Thomas Hellström 2021-11-30 15:02 ` Christian König 2021-11-30 15:02 ` [Intel-gfx] " Christian König 2021-11-30 18:12 ` Thomas Hellström 2021-11-30 18:12 ` Thomas Hellström 2021-11-30 19:27 ` Thomas Hellström 2021-11-30 19:27 ` [Intel-gfx] " Thomas Hellström 2021-12-01 7:05 ` Christian König 2021-12-01 7:05 ` [Intel-gfx] " Christian König 2021-12-01 8:23 ` [Linaro-mm-sig] " Thomas Hellström (Intel) 2021-12-01 8:23 ` [Intel-gfx] " Thomas Hellström (Intel) 2021-12-01 8:36 ` Christian König 2021-12-01 8:36 ` [Intel-gfx] " Christian König 2021-12-01 10:15 ` Thomas Hellström (Intel) 2021-12-01 10:15 ` [Intel-gfx] " Thomas Hellström (Intel) 2021-12-01 10:32 ` Christian König 2021-12-01 10:32 ` [Intel-gfx] " Christian König 2021-12-01 11:04 ` Thomas Hellström (Intel) 2021-12-01 11:04 ` [Intel-gfx] " Thomas Hellström (Intel) 2021-12-01 11:25 ` Christian König 2021-12-01 11:25 ` [Intel-gfx] " Christian König 2021-12-01 12:16 ` Thomas Hellström (Intel) 2021-12-01 12:16 ` Thomas Hellström (Intel) 2021-12-03 13:08 ` Christian König 2021-12-03 13:08 ` [Intel-gfx] " Christian König 2021-12-03 14:18 ` Thomas Hellström 2021-12-03 14:18 ` [Intel-gfx] " Thomas Hellström 2021-12-03 14:26 ` Christian König 2021-12-03 14:26 ` [Intel-gfx] " Christian König 2021-12-03 14:50 ` Thomas Hellström 2021-12-03 14:50 ` [Intel-gfx] " Thomas Hellström 2021-12-03 15:00 ` Christian König 2021-12-03 15:00 ` [Intel-gfx] " Christian König 2021-12-03 15:13 ` Thomas Hellström (Intel) 2021-12-03 15:13 ` [Intel-gfx] " Thomas Hellström (Intel) 2021-12-07 18:08 ` Daniel Vetter 2021-12-07 18:08 ` Daniel Vetter 2021-12-07 20:46 ` Thomas Hellström 2021-12-07 20:46 ` Thomas Hellström 2021-12-20 9:37 ` Daniel Vetter 2021-12-20 9:37 ` Daniel Vetter 2021-11-30 12:32 ` Thomas Hellström 2021-11-30 12:32 ` [Intel-gfx] " Thomas Hellström 2021-11-30 12:19 ` Thomas Hellström [this message] 2021-11-30 12:19 ` [Intel-gfx] [RFC PATCH 2/2] dma-fence: Avoid excessive recursive fence locking from enable_signaling() callbacks Thomas Hellström 2021-11-30 12:36 ` [RFC PATCH 0/2] Attempt to avoid dma-fence-[chain|array] lockdep splats Christian König 2021-11-30 12:36 ` [Intel-gfx] " Christian König 2021-11-30 13:05 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for " Patchwork 2021-11-30 13:48 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork 2021-11-30 17:47 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211130121936.586031-3-thomas.hellstrom@linux.intel.com \ --to=thomas.hellstrom@linux.intel.com \ --cc=christian.koenig@amd.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=intel-gfx@lists.freedesktop.org \ --cc=linaro-mm-sig@lists.linaro.org \ --cc=matthew.auld@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.