b/arch/powerpc/platforms/cell/spufs/context.c
@@ -57,6 +57,17 @@ struct spu_context *alloc_spu_context(struct spu_gang
*gang)
if (spu_init_csa(&ctx->csa))
goto out_free_gang;
+ /* If the gang is running, it needs to be stopped, since we have a
+ * new context that needs to be gang scheduled. Gangs are allowed
+ * to grow and shrink over time, but they are unscheduled when it
+ * happens as the gang may need to migrated to a different node.
+ */
+ if (atomic_read(&gang->nstarted)) {
+ mutex_lock(&gang->mutex);
+ spu_deactivate(gang);
+ mutex_unlock(&gang->mutex);
+ }
+
spin_lock_init(&ctx->mmio_lock);
mutex_init(&ctx->mapping_lock);