diff mbox series

dma-buf: make dma_fence structure a bit smaller

Message ID 20190807135405.2036-1-christian.koenig@amd.com (mailing list archive)
State New, archived
Headers show
Series dma-buf: make dma_fence structure a bit smaller | expand

Commit Message

Christian König Aug. 7, 2019, 1:54 p.m. UTC
The ruc and cb_list are never used at the same time.
This smal change is actually making the structure 16% smaller.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 include/linux/dma-fence.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Chris Wilson Aug. 7, 2019, 2:01 p.m. UTC | #1
Quoting Christian König (2019-08-07 14:54:05)
> The ruc and cb_list are never used at the same time.
> This smal change is actually making the structure 16% smaller.
(Trivial pair of typos)

Yes. We clear the callback list on kref_put so that by the time we
release the fence it is unused. No one should be adding to the cb_list
that they don't themselves hold a reference for, this only now makes for
a much more spectacular use-after-free. :)

> Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Daniel Vetter Aug. 7, 2019, 9:11 p.m. UTC | #2
On Wed, Aug 07, 2019 at 03:01:59PM +0100, Chris Wilson wrote:
> Quoting Christian König (2019-08-07 14:54:05)
> > The ruc and cb_list are never used at the same time.
> > This smal change is actually making the structure 16% smaller.
> (Trivial pair of typos)
> 
> Yes. We clear the callback list on kref_put so that by the time we
> release the fence it is unused. No one should be adding to the cb_list
> that they don't themselves hold a reference for, this only now makes for
> a much more spectacular use-after-free. :)

^^ stuff the above as an inline kerneldoc comment into the patch? And into
the commit message too pls. We need better docs for all this scorcery :-)

Thanks, Daniel

> 
> > Signed-off-by: Christian König <christian.koenig@amd.com>
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> -Chris
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox series

Patch

diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 05d29dbc7e62..3985c72cd0c2 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -65,8 +65,10 @@  struct dma_fence_cb;
 struct dma_fence {
 	struct kref refcount;
 	const struct dma_fence_ops *ops;
-	struct rcu_head rcu;
-	struct list_head cb_list;
+	union {
+		struct rcu_head rcu;
+		struct list_head cb_list;
+	};
 	spinlock_t *lock;
 	u64 context;
 	u64 seqno;