aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/user.c
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2006-01-31 19:34:26 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-31 19:49:43 -0500
commit3fa97c9db4f6f93f41f7a40d08872dbfd8dc907e (patch)
tree6a71aea65a6854f6ab16dc2f8cadf885f01b927e /kernel/user.c
parentb8c475be7bf9b79e6417c08d7a921b2e8cb04258 (diff)
[PATCH] "Fix uidhash_lock <-> RXU deadlock" fix
I get storms of warnings from local_bh_enable(). Better-tested patches, please. Cc: Ingo Molnar <mingo@elte.hu> Cc: "Paul E. McKenney" <paulmck@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/user.c')
-rw-r--r--kernel/user.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/kernel/user.c b/kernel/user.c
index d1ae2349347e..d9deae43a9ab 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -33,6 +33,10 @@ static struct list_head uidhash_table[UIDHASH_SZ];
33 * The uidhash_lock is mostly taken from process context, but it is 33 * The uidhash_lock is mostly taken from process context, but it is
34 * occasionally also taken from softirq/tasklet context, when 34 * occasionally also taken from softirq/tasklet context, when
35 * task-structs get RCU-freed. Hence all locking must be softirq-safe. 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..
36 */ 40 */
37static DEFINE_SPINLOCK(uidhash_lock); 41static DEFINE_SPINLOCK(uidhash_lock);
38 42
@@ -89,16 +93,19 @@ static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *has
89struct user_struct *find_user(uid_t uid) 93struct user_struct *find_user(uid_t uid)
90{ 94{
91 struct user_struct *ret; 95 struct user_struct *ret;
96 unsigned long flags;
92 97
93 spin_lock_bh(&uidhash_lock); 98 spin_lock_irqsave(&uidhash_lock, flags);
94 ret = uid_hash_find(uid, uidhashentry(uid)); 99 ret = uid_hash_find(uid, uidhashentry(uid));
95 spin_unlock_bh(&uidhash_lock); 100 spin_unlock_irqrestore(&uidhash_lock, flags);
96 return ret; 101 return ret;
97} 102}
98 103
99void free_uid(struct user_struct *up) 104void free_uid(struct user_struct *up)
100{ 105{
101 local_bh_disable(); 106 unsigned long flags;
107
108 local_irq_save(flags);
102 if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) { 109 if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
103 uid_hash_remove(up); 110 uid_hash_remove(up);
104 key_put(up->uid_keyring); 111 key_put(up->uid_keyring);
@@ -106,7 +113,7 @@ void free_uid(struct user_struct *up)
106 kmem_cache_free(uid_cachep, up); 113 kmem_cache_free(uid_cachep, up);
107 spin_unlock(&uidhash_lock); 114 spin_unlock(&uidhash_lock);
108 } 115 }
109 local_bh_enable(); 116 local_irq_restore(flags);
110} 117}
111 118
112struct user_struct * alloc_uid(uid_t uid) 119struct user_struct * alloc_uid(uid_t uid)
@@ -114,9 +121,9 @@ struct user_struct * alloc_uid(uid_t uid)
114 struct list_head *hashent = uidhashentry(uid); 121 struct list_head *hashent = uidhashentry(uid);
115 struct user_struct *up; 122 struct user_struct *up;
116 123
117 spin_lock_bh(&uidhash_lock); 124 spin_lock_irq(&uidhash_lock);
118 up = uid_hash_find(uid, hashent); 125 up = uid_hash_find(uid, hashent);
119 spin_unlock_bh(&uidhash_lock); 126 spin_unlock_irq(&uidhash_lock);
120 127
121 if (!up) { 128 if (!up) {
122 struct user_struct *new; 129 struct user_struct *new;
@@ -146,7 +153,7 @@ struct user_struct * alloc_uid(uid_t uid)
146 * Before adding this, check whether we raced 153 * Before adding this, check whether we raced
147 * on adding the same user already.. 154 * on adding the same user already..
148 */ 155 */
149 spin_lock_bh(&uidhash_lock); 156 spin_lock_irq(&uidhash_lock);
150 up = uid_hash_find(uid, hashent); 157 up = uid_hash_find(uid, hashent);
151 if (up) { 158 if (up) {
152 key_put(new->uid_keyring); 159 key_put(new->uid_keyring);
@@ -156,7 +163,7 @@ struct user_struct * alloc_uid(uid_t uid)
156 uid_hash_insert(new, hashent); 163 uid_hash_insert(new, hashent);
157 up = new; 164 up = new;
158 } 165 }
159 spin_unlock_bh(&uidhash_lock); 166 spin_unlock_irq(&uidhash_lock);
160 167
161 } 168 }
162 return up; 169 return up;
@@ -192,9 +199,9 @@ static int __init uid_cache_init(void)
192 INIT_LIST_HEAD(uidhash_table + n); 199 INIT_LIST_HEAD(uidhash_table + n);
193 200
194 /* Insert the root user immediately (init already runs as root) */ 201 /* Insert the root user immediately (init already runs as root) */
195 spin_lock_bh(&uidhash_lock); 202 spin_lock_irq(&uidhash_lock);
196 uid_hash_insert(&root_user, uidhashentry(0)); 203 uid_hash_insert(&root_user, uidhashentry(0));
197 spin_unlock_bh(&uidhash_lock); 204 spin_unlock_irq(&uidhash_lock);
198 205
199 return 0; 206 return 0;
200} 207}