dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm/ast: Fix modeset failed on DisplayPort
@ 2023-05-25  1:29 Jammy Huang
  2023-05-31 10:51 ` Thomas Zimmermann
  0 siblings, 1 reply; 2+ messages in thread
From: Jammy Huang @ 2023-05-25  1:29 UTC (permalink / raw)
  To: tzimmermann, airlied, airlied, daniel; +Cc: linux-kernel, dri-devel

If we switch display and update cursor together, it could lead to
modeset failed because of concurrent access to IO registers.

Add lock protection in DP's edid access to avoid this problem.

Signed-off-by: Jammy Huang <jammy_huang@aspeedtech.com>
---
 v2 changes:
  - Fix build error since new struct ast_device is used.
---
 drivers/gpu/drm/ast/ast_mode.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 36374828f6c8..9fcbf540d6fc 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -1647,6 +1647,8 @@ static int ast_dp501_output_init(struct ast_device *ast)
 static int ast_astdp_connector_helper_get_modes(struct drm_connector *connector)
 {
 	void *edid;
+	struct drm_device *dev = connector->dev;
+	struct ast_device *ast = to_ast_device(dev);
 
 	int succ;
 	int count;
@@ -1655,10 +1657,18 @@ static int ast_astdp_connector_helper_get_modes(struct drm_connector *connector)
 	if (!edid)
 		goto err_drm_connector_update_edid_property;
 
+	/*
+	 * Protect access to I/O registers from concurrent modesetting
+	 * by acquiring the I/O-register lock.
+	 */
+	mutex_lock(&ast->ioregs_lock);
+
 	succ = ast_astdp_read_edid(connector->dev, edid);
 	if (succ < 0)
 		goto err_kfree;
 
+	mutex_unlock(&ast->ioregs_lock);
+
 	drm_connector_update_edid_property(connector, edid);
 	count = drm_add_edid_modes(connector, edid);
 	kfree(edid);
@@ -1666,6 +1676,7 @@ static int ast_astdp_connector_helper_get_modes(struct drm_connector *connector)
 	return count;
 
 err_kfree:
+	mutex_unlock(&ast->ioregs_lock);
 	kfree(edid);
 err_drm_connector_update_edid_property:
 	drm_connector_update_edid_property(connector, NULL);

base-commit: 933174ae28ba72ab8de5b35cb7c98fc211235096
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] drm/ast: Fix modeset failed on DisplayPort
  2023-05-25  1:29 [PATCH v2] drm/ast: Fix modeset failed on DisplayPort Jammy Huang
@ 2023-05-31 10:51 ` Thomas Zimmermann
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Zimmermann @ 2023-05-31 10:51 UTC (permalink / raw)
  To: Jammy Huang, airlied, airlied, daniel; +Cc: linux-kernel, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 2437 bytes --]

Hi Jammy

Am 25.05.23 um 03:29 schrieb Jammy Huang:
> If we switch display and update cursor together, it could lead to
> modeset failed because of concurrent access to IO registers.
> 
> Add lock protection in DP's edid access to avoid this problem.
> 
> Signed-off-by: Jammy Huang <jammy_huang@aspeedtech.com>
> ---
>   v2 changes:
>    - Fix build error since new struct ast_device is used.
> ---
>   drivers/gpu/drm/ast/ast_mode.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> index 36374828f6c8..9fcbf540d6fc 100644
> --- a/drivers/gpu/drm/ast/ast_mode.c
> +++ b/drivers/gpu/drm/ast/ast_mode.c
> @@ -1647,6 +1647,8 @@ static int ast_dp501_output_init(struct ast_device *ast)
>   static int ast_astdp_connector_helper_get_modes(struct drm_connector *connector)
>   {
>   	void *edid;
> +	struct drm_device *dev = connector->dev;
> +	struct ast_device *ast = to_ast_device(dev);
>   
>   	int succ;
>   	int count;
> @@ -1655,10 +1657,18 @@ static int ast_astdp_connector_helper_get_modes(struct drm_connector *connector)
>   	if (!edid)
>   		goto err_drm_connector_update_edid_property;
>   
> +	/*
> +	 * Protect access to I/O registers from concurrent modesetting
> +	 * by acquiring the I/O-register lock.
> +	 */
> +	mutex_lock(&ast->ioregs_lock);
> +
>   	succ = ast_astdp_read_edid(connector->dev, edid);
>   	if (succ < 0)
>   		goto err_kfree;
>   
> +	mutex_unlock(&ast->ioregs_lock);
> +
>   	drm_connector_update_edid_property(connector, edid);
>   	count = drm_add_edid_modes(connector, edid);
>   	kfree(edid);
> @@ -1666,6 +1676,7 @@ static int ast_astdp_connector_helper_get_modes(struct drm_connector *connector)
>   	return count;
>   
>   err_kfree:

This label needs to be named 'err_mutex_unlock' please. With that fixed, 
you can add

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

Best regards
Thomas

> +	mutex_unlock(&ast->ioregs_lock);
>   	kfree(edid);
>   err_drm_connector_update_edid_property:
>   	drm_connector_update_edid_property(connector, NULL);
> 
> base-commit: 933174ae28ba72ab8de5b35cb7c98fc211235096

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-31 10:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-25  1:29 [PATCH v2] drm/ast: Fix modeset failed on DisplayPort Jammy Huang
2023-05-31 10:51 ` Thomas Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).