drm/etnaviv: check for reaped mapping in etnaviv_iommu_unmap_gem
authorLucas Stach <l.stach@pengutronix.de>
Wed, 23 Mar 2022 16:08:22 +0000 (17:08 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Wed, 13 Mar 2024 06:58:52 +0000 (15:58 +0900)
commit e168c25526cd0368af098095c2ded4a008007e1b upstream.

When the mapping is already reaped the unmap must be a no-op, as we
would otherwise try to remove the mapping twice, corrupting the involved
data structures.

Cc: stable@vger.kernel.org # 5.4
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Tested-by: Guido Günther <agx@sigxcpu.org>
Acked-by: Guido Günther <agx@sigxcpu.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 58f804da14e05700baa328bf20a26e31db66efbd)
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/gpu/drm/etnaviv/etnaviv_mmu.c

index 984569a59a90a250a84d3fec4feb9ceb5e92503e..9ba2fe48228f1af032330a4bf87d10ec89e0f058 100644 (file)
@@ -282,6 +282,12 @@ void etnaviv_iommu_unmap_gem(struct etnaviv_iommu_context *context,
 
        mutex_lock(&context->lock);
 
+       /* Bail if the mapping has been reaped by another thread */
+       if (!mapping->context) {
+               mutex_unlock(&context->lock);
+               return;
+       }
+
        /* If the vram node is on the mm, unmap and remove the node */
        if (mapping->vram_node.mm == &context->mm)
                etnaviv_iommu_remove_mapping(context, mapping);