drm/gem: Check for valid formats
Subsystems (3)
PATCH 1/1 drm/gem: Check for valid formats
Currently, drm_gem_fb_create() 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 drm_gem_fb_create().
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 therefor reject valid formats.
--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)
Documentation/gpu/todo.rst +2 -5
@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe called
drivers/gpu/drm/drm_gem_framebuffer_helper.c +9 -0
@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h>
@@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } +if (drm_drv_uses_atomic_modeset (dev) && + !drm_any_plane_has_format (dev, mode_cmd->pixel_format, + mode_cmd->modifier[0 ])) { +drm_dbg (dev,"Unsupported pixel format %p4cc / modifier 0x%llx\n" , + &mode_cmd->pixel_format, mode_cmd->modifier[0 ]); +return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );
Signature · 1 line
2.38.1
Thomas Zimmermann
maintainerHi,
thanks for the follow-up patch.
Am 03.01.23 um 13:53 schrieb Maíra Canal:
Quoted 48 lines
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)Documentation/gpu/todo.rst +2
-5@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe calleddrivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h>
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 170
Quoted 6 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-0@@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } +if (drm_drv_uses_atomic_modeset (dev) && + !drm_any_plane_has_format (dev, mode_cmd->pixel_format, + mode_cmd->modifier[0 ])) {
Because this is a generic helper, it has to handle the odd cases as well. Here we cannot assume modifier[0], because there's a modifier for each pixel plane in multi-plane formats. (That's a different type of plane than the struct plane we're passing in.) If one combination isn't supported, the helper should fail.
We get the number of pixel planes from the format info. So the correct implementation is something like that
if (drm_drv_uses_atomic_modeset())) {
for (i = 0; i < info->num_planes; ++i) {
if (!drm_any_plane_has_format(dev, pixel_format, \
modifier[i]) {
drm_dbg_kms(dev, "error msg");
return -EINVAL;
}
}
}drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 171
Quoted 1 line
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-0+ drm_dbg(dev, "Unsupported pixel format %p4cc / modifier 0x%llx\n",
drm_dbg() is for drivers. Use drm_dbg_kms() please.
Best regards
Thomas
Quoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4
-0+ &mode_cmd->pixel_format, mode_cmd->modifier[0]); +return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Quoted 53 lines · Thomas Zimmermann
Hi,
thanks for the follow-up patch.
Am 03.01.23 um 13:53 schrieb Maíra Canal:
Quoted 48 lines
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)Documentation/gpu/todo.rst +2
-5@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe calleddrivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h> @@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } + if (drm_drv_uses_atomic_modeset(dev) &&
Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 170
Quoted 2 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-0+ !drm_any_plane_has_format(dev, mode_cmd->pixel_format, + mode_cmd->modifier[0])) {Because this is a generic helper, it has to handle the odd cases as well. Here we cannot assume modifier[0], because there's a modifier for each pixel plane in multi-plane formats. (That's a different type of plane than the struct plane we're passing in.) If one combination isn't supported, the helper should fail.
This was a mistake in the addfb2 design, we later rectified that all modifiers must match. This is because the modifier itsel can change the number of planes (for aux compression planes and stuff like that).
The full drm format description is the (drm_fourcc, drm_format_modifier) pair.
This should be documented somewhere already, if not, good idea to update addfb docs (or make them happen in the first place).
-Daniel
Quoted 38 lines
We get the number of pixel planes from the format info. So the correct implementation is something like that
if (drm_drv_uses_atomic_modeset())) { for (i = 0; i < info->num_planes; ++i) { if (!drm_any_plane_has_format(dev, pixel_format, \ modifier[i]) { drm_dbg_kms(dev, "error msg"); return -EINVAL; } } }drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 171
Quoted 1 line
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-0+ drm_dbg(dev, "Unsupported pixel format %p4cc / modifier 0x%llx\n",
drm_dbg()is for drivers. Usedrm_dbg_kms()please.Best regards
ThomasQuoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4
-0+ &mode_cmd->pixel_format, mode_cmd->modifier[0]); +return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Thomas Zimmermann
maintainerHi
Am 05.01.23 um 16:24 schrieb Daniel Vetter:
Quoted 63 lines · Thomas Zimmermann
Quoted 53 lines
Hi,
thanks for the follow-up patch.
Am 03.01.23 um 13:53 schrieb Maíra Canal:
Quoted 48 lines
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)Documentation/gpu/todo.rst +2
-5@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe calleddrivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h> @@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } + if (drm_drv_uses_atomic_modeset(dev) &&Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 170
Quoted 2 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-0+ !drm_any_plane_has_format(dev, mode_cmd->pixel_format, + mode_cmd->modifier[0])) {Because this is a generic helper, it has to handle the odd cases as well. Here we cannot assume modifier[0], because there's a modifier for each pixel plane in multi-plane formats. (That's a different type of plane than the struct plane we're passing in.) If one combination isn't supported, the helper should fail.
Quoted 6 lines
This was a mistake in the addfb2 design, we later rectified that all modifiers must match. This is because the modifier itsel can change the number of planes (for aux compression planes and stuff like that).
The full drm format description is the (
drm_fourcc,drm_format_modifier) pair.
Does this mean that only modifier[0] will ever contain a valid value, OR that all modifiers[i] have to contain the same value?
Best regards
Thomas
Quoted 47 lines
This should be documented somewhere already, if not, good idea to update addfb docs (or make them happen in the first place).
-DanielQuoted 38 lines
We get the number of pixel planes from the format info. So the correct implementation is something like that
if (drm_drv_uses_atomic_modeset())) { for (i = 0; i < info->num_planes; ++i) { if (!drm_any_plane_has_format(dev, pixel_format, \ modifier[i]) { drm_dbg_kms(dev, "error msg"); return -EINVAL; } } }drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 171
Quoted 1 line
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-0+ drm_dbg(dev, "Unsupported pixel format %p4cc / modifier 0x%llx\n",
drm_dbg()is for drivers. Usedrm_dbg_kms()please.Best regards
ThomasQuoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4
-0+ &mode_cmd->pixel_format, mode_cmd->modifier[0]); +return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Quoted 71 lines · Thomas Zimmermann
Hi
Am 05.01.23 um 16:24 schrieb Daniel Vetter:
Quoted 67 lines · Thomas Zimmermann
Quoted 53 lines
Hi,
thanks for the follow-up patch.
Am 03.01.23 um 13:53 schrieb Maíra Canal:
Quoted 48 lines
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)Documentation/gpu/todo.rst +2
-5@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe calleddrivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h> @@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } + if (drm_drv_uses_atomic_modeset(dev) &&Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 170
Quoted 2 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-0+ !drm_any_plane_has_format(dev, mode_cmd->pixel_format, + mode_cmd->modifier[0])) {Because this is a generic helper, it has to handle the odd cases as well. Here we cannot assume modifier[0], because there's a modifier for each pixel plane in multi-plane formats. (That's a different type of plane than the struct plane we're passing in.) If one combination isn't supported, the helper should fail.
This was a mistake in the addfb2 design, we later rectified that all modifiers must match. This is because the modifier itsel can change the number of planes (for aux compression planes and stuff like that).
Quoted 5 lines
Quoted 2 lines
The full drm format description is the (
drm_fourcc,drm_format_modifier) pair.Does this mean that only modifier[0] will ever contain a valid value, OR that all modifiers[i] have to contain the same value?
All must have the same, addfb checks for that. See framebuffer_check() -Daniel
Quoted 59 lines
Best regards
ThomasQuoted 47 lines
This should be documented somewhere already, if not, good idea to update addfb docs (or make them happen in the first place).
-DanielQuoted 38 lines
We get the number of pixel planes from the format info. So the correct implementation is something like that
if (drm_drv_uses_atomic_modeset())) { for (i = 0; i < info->num_planes; ++i) { if (!drm_any_plane_has_format(dev, pixel_format, \ modifier[i]) { drm_dbg_kms(dev, "error msg"); return -EINVAL; } } }drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 171
Quoted 1 line
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-0+ drm_dbg(dev, "Unsupported pixel format %p4cc / modifier 0x%llx\n",
drm_dbg()is for drivers. Usedrm_dbg_kms()please.Best regards
Thomasdrivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 178
Quoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4
-0+ &mode_cmd->pixel_format, mode_cmd->modifier[0]); +return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
drive-by thought/concern, what are the odds that there is some wayland compositor out there that creates an fb for every window surface, even if it later decides to composite on the GPU because the display does not support the format? It seems like there is a non-zero chance of breaking userspace..
BR,
-R
Quoted 66 lines · Maíra Canal
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)Documentation/gpu/todo.rst +2
-5@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe calleddrivers/gpu/drm/drm_gem_framebuffer_helper.c +9
-1@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h> @@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } +if (drm_drv_uses_atomic_modeset (dev) && + !drm_any_plane_has_format (dev, mode_cmd->pixel_format, + mode_cmd->modifier[0 ])) { +drm_dbg (dev,"Unsupported pixel format %p4cc / modifier 0x%llx\n" , + &mode_cmd->pixel_format, mode_cmd->modifier[0 ]); +return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); --2.38.1
Quoted 5 lines · Rob Clark
drive-by thought/concern, what are the odds that there is some wayland compositor out there that creates an fb for every window surface, even if it later decides to composite on the GPU because the display does not support the format? It seems like there is a non-zero chance of breaking userspace..
User-space is prepared for ADDFB2 to fail. Other drivers already reject IOCTLs with FB parameters not supported for scanout.
Quoted 6 lines · Rob Clark
drive-by thought/concern, what are the odds that there is some wayland compositor out there that creates an fb for every window surface, even if it later decides to composite on the GPU because the display does not support the format? It seems like there is a non-zero chance of breaking userspace..
As Simon pointed out, drivers like i915 and AMDGPU already reject IOCTLs with invalid parameters, as you can see on [1] and [2], so this patch would make the behavior more consistent between the drivers. That said, I don't believe that this patch would break userspace, as userspace already needs to handle with the existing drivers.
[1] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/i915/display/intel_fb.c#n1917
[2] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c#n1124
Best Regards,
- Maíra Canal
Quoted 3 lines
BR,
-R
Quoted 9 lines · Maíra Canal
Quoted 6 lines · Rob Clark
drive-by thought/concern, what are the odds that there is some wayland compositor out there that creates an fb for every window surface, even if it later decides to composite on the GPU because the display does not support the format? It seems like there is a non-zero chance of breaking userspace..
Quoted 5 lines
As Simon pointed out, drivers like i915 and AMDGPU already reject IOCTLs with invalid parameters, as you can see on [1] and [2], so this patch would make the behavior more consistent between the drivers. That said, I don't believe that this patch would break userspace, as userspace already needs to handle with the existing drivers.
ok, maybe this won't be a problem then
BR,
-R
Quoted 10 lines
[1] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/i915/display/intel_fb.c#n1917
[2] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c#n1124Best Regards,
- Maíra CanalQuoted 3 lines
BR,
-R
Quoted 5 lines · Maíra Canal
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().
Quoted 7 lines
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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>
I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to drm_any_plane_has_format() from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)
-Daniel
Quoted 53 lines
--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)Documentation/gpu/todo.rst +2
-5@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe calleddrivers/gpu/drm/drm_gem_framebuffer_helper.c +9
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h> @@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } +if (drm_drv_uses_atomic_modeset (dev) && + !drm_any_plane_has_format (dev, mode_cmd->pixel_format, + mode_cmd->modifier[0 ])) { +drm_dbg (dev,"Unsupported pixel format %p4cc / modifier 0x%llx\n" , + &mode_cmd->pixel_format, mode_cmd->modifier[0 ]); +return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );Signature · 1 line
2.38.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 14 lines · Daniel Vetter
Quoted 5 lines · Maíra Canal
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().Quoted 7 lines
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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>
Quoted 6 lines
Acked-by Daniel Vetter <[email protected]>I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)
I took a look at the callers to drm_any_plane_has_format() and there are only 3 callers (amdgpu, i915 and vmwgfx). They all use drm_any_plane_has_format() before calling drm_framebuffer_init(). So, I'm not sure I could remove drm_any_plane_has_format() from those drivers. Maybe adding this same check to drm_gem_fb_init() and refactor the drivers to make them use drm_gem_fb_init(), but I guess this would be part of a different series.
Best Regards,
- Maíra Canal
Quoted 2 lines
-Daniel
Quoted 23 lines · Maíra Canal
Quoted 14 lines · Daniel Vetter
Quoted 5 lines · Maíra Canal
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().Quoted 7 lines
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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>Quoted 6 lines
Acked-by Daniel Vetter <[email protected]>I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)
Quoted 6 lines
I took a look at the callers to
drm_any_plane_has_format()and there are only 3 callers (amdgpu, i915 and vmwgfx). They all usedrm_any_plane_has_format()before callingdrm_framebuffer_init(). So, I'm not sure I could removedrm_any_plane_has_format()from those drivers. Maybe adding this same check todrm_gem_fb_init()and refactor the drivers to make them usedrm_gem_fb_init(), but I guess this would be part of a different series.
Well vmwgfx still not yet using gem afaik, so that doesn't work.
But why can't we move the modifier check int drm_framebuffer_init()? That's kinda where it probably should be anyway, there's nothing gem bo specific in the code you're adding.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 31 lines · Daniel Vetter
Quoted 23 lines · Maíra Canal
Quoted 14 lines · Daniel Vetter
Quoted 5 lines · Maíra Canal
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().Quoted 7 lines
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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>Quoted 6 lines
Acked-by Daniel Vetter <[email protected]>I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)Quoted 6 lines
I took a look at the callers to
drm_any_plane_has_format()and there are only 3 callers (amdgpu, i915 and vmwgfx). They all usedrm_any_plane_has_format()before callingdrm_framebuffer_init(). So, I'm not sure I could removedrm_any_plane_has_format()from those drivers. Maybe adding this same check todrm_gem_fb_init()and refactor the drivers to make them usedrm_gem_fb_init(), but I guess this would be part of a different series.
Quoted 5 lines
Well vmwgfx still not yet using gem afaik, so that doesn't work.
But why can't we move the modifier check int
drm_framebuffer_init()? That's kinda where it probably should be anyway, there's nothing gem bo specific in the code you're adding.
I'm not sure if this would correct the problem that I was trying to fix initially. I was trying to make sure that the drivers pass on the igt@kms_addfb_basic@addfb25-bad-modifier IGT test by making sure that the addfb ioctl returns the error.
By moving the modifier check to the drm_framebuffer_init(), the test would still fail.
Best Regards,
- Maíra Canal
Quoted 1 line
-Daniel
Quoted 19 lines · Maíra Canal
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)I took a look at the callers to
drm_any_plane_has_format()and there are only 3 callers (amdgpu, i915 and vmwgfx). They all usedrm_any_plane_has_format()before callingdrm_framebuffer_init(). So, I'm not sure I could removedrm_any_plane_has_format()from those drivers. Maybe adding this same check todrm_gem_fb_init()and refactor the drivers to make them usedrm_gem_fb_init(), but I guess this would be part of a different series.Quoted 5 lines
Well vmwgfx still not yet using gem afaik, so that doesn't work.
But why can't we move the modifier check int
drm_framebuffer_init()? That's kinda where it probably should be anyway, there's nothing gem bo specific in the code you're adding.
Quoted 7 lines
I'm not sure if this would correct the problem that I was trying to fix initially. I was trying to make sure that the drivers pass on the igt@kms_addfb_basic@addfb25-bad-modifier IGT test by making sure that the addfb ioctl returns the error.
By moving the modifier check to the
drm_framebuffer_init(), the test would still fail.
Hm, why is that? The ADDFB2 IOCTL impl calls drm_framebuffer_init().
Quoted 26 lines · Simon Ser
Quoted 24 lines · Maíra Canal
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)I took a look at the callers to
drm_any_plane_has_format()and there are only 3 callers (amdgpu, i915 and vmwgfx). They all usedrm_any_plane_has_format()before callingdrm_framebuffer_init(). So, I'm not sure I could removedrm_any_plane_has_format()from those drivers. Maybe adding this same check todrm_gem_fb_init()and refactor the drivers to make them usedrm_gem_fb_init(), but I guess this would be part of a different series.Quoted 5 lines
Well vmwgfx still not yet using gem afaik, so that doesn't work.
But why can't we move the modifier check int
drm_framebuffer_init()? That's kinda where it probably should be anyway, there's nothing gem bo specific in the code you're adding.I'm not sure if this would correct the problem that I was trying to fix initially. I was trying to make sure that the drivers pass on the igt@kms_addfb_basic@addfb25-bad-modifier IGT test by making sure that the addfb ioctl returns the error.
Quoted 4 lines
Quoted 2 lines
By moving the modifier check to the
drm_framebuffer_init(), the test would still fail.Hm, why is that? The ADDFB2 IOCTL impl calls
drm_framebuffer_init().
From what I can see, ADDFB2 IOCTL calls drm_internal_framebuffer_create() [1], then drm_internal_framebuffer_create() calls the fb_create hook [2]. I'm not sure here ADDFB2 implicitly calls drm_framebuffer_init(), but I'm probably missing something.
Also, by looking at this file, I realize that maybe it would be better to add the check on framebuffer_check(), but I don't know how does it sound to Daniel.
[1] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/drm_framebuffer.c#n346
[2] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/drm_framebuffer.c#n321
Best Regards,
- Maíra Canal
Quoted 30 lines · Maíra Canal
Quoted 28 lines · Simon Ser
Quoted 25 lines · On Thursday, January 5th, 2023 at 19:30, Maíra Canal [email protected] wrote:
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)I took a look at the callers to
drm_any_plane_has_format()and there are only 3 callers (amdgpu, i915 and vmwgfx). They all usedrm_any_plane_has_format()before callingdrm_framebuffer_init(). So, I'm not sure I could removedrm_any_plane_has_format()from those drivers. Maybe adding this same check todrm_gem_fb_init()and refactor the drivers to make them usedrm_gem_fb_init(), but I guess this would be part of a different series.Quoted 5 lines
Well vmwgfx still not yet using gem afaik, so that doesn't work.
But why can't we move the modifier check int
drm_framebuffer_init()? That's kinda where it probably should be anyway, there's nothing gem bo specific in the code you're adding.I'm not sure if this would correct the problem that I was trying to fix initially. I was trying to make sure that the drivers pass on the igt@kms_addfb_basic@addfb25-bad-modifier IGT test by making sure that the addfb ioctl returns the error.
By moving the modifier check to the
drm_framebuffer_init(), the test would still fail.
Quoted 7 lines
Quoted 1 line
Hm, why is that? The ADDFB2 IOCTL impl calls
drm_framebuffer_init().From what I can see, ADDFB2 IOCTL calls
drm_internal_framebuffer_create()[1], thendrm_internal_framebuffer_create()calls thefb_createhook [2]. I'm not sure here ADDFB2 implicitly callsdrm_framebuffer_init(), but I'm probably missing something.
Right, but then all drivers will call drm_framebuffer_init() somewhere in their fb_create hook. For instance amdgpu calls it in amdgpu_display_gem_fb_verify_and_init().
Quoted 35 lines · Simon Ser
Quoted 33 lines · Maíra Canal
Quoted 29 lines · Simon Ser
Quoted 18 lines · On Thursday, January 5th, 2023 at 19:30, Maíra Canal [email protected] wrote:
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)I took a look at the callers to
drm_any_plane_has_format()and there are only 3 callers (amdgpu, i915 and vmwgfx). They all usedrm_any_plane_has_format()before callingdrm_framebuffer_init(). So, I'm not sure I could removedrm_any_plane_has_format()from those drivers. Maybe adding this same check todrm_gem_fb_init()and refactor the drivers to make them usedrm_gem_fb_init(), but I guess this would be part of a different series.Quoted 5 lines
Well vmwgfx still not yet using gem afaik, so that doesn't work.
But why can't we move the modifier check int
drm_framebuffer_init()? That's kinda where it probably should be anyway, there's nothing gem bo specific in the code you're adding.Quoted 7 lines
I'm not sure if this would correct the problem that I was trying to fix initially. I was trying to make sure that the drivers pass on the igt@kms_addfb_basic@addfb25-bad-modifier IGT test by making sure that the addfb ioctl returns the error.
By moving the modifier check to the
drm_framebuffer_init(), the test would still fail.Hm, why is that? The ADDFB2 IOCTL impl calls
drm_framebuffer_init().
Quoted 8 lines
Quoted 4 lines
From what I can see, ADDFB2 IOCTL calls
drm_internal_framebuffer_create()[1],
thendrm_internal_framebuffer_create()calls thefb_createhook [2]. I'm not sure here ADDFB2 implicitly callsdrm_framebuffer_init(), but I'm probably missing something.Right, but then all drivers will call
drm_framebuffer_init()somewhere in theirfb_createhook. For instance amdgpu calls it inamdgpu_display_gem_fb_verify_and_init().
I see. Thanks for explaining me the relation between the functions. I will send a v3 of this patch, introducing the check on drm_framebuffer_init().
Best Regards,
- Maíra Canal
To be honest, your suggestion to put the check inside framebuffer_check() sounds like a better idea: we wouldn't even hit any driver-specific code-path when the check fails. Daniel, do you think there'd be an issue with this approach?
Quoted 4 lines · Simon Ser
To be honest, your suggestion to put the check inside
framebuffer_check()sounds like a better idea: we wouldn't even hit any driver-specific code-path when the check fails. Daniel, do you think there'd be an issue with this approach?
framebuffer_check probably even better, since it'll stop nonsense before a driver potentially blows up. Which would be a CVE. So even better at catching potential issues.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Thomas Zimmermann
maintainerHi
Am 05.01.23 um 19:22 schrieb Daniel Vetter:
Quoted 24 lines · Maíra Canal
Quoted 23 lines · Daniel Vetter
Quoted 20 lines · Maíra Canal
Quoted 5 lines
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().Quoted 7 lines
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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>Acked-by Daniel Vetter <[email protected]>I think to really make sure we have consensus it'd be good to extend this to a series which removes all the callers to
drm_any_plane_has_format()from the various drivers, and then unexports that helper. That way your series here will have more eyes on it :-)
Quoted 8 lines
Quoted 6 lines
I took a look at the callers to
drm_any_plane_has_format()and there are only 3 callers (amdgpu, i915 and vmwgfx). They all usedrm_any_plane_has_format()before callingdrm_framebuffer_init(). So, I'm not sure I could removedrm_any_plane_has_format()from those drivers. Maybe adding this same check todrm_gem_fb_init()and refactor the drivers to make them usedrm_gem_fb_init(), but I guess this would be part of a different series.Well vmwgfx still not yet using gem afaik, so that doesn't work.
There was a patchset that converted vmwgfx to GEM IIRC. It even uses generic fbdev emulation now, for which GEM is a hard requirement.
Best regards
Thomas
Quoted 5 lines
But why can't we move the modifier check int
drm_framebuffer_init()? That's kinda where it probably should be anyway, there's nothing gem bo specific in the code you're adding.
-Daniel
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Hi
Am 03.01.23 um 13:53 schrieb Maíra Canal:
Quoted 48 lines
Currently,
drm_gem_fb_create()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 ondrm_gem_fb_create().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 therefor reject valid formats.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Maíra Canal <[email protected]>--- Documentation/gpu/todo.rst | 7 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)Documentation/gpu/todo.rst +2
-5@@ -276,11 +276,8 @@ 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 drm_gem_fb_create() checks for + valid formats for atomic drivers. - Many drivers subclass drm_framebuffer, we'd need a embedding compatible version of the varios drm_gem_fb_create functions. Maybe calleddrivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h>
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_init_with_funcs(struct drm_device *dev, · line 172
Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +5
-0@@ -164,6 +165,14 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return -EINVAL ; } +if (drm_drv_uses_atomic_modeset (dev) && + !drm_any_plane_has_format (dev, mode_cmd->pixel_format, + mode_cmd->modifier[0 ])) { +drm_dbg (dev,"Unsupported pixel format %p4cc / modifier 0x%llx\n" , + &mode_cmd->pixel_format, mode_cmd->modifier[0 ]);
Given Daniel's comment on modifier[0], please change this comment to drm_dbg_kms() and you can
to this patch.
Best regards
Thomas
Quoted 6 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-0+return -EINVAL ; + } +for (i =0 ; i < info->num_planes; i++) {unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev