[PATCH 4/4] dma-buf: Add callback and enable signaling on debug

Arvind Yadav
2022-09-05T10:58:48Z

Here's on debug adding an enable_signaling callback for fences
and enabling software signaling for selftest.

Signed-off-by: Arvind Yadav <Arvind.Yadav@amd.com>
---
drivers/dma-buf/st-dma-fence-chain.c | 17 +++++++++
drivers/dma-buf/st-dma-fence-unwrap.c | 54 +++++++++++++++++++++++++++
drivers/dma-buf/st-dma-fence.c | 34 ++++++++++++++++-
drivers/dma-buf/st-dma-resv.c | 30 +++++++++++++++
4 files changed, 134 insertions(+), 1 deletion(-)

diff --git a/drivers/dma-buf/st-dma-fence-chain.c b/drivers/dma-buf/st-dma-fence-chain.c
index 8ce1ea59d31b..ffbb24d6a890 100644
--- a/drivers/dma-buf/st-dma-fence-chain.c
+++ b/drivers/dma-buf/st-dma-fence-chain.c
@@ -32,6 +32,12 @@ static const char *mock_name(struct dma_fence *f)
{
return "mock";
}
+#ifdef CONFIG_DEBUG_FS
+static bool mock_fence_enable_signaling(struct dma_fence *f)
+{
+ return true;
+}
+#endif

static void mock_fence_release(struct dma_fence *f)
{
@@ -41,6 +47,9 @@ static void mock_fence_release(struct dma_fence *f)
static const struct dma_fence_ops mock_ops = {
.get_driver_name = mock_name,
.get_timeline_name = mock_name,
+#ifdef CONFIG_DEBUG_FS
+ .enable_signaling = mock_fence_enable_signaling,
+#endif
.release = mock_fence_release,
};

@@ -87,6 +96,10 @@ static int sanitycheck(void *arg)
if (!chain)
err = -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(chain);
+#endif
+
dma_fence_signal(f);
dma_fence_put(f);

@@ -143,6 +156,10 @@ static int fence_chains_init(struct fence_chains *fc, unsigned int count,
}

fc->tail = fc->chains[i];
+
+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(fc->chains[i]);
+#endif
}

fc->chain_length = i;
diff --git a/drivers/dma-buf/st-dma-fence-unwrap.c b/drivers/dma-buf/st-dma-fence-unwrap.c
index 4105d5ea8dde..b43c57559ead 100644
--- a/drivers/dma-buf/st-dma-fence-unwrap.c
+++ b/drivers/dma-buf/st-dma-fence-unwrap.c
@@ -23,9 +23,19 @@ static const char *mock_name(struct dma_fence *f)
return "mock";
}

+#ifdef CONFIG_DEBUG_FS
+static bool mock_fence_enable_signaling(struct dma_fence *f)
+{
+ return true;
+}
+#endif
+
static const struct dma_fence_ops mock_ops = {
.get_driver_name = mock_name,
.get_timeline_name = mock_name,
+#ifdef CONFIG_DEBUG_FS
+ .enable_signaling = mock_fence_enable_signaling,
+#endif
};

static struct dma_fence *mock_fence(void)
@@ -102,6 +112,10 @@ static int sanitycheck(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
+
array = mock_array(1, f);
if (!array)
return -ENOMEM;
@@ -124,12 +138,20 @@ static int unwrap_array(void *arg)
if (!f1)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f1);
+#endif
+
f2 = mock_fence();
if (!f2) {
dma_fence_put(f1);
return -ENOMEM;
}

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f2);
+#endif
+
array = mock_array(2, f1, f2);
if (!array)
return -ENOMEM;
@@ -164,12 +186,20 @@ static int unwrap_chain(void *arg)
if (!f1)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f1);
+#endif
+
f2 = mock_fence();
if (!f2) {
dma_fence_put(f1);
return -ENOMEM;
}

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f2);
+#endif
+
chain = mock_chain(f1, f2);
if (!chain)
return -ENOMEM;
@@ -204,12 +234,20 @@ static int unwrap_chain_array(void *arg)
if (!f1)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f1);
+#endif
+
f2 = mock_fence();
if (!f2) {
dma_fence_put(f1);
return -ENOMEM;
}

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f2);
+#endif
+
array = mock_array(2, f1, f2);
if (!array)
return -ENOMEM;
@@ -248,12 +286,20 @@ static int unwrap_merge(void *arg)
if (!f1)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f1);
+#endif
+
f2 = mock_fence();
if (!f2) {
err = -ENOMEM;
goto error_put_f1;
}

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f2);
+#endif
+
f3 = dma_fence_unwrap_merge(f1, f2);
if (!f3) {
err = -ENOMEM;
@@ -296,10 +342,18 @@ static int unwrap_merge_complex(void *arg)
if (!f1)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f1);
+#endif
+
f2 = mock_fence();
if (!f2)
goto error_put_f1;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f2);
+#endif
+
f3 = dma_fence_unwrap_merge(f1, f2);
if (!f3)
goto error_put_f2;
diff --git a/drivers/dma-buf/st-dma-fence.c b/drivers/dma-buf/st-dma-fence.c
index c8a12d7ad71a..4adb763f4509 100644
--- a/drivers/dma-buf/st-dma-fence.c
+++ b/drivers/dma-buf/st-dma-fence.c
@@ -27,6 +27,12 @@ static const char *mock_name(struct dma_fence *f)
{
return "mock";
}
+#ifdef CONFIG_DEBUG_FS
+static bool mock_fence_enable_signaling(struct dma_fence *f)
+{
+ return true;
+}
+#endif

static void mock_fence_release(struct dma_fence *f)
{
@@ -77,6 +83,9 @@ static const struct dma_fence_ops mock_ops = {
.get_driver_name = mock_name,
.get_timeline_name = mock_name,
.wait = mock_wait,
+#ifdef CONFIG_DEBUG_FS
+ .enable_signaling = mock_fence_enable_signaling,
+#endif
.release = mock_fence_release,
};

@@ -101,7 +110,9 @@ static int sanitycheck(void *arg)
f = mock_fence();
if (!f)
return -ENOMEM;
-
+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
dma_fence_signal(f);
dma_fence_put(f);

@@ -117,6 +128,9 @@ static int test_signaling(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
if (dma_fence_is_signaled(f)) {
pr_err("Fence unexpectedly signaled on creation\n");
goto err_free;
@@ -190,6 +204,9 @@ static int test_late_add_callback(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
dma_fence_signal(f);

if (!dma_fence_add_callback(f, &cb.cb, simple_callback)) {
@@ -282,6 +299,9 @@ static int test_status(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
if (dma_fence_get_status(f)) {
pr_err("Fence unexpectedly has signaled status on creation\n");
goto err_free;
@@ -308,6 +328,9 @@ static int test_error(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
dma_fence_set_error(f, -EIO);

if (dma_fence_get_status(f)) {
@@ -337,6 +360,9 @@ static int test_wait(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
if (dma_fence_wait_timeout(f, false, 0) != -ETIME) {
pr_err("Wait reported complete before being signaled\n");
goto err_free;
@@ -379,6 +405,9 @@ static int test_wait_timeout(void *arg)
if (!wt.f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(wt.f);
+#endif
if (dma_fence_wait_timeout(wt.f, false, 1) != -ETIME) {
pr_err("Wait reported complete before being signaled\n");
goto err_free;
@@ -458,6 +487,9 @@ static int thread_signal_callback(void *arg)
break;
}

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f1);
+#endif
rcu_assign_pointer(t->fences[t->id], f1);
smp_wmb();

diff --git a/drivers/dma-buf/st-dma-resv.c b/drivers/dma-buf/st-dma-resv.c
index 813779e3c9be..fa4e7b09d54c 100644
--- a/drivers/dma-buf/st-dma-resv.c
+++ b/drivers/dma-buf/st-dma-resv.c
@@ -18,9 +18,19 @@ static const char *fence_name(struct dma_fence *f)
return "selftest";
}

+#ifdef CONFIG_DEBUG_FS
+static bool fence_enable_signaling(struct dma_fence *f)
+{
+ return true;
+}
+#endif
+
static const struct dma_fence_ops fence_ops = {
.get_driver_name = fence_name,
.get_timeline_name = fence_name,
+#ifdef CONFIG_DEBUG_FS
+ .enable_signaling = fence_enable_signaling,
+#endif
};

static struct dma_fence *alloc_fence(void)
@@ -45,6 +55,10 @@ static int sanitycheck(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
+
dma_fence_signal(f);
dma_fence_put(f);

@@ -69,6 +83,10 @@ static int test_signaling(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
+
dma_resv_init(&resv);
r = dma_resv_lock(&resv, NULL);
if (r) {
@@ -114,6 +132,10 @@ static int test_for_each(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
+
dma_resv_init(&resv);
r = dma_resv_lock(&resv, NULL);
if (r) {
@@ -173,6 +195,10 @@ static int test_for_each_unlocked(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
+
dma_resv_init(&resv);
r = dma_resv_lock(&resv, NULL);
if (r) {
@@ -244,6 +270,10 @@ static int test_get_fences(void *arg)
if (!f)
return -ENOMEM;

+#ifdef CONFIG_DEBUG_FS
+ dma_fence_enable_sw_signaling(f);
+#endif
+
dma_resv_init(&resv);
r = dma_resv_lock(&resv, NULL);
if (r) {
--
2.25.1