* [PATCH v2] drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats
@ 2025-11-04 15:38 Thomas Zimmermann
2025-11-10 13:20 ` Thomas Zimmermann
2025-11-12 12:53 ` Philipp Zabel
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Zimmermann @ 2025-11-04 15:38 UTC (permalink / raw)
To: p.zabel, shawnguo, s.hauer, festevam, dmitry.baryshkov,
maarten.lankhorst, mripard, airlied, simona
Cc: dri-devel, imx, linux-arm-kernel, Thomas Zimmermann,
Pengutronix Kernel Team
Align pitch to multiples of 8 pixels for bpp values that do not map
to RGB formats. The call to drm_driver_color_mode_format() fails with
DRM_INVALID_FORMAT in these cases. Fall back to manually computing
the pitch alignment from which drm_mode_size_dumb() can compute the
correct pitch.
Fixes userspace that allocates dumb buffers for YUV formats, where
bpp equals 12. A common example is the IGT kms_getfb test.
v2:
- ignore width in calculation
Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Fixes: b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Cc: imx@lists.linux.dev
Cc: linux-arm-kernel@lists.infradead.org
---
This patch is based on Dmitry's fix for msm. [1] Please test.
There could later be a helper to contain these aligmentment calculations
in a single place.
[1] https://lore.kernel.org/dri-devel/20251103-drm-msm-fix-nv12-v2-1-75103b64576e@oss.qualcomm.com/
---
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
index 465b5a6ad5bb..eddb471119c6 100644
--- a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
+++ b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
@@ -144,7 +144,6 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
struct drm_mode_create_dumb *args)
{
u32 fourcc;
- const struct drm_format_info *info;
u64 pitch_align;
int ret;
@@ -156,12 +155,15 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
* the allocated buffer.
*/
fourcc = drm_driver_color_mode_format(drm, args->bpp);
- if (fourcc == DRM_FORMAT_INVALID)
- return -EINVAL;
- info = drm_format_info(fourcc);
- if (!info)
- return -EINVAL;
- pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
+ if (fourcc != DRM_FORMAT_INVALID) {
+ const struct drm_format_info *info = drm_format_info(fourcc);
+
+ if (!info)
+ return -EINVAL;
+ pitch_align = drm_format_info_min_pitch(info, 0, 8);
+ } else {
+ pitch_align = DIV_ROUND_UP(args->bpp, SZ_8) * 8;
+ }
if (!pitch_align || pitch_align > U32_MAX)
return -EINVAL;
ret = drm_mode_size_dumb(drm, args, pitch_align, 0);
--
2.51.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats
2025-11-04 15:38 [PATCH v2] drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats Thomas Zimmermann
@ 2025-11-10 13:20 ` Thomas Zimmermann
2025-11-12 12:53 ` Philipp Zabel
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Zimmermann @ 2025-11-10 13:20 UTC (permalink / raw)
To: p.zabel, shawnguo, s.hauer, festevam, dmitry.baryshkov,
maarten.lankhorst, mripard, airlied, simona
Cc: dri-devel, imx, linux-arm-kernel, Pengutronix Kernel Team
Ping! Could this patch please get a timely review from imx maintainers?
Not fixing this bug could break user space.
Am 04.11.25 um 16:38 schrieb Thomas Zimmermann:
> Align pitch to multiples of 8 pixels for bpp values that do not map
> to RGB formats. The call to drm_driver_color_mode_format() fails with
> DRM_INVALID_FORMAT in these cases. Fall back to manually computing
> the pitch alignment from which drm_mode_size_dumb() can compute the
> correct pitch.
>
> Fixes userspace that allocates dumb buffers for YUV formats, where
> bpp equals 12. A common example is the IGT kms_getfb test.
>
> v2:
> - ignore width in calculation
>
> Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Fixes: b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: imx@lists.linux.dev
> Cc: linux-arm-kernel@lists.infradead.org
> ---
> This patch is based on Dmitry's fix for msm. [1] Please test.
>
> There could later be a helper to contain these aligmentment calculations
> in a single place.
>
> [1] https://lore.kernel.org/dri-devel/20251103-drm-msm-fix-nv12-v2-1-75103b64576e@oss.qualcomm.com/
> ---
> drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
> index 465b5a6ad5bb..eddb471119c6 100644
> --- a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
> +++ b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
> @@ -144,7 +144,6 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
> struct drm_mode_create_dumb *args)
> {
> u32 fourcc;
> - const struct drm_format_info *info;
> u64 pitch_align;
> int ret;
>
> @@ -156,12 +155,15 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
> * the allocated buffer.
> */
> fourcc = drm_driver_color_mode_format(drm, args->bpp);
> - if (fourcc == DRM_FORMAT_INVALID)
> - return -EINVAL;
> - info = drm_format_info(fourcc);
> - if (!info)
> - return -EINVAL;
> - pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
> + if (fourcc != DRM_FORMAT_INVALID) {
> + const struct drm_format_info *info = drm_format_info(fourcc);
> +
> + if (!info)
> + return -EINVAL;
> + pitch_align = drm_format_info_min_pitch(info, 0, 8);
> + } else {
> + pitch_align = DIV_ROUND_UP(args->bpp, SZ_8) * 8;
> + }
> if (!pitch_align || pitch_align > U32_MAX)
> return -EINVAL;
> ret = drm_mode_size_dumb(drm, args, pitch_align, 0);
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats
2025-11-04 15:38 [PATCH v2] drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats Thomas Zimmermann
2025-11-10 13:20 ` Thomas Zimmermann
@ 2025-11-12 12:53 ` Philipp Zabel
2025-11-12 13:13 ` Thomas Zimmermann
1 sibling, 1 reply; 4+ messages in thread
From: Philipp Zabel @ 2025-11-12 12:53 UTC (permalink / raw)
To: Thomas Zimmermann, shawnguo, s.hauer, festevam, dmitry.baryshkov,
maarten.lankhorst, mripard, airlied, simona
Cc: dri-devel, imx, linux-arm-kernel, Pengutronix Kernel Team
On Di, 2025-11-04 at 16:38 +0100, Thomas Zimmermann wrote:
> Align pitch to multiples of 8 pixels for bpp values that do not map
> to RGB formats. The call to drm_driver_color_mode_format() fails with
> DRM_INVALID_FORMAT in these cases. Fall back to manually computing
> the pitch alignment from which drm_mode_size_dumb() can compute the
> correct pitch.
>
> Fixes userspace that allocates dumb buffers for YUV formats, where
> bpp equals 12. A common example is the IGT kms_getfb test.
>
> v2:
> - ignore width in calculation
>
> Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Fixes: b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: imx@lists.linux.dev
> Cc: linux-arm-kernel@lists.infradead.org
> ---
> This patch is based on Dmitry's fix for msm. [1] Please test.
Thank you,
[IGT] kms_getfb: finished subtest getfb2-accept-nv12, CRASH -> SUCCESS
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> There could later be a helper to contain these aligmentment calculations
> in a single place.
>
> [1] https://lore.kernel.org/dri-devel/20251103-drm-msm-fix-nv12-v2-1-75103b64576e@oss.qualcomm.com/
> ---
> drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
> index 465b5a6ad5bb..eddb471119c6 100644
> --- a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
> +++ b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
> @@ -144,7 +144,6 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
> struct drm_mode_create_dumb *args)
> {
> u32 fourcc;
> - const struct drm_format_info *info;
> u64 pitch_align;
> int ret;
>
> @@ -156,12 +155,15 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
> * the allocated buffer.
> */
> fourcc = drm_driver_color_mode_format(drm, args->bpp);
> - if (fourcc == DRM_FORMAT_INVALID)
> - return -EINVAL;
> - info = drm_format_info(fourcc);
> - if (!info)
> - return -EINVAL;
> - pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
> + if (fourcc != DRM_FORMAT_INVALID) {
> + const struct drm_format_info *info = drm_format_info(fourcc);
> +
> + if (!info)
> + return -EINVAL;
> + pitch_align = drm_format_info_min_pitch(info, 0, 8);
> + } else {
> + pitch_align = DIV_ROUND_UP(args->bpp, SZ_8) * 8;
> + }
> if (!pitch_align || pitch_align > U32_MAX)
> return -EINVAL;
> ret = drm_mode_size_dumb(drm, args, pitch_align, 0);
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
regards
Philipp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats
2025-11-12 12:53 ` Philipp Zabel
@ 2025-11-12 13:13 ` Thomas Zimmermann
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Zimmermann @ 2025-11-12 13:13 UTC (permalink / raw)
To: Philipp Zabel, shawnguo, s.hauer, festevam, dmitry.baryshkov,
maarten.lankhorst, mripard, airlied, simona
Cc: dri-devel, imx, linux-arm-kernel, Pengutronix Kernel Team
Hi
Am 12.11.25 um 13:53 schrieb Philipp Zabel:
> On Di, 2025-11-04 at 16:38 +0100, Thomas Zimmermann wrote:
>> Align pitch to multiples of 8 pixels for bpp values that do not map
>> to RGB formats. The call to drm_driver_color_mode_format() fails with
>> DRM_INVALID_FORMAT in these cases. Fall back to manually computing
>> the pitch alignment from which drm_mode_size_dumb() can compute the
>> correct pitch.
>>
>> Fixes userspace that allocates dumb buffers for YUV formats, where
>> bpp equals 12. A common example is the IGT kms_getfb test.
>>
>> v2:
>> - ignore width in calculation
>>
>> Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Fixes: b1d0e470f881 ("drm/imx/ipuv3: Compute dumb-buffer sizes with drm_mode_size_dumb()")
>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>> Cc: Philipp Zabel <p.zabel@pengutronix.de>
>> Cc: Shawn Guo <shawnguo@kernel.org>
>> Cc: Sascha Hauer <s.hauer@pengutronix.de>
>> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
>> Cc: Fabio Estevam <festevam@gmail.com>
>> Cc: dri-devel@lists.freedesktop.org
>> Cc: imx@lists.linux.dev
>> Cc: linux-arm-kernel@lists.infradead.org
>> ---
>> This patch is based on Dmitry's fix for msm. [1] Please test.
> Thank you,
>
> [IGT] kms_getfb: finished subtest getfb2-accept-nv12, CRASH -> SUCCESS
>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
>
>> There could later be a helper to contain these aligmentment calculations
>> in a single place.
>>
>> [1] https://lore.kernel.org/dri-devel/20251103-drm-msm-fix-nv12-v2-1-75103b64576e@oss.qualcomm.com/
>> ---
>> drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 16 +++++++++-------
>> 1 file changed, 9 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
>> index 465b5a6ad5bb..eddb471119c6 100644
>> --- a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
>> +++ b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c
>> @@ -144,7 +144,6 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
>> struct drm_mode_create_dumb *args)
>> {
>> u32 fourcc;
>> - const struct drm_format_info *info;
>> u64 pitch_align;
>> int ret;
>>
>> @@ -156,12 +155,15 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,
>> * the allocated buffer.
>> */
>> fourcc = drm_driver_color_mode_format(drm, args->bpp);
>> - if (fourcc == DRM_FORMAT_INVALID)
>> - return -EINVAL;
>> - info = drm_format_info(fourcc);
>> - if (!info)
>> - return -EINVAL;
>> - pitch_align = drm_format_info_min_pitch(info, 0, SZ_8);
>> + if (fourcc != DRM_FORMAT_INVALID) {
>> + const struct drm_format_info *info = drm_format_info(fourcc);
>> +
>> + if (!info)
>> + return -EINVAL;
>> + pitch_align = drm_format_info_min_pitch(info, 0, 8);
>> + } else {
>> + pitch_align = DIV_ROUND_UP(args->bpp, SZ_8) * 8;
>> + }
>> if (!pitch_align || pitch_align > U32_MAX)
>> return -EINVAL;
>> ret = drm_mode_size_dumb(drm, args, pitch_align, 0);
> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Thanks a lot. I'll land this fix ASAP.
Best regards
Thomas
>
> regards
> Philipp
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-12 13:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 15:38 [PATCH v2] drm/imx/ipuv3: Fix dumb-buffer allocation for non-RGB formats Thomas Zimmermann
2025-11-10 13:20 ` Thomas Zimmermann
2025-11-12 12:53 ` Philipp Zabel
2025-11-12 13:13 ` Thomas Zimmermann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox