Skip to contentSkip to conversation

drm/lima: two driver cleanups

PATCH Applied Erico Nunes 2 participants 5 messages Apr 1, 2024 – Apr 15, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drm/lima: two driver cleanups

Patch 1 is a fix for a crash which triggers on removing the module on kernels with CONFIG_DEBUG_SHIRQ enabled, such as the Fedora kernel.

Patch 2 is a fix to this warning:
drivers/gpu/drm/lima/lima_drv.c:387:13: error: cast to smaller integer type 'enum lima_gpu_id' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
which we have received as a repeated report from the kernel test bot to the lima mailing list.
The warning only reproduces with recent clang on aarch64, but the patch does get rid of it and there seem to be no more warnings for W=1.

Erico Nunes (2):
drm/lima: fix shared irq handling on driver remove drm/lima: fix void pointer to enum lima_gpu_id cast warning

 drivers/gpu/drm/lima/lima_drv.c | 21 ++++++++++++++++++---
 drivers/gpu/drm/lima/lima_drv.h |  5 +++++
 drivers/gpu/drm/lima/lima_gp.c  |  2 ++
 drivers/gpu/drm/lima/lima_mmu.c |  5 +++++
 drivers/gpu/drm/lima/lima_pp.c  |  4 ++++
 5 files changed, 34 insertions(+), 3 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/2 drm/lima: fix shared irq handling on driver remove

lima uses a shared interrupt, so the interrupt handlers must be prepared to be called at any time. At driver removal time, the clocks are disabled early and the interrupts stay registered until the very end of the remove process due to the devm usage.
This is potentially a bug as the interrupts access device registers which assumes clocks are enabled. A crash can be triggered by removing the driver in a kernel with CONFIG_DEBUG_SHIRQ enabled.
This patch frees the interrupts at each lima device finishing callback so that the handlers are already unregistered by the time we fully disable clocks.

---
 drivers/gpu/drm/lima/lima_gp.c  | 2 ++
 drivers/gpu/drm/lima/lima_mmu.c | 5 +++++
 drivers/gpu/drm/lima/lima_pp.c  | 4 ++++
 3 files changed, 11 insertions(+)
drivers/gpu/drm/lima/lima_gp.c +2 -0
index 6b354e2fb61d..14c39be8da90 100644
@@ -338,7 +338,9 @@ int lima_gp_init(struct lima_ip *ip)
 
 void lima_gp_fini(struct lima_ip *ip)
 {
+	struct lima_device *dev = ip->dev;
 
+	devm_free_irq(dev->dev, ip->irq, ip);
 }
 
 int lima_gp_pipe_init(struct lima_device *dev)
drivers/gpu/drm/lima/lima_mmu.c +5 -0
index e18317c5ca8c..6611e2836bf0 100644
@@ -118,7 +118,12 @@ int lima_mmu_init(struct lima_ip *ip)
 
 void lima_mmu_fini(struct lima_ip *ip)
 {
+	struct lima_device *dev = ip->dev;
+
+	if (ip->id == lima_ip_ppmmu_bcast)
+		return;
 
+	devm_free_irq(dev->dev, ip->irq, ip);
 }
 
 void lima_mmu_flush_tlb(struct lima_ip *ip)
drivers/gpu/drm/lima/lima_pp.c +4 -0
index d0d2db0ef1ce..84bec163c9ed 100644
@@ -286,7 +286,9 @@ int lima_pp_init(struct lima_ip *ip)
 
 void lima_pp_fini(struct lima_ip *ip)
 {
+	struct lima_device *dev = ip->dev;
 
+	devm_free_irq(dev->dev, ip->irq, ip);
 }
 
 int lima_pp_bcast_resume(struct lima_ip *ip)
@@ -319,7 +321,9 @@ int lima_pp_bcast_init(struct lima_ip *ip)
 
 void lima_pp_bcast_fini(struct lima_ip *ip)
 {
+	struct lima_device *dev = ip->dev;
 
+	devm_free_irq(dev->dev, ip->irq, ip);
 }
 
 static int lima_pp_task_validate(struct lima_sched_pipe *pipe,
Signature · 1 line
2.44.0
#2 lore raw

PATCH 2/2 drm/lima: fix void pointer to enum lima_gpu_id cast warning

In reply to Erico Nunes

Create a simple data struct to hold compatible data so that we don't have to do the casts to void pointer to hold data.
Fixes the following warning:
drivers/gpu/drm/lima/lima_drv.c:387:13: error: cast to smaller integer type 'enum lima_gpu_id' from 'const void *'

---
 drivers/gpu/drm/lima/lima_drv.c | 21 ++++++++++++++++++---
 drivers/gpu/drm/lima/lima_drv.h |  5 +++++
 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/gpu/drm/lima/lima_drv.c +18 -3
index 10fd9154cc46..739c865b556f 100644
@@ -371,6 +371,7 @@ static int lima_pdev_probe(struct platform_device *pdev)
 {
 	struct lima_device *ldev;
 	struct drm_device *ddev;
+	const struct lima_compatible *comp;
 	int err;
 
 	err = lima_sched_slab_init();
@@ -384,7 +385,13 @@ static int lima_pdev_probe(struct platform_device *pdev)
 	}
 
 	ldev->dev = &pdev->dev;
-	ldev->id = (enum lima_gpu_id)of_device_get_match_data(&pdev->dev);
+	comp = of_device_get_match_data(&pdev->dev);
+	if (!comp) {
+		err = -ENODEV;
+		goto err_out0;
+	}
+
+	ldev->id = comp->id;
 
 	platform_set_drvdata(pdev, ldev);
 
@@ -459,9 +466,17 @@ static void lima_pdev_remove(struct platform_device *pdev)
 	lima_sched_slab_fini();
 }
 
+static const struct lima_compatible lima_mali400_data = {
+	.id = lima_gpu_mali400,
+};
+
+static const struct lima_compatible lima_mali450_data = {
+	.id = lima_gpu_mali450,
+};
+
 static const struct of_device_id dt_match[] = {
-	{ .compatible = "arm,mali-400", .data = (void *)lima_gpu_mali400 },
-	{ .compatible = "arm,mali-450", .data = (void *)lima_gpu_mali450 },
+	{ .compatible = "arm,mali-400", .data = &lima_mali400_data },
+	{ .compatible = "arm,mali-450", .data = &lima_mali450_data },
 	{}
 };
 MODULE_DEVICE_TABLE(of, dt_match);
drivers/gpu/drm/lima/lima_drv.h +5 -0
index c738d288547b..6706c19b166e 100644
@@ -7,6 +7,7 @@
 #include <drm/drm_file.h>
 
 #include "lima_ctx.h"
+#include "lima_device.h"
 
 extern int lima_sched_timeout_ms;
 extern uint lima_heap_init_nr_pages;
@@ -39,6 +40,10 @@ struct lima_submit {
 	struct lima_sched_task *task;
 };
 
+struct lima_compatible {
+	enum lima_gpu_id id;
+};
+
 static inline struct lima_drm_priv *
 to_lima_drm_priv(struct drm_file *file)
 {
Signature · 1 line
2.44.0
maintainer
#3 lore raw
In reply to Erico Nunes

Serial is Reviewed-by: Qiang Yu <[email protected]>

Quoted 27 lines · Erico Nunes

Patch 1 is a fix for a crash which triggers on removing the module on kernels with CONFIG_DEBUG_SHIRQ enabled, such as the Fedora kernel.

Patch 2 is a fix to this warning:
drivers/gpu/drm/lima/lima_drv.c:387:13: error: cast to smaller integer type 'enum lima_gpu_id' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
which we have received as a repeated report from the kernel test bot to the lima mailing list.
The warning only reproduces with recent clang on aarch64, but the patch does get rid of it and there seem to be no more warnings for W=1.

Erico Nunes (2):
drm/lima: fix shared irq handling on driver remove drm/lima: fix void pointer to enum lima_gpu_id cast warning

 drivers/gpu/drm/lima/lima_drv.c | 21 ++++++++++++++++++---
 drivers/gpu/drm/lima/lima_drv.h |  5 +++++
 drivers/gpu/drm/lima/lima_gp.c  |  2 ++
 drivers/gpu/drm/lima/lima_mmu.c |  5 +++++
 drivers/gpu/drm/lima/lima_pp.c  |  4 ++++
 5 files changed, 34 insertions(+), 3 deletions(-)

--
2.44.0

maintainer Applied
#4 lore raw

applied to drm-misc-next

Quoted 31 lines · Qiang Yu

Serial is Reviewed-by: Qiang Yu <[email protected]>

Quoted 27 lines · Erico Nunes

Patch 1 is a fix for a crash which triggers on removing the module on kernels with CONFIG_DEBUG_SHIRQ enabled, such as the Fedora kernel.

Patch 2 is a fix to this warning:
drivers/gpu/drm/lima/lima_drv.c:387:13: error: cast to smaller integer type 'enum lima_gpu_id' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
which we have received as a repeated report from the kernel test bot to the lima mailing list.
The warning only reproduces with recent clang on aarch64, but the patch does get rid of it and there seem to be no more warnings for W=1.

Erico Nunes (2):
drm/lima: fix shared irq handling on driver remove drm/lima: fix void pointer to enum lima_gpu_id cast warning

 drivers/gpu/drm/lima/lima_drv.c | 21 ++++++++++++++++++---
 drivers/gpu/drm/lima/lima_drv.h |  5 +++++
 drivers/gpu/drm/lima/lima_gp.c  |  2 ++
 drivers/gpu/drm/lima/lima_mmu.c |  5 +++++
 drivers/gpu/drm/lima/lima_pp.c  |  4 ++++
 5 files changed, 34 insertions(+), 3 deletions(-)

--
2.44.0