diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-07-26 09:30:40 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-26 09:30:40 -0400 |
commit | 1503af661947b7a4a09355cc2ae6aa0d43f16776 (patch) | |
tree | 5bfcfadf2dd2d98c2ad251c96d7ee43a6903819a /kernel | |
parent | a31863168660c6b6f6c7ffe05bb6a38e97803326 (diff) | |
parent | 024e8ac04453b3525448c31ef39848cf675ba6db (diff) |
Merge branch 'linus' into x86/header-guards
Conflicts:
include/asm-x86/gpio.h
include/asm-x86/ide.h
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel')
55 files changed, 1992 insertions, 1373 deletions
diff --git a/kernel/Kconfig.hz b/kernel/Kconfig.hz index 526128a2e622..382dd5a8b2d7 100644 --- a/kernel/Kconfig.hz +++ b/kernel/Kconfig.hz | |||
@@ -55,4 +55,4 @@ config HZ | |||
55 | default 1000 if HZ_1000 | 55 | default 1000 if HZ_1000 |
56 | 56 | ||
57 | config SCHED_HRTICK | 57 | config SCHED_HRTICK |
58 | def_bool HIGH_RES_TIMERS && X86 | 58 | def_bool HIGH_RES_TIMERS && USE_GENERIC_SMP_HELPERS |
diff --git a/kernel/Makefile b/kernel/Makefile index 985ddb7da4d0..54f69837d35a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for the linux kernel. | 2 | # Makefile for the linux kernel. |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ | 5 | obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ |
6 | cpu.o exit.o itimer.o time.o softirq.o resource.o \ | 6 | cpu.o exit.o itimer.o time.o softirq.o resource.o \ |
7 | sysctl.o capability.o ptrace.o timer.o user.o \ | 7 | sysctl.o capability.o ptrace.o timer.o user.o \ |
8 | signal.o sys.o kmod.o workqueue.o pid.o \ | 8 | signal.o sys.o kmod.o workqueue.o pid.o \ |
@@ -11,6 +11,8 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ | |||
11 | hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ | 11 | hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ |
12 | notifier.o ksysfs.o pm_qos_params.o sched_clock.o | 12 | notifier.o ksysfs.o pm_qos_params.o sched_clock.o |
13 | 13 | ||
14 | CFLAGS_REMOVE_sched.o = -mno-spe | ||
15 | |||
14 | ifdef CONFIG_FTRACE | 16 | ifdef CONFIG_FTRACE |
15 | # Do not trace debug files and internal ftrace files | 17 | # Do not trace debug files and internal ftrace files |
16 | CFLAGS_REMOVE_lockdep.o = -pg | 18 | CFLAGS_REMOVE_lockdep.o = -pg |
@@ -22,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg | |||
22 | CFLAGS_REMOVE_sched.o = -mno-spe -pg | 24 | CFLAGS_REMOVE_sched.o = -mno-spe -pg |
23 | endif | 25 | endif |
24 | 26 | ||
27 | obj-$(CONFIG_PROFILING) += profile.o | ||
25 | obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o | 28 | obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o |
26 | obj-$(CONFIG_STACKTRACE) += stacktrace.o | 29 | obj-$(CONFIG_STACKTRACE) += stacktrace.o |
27 | obj-y += time/ | 30 | obj-y += time/ |
diff --git a/kernel/acct.c b/kernel/acct.c index 91e1cfd734d2..dd68b9059418 100644 --- a/kernel/acct.c +++ b/kernel/acct.c | |||
@@ -75,37 +75,39 @@ int acct_parm[3] = {4, 2, 30}; | |||
75 | /* | 75 | /* |
76 | * External references and all of the globals. | 76 | * External references and all of the globals. |
77 | */ | 77 | */ |
78 | static void do_acct_process(struct pid_namespace *ns, struct file *); | 78 | static void do_acct_process(struct bsd_acct_struct *acct, |
79 | struct pid_namespace *ns, struct file *); | ||
79 | 80 | ||
80 | /* | 81 | /* |
81 | * This structure is used so that all the data protected by lock | 82 | * This structure is used so that all the data protected by lock |
82 | * can be placed in the same cache line as the lock. This primes | 83 | * can be placed in the same cache line as the lock. This primes |
83 | * the cache line to have the data after getting the lock. | 84 | * the cache line to have the data after getting the lock. |
84 | */ | 85 | */ |
85 | struct acct_glbs { | 86 | struct bsd_acct_struct { |
86 | spinlock_t lock; | ||
87 | volatile int active; | 87 | volatile int active; |
88 | volatile int needcheck; | 88 | volatile int needcheck; |
89 | struct file *file; | 89 | struct file *file; |
90 | struct pid_namespace *ns; | 90 | struct pid_namespace *ns; |
91 | struct timer_list timer; | 91 | struct timer_list timer; |
92 | struct list_head list; | ||
92 | }; | 93 | }; |
93 | 94 | ||
94 | static struct acct_glbs acct_globals __cacheline_aligned = | 95 | static DEFINE_SPINLOCK(acct_lock); |
95 | {__SPIN_LOCK_UNLOCKED(acct_globals.lock)}; | 96 | static LIST_HEAD(acct_list); |
96 | 97 | ||
97 | /* | 98 | /* |
98 | * Called whenever the timer says to check the free space. | 99 | * Called whenever the timer says to check the free space. |
99 | */ | 100 | */ |
100 | static void acct_timeout(unsigned long unused) | 101 | static void acct_timeout(unsigned long x) |
101 | { | 102 | { |
102 | acct_globals.needcheck = 1; | 103 | struct bsd_acct_struct *acct = (struct bsd_acct_struct *)x; |
104 | acct->needcheck = 1; | ||
103 | } | 105 | } |
104 | 106 | ||
105 | /* | 107 | /* |
106 | * Check the amount of free space and suspend/resume accordingly. | 108 | * Check the amount of free space and suspend/resume accordingly. |
107 | */ | 109 | */ |
108 | static int check_free_space(struct file *file) | 110 | static int check_free_space(struct bsd_acct_struct *acct, struct file *file) |
109 | { | 111 | { |
110 | struct kstatfs sbuf; | 112 | struct kstatfs sbuf; |
111 | int res; | 113 | int res; |
@@ -113,11 +115,11 @@ static int check_free_space(struct file *file) | |||
113 | sector_t resume; | 115 | sector_t resume; |
114 | sector_t suspend; | 116 | sector_t suspend; |
115 | 117 | ||
116 | spin_lock(&acct_globals.lock); | 118 | spin_lock(&acct_lock); |
117 | res = acct_globals.active; | 119 | res = acct->active; |
118 | if (!file || !acct_globals.needcheck) | 120 | if (!file || !acct->needcheck) |
119 | goto out; | 121 | goto out; |
120 | spin_unlock(&acct_globals.lock); | 122 | spin_unlock(&acct_lock); |
121 | 123 | ||
122 | /* May block */ | 124 | /* May block */ |
123 | if (vfs_statfs(file->f_path.dentry, &sbuf)) | 125 | if (vfs_statfs(file->f_path.dentry, &sbuf)) |
@@ -136,35 +138,35 @@ static int check_free_space(struct file *file) | |||
136 | act = 0; | 138 | act = 0; |
137 | 139 | ||
138 | /* | 140 | /* |
139 | * If some joker switched acct_globals.file under us we'ld better be | 141 | * If some joker switched acct->file under us we'ld better be |
140 | * silent and _not_ touch anything. | 142 | * silent and _not_ touch anything. |
141 | */ | 143 | */ |
142 | spin_lock(&acct_globals.lock); | 144 | spin_lock(&acct_lock); |
143 | if (file != acct_globals.file) { | 145 | if (file != acct->file) { |
144 | if (act) | 146 | if (act) |
145 | res = act>0; | 147 | res = act>0; |
146 | goto out; | 148 | goto out; |
147 | } | 149 | } |
148 | 150 | ||
149 | if (acct_globals.active) { | 151 | if (acct->active) { |
150 | if (act < 0) { | 152 | if (act < 0) { |
151 | acct_globals.active = 0; | 153 | acct->active = 0; |
152 | printk(KERN_INFO "Process accounting paused\n"); | 154 | printk(KERN_INFO "Process accounting paused\n"); |
153 | } | 155 | } |
154 | } else { | 156 | } else { |
155 | if (act > 0) { | 157 | if (act > 0) { |
156 | acct_globals.active = 1; | 158 | acct->active = 1; |
157 | printk(KERN_INFO "Process accounting resumed\n"); | 159 | printk(KERN_INFO "Process accounting resumed\n"); |
158 | } | 160 | } |
159 | } | 161 | } |
160 | 162 | ||
161 | del_timer(&acct_globals.timer); | 163 | del_timer(&acct->timer); |
162 | acct_globals.needcheck = 0; | 164 | acct->needcheck = 0; |
163 | acct_globals.timer.expires = jiffies + ACCT_TIMEOUT*HZ; | 165 | acct->timer.expires = jiffies + ACCT_TIMEOUT*HZ; |
164 | add_timer(&acct_globals.timer); | 166 | add_timer(&acct->timer); |
165 | res = acct_globals.active; | 167 | res = acct->active; |
166 | out: | 168 | out: |
167 | spin_unlock(&acct_globals.lock); | 169 | spin_unlock(&acct_lock); |
168 | return res; | 170 | return res; |
169 | } | 171 | } |
170 | 172 | ||
@@ -172,39 +174,41 @@ out: | |||
172 | * Close the old accounting file (if currently open) and then replace | 174 | * Close the old accounting file (if currently open) and then replace |
173 | * it with file (if non-NULL). | 175 | * it with file (if non-NULL). |
174 | * | 176 | * |
175 | * NOTE: acct_globals.lock MUST be held on entry and exit. | 177 | * NOTE: acct_lock MUST be held on entry and exit. |
176 | */ | 178 | */ |
177 | static void acct_file_reopen(struct file *file) | 179 | static void acct_file_reopen(struct bsd_acct_struct *acct, struct file *file, |
180 | struct pid_namespace *ns) | ||
178 | { | 181 | { |
179 | struct file *old_acct = NULL; | 182 | struct file *old_acct = NULL; |
180 | struct pid_namespace *old_ns = NULL; | 183 | struct pid_namespace *old_ns = NULL; |
181 | 184 | ||
182 | if (acct_globals.file) { | 185 | if (acct->file) { |
183 | old_acct = acct_globals.file; | 186 | old_acct = acct->file; |
184 | old_ns = acct_globals.ns; | 187 | old_ns = acct->ns; |
185 | del_timer(&acct_globals.timer); | 188 | del_timer(&acct->timer); |
186 | acct_globals.active = 0; | 189 | acct->active = 0; |
187 | acct_globals.needcheck = 0; | 190 | acct->needcheck = 0; |
188 | acct_globals.file = NULL; | 191 | acct->file = NULL; |
192 | acct->ns = NULL; | ||
193 | list_del(&acct->list); | ||
189 | } | 194 | } |
190 | if (file) { | 195 | if (file) { |
191 | acct_globals.file = file; | 196 | acct->file = file; |
192 | acct_globals.ns = get_pid_ns(task_active_pid_ns(current)); | 197 | acct->ns = ns; |
193 | acct_globals.needcheck = 0; | 198 | acct->needcheck = 0; |
194 | acct_globals.active = 1; | 199 | acct->active = 1; |
200 | list_add(&acct->list, &acct_list); | ||
195 | /* It's been deleted if it was used before so this is safe */ | 201 | /* It's been deleted if it was used before so this is safe */ |
196 | init_timer(&acct_globals.timer); | 202 | setup_timer(&acct->timer, acct_timeout, (unsigned long)acct); |
197 | acct_globals.timer.function = acct_timeout; | 203 | acct->timer.expires = jiffies + ACCT_TIMEOUT*HZ; |
198 | acct_globals.timer.expires = jiffies + ACCT_TIMEOUT*HZ; | 204 | add_timer(&acct->timer); |
199 | add_timer(&acct_globals.timer); | ||
200 | } | 205 | } |
201 | if (old_acct) { | 206 | if (old_acct) { |
202 | mnt_unpin(old_acct->f_path.mnt); | 207 | mnt_unpin(old_acct->f_path.mnt); |
203 | spin_unlock(&acct_globals.lock); | 208 | spin_unlock(&acct_lock); |
204 | do_acct_process(old_ns, old_acct); | 209 | do_acct_process(acct, old_ns, old_acct); |
205 | filp_close(old_acct, NULL); | 210 | filp_close(old_acct, NULL); |
206 | put_pid_ns(old_ns); | 211 | spin_lock(&acct_lock); |
207 | spin_lock(&acct_globals.lock); | ||
208 | } | 212 | } |
209 | } | 213 | } |
210 | 214 | ||
@@ -212,6 +216,8 @@ static int acct_on(char *name) | |||
212 | { | 216 | { |
213 | struct file *file; | 217 | struct file *file; |
214 | int error; | 218 | int error; |
219 | struct pid_namespace *ns; | ||
220 | struct bsd_acct_struct *acct = NULL; | ||
215 | 221 | ||
216 | /* Difference from BSD - they don't do O_APPEND */ | 222 | /* Difference from BSD - they don't do O_APPEND */ |
217 | file = filp_open(name, O_WRONLY|O_APPEND|O_LARGEFILE, 0); | 223 | file = filp_open(name, O_WRONLY|O_APPEND|O_LARGEFILE, 0); |
@@ -228,18 +234,34 @@ static int acct_on(char *name) | |||
228 | return -EIO; | 234 | return -EIO; |
229 | } | 235 | } |
230 | 236 | ||
237 | ns = task_active_pid_ns(current); | ||
238 | if (ns->bacct == NULL) { | ||
239 | acct = kzalloc(sizeof(struct bsd_acct_struct), GFP_KERNEL); | ||
240 | if (acct == NULL) { | ||
241 | filp_close(file, NULL); | ||
242 | return -ENOMEM; | ||
243 | } | ||
244 | } | ||
245 | |||
231 | error = security_acct(file); | 246 | error = security_acct(file); |
232 | if (error) { | 247 | if (error) { |
248 | kfree(acct); | ||
233 | filp_close(file, NULL); | 249 | filp_close(file, NULL); |
234 | return error; | 250 | return error; |
235 | } | 251 | } |
236 | 252 | ||
237 | spin_lock(&acct_globals.lock); | 253 | spin_lock(&acct_lock); |
254 | if (ns->bacct == NULL) { | ||
255 | ns->bacct = acct; | ||
256 | acct = NULL; | ||
257 | } | ||
258 | |||
238 | mnt_pin(file->f_path.mnt); | 259 | mnt_pin(file->f_path.mnt); |
239 | acct_file_reopen(file); | 260 | acct_file_reopen(ns->bacct, file, ns); |
240 | spin_unlock(&acct_globals.lock); | 261 | spin_unlock(&acct_lock); |
241 | 262 | ||
242 | mntput(file->f_path.mnt); /* it's pinned, now give up active reference */ | 263 | mntput(file->f_path.mnt); /* it's pinned, now give up active reference */ |
264 | kfree(acct); | ||
243 | 265 | ||
244 | return 0; | 266 | return 0; |
245 | } | 267 | } |
@@ -269,11 +291,17 @@ asmlinkage long sys_acct(const char __user *name) | |||
269 | error = acct_on(tmp); | 291 | error = acct_on(tmp); |
270 | putname(tmp); | 292 | putname(tmp); |
271 | } else { | 293 | } else { |
294 | struct bsd_acct_struct *acct; | ||
295 | |||
296 | acct = task_active_pid_ns(current)->bacct; | ||
297 | if (acct == NULL) | ||
298 | return 0; | ||
299 | |||
272 | error = security_acct(NULL); | 300 | error = security_acct(NULL); |
273 | if (!error) { | 301 | if (!error) { |
274 | spin_lock(&acct_globals.lock); | 302 | spin_lock(&acct_lock); |
275 | acct_file_reopen(NULL); | 303 | acct_file_reopen(acct, NULL, NULL); |
276 | spin_unlock(&acct_globals.lock); | 304 | spin_unlock(&acct_lock); |
277 | } | 305 | } |
278 | } | 306 | } |
279 | return error; | 307 | return error; |
@@ -288,10 +316,16 @@ asmlinkage long sys_acct(const char __user *name) | |||
288 | */ | 316 | */ |
289 | void acct_auto_close_mnt(struct vfsmount *m) | 317 | void acct_auto_close_mnt(struct vfsmount *m) |
290 | { | 318 | { |
291 | spin_lock(&acct_globals.lock); | 319 | struct bsd_acct_struct *acct; |
292 | if (acct_globals.file && acct_globals.file->f_path.mnt == m) | 320 | |
293 | acct_file_reopen(NULL); | 321 | spin_lock(&acct_lock); |
294 | spin_unlock(&acct_globals.lock); | 322 | restart: |
323 | list_for_each_entry(acct, &acct_list, list) | ||
324 | if (acct->file && acct->file->f_path.mnt == m) { | ||
325 | acct_file_reopen(acct, NULL, NULL); | ||
326 | goto restart; | ||
327 | } | ||
328 | spin_unlock(&acct_lock); | ||
295 | } | 329 | } |
296 | 330 | ||
297 | /** | 331 | /** |
@@ -303,12 +337,31 @@ void acct_auto_close_mnt(struct vfsmount *m) | |||
303 | */ | 337 | */ |
304 | void acct_auto_close(struct super_block *sb) | 338 | void acct_auto_close(struct super_block *sb) |
305 | { | 339 | { |
306 | spin_lock(&acct_globals.lock); | 340 | struct bsd_acct_struct *acct; |
307 | if (acct_globals.file && | 341 | |
308 | acct_globals.file->f_path.mnt->mnt_sb == sb) { | 342 | spin_lock(&acct_lock); |
309 | acct_file_reopen(NULL); | 343 | restart: |
344 | list_for_each_entry(acct, &acct_list, list) | ||
345 | if (acct->file && acct->file->f_path.mnt->mnt_sb == sb) { | ||
346 | acct_file_reopen(acct, NULL, NULL); | ||
347 | goto restart; | ||
348 | } | ||
349 | spin_unlock(&acct_lock); | ||
350 | } | ||
351 | |||
352 | void acct_exit_ns(struct pid_namespace *ns) | ||
353 | { | ||
354 | struct bsd_acct_struct *acct; | ||
355 | |||
356 | spin_lock(&acct_lock); | ||
357 | acct = ns->bacct; | ||
358 | if (acct != NULL) { | ||
359 | if (acct->file != NULL) | ||
360 | acct_file_reopen(acct, NULL, NULL); | ||
361 | |||
362 | kfree(acct); | ||
310 | } | 363 | } |
311 | spin_unlock(&acct_globals.lock); | 364 | spin_unlock(&acct_lock); |
312 | } | 365 | } |
313 | 366 | ||
314 | /* | 367 | /* |
@@ -425,7 +478,8 @@ static u32 encode_float(u64 value) | |||
425 | /* | 478 | /* |
426 | * do_acct_process does all actual work. Caller holds the reference to file. | 479 | * do_acct_process does all actual work. Caller holds the reference to file. |
427 | */ | 480 | */ |
428 | static void do_acct_process(struct pid_namespace *ns, struct file *file) | 481 | static void do_acct_process(struct bsd_acct_struct *acct, |
482 | struct pid_namespace *ns, struct file *file) | ||
429 | { | 483 | { |
430 | struct pacct_struct *pacct = ¤t->signal->pacct; | 484 | struct pacct_struct *pacct = ¤t->signal->pacct; |
431 | acct_t ac; | 485 | acct_t ac; |
@@ -440,7 +494,7 @@ static void do_acct_process(struct pid_namespace *ns, struct file *file) | |||
440 | * First check to see if there is enough free_space to continue | 494 | * First check to see if there is enough free_space to continue |
441 | * the process accounting system. | 495 | * the process accounting system. |
442 | */ | 496 | */ |
443 | if (!check_free_space(file)) | 497 | if (!check_free_space(acct, file)) |
444 | return; | 498 | return; |
445 | 499 | ||
446 | /* | 500 | /* |
@@ -577,34 +631,46 @@ void acct_collect(long exitcode, int group_dead) | |||
577 | spin_unlock_irq(¤t->sighand->siglock); | 631 | spin_unlock_irq(¤t->sighand->siglock); |
578 | } | 632 | } |
579 | 633 | ||
580 | /** | 634 | static void acct_process_in_ns(struct pid_namespace *ns) |
581 | * acct_process - now just a wrapper around do_acct_process | ||
582 | * @exitcode: task exit code | ||
583 | * | ||
584 | * handles process accounting for an exiting task | ||
585 | */ | ||
586 | void acct_process(void) | ||
587 | { | 635 | { |
588 | struct file *file = NULL; | 636 | struct file *file = NULL; |
589 | struct pid_namespace *ns; | 637 | struct bsd_acct_struct *acct; |
590 | 638 | ||
639 | acct = ns->bacct; | ||
591 | /* | 640 | /* |
592 | * accelerate the common fastpath: | 641 | * accelerate the common fastpath: |
593 | */ | 642 | */ |
594 | if (!acct_globals.file) | 643 | if (!acct || !acct->file) |
595 | return; | 644 | return; |
596 | 645 | ||
597 | spin_lock(&acct_globals.lock); | 646 | spin_lock(&acct_lock); |
598 | file = acct_globals.file; | 647 | file = acct->file; |
599 | if (unlikely(!file)) { | 648 | if (unlikely(!file)) { |
600 | spin_unlock(&acct_globals.lock); | 649 | spin_unlock(&acct_lock); |
601 | return; | 650 | return; |
602 | } | 651 | } |
603 | get_file(file); | 652 | get_file(file); |
604 | ns = get_pid_ns(acct_globals.ns); | 653 | spin_unlock(&acct_lock); |
605 | spin_unlock(&acct_globals.lock); | ||
606 | 654 | ||
607 | do_acct_process(ns, file); | 655 | do_acct_process(acct, ns, file); |
608 | fput(file); | 656 | fput(file); |
609 | put_pid_ns(ns); | 657 | } |
658 | |||
659 | /** | ||
660 | * acct_process - now just a wrapper around acct_process_in_ns, | ||
661 | * which in turn is a wrapper around do_acct_process. | ||
662 | * | ||
663 | * handles process accounting for an exiting task | ||
664 | */ | ||
665 | void acct_process(void) | ||
666 | { | ||
667 | struct pid_namespace *ns; | ||
668 | |||
669 | /* | ||
670 | * This loop is safe lockless, since current is still | ||
671 | * alive and holds its namespace, which in turn holds | ||
672 | * its parent. | ||
673 | */ | ||
674 | for (ns = task_active_pid_ns(current); ns != NULL; ns = ns->parent) | ||
675 | acct_process_in_ns(ns); | ||
610 | } | 676 | } |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index c10e7aae04d7..4699950e65bd 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -1476,7 +1476,8 @@ void audit_syscall_entry(int arch, int major, | |||
1476 | struct audit_context *context = tsk->audit_context; | 1476 | struct audit_context *context = tsk->audit_context; |
1477 | enum audit_state state; | 1477 | enum audit_state state; |
1478 | 1478 | ||
1479 | BUG_ON(!context); | 1479 | if (unlikely(!context)) |
1480 | return; | ||
1480 | 1481 | ||
1481 | /* | 1482 | /* |
1482 | * This happens only on certain architectures that make system | 1483 | * This happens only on certain architectures that make system |
diff --git a/kernel/capability.c b/kernel/capability.c index 901e0fdc3fff..0101e847603e 100644 --- a/kernel/capability.c +++ b/kernel/capability.c | |||
@@ -115,11 +115,208 @@ static int cap_validate_magic(cap_user_header_t header, unsigned *tocopy) | |||
115 | return 0; | 115 | return 0; |
116 | } | 116 | } |
117 | 117 | ||
118 | #ifndef CONFIG_SECURITY_FILE_CAPABILITIES | ||
119 | |||
120 | /* | ||
121 | * Without filesystem capability support, we nominally support one process | ||
122 | * setting the capabilities of another | ||
123 | */ | ||
124 | static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp, | ||
125 | kernel_cap_t *pIp, kernel_cap_t *pPp) | ||
126 | { | ||
127 | struct task_struct *target; | ||
128 | int ret; | ||
129 | |||
130 | spin_lock(&task_capability_lock); | ||
131 | read_lock(&tasklist_lock); | ||
132 | |||
133 | if (pid && pid != task_pid_vnr(current)) { | ||
134 | target = find_task_by_vpid(pid); | ||
135 | if (!target) { | ||
136 | ret = -ESRCH; | ||
137 | goto out; | ||
138 | } | ||
139 | } else | ||
140 | target = current; | ||
141 | |||
142 | ret = security_capget(target, pEp, pIp, pPp); | ||
143 | |||
144 | out: | ||
145 | read_unlock(&tasklist_lock); | ||
146 | spin_unlock(&task_capability_lock); | ||
147 | |||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | /* | ||
152 | * cap_set_pg - set capabilities for all processes in a given process | ||
153 | * group. We call this holding task_capability_lock and tasklist_lock. | ||
154 | */ | ||
155 | static inline int cap_set_pg(int pgrp_nr, kernel_cap_t *effective, | ||
156 | kernel_cap_t *inheritable, | ||
157 | kernel_cap_t *permitted) | ||
158 | { | ||
159 | struct task_struct *g, *target; | ||
160 | int ret = -EPERM; | ||
161 | int found = 0; | ||
162 | struct pid *pgrp; | ||
163 | |||
164 | spin_lock(&task_capability_lock); | ||
165 | read_lock(&tasklist_lock); | ||
166 | |||
167 | pgrp = find_vpid(pgrp_nr); | ||
168 | do_each_pid_task(pgrp, PIDTYPE_PGID, g) { | ||
169 | target = g; | ||
170 | while_each_thread(g, target) { | ||
171 | if (!security_capset_check(target, effective, | ||
172 | inheritable, permitted)) { | ||
173 | security_capset_set(target, effective, | ||
174 | inheritable, permitted); | ||
175 | ret = 0; | ||
176 | } | ||
177 | found = 1; | ||
178 | } | ||
179 | } while_each_pid_task(pgrp, PIDTYPE_PGID, g); | ||
180 | |||
181 | read_unlock(&tasklist_lock); | ||
182 | spin_unlock(&task_capability_lock); | ||
183 | |||
184 | if (!found) | ||
185 | ret = 0; | ||
186 | return ret; | ||
187 | } | ||
188 | |||
118 | /* | 189 | /* |
119 | * For sys_getproccap() and sys_setproccap(), any of the three | 190 | * cap_set_all - set capabilities for all processes other than init |
120 | * capability set pointers may be NULL -- indicating that that set is | 191 | * and self. We call this holding task_capability_lock and tasklist_lock. |
121 | * uninteresting and/or not to be changed. | ||
122 | */ | 192 | */ |
193 | static inline int cap_set_all(kernel_cap_t *effective, | ||
194 | kernel_cap_t *inheritable, | ||
195 | kernel_cap_t *permitted) | ||
196 | { | ||
197 | struct task_struct *g, *target; | ||
198 | int ret = -EPERM; | ||
199 | int found = 0; | ||
200 | |||
201 | spin_lock(&task_capability_lock); | ||
202 | read_lock(&tasklist_lock); | ||
203 | |||
204 | do_each_thread(g, target) { | ||
205 | if (target == current | ||
206 | || is_container_init(target->group_leader)) | ||
207 | continue; | ||
208 | found = 1; | ||
209 | if (security_capset_check(target, effective, inheritable, | ||
210 | permitted)) | ||
211 | continue; | ||
212 | ret = 0; | ||
213 | security_capset_set(target, effective, inheritable, permitted); | ||
214 | } while_each_thread(g, target); | ||
215 | |||
216 | read_unlock(&tasklist_lock); | ||
217 | spin_unlock(&task_capability_lock); | ||
218 | |||
219 | if (!found) | ||
220 | ret = 0; | ||
221 | |||
222 | return ret; | ||
223 | } | ||
224 | |||
225 | /* | ||
226 | * Given the target pid does not refer to the current process we | ||
227 | * need more elaborate support... (This support is not present when | ||
228 | * filesystem capabilities are configured.) | ||
229 | */ | ||
230 | static inline int do_sys_capset_other_tasks(pid_t pid, kernel_cap_t *effective, | ||
231 | kernel_cap_t *inheritable, | ||
232 | kernel_cap_t *permitted) | ||
233 | { | ||
234 | struct task_struct *target; | ||
235 | int ret; | ||
236 | |||
237 | if (!capable(CAP_SETPCAP)) | ||
238 | return -EPERM; | ||
239 | |||
240 | if (pid == -1) /* all procs other than current and init */ | ||
241 | return cap_set_all(effective, inheritable, permitted); | ||
242 | |||
243 | else if (pid < 0) /* all procs in process group */ | ||
244 | return cap_set_pg(-pid, effective, inheritable, permitted); | ||
245 | |||
246 | /* target != current */ | ||
247 | spin_lock(&task_capability_lock); | ||
248 | read_lock(&tasklist_lock); | ||
249 | |||
250 | target = find_task_by_vpid(pid); | ||
251 | if (!target) | ||
252 | ret = -ESRCH; | ||
253 | else { | ||
254 | ret = security_capset_check(target, effective, inheritable, | ||
255 | permitted); | ||
256 | |||
257 | /* having verified that the proposed changes are legal, | ||
258 | we now put them into effect. */ | ||
259 | if (!ret) | ||
260 | security_capset_set(target, effective, inheritable, | ||
261 | permitted); | ||
262 | } | ||
263 | |||
264 | read_unlock(&tasklist_lock); | ||
265 | spin_unlock(&task_capability_lock); | ||
266 | |||
267 | return ret; | ||
268 | } | ||
269 | |||
270 | #else /* ie., def CONFIG_SECURITY_FILE_CAPABILITIES */ | ||
271 | |||
272 | /* | ||
273 | * If we have configured with filesystem capability support, then the | ||
274 | * only thing that can change the capabilities of the current process | ||
275 | * is the current process. As such, we can't be in this code at the | ||
276 | * same time as we are in the process of setting capabilities in this | ||
277 | * process. The net result is that we can limit our use of locks to | ||
278 | * when we are reading the caps of another process. | ||
279 | */ | ||
280 | static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp, | ||
281 | kernel_cap_t *pIp, kernel_cap_t *pPp) | ||
282 | { | ||
283 | int ret; | ||
284 | |||
285 | if (pid && (pid != task_pid_vnr(current))) { | ||
286 | struct task_struct *target; | ||
287 | |||
288 | spin_lock(&task_capability_lock); | ||
289 | read_lock(&tasklist_lock); | ||
290 | |||
291 | target = find_task_by_vpid(pid); | ||
292 | if (!target) | ||
293 | ret = -ESRCH; | ||
294 | else | ||
295 | ret = security_capget(target, pEp, pIp, pPp); | ||
296 | |||
297 | read_unlock(&tasklist_lock); | ||
298 | spin_unlock(&task_capability_lock); | ||
299 | } else | ||
300 | ret = security_capget(current, pEp, pIp, pPp); | ||
301 | |||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | /* | ||
306 | * With filesystem capability support configured, the kernel does not | ||
307 | * permit the changing of capabilities in one process by another | ||
308 | * process. (CAP_SETPCAP has much less broad semantics when configured | ||
309 | * this way.) | ||
310 | */ | ||
311 | static inline int do_sys_capset_other_tasks(pid_t pid, | ||
312 | kernel_cap_t *effective, | ||
313 | kernel_cap_t *inheritable, | ||
314 | kernel_cap_t *permitted) | ||
315 | { | ||
316 | return -EPERM; | ||
317 | } | ||
318 | |||
319 | #endif /* ie., ndef CONFIG_SECURITY_FILE_CAPABILITIES */ | ||
123 | 320 | ||
124 | /* | 321 | /* |
125 | * Atomically modify the effective capabilities returning the original | 322 | * Atomically modify the effective capabilities returning the original |
@@ -155,7 +352,6 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr) | |||
155 | { | 352 | { |
156 | int ret = 0; | 353 | int ret = 0; |
157 | pid_t pid; | 354 | pid_t pid; |
158 | struct task_struct *target; | ||
159 | unsigned tocopy; | 355 | unsigned tocopy; |
160 | kernel_cap_t pE, pI, pP; | 356 | kernel_cap_t pE, pI, pP; |
161 | 357 | ||
@@ -169,23 +365,7 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr) | |||
169 | if (pid < 0) | 365 | if (pid < 0) |
170 | return -EINVAL; | 366 | return -EINVAL; |
171 | 367 | ||
172 | spin_lock(&task_capability_lock); | 368 | ret = cap_get_target_pid(pid, &pE, &pI, &pP); |
173 | read_lock(&tasklist_lock); | ||
174 | |||
175 | if (pid && pid != task_pid_vnr(current)) { | ||
176 | target = find_task_by_vpid(pid); | ||
177 | if (!target) { | ||
178 | ret = -ESRCH; | ||
179 | goto out; | ||
180 | } | ||
181 | } else | ||
182 | target = current; | ||
183 | |||
184 | ret = security_capget(target, &pE, &pI, &pP); | ||
185 | |||
186 | out: | ||
187 | read_unlock(&tasklist_lock); | ||
188 | spin_unlock(&task_capability_lock); | ||
189 | 369 | ||
190 | if (!ret) { | 370 | if (!ret) { |
191 | struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S]; | 371 | struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S]; |
@@ -216,7 +396,6 @@ out: | |||
216 | * before modification is attempted and the application | 396 | * before modification is attempted and the application |
217 | * fails. | 397 | * fails. |
218 | */ | 398 | */ |
219 | |||
220 | if (copy_to_user(dataptr, kdata, tocopy | 399 | if (copy_to_user(dataptr, kdata, tocopy |
221 | * sizeof(struct __user_cap_data_struct))) { | 400 | * sizeof(struct __user_cap_data_struct))) { |
222 | return -EFAULT; | 401 | return -EFAULT; |
@@ -226,70 +405,8 @@ out: | |||
226 | return ret; | 405 | return ret; |
227 | } | 406 | } |
228 | 407 | ||
229 | /* | ||
230 | * cap_set_pg - set capabilities for all processes in a given process | ||
231 | * group. We call this holding task_capability_lock and tasklist_lock. | ||
232 | */ | ||
233 | static inline int cap_set_pg(int pgrp_nr, kernel_cap_t *effective, | ||
234 | kernel_cap_t *inheritable, | ||
235 | kernel_cap_t *permitted) | ||
236 | { | ||
237 | struct task_struct *g, *target; | ||
238 | int ret = -EPERM; | ||
239 | int found = 0; | ||
240 | struct pid *pgrp; | ||
241 | |||
242 | pgrp = find_vpid(pgrp_nr); | ||
243 | do_each_pid_task(pgrp, PIDTYPE_PGID, g) { | ||
244 | target = g; | ||
245 | while_each_thread(g, target) { | ||
246 | if (!security_capset_check(target, effective, | ||
247 | inheritable, | ||
248 | permitted)) { | ||
249 | security_capset_set(target, effective, | ||
250 | inheritable, | ||
251 | permitted); | ||
252 | ret = 0; | ||
253 | } | ||
254 | found = 1; | ||
255 | } | ||
256 | } while_each_pid_task(pgrp, PIDTYPE_PGID, g); | ||
257 | |||
258 | if (!found) | ||
259 | ret = 0; | ||
260 | return ret; | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * cap_set_all - set capabilities for all processes other than init | ||
265 | * and self. We call this holding task_capability_lock and tasklist_lock. | ||
266 | */ | ||
267 | static inline int cap_set_all(kernel_cap_t *effective, | ||
268 | kernel_cap_t *inheritable, | ||
269 | kernel_cap_t *permitted) | ||
270 | { | ||
271 | struct task_struct *g, *target; | ||
272 | int ret = -EPERM; | ||
273 | int found = 0; | ||
274 | |||
275 | do_each_thread(g, target) { | ||
276 | if (target == current || is_container_init(target->group_leader)) | ||
277 | continue; | ||
278 | found = 1; | ||
279 | if (security_capset_check(target, effective, inheritable, | ||
280 | permitted)) | ||
281 | continue; | ||
282 | ret = 0; | ||
283 | security_capset_set(target, effective, inheritable, permitted); | ||
284 | } while_each_thread(g, target); | ||
285 | |||
286 | if (!found) | ||
287 | ret = 0; | ||
288 | return ret; | ||
289 | } | ||
290 | |||
291 | /** | 408 | /** |
292 | * sys_capset - set capabilities for a process or a group of processes | 409 | * sys_capset - set capabilities for a process or (*) a group of processes |
293 | * @header: pointer to struct that contains capability version and | 410 | * @header: pointer to struct that contains capability version and |
294 | * target pid data | 411 | * target pid data |
295 | * @data: pointer to struct that contains the effective, permitted, | 412 | * @data: pointer to struct that contains the effective, permitted, |
@@ -313,7 +430,6 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) | |||
313 | struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S]; | 430 | struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S]; |
314 | unsigned i, tocopy; | 431 | unsigned i, tocopy; |
315 | kernel_cap_t inheritable, permitted, effective; | 432 | kernel_cap_t inheritable, permitted, effective; |
316 | struct task_struct *target; | ||
317 | int ret; | 433 | int ret; |
318 | pid_t pid; | 434 | pid_t pid; |
319 | 435 | ||
@@ -324,9 +440,6 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) | |||
324 | if (get_user(pid, &header->pid)) | 440 | if (get_user(pid, &header->pid)) |
325 | return -EFAULT; | 441 | return -EFAULT; |
326 | 442 | ||
327 | if (pid && pid != task_pid_vnr(current) && !capable(CAP_SETPCAP)) | ||
328 | return -EPERM; | ||
329 | |||
330 | if (copy_from_user(&kdata, data, tocopy | 443 | if (copy_from_user(&kdata, data, tocopy |
331 | * sizeof(struct __user_cap_data_struct))) { | 444 | * sizeof(struct __user_cap_data_struct))) { |
332 | return -EFAULT; | 445 | return -EFAULT; |
@@ -344,40 +457,31 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) | |||
344 | i++; | 457 | i++; |
345 | } | 458 | } |
346 | 459 | ||
347 | spin_lock(&task_capability_lock); | 460 | if (pid && (pid != task_pid_vnr(current))) |
348 | read_lock(&tasklist_lock); | 461 | ret = do_sys_capset_other_tasks(pid, &effective, &inheritable, |
349 | 462 | &permitted); | |
350 | if (pid > 0 && pid != task_pid_vnr(current)) { | 463 | else { |
351 | target = find_task_by_vpid(pid); | 464 | /* |
352 | if (!target) { | 465 | * This lock is required even when filesystem |
353 | ret = -ESRCH; | 466 | * capability support is configured - it protects the |
354 | goto out; | 467 | * sys_capget() call from returning incorrect data in |
355 | } | 468 | * the case that the targeted process is not the |
356 | } else | 469 | * current one. |
357 | target = current; | 470 | */ |
358 | 471 | spin_lock(&task_capability_lock); | |
359 | ret = 0; | ||
360 | |||
361 | /* having verified that the proposed changes are legal, | ||
362 | we now put them into effect. */ | ||
363 | if (pid < 0) { | ||
364 | if (pid == -1) /* all procs other than current and init */ | ||
365 | ret = cap_set_all(&effective, &inheritable, &permitted); | ||
366 | 472 | ||
367 | else /* all procs in process group */ | 473 | ret = security_capset_check(current, &effective, &inheritable, |
368 | ret = cap_set_pg(-pid, &effective, &inheritable, | ||
369 | &permitted); | ||
370 | } else { | ||
371 | ret = security_capset_check(target, &effective, &inheritable, | ||
372 | &permitted); | 474 | &permitted); |
475 | /* | ||
476 | * Having verified that the proposed changes are | ||
477 | * legal, we now put them into effect. | ||
478 | */ | ||
373 | if (!ret) | 479 | if (!ret) |
374 | security_capset_set(target, &effective, &inheritable, | 480 | security_capset_set(current, &effective, &inheritable, |
375 | &permitted); | 481 | &permitted); |
482 | spin_unlock(&task_capability_lock); | ||
376 | } | 483 | } |
377 | 484 | ||
378 | out: | ||
379 | read_unlock(&tasklist_lock); | ||
380 | spin_unlock(&task_capability_lock); | ||
381 | 485 | ||
382 | return ret; | 486 | return ret; |
383 | } | 487 | } |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 15ac0e1e4f4d..66ec9fd21e0c 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -89,11 +89,7 @@ struct cgroupfs_root { | |||
89 | /* Hierarchy-specific flags */ | 89 | /* Hierarchy-specific flags */ |
90 | unsigned long flags; | 90 | unsigned long flags; |
91 | 91 | ||
92 | /* The path to use for release notifications. No locking | 92 | /* The path to use for release notifications. */ |
93 | * between setting and use - so if userspace updates this | ||
94 | * while child cgroups exist, you could miss a | ||
95 | * notification. We ensure that it's always a valid | ||
96 | * NUL-terminated string */ | ||
97 | char release_agent_path[PATH_MAX]; | 93 | char release_agent_path[PATH_MAX]; |
98 | }; | 94 | }; |
99 | 95 | ||
@@ -118,7 +114,7 @@ static int root_count; | |||
118 | * extra work in the fork/exit path if none of the subsystems need to | 114 | * extra work in the fork/exit path if none of the subsystems need to |
119 | * be called. | 115 | * be called. |
120 | */ | 116 | */ |
121 | static int need_forkexit_callback; | 117 | static int need_forkexit_callback __read_mostly; |
122 | static int need_mm_owner_callback __read_mostly; | 118 | static int need_mm_owner_callback __read_mostly; |
123 | 119 | ||
124 | /* convenient tests for these bits */ | 120 | /* convenient tests for these bits */ |
@@ -220,7 +216,7 @@ static struct hlist_head *css_set_hash(struct cgroup_subsys_state *css[]) | |||
220 | * task until after the first call to cgroup_iter_start(). This | 216 | * task until after the first call to cgroup_iter_start(). This |
221 | * reduces the fork()/exit() overhead for people who have cgroups | 217 | * reduces the fork()/exit() overhead for people who have cgroups |
222 | * compiled into their kernel but not actually in use */ | 218 | * compiled into their kernel but not actually in use */ |
223 | static int use_task_css_set_links; | 219 | static int use_task_css_set_links __read_mostly; |
224 | 220 | ||
225 | /* When we create or destroy a css_set, the operation simply | 221 | /* When we create or destroy a css_set, the operation simply |
226 | * takes/releases a reference count on all the cgroups referenced | 222 | * takes/releases a reference count on all the cgroups referenced |
@@ -241,17 +237,20 @@ static int use_task_css_set_links; | |||
241 | */ | 237 | */ |
242 | static void unlink_css_set(struct css_set *cg) | 238 | static void unlink_css_set(struct css_set *cg) |
243 | { | 239 | { |
240 | struct cg_cgroup_link *link; | ||
241 | struct cg_cgroup_link *saved_link; | ||
242 | |||
244 | write_lock(&css_set_lock); | 243 | write_lock(&css_set_lock); |
245 | hlist_del(&cg->hlist); | 244 | hlist_del(&cg->hlist); |
246 | css_set_count--; | 245 | css_set_count--; |
247 | while (!list_empty(&cg->cg_links)) { | 246 | |
248 | struct cg_cgroup_link *link; | 247 | list_for_each_entry_safe(link, saved_link, &cg->cg_links, |
249 | link = list_entry(cg->cg_links.next, | 248 | cg_link_list) { |
250 | struct cg_cgroup_link, cg_link_list); | ||
251 | list_del(&link->cg_link_list); | 249 | list_del(&link->cg_link_list); |
252 | list_del(&link->cgrp_link_list); | 250 | list_del(&link->cgrp_link_list); |
253 | kfree(link); | 251 | kfree(link); |
254 | } | 252 | } |
253 | |||
255 | write_unlock(&css_set_lock); | 254 | write_unlock(&css_set_lock); |
256 | } | 255 | } |
257 | 256 | ||
@@ -363,15 +362,14 @@ static struct css_set *find_existing_css_set( | |||
363 | static int allocate_cg_links(int count, struct list_head *tmp) | 362 | static int allocate_cg_links(int count, struct list_head *tmp) |
364 | { | 363 | { |
365 | struct cg_cgroup_link *link; | 364 | struct cg_cgroup_link *link; |
365 | struct cg_cgroup_link *saved_link; | ||
366 | int i; | 366 | int i; |
367 | INIT_LIST_HEAD(tmp); | 367 | INIT_LIST_HEAD(tmp); |
368 | for (i = 0; i < count; i++) { | 368 | for (i = 0; i < count; i++) { |
369 | link = kmalloc(sizeof(*link), GFP_KERNEL); | 369 | link = kmalloc(sizeof(*link), GFP_KERNEL); |
370 | if (!link) { | 370 | if (!link) { |
371 | while (!list_empty(tmp)) { | 371 | list_for_each_entry_safe(link, saved_link, tmp, |
372 | link = list_entry(tmp->next, | 372 | cgrp_link_list) { |
373 | struct cg_cgroup_link, | ||
374 | cgrp_link_list); | ||
375 | list_del(&link->cgrp_link_list); | 373 | list_del(&link->cgrp_link_list); |
376 | kfree(link); | 374 | kfree(link); |
377 | } | 375 | } |
@@ -384,11 +382,10 @@ static int allocate_cg_links(int count, struct list_head *tmp) | |||
384 | 382 | ||
385 | static void free_cg_links(struct list_head *tmp) | 383 | static void free_cg_links(struct list_head *tmp) |
386 | { | 384 | { |
387 | while (!list_empty(tmp)) { | 385 | struct cg_cgroup_link *link; |
388 | struct cg_cgroup_link *link; | 386 | struct cg_cgroup_link *saved_link; |
389 | link = list_entry(tmp->next, | 387 | |
390 | struct cg_cgroup_link, | 388 | list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) { |
391 | cgrp_link_list); | ||
392 | list_del(&link->cgrp_link_list); | 389 | list_del(&link->cgrp_link_list); |
393 | kfree(link); | 390 | kfree(link); |
394 | } | 391 | } |
@@ -415,11 +412,11 @@ static struct css_set *find_css_set( | |||
415 | 412 | ||
416 | /* First see if we already have a cgroup group that matches | 413 | /* First see if we already have a cgroup group that matches |
417 | * the desired set */ | 414 | * the desired set */ |
418 | write_lock(&css_set_lock); | 415 | read_lock(&css_set_lock); |
419 | res = find_existing_css_set(oldcg, cgrp, template); | 416 | res = find_existing_css_set(oldcg, cgrp, template); |
420 | if (res) | 417 | if (res) |
421 | get_css_set(res); | 418 | get_css_set(res); |
422 | write_unlock(&css_set_lock); | 419 | read_unlock(&css_set_lock); |
423 | 420 | ||
424 | if (res) | 421 | if (res) |
425 | return res; | 422 | return res; |
@@ -507,10 +504,6 @@ static struct css_set *find_css_set( | |||
507 | * knows that the cgroup won't be removed, as cgroup_rmdir() | 504 | * knows that the cgroup won't be removed, as cgroup_rmdir() |
508 | * needs that mutex. | 505 | * needs that mutex. |
509 | * | 506 | * |
510 | * The cgroup_common_file_write handler for operations that modify | ||
511 | * the cgroup hierarchy holds cgroup_mutex across the entire operation, | ||
512 | * single threading all such cgroup modifications across the system. | ||
513 | * | ||
514 | * The fork and exit callbacks cgroup_fork() and cgroup_exit(), don't | 507 | * The fork and exit callbacks cgroup_fork() and cgroup_exit(), don't |
515 | * (usually) take cgroup_mutex. These are the two most performance | 508 | * (usually) take cgroup_mutex. These are the two most performance |
516 | * critical pieces of code here. The exception occurs on cgroup_exit(), | 509 | * critical pieces of code here. The exception occurs on cgroup_exit(), |
@@ -1093,6 +1086,8 @@ static void cgroup_kill_sb(struct super_block *sb) { | |||
1093 | struct cgroupfs_root *root = sb->s_fs_info; | 1086 | struct cgroupfs_root *root = sb->s_fs_info; |
1094 | struct cgroup *cgrp = &root->top_cgroup; | 1087 | struct cgroup *cgrp = &root->top_cgroup; |
1095 | int ret; | 1088 | int ret; |
1089 | struct cg_cgroup_link *link; | ||
1090 | struct cg_cgroup_link *saved_link; | ||
1096 | 1091 | ||
1097 | BUG_ON(!root); | 1092 | BUG_ON(!root); |
1098 | 1093 | ||
@@ -1112,10 +1107,9 @@ static void cgroup_kill_sb(struct super_block *sb) { | |||
1112 | * root cgroup | 1107 | * root cgroup |
1113 | */ | 1108 | */ |
1114 | write_lock(&css_set_lock); | 1109 | write_lock(&css_set_lock); |
1115 | while (!list_empty(&cgrp->css_sets)) { | 1110 | |
1116 | struct cg_cgroup_link *link; | 1111 | list_for_each_entry_safe(link, saved_link, &cgrp->css_sets, |
1117 | link = list_entry(cgrp->css_sets.next, | 1112 | cgrp_link_list) { |
1118 | struct cg_cgroup_link, cgrp_link_list); | ||
1119 | list_del(&link->cg_link_list); | 1113 | list_del(&link->cg_link_list); |
1120 | list_del(&link->cgrp_link_list); | 1114 | list_del(&link->cgrp_link_list); |
1121 | kfree(link); | 1115 | kfree(link); |
@@ -1281,18 +1275,14 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | |||
1281 | } | 1275 | } |
1282 | 1276 | ||
1283 | /* | 1277 | /* |
1284 | * Attach task with pid 'pid' to cgroup 'cgrp'. Call with | 1278 | * Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex |
1285 | * cgroup_mutex, may take task_lock of task | 1279 | * held. May take task_lock of task |
1286 | */ | 1280 | */ |
1287 | static int attach_task_by_pid(struct cgroup *cgrp, char *pidbuf) | 1281 | static int attach_task_by_pid(struct cgroup *cgrp, u64 pid) |
1288 | { | 1282 | { |
1289 | pid_t pid; | ||
1290 | struct task_struct *tsk; | 1283 | struct task_struct *tsk; |
1291 | int ret; | 1284 | int ret; |
1292 | 1285 | ||
1293 | if (sscanf(pidbuf, "%d", &pid) != 1) | ||
1294 | return -EIO; | ||
1295 | |||
1296 | if (pid) { | 1286 | if (pid) { |
1297 | rcu_read_lock(); | 1287 | rcu_read_lock(); |
1298 | tsk = find_task_by_vpid(pid); | 1288 | tsk = find_task_by_vpid(pid); |
@@ -1318,6 +1308,16 @@ static int attach_task_by_pid(struct cgroup *cgrp, char *pidbuf) | |||
1318 | return ret; | 1308 | return ret; |
1319 | } | 1309 | } |
1320 | 1310 | ||
1311 | static int cgroup_tasks_write(struct cgroup *cgrp, struct cftype *cft, u64 pid) | ||
1312 | { | ||
1313 | int ret; | ||
1314 | if (!cgroup_lock_live_group(cgrp)) | ||
1315 | return -ENODEV; | ||
1316 | ret = attach_task_by_pid(cgrp, pid); | ||
1317 | cgroup_unlock(); | ||
1318 | return ret; | ||
1319 | } | ||
1320 | |||
1321 | /* The various types of files and directories in a cgroup file system */ | 1321 | /* The various types of files and directories in a cgroup file system */ |
1322 | enum cgroup_filetype { | 1322 | enum cgroup_filetype { |
1323 | FILE_ROOT, | 1323 | FILE_ROOT, |
@@ -1327,12 +1327,54 @@ enum cgroup_filetype { | |||
1327 | FILE_RELEASE_AGENT, | 1327 | FILE_RELEASE_AGENT, |
1328 | }; | 1328 | }; |
1329 | 1329 | ||
1330 | /** | ||
1331 | * cgroup_lock_live_group - take cgroup_mutex and check that cgrp is alive. | ||
1332 | * @cgrp: the cgroup to be checked for liveness | ||
1333 | * | ||
1334 | * On success, returns true; the lock should be later released with | ||
1335 | * cgroup_unlock(). On failure returns false with no lock held. | ||
1336 | */ | ||
1337 | bool cgroup_lock_live_group(struct cgroup *cgrp) | ||
1338 | { | ||
1339 | mutex_lock(&cgroup_mutex); | ||
1340 | if (cgroup_is_removed(cgrp)) { | ||
1341 | mutex_unlock(&cgroup_mutex); | ||
1342 | return false; | ||
1343 | } | ||
1344 | return true; | ||
1345 | } | ||
1346 | |||
1347 | static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, | ||
1348 | const char *buffer) | ||
1349 | { | ||
1350 | BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX); | ||
1351 | if (!cgroup_lock_live_group(cgrp)) | ||
1352 | return -ENODEV; | ||
1353 | strcpy(cgrp->root->release_agent_path, buffer); | ||
1354 | cgroup_unlock(); | ||
1355 | return 0; | ||
1356 | } | ||
1357 | |||
1358 | static int cgroup_release_agent_show(struct cgroup *cgrp, struct cftype *cft, | ||
1359 | struct seq_file *seq) | ||
1360 | { | ||
1361 | if (!cgroup_lock_live_group(cgrp)) | ||
1362 | return -ENODEV; | ||
1363 | seq_puts(seq, cgrp->root->release_agent_path); | ||
1364 | seq_putc(seq, '\n'); | ||
1365 | cgroup_unlock(); | ||
1366 | return 0; | ||
1367 | } | ||
1368 | |||
1369 | /* A buffer size big enough for numbers or short strings */ | ||
1370 | #define CGROUP_LOCAL_BUFFER_SIZE 64 | ||
1371 | |||
1330 | static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft, | 1372 | static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft, |
1331 | struct file *file, | 1373 | struct file *file, |
1332 | const char __user *userbuf, | 1374 | const char __user *userbuf, |
1333 | size_t nbytes, loff_t *unused_ppos) | 1375 | size_t nbytes, loff_t *unused_ppos) |
1334 | { | 1376 | { |
1335 | char buffer[64]; | 1377 | char buffer[CGROUP_LOCAL_BUFFER_SIZE]; |
1336 | int retval = 0; | 1378 | int retval = 0; |
1337 | char *end; | 1379 | char *end; |
1338 | 1380 | ||
@@ -1361,68 +1403,36 @@ static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft, | |||
1361 | return retval; | 1403 | return retval; |
1362 | } | 1404 | } |
1363 | 1405 | ||
1364 | static ssize_t cgroup_common_file_write(struct cgroup *cgrp, | 1406 | static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft, |
1365 | struct cftype *cft, | 1407 | struct file *file, |
1366 | struct file *file, | 1408 | const char __user *userbuf, |
1367 | const char __user *userbuf, | 1409 | size_t nbytes, loff_t *unused_ppos) |
1368 | size_t nbytes, loff_t *unused_ppos) | ||
1369 | { | 1410 | { |
1370 | enum cgroup_filetype type = cft->private; | 1411 | char local_buffer[CGROUP_LOCAL_BUFFER_SIZE]; |
1371 | char *buffer; | ||
1372 | int retval = 0; | 1412 | int retval = 0; |
1413 | size_t max_bytes = cft->max_write_len; | ||
1414 | char *buffer = local_buffer; | ||
1373 | 1415 | ||
1374 | if (nbytes >= PATH_MAX) | 1416 | if (!max_bytes) |
1417 | max_bytes = sizeof(local_buffer) - 1; | ||
1418 | if (nbytes >= max_bytes) | ||
1375 | return -E2BIG; | 1419 | return -E2BIG; |
1376 | 1420 | /* Allocate a dynamic buffer if we need one */ | |
1377 | /* +1 for nul-terminator */ | 1421 | if (nbytes >= sizeof(local_buffer)) { |
1378 | buffer = kmalloc(nbytes + 1, GFP_KERNEL); | 1422 | buffer = kmalloc(nbytes + 1, GFP_KERNEL); |
1379 | if (buffer == NULL) | 1423 | if (buffer == NULL) |
1380 | return -ENOMEM; | 1424 | return -ENOMEM; |
1381 | |||
1382 | if (copy_from_user(buffer, userbuf, nbytes)) { | ||
1383 | retval = -EFAULT; | ||
1384 | goto out1; | ||
1385 | } | 1425 | } |
1386 | buffer[nbytes] = 0; /* nul-terminate */ | 1426 | if (nbytes && copy_from_user(buffer, userbuf, nbytes)) |
1387 | strstrip(buffer); /* strip -just- trailing whitespace */ | 1427 | return -EFAULT; |
1388 | |||
1389 | mutex_lock(&cgroup_mutex); | ||
1390 | 1428 | ||
1391 | /* | 1429 | buffer[nbytes] = 0; /* nul-terminate */ |
1392 | * This was already checked for in cgroup_file_write(), but | 1430 | strstrip(buffer); |
1393 | * check again now we're holding cgroup_mutex. | 1431 | retval = cft->write_string(cgrp, cft, buffer); |
1394 | */ | 1432 | if (!retval) |
1395 | if (cgroup_is_removed(cgrp)) { | ||
1396 | retval = -ENODEV; | ||
1397 | goto out2; | ||
1398 | } | ||
1399 | |||
1400 | switch (type) { | ||
1401 | case FILE_TASKLIST: | ||
1402 | retval = attach_task_by_pid(cgrp, buffer); | ||
1403 | break; | ||
1404 | case FILE_NOTIFY_ON_RELEASE: | ||
1405 | clear_bit(CGRP_RELEASABLE, &cgrp->flags); | ||
1406 | if (simple_strtoul(buffer, NULL, 10) != 0) | ||
1407 | set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); | ||
1408 | else | ||
1409 | clear_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); | ||
1410 | break; | ||
1411 | case FILE_RELEASE_AGENT: | ||
1412 | BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX); | ||
1413 | strcpy(cgrp->root->release_agent_path, buffer); | ||
1414 | break; | ||
1415 | default: | ||
1416 | retval = -EINVAL; | ||
1417 | goto out2; | ||
1418 | } | ||
1419 | |||
1420 | if (retval == 0) | ||
1421 | retval = nbytes; | 1433 | retval = nbytes; |
1422 | out2: | 1434 | if (buffer != local_buffer) |
1423 | mutex_unlock(&cgroup_mutex); | 1435 | kfree(buffer); |
1424 | out1: | ||
1425 | kfree(buffer); | ||
1426 | return retval; | 1436 | return retval; |
1427 | } | 1437 | } |
1428 | 1438 | ||
@@ -1438,6 +1448,8 @@ static ssize_t cgroup_file_write(struct file *file, const char __user *buf, | |||
1438 | return cft->write(cgrp, cft, file, buf, nbytes, ppos); | 1448 | return cft->write(cgrp, cft, file, buf, nbytes, ppos); |
1439 | if (cft->write_u64 || cft->write_s64) | 1449 | if (cft->write_u64 || cft->write_s64) |
1440 | return cgroup_write_X64(cgrp, cft, file, buf, nbytes, ppos); | 1450 | return cgroup_write_X64(cgrp, cft, file, buf, nbytes, ppos); |
1451 | if (cft->write_string) | ||
1452 | return cgroup_write_string(cgrp, cft, file, buf, nbytes, ppos); | ||
1441 | if (cft->trigger) { | 1453 | if (cft->trigger) { |
1442 | int ret = cft->trigger(cgrp, (unsigned int)cft->private); | 1454 | int ret = cft->trigger(cgrp, (unsigned int)cft->private); |
1443 | return ret ? ret : nbytes; | 1455 | return ret ? ret : nbytes; |
@@ -1450,7 +1462,7 @@ static ssize_t cgroup_read_u64(struct cgroup *cgrp, struct cftype *cft, | |||
1450 | char __user *buf, size_t nbytes, | 1462 | char __user *buf, size_t nbytes, |
1451 | loff_t *ppos) | 1463 | loff_t *ppos) |
1452 | { | 1464 | { |
1453 | char tmp[64]; | 1465 | char tmp[CGROUP_LOCAL_BUFFER_SIZE]; |
1454 | u64 val = cft->read_u64(cgrp, cft); | 1466 | u64 val = cft->read_u64(cgrp, cft); |
1455 | int len = sprintf(tmp, "%llu\n", (unsigned long long) val); | 1467 | int len = sprintf(tmp, "%llu\n", (unsigned long long) val); |
1456 | 1468 | ||
@@ -1462,56 +1474,13 @@ static ssize_t cgroup_read_s64(struct cgroup *cgrp, struct cftype *cft, | |||
1462 | char __user *buf, size_t nbytes, | 1474 | char __user *buf, size_t nbytes, |
1463 | loff_t *ppos) | 1475 | loff_t *ppos) |
1464 | { | 1476 | { |
1465 | char tmp[64]; | 1477 | char tmp[CGROUP_LOCAL_BUFFER_SIZE]; |
1466 | s64 val = cft->read_s64(cgrp, cft); | 1478 | s64 val = cft->read_s64(cgrp, cft); |
1467 | int len = sprintf(tmp, "%lld\n", (long long) val); | 1479 | int len = sprintf(tmp, "%lld\n", (long long) val); |
1468 | 1480 | ||
1469 | return simple_read_from_buffer(buf, nbytes, ppos, tmp, len); | 1481 | return simple_read_from_buffer(buf, nbytes, ppos, tmp, len); |
1470 | } | 1482 | } |
1471 | 1483 | ||
1472 | static ssize_t cgroup_common_file_read(struct cgroup *cgrp, | ||
1473 | struct cftype *cft, | ||
1474 | struct file *file, | ||
1475 | char __user *buf, | ||
1476 | size_t nbytes, loff_t *ppos) | ||
1477 | { | ||
1478 | enum cgroup_filetype type = cft->private; | ||
1479 | char *page; | ||
1480 | ssize_t retval = 0; | ||
1481 | char *s; | ||
1482 | |||
1483 | if (!(page = (char *)__get_free_page(GFP_KERNEL))) | ||
1484 | return -ENOMEM; | ||
1485 | |||
1486 | s = page; | ||
1487 | |||
1488 | switch (type) { | ||
1489 | case FILE_RELEASE_AGENT: | ||
1490 | { | ||
1491 | struct cgroupfs_root *root; | ||
1492 | size_t n; | ||
1493 | mutex_lock(&cgroup_mutex); | ||
1494 | root = cgrp->root; | ||
1495 | n = strnlen(root->release_agent_path, | ||
1496 | sizeof(root->release_agent_path)); | ||
1497 | n = min(n, (size_t) PAGE_SIZE); | ||
1498 | strncpy(s, root->release_agent_path, n); | ||
1499 | mutex_unlock(&cgroup_mutex); | ||
1500 | s += n; | ||
1501 | break; | ||
1502 | } | ||
1503 | default: | ||
1504 | retval = -EINVAL; | ||
1505 | goto out; | ||
1506 | } | ||
1507 | *s++ = '\n'; | ||
1508 | |||
1509 | retval = simple_read_from_buffer(buf, nbytes, ppos, page, s - page); | ||
1510 | out: | ||
1511 | free_page((unsigned long)page); | ||
1512 | return retval; | ||
1513 | } | ||
1514 | |||
1515 | static ssize_t cgroup_file_read(struct file *file, char __user *buf, | 1484 | static ssize_t cgroup_file_read(struct file *file, char __user *buf, |
1516 | size_t nbytes, loff_t *ppos) | 1485 | size_t nbytes, loff_t *ppos) |
1517 | { | 1486 | { |
@@ -1569,6 +1538,7 @@ int cgroup_seqfile_release(struct inode *inode, struct file *file) | |||
1569 | 1538 | ||
1570 | static struct file_operations cgroup_seqfile_operations = { | 1539 | static struct file_operations cgroup_seqfile_operations = { |
1571 | .read = seq_read, | 1540 | .read = seq_read, |
1541 | .write = cgroup_file_write, | ||
1572 | .llseek = seq_lseek, | 1542 | .llseek = seq_lseek, |
1573 | .release = cgroup_seqfile_release, | 1543 | .release = cgroup_seqfile_release, |
1574 | }; | 1544 | }; |
@@ -1756,15 +1726,11 @@ int cgroup_add_files(struct cgroup *cgrp, | |||
1756 | int cgroup_task_count(const struct cgroup *cgrp) | 1726 | int cgroup_task_count(const struct cgroup *cgrp) |
1757 | { | 1727 | { |
1758 | int count = 0; | 1728 | int count = 0; |
1759 | struct list_head *l; | 1729 | struct cg_cgroup_link *link; |
1760 | 1730 | ||
1761 | read_lock(&css_set_lock); | 1731 | read_lock(&css_set_lock); |
1762 | l = cgrp->css_sets.next; | 1732 | list_for_each_entry(link, &cgrp->css_sets, cgrp_link_list) { |
1763 | while (l != &cgrp->css_sets) { | ||
1764 | struct cg_cgroup_link *link = | ||
1765 | list_entry(l, struct cg_cgroup_link, cgrp_link_list); | ||
1766 | count += atomic_read(&link->cg->ref.refcount); | 1733 | count += atomic_read(&link->cg->ref.refcount); |
1767 | l = l->next; | ||
1768 | } | 1734 | } |
1769 | read_unlock(&css_set_lock); | 1735 | read_unlock(&css_set_lock); |
1770 | return count; | 1736 | return count; |
@@ -2227,6 +2193,18 @@ static u64 cgroup_read_notify_on_release(struct cgroup *cgrp, | |||
2227 | return notify_on_release(cgrp); | 2193 | return notify_on_release(cgrp); |
2228 | } | 2194 | } |
2229 | 2195 | ||
2196 | static int cgroup_write_notify_on_release(struct cgroup *cgrp, | ||
2197 | struct cftype *cft, | ||
2198 | u64 val) | ||
2199 | { | ||
2200 | clear_bit(CGRP_RELEASABLE, &cgrp->flags); | ||
2201 | if (val) | ||
2202 | set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); | ||
2203 | else | ||
2204 | clear_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); | ||
2205 | return 0; | ||
2206 | } | ||
2207 | |||
2230 | /* | 2208 | /* |
2231 | * for the common functions, 'private' gives the type of file | 2209 | * for the common functions, 'private' gives the type of file |
2232 | */ | 2210 | */ |
@@ -2235,7 +2213,7 @@ static struct cftype files[] = { | |||
2235 | .name = "tasks", | 2213 | .name = "tasks", |
2236 | .open = cgroup_tasks_open, | 2214 | .open = cgroup_tasks_open, |
2237 | .read = cgroup_tasks_read, | 2215 | .read = cgroup_tasks_read, |
2238 | .write = cgroup_common_file_write, | 2216 | .write_u64 = cgroup_tasks_write, |
2239 | .release = cgroup_tasks_release, | 2217 | .release = cgroup_tasks_release, |
2240 | .private = FILE_TASKLIST, | 2218 | .private = FILE_TASKLIST, |
2241 | }, | 2219 | }, |
@@ -2243,15 +2221,16 @@ static struct cftype files[] = { | |||
2243 | { | 2221 | { |
2244 | .name = "notify_on_release", | 2222 | .name = "notify_on_release", |
2245 | .read_u64 = cgroup_read_notify_on_release, | 2223 | .read_u64 = cgroup_read_notify_on_release, |
2246 | .write = cgroup_common_file_write, | 2224 | .write_u64 = cgroup_write_notify_on_release, |
2247 | .private = FILE_NOTIFY_ON_RELEASE, | 2225 | .private = FILE_NOTIFY_ON_RELEASE, |
2248 | }, | 2226 | }, |
2249 | }; | 2227 | }; |
2250 | 2228 | ||
2251 | static struct cftype cft_release_agent = { | 2229 | static struct cftype cft_release_agent = { |
2252 | .name = "release_agent", | 2230 | .name = "release_agent", |
2253 | .read = cgroup_common_file_read, | 2231 | .read_seq_string = cgroup_release_agent_show, |
2254 | .write = cgroup_common_file_write, | 2232 | .write_string = cgroup_release_agent_write, |
2233 | .max_write_len = PATH_MAX, | ||
2255 | .private = FILE_RELEASE_AGENT, | 2234 | .private = FILE_RELEASE_AGENT, |
2256 | }; | 2235 | }; |
2257 | 2236 | ||
@@ -2869,16 +2848,17 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks) | |||
2869 | * cgroup_clone - clone the cgroup the given subsystem is attached to | 2848 | * cgroup_clone - clone the cgroup the given subsystem is attached to |
2870 | * @tsk: the task to be moved | 2849 | * @tsk: the task to be moved |
2871 | * @subsys: the given subsystem | 2850 | * @subsys: the given subsystem |
2851 | * @nodename: the name for the new cgroup | ||
2872 | * | 2852 | * |
2873 | * Duplicate the current cgroup in the hierarchy that the given | 2853 | * Duplicate the current cgroup in the hierarchy that the given |
2874 | * subsystem is attached to, and move this task into the new | 2854 | * subsystem is attached to, and move this task into the new |
2875 | * child. | 2855 | * child. |
2876 | */ | 2856 | */ |
2877 | int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *subsys) | 2857 | int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *subsys, |
2858 | char *nodename) | ||
2878 | { | 2859 | { |
2879 | struct dentry *dentry; | 2860 | struct dentry *dentry; |
2880 | int ret = 0; | 2861 | int ret = 0; |
2881 | char nodename[MAX_CGROUP_TYPE_NAMELEN]; | ||
2882 | struct cgroup *parent, *child; | 2862 | struct cgroup *parent, *child; |
2883 | struct inode *inode; | 2863 | struct inode *inode; |
2884 | struct css_set *cg; | 2864 | struct css_set *cg; |
@@ -2903,8 +2883,6 @@ int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *subsys) | |||
2903 | cg = tsk->cgroups; | 2883 | cg = tsk->cgroups; |
2904 | parent = task_cgroup(tsk, subsys->subsys_id); | 2884 | parent = task_cgroup(tsk, subsys->subsys_id); |
2905 | 2885 | ||
2906 | snprintf(nodename, MAX_CGROUP_TYPE_NAMELEN, "%d", tsk->pid); | ||
2907 | |||
2908 | /* Pin the hierarchy */ | 2886 | /* Pin the hierarchy */ |
2909 | atomic_inc(&parent->root->sb->s_active); | 2887 | atomic_inc(&parent->root->sb->s_active); |
2910 | 2888 | ||
@@ -3078,27 +3056,24 @@ static void cgroup_release_agent(struct work_struct *work) | |||
3078 | while (!list_empty(&release_list)) { | 3056 | while (!list_empty(&release_list)) { |
3079 | char *argv[3], *envp[3]; | 3057 | char *argv[3], *envp[3]; |
3080 | int i; | 3058 | int i; |
3081 | char *pathbuf; | 3059 | char *pathbuf = NULL, *agentbuf = NULL; |
3082 | struct cgroup *cgrp = list_entry(release_list.next, | 3060 | struct cgroup *cgrp = list_entry(release_list.next, |
3083 | struct cgroup, | 3061 | struct cgroup, |
3084 | release_list); | 3062 | release_list); |
3085 | list_del_init(&cgrp->release_list); | 3063 | list_del_init(&cgrp->release_list); |
3086 | spin_unlock(&release_list_lock); | 3064 | spin_unlock(&release_list_lock); |
3087 | pathbuf = kmalloc(PAGE_SIZE, GFP_KERNEL); | 3065 | pathbuf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
3088 | if (!pathbuf) { | 3066 | if (!pathbuf) |
3089 | spin_lock(&release_list_lock); | 3067 | goto continue_free; |
3090 | continue; | 3068 | if (cgroup_path(cgrp, pathbuf, PAGE_SIZE) < 0) |
3091 | } | 3069 | goto continue_free; |
3092 | 3070 | agentbuf = kstrdup(cgrp->root->release_agent_path, GFP_KERNEL); | |
3093 | if (cgroup_path(cgrp, pathbuf, PAGE_SIZE) < 0) { | 3071 | if (!agentbuf) |
3094 | kfree(pathbuf); | 3072 | goto continue_free; |
3095 | spin_lock(&release_list_lock); | ||
3096 | continue; | ||
3097 | } | ||
3098 | 3073 | ||
3099 | i = 0; | 3074 | i = 0; |
3100 | argv[i++] = cgrp->root->release_agent_path; | 3075 | argv[i++] = agentbuf; |
3101 | argv[i++] = (char *)pathbuf; | 3076 | argv[i++] = pathbuf; |
3102 | argv[i] = NULL; | 3077 | argv[i] = NULL; |
3103 | 3078 | ||
3104 | i = 0; | 3079 | i = 0; |
@@ -3112,8 +3087,10 @@ static void cgroup_release_agent(struct work_struct *work) | |||
3112 | * be a slow process */ | 3087 | * be a slow process */ |
3113 | mutex_unlock(&cgroup_mutex); | 3088 | mutex_unlock(&cgroup_mutex); |
3114 | call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); | 3089 | call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); |
3115 | kfree(pathbuf); | ||
3116 | mutex_lock(&cgroup_mutex); | 3090 | mutex_lock(&cgroup_mutex); |
3091 | continue_free: | ||
3092 | kfree(pathbuf); | ||
3093 | kfree(agentbuf); | ||
3117 | spin_lock(&release_list_lock); | 3094 | spin_lock(&release_list_lock); |
3118 | } | 3095 | } |
3119 | spin_unlock(&release_list_lock); | 3096 | spin_unlock(&release_list_lock); |
diff --git a/kernel/cpu.c b/kernel/cpu.c index cfb1d43ab801..10ba5f1004a5 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
@@ -64,6 +64,8 @@ void __init cpu_hotplug_init(void) | |||
64 | cpu_hotplug.refcount = 0; | 64 | cpu_hotplug.refcount = 0; |
65 | } | 65 | } |
66 | 66 | ||
67 | cpumask_t cpu_active_map; | ||
68 | |||
67 | #ifdef CONFIG_HOTPLUG_CPU | 69 | #ifdef CONFIG_HOTPLUG_CPU |
68 | 70 | ||
69 | void get_online_cpus(void) | 71 | void get_online_cpus(void) |
@@ -283,6 +285,11 @@ out_allowed: | |||
283 | set_cpus_allowed_ptr(current, &old_allowed); | 285 | set_cpus_allowed_ptr(current, &old_allowed); |
284 | out_release: | 286 | out_release: |
285 | cpu_hotplug_done(); | 287 | cpu_hotplug_done(); |
288 | if (!err) { | ||
289 | if (raw_notifier_call_chain(&cpu_chain, CPU_POST_DEAD | mod, | ||
290 | hcpu) == NOTIFY_BAD) | ||
291 | BUG(); | ||
292 | } | ||
286 | return err; | 293 | return err; |
287 | } | 294 | } |
288 | 295 | ||
@@ -291,11 +298,30 @@ int __ref cpu_down(unsigned int cpu) | |||
291 | int err = 0; | 298 | int err = 0; |
292 | 299 | ||
293 | cpu_maps_update_begin(); | 300 | cpu_maps_update_begin(); |
294 | if (cpu_hotplug_disabled) | 301 | |
302 | if (cpu_hotplug_disabled) { | ||
295 | err = -EBUSY; | 303 | err = -EBUSY; |
296 | else | 304 | goto out; |
297 | err = _cpu_down(cpu, 0); | 305 | } |
306 | |||
307 | cpu_clear(cpu, cpu_active_map); | ||
308 | |||
309 | /* | ||
310 | * Make sure the all cpus did the reschedule and are not | ||
311 | * using stale version of the cpu_active_map. | ||
312 | * This is not strictly necessary becuase stop_machine() | ||
313 | * that we run down the line already provides the required | ||
314 | * synchronization. But it's really a side effect and we do not | ||
315 | * want to depend on the innards of the stop_machine here. | ||
316 | */ | ||
317 | synchronize_sched(); | ||
318 | |||
319 | err = _cpu_down(cpu, 0); | ||
320 | |||
321 | if (cpu_online(cpu)) | ||
322 | cpu_set(cpu, cpu_active_map); | ||
298 | 323 | ||
324 | out: | ||
299 | cpu_maps_update_done(); | 325 | cpu_maps_update_done(); |
300 | return err; | 326 | return err; |
301 | } | 327 | } |
@@ -355,11 +381,18 @@ int __cpuinit cpu_up(unsigned int cpu) | |||
355 | } | 381 | } |
356 | 382 | ||
357 | cpu_maps_update_begin(); | 383 | cpu_maps_update_begin(); |
358 | if (cpu_hotplug_disabled) | 384 | |
385 | if (cpu_hotplug_disabled) { | ||
359 | err = -EBUSY; | 386 | err = -EBUSY; |
360 | else | 387 | goto out; |
361 | err = _cpu_up(cpu, 0); | 388 | } |
389 | |||
390 | err = _cpu_up(cpu, 0); | ||
362 | 391 | ||
392 | if (cpu_online(cpu)) | ||
393 | cpu_set(cpu, cpu_active_map); | ||
394 | |||
395 | out: | ||
363 | cpu_maps_update_done(); | 396 | cpu_maps_update_done(); |
364 | return err; | 397 | return err; |
365 | } | 398 | } |
@@ -413,7 +446,7 @@ void __ref enable_nonboot_cpus(void) | |||
413 | goto out; | 446 | goto out; |
414 | 447 | ||
415 | printk("Enabling non-boot CPUs ...\n"); | 448 | printk("Enabling non-boot CPUs ...\n"); |
416 | for_each_cpu_mask(cpu, frozen_cpus) { | 449 | for_each_cpu_mask_nr(cpu, frozen_cpus) { |
417 | error = _cpu_up(cpu, 1); | 450 | error = _cpu_up(cpu, 1); |
418 | if (!error) { | 451 | if (!error) { |
419 | printk("CPU%d is up\n", cpu); | 452 | printk("CPU%d is up\n", cpu); |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 459d601947a8..91cf85b36dd5 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -227,10 +227,6 @@ static struct cpuset top_cpuset = { | |||
227 | * The task_struct fields mems_allowed and mems_generation may only | 227 | * The task_struct fields mems_allowed and mems_generation may only |
228 | * be accessed in the context of that task, so require no locks. | 228 | * be accessed in the context of that task, so require no locks. |
229 | * | 229 | * |
230 | * The cpuset_common_file_write handler for operations that modify | ||
231 | * the cpuset hierarchy holds cgroup_mutex across the entire operation, | ||
232 | * single threading all such cpuset modifications across the system. | ||
233 | * | ||
234 | * The cpuset_common_file_read() handlers only hold callback_mutex across | 230 | * The cpuset_common_file_read() handlers only hold callback_mutex across |
235 | * small pieces of code, such as when reading out possibly multi-word | 231 | * small pieces of code, such as when reading out possibly multi-word |
236 | * cpumasks and nodemasks. | 232 | * cpumasks and nodemasks. |
@@ -369,7 +365,7 @@ void cpuset_update_task_memory_state(void) | |||
369 | my_cpusets_mem_gen = top_cpuset.mems_generation; | 365 | my_cpusets_mem_gen = top_cpuset.mems_generation; |
370 | } else { | 366 | } else { |
371 | rcu_read_lock(); | 367 | rcu_read_lock(); |
372 | my_cpusets_mem_gen = task_cs(current)->mems_generation; | 368 | my_cpusets_mem_gen = task_cs(tsk)->mems_generation; |
373 | rcu_read_unlock(); | 369 | rcu_read_unlock(); |
374 | } | 370 | } |
375 | 371 | ||
@@ -500,11 +496,16 @@ update_domain_attr(struct sched_domain_attr *dattr, struct cpuset *c) | |||
500 | /* | 496 | /* |
501 | * rebuild_sched_domains() | 497 | * rebuild_sched_domains() |
502 | * | 498 | * |
503 | * If the flag 'sched_load_balance' of any cpuset with non-empty | 499 | * This routine will be called to rebuild the scheduler's dynamic |
504 | * 'cpus' changes, or if the 'cpus' allowed changes in any cpuset | 500 | * sched domains: |
505 | * which has that flag enabled, or if any cpuset with a non-empty | 501 | * - if the flag 'sched_load_balance' of any cpuset with non-empty |
506 | * 'cpus' is removed, then call this routine to rebuild the | 502 | * 'cpus' changes, |
507 | * scheduler's dynamic sched domains. | 503 | * - or if the 'cpus' allowed changes in any cpuset which has that |
504 | * flag enabled, | ||
505 | * - or if the 'sched_relax_domain_level' of any cpuset which has | ||
506 | * that flag enabled and with non-empty 'cpus' changes, | ||
507 | * - or if any cpuset with non-empty 'cpus' is removed, | ||
508 | * - or if a cpu gets offlined. | ||
508 | * | 509 | * |
509 | * This routine builds a partial partition of the systems CPUs | 510 | * This routine builds a partial partition of the systems CPUs |
510 | * (the set of non-overlappping cpumask_t's in the array 'part' | 511 | * (the set of non-overlappping cpumask_t's in the array 'part' |
@@ -564,7 +565,7 @@ update_domain_attr(struct sched_domain_attr *dattr, struct cpuset *c) | |||
564 | * partition_sched_domains(). | 565 | * partition_sched_domains(). |
565 | */ | 566 | */ |
566 | 567 | ||
567 | static void rebuild_sched_domains(void) | 568 | void rebuild_sched_domains(void) |
568 | { | 569 | { |
569 | struct kfifo *q; /* queue of cpusets to be scanned */ | 570 | struct kfifo *q; /* queue of cpusets to be scanned */ |
570 | struct cpuset *cp; /* scans q */ | 571 | struct cpuset *cp; /* scans q */ |
@@ -609,8 +610,13 @@ static void rebuild_sched_domains(void) | |||
609 | while (__kfifo_get(q, (void *)&cp, sizeof(cp))) { | 610 | while (__kfifo_get(q, (void *)&cp, sizeof(cp))) { |
610 | struct cgroup *cont; | 611 | struct cgroup *cont; |
611 | struct cpuset *child; /* scans child cpusets of cp */ | 612 | struct cpuset *child; /* scans child cpusets of cp */ |
613 | |||
614 | if (cpus_empty(cp->cpus_allowed)) | ||
615 | continue; | ||
616 | |||
612 | if (is_sched_load_balance(cp)) | 617 | if (is_sched_load_balance(cp)) |
613 | csa[csn++] = cp; | 618 | csa[csn++] = cp; |
619 | |||
614 | list_for_each_entry(cont, &cp->css.cgroup->children, sibling) { | 620 | list_for_each_entry(cont, &cp->css.cgroup->children, sibling) { |
615 | child = cgroup_cs(cont); | 621 | child = cgroup_cs(cont); |
616 | __kfifo_put(q, (void *)&child, sizeof(cp)); | 622 | __kfifo_put(q, (void *)&child, sizeof(cp)); |
@@ -679,7 +685,9 @@ restart: | |||
679 | if (apn == b->pn) { | 685 | if (apn == b->pn) { |
680 | cpus_or(*dp, *dp, b->cpus_allowed); | 686 | cpus_or(*dp, *dp, b->cpus_allowed); |
681 | b->pn = -1; | 687 | b->pn = -1; |
682 | update_domain_attr(dattr, b); | 688 | if (dattr) |
689 | update_domain_attr(dattr | ||
690 | + nslot, b); | ||
683 | } | 691 | } |
684 | } | 692 | } |
685 | nslot++; | 693 | nslot++; |
@@ -701,36 +709,6 @@ done: | |||
701 | /* Don't kfree(dattr) -- partition_sched_domains() does that. */ | 709 | /* Don't kfree(dattr) -- partition_sched_domains() does that. */ |
702 | } | 710 | } |
703 | 711 | ||
704 | static inline int started_after_time(struct task_struct *t1, | ||
705 | struct timespec *time, | ||
706 | struct task_struct *t2) | ||
707 | { | ||
708 | int start_diff = timespec_compare(&t1->start_time, time); | ||
709 | if (start_diff > 0) { | ||
710 | return 1; | ||
711 | } else if (start_diff < 0) { | ||
712 | return 0; | ||
713 | } else { | ||
714 | /* | ||
715 | * Arbitrarily, if two processes started at the same | ||
716 | * time, we'll say that the lower pointer value | ||
717 | * started first. Note that t2 may have exited by now | ||
718 | * so this may not be a valid pointer any longer, but | ||
719 | * that's fine - it still serves to distinguish | ||
720 | * between two tasks started (effectively) | ||
721 | * simultaneously. | ||
722 | */ | ||
723 | return t1 > t2; | ||
724 | } | ||
725 | } | ||
726 | |||
727 | static inline int started_after(void *p1, void *p2) | ||
728 | { | ||
729 | struct task_struct *t1 = p1; | ||
730 | struct task_struct *t2 = p2; | ||
731 | return started_after_time(t1, &t2->start_time, t2); | ||
732 | } | ||
733 | |||
734 | /** | 712 | /** |
735 | * cpuset_test_cpumask - test a task's cpus_allowed versus its cpuset's | 713 | * cpuset_test_cpumask - test a task's cpus_allowed versus its cpuset's |
736 | * @tsk: task to test | 714 | * @tsk: task to test |
@@ -766,15 +744,49 @@ static void cpuset_change_cpumask(struct task_struct *tsk, | |||
766 | } | 744 | } |
767 | 745 | ||
768 | /** | 746 | /** |
747 | * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. | ||
748 | * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed | ||
749 | * | ||
750 | * Called with cgroup_mutex held | ||
751 | * | ||
752 | * The cgroup_scan_tasks() function will scan all the tasks in a cgroup, | ||
753 | * calling callback functions for each. | ||
754 | * | ||
755 | * Return 0 if successful, -errno if not. | ||
756 | */ | ||
757 | static int update_tasks_cpumask(struct cpuset *cs) | ||
758 | { | ||
759 | struct cgroup_scanner scan; | ||
760 | struct ptr_heap heap; | ||
761 | int retval; | ||
762 | |||
763 | /* | ||
764 | * cgroup_scan_tasks() will initialize heap->gt for us. | ||
765 | * heap_init() is still needed here for we should not change | ||
766 | * cs->cpus_allowed when heap_init() fails. | ||
767 | */ | ||
768 | retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL); | ||
769 | if (retval) | ||
770 | return retval; | ||
771 | |||
772 | scan.cg = cs->css.cgroup; | ||
773 | scan.test_task = cpuset_test_cpumask; | ||
774 | scan.process_task = cpuset_change_cpumask; | ||
775 | scan.heap = &heap; | ||
776 | retval = cgroup_scan_tasks(&scan); | ||
777 | |||
778 | heap_free(&heap); | ||
779 | return retval; | ||
780 | } | ||
781 | |||
782 | /** | ||
769 | * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it | 783 | * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it |
770 | * @cs: the cpuset to consider | 784 | * @cs: the cpuset to consider |
771 | * @buf: buffer of cpu numbers written to this cpuset | 785 | * @buf: buffer of cpu numbers written to this cpuset |
772 | */ | 786 | */ |
773 | static int update_cpumask(struct cpuset *cs, char *buf) | 787 | static int update_cpumask(struct cpuset *cs, const char *buf) |
774 | { | 788 | { |
775 | struct cpuset trialcs; | 789 | struct cpuset trialcs; |
776 | struct cgroup_scanner scan; | ||
777 | struct ptr_heap heap; | ||
778 | int retval; | 790 | int retval; |
779 | int is_load_balanced; | 791 | int is_load_balanced; |
780 | 792 | ||
@@ -790,7 +802,6 @@ static int update_cpumask(struct cpuset *cs, char *buf) | |||
790 | * that parsing. The validate_change() call ensures that cpusets | 802 | * that parsing. The validate_change() call ensures that cpusets |
791 | * with tasks have cpus. | 803 | * with tasks have cpus. |
792 | */ | 804 | */ |
793 | buf = strstrip(buf); | ||
794 | if (!*buf) { | 805 | if (!*buf) { |
795 | cpus_clear(trialcs.cpus_allowed); | 806 | cpus_clear(trialcs.cpus_allowed); |
796 | } else { | 807 | } else { |
@@ -809,10 +820,6 @@ static int update_cpumask(struct cpuset *cs, char *buf) | |||
809 | if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed)) | 820 | if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed)) |
810 | return 0; | 821 | return 0; |
811 | 822 | ||
812 | retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, &started_after); | ||
813 | if (retval) | ||
814 | return retval; | ||
815 | |||
816 | is_load_balanced = is_sched_load_balance(&trialcs); | 823 | is_load_balanced = is_sched_load_balance(&trialcs); |
817 | 824 | ||
818 | mutex_lock(&callback_mutex); | 825 | mutex_lock(&callback_mutex); |
@@ -823,12 +830,9 @@ static int update_cpumask(struct cpuset *cs, char *buf) | |||
823 | * Scan tasks in the cpuset, and update the cpumasks of any | 830 | * Scan tasks in the cpuset, and update the cpumasks of any |
824 | * that need an update. | 831 | * that need an update. |
825 | */ | 832 | */ |
826 | scan.cg = cs->css.cgroup; | 833 | retval = update_tasks_cpumask(cs); |
827 | scan.test_task = cpuset_test_cpumask; | 834 | if (retval < 0) |
828 | scan.process_task = cpuset_change_cpumask; | 835 | return retval; |
829 | scan.heap = &heap; | ||
830 | cgroup_scan_tasks(&scan); | ||
831 | heap_free(&heap); | ||
832 | 836 | ||
833 | if (is_load_balanced) | 837 | if (is_load_balanced) |
834 | rebuild_sched_domains(); | 838 | rebuild_sched_domains(); |
@@ -884,74 +888,25 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from, | |||
884 | mutex_unlock(&callback_mutex); | 888 | mutex_unlock(&callback_mutex); |
885 | } | 889 | } |
886 | 890 | ||
887 | /* | ||
888 | * Handle user request to change the 'mems' memory placement | ||
889 | * of a cpuset. Needs to validate the request, update the | ||
890 | * cpusets mems_allowed and mems_generation, and for each | ||
891 | * task in the cpuset, rebind any vma mempolicies and if | ||
892 | * the cpuset is marked 'memory_migrate', migrate the tasks | ||
893 | * pages to the new memory. | ||
894 | * | ||
895 | * Call with cgroup_mutex held. May take callback_mutex during call. | ||
896 | * Will take tasklist_lock, scan tasklist for tasks in cpuset cs, | ||
897 | * lock each such tasks mm->mmap_sem, scan its vma's and rebind | ||
898 | * their mempolicies to the cpusets new mems_allowed. | ||
899 | */ | ||
900 | |||
901 | static void *cpuset_being_rebound; | 891 | static void *cpuset_being_rebound; |
902 | 892 | ||
903 | static int update_nodemask(struct cpuset *cs, char *buf) | 893 | /** |
894 | * update_tasks_nodemask - Update the nodemasks of tasks in the cpuset. | ||
895 | * @cs: the cpuset in which each task's mems_allowed mask needs to be changed | ||
896 | * @oldmem: old mems_allowed of cpuset cs | ||
897 | * | ||
898 | * Called with cgroup_mutex held | ||
899 | * Return 0 if successful, -errno if not. | ||
900 | */ | ||
901 | static int update_tasks_nodemask(struct cpuset *cs, const nodemask_t *oldmem) | ||
904 | { | 902 | { |
905 | struct cpuset trialcs; | ||
906 | nodemask_t oldmem; | ||
907 | struct task_struct *p; | 903 | struct task_struct *p; |
908 | struct mm_struct **mmarray; | 904 | struct mm_struct **mmarray; |
909 | int i, n, ntasks; | 905 | int i, n, ntasks; |
910 | int migrate; | 906 | int migrate; |
911 | int fudge; | 907 | int fudge; |
912 | int retval; | ||
913 | struct cgroup_iter it; | 908 | struct cgroup_iter it; |
914 | 909 | int retval; | |
915 | /* | ||
916 | * top_cpuset.mems_allowed tracks node_stats[N_HIGH_MEMORY]; | ||
917 | * it's read-only | ||
918 | */ | ||
919 | if (cs == &top_cpuset) | ||
920 | return -EACCES; | ||
921 | |||
922 | trialcs = *cs; | ||
923 | |||
924 | /* | ||
925 | * An empty mems_allowed is ok iff there are no tasks in the cpuset. | ||
926 | * Since nodelist_parse() fails on an empty mask, we special case | ||
927 | * that parsing. The validate_change() call ensures that cpusets | ||
928 | * with tasks have memory. | ||
929 | */ | ||
930 | buf = strstrip(buf); | ||
931 | if (!*buf) { | ||
932 | nodes_clear(trialcs.mems_allowed); | ||
933 | } else { | ||
934 | retval = nodelist_parse(buf, trialcs.mems_allowed); | ||
935 | if (retval < 0) | ||
936 | goto done; | ||
937 | |||
938 | if (!nodes_subset(trialcs.mems_allowed, | ||
939 | node_states[N_HIGH_MEMORY])) | ||
940 | return -EINVAL; | ||
941 | } | ||
942 | oldmem = cs->mems_allowed; | ||
943 | if (nodes_equal(oldmem, trialcs.mems_allowed)) { | ||
944 | retval = 0; /* Too easy - nothing to do */ | ||
945 | goto done; | ||
946 | } | ||
947 | retval = validate_change(cs, &trialcs); | ||
948 | if (retval < 0) | ||
949 | goto done; | ||
950 | |||
951 | mutex_lock(&callback_mutex); | ||
952 | cs->mems_allowed = trialcs.mems_allowed; | ||
953 | cs->mems_generation = cpuset_mems_generation++; | ||
954 | mutex_unlock(&callback_mutex); | ||
955 | 910 | ||
956 | cpuset_being_rebound = cs; /* causes mpol_dup() rebind */ | 911 | cpuset_being_rebound = cs; /* causes mpol_dup() rebind */ |
957 | 912 | ||
@@ -1018,7 +973,7 @@ static int update_nodemask(struct cpuset *cs, char *buf) | |||
1018 | 973 | ||
1019 | mpol_rebind_mm(mm, &cs->mems_allowed); | 974 | mpol_rebind_mm(mm, &cs->mems_allowed); |
1020 | if (migrate) | 975 | if (migrate) |
1021 | cpuset_migrate_mm(mm, &oldmem, &cs->mems_allowed); | 976 | cpuset_migrate_mm(mm, oldmem, &cs->mems_allowed); |
1022 | mmput(mm); | 977 | mmput(mm); |
1023 | } | 978 | } |
1024 | 979 | ||
@@ -1030,6 +985,70 @@ done: | |||
1030 | return retval; | 985 | return retval; |
1031 | } | 986 | } |
1032 | 987 | ||
988 | /* | ||
989 | * Handle user request to change the 'mems' memory placement | ||
990 | * of a cpuset. Needs to validate the request, update the | ||
991 | * cpusets mems_allowed and mems_generation, and for each | ||
992 | * task in the cpuset, rebind any vma mempolicies and if | ||
993 | * the cpuset is marked 'memory_migrate', migrate the tasks | ||
994 | * pages to the new memory. | ||
995 | * | ||
996 | * Call with cgroup_mutex held. May take callback_mutex during call. | ||
997 | * Will take tasklist_lock, scan tasklist for tasks in cpuset cs, | ||
998 | * lock each such tasks mm->mmap_sem, scan its vma's and rebind | ||
999 | * their mempolicies to the cpusets new mems_allowed. | ||
1000 | */ | ||
1001 | static int update_nodemask(struct cpuset *cs, const char *buf) | ||
1002 | { | ||
1003 | struct cpuset trialcs; | ||
1004 | nodemask_t oldmem; | ||
1005 | int retval; | ||
1006 | |||
1007 | /* | ||
1008 | * top_cpuset.mems_allowed tracks node_stats[N_HIGH_MEMORY]; | ||
1009 | * it's read-only | ||
1010 | */ | ||
1011 | if (cs == &top_cpuset) | ||
1012 | return -EACCES; | ||
1013 | |||
1014 | trialcs = *cs; | ||
1015 | |||
1016 | /* | ||
1017 | * An empty mems_allowed is ok iff there are no tasks in the cpuset. | ||
1018 | * Since nodelist_parse() fails on an empty mask, we special case | ||
1019 | * that parsing. The validate_change() call ensures that cpusets | ||
1020 | * with tasks have memory. | ||
1021 | */ | ||
1022 | if (!*buf) { | ||
1023 | nodes_clear(trialcs.mems_allowed); | ||
1024 | } else { | ||
1025 | retval = nodelist_parse(buf, trialcs.mems_allowed); | ||
1026 | if (retval < 0) | ||
1027 | goto done; | ||
1028 | |||
1029 | if (!nodes_subset(trialcs.mems_allowed, | ||
1030 | node_states[N_HIGH_MEMORY])) | ||
1031 | return -EINVAL; | ||
1032 | } | ||
1033 | oldmem = cs->mems_allowed; | ||
1034 | if (nodes_equal(oldmem, trialcs.mems_allowed)) { | ||
1035 | retval = 0; /* Too easy - nothing to do */ | ||
1036 | goto done; | ||
1037 | } | ||
1038 | retval = validate_change(cs, &trialcs); | ||
1039 | if (retval < 0) | ||
1040 | goto done; | ||
1041 | |||
1042 | mutex_lock(&callback_mutex); | ||
1043 | cs->mems_allowed = trialcs.mems_allowed; | ||
1044 | cs->mems_generation = cpuset_mems_generation++; | ||
1045 | mutex_unlock(&callback_mutex); | ||
1046 | |||
1047 | retval = update_tasks_nodemask(cs, &oldmem); | ||
1048 | done: | ||
1049 | return retval; | ||
1050 | } | ||
1051 | |||
1033 | int current_cpuset_is_being_rebound(void) | 1052 | int current_cpuset_is_being_rebound(void) |
1034 | { | 1053 | { |
1035 | return task_cs(current) == cpuset_being_rebound; | 1054 | return task_cs(current) == cpuset_being_rebound; |
@@ -1042,7 +1061,8 @@ static int update_relax_domain_level(struct cpuset *cs, s64 val) | |||
1042 | 1061 | ||
1043 | if (val != cs->relax_domain_level) { | 1062 | if (val != cs->relax_domain_level) { |
1044 | cs->relax_domain_level = val; | 1063 | cs->relax_domain_level = val; |
1045 | rebuild_sched_domains(); | 1064 | if (!cpus_empty(cs->cpus_allowed) && is_sched_load_balance(cs)) |
1065 | rebuild_sched_domains(); | ||
1046 | } | 1066 | } |
1047 | 1067 | ||
1048 | return 0; | 1068 | return 0; |
@@ -1254,72 +1274,14 @@ typedef enum { | |||
1254 | FILE_SPREAD_SLAB, | 1274 | FILE_SPREAD_SLAB, |
1255 | } cpuset_filetype_t; | 1275 | } cpuset_filetype_t; |
1256 | 1276 | ||
1257 | static ssize_t cpuset_common_file_write(struct cgroup *cont, | ||
1258 | struct cftype *cft, | ||
1259 | struct file *file, | ||
1260 | const char __user *userbuf, | ||
1261 | size_t nbytes, loff_t *unused_ppos) | ||
1262 | { | ||
1263 | struct cpuset *cs = cgroup_cs(cont); | ||
1264 | cpuset_filetype_t type = cft->private; | ||
1265 | char *buffer; | ||
1266 | int retval = 0; | ||
1267 | |||
1268 | /* Crude upper limit on largest legitimate cpulist user might write. */ | ||
1269 | if (nbytes > 100U + 6 * max(NR_CPUS, MAX_NUMNODES)) | ||
1270 | return -E2BIG; | ||
1271 | |||
1272 | /* +1 for nul-terminator */ | ||
1273 | buffer = kmalloc(nbytes + 1, GFP_KERNEL); | ||
1274 | if (!buffer) | ||
1275 | return -ENOMEM; | ||
1276 | |||
1277 | if (copy_from_user(buffer, userbuf, nbytes)) { | ||
1278 | retval = -EFAULT; | ||
1279 | goto out1; | ||
1280 | } | ||
1281 | buffer[nbytes] = 0; /* nul-terminate */ | ||
1282 | |||
1283 | cgroup_lock(); | ||
1284 | |||
1285 | if (cgroup_is_removed(cont)) { | ||
1286 | retval = -ENODEV; | ||
1287 | goto out2; | ||
1288 | } | ||
1289 | |||
1290 | switch (type) { | ||
1291 | case FILE_CPULIST: | ||
1292 | retval = update_cpumask(cs, buffer); | ||
1293 | break; | ||
1294 | case FILE_MEMLIST: | ||
1295 | retval = update_nodemask(cs, buffer); | ||
1296 | break; | ||
1297 | default: | ||
1298 | retval = -EINVAL; | ||
1299 | goto out2; | ||
1300 | } | ||
1301 | |||
1302 | if (retval == 0) | ||
1303 | retval = nbytes; | ||
1304 | out2: | ||
1305 | cgroup_unlock(); | ||
1306 | out1: | ||
1307 | kfree(buffer); | ||
1308 | return retval; | ||
1309 | } | ||
1310 | |||
1311 | static int cpuset_write_u64(struct cgroup *cgrp, struct cftype *cft, u64 val) | 1277 | static int cpuset_write_u64(struct cgroup *cgrp, struct cftype *cft, u64 val) |
1312 | { | 1278 | { |
1313 | int retval = 0; | 1279 | int retval = 0; |
1314 | struct cpuset *cs = cgroup_cs(cgrp); | 1280 | struct cpuset *cs = cgroup_cs(cgrp); |
1315 | cpuset_filetype_t type = cft->private; | 1281 | cpuset_filetype_t type = cft->private; |
1316 | 1282 | ||
1317 | cgroup_lock(); | 1283 | if (!cgroup_lock_live_group(cgrp)) |
1318 | |||
1319 | if (cgroup_is_removed(cgrp)) { | ||
1320 | cgroup_unlock(); | ||
1321 | return -ENODEV; | 1284 | return -ENODEV; |
1322 | } | ||
1323 | 1285 | ||
1324 | switch (type) { | 1286 | switch (type) { |
1325 | case FILE_CPU_EXCLUSIVE: | 1287 | case FILE_CPU_EXCLUSIVE: |
@@ -1365,12 +1327,9 @@ static int cpuset_write_s64(struct cgroup *cgrp, struct cftype *cft, s64 val) | |||
1365 | struct cpuset *cs = cgroup_cs(cgrp); | 1327 | struct cpuset *cs = cgroup_cs(cgrp); |
1366 | cpuset_filetype_t type = cft->private; | 1328 | cpuset_filetype_t type = cft->private; |
1367 | 1329 | ||
1368 | cgroup_lock(); | 1330 | if (!cgroup_lock_live_group(cgrp)) |
1369 | |||
1370 | if (cgroup_is_removed(cgrp)) { | ||
1371 | cgroup_unlock(); | ||
1372 | return -ENODEV; | 1331 | return -ENODEV; |
1373 | } | 1332 | |
1374 | switch (type) { | 1333 | switch (type) { |
1375 | case FILE_SCHED_RELAX_DOMAIN_LEVEL: | 1334 | case FILE_SCHED_RELAX_DOMAIN_LEVEL: |
1376 | retval = update_relax_domain_level(cs, val); | 1335 | retval = update_relax_domain_level(cs, val); |
@@ -1384,6 +1343,32 @@ static int cpuset_write_s64(struct cgroup *cgrp, struct cftype *cft, s64 val) | |||
1384 | } | 1343 | } |
1385 | 1344 | ||
1386 | /* | 1345 | /* |
1346 | * Common handling for a write to a "cpus" or "mems" file. | ||
1347 | */ | ||
1348 | static int cpuset_write_resmask(struct cgroup *cgrp, struct cftype *cft, | ||
1349 | const char *buf) | ||
1350 | { | ||
1351 | int retval = 0; | ||
1352 | |||
1353 | if (!cgroup_lock_live_group(cgrp)) | ||
1354 | return -ENODEV; | ||
1355 | |||
1356 | switch (cft->private) { | ||
1357 | case FILE_CPULIST: | ||
1358 | retval = update_cpumask(cgroup_cs(cgrp), buf); | ||
1359 | break; | ||
1360 | case FILE_MEMLIST: | ||
1361 | retval = update_nodemask(cgroup_cs(cgrp), buf); | ||
1362 | break; | ||
1363 | default: | ||
1364 | retval = -EINVAL; | ||
1365 | break; | ||
1366 | } | ||
1367 | cgroup_unlock(); | ||
1368 | return retval; | ||
1369 | } | ||
1370 | |||
1371 | /* | ||
1387 | * These ascii lists should be read in a single call, by using a user | 1372 | * These ascii lists should be read in a single call, by using a user |
1388 | * buffer large enough to hold the entire map. If read in smaller | 1373 | * buffer large enough to hold the entire map. If read in smaller |
1389 | * chunks, there is no guarantee of atomicity. Since the display format | 1374 | * chunks, there is no guarantee of atomicity. Since the display format |
@@ -1502,14 +1487,16 @@ static struct cftype files[] = { | |||
1502 | { | 1487 | { |
1503 | .name = "cpus", | 1488 | .name = "cpus", |
1504 | .read = cpuset_common_file_read, | 1489 | .read = cpuset_common_file_read, |
1505 | .write = cpuset_common_file_write, | 1490 | .write_string = cpuset_write_resmask, |
1491 | .max_write_len = (100U + 6 * NR_CPUS), | ||
1506 | .private = FILE_CPULIST, | 1492 | .private = FILE_CPULIST, |
1507 | }, | 1493 | }, |
1508 | 1494 | ||
1509 | { | 1495 | { |
1510 | .name = "mems", | 1496 | .name = "mems", |
1511 | .read = cpuset_common_file_read, | 1497 | .read = cpuset_common_file_read, |
1512 | .write = cpuset_common_file_write, | 1498 | .write_string = cpuset_write_resmask, |
1499 | .max_write_len = (100U + 6 * MAX_NUMNODES), | ||
1513 | .private = FILE_MEMLIST, | 1500 | .private = FILE_MEMLIST, |
1514 | }, | 1501 | }, |
1515 | 1502 | ||
@@ -1790,7 +1777,7 @@ static void move_member_tasks_to_cpuset(struct cpuset *from, struct cpuset *to) | |||
1790 | scan.scan.heap = NULL; | 1777 | scan.scan.heap = NULL; |
1791 | scan.to = to->css.cgroup; | 1778 | scan.to = to->css.cgroup; |
1792 | 1779 | ||
1793 | if (cgroup_scan_tasks((struct cgroup_scanner *)&scan)) | 1780 | if (cgroup_scan_tasks(&scan.scan)) |
1794 | printk(KERN_ERR "move_member_tasks_to_cpuset: " | 1781 | printk(KERN_ERR "move_member_tasks_to_cpuset: " |
1795 | "cgroup_scan_tasks failed\n"); | 1782 | "cgroup_scan_tasks failed\n"); |
1796 | } | 1783 | } |
@@ -1850,6 +1837,7 @@ static void scan_for_empty_cpusets(const struct cpuset *root) | |||
1850 | struct cpuset *child; /* scans child cpusets of cp */ | 1837 | struct cpuset *child; /* scans child cpusets of cp */ |
1851 | struct list_head queue; | 1838 | struct list_head queue; |
1852 | struct cgroup *cont; | 1839 | struct cgroup *cont; |
1840 | nodemask_t oldmems; | ||
1853 | 1841 | ||
1854 | INIT_LIST_HEAD(&queue); | 1842 | INIT_LIST_HEAD(&queue); |
1855 | 1843 | ||
@@ -1869,6 +1857,8 @@ static void scan_for_empty_cpusets(const struct cpuset *root) | |||
1869 | nodes_subset(cp->mems_allowed, node_states[N_HIGH_MEMORY])) | 1857 | nodes_subset(cp->mems_allowed, node_states[N_HIGH_MEMORY])) |
1870 | continue; | 1858 | continue; |
1871 | 1859 | ||
1860 | oldmems = cp->mems_allowed; | ||
1861 | |||
1872 | /* Remove offline cpus and mems from this cpuset. */ | 1862 | /* Remove offline cpus and mems from this cpuset. */ |
1873 | mutex_lock(&callback_mutex); | 1863 | mutex_lock(&callback_mutex); |
1874 | cpus_and(cp->cpus_allowed, cp->cpus_allowed, cpu_online_map); | 1864 | cpus_and(cp->cpus_allowed, cp->cpus_allowed, cpu_online_map); |
@@ -1880,6 +1870,10 @@ static void scan_for_empty_cpusets(const struct cpuset *root) | |||
1880 | if (cpus_empty(cp->cpus_allowed) || | 1870 | if (cpus_empty(cp->cpus_allowed) || |
1881 | nodes_empty(cp->mems_allowed)) | 1871 | nodes_empty(cp->mems_allowed)) |
1882 | remove_tasks_in_empty_cpuset(cp); | 1872 | remove_tasks_in_empty_cpuset(cp); |
1873 | else { | ||
1874 | update_tasks_cpumask(cp); | ||
1875 | update_tasks_nodemask(cp, &oldmems); | ||
1876 | } | ||
1883 | } | 1877 | } |
1884 | } | 1878 | } |
1885 | 1879 | ||
@@ -1972,7 +1966,6 @@ void __init cpuset_init_smp(void) | |||
1972 | } | 1966 | } |
1973 | 1967 | ||
1974 | /** | 1968 | /** |
1975 | |||
1976 | * cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset. | 1969 | * cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset. |
1977 | * @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed. | 1970 | * @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed. |
1978 | * @pmask: pointer to cpumask_t variable to receive cpus_allowed set. | 1971 | * @pmask: pointer to cpumask_t variable to receive cpus_allowed set. |
diff --git a/kernel/delayacct.c b/kernel/delayacct.c index 10e43fd8b721..b3179dad71be 100644 --- a/kernel/delayacct.c +++ b/kernel/delayacct.c | |||
@@ -145,8 +145,11 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk) | |||
145 | d->blkio_delay_total = (tmp < d->blkio_delay_total) ? 0 : tmp; | 145 | d->blkio_delay_total = (tmp < d->blkio_delay_total) ? 0 : tmp; |
146 | tmp = d->swapin_delay_total + tsk->delays->swapin_delay; | 146 | tmp = d->swapin_delay_total + tsk->delays->swapin_delay; |
147 | d->swapin_delay_total = (tmp < d->swapin_delay_total) ? 0 : tmp; | 147 | d->swapin_delay_total = (tmp < d->swapin_delay_total) ? 0 : tmp; |
148 | tmp = d->freepages_delay_total + tsk->delays->freepages_delay; | ||
149 | d->freepages_delay_total = (tmp < d->freepages_delay_total) ? 0 : tmp; | ||
148 | d->blkio_count += tsk->delays->blkio_count; | 150 | d->blkio_count += tsk->delays->blkio_count; |
149 | d->swapin_count += tsk->delays->swapin_count; | 151 | d->swapin_count += tsk->delays->swapin_count; |
152 | d->freepages_count += tsk->delays->freepages_count; | ||
150 | spin_unlock_irqrestore(&tsk->delays->lock, flags); | 153 | spin_unlock_irqrestore(&tsk->delays->lock, flags); |
151 | 154 | ||
152 | done: | 155 | done: |
@@ -165,3 +168,16 @@ __u64 __delayacct_blkio_ticks(struct task_struct *tsk) | |||
165 | return ret; | 168 | return ret; |
166 | } | 169 | } |
167 | 170 | ||
171 | void __delayacct_freepages_start(void) | ||
172 | { | ||
173 | delayacct_start(¤t->delays->freepages_start); | ||
174 | } | ||
175 | |||
176 | void __delayacct_freepages_end(void) | ||
177 | { | ||
178 | delayacct_end(¤t->delays->freepages_start, | ||
179 | ¤t->delays->freepages_end, | ||
180 | ¤t->delays->freepages_delay, | ||
181 | ¤t->delays->freepages_count); | ||
182 | } | ||
183 | |||
diff --git a/kernel/exec_domain.c b/kernel/exec_domain.c index a9e6bad9f706..c1ef192aa655 100644 --- a/kernel/exec_domain.c +++ b/kernel/exec_domain.c | |||
@@ -65,7 +65,7 @@ lookup_exec_domain(u_long personality) | |||
65 | goto out; | 65 | goto out; |
66 | } | 66 | } |
67 | 67 | ||
68 | #ifdef CONFIG_KMOD | 68 | #ifdef CONFIG_MODULES |
69 | read_unlock(&exec_domains_lock); | 69 | read_unlock(&exec_domains_lock); |
70 | request_module("personality-%ld", pers); | 70 | request_module("personality-%ld", pers); |
71 | read_lock(&exec_domains_lock); | 71 | read_lock(&exec_domains_lock); |
diff --git a/kernel/exit.c b/kernel/exit.c index 93d2711b9381..ad933bb29ec7 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -85,7 +85,6 @@ static void __exit_signal(struct task_struct *tsk) | |||
85 | BUG_ON(!sig); | 85 | BUG_ON(!sig); |
86 | BUG_ON(!atomic_read(&sig->count)); | 86 | BUG_ON(!atomic_read(&sig->count)); |
87 | 87 | ||
88 | rcu_read_lock(); | ||
89 | sighand = rcu_dereference(tsk->sighand); | 88 | sighand = rcu_dereference(tsk->sighand); |
90 | spin_lock(&sighand->siglock); | 89 | spin_lock(&sighand->siglock); |
91 | 90 | ||
@@ -121,6 +120,18 @@ static void __exit_signal(struct task_struct *tsk) | |||
121 | sig->nivcsw += tsk->nivcsw; | 120 | sig->nivcsw += tsk->nivcsw; |
122 | sig->inblock += task_io_get_inblock(tsk); | 121 | sig->inblock += task_io_get_inblock(tsk); |
123 | sig->oublock += task_io_get_oublock(tsk); | 122 | sig->oublock += task_io_get_oublock(tsk); |
123 | #ifdef CONFIG_TASK_XACCT | ||
124 | sig->rchar += tsk->rchar; | ||
125 | sig->wchar += tsk->wchar; | ||
126 | sig->syscr += tsk->syscr; | ||
127 | sig->syscw += tsk->syscw; | ||
128 | #endif /* CONFIG_TASK_XACCT */ | ||
129 | #ifdef CONFIG_TASK_IO_ACCOUNTING | ||
130 | sig->ioac.read_bytes += tsk->ioac.read_bytes; | ||
131 | sig->ioac.write_bytes += tsk->ioac.write_bytes; | ||
132 | sig->ioac.cancelled_write_bytes += | ||
133 | tsk->ioac.cancelled_write_bytes; | ||
134 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ | ||
124 | sig->sum_sched_runtime += tsk->se.sum_exec_runtime; | 135 | sig->sum_sched_runtime += tsk->se.sum_exec_runtime; |
125 | sig = NULL; /* Marker for below. */ | 136 | sig = NULL; /* Marker for below. */ |
126 | } | 137 | } |
@@ -136,7 +147,6 @@ static void __exit_signal(struct task_struct *tsk) | |||
136 | tsk->signal = NULL; | 147 | tsk->signal = NULL; |
137 | tsk->sighand = NULL; | 148 | tsk->sighand = NULL; |
138 | spin_unlock(&sighand->siglock); | 149 | spin_unlock(&sighand->siglock); |
139 | rcu_read_unlock(); | ||
140 | 150 | ||
141 | __cleanup_sighand(sighand); | 151 | __cleanup_sighand(sighand); |
142 | clear_tsk_thread_flag(tsk,TIF_SIGPENDING); | 152 | clear_tsk_thread_flag(tsk,TIF_SIGPENDING); |
@@ -432,7 +442,7 @@ void daemonize(const char *name, ...) | |||
432 | * We don't want to have TIF_FREEZE set if the system-wide hibernation | 442 | * We don't want to have TIF_FREEZE set if the system-wide hibernation |
433 | * or suspend transition begins right now. | 443 | * or suspend transition begins right now. |
434 | */ | 444 | */ |
435 | current->flags |= PF_NOFREEZE; | 445 | current->flags |= (PF_NOFREEZE | PF_KTHREAD); |
436 | 446 | ||
437 | if (current->nsproxy != &init_nsproxy) { | 447 | if (current->nsproxy != &init_nsproxy) { |
438 | get_nsproxy(&init_nsproxy); | 448 | get_nsproxy(&init_nsproxy); |
@@ -666,26 +676,40 @@ assign_new_owner: | |||
666 | static void exit_mm(struct task_struct * tsk) | 676 | static void exit_mm(struct task_struct * tsk) |
667 | { | 677 | { |
668 | struct mm_struct *mm = tsk->mm; | 678 | struct mm_struct *mm = tsk->mm; |
679 | struct core_state *core_state; | ||
669 | 680 | ||
670 | mm_release(tsk, mm); | 681 | mm_release(tsk, mm); |
671 | if (!mm) | 682 | if (!mm) |
672 | return; | 683 | return; |
673 | /* | 684 | /* |
674 | * Serialize with any possible pending coredump. | 685 | * Serialize with any possible pending coredump. |
675 | * We must hold mmap_sem around checking core_waiters | 686 | * We must hold mmap_sem around checking core_state |
676 | * and clearing tsk->mm. The core-inducing thread | 687 | * and clearing tsk->mm. The core-inducing thread |
677 | * will increment core_waiters for each thread in the | 688 | * will increment ->nr_threads for each thread in the |
678 | * group with ->mm != NULL. | 689 | * group with ->mm != NULL. |
679 | */ | 690 | */ |
680 | down_read(&mm->mmap_sem); | 691 | down_read(&mm->mmap_sem); |
681 | if (mm->core_waiters) { | 692 | core_state = mm->core_state; |
693 | if (core_state) { | ||
694 | struct core_thread self; | ||
682 | up_read(&mm->mmap_sem); | 695 | up_read(&mm->mmap_sem); |
683 | down_write(&mm->mmap_sem); | ||
684 | if (!--mm->core_waiters) | ||
685 | complete(mm->core_startup_done); | ||
686 | up_write(&mm->mmap_sem); | ||
687 | 696 | ||
688 | wait_for_completion(&mm->core_done); | 697 | self.task = tsk; |
698 | self.next = xchg(&core_state->dumper.next, &self); | ||
699 | /* | ||
700 | * Implies mb(), the result of xchg() must be visible | ||
701 | * to core_state->dumper. | ||
702 | */ | ||
703 | if (atomic_dec_and_test(&core_state->nr_threads)) | ||
704 | complete(&core_state->startup); | ||
705 | |||
706 | for (;;) { | ||
707 | set_task_state(tsk, TASK_UNINTERRUPTIBLE); | ||
708 | if (!self.task) /* see coredump_finish() */ | ||
709 | break; | ||
710 | schedule(); | ||
711 | } | ||
712 | __set_task_state(tsk, TASK_RUNNING); | ||
689 | down_read(&mm->mmap_sem); | 713 | down_read(&mm->mmap_sem); |
690 | } | 714 | } |
691 | atomic_inc(&mm->mm_count); | 715 | atomic_inc(&mm->mm_count); |
@@ -1354,6 +1378,21 @@ static int wait_task_zombie(struct task_struct *p, int options, | |||
1354 | psig->coublock += | 1378 | psig->coublock += |
1355 | task_io_get_oublock(p) + | 1379 | task_io_get_oublock(p) + |
1356 | sig->oublock + sig->coublock; | 1380 | sig->oublock + sig->coublock; |
1381 | #ifdef CONFIG_TASK_XACCT | ||
1382 | psig->rchar += p->rchar + sig->rchar; | ||
1383 | psig->wchar += p->wchar + sig->wchar; | ||
1384 | psig->syscr += p->syscr + sig->syscr; | ||
1385 | psig->syscw += p->syscw + sig->syscw; | ||
1386 | #endif /* CONFIG_TASK_XACCT */ | ||
1387 | #ifdef CONFIG_TASK_IO_ACCOUNTING | ||
1388 | psig->ioac.read_bytes += | ||
1389 | p->ioac.read_bytes + sig->ioac.read_bytes; | ||
1390 | psig->ioac.write_bytes += | ||
1391 | p->ioac.write_bytes + sig->ioac.write_bytes; | ||
1392 | psig->ioac.cancelled_write_bytes += | ||
1393 | p->ioac.cancelled_write_bytes + | ||
1394 | sig->ioac.cancelled_write_bytes; | ||
1395 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ | ||
1357 | spin_unlock_irq(&p->parent->sighand->siglock); | 1396 | spin_unlock_irq(&p->parent->sighand->siglock); |
1358 | } | 1397 | } |
1359 | 1398 | ||
diff --git a/kernel/fork.c b/kernel/fork.c index adefc1131f27..b99d73e971a4 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/cpu.h> | 33 | #include <linux/cpu.h> |
34 | #include <linux/cgroup.h> | 34 | #include <linux/cgroup.h> |
35 | #include <linux/security.h> | 35 | #include <linux/security.h> |
36 | #include <linux/hugetlb.h> | ||
36 | #include <linux/swap.h> | 37 | #include <linux/swap.h> |
37 | #include <linux/syscalls.h> | 38 | #include <linux/syscalls.h> |
38 | #include <linux/jiffies.h> | 39 | #include <linux/jiffies.h> |
@@ -92,6 +93,23 @@ int nr_processes(void) | |||
92 | static struct kmem_cache *task_struct_cachep; | 93 | static struct kmem_cache *task_struct_cachep; |
93 | #endif | 94 | #endif |
94 | 95 | ||
96 | #ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR | ||
97 | static inline struct thread_info *alloc_thread_info(struct task_struct *tsk) | ||
98 | { | ||
99 | #ifdef CONFIG_DEBUG_STACK_USAGE | ||
100 | gfp_t mask = GFP_KERNEL | __GFP_ZERO; | ||
101 | #else | ||
102 | gfp_t mask = GFP_KERNEL; | ||
103 | #endif | ||
104 | return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER); | ||
105 | } | ||
106 | |||
107 | static inline void free_thread_info(struct thread_info *ti) | ||
108 | { | ||
109 | free_pages((unsigned long)ti, THREAD_SIZE_ORDER); | ||
110 | } | ||
111 | #endif | ||
112 | |||
95 | /* SLAB cache for signal_struct structures (tsk->signal) */ | 113 | /* SLAB cache for signal_struct structures (tsk->signal) */ |
96 | static struct kmem_cache *signal_cachep; | 114 | static struct kmem_cache *signal_cachep; |
97 | 115 | ||
@@ -307,6 +325,14 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) | |||
307 | } | 325 | } |
308 | 326 | ||
309 | /* | 327 | /* |
328 | * Clear hugetlb-related page reserves for children. This only | ||
329 | * affects MAP_PRIVATE mappings. Faults generated by the child | ||
330 | * are not guaranteed to succeed, even if read-only | ||
331 | */ | ||
332 | if (is_vm_hugetlb_page(tmp)) | ||
333 | reset_vma_resv_huge_pages(tmp); | ||
334 | |||
335 | /* | ||
310 | * Link in the new vma and copy the page table entries. | 336 | * Link in the new vma and copy the page table entries. |
311 | */ | 337 | */ |
312 | *pprev = tmp; | 338 | *pprev = tmp; |
@@ -374,7 +400,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p) | |||
374 | INIT_LIST_HEAD(&mm->mmlist); | 400 | INIT_LIST_HEAD(&mm->mmlist); |
375 | mm->flags = (current->mm) ? current->mm->flags | 401 | mm->flags = (current->mm) ? current->mm->flags |
376 | : MMF_DUMP_FILTER_DEFAULT; | 402 | : MMF_DUMP_FILTER_DEFAULT; |
377 | mm->core_waiters = 0; | 403 | mm->core_state = NULL; |
378 | mm->nr_ptes = 0; | 404 | mm->nr_ptes = 0; |
379 | set_mm_counter(mm, file_rss, 0); | 405 | set_mm_counter(mm, file_rss, 0); |
380 | set_mm_counter(mm, anon_rss, 0); | 406 | set_mm_counter(mm, anon_rss, 0); |
@@ -448,7 +474,7 @@ EXPORT_SYMBOL_GPL(mmput); | |||
448 | /** | 474 | /** |
449 | * get_task_mm - acquire a reference to the task's mm | 475 | * get_task_mm - acquire a reference to the task's mm |
450 | * | 476 | * |
451 | * Returns %NULL if the task has no mm. Checks PF_BORROWED_MM (meaning | 477 | * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning |
452 | * this kernel workthread has transiently adopted a user mm with use_mm, | 478 | * this kernel workthread has transiently adopted a user mm with use_mm, |
453 | * to do its AIO) is not set and if so returns a reference to it, after | 479 | * to do its AIO) is not set and if so returns a reference to it, after |
454 | * bumping up the use count. User must release the mm via mmput() | 480 | * bumping up the use count. User must release the mm via mmput() |
@@ -461,7 +487,7 @@ struct mm_struct *get_task_mm(struct task_struct *task) | |||
461 | task_lock(task); | 487 | task_lock(task); |
462 | mm = task->mm; | 488 | mm = task->mm; |
463 | if (mm) { | 489 | if (mm) { |
464 | if (task->flags & PF_BORROWED_MM) | 490 | if (task->flags & PF_KTHREAD) |
465 | mm = NULL; | 491 | mm = NULL; |
466 | else | 492 | else |
467 | atomic_inc(&mm->mm_users); | 493 | atomic_inc(&mm->mm_users); |
@@ -786,6 +812,12 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
786 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; | 812 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; |
787 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; | 813 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; |
788 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; | 814 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; |
815 | #ifdef CONFIG_TASK_XACCT | ||
816 | sig->rchar = sig->wchar = sig->syscr = sig->syscw = 0; | ||
817 | #endif | ||
818 | #ifdef CONFIG_TASK_IO_ACCOUNTING | ||
819 | memset(&sig->ioac, 0, sizeof(sig->ioac)); | ||
820 | #endif | ||
789 | sig->sum_sched_runtime = 0; | 821 | sig->sum_sched_runtime = 0; |
790 | INIT_LIST_HEAD(&sig->cpu_timers[0]); | 822 | INIT_LIST_HEAD(&sig->cpu_timers[0]); |
791 | INIT_LIST_HEAD(&sig->cpu_timers[1]); | 823 | INIT_LIST_HEAD(&sig->cpu_timers[1]); |
@@ -1081,6 +1113,12 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1081 | if (clone_flags & CLONE_THREAD) | 1113 | if (clone_flags & CLONE_THREAD) |
1082 | p->tgid = current->tgid; | 1114 | p->tgid = current->tgid; |
1083 | 1115 | ||
1116 | if (current->nsproxy != p->nsproxy) { | ||
1117 | retval = ns_cgroup_clone(p, pid); | ||
1118 | if (retval) | ||
1119 | goto bad_fork_free_pid; | ||
1120 | } | ||
1121 | |||
1084 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; | 1122 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; |
1085 | /* | 1123 | /* |
1086 | * Clear TID on mm_release()? | 1124 | * Clear TID on mm_release()? |
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 77a51be36010..f8914b92b664 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c | |||
@@ -217,6 +217,17 @@ void enable_irq(unsigned int irq) | |||
217 | } | 217 | } |
218 | EXPORT_SYMBOL(enable_irq); | 218 | EXPORT_SYMBOL(enable_irq); |
219 | 219 | ||
220 | int set_irq_wake_real(unsigned int irq, unsigned int on) | ||
221 | { | ||
222 | struct irq_desc *desc = irq_desc + irq; | ||
223 | int ret = -ENXIO; | ||
224 | |||
225 | if (desc->chip->set_wake) | ||
226 | ret = desc->chip->set_wake(irq, on); | ||
227 | |||
228 | return ret; | ||
229 | } | ||
230 | |||
220 | /** | 231 | /** |
221 | * set_irq_wake - control irq power management wakeup | 232 | * set_irq_wake - control irq power management wakeup |
222 | * @irq: interrupt to control | 233 | * @irq: interrupt to control |
@@ -233,30 +244,32 @@ int set_irq_wake(unsigned int irq, unsigned int on) | |||
233 | { | 244 | { |
234 | struct irq_desc *desc = irq_desc + irq; | 245 | struct irq_desc *desc = irq_desc + irq; |
235 | unsigned long flags; | 246 | unsigned long flags; |
236 | int ret = -ENXIO; | 247 | int ret = 0; |
237 | int (*set_wake)(unsigned, unsigned) = desc->chip->set_wake; | ||
238 | 248 | ||
239 | /* wakeup-capable irqs can be shared between drivers that | 249 | /* wakeup-capable irqs can be shared between drivers that |
240 | * don't need to have the same sleep mode behaviors. | 250 | * don't need to have the same sleep mode behaviors. |
241 | */ | 251 | */ |
242 | spin_lock_irqsave(&desc->lock, flags); | 252 | spin_lock_irqsave(&desc->lock, flags); |
243 | if (on) { | 253 | if (on) { |
244 | if (desc->wake_depth++ == 0) | 254 | if (desc->wake_depth++ == 0) { |
245 | desc->status |= IRQ_WAKEUP; | 255 | ret = set_irq_wake_real(irq, on); |
246 | else | 256 | if (ret) |
247 | set_wake = NULL; | 257 | desc->wake_depth = 0; |
258 | else | ||
259 | desc->status |= IRQ_WAKEUP; | ||
260 | } | ||
248 | } else { | 261 | } else { |
249 | if (desc->wake_depth == 0) { | 262 | if (desc->wake_depth == 0) { |
250 | printk(KERN_WARNING "Unbalanced IRQ %d " | 263 | WARN(1, "Unbalanced IRQ %d wake disable\n", irq); |
251 | "wake disable\n", irq); | 264 | } else if (--desc->wake_depth == 0) { |
252 | WARN_ON(1); | 265 | ret = set_irq_wake_real(irq, on); |
253 | } else if (--desc->wake_depth == 0) | 266 | if (ret) |
254 | desc->status &= ~IRQ_WAKEUP; | 267 | desc->wake_depth = 1; |
255 | else | 268 | else |
256 | set_wake = NULL; | 269 | desc->status &= ~IRQ_WAKEUP; |
270 | } | ||
257 | } | 271 | } |
258 | if (set_wake) | 272 | |
259 | ret = desc->chip->set_wake(irq, on); | ||
260 | spin_unlock_irqrestore(&desc->lock, flags); | 273 | spin_unlock_irqrestore(&desc->lock, flags); |
261 | return ret; | 274 | return ret; |
262 | } | 275 | } |
@@ -293,6 +306,30 @@ void compat_irq_chip_set_default_handler(struct irq_desc *desc) | |||
293 | desc->handle_irq = NULL; | 306 | desc->handle_irq = NULL; |
294 | } | 307 | } |
295 | 308 | ||
309 | static int __irq_set_trigger(struct irq_chip *chip, unsigned int irq, | ||
310 | unsigned long flags) | ||
311 | { | ||
312 | int ret; | ||
313 | |||
314 | if (!chip || !chip->set_type) { | ||
315 | /* | ||
316 | * IRQF_TRIGGER_* but the PIC does not support multiple | ||
317 | * flow-types? | ||
318 | */ | ||
319 | pr_warning("No set_type function for IRQ %d (%s)\n", irq, | ||
320 | chip ? (chip->name ? : "unknown") : "unknown"); | ||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | ret = chip->set_type(irq, flags & IRQF_TRIGGER_MASK); | ||
325 | |||
326 | if (ret) | ||
327 | pr_err("setting flow type for irq %u failed (%pF)\n", | ||
328 | irq, chip->set_type); | ||
329 | |||
330 | return ret; | ||
331 | } | ||
332 | |||
296 | /* | 333 | /* |
297 | * Internal function to register an irqaction - typically used to | 334 | * Internal function to register an irqaction - typically used to |
298 | * allocate special interrupts that are part of the architecture. | 335 | * allocate special interrupts that are part of the architecture. |
@@ -304,6 +341,7 @@ int setup_irq(unsigned int irq, struct irqaction *new) | |||
304 | const char *old_name = NULL; | 341 | const char *old_name = NULL; |
305 | unsigned long flags; | 342 | unsigned long flags; |
306 | int shared = 0; | 343 | int shared = 0; |
344 | int ret; | ||
307 | 345 | ||
308 | if (irq >= NR_IRQS) | 346 | if (irq >= NR_IRQS) |
309 | return -EINVAL; | 347 | return -EINVAL; |
@@ -361,35 +399,23 @@ int setup_irq(unsigned int irq, struct irqaction *new) | |||
361 | shared = 1; | 399 | shared = 1; |
362 | } | 400 | } |
363 | 401 | ||
364 | *p = new; | ||
365 | |||
366 | /* Exclude IRQ from balancing */ | ||
367 | if (new->flags & IRQF_NOBALANCING) | ||
368 | desc->status |= IRQ_NO_BALANCING; | ||
369 | |||
370 | if (!shared) { | 402 | if (!shared) { |
371 | irq_chip_set_defaults(desc->chip); | 403 | irq_chip_set_defaults(desc->chip); |
372 | 404 | ||
373 | #if defined(CONFIG_IRQ_PER_CPU) | ||
374 | if (new->flags & IRQF_PERCPU) | ||
375 | desc->status |= IRQ_PER_CPU; | ||
376 | #endif | ||
377 | |||
378 | /* Setup the type (level, edge polarity) if configured: */ | 405 | /* Setup the type (level, edge polarity) if configured: */ |
379 | if (new->flags & IRQF_TRIGGER_MASK) { | 406 | if (new->flags & IRQF_TRIGGER_MASK) { |
380 | if (desc->chip->set_type) | 407 | ret = __irq_set_trigger(desc->chip, irq, new->flags); |
381 | desc->chip->set_type(irq, | 408 | |
382 | new->flags & IRQF_TRIGGER_MASK); | 409 | if (ret) { |
383 | else | 410 | spin_unlock_irqrestore(&desc->lock, flags); |
384 | /* | 411 | return ret; |
385 | * IRQF_TRIGGER_* but the PIC does not support | 412 | } |
386 | * multiple flow-types? | ||
387 | */ | ||
388 | printk(KERN_WARNING "No IRQF_TRIGGER set_type " | ||
389 | "function for IRQ %d (%s)\n", irq, | ||
390 | desc->chip->name); | ||
391 | } else | 413 | } else |
392 | compat_irq_chip_set_default_handler(desc); | 414 | compat_irq_chip_set_default_handler(desc); |
415 | #if defined(CONFIG_IRQ_PER_CPU) | ||
416 | if (new->flags & IRQF_PERCPU) | ||
417 | desc->status |= IRQ_PER_CPU; | ||
418 | #endif | ||
393 | 419 | ||
394 | desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING | | 420 | desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING | |
395 | IRQ_INPROGRESS | IRQ_SPURIOUS_DISABLED); | 421 | IRQ_INPROGRESS | IRQ_SPURIOUS_DISABLED); |
@@ -408,6 +434,13 @@ int setup_irq(unsigned int irq, struct irqaction *new) | |||
408 | /* Set default affinity mask once everything is setup */ | 434 | /* Set default affinity mask once everything is setup */ |
409 | irq_select_affinity(irq); | 435 | irq_select_affinity(irq); |
410 | } | 436 | } |
437 | |||
438 | *p = new; | ||
439 | |||
440 | /* Exclude IRQ from balancing */ | ||
441 | if (new->flags & IRQF_NOBALANCING) | ||
442 | desc->status |= IRQ_NO_BALANCING; | ||
443 | |||
411 | /* Reset broken irq detection when installing new handler */ | 444 | /* Reset broken irq detection when installing new handler */ |
412 | desc->irq_count = 0; | 445 | desc->irq_count = 0; |
413 | desc->irqs_unhandled = 0; | 446 | desc->irqs_unhandled = 0; |
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 6fc0040f3e3a..38fc10ac7541 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c | |||
@@ -176,7 +176,7 @@ static unsigned long get_symbol_pos(unsigned long addr, | |||
176 | high = kallsyms_num_syms; | 176 | high = kallsyms_num_syms; |
177 | 177 | ||
178 | while (high - low > 1) { | 178 | while (high - low > 1) { |
179 | mid = (low + high) / 2; | 179 | mid = low + (high - low) / 2; |
180 | if (kallsyms_addresses[mid] <= addr) | 180 | if (kallsyms_addresses[mid] <= addr) |
181 | low = mid; | 181 | low = mid; |
182 | else | 182 | else |
diff --git a/kernel/kmod.c b/kernel/kmod.c index 8df97d3dfda8..2456d1a0befb 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c | |||
@@ -42,7 +42,7 @@ extern int max_threads; | |||
42 | 42 | ||
43 | static struct workqueue_struct *khelper_wq; | 43 | static struct workqueue_struct *khelper_wq; |
44 | 44 | ||
45 | #ifdef CONFIG_KMOD | 45 | #ifdef CONFIG_MODULES |
46 | 46 | ||
47 | /* | 47 | /* |
48 | modprobe_path is set via /proc/sys. | 48 | modprobe_path is set via /proc/sys. |
@@ -352,16 +352,17 @@ static inline void register_pm_notifier_callback(void) {} | |||
352 | * @path: path to usermode executable | 352 | * @path: path to usermode executable |
353 | * @argv: arg vector for process | 353 | * @argv: arg vector for process |
354 | * @envp: environment for process | 354 | * @envp: environment for process |
355 | * @gfp_mask: gfp mask for memory allocation | ||
355 | * | 356 | * |
356 | * Returns either %NULL on allocation failure, or a subprocess_info | 357 | * Returns either %NULL on allocation failure, or a subprocess_info |
357 | * structure. This should be passed to call_usermodehelper_exec to | 358 | * structure. This should be passed to call_usermodehelper_exec to |
358 | * exec the process and free the structure. | 359 | * exec the process and free the structure. |
359 | */ | 360 | */ |
360 | struct subprocess_info *call_usermodehelper_setup(char *path, | 361 | struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, |
361 | char **argv, char **envp) | 362 | char **envp, gfp_t gfp_mask) |
362 | { | 363 | { |
363 | struct subprocess_info *sub_info; | 364 | struct subprocess_info *sub_info; |
364 | sub_info = kzalloc(sizeof(struct subprocess_info), GFP_ATOMIC); | 365 | sub_info = kzalloc(sizeof(struct subprocess_info), gfp_mask); |
365 | if (!sub_info) | 366 | if (!sub_info) |
366 | goto out; | 367 | goto out; |
367 | 368 | ||
@@ -417,12 +418,12 @@ int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info, | |||
417 | { | 418 | { |
418 | struct file *f; | 419 | struct file *f; |
419 | 420 | ||
420 | f = create_write_pipe(); | 421 | f = create_write_pipe(0); |
421 | if (IS_ERR(f)) | 422 | if (IS_ERR(f)) |
422 | return PTR_ERR(f); | 423 | return PTR_ERR(f); |
423 | *filp = f; | 424 | *filp = f; |
424 | 425 | ||
425 | f = create_read_pipe(f); | 426 | f = create_read_pipe(f, 0); |
426 | if (IS_ERR(f)) { | 427 | if (IS_ERR(f)) { |
427 | free_write_pipe(*filp); | 428 | free_write_pipe(*filp); |
428 | return PTR_ERR(f); | 429 | return PTR_ERR(f); |
@@ -494,7 +495,7 @@ int call_usermodehelper_pipe(char *path, char **argv, char **envp, | |||
494 | struct subprocess_info *sub_info; | 495 | struct subprocess_info *sub_info; |
495 | int ret; | 496 | int ret; |
496 | 497 | ||
497 | sub_info = call_usermodehelper_setup(path, argv, envp); | 498 | sub_info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL); |
498 | if (sub_info == NULL) | 499 | if (sub_info == NULL) |
499 | return -ENOMEM; | 500 | return -ENOMEM; |
500 | 501 | ||
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 1485ca8d0e00..75bc2cd9ebc6 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -62,6 +62,7 @@ | |||
62 | addr = ((kprobe_opcode_t *)(kallsyms_lookup_name(name))) | 62 | addr = ((kprobe_opcode_t *)(kallsyms_lookup_name(name))) |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | static int kprobes_initialized; | ||
65 | static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; | 66 | static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; |
66 | static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; | 67 | static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; |
67 | 68 | ||
@@ -69,8 +70,15 @@ static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; | |||
69 | static bool kprobe_enabled; | 70 | static bool kprobe_enabled; |
70 | 71 | ||
71 | DEFINE_MUTEX(kprobe_mutex); /* Protects kprobe_table */ | 72 | DEFINE_MUTEX(kprobe_mutex); /* Protects kprobe_table */ |
72 | DEFINE_SPINLOCK(kretprobe_lock); /* Protects kretprobe_inst_table */ | ||
73 | static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL; | 73 | static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL; |
74 | static struct { | ||
75 | spinlock_t lock ____cacheline_aligned; | ||
76 | } kretprobe_table_locks[KPROBE_TABLE_SIZE]; | ||
77 | |||
78 | static spinlock_t *kretprobe_table_lock_ptr(unsigned long hash) | ||
79 | { | ||
80 | return &(kretprobe_table_locks[hash].lock); | ||
81 | } | ||
74 | 82 | ||
75 | /* | 83 | /* |
76 | * Normally, functions that we'd want to prohibit kprobes in, are marked | 84 | * Normally, functions that we'd want to prohibit kprobes in, are marked |
@@ -368,26 +376,53 @@ void __kprobes kprobes_inc_nmissed_count(struct kprobe *p) | |||
368 | return; | 376 | return; |
369 | } | 377 | } |
370 | 378 | ||
371 | /* Called with kretprobe_lock held */ | ||
372 | void __kprobes recycle_rp_inst(struct kretprobe_instance *ri, | 379 | void __kprobes recycle_rp_inst(struct kretprobe_instance *ri, |
373 | struct hlist_head *head) | 380 | struct hlist_head *head) |
374 | { | 381 | { |
382 | struct kretprobe *rp = ri->rp; | ||
383 | |||
375 | /* remove rp inst off the rprobe_inst_table */ | 384 | /* remove rp inst off the rprobe_inst_table */ |
376 | hlist_del(&ri->hlist); | 385 | hlist_del(&ri->hlist); |
377 | if (ri->rp) { | 386 | INIT_HLIST_NODE(&ri->hlist); |
378 | /* remove rp inst off the used list */ | 387 | if (likely(rp)) { |
379 | hlist_del(&ri->uflist); | 388 | spin_lock(&rp->lock); |
380 | /* put rp inst back onto the free list */ | 389 | hlist_add_head(&ri->hlist, &rp->free_instances); |
381 | INIT_HLIST_NODE(&ri->uflist); | 390 | spin_unlock(&rp->lock); |
382 | hlist_add_head(&ri->uflist, &ri->rp->free_instances); | ||
383 | } else | 391 | } else |
384 | /* Unregistering */ | 392 | /* Unregistering */ |
385 | hlist_add_head(&ri->hlist, head); | 393 | hlist_add_head(&ri->hlist, head); |
386 | } | 394 | } |
387 | 395 | ||
388 | struct hlist_head __kprobes *kretprobe_inst_table_head(struct task_struct *tsk) | 396 | void kretprobe_hash_lock(struct task_struct *tsk, |
397 | struct hlist_head **head, unsigned long *flags) | ||
389 | { | 398 | { |
390 | return &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)]; | 399 | unsigned long hash = hash_ptr(tsk, KPROBE_HASH_BITS); |
400 | spinlock_t *hlist_lock; | ||
401 | |||
402 | *head = &kretprobe_inst_table[hash]; | ||
403 | hlist_lock = kretprobe_table_lock_ptr(hash); | ||
404 | spin_lock_irqsave(hlist_lock, *flags); | ||
405 | } | ||
406 | |||
407 | void kretprobe_table_lock(unsigned long hash, unsigned long *flags) | ||
408 | { | ||
409 | spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); | ||
410 | spin_lock_irqsave(hlist_lock, *flags); | ||
411 | } | ||
412 | |||
413 | void kretprobe_hash_unlock(struct task_struct *tsk, unsigned long *flags) | ||
414 | { | ||
415 | unsigned long hash = hash_ptr(tsk, KPROBE_HASH_BITS); | ||
416 | spinlock_t *hlist_lock; | ||
417 | |||
418 | hlist_lock = kretprobe_table_lock_ptr(hash); | ||
419 | spin_unlock_irqrestore(hlist_lock, *flags); | ||
420 | } | ||
421 | |||
422 | void kretprobe_table_unlock(unsigned long hash, unsigned long *flags) | ||
423 | { | ||
424 | spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); | ||
425 | spin_unlock_irqrestore(hlist_lock, *flags); | ||
391 | } | 426 | } |
392 | 427 | ||
393 | /* | 428 | /* |
@@ -401,17 +436,21 @@ void __kprobes kprobe_flush_task(struct task_struct *tk) | |||
401 | struct kretprobe_instance *ri; | 436 | struct kretprobe_instance *ri; |
402 | struct hlist_head *head, empty_rp; | 437 | struct hlist_head *head, empty_rp; |
403 | struct hlist_node *node, *tmp; | 438 | struct hlist_node *node, *tmp; |
404 | unsigned long flags = 0; | 439 | unsigned long hash, flags = 0; |
405 | 440 | ||
406 | INIT_HLIST_HEAD(&empty_rp); | 441 | if (unlikely(!kprobes_initialized)) |
407 | spin_lock_irqsave(&kretprobe_lock, flags); | 442 | /* Early boot. kretprobe_table_locks not yet initialized. */ |
408 | head = kretprobe_inst_table_head(tk); | 443 | return; |
444 | |||
445 | hash = hash_ptr(tk, KPROBE_HASH_BITS); | ||
446 | head = &kretprobe_inst_table[hash]; | ||
447 | kretprobe_table_lock(hash, &flags); | ||
409 | hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { | 448 | hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { |
410 | if (ri->task == tk) | 449 | if (ri->task == tk) |
411 | recycle_rp_inst(ri, &empty_rp); | 450 | recycle_rp_inst(ri, &empty_rp); |
412 | } | 451 | } |
413 | spin_unlock_irqrestore(&kretprobe_lock, flags); | 452 | kretprobe_table_unlock(hash, &flags); |
414 | 453 | INIT_HLIST_HEAD(&empty_rp); | |
415 | hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) { | 454 | hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) { |
416 | hlist_del(&ri->hlist); | 455 | hlist_del(&ri->hlist); |
417 | kfree(ri); | 456 | kfree(ri); |
@@ -423,24 +462,29 @@ static inline void free_rp_inst(struct kretprobe *rp) | |||
423 | struct kretprobe_instance *ri; | 462 | struct kretprobe_instance *ri; |
424 | struct hlist_node *pos, *next; | 463 | struct hlist_node *pos, *next; |
425 | 464 | ||
426 | hlist_for_each_entry_safe(ri, pos, next, &rp->free_instances, uflist) { | 465 | hlist_for_each_entry_safe(ri, pos, next, &rp->free_instances, hlist) { |
427 | hlist_del(&ri->uflist); | 466 | hlist_del(&ri->hlist); |
428 | kfree(ri); | 467 | kfree(ri); |
429 | } | 468 | } |
430 | } | 469 | } |
431 | 470 | ||
432 | static void __kprobes cleanup_rp_inst(struct kretprobe *rp) | 471 | static void __kprobes cleanup_rp_inst(struct kretprobe *rp) |
433 | { | 472 | { |
434 | unsigned long flags; | 473 | unsigned long flags, hash; |
435 | struct kretprobe_instance *ri; | 474 | struct kretprobe_instance *ri; |
436 | struct hlist_node *pos, *next; | 475 | struct hlist_node *pos, *next; |
476 | struct hlist_head *head; | ||
477 | |||
437 | /* No race here */ | 478 | /* No race here */ |
438 | spin_lock_irqsave(&kretprobe_lock, flags); | 479 | for (hash = 0; hash < KPROBE_TABLE_SIZE; hash++) { |
439 | hlist_for_each_entry_safe(ri, pos, next, &rp->used_instances, uflist) { | 480 | kretprobe_table_lock(hash, &flags); |
440 | ri->rp = NULL; | 481 | head = &kretprobe_inst_table[hash]; |
441 | hlist_del(&ri->uflist); | 482 | hlist_for_each_entry_safe(ri, pos, next, head, hlist) { |
483 | if (ri->rp == rp) | ||
484 | ri->rp = NULL; | ||
485 | } | ||
486 | kretprobe_table_unlock(hash, &flags); | ||
442 | } | 487 | } |
443 | spin_unlock_irqrestore(&kretprobe_lock, flags); | ||
444 | free_rp_inst(rp); | 488 | free_rp_inst(rp); |
445 | } | 489 | } |
446 | 490 | ||
@@ -831,32 +875,37 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p, | |||
831 | struct pt_regs *regs) | 875 | struct pt_regs *regs) |
832 | { | 876 | { |
833 | struct kretprobe *rp = container_of(p, struct kretprobe, kp); | 877 | struct kretprobe *rp = container_of(p, struct kretprobe, kp); |
834 | unsigned long flags = 0; | 878 | unsigned long hash, flags = 0; |
879 | struct kretprobe_instance *ri; | ||
835 | 880 | ||
836 | /*TODO: consider to only swap the RA after the last pre_handler fired */ | 881 | /*TODO: consider to only swap the RA after the last pre_handler fired */ |
837 | spin_lock_irqsave(&kretprobe_lock, flags); | 882 | hash = hash_ptr(current, KPROBE_HASH_BITS); |
883 | spin_lock_irqsave(&rp->lock, flags); | ||
838 | if (!hlist_empty(&rp->free_instances)) { | 884 | if (!hlist_empty(&rp->free_instances)) { |
839 | struct kretprobe_instance *ri; | ||
840 | |||
841 | ri = hlist_entry(rp->free_instances.first, | 885 | ri = hlist_entry(rp->free_instances.first, |
842 | struct kretprobe_instance, uflist); | 886 | struct kretprobe_instance, hlist); |
887 | hlist_del(&ri->hlist); | ||
888 | spin_unlock_irqrestore(&rp->lock, flags); | ||
889 | |||
843 | ri->rp = rp; | 890 | ri->rp = rp; |
844 | ri->task = current; | 891 | ri->task = current; |
845 | 892 | ||
846 | if (rp->entry_handler && rp->entry_handler(ri, regs)) { | 893 | if (rp->entry_handler && rp->entry_handler(ri, regs)) { |
847 | spin_unlock_irqrestore(&kretprobe_lock, flags); | 894 | spin_unlock_irqrestore(&rp->lock, flags); |
848 | return 0; | 895 | return 0; |
849 | } | 896 | } |
850 | 897 | ||
851 | arch_prepare_kretprobe(ri, regs); | 898 | arch_prepare_kretprobe(ri, regs); |
852 | 899 | ||
853 | /* XXX(hch): why is there no hlist_move_head? */ | 900 | /* XXX(hch): why is there no hlist_move_head? */ |
854 | hlist_del(&ri->uflist); | 901 | INIT_HLIST_NODE(&ri->hlist); |
855 | hlist_add_head(&ri->uflist, &ri->rp->used_instances); | 902 | kretprobe_table_lock(hash, &flags); |
856 | hlist_add_head(&ri->hlist, kretprobe_inst_table_head(ri->task)); | 903 | hlist_add_head(&ri->hlist, &kretprobe_inst_table[hash]); |
857 | } else | 904 | kretprobe_table_unlock(hash, &flags); |
905 | } else { | ||
858 | rp->nmissed++; | 906 | rp->nmissed++; |
859 | spin_unlock_irqrestore(&kretprobe_lock, flags); | 907 | spin_unlock_irqrestore(&rp->lock, flags); |
908 | } | ||
860 | return 0; | 909 | return 0; |
861 | } | 910 | } |
862 | 911 | ||
@@ -892,7 +941,7 @@ static int __kprobes __register_kretprobe(struct kretprobe *rp, | |||
892 | rp->maxactive = NR_CPUS; | 941 | rp->maxactive = NR_CPUS; |
893 | #endif | 942 | #endif |
894 | } | 943 | } |
895 | INIT_HLIST_HEAD(&rp->used_instances); | 944 | spin_lock_init(&rp->lock); |
896 | INIT_HLIST_HEAD(&rp->free_instances); | 945 | INIT_HLIST_HEAD(&rp->free_instances); |
897 | for (i = 0; i < rp->maxactive; i++) { | 946 | for (i = 0; i < rp->maxactive; i++) { |
898 | inst = kmalloc(sizeof(struct kretprobe_instance) + | 947 | inst = kmalloc(sizeof(struct kretprobe_instance) + |
@@ -901,8 +950,8 @@ static int __kprobes __register_kretprobe(struct kretprobe *rp, | |||
901 | free_rp_inst(rp); | 950 | free_rp_inst(rp); |
902 | return -ENOMEM; | 951 | return -ENOMEM; |
903 | } | 952 | } |
904 | INIT_HLIST_NODE(&inst->uflist); | 953 | INIT_HLIST_NODE(&inst->hlist); |
905 | hlist_add_head(&inst->uflist, &rp->free_instances); | 954 | hlist_add_head(&inst->hlist, &rp->free_instances); |
906 | } | 955 | } |
907 | 956 | ||
908 | rp->nmissed = 0; | 957 | rp->nmissed = 0; |
@@ -1009,6 +1058,7 @@ static int __init init_kprobes(void) | |||
1009 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 1058 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
1010 | INIT_HLIST_HEAD(&kprobe_table[i]); | 1059 | INIT_HLIST_HEAD(&kprobe_table[i]); |
1011 | INIT_HLIST_HEAD(&kretprobe_inst_table[i]); | 1060 | INIT_HLIST_HEAD(&kretprobe_inst_table[i]); |
1061 | spin_lock_init(&(kretprobe_table_locks[i].lock)); | ||
1012 | } | 1062 | } |
1013 | 1063 | ||
1014 | /* | 1064 | /* |
@@ -1050,6 +1100,7 @@ static int __init init_kprobes(void) | |||
1050 | err = arch_init_kprobes(); | 1100 | err = arch_init_kprobes(); |
1051 | if (!err) | 1101 | if (!err) |
1052 | err = register_die_notifier(&kprobe_exceptions_nb); | 1102 | err = register_die_notifier(&kprobe_exceptions_nb); |
1103 | kprobes_initialized = (err == 0); | ||
1053 | 1104 | ||
1054 | if (!err) | 1105 | if (!err) |
1055 | init_test_probes(); | 1106 | init_test_probes(); |
@@ -1286,13 +1337,8 @@ EXPORT_SYMBOL_GPL(register_jprobe); | |||
1286 | EXPORT_SYMBOL_GPL(unregister_jprobe); | 1337 | EXPORT_SYMBOL_GPL(unregister_jprobe); |
1287 | EXPORT_SYMBOL_GPL(register_jprobes); | 1338 | EXPORT_SYMBOL_GPL(register_jprobes); |
1288 | EXPORT_SYMBOL_GPL(unregister_jprobes); | 1339 | EXPORT_SYMBOL_GPL(unregister_jprobes); |
1289 | #ifdef CONFIG_KPROBES | ||
1290 | EXPORT_SYMBOL_GPL(jprobe_return); | 1340 | EXPORT_SYMBOL_GPL(jprobe_return); |
1291 | #endif | ||
1292 | |||
1293 | #ifdef CONFIG_KPROBES | ||
1294 | EXPORT_SYMBOL_GPL(register_kretprobe); | 1341 | EXPORT_SYMBOL_GPL(register_kretprobe); |
1295 | EXPORT_SYMBOL_GPL(unregister_kretprobe); | 1342 | EXPORT_SYMBOL_GPL(unregister_kretprobe); |
1296 | EXPORT_SYMBOL_GPL(register_kretprobes); | 1343 | EXPORT_SYMBOL_GPL(register_kretprobes); |
1297 | EXPORT_SYMBOL_GPL(unregister_kretprobes); | 1344 | EXPORT_SYMBOL_GPL(unregister_kretprobes); |
1298 | #endif | ||
diff --git a/kernel/kthread.c b/kernel/kthread.c index ac3fb7326641..6111c27491b1 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c | |||
@@ -106,7 +106,7 @@ static void create_kthread(struct kthread_create_info *create) | |||
106 | */ | 106 | */ |
107 | sched_setscheduler(create->result, SCHED_NORMAL, ¶m); | 107 | sched_setscheduler(create->result, SCHED_NORMAL, ¶m); |
108 | set_user_nice(create->result, KTHREAD_NICE_LEVEL); | 108 | set_user_nice(create->result, KTHREAD_NICE_LEVEL); |
109 | set_cpus_allowed(create->result, CPU_MASK_ALL); | 109 | set_cpus_allowed_ptr(create->result, CPU_MASK_ALL_PTR); |
110 | } | 110 | } |
111 | complete(&create->done); | 111 | complete(&create->done); |
112 | } | 112 | } |
@@ -233,7 +233,7 @@ int kthreadd(void *unused) | |||
233 | set_task_comm(tsk, "kthreadd"); | 233 | set_task_comm(tsk, "kthreadd"); |
234 | ignore_signals(tsk); | 234 | ignore_signals(tsk); |
235 | set_user_nice(tsk, KTHREAD_NICE_LEVEL); | 235 | set_user_nice(tsk, KTHREAD_NICE_LEVEL); |
236 | set_cpus_allowed(tsk, CPU_MASK_ALL); | 236 | set_cpus_allowed_ptr(tsk, CPU_MASK_ALL_PTR); |
237 | 237 | ||
238 | current->flags |= PF_NOFREEZE | PF_FREEZER_NOSIG; | 238 | current->flags |= PF_NOFREEZE | PF_FREEZER_NOSIG; |
239 | 239 | ||
diff --git a/kernel/marker.c b/kernel/marker.c index 1abfb923b761..971da5317903 100644 --- a/kernel/marker.c +++ b/kernel/marker.c | |||
@@ -441,7 +441,7 @@ static int remove_marker(const char *name) | |||
441 | hlist_del(&e->hlist); | 441 | hlist_del(&e->hlist); |
442 | /* Make sure the call_rcu has been executed */ | 442 | /* Make sure the call_rcu has been executed */ |
443 | if (e->rcu_pending) | 443 | if (e->rcu_pending) |
444 | rcu_barrier(); | 444 | rcu_barrier_sched(); |
445 | kfree(e); | 445 | kfree(e); |
446 | return 0; | 446 | return 0; |
447 | } | 447 | } |
@@ -476,7 +476,7 @@ static int marker_set_format(struct marker_entry **entry, const char *format) | |||
476 | hlist_del(&(*entry)->hlist); | 476 | hlist_del(&(*entry)->hlist); |
477 | /* Make sure the call_rcu has been executed */ | 477 | /* Make sure the call_rcu has been executed */ |
478 | if ((*entry)->rcu_pending) | 478 | if ((*entry)->rcu_pending) |
479 | rcu_barrier(); | 479 | rcu_barrier_sched(); |
480 | kfree(*entry); | 480 | kfree(*entry); |
481 | *entry = e; | 481 | *entry = e; |
482 | trace_mark(core_marker_format, "name %s format %s", | 482 | trace_mark(core_marker_format, "name %s format %s", |
@@ -655,7 +655,7 @@ int marker_probe_register(const char *name, const char *format, | |||
655 | * make sure it's executed now. | 655 | * make sure it's executed now. |
656 | */ | 656 | */ |
657 | if (entry->rcu_pending) | 657 | if (entry->rcu_pending) |
658 | rcu_barrier(); | 658 | rcu_barrier_sched(); |
659 | old = marker_entry_add_probe(entry, probe, probe_private); | 659 | old = marker_entry_add_probe(entry, probe, probe_private); |
660 | if (IS_ERR(old)) { | 660 | if (IS_ERR(old)) { |
661 | ret = PTR_ERR(old); | 661 | ret = PTR_ERR(old); |
@@ -670,10 +670,7 @@ int marker_probe_register(const char *name, const char *format, | |||
670 | entry->rcu_pending = 1; | 670 | entry->rcu_pending = 1; |
671 | /* write rcu_pending before calling the RCU callback */ | 671 | /* write rcu_pending before calling the RCU callback */ |
672 | smp_wmb(); | 672 | smp_wmb(); |
673 | #ifdef CONFIG_PREEMPT_RCU | 673 | call_rcu_sched(&entry->rcu, free_old_closure); |
674 | synchronize_sched(); /* Until we have the call_rcu_sched() */ | ||
675 | #endif | ||
676 | call_rcu(&entry->rcu, free_old_closure); | ||
677 | end: | 674 | end: |
678 | mutex_unlock(&markers_mutex); | 675 | mutex_unlock(&markers_mutex); |
679 | return ret; | 676 | return ret; |
@@ -704,7 +701,7 @@ int marker_probe_unregister(const char *name, | |||
704 | if (!entry) | 701 | if (!entry) |
705 | goto end; | 702 | goto end; |
706 | if (entry->rcu_pending) | 703 | if (entry->rcu_pending) |
707 | rcu_barrier(); | 704 | rcu_barrier_sched(); |
708 | old = marker_entry_remove_probe(entry, probe, probe_private); | 705 | old = marker_entry_remove_probe(entry, probe, probe_private); |
709 | mutex_unlock(&markers_mutex); | 706 | mutex_unlock(&markers_mutex); |
710 | marker_update_probes(); /* may update entry */ | 707 | marker_update_probes(); /* may update entry */ |
@@ -716,10 +713,7 @@ int marker_probe_unregister(const char *name, | |||
716 | entry->rcu_pending = 1; | 713 | entry->rcu_pending = 1; |
717 | /* write rcu_pending before calling the RCU callback */ | 714 | /* write rcu_pending before calling the RCU callback */ |
718 | smp_wmb(); | 715 | smp_wmb(); |
719 | #ifdef CONFIG_PREEMPT_RCU | 716 | call_rcu_sched(&entry->rcu, free_old_closure); |
720 | synchronize_sched(); /* Until we have the call_rcu_sched() */ | ||
721 | #endif | ||
722 | call_rcu(&entry->rcu, free_old_closure); | ||
723 | remove_marker(name); /* Ignore busy error message */ | 717 | remove_marker(name); /* Ignore busy error message */ |
724 | ret = 0; | 718 | ret = 0; |
725 | end: | 719 | end: |
@@ -786,7 +780,7 @@ int marker_probe_unregister_private_data(marker_probe_func *probe, | |||
786 | goto end; | 780 | goto end; |
787 | } | 781 | } |
788 | if (entry->rcu_pending) | 782 | if (entry->rcu_pending) |
789 | rcu_barrier(); | 783 | rcu_barrier_sched(); |
790 | old = marker_entry_remove_probe(entry, NULL, probe_private); | 784 | old = marker_entry_remove_probe(entry, NULL, probe_private); |
791 | mutex_unlock(&markers_mutex); | 785 | mutex_unlock(&markers_mutex); |
792 | marker_update_probes(); /* may update entry */ | 786 | marker_update_probes(); /* may update entry */ |
@@ -797,10 +791,7 @@ int marker_probe_unregister_private_data(marker_probe_func *probe, | |||
797 | entry->rcu_pending = 1; | 791 | entry->rcu_pending = 1; |
798 | /* write rcu_pending before calling the RCU callback */ | 792 | /* write rcu_pending before calling the RCU callback */ |
799 | smp_wmb(); | 793 | smp_wmb(); |
800 | #ifdef CONFIG_PREEMPT_RCU | 794 | call_rcu_sched(&entry->rcu, free_old_closure); |
801 | synchronize_sched(); /* Until we have the call_rcu_sched() */ | ||
802 | #endif | ||
803 | call_rcu(&entry->rcu, free_old_closure); | ||
804 | remove_marker(entry->name); /* Ignore busy error message */ | 795 | remove_marker(entry->name); /* Ignore busy error message */ |
805 | end: | 796 | end: |
806 | mutex_unlock(&markers_mutex); | 797 | mutex_unlock(&markers_mutex); |
diff --git a/kernel/module.c b/kernel/module.c index 5f80478b746d..d8b5605132a0 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -70,6 +70,9 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq); | |||
70 | 70 | ||
71 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); | 71 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); |
72 | 72 | ||
73 | /* Bounds of module allocation, for speeding __module_text_address */ | ||
74 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; | ||
75 | |||
73 | int register_module_notifier(struct notifier_block * nb) | 76 | int register_module_notifier(struct notifier_block * nb) |
74 | { | 77 | { |
75 | return blocking_notifier_chain_register(&module_notify_list, nb); | 78 | return blocking_notifier_chain_register(&module_notify_list, nb); |
@@ -134,17 +137,19 @@ extern const struct kernel_symbol __start___ksymtab_gpl[]; | |||
134 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; | 137 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; |
135 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; | 138 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; |
136 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; | 139 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; |
137 | extern const struct kernel_symbol __start___ksymtab_unused[]; | ||
138 | extern const struct kernel_symbol __stop___ksymtab_unused[]; | ||
139 | extern const struct kernel_symbol __start___ksymtab_unused_gpl[]; | ||
140 | extern const struct kernel_symbol __stop___ksymtab_unused_gpl[]; | ||
141 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; | 140 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; |
142 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; | 141 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; |
143 | extern const unsigned long __start___kcrctab[]; | 142 | extern const unsigned long __start___kcrctab[]; |
144 | extern const unsigned long __start___kcrctab_gpl[]; | 143 | extern const unsigned long __start___kcrctab_gpl[]; |
145 | extern const unsigned long __start___kcrctab_gpl_future[]; | 144 | extern const unsigned long __start___kcrctab_gpl_future[]; |
145 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
146 | extern const struct kernel_symbol __start___ksymtab_unused[]; | ||
147 | extern const struct kernel_symbol __stop___ksymtab_unused[]; | ||
148 | extern const struct kernel_symbol __start___ksymtab_unused_gpl[]; | ||
149 | extern const struct kernel_symbol __stop___ksymtab_unused_gpl[]; | ||
146 | extern const unsigned long __start___kcrctab_unused[]; | 150 | extern const unsigned long __start___kcrctab_unused[]; |
147 | extern const unsigned long __start___kcrctab_unused_gpl[]; | 151 | extern const unsigned long __start___kcrctab_unused_gpl[]; |
152 | #endif | ||
148 | 153 | ||
149 | #ifndef CONFIG_MODVERSIONS | 154 | #ifndef CONFIG_MODVERSIONS |
150 | #define symversion(base, idx) NULL | 155 | #define symversion(base, idx) NULL |
@@ -152,156 +157,186 @@ extern const unsigned long __start___kcrctab_unused_gpl[]; | |||
152 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) | 157 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) |
153 | #endif | 158 | #endif |
154 | 159 | ||
155 | /* lookup symbol in given range of kernel_symbols */ | ||
156 | static const struct kernel_symbol *lookup_symbol(const char *name, | ||
157 | const struct kernel_symbol *start, | ||
158 | const struct kernel_symbol *stop) | ||
159 | { | ||
160 | const struct kernel_symbol *ks = start; | ||
161 | for (; ks < stop; ks++) | ||
162 | if (strcmp(ks->name, name) == 0) | ||
163 | return ks; | ||
164 | return NULL; | ||
165 | } | ||
166 | |||
167 | static bool always_ok(bool gplok, bool warn, const char *name) | ||
168 | { | ||
169 | return true; | ||
170 | } | ||
171 | |||
172 | static bool printk_unused_warning(bool gplok, bool warn, const char *name) | ||
173 | { | ||
174 | if (warn) { | ||
175 | printk(KERN_WARNING "Symbol %s is marked as UNUSED, " | ||
176 | "however this module is using it.\n", name); | ||
177 | printk(KERN_WARNING | ||
178 | "This symbol will go away in the future.\n"); | ||
179 | printk(KERN_WARNING | ||
180 | "Please evalute if this is the right api to use and if " | ||
181 | "it really is, submit a report the linux kernel " | ||
182 | "mailinglist together with submitting your code for " | ||
183 | "inclusion.\n"); | ||
184 | } | ||
185 | return true; | ||
186 | } | ||
187 | |||
188 | static bool gpl_only_unused_warning(bool gplok, bool warn, const char *name) | ||
189 | { | ||
190 | if (!gplok) | ||
191 | return false; | ||
192 | return printk_unused_warning(gplok, warn, name); | ||
193 | } | ||
194 | |||
195 | static bool gpl_only(bool gplok, bool warn, const char *name) | ||
196 | { | ||
197 | return gplok; | ||
198 | } | ||
199 | |||
200 | static bool warn_if_not_gpl(bool gplok, bool warn, const char *name) | ||
201 | { | ||
202 | if (!gplok && warn) { | ||
203 | printk(KERN_WARNING "Symbol %s is being used " | ||
204 | "by a non-GPL module, which will not " | ||
205 | "be allowed in the future\n", name); | ||
206 | printk(KERN_WARNING "Please see the file " | ||
207 | "Documentation/feature-removal-schedule.txt " | ||
208 | "in the kernel source tree for more details.\n"); | ||
209 | } | ||
210 | return true; | ||
211 | } | ||
212 | |||
213 | struct symsearch { | 160 | struct symsearch { |
214 | const struct kernel_symbol *start, *stop; | 161 | const struct kernel_symbol *start, *stop; |
215 | const unsigned long *crcs; | 162 | const unsigned long *crcs; |
216 | bool (*check)(bool gplok, bool warn, const char *name); | 163 | enum { |
164 | NOT_GPL_ONLY, | ||
165 | GPL_ONLY, | ||
166 | WILL_BE_GPL_ONLY, | ||
167 | } licence; | ||
168 | bool unused; | ||
217 | }; | 169 | }; |
218 | 170 | ||
219 | /* Look through this array of symbol tables for a symbol match which | 171 | static bool each_symbol_in_section(const struct symsearch *arr, |
220 | * passes the check function. */ | 172 | unsigned int arrsize, |
221 | static const struct kernel_symbol *search_symarrays(const struct symsearch *arr, | 173 | struct module *owner, |
222 | unsigned int num, | 174 | bool (*fn)(const struct symsearch *syms, |
223 | const char *name, | 175 | struct module *owner, |
224 | bool gplok, | 176 | unsigned int symnum, void *data), |
225 | bool warn, | 177 | void *data) |
226 | const unsigned long **crc) | ||
227 | { | 178 | { |
228 | unsigned int i; | 179 | unsigned int i, j; |
229 | const struct kernel_symbol *ks; | ||
230 | 180 | ||
231 | for (i = 0; i < num; i++) { | 181 | for (j = 0; j < arrsize; j++) { |
232 | ks = lookup_symbol(name, arr[i].start, arr[i].stop); | 182 | for (i = 0; i < arr[j].stop - arr[j].start; i++) |
233 | if (!ks || !arr[i].check(gplok, warn, name)) | 183 | if (fn(&arr[j], owner, i, data)) |
234 | continue; | 184 | return true; |
235 | |||
236 | if (crc) | ||
237 | *crc = symversion(arr[i].crcs, ks - arr[i].start); | ||
238 | return ks; | ||
239 | } | 185 | } |
240 | return NULL; | 186 | |
187 | return false; | ||
241 | } | 188 | } |
242 | 189 | ||
243 | /* Find a symbol, return value, (optional) crc and (optional) module | 190 | /* Returns true as soon as fn returns true, otherwise false. */ |
244 | * which owns it */ | 191 | static bool each_symbol(bool (*fn)(const struct symsearch *arr, |
245 | static unsigned long find_symbol(const char *name, | 192 | struct module *owner, |
246 | struct module **owner, | 193 | unsigned int symnum, void *data), |
247 | const unsigned long **crc, | 194 | void *data) |
248 | bool gplok, | ||
249 | bool warn) | ||
250 | { | 195 | { |
251 | struct module *mod; | 196 | struct module *mod; |
252 | const struct kernel_symbol *ks; | ||
253 | const struct symsearch arr[] = { | 197 | const struct symsearch arr[] = { |
254 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, | 198 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, |
255 | always_ok }, | 199 | NOT_GPL_ONLY, false }, |
256 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, | 200 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, |
257 | __start___kcrctab_gpl, gpl_only }, | 201 | __start___kcrctab_gpl, |
202 | GPL_ONLY, false }, | ||
258 | { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, | 203 | { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, |
259 | __start___kcrctab_gpl_future, warn_if_not_gpl }, | 204 | __start___kcrctab_gpl_future, |
205 | WILL_BE_GPL_ONLY, false }, | ||
206 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
260 | { __start___ksymtab_unused, __stop___ksymtab_unused, | 207 | { __start___ksymtab_unused, __stop___ksymtab_unused, |
261 | __start___kcrctab_unused, printk_unused_warning }, | 208 | __start___kcrctab_unused, |
209 | NOT_GPL_ONLY, true }, | ||
262 | { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, | 210 | { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, |
263 | __start___kcrctab_unused_gpl, gpl_only_unused_warning }, | 211 | __start___kcrctab_unused_gpl, |
212 | GPL_ONLY, true }, | ||
213 | #endif | ||
264 | }; | 214 | }; |
265 | 215 | ||
266 | /* Core kernel first. */ | 216 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) |
267 | ks = search_symarrays(arr, ARRAY_SIZE(arr), name, gplok, warn, crc); | 217 | return true; |
268 | if (ks) { | ||
269 | if (owner) | ||
270 | *owner = NULL; | ||
271 | return ks->value; | ||
272 | } | ||
273 | 218 | ||
274 | /* Now try modules. */ | ||
275 | list_for_each_entry(mod, &modules, list) { | 219 | list_for_each_entry(mod, &modules, list) { |
276 | struct symsearch arr[] = { | 220 | struct symsearch arr[] = { |
277 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, | 221 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, |
278 | always_ok }, | 222 | NOT_GPL_ONLY, false }, |
279 | { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, | 223 | { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, |
280 | mod->gpl_crcs, gpl_only }, | 224 | mod->gpl_crcs, |
225 | GPL_ONLY, false }, | ||
281 | { mod->gpl_future_syms, | 226 | { mod->gpl_future_syms, |
282 | mod->gpl_future_syms + mod->num_gpl_future_syms, | 227 | mod->gpl_future_syms + mod->num_gpl_future_syms, |
283 | mod->gpl_future_crcs, warn_if_not_gpl }, | 228 | mod->gpl_future_crcs, |
229 | WILL_BE_GPL_ONLY, false }, | ||
230 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
284 | { mod->unused_syms, | 231 | { mod->unused_syms, |
285 | mod->unused_syms + mod->num_unused_syms, | 232 | mod->unused_syms + mod->num_unused_syms, |
286 | mod->unused_crcs, printk_unused_warning }, | 233 | mod->unused_crcs, |
234 | NOT_GPL_ONLY, true }, | ||
287 | { mod->unused_gpl_syms, | 235 | { mod->unused_gpl_syms, |
288 | mod->unused_gpl_syms + mod->num_unused_gpl_syms, | 236 | mod->unused_gpl_syms + mod->num_unused_gpl_syms, |
289 | mod->unused_gpl_crcs, gpl_only_unused_warning }, | 237 | mod->unused_gpl_crcs, |
238 | GPL_ONLY, true }, | ||
239 | #endif | ||
290 | }; | 240 | }; |
291 | 241 | ||
292 | ks = search_symarrays(arr, ARRAY_SIZE(arr), | 242 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) |
293 | name, gplok, warn, crc); | 243 | return true; |
294 | if (ks) { | 244 | } |
295 | if (owner) | 245 | return false; |
296 | *owner = mod; | 246 | } |
297 | return ks->value; | 247 | |
248 | struct find_symbol_arg { | ||
249 | /* Input */ | ||
250 | const char *name; | ||
251 | bool gplok; | ||
252 | bool warn; | ||
253 | |||
254 | /* Output */ | ||
255 | struct module *owner; | ||
256 | const unsigned long *crc; | ||
257 | unsigned long value; | ||
258 | }; | ||
259 | |||
260 | static bool find_symbol_in_section(const struct symsearch *syms, | ||
261 | struct module *owner, | ||
262 | unsigned int symnum, void *data) | ||
263 | { | ||
264 | struct find_symbol_arg *fsa = data; | ||
265 | |||
266 | if (strcmp(syms->start[symnum].name, fsa->name) != 0) | ||
267 | return false; | ||
268 | |||
269 | if (!fsa->gplok) { | ||
270 | if (syms->licence == GPL_ONLY) | ||
271 | return false; | ||
272 | if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { | ||
273 | printk(KERN_WARNING "Symbol %s is being used " | ||
274 | "by a non-GPL module, which will not " | ||
275 | "be allowed in the future\n", fsa->name); | ||
276 | printk(KERN_WARNING "Please see the file " | ||
277 | "Documentation/feature-removal-schedule.txt " | ||
278 | "in the kernel source tree for more details.\n"); | ||
298 | } | 279 | } |
299 | } | 280 | } |
300 | 281 | ||
282 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
283 | if (syms->unused && fsa->warn) { | ||
284 | printk(KERN_WARNING "Symbol %s is marked as UNUSED, " | ||
285 | "however this module is using it.\n", fsa->name); | ||
286 | printk(KERN_WARNING | ||
287 | "This symbol will go away in the future.\n"); | ||
288 | printk(KERN_WARNING | ||
289 | "Please evalute if this is the right api to use and if " | ||
290 | "it really is, submit a report the linux kernel " | ||
291 | "mailinglist together with submitting your code for " | ||
292 | "inclusion.\n"); | ||
293 | } | ||
294 | #endif | ||
295 | |||
296 | fsa->owner = owner; | ||
297 | fsa->crc = symversion(syms->crcs, symnum); | ||
298 | fsa->value = syms->start[symnum].value; | ||
299 | return true; | ||
300 | } | ||
301 | |||
302 | /* Find a symbol, return value, (optional) crc and (optional) module | ||
303 | * which owns it */ | ||
304 | static unsigned long find_symbol(const char *name, | ||
305 | struct module **owner, | ||
306 | const unsigned long **crc, | ||
307 | bool gplok, | ||
308 | bool warn) | ||
309 | { | ||
310 | struct find_symbol_arg fsa; | ||
311 | |||
312 | fsa.name = name; | ||
313 | fsa.gplok = gplok; | ||
314 | fsa.warn = warn; | ||
315 | |||
316 | if (each_symbol(find_symbol_in_section, &fsa)) { | ||
317 | if (owner) | ||
318 | *owner = fsa.owner; | ||
319 | if (crc) | ||
320 | *crc = fsa.crc; | ||
321 | return fsa.value; | ||
322 | } | ||
323 | |||
301 | DEBUGP("Failed to find symbol %s\n", name); | 324 | DEBUGP("Failed to find symbol %s\n", name); |
302 | return -ENOENT; | 325 | return -ENOENT; |
303 | } | 326 | } |
304 | 327 | ||
328 | /* lookup symbol in given range of kernel_symbols */ | ||
329 | static const struct kernel_symbol *lookup_symbol(const char *name, | ||
330 | const struct kernel_symbol *start, | ||
331 | const struct kernel_symbol *stop) | ||
332 | { | ||
333 | const struct kernel_symbol *ks = start; | ||
334 | for (; ks < stop; ks++) | ||
335 | if (strcmp(ks->name, name) == 0) | ||
336 | return ks; | ||
337 | return NULL; | ||
338 | } | ||
339 | |||
305 | /* Search for module by name: must hold module_mutex. */ | 340 | /* Search for module by name: must hold module_mutex. */ |
306 | static struct module *find_module(const char *name) | 341 | static struct module *find_module(const char *name) |
307 | { | 342 | { |
@@ -639,8 +674,8 @@ static int __try_stop_module(void *_sref) | |||
639 | { | 674 | { |
640 | struct stopref *sref = _sref; | 675 | struct stopref *sref = _sref; |
641 | 676 | ||
642 | /* If it's not unused, quit unless we are told to block. */ | 677 | /* If it's not unused, quit unless we're forcing. */ |
643 | if ((sref->flags & O_NONBLOCK) && module_refcount(sref->mod) != 0) { | 678 | if (module_refcount(sref->mod) != 0) { |
644 | if (!(*sref->forced = try_force_unload(sref->flags))) | 679 | if (!(*sref->forced = try_force_unload(sref->flags))) |
645 | return -EWOULDBLOCK; | 680 | return -EWOULDBLOCK; |
646 | } | 681 | } |
@@ -652,9 +687,16 @@ static int __try_stop_module(void *_sref) | |||
652 | 687 | ||
653 | static int try_stop_module(struct module *mod, int flags, int *forced) | 688 | static int try_stop_module(struct module *mod, int flags, int *forced) |
654 | { | 689 | { |
655 | struct stopref sref = { mod, flags, forced }; | 690 | if (flags & O_NONBLOCK) { |
691 | struct stopref sref = { mod, flags, forced }; | ||
656 | 692 | ||
657 | return stop_machine_run(__try_stop_module, &sref, NR_CPUS); | 693 | return stop_machine_run(__try_stop_module, &sref, NR_CPUS); |
694 | } else { | ||
695 | /* We don't need to stop the machine for this. */ | ||
696 | mod->state = MODULE_STATE_GOING; | ||
697 | synchronize_sched(); | ||
698 | return 0; | ||
699 | } | ||
658 | } | 700 | } |
659 | 701 | ||
660 | unsigned int module_refcount(struct module *mod) | 702 | unsigned int module_refcount(struct module *mod) |
@@ -1445,8 +1487,10 @@ static int verify_export_symbols(struct module *mod) | |||
1445 | { mod->syms, mod->num_syms }, | 1487 | { mod->syms, mod->num_syms }, |
1446 | { mod->gpl_syms, mod->num_gpl_syms }, | 1488 | { mod->gpl_syms, mod->num_gpl_syms }, |
1447 | { mod->gpl_future_syms, mod->num_gpl_future_syms }, | 1489 | { mod->gpl_future_syms, mod->num_gpl_future_syms }, |
1490 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
1448 | { mod->unused_syms, mod->num_unused_syms }, | 1491 | { mod->unused_syms, mod->num_unused_syms }, |
1449 | { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, | 1492 | { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, |
1493 | #endif | ||
1450 | }; | 1494 | }; |
1451 | 1495 | ||
1452 | for (i = 0; i < ARRAY_SIZE(arr); i++) { | 1496 | for (i = 0; i < ARRAY_SIZE(arr); i++) { |
@@ -1526,7 +1570,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
1526 | } | 1570 | } |
1527 | 1571 | ||
1528 | /* Update size with this section: return offset. */ | 1572 | /* Update size with this section: return offset. */ |
1529 | static long get_offset(unsigned long *size, Elf_Shdr *sechdr) | 1573 | static long get_offset(unsigned int *size, Elf_Shdr *sechdr) |
1530 | { | 1574 | { |
1531 | long ret; | 1575 | long ret; |
1532 | 1576 | ||
@@ -1738,6 +1782,20 @@ static inline void add_kallsyms(struct module *mod, | |||
1738 | } | 1782 | } |
1739 | #endif /* CONFIG_KALLSYMS */ | 1783 | #endif /* CONFIG_KALLSYMS */ |
1740 | 1784 | ||
1785 | static void *module_alloc_update_bounds(unsigned long size) | ||
1786 | { | ||
1787 | void *ret = module_alloc(size); | ||
1788 | |||
1789 | if (ret) { | ||
1790 | /* Update module bounds. */ | ||
1791 | if ((unsigned long)ret < module_addr_min) | ||
1792 | module_addr_min = (unsigned long)ret; | ||
1793 | if ((unsigned long)ret + size > module_addr_max) | ||
1794 | module_addr_max = (unsigned long)ret + size; | ||
1795 | } | ||
1796 | return ret; | ||
1797 | } | ||
1798 | |||
1741 | /* Allocate and load the module: note that size of section 0 is always | 1799 | /* Allocate and load the module: note that size of section 0 is always |
1742 | zero, and we rely on this for optional sections. */ | 1800 | zero, and we rely on this for optional sections. */ |
1743 | static struct module *load_module(void __user *umod, | 1801 | static struct module *load_module(void __user *umod, |
@@ -1764,10 +1822,12 @@ static struct module *load_module(void __user *umod, | |||
1764 | unsigned int gplfutureindex; | 1822 | unsigned int gplfutureindex; |
1765 | unsigned int gplfuturecrcindex; | 1823 | unsigned int gplfuturecrcindex; |
1766 | unsigned int unwindex = 0; | 1824 | unsigned int unwindex = 0; |
1825 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
1767 | unsigned int unusedindex; | 1826 | unsigned int unusedindex; |
1768 | unsigned int unusedcrcindex; | 1827 | unsigned int unusedcrcindex; |
1769 | unsigned int unusedgplindex; | 1828 | unsigned int unusedgplindex; |
1770 | unsigned int unusedgplcrcindex; | 1829 | unsigned int unusedgplcrcindex; |
1830 | #endif | ||
1771 | unsigned int markersindex; | 1831 | unsigned int markersindex; |
1772 | unsigned int markersstringsindex; | 1832 | unsigned int markersstringsindex; |
1773 | struct module *mod; | 1833 | struct module *mod; |
@@ -1850,13 +1910,15 @@ static struct module *load_module(void __user *umod, | |||
1850 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); | 1910 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); |
1851 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); | 1911 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); |
1852 | gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); | 1912 | gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); |
1853 | unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused"); | ||
1854 | unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl"); | ||
1855 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); | 1913 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); |
1856 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | 1914 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); |
1857 | gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); | 1915 | gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); |
1916 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
1917 | unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused"); | ||
1918 | unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl"); | ||
1858 | unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused"); | 1919 | unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused"); |
1859 | unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl"); | 1920 | unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl"); |
1921 | #endif | ||
1860 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); | 1922 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); |
1861 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); | 1923 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); |
1862 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); | 1924 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); |
@@ -1935,7 +1997,7 @@ static struct module *load_module(void __user *umod, | |||
1935 | layout_sections(mod, hdr, sechdrs, secstrings); | 1997 | layout_sections(mod, hdr, sechdrs, secstrings); |
1936 | 1998 | ||
1937 | /* Do the allocs. */ | 1999 | /* Do the allocs. */ |
1938 | ptr = module_alloc(mod->core_size); | 2000 | ptr = module_alloc_update_bounds(mod->core_size); |
1939 | if (!ptr) { | 2001 | if (!ptr) { |
1940 | err = -ENOMEM; | 2002 | err = -ENOMEM; |
1941 | goto free_percpu; | 2003 | goto free_percpu; |
@@ -1943,7 +2005,7 @@ static struct module *load_module(void __user *umod, | |||
1943 | memset(ptr, 0, mod->core_size); | 2005 | memset(ptr, 0, mod->core_size); |
1944 | mod->module_core = ptr; | 2006 | mod->module_core = ptr; |
1945 | 2007 | ||
1946 | ptr = module_alloc(mod->init_size); | 2008 | ptr = module_alloc_update_bounds(mod->init_size); |
1947 | if (!ptr && mod->init_size) { | 2009 | if (!ptr && mod->init_size) { |
1948 | err = -ENOMEM; | 2010 | err = -ENOMEM; |
1949 | goto free_core; | 2011 | goto free_core; |
@@ -2018,14 +2080,15 @@ static struct module *load_module(void __user *umod, | |||
2018 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; | 2080 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; |
2019 | mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / | 2081 | mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / |
2020 | sizeof(*mod->gpl_future_syms); | 2082 | sizeof(*mod->gpl_future_syms); |
2021 | mod->num_unused_syms = sechdrs[unusedindex].sh_size / | ||
2022 | sizeof(*mod->unused_syms); | ||
2023 | mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size / | ||
2024 | sizeof(*mod->unused_gpl_syms); | ||
2025 | mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; | 2083 | mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; |
2026 | if (gplfuturecrcindex) | 2084 | if (gplfuturecrcindex) |
2027 | mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; | 2085 | mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; |
2028 | 2086 | ||
2087 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
2088 | mod->num_unused_syms = sechdrs[unusedindex].sh_size / | ||
2089 | sizeof(*mod->unused_syms); | ||
2090 | mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size / | ||
2091 | sizeof(*mod->unused_gpl_syms); | ||
2029 | mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; | 2092 | mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; |
2030 | if (unusedcrcindex) | 2093 | if (unusedcrcindex) |
2031 | mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; | 2094 | mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; |
@@ -2033,13 +2096,17 @@ static struct module *load_module(void __user *umod, | |||
2033 | if (unusedgplcrcindex) | 2096 | if (unusedgplcrcindex) |
2034 | mod->unused_gpl_crcs | 2097 | mod->unused_gpl_crcs |
2035 | = (void *)sechdrs[unusedgplcrcindex].sh_addr; | 2098 | = (void *)sechdrs[unusedgplcrcindex].sh_addr; |
2099 | #endif | ||
2036 | 2100 | ||
2037 | #ifdef CONFIG_MODVERSIONS | 2101 | #ifdef CONFIG_MODVERSIONS |
2038 | if ((mod->num_syms && !crcindex) || | 2102 | if ((mod->num_syms && !crcindex) |
2039 | (mod->num_gpl_syms && !gplcrcindex) || | 2103 | || (mod->num_gpl_syms && !gplcrcindex) |
2040 | (mod->num_gpl_future_syms && !gplfuturecrcindex) || | 2104 | || (mod->num_gpl_future_syms && !gplfuturecrcindex) |
2041 | (mod->num_unused_syms && !unusedcrcindex) || | 2105 | #ifdef CONFIG_UNUSED_SYMBOLS |
2042 | (mod->num_unused_gpl_syms && !unusedgplcrcindex)) { | 2106 | || (mod->num_unused_syms && !unusedcrcindex) |
2107 | || (mod->num_unused_gpl_syms && !unusedgplcrcindex) | ||
2108 | #endif | ||
2109 | ) { | ||
2043 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); | 2110 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); |
2044 | err = try_to_force_load(mod, "nocrc"); | 2111 | err = try_to_force_load(mod, "nocrc"); |
2045 | if (err) | 2112 | if (err) |
@@ -2512,7 +2579,7 @@ static int m_show(struct seq_file *m, void *p) | |||
2512 | struct module *mod = list_entry(p, struct module, list); | 2579 | struct module *mod = list_entry(p, struct module, list); |
2513 | char buf[8]; | 2580 | char buf[8]; |
2514 | 2581 | ||
2515 | seq_printf(m, "%s %lu", | 2582 | seq_printf(m, "%s %u", |
2516 | mod->name, mod->init_size + mod->core_size); | 2583 | mod->name, mod->init_size + mod->core_size); |
2517 | print_unload_info(m, mod); | 2584 | print_unload_info(m, mod); |
2518 | 2585 | ||
@@ -2595,6 +2662,9 @@ struct module *__module_text_address(unsigned long addr) | |||
2595 | { | 2662 | { |
2596 | struct module *mod; | 2663 | struct module *mod; |
2597 | 2664 | ||
2665 | if (addr < module_addr_min || addr > module_addr_max) | ||
2666 | return NULL; | ||
2667 | |||
2598 | list_for_each_entry(mod, &modules, list) | 2668 | list_for_each_entry(mod, &modules, list) |
2599 | if (within(addr, mod->module_init, mod->init_text_size) | 2669 | if (within(addr, mod->module_init, mod->init_text_size) |
2600 | || within(addr, mod->module_core, mod->core_text_size)) | 2670 | || within(addr, mod->module_core, mod->core_text_size)) |
diff --git a/kernel/ns_cgroup.c b/kernel/ns_cgroup.c index 48d7ed6fc3a4..43c2111cd54d 100644 --- a/kernel/ns_cgroup.c +++ b/kernel/ns_cgroup.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
8 | #include <linux/cgroup.h> | 8 | #include <linux/cgroup.h> |
9 | #include <linux/fs.h> | 9 | #include <linux/fs.h> |
10 | #include <linux/proc_fs.h> | ||
10 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
11 | #include <linux/nsproxy.h> | 12 | #include <linux/nsproxy.h> |
12 | 13 | ||
@@ -24,9 +25,12 @@ static inline struct ns_cgroup *cgroup_to_ns( | |||
24 | struct ns_cgroup, css); | 25 | struct ns_cgroup, css); |
25 | } | 26 | } |
26 | 27 | ||
27 | int ns_cgroup_clone(struct task_struct *task) | 28 | int ns_cgroup_clone(struct task_struct *task, struct pid *pid) |
28 | { | 29 | { |
29 | return cgroup_clone(task, &ns_subsys); | 30 | char name[PROC_NUMBUF]; |
31 | |||
32 | snprintf(name, PROC_NUMBUF, "%d", pid_vnr(pid)); | ||
33 | return cgroup_clone(task, &ns_subsys, name); | ||
30 | } | 34 | } |
31 | 35 | ||
32 | /* | 36 | /* |
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index adc785146a1c..21575fc46d05 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c | |||
@@ -157,12 +157,6 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk) | |||
157 | goto out; | 157 | goto out; |
158 | } | 158 | } |
159 | 159 | ||
160 | err = ns_cgroup_clone(tsk); | ||
161 | if (err) { | ||
162 | put_nsproxy(new_ns); | ||
163 | goto out; | ||
164 | } | ||
165 | |||
166 | tsk->nsproxy = new_ns; | 160 | tsk->nsproxy = new_ns; |
167 | 161 | ||
168 | out: | 162 | out: |
@@ -209,7 +203,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags, | |||
209 | goto out; | 203 | goto out; |
210 | } | 204 | } |
211 | 205 | ||
212 | err = ns_cgroup_clone(current); | 206 | err = ns_cgroup_clone(current, task_pid(current)); |
213 | if (err) | 207 | if (err) |
214 | put_nsproxy(*new_nsp); | 208 | put_nsproxy(*new_nsp); |
215 | 209 | ||
diff --git a/kernel/panic.c b/kernel/panic.c index 425567f45b9f..12c5a0a6c89b 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
@@ -318,6 +318,28 @@ void warn_on_slowpath(const char *file, int line) | |||
318 | add_taint(TAINT_WARN); | 318 | add_taint(TAINT_WARN); |
319 | } | 319 | } |
320 | EXPORT_SYMBOL(warn_on_slowpath); | 320 | EXPORT_SYMBOL(warn_on_slowpath); |
321 | |||
322 | |||
323 | void warn_slowpath(const char *file, int line, const char *fmt, ...) | ||
324 | { | ||
325 | va_list args; | ||
326 | char function[KSYM_SYMBOL_LEN]; | ||
327 | unsigned long caller = (unsigned long)__builtin_return_address(0); | ||
328 | sprint_symbol(function, caller); | ||
329 | |||
330 | printk(KERN_WARNING "------------[ cut here ]------------\n"); | ||
331 | printk(KERN_WARNING "WARNING: at %s:%d %s()\n", file, | ||
332 | line, function); | ||
333 | va_start(args, fmt); | ||
334 | vprintk(fmt, args); | ||
335 | va_end(args); | ||
336 | |||
337 | print_modules(); | ||
338 | dump_stack(); | ||
339 | print_oops_end_marker(); | ||
340 | add_taint(TAINT_WARN); | ||
341 | } | ||
342 | EXPORT_SYMBOL(warn_slowpath); | ||
321 | #endif | 343 | #endif |
322 | 344 | ||
323 | #ifdef CONFIG_CC_STACKPROTECTOR | 345 | #ifdef CONFIG_CC_STACKPROTECTOR |
diff --git a/kernel/pid.c b/kernel/pid.c index 30bd5d4b2ac7..064e76afa507 100644 --- a/kernel/pid.c +++ b/kernel/pid.c | |||
@@ -309,12 +309,6 @@ struct pid *find_vpid(int nr) | |||
309 | } | 309 | } |
310 | EXPORT_SYMBOL_GPL(find_vpid); | 310 | EXPORT_SYMBOL_GPL(find_vpid); |
311 | 311 | ||
312 | struct pid *find_pid(int nr) | ||
313 | { | ||
314 | return find_pid_ns(nr, &init_pid_ns); | ||
315 | } | ||
316 | EXPORT_SYMBOL_GPL(find_pid); | ||
317 | |||
318 | /* | 312 | /* |
319 | * attach_pid() must be called with the tasklist_lock write-held. | 313 | * attach_pid() must be called with the tasklist_lock write-held. |
320 | */ | 314 | */ |
@@ -435,6 +429,7 @@ struct pid *find_get_pid(pid_t nr) | |||
435 | 429 | ||
436 | return pid; | 430 | return pid; |
437 | } | 431 | } |
432 | EXPORT_SYMBOL_GPL(find_get_pid); | ||
438 | 433 | ||
439 | pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns) | 434 | pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns) |
440 | { | 435 | { |
@@ -482,7 +477,7 @@ EXPORT_SYMBOL(task_session_nr_ns); | |||
482 | /* | 477 | /* |
483 | * Used by proc to find the first pid that is greater then or equal to nr. | 478 | * Used by proc to find the first pid that is greater then or equal to nr. |
484 | * | 479 | * |
485 | * If there is a pid at nr this function is exactly the same as find_pid. | 480 | * If there is a pid at nr this function is exactly the same as find_pid_ns. |
486 | */ | 481 | */ |
487 | struct pid *find_ge_pid(int nr, struct pid_namespace *ns) | 482 | struct pid *find_ge_pid(int nr, struct pid_namespace *ns) |
488 | { | 483 | { |
@@ -497,7 +492,6 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns) | |||
497 | 492 | ||
498 | return pid; | 493 | return pid; |
499 | } | 494 | } |
500 | EXPORT_SYMBOL_GPL(find_get_pid); | ||
501 | 495 | ||
502 | /* | 496 | /* |
503 | * The pid hash table is scaled according to the amount of memory in the | 497 | * The pid hash table is scaled according to the amount of memory in the |
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 98702b4b8851..ea567b78d1aa 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/pid_namespace.h> | 12 | #include <linux/pid_namespace.h> |
13 | #include <linux/syscalls.h> | 13 | #include <linux/syscalls.h> |
14 | #include <linux/err.h> | 14 | #include <linux/err.h> |
15 | #include <linux/acct.h> | ||
15 | 16 | ||
16 | #define BITS_PER_PAGE (PAGE_SIZE*8) | 17 | #define BITS_PER_PAGE (PAGE_SIZE*8) |
17 | 18 | ||
@@ -71,7 +72,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level) | |||
71 | struct pid_namespace *ns; | 72 | struct pid_namespace *ns; |
72 | int i; | 73 | int i; |
73 | 74 | ||
74 | ns = kmem_cache_alloc(pid_ns_cachep, GFP_KERNEL); | 75 | ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL); |
75 | if (ns == NULL) | 76 | if (ns == NULL) |
76 | goto out; | 77 | goto out; |
77 | 78 | ||
@@ -84,17 +85,13 @@ static struct pid_namespace *create_pid_namespace(unsigned int level) | |||
84 | goto out_free_map; | 85 | goto out_free_map; |
85 | 86 | ||
86 | kref_init(&ns->kref); | 87 | kref_init(&ns->kref); |
87 | ns->last_pid = 0; | ||
88 | ns->child_reaper = NULL; | ||
89 | ns->level = level; | 88 | ns->level = level; |
90 | 89 | ||
91 | set_bit(0, ns->pidmap[0].page); | 90 | set_bit(0, ns->pidmap[0].page); |
92 | atomic_set(&ns->pidmap[0].nr_free, BITS_PER_PAGE - 1); | 91 | atomic_set(&ns->pidmap[0].nr_free, BITS_PER_PAGE - 1); |
93 | 92 | ||
94 | for (i = 1; i < PIDMAP_ENTRIES; i++) { | 93 | for (i = 1; i < PIDMAP_ENTRIES; i++) |
95 | ns->pidmap[i].page = NULL; | ||
96 | atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE); | 94 | atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE); |
97 | } | ||
98 | 95 | ||
99 | return ns; | 96 | return ns; |
100 | 97 | ||
@@ -185,6 +182,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) | |||
185 | 182 | ||
186 | /* Child reaper for the pid namespace is going away */ | 183 | /* Child reaper for the pid namespace is going away */ |
187 | pid_ns->child_reaper = NULL; | 184 | pid_ns->child_reaper = NULL; |
185 | acct_exit_ns(pid_ns); | ||
188 | return; | 186 | return; |
189 | } | 187 | } |
190 | 188 | ||
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index dbd8398ddb0b..9a21681aa80f 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c | |||
@@ -449,9 +449,6 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set) | |||
449 | spin_unlock_irqrestore(&idr_lock, flags); | 449 | spin_unlock_irqrestore(&idr_lock, flags); |
450 | } | 450 | } |
451 | sigqueue_free(tmr->sigq); | 451 | sigqueue_free(tmr->sigq); |
452 | if (unlikely(tmr->it_process) && | ||
453 | tmr->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) | ||
454 | put_task_struct(tmr->it_process); | ||
455 | kmem_cache_free(posix_timers_cache, tmr); | 452 | kmem_cache_free(posix_timers_cache, tmr); |
456 | } | 453 | } |
457 | 454 | ||
@@ -856,11 +853,10 @@ retry_delete: | |||
856 | * This keeps any tasks waiting on the spin lock from thinking | 853 | * This keeps any tasks waiting on the spin lock from thinking |
857 | * they got something (see the lock code above). | 854 | * they got something (see the lock code above). |
858 | */ | 855 | */ |
859 | if (timer->it_process) { | 856 | if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) |
860 | if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) | 857 | put_task_struct(timer->it_process); |
861 | put_task_struct(timer->it_process); | 858 | timer->it_process = NULL; |
862 | timer->it_process = NULL; | 859 | |
863 | } | ||
864 | unlock_timer(timer, flags); | 860 | unlock_timer(timer, flags); |
865 | release_posix_timer(timer, IT_ID_SET); | 861 | release_posix_timer(timer, IT_ID_SET); |
866 | return 0; | 862 | return 0; |
@@ -885,11 +881,10 @@ retry_delete: | |||
885 | * This keeps any tasks waiting on the spin lock from thinking | 881 | * This keeps any tasks waiting on the spin lock from thinking |
886 | * they got something (see the lock code above). | 882 | * they got something (see the lock code above). |
887 | */ | 883 | */ |
888 | if (timer->it_process) { | 884 | if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) |
889 | if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) | 885 | put_task_struct(timer->it_process); |
890 | put_task_struct(timer->it_process); | 886 | timer->it_process = NULL; |
891 | timer->it_process = NULL; | 887 | |
892 | } | ||
893 | unlock_timer(timer, flags); | 888 | unlock_timer(timer, flags); |
894 | release_posix_timer(timer, IT_ID_SET); | 889 | release_posix_timer(timer, IT_ID_SET); |
895 | } | 890 | } |
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index 59dfdf1e1d20..dcd165f92a88 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig | |||
@@ -94,6 +94,17 @@ config SUSPEND | |||
94 | powered and thus its contents are preserved, such as the | 94 | powered and thus its contents are preserved, such as the |
95 | suspend-to-RAM state (e.g. the ACPI S3 state). | 95 | suspend-to-RAM state (e.g. the ACPI S3 state). |
96 | 96 | ||
97 | config PM_TEST_SUSPEND | ||
98 | bool "Test suspend/resume and wakealarm during bootup" | ||
99 | depends on SUSPEND && PM_DEBUG && RTC_LIB=y | ||
100 | ---help--- | ||
101 | This option will let you suspend your machine during bootup, and | ||
102 | make it wake up a few seconds later using an RTC wakeup alarm. | ||
103 | Enable this with a kernel parameter like "test_suspend=mem". | ||
104 | |||
105 | You probably want to have your system's RTC driver statically | ||
106 | linked, ensuring that it's available when this test runs. | ||
107 | |||
97 | config SUSPEND_FREEZER | 108 | config SUSPEND_FREEZER |
98 | bool "Enable freezer for suspend to RAM/standby" \ | 109 | bool "Enable freezer for suspend to RAM/standby" \ |
99 | if ARCH_WANTS_FREEZER_CONTROL || BROKEN | 110 | if ARCH_WANTS_FREEZER_CONTROL || BROKEN |
diff --git a/kernel/power/main.c b/kernel/power/main.c index 3398f4651aa1..95bff23ecdaa 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c | |||
@@ -132,6 +132,61 @@ static inline int suspend_test(int level) { return 0; } | |||
132 | 132 | ||
133 | #ifdef CONFIG_SUSPEND | 133 | #ifdef CONFIG_SUSPEND |
134 | 134 | ||
135 | #ifdef CONFIG_PM_TEST_SUSPEND | ||
136 | |||
137 | /* | ||
138 | * We test the system suspend code by setting an RTC wakealarm a short | ||
139 | * time in the future, then suspending. Suspending the devices won't | ||
140 | * normally take long ... some systems only need a few milliseconds. | ||
141 | * | ||
142 | * The time it takes is system-specific though, so when we test this | ||
143 | * during system bootup we allow a LOT of time. | ||
144 | */ | ||
145 | #define TEST_SUSPEND_SECONDS 5 | ||
146 | |||
147 | static unsigned long suspend_test_start_time; | ||
148 | |||
149 | static void suspend_test_start(void) | ||
150 | { | ||
151 | /* FIXME Use better timebase than "jiffies", ideally a clocksource. | ||
152 | * What we want is a hardware counter that will work correctly even | ||
153 | * during the irqs-are-off stages of the suspend/resume cycle... | ||
154 | */ | ||
155 | suspend_test_start_time = jiffies; | ||
156 | } | ||
157 | |||
158 | static void suspend_test_finish(const char *label) | ||
159 | { | ||
160 | long nj = jiffies - suspend_test_start_time; | ||
161 | unsigned msec; | ||
162 | |||
163 | msec = jiffies_to_msecs(abs(nj)); | ||
164 | pr_info("PM: %s took %d.%03d seconds\n", label, | ||
165 | msec / 1000, msec % 1000); | ||
166 | |||
167 | /* Warning on suspend means the RTC alarm period needs to be | ||
168 | * larger -- the system was sooo slooowwww to suspend that the | ||
169 | * alarm (should have) fired before the system went to sleep! | ||
170 | * | ||
171 | * Warning on either suspend or resume also means the system | ||
172 | * has some performance issues. The stack dump of a WARN_ON | ||
173 | * is more likely to get the right attention than a printk... | ||
174 | */ | ||
175 | WARN_ON(msec > (TEST_SUSPEND_SECONDS * 1000)); | ||
176 | } | ||
177 | |||
178 | #else | ||
179 | |||
180 | static void suspend_test_start(void) | ||
181 | { | ||
182 | } | ||
183 | |||
184 | static void suspend_test_finish(const char *label) | ||
185 | { | ||
186 | } | ||
187 | |||
188 | #endif | ||
189 | |||
135 | /* This is just an arbitrary number */ | 190 | /* This is just an arbitrary number */ |
136 | #define FREE_PAGE_NUMBER (100) | 191 | #define FREE_PAGE_NUMBER (100) |
137 | 192 | ||
@@ -266,12 +321,13 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
266 | goto Close; | 321 | goto Close; |
267 | } | 322 | } |
268 | suspend_console(); | 323 | suspend_console(); |
324 | suspend_test_start(); | ||
269 | error = device_suspend(PMSG_SUSPEND); | 325 | error = device_suspend(PMSG_SUSPEND); |
270 | if (error) { | 326 | if (error) { |
271 | printk(KERN_ERR "PM: Some devices failed to suspend\n"); | 327 | printk(KERN_ERR "PM: Some devices failed to suspend\n"); |
272 | goto Recover_platform; | 328 | goto Recover_platform; |
273 | } | 329 | } |
274 | 330 | suspend_test_finish("suspend devices"); | |
275 | if (suspend_test(TEST_DEVICES)) | 331 | if (suspend_test(TEST_DEVICES)) |
276 | goto Recover_platform; | 332 | goto Recover_platform; |
277 | 333 | ||
@@ -293,7 +349,9 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
293 | if (suspend_ops->finish) | 349 | if (suspend_ops->finish) |
294 | suspend_ops->finish(); | 350 | suspend_ops->finish(); |
295 | Resume_devices: | 351 | Resume_devices: |
352 | suspend_test_start(); | ||
296 | device_resume(PMSG_RESUME); | 353 | device_resume(PMSG_RESUME); |
354 | suspend_test_finish("resume devices"); | ||
297 | resume_console(); | 355 | resume_console(); |
298 | Close: | 356 | Close: |
299 | if (suspend_ops->end) | 357 | if (suspend_ops->end) |
@@ -521,3 +579,137 @@ static int __init pm_init(void) | |||
521 | } | 579 | } |
522 | 580 | ||
523 | core_initcall(pm_init); | 581 | core_initcall(pm_init); |
582 | |||
583 | |||
584 | #ifdef CONFIG_PM_TEST_SUSPEND | ||
585 | |||
586 | #include <linux/rtc.h> | ||
587 | |||
588 | /* | ||
589 | * To test system suspend, we need a hands-off mechanism to resume the | ||
590 | * system. RTCs wake alarms are a common self-contained mechanism. | ||
591 | */ | ||
592 | |||
593 | static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state) | ||
594 | { | ||
595 | static char err_readtime[] __initdata = | ||
596 | KERN_ERR "PM: can't read %s time, err %d\n"; | ||
597 | static char err_wakealarm [] __initdata = | ||
598 | KERN_ERR "PM: can't set %s wakealarm, err %d\n"; | ||
599 | static char err_suspend[] __initdata = | ||
600 | KERN_ERR "PM: suspend test failed, error %d\n"; | ||
601 | static char info_test[] __initdata = | ||
602 | KERN_INFO "PM: test RTC wakeup from '%s' suspend\n"; | ||
603 | |||
604 | unsigned long now; | ||
605 | struct rtc_wkalrm alm; | ||
606 | int status; | ||
607 | |||
608 | /* this may fail if the RTC hasn't been initialized */ | ||
609 | status = rtc_read_time(rtc, &alm.time); | ||
610 | if (status < 0) { | ||
611 | printk(err_readtime, rtc->dev.bus_id, status); | ||
612 | return; | ||
613 | } | ||
614 | rtc_tm_to_time(&alm.time, &now); | ||
615 | |||
616 | memset(&alm, 0, sizeof alm); | ||
617 | rtc_time_to_tm(now + TEST_SUSPEND_SECONDS, &alm.time); | ||
618 | alm.enabled = true; | ||
619 | |||
620 | status = rtc_set_alarm(rtc, &alm); | ||
621 | if (status < 0) { | ||
622 | printk(err_wakealarm, rtc->dev.bus_id, status); | ||
623 | return; | ||
624 | } | ||
625 | |||
626 | if (state == PM_SUSPEND_MEM) { | ||
627 | printk(info_test, pm_states[state]); | ||
628 | status = pm_suspend(state); | ||
629 | if (status == -ENODEV) | ||
630 | state = PM_SUSPEND_STANDBY; | ||
631 | } | ||
632 | if (state == PM_SUSPEND_STANDBY) { | ||
633 | printk(info_test, pm_states[state]); | ||
634 | status = pm_suspend(state); | ||
635 | } | ||
636 | if (status < 0) | ||
637 | printk(err_suspend, status); | ||
638 | } | ||
639 | |||
640 | static int __init has_wakealarm(struct device *dev, void *name_ptr) | ||
641 | { | ||
642 | struct rtc_device *candidate = to_rtc_device(dev); | ||
643 | |||
644 | if (!candidate->ops->set_alarm) | ||
645 | return 0; | ||
646 | if (!device_may_wakeup(candidate->dev.parent)) | ||
647 | return 0; | ||
648 | |||
649 | *(char **)name_ptr = dev->bus_id; | ||
650 | return 1; | ||
651 | } | ||
652 | |||
653 | /* | ||
654 | * Kernel options like "test_suspend=mem" force suspend/resume sanity tests | ||
655 | * at startup time. They're normally disabled, for faster boot and because | ||
656 | * we can't know which states really work on this particular system. | ||
657 | */ | ||
658 | static suspend_state_t test_state __initdata = PM_SUSPEND_ON; | ||
659 | |||
660 | static char warn_bad_state[] __initdata = | ||
661 | KERN_WARNING "PM: can't test '%s' suspend state\n"; | ||
662 | |||
663 | static int __init setup_test_suspend(char *value) | ||
664 | { | ||
665 | unsigned i; | ||
666 | |||
667 | /* "=mem" ==> "mem" */ | ||
668 | value++; | ||
669 | for (i = 0; i < PM_SUSPEND_MAX; i++) { | ||
670 | if (!pm_states[i]) | ||
671 | continue; | ||
672 | if (strcmp(pm_states[i], value) != 0) | ||
673 | continue; | ||
674 | test_state = (__force suspend_state_t) i; | ||
675 | return 0; | ||
676 | } | ||
677 | printk(warn_bad_state, value); | ||
678 | return 0; | ||
679 | } | ||
680 | __setup("test_suspend", setup_test_suspend); | ||
681 | |||
682 | static int __init test_suspend(void) | ||
683 | { | ||
684 | static char warn_no_rtc[] __initdata = | ||
685 | KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n"; | ||
686 | |||
687 | char *pony = NULL; | ||
688 | struct rtc_device *rtc = NULL; | ||
689 | |||
690 | /* PM is initialized by now; is that state testable? */ | ||
691 | if (test_state == PM_SUSPEND_ON) | ||
692 | goto done; | ||
693 | if (!valid_state(test_state)) { | ||
694 | printk(warn_bad_state, pm_states[test_state]); | ||
695 | goto done; | ||
696 | } | ||
697 | |||
698 | /* RTCs have initialized by now too ... can we use one? */ | ||
699 | class_find_device(rtc_class, NULL, &pony, has_wakealarm); | ||
700 | if (pony) | ||
701 | rtc = rtc_class_open(pony); | ||
702 | if (!rtc) { | ||
703 | printk(warn_no_rtc); | ||
704 | goto done; | ||
705 | } | ||
706 | |||
707 | /* go for it */ | ||
708 | test_wakealarm(rtc, test_state); | ||
709 | rtc_class_close(rtc); | ||
710 | done: | ||
711 | return 0; | ||
712 | } | ||
713 | late_initcall(test_suspend); | ||
714 | |||
715 | #endif /* CONFIG_PM_TEST_SUSPEND */ | ||
diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c index 678ec736076b..72016f051477 100644 --- a/kernel/power/poweroff.c +++ b/kernel/power/poweroff.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/pm.h> | 10 | #include <linux/pm.h> |
11 | #include <linux/workqueue.h> | 11 | #include <linux/workqueue.h> |
12 | #include <linux/reboot.h> | 12 | #include <linux/reboot.h> |
13 | #include <linux/cpumask.h> | ||
13 | 14 | ||
14 | /* | 15 | /* |
15 | * When the user hits Sys-Rq o to power down the machine this is the | 16 | * When the user hits Sys-Rq o to power down the machine this is the |
@@ -25,7 +26,8 @@ static DECLARE_WORK(poweroff_work, do_poweroff); | |||
25 | 26 | ||
26 | static void handle_poweroff(int key, struct tty_struct *tty) | 27 | static void handle_poweroff(int key, struct tty_struct *tty) |
27 | { | 28 | { |
28 | schedule_work(&poweroff_work); | 29 | /* run sysrq poweroff on boot cpu */ |
30 | schedule_work_on(first_cpu(cpu_online_map), &poweroff_work); | ||
29 | } | 31 | } |
30 | 32 | ||
31 | static struct sysrq_key_op sysrq_poweroff_op = { | 33 | static struct sysrq_key_op sysrq_poweroff_op = { |
diff --git a/kernel/power/process.c b/kernel/power/process.c index 5fb87652f214..278946aecaf0 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c | |||
@@ -149,7 +149,7 @@ static int try_to_freeze_tasks(bool sig_only) | |||
149 | unsigned long end_time; | 149 | unsigned long end_time; |
150 | unsigned int todo; | 150 | unsigned int todo; |
151 | struct timeval start, end; | 151 | struct timeval start, end; |
152 | s64 elapsed_csecs64; | 152 | u64 elapsed_csecs64; |
153 | unsigned int elapsed_csecs; | 153 | unsigned int elapsed_csecs; |
154 | 154 | ||
155 | do_gettimeofday(&start); | 155 | do_gettimeofday(&start); |
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 5f91a07c4eac..5d2ab836e998 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c | |||
@@ -205,8 +205,7 @@ static void chain_free(struct chain_allocator *ca, int clear_page_nosave) | |||
205 | * objects. The main list's elements are of type struct zone_bitmap | 205 | * objects. The main list's elements are of type struct zone_bitmap |
206 | * and each of them corresonds to one zone. For each zone bitmap | 206 | * and each of them corresonds to one zone. For each zone bitmap |
207 | * object there is a list of objects of type struct bm_block that | 207 | * object there is a list of objects of type struct bm_block that |
208 | * represent each blocks of bit chunks in which information is | 208 | * represent each blocks of bitmap in which information is stored. |
209 | * stored. | ||
210 | * | 209 | * |
211 | * struct memory_bitmap contains a pointer to the main list of zone | 210 | * struct memory_bitmap contains a pointer to the main list of zone |
212 | * bitmap objects, a struct bm_position used for browsing the bitmap, | 211 | * bitmap objects, a struct bm_position used for browsing the bitmap, |
@@ -224,26 +223,27 @@ static void chain_free(struct chain_allocator *ca, int clear_page_nosave) | |||
224 | * pfns that correspond to the start and end of the represented zone. | 223 | * pfns that correspond to the start and end of the represented zone. |
225 | * | 224 | * |
226 | * struct bm_block contains a pointer to the memory page in which | 225 | * struct bm_block contains a pointer to the memory page in which |
227 | * information is stored (in the form of a block of bit chunks | 226 | * information is stored (in the form of a block of bitmap) |
228 | * of type unsigned long each). It also contains the pfns that | 227 | * It also contains the pfns that correspond to the start and end of |
229 | * correspond to the start and end of the represented memory area and | 228 | * the represented memory area. |
230 | * the number of bit chunks in the block. | ||
231 | */ | 229 | */ |
232 | 230 | ||
233 | #define BM_END_OF_MAP (~0UL) | 231 | #define BM_END_OF_MAP (~0UL) |
234 | 232 | ||
235 | #define BM_CHUNKS_PER_BLOCK (PAGE_SIZE / sizeof(long)) | ||
236 | #define BM_BITS_PER_CHUNK (sizeof(long) << 3) | ||
237 | #define BM_BITS_PER_BLOCK (PAGE_SIZE << 3) | 233 | #define BM_BITS_PER_BLOCK (PAGE_SIZE << 3) |
238 | 234 | ||
239 | struct bm_block { | 235 | struct bm_block { |
240 | struct bm_block *next; /* next element of the list */ | 236 | struct bm_block *next; /* next element of the list */ |
241 | unsigned long start_pfn; /* pfn represented by the first bit */ | 237 | unsigned long start_pfn; /* pfn represented by the first bit */ |
242 | unsigned long end_pfn; /* pfn represented by the last bit plus 1 */ | 238 | unsigned long end_pfn; /* pfn represented by the last bit plus 1 */ |
243 | unsigned int size; /* number of bit chunks */ | 239 | unsigned long *data; /* bitmap representing pages */ |
244 | unsigned long *data; /* chunks of bits representing pages */ | ||
245 | }; | 240 | }; |
246 | 241 | ||
242 | static inline unsigned long bm_block_bits(struct bm_block *bb) | ||
243 | { | ||
244 | return bb->end_pfn - bb->start_pfn; | ||
245 | } | ||
246 | |||
247 | struct zone_bitmap { | 247 | struct zone_bitmap { |
248 | struct zone_bitmap *next; /* next element of the list */ | 248 | struct zone_bitmap *next; /* next element of the list */ |
249 | unsigned long start_pfn; /* minimal pfn in this zone */ | 249 | unsigned long start_pfn; /* minimal pfn in this zone */ |
@@ -257,7 +257,6 @@ struct zone_bitmap { | |||
257 | struct bm_position { | 257 | struct bm_position { |
258 | struct zone_bitmap *zone_bm; | 258 | struct zone_bitmap *zone_bm; |
259 | struct bm_block *block; | 259 | struct bm_block *block; |
260 | int chunk; | ||
261 | int bit; | 260 | int bit; |
262 | }; | 261 | }; |
263 | 262 | ||
@@ -272,12 +271,6 @@ struct memory_bitmap { | |||
272 | 271 | ||
273 | /* Functions that operate on memory bitmaps */ | 272 | /* Functions that operate on memory bitmaps */ |
274 | 273 | ||
275 | static inline void memory_bm_reset_chunk(struct memory_bitmap *bm) | ||
276 | { | ||
277 | bm->cur.chunk = 0; | ||
278 | bm->cur.bit = -1; | ||
279 | } | ||
280 | |||
281 | static void memory_bm_position_reset(struct memory_bitmap *bm) | 274 | static void memory_bm_position_reset(struct memory_bitmap *bm) |
282 | { | 275 | { |
283 | struct zone_bitmap *zone_bm; | 276 | struct zone_bitmap *zone_bm; |
@@ -285,7 +278,7 @@ static void memory_bm_position_reset(struct memory_bitmap *bm) | |||
285 | zone_bm = bm->zone_bm_list; | 278 | zone_bm = bm->zone_bm_list; |
286 | bm->cur.zone_bm = zone_bm; | 279 | bm->cur.zone_bm = zone_bm; |
287 | bm->cur.block = zone_bm->bm_blocks; | 280 | bm->cur.block = zone_bm->bm_blocks; |
288 | memory_bm_reset_chunk(bm); | 281 | bm->cur.bit = 0; |
289 | } | 282 | } |
290 | 283 | ||
291 | static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free); | 284 | static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free); |
@@ -394,12 +387,10 @@ memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask, int safe_needed) | |||
394 | bb->start_pfn = pfn; | 387 | bb->start_pfn = pfn; |
395 | if (nr >= BM_BITS_PER_BLOCK) { | 388 | if (nr >= BM_BITS_PER_BLOCK) { |
396 | pfn += BM_BITS_PER_BLOCK; | 389 | pfn += BM_BITS_PER_BLOCK; |
397 | bb->size = BM_CHUNKS_PER_BLOCK; | ||
398 | nr -= BM_BITS_PER_BLOCK; | 390 | nr -= BM_BITS_PER_BLOCK; |
399 | } else { | 391 | } else { |
400 | /* This is executed only once in the loop */ | 392 | /* This is executed only once in the loop */ |
401 | pfn += nr; | 393 | pfn += nr; |
402 | bb->size = DIV_ROUND_UP(nr, BM_BITS_PER_CHUNK); | ||
403 | } | 394 | } |
404 | bb->end_pfn = pfn; | 395 | bb->end_pfn = pfn; |
405 | bb = bb->next; | 396 | bb = bb->next; |
@@ -478,8 +469,8 @@ static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn, | |||
478 | } | 469 | } |
479 | zone_bm->cur_block = bb; | 470 | zone_bm->cur_block = bb; |
480 | pfn -= bb->start_pfn; | 471 | pfn -= bb->start_pfn; |
481 | *bit_nr = pfn % BM_BITS_PER_CHUNK; | 472 | *bit_nr = pfn; |
482 | *addr = bb->data + pfn / BM_BITS_PER_CHUNK; | 473 | *addr = bb->data; |
483 | return 0; | 474 | return 0; |
484 | } | 475 | } |
485 | 476 | ||
@@ -528,36 +519,6 @@ static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn) | |||
528 | return test_bit(bit, addr); | 519 | return test_bit(bit, addr); |
529 | } | 520 | } |
530 | 521 | ||
531 | /* Two auxiliary functions for memory_bm_next_pfn */ | ||
532 | |||
533 | /* Find the first set bit in the given chunk, if there is one */ | ||
534 | |||
535 | static inline int next_bit_in_chunk(int bit, unsigned long *chunk_p) | ||
536 | { | ||
537 | bit++; | ||
538 | while (bit < BM_BITS_PER_CHUNK) { | ||
539 | if (test_bit(bit, chunk_p)) | ||
540 | return bit; | ||
541 | |||
542 | bit++; | ||
543 | } | ||
544 | return -1; | ||
545 | } | ||
546 | |||
547 | /* Find a chunk containing some bits set in given block of bits */ | ||
548 | |||
549 | static inline int next_chunk_in_block(int n, struct bm_block *bb) | ||
550 | { | ||
551 | n++; | ||
552 | while (n < bb->size) { | ||
553 | if (bb->data[n]) | ||
554 | return n; | ||
555 | |||
556 | n++; | ||
557 | } | ||
558 | return -1; | ||
559 | } | ||
560 | |||
561 | /** | 522 | /** |
562 | * memory_bm_next_pfn - find the pfn that corresponds to the next set bit | 523 | * memory_bm_next_pfn - find the pfn that corresponds to the next set bit |
563 | * in the bitmap @bm. If the pfn cannot be found, BM_END_OF_MAP is | 524 | * in the bitmap @bm. If the pfn cannot be found, BM_END_OF_MAP is |
@@ -571,40 +532,33 @@ static unsigned long memory_bm_next_pfn(struct memory_bitmap *bm) | |||
571 | { | 532 | { |
572 | struct zone_bitmap *zone_bm; | 533 | struct zone_bitmap *zone_bm; |
573 | struct bm_block *bb; | 534 | struct bm_block *bb; |
574 | int chunk; | ||
575 | int bit; | 535 | int bit; |
576 | 536 | ||
577 | do { | 537 | do { |
578 | bb = bm->cur.block; | 538 | bb = bm->cur.block; |
579 | do { | 539 | do { |
580 | chunk = bm->cur.chunk; | ||
581 | bit = bm->cur.bit; | 540 | bit = bm->cur.bit; |
582 | do { | 541 | bit = find_next_bit(bb->data, bm_block_bits(bb), bit); |
583 | bit = next_bit_in_chunk(bit, bb->data + chunk); | 542 | if (bit < bm_block_bits(bb)) |
584 | if (bit >= 0) | 543 | goto Return_pfn; |
585 | goto Return_pfn; | 544 | |
586 | |||
587 | chunk = next_chunk_in_block(chunk, bb); | ||
588 | bit = -1; | ||
589 | } while (chunk >= 0); | ||
590 | bb = bb->next; | 545 | bb = bb->next; |
591 | bm->cur.block = bb; | 546 | bm->cur.block = bb; |
592 | memory_bm_reset_chunk(bm); | 547 | bm->cur.bit = 0; |
593 | } while (bb); | 548 | } while (bb); |
594 | zone_bm = bm->cur.zone_bm->next; | 549 | zone_bm = bm->cur.zone_bm->next; |
595 | if (zone_bm) { | 550 | if (zone_bm) { |
596 | bm->cur.zone_bm = zone_bm; | 551 | bm->cur.zone_bm = zone_bm; |
597 | bm->cur.block = zone_bm->bm_blocks; | 552 | bm->cur.block = zone_bm->bm_blocks; |
598 | memory_bm_reset_chunk(bm); | 553 | bm->cur.bit = 0; |
599 | } | 554 | } |
600 | } while (zone_bm); | 555 | } while (zone_bm); |
601 | memory_bm_position_reset(bm); | 556 | memory_bm_position_reset(bm); |
602 | return BM_END_OF_MAP; | 557 | return BM_END_OF_MAP; |
603 | 558 | ||
604 | Return_pfn: | 559 | Return_pfn: |
605 | bm->cur.chunk = chunk; | 560 | bm->cur.bit = bit + 1; |
606 | bm->cur.bit = bit; | 561 | return bb->start_pfn + bit; |
607 | return bb->start_pfn + chunk * BM_BITS_PER_CHUNK + bit; | ||
608 | } | 562 | } |
609 | 563 | ||
610 | /** | 564 | /** |
diff --git a/kernel/printk.c b/kernel/printk.c index 07ad9e7f7a66..a7f7559c5f6c 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -933,7 +933,7 @@ void suspend_console(void) | |||
933 | { | 933 | { |
934 | if (!console_suspend_enabled) | 934 | if (!console_suspend_enabled) |
935 | return; | 935 | return; |
936 | printk("Suspending console(s)\n"); | 936 | printk("Suspending console(s) (use no_console_suspend to debug)\n"); |
937 | acquire_console_sem(); | 937 | acquire_console_sem(); |
938 | console_suspended = 1; | 938 | console_suspended = 1; |
939 | } | 939 | } |
@@ -1308,6 +1308,8 @@ void tty_write_message(struct tty_struct *tty, char *msg) | |||
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | #if defined CONFIG_PRINTK | 1310 | #if defined CONFIG_PRINTK |
1311 | |||
1312 | DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10); | ||
1311 | /* | 1313 | /* |
1312 | * printk rate limiting, lifted from the networking subsystem. | 1314 | * printk rate limiting, lifted from the networking subsystem. |
1313 | * | 1315 | * |
@@ -1315,22 +1317,9 @@ void tty_write_message(struct tty_struct *tty, char *msg) | |||
1315 | * every printk_ratelimit_jiffies to make a denial-of-service | 1317 | * every printk_ratelimit_jiffies to make a denial-of-service |
1316 | * attack impossible. | 1318 | * attack impossible. |
1317 | */ | 1319 | */ |
1318 | int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst) | ||
1319 | { | ||
1320 | return __ratelimit(ratelimit_jiffies, ratelimit_burst); | ||
1321 | } | ||
1322 | EXPORT_SYMBOL(__printk_ratelimit); | ||
1323 | |||
1324 | /* minimum time in jiffies between messages */ | ||
1325 | int printk_ratelimit_jiffies = 5 * HZ; | ||
1326 | |||
1327 | /* number of messages we send before ratelimiting */ | ||
1328 | int printk_ratelimit_burst = 10; | ||
1329 | |||
1330 | int printk_ratelimit(void) | 1320 | int printk_ratelimit(void) |
1331 | { | 1321 | { |
1332 | return __printk_ratelimit(printk_ratelimit_jiffies, | 1322 | return __ratelimit(&printk_ratelimit_state); |
1333 | printk_ratelimit_burst); | ||
1334 | } | 1323 | } |
1335 | EXPORT_SYMBOL(printk_ratelimit); | 1324 | EXPORT_SYMBOL(printk_ratelimit); |
1336 | 1325 | ||
diff --git a/kernel/profile.c b/kernel/profile.c index 58926411eb2a..cd26bed4cc26 100644 --- a/kernel/profile.c +++ b/kernel/profile.c | |||
@@ -112,8 +112,6 @@ void __init profile_init(void) | |||
112 | 112 | ||
113 | /* Profile event notifications */ | 113 | /* Profile event notifications */ |
114 | 114 | ||
115 | #ifdef CONFIG_PROFILING | ||
116 | |||
117 | static BLOCKING_NOTIFIER_HEAD(task_exit_notifier); | 115 | static BLOCKING_NOTIFIER_HEAD(task_exit_notifier); |
118 | static ATOMIC_NOTIFIER_HEAD(task_free_notifier); | 116 | static ATOMIC_NOTIFIER_HEAD(task_free_notifier); |
119 | static BLOCKING_NOTIFIER_HEAD(munmap_notifier); | 117 | static BLOCKING_NOTIFIER_HEAD(munmap_notifier); |
@@ -203,8 +201,6 @@ void unregister_timer_hook(int (*hook)(struct pt_regs *)) | |||
203 | } | 201 | } |
204 | EXPORT_SYMBOL_GPL(unregister_timer_hook); | 202 | EXPORT_SYMBOL_GPL(unregister_timer_hook); |
205 | 203 | ||
206 | #endif /* CONFIG_PROFILING */ | ||
207 | |||
208 | 204 | ||
209 | #ifdef CONFIG_SMP | 205 | #ifdef CONFIG_SMP |
210 | /* | 206 | /* |
diff --git a/kernel/rcuclassic.c b/kernel/rcuclassic.c index 16eeeaa9d618..6f8696c502f4 100644 --- a/kernel/rcuclassic.c +++ b/kernel/rcuclassic.c | |||
@@ -106,7 +106,7 @@ static void force_quiescent_state(struct rcu_data *rdp, | |||
106 | */ | 106 | */ |
107 | cpus_and(cpumask, rcp->cpumask, cpu_online_map); | 107 | cpus_and(cpumask, rcp->cpumask, cpu_online_map); |
108 | cpu_clear(rdp->cpu, cpumask); | 108 | cpu_clear(rdp->cpu, cpumask); |
109 | for_each_cpu_mask(cpu, cpumask) | 109 | for_each_cpu_mask_nr(cpu, cpumask) |
110 | smp_send_reschedule(cpu); | 110 | smp_send_reschedule(cpu); |
111 | } | 111 | } |
112 | } | 112 | } |
diff --git a/kernel/rcupreempt.c b/kernel/rcupreempt.c index 6f62b77d93c4..27827931ca0d 100644 --- a/kernel/rcupreempt.c +++ b/kernel/rcupreempt.c | |||
@@ -756,7 +756,7 @@ rcu_try_flip_idle(void) | |||
756 | 756 | ||
757 | /* Now ask each CPU for acknowledgement of the flip. */ | 757 | /* Now ask each CPU for acknowledgement of the flip. */ |
758 | 758 | ||
759 | for_each_cpu_mask(cpu, rcu_cpu_online_map) { | 759 | for_each_cpu_mask_nr(cpu, rcu_cpu_online_map) { |
760 | per_cpu(rcu_flip_flag, cpu) = rcu_flipped; | 760 | per_cpu(rcu_flip_flag, cpu) = rcu_flipped; |
761 | dyntick_save_progress_counter(cpu); | 761 | dyntick_save_progress_counter(cpu); |
762 | } | 762 | } |
@@ -774,7 +774,7 @@ rcu_try_flip_waitack(void) | |||
774 | int cpu; | 774 | int cpu; |
775 | 775 | ||
776 | RCU_TRACE_ME(rcupreempt_trace_try_flip_a1); | 776 | RCU_TRACE_ME(rcupreempt_trace_try_flip_a1); |
777 | for_each_cpu_mask(cpu, rcu_cpu_online_map) | 777 | for_each_cpu_mask_nr(cpu, rcu_cpu_online_map) |
778 | if (rcu_try_flip_waitack_needed(cpu) && | 778 | if (rcu_try_flip_waitack_needed(cpu) && |
779 | per_cpu(rcu_flip_flag, cpu) != rcu_flip_seen) { | 779 | per_cpu(rcu_flip_flag, cpu) != rcu_flip_seen) { |
780 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ae1); | 780 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ae1); |
@@ -806,7 +806,7 @@ rcu_try_flip_waitzero(void) | |||
806 | /* Check to see if the sum of the "last" counters is zero. */ | 806 | /* Check to see if the sum of the "last" counters is zero. */ |
807 | 807 | ||
808 | RCU_TRACE_ME(rcupreempt_trace_try_flip_z1); | 808 | RCU_TRACE_ME(rcupreempt_trace_try_flip_z1); |
809 | for_each_cpu_mask(cpu, rcu_cpu_online_map) | 809 | for_each_cpu_mask_nr(cpu, rcu_cpu_online_map) |
810 | sum += RCU_DATA_CPU(cpu)->rcu_flipctr[lastidx]; | 810 | sum += RCU_DATA_CPU(cpu)->rcu_flipctr[lastidx]; |
811 | if (sum != 0) { | 811 | if (sum != 0) { |
812 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ze1); | 812 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ze1); |
@@ -821,7 +821,7 @@ rcu_try_flip_waitzero(void) | |||
821 | smp_mb(); /* ^^^^^^^^^^^^ */ | 821 | smp_mb(); /* ^^^^^^^^^^^^ */ |
822 | 822 | ||
823 | /* Call for a memory barrier from each CPU. */ | 823 | /* Call for a memory barrier from each CPU. */ |
824 | for_each_cpu_mask(cpu, rcu_cpu_online_map) { | 824 | for_each_cpu_mask_nr(cpu, rcu_cpu_online_map) { |
825 | per_cpu(rcu_mb_flag, cpu) = rcu_mb_needed; | 825 | per_cpu(rcu_mb_flag, cpu) = rcu_mb_needed; |
826 | dyntick_save_progress_counter(cpu); | 826 | dyntick_save_progress_counter(cpu); |
827 | } | 827 | } |
@@ -841,7 +841,7 @@ rcu_try_flip_waitmb(void) | |||
841 | int cpu; | 841 | int cpu; |
842 | 842 | ||
843 | RCU_TRACE_ME(rcupreempt_trace_try_flip_m1); | 843 | RCU_TRACE_ME(rcupreempt_trace_try_flip_m1); |
844 | for_each_cpu_mask(cpu, rcu_cpu_online_map) | 844 | for_each_cpu_mask_nr(cpu, rcu_cpu_online_map) |
845 | if (rcu_try_flip_waitmb_needed(cpu) && | 845 | if (rcu_try_flip_waitmb_needed(cpu) && |
846 | per_cpu(rcu_mb_flag, cpu) != rcu_mb_done) { | 846 | per_cpu(rcu_mb_flag, cpu) != rcu_mb_done) { |
847 | RCU_TRACE_ME(rcupreempt_trace_try_flip_me1); | 847 | RCU_TRACE_ME(rcupreempt_trace_try_flip_me1); |
diff --git a/kernel/res_counter.c b/kernel/res_counter.c index d3c61b4ebef2..f275c8eca772 100644 --- a/kernel/res_counter.c +++ b/kernel/res_counter.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/res_counter.h> | 14 | #include <linux/res_counter.h> |
15 | #include <linux/uaccess.h> | 15 | #include <linux/uaccess.h> |
16 | #include <linux/mm.h> | ||
16 | 17 | ||
17 | void res_counter_init(struct res_counter *counter) | 18 | void res_counter_init(struct res_counter *counter) |
18 | { | 19 | { |
@@ -102,44 +103,37 @@ u64 res_counter_read_u64(struct res_counter *counter, int member) | |||
102 | return *res_counter_member(counter, member); | 103 | return *res_counter_member(counter, member); |
103 | } | 104 | } |
104 | 105 | ||
105 | ssize_t res_counter_write(struct res_counter *counter, int member, | 106 | int res_counter_memparse_write_strategy(const char *buf, |
106 | const char __user *userbuf, size_t nbytes, loff_t *pos, | 107 | unsigned long long *res) |
107 | int (*write_strategy)(char *st_buf, unsigned long long *val)) | ||
108 | { | 108 | { |
109 | int ret; | 109 | char *end; |
110 | char *buf, *end; | 110 | /* FIXME - make memparse() take const char* args */ |
111 | unsigned long flags; | 111 | *res = memparse((char *)buf, &end); |
112 | unsigned long long tmp, *val; | 112 | if (*end != '\0') |
113 | 113 | return -EINVAL; | |
114 | buf = kmalloc(nbytes + 1, GFP_KERNEL); | ||
115 | ret = -ENOMEM; | ||
116 | if (buf == NULL) | ||
117 | goto out; | ||
118 | 114 | ||
119 | buf[nbytes] = '\0'; | 115 | *res = PAGE_ALIGN(*res); |
120 | ret = -EFAULT; | 116 | return 0; |
121 | if (copy_from_user(buf, userbuf, nbytes)) | 117 | } |
122 | goto out_free; | ||
123 | 118 | ||
124 | ret = -EINVAL; | 119 | int res_counter_write(struct res_counter *counter, int member, |
120 | const char *buf, write_strategy_fn write_strategy) | ||
121 | { | ||
122 | char *end; | ||
123 | unsigned long flags; | ||
124 | unsigned long long tmp, *val; | ||
125 | 125 | ||
126 | strstrip(buf); | ||
127 | if (write_strategy) { | 126 | if (write_strategy) { |
128 | if (write_strategy(buf, &tmp)) { | 127 | if (write_strategy(buf, &tmp)) |
129 | goto out_free; | 128 | return -EINVAL; |
130 | } | ||
131 | } else { | 129 | } else { |
132 | tmp = simple_strtoull(buf, &end, 10); | 130 | tmp = simple_strtoull(buf, &end, 10); |
133 | if (*end != '\0') | 131 | if (*end != '\0') |
134 | goto out_free; | 132 | return -EINVAL; |
135 | } | 133 | } |
136 | spin_lock_irqsave(&counter->lock, flags); | 134 | spin_lock_irqsave(&counter->lock, flags); |
137 | val = res_counter_member(counter, member); | 135 | val = res_counter_member(counter, member); |
138 | *val = tmp; | 136 | *val = tmp; |
139 | spin_unlock_irqrestore(&counter->lock, flags); | 137 | spin_unlock_irqrestore(&counter->lock, flags); |
140 | ret = nbytes; | 138 | return 0; |
141 | out_free: | ||
142 | kfree(buf); | ||
143 | out: | ||
144 | return ret; | ||
145 | } | 139 | } |
diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c index 092e4c620af9..a56f629b057a 100644 --- a/kernel/rtmutex-tester.c +++ b/kernel/rtmutex-tester.c | |||
@@ -297,8 +297,8 @@ static int test_func(void *data) | |||
297 | * | 297 | * |
298 | * opcode:data | 298 | * opcode:data |
299 | */ | 299 | */ |
300 | static ssize_t sysfs_test_command(struct sys_device *dev, const char *buf, | 300 | static ssize_t sysfs_test_command(struct sys_device *dev, struct sysdev_attribute *attr, |
301 | size_t count) | 301 | const char *buf, size_t count) |
302 | { | 302 | { |
303 | struct sched_param schedpar; | 303 | struct sched_param schedpar; |
304 | struct test_thread_data *td; | 304 | struct test_thread_data *td; |
@@ -360,7 +360,8 @@ static ssize_t sysfs_test_command(struct sys_device *dev, const char *buf, | |||
360 | * @dev: thread to query | 360 | * @dev: thread to query |
361 | * @buf: char buffer to be filled with thread status info | 361 | * @buf: char buffer to be filled with thread status info |
362 | */ | 362 | */ |
363 | static ssize_t sysfs_test_status(struct sys_device *dev, char *buf) | 363 | static ssize_t sysfs_test_status(struct sys_device *dev, struct sysdev_attribute *attr, |
364 | char *buf) | ||
364 | { | 365 | { |
365 | struct test_thread_data *td; | 366 | struct test_thread_data *td; |
366 | struct task_struct *tsk; | 367 | struct task_struct *tsk; |
diff --git a/kernel/sched.c b/kernel/sched.c index 99e6d850ecab..0047bd9b96aa 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -571,8 +571,10 @@ struct rq { | |||
571 | #endif | 571 | #endif |
572 | 572 | ||
573 | #ifdef CONFIG_SCHED_HRTICK | 573 | #ifdef CONFIG_SCHED_HRTICK |
574 | unsigned long hrtick_flags; | 574 | #ifdef CONFIG_SMP |
575 | ktime_t hrtick_expire; | 575 | int hrtick_csd_pending; |
576 | struct call_single_data hrtick_csd; | ||
577 | #endif | ||
576 | struct hrtimer hrtick_timer; | 578 | struct hrtimer hrtick_timer; |
577 | #endif | 579 | #endif |
578 | 580 | ||
@@ -983,13 +985,6 @@ static struct rq *this_rq_lock(void) | |||
983 | return rq; | 985 | return rq; |
984 | } | 986 | } |
985 | 987 | ||
986 | static void __resched_task(struct task_struct *p, int tif_bit); | ||
987 | |||
988 | static inline void resched_task(struct task_struct *p) | ||
989 | { | ||
990 | __resched_task(p, TIF_NEED_RESCHED); | ||
991 | } | ||
992 | |||
993 | #ifdef CONFIG_SCHED_HRTICK | 988 | #ifdef CONFIG_SCHED_HRTICK |
994 | /* | 989 | /* |
995 | * Use HR-timers to deliver accurate preemption points. | 990 | * Use HR-timers to deliver accurate preemption points. |
@@ -1001,25 +996,6 @@ static inline void resched_task(struct task_struct *p) | |||
1001 | * When we get rescheduled we reprogram the hrtick_timer outside of the | 996 | * When we get rescheduled we reprogram the hrtick_timer outside of the |
1002 | * rq->lock. | 997 | * rq->lock. |
1003 | */ | 998 | */ |
1004 | static inline void resched_hrt(struct task_struct *p) | ||
1005 | { | ||
1006 | __resched_task(p, TIF_HRTICK_RESCHED); | ||
1007 | } | ||
1008 | |||
1009 | static inline void resched_rq(struct rq *rq) | ||
1010 | { | ||
1011 | unsigned long flags; | ||
1012 | |||
1013 | spin_lock_irqsave(&rq->lock, flags); | ||
1014 | resched_task(rq->curr); | ||
1015 | spin_unlock_irqrestore(&rq->lock, flags); | ||
1016 | } | ||
1017 | |||
1018 | enum { | ||
1019 | HRTICK_SET, /* re-programm hrtick_timer */ | ||
1020 | HRTICK_RESET, /* not a new slice */ | ||
1021 | HRTICK_BLOCK, /* stop hrtick operations */ | ||
1022 | }; | ||
1023 | 999 | ||
1024 | /* | 1000 | /* |
1025 | * Use hrtick when: | 1001 | * Use hrtick when: |
@@ -1030,40 +1006,11 @@ static inline int hrtick_enabled(struct rq *rq) | |||
1030 | { | 1006 | { |
1031 | if (!sched_feat(HRTICK)) | 1007 | if (!sched_feat(HRTICK)) |
1032 | return 0; | 1008 | return 0; |
1033 | if (unlikely(test_bit(HRTICK_BLOCK, &rq->hrtick_flags))) | 1009 | if (!cpu_active(cpu_of(rq))) |
1034 | return 0; | 1010 | return 0; |
1035 | return hrtimer_is_hres_active(&rq->hrtick_timer); | 1011 | return hrtimer_is_hres_active(&rq->hrtick_timer); |
1036 | } | 1012 | } |
1037 | 1013 | ||
1038 | /* | ||
1039 | * Called to set the hrtick timer state. | ||
1040 | * | ||
1041 | * called with rq->lock held and irqs disabled | ||
1042 | */ | ||
1043 | static void hrtick_start(struct rq *rq, u64 delay, int reset) | ||
1044 | { | ||
1045 | assert_spin_locked(&rq->lock); | ||
1046 | |||
1047 | /* | ||
1048 | * preempt at: now + delay | ||
1049 | */ | ||
1050 | rq->hrtick_expire = | ||
1051 | ktime_add_ns(rq->hrtick_timer.base->get_time(), delay); | ||
1052 | /* | ||
1053 | * indicate we need to program the timer | ||
1054 | */ | ||
1055 | __set_bit(HRTICK_SET, &rq->hrtick_flags); | ||
1056 | if (reset) | ||
1057 | __set_bit(HRTICK_RESET, &rq->hrtick_flags); | ||
1058 | |||
1059 | /* | ||
1060 | * New slices are called from the schedule path and don't need a | ||
1061 | * forced reschedule. | ||
1062 | */ | ||
1063 | if (reset) | ||
1064 | resched_hrt(rq->curr); | ||
1065 | } | ||
1066 | |||
1067 | static void hrtick_clear(struct rq *rq) | 1014 | static void hrtick_clear(struct rq *rq) |
1068 | { | 1015 | { |
1069 | if (hrtimer_active(&rq->hrtick_timer)) | 1016 | if (hrtimer_active(&rq->hrtick_timer)) |
@@ -1071,32 +1018,6 @@ static void hrtick_clear(struct rq *rq) | |||
1071 | } | 1018 | } |
1072 | 1019 | ||
1073 | /* | 1020 | /* |
1074 | * Update the timer from the possible pending state. | ||
1075 | */ | ||
1076 | static void hrtick_set(struct rq *rq) | ||
1077 | { | ||
1078 | ktime_t time; | ||
1079 | int set, reset; | ||
1080 | unsigned long flags; | ||
1081 | |||
1082 | WARN_ON_ONCE(cpu_of(rq) != smp_processor_id()); | ||
1083 | |||
1084 | spin_lock_irqsave(&rq->lock, flags); | ||
1085 | set = __test_and_clear_bit(HRTICK_SET, &rq->hrtick_flags); | ||
1086 | reset = __test_and_clear_bit(HRTICK_RESET, &rq->hrtick_flags); | ||
1087 | time = rq->hrtick_expire; | ||
1088 | clear_thread_flag(TIF_HRTICK_RESCHED); | ||
1089 | spin_unlock_irqrestore(&rq->lock, flags); | ||
1090 | |||
1091 | if (set) { | ||
1092 | hrtimer_start(&rq->hrtick_timer, time, HRTIMER_MODE_ABS); | ||
1093 | if (reset && !hrtimer_active(&rq->hrtick_timer)) | ||
1094 | resched_rq(rq); | ||
1095 | } else | ||
1096 | hrtick_clear(rq); | ||
1097 | } | ||
1098 | |||
1099 | /* | ||
1100 | * High-resolution timer tick. | 1021 | * High-resolution timer tick. |
1101 | * Runs from hardirq context with interrupts disabled. | 1022 | * Runs from hardirq context with interrupts disabled. |
1102 | */ | 1023 | */ |
@@ -1115,27 +1036,37 @@ static enum hrtimer_restart hrtick(struct hrtimer *timer) | |||
1115 | } | 1036 | } |
1116 | 1037 | ||
1117 | #ifdef CONFIG_SMP | 1038 | #ifdef CONFIG_SMP |
1118 | static void hotplug_hrtick_disable(int cpu) | 1039 | /* |
1040 | * called from hardirq (IPI) context | ||
1041 | */ | ||
1042 | static void __hrtick_start(void *arg) | ||
1119 | { | 1043 | { |
1120 | struct rq *rq = cpu_rq(cpu); | 1044 | struct rq *rq = arg; |
1121 | unsigned long flags; | ||
1122 | 1045 | ||
1123 | spin_lock_irqsave(&rq->lock, flags); | 1046 | spin_lock(&rq->lock); |
1124 | rq->hrtick_flags = 0; | 1047 | hrtimer_restart(&rq->hrtick_timer); |
1125 | __set_bit(HRTICK_BLOCK, &rq->hrtick_flags); | 1048 | rq->hrtick_csd_pending = 0; |
1126 | spin_unlock_irqrestore(&rq->lock, flags); | 1049 | spin_unlock(&rq->lock); |
1127 | |||
1128 | hrtick_clear(rq); | ||
1129 | } | 1050 | } |
1130 | 1051 | ||
1131 | static void hotplug_hrtick_enable(int cpu) | 1052 | /* |
1053 | * Called to set the hrtick timer state. | ||
1054 | * | ||
1055 | * called with rq->lock held and irqs disabled | ||
1056 | */ | ||
1057 | static void hrtick_start(struct rq *rq, u64 delay) | ||
1132 | { | 1058 | { |
1133 | struct rq *rq = cpu_rq(cpu); | 1059 | struct hrtimer *timer = &rq->hrtick_timer; |
1134 | unsigned long flags; | 1060 | ktime_t time = ktime_add_ns(timer->base->get_time(), delay); |
1135 | 1061 | ||
1136 | spin_lock_irqsave(&rq->lock, flags); | 1062 | timer->expires = time; |
1137 | __clear_bit(HRTICK_BLOCK, &rq->hrtick_flags); | 1063 | |
1138 | spin_unlock_irqrestore(&rq->lock, flags); | 1064 | if (rq == this_rq()) { |
1065 | hrtimer_restart(timer); | ||
1066 | } else if (!rq->hrtick_csd_pending) { | ||
1067 | __smp_call_function_single(cpu_of(rq), &rq->hrtick_csd); | ||
1068 | rq->hrtick_csd_pending = 1; | ||
1069 | } | ||
1139 | } | 1070 | } |
1140 | 1071 | ||
1141 | static int | 1072 | static int |
@@ -1150,16 +1081,7 @@ hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
1150 | case CPU_DOWN_PREPARE_FROZEN: | 1081 | case CPU_DOWN_PREPARE_FROZEN: |
1151 | case CPU_DEAD: | 1082 | case CPU_DEAD: |
1152 | case CPU_DEAD_FROZEN: | 1083 | case CPU_DEAD_FROZEN: |
1153 | hotplug_hrtick_disable(cpu); | 1084 | hrtick_clear(cpu_rq(cpu)); |
1154 | return NOTIFY_OK; | ||
1155 | |||
1156 | case CPU_UP_PREPARE: | ||
1157 | case CPU_UP_PREPARE_FROZEN: | ||
1158 | case CPU_DOWN_FAILED: | ||
1159 | case CPU_DOWN_FAILED_FROZEN: | ||
1160 | case CPU_ONLINE: | ||
1161 | case CPU_ONLINE_FROZEN: | ||
1162 | hotplug_hrtick_enable(cpu); | ||
1163 | return NOTIFY_OK; | 1085 | return NOTIFY_OK; |
1164 | } | 1086 | } |
1165 | 1087 | ||
@@ -1170,46 +1092,45 @@ static void init_hrtick(void) | |||
1170 | { | 1092 | { |
1171 | hotcpu_notifier(hotplug_hrtick, 0); | 1093 | hotcpu_notifier(hotplug_hrtick, 0); |
1172 | } | 1094 | } |
1173 | #endif /* CONFIG_SMP */ | 1095 | #else |
1096 | /* | ||
1097 | * Called to set the hrtick timer state. | ||
1098 | * | ||
1099 | * called with rq->lock held and irqs disabled | ||
1100 | */ | ||
1101 | static void hrtick_start(struct rq *rq, u64 delay) | ||
1102 | { | ||
1103 | hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay), HRTIMER_MODE_REL); | ||
1104 | } | ||
1174 | 1105 | ||
1175 | static void init_rq_hrtick(struct rq *rq) | 1106 | static void init_hrtick(void) |
1176 | { | 1107 | { |
1177 | rq->hrtick_flags = 0; | ||
1178 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
1179 | rq->hrtick_timer.function = hrtick; | ||
1180 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | ||
1181 | } | 1108 | } |
1109 | #endif /* CONFIG_SMP */ | ||
1182 | 1110 | ||
1183 | void hrtick_resched(void) | 1111 | static void init_rq_hrtick(struct rq *rq) |
1184 | { | 1112 | { |
1185 | struct rq *rq; | 1113 | #ifdef CONFIG_SMP |
1186 | unsigned long flags; | 1114 | rq->hrtick_csd_pending = 0; |
1187 | 1115 | ||
1188 | if (!test_thread_flag(TIF_HRTICK_RESCHED)) | 1116 | rq->hrtick_csd.flags = 0; |
1189 | return; | 1117 | rq->hrtick_csd.func = __hrtick_start; |
1118 | rq->hrtick_csd.info = rq; | ||
1119 | #endif | ||
1190 | 1120 | ||
1191 | local_irq_save(flags); | 1121 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
1192 | rq = cpu_rq(smp_processor_id()); | 1122 | rq->hrtick_timer.function = hrtick; |
1193 | hrtick_set(rq); | 1123 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; |
1194 | local_irq_restore(flags); | ||
1195 | } | 1124 | } |
1196 | #else | 1125 | #else |
1197 | static inline void hrtick_clear(struct rq *rq) | 1126 | static inline void hrtick_clear(struct rq *rq) |
1198 | { | 1127 | { |
1199 | } | 1128 | } |
1200 | 1129 | ||
1201 | static inline void hrtick_set(struct rq *rq) | ||
1202 | { | ||
1203 | } | ||
1204 | |||
1205 | static inline void init_rq_hrtick(struct rq *rq) | 1130 | static inline void init_rq_hrtick(struct rq *rq) |
1206 | { | 1131 | { |
1207 | } | 1132 | } |
1208 | 1133 | ||
1209 | void hrtick_resched(void) | ||
1210 | { | ||
1211 | } | ||
1212 | |||
1213 | static inline void init_hrtick(void) | 1134 | static inline void init_hrtick(void) |
1214 | { | 1135 | { |
1215 | } | 1136 | } |
@@ -1228,16 +1149,16 @@ static inline void init_hrtick(void) | |||
1228 | #define tsk_is_polling(t) test_tsk_thread_flag(t, TIF_POLLING_NRFLAG) | 1149 | #define tsk_is_polling(t) test_tsk_thread_flag(t, TIF_POLLING_NRFLAG) |
1229 | #endif | 1150 | #endif |
1230 | 1151 | ||
1231 | static void __resched_task(struct task_struct *p, int tif_bit) | 1152 | static void resched_task(struct task_struct *p) |
1232 | { | 1153 | { |
1233 | int cpu; | 1154 | int cpu; |
1234 | 1155 | ||
1235 | assert_spin_locked(&task_rq(p)->lock); | 1156 | assert_spin_locked(&task_rq(p)->lock); |
1236 | 1157 | ||
1237 | if (unlikely(test_tsk_thread_flag(p, tif_bit))) | 1158 | if (unlikely(test_tsk_thread_flag(p, TIF_NEED_RESCHED))) |
1238 | return; | 1159 | return; |
1239 | 1160 | ||
1240 | set_tsk_thread_flag(p, tif_bit); | 1161 | set_tsk_thread_flag(p, TIF_NEED_RESCHED); |
1241 | 1162 | ||
1242 | cpu = task_cpu(p); | 1163 | cpu = task_cpu(p); |
1243 | if (cpu == smp_processor_id()) | 1164 | if (cpu == smp_processor_id()) |
@@ -1303,10 +1224,10 @@ void wake_up_idle_cpu(int cpu) | |||
1303 | #endif /* CONFIG_NO_HZ */ | 1224 | #endif /* CONFIG_NO_HZ */ |
1304 | 1225 | ||
1305 | #else /* !CONFIG_SMP */ | 1226 | #else /* !CONFIG_SMP */ |
1306 | static void __resched_task(struct task_struct *p, int tif_bit) | 1227 | static void resched_task(struct task_struct *p) |
1307 | { | 1228 | { |
1308 | assert_spin_locked(&task_rq(p)->lock); | 1229 | assert_spin_locked(&task_rq(p)->lock); |
1309 | set_tsk_thread_flag(p, tif_bit); | 1230 | set_tsk_need_resched(p); |
1310 | } | 1231 | } |
1311 | #endif /* CONFIG_SMP */ | 1232 | #endif /* CONFIG_SMP */ |
1312 | 1233 | ||
@@ -2108,7 +2029,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu) | |||
2108 | /* Tally up the load of all CPUs in the group */ | 2029 | /* Tally up the load of all CPUs in the group */ |
2109 | avg_load = 0; | 2030 | avg_load = 0; |
2110 | 2031 | ||
2111 | for_each_cpu_mask(i, group->cpumask) { | 2032 | for_each_cpu_mask_nr(i, group->cpumask) { |
2112 | /* Bias balancing toward cpus of our domain */ | 2033 | /* Bias balancing toward cpus of our domain */ |
2113 | if (local_group) | 2034 | if (local_group) |
2114 | load = source_load(i, load_idx); | 2035 | load = source_load(i, load_idx); |
@@ -2150,7 +2071,7 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu, | |||
2150 | /* Traverse only the allowed CPUs */ | 2071 | /* Traverse only the allowed CPUs */ |
2151 | cpus_and(*tmp, group->cpumask, p->cpus_allowed); | 2072 | cpus_and(*tmp, group->cpumask, p->cpus_allowed); |
2152 | 2073 | ||
2153 | for_each_cpu_mask(i, *tmp) { | 2074 | for_each_cpu_mask_nr(i, *tmp) { |
2154 | load = weighted_cpuload(i); | 2075 | load = weighted_cpuload(i); |
2155 | 2076 | ||
2156 | if (load < min_load || (load == min_load && i == this_cpu)) { | 2077 | if (load < min_load || (load == min_load && i == this_cpu)) { |
@@ -2881,7 +2802,7 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu) | |||
2881 | 2802 | ||
2882 | rq = task_rq_lock(p, &flags); | 2803 | rq = task_rq_lock(p, &flags); |
2883 | if (!cpu_isset(dest_cpu, p->cpus_allowed) | 2804 | if (!cpu_isset(dest_cpu, p->cpus_allowed) |
2884 | || unlikely(cpu_is_offline(dest_cpu))) | 2805 | || unlikely(!cpu_active(dest_cpu))) |
2885 | goto out; | 2806 | goto out; |
2886 | 2807 | ||
2887 | /* force the process onto the specified CPU */ | 2808 | /* force the process onto the specified CPU */ |
@@ -3168,7 +3089,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3168 | max_cpu_load = 0; | 3089 | max_cpu_load = 0; |
3169 | min_cpu_load = ~0UL; | 3090 | min_cpu_load = ~0UL; |
3170 | 3091 | ||
3171 | for_each_cpu_mask(i, group->cpumask) { | 3092 | for_each_cpu_mask_nr(i, group->cpumask) { |
3172 | struct rq *rq; | 3093 | struct rq *rq; |
3173 | 3094 | ||
3174 | if (!cpu_isset(i, *cpus)) | 3095 | if (!cpu_isset(i, *cpus)) |
@@ -3447,7 +3368,7 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, | |||
3447 | unsigned long max_load = 0; | 3368 | unsigned long max_load = 0; |
3448 | int i; | 3369 | int i; |
3449 | 3370 | ||
3450 | for_each_cpu_mask(i, group->cpumask) { | 3371 | for_each_cpu_mask_nr(i, group->cpumask) { |
3451 | unsigned long wl; | 3372 | unsigned long wl; |
3452 | 3373 | ||
3453 | if (!cpu_isset(i, *cpus)) | 3374 | if (!cpu_isset(i, *cpus)) |
@@ -3849,7 +3770,7 @@ int select_nohz_load_balancer(int stop_tick) | |||
3849 | /* | 3770 | /* |
3850 | * If we are going offline and still the leader, give up! | 3771 | * If we are going offline and still the leader, give up! |
3851 | */ | 3772 | */ |
3852 | if (cpu_is_offline(cpu) && | 3773 | if (!cpu_active(cpu) && |
3853 | atomic_read(&nohz.load_balancer) == cpu) { | 3774 | atomic_read(&nohz.load_balancer) == cpu) { |
3854 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) | 3775 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) |
3855 | BUG(); | 3776 | BUG(); |
@@ -3989,7 +3910,7 @@ static void run_rebalance_domains(struct softirq_action *h) | |||
3989 | int balance_cpu; | 3910 | int balance_cpu; |
3990 | 3911 | ||
3991 | cpu_clear(this_cpu, cpus); | 3912 | cpu_clear(this_cpu, cpus); |
3992 | for_each_cpu_mask(balance_cpu, cpus) { | 3913 | for_each_cpu_mask_nr(balance_cpu, cpus) { |
3993 | /* | 3914 | /* |
3994 | * If this cpu gets work to do, stop the load balancing | 3915 | * If this cpu gets work to do, stop the load balancing |
3995 | * work being done for other cpus. Next load | 3916 | * work being done for other cpus. Next load |
@@ -4125,6 +4046,8 @@ void account_user_time(struct task_struct *p, cputime_t cputime) | |||
4125 | cpustat->nice = cputime64_add(cpustat->nice, tmp); | 4046 | cpustat->nice = cputime64_add(cpustat->nice, tmp); |
4126 | else | 4047 | else |
4127 | cpustat->user = cputime64_add(cpustat->user, tmp); | 4048 | cpustat->user = cputime64_add(cpustat->user, tmp); |
4049 | /* Account for user time used */ | ||
4050 | acct_update_integrals(p); | ||
4128 | } | 4051 | } |
4129 | 4052 | ||
4130 | /* | 4053 | /* |
@@ -4395,7 +4318,7 @@ asmlinkage void __sched schedule(void) | |||
4395 | struct task_struct *prev, *next; | 4318 | struct task_struct *prev, *next; |
4396 | unsigned long *switch_count; | 4319 | unsigned long *switch_count; |
4397 | struct rq *rq; | 4320 | struct rq *rq; |
4398 | int cpu, hrtick = sched_feat(HRTICK); | 4321 | int cpu; |
4399 | 4322 | ||
4400 | need_resched: | 4323 | need_resched: |
4401 | preempt_disable(); | 4324 | preempt_disable(); |
@@ -4410,7 +4333,7 @@ need_resched_nonpreemptible: | |||
4410 | 4333 | ||
4411 | schedule_debug(prev); | 4334 | schedule_debug(prev); |
4412 | 4335 | ||
4413 | if (hrtick) | 4336 | if (sched_feat(HRTICK)) |
4414 | hrtick_clear(rq); | 4337 | hrtick_clear(rq); |
4415 | 4338 | ||
4416 | /* | 4339 | /* |
@@ -4457,9 +4380,6 @@ need_resched_nonpreemptible: | |||
4457 | } else | 4380 | } else |
4458 | spin_unlock_irq(&rq->lock); | 4381 | spin_unlock_irq(&rq->lock); |
4459 | 4382 | ||
4460 | if (hrtick) | ||
4461 | hrtick_set(rq); | ||
4462 | |||
4463 | if (unlikely(reacquire_kernel_lock(current) < 0)) | 4383 | if (unlikely(reacquire_kernel_lock(current) < 0)) |
4464 | goto need_resched_nonpreemptible; | 4384 | goto need_resched_nonpreemptible; |
4465 | 4385 | ||
@@ -5876,7 +5796,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
5876 | struct rq *rq_dest, *rq_src; | 5796 | struct rq *rq_dest, *rq_src; |
5877 | int ret = 0, on_rq; | 5797 | int ret = 0, on_rq; |
5878 | 5798 | ||
5879 | if (unlikely(cpu_is_offline(dest_cpu))) | 5799 | if (unlikely(!cpu_active(dest_cpu))) |
5880 | return ret; | 5800 | return ret; |
5881 | 5801 | ||
5882 | rq_src = cpu_rq(src_cpu); | 5802 | rq_src = cpu_rq(src_cpu); |
@@ -6768,7 +6688,8 @@ static cpumask_t cpu_isolated_map = CPU_MASK_NONE; | |||
6768 | /* Setup the mask of cpus configured for isolated domains */ | 6688 | /* Setup the mask of cpus configured for isolated domains */ |
6769 | static int __init isolated_cpu_setup(char *str) | 6689 | static int __init isolated_cpu_setup(char *str) |
6770 | { | 6690 | { |
6771 | int ints[NR_CPUS], i; | 6691 | static int __initdata ints[NR_CPUS]; |
6692 | int i; | ||
6772 | 6693 | ||
6773 | str = get_options(str, ARRAY_SIZE(ints), ints); | 6694 | str = get_options(str, ARRAY_SIZE(ints), ints); |
6774 | cpus_clear(cpu_isolated_map); | 6695 | cpus_clear(cpu_isolated_map); |
@@ -6802,7 +6723,7 @@ init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, | |||
6802 | 6723 | ||
6803 | cpus_clear(*covered); | 6724 | cpus_clear(*covered); |
6804 | 6725 | ||
6805 | for_each_cpu_mask(i, *span) { | 6726 | for_each_cpu_mask_nr(i, *span) { |
6806 | struct sched_group *sg; | 6727 | struct sched_group *sg; |
6807 | int group = group_fn(i, cpu_map, &sg, tmpmask); | 6728 | int group = group_fn(i, cpu_map, &sg, tmpmask); |
6808 | int j; | 6729 | int j; |
@@ -6813,7 +6734,7 @@ init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, | |||
6813 | cpus_clear(sg->cpumask); | 6734 | cpus_clear(sg->cpumask); |
6814 | sg->__cpu_power = 0; | 6735 | sg->__cpu_power = 0; |
6815 | 6736 | ||
6816 | for_each_cpu_mask(j, *span) { | 6737 | for_each_cpu_mask_nr(j, *span) { |
6817 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) | 6738 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) |
6818 | continue; | 6739 | continue; |
6819 | 6740 | ||
@@ -7013,7 +6934,7 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7013 | if (!sg) | 6934 | if (!sg) |
7014 | return; | 6935 | return; |
7015 | do { | 6936 | do { |
7016 | for_each_cpu_mask(j, sg->cpumask) { | 6937 | for_each_cpu_mask_nr(j, sg->cpumask) { |
7017 | struct sched_domain *sd; | 6938 | struct sched_domain *sd; |
7018 | 6939 | ||
7019 | sd = &per_cpu(phys_domains, j); | 6940 | sd = &per_cpu(phys_domains, j); |
@@ -7038,7 +6959,7 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | |||
7038 | { | 6959 | { |
7039 | int cpu, i; | 6960 | int cpu, i; |
7040 | 6961 | ||
7041 | for_each_cpu_mask(cpu, *cpu_map) { | 6962 | for_each_cpu_mask_nr(cpu, *cpu_map) { |
7042 | struct sched_group **sched_group_nodes | 6963 | struct sched_group **sched_group_nodes |
7043 | = sched_group_nodes_bycpu[cpu]; | 6964 | = sched_group_nodes_bycpu[cpu]; |
7044 | 6965 | ||
@@ -7277,7 +7198,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7277 | /* | 7198 | /* |
7278 | * Set up domains for cpus specified by the cpu_map. | 7199 | * Set up domains for cpus specified by the cpu_map. |
7279 | */ | 7200 | */ |
7280 | for_each_cpu_mask(i, *cpu_map) { | 7201 | for_each_cpu_mask_nr(i, *cpu_map) { |
7281 | struct sched_domain *sd = NULL, *p; | 7202 | struct sched_domain *sd = NULL, *p; |
7282 | SCHED_CPUMASK_VAR(nodemask, allmasks); | 7203 | SCHED_CPUMASK_VAR(nodemask, allmasks); |
7283 | 7204 | ||
@@ -7344,7 +7265,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7344 | 7265 | ||
7345 | #ifdef CONFIG_SCHED_SMT | 7266 | #ifdef CONFIG_SCHED_SMT |
7346 | /* Set up CPU (sibling) groups */ | 7267 | /* Set up CPU (sibling) groups */ |
7347 | for_each_cpu_mask(i, *cpu_map) { | 7268 | for_each_cpu_mask_nr(i, *cpu_map) { |
7348 | SCHED_CPUMASK_VAR(this_sibling_map, allmasks); | 7269 | SCHED_CPUMASK_VAR(this_sibling_map, allmasks); |
7349 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7270 | SCHED_CPUMASK_VAR(send_covered, allmasks); |
7350 | 7271 | ||
@@ -7361,7 +7282,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7361 | 7282 | ||
7362 | #ifdef CONFIG_SCHED_MC | 7283 | #ifdef CONFIG_SCHED_MC |
7363 | /* Set up multi-core groups */ | 7284 | /* Set up multi-core groups */ |
7364 | for_each_cpu_mask(i, *cpu_map) { | 7285 | for_each_cpu_mask_nr(i, *cpu_map) { |
7365 | SCHED_CPUMASK_VAR(this_core_map, allmasks); | 7286 | SCHED_CPUMASK_VAR(this_core_map, allmasks); |
7366 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7287 | SCHED_CPUMASK_VAR(send_covered, allmasks); |
7367 | 7288 | ||
@@ -7428,7 +7349,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7428 | goto error; | 7349 | goto error; |
7429 | } | 7350 | } |
7430 | sched_group_nodes[i] = sg; | 7351 | sched_group_nodes[i] = sg; |
7431 | for_each_cpu_mask(j, *nodemask) { | 7352 | for_each_cpu_mask_nr(j, *nodemask) { |
7432 | struct sched_domain *sd; | 7353 | struct sched_domain *sd; |
7433 | 7354 | ||
7434 | sd = &per_cpu(node_domains, j); | 7355 | sd = &per_cpu(node_domains, j); |
@@ -7474,21 +7395,21 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7474 | 7395 | ||
7475 | /* Calculate CPU power for physical packages and nodes */ | 7396 | /* Calculate CPU power for physical packages and nodes */ |
7476 | #ifdef CONFIG_SCHED_SMT | 7397 | #ifdef CONFIG_SCHED_SMT |
7477 | for_each_cpu_mask(i, *cpu_map) { | 7398 | for_each_cpu_mask_nr(i, *cpu_map) { |
7478 | struct sched_domain *sd = &per_cpu(cpu_domains, i); | 7399 | struct sched_domain *sd = &per_cpu(cpu_domains, i); |
7479 | 7400 | ||
7480 | init_sched_groups_power(i, sd); | 7401 | init_sched_groups_power(i, sd); |
7481 | } | 7402 | } |
7482 | #endif | 7403 | #endif |
7483 | #ifdef CONFIG_SCHED_MC | 7404 | #ifdef CONFIG_SCHED_MC |
7484 | for_each_cpu_mask(i, *cpu_map) { | 7405 | for_each_cpu_mask_nr(i, *cpu_map) { |
7485 | struct sched_domain *sd = &per_cpu(core_domains, i); | 7406 | struct sched_domain *sd = &per_cpu(core_domains, i); |
7486 | 7407 | ||
7487 | init_sched_groups_power(i, sd); | 7408 | init_sched_groups_power(i, sd); |
7488 | } | 7409 | } |
7489 | #endif | 7410 | #endif |
7490 | 7411 | ||
7491 | for_each_cpu_mask(i, *cpu_map) { | 7412 | for_each_cpu_mask_nr(i, *cpu_map) { |
7492 | struct sched_domain *sd = &per_cpu(phys_domains, i); | 7413 | struct sched_domain *sd = &per_cpu(phys_domains, i); |
7493 | 7414 | ||
7494 | init_sched_groups_power(i, sd); | 7415 | init_sched_groups_power(i, sd); |
@@ -7508,7 +7429,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7508 | #endif | 7429 | #endif |
7509 | 7430 | ||
7510 | /* Attach the domains */ | 7431 | /* Attach the domains */ |
7511 | for_each_cpu_mask(i, *cpu_map) { | 7432 | for_each_cpu_mask_nr(i, *cpu_map) { |
7512 | struct sched_domain *sd; | 7433 | struct sched_domain *sd; |
7513 | #ifdef CONFIG_SCHED_SMT | 7434 | #ifdef CONFIG_SCHED_SMT |
7514 | sd = &per_cpu(cpu_domains, i); | 7435 | sd = &per_cpu(cpu_domains, i); |
@@ -7553,18 +7474,6 @@ void __attribute__((weak)) arch_update_cpu_topology(void) | |||
7553 | } | 7474 | } |
7554 | 7475 | ||
7555 | /* | 7476 | /* |
7556 | * Free current domain masks. | ||
7557 | * Called after all cpus are attached to NULL domain. | ||
7558 | */ | ||
7559 | static void free_sched_domains(void) | ||
7560 | { | ||
7561 | ndoms_cur = 0; | ||
7562 | if (doms_cur != &fallback_doms) | ||
7563 | kfree(doms_cur); | ||
7564 | doms_cur = &fallback_doms; | ||
7565 | } | ||
7566 | |||
7567 | /* | ||
7568 | * Set up scheduler domains and groups. Callers must hold the hotplug lock. | 7477 | * Set up scheduler domains and groups. Callers must hold the hotplug lock. |
7569 | * For now this just excludes isolated cpus, but could be used to | 7478 | * For now this just excludes isolated cpus, but could be used to |
7570 | * exclude other special cases in the future. | 7479 | * exclude other special cases in the future. |
@@ -7603,7 +7512,7 @@ static void detach_destroy_domains(const cpumask_t *cpu_map) | |||
7603 | 7512 | ||
7604 | unregister_sched_domain_sysctl(); | 7513 | unregister_sched_domain_sysctl(); |
7605 | 7514 | ||
7606 | for_each_cpu_mask(i, *cpu_map) | 7515 | for_each_cpu_mask_nr(i, *cpu_map) |
7607 | cpu_attach_domain(NULL, &def_root_domain, i); | 7516 | cpu_attach_domain(NULL, &def_root_domain, i); |
7608 | synchronize_sched(); | 7517 | synchronize_sched(); |
7609 | arch_destroy_sched_domains(cpu_map, &tmpmask); | 7518 | arch_destroy_sched_domains(cpu_map, &tmpmask); |
@@ -7642,7 +7551,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7642 | * ownership of it and will kfree it when done with it. If the caller | 7551 | * ownership of it and will kfree it when done with it. If the caller |
7643 | * failed the kmalloc call, then it can pass in doms_new == NULL, | 7552 | * failed the kmalloc call, then it can pass in doms_new == NULL, |
7644 | * and partition_sched_domains() will fallback to the single partition | 7553 | * and partition_sched_domains() will fallback to the single partition |
7645 | * 'fallback_doms'. | 7554 | * 'fallback_doms', it also forces the domains to be rebuilt. |
7646 | * | 7555 | * |
7647 | * Call with hotplug lock held | 7556 | * Call with hotplug lock held |
7648 | */ | 7557 | */ |
@@ -7656,12 +7565,8 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | |||
7656 | /* always unregister in case we don't destroy any domains */ | 7565 | /* always unregister in case we don't destroy any domains */ |
7657 | unregister_sched_domain_sysctl(); | 7566 | unregister_sched_domain_sysctl(); |
7658 | 7567 | ||
7659 | if (doms_new == NULL) { | 7568 | if (doms_new == NULL) |
7660 | ndoms_new = 1; | 7569 | ndoms_new = 0; |
7661 | doms_new = &fallback_doms; | ||
7662 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | ||
7663 | dattr_new = NULL; | ||
7664 | } | ||
7665 | 7570 | ||
7666 | /* Destroy deleted domains */ | 7571 | /* Destroy deleted domains */ |
7667 | for (i = 0; i < ndoms_cur; i++) { | 7572 | for (i = 0; i < ndoms_cur; i++) { |
@@ -7676,6 +7581,14 @@ match1: | |||
7676 | ; | 7581 | ; |
7677 | } | 7582 | } |
7678 | 7583 | ||
7584 | if (doms_new == NULL) { | ||
7585 | ndoms_cur = 0; | ||
7586 | ndoms_new = 1; | ||
7587 | doms_new = &fallback_doms; | ||
7588 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | ||
7589 | dattr_new = NULL; | ||
7590 | } | ||
7591 | |||
7679 | /* Build new domains */ | 7592 | /* Build new domains */ |
7680 | for (i = 0; i < ndoms_new; i++) { | 7593 | for (i = 0; i < ndoms_new; i++) { |
7681 | for (j = 0; j < ndoms_cur; j++) { | 7594 | for (j = 0; j < ndoms_cur; j++) { |
@@ -7706,17 +7619,10 @@ match2: | |||
7706 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) | 7619 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) |
7707 | int arch_reinit_sched_domains(void) | 7620 | int arch_reinit_sched_domains(void) |
7708 | { | 7621 | { |
7709 | int err; | ||
7710 | |||
7711 | get_online_cpus(); | 7622 | get_online_cpus(); |
7712 | mutex_lock(&sched_domains_mutex); | 7623 | rebuild_sched_domains(); |
7713 | detach_destroy_domains(&cpu_online_map); | ||
7714 | free_sched_domains(); | ||
7715 | err = arch_init_sched_domains(&cpu_online_map); | ||
7716 | mutex_unlock(&sched_domains_mutex); | ||
7717 | put_online_cpus(); | 7624 | put_online_cpus(); |
7718 | 7625 | return 0; | |
7719 | return err; | ||
7720 | } | 7626 | } |
7721 | 7627 | ||
7722 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | 7628 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) |
@@ -7737,11 +7643,13 @@ static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | |||
7737 | } | 7643 | } |
7738 | 7644 | ||
7739 | #ifdef CONFIG_SCHED_MC | 7645 | #ifdef CONFIG_SCHED_MC |
7740 | static ssize_t sched_mc_power_savings_show(struct sys_device *dev, char *page) | 7646 | static ssize_t sched_mc_power_savings_show(struct sys_device *dev, |
7647 | struct sysdev_attribute *attr, char *page) | ||
7741 | { | 7648 | { |
7742 | return sprintf(page, "%u\n", sched_mc_power_savings); | 7649 | return sprintf(page, "%u\n", sched_mc_power_savings); |
7743 | } | 7650 | } |
7744 | static ssize_t sched_mc_power_savings_store(struct sys_device *dev, | 7651 | static ssize_t sched_mc_power_savings_store(struct sys_device *dev, |
7652 | struct sysdev_attribute *attr, | ||
7745 | const char *buf, size_t count) | 7653 | const char *buf, size_t count) |
7746 | { | 7654 | { |
7747 | return sched_power_savings_store(buf, count, 0); | 7655 | return sched_power_savings_store(buf, count, 0); |
@@ -7751,11 +7659,13 @@ static SYSDEV_ATTR(sched_mc_power_savings, 0644, sched_mc_power_savings_show, | |||
7751 | #endif | 7659 | #endif |
7752 | 7660 | ||
7753 | #ifdef CONFIG_SCHED_SMT | 7661 | #ifdef CONFIG_SCHED_SMT |
7754 | static ssize_t sched_smt_power_savings_show(struct sys_device *dev, char *page) | 7662 | static ssize_t sched_smt_power_savings_show(struct sys_device *dev, |
7663 | struct sysdev_attribute *attr, char *page) | ||
7755 | { | 7664 | { |
7756 | return sprintf(page, "%u\n", sched_smt_power_savings); | 7665 | return sprintf(page, "%u\n", sched_smt_power_savings); |
7757 | } | 7666 | } |
7758 | static ssize_t sched_smt_power_savings_store(struct sys_device *dev, | 7667 | static ssize_t sched_smt_power_savings_store(struct sys_device *dev, |
7668 | struct sysdev_attribute *attr, | ||
7759 | const char *buf, size_t count) | 7669 | const char *buf, size_t count) |
7760 | { | 7670 | { |
7761 | return sched_power_savings_store(buf, count, 1); | 7671 | return sched_power_savings_store(buf, count, 1); |
@@ -7782,59 +7692,49 @@ int sched_create_sysfs_power_savings_entries(struct sysdev_class *cls) | |||
7782 | } | 7692 | } |
7783 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ | 7693 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ |
7784 | 7694 | ||
7695 | #ifndef CONFIG_CPUSETS | ||
7785 | /* | 7696 | /* |
7786 | * Force a reinitialization of the sched domains hierarchy. The domains | 7697 | * Add online and remove offline CPUs from the scheduler domains. |
7787 | * and groups cannot be updated in place without racing with the balancing | 7698 | * When cpusets are enabled they take over this function. |
7788 | * code, so we temporarily attach all running cpus to the NULL domain | ||
7789 | * which will prevent rebalancing while the sched domains are recalculated. | ||
7790 | */ | 7699 | */ |
7791 | static int update_sched_domains(struct notifier_block *nfb, | 7700 | static int update_sched_domains(struct notifier_block *nfb, |
7792 | unsigned long action, void *hcpu) | 7701 | unsigned long action, void *hcpu) |
7793 | { | 7702 | { |
7703 | switch (action) { | ||
7704 | case CPU_ONLINE: | ||
7705 | case CPU_ONLINE_FROZEN: | ||
7706 | case CPU_DEAD: | ||
7707 | case CPU_DEAD_FROZEN: | ||
7708 | partition_sched_domains(0, NULL, NULL); | ||
7709 | return NOTIFY_OK; | ||
7710 | |||
7711 | default: | ||
7712 | return NOTIFY_DONE; | ||
7713 | } | ||
7714 | } | ||
7715 | #endif | ||
7716 | |||
7717 | static int update_runtime(struct notifier_block *nfb, | ||
7718 | unsigned long action, void *hcpu) | ||
7719 | { | ||
7794 | int cpu = (int)(long)hcpu; | 7720 | int cpu = (int)(long)hcpu; |
7795 | 7721 | ||
7796 | switch (action) { | 7722 | switch (action) { |
7797 | case CPU_DOWN_PREPARE: | 7723 | case CPU_DOWN_PREPARE: |
7798 | case CPU_DOWN_PREPARE_FROZEN: | 7724 | case CPU_DOWN_PREPARE_FROZEN: |
7799 | disable_runtime(cpu_rq(cpu)); | 7725 | disable_runtime(cpu_rq(cpu)); |
7800 | /* fall-through */ | ||
7801 | case CPU_UP_PREPARE: | ||
7802 | case CPU_UP_PREPARE_FROZEN: | ||
7803 | detach_destroy_domains(&cpu_online_map); | ||
7804 | free_sched_domains(); | ||
7805 | return NOTIFY_OK; | 7726 | return NOTIFY_OK; |
7806 | 7727 | ||
7807 | |||
7808 | case CPU_DOWN_FAILED: | 7728 | case CPU_DOWN_FAILED: |
7809 | case CPU_DOWN_FAILED_FROZEN: | 7729 | case CPU_DOWN_FAILED_FROZEN: |
7810 | case CPU_ONLINE: | 7730 | case CPU_ONLINE: |
7811 | case CPU_ONLINE_FROZEN: | 7731 | case CPU_ONLINE_FROZEN: |
7812 | enable_runtime(cpu_rq(cpu)); | 7732 | enable_runtime(cpu_rq(cpu)); |
7813 | /* fall-through */ | 7733 | return NOTIFY_OK; |
7814 | case CPU_UP_CANCELED: | 7734 | |
7815 | case CPU_UP_CANCELED_FROZEN: | ||
7816 | case CPU_DEAD: | ||
7817 | case CPU_DEAD_FROZEN: | ||
7818 | /* | ||
7819 | * Fall through and re-initialise the domains. | ||
7820 | */ | ||
7821 | break; | ||
7822 | default: | 7735 | default: |
7823 | return NOTIFY_DONE; | 7736 | return NOTIFY_DONE; |
7824 | } | 7737 | } |
7825 | |||
7826 | #ifndef CONFIG_CPUSETS | ||
7827 | /* | ||
7828 | * Create default domain partitioning if cpusets are disabled. | ||
7829 | * Otherwise we let cpusets rebuild the domains based on the | ||
7830 | * current setup. | ||
7831 | */ | ||
7832 | |||
7833 | /* The hotplug lock is already held by cpu_up/cpu_down */ | ||
7834 | arch_init_sched_domains(&cpu_online_map); | ||
7835 | #endif | ||
7836 | |||
7837 | return NOTIFY_OK; | ||
7838 | } | 7738 | } |
7839 | 7739 | ||
7840 | void __init sched_init_smp(void) | 7740 | void __init sched_init_smp(void) |
@@ -7854,8 +7754,15 @@ void __init sched_init_smp(void) | |||
7854 | cpu_set(smp_processor_id(), non_isolated_cpus); | 7754 | cpu_set(smp_processor_id(), non_isolated_cpus); |
7855 | mutex_unlock(&sched_domains_mutex); | 7755 | mutex_unlock(&sched_domains_mutex); |
7856 | put_online_cpus(); | 7756 | put_online_cpus(); |
7757 | |||
7758 | #ifndef CONFIG_CPUSETS | ||
7857 | /* XXX: Theoretical race here - CPU may be hotplugged now */ | 7759 | /* XXX: Theoretical race here - CPU may be hotplugged now */ |
7858 | hotcpu_notifier(update_sched_domains, 0); | 7760 | hotcpu_notifier(update_sched_domains, 0); |
7761 | #endif | ||
7762 | |||
7763 | /* RT runtime code needs to handle some hotplug events */ | ||
7764 | hotcpu_notifier(update_runtime, 0); | ||
7765 | |||
7859 | init_hrtick(); | 7766 | init_hrtick(); |
7860 | 7767 | ||
7861 | /* Move init over to a non-isolated CPU */ | 7768 | /* Move init over to a non-isolated CPU */ |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index f2aa987027d6..cf2cd6ce4cb2 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
@@ -878,7 +878,6 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued) | |||
878 | #ifdef CONFIG_SCHED_HRTICK | 878 | #ifdef CONFIG_SCHED_HRTICK |
879 | static void hrtick_start_fair(struct rq *rq, struct task_struct *p) | 879 | static void hrtick_start_fair(struct rq *rq, struct task_struct *p) |
880 | { | 880 | { |
881 | int requeue = rq->curr == p; | ||
882 | struct sched_entity *se = &p->se; | 881 | struct sched_entity *se = &p->se; |
883 | struct cfs_rq *cfs_rq = cfs_rq_of(se); | 882 | struct cfs_rq *cfs_rq = cfs_rq_of(se); |
884 | 883 | ||
@@ -899,10 +898,10 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p) | |||
899 | * Don't schedule slices shorter than 10000ns, that just | 898 | * Don't schedule slices shorter than 10000ns, that just |
900 | * doesn't make sense. Rely on vruntime for fairness. | 899 | * doesn't make sense. Rely on vruntime for fairness. |
901 | */ | 900 | */ |
902 | if (!requeue) | 901 | if (rq->curr != p) |
903 | delta = max(10000LL, delta); | 902 | delta = max(10000LL, delta); |
904 | 903 | ||
905 | hrtick_start(rq, delta, requeue); | 904 | hrtick_start(rq, delta); |
906 | } | 905 | } |
907 | } | 906 | } |
908 | #else /* !CONFIG_SCHED_HRTICK */ | 907 | #else /* !CONFIG_SCHED_HRTICK */ |
@@ -1004,6 +1003,8 @@ static void yield_task_fair(struct rq *rq) | |||
1004 | * not idle and an idle cpu is available. The span of cpus to | 1003 | * not idle and an idle cpu is available. The span of cpus to |
1005 | * search starts with cpus closest then further out as needed, | 1004 | * search starts with cpus closest then further out as needed, |
1006 | * so we always favor a closer, idle cpu. | 1005 | * so we always favor a closer, idle cpu. |
1006 | * Domains may include CPUs that are not usable for migration, | ||
1007 | * hence we need to mask them out (cpu_active_map) | ||
1007 | * | 1008 | * |
1008 | * Returns the CPU we should wake onto. | 1009 | * Returns the CPU we should wake onto. |
1009 | */ | 1010 | */ |
@@ -1031,7 +1032,8 @@ static int wake_idle(int cpu, struct task_struct *p) | |||
1031 | || ((sd->flags & SD_WAKE_IDLE_FAR) | 1032 | || ((sd->flags & SD_WAKE_IDLE_FAR) |
1032 | && !task_hot(p, task_rq(p)->clock, sd))) { | 1033 | && !task_hot(p, task_rq(p)->clock, sd))) { |
1033 | cpus_and(tmp, sd->span, p->cpus_allowed); | 1034 | cpus_and(tmp, sd->span, p->cpus_allowed); |
1034 | for_each_cpu_mask(i, tmp) { | 1035 | cpus_and(tmp, tmp, cpu_active_map); |
1036 | for_each_cpu_mask_nr(i, tmp) { | ||
1035 | if (idle_cpu(i)) { | 1037 | if (idle_cpu(i)) { |
1036 | if (i != task_cpu(p)) { | 1038 | if (i != task_cpu(p)) { |
1037 | schedstat_inc(p, | 1039 | schedstat_inc(p, |
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index 47ceac9e8552..908c04f9dad0 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
@@ -240,7 +240,7 @@ static int do_balance_runtime(struct rt_rq *rt_rq) | |||
240 | 240 | ||
241 | spin_lock(&rt_b->rt_runtime_lock); | 241 | spin_lock(&rt_b->rt_runtime_lock); |
242 | rt_period = ktime_to_ns(rt_b->rt_period); | 242 | rt_period = ktime_to_ns(rt_b->rt_period); |
243 | for_each_cpu_mask(i, rd->span) { | 243 | for_each_cpu_mask_nr(i, rd->span) { |
244 | struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i); | 244 | struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i); |
245 | s64 diff; | 245 | s64 diff; |
246 | 246 | ||
@@ -253,7 +253,7 @@ static int do_balance_runtime(struct rt_rq *rt_rq) | |||
253 | 253 | ||
254 | diff = iter->rt_runtime - iter->rt_time; | 254 | diff = iter->rt_runtime - iter->rt_time; |
255 | if (diff > 0) { | 255 | if (diff > 0) { |
256 | do_div(diff, weight); | 256 | diff = div_u64((u64)diff, weight); |
257 | if (rt_rq->rt_runtime + diff > rt_period) | 257 | if (rt_rq->rt_runtime + diff > rt_period) |
258 | diff = rt_period - rt_rq->rt_runtime; | 258 | diff = rt_period - rt_rq->rt_runtime; |
259 | iter->rt_runtime -= diff; | 259 | iter->rt_runtime -= diff; |
@@ -505,7 +505,9 @@ void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | |||
505 | rt_rq->rt_nr_running++; | 505 | rt_rq->rt_nr_running++; |
506 | #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED | 506 | #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED |
507 | if (rt_se_prio(rt_se) < rt_rq->highest_prio) { | 507 | if (rt_se_prio(rt_se) < rt_rq->highest_prio) { |
508 | #ifdef CONFIG_SMP | ||
508 | struct rq *rq = rq_of_rt_rq(rt_rq); | 509 | struct rq *rq = rq_of_rt_rq(rt_rq); |
510 | #endif | ||
509 | 511 | ||
510 | rt_rq->highest_prio = rt_se_prio(rt_se); | 512 | rt_rq->highest_prio = rt_se_prio(rt_se); |
511 | #ifdef CONFIG_SMP | 513 | #ifdef CONFIG_SMP |
@@ -599,11 +601,7 @@ static void __enqueue_rt_entity(struct sched_rt_entity *rt_se) | |||
599 | if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) | 601 | if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) |
600 | return; | 602 | return; |
601 | 603 | ||
602 | if (rt_se->nr_cpus_allowed == 1) | 604 | list_add_tail(&rt_se->run_list, queue); |
603 | list_add(&rt_se->run_list, queue); | ||
604 | else | ||
605 | list_add_tail(&rt_se->run_list, queue); | ||
606 | |||
607 | __set_bit(rt_se_prio(rt_se), array->bitmap); | 605 | __set_bit(rt_se_prio(rt_se), array->bitmap); |
608 | 606 | ||
609 | inc_rt_tasks(rt_se, rt_rq); | 607 | inc_rt_tasks(rt_se, rt_rq); |
@@ -688,32 +686,34 @@ static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep) | |||
688 | * Put task to the end of the run list without the overhead of dequeue | 686 | * Put task to the end of the run list without the overhead of dequeue |
689 | * followed by enqueue. | 687 | * followed by enqueue. |
690 | */ | 688 | */ |
691 | static | 689 | static void |
692 | void requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se) | 690 | requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int head) |
693 | { | 691 | { |
694 | struct rt_prio_array *array = &rt_rq->active; | ||
695 | |||
696 | if (on_rt_rq(rt_se)) { | 692 | if (on_rt_rq(rt_se)) { |
697 | list_del_init(&rt_se->run_list); | 693 | struct rt_prio_array *array = &rt_rq->active; |
698 | list_add_tail(&rt_se->run_list, | 694 | struct list_head *queue = array->queue + rt_se_prio(rt_se); |
699 | array->queue + rt_se_prio(rt_se)); | 695 | |
696 | if (head) | ||
697 | list_move(&rt_se->run_list, queue); | ||
698 | else | ||
699 | list_move_tail(&rt_se->run_list, queue); | ||
700 | } | 700 | } |
701 | } | 701 | } |
702 | 702 | ||
703 | static void requeue_task_rt(struct rq *rq, struct task_struct *p) | 703 | static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head) |
704 | { | 704 | { |
705 | struct sched_rt_entity *rt_se = &p->rt; | 705 | struct sched_rt_entity *rt_se = &p->rt; |
706 | struct rt_rq *rt_rq; | 706 | struct rt_rq *rt_rq; |
707 | 707 | ||
708 | for_each_sched_rt_entity(rt_se) { | 708 | for_each_sched_rt_entity(rt_se) { |
709 | rt_rq = rt_rq_of_se(rt_se); | 709 | rt_rq = rt_rq_of_se(rt_se); |
710 | requeue_rt_entity(rt_rq, rt_se); | 710 | requeue_rt_entity(rt_rq, rt_se, head); |
711 | } | 711 | } |
712 | } | 712 | } |
713 | 713 | ||
714 | static void yield_task_rt(struct rq *rq) | 714 | static void yield_task_rt(struct rq *rq) |
715 | { | 715 | { |
716 | requeue_task_rt(rq, rq->curr); | 716 | requeue_task_rt(rq, rq->curr, 0); |
717 | } | 717 | } |
718 | 718 | ||
719 | #ifdef CONFIG_SMP | 719 | #ifdef CONFIG_SMP |
@@ -753,6 +753,30 @@ static int select_task_rq_rt(struct task_struct *p, int sync) | |||
753 | */ | 753 | */ |
754 | return task_cpu(p); | 754 | return task_cpu(p); |
755 | } | 755 | } |
756 | |||
757 | static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) | ||
758 | { | ||
759 | cpumask_t mask; | ||
760 | |||
761 | if (rq->curr->rt.nr_cpus_allowed == 1) | ||
762 | return; | ||
763 | |||
764 | if (p->rt.nr_cpus_allowed != 1 | ||
765 | && cpupri_find(&rq->rd->cpupri, p, &mask)) | ||
766 | return; | ||
767 | |||
768 | if (!cpupri_find(&rq->rd->cpupri, rq->curr, &mask)) | ||
769 | return; | ||
770 | |||
771 | /* | ||
772 | * There appears to be other cpus that can accept | ||
773 | * current and none to run 'p', so lets reschedule | ||
774 | * to try and push current away: | ||
775 | */ | ||
776 | requeue_task_rt(rq, p, 1); | ||
777 | resched_task(rq->curr); | ||
778 | } | ||
779 | |||
756 | #endif /* CONFIG_SMP */ | 780 | #endif /* CONFIG_SMP */ |
757 | 781 | ||
758 | /* | 782 | /* |
@@ -778,18 +802,8 @@ static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p) | |||
778 | * to move current somewhere else, making room for our non-migratable | 802 | * to move current somewhere else, making room for our non-migratable |
779 | * task. | 803 | * task. |
780 | */ | 804 | */ |
781 | if((p->prio == rq->curr->prio) | 805 | if (p->prio == rq->curr->prio && !need_resched()) |
782 | && p->rt.nr_cpus_allowed == 1 | 806 | check_preempt_equal_prio(rq, p); |
783 | && rq->curr->rt.nr_cpus_allowed != 1) { | ||
784 | cpumask_t mask; | ||
785 | |||
786 | if (cpupri_find(&rq->rd->cpupri, rq->curr, &mask)) | ||
787 | /* | ||
788 | * There appears to be other cpus that can accept | ||
789 | * current, so lets reschedule to try and push it away | ||
790 | */ | ||
791 | resched_task(rq->curr); | ||
792 | } | ||
793 | #endif | 807 | #endif |
794 | } | 808 | } |
795 | 809 | ||
@@ -922,6 +936,13 @@ static int find_lowest_rq(struct task_struct *task) | |||
922 | return -1; /* No targets found */ | 936 | return -1; /* No targets found */ |
923 | 937 | ||
924 | /* | 938 | /* |
939 | * Only consider CPUs that are usable for migration. | ||
940 | * I guess we might want to change cpupri_find() to ignore those | ||
941 | * in the first place. | ||
942 | */ | ||
943 | cpus_and(*lowest_mask, *lowest_mask, cpu_active_map); | ||
944 | |||
945 | /* | ||
925 | * At this point we have built a mask of cpus representing the | 946 | * At this point we have built a mask of cpus representing the |
926 | * lowest priority tasks in the system. Now we want to elect | 947 | * lowest priority tasks in the system. Now we want to elect |
927 | * the best one based on our affinity and topology. | 948 | * the best one based on our affinity and topology. |
@@ -1107,7 +1128,7 @@ static int pull_rt_task(struct rq *this_rq) | |||
1107 | 1128 | ||
1108 | next = pick_next_task_rt(this_rq); | 1129 | next = pick_next_task_rt(this_rq); |
1109 | 1130 | ||
1110 | for_each_cpu_mask(cpu, this_rq->rd->rto_mask) { | 1131 | for_each_cpu_mask_nr(cpu, this_rq->rd->rto_mask) { |
1111 | if (this_cpu == cpu) | 1132 | if (this_cpu == cpu) |
1112 | continue; | 1133 | continue; |
1113 | 1134 | ||
@@ -1415,7 +1436,7 @@ static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued) | |||
1415 | * on the queue: | 1436 | * on the queue: |
1416 | */ | 1437 | */ |
1417 | if (p->rt.run_list.prev != p->rt.run_list.next) { | 1438 | if (p->rt.run_list.prev != p->rt.run_list.next) { |
1418 | requeue_task_rt(rq, p); | 1439 | requeue_task_rt(rq, p, 0); |
1419 | set_tsk_need_resched(p); | 1440 | set_tsk_need_resched(p); |
1420 | } | 1441 | } |
1421 | } | 1442 | } |
diff --git a/kernel/signal.c b/kernel/signal.c index 6c0958e52ea7..82c3545596c5 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -338,13 +338,9 @@ unblock_all_signals(void) | |||
338 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); | 338 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
339 | } | 339 | } |
340 | 340 | ||
341 | static int collect_signal(int sig, struct sigpending *list, siginfo_t *info) | 341 | static void collect_signal(int sig, struct sigpending *list, siginfo_t *info) |
342 | { | 342 | { |
343 | struct sigqueue *q, *first = NULL; | 343 | struct sigqueue *q, *first = NULL; |
344 | int still_pending = 0; | ||
345 | |||
346 | if (unlikely(!sigismember(&list->signal, sig))) | ||
347 | return 0; | ||
348 | 344 | ||
349 | /* | 345 | /* |
350 | * Collect the siginfo appropriate to this signal. Check if | 346 | * Collect the siginfo appropriate to this signal. Check if |
@@ -352,33 +348,30 @@ static int collect_signal(int sig, struct sigpending *list, siginfo_t *info) | |||
352 | */ | 348 | */ |
353 | list_for_each_entry(q, &list->list, list) { | 349 | list_for_each_entry(q, &list->list, list) { |
354 | if (q->info.si_signo == sig) { | 350 | if (q->info.si_signo == sig) { |
355 | if (first) { | 351 | if (first) |
356 | still_pending = 1; | 352 | goto still_pending; |
357 | break; | ||
358 | } | ||
359 | first = q; | 353 | first = q; |
360 | } | 354 | } |
361 | } | 355 | } |
356 | |||
357 | sigdelset(&list->signal, sig); | ||
358 | |||
362 | if (first) { | 359 | if (first) { |
360 | still_pending: | ||
363 | list_del_init(&first->list); | 361 | list_del_init(&first->list); |
364 | copy_siginfo(info, &first->info); | 362 | copy_siginfo(info, &first->info); |
365 | __sigqueue_free(first); | 363 | __sigqueue_free(first); |
366 | if (!still_pending) | ||
367 | sigdelset(&list->signal, sig); | ||
368 | } else { | 364 | } else { |
369 | |||
370 | /* Ok, it wasn't in the queue. This must be | 365 | /* Ok, it wasn't in the queue. This must be |
371 | a fast-pathed signal or we must have been | 366 | a fast-pathed signal or we must have been |
372 | out of queue space. So zero out the info. | 367 | out of queue space. So zero out the info. |
373 | */ | 368 | */ |
374 | sigdelset(&list->signal, sig); | ||
375 | info->si_signo = sig; | 369 | info->si_signo = sig; |
376 | info->si_errno = 0; | 370 | info->si_errno = 0; |
377 | info->si_code = 0; | 371 | info->si_code = 0; |
378 | info->si_pid = 0; | 372 | info->si_pid = 0; |
379 | info->si_uid = 0; | 373 | info->si_uid = 0; |
380 | } | 374 | } |
381 | return 1; | ||
382 | } | 375 | } |
383 | 376 | ||
384 | static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, | 377 | static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, |
@@ -396,8 +389,7 @@ static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, | |||
396 | } | 389 | } |
397 | } | 390 | } |
398 | 391 | ||
399 | if (!collect_signal(sig, pending, info)) | 392 | collect_signal(sig, pending, info); |
400 | sig = 0; | ||
401 | } | 393 | } |
402 | 394 | ||
403 | return sig; | 395 | return sig; |
@@ -462,8 +454,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) | |||
462 | * is to alert stop-signal processing code when another | 454 | * is to alert stop-signal processing code when another |
463 | * processor has come along and cleared the flag. | 455 | * processor has come along and cleared the flag. |
464 | */ | 456 | */ |
465 | if (!(tsk->signal->flags & SIGNAL_GROUP_EXIT)) | 457 | tsk->signal->flags |= SIGNAL_STOP_DEQUEUED; |
466 | tsk->signal->flags |= SIGNAL_STOP_DEQUEUED; | ||
467 | } | 458 | } |
468 | if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) { | 459 | if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) { |
469 | /* | 460 | /* |
@@ -1125,7 +1116,7 @@ EXPORT_SYMBOL_GPL(kill_pid_info_as_uid); | |||
1125 | * is probably wrong. Should make it like BSD or SYSV. | 1116 | * is probably wrong. Should make it like BSD or SYSV. |
1126 | */ | 1117 | */ |
1127 | 1118 | ||
1128 | static int kill_something_info(int sig, struct siginfo *info, int pid) | 1119 | static int kill_something_info(int sig, struct siginfo *info, pid_t pid) |
1129 | { | 1120 | { |
1130 | int ret; | 1121 | int ret; |
1131 | 1122 | ||
@@ -1237,17 +1228,6 @@ int kill_pid(struct pid *pid, int sig, int priv) | |||
1237 | } | 1228 | } |
1238 | EXPORT_SYMBOL(kill_pid); | 1229 | EXPORT_SYMBOL(kill_pid); |
1239 | 1230 | ||
1240 | int | ||
1241 | kill_proc(pid_t pid, int sig, int priv) | ||
1242 | { | ||
1243 | int ret; | ||
1244 | |||
1245 | rcu_read_lock(); | ||
1246 | ret = kill_pid_info(sig, __si_special(priv), find_pid(pid)); | ||
1247 | rcu_read_unlock(); | ||
1248 | return ret; | ||
1249 | } | ||
1250 | |||
1251 | /* | 1231 | /* |
1252 | * These functions support sending signals using preallocated sigqueue | 1232 | * These functions support sending signals using preallocated sigqueue |
1253 | * structures. This is needed "because realtime applications cannot | 1233 | * structures. This is needed "because realtime applications cannot |
@@ -1379,10 +1359,9 @@ void do_notify_parent(struct task_struct *tsk, int sig) | |||
1379 | 1359 | ||
1380 | info.si_uid = tsk->uid; | 1360 | info.si_uid = tsk->uid; |
1381 | 1361 | ||
1382 | /* FIXME: find out whether or not this is supposed to be c*time. */ | 1362 | info.si_utime = cputime_to_clock_t(cputime_add(tsk->utime, |
1383 | info.si_utime = cputime_to_jiffies(cputime_add(tsk->utime, | ||
1384 | tsk->signal->utime)); | 1363 | tsk->signal->utime)); |
1385 | info.si_stime = cputime_to_jiffies(cputime_add(tsk->stime, | 1364 | info.si_stime = cputime_to_clock_t(cputime_add(tsk->stime, |
1386 | tsk->signal->stime)); | 1365 | tsk->signal->stime)); |
1387 | 1366 | ||
1388 | info.si_status = tsk->exit_code & 0x7f; | 1367 | info.si_status = tsk->exit_code & 0x7f; |
@@ -1450,9 +1429,8 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, int why) | |||
1450 | 1429 | ||
1451 | info.si_uid = tsk->uid; | 1430 | info.si_uid = tsk->uid; |
1452 | 1431 | ||
1453 | /* FIXME: find out whether or not this is supposed to be c*time. */ | 1432 | info.si_utime = cputime_to_clock_t(tsk->utime); |
1454 | info.si_utime = cputime_to_jiffies(tsk->utime); | 1433 | info.si_stime = cputime_to_clock_t(tsk->stime); |
1455 | info.si_stime = cputime_to_jiffies(tsk->stime); | ||
1456 | 1434 | ||
1457 | info.si_code = why; | 1435 | info.si_code = why; |
1458 | switch (why) { | 1436 | switch (why) { |
@@ -1491,10 +1469,10 @@ static inline int may_ptrace_stop(void) | |||
1491 | * is a deadlock situation, and pointless because our tracer | 1469 | * is a deadlock situation, and pointless because our tracer |
1492 | * is dead so don't allow us to stop. | 1470 | * is dead so don't allow us to stop. |
1493 | * If SIGKILL was already sent before the caller unlocked | 1471 | * If SIGKILL was already sent before the caller unlocked |
1494 | * ->siglock we must see ->core_waiters != 0. Otherwise it | 1472 | * ->siglock we must see ->core_state != NULL. Otherwise it |
1495 | * is safe to enter schedule(). | 1473 | * is safe to enter schedule(). |
1496 | */ | 1474 | */ |
1497 | if (unlikely(current->mm->core_waiters) && | 1475 | if (unlikely(current->mm->core_state) && |
1498 | unlikely(current->mm == current->parent->mm)) | 1476 | unlikely(current->mm == current->parent->mm)) |
1499 | return 0; | 1477 | return 0; |
1500 | 1478 | ||
@@ -1507,9 +1485,8 @@ static inline int may_ptrace_stop(void) | |||
1507 | */ | 1485 | */ |
1508 | static int sigkill_pending(struct task_struct *tsk) | 1486 | static int sigkill_pending(struct task_struct *tsk) |
1509 | { | 1487 | { |
1510 | return ((sigismember(&tsk->pending.signal, SIGKILL) || | 1488 | return sigismember(&tsk->pending.signal, SIGKILL) || |
1511 | sigismember(&tsk->signal->shared_pending.signal, SIGKILL)) && | 1489 | sigismember(&tsk->signal->shared_pending.signal, SIGKILL); |
1512 | !unlikely(sigismember(&tsk->blocked, SIGKILL))); | ||
1513 | } | 1490 | } |
1514 | 1491 | ||
1515 | /* | 1492 | /* |
@@ -1525,8 +1502,6 @@ static int sigkill_pending(struct task_struct *tsk) | |||
1525 | */ | 1502 | */ |
1526 | static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) | 1503 | static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) |
1527 | { | 1504 | { |
1528 | int killed = 0; | ||
1529 | |||
1530 | if (arch_ptrace_stop_needed(exit_code, info)) { | 1505 | if (arch_ptrace_stop_needed(exit_code, info)) { |
1531 | /* | 1506 | /* |
1532 | * The arch code has something special to do before a | 1507 | * The arch code has something special to do before a |
@@ -1542,7 +1517,8 @@ static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) | |||
1542 | spin_unlock_irq(¤t->sighand->siglock); | 1517 | spin_unlock_irq(¤t->sighand->siglock); |
1543 | arch_ptrace_stop(exit_code, info); | 1518 | arch_ptrace_stop(exit_code, info); |
1544 | spin_lock_irq(¤t->sighand->siglock); | 1519 | spin_lock_irq(¤t->sighand->siglock); |
1545 | killed = sigkill_pending(current); | 1520 | if (sigkill_pending(current)) |
1521 | return; | ||
1546 | } | 1522 | } |
1547 | 1523 | ||
1548 | /* | 1524 | /* |
@@ -1559,7 +1535,7 @@ static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) | |||
1559 | __set_current_state(TASK_TRACED); | 1535 | __set_current_state(TASK_TRACED); |
1560 | spin_unlock_irq(¤t->sighand->siglock); | 1536 | spin_unlock_irq(¤t->sighand->siglock); |
1561 | read_lock(&tasklist_lock); | 1537 | read_lock(&tasklist_lock); |
1562 | if (!unlikely(killed) && may_ptrace_stop()) { | 1538 | if (may_ptrace_stop()) { |
1563 | do_notify_parent_cldstop(current, CLD_TRAPPED); | 1539 | do_notify_parent_cldstop(current, CLD_TRAPPED); |
1564 | read_unlock(&tasklist_lock); | 1540 | read_unlock(&tasklist_lock); |
1565 | schedule(); | 1541 | schedule(); |
@@ -1658,8 +1634,7 @@ static int do_signal_stop(int signr) | |||
1658 | } else { | 1634 | } else { |
1659 | struct task_struct *t; | 1635 | struct task_struct *t; |
1660 | 1636 | ||
1661 | if (unlikely((sig->flags & (SIGNAL_STOP_DEQUEUED | SIGNAL_UNKILLABLE)) | 1637 | if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) || |
1662 | != SIGNAL_STOP_DEQUEUED) || | ||
1663 | unlikely(signal_group_exit(sig))) | 1638 | unlikely(signal_group_exit(sig))) |
1664 | return 0; | 1639 | return 0; |
1665 | /* | 1640 | /* |
@@ -1920,7 +1895,6 @@ EXPORT_SYMBOL(recalc_sigpending); | |||
1920 | EXPORT_SYMBOL_GPL(dequeue_signal); | 1895 | EXPORT_SYMBOL_GPL(dequeue_signal); |
1921 | EXPORT_SYMBOL(flush_signals); | 1896 | EXPORT_SYMBOL(flush_signals); |
1922 | EXPORT_SYMBOL(force_sig); | 1897 | EXPORT_SYMBOL(force_sig); |
1923 | EXPORT_SYMBOL(kill_proc); | ||
1924 | EXPORT_SYMBOL(ptrace_notify); | 1898 | EXPORT_SYMBOL(ptrace_notify); |
1925 | EXPORT_SYMBOL(send_sig); | 1899 | EXPORT_SYMBOL(send_sig); |
1926 | EXPORT_SYMBOL(send_sig_info); | 1900 | EXPORT_SYMBOL(send_sig_info); |
@@ -2196,7 +2170,7 @@ sys_rt_sigtimedwait(const sigset_t __user *uthese, | |||
2196 | } | 2170 | } |
2197 | 2171 | ||
2198 | asmlinkage long | 2172 | asmlinkage long |
2199 | sys_kill(int pid, int sig) | 2173 | sys_kill(pid_t pid, int sig) |
2200 | { | 2174 | { |
2201 | struct siginfo info; | 2175 | struct siginfo info; |
2202 | 2176 | ||
@@ -2209,7 +2183,7 @@ sys_kill(int pid, int sig) | |||
2209 | return kill_something_info(sig, &info, pid); | 2183 | return kill_something_info(sig, &info, pid); |
2210 | } | 2184 | } |
2211 | 2185 | ||
2212 | static int do_tkill(int tgid, int pid, int sig) | 2186 | static int do_tkill(pid_t tgid, pid_t pid, int sig) |
2213 | { | 2187 | { |
2214 | int error; | 2188 | int error; |
2215 | struct siginfo info; | 2189 | struct siginfo info; |
@@ -2255,7 +2229,7 @@ static int do_tkill(int tgid, int pid, int sig) | |||
2255 | * exists but it's not belonging to the target process anymore. This | 2229 | * exists but it's not belonging to the target process anymore. This |
2256 | * method solves the problem of threads exiting and PIDs getting reused. | 2230 | * method solves the problem of threads exiting and PIDs getting reused. |
2257 | */ | 2231 | */ |
2258 | asmlinkage long sys_tgkill(int tgid, int pid, int sig) | 2232 | asmlinkage long sys_tgkill(pid_t tgid, pid_t pid, int sig) |
2259 | { | 2233 | { |
2260 | /* This is only valid for single tasks */ | 2234 | /* This is only valid for single tasks */ |
2261 | if (pid <= 0 || tgid <= 0) | 2235 | if (pid <= 0 || tgid <= 0) |
@@ -2268,7 +2242,7 @@ asmlinkage long sys_tgkill(int tgid, int pid, int sig) | |||
2268 | * Send a signal to only one task, even if it's a CLONE_THREAD task. | 2242 | * Send a signal to only one task, even if it's a CLONE_THREAD task. |
2269 | */ | 2243 | */ |
2270 | asmlinkage long | 2244 | asmlinkage long |
2271 | sys_tkill(int pid, int sig) | 2245 | sys_tkill(pid_t pid, int sig) |
2272 | { | 2246 | { |
2273 | /* This is only valid for single tasks */ | 2247 | /* This is only valid for single tasks */ |
2274 | if (pid <= 0) | 2248 | if (pid <= 0) |
@@ -2278,7 +2252,7 @@ sys_tkill(int pid, int sig) | |||
2278 | } | 2252 | } |
2279 | 2253 | ||
2280 | asmlinkage long | 2254 | asmlinkage long |
2281 | sys_rt_sigqueueinfo(int pid, int sig, siginfo_t __user *uinfo) | 2255 | sys_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t __user *uinfo) |
2282 | { | 2256 | { |
2283 | siginfo_t info; | 2257 | siginfo_t info; |
2284 | 2258 | ||
diff --git a/kernel/softirq.c b/kernel/softirq.c index 81e2fe0f983a..f6b03d56c2bf 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c | |||
@@ -286,7 +286,7 @@ void irq_exit(void) | |||
286 | #ifdef CONFIG_NO_HZ | 286 | #ifdef CONFIG_NO_HZ |
287 | /* Make sure that timer wheel updates are propagated */ | 287 | /* Make sure that timer wheel updates are propagated */ |
288 | if (!in_interrupt() && idle_cpu(smp_processor_id()) && !need_resched()) | 288 | if (!in_interrupt() && idle_cpu(smp_processor_id()) && !need_resched()) |
289 | tick_nohz_stop_sched_tick(); | 289 | tick_nohz_stop_sched_tick(0); |
290 | rcu_irq_exit(); | 290 | rcu_irq_exit(); |
291 | #endif | 291 | #endif |
292 | preempt_enable_no_resched(); | 292 | preempt_enable_no_resched(); |
diff --git a/kernel/softlockup.c b/kernel/softlockup.c index a272d78185eb..7bd8d1aadd5d 100644 --- a/kernel/softlockup.c +++ b/kernel/softlockup.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/delay.h> | 13 | #include <linux/delay.h> |
14 | #include <linux/freezer.h> | 14 | #include <linux/freezer.h> |
15 | #include <linux/kthread.h> | 15 | #include <linux/kthread.h> |
16 | #include <linux/lockdep.h> | ||
16 | #include <linux/notifier.h> | 17 | #include <linux/notifier.h> |
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
18 | 19 | ||
@@ -25,7 +26,22 @@ static DEFINE_PER_CPU(unsigned long, print_timestamp); | |||
25 | static DEFINE_PER_CPU(struct task_struct *, watchdog_task); | 26 | static DEFINE_PER_CPU(struct task_struct *, watchdog_task); |
26 | 27 | ||
27 | static int __read_mostly did_panic; | 28 | static int __read_mostly did_panic; |
28 | unsigned long __read_mostly softlockup_thresh = 60; | 29 | int __read_mostly softlockup_thresh = 60; |
30 | |||
31 | /* | ||
32 | * Should we panic (and reboot, if panic_timeout= is set) when a | ||
33 | * soft-lockup occurs: | ||
34 | */ | ||
35 | unsigned int __read_mostly softlockup_panic = | ||
36 | CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE; | ||
37 | |||
38 | static int __init softlockup_panic_setup(char *str) | ||
39 | { | ||
40 | softlockup_panic = simple_strtoul(str, NULL, 0); | ||
41 | |||
42 | return 1; | ||
43 | } | ||
44 | __setup("softlockup_panic=", softlockup_panic_setup); | ||
29 | 45 | ||
30 | static int | 46 | static int |
31 | softlock_panic(struct notifier_block *this, unsigned long event, void *ptr) | 47 | softlock_panic(struct notifier_block *this, unsigned long event, void *ptr) |
@@ -84,6 +100,14 @@ void softlockup_tick(void) | |||
84 | struct pt_regs *regs = get_irq_regs(); | 100 | struct pt_regs *regs = get_irq_regs(); |
85 | unsigned long now; | 101 | unsigned long now; |
86 | 102 | ||
103 | /* Is detection switched off? */ | ||
104 | if (!per_cpu(watchdog_task, this_cpu) || softlockup_thresh <= 0) { | ||
105 | /* Be sure we don't false trigger if switched back on */ | ||
106 | if (touch_timestamp) | ||
107 | per_cpu(touch_timestamp, this_cpu) = 0; | ||
108 | return; | ||
109 | } | ||
110 | |||
87 | if (touch_timestamp == 0) { | 111 | if (touch_timestamp == 0) { |
88 | __touch_softlockup_watchdog(); | 112 | __touch_softlockup_watchdog(); |
89 | return; | 113 | return; |
@@ -92,11 +116,8 @@ void softlockup_tick(void) | |||
92 | print_timestamp = per_cpu(print_timestamp, this_cpu); | 116 | print_timestamp = per_cpu(print_timestamp, this_cpu); |
93 | 117 | ||
94 | /* report at most once a second */ | 118 | /* report at most once a second */ |
95 | if ((print_timestamp >= touch_timestamp && | 119 | if (print_timestamp == touch_timestamp || did_panic) |
96 | print_timestamp < (touch_timestamp + 1)) || | ||
97 | did_panic || !per_cpu(watchdog_task, this_cpu)) { | ||
98 | return; | 120 | return; |
99 | } | ||
100 | 121 | ||
101 | /* do not print during early bootup: */ | 122 | /* do not print during early bootup: */ |
102 | if (unlikely(system_state != SYSTEM_RUNNING)) { | 123 | if (unlikely(system_state != SYSTEM_RUNNING)) { |
@@ -106,8 +127,11 @@ void softlockup_tick(void) | |||
106 | 127 | ||
107 | now = get_timestamp(this_cpu); | 128 | now = get_timestamp(this_cpu); |
108 | 129 | ||
109 | /* Wake up the high-prio watchdog task every second: */ | 130 | /* |
110 | if (now > (touch_timestamp + 1)) | 131 | * Wake up the high-prio watchdog task twice per |
132 | * threshold timespan. | ||
133 | */ | ||
134 | if (now > touch_timestamp + softlockup_thresh/2) | ||
111 | wake_up_process(per_cpu(watchdog_task, this_cpu)); | 135 | wake_up_process(per_cpu(watchdog_task, this_cpu)); |
112 | 136 | ||
113 | /* Warn about unreasonable delays: */ | 137 | /* Warn about unreasonable delays: */ |
@@ -121,11 +145,15 @@ void softlockup_tick(void) | |||
121 | this_cpu, now - touch_timestamp, | 145 | this_cpu, now - touch_timestamp, |
122 | current->comm, task_pid_nr(current)); | 146 | current->comm, task_pid_nr(current)); |
123 | print_modules(); | 147 | print_modules(); |
148 | print_irqtrace_events(current); | ||
124 | if (regs) | 149 | if (regs) |
125 | show_regs(regs); | 150 | show_regs(regs); |
126 | else | 151 | else |
127 | dump_stack(); | 152 | dump_stack(); |
128 | spin_unlock(&print_lock); | 153 | spin_unlock(&print_lock); |
154 | |||
155 | if (softlockup_panic) | ||
156 | panic("softlockup: hung tasks"); | ||
129 | } | 157 | } |
130 | 158 | ||
131 | /* | 159 | /* |
@@ -178,6 +206,9 @@ static void check_hung_task(struct task_struct *t, unsigned long now) | |||
178 | 206 | ||
179 | t->last_switch_timestamp = now; | 207 | t->last_switch_timestamp = now; |
180 | touch_nmi_watchdog(); | 208 | touch_nmi_watchdog(); |
209 | |||
210 | if (softlockup_panic) | ||
211 | panic("softlockup: blocked tasks"); | ||
181 | } | 212 | } |
182 | 213 | ||
183 | /* | 214 | /* |
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index ba9b2054ecbd..738b411ff2d3 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c | |||
@@ -33,8 +33,9 @@ static int stopmachine(void *cpu) | |||
33 | { | 33 | { |
34 | int irqs_disabled = 0; | 34 | int irqs_disabled = 0; |
35 | int prepared = 0; | 35 | int prepared = 0; |
36 | cpumask_of_cpu_ptr(cpumask, (int)(long)cpu); | ||
36 | 37 | ||
37 | set_cpus_allowed_ptr(current, &cpumask_of_cpu((int)(long)cpu)); | 38 | set_cpus_allowed_ptr(current, cpumask); |
38 | 39 | ||
39 | /* Ack: we are alive */ | 40 | /* Ack: we are alive */ |
40 | smp_mb(); /* Theoretically the ack = 0 might not be on this CPU yet. */ | 41 | smp_mb(); /* Theoretically the ack = 0 might not be on this CPU yet. */ |
diff --git a/kernel/sys.c b/kernel/sys.c index 14e97282eb6c..0c9d3fa1f5ff 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -1343,8 +1343,6 @@ EXPORT_SYMBOL(in_egroup_p); | |||
1343 | 1343 | ||
1344 | DECLARE_RWSEM(uts_sem); | 1344 | DECLARE_RWSEM(uts_sem); |
1345 | 1345 | ||
1346 | EXPORT_SYMBOL(uts_sem); | ||
1347 | |||
1348 | asmlinkage long sys_newuname(struct new_utsname __user * name) | 1346 | asmlinkage long sys_newuname(struct new_utsname __user * name) |
1349 | { | 1347 | { |
1350 | int errno = 0; | 1348 | int errno = 0; |
@@ -1795,7 +1793,7 @@ int orderly_poweroff(bool force) | |||
1795 | goto out; | 1793 | goto out; |
1796 | } | 1794 | } |
1797 | 1795 | ||
1798 | info = call_usermodehelper_setup(argv[0], argv, envp); | 1796 | info = call_usermodehelper_setup(argv[0], argv, envp, GFP_ATOMIC); |
1799 | if (info == NULL) { | 1797 | if (info == NULL) { |
1800 | argv_free(argv); | 1798 | argv_free(argv); |
1801 | goto out; | 1799 | goto out; |
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 5b9b467de070..08d6e1bb99ac 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c | |||
@@ -31,6 +31,7 @@ cond_syscall(sys_socketpair); | |||
31 | cond_syscall(sys_bind); | 31 | cond_syscall(sys_bind); |
32 | cond_syscall(sys_listen); | 32 | cond_syscall(sys_listen); |
33 | cond_syscall(sys_accept); | 33 | cond_syscall(sys_accept); |
34 | cond_syscall(sys_paccept); | ||
34 | cond_syscall(sys_connect); | 35 | cond_syscall(sys_connect); |
35 | cond_syscall(sys_getsockname); | 36 | cond_syscall(sys_getsockname); |
36 | cond_syscall(sys_getpeername); | 37 | cond_syscall(sys_getpeername); |
@@ -56,9 +57,11 @@ cond_syscall(compat_sys_set_robust_list); | |||
56 | cond_syscall(sys_get_robust_list); | 57 | cond_syscall(sys_get_robust_list); |
57 | cond_syscall(compat_sys_get_robust_list); | 58 | cond_syscall(compat_sys_get_robust_list); |
58 | cond_syscall(sys_epoll_create); | 59 | cond_syscall(sys_epoll_create); |
60 | cond_syscall(sys_epoll_create1); | ||
59 | cond_syscall(sys_epoll_ctl); | 61 | cond_syscall(sys_epoll_ctl); |
60 | cond_syscall(sys_epoll_wait); | 62 | cond_syscall(sys_epoll_wait); |
61 | cond_syscall(sys_epoll_pwait); | 63 | cond_syscall(sys_epoll_pwait); |
64 | cond_syscall(compat_sys_epoll_pwait); | ||
62 | cond_syscall(sys_semget); | 65 | cond_syscall(sys_semget); |
63 | cond_syscall(sys_semop); | 66 | cond_syscall(sys_semop); |
64 | cond_syscall(sys_semtimedop); | 67 | cond_syscall(sys_semtimedop); |
@@ -94,6 +97,7 @@ cond_syscall(sys_keyctl); | |||
94 | cond_syscall(compat_sys_keyctl); | 97 | cond_syscall(compat_sys_keyctl); |
95 | cond_syscall(compat_sys_socketcall); | 98 | cond_syscall(compat_sys_socketcall); |
96 | cond_syscall(sys_inotify_init); | 99 | cond_syscall(sys_inotify_init); |
100 | cond_syscall(sys_inotify_init1); | ||
97 | cond_syscall(sys_inotify_add_watch); | 101 | cond_syscall(sys_inotify_add_watch); |
98 | cond_syscall(sys_inotify_rm_watch); | 102 | cond_syscall(sys_inotify_rm_watch); |
99 | cond_syscall(sys_migrate_pages); | 103 | cond_syscall(sys_migrate_pages); |
@@ -154,10 +158,13 @@ cond_syscall(sys_ioprio_get); | |||
154 | 158 | ||
155 | /* New file descriptors */ | 159 | /* New file descriptors */ |
156 | cond_syscall(sys_signalfd); | 160 | cond_syscall(sys_signalfd); |
161 | cond_syscall(sys_signalfd4); | ||
157 | cond_syscall(compat_sys_signalfd); | 162 | cond_syscall(compat_sys_signalfd); |
163 | cond_syscall(compat_sys_signalfd4); | ||
158 | cond_syscall(sys_timerfd_create); | 164 | cond_syscall(sys_timerfd_create); |
159 | cond_syscall(sys_timerfd_settime); | 165 | cond_syscall(sys_timerfd_settime); |
160 | cond_syscall(sys_timerfd_gettime); | 166 | cond_syscall(sys_timerfd_gettime); |
161 | cond_syscall(compat_sys_timerfd_settime); | 167 | cond_syscall(compat_sys_timerfd_settime); |
162 | cond_syscall(compat_sys_timerfd_gettime); | 168 | cond_syscall(compat_sys_timerfd_gettime); |
163 | cond_syscall(sys_eventfd); | 169 | cond_syscall(sys_eventfd); |
170 | cond_syscall(sys_eventfd2); | ||
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 6b16e16428d8..35a50db9b6ce 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/limits.h> | 43 | #include <linux/limits.h> |
44 | #include <linux/dcache.h> | 44 | #include <linux/dcache.h> |
45 | #include <linux/syscalls.h> | 45 | #include <linux/syscalls.h> |
46 | #include <linux/vmstat.h> | ||
46 | #include <linux/nfs_fs.h> | 47 | #include <linux/nfs_fs.h> |
47 | #include <linux/acpi.h> | 48 | #include <linux/acpi.h> |
48 | #include <linux/reboot.h> | 49 | #include <linux/reboot.h> |
@@ -80,7 +81,6 @@ extern int sysctl_drop_caches; | |||
80 | extern int percpu_pagelist_fraction; | 81 | extern int percpu_pagelist_fraction; |
81 | extern int compat_log; | 82 | extern int compat_log; |
82 | extern int maps_protect; | 83 | extern int maps_protect; |
83 | extern int sysctl_stat_interval; | ||
84 | extern int latencytop_enabled; | 84 | extern int latencytop_enabled; |
85 | extern int sysctl_nr_open_min, sysctl_nr_open_max; | 85 | extern int sysctl_nr_open_min, sysctl_nr_open_max; |
86 | #ifdef CONFIG_RCU_TORTURE_TEST | 86 | #ifdef CONFIG_RCU_TORTURE_TEST |
@@ -88,12 +88,13 @@ extern int rcutorture_runnable; | |||
88 | #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ | 88 | #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ |
89 | 89 | ||
90 | /* Constants used for minimum and maximum */ | 90 | /* Constants used for minimum and maximum */ |
91 | #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM) | 91 | #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP) |
92 | static int one = 1; | 92 | static int one = 1; |
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | #ifdef CONFIG_DETECT_SOFTLOCKUP | 95 | #ifdef CONFIG_DETECT_SOFTLOCKUP |
96 | static int sixty = 60; | 96 | static int sixty = 60; |
97 | static int neg_one = -1; | ||
97 | #endif | 98 | #endif |
98 | 99 | ||
99 | #ifdef CONFIG_MMU | 100 | #ifdef CONFIG_MMU |
@@ -110,7 +111,7 @@ static int min_percpu_pagelist_fract = 8; | |||
110 | 111 | ||
111 | static int ngroups_max = NGROUPS_MAX; | 112 | static int ngroups_max = NGROUPS_MAX; |
112 | 113 | ||
113 | #ifdef CONFIG_KMOD | 114 | #ifdef CONFIG_MODULES |
114 | extern char modprobe_path[]; | 115 | extern char modprobe_path[]; |
115 | #endif | 116 | #endif |
116 | #ifdef CONFIG_CHR_DEV_SG | 117 | #ifdef CONFIG_CHR_DEV_SG |
@@ -475,7 +476,7 @@ static struct ctl_table kern_table[] = { | |||
475 | .proc_handler = &ftrace_enable_sysctl, | 476 | .proc_handler = &ftrace_enable_sysctl, |
476 | }, | 477 | }, |
477 | #endif | 478 | #endif |
478 | #ifdef CONFIG_KMOD | 479 | #ifdef CONFIG_MODULES |
479 | { | 480 | { |
480 | .ctl_name = KERN_MODPROBE, | 481 | .ctl_name = KERN_MODPROBE, |
481 | .procname = "modprobe", | 482 | .procname = "modprobe", |
@@ -623,7 +624,7 @@ static struct ctl_table kern_table[] = { | |||
623 | { | 624 | { |
624 | .ctl_name = KERN_PRINTK_RATELIMIT, | 625 | .ctl_name = KERN_PRINTK_RATELIMIT, |
625 | .procname = "printk_ratelimit", | 626 | .procname = "printk_ratelimit", |
626 | .data = &printk_ratelimit_jiffies, | 627 | .data = &printk_ratelimit_state.interval, |
627 | .maxlen = sizeof(int), | 628 | .maxlen = sizeof(int), |
628 | .mode = 0644, | 629 | .mode = 0644, |
629 | .proc_handler = &proc_dointvec_jiffies, | 630 | .proc_handler = &proc_dointvec_jiffies, |
@@ -632,7 +633,7 @@ static struct ctl_table kern_table[] = { | |||
632 | { | 633 | { |
633 | .ctl_name = KERN_PRINTK_RATELIMIT_BURST, | 634 | .ctl_name = KERN_PRINTK_RATELIMIT_BURST, |
634 | .procname = "printk_ratelimit_burst", | 635 | .procname = "printk_ratelimit_burst", |
635 | .data = &printk_ratelimit_burst, | 636 | .data = &printk_ratelimit_state.burst, |
636 | .maxlen = sizeof(int), | 637 | .maxlen = sizeof(int), |
637 | .mode = 0644, | 638 | .mode = 0644, |
638 | .proc_handler = &proc_dointvec, | 639 | .proc_handler = &proc_dointvec, |
@@ -739,13 +740,24 @@ static struct ctl_table kern_table[] = { | |||
739 | #ifdef CONFIG_DETECT_SOFTLOCKUP | 740 | #ifdef CONFIG_DETECT_SOFTLOCKUP |
740 | { | 741 | { |
741 | .ctl_name = CTL_UNNUMBERED, | 742 | .ctl_name = CTL_UNNUMBERED, |
743 | .procname = "softlockup_panic", | ||
744 | .data = &softlockup_panic, | ||
745 | .maxlen = sizeof(int), | ||
746 | .mode = 0644, | ||
747 | .proc_handler = &proc_dointvec_minmax, | ||
748 | .strategy = &sysctl_intvec, | ||
749 | .extra1 = &zero, | ||
750 | .extra2 = &one, | ||
751 | }, | ||
752 | { | ||
753 | .ctl_name = CTL_UNNUMBERED, | ||
742 | .procname = "softlockup_thresh", | 754 | .procname = "softlockup_thresh", |
743 | .data = &softlockup_thresh, | 755 | .data = &softlockup_thresh, |
744 | .maxlen = sizeof(unsigned long), | 756 | .maxlen = sizeof(int), |
745 | .mode = 0644, | 757 | .mode = 0644, |
746 | .proc_handler = &proc_doulongvec_minmax, | 758 | .proc_handler = &proc_dointvec_minmax, |
747 | .strategy = &sysctl_intvec, | 759 | .strategy = &sysctl_intvec, |
748 | .extra1 = &one, | 760 | .extra1 = &neg_one, |
749 | .extra2 = &sixty, | 761 | .extra2 = &sixty, |
750 | }, | 762 | }, |
751 | { | 763 | { |
@@ -947,7 +959,7 @@ static struct ctl_table vm_table[] = { | |||
947 | #ifdef CONFIG_HUGETLB_PAGE | 959 | #ifdef CONFIG_HUGETLB_PAGE |
948 | { | 960 | { |
949 | .procname = "nr_hugepages", | 961 | .procname = "nr_hugepages", |
950 | .data = &max_huge_pages, | 962 | .data = NULL, |
951 | .maxlen = sizeof(unsigned long), | 963 | .maxlen = sizeof(unsigned long), |
952 | .mode = 0644, | 964 | .mode = 0644, |
953 | .proc_handler = &hugetlb_sysctl_handler, | 965 | .proc_handler = &hugetlb_sysctl_handler, |
@@ -973,10 +985,12 @@ static struct ctl_table vm_table[] = { | |||
973 | { | 985 | { |
974 | .ctl_name = CTL_UNNUMBERED, | 986 | .ctl_name = CTL_UNNUMBERED, |
975 | .procname = "nr_overcommit_hugepages", | 987 | .procname = "nr_overcommit_hugepages", |
976 | .data = &sysctl_overcommit_huge_pages, | 988 | .data = NULL, |
977 | .maxlen = sizeof(sysctl_overcommit_huge_pages), | 989 | .maxlen = sizeof(unsigned long), |
978 | .mode = 0644, | 990 | .mode = 0644, |
979 | .proc_handler = &hugetlb_overcommit_handler, | 991 | .proc_handler = &hugetlb_overcommit_handler, |
992 | .extra1 = (void *)&hugetlb_zero, | ||
993 | .extra2 = (void *)&hugetlb_infinity, | ||
980 | }, | 994 | }, |
981 | #endif | 995 | #endif |
982 | { | 996 | { |
diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c index c09350d564f2..c35da23ab8fb 100644 --- a/kernel/sysctl_check.c +++ b/kernel/sysctl_check.c | |||
@@ -1532,6 +1532,8 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table) | |||
1532 | sysctl_check_leaf(namespaces, table, &fail); | 1532 | sysctl_check_leaf(namespaces, table, &fail); |
1533 | } | 1533 | } |
1534 | sysctl_check_bin_path(table, &fail); | 1534 | sysctl_check_bin_path(table, &fail); |
1535 | if (table->mode > 0777) | ||
1536 | set_fail(&fail, table, "bogus .mode"); | ||
1535 | if (fail) { | 1537 | if (fail) { |
1536 | set_fail(&fail, table, NULL); | 1538 | set_fail(&fail, table, NULL); |
1537 | error = -EINVAL; | 1539 | error = -EINVAL; |
diff --git a/kernel/taskstats.c b/kernel/taskstats.c index 4a23517169a6..bd6be76303cf 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c | |||
@@ -35,7 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | #define TASKSTATS_CPUMASK_MAXLEN (100+6*NR_CPUS) | 36 | #define TASKSTATS_CPUMASK_MAXLEN (100+6*NR_CPUS) |
37 | 37 | ||
38 | static DEFINE_PER_CPU(__u32, taskstats_seqnum) = { 0 }; | 38 | static DEFINE_PER_CPU(__u32, taskstats_seqnum); |
39 | static int family_registered; | 39 | static int family_registered; |
40 | struct kmem_cache *taskstats_cache; | 40 | struct kmem_cache *taskstats_cache; |
41 | 41 | ||
@@ -301,7 +301,7 @@ static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd) | |||
301 | return -EINVAL; | 301 | return -EINVAL; |
302 | 302 | ||
303 | if (isadd == REGISTER) { | 303 | if (isadd == REGISTER) { |
304 | for_each_cpu_mask(cpu, mask) { | 304 | for_each_cpu_mask_nr(cpu, mask) { |
305 | s = kmalloc_node(sizeof(struct listener), GFP_KERNEL, | 305 | s = kmalloc_node(sizeof(struct listener), GFP_KERNEL, |
306 | cpu_to_node(cpu)); | 306 | cpu_to_node(cpu)); |
307 | if (!s) | 307 | if (!s) |
@@ -320,7 +320,7 @@ static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd) | |||
320 | 320 | ||
321 | /* Deregister or cleanup */ | 321 | /* Deregister or cleanup */ |
322 | cleanup: | 322 | cleanup: |
323 | for_each_cpu_mask(cpu, mask) { | 323 | for_each_cpu_mask_nr(cpu, mask) { |
324 | listeners = &per_cpu(listener_array, cpu); | 324 | listeners = &per_cpu(listener_array, cpu); |
325 | down_write(&listeners->sem); | 325 | down_write(&listeners->sem); |
326 | list_for_each_entry_safe(s, tmp, &listeners->list, list) { | 326 | list_for_each_entry_safe(s, tmp, &listeners->list, list) { |
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index dadde5361f32..093d4acf993b 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c | |||
@@ -145,9 +145,9 @@ static void clocksource_watchdog(unsigned long data) | |||
145 | * Cycle through CPUs to check if the CPUs stay | 145 | * Cycle through CPUs to check if the CPUs stay |
146 | * synchronized to each other. | 146 | * synchronized to each other. |
147 | */ | 147 | */ |
148 | int next_cpu = next_cpu(raw_smp_processor_id(), cpu_online_map); | 148 | int next_cpu = next_cpu_nr(raw_smp_processor_id(), cpu_online_map); |
149 | 149 | ||
150 | if (next_cpu >= NR_CPUS) | 150 | if (next_cpu >= nr_cpu_ids) |
151 | next_cpu = first_cpu(cpu_online_map); | 151 | next_cpu = first_cpu(cpu_online_map); |
152 | watchdog_timer.expires += WATCHDOG_INTERVAL; | 152 | watchdog_timer.expires += WATCHDOG_INTERVAL; |
153 | add_timer_on(&watchdog_timer, next_cpu); | 153 | add_timer_on(&watchdog_timer, next_cpu); |
@@ -376,7 +376,8 @@ void clocksource_unregister(struct clocksource *cs) | |||
376 | * Provides sysfs interface for listing current clocksource. | 376 | * Provides sysfs interface for listing current clocksource. |
377 | */ | 377 | */ |
378 | static ssize_t | 378 | static ssize_t |
379 | sysfs_show_current_clocksources(struct sys_device *dev, char *buf) | 379 | sysfs_show_current_clocksources(struct sys_device *dev, |
380 | struct sysdev_attribute *attr, char *buf) | ||
380 | { | 381 | { |
381 | ssize_t count = 0; | 382 | ssize_t count = 0; |
382 | 383 | ||
@@ -397,6 +398,7 @@ sysfs_show_current_clocksources(struct sys_device *dev, char *buf) | |||
397 | * clocksource selction. | 398 | * clocksource selction. |
398 | */ | 399 | */ |
399 | static ssize_t sysfs_override_clocksource(struct sys_device *dev, | 400 | static ssize_t sysfs_override_clocksource(struct sys_device *dev, |
401 | struct sysdev_attribute *attr, | ||
400 | const char *buf, size_t count) | 402 | const char *buf, size_t count) |
401 | { | 403 | { |
402 | struct clocksource *ovr = NULL; | 404 | struct clocksource *ovr = NULL; |
@@ -449,7 +451,9 @@ static ssize_t sysfs_override_clocksource(struct sys_device *dev, | |||
449 | * Provides sysfs interface for listing registered clocksources | 451 | * Provides sysfs interface for listing registered clocksources |
450 | */ | 452 | */ |
451 | static ssize_t | 453 | static ssize_t |
452 | sysfs_show_available_clocksources(struct sys_device *dev, char *buf) | 454 | sysfs_show_available_clocksources(struct sys_device *dev, |
455 | struct sysdev_attribute *attr, | ||
456 | char *buf) | ||
453 | { | 457 | { |
454 | struct clocksource *src; | 458 | struct clocksource *src; |
455 | ssize_t count = 0; | 459 | ssize_t count = 0; |
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index f48d0f09d32f..31463d370b94 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c | |||
@@ -399,8 +399,7 @@ again: | |||
399 | mask = CPU_MASK_NONE; | 399 | mask = CPU_MASK_NONE; |
400 | now = ktime_get(); | 400 | now = ktime_get(); |
401 | /* Find all expired events */ | 401 | /* Find all expired events */ |
402 | for (cpu = first_cpu(tick_broadcast_oneshot_mask); cpu != NR_CPUS; | 402 | for_each_cpu_mask_nr(cpu, tick_broadcast_oneshot_mask) { |
403 | cpu = next_cpu(cpu, tick_broadcast_oneshot_mask)) { | ||
404 | td = &per_cpu(tick_cpu_device, cpu); | 403 | td = &per_cpu(tick_cpu_device, cpu); |
405 | if (td->evtdev->next_event.tv64 <= now.tv64) | 404 | if (td->evtdev->next_event.tv64 <= now.tv64) |
406 | cpu_set(cpu, mask); | 405 | cpu_set(cpu, mask); |
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 4f3886562b8c..bf43284d6855 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c | |||
@@ -135,7 +135,7 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast) | |||
135 | */ | 135 | */ |
136 | static void tick_setup_device(struct tick_device *td, | 136 | static void tick_setup_device(struct tick_device *td, |
137 | struct clock_event_device *newdev, int cpu, | 137 | struct clock_event_device *newdev, int cpu, |
138 | cpumask_t cpumask) | 138 | const cpumask_t *cpumask) |
139 | { | 139 | { |
140 | ktime_t next_event; | 140 | ktime_t next_event; |
141 | void (*handler)(struct clock_event_device *) = NULL; | 141 | void (*handler)(struct clock_event_device *) = NULL; |
@@ -169,8 +169,8 @@ static void tick_setup_device(struct tick_device *td, | |||
169 | * When the device is not per cpu, pin the interrupt to the | 169 | * When the device is not per cpu, pin the interrupt to the |
170 | * current cpu: | 170 | * current cpu: |
171 | */ | 171 | */ |
172 | if (!cpus_equal(newdev->cpumask, cpumask)) | 172 | if (!cpus_equal(newdev->cpumask, *cpumask)) |
173 | irq_set_affinity(newdev->irq, cpumask); | 173 | irq_set_affinity(newdev->irq, *cpumask); |
174 | 174 | ||
175 | /* | 175 | /* |
176 | * When global broadcasting is active, check if the current | 176 | * When global broadcasting is active, check if the current |
@@ -196,20 +196,20 @@ static int tick_check_new_device(struct clock_event_device *newdev) | |||
196 | struct tick_device *td; | 196 | struct tick_device *td; |
197 | int cpu, ret = NOTIFY_OK; | 197 | int cpu, ret = NOTIFY_OK; |
198 | unsigned long flags; | 198 | unsigned long flags; |
199 | cpumask_t cpumask; | 199 | cpumask_of_cpu_ptr_declare(cpumask); |
200 | 200 | ||
201 | spin_lock_irqsave(&tick_device_lock, flags); | 201 | spin_lock_irqsave(&tick_device_lock, flags); |
202 | 202 | ||
203 | cpu = smp_processor_id(); | 203 | cpu = smp_processor_id(); |
204 | cpumask_of_cpu_ptr_next(cpumask, cpu); | ||
204 | if (!cpu_isset(cpu, newdev->cpumask)) | 205 | if (!cpu_isset(cpu, newdev->cpumask)) |
205 | goto out_bc; | 206 | goto out_bc; |
206 | 207 | ||
207 | td = &per_cpu(tick_cpu_device, cpu); | 208 | td = &per_cpu(tick_cpu_device, cpu); |
208 | curdev = td->evtdev; | 209 | curdev = td->evtdev; |
209 | cpumask = cpumask_of_cpu(cpu); | ||
210 | 210 | ||
211 | /* cpu local device ? */ | 211 | /* cpu local device ? */ |
212 | if (!cpus_equal(newdev->cpumask, cpumask)) { | 212 | if (!cpus_equal(newdev->cpumask, *cpumask)) { |
213 | 213 | ||
214 | /* | 214 | /* |
215 | * If the cpu affinity of the device interrupt can not | 215 | * If the cpu affinity of the device interrupt can not |
@@ -222,7 +222,7 @@ static int tick_check_new_device(struct clock_event_device *newdev) | |||
222 | * If we have a cpu local device already, do not replace it | 222 | * If we have a cpu local device already, do not replace it |
223 | * by a non cpu local device | 223 | * by a non cpu local device |
224 | */ | 224 | */ |
225 | if (curdev && cpus_equal(curdev->cpumask, cpumask)) | 225 | if (curdev && cpus_equal(curdev->cpumask, *cpumask)) |
226 | goto out_bc; | 226 | goto out_bc; |
227 | } | 227 | } |
228 | 228 | ||
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index beef7ccdf842..825b4c00fe44 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c | |||
@@ -140,8 +140,6 @@ void tick_nohz_update_jiffies(void) | |||
140 | if (!ts->tick_stopped) | 140 | if (!ts->tick_stopped) |
141 | return; | 141 | return; |
142 | 142 | ||
143 | touch_softlockup_watchdog(); | ||
144 | |||
145 | cpu_clear(cpu, nohz_cpu_mask); | 143 | cpu_clear(cpu, nohz_cpu_mask); |
146 | now = ktime_get(); | 144 | now = ktime_get(); |
147 | ts->idle_waketime = now; | 145 | ts->idle_waketime = now; |
@@ -149,6 +147,8 @@ void tick_nohz_update_jiffies(void) | |||
149 | local_irq_save(flags); | 147 | local_irq_save(flags); |
150 | tick_do_update_jiffies64(now); | 148 | tick_do_update_jiffies64(now); |
151 | local_irq_restore(flags); | 149 | local_irq_restore(flags); |
150 | |||
151 | touch_softlockup_watchdog(); | ||
152 | } | 152 | } |
153 | 153 | ||
154 | void tick_nohz_stop_idle(int cpu) | 154 | void tick_nohz_stop_idle(int cpu) |
@@ -195,7 +195,7 @@ u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) | |||
195 | * Called either from the idle loop or from irq_exit() when an idle period was | 195 | * Called either from the idle loop or from irq_exit() when an idle period was |
196 | * just interrupted by an interrupt which did not cause a reschedule. | 196 | * just interrupted by an interrupt which did not cause a reschedule. |
197 | */ | 197 | */ |
198 | void tick_nohz_stop_sched_tick(void) | 198 | void tick_nohz_stop_sched_tick(int inidle) |
199 | { | 199 | { |
200 | unsigned long seq, last_jiffies, next_jiffies, delta_jiffies, flags; | 200 | unsigned long seq, last_jiffies, next_jiffies, delta_jiffies, flags; |
201 | struct tick_sched *ts; | 201 | struct tick_sched *ts; |
@@ -224,6 +224,11 @@ void tick_nohz_stop_sched_tick(void) | |||
224 | if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) | 224 | if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) |
225 | goto end; | 225 | goto end; |
226 | 226 | ||
227 | if (!inidle && !ts->inidle) | ||
228 | goto end; | ||
229 | |||
230 | ts->inidle = 1; | ||
231 | |||
227 | if (need_resched()) | 232 | if (need_resched()) |
228 | goto end; | 233 | goto end; |
229 | 234 | ||
@@ -373,11 +378,14 @@ void tick_nohz_restart_sched_tick(void) | |||
373 | local_irq_disable(); | 378 | local_irq_disable(); |
374 | tick_nohz_stop_idle(cpu); | 379 | tick_nohz_stop_idle(cpu); |
375 | 380 | ||
376 | if (!ts->tick_stopped) { | 381 | if (!ts->inidle || !ts->tick_stopped) { |
382 | ts->inidle = 0; | ||
377 | local_irq_enable(); | 383 | local_irq_enable(); |
378 | return; | 384 | return; |
379 | } | 385 | } |
380 | 386 | ||
387 | ts->inidle = 0; | ||
388 | |||
381 | rcu_exit_nohz(); | 389 | rcu_exit_nohz(); |
382 | 390 | ||
383 | /* Update jiffies first */ | 391 | /* Update jiffies first */ |
diff --git a/kernel/trace/trace_sysprof.c b/kernel/trace/trace_sysprof.c index 2301e1e7c606..ce2d723c10e1 100644 --- a/kernel/trace/trace_sysprof.c +++ b/kernel/trace/trace_sysprof.c | |||
@@ -161,7 +161,7 @@ static void timer_notify(struct pt_regs *regs, int cpu) | |||
161 | __trace_special(tr, data, 2, regs->ip, 0); | 161 | __trace_special(tr, data, 2, regs->ip, 0); |
162 | 162 | ||
163 | while (i < sample_max_depth) { | 163 | while (i < sample_max_depth) { |
164 | frame.next_fp = 0; | 164 | frame.next_fp = NULL; |
165 | frame.return_address = 0; | 165 | frame.return_address = 0; |
166 | if (!copy_stack_frame(fp, &frame)) | 166 | if (!copy_stack_frame(fp, &frame)) |
167 | break; | 167 | break; |
@@ -213,7 +213,9 @@ static void start_stack_timers(void) | |||
213 | int cpu; | 213 | int cpu; |
214 | 214 | ||
215 | for_each_online_cpu(cpu) { | 215 | for_each_online_cpu(cpu) { |
216 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); | 216 | cpumask_of_cpu_ptr(new_mask, cpu); |
217 | |||
218 | set_cpus_allowed_ptr(current, new_mask); | ||
217 | start_stack_timer(cpu); | 219 | start_stack_timer(cpu); |
218 | } | 220 | } |
219 | set_cpus_allowed_ptr(current, &saved_mask); | 221 | set_cpus_allowed_ptr(current, &saved_mask); |
diff --git a/kernel/tsacct.c b/kernel/tsacct.c index 4ab1b584961b..3da47ccdc5e5 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c | |||
@@ -28,14 +28,14 @@ | |||
28 | void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk) | 28 | void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk) |
29 | { | 29 | { |
30 | struct timespec uptime, ts; | 30 | struct timespec uptime, ts; |
31 | s64 ac_etime; | 31 | u64 ac_etime; |
32 | 32 | ||
33 | BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); | 33 | BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); |
34 | 34 | ||
35 | /* calculate task elapsed time in timespec */ | 35 | /* calculate task elapsed time in timespec */ |
36 | do_posix_clock_monotonic_gettime(&uptime); | 36 | do_posix_clock_monotonic_gettime(&uptime); |
37 | ts = timespec_sub(uptime, tsk->start_time); | 37 | ts = timespec_sub(uptime, tsk->start_time); |
38 | /* rebase elapsed time to usec */ | 38 | /* rebase elapsed time to usec (should never be negative) */ |
39 | ac_etime = timespec_to_ns(&ts); | 39 | ac_etime = timespec_to_ns(&ts); |
40 | do_div(ac_etime, NSEC_PER_USEC); | 40 | do_div(ac_etime, NSEC_PER_USEC); |
41 | stats->ac_etime = ac_etime; | 41 | stats->ac_etime = ac_etime; |
@@ -84,9 +84,9 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p) | |||
84 | { | 84 | { |
85 | struct mm_struct *mm; | 85 | struct mm_struct *mm; |
86 | 86 | ||
87 | /* convert pages-jiffies to Mbyte-usec */ | 87 | /* convert pages-usec to Mbyte-usec */ |
88 | stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB; | 88 | stats->coremem = p->acct_rss_mem1 * PAGE_SIZE / MB; |
89 | stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB; | 89 | stats->virtmem = p->acct_vm_mem1 * PAGE_SIZE / MB; |
90 | mm = get_task_mm(p); | 90 | mm = get_task_mm(p); |
91 | if (mm) { | 91 | if (mm) { |
92 | /* adjust to KB unit */ | 92 | /* adjust to KB unit */ |
@@ -118,12 +118,19 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p) | |||
118 | void acct_update_integrals(struct task_struct *tsk) | 118 | void acct_update_integrals(struct task_struct *tsk) |
119 | { | 119 | { |
120 | if (likely(tsk->mm)) { | 120 | if (likely(tsk->mm)) { |
121 | long delta = cputime_to_jiffies( | 121 | cputime_t time, dtime; |
122 | cputime_sub(tsk->stime, tsk->acct_stimexpd)); | 122 | struct timeval value; |
123 | u64 delta; | ||
124 | |||
125 | time = tsk->stime + tsk->utime; | ||
126 | dtime = cputime_sub(time, tsk->acct_timexpd); | ||
127 | jiffies_to_timeval(cputime_to_jiffies(dtime), &value); | ||
128 | delta = value.tv_sec; | ||
129 | delta = delta * USEC_PER_SEC + value.tv_usec; | ||
123 | 130 | ||
124 | if (delta == 0) | 131 | if (delta == 0) |
125 | return; | 132 | return; |
126 | tsk->acct_stimexpd = tsk->stime; | 133 | tsk->acct_timexpd = time; |
127 | tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm); | 134 | tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm); |
128 | tsk->acct_vm_mem1 += delta * tsk->mm->total_vm; | 135 | tsk->acct_vm_mem1 += delta * tsk->mm->total_vm; |
129 | } | 136 | } |
@@ -135,7 +142,7 @@ void acct_update_integrals(struct task_struct *tsk) | |||
135 | */ | 142 | */ |
136 | void acct_clear_integrals(struct task_struct *tsk) | 143 | void acct_clear_integrals(struct task_struct *tsk) |
137 | { | 144 | { |
138 | tsk->acct_stimexpd = 0; | 145 | tsk->acct_timexpd = 0; |
139 | tsk->acct_rss_mem1 = 0; | 146 | tsk->acct_rss_mem1 = 0; |
140 | tsk->acct_vm_mem1 = 0; | 147 | tsk->acct_vm_mem1 = 0; |
141 | } | 148 | } |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ce7799540c91..ec7e4f62aaff 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -125,7 +125,7 @@ struct cpu_workqueue_struct *get_wq_data(struct work_struct *work) | |||
125 | } | 125 | } |
126 | 126 | ||
127 | static void insert_work(struct cpu_workqueue_struct *cwq, | 127 | static void insert_work(struct cpu_workqueue_struct *cwq, |
128 | struct work_struct *work, int tail) | 128 | struct work_struct *work, struct list_head *head) |
129 | { | 129 | { |
130 | set_wq_data(work, cwq); | 130 | set_wq_data(work, cwq); |
131 | /* | 131 | /* |
@@ -133,21 +133,17 @@ static void insert_work(struct cpu_workqueue_struct *cwq, | |||
133 | * result of list_add() below, see try_to_grab_pending(). | 133 | * result of list_add() below, see try_to_grab_pending(). |
134 | */ | 134 | */ |
135 | smp_wmb(); | 135 | smp_wmb(); |
136 | if (tail) | 136 | list_add_tail(&work->entry, head); |
137 | list_add_tail(&work->entry, &cwq->worklist); | ||
138 | else | ||
139 | list_add(&work->entry, &cwq->worklist); | ||
140 | wake_up(&cwq->more_work); | 137 | wake_up(&cwq->more_work); |
141 | } | 138 | } |
142 | 139 | ||
143 | /* Preempt must be disabled. */ | ||
144 | static void __queue_work(struct cpu_workqueue_struct *cwq, | 140 | static void __queue_work(struct cpu_workqueue_struct *cwq, |
145 | struct work_struct *work) | 141 | struct work_struct *work) |
146 | { | 142 | { |
147 | unsigned long flags; | 143 | unsigned long flags; |
148 | 144 | ||
149 | spin_lock_irqsave(&cwq->lock, flags); | 145 | spin_lock_irqsave(&cwq->lock, flags); |
150 | insert_work(cwq, work, 1); | 146 | insert_work(cwq, work, &cwq->worklist); |
151 | spin_unlock_irqrestore(&cwq->lock, flags); | 147 | spin_unlock_irqrestore(&cwq->lock, flags); |
152 | } | 148 | } |
153 | 149 | ||
@@ -163,17 +159,39 @@ static void __queue_work(struct cpu_workqueue_struct *cwq, | |||
163 | */ | 159 | */ |
164 | int queue_work(struct workqueue_struct *wq, struct work_struct *work) | 160 | int queue_work(struct workqueue_struct *wq, struct work_struct *work) |
165 | { | 161 | { |
162 | int ret; | ||
163 | |||
164 | ret = queue_work_on(get_cpu(), wq, work); | ||
165 | put_cpu(); | ||
166 | |||
167 | return ret; | ||
168 | } | ||
169 | EXPORT_SYMBOL_GPL(queue_work); | ||
170 | |||
171 | /** | ||
172 | * queue_work_on - queue work on specific cpu | ||
173 | * @cpu: CPU number to execute work on | ||
174 | * @wq: workqueue to use | ||
175 | * @work: work to queue | ||
176 | * | ||
177 | * Returns 0 if @work was already on a queue, non-zero otherwise. | ||
178 | * | ||
179 | * We queue the work to a specific CPU, the caller must ensure it | ||
180 | * can't go away. | ||
181 | */ | ||
182 | int | ||
183 | queue_work_on(int cpu, struct workqueue_struct *wq, struct work_struct *work) | ||
184 | { | ||
166 | int ret = 0; | 185 | int ret = 0; |
167 | 186 | ||
168 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { | 187 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { |
169 | BUG_ON(!list_empty(&work->entry)); | 188 | BUG_ON(!list_empty(&work->entry)); |
170 | __queue_work(wq_per_cpu(wq, get_cpu()), work); | 189 | __queue_work(wq_per_cpu(wq, cpu), work); |
171 | put_cpu(); | ||
172 | ret = 1; | 190 | ret = 1; |
173 | } | 191 | } |
174 | return ret; | 192 | return ret; |
175 | } | 193 | } |
176 | EXPORT_SYMBOL_GPL(queue_work); | 194 | EXPORT_SYMBOL_GPL(queue_work_on); |
177 | 195 | ||
178 | static void delayed_work_timer_fn(unsigned long __data) | 196 | static void delayed_work_timer_fn(unsigned long __data) |
179 | { | 197 | { |
@@ -337,14 +355,14 @@ static void wq_barrier_func(struct work_struct *work) | |||
337 | } | 355 | } |
338 | 356 | ||
339 | static void insert_wq_barrier(struct cpu_workqueue_struct *cwq, | 357 | static void insert_wq_barrier(struct cpu_workqueue_struct *cwq, |
340 | struct wq_barrier *barr, int tail) | 358 | struct wq_barrier *barr, struct list_head *head) |
341 | { | 359 | { |
342 | INIT_WORK(&barr->work, wq_barrier_func); | 360 | INIT_WORK(&barr->work, wq_barrier_func); |
343 | __set_bit(WORK_STRUCT_PENDING, work_data_bits(&barr->work)); | 361 | __set_bit(WORK_STRUCT_PENDING, work_data_bits(&barr->work)); |
344 | 362 | ||
345 | init_completion(&barr->done); | 363 | init_completion(&barr->done); |
346 | 364 | ||
347 | insert_work(cwq, &barr->work, tail); | 365 | insert_work(cwq, &barr->work, head); |
348 | } | 366 | } |
349 | 367 | ||
350 | static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq) | 368 | static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq) |
@@ -364,7 +382,7 @@ static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq) | |||
364 | active = 0; | 382 | active = 0; |
365 | spin_lock_irq(&cwq->lock); | 383 | spin_lock_irq(&cwq->lock); |
366 | if (!list_empty(&cwq->worklist) || cwq->current_work != NULL) { | 384 | if (!list_empty(&cwq->worklist) || cwq->current_work != NULL) { |
367 | insert_wq_barrier(cwq, &barr, 1); | 385 | insert_wq_barrier(cwq, &barr, &cwq->worklist); |
368 | active = 1; | 386 | active = 1; |
369 | } | 387 | } |
370 | spin_unlock_irq(&cwq->lock); | 388 | spin_unlock_irq(&cwq->lock); |
@@ -397,11 +415,62 @@ void flush_workqueue(struct workqueue_struct *wq) | |||
397 | might_sleep(); | 415 | might_sleep(); |
398 | lock_acquire(&wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 416 | lock_acquire(&wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); |
399 | lock_release(&wq->lockdep_map, 1, _THIS_IP_); | 417 | lock_release(&wq->lockdep_map, 1, _THIS_IP_); |
400 | for_each_cpu_mask(cpu, *cpu_map) | 418 | for_each_cpu_mask_nr(cpu, *cpu_map) |
401 | flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu)); | 419 | flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu)); |
402 | } | 420 | } |
403 | EXPORT_SYMBOL_GPL(flush_workqueue); | 421 | EXPORT_SYMBOL_GPL(flush_workqueue); |
404 | 422 | ||
423 | /** | ||
424 | * flush_work - block until a work_struct's callback has terminated | ||
425 | * @work: the work which is to be flushed | ||
426 | * | ||
427 | * Returns false if @work has already terminated. | ||
428 | * | ||
429 | * It is expected that, prior to calling flush_work(), the caller has | ||
430 | * arranged for the work to not be requeued, otherwise it doesn't make | ||
431 | * sense to use this function. | ||
432 | */ | ||
433 | int flush_work(struct work_struct *work) | ||
434 | { | ||
435 | struct cpu_workqueue_struct *cwq; | ||
436 | struct list_head *prev; | ||
437 | struct wq_barrier barr; | ||
438 | |||
439 | might_sleep(); | ||
440 | cwq = get_wq_data(work); | ||
441 | if (!cwq) | ||
442 | return 0; | ||
443 | |||
444 | lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | ||
445 | lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); | ||
446 | |||
447 | prev = NULL; | ||
448 | spin_lock_irq(&cwq->lock); | ||
449 | if (!list_empty(&work->entry)) { | ||
450 | /* | ||
451 | * See the comment near try_to_grab_pending()->smp_rmb(). | ||
452 | * If it was re-queued under us we are not going to wait. | ||
453 | */ | ||
454 | smp_rmb(); | ||
455 | if (unlikely(cwq != get_wq_data(work))) | ||
456 | goto out; | ||
457 | prev = &work->entry; | ||
458 | } else { | ||
459 | if (cwq->current_work != work) | ||
460 | goto out; | ||
461 | prev = &cwq->worklist; | ||
462 | } | ||
463 | insert_wq_barrier(cwq, &barr, prev->next); | ||
464 | out: | ||
465 | spin_unlock_irq(&cwq->lock); | ||
466 | if (!prev) | ||
467 | return 0; | ||
468 | |||
469 | wait_for_completion(&barr.done); | ||
470 | return 1; | ||
471 | } | ||
472 | EXPORT_SYMBOL_GPL(flush_work); | ||
473 | |||
405 | /* | 474 | /* |
406 | * Upon a successful return (>= 0), the caller "owns" WORK_STRUCT_PENDING bit, | 475 | * Upon a successful return (>= 0), the caller "owns" WORK_STRUCT_PENDING bit, |
407 | * so this work can't be re-armed in any way. | 476 | * so this work can't be re-armed in any way. |
@@ -449,7 +518,7 @@ static void wait_on_cpu_work(struct cpu_workqueue_struct *cwq, | |||
449 | 518 | ||
450 | spin_lock_irq(&cwq->lock); | 519 | spin_lock_irq(&cwq->lock); |
451 | if (unlikely(cwq->current_work == work)) { | 520 | if (unlikely(cwq->current_work == work)) { |
452 | insert_wq_barrier(cwq, &barr, 0); | 521 | insert_wq_barrier(cwq, &barr, cwq->worklist.next); |
453 | running = 1; | 522 | running = 1; |
454 | } | 523 | } |
455 | spin_unlock_irq(&cwq->lock); | 524 | spin_unlock_irq(&cwq->lock); |
@@ -477,7 +546,7 @@ static void wait_on_work(struct work_struct *work) | |||
477 | wq = cwq->wq; | 546 | wq = cwq->wq; |
478 | cpu_map = wq_cpu_map(wq); | 547 | cpu_map = wq_cpu_map(wq); |
479 | 548 | ||
480 | for_each_cpu_mask(cpu, *cpu_map) | 549 | for_each_cpu_mask_nr(cpu, *cpu_map) |
481 | wait_on_cpu_work(per_cpu_ptr(wq->cpu_wq, cpu), work); | 550 | wait_on_cpu_work(per_cpu_ptr(wq->cpu_wq, cpu), work); |
482 | } | 551 | } |
483 | 552 | ||
@@ -553,6 +622,19 @@ int schedule_work(struct work_struct *work) | |||
553 | } | 622 | } |
554 | EXPORT_SYMBOL(schedule_work); | 623 | EXPORT_SYMBOL(schedule_work); |
555 | 624 | ||
625 | /* | ||
626 | * schedule_work_on - put work task on a specific cpu | ||
627 | * @cpu: cpu to put the work task on | ||
628 | * @work: job to be done | ||
629 | * | ||
630 | * This puts a job on a specific cpu | ||
631 | */ | ||
632 | int schedule_work_on(int cpu, struct work_struct *work) | ||
633 | { | ||
634 | return queue_work_on(cpu, keventd_wq, work); | ||
635 | } | ||
636 | EXPORT_SYMBOL(schedule_work_on); | ||
637 | |||
556 | /** | 638 | /** |
557 | * schedule_delayed_work - put work task in global workqueue after delay | 639 | * schedule_delayed_work - put work task in global workqueue after delay |
558 | * @dwork: job to be done | 640 | * @dwork: job to be done |
@@ -607,10 +689,10 @@ int schedule_on_each_cpu(work_func_t func) | |||
607 | struct work_struct *work = per_cpu_ptr(works, cpu); | 689 | struct work_struct *work = per_cpu_ptr(works, cpu); |
608 | 690 | ||
609 | INIT_WORK(work, func); | 691 | INIT_WORK(work, func); |
610 | set_bit(WORK_STRUCT_PENDING, work_data_bits(work)); | 692 | schedule_work_on(cpu, work); |
611 | __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), work); | ||
612 | } | 693 | } |
613 | flush_workqueue(keventd_wq); | 694 | for_each_online_cpu(cpu) |
695 | flush_work(per_cpu_ptr(works, cpu)); | ||
614 | put_online_cpus(); | 696 | put_online_cpus(); |
615 | free_percpu(works); | 697 | free_percpu(works); |
616 | return 0; | 698 | return 0; |
@@ -747,7 +829,7 @@ struct workqueue_struct *__create_workqueue_key(const char *name, | |||
747 | err = create_workqueue_thread(cwq, singlethread_cpu); | 829 | err = create_workqueue_thread(cwq, singlethread_cpu); |
748 | start_workqueue_thread(cwq, -1); | 830 | start_workqueue_thread(cwq, -1); |
749 | } else { | 831 | } else { |
750 | get_online_cpus(); | 832 | cpu_maps_update_begin(); |
751 | spin_lock(&workqueue_lock); | 833 | spin_lock(&workqueue_lock); |
752 | list_add(&wq->list, &workqueues); | 834 | list_add(&wq->list, &workqueues); |
753 | spin_unlock(&workqueue_lock); | 835 | spin_unlock(&workqueue_lock); |
@@ -759,7 +841,7 @@ struct workqueue_struct *__create_workqueue_key(const char *name, | |||
759 | err = create_workqueue_thread(cwq, cpu); | 841 | err = create_workqueue_thread(cwq, cpu); |
760 | start_workqueue_thread(cwq, cpu); | 842 | start_workqueue_thread(cwq, cpu); |
761 | } | 843 | } |
762 | put_online_cpus(); | 844 | cpu_maps_update_done(); |
763 | } | 845 | } |
764 | 846 | ||
765 | if (err) { | 847 | if (err) { |
@@ -773,8 +855,8 @@ EXPORT_SYMBOL_GPL(__create_workqueue_key); | |||
773 | static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq) | 855 | static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq) |
774 | { | 856 | { |
775 | /* | 857 | /* |
776 | * Our caller is either destroy_workqueue() or CPU_DEAD, | 858 | * Our caller is either destroy_workqueue() or CPU_POST_DEAD, |
777 | * get_online_cpus() protects cwq->thread. | 859 | * cpu_add_remove_lock protects cwq->thread. |
778 | */ | 860 | */ |
779 | if (cwq->thread == NULL) | 861 | if (cwq->thread == NULL) |
780 | return; | 862 | return; |
@@ -784,7 +866,7 @@ static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq) | |||
784 | 866 | ||
785 | flush_cpu_workqueue(cwq); | 867 | flush_cpu_workqueue(cwq); |
786 | /* | 868 | /* |
787 | * If the caller is CPU_DEAD and cwq->worklist was not empty, | 869 | * If the caller is CPU_POST_DEAD and cwq->worklist was not empty, |
788 | * a concurrent flush_workqueue() can insert a barrier after us. | 870 | * a concurrent flush_workqueue() can insert a barrier after us. |
789 | * However, in that case run_workqueue() won't return and check | 871 | * However, in that case run_workqueue() won't return and check |
790 | * kthread_should_stop() until it flushes all work_struct's. | 872 | * kthread_should_stop() until it flushes all work_struct's. |
@@ -808,14 +890,14 @@ void destroy_workqueue(struct workqueue_struct *wq) | |||
808 | const cpumask_t *cpu_map = wq_cpu_map(wq); | 890 | const cpumask_t *cpu_map = wq_cpu_map(wq); |
809 | int cpu; | 891 | int cpu; |
810 | 892 | ||
811 | get_online_cpus(); | 893 | cpu_maps_update_begin(); |
812 | spin_lock(&workqueue_lock); | 894 | spin_lock(&workqueue_lock); |
813 | list_del(&wq->list); | 895 | list_del(&wq->list); |
814 | spin_unlock(&workqueue_lock); | 896 | spin_unlock(&workqueue_lock); |
815 | 897 | ||
816 | for_each_cpu_mask(cpu, *cpu_map) | 898 | for_each_cpu_mask_nr(cpu, *cpu_map) |
817 | cleanup_workqueue_thread(per_cpu_ptr(wq->cpu_wq, cpu)); | 899 | cleanup_workqueue_thread(per_cpu_ptr(wq->cpu_wq, cpu)); |
818 | put_online_cpus(); | 900 | cpu_maps_update_done(); |
819 | 901 | ||
820 | free_percpu(wq->cpu_wq); | 902 | free_percpu(wq->cpu_wq); |
821 | kfree(wq); | 903 | kfree(wq); |
@@ -829,6 +911,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
829 | unsigned int cpu = (unsigned long)hcpu; | 911 | unsigned int cpu = (unsigned long)hcpu; |
830 | struct cpu_workqueue_struct *cwq; | 912 | struct cpu_workqueue_struct *cwq; |
831 | struct workqueue_struct *wq; | 913 | struct workqueue_struct *wq; |
914 | int ret = NOTIFY_OK; | ||
832 | 915 | ||
833 | action &= ~CPU_TASKS_FROZEN; | 916 | action &= ~CPU_TASKS_FROZEN; |
834 | 917 | ||
@@ -836,7 +919,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
836 | case CPU_UP_PREPARE: | 919 | case CPU_UP_PREPARE: |
837 | cpu_set(cpu, cpu_populated_map); | 920 | cpu_set(cpu, cpu_populated_map); |
838 | } | 921 | } |
839 | 922 | undo: | |
840 | list_for_each_entry(wq, &workqueues, list) { | 923 | list_for_each_entry(wq, &workqueues, list) { |
841 | cwq = per_cpu_ptr(wq->cpu_wq, cpu); | 924 | cwq = per_cpu_ptr(wq->cpu_wq, cpu); |
842 | 925 | ||
@@ -846,7 +929,9 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
846 | break; | 929 | break; |
847 | printk(KERN_ERR "workqueue [%s] for %i failed\n", | 930 | printk(KERN_ERR "workqueue [%s] for %i failed\n", |
848 | wq->name, cpu); | 931 | wq->name, cpu); |
849 | return NOTIFY_BAD; | 932 | action = CPU_UP_CANCELED; |
933 | ret = NOTIFY_BAD; | ||
934 | goto undo; | ||
850 | 935 | ||
851 | case CPU_ONLINE: | 936 | case CPU_ONLINE: |
852 | start_workqueue_thread(cwq, cpu); | 937 | start_workqueue_thread(cwq, cpu); |
@@ -854,7 +939,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
854 | 939 | ||
855 | case CPU_UP_CANCELED: | 940 | case CPU_UP_CANCELED: |
856 | start_workqueue_thread(cwq, -1); | 941 | start_workqueue_thread(cwq, -1); |
857 | case CPU_DEAD: | 942 | case CPU_POST_DEAD: |
858 | cleanup_workqueue_thread(cwq); | 943 | cleanup_workqueue_thread(cwq); |
859 | break; | 944 | break; |
860 | } | 945 | } |
@@ -862,11 +947,11 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
862 | 947 | ||
863 | switch (action) { | 948 | switch (action) { |
864 | case CPU_UP_CANCELED: | 949 | case CPU_UP_CANCELED: |
865 | case CPU_DEAD: | 950 | case CPU_POST_DEAD: |
866 | cpu_clear(cpu, cpu_populated_map); | 951 | cpu_clear(cpu, cpu_populated_map); |
867 | } | 952 | } |
868 | 953 | ||
869 | return NOTIFY_OK; | 954 | return ret; |
870 | } | 955 | } |
871 | 956 | ||
872 | void __init init_workqueues(void) | 957 | void __init init_workqueues(void) |