[POWERPC] Fix idr locking in init_new_context
[linux-2.6/linux-2.6-openrd.git] / arch / powerpc / mm / mmu_context_64.c
blobe2051efa09c58d413d95814615c94f2d683b8b22
1 /*
2 * MMU context allocation for 64-bit kernels.
4 * Copyright (C) 2004 Anton Blanchard, IBM Corp. <anton@samba.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/types.h>
19 #include <linux/mm.h>
20 #include <linux/spinlock.h>
21 #include <linux/idr.h>
23 #include <asm/mmu_context.h>
25 static DEFINE_SPINLOCK(mmu_context_lock);
26 static DEFINE_IDR(mmu_context_idr);
28 int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
30 int index;
31 int err;
33 again:
34 if (!idr_pre_get(&mmu_context_idr, GFP_KERNEL))
35 return -ENOMEM;
37 spin_lock(&mmu_context_lock);
38 err = idr_get_new_above(&mmu_context_idr, NULL, 1, &index);
39 spin_unlock(&mmu_context_lock);
41 if (err == -EAGAIN)
42 goto again;
43 else if (err)
44 return err;
46 if (index > MAX_CONTEXT) {
47 spin_lock(&mmu_context_lock);
48 idr_remove(&mmu_context_idr, index);
49 spin_unlock(&mmu_context_lock);
50 return -ENOMEM;
53 mm->context.id = index;
54 mm->context.user_psize = mmu_virtual_psize;
55 mm->context.sllp = SLB_VSID_USER |
56 mmu_psize_defs[mmu_virtual_psize].sllp;
58 return 0;
61 void destroy_context(struct mm_struct *mm)
63 spin_lock(&mmu_context_lock);
64 idr_remove(&mmu_context_idr, mm->context.id);
65 spin_unlock(&mmu_context_lock);
67 mm->context.id = NO_CONTEXT;