Skip to contentSkip to conversation

media: mali-c55: Serialise the ISP enable in the params and stats paths

PATCH In review David Carlier 2 participants 2 messages Nov 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: mali-c55: Serialise the ISP enable in the params and stats paths

Only the capture devices hold isp->capture_lock around the mali_c55_pipeline_ready() check and the ISP enable or disable. When the last two queues to start are on different video devices, both can see a ready pipeline and both enable the ISP. The second call fails with -EALREADY and its queue's start_streaming_called flag is cleared, so the ISP is never disabled again and every later start fails.

Take capture_lock in the params and stats paths too, and assert that it is held in mali_c55_pipeline_ready().

Fixes d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")

---
v2:
- Add lockdep_assert_held() in mali_c55_pipeline_ready() (Jacopo)
- Collect Linus's Reviewed-by

 drivers/media/platform/arm/mali-c55/mali-c55-core.c   | 3 +++
 drivers/media/platform/arm/mali-c55/mali-c55-params.c | 4 ++++
 drivers/media/platform/arm/mali-c55/mali-c55-stats.c  | 4 ++++
 3 files changed, 11 insertions(+)
drivers/media/platform/arm/mali-c55/mali-c55-core.c +3 -0
index 241a625f7284..bf80935c20d2 100644
@@ -13,6 +13,7 @@
 #include <linux/interrupt.h>
 #include <linux/iopoll.h>
 #include <linux/ioport.h>
+#include <linux/lockdep.h>
 #include <linux/of.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
@@ -510,6 +511,8 @@ bool mali_c55_pipeline_ready(struct mali_c55 *mali_c55)
 	struct mali_c55_params *params = &mali_c55->params;
 	struct mali_c55_stats *stats = &mali_c55->stats;
 
+	lockdep_assert_held(&mali_c55->isp.capture_lock);
+
 	/* Only wait for queues connected through enabled media links. */
 	return (!media_pad_remote_pad_first(&fr->pad) ||
 		vb2_start_streaming_called(&fr->queue)) &&
drivers/media/platform/arm/mali-c55/mali-c55-params.c +4 -0
index 16e895e3488e..6515c78c1bb2 100644
@@ -762,6 +762,8 @@ static int mali_c55_params_start_streaming(struct vb2_queue *q,
 	struct mali_c55 *mali_c55 = params->mali_c55;
 	int ret;
 
+	guard(mutex)(&mali_c55->isp.capture_lock);
+
 	ret = pm_runtime_resume_and_get(mali_c55->dev);
 	if (ret)
 		goto err_return_buffers;
@@ -796,6 +798,8 @@ static void mali_c55_params_stop_streaming(struct vb2_queue *q)
 	struct mali_c55 *mali_c55 = params->mali_c55;
 	struct mali_c55_isp *isp = &mali_c55->isp;
 
+	guard(mutex)(&isp->capture_lock);
+
 	if (mali_c55_pipeline_ready(mali_c55)) {
 		if (v4l2_subdev_is_streaming(&isp->sd))
 			v4l2_subdev_disable_streams(&isp->sd,
drivers/media/platform/arm/mali-c55/mali-c55-stats.c +4 -0
index a9c28b090b2a..cbd2a2f77da3 100644
@@ -146,6 +146,8 @@ static int mali_c55_stats_start_streaming(struct vb2_queue *q,
 	struct mali_c55 *mali_c55 = stats->mali_c55;
 	int ret;
 
+	guard(mutex)(&mali_c55->isp.capture_lock);
+
 	ret = pm_runtime_resume_and_get(mali_c55->dev);
 	if (ret)
 		goto err_return_buffers;
@@ -180,6 +182,8 @@ static void mali_c55_stats_stop_streaming(struct vb2_queue *q)
 	struct mali_c55 *mali_c55 = stats->mali_c55;
 	struct mali_c55_isp *isp = &mali_c55->isp;
 
+	guard(mutex)(&isp->capture_lock);
+
 	if (mali_c55_pipeline_ready(mali_c55)) {
 		if (v4l2_subdev_is_streaming(&isp->sd))
 			v4l2_subdev_disable_streams(&isp->sd,
Signature · 1 line
2.55.0
maintainer Tested-by Reviewed-by on v2 1/1
#1 lore raw

Hi David

Quoted 10 lines · David Carlier

Only the capture devices hold isp->capture_lock around the mali_c55_pipeline_ready() check and the ISP enable or disable. When the last two queues to start are on different video devices, both can see a ready pipeline and both enable the ISP. The second call fails with -EALREADY and its queue's start_streaming_called flag is cleared, so the ISP is never disabled again and every later start fails.

Take capture_lock in the params and stats paths too, and assert that it is held in mali_c55_pipeline_ready().

Quoted 7 lines
Fixes d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")

---
v2:
- Add lockdep_assert_held() in mali_c55_pipeline_ready() (Jacopo)

Thanks, if I

drivers/media/platform/arm/mali-c55/mali-c55-params.c +0 -1
@@ -894,7 +894,6 @@ static int mali_c55_params_start_streaming(struct vb2_queue *q,
        struct mali_c55 *mali_c55 = params->mali_c55;
        int ret;
 
-       guard(mutex)(&mali_c55->isp.capture_lock);
 
        ret = pm_runtime_resume_and_get(mali_c55->dev);
        if (ret)

Then I get the expected splat

# cam -c2 -C
  40.154659] ------------[ cut here ]------------
[   40.159731] WARNING: drivers/media/platform/arm/mali-c55/mali-c55-core.c:521 at mali_c55_pipeline_ready+0xb4/0xf4, CPU#0: CameraManager/360

I'll queue this for the v7.5 PR (which I shall send out by Friday if possible)

Quoted 74 lines

- Collect Linus's Reviewed-by

 drivers/media/platform/arm/mali-c55/mali-c55-core.c   | 3 +++
 drivers/media/platform/arm/mali-c55/mali-c55-params.c | 4 ++++
 drivers/media/platform/arm/mali-c55/mali-c55-stats.c  | 4 ++++
 3 files changed, 11 insertions(+)
drivers/media/platform/arm/mali-c55/mali-c55-core.c +3 -0
index 241a625f7284..bf80935c20d2 100644
@@ -13,6 +13,7 @@
 #include <linux/interrupt.h>
 #include <linux/iopoll.h>
 #include <linux/ioport.h>
+#include <linux/lockdep.h>
 #include <linux/of.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
@@ -510,6 +511,8 @@ bool mali_c55_pipeline_ready(struct mali_c55 *mali_c55)
 	struct mali_c55_params *params = &mali_c55->params;
 	struct mali_c55_stats *stats = &mali_c55->stats;
 
+	lockdep_assert_held(&mali_c55->isp.capture_lock);
+
 	/* Only wait for queues connected through enabled media links. */
 	return (!media_pad_remote_pad_first(&fr->pad) ||
 		vb2_start_streaming_called(&fr->queue)) &&
drivers/media/platform/arm/mali-c55/mali-c55-params.c +4 -0
index 16e895e3488e..6515c78c1bb2 100644
@@ -762,6 +762,8 @@ static int mali_c55_params_start_streaming(struct vb2_queue *q,
 	struct mali_c55 *mali_c55 = params->mali_c55;
 	int ret;
 
+	guard(mutex)(&mali_c55->isp.capture_lock);
+
 	ret = pm_runtime_resume_and_get(mali_c55->dev);
 	if (ret)
 		goto err_return_buffers;
@@ -796,6 +798,8 @@ static void mali_c55_params_stop_streaming(struct vb2_queue *q)
 	struct mali_c55 *mali_c55 = params->mali_c55;
 	struct mali_c55_isp *isp = &mali_c55->isp;
 
+	guard(mutex)(&isp->capture_lock);
+
 	if (mali_c55_pipeline_ready(mali_c55)) {
 		if (v4l2_subdev_is_streaming(&isp->sd))
 			v4l2_subdev_disable_streams(&isp->sd,
drivers/media/platform/arm/mali-c55/mali-c55-stats.c +4 -1
index a9c28b090b2a..cbd2a2f77da3 100644
@@ -146,6 +146,8 @@ static int mali_c55_stats_start_streaming(struct vb2_queue *q,
 	struct mali_c55 *mali_c55 = stats->mali_c55;
 	int ret;
 
+	guard(mutex)(&mali_c55->isp.capture_lock);
+
 	ret = pm_runtime_resume_and_get(mali_c55->dev);
 	if (ret)
 		goto err_return_buffers;
@@ -180,6 +182,8 @@ static void mali_c55_stats_stop_streaming(struct vb2_queue *q)
 	struct mali_c55 *mali_c55 = stats->mali_c55;
 	struct mali_c55_isp *isp = &mali_c55->isp;
 
+	guard(mutex)(&isp->capture_lock);
+
 	if (mali_c55_pipeline_ready(mali_c55)) {
 		if (v4l2_subdev_is_streaming(&isp->sd))
 			v4l2_subdev_disable_streams(&isp->sd,
--

2.55.0