MGS-2857 [#imx-530] fix spinlock in gpu kernel driver
authorXianzhong <xianzhong.li@nxp.com>
Tue, 2 May 2017 07:41:18 +0000 (15:41 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:22:05 +0000 (15:22 -0500)
there are two critical problems with spinlock in gpu driver:
1. spin_unlock is missing when pte_offset_map_lock return invalid pte pointer,
this will cause dead lock in stress case.
2. pte_unmap is missing in spinlock debug build, this will cause kernel panic,
which can be reproduced when enable CONFIG_DEBUG_SPINLOCK in kernel build.

Date: May 02, 2017
Signed-off-by: Xianzhong <xianzhong.li@nxp.com>
drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c

index b348ac1..3ef1650 100644 (file)
@@ -366,7 +366,7 @@ _QueryProcessPageTable(
     )
 {
 #ifndef CONFIG_DEBUG_SPINLOCK
-    spinlock_t *lock;
+    spinlock_t *lock = NULL;
 #endif
     gctUINTPTR_T logical = (gctUINTPTR_T)Logical;
     pgd_t *pgd;
@@ -415,6 +415,14 @@ _QueryProcessPageTable(
 
     if (!pte)
     {
+#ifndef CONFIG_DEBUG_SPINLOCK
+        if (lock)
+        {
+            spin_unlock(lock);
+        }
+#else
+        spin_unlock(&current->mm->page_table_lock);
+#endif
         return gcvSTATUS_NOT_FOUND;
     }
 
@@ -423,6 +431,7 @@ _QueryProcessPageTable(
 #ifndef CONFIG_DEBUG_SPINLOCK
         pte_unmap_unlock(pte, lock);
 #else
+        pte_unmap(pte);
         spin_unlock(&current->mm->page_table_lock);
 #endif
         return gcvSTATUS_NOT_FOUND;
@@ -432,6 +441,7 @@ _QueryProcessPageTable(
 #ifndef CONFIG_DEBUG_SPINLOCK
     pte_unmap_unlock(pte, lock);
 #else
+    pte_unmap(pte);
     spin_unlock(&current->mm->page_table_lock);
 #endif