drm/vc4: Check for valid formats
Subsystems (3)
Maíra Canal
reviewerPATCH 1/1 drm/vc4: Check for valid formats
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
--- drivers/gpu/drm/vc4/vc4_kms.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_kms.c +0 -0
@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev,
mode_cmd = &mode_cmd_local; }
+ 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]);
+ return ERR_PTR(-EINVAL);
+ }
+
+ return drm_gem_fb_create(dev, file_priv, mode_cmd);
+}
+
+static struct drm_framebuffer *vc5_fb_create(struct drm_device *dev,
+ struct drm_file *file_priv,
+ const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+ 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]);
+ return ERR_PTR(-EINVAL);
+ }
+
return drm_gem_fb_create(dev, file_priv, mode_cmd);
}
@@ -1033,7 +1054,7 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = {
static const struct drm_mode_config_funcs vc5_mode_funcs = {
.atomic_check = vc4_atomic_check,
.atomic_commit = drm_atomic_helper_commit,
- .fb_create = drm_gem_fb_create,
+ .fb_create = vc5_fb_create,
};
int vc4_kms_load(struct drm_device *dev)
--
2.38.1
Thomas Zimmermann
maintainerHi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 17 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>--- drivers/gpu/drm/vc4/vc4_kms.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, · line 508
Quoted 9 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; } +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 ]); +return ERR_PTR (-EINVAL ); + }
This might be a stupid question, but why doesn't drm_fbgem_fb_create() do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.
Best regards
Thomas
Quoted 30 lines
drivers/gpu/drm/vc4/vc4_kms.c +16
-2+ +return drm_gem_fb_create (dev, file_priv, mode_cmd); +} + +static struct drm_framebuffer *vc5_fb_create (struct drm_device *dev, +struct drm_file *file_priv, +const struct drm_mode_fb_cmd2 *mode_cmd) +{ +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 ]); +return ERR_PTR (-EINVAL ); + } +return drm_gem_fb_create (dev, file_priv, mode_cmd); }@@ -1033,7 +1054,7 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = {static const struct drm_mode_config_funcs vc5_mode_funcs = { .atomic_check = vc4_atomic_check, .atomic_commit = drm_atomic_helper_commit, - .fb_create = drm_gem_fb_create, + .fb_create = vc5_fb_create, };int vc4_kms_load (struct drm_device *dev) --2.38.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
Maíra Canal
reviewerHi,
Quoted 23 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 20 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>---
drivers/gpu/drm/vc4/vc4_kms.c| 23 ++++++++++++++++++++++-1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }
Quoted 8 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, · line 508
Quoted 6 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+ 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]); + return ERR_PTR(-EINVAL); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.
I thought the same initially, but then I found this mention on the TODO list [1]. So, it is not possible to test it on drm_gem_fb_create() because, for non-atomic, checking drm_any_plane_has_format() is not possible since like the format list for the primary plane is fake and we'd therefor reject valid formats.
I'm not sure if anything changed since this was written, but that was the reason that I decided to introduce the check in the driver instead of the API.
[1] https://cgit.freedesktop.org/drm/drm/tree/Documentation/gpu/todo.rst#n279
Best Regards,
- Maíra Canal
Quoted 35 lines
Best regards
ThomasQuoted 30 lines
drivers/gpu/drm/vc4/vc4_kms.c +16
-1+ + return drm_gem_fb_create(dev, file_priv, mode_cmd); +} + +static struct drm_framebuffer *vc5_fb_create (struct drm_device *dev, + struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + 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]); + return ERR_PTR(-EINVAL); + } + return drm_gem_fb_create(dev, file_priv, mode_cmd); }@@ -1033,7 +1054,7 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = { static const struct drm_mode_config_funcs vc5_mode_funcs = { .atomic_check = vc4_atomic_check, .atomic_commit = drm_atomic_helper_commit, - .fb_create = drm_gem_fb_create, + .fb_create = vc5_fb_create, }; int vc4_kms_load(struct drm_device *dev)Signature · 1 line
2.38.1
Thomas Zimmermann
maintainerHi
Am 02.01.23 um 15:29 schrieb Maíra Canal:
Quoted 37 lines
Hi,
Quoted 24 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 21 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>---
drivers/gpu/drm/vc4/vc4_kms.c| 23 ++++++++++++++++++++++-1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }Quoted 9 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer · line 510
Quoted 7 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+ 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]); + return ERR_PTR(-EINVAL); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.
Quoted 4 lines
I thought the same initially, but then I found this mention on the TODO list [1]. So, it is not possible to test it on
drm_gem_fb_create()because, for non-atomic, checkingdrm_any_plane_has_format()is not possible since like the format list for the primary plane is fake and we'd therefor reject valid formats.
Thanks for the pointer to the docs.
I see two options:
1) Testing for atomic modesetting can be done via drm_core_check_feature(dev, DRIVER_ATOMIC). If true, drm_gem_fb_create() can further test for the plane formats. For non-atomic drivers, just skip the format test.
2) As an alternative, we could invert the IGT test and explicitly allow any format to be allocated. Almost no drivers currently bother with the format test anyway. And DRM will already fail if userspace attaches a framebuffer to a plane with incompatible formats. [1] (I'd personally prefer this option, but I'm not sure if there's any consensus on that.)
With either implemented, the TODO item could be remvoed AFAICT.
Best regards
Thomas
[1] https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/drm_plane.c#L789
Quoted 46 lines
I'm not sure if anything changed since this was written, but that was the reason that I decided to introduce the check in the driver instead of the API.
[1] https://cgit.freedesktop.org/drm/drm/tree/Documentation/gpu/todo.rst#n279
Best Regards,
- Maíra CanalQuoted 37 lines
Best regards
ThomasQuoted 32 lines
drivers/gpu/drm/vc4/vc4_kms.c +15
-0+ + return drm_gem_fb_create(dev, file_priv, mode_cmd); +} + +static struct drm_framebuffer *vc5_fb_create (struct drm_device *dev, + struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + 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]); + return ERR_PTR(-EINVAL); + } +return
drm_gem_fb_create(dev, file_priv, mode_cmd); }drivers/gpu/drm/vc4/vc4_kms.c +1
-1@@ -1033,7 +1054,7 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = { static const struct drm_mode_config_funcs vc5_mode_funcs = { .atomic_check = vc4_atomic_check, .atomic_commit = drm_atomic_helper_commit, - .fb_create = drm_gem_fb_create, + .fb_create = vc5_fb_create, };int
vc4_kms_load(struct drm_device *dev)Signature · 1 line
2.38.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
Maíra Canal
reviewerQuoted 43 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 15:29 schrieb Maíra Canal:
Quoted 35 lines
Hi,
Quoted 23 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 20 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>---
drivers/gpu/drm/vc4/vc4_kms.c| 23 ++++++++++++++++++++++-1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }Quoted 8 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, · line 508
Quoted 6 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+ 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]); + return ERR_PTR(-EINVAL); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.Quoted 4 lines
I thought the same initially, but then I found this mention on the TODO list [1]. So, it is not possible to test it on
drm_gem_fb_create()because, for non-atomic, checkingdrm_any_plane_has_format()is not possible since like the format list for the primary plane is fake and we'd therefor reject valid formats.
Quoted 7 lines
Thanks for the pointer to the docs.
I see two options:
1) Testing for atomic modesetting can be done via
drm_core_check_feature(dev, DRIVER_ATOMIC). If true,drm_gem_fb_create()can further test for the plane formats. For non-atomic drivers, just skip the format test.2) As an alternative, we could invert the IGT test and explicitly allow any format to be allocated. Almost no drivers currently bother with the format test anyway. And DRM will already fail if userspace attaches a framebuffer to a plane with incompatible formats. [1] (I'd personally prefer this option, but I'm not sure if there's any consensus on that.)
I guess the second option will probably break Intel's CI, which I'm not sure if it is a good idea. Maybe the first option is a bit less intrusive and will help the DRM helper to have the same behavior as drivers like i915 and AMDGPU.
Thanks for the suggestions!
Best Regards,
- Maíra Canal
Quoted 53 lines
With either implemented, the TODO item could be remvoed AFAICT.
Best regards
Thomas[1] https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/drm_plane.c#L789
Quoted 44 lines
I'm not sure if anything changed since this was written, but that was the reason that I decided to introduce the check in the driver instead of the API.
[1] https://cgit.freedesktop.org/drm/drm/tree/Documentation/gpu/todo.rst#n279
Best Regards,
- Maíra CanalQuoted 35 lines
Best regards
ThomasQuoted 30 lines
drivers/gpu/drm/vc4/vc4_kms.c +16
-1+ + return drm_gem_fb_create(dev, file_priv, mode_cmd); +} + +static struct drm_framebuffer *vc5_fb_create (struct drm_device *dev, + struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + 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]); + return ERR_PTR(-EINVAL); + } + return drm_gem_fb_create(dev, file_priv, mode_cmd); }@@ -1033,7 +1054,7 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = { static const struct drm_mode_config_funcs vc5_mode_funcs = { .atomic_check = vc4_atomic_check, .atomic_commit = drm_atomic_helper_commit, - .fb_create = drm_gem_fb_create, + .fb_create = vc5_fb_create, }; int vc4_kms_load(struct drm_device *dev)Signature · 1 line
2.38.1
Thomas Zimmermann
maintainerHi
Am 02.01.23 um 16:39 schrieb Maíra Canal:
Quoted 50 lines · Thomas Zimmermann
Quoted 49 lines
Hi
Am 02.01.23 um 15:29 schrieb Maíra Canal:
Quoted 37 lines
Hi,
Quoted 24 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 21 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>---
drivers/gpu/drm/vc4/vc4_kms.c| 23 ++++++++++++++++++++++-1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }Quoted 9 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer · line 510
Quoted 7 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+ 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]); + return ERR_PTR(-EINVAL); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.Quoted 4 lines
I thought the same initially, but then I found this mention on the TODO list [1]. So, it is not possible to test it on
drm_gem_fb_create()because, for non-atomic, checkingdrm_any_plane_has_format()is not possible since like the format list for the primary plane is fake and we'd therefor reject valid formats.Thanks for the pointer to the docs.
I see two options:
Quoted 7 lines
Quoted 3 lines
1) Testing for atomic modesetting can be done via
drm_core_check_feature(dev, DRIVER_ATOMIC). If true,drm_gem_fb_create()can further test for the plane formats. For non-atomic drivers, just skip the format test.2) As an alternative, we could invert the IGT test and explicitly allow any format to be allocated. Almost no drivers currently bother with the format test anyway. And DRM will already fail if userspace attaches a framebuffer to a plane with incompatible formats. [1] (I'd personally prefer this option, but I'm not sure if there's any consensus on that.)
I guess the second option will probably break Intel's CI, which I'm not sure if it is a good idea. Maybe the first option is a bit less intrusive and will help the DRM helper to have the same behavior as drivers like i915 and AMDGPU.
That makes some sense. I'd like to hear the opinion of the affected developers. If no one shows up, go for option 1 then. It has the potential to break someone's userspace code, but it's easily revert-able.
Best regards
Thomas
Quoted 61 lines
Thanks for the suggestions!
Best Regards,
- Maíra CanalQuoted 55 lines
With either implemented, the TODO item could be remvoed AFAICT.
Best regards
Thomas[1] https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/drm_plane.c#L789
Quoted 46 lines
I'm not sure if anything changed since this was written, but that was the reason that I decided to introduce the check in the driver instead of the API.
[1] https://cgit.freedesktop.org/drm/drm/tree/Documentation/gpu/todo.rst#n279
Best Regards,
- Maíra CanalQuoted 37 lines
Best regards
ThomasQuoted 32 lines
drivers/gpu/drm/vc4/vc4_kms.c +15
-0+ + return drm_gem_fb_create(dev, file_priv, mode_cmd); +} + +static struct drm_framebuffer *vc5_fb_create (struct drm_device *dev, + struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + 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]); + return ERR_PTR(-EINVAL); + } +return
drm_gem_fb_create(dev, file_priv, mode_cmd); }drivers/gpu/drm/vc4/vc4_kms.c +1
-1@@ -1033,7 +1054,7 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = { static const struct drm_mode_config_funcs vc5_mode_funcs = { .atomic_check = vc4_atomic_check, .atomic_commit = drm_atomic_helper_commit, - .fb_create = drm_gem_fb_create, + .fb_create = vc5_fb_create, };int
vc4_kms_load(struct drm_device *dev)Signature · 1 line
2.38.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 52 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 15:29 schrieb Maíra Canal:
Quoted 41 lines
Hi,
Quoted 25 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 22 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>---
drivers/gpu/drm/vc4/vc4_kms.c| 23 ++++++++++++++++++++++-1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }Quoted 12 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer · line 510
Quoted 7 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+ 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]); + return ERR_PTR(-EINVAL); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.Quoted 7 lines
I thought the same initially, but then I found this mention on the TODO list [1]. So, it
is not possible to test it ondrm_gem_fb_create()because, for non-atomic, checkingdrm_any_plane_has_format()is not possible since like the format list for the primary plane
is fake and we'd therefor reject valid formats.
Quoted 8 lines
Thanks for the pointer to the docs.
I see two options:
1) Testing for atomic modesetting can be done via
drm_core_check_feature(dev, DRIVER_ATOMIC). If true,drm_gem_fb_create()can further test for the plane formats. For non-atomic drivers, just skip the format test.
^^ this sounds like a good idea. Also note that for these checks the right check is actually drm_drv_uses_atomic_modesetting, since it's about the driver interface. DRIVER_ATOMIC is more about whether the driver interface actually upholds the atomic/tearfree guarantees userspace expects.
-Daniel
Quoted 70 lines
2) As an alternative, we could invert the IGT test and explicitly allow any format to be allocated. Almost no drivers currently bother with the format test anyway. And DRM will already fail if userspace attaches a framebuffer to a plane with incompatible formats. [1] (I'd personally prefer this option, but I'm not sure if there's any consensus on that.)
With either implemented, the TODO item could be remvoed AFAICT.
Best regards
Thomas[1] https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/drm_plane.c#L789
Quoted 48 lines
I'm not sure if anything changed since this was written, but that was the reason that I
decided to introduce the check in the driver instead of the API.[1]
https://cgit.freedesktop.org/drm/drm/tree/Documentation/gpu/todo.rst#n279Best Regards,
- Maíra CanalQuoted 37 lines
Best regards
ThomasQuoted 32 lines
drivers/gpu/drm/vc4/vc4_kms.c +15
-0+ + return drm_gem_fb_create(dev, file_priv, mode_cmd); +} + +static struct drm_framebuffer *vc5_fb_create (struct drm_device *dev, + struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + 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]); + return ERR_PTR(-EINVAL); + } +return
drm_gem_fb_create(dev, file_priv, mode_cmd); }drivers/gpu/drm/vc4/vc4_kms.c +1
-1@@ -1033,7 +1054,7 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = { static const struct drm_mode_config_funcs vc5_mode_funcs = { .atomic_check = vc4_atomic_check, .atomic_commit = drm_atomic_helper_commit, - .fb_create = drm_gem_fb_create, + .fb_create = vc5_fb_create, };int
vc4_kms_load(struct drm_device *dev)Signature · 1 line
2.38.1Signature · 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
Quoted 23 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 20 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>--- drivers/gpu/drm/vc4/vc4_kms.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }
Quoted 10 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, · line 508
Quoted 6 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+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 ]); +return ERR_PTR (-EINVAL ); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.
That was the approach I tried originally but there were a bunch of problems with various drivers it at the time. Dunno if all of those got sorted out or not. IIRC the idea floating around for ancient drivers was to skip the check based on plane->format_default. Looks like we're already using that approach in the setcrtc ioctl.
Signature · 2 lines
Ville Syrjälä Intel
Maíra Canal
reviewerQuoted 35 lines · Ville Syrjälä
Quoted 23 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 20 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>--- drivers/gpu/drm/vc4/vc4_kms.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }Quoted 10 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, · line 508
Quoted 6 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+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 ]); +return ERR_PTR (-EINVAL ); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.
Quoted 6 lines
That was the approach I tried originally but there were a bunch of problems with various drivers it at the time. Dunno if all of those got sorted out or not. IIRC the idea floating around for ancient drivers was to skip the check based on
plane->format_default. Looks like we're already using that approach in the setcrtc ioctl.
I ended up following Thomas's idea to check drm_drv_uses_atomic_modesetting() in order to check the modifier only for atomic drivers. If you have any feedback on this idea, I would be glad to hear it. The current version of this patch is [1].
[1] https://lore.kernel.org/dri-devel/[email protected]/T/
Best Regards,
- Maíra Canal
Quoted 43 lines · Maíra Canal
Quoted 35 lines · Ville Syrjälä
Quoted 23 lines · Thomas Zimmermann
Hi
Am 02.01.23 um 14:57 schrieb Maíra Canal:
Quoted 20 lines
Currently, vc4 is not checking valid formats before creating a framebuffer, which is triggering the IGT test igt@kms_addfb_basic@addfb25-bad-modifier to fail, as vc4 accepts to create a framebuffer with an invalid modifier. Therefore, check for valid formats before creating framebuffers on vc4 and vc5 in order to avoid creating framebuffers with invalid formats.
Signed-off-by Maíra Canal <[email protected]>--- drivers/gpu/drm/vc4/vc4_kms.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/vc4/vc4_kms.c +0
-0@@ -500,6 +500,27 @@ static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, mode_cmd = &mode_cmd_local; }Quoted 10 lines
drivers/gpu/drm/vc4/vc4_kms.c static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev, · line 508
Quoted 6 lines
drivers/gpu/drm/vc4/vc4_kms.c +6
-0+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 ]); +return ERR_PTR (-EINVAL ); + }This might be a stupid question, but why doesn't
drm_fbgem_fb_create()do this test already? It seems like a no-brainer and *not* testing for the plane formats should be the exception.Quoted 6 lines
That was the approach I tried originally but there were a bunch of problems with various drivers it at the time. Dunno if all of those got sorted out or not. IIRC the idea floating around for ancient drivers was to skip the check based on
plane->format_default. Looks like we're already using that approach in the setcrtc ioctl.
Quoted 5 lines
I ended up following Thomas's idea to check
drm_drv_uses_atomic_modesetting()in order to check the modifier only for atomic drivers. If you have any feedback on this idea, I would be glad to hear it. The current version of this patch is [1].
Yeah for atomic drivers the format list better be accurate, so we should be able to enforce this.
For legacy driver it's a bit a mess, but I'm toying with some ideas how we could add at least some validation there too. It's just that the audit is a total pain :-/
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch