diff mbox series

[2/2] drm/etnaviv: reinstate MMUv1 command buffer window check

Message ID 20191016142716.10168-2-l.stach@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series [1/2] drm/etnaviv: fix deadlock in GPU coredump | expand

Commit Message

Lucas Stach Oct. 16, 2019, 2:27 p.m. UTC
The switch to per-process address spaces erroneously dropped the check
which validated that the command buffer is mapped through the linear
apperture as required by the hardware. This turned a system
misconfiguration with a helpful error message into a very hard to
debug issue. Reinstate the check at the appropriate location.

Fixes: 17e4660ae3d7 (drm/etnaviv: implement per-process address spaces on MMUv2)
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Guido Günther Oct. 24, 2019, 8:28 a.m. UTC | #1
Hi Lucas,
On Wed, Oct 16, 2019 at 04:27:16PM +0200, Lucas Stach wrote:
> The switch to per-process address spaces erroneously dropped the check
> which validated that the command buffer is mapped through the linear
> apperture as required by the hardware. This turned a system
> misconfiguration with a helpful error message into a very hard to
> debug issue. Reinstate the check at the appropriate location.
> 
> Fixes: 17e4660ae3d7 (drm/etnaviv: implement per-process address spaces on MMUv2)
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
>  drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
> index 35ebae6a1be7..3607d348c298 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
> @@ -328,12 +328,23 @@ etnaviv_iommu_context_init(struct etnaviv_iommu_global *global,
>  
>  	ret = etnaviv_cmdbuf_suballoc_map(suballoc, ctx, &ctx->cmdbuf_mapping,
>  					  global->memory_base);
> -	if (ret) {
> -		global->ops->free(ctx);
> -		return NULL;
> +	if (ret)
> +		goto out_free;
> +
> +	if (global->version == ETNAVIV_IOMMU_V1 &&
> +	    ctx->cmdbuf_mapping.iova > 0x80000000) {
> +		dev_err(global->dev,
> +		        "command buffer outside valid memory window\n");
> +		goto out_unmap;
>  	}
>  
>  	return ctx;
> +
> +out_unmap:
> +	etnaviv_cmdbuf_suballoc_unmap(ctx, &ctx->cmdbuf_mapping);
> +out_free:
> +	global->ops->free(ctx);
> +	return NULL;
>  }
>  
>  void etnaviv_iommu_restore(struct etnaviv_gpu *gpu,

Reviewed-by: Guido Günther <agx@sigxcpu.org>

Cheers,
 -- Guido

> -- 
> 2.20.1
> 
> _______________________________________________
> etnaviv mailing list
> etnaviv@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv
diff mbox series

Patch

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
index 35ebae6a1be7..3607d348c298 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
@@ -328,12 +328,23 @@  etnaviv_iommu_context_init(struct etnaviv_iommu_global *global,
 
 	ret = etnaviv_cmdbuf_suballoc_map(suballoc, ctx, &ctx->cmdbuf_mapping,
 					  global->memory_base);
-	if (ret) {
-		global->ops->free(ctx);
-		return NULL;
+	if (ret)
+		goto out_free;
+
+	if (global->version == ETNAVIV_IOMMU_V1 &&
+	    ctx->cmdbuf_mapping.iova > 0x80000000) {
+		dev_err(global->dev,
+		        "command buffer outside valid memory window\n");
+		goto out_unmap;
 	}
 
 	return ctx;
+
+out_unmap:
+	etnaviv_cmdbuf_suballoc_unmap(ctx, &ctx->cmdbuf_mapping);
+out_free:
+	global->ops->free(ctx);
+	return NULL;
 }
 
 void etnaviv_iommu_restore(struct etnaviv_gpu *gpu,