drm/client: Fix display-mode selection
Subsystems (2)
Thomas Zimmermann
maintainercover drm/client: Fix display-mode selection
Pick user-defined display mode in DRM clients if the mode has been validated by the driver. Otherwise pick a preferred display mode.
Booting the kernel with video=<mode> and giving an unsupported display mode can easily turn the display unusable. This is best tested by booting simpledrm with a display mode that does not use the firmware framebuffer's resolution. While simpledrm filter's out the mode as invalid, the DRM client still picks it and the console won't show up.
Several factors contribute to this problem.
* The connector invalidates the user-defined display mode, but never tells the user about it.
* The DRM client doesn't look for user-defined display modes, but for modes that are similar.
* If no similar mode can be found, the client adds the invalid display mode back to the connector's mode list for use.
Each of the patches in this patchset addresses one of these problems. Overall the DRM client has no business in display-mode detection and should only pick one of the modes that has been detected and validated by the connector.
Thomas Zimmermann (3):
drm: Always warn if user-defined modes are not supported drm/client: Look for command-line modes first drm/client: Don't add new command-line mode
drivers/gpu/drm/drm_client_modeset.c | 28 ++++++++++++++++------------ drivers/gpu/drm/drm_modes.c | 4 ++++ 2 files changed, 20 insertions(+), 12 deletions(-)
Signature · 1 line
2.36.0
Thomas Zimmermann
maintainerPATCH 2/3 drm/client: Look for command-line modes first
When picking a mode, first look for modes that have been specified by the user on the kernel's command line. Only if that fails, use the existing heuristic of picking a nearby mode from it's various parameters.
--- drivers/gpu/drm/drm_client_modeset.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/drm_client_modeset.c +11 -0
@@ -165,6 +165,17 @@ drm_connector_pick_cmdline_mode(struct drm_connector *connector)struct drm_display_mode *mode;bool prefer_non_interlace; +/* +* Find a user-defined mode. If the user gave us a valid +* mode on the kernel command line, it will show up in this +* list. +*/ + +list_for_each_entry (mode, &connector->modes, head) { +if (mode->type &DRM_MODE_TYPE_USERDEF ) +return mode; + } + cmdline_mode = &connector->cmdline_mode;if (cmdline_mode->specified == false)return NULL ;
Signature · 1 line
2.36.0
Thomas Zimmermann
maintainerPATCH 1/3 drm: Always warn if user-defined modes are not supported
In reply to Thomas ZimmermannPrint a warning if a user-specifed display mode is not supported by the display pipeline. Users specified the display mode on the kernel command line with the use of the video= parameter. Setting an unsupported mode will leave the console blank, so we should at least let the user know why.
--- drivers/gpu/drm/drm_modes.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_modes.c +4 -0
@@ -1328,6 +1328,10 @@ void drm_mode_prune_invalid(struct drm_device *dev,list_for_each_entry_safe (mode, t, mode_list, head) {if (mode->status !=MODE_OK ) {list_del (&mode->head); +if (mode->type &DRM_MODE_TYPE_USERDEF ) { +drm_warn (dev,"User-defined mode not supported: " +DRM_MODE_FMT "\n" ,DRM_MODE_ARG (mode)); + }if (verbose) {drm_mode_debug_printmodeline (mode); DRM_DEBUG_KMS("Not using %s mode: %s\n",
Signature · 1 line
2.36.0
Thomas Zimmermann
maintainerPATCH 3/3 drm/client: Don't add new command-line mode
In reply to Thomas ZimmermannDon't add a mode for the kernel's command-line parameters from within the DRM client code. Doing so can result in an unusable display. If there's no compatible command-line mode, the client will use one of the connector's preferred modes.
All mode creation and validation has to be performed by the connector. When clients run, the connector's fill_modes callback has already processes the kernel parameters and validates each mode before adding it. The connector's mode list does not contain invalid modes.
--- drivers/gpu/drm/drm_client_modeset.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/gpu/drm/drm_client_modeset.c +5 -12
@@ -158,8 +158,7 @@ drm_connector_has_preferred_mode(struct drm_connector *connector, int width, intreturn NULL ; } -static struct drm_display_mode * -drm_connector_pick_cmdline_mode (struct drm_connector *connector) +static struct drm_display_mode *drm_connector_pick_cmdline_mode (struct drm_connector *connector) {struct drm_cmdline_mode *cmdline_mode;struct drm_display_mode *mode;
@@ -180,11 +179,10 @@ drm_connector_pick_cmdline_mode(struct drm_connector *connector)if (cmdline_mode->specified == false)return NULL ; -/* attempt to find a matching mode in the list of modes -* we have gotten so far, if not add a CVT mode that conforms +/* +* Attempt to find a matching mode in the list of modes we +* have gotten so far. */ -if (cmdline_mode->rb || cmdline_mode->margins) - goto create_mode; prefer_non_interlace = !cmdline_mode->interlace; again:
@@ -218,12 +216,7 @@ drm_connector_pick_cmdline_mode(struct drm_connector *connector) goto again; } -create_mode: - mode =drm_mode_create_from_cmdline_mode (connector->dev, cmdline_mode); -if (mode) -list_add (&mode->head, &connector->modes); - -return mode; +return NULL ; }static bool drm_connector_enabled (struct drm_connector *connector,bool strict)
Signature · 1 line
2.36.0
Re: [PATCH 1/3] drm: Always warn if user-defined modes are not supported
In reply to Thomas ZimmermannHello Thomas,
Quoted 16 lines · Thomas Zimmermann
Print a warning if a user-specifed display mode is not supported by the display pipeline. Users specified the display mode on the kernel command line with the use of the video= parameter. Setting an unsupported mode will leave the console blank, so we should at least let the user know why.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_modes.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/drm_modes.c +0
-0
drivers/gpu/drm/drm_modes.c void drm_mode_prune_invalid(struct drm_device *dev, · line 1333
Quoted 6 lines
drivers/gpu/drm/drm_modes.c +3
-0@@ -1328,6 +1328,10 @@ void drm_mode_prune_invalid(struct drm_device *dev,list_for_each_entry_safe (mode, t, mode_list, head) {if (mode->status !=MODE_OK ) {list_del (&mode->head); +if (mode->type &DRM_MODE_TYPE_USERDEF ) { +drm_warn (dev,"User-defined mode not supported: " +DRM_MODE_FMT "\n" ,DRM_MODE_ARG (mode));
I wonder if should be more explicit here like "... and it will not be used".
drivers/gpu/drm/drm_modes.c void drm_mode_prune_invalid(struct drm_device *dev, · line 1337
Quoted 4 lines
drivers/gpu/drm/drm_modes.c +1
-0+ }if (verbose) {drm_mode_debug_printmodeline (mode); DRM_DEBUG_KMS("Not using %s mode: %s\n",
Does it make sense to keep this line when verbose is set if there's a warn now. Maybe just keep the drm_mode_debug_printmode() but remove the rest ?
I think the patch is good as is too, so regardless you do:
Signature · 5 lines
Best regards, Javier Martinez Canillas Linux Engineering Red Hat
Re: [PATCH 2/3] drm/client: Look for command-line modes first
In reply to Thomas ZimmermannQuoted 7 lines · Thomas Zimmermann
When picking a mode, first look for modes that have been specified by the user on the kernel's command line. Only if that fails, use the existing heuristic of picking a nearby mode from it's various parameters.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Linux Engineering Red Hat
Re: [PATCH 3/3] drm/client: Don't add new command-line mode
In reply to Thomas ZimmermannQuoted 8 lines · Thomas Zimmermann
Don't add a mode for the kernel's command-line parameters from within the DRM client code. Doing so can result in an unusable display. If there's no compatible command-line mode, the client will use one of the connector's preferred modes.
All mode creation and validation has to be performed by the connector. When clients run, the connector's
fill_modescallback has already processes the kernel parameters and validates each
s/process/processed and s/validates/validated ?
or
remove the "has" in the sentence, either work I think.
Quoted 13 lines
mode before adding it. The connector's mode list does not contain invalid modes.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_client_modeset.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)drivers/gpu/drm/drm_client_modeset.c +0
-0
drivers/gpu/drm/drm_client_modeset.c drm_connector_has_preferred_mode(struct drm_connector *connector, int width, int · line 161
Quoted 6 lines
drivers/gpu/drm/drm_client_modeset.c +1
-2@@ -158,8 +158,7 @@ drm_connector_has_preferred_mode(struct drm_connector *connector, int width, intreturn NULL ; } -static struct drm_display_mode * -drm_connector_pick_cmdline_mode (struct drm_connector *connector) +static struct drm_display_mode *drm_connector_pick_cmdline_mode (struct drm_connector *connector)
This seems like an unrelated cleanup.
The rest looks good to me.
Signature · 5 lines
Best regards, Javier Martinez Canillas Linux Engineering Red Hat
Quoted 18 lines · Thomas Zimmermann
Pick user-defined display mode in DRM clients if the mode has been validated by the driver. Otherwise pick a preferred display mode.
Booting the kernel with video=<mode> and giving an unsupported display mode can easily turn the display unusable. This is best tested by booting simpledrm with a display mode that does not use the firmware framebuffer's resolution. While simpledrm filter's out the mode as invalid, the DRM client still picks it and the console won't show up.
Several factors contribute to this problem.
* The connector invalidates the user-defined display mode, but never tells the user about it.
* The DRM client doesn't look for user-defined display modes, but for modes that are similar.
* If no similar mode can be found, the client adds the invalid display mode back to the connector's mode list for use.
Quoted 4 lines
Each of the patches in this patchset addresses one of these problems. Overall the DRM client has no business in display-mode detection and should only pick one of the modes that has been detected and validated by the connector.
That's awesome, thanks!
For the series,
Maxime