summarylogtreecommitdiffstats
path: root/0020-dma-buf-add-dma_resv_get_singleton-v2.patch
diff options
context:
space:
mode:
authorboogie2023-07-21 00:12:50 +0200
committerboogie2023-07-21 02:18:56 +0200
commit14a0a8705f127a23347fcbdfbde4dbb058b13182 (patch)
tree056405c80516964dd4941fbc062a57666775abb4 /0020-dma-buf-add-dma_resv_get_singleton-v2.patch
parenta001021fbecb1867e9b443501c783700d47f5010 (diff)
downloadaur-14a0a8705f127a23347fcbdfbde4dbb058b13182.tar.gz
update to rkr4.1 and deliver libmali together
Diffstat (limited to '0020-dma-buf-add-dma_resv_get_singleton-v2.patch')
-rw-r--r--0020-dma-buf-add-dma_resv_get_singleton-v2.patch112
1 files changed, 112 insertions, 0 deletions
diff --git a/0020-dma-buf-add-dma_resv_get_singleton-v2.patch b/0020-dma-buf-add-dma_resv_get_singleton-v2.patch
new file mode 100644
index 000000000000..4c8112892e2d
--- /dev/null
+++ b/0020-dma-buf-add-dma_resv_get_singleton-v2.patch
@@ -0,0 +1,112 @@
+From d24c7e4bc3ac3367910efd78e2aa413df224c231 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Christian=20K=C3=B6nig?= <christian.koenig@amd.com>
+Date: Wed, 3 Nov 2021 10:02:08 +0100
+Subject: [PATCH] dma-buf: add dma_resv_get_singleton v2
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Add a function to simplify getting a single fence for all the fences in
+the dma_resv object.
+
+v2: fix ref leak in error handling
+
+Signed-off-by: Christian König <christian.koenig@amd.com>
+Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+Link: https://patchwork.freedesktop.org/patch/msgid/20220321135856.1331-3-christian.koenig@amd.com
+(cherry picked from commit 92cedee6a6a3e6fcc3ffc0e3866baae5f6f76ac1)
+---
+ drivers/dma-buf/dma-resv.c | 59 ++++++++++++++++++++++++++++++++++++++
+ include/linux/dma-resv.h | 2 ++
+ 2 files changed, 61 insertions(+)
+
+diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
+index 1187e5e80eded..35cca3ca4dcfe 100644
+--- a/drivers/dma-buf/dma-resv.c
++++ b/drivers/dma-buf/dma-resv.c
+@@ -33,6 +33,7 @@
+ */
+
+ #include <linux/dma-resv.h>
++#include <linux/dma-fence-array.h>
+ #include <linux/export.h>
+ #include <linux/mm.h>
+ #include <linux/sched/mm.h>
+@@ -517,6 +518,64 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
+ }
+ EXPORT_SYMBOL_GPL(dma_resv_get_fences_rcu);
+
++/**
++ * dma_resv_get_singleton - Get a single fence for all the fences
++ * @obj: the reservation object
++ * @write: true if we should return all fences
++ * @fence: the resulting fence
++ *
++ * Get a single fence representing all the fences inside the resv object.
++ * Returns either 0 for success or -ENOMEM.
++ *
++ * Warning: This can't be used like this when adding the fence back to the resv
++ * object since that can lead to stack corruption when finalizing the
++ * dma_fence_array.
++ *
++ * Returns 0 on success and negative error values on failure.
++ */
++int dma_resv_get_singleton(struct dma_resv *obj, bool write,
++ struct dma_fence **fence)
++{
++ struct dma_fence_array *array;
++ struct dma_fence **fences;
++ unsigned count;
++ int r;
++
++ if (!write) {
++ *fence = dma_resv_get_excl_rcu(obj);
++ return 0;
++ }
++
++ r = dma_resv_get_fences_rcu(obj, NULL, &count, &fences);
++ if (r)
++ return r;
++
++ if (count == 0) {
++ *fence = NULL;
++ return 0;
++ }
++
++ if (count == 1) {
++ *fence = fences[0];
++ kfree(fences);
++ return 0;
++ }
++
++ array = dma_fence_array_create(count, fences,
++ dma_fence_context_alloc(1),
++ 1, false);
++ if (!array) {
++ while (count--)
++ dma_fence_put(fences[count]);
++ kfree(fences);
++ return -ENOMEM;
++ }
++
++ *fence = &array->base;
++ return 0;
++}
++EXPORT_SYMBOL_GPL(dma_resv_get_singleton);
++
+ /**
+ * dma_resv_wait_timeout_rcu - Wait on reservation's objects
+ * shared and/or exclusive fences.
+diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h
+index d44a77e8a7e34..171ff5e7ff885 100644
+--- a/include/linux/dma-resv.h
++++ b/include/linux/dma-resv.h
+@@ -283,6 +283,8 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
+ unsigned *pshared_count,
+ struct dma_fence ***pshared);
+
++int dma_resv_get_singleton(struct dma_resv *obj, bool write,
++ struct dma_fence **fence);
+ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src);
+
+ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, bool wait_all, bool intr,