Skip to contentSkip to conversation

gpu: host1x: fix error return code in host1x_memory_context_list_init()

PATCH RESEND In review Yang Yingliang 2 participants 3 messages Nov 24, 2022 – Nov 26, 2022

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

PATCH RESEND 1/1 gpu: host1x: fix error return code in host1x_memory_context_list_init()

If context device has no IOMMU, the 'cdl->devs' is freed in error path, but host1x_memory_context_list_init() doesn't return an error code, so the module can be loaded successfully, when it's unloading, the host1x_memory_context_list_free() is called in host1x_remove(), it will cause double free. Return an error code to fix this.

Fixes 8aa5bcb61612 ("gpu: host1x: Add context device management code")

---
The previous patch link:
https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/host1x/context.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/host1x/context.c +1 -0
index b08cf11f9a66..5cf9b98bedd0 100644
@@ -74,6 +74,7 @@ int host1x_memory_context_list_init(struct host1x *host1x)
 		if (!fwspec || !device_iommu_mapped(&ctx->dev)) {
 			dev_err(host1x->dev, "Context device %d has no IOMMU!\n", i);
 			device_del(&ctx->dev);
+			err = -EOPNOTSUPP;
 			goto del_devices;
 		}
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 20 lines · Yang Yingliang

If context device has no IOMMU, the 'cdl->devs' is freed in error path, but host1x_memory_context_list_init() doesn't return an error code, so the module can be loaded successfully, when it's unloading, the host1x_memory_context_list_free() is called in host1x_remove(), it will cause double free. Return an error code to fix this.

Fixes 8aa5bcb61612 ("gpu: host1x: Add context device management code")

---
The previous patch link:
https://lore.kernel.org/lkml/[email protected]/

---
  drivers/gpu/host1x/context.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/host1x/context.c +0 -0
index b08cf11f9a66..5cf9b98bedd0 100644

drivers/gpu/host1x/context.c int host1x_memory_context_list_init(struct host1x *host1x) · line 80

Quoted 7 lines
drivers/gpu/host1x/context.c +1 -0
@@ -74,6 +74,7 @@ int host1x_memory_context_list_init(struct host1x *host1x)
  		if (!fwspec || !device_iommu_mapped(&ctx->dev)) {
  			dev_err(host1x->dev, "Context device %d has no IOMMU!\n", i);
  			device_del(&ctx->dev);
+			err = -EOPNOTSUPP;
  			goto del_devices;
  		}
 

One side effect of this patch would be that if IOMMU is disabled on a system with context devices defined, Host1x won't work at all (currently probe continues and it works though without context isolation).

I'm not sure if that's something anyone is likely to run into, but it might be better to get rid of one of the frees instead.

If you can update with that that'd be great, or I can put it onto the TODO list.

Thanks,
Mikko

#2 lore raw
Quoted 32 lines · Mikko Perttunen
Quoted 21 lines · Yang Yingliang

If context device has no IOMMU, the 'cdl->devs' is freed in error path, but host1x_memory_context_list_init() doesn't return an error code, so the module can be loaded successfully, when it's unloading, the host1x_memory_context_list_free() is called in host1x_remove(), it will cause double free. Return an error code to fix this.

Fixes 8aa5bcb61612 ("gpu: host1x: Add context device management code")

---
The previous patch link:
https://lore.kernel.org/lkml/[email protected]/

---
  drivers/gpu/host1x/context.c | 1 +

  1 file changed, 1 insertion(+)
drivers/gpu/host1x/context.c +0 -0
index b08cf11f9a66..5cf9b98bedd0 100644

drivers/gpu/host1x/context.c int host1x_memory_context_list_init(struct host1x · line 80

Quoted 7 lines
drivers/gpu/host1x/context.c +1 -0
@@ -74,6 +74,7 @@ int host1x_memory_context_list_init(struct host1x 
 *host1x)
           if (!fwspec || !device_iommu_mapped(&ctx->dev)) {
               dev_err(host1x->dev, "Context device %d has no IOMMU!\n", i);
               device_del(&ctx->dev);
+            err = -EOPNOTSUPP;
               goto del_devices;
           }

One side effect of this patch would be that if IOMMU is disabled on a system with context devices defined, Host1x won't work at all (currently probe continues and it works though without context isolation).

Quoted 3 lines

I'm not sure if that's something anyone is likely to run into, but it might be better to get rid of one of the frees instead.

If you can update with that that'd be great, or I can put it onto the TODO list.

I can send a v2 later.

Thanks,
Yang

Quoted 4 lines

Thanks,
Mikko
.