During an earlier cleanup, we lost the serialization
of multiple spu_run calls performed on the same
spu_context. In order to get this back, introduce a
mutex in the spu_context that is held inside of spu_run.
Noticed by Al Viro.
Signed-off-by: Arnd Bergmann <arndb@de.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
        spin_lock_init(&ctx->mmio_lock);
        kref_init(&ctx->kref);
        init_rwsem(&ctx->state_sema);
+       init_MUTEX(&ctx->run_sema);
        init_waitqueue_head(&ctx->ibox_wq);
        init_waitqueue_head(&ctx->wbox_wq);
        init_waitqueue_head(&ctx->stop_wq);
 
 {
        int ret;
 
-       if ((ret = spu_run_init(ctx, npc, status)) != 0)
-               return ret;
+       if (down_interruptible(&ctx->run_sema))
+               return -ERESTARTSYS;
+
+       ret = spu_run_init(ctx, npc, status);
+       if (ret)
+               goto out;
 
        do {
                ret = spufs_wait(ctx->stop_wq, spu_stopped(ctx, status));
                        break;
                if (unlikely(ctx->state != SPU_STATE_RUNNABLE)) {
                        ret = spu_reacquire_runnable(ctx, npc, status);
-                       if (ret) {
-                               return ret;
-                       }
+                       if (ret)
+                               goto out;
                        continue;
                }
                ret = spu_process_events(ctx);
                ret = *status;
        spu_yield(ctx);
 
+out:
+       up(&ctx->run_sema);
        return ret;
 }
 
 
 
        enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
        struct rw_semaphore state_sema;
+       struct semaphore run_sema;
 
        struct mm_struct *owner;