drm/etnaviv: reap idle mapping if it doesn't match the softpin address
authorLucas Stach <l.stach@pengutronix.de>
Thu, 14 Jul 2022 10:31:43 +0000 (12:31 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Wed, 13 Mar 2024 06:58:55 +0000 (15:58 +0900)
When a idle BO, which is held open by another process, gets freed by
userspace and subsequently referenced again by e.g. importing it again,
userspace may assign a different softpin VA than the last time around.
As the kernel GEM object still exists, we likely have a idle mapping
with the old VA still cached, if it hasn't been reaped in the meantime.

As the context matches, we then simply try to resurrect this mapping by
increasing the refcount. As the VA in this mapping does not match the
new softpin address, we consequently fail the otherwise valid submit.
Instead of failing, reap the idle mapping.

Cc: stable@vger.kernel.org # 5.19
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Guido Günther <agx@sigxcpu.org>
(cherry picked from commit 51464f659288061a1e3a85689bb0c04d8e92f92a)
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/gpu/drm/etnaviv/etnaviv_gem.c

index 6e2bbb19650a38b54ed755f3fdd68827573ff0ec..e3dea85451c621fd79cb5a4c985e3011ddba6b96 100644 (file)
@@ -269,7 +269,12 @@ struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
                if (mapping->use == 0) {
                        mutex_lock(&mmu_context->lock);
                        if (mapping->context == mmu_context)
-                               mapping->use += 1;
+                               if (va && mapping->iova != va) {
+                                       etnaviv_iommu_reap_mapping(mapping);
+                                       mapping = NULL;
+                               } else {
+                                       mapping->use += 1;
+                               }
                        else
                                mapping = NULL;
                        mutex_unlock(&mmu_context->lock);