* [PATCH v2 0/3] Check for valid framebuffer's format
@ 2023-01-13 11:27 Maíra Canal
2023-01-13 11:27 ` [PATCH v2 1/3] drm/framebuffer: Check for valid formats Maíra Canal
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Maíra Canal @ 2023-01-13 11:27 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Daniel Vetter, Rob Clark, Simon Ser, Alex Deucher,
Christian König, Zack Rusin
Cc: André Almeida, Maíra Canal, amd-gfx, Melissa Wen,
VMware Graphics Reviewers, dri-devel
This series is a follow-up of the [1] in which I introduced a check for valid
formats on drm_gem_fb_create(). During the discussion, I realized that would be
a better idea to put the check inside framebuffer_check() so that it wouldn't be
needed to hit any driver-specific code path when the check fails.
Therefore, add the valid format check inside framebuffer_check() and remove the
same check from the drivers, except from i915, because this doesn't work for the
legacy tiling->modifier path. Adding the check to framebuffer_check() will
guarantee that the igt@kms_addfb_basic@addfb25-bad-modifier IGT test passes,
showing the correct behavior of the check.
This patchset was tested on amdgpu and vc4 with the IGT tests.
[1] https://lore.kernel.org/dri-devel/20230103125322.855089-1-mcanal@igalia.com/T/
---
v1 -> v2: https://lore.kernel.org/dri-devel/20230109105807.18172-1-mcanal@igalia.com/T/
- Don't remove check from i915 driver (Ville Syrjälä)
- Don't unexport drm_any_plane_has_format().
---
Best Regards,
- Maíra Canal
Maíra Canal (3):
drm/framebuffer: Check for valid formats
drm/amdgpu: Remove redundant framebuffer format check
drm/vmwgfx: Remove redundant framebuffer format check
Documentation/gpu/todo.rst | 9 ++++-----
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 10 ----------
drivers/gpu/drm/drm_framebuffer.c | 8 ++++++++
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 18 ------------------
4 files changed, 12 insertions(+), 33 deletions(-)
--
2.39.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] drm/framebuffer: Check for valid formats
2023-01-13 11:27 [PATCH v2 0/3] Check for valid framebuffer's format Maíra Canal
@ 2023-01-13 11:27 ` Maíra Canal
2023-01-13 13:06 ` Ville Syrjälä
2023-01-13 11:27 ` [PATCH v2 2/3] drm/amdgpu: Remove redundant framebuffer format check Maíra Canal
2023-01-13 11:27 ` [PATCH v2 3/3] drm/vmwgfx: " Maíra Canal
2 siblings, 1 reply; 6+ messages in thread
From: Maíra Canal @ 2023-01-13 11:27 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Daniel Vetter, Rob Clark, Simon Ser, Alex Deucher,
Christian König, Zack Rusin
Cc: André Almeida, Daniel Vetter, Maíra Canal, amd-gfx,
Melissa Wen, VMware Graphics Reviewers, dri-devel
Currently, framebuffer_check() doesn't check if the pixel format is
supported, which can lead to the acceptance of invalid pixel formats
e.g. the acceptance of invalid modifiers. Therefore, add a check for
valid formats on framebuffer_check(), so that the ADDFB2 IOCTL rejects
calls with invalid formats.
Moreover, note that this check is only valid for atomic drivers,
because, for non-atomic drivers, checking drm_any_plane_has_format() is
not possible since the format list for the primary plane is fake, and
we'd therefore reject valid formats.
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
Documentation/gpu/todo.rst | 9 ++++-----
drivers/gpu/drm/drm_framebuffer.c | 8 ++++++++
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index 1f8a5ebe188e..3a79c26c5cc7 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -276,11 +276,10 @@ Various hold-ups:
- Need to switch to drm_fbdev_generic_setup(), otherwise a lot of the custom fb
setup code can't be deleted.
-- Many drivers wrap drm_gem_fb_create() only to check for valid formats. For
- atomic drivers we could check for valid formats by calling
- drm_plane_check_pixel_format() against all planes, and pass if any plane
- supports the format. For non-atomic that's not possible since like the format
- list for the primary plane is fake and we'd therefor reject valid formats.
+- Need to switch to drm_gem_fb_create(), as now framebuffer_check() checks for
+ valid formats for atomic drivers.
+
+- Add an addfb format validation for non-atomic drivers.
- Many drivers subclass drm_framebuffer, we'd need a embedding compatible
version of the varios drm_gem_fb_create functions. Maybe called
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index aff3746dedfb..605642bf3650 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -280,6 +280,14 @@ static int framebuffer_check(struct drm_device *dev,
}
}
+ /* Verify that the modifier is supported. */
+ if (drm_drv_uses_atomic_modeset(dev) &&
+ !drm_any_plane_has_format(dev, r->pixel_format, r->modifier[0])) {
+ drm_dbg_kms(dev, "Unsupported pixel format %p4cc / modifier 0x%llx\n",
+ &r->pixel_format, r->modifier[0]);
+ return -EINVAL;
+ }
+
return 0;
}
--
2.39.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] drm/amdgpu: Remove redundant framebuffer format check
2023-01-13 11:27 [PATCH v2 0/3] Check for valid framebuffer's format Maíra Canal
2023-01-13 11:27 ` [PATCH v2 1/3] drm/framebuffer: Check for valid formats Maíra Canal
@ 2023-01-13 11:27 ` Maíra Canal
2023-01-13 11:27 ` [PATCH v2 3/3] drm/vmwgfx: " Maíra Canal
2 siblings, 0 replies; 6+ messages in thread
From: Maíra Canal @ 2023-01-13 11:27 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Daniel Vetter, Rob Clark, Simon Ser, Alex Deucher,
Christian König, Zack Rusin
Cc: André Almeida, Maíra Canal, amd-gfx, Melissa Wen,
VMware Graphics Reviewers, dri-devel
Now that framebuffer_check() verifies that the format is properly
supported, there is no need to check it again on amdgpu's inside
helpers.
Therefore, remove the redundant framebuffer format check from the
amdgpu_display_gem_fb_verify_and_init() function, letting
framebuffer_check() perform the framebuffer validation.
Reviewed-by: Simon Ser <contact@emersion.fr>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index b22471b3bd63..611b7a4b086c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -1120,16 +1120,6 @@ static int amdgpu_display_gem_fb_verify_and_init(struct drm_device *dev,
rfb->base.obj[0] = obj;
drm_helper_mode_fill_fb_struct(dev, &rfb->base, mode_cmd);
- /* Verify that the modifier is supported. */
- if (!drm_any_plane_has_format(dev, mode_cmd->pixel_format,
- mode_cmd->modifier[0])) {
- drm_dbg_kms(dev,
- "unsupported pixel format %p4cc / modifier 0x%llx\n",
- &mode_cmd->pixel_format, mode_cmd->modifier[0]);
-
- ret = -EINVAL;
- goto err;
- }
ret = amdgpu_display_framebuffer_init(dev, rfb, mode_cmd, obj);
if (ret)
--
2.39.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] drm/vmwgfx: Remove redundant framebuffer format check
2023-01-13 11:27 [PATCH v2 0/3] Check for valid framebuffer's format Maíra Canal
2023-01-13 11:27 ` [PATCH v2 1/3] drm/framebuffer: Check for valid formats Maíra Canal
2023-01-13 11:27 ` [PATCH v2 2/3] drm/amdgpu: Remove redundant framebuffer format check Maíra Canal
@ 2023-01-13 11:27 ` Maíra Canal
2 siblings, 0 replies; 6+ messages in thread
From: Maíra Canal @ 2023-01-13 11:27 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Daniel Vetter, Rob Clark, Simon Ser, Alex Deucher,
Christian König, Zack Rusin
Cc: André Almeida, Maíra Canal, amd-gfx, Melissa Wen,
VMware Graphics Reviewers, dri-devel
Now that framebuffer_check() verifies that the format is properly
supported, there is no need to check it again on vmwgfx's inside
helpers.
Therefore, remove the redundant framebuffer format check from the
vmw_kms_new_framebuffer_surface() and vmw_kms_new_framebuffer_bo()
functions, letting framebuffer_check() perform the framebuffer
validation.
Reviewed-by: Zack Rusin <zackr@vmware.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 257f090071f1..05b8d8f912bf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -1317,15 +1317,6 @@ static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv,
* Sanity checks.
*/
- if (!drm_any_plane_has_format(&dev_priv->drm,
- mode_cmd->pixel_format,
- mode_cmd->modifier[0])) {
- drm_dbg(&dev_priv->drm,
- "unsupported pixel format %p4cc / modifier 0x%llx\n",
- &mode_cmd->pixel_format, mode_cmd->modifier[0]);
- return -EINVAL;
- }
-
/* Surface must be marked as a scanout. */
if (unlikely(!surface->metadata.scanout))
return -EINVAL;
@@ -1648,15 +1639,6 @@ static int vmw_kms_new_framebuffer_bo(struct vmw_private *dev_priv,
return -EINVAL;
}
- if (!drm_any_plane_has_format(&dev_priv->drm,
- mode_cmd->pixel_format,
- mode_cmd->modifier[0])) {
- drm_dbg(&dev_priv->drm,
- "unsupported pixel format %p4cc / modifier 0x%llx\n",
- &mode_cmd->pixel_format, mode_cmd->modifier[0]);
- return -EINVAL;
- }
-
vfbd = kzalloc(sizeof(*vfbd), GFP_KERNEL);
if (!vfbd) {
ret = -ENOMEM;
--
2.39.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] drm/framebuffer: Check for valid formats
2023-01-13 11:27 ` [PATCH v2 1/3] drm/framebuffer: Check for valid formats Maíra Canal
@ 2023-01-13 13:06 ` Ville Syrjälä
0 siblings, 0 replies; 6+ messages in thread
From: Ville Syrjälä @ 2023-01-13 13:06 UTC (permalink / raw)
To: Maíra Canal
Cc: André Almeida, Thomas Zimmermann, Simon Ser, dri-devel,
Maarten Lankhorst, Maxime Ripard, Melissa Wen, Rob Clark,
VMware Graphics Reviewers, amd-gfx, Daniel Vetter, Daniel Vetter,
Alex Deucher, David Airlie, Christian König, Zack Rusin
On Fri, Jan 13, 2023 at 08:27:42AM -0300, Maíra Canal wrote:
> Currently, framebuffer_check() doesn't check if the pixel format is
> supported, which can lead to the acceptance of invalid pixel formats
> e.g. the acceptance of invalid modifiers. Therefore, add a check for
> valid formats on framebuffer_check(), so that the ADDFB2 IOCTL rejects
> calls with invalid formats.
>
> Moreover, note that this check is only valid for atomic drivers,
> because, for non-atomic drivers, checking drm_any_plane_has_format() is
> not possible since the format list for the primary plane is fake, and
> we'd therefore reject valid formats.
>
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
> Documentation/gpu/todo.rst | 9 ++++-----
> drivers/gpu/drm/drm_framebuffer.c | 8 ++++++++
> 2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
> index 1f8a5ebe188e..3a79c26c5cc7 100644
> --- a/Documentation/gpu/todo.rst
> +++ b/Documentation/gpu/todo.rst
> @@ -276,11 +276,10 @@ Various hold-ups:
> - Need to switch to drm_fbdev_generic_setup(), otherwise a lot of the custom fb
> setup code can't be deleted.
>
> -- Many drivers wrap drm_gem_fb_create() only to check for valid formats. For
> - atomic drivers we could check for valid formats by calling
> - drm_plane_check_pixel_format() against all planes, and pass if any plane
> - supports the format. For non-atomic that's not possible since like the format
> - list for the primary plane is fake and we'd therefor reject valid formats.
> +- Need to switch to drm_gem_fb_create(), as now framebuffer_check() checks for
> + valid formats for atomic drivers.
> +
> +- Add an addfb format validation for non-atomic drivers.
>
> - Many drivers subclass drm_framebuffer, we'd need a embedding compatible
> version of the varios drm_gem_fb_create functions. Maybe called
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index aff3746dedfb..605642bf3650 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -280,6 +280,14 @@ static int framebuffer_check(struct drm_device *dev,
> }
> }
>
> + /* Verify that the modifier is supported. */
> + if (drm_drv_uses_atomic_modeset(dev) &&
> + !drm_any_plane_has_format(dev, r->pixel_format, r->modifier[0])) {
> + drm_dbg_kms(dev, "Unsupported pixel format %p4cc / modifier 0x%llx\n",
> + &r->pixel_format, r->modifier[0]);
> + return -EINVAL;
> + }
Like I said this is still wrong for the !modifiers case.
> +
> return 0;
> }
>
> --
> 2.39.0
--
Ville Syrjälä
Intel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] drm/framebuffer: Check for valid formats
@ 2023-01-13 13:06 ` Ville Syrjälä
0 siblings, 0 replies; 6+ messages in thread
From: Ville Syrjälä @ 2023-01-13 13:06 UTC (permalink / raw)
To: Maíra Canal
Cc: André Almeida, Thomas Zimmermann, dri-devel, Melissa Wen,
VMware Graphics Reviewers, amd-gfx, Daniel Vetter, Alex Deucher,
Christian König
On Fri, Jan 13, 2023 at 08:27:42AM -0300, Maíra Canal wrote:
> Currently, framebuffer_check() doesn't check if the pixel format is
> supported, which can lead to the acceptance of invalid pixel formats
> e.g. the acceptance of invalid modifiers. Therefore, add a check for
> valid formats on framebuffer_check(), so that the ADDFB2 IOCTL rejects
> calls with invalid formats.
>
> Moreover, note that this check is only valid for atomic drivers,
> because, for non-atomic drivers, checking drm_any_plane_has_format() is
> not possible since the format list for the primary plane is fake, and
> we'd therefore reject valid formats.
>
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
> Documentation/gpu/todo.rst | 9 ++++-----
> drivers/gpu/drm/drm_framebuffer.c | 8 ++++++++
> 2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
> index 1f8a5ebe188e..3a79c26c5cc7 100644
> --- a/Documentation/gpu/todo.rst
> +++ b/Documentation/gpu/todo.rst
> @@ -276,11 +276,10 @@ Various hold-ups:
> - Need to switch to drm_fbdev_generic_setup(), otherwise a lot of the custom fb
> setup code can't be deleted.
>
> -- Many drivers wrap drm_gem_fb_create() only to check for valid formats. For
> - atomic drivers we could check for valid formats by calling
> - drm_plane_check_pixel_format() against all planes, and pass if any plane
> - supports the format. For non-atomic that's not possible since like the format
> - list for the primary plane is fake and we'd therefor reject valid formats.
> +- Need to switch to drm_gem_fb_create(), as now framebuffer_check() checks for
> + valid formats for atomic drivers.
> +
> +- Add an addfb format validation for non-atomic drivers.
>
> - Many drivers subclass drm_framebuffer, we'd need a embedding compatible
> version of the varios drm_gem_fb_create functions. Maybe called
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index aff3746dedfb..605642bf3650 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -280,6 +280,14 @@ static int framebuffer_check(struct drm_device *dev,
> }
> }
>
> + /* Verify that the modifier is supported. */
> + if (drm_drv_uses_atomic_modeset(dev) &&
> + !drm_any_plane_has_format(dev, r->pixel_format, r->modifier[0])) {
> + drm_dbg_kms(dev, "Unsupported pixel format %p4cc / modifier 0x%llx\n",
> + &r->pixel_format, r->modifier[0]);
> + return -EINVAL;
> + }
Like I said this is still wrong for the !modifiers case.
> +
> return 0;
> }
>
> --
> 2.39.0
--
Ville Syrjälä
Intel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-01-13 13:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-13 11:27 [PATCH v2 0/3] Check for valid framebuffer's format Maíra Canal
2023-01-13 11:27 ` [PATCH v2 1/3] drm/framebuffer: Check for valid formats Maíra Canal
2023-01-13 13:06 ` Ville Syrjälä
2023-01-13 13:06 ` Ville Syrjälä
2023-01-13 11:27 ` [PATCH v2 2/3] drm/amdgpu: Remove redundant framebuffer format check Maíra Canal
2023-01-13 11:27 ` [PATCH v2 3/3] drm/vmwgfx: " Maíra Canal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.