Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
[pandora-kernel.git] / arch / powerpc / platforms / cell / spufs / file.c
index c66c375..c7df0a6 100644 (file)
@@ -32,7 +32,6 @@
 #include <linux/marker.h>
 
 #include <asm/io.h>
-#include <asm/semaphore.h>
 #include <asm/spu.h>
 #include <asm/spu_info.h>
 #include <asm/uaccess.h>
@@ -366,6 +365,13 @@ static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
        if (offset >= ps_size)
                return NOPFN_SIGBUS;
 
+       /*
+        * Because we release the mmap_sem, the context may be destroyed while
+        * we're in spu_wait. Grab an extra reference so it isn't destroyed
+        * in the meantime.
+        */
+       get_spu_context(ctx);
+
        /*
         * We have to wait for context to be loaded before we have
         * pages to hand out to the user, but we don't want to wait
@@ -375,7 +381,7 @@ static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
         * hanged.
         */
        if (spu_acquire(ctx))
-               return NOPFN_REFAULT;
+               goto refault;
 
        if (ctx->state == SPU_STATE_SAVED) {
                up_read(&current->mm->mmap_sem);
@@ -391,6 +397,9 @@ static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
 
        if (!ret)
                spu_release(ctx);
+
+refault:
+       put_spu_context(ctx);
        return NOPFN_REFAULT;
 }