Skip to contentSkip to conversation

staging: media: ipu3-imgu: Ensure correct binary selection

PATCH In review Sakari Ailus 2 participants 6 messages May 22 – Jun 1

Subsystems (3)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

PATCH 1/1 staging: media: ipu3-imgu: Ensure correct binary selection

The ImgU has two sets of binaries, those that support striping (fixed at
2) and those that don't. There's overlap between the stripes and so that implies a minimum width for the images themselves, or the Bayer downscale rectangle in particular.

Take this account in binary selection.

---
Hi Ricardo,

I'm not sure if this makes smatch happy but it somehow addresses the issue it found. In the end it's up to the userspace to configure this correctly...

Compile tested only.

- Sakari

 drivers/staging/media/ipu3/ipu3-css.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/staging/media/ipu3/ipu3-css.c +6 -0
index 8063401246fb..3e4e03a8fa3a 100644
@@ -1613,6 +1613,12 @@ static int imgu_css_find_binary(struct imgu_css *css,
 		    in->height > bi->info.isp.sp.input.max_height)
 			continue;
 
+		/* Check the striping overlap isn't wider than the stripe. */
+		if (bi->info.isp.sp.iterator.num_stripes > 1 &&
+		    rects[IPU3_CSS_RECT_BDS].width <
+		    4 * IPU3_UAPI_ISP_VEC_ELEMS * 2)
+			continue;
+
 		if (imgu_css_queue_enabled(&queue[IPU3_CSS_QUEUE_OUT])) {
 			if (bi->info.isp.num_output_pins <= 0)
 				continue;
Signature · 1 line
2.47.3
#1 lore raw

Hi Sakari

Quoted 8 lines · Sakari Ailus

The ImgU has two sets of binaries, those that support striping (fixed at
2) and those that don't. There's overlap between the stripes and so that implies a minimum width for the images themselves, or the Bayer downscale rectangle in particular.

Take this account in binary selection.

Quoted 7 lines

---
Hi Ricardo,

I'm not sure if this makes smatch happy but it somehow addresses the issue it found. In the end it's up to the userspace to configure this correctly...

Smatch should be calmed now:

https://gitlab.freedesktop.org/linux-media/media-committers/-/commit/c32fe4c4918c9aa49f61359e3b42619c4d8686de

But if you want to add more tests, you are of course welcome :)

Quoted 28 lines

Compile tested only.

- Sakari

 drivers/staging/media/ipu3/ipu3-css.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/staging/media/ipu3/ipu3-css.c +6 -1
index 8063401246fb..3e4e03a8fa3a 100644
@@ -1613,6 +1613,12 @@ static int imgu_css_find_binary(struct imgu_css *css,
                    in->height > bi->info.isp.sp.input.max_height)
                        continue;
 
+               /* Check the striping overlap isn't wider than the stripe. */
+               if (bi->info.isp.sp.iterator.num_stripes > 1 &&
+                   rects[IPU3_CSS_RECT_BDS].width <
+                   4 * IPU3_UAPI_ISP_VEC_ELEMS * 2)
+                       continue;
+
                if (imgu_css_queue_enabled(&queue[IPU3_CSS_QUEUE_OUT])) {
                        if (bi->info.isp.num_output_pins <= 0)
                                continue;
--

2.47.3

Signature · 1 line
Ricardo Ribalda
author maintainer
#2 lore raw

Hi Ricardo,

Quoted 17 lines · Ricardo Ribalda

Hi Sakari

Quoted 12 lines · Sakari Ailus

The ImgU has two sets of binaries, those that support striping (fixed at
2) and those that don't. There's overlap between the stripes and so that implies a minimum width for the images themselves, or the Bayer downscale rectangle in particular.

Take this account in binary selection.

---
Hi Ricardo,

Quoted 7 lines
Quoted 3 lines

I'm not sure if this makes smatch happy but it somehow addresses the issue it found. In the end it's up to the userspace to configure this correctly...

Smatch should be calmed now:

https://gitlab.freedesktop.org/linux-media/media-committers/-/commit/c32fe4c4918c9aa49f61359e3b42619c4d8686de

I dislike that because it's written simply to appease smatch and does not properly even try to address a problem. Can you try to revert it once this patch is merged? At the very least we need a comment on why that check is there.

Quoted 28 lines

But if you want to add more tests, you are of course welcome :)

Quoted 25 lines

Compile tested only.

- Sakari

 drivers/staging/media/ipu3/ipu3-css.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/staging/media/ipu3/ipu3-css.c +6 -0
index 8063401246fb..3e4e03a8fa3a 100644
@@ -1613,6 +1613,12 @@ static int imgu_css_find_binary(struct imgu_css *css,
                    in->height > bi->info.isp.sp.input.max_height)
                        continue;
 
+               /* Check the striping overlap isn't wider than the stripe. */
+               if (bi->info.isp.sp.iterator.num_stripes > 1 &&
+                   rects[IPU3_CSS_RECT_BDS].width <
+                   4 * IPU3_UAPI_ISP_VEC_ELEMS * 2)
+                       continue;
+
                if (imgu_css_queue_enabled(&queue[IPU3_CSS_QUEUE_OUT])) {
                        if (bi->info.isp.num_output_pins <= 0)
                                continue;
Signature · 3 lines
Regards,

Sakari Ailus
#3 lore raw

Hi Sakari

Quoted 25 lines · Sakari Ailus

Hi Ricardo,

Quoted 21 lines · Ricardo Ribalda

Hi Sakari

Quoted 15 lines · Sakari Ailus

The ImgU has two sets of binaries, those that support striping (fixed at
2) and those that don't. There's overlap between the stripes and so that implies a minimum width for the images themselves, or the Bayer downscale rectangle in particular.

Take this account in binary selection.

---
Hi Ricardo,

I'm not sure if this makes smatch happy but it somehow addresses the issue it found. In the end it's up to the userspace to configure this correctly...

Quoted 8 lines
Quoted 3 lines

Smatch should be calmed now:

https://gitlab.freedesktop.org/linux-media/media-committers/-/commit/c32fe4c4918c9aa49f61359e3b42619c4d8686de

I dislike that because it's written simply to appease smatch and does not properly even try to address a problem. Can you try to revert it once this patch is merged? At the very least we need a comment on why that check is there.

I think instead of reverting the patch, I think it would make more sense to do:

- if (offset > 65535)
+ if (WARN_ON(offset > 65535))

I believe it would be safer, that way if the condition changes in the caller we will catch this error earlier.

Quoted 34 lines
Quoted 20 lines

But if you want to add more tests, you are of course welcome :)

Quoted 16 lines

Compile tested only.

- Sakari

 drivers/staging/media/ipu3/ipu3-css.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/staging/media/ipu3/ipu3-css.c +0 -0
index 8063401246fb..3e4e03a8fa3a 100644
@@ -1613,6 +1613,12 @@ static int imgu_css_find_binary(struct imgu_css *css,
                    in->height > bi->info.isp.sp.input.max_height)
                        continue;
 
Quoted 9 lines

drivers/staging/media/ipu3/ipu3-css.c static int imgu_css_find_binary(struct imgu_css *css, · line 1624

Quoted 9 lines
drivers/staging/media/ipu3/ipu3-css.c +6 -0
+               /* Check the striping overlap isn't wider than the stripe. */
+               if (bi->info.isp.sp.iterator.num_stripes > 1 &&
+                   rects[IPU3_CSS_RECT_BDS].width <
+                   4 * IPU3_UAPI_ISP_VEC_ELEMS * 2)
+                       continue;
+
                if (imgu_css_queue_enabled(&queue[IPU3_CSS_QUEUE_OUT])) {
                        if (bi->info.isp.num_output_pins <= 0)
                                continue;

--
Regards,

Sakari Ailus

Signature · 1 line
Ricardo Ribalda
author maintainer
#4 lore raw

Hi Ricardo,

Quoted 37 lines · Ricardo Ribalda

Hi Sakari

Quoted 25 lines · Sakari Ailus

Hi Ricardo,

Quoted 21 lines · Ricardo Ribalda

Hi Sakari

Quoted 15 lines · Sakari Ailus

The ImgU has two sets of binaries, those that support striping (fixed at
2) and those that don't. There's overlap between the stripes and so that implies a minimum width for the images themselves, or the Bayer downscale rectangle in particular.

Take this account in binary selection.

---
Hi Ricardo,

I'm not sure if this makes smatch happy but it somehow addresses the issue it found. In the end it's up to the userspace to configure this correctly...

Quoted 8 lines
Quoted 3 lines

Smatch should be calmed now:

https://gitlab.freedesktop.org/linux-media/media-committers/-/commit/c32fe4c4918c9aa49f61359e3b42619c4d8686de

I dislike that because it's written simply to appease smatch and does not properly even try to address a problem. Can you try to revert it once this patch is merged? At the very least we need a comment on why that check is there.

Quoted 7 lines

I think instead of reverting the patch, I think it would make more sense to do:

- if (offset > 65535)
+ if (WARN_ON(offset > 65535))

I believe it would be safer, that way if the condition changes in the caller we will catch this error earlier.

Is there a need for an extra check in the code if smatch can perform it at build time?

Signature · 3 lines
Regards,

Sakari Ailus
#5 lore raw

Hi Sakari

Quoted 43 lines · Sakari Ailus

Hi Ricardo,

Quoted 39 lines · Ricardo Ribalda

Hi Sakari

Quoted 25 lines · Sakari Ailus

Hi Ricardo,

Quoted 21 lines · Ricardo Ribalda

Hi Sakari

Quoted 15 lines · Sakari Ailus

The ImgU has two sets of binaries, those that support striping (fixed at
2) and those that don't. There's overlap between the stripes and so that implies a minimum width for the images themselves, or the Bayer downscale rectangle in particular.

Take this account in binary selection.

---
Hi Ricardo,

I'm not sure if this makes smatch happy but it somehow addresses the issue it found. In the end it's up to the userspace to configure this correctly...

Quoted 8 lines
Quoted 3 lines

Smatch should be calmed now:

https://gitlab.freedesktop.org/linux-media/media-committers/-/commit/c32fe4c4918c9aa49f61359e3b42619c4d8686de

I dislike that because it's written simply to appease smatch and does not properly even try to address a problem. Can you try to revert it once this patch is merged? At the very least we need a comment on why that check is there.

I think instead of reverting the patch, I think it would make more sense to do:

Quoted 8 lines
Quoted 5 lines

- if (offset > 65535)
+ if (WARN_ON(offset > 65535))

I believe it would be safer, that way if the condition changes in the caller we will catch this error earlier.

Is there a need for an extra check in the code if smatch can perform it at build time?

There are no guarantees regarding how smatch will behave in future versions.

Also, smatch stops testing the code after some "effort", if the code is more complex it will not test it.

The only way to be sure there are no errors is with asserts.

Quoted 5 lines

--
Regards,

Sakari Ailus

Signature · 1 line
Ricardo Ribalda