--- kernel/vcontext.c.orig Fri Nov 21 21:56:46 2003 +++ kernel/vcontext.c Wed Nov 26 16:37:07 2003 @@ -217,19 +217,21 @@ int vc_new_s_context(uint32_t ctx, void /* it. Wrap around possible, so we loop */ static int alloc_ctx = MIN_D_CONTEXT; static spinlock_t alloc_ctx_lock = SPIN_LOCK_UNLOCKED; + int barrier = alloc_ctx; spin_lock(&alloc_ctx_lock); while (1) { int found = 0; struct task_struct *p; - alloc_ctx++; - /* The vx_id 1 is special. It sess all processes */ - if (alloc_ctx == 1) - alloc_ctx++; - else if (alloc_ctx > MAX_S_CONTEXT) + if (++alloc_ctx > MAX_S_CONTEXT) // No need to grow and grow alloc_ctx = MIN_D_CONTEXT; + if (barrier == alloc_ctx) { + ret = -EDEADLK; + goto unlock; + } + /* Check if in use */ read_lock(&tasklist_lock); for_each_task(p) { @@ -239,7 +241,8 @@ int vc_new_s_context(uint32_t ctx, void } } read_unlock(&tasklist_lock); - if (!found) break; + if (!found) + break; } ret = vx_switch_user_struct(alloc_ctx); if (ret == 0) { @@ -252,6 +255,7 @@ int vc_new_s_context(uint32_t ctx, void current->s_info->flags |= vc_data.flags; } } + unlock: spin_unlock(&alloc_ctx_lock); } } else if (ctx == -2) {