diff options
| author | Dave Kleikamp <shaggy@austin.ibm.com> | 2006-03-14 18:05:45 -0500 |
|---|---|---|
| committer | Dave Kleikamp <shaggy@austin.ibm.com> | 2006-03-14 18:05:45 -0500 |
| commit | c5111f504d2a9b0d258d7c4752b4093523315989 (patch) | |
| tree | 6a52864aff79691689aea21cb0cb928327d5de5b /kernel/user.c | |
| parent | 69eb66d7da7dba2696281981347698e1693c2340 (diff) | |
| parent | a488edc914aa1d766a4e2c982b5ae03d5657ec1b (diff) | |
Merge with /home/shaggy/git/linus-clean/
Diffstat (limited to 'kernel/user.c')
| -rw-r--r-- | kernel/user.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/kernel/user.c b/kernel/user.c index 89e562feb1b1..d9deae43a9ab 100644 --- a/kernel/user.c +++ b/kernel/user.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
| 14 | #include <linux/bitops.h> | 14 | #include <linux/bitops.h> |
| 15 | #include <linux/key.h> | 15 | #include <linux/key.h> |
| 16 | #include <linux/interrupt.h> | ||
| 16 | 17 | ||
| 17 | /* | 18 | /* |
| 18 | * UID task count cache, to get fast user lookup in "alloc_uid" | 19 | * UID task count cache, to get fast user lookup in "alloc_uid" |
| @@ -27,6 +28,16 @@ | |||
| 27 | 28 | ||
| 28 | static kmem_cache_t *uid_cachep; | 29 | static kmem_cache_t *uid_cachep; |
| 29 | static struct list_head uidhash_table[UIDHASH_SZ]; | 30 | static struct list_head uidhash_table[UIDHASH_SZ]; |
| 31 | |||
| 32 | /* | ||
| 33 | * The uidhash_lock is mostly taken from process context, but it is | ||
| 34 | * occasionally also taken from softirq/tasklet context, when | ||
| 35 | * task-structs get RCU-freed. Hence all locking must be softirq-safe. | ||
| 36 | * But free_uid() is also called with local interrupts disabled, and running | ||
| 37 | * local_bh_enable() with local interrupts disabled is an error - we'll run | ||
| 38 | * softirq callbacks, and they can unconditionally enable interrupts, and | ||
| 39 | * the caller of free_uid() didn't expect that.. | ||
| 40 | */ | ||
| 30 | static DEFINE_SPINLOCK(uidhash_lock); | 41 | static DEFINE_SPINLOCK(uidhash_lock); |
| 31 | 42 | ||
| 32 | struct user_struct root_user = { | 43 | struct user_struct root_user = { |
| @@ -82,15 +93,19 @@ static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *has | |||
| 82 | struct user_struct *find_user(uid_t uid) | 93 | struct user_struct *find_user(uid_t uid) |
| 83 | { | 94 | { |
| 84 | struct user_struct *ret; | 95 | struct user_struct *ret; |
| 96 | unsigned long flags; | ||
| 85 | 97 | ||
| 86 | spin_lock(&uidhash_lock); | 98 | spin_lock_irqsave(&uidhash_lock, flags); |
| 87 | ret = uid_hash_find(uid, uidhashentry(uid)); | 99 | ret = uid_hash_find(uid, uidhashentry(uid)); |
| 88 | spin_unlock(&uidhash_lock); | 100 | spin_unlock_irqrestore(&uidhash_lock, flags); |
| 89 | return ret; | 101 | return ret; |
| 90 | } | 102 | } |
| 91 | 103 | ||
| 92 | void free_uid(struct user_struct *up) | 104 | void free_uid(struct user_struct *up) |
| 93 | { | 105 | { |
| 106 | unsigned long flags; | ||
| 107 | |||
| 108 | local_irq_save(flags); | ||
| 94 | if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) { | 109 | if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) { |
| 95 | uid_hash_remove(up); | 110 | uid_hash_remove(up); |
| 96 | key_put(up->uid_keyring); | 111 | key_put(up->uid_keyring); |
| @@ -98,6 +113,7 @@ void free_uid(struct user_struct *up) | |||
| 98 | kmem_cache_free(uid_cachep, up); | 113 | kmem_cache_free(uid_cachep, up); |
| 99 | spin_unlock(&uidhash_lock); | 114 | spin_unlock(&uidhash_lock); |
| 100 | } | 115 | } |
| 116 | local_irq_restore(flags); | ||
| 101 | } | 117 | } |
| 102 | 118 | ||
| 103 | struct user_struct * alloc_uid(uid_t uid) | 119 | struct user_struct * alloc_uid(uid_t uid) |
| @@ -105,9 +121,9 @@ struct user_struct * alloc_uid(uid_t uid) | |||
| 105 | struct list_head *hashent = uidhashentry(uid); | 121 | struct list_head *hashent = uidhashentry(uid); |
| 106 | struct user_struct *up; | 122 | struct user_struct *up; |
| 107 | 123 | ||
| 108 | spin_lock(&uidhash_lock); | 124 | spin_lock_irq(&uidhash_lock); |
| 109 | up = uid_hash_find(uid, hashent); | 125 | up = uid_hash_find(uid, hashent); |
| 110 | spin_unlock(&uidhash_lock); | 126 | spin_unlock_irq(&uidhash_lock); |
| 111 | 127 | ||
| 112 | if (!up) { | 128 | if (!up) { |
| 113 | struct user_struct *new; | 129 | struct user_struct *new; |
| @@ -137,7 +153,7 @@ struct user_struct * alloc_uid(uid_t uid) | |||
| 137 | * Before adding this, check whether we raced | 153 | * Before adding this, check whether we raced |
| 138 | * on adding the same user already.. | 154 | * on adding the same user already.. |
| 139 | */ | 155 | */ |
| 140 | spin_lock(&uidhash_lock); | 156 | spin_lock_irq(&uidhash_lock); |
| 141 | up = uid_hash_find(uid, hashent); | 157 | up = uid_hash_find(uid, hashent); |
| 142 | if (up) { | 158 | if (up) { |
| 143 | key_put(new->uid_keyring); | 159 | key_put(new->uid_keyring); |
| @@ -147,7 +163,7 @@ struct user_struct * alloc_uid(uid_t uid) | |||
| 147 | uid_hash_insert(new, hashent); | 163 | uid_hash_insert(new, hashent); |
| 148 | up = new; | 164 | up = new; |
| 149 | } | 165 | } |
| 150 | spin_unlock(&uidhash_lock); | 166 | spin_unlock_irq(&uidhash_lock); |
| 151 | 167 | ||
| 152 | } | 168 | } |
| 153 | return up; | 169 | return up; |
| @@ -183,9 +199,9 @@ static int __init uid_cache_init(void) | |||
| 183 | INIT_LIST_HEAD(uidhash_table + n); | 199 | INIT_LIST_HEAD(uidhash_table + n); |
| 184 | 200 | ||
| 185 | /* Insert the root user immediately (init already runs as root) */ | 201 | /* Insert the root user immediately (init already runs as root) */ |
| 186 | spin_lock(&uidhash_lock); | 202 | spin_lock_irq(&uidhash_lock); |
| 187 | uid_hash_insert(&root_user, uidhashentry(0)); | 203 | uid_hash_insert(&root_user, uidhashentry(0)); |
| 188 | spin_unlock(&uidhash_lock); | 204 | spin_unlock_irq(&uidhash_lock); |
| 189 | 205 | ||
| 190 | return 0; | 206 | return 0; |
| 191 | } | 207 | } |
