diff options
Diffstat (limited to 'kernel')
35 files changed, 2451 insertions, 3568 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 2093a691f1c2..b833bd5cc127 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
| @@ -80,11 +80,9 @@ obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o | |||
| 80 | obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ | 80 | obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ |
| 81 | obj-$(CONFIG_SECCOMP) += seccomp.o | 81 | obj-$(CONFIG_SECCOMP) += seccomp.o |
| 82 | obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o | 82 | obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o |
| 83 | obj-$(CONFIG_CLASSIC_RCU) += rcuclassic.o | ||
| 84 | obj-$(CONFIG_TREE_RCU) += rcutree.o | 83 | obj-$(CONFIG_TREE_RCU) += rcutree.o |
| 85 | obj-$(CONFIG_PREEMPT_RCU) += rcupreempt.o | 84 | obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o |
| 86 | obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o | 85 | obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o |
| 87 | obj-$(CONFIG_PREEMPT_RCU_TRACE) += rcupreempt_trace.o | ||
| 88 | obj-$(CONFIG_RELAY) += relay.o | 86 | obj-$(CONFIG_RELAY) += relay.o |
| 89 | obj-$(CONFIG_SYSCTL) += utsname_sysctl.o | 87 | obj-$(CONFIG_SYSCTL) += utsname_sysctl.o |
| 90 | obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o | 88 | obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o |
diff --git a/kernel/acct.c b/kernel/acct.c index 9f3391090b3e..9a4715a2f6bf 100644 --- a/kernel/acct.c +++ b/kernel/acct.c | |||
| @@ -491,13 +491,17 @@ static void do_acct_process(struct bsd_acct_struct *acct, | |||
| 491 | u64 run_time; | 491 | u64 run_time; |
| 492 | struct timespec uptime; | 492 | struct timespec uptime; |
| 493 | struct tty_struct *tty; | 493 | struct tty_struct *tty; |
| 494 | const struct cred *orig_cred; | ||
| 495 | |||
| 496 | /* Perform file operations on behalf of whoever enabled accounting */ | ||
| 497 | orig_cred = override_creds(file->f_cred); | ||
| 494 | 498 | ||
| 495 | /* | 499 | /* |
| 496 | * First check to see if there is enough free_space to continue | 500 | * First check to see if there is enough free_space to continue |
| 497 | * the process accounting system. | 501 | * the process accounting system. |
| 498 | */ | 502 | */ |
| 499 | if (!check_free_space(acct, file)) | 503 | if (!check_free_space(acct, file)) |
| 500 | return; | 504 | goto out; |
| 501 | 505 | ||
| 502 | /* | 506 | /* |
| 503 | * Fill the accounting struct with the needed info as recorded | 507 | * Fill the accounting struct with the needed info as recorded |
| @@ -578,6 +582,8 @@ static void do_acct_process(struct bsd_acct_struct *acct, | |||
| 578 | sizeof(acct_t), &file->f_pos); | 582 | sizeof(acct_t), &file->f_pos); |
| 579 | current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim; | 583 | current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim; |
| 580 | set_fs(fs); | 584 | set_fs(fs); |
| 585 | out: | ||
| 586 | revert_creds(orig_cred); | ||
| 581 | } | 587 | } |
| 582 | 588 | ||
| 583 | /** | 589 | /** |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index b6eadfe30e7b..c7ece8f027f2 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
| @@ -600,6 +600,7 @@ static struct inode_operations cgroup_dir_inode_operations; | |||
| 600 | static struct file_operations proc_cgroupstats_operations; | 600 | static struct file_operations proc_cgroupstats_operations; |
| 601 | 601 | ||
| 602 | static struct backing_dev_info cgroup_backing_dev_info = { | 602 | static struct backing_dev_info cgroup_backing_dev_info = { |
| 603 | .name = "cgroup", | ||
| 603 | .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, | 604 | .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, |
| 604 | }; | 605 | }; |
| 605 | 606 | ||
diff --git a/kernel/cred.c b/kernel/cred.c index 1bb4d7e5d616..006fcab009d5 100644 --- a/kernel/cred.c +++ b/kernel/cred.c | |||
| @@ -18,6 +18,18 @@ | |||
| 18 | #include <linux/cn_proc.h> | 18 | #include <linux/cn_proc.h> |
| 19 | #include "cred-internals.h" | 19 | #include "cred-internals.h" |
| 20 | 20 | ||
| 21 | #if 0 | ||
| 22 | #define kdebug(FMT, ...) \ | ||
| 23 | printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) | ||
| 24 | #else | ||
| 25 | static inline __attribute__((format(printf, 1, 2))) | ||
| 26 | void no_printk(const char *fmt, ...) | ||
| 27 | { | ||
| 28 | } | ||
| 29 | #define kdebug(FMT, ...) \ | ||
| 30 | no_printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) | ||
| 31 | #endif | ||
| 32 | |||
| 21 | static struct kmem_cache *cred_jar; | 33 | static struct kmem_cache *cred_jar; |
| 22 | 34 | ||
| 23 | /* | 35 | /* |
| @@ -36,6 +48,10 @@ static struct thread_group_cred init_tgcred = { | |||
| 36 | */ | 48 | */ |
| 37 | struct cred init_cred = { | 49 | struct cred init_cred = { |
| 38 | .usage = ATOMIC_INIT(4), | 50 | .usage = ATOMIC_INIT(4), |
| 51 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 52 | .subscribers = ATOMIC_INIT(2), | ||
| 53 | .magic = CRED_MAGIC, | ||
| 54 | #endif | ||
| 39 | .securebits = SECUREBITS_DEFAULT, | 55 | .securebits = SECUREBITS_DEFAULT, |
| 40 | .cap_inheritable = CAP_INIT_INH_SET, | 56 | .cap_inheritable = CAP_INIT_INH_SET, |
| 41 | .cap_permitted = CAP_FULL_SET, | 57 | .cap_permitted = CAP_FULL_SET, |
| @@ -48,6 +64,31 @@ struct cred init_cred = { | |||
| 48 | #endif | 64 | #endif |
| 49 | }; | 65 | }; |
| 50 | 66 | ||
| 67 | static inline void set_cred_subscribers(struct cred *cred, int n) | ||
| 68 | { | ||
| 69 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 70 | atomic_set(&cred->subscribers, n); | ||
| 71 | #endif | ||
| 72 | } | ||
| 73 | |||
| 74 | static inline int read_cred_subscribers(const struct cred *cred) | ||
| 75 | { | ||
| 76 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 77 | return atomic_read(&cred->subscribers); | ||
| 78 | #else | ||
| 79 | return 0; | ||
| 80 | #endif | ||
| 81 | } | ||
| 82 | |||
| 83 | static inline void alter_cred_subscribers(const struct cred *_cred, int n) | ||
| 84 | { | ||
| 85 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 86 | struct cred *cred = (struct cred *) _cred; | ||
| 87 | |||
| 88 | atomic_add(n, &cred->subscribers); | ||
| 89 | #endif | ||
| 90 | } | ||
| 91 | |||
| 51 | /* | 92 | /* |
| 52 | * Dispose of the shared task group credentials | 93 | * Dispose of the shared task group credentials |
| 53 | */ | 94 | */ |
| @@ -85,9 +126,22 @@ static void put_cred_rcu(struct rcu_head *rcu) | |||
| 85 | { | 126 | { |
| 86 | struct cred *cred = container_of(rcu, struct cred, rcu); | 127 | struct cred *cred = container_of(rcu, struct cred, rcu); |
| 87 | 128 | ||
| 129 | kdebug("put_cred_rcu(%p)", cred); | ||
| 130 | |||
| 131 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 132 | if (cred->magic != CRED_MAGIC_DEAD || | ||
| 133 | atomic_read(&cred->usage) != 0 || | ||
| 134 | read_cred_subscribers(cred) != 0) | ||
| 135 | panic("CRED: put_cred_rcu() sees %p with" | ||
| 136 | " mag %x, put %p, usage %d, subscr %d\n", | ||
| 137 | cred, cred->magic, cred->put_addr, | ||
| 138 | atomic_read(&cred->usage), | ||
| 139 | read_cred_subscribers(cred)); | ||
| 140 | #else | ||
| 88 | if (atomic_read(&cred->usage) != 0) | 141 | if (atomic_read(&cred->usage) != 0) |
| 89 | panic("CRED: put_cred_rcu() sees %p with usage %d\n", | 142 | panic("CRED: put_cred_rcu() sees %p with usage %d\n", |
| 90 | cred, atomic_read(&cred->usage)); | 143 | cred, atomic_read(&cred->usage)); |
| 144 | #endif | ||
| 91 | 145 | ||
| 92 | security_cred_free(cred); | 146 | security_cred_free(cred); |
| 93 | key_put(cred->thread_keyring); | 147 | key_put(cred->thread_keyring); |
| @@ -106,12 +160,90 @@ static void put_cred_rcu(struct rcu_head *rcu) | |||
| 106 | */ | 160 | */ |
| 107 | void __put_cred(struct cred *cred) | 161 | void __put_cred(struct cred *cred) |
| 108 | { | 162 | { |
| 163 | kdebug("__put_cred(%p{%d,%d})", cred, | ||
| 164 | atomic_read(&cred->usage), | ||
| 165 | read_cred_subscribers(cred)); | ||
| 166 | |||
| 109 | BUG_ON(atomic_read(&cred->usage) != 0); | 167 | BUG_ON(atomic_read(&cred->usage) != 0); |
| 168 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 169 | BUG_ON(read_cred_subscribers(cred) != 0); | ||
| 170 | cred->magic = CRED_MAGIC_DEAD; | ||
| 171 | cred->put_addr = __builtin_return_address(0); | ||
| 172 | #endif | ||
| 173 | BUG_ON(cred == current->cred); | ||
| 174 | BUG_ON(cred == current->real_cred); | ||
| 110 | 175 | ||
| 111 | call_rcu(&cred->rcu, put_cred_rcu); | 176 | call_rcu(&cred->rcu, put_cred_rcu); |
| 112 | } | 177 | } |
| 113 | EXPORT_SYMBOL(__put_cred); | 178 | EXPORT_SYMBOL(__put_cred); |
| 114 | 179 | ||
| 180 | /* | ||
| 181 | * Clean up a task's credentials when it exits | ||
| 182 | */ | ||
| 183 | void exit_creds(struct task_struct *tsk) | ||
| 184 | { | ||
| 185 | struct cred *cred; | ||
| 186 | |||
| 187 | kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred, | ||
| 188 | atomic_read(&tsk->cred->usage), | ||
| 189 | read_cred_subscribers(tsk->cred)); | ||
| 190 | |||
| 191 | cred = (struct cred *) tsk->real_cred; | ||
| 192 | tsk->real_cred = NULL; | ||
| 193 | validate_creds(cred); | ||
| 194 | alter_cred_subscribers(cred, -1); | ||
| 195 | put_cred(cred); | ||
| 196 | |||
| 197 | cred = (struct cred *) tsk->cred; | ||
| 198 | tsk->cred = NULL; | ||
| 199 | validate_creds(cred); | ||
| 200 | alter_cred_subscribers(cred, -1); | ||
| 201 | put_cred(cred); | ||
| 202 | |||
| 203 | cred = (struct cred *) tsk->replacement_session_keyring; | ||
| 204 | if (cred) { | ||
| 205 | tsk->replacement_session_keyring = NULL; | ||
| 206 | validate_creds(cred); | ||
| 207 | put_cred(cred); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | /* | ||
| 212 | * Allocate blank credentials, such that the credentials can be filled in at a | ||
| 213 | * later date without risk of ENOMEM. | ||
| 214 | */ | ||
| 215 | struct cred *cred_alloc_blank(void) | ||
| 216 | { | ||
| 217 | struct cred *new; | ||
| 218 | |||
| 219 | new = kmem_cache_zalloc(cred_jar, GFP_KERNEL); | ||
| 220 | if (!new) | ||
| 221 | return NULL; | ||
| 222 | |||
| 223 | #ifdef CONFIG_KEYS | ||
| 224 | new->tgcred = kzalloc(sizeof(*new->tgcred), GFP_KERNEL); | ||
| 225 | if (!new->tgcred) { | ||
| 226 | kfree(new); | ||
| 227 | return NULL; | ||
| 228 | } | ||
| 229 | atomic_set(&new->tgcred->usage, 1); | ||
| 230 | #endif | ||
| 231 | |||
| 232 | atomic_set(&new->usage, 1); | ||
| 233 | |||
| 234 | if (security_cred_alloc_blank(new, GFP_KERNEL) < 0) | ||
| 235 | goto error; | ||
| 236 | |||
| 237 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 238 | new->magic = CRED_MAGIC; | ||
| 239 | #endif | ||
| 240 | return new; | ||
| 241 | |||
| 242 | error: | ||
| 243 | abort_creds(new); | ||
| 244 | return NULL; | ||
| 245 | } | ||
| 246 | |||
| 115 | /** | 247 | /** |
| 116 | * prepare_creds - Prepare a new set of credentials for modification | 248 | * prepare_creds - Prepare a new set of credentials for modification |
| 117 | * | 249 | * |
| @@ -132,16 +264,19 @@ struct cred *prepare_creds(void) | |||
| 132 | const struct cred *old; | 264 | const struct cred *old; |
| 133 | struct cred *new; | 265 | struct cred *new; |
| 134 | 266 | ||
| 135 | BUG_ON(atomic_read(&task->real_cred->usage) < 1); | 267 | validate_process_creds(); |
| 136 | 268 | ||
| 137 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); | 269 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); |
| 138 | if (!new) | 270 | if (!new) |
| 139 | return NULL; | 271 | return NULL; |
| 140 | 272 | ||
| 273 | kdebug("prepare_creds() alloc %p", new); | ||
| 274 | |||
| 141 | old = task->cred; | 275 | old = task->cred; |
| 142 | memcpy(new, old, sizeof(struct cred)); | 276 | memcpy(new, old, sizeof(struct cred)); |
| 143 | 277 | ||
| 144 | atomic_set(&new->usage, 1); | 278 | atomic_set(&new->usage, 1); |
| 279 | set_cred_subscribers(new, 0); | ||
| 145 | get_group_info(new->group_info); | 280 | get_group_info(new->group_info); |
| 146 | get_uid(new->user); | 281 | get_uid(new->user); |
| 147 | 282 | ||
| @@ -157,6 +292,7 @@ struct cred *prepare_creds(void) | |||
| 157 | 292 | ||
| 158 | if (security_prepare_creds(new, old, GFP_KERNEL) < 0) | 293 | if (security_prepare_creds(new, old, GFP_KERNEL) < 0) |
| 159 | goto error; | 294 | goto error; |
| 295 | validate_creds(new); | ||
| 160 | return new; | 296 | return new; |
| 161 | 297 | ||
| 162 | error: | 298 | error: |
| @@ -229,9 +365,12 @@ struct cred *prepare_usermodehelper_creds(void) | |||
| 229 | if (!new) | 365 | if (!new) |
| 230 | return NULL; | 366 | return NULL; |
| 231 | 367 | ||
| 368 | kdebug("prepare_usermodehelper_creds() alloc %p", new); | ||
| 369 | |||
| 232 | memcpy(new, &init_cred, sizeof(struct cred)); | 370 | memcpy(new, &init_cred, sizeof(struct cred)); |
| 233 | 371 | ||
| 234 | atomic_set(&new->usage, 1); | 372 | atomic_set(&new->usage, 1); |
| 373 | set_cred_subscribers(new, 0); | ||
| 235 | get_group_info(new->group_info); | 374 | get_group_info(new->group_info); |
| 236 | get_uid(new->user); | 375 | get_uid(new->user); |
| 237 | 376 | ||
| @@ -250,6 +389,7 @@ struct cred *prepare_usermodehelper_creds(void) | |||
| 250 | #endif | 389 | #endif |
| 251 | if (security_prepare_creds(new, &init_cred, GFP_ATOMIC) < 0) | 390 | if (security_prepare_creds(new, &init_cred, GFP_ATOMIC) < 0) |
| 252 | goto error; | 391 | goto error; |
| 392 | validate_creds(new); | ||
| 253 | 393 | ||
| 254 | BUG_ON(atomic_read(&new->usage) != 1); | 394 | BUG_ON(atomic_read(&new->usage) != 1); |
| 255 | return new; | 395 | return new; |
| @@ -286,6 +426,10 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
| 286 | ) { | 426 | ) { |
| 287 | p->real_cred = get_cred(p->cred); | 427 | p->real_cred = get_cred(p->cred); |
| 288 | get_cred(p->cred); | 428 | get_cred(p->cred); |
| 429 | alter_cred_subscribers(p->cred, 2); | ||
| 430 | kdebug("share_creds(%p{%d,%d})", | ||
| 431 | p->cred, atomic_read(&p->cred->usage), | ||
| 432 | read_cred_subscribers(p->cred)); | ||
| 289 | atomic_inc(&p->cred->user->processes); | 433 | atomic_inc(&p->cred->user->processes); |
| 290 | return 0; | 434 | return 0; |
| 291 | } | 435 | } |
| @@ -331,6 +475,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
| 331 | 475 | ||
| 332 | atomic_inc(&new->user->processes); | 476 | atomic_inc(&new->user->processes); |
| 333 | p->cred = p->real_cred = get_cred(new); | 477 | p->cred = p->real_cred = get_cred(new); |
| 478 | alter_cred_subscribers(new, 2); | ||
| 479 | validate_creds(new); | ||
| 334 | return 0; | 480 | return 0; |
| 335 | 481 | ||
| 336 | error_put: | 482 | error_put: |
| @@ -355,13 +501,20 @@ error_put: | |||
| 355 | int commit_creds(struct cred *new) | 501 | int commit_creds(struct cred *new) |
| 356 | { | 502 | { |
| 357 | struct task_struct *task = current; | 503 | struct task_struct *task = current; |
| 358 | const struct cred *old; | 504 | const struct cred *old = task->real_cred; |
| 359 | 505 | ||
| 360 | BUG_ON(task->cred != task->real_cred); | 506 | kdebug("commit_creds(%p{%d,%d})", new, |
| 361 | BUG_ON(atomic_read(&task->real_cred->usage) < 2); | 507 | atomic_read(&new->usage), |
| 508 | read_cred_subscribers(new)); | ||
| 509 | |||
| 510 | BUG_ON(task->cred != old); | ||
| 511 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 512 | BUG_ON(read_cred_subscribers(old) < 2); | ||
| 513 | validate_creds(old); | ||
| 514 | validate_creds(new); | ||
| 515 | #endif | ||
| 362 | BUG_ON(atomic_read(&new->usage) < 1); | 516 | BUG_ON(atomic_read(&new->usage) < 1); |
| 363 | 517 | ||
| 364 | old = task->real_cred; | ||
| 365 | security_commit_creds(new, old); | 518 | security_commit_creds(new, old); |
| 366 | 519 | ||
| 367 | get_cred(new); /* we will require a ref for the subj creds too */ | 520 | get_cred(new); /* we will require a ref for the subj creds too */ |
| @@ -390,12 +543,14 @@ int commit_creds(struct cred *new) | |||
| 390 | * cheaply with the new uid cache, so if it matters | 543 | * cheaply with the new uid cache, so if it matters |
| 391 | * we should be checking for it. -DaveM | 544 | * we should be checking for it. -DaveM |
| 392 | */ | 545 | */ |
| 546 | alter_cred_subscribers(new, 2); | ||
| 393 | if (new->user != old->user) | 547 | if (new->user != old->user) |
| 394 | atomic_inc(&new->user->processes); | 548 | atomic_inc(&new->user->processes); |
| 395 | rcu_assign_pointer(task->real_cred, new); | 549 | rcu_assign_pointer(task->real_cred, new); |
| 396 | rcu_assign_pointer(task->cred, new); | 550 | rcu_assign_pointer(task->cred, new); |
| 397 | if (new->user != old->user) | 551 | if (new->user != old->user) |
| 398 | atomic_dec(&old->user->processes); | 552 | atomic_dec(&old->user->processes); |
| 553 | alter_cred_subscribers(old, -2); | ||
| 399 | 554 | ||
| 400 | sched_switch_user(task); | 555 | sched_switch_user(task); |
| 401 | 556 | ||
| @@ -428,6 +583,13 @@ EXPORT_SYMBOL(commit_creds); | |||
| 428 | */ | 583 | */ |
| 429 | void abort_creds(struct cred *new) | 584 | void abort_creds(struct cred *new) |
| 430 | { | 585 | { |
| 586 | kdebug("abort_creds(%p{%d,%d})", new, | ||
| 587 | atomic_read(&new->usage), | ||
| 588 | read_cred_subscribers(new)); | ||
| 589 | |||
| 590 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 591 | BUG_ON(read_cred_subscribers(new) != 0); | ||
| 592 | #endif | ||
| 431 | BUG_ON(atomic_read(&new->usage) < 1); | 593 | BUG_ON(atomic_read(&new->usage) < 1); |
| 432 | put_cred(new); | 594 | put_cred(new); |
| 433 | } | 595 | } |
| @@ -444,7 +606,20 @@ const struct cred *override_creds(const struct cred *new) | |||
| 444 | { | 606 | { |
| 445 | const struct cred *old = current->cred; | 607 | const struct cred *old = current->cred; |
| 446 | 608 | ||
| 447 | rcu_assign_pointer(current->cred, get_cred(new)); | 609 | kdebug("override_creds(%p{%d,%d})", new, |
| 610 | atomic_read(&new->usage), | ||
| 611 | read_cred_subscribers(new)); | ||
| 612 | |||
| 613 | validate_creds(old); | ||
| 614 | validate_creds(new); | ||
| 615 | get_cred(new); | ||
| 616 | alter_cred_subscribers(new, 1); | ||
| 617 | rcu_assign_pointer(current->cred, new); | ||
| 618 | alter_cred_subscribers(old, -1); | ||
| 619 | |||
| 620 | kdebug("override_creds() = %p{%d,%d}", old, | ||
| 621 | atomic_read(&old->usage), | ||
| 622 | read_cred_subscribers(old)); | ||
| 448 | return old; | 623 | return old; |
| 449 | } | 624 | } |
| 450 | EXPORT_SYMBOL(override_creds); | 625 | EXPORT_SYMBOL(override_creds); |
| @@ -460,7 +635,15 @@ void revert_creds(const struct cred *old) | |||
| 460 | { | 635 | { |
| 461 | const struct cred *override = current->cred; | 636 | const struct cred *override = current->cred; |
| 462 | 637 | ||
| 638 | kdebug("revert_creds(%p{%d,%d})", old, | ||
| 639 | atomic_read(&old->usage), | ||
| 640 | read_cred_subscribers(old)); | ||
| 641 | |||
| 642 | validate_creds(old); | ||
| 643 | validate_creds(override); | ||
| 644 | alter_cred_subscribers(old, 1); | ||
| 463 | rcu_assign_pointer(current->cred, old); | 645 | rcu_assign_pointer(current->cred, old); |
| 646 | alter_cred_subscribers(override, -1); | ||
| 464 | put_cred(override); | 647 | put_cred(override); |
| 465 | } | 648 | } |
| 466 | EXPORT_SYMBOL(revert_creds); | 649 | EXPORT_SYMBOL(revert_creds); |
| @@ -502,11 +685,15 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) | |||
| 502 | if (!new) | 685 | if (!new) |
| 503 | return NULL; | 686 | return NULL; |
| 504 | 687 | ||
| 688 | kdebug("prepare_kernel_cred() alloc %p", new); | ||
| 689 | |||
| 505 | if (daemon) | 690 | if (daemon) |
| 506 | old = get_task_cred(daemon); | 691 | old = get_task_cred(daemon); |
| 507 | else | 692 | else |
| 508 | old = get_cred(&init_cred); | 693 | old = get_cred(&init_cred); |
| 509 | 694 | ||
| 695 | validate_creds(old); | ||
| 696 | |||
| 510 | *new = *old; | 697 | *new = *old; |
| 511 | get_uid(new->user); | 698 | get_uid(new->user); |
| 512 | get_group_info(new->group_info); | 699 | get_group_info(new->group_info); |
| @@ -526,7 +713,9 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) | |||
| 526 | goto error; | 713 | goto error; |
| 527 | 714 | ||
| 528 | atomic_set(&new->usage, 1); | 715 | atomic_set(&new->usage, 1); |
| 716 | set_cred_subscribers(new, 0); | ||
| 529 | put_cred(old); | 717 | put_cred(old); |
| 718 | validate_creds(new); | ||
| 530 | return new; | 719 | return new; |
| 531 | 720 | ||
| 532 | error: | 721 | error: |
| @@ -589,3 +778,95 @@ int set_create_files_as(struct cred *new, struct inode *inode) | |||
| 589 | return security_kernel_create_files_as(new, inode); | 778 | return security_kernel_create_files_as(new, inode); |
| 590 | } | 779 | } |
| 591 | EXPORT_SYMBOL(set_create_files_as); | 780 | EXPORT_SYMBOL(set_create_files_as); |
| 781 | |||
| 782 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 783 | |||
| 784 | /* | ||
| 785 | * dump invalid credentials | ||
| 786 | */ | ||
| 787 | static void dump_invalid_creds(const struct cred *cred, const char *label, | ||
| 788 | const struct task_struct *tsk) | ||
| 789 | { | ||
| 790 | printk(KERN_ERR "CRED: %s credentials: %p %s%s%s\n", | ||
| 791 | label, cred, | ||
| 792 | cred == &init_cred ? "[init]" : "", | ||
| 793 | cred == tsk->real_cred ? "[real]" : "", | ||
| 794 | cred == tsk->cred ? "[eff]" : ""); | ||
| 795 | printk(KERN_ERR "CRED: ->magic=%x, put_addr=%p\n", | ||
| 796 | cred->magic, cred->put_addr); | ||
| 797 | printk(KERN_ERR "CRED: ->usage=%d, subscr=%d\n", | ||
| 798 | atomic_read(&cred->usage), | ||
| 799 | read_cred_subscribers(cred)); | ||
| 800 | printk(KERN_ERR "CRED: ->*uid = { %d,%d,%d,%d }\n", | ||
| 801 | cred->uid, cred->euid, cred->suid, cred->fsuid); | ||
| 802 | printk(KERN_ERR "CRED: ->*gid = { %d,%d,%d,%d }\n", | ||
| 803 | cred->gid, cred->egid, cred->sgid, cred->fsgid); | ||
| 804 | #ifdef CONFIG_SECURITY | ||
| 805 | printk(KERN_ERR "CRED: ->security is %p\n", cred->security); | ||
| 806 | if ((unsigned long) cred->security >= PAGE_SIZE && | ||
| 807 | (((unsigned long) cred->security & 0xffffff00) != | ||
| 808 | (POISON_FREE << 24 | POISON_FREE << 16 | POISON_FREE << 8))) | ||
| 809 | printk(KERN_ERR "CRED: ->security {%x, %x}\n", | ||
| 810 | ((u32*)cred->security)[0], | ||
| 811 | ((u32*)cred->security)[1]); | ||
| 812 | #endif | ||
| 813 | } | ||
| 814 | |||
| 815 | /* | ||
| 816 | * report use of invalid credentials | ||
| 817 | */ | ||
| 818 | void __invalid_creds(const struct cred *cred, const char *file, unsigned line) | ||
| 819 | { | ||
| 820 | printk(KERN_ERR "CRED: Invalid credentials\n"); | ||
| 821 | printk(KERN_ERR "CRED: At %s:%u\n", file, line); | ||
| 822 | dump_invalid_creds(cred, "Specified", current); | ||
| 823 | BUG(); | ||
| 824 | } | ||
| 825 | EXPORT_SYMBOL(__invalid_creds); | ||
| 826 | |||
| 827 | /* | ||
| 828 | * check the credentials on a process | ||
| 829 | */ | ||
| 830 | void __validate_process_creds(struct task_struct *tsk, | ||
| 831 | const char *file, unsigned line) | ||
| 832 | { | ||
| 833 | if (tsk->cred == tsk->real_cred) { | ||
| 834 | if (unlikely(read_cred_subscribers(tsk->cred) < 2 || | ||
| 835 | creds_are_invalid(tsk->cred))) | ||
| 836 | goto invalid_creds; | ||
| 837 | } else { | ||
| 838 | if (unlikely(read_cred_subscribers(tsk->real_cred) < 1 || | ||
| 839 | read_cred_subscribers(tsk->cred) < 1 || | ||
| 840 | creds_are_invalid(tsk->real_cred) || | ||
| 841 | creds_are_invalid(tsk->cred))) | ||
| 842 | goto invalid_creds; | ||
| 843 | } | ||
| 844 | return; | ||
| 845 | |||
| 846 | invalid_creds: | ||
| 847 | printk(KERN_ERR "CRED: Invalid process credentials\n"); | ||
| 848 | printk(KERN_ERR "CRED: At %s:%u\n", file, line); | ||
| 849 | |||
| 850 | dump_invalid_creds(tsk->real_cred, "Real", tsk); | ||
| 851 | if (tsk->cred != tsk->real_cred) | ||
| 852 | dump_invalid_creds(tsk->cred, "Effective", tsk); | ||
| 853 | else | ||
| 854 | printk(KERN_ERR "CRED: Effective creds == Real creds\n"); | ||
| 855 | BUG(); | ||
| 856 | } | ||
| 857 | EXPORT_SYMBOL(__validate_process_creds); | ||
| 858 | |||
| 859 | /* | ||
| 860 | * check creds for do_exit() | ||
| 861 | */ | ||
| 862 | void validate_creds_for_do_exit(struct task_struct *tsk) | ||
| 863 | { | ||
| 864 | kdebug("validate_creds_for_do_exit(%p,%p{%d,%d})", | ||
| 865 | tsk->real_cred, tsk->cred, | ||
| 866 | atomic_read(&tsk->cred->usage), | ||
| 867 | read_cred_subscribers(tsk->cred)); | ||
| 868 | |||
| 869 | __validate_process_creds(tsk, __FILE__, __LINE__); | ||
| 870 | } | ||
| 871 | |||
| 872 | #endif /* CONFIG_DEBUG_CREDENTIALS */ | ||
diff --git a/kernel/exit.c b/kernel/exit.c index 869dc221733e..ae5d8660ddff 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -901,6 +901,8 @@ NORET_TYPE void do_exit(long code) | |||
| 901 | 901 | ||
| 902 | tracehook_report_exit(&code); | 902 | tracehook_report_exit(&code); |
| 903 | 903 | ||
| 904 | validate_creds_for_do_exit(tsk); | ||
| 905 | |||
| 904 | /* | 906 | /* |
| 905 | * We're taking recursive faults here in do_exit. Safest is to just | 907 | * We're taking recursive faults here in do_exit. Safest is to just |
| 906 | * leave this task alone and wait for reboot. | 908 | * leave this task alone and wait for reboot. |
| @@ -1009,7 +1011,10 @@ NORET_TYPE void do_exit(long code) | |||
| 1009 | if (tsk->splice_pipe) | 1011 | if (tsk->splice_pipe) |
| 1010 | __free_pipe_info(tsk->splice_pipe); | 1012 | __free_pipe_info(tsk->splice_pipe); |
| 1011 | 1013 | ||
| 1014 | validate_creds_for_do_exit(tsk); | ||
| 1015 | |||
| 1012 | preempt_disable(); | 1016 | preempt_disable(); |
| 1017 | exit_rcu(); | ||
| 1013 | /* causes final put_task_struct in finish_task_switch(). */ | 1018 | /* causes final put_task_struct in finish_task_switch(). */ |
| 1014 | tsk->state = TASK_DEAD; | 1019 | tsk->state = TASK_DEAD; |
| 1015 | schedule(); | 1020 | schedule(); |
diff --git a/kernel/fork.c b/kernel/fork.c index 144326b7af50..bfee931ee3fb 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
| @@ -152,8 +152,7 @@ void __put_task_struct(struct task_struct *tsk) | |||
| 152 | WARN_ON(atomic_read(&tsk->usage)); | 152 | WARN_ON(atomic_read(&tsk->usage)); |
| 153 | WARN_ON(tsk == current); | 153 | WARN_ON(tsk == current); |
| 154 | 154 | ||
| 155 | put_cred(tsk->real_cred); | 155 | exit_creds(tsk); |
| 156 | put_cred(tsk->cred); | ||
| 157 | delayacct_tsk_free(tsk); | 156 | delayacct_tsk_free(tsk); |
| 158 | 157 | ||
| 159 | if (!profile_handoff_task(tsk)) | 158 | if (!profile_handoff_task(tsk)) |
| @@ -815,11 +814,8 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
| 815 | { | 814 | { |
| 816 | struct signal_struct *sig; | 815 | struct signal_struct *sig; |
| 817 | 816 | ||
| 818 | if (clone_flags & CLONE_THREAD) { | 817 | if (clone_flags & CLONE_THREAD) |
| 819 | atomic_inc(¤t->signal->count); | ||
| 820 | atomic_inc(¤t->signal->live); | ||
| 821 | return 0; | 818 | return 0; |
| 822 | } | ||
| 823 | 819 | ||
| 824 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); | 820 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); |
| 825 | tsk->signal = sig; | 821 | tsk->signal = sig; |
| @@ -877,16 +873,6 @@ void __cleanup_signal(struct signal_struct *sig) | |||
| 877 | kmem_cache_free(signal_cachep, sig); | 873 | kmem_cache_free(signal_cachep, sig); |
| 878 | } | 874 | } |
| 879 | 875 | ||
| 880 | static void cleanup_signal(struct task_struct *tsk) | ||
| 881 | { | ||
| 882 | struct signal_struct *sig = tsk->signal; | ||
| 883 | |||
| 884 | atomic_dec(&sig->live); | ||
| 885 | |||
| 886 | if (atomic_dec_and_test(&sig->count)) | ||
| 887 | __cleanup_signal(sig); | ||
| 888 | } | ||
| 889 | |||
| 890 | static void copy_flags(unsigned long clone_flags, struct task_struct *p) | 876 | static void copy_flags(unsigned long clone_flags, struct task_struct *p) |
| 891 | { | 877 | { |
| 892 | unsigned long new_flags = p->flags; | 878 | unsigned long new_flags = p->flags; |
| @@ -1021,10 +1007,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
| 1021 | copy_flags(clone_flags, p); | 1007 | copy_flags(clone_flags, p); |
| 1022 | INIT_LIST_HEAD(&p->children); | 1008 | INIT_LIST_HEAD(&p->children); |
| 1023 | INIT_LIST_HEAD(&p->sibling); | 1009 | INIT_LIST_HEAD(&p->sibling); |
| 1024 | #ifdef CONFIG_PREEMPT_RCU | 1010 | rcu_copy_process(p); |
| 1025 | p->rcu_read_lock_nesting = 0; | ||
| 1026 | p->rcu_flipctr_idx = 0; | ||
| 1027 | #endif /* #ifdef CONFIG_PREEMPT_RCU */ | ||
| 1028 | p->vfork_done = NULL; | 1011 | p->vfork_done = NULL; |
| 1029 | spin_lock_init(&p->alloc_lock); | 1012 | spin_lock_init(&p->alloc_lock); |
| 1030 | 1013 | ||
| @@ -1239,6 +1222,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
| 1239 | } | 1222 | } |
| 1240 | 1223 | ||
| 1241 | if (clone_flags & CLONE_THREAD) { | 1224 | if (clone_flags & CLONE_THREAD) { |
| 1225 | atomic_inc(¤t->signal->count); | ||
| 1226 | atomic_inc(¤t->signal->live); | ||
| 1242 | p->group_leader = current->group_leader; | 1227 | p->group_leader = current->group_leader; |
| 1243 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); | 1228 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); |
| 1244 | } | 1229 | } |
| @@ -1282,7 +1267,8 @@ bad_fork_cleanup_mm: | |||
| 1282 | if (p->mm) | 1267 | if (p->mm) |
| 1283 | mmput(p->mm); | 1268 | mmput(p->mm); |
| 1284 | bad_fork_cleanup_signal: | 1269 | bad_fork_cleanup_signal: |
| 1285 | cleanup_signal(p); | 1270 | if (!(clone_flags & CLONE_THREAD)) |
| 1271 | __cleanup_signal(p->signal); | ||
| 1286 | bad_fork_cleanup_sighand: | 1272 | bad_fork_cleanup_sighand: |
| 1287 | __cleanup_sighand(p->sighand); | 1273 | __cleanup_sighand(p->sighand); |
| 1288 | bad_fork_cleanup_fs: | 1274 | bad_fork_cleanup_fs: |
| @@ -1307,8 +1293,7 @@ bad_fork_cleanup_put_domain: | |||
| 1307 | module_put(task_thread_info(p)->exec_domain->module); | 1293 | module_put(task_thread_info(p)->exec_domain->module); |
| 1308 | bad_fork_cleanup_count: | 1294 | bad_fork_cleanup_count: |
| 1309 | atomic_dec(&p->cred->user->processes); | 1295 | atomic_dec(&p->cred->user->processes); |
| 1310 | put_cred(p->real_cred); | 1296 | exit_creds(p); |
| 1311 | put_cred(p->cred); | ||
| 1312 | bad_fork_free: | 1297 | bad_fork_free: |
| 1313 | free_task(p); | 1298 | free_task(p); |
| 1314 | fork_out: | 1299 | fork_out: |
diff --git a/kernel/futex.c b/kernel/futex.c index e18cfbdc7190..248dd119a86e 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
| @@ -115,6 +115,9 @@ struct futex_q { | |||
| 115 | /* rt_waiter storage for requeue_pi: */ | 115 | /* rt_waiter storage for requeue_pi: */ |
| 116 | struct rt_mutex_waiter *rt_waiter; | 116 | struct rt_mutex_waiter *rt_waiter; |
| 117 | 117 | ||
| 118 | /* The expected requeue pi target futex key: */ | ||
| 119 | union futex_key *requeue_pi_key; | ||
| 120 | |||
| 118 | /* Bitset for the optional bitmasked wakeup */ | 121 | /* Bitset for the optional bitmasked wakeup */ |
| 119 | u32 bitset; | 122 | u32 bitset; |
| 120 | }; | 123 | }; |
| @@ -1089,6 +1092,10 @@ static int futex_proxy_trylock_atomic(u32 __user *pifutex, | |||
| 1089 | if (!top_waiter) | 1092 | if (!top_waiter) |
| 1090 | return 0; | 1093 | return 0; |
| 1091 | 1094 | ||
| 1095 | /* Ensure we requeue to the expected futex. */ | ||
| 1096 | if (!match_futex(top_waiter->requeue_pi_key, key2)) | ||
| 1097 | return -EINVAL; | ||
| 1098 | |||
| 1092 | /* | 1099 | /* |
| 1093 | * Try to take the lock for top_waiter. Set the FUTEX_WAITERS bit in | 1100 | * Try to take the lock for top_waiter. Set the FUTEX_WAITERS bit in |
| 1094 | * the contended case or if set_waiters is 1. The pi_state is returned | 1101 | * the contended case or if set_waiters is 1. The pi_state is returned |
| @@ -1276,6 +1283,12 @@ retry_private: | |||
| 1276 | continue; | 1283 | continue; |
| 1277 | } | 1284 | } |
| 1278 | 1285 | ||
| 1286 | /* Ensure we requeue to the expected futex for requeue_pi. */ | ||
| 1287 | if (requeue_pi && !match_futex(this->requeue_pi_key, &key2)) { | ||
| 1288 | ret = -EINVAL; | ||
| 1289 | break; | ||
| 1290 | } | ||
| 1291 | |||
| 1279 | /* | 1292 | /* |
| 1280 | * Requeue nr_requeue waiters and possibly one more in the case | 1293 | * Requeue nr_requeue waiters and possibly one more in the case |
| 1281 | * of requeue_pi if we couldn't acquire the lock atomically. | 1294 | * of requeue_pi if we couldn't acquire the lock atomically. |
| @@ -1751,6 +1764,7 @@ static int futex_wait(u32 __user *uaddr, int fshared, | |||
| 1751 | q.pi_state = NULL; | 1764 | q.pi_state = NULL; |
| 1752 | q.bitset = bitset; | 1765 | q.bitset = bitset; |
| 1753 | q.rt_waiter = NULL; | 1766 | q.rt_waiter = NULL; |
| 1767 | q.requeue_pi_key = NULL; | ||
| 1754 | 1768 | ||
| 1755 | if (abs_time) { | 1769 | if (abs_time) { |
| 1756 | to = &timeout; | 1770 | to = &timeout; |
| @@ -1858,6 +1872,7 @@ static int futex_lock_pi(u32 __user *uaddr, int fshared, | |||
| 1858 | 1872 | ||
| 1859 | q.pi_state = NULL; | 1873 | q.pi_state = NULL; |
| 1860 | q.rt_waiter = NULL; | 1874 | q.rt_waiter = NULL; |
| 1875 | q.requeue_pi_key = NULL; | ||
| 1861 | retry: | 1876 | retry: |
| 1862 | q.key = FUTEX_KEY_INIT; | 1877 | q.key = FUTEX_KEY_INIT; |
| 1863 | ret = get_futex_key(uaddr, fshared, &q.key, VERIFY_WRITE); | 1878 | ret = get_futex_key(uaddr, fshared, &q.key, VERIFY_WRITE); |
| @@ -2118,11 +2133,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb, | |||
| 2118 | * We call schedule in futex_wait_queue_me() when we enqueue and return there | 2133 | * We call schedule in futex_wait_queue_me() when we enqueue and return there |
| 2119 | * via the following: | 2134 | * via the following: |
| 2120 | * 1) wakeup on uaddr2 after an atomic lock acquisition by futex_requeue() | 2135 | * 1) wakeup on uaddr2 after an atomic lock acquisition by futex_requeue() |
| 2121 | * 2) wakeup on uaddr2 after a requeue and subsequent unlock | 2136 | * 2) wakeup on uaddr2 after a requeue |
| 2122 | * 3) signal (before or after requeue) | 2137 | * 3) signal |
| 2123 | * 4) timeout (before or after requeue) | 2138 | * 4) timeout |
| 2124 | * | 2139 | * |
| 2125 | * If 3, we setup a restart_block with futex_wait_requeue_pi() as the function. | 2140 | * If 3, cleanup and return -ERESTARTNOINTR. |
| 2126 | * | 2141 | * |
| 2127 | * If 2, we may then block on trying to take the rt_mutex and return via: | 2142 | * If 2, we may then block on trying to take the rt_mutex and return via: |
| 2128 | * 5) successful lock | 2143 | * 5) successful lock |
| @@ -2130,7 +2145,7 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb, | |||
| 2130 | * 7) timeout | 2145 | * 7) timeout |
| 2131 | * 8) other lock acquisition failure | 2146 | * 8) other lock acquisition failure |
| 2132 | * | 2147 | * |
| 2133 | * If 6, we setup a restart_block with futex_lock_pi() as the function. | 2148 | * If 6, return -EWOULDBLOCK (restarting the syscall would do the same). |
| 2134 | * | 2149 | * |
| 2135 | * If 4 or 7, we cleanup and return with -ETIMEDOUT. | 2150 | * If 4 or 7, we cleanup and return with -ETIMEDOUT. |
| 2136 | * | 2151 | * |
| @@ -2169,15 +2184,16 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared, | |||
| 2169 | debug_rt_mutex_init_waiter(&rt_waiter); | 2184 | debug_rt_mutex_init_waiter(&rt_waiter); |
| 2170 | rt_waiter.task = NULL; | 2185 | rt_waiter.task = NULL; |
| 2171 | 2186 | ||
| 2172 | q.pi_state = NULL; | ||
| 2173 | q.bitset = bitset; | ||
| 2174 | q.rt_waiter = &rt_waiter; | ||
| 2175 | |||
| 2176 | key2 = FUTEX_KEY_INIT; | 2187 | key2 = FUTEX_KEY_INIT; |
| 2177 | ret = get_futex_key(uaddr2, fshared, &key2, VERIFY_WRITE); | 2188 | ret = get_futex_key(uaddr2, fshared, &key2, VERIFY_WRITE); |
| 2178 | if (unlikely(ret != 0)) | 2189 | if (unlikely(ret != 0)) |
| 2179 | goto out; | 2190 | goto out; |
| 2180 | 2191 | ||
| 2192 | q.pi_state = NULL; | ||
| 2193 | q.bitset = bitset; | ||
| 2194 | q.rt_waiter = &rt_waiter; | ||
| 2195 | q.requeue_pi_key = &key2; | ||
| 2196 | |||
| 2181 | /* Prepare to wait on uaddr. */ | 2197 | /* Prepare to wait on uaddr. */ |
| 2182 | ret = futex_wait_setup(uaddr, val, fshared, &q, &hb); | 2198 | ret = futex_wait_setup(uaddr, val, fshared, &q, &hb); |
| 2183 | if (ret) | 2199 | if (ret) |
| @@ -2248,14 +2264,11 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared, | |||
| 2248 | rt_mutex_unlock(pi_mutex); | 2264 | rt_mutex_unlock(pi_mutex); |
| 2249 | } else if (ret == -EINTR) { | 2265 | } else if (ret == -EINTR) { |
| 2250 | /* | 2266 | /* |
| 2251 | * We've already been requeued, but we have no way to | 2267 | * We've already been requeued, but cannot restart by calling |
| 2252 | * restart by calling futex_lock_pi() directly. We | 2268 | * futex_lock_pi() directly. We could restart this syscall, but |
| 2253 | * could restart the syscall, but that will look at | 2269 | * it would detect that the user space "val" changed and return |
| 2254 | * the user space value and return right away. So we | 2270 | * -EWOULDBLOCK. Save the overhead of the restart and return |
| 2255 | * drop back with EWOULDBLOCK to tell user space that | 2271 | * -EWOULDBLOCK directly. |
| 2256 | * "val" has been changed. That's the same what the | ||
| 2257 | * restart of the syscall would do in | ||
| 2258 | * futex_wait_setup(). | ||
| 2259 | */ | 2272 | */ |
| 2260 | ret = -EWOULDBLOCK; | 2273 | ret = -EWOULDBLOCK; |
| 2261 | } | 2274 | } |
diff --git a/kernel/kmod.c b/kernel/kmod.c index 385c31a1bdbf..4e8cae2e9148 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c | |||
| @@ -78,6 +78,10 @@ int __request_module(bool wait, const char *fmt, ...) | |||
| 78 | #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */ | 78 | #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */ |
| 79 | static int kmod_loop_msg; | 79 | static int kmod_loop_msg; |
| 80 | 80 | ||
| 81 | ret = security_kernel_module_request(); | ||
| 82 | if (ret) | ||
| 83 | return ret; | ||
| 84 | |||
| 81 | va_start(args, fmt); | 85 | va_start(args, fmt); |
| 82 | ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args); | 86 | ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args); |
| 83 | va_end(args); | 87 | va_end(args); |
| @@ -462,6 +466,7 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, | |||
| 462 | int retval = 0; | 466 | int retval = 0; |
| 463 | 467 | ||
| 464 | BUG_ON(atomic_read(&sub_info->cred->usage) != 1); | 468 | BUG_ON(atomic_read(&sub_info->cred->usage) != 1); |
| 469 | validate_creds(sub_info->cred); | ||
| 465 | 470 | ||
| 466 | helper_lock(); | 471 | helper_lock(); |
| 467 | if (sub_info->path[0] == '\0') | 472 | if (sub_info->path[0] == '\0') |
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 8bbeef996c76..f74d2d7aa605 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
| @@ -42,6 +42,7 @@ | |||
| 42 | #include <linux/hash.h> | 42 | #include <linux/hash.h> |
| 43 | #include <linux/ftrace.h> | 43 | #include <linux/ftrace.h> |
| 44 | #include <linux/stringify.h> | 44 | #include <linux/stringify.h> |
| 45 | #include <linux/bitops.h> | ||
| 45 | 46 | ||
| 46 | #include <asm/sections.h> | 47 | #include <asm/sections.h> |
| 47 | 48 | ||
| @@ -366,11 +367,21 @@ static int save_trace(struct stack_trace *trace) | |||
| 366 | 367 | ||
| 367 | save_stack_trace(trace); | 368 | save_stack_trace(trace); |
| 368 | 369 | ||
| 370 | /* | ||
| 371 | * Some daft arches put -1 at the end to indicate its a full trace. | ||
| 372 | * | ||
| 373 | * <rant> this is buggy anyway, since it takes a whole extra entry so a | ||
| 374 | * complete trace that maxes out the entries provided will be reported | ||
| 375 | * as incomplete, friggin useless </rant> | ||
| 376 | */ | ||
| 377 | if (trace->entries[trace->nr_entries-1] == ULONG_MAX) | ||
| 378 | trace->nr_entries--; | ||
| 379 | |||
| 369 | trace->max_entries = trace->nr_entries; | 380 | trace->max_entries = trace->nr_entries; |
| 370 | 381 | ||
| 371 | nr_stack_trace_entries += trace->nr_entries; | 382 | nr_stack_trace_entries += trace->nr_entries; |
| 372 | 383 | ||
| 373 | if (nr_stack_trace_entries == MAX_STACK_TRACE_ENTRIES) { | 384 | if (nr_stack_trace_entries >= MAX_STACK_TRACE_ENTRIES-1) { |
| 374 | if (!debug_locks_off_graph_unlock()) | 385 | if (!debug_locks_off_graph_unlock()) |
| 375 | return 0; | 386 | return 0; |
| 376 | 387 | ||
| @@ -388,20 +399,6 @@ unsigned int nr_hardirq_chains; | |||
| 388 | unsigned int nr_softirq_chains; | 399 | unsigned int nr_softirq_chains; |
| 389 | unsigned int nr_process_chains; | 400 | unsigned int nr_process_chains; |
| 390 | unsigned int max_lockdep_depth; | 401 | unsigned int max_lockdep_depth; |
| 391 | unsigned int max_recursion_depth; | ||
| 392 | |||
| 393 | static unsigned int lockdep_dependency_gen_id; | ||
| 394 | |||
| 395 | static bool lockdep_dependency_visit(struct lock_class *source, | ||
| 396 | unsigned int depth) | ||
| 397 | { | ||
| 398 | if (!depth) | ||
| 399 | lockdep_dependency_gen_id++; | ||
| 400 | if (source->dep_gen_id == lockdep_dependency_gen_id) | ||
| 401 | return true; | ||
| 402 | source->dep_gen_id = lockdep_dependency_gen_id; | ||
| 403 | return false; | ||
| 404 | } | ||
| 405 | 402 | ||
| 406 | #ifdef CONFIG_DEBUG_LOCKDEP | 403 | #ifdef CONFIG_DEBUG_LOCKDEP |
| 407 | /* | 404 | /* |
| @@ -431,11 +428,8 @@ atomic_t redundant_softirqs_on; | |||
| 431 | atomic_t redundant_softirqs_off; | 428 | atomic_t redundant_softirqs_off; |
| 432 | atomic_t nr_unused_locks; | 429 | atomic_t nr_unused_locks; |
| 433 | atomic_t nr_cyclic_checks; | 430 | atomic_t nr_cyclic_checks; |
| 434 | atomic_t nr_cyclic_check_recursions; | ||
| 435 | atomic_t nr_find_usage_forwards_checks; | 431 | atomic_t nr_find_usage_forwards_checks; |
| 436 | atomic_t nr_find_usage_forwards_recursions; | ||
| 437 | atomic_t nr_find_usage_backwards_checks; | 432 | atomic_t nr_find_usage_backwards_checks; |
| 438 | atomic_t nr_find_usage_backwards_recursions; | ||
| 439 | #endif | 433 | #endif |
| 440 | 434 | ||
| 441 | /* | 435 | /* |
| @@ -551,58 +545,6 @@ static void lockdep_print_held_locks(struct task_struct *curr) | |||
| 551 | } | 545 | } |
| 552 | } | 546 | } |
| 553 | 547 | ||
| 554 | static void print_lock_class_header(struct lock_class *class, int depth) | ||
| 555 | { | ||
| 556 | int bit; | ||
| 557 | |||
| 558 | printk("%*s->", depth, ""); | ||
| 559 | print_lock_name(class); | ||
| 560 | printk(" ops: %lu", class->ops); | ||
| 561 | printk(" {\n"); | ||
| 562 | |||
| 563 | for (bit = 0; bit < LOCK_USAGE_STATES; bit++) { | ||
| 564 | if (class->usage_mask & (1 << bit)) { | ||
| 565 | int len = depth; | ||
| 566 | |||
| 567 | len += printk("%*s %s", depth, "", usage_str[bit]); | ||
| 568 | len += printk(" at:\n"); | ||
| 569 | print_stack_trace(class->usage_traces + bit, len); | ||
| 570 | } | ||
| 571 | } | ||
| 572 | printk("%*s }\n", depth, ""); | ||
| 573 | |||
| 574 | printk("%*s ... key at: ",depth,""); | ||
| 575 | print_ip_sym((unsigned long)class->key); | ||
| 576 | } | ||
| 577 | |||
| 578 | /* | ||
| 579 | * printk all lock dependencies starting at <entry>: | ||
| 580 | */ | ||
| 581 | static void __used | ||
| 582 | print_lock_dependencies(struct lock_class *class, int depth) | ||
| 583 | { | ||
| 584 | struct lock_list *entry; | ||
| 585 | |||
| 586 | if (lockdep_dependency_visit(class, depth)) | ||
| 587 | return; | ||
| 588 | |||
| 589 | if (DEBUG_LOCKS_WARN_ON(depth >= 20)) | ||
| 590 | return; | ||
| 591 | |||
| 592 | print_lock_class_header(class, depth); | ||
| 593 | |||
| 594 | list_for_each_entry(entry, &class->locks_after, entry) { | ||
| 595 | if (DEBUG_LOCKS_WARN_ON(!entry->class)) | ||
| 596 | return; | ||
| 597 | |||
| 598 | print_lock_dependencies(entry->class, depth + 1); | ||
| 599 | |||
| 600 | printk("%*s ... acquired at:\n",depth,""); | ||
| 601 | print_stack_trace(&entry->trace, 2); | ||
| 602 | printk("\n"); | ||
| 603 | } | ||
| 604 | } | ||
| 605 | |||
| 606 | static void print_kernel_version(void) | 548 | static void print_kernel_version(void) |
| 607 | { | 549 | { |
| 608 | printk("%s %.*s\n", init_utsname()->release, | 550 | printk("%s %.*s\n", init_utsname()->release, |
| @@ -898,22 +840,203 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | |||
| 898 | } | 840 | } |
| 899 | 841 | ||
| 900 | /* | 842 | /* |
| 843 | * For good efficiency of modular, we use power of 2 | ||
| 844 | */ | ||
| 845 | #define MAX_CIRCULAR_QUEUE_SIZE 4096UL | ||
| 846 | #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1) | ||
| 847 | |||
| 848 | /* | ||
| 849 | * The circular_queue and helpers is used to implement the | ||
| 850 | * breadth-first search(BFS)algorithem, by which we can build | ||
| 851 | * the shortest path from the next lock to be acquired to the | ||
| 852 | * previous held lock if there is a circular between them. | ||
| 853 | */ | ||
| 854 | struct circular_queue { | ||
| 855 | unsigned long element[MAX_CIRCULAR_QUEUE_SIZE]; | ||
| 856 | unsigned int front, rear; | ||
| 857 | }; | ||
| 858 | |||
| 859 | static struct circular_queue lock_cq; | ||
| 860 | |||
| 861 | unsigned int max_bfs_queue_depth; | ||
| 862 | |||
| 863 | static unsigned int lockdep_dependency_gen_id; | ||
| 864 | |||
| 865 | static inline void __cq_init(struct circular_queue *cq) | ||
| 866 | { | ||
| 867 | cq->front = cq->rear = 0; | ||
| 868 | lockdep_dependency_gen_id++; | ||
| 869 | } | ||
| 870 | |||
| 871 | static inline int __cq_empty(struct circular_queue *cq) | ||
| 872 | { | ||
| 873 | return (cq->front == cq->rear); | ||
| 874 | } | ||
| 875 | |||
| 876 | static inline int __cq_full(struct circular_queue *cq) | ||
| 877 | { | ||
| 878 | return ((cq->rear + 1) & CQ_MASK) == cq->front; | ||
| 879 | } | ||
| 880 | |||
| 881 | static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) | ||
| 882 | { | ||
| 883 | if (__cq_full(cq)) | ||
| 884 | return -1; | ||
| 885 | |||
| 886 | cq->element[cq->rear] = elem; | ||
| 887 | cq->rear = (cq->rear + 1) & CQ_MASK; | ||
| 888 | return 0; | ||
| 889 | } | ||
| 890 | |||
| 891 | static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem) | ||
| 892 | { | ||
| 893 | if (__cq_empty(cq)) | ||
| 894 | return -1; | ||
| 895 | |||
| 896 | *elem = cq->element[cq->front]; | ||
| 897 | cq->front = (cq->front + 1) & CQ_MASK; | ||
| 898 | return 0; | ||
| 899 | } | ||
| 900 | |||
| 901 | static inline unsigned int __cq_get_elem_count(struct circular_queue *cq) | ||
| 902 | { | ||
| 903 | return (cq->rear - cq->front) & CQ_MASK; | ||
| 904 | } | ||
| 905 | |||
| 906 | static inline void mark_lock_accessed(struct lock_list *lock, | ||
| 907 | struct lock_list *parent) | ||
| 908 | { | ||
| 909 | unsigned long nr; | ||
| 910 | |||
| 911 | nr = lock - list_entries; | ||
| 912 | WARN_ON(nr >= nr_list_entries); | ||
| 913 | lock->parent = parent; | ||
| 914 | lock->class->dep_gen_id = lockdep_dependency_gen_id; | ||
| 915 | } | ||
| 916 | |||
| 917 | static inline unsigned long lock_accessed(struct lock_list *lock) | ||
| 918 | { | ||
| 919 | unsigned long nr; | ||
| 920 | |||
| 921 | nr = lock - list_entries; | ||
| 922 | WARN_ON(nr >= nr_list_entries); | ||
| 923 | return lock->class->dep_gen_id == lockdep_dependency_gen_id; | ||
| 924 | } | ||
| 925 | |||
| 926 | static inline struct lock_list *get_lock_parent(struct lock_list *child) | ||
| 927 | { | ||
| 928 | return child->parent; | ||
| 929 | } | ||
| 930 | |||
| 931 | static inline int get_lock_depth(struct lock_list *child) | ||
| 932 | { | ||
| 933 | int depth = 0; | ||
| 934 | struct lock_list *parent; | ||
| 935 | |||
| 936 | while ((parent = get_lock_parent(child))) { | ||
| 937 | child = parent; | ||
| 938 | depth++; | ||
| 939 | } | ||
| 940 | return depth; | ||
| 941 | } | ||
| 942 | |||
| 943 | static int __bfs(struct lock_list *source_entry, | ||
| 944 | void *data, | ||
| 945 | int (*match)(struct lock_list *entry, void *data), | ||
| 946 | struct lock_list **target_entry, | ||
| 947 | int forward) | ||
| 948 | { | ||
| 949 | struct lock_list *entry; | ||
| 950 | struct list_head *head; | ||
| 951 | struct circular_queue *cq = &lock_cq; | ||
| 952 | int ret = 1; | ||
| 953 | |||
| 954 | if (match(source_entry, data)) { | ||
| 955 | *target_entry = source_entry; | ||
| 956 | ret = 0; | ||
| 957 | goto exit; | ||
| 958 | } | ||
| 959 | |||
| 960 | if (forward) | ||
| 961 | head = &source_entry->class->locks_after; | ||
| 962 | else | ||
| 963 | head = &source_entry->class->locks_before; | ||
| 964 | |||
| 965 | if (list_empty(head)) | ||
| 966 | goto exit; | ||
| 967 | |||
| 968 | __cq_init(cq); | ||
| 969 | __cq_enqueue(cq, (unsigned long)source_entry); | ||
| 970 | |||
| 971 | while (!__cq_empty(cq)) { | ||
| 972 | struct lock_list *lock; | ||
| 973 | |||
| 974 | __cq_dequeue(cq, (unsigned long *)&lock); | ||
| 975 | |||
| 976 | if (!lock->class) { | ||
| 977 | ret = -2; | ||
| 978 | goto exit; | ||
| 979 | } | ||
| 980 | |||
| 981 | if (forward) | ||
| 982 | head = &lock->class->locks_after; | ||
| 983 | else | ||
| 984 | head = &lock->class->locks_before; | ||
| 985 | |||
| 986 | list_for_each_entry(entry, head, entry) { | ||
| 987 | if (!lock_accessed(entry)) { | ||
| 988 | unsigned int cq_depth; | ||
| 989 | mark_lock_accessed(entry, lock); | ||
| 990 | if (match(entry, data)) { | ||
| 991 | *target_entry = entry; | ||
| 992 | ret = 0; | ||
| 993 | goto exit; | ||
| 994 | } | ||
| 995 | |||
| 996 | if (__cq_enqueue(cq, (unsigned long)entry)) { | ||
| 997 | ret = -1; | ||
| 998 | goto exit; | ||
| 999 | } | ||
| 1000 | cq_depth = __cq_get_elem_count(cq); | ||
| 1001 | if (max_bfs_queue_depth < cq_depth) | ||
| 1002 | max_bfs_queue_depth = cq_depth; | ||
| 1003 | } | ||
| 1004 | } | ||
| 1005 | } | ||
| 1006 | exit: | ||
| 1007 | return ret; | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | static inline int __bfs_forwards(struct lock_list *src_entry, | ||
| 1011 | void *data, | ||
| 1012 | int (*match)(struct lock_list *entry, void *data), | ||
| 1013 | struct lock_list **target_entry) | ||
| 1014 | { | ||
| 1015 | return __bfs(src_entry, data, match, target_entry, 1); | ||
| 1016 | |||
| 1017 | } | ||
| 1018 | |||
| 1019 | static inline int __bfs_backwards(struct lock_list *src_entry, | ||
| 1020 | void *data, | ||
| 1021 | int (*match)(struct lock_list *entry, void *data), | ||
| 1022 | struct lock_list **target_entry) | ||
| 1023 | { | ||
| 1024 | return __bfs(src_entry, data, match, target_entry, 0); | ||
| 1025 | |||
| 1026 | } | ||
| 1027 | |||
| 1028 | /* | ||
| 901 | * Recursive, forwards-direction lock-dependency checking, used for | 1029 | * Recursive, forwards-direction lock-dependency checking, used for |
| 902 | * both noncyclic checking and for hardirq-unsafe/softirq-unsafe | 1030 | * both noncyclic checking and for hardirq-unsafe/softirq-unsafe |
| 903 | * checking. | 1031 | * checking. |
| 904 | * | ||
| 905 | * (to keep the stackframe of the recursive functions small we | ||
| 906 | * use these global variables, and we also mark various helper | ||
| 907 | * functions as noinline.) | ||
| 908 | */ | 1032 | */ |
| 909 | static struct held_lock *check_source, *check_target; | ||
| 910 | 1033 | ||
| 911 | /* | 1034 | /* |
| 912 | * Print a dependency chain entry (this is only done when a deadlock | 1035 | * Print a dependency chain entry (this is only done when a deadlock |
| 913 | * has been detected): | 1036 | * has been detected): |
| 914 | */ | 1037 | */ |
| 915 | static noinline int | 1038 | static noinline int |
| 916 | print_circular_bug_entry(struct lock_list *target, unsigned int depth) | 1039 | print_circular_bug_entry(struct lock_list *target, int depth) |
| 917 | { | 1040 | { |
| 918 | if (debug_locks_silent) | 1041 | if (debug_locks_silent) |
| 919 | return 0; | 1042 | return 0; |
| @@ -930,11 +1053,13 @@ print_circular_bug_entry(struct lock_list *target, unsigned int depth) | |||
| 930 | * header first: | 1053 | * header first: |
| 931 | */ | 1054 | */ |
| 932 | static noinline int | 1055 | static noinline int |
| 933 | print_circular_bug_header(struct lock_list *entry, unsigned int depth) | 1056 | print_circular_bug_header(struct lock_list *entry, unsigned int depth, |
| 1057 | struct held_lock *check_src, | ||
| 1058 | struct held_lock *check_tgt) | ||
| 934 | { | 1059 | { |
| 935 | struct task_struct *curr = current; | 1060 | struct task_struct *curr = current; |
| 936 | 1061 | ||
| 937 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) | 1062 | if (debug_locks_silent) |
| 938 | return 0; | 1063 | return 0; |
| 939 | 1064 | ||
| 940 | printk("\n=======================================================\n"); | 1065 | printk("\n=======================================================\n"); |
| @@ -943,9 +1068,9 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth) | |||
| 943 | printk( "-------------------------------------------------------\n"); | 1068 | printk( "-------------------------------------------------------\n"); |
| 944 | printk("%s/%d is trying to acquire lock:\n", | 1069 | printk("%s/%d is trying to acquire lock:\n", |
| 945 | curr->comm, task_pid_nr(curr)); | 1070 | curr->comm, task_pid_nr(curr)); |
| 946 | print_lock(check_source); | 1071 | print_lock(check_src); |
| 947 | printk("\nbut task is already holding lock:\n"); | 1072 | printk("\nbut task is already holding lock:\n"); |
| 948 | print_lock(check_target); | 1073 | print_lock(check_tgt); |
| 949 | printk("\nwhich lock already depends on the new lock.\n\n"); | 1074 | printk("\nwhich lock already depends on the new lock.\n\n"); |
| 950 | printk("\nthe existing dependency chain (in reverse order) is:\n"); | 1075 | printk("\nthe existing dependency chain (in reverse order) is:\n"); |
| 951 | 1076 | ||
| @@ -954,19 +1079,36 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth) | |||
| 954 | return 0; | 1079 | return 0; |
| 955 | } | 1080 | } |
| 956 | 1081 | ||
| 957 | static noinline int print_circular_bug_tail(void) | 1082 | static inline int class_equal(struct lock_list *entry, void *data) |
| 1083 | { | ||
| 1084 | return entry->class == data; | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | static noinline int print_circular_bug(struct lock_list *this, | ||
| 1088 | struct lock_list *target, | ||
| 1089 | struct held_lock *check_src, | ||
| 1090 | struct held_lock *check_tgt) | ||
| 958 | { | 1091 | { |
| 959 | struct task_struct *curr = current; | 1092 | struct task_struct *curr = current; |
| 960 | struct lock_list this; | 1093 | struct lock_list *parent; |
| 1094 | int depth; | ||
| 961 | 1095 | ||
| 962 | if (debug_locks_silent) | 1096 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) |
| 963 | return 0; | 1097 | return 0; |
| 964 | 1098 | ||
| 965 | this.class = hlock_class(check_source); | 1099 | if (!save_trace(&this->trace)) |
| 966 | if (!save_trace(&this.trace)) | ||
| 967 | return 0; | 1100 | return 0; |
| 968 | 1101 | ||
| 969 | print_circular_bug_entry(&this, 0); | 1102 | depth = get_lock_depth(target); |
| 1103 | |||
| 1104 | print_circular_bug_header(target, depth, check_src, check_tgt); | ||
| 1105 | |||
| 1106 | parent = get_lock_parent(target); | ||
| 1107 | |||
| 1108 | while (parent) { | ||
| 1109 | print_circular_bug_entry(parent, --depth); | ||
| 1110 | parent = get_lock_parent(parent); | ||
| 1111 | } | ||
| 970 | 1112 | ||
| 971 | printk("\nother info that might help us debug this:\n\n"); | 1113 | printk("\nother info that might help us debug this:\n\n"); |
| 972 | lockdep_print_held_locks(curr); | 1114 | lockdep_print_held_locks(curr); |
| @@ -977,73 +1119,69 @@ static noinline int print_circular_bug_tail(void) | |||
| 977 | return 0; | 1119 | return 0; |
| 978 | } | 1120 | } |
| 979 | 1121 | ||
| 980 | #define RECURSION_LIMIT 40 | 1122 | static noinline int print_bfs_bug(int ret) |
| 981 | |||
| 982 | static int noinline print_infinite_recursion_bug(void) | ||
| 983 | { | 1123 | { |
| 984 | if (!debug_locks_off_graph_unlock()) | 1124 | if (!debug_locks_off_graph_unlock()) |
| 985 | return 0; | 1125 | return 0; |
| 986 | 1126 | ||
| 987 | WARN_ON(1); | 1127 | WARN(1, "lockdep bfs error:%d\n", ret); |
| 988 | 1128 | ||
| 989 | return 0; | 1129 | return 0; |
| 990 | } | 1130 | } |
| 991 | 1131 | ||
| 992 | unsigned long __lockdep_count_forward_deps(struct lock_class *class, | 1132 | static int noop_count(struct lock_list *entry, void *data) |
| 993 | unsigned int depth) | ||
| 994 | { | 1133 | { |
| 995 | struct lock_list *entry; | 1134 | (*(unsigned long *)data)++; |
| 996 | unsigned long ret = 1; | 1135 | return 0; |
| 1136 | } | ||
| 997 | 1137 | ||
| 998 | if (lockdep_dependency_visit(class, depth)) | 1138 | unsigned long __lockdep_count_forward_deps(struct lock_list *this) |
| 999 | return 0; | 1139 | { |
| 1140 | unsigned long count = 0; | ||
| 1141 | struct lock_list *uninitialized_var(target_entry); | ||
| 1000 | 1142 | ||
| 1001 | /* | 1143 | __bfs_forwards(this, (void *)&count, noop_count, &target_entry); |
| 1002 | * Recurse this class's dependency list: | ||
| 1003 | */ | ||
| 1004 | list_for_each_entry(entry, &class->locks_after, entry) | ||
| 1005 | ret += __lockdep_count_forward_deps(entry->class, depth + 1); | ||
| 1006 | 1144 | ||
| 1007 | return ret; | 1145 | return count; |
| 1008 | } | 1146 | } |
| 1009 | |||
| 1010 | unsigned long lockdep_count_forward_deps(struct lock_class *class) | 1147 | unsigned long lockdep_count_forward_deps(struct lock_class *class) |
| 1011 | { | 1148 | { |
| 1012 | unsigned long ret, flags; | 1149 | unsigned long ret, flags; |
| 1150 | struct lock_list this; | ||
| 1151 | |||
| 1152 | this.parent = NULL; | ||
| 1153 | this.class = class; | ||
| 1013 | 1154 | ||
| 1014 | local_irq_save(flags); | 1155 | local_irq_save(flags); |
| 1015 | __raw_spin_lock(&lockdep_lock); | 1156 | __raw_spin_lock(&lockdep_lock); |
| 1016 | ret = __lockdep_count_forward_deps(class, 0); | 1157 | ret = __lockdep_count_forward_deps(&this); |
| 1017 | __raw_spin_unlock(&lockdep_lock); | 1158 | __raw_spin_unlock(&lockdep_lock); |
| 1018 | local_irq_restore(flags); | 1159 | local_irq_restore(flags); |
| 1019 | 1160 | ||
| 1020 | return ret; | 1161 | return ret; |
| 1021 | } | 1162 | } |
| 1022 | 1163 | ||
| 1023 | unsigned long __lockdep_count_backward_deps(struct lock_class *class, | 1164 | unsigned long __lockdep_count_backward_deps(struct lock_list *this) |
| 1024 | unsigned int depth) | ||
| 1025 | { | 1165 | { |
| 1026 | struct lock_list *entry; | 1166 | unsigned long count = 0; |
| 1027 | unsigned long ret = 1; | 1167 | struct lock_list *uninitialized_var(target_entry); |
| 1028 | 1168 | ||
| 1029 | if (lockdep_dependency_visit(class, depth)) | 1169 | __bfs_backwards(this, (void *)&count, noop_count, &target_entry); |
| 1030 | return 0; | ||
| 1031 | /* | ||
| 1032 | * Recurse this class's dependency list: | ||
| 1033 | */ | ||
| 1034 | list_for_each_entry(entry, &class->locks_before, entry) | ||
| 1035 | ret += __lockdep_count_backward_deps(entry->class, depth + 1); | ||
| 1036 | 1170 | ||
| 1037 | return ret; | 1171 | return count; |
| 1038 | } | 1172 | } |
| 1039 | 1173 | ||
| 1040 | unsigned long lockdep_count_backward_deps(struct lock_class *class) | 1174 | unsigned long lockdep_count_backward_deps(struct lock_class *class) |
| 1041 | { | 1175 | { |
| 1042 | unsigned long ret, flags; | 1176 | unsigned long ret, flags; |
| 1177 | struct lock_list this; | ||
| 1178 | |||
| 1179 | this.parent = NULL; | ||
| 1180 | this.class = class; | ||
| 1043 | 1181 | ||
| 1044 | local_irq_save(flags); | 1182 | local_irq_save(flags); |
| 1045 | __raw_spin_lock(&lockdep_lock); | 1183 | __raw_spin_lock(&lockdep_lock); |
| 1046 | ret = __lockdep_count_backward_deps(class, 0); | 1184 | ret = __lockdep_count_backward_deps(&this); |
| 1047 | __raw_spin_unlock(&lockdep_lock); | 1185 | __raw_spin_unlock(&lockdep_lock); |
| 1048 | local_irq_restore(flags); | 1186 | local_irq_restore(flags); |
| 1049 | 1187 | ||
| @@ -1055,29 +1193,16 @@ unsigned long lockdep_count_backward_deps(struct lock_class *class) | |||
| 1055 | * lead to <target>. Print an error and return 0 if it does. | 1193 | * lead to <target>. Print an error and return 0 if it does. |
| 1056 | */ | 1194 | */ |
| 1057 | static noinline int | 1195 | static noinline int |
| 1058 | check_noncircular(struct lock_class *source, unsigned int depth) | 1196 | check_noncircular(struct lock_list *root, struct lock_class *target, |
| 1197 | struct lock_list **target_entry) | ||
| 1059 | { | 1198 | { |
| 1060 | struct lock_list *entry; | 1199 | int result; |
| 1061 | 1200 | ||
| 1062 | if (lockdep_dependency_visit(source, depth)) | 1201 | debug_atomic_inc(&nr_cyclic_checks); |
| 1063 | return 1; | ||
| 1064 | 1202 | ||
| 1065 | debug_atomic_inc(&nr_cyclic_check_recursions); | 1203 | result = __bfs_forwards(root, target, class_equal, target_entry); |
| 1066 | if (depth > max_recursion_depth) | 1204 | |
| 1067 | max_recursion_depth = depth; | 1205 | return result; |
| 1068 | if (depth >= RECURSION_LIMIT) | ||
| 1069 | return print_infinite_recursion_bug(); | ||
| 1070 | /* | ||
| 1071 | * Check this lock's dependency list: | ||
| 1072 | */ | ||
| 1073 | list_for_each_entry(entry, &source->locks_after, entry) { | ||
| 1074 | if (entry->class == hlock_class(check_target)) | ||
| 1075 | return print_circular_bug_header(entry, depth+1); | ||
| 1076 | debug_atomic_inc(&nr_cyclic_checks); | ||
| 1077 | if (!check_noncircular(entry->class, depth+1)) | ||
| 1078 | return print_circular_bug_entry(entry, depth+1); | ||
| 1079 | } | ||
| 1080 | return 1; | ||
| 1081 | } | 1206 | } |
| 1082 | 1207 | ||
| 1083 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) | 1208 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) |
| @@ -1086,103 +1211,121 @@ check_noncircular(struct lock_class *source, unsigned int depth) | |||
| 1086 | * proving that two subgraphs can be connected by a new dependency | 1211 | * proving that two subgraphs can be connected by a new dependency |
| 1087 | * without creating any illegal irq-safe -> irq-unsafe lock dependency. | 1212 | * without creating any illegal irq-safe -> irq-unsafe lock dependency. |
| 1088 | */ | 1213 | */ |
| 1089 | static enum lock_usage_bit find_usage_bit; | 1214 | |
| 1090 | static struct lock_class *forwards_match, *backwards_match; | 1215 | static inline int usage_match(struct lock_list *entry, void *bit) |
| 1216 | { | ||
| 1217 | return entry->class->usage_mask & (1 << (enum lock_usage_bit)bit); | ||
| 1218 | } | ||
| 1219 | |||
| 1220 | |||
| 1091 | 1221 | ||
| 1092 | /* | 1222 | /* |
| 1093 | * Find a node in the forwards-direction dependency sub-graph starting | 1223 | * Find a node in the forwards-direction dependency sub-graph starting |
| 1094 | * at <source> that matches <find_usage_bit>. | 1224 | * at @root->class that matches @bit. |
| 1095 | * | 1225 | * |
| 1096 | * Return 2 if such a node exists in the subgraph, and put that node | 1226 | * Return 0 if such a node exists in the subgraph, and put that node |
| 1097 | * into <forwards_match>. | 1227 | * into *@target_entry. |
| 1098 | * | 1228 | * |
| 1099 | * Return 1 otherwise and keep <forwards_match> unchanged. | 1229 | * Return 1 otherwise and keep *@target_entry unchanged. |
| 1100 | * Return 0 on error. | 1230 | * Return <0 on error. |
| 1101 | */ | 1231 | */ |
| 1102 | static noinline int | 1232 | static int |
| 1103 | find_usage_forwards(struct lock_class *source, unsigned int depth) | 1233 | find_usage_forwards(struct lock_list *root, enum lock_usage_bit bit, |
| 1234 | struct lock_list **target_entry) | ||
| 1104 | { | 1235 | { |
| 1105 | struct lock_list *entry; | 1236 | int result; |
| 1106 | int ret; | ||
| 1107 | |||
| 1108 | if (lockdep_dependency_visit(source, depth)) | ||
| 1109 | return 1; | ||
| 1110 | |||
| 1111 | if (depth > max_recursion_depth) | ||
| 1112 | max_recursion_depth = depth; | ||
| 1113 | if (depth >= RECURSION_LIMIT) | ||
| 1114 | return print_infinite_recursion_bug(); | ||
| 1115 | 1237 | ||
| 1116 | debug_atomic_inc(&nr_find_usage_forwards_checks); | 1238 | debug_atomic_inc(&nr_find_usage_forwards_checks); |
| 1117 | if (source->usage_mask & (1 << find_usage_bit)) { | ||
| 1118 | forwards_match = source; | ||
| 1119 | return 2; | ||
| 1120 | } | ||
| 1121 | 1239 | ||
| 1122 | /* | 1240 | result = __bfs_forwards(root, (void *)bit, usage_match, target_entry); |
| 1123 | * Check this lock's dependency list: | 1241 | |
| 1124 | */ | 1242 | return result; |
| 1125 | list_for_each_entry(entry, &source->locks_after, entry) { | ||
| 1126 | debug_atomic_inc(&nr_find_usage_forwards_recursions); | ||
| 1127 | ret = find_usage_forwards(entry->class, depth+1); | ||
| 1128 | if (ret == 2 || ret == 0) | ||
| 1129 | return ret; | ||
| 1130 | } | ||
| 1131 | return 1; | ||
| 1132 | } | 1243 | } |
| 1133 | 1244 | ||
| 1134 | /* | 1245 | /* |
| 1135 | * Find a node in the backwards-direction dependency sub-graph starting | 1246 | * Find a node in the backwards-direction dependency sub-graph starting |
| 1136 | * at <source> that matches <find_usage_bit>. | 1247 | * at @root->class that matches @bit. |
| 1137 | * | 1248 | * |
| 1138 | * Return 2 if such a node exists in the subgraph, and put that node | 1249 | * Return 0 if such a node exists in the subgraph, and put that node |
| 1139 | * into <backwards_match>. | 1250 | * into *@target_entry. |
| 1140 | * | 1251 | * |
| 1141 | * Return 1 otherwise and keep <backwards_match> unchanged. | 1252 | * Return 1 otherwise and keep *@target_entry unchanged. |
| 1142 | * Return 0 on error. | 1253 | * Return <0 on error. |
| 1143 | */ | 1254 | */ |
| 1144 | static noinline int | 1255 | static int |
| 1145 | find_usage_backwards(struct lock_class *source, unsigned int depth) | 1256 | find_usage_backwards(struct lock_list *root, enum lock_usage_bit bit, |
| 1257 | struct lock_list **target_entry) | ||
| 1146 | { | 1258 | { |
| 1147 | struct lock_list *entry; | 1259 | int result; |
| 1148 | int ret; | ||
| 1149 | 1260 | ||
| 1150 | if (lockdep_dependency_visit(source, depth)) | 1261 | debug_atomic_inc(&nr_find_usage_backwards_checks); |
| 1151 | return 1; | ||
| 1152 | 1262 | ||
| 1153 | if (!__raw_spin_is_locked(&lockdep_lock)) | 1263 | result = __bfs_backwards(root, (void *)bit, usage_match, target_entry); |
| 1154 | return DEBUG_LOCKS_WARN_ON(1); | ||
| 1155 | 1264 | ||
| 1156 | if (depth > max_recursion_depth) | 1265 | return result; |
| 1157 | max_recursion_depth = depth; | 1266 | } |
| 1158 | if (depth >= RECURSION_LIMIT) | ||
| 1159 | return print_infinite_recursion_bug(); | ||
| 1160 | 1267 | ||
| 1161 | debug_atomic_inc(&nr_find_usage_backwards_checks); | 1268 | static void print_lock_class_header(struct lock_class *class, int depth) |
| 1162 | if (source->usage_mask & (1 << find_usage_bit)) { | 1269 | { |
| 1163 | backwards_match = source; | 1270 | int bit; |
| 1164 | return 2; | ||
| 1165 | } | ||
| 1166 | 1271 | ||
| 1167 | if (!source && debug_locks_off_graph_unlock()) { | 1272 | printk("%*s->", depth, ""); |
| 1168 | WARN_ON(1); | 1273 | print_lock_name(class); |
| 1169 | return 0; | 1274 | printk(" ops: %lu", class->ops); |
| 1170 | } | 1275 | printk(" {\n"); |
| 1171 | 1276 | ||
| 1172 | /* | 1277 | for (bit = 0; bit < LOCK_USAGE_STATES; bit++) { |
| 1173 | * Check this lock's dependency list: | 1278 | if (class->usage_mask & (1 << bit)) { |
| 1174 | */ | 1279 | int len = depth; |
| 1175 | list_for_each_entry(entry, &source->locks_before, entry) { | 1280 | |
| 1176 | debug_atomic_inc(&nr_find_usage_backwards_recursions); | 1281 | len += printk("%*s %s", depth, "", usage_str[bit]); |
| 1177 | ret = find_usage_backwards(entry->class, depth+1); | 1282 | len += printk(" at:\n"); |
| 1178 | if (ret == 2 || ret == 0) | 1283 | print_stack_trace(class->usage_traces + bit, len); |
| 1179 | return ret; | 1284 | } |
| 1180 | } | 1285 | } |
| 1181 | return 1; | 1286 | printk("%*s }\n", depth, ""); |
| 1287 | |||
| 1288 | printk("%*s ... key at: ",depth,""); | ||
| 1289 | print_ip_sym((unsigned long)class->key); | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | /* | ||
| 1293 | * printk the shortest lock dependencies from @start to @end in reverse order: | ||
| 1294 | */ | ||
| 1295 | static void __used | ||
| 1296 | print_shortest_lock_dependencies(struct lock_list *leaf, | ||
| 1297 | struct lock_list *root) | ||
| 1298 | { | ||
| 1299 | struct lock_list *entry = leaf; | ||
| 1300 | int depth; | ||
| 1301 | |||
| 1302 | /*compute depth from generated tree by BFS*/ | ||
| 1303 | depth = get_lock_depth(leaf); | ||
| 1304 | |||
| 1305 | do { | ||
| 1306 | print_lock_class_header(entry->class, depth); | ||
| 1307 | printk("%*s ... acquired at:\n", depth, ""); | ||
| 1308 | print_stack_trace(&entry->trace, 2); | ||
| 1309 | printk("\n"); | ||
| 1310 | |||
| 1311 | if (depth == 0 && (entry != root)) { | ||
| 1312 | printk("lockdep:%s bad BFS generated tree\n", __func__); | ||
| 1313 | break; | ||
| 1314 | } | ||
| 1315 | |||
| 1316 | entry = get_lock_parent(entry); | ||
| 1317 | depth--; | ||
| 1318 | } while (entry && (depth >= 0)); | ||
| 1319 | |||
| 1320 | return; | ||
| 1182 | } | 1321 | } |
| 1183 | 1322 | ||
| 1184 | static int | 1323 | static int |
| 1185 | print_bad_irq_dependency(struct task_struct *curr, | 1324 | print_bad_irq_dependency(struct task_struct *curr, |
| 1325 | struct lock_list *prev_root, | ||
| 1326 | struct lock_list *next_root, | ||
| 1327 | struct lock_list *backwards_entry, | ||
| 1328 | struct lock_list *forwards_entry, | ||
| 1186 | struct held_lock *prev, | 1329 | struct held_lock *prev, |
| 1187 | struct held_lock *next, | 1330 | struct held_lock *next, |
| 1188 | enum lock_usage_bit bit1, | 1331 | enum lock_usage_bit bit1, |
| @@ -1215,26 +1358,32 @@ print_bad_irq_dependency(struct task_struct *curr, | |||
| 1215 | 1358 | ||
| 1216 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", | 1359 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", |
| 1217 | irqclass); | 1360 | irqclass); |
| 1218 | print_lock_name(backwards_match); | 1361 | print_lock_name(backwards_entry->class); |
| 1219 | printk("\n... which became %s-irq-safe at:\n", irqclass); | 1362 | printk("\n... which became %s-irq-safe at:\n", irqclass); |
| 1220 | 1363 | ||
| 1221 | print_stack_trace(backwards_match->usage_traces + bit1, 1); | 1364 | print_stack_trace(backwards_entry->class->usage_traces + bit1, 1); |
| 1222 | 1365 | ||
| 1223 | printk("\nto a %s-irq-unsafe lock:\n", irqclass); | 1366 | printk("\nto a %s-irq-unsafe lock:\n", irqclass); |
| 1224 | print_lock_name(forwards_match); | 1367 | print_lock_name(forwards_entry->class); |
| 1225 | printk("\n... which became %s-irq-unsafe at:\n", irqclass); | 1368 | printk("\n... which became %s-irq-unsafe at:\n", irqclass); |
| 1226 | printk("..."); | 1369 | printk("..."); |
| 1227 | 1370 | ||
| 1228 | print_stack_trace(forwards_match->usage_traces + bit2, 1); | 1371 | print_stack_trace(forwards_entry->class->usage_traces + bit2, 1); |
| 1229 | 1372 | ||
| 1230 | printk("\nother info that might help us debug this:\n\n"); | 1373 | printk("\nother info that might help us debug this:\n\n"); |
| 1231 | lockdep_print_held_locks(curr); | 1374 | lockdep_print_held_locks(curr); |
| 1232 | 1375 | ||
| 1233 | printk("\nthe %s-irq-safe lock's dependencies:\n", irqclass); | 1376 | printk("\nthe dependencies between %s-irq-safe lock", irqclass); |
| 1234 | print_lock_dependencies(backwards_match, 0); | 1377 | printk(" and the holding lock:\n"); |
| 1378 | if (!save_trace(&prev_root->trace)) | ||
| 1379 | return 0; | ||
| 1380 | print_shortest_lock_dependencies(backwards_entry, prev_root); | ||
| 1235 | 1381 | ||
| 1236 | printk("\nthe %s-irq-unsafe lock's dependencies:\n", irqclass); | 1382 | printk("\nthe dependencies between the lock to be acquired"); |
| 1237 | print_lock_dependencies(forwards_match, 0); | 1383 | printk(" and %s-irq-unsafe lock:\n", irqclass); |
| 1384 | if (!save_trace(&next_root->trace)) | ||
| 1385 | return 0; | ||
| 1386 | print_shortest_lock_dependencies(forwards_entry, next_root); | ||
| 1238 | 1387 | ||
| 1239 | printk("\nstack backtrace:\n"); | 1388 | printk("\nstack backtrace:\n"); |
| 1240 | dump_stack(); | 1389 | dump_stack(); |
| @@ -1248,19 +1397,30 @@ check_usage(struct task_struct *curr, struct held_lock *prev, | |||
| 1248 | enum lock_usage_bit bit_forwards, const char *irqclass) | 1397 | enum lock_usage_bit bit_forwards, const char *irqclass) |
| 1249 | { | 1398 | { |
| 1250 | int ret; | 1399 | int ret; |
| 1400 | struct lock_list this, that; | ||
| 1401 | struct lock_list *uninitialized_var(target_entry); | ||
| 1402 | struct lock_list *uninitialized_var(target_entry1); | ||
| 1251 | 1403 | ||
| 1252 | find_usage_bit = bit_backwards; | 1404 | this.parent = NULL; |
| 1253 | /* fills in <backwards_match> */ | 1405 | |
| 1254 | ret = find_usage_backwards(hlock_class(prev), 0); | 1406 | this.class = hlock_class(prev); |
| 1255 | if (!ret || ret == 1) | 1407 | ret = find_usage_backwards(&this, bit_backwards, &target_entry); |
| 1408 | if (ret < 0) | ||
| 1409 | return print_bfs_bug(ret); | ||
| 1410 | if (ret == 1) | ||
| 1256 | return ret; | 1411 | return ret; |
| 1257 | 1412 | ||
| 1258 | find_usage_bit = bit_forwards; | 1413 | that.parent = NULL; |
| 1259 | ret = find_usage_forwards(hlock_class(next), 0); | 1414 | that.class = hlock_class(next); |
| 1260 | if (!ret || ret == 1) | 1415 | ret = find_usage_forwards(&that, bit_forwards, &target_entry1); |
| 1416 | if (ret < 0) | ||
| 1417 | return print_bfs_bug(ret); | ||
| 1418 | if (ret == 1) | ||
| 1261 | return ret; | 1419 | return ret; |
| 1262 | /* ret == 2 */ | 1420 | |
| 1263 | return print_bad_irq_dependency(curr, prev, next, | 1421 | return print_bad_irq_dependency(curr, &this, &that, |
| 1422 | target_entry, target_entry1, | ||
| 1423 | prev, next, | ||
| 1264 | bit_backwards, bit_forwards, irqclass); | 1424 | bit_backwards, bit_forwards, irqclass); |
| 1265 | } | 1425 | } |
| 1266 | 1426 | ||
| @@ -1472,6 +1632,8 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
| 1472 | { | 1632 | { |
| 1473 | struct lock_list *entry; | 1633 | struct lock_list *entry; |
| 1474 | int ret; | 1634 | int ret; |
| 1635 | struct lock_list this; | ||
| 1636 | struct lock_list *uninitialized_var(target_entry); | ||
| 1475 | 1637 | ||
| 1476 | /* | 1638 | /* |
| 1477 | * Prove that the new <prev> -> <next> dependency would not | 1639 | * Prove that the new <prev> -> <next> dependency would not |
| @@ -1482,10 +1644,13 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
| 1482 | * We are using global variables to control the recursion, to | 1644 | * We are using global variables to control the recursion, to |
| 1483 | * keep the stackframe size of the recursive functions low: | 1645 | * keep the stackframe size of the recursive functions low: |
| 1484 | */ | 1646 | */ |
| 1485 | check_source = next; | 1647 | this.class = hlock_class(next); |
| 1486 | check_target = prev; | 1648 | this.parent = NULL; |
| 1487 | if (!(check_noncircular(hlock_class(next), 0))) | 1649 | ret = check_noncircular(&this, hlock_class(prev), &target_entry); |
| 1488 | return print_circular_bug_tail(); | 1650 | if (unlikely(!ret)) |
| 1651 | return print_circular_bug(&this, target_entry, next, prev); | ||
| 1652 | else if (unlikely(ret < 0)) | ||
| 1653 | return print_bfs_bug(ret); | ||
| 1489 | 1654 | ||
| 1490 | if (!check_prev_add_irq(curr, prev, next)) | 1655 | if (!check_prev_add_irq(curr, prev, next)) |
| 1491 | return 0; | 1656 | return 0; |
| @@ -1884,7 +2049,8 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, | |||
| 1884 | * print irq inversion bug: | 2049 | * print irq inversion bug: |
| 1885 | */ | 2050 | */ |
| 1886 | static int | 2051 | static int |
| 1887 | print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other, | 2052 | print_irq_inversion_bug(struct task_struct *curr, |
| 2053 | struct lock_list *root, struct lock_list *other, | ||
| 1888 | struct held_lock *this, int forwards, | 2054 | struct held_lock *this, int forwards, |
| 1889 | const char *irqclass) | 2055 | const char *irqclass) |
| 1890 | { | 2056 | { |
| @@ -1902,17 +2068,16 @@ print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other, | |||
| 1902 | printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass); | 2068 | printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass); |
| 1903 | else | 2069 | else |
| 1904 | printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); | 2070 | printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); |
| 1905 | print_lock_name(other); | 2071 | print_lock_name(other->class); |
| 1906 | printk("\n\nand interrupts could create inverse lock ordering between them.\n\n"); | 2072 | printk("\n\nand interrupts could create inverse lock ordering between them.\n\n"); |
| 1907 | 2073 | ||
| 1908 | printk("\nother info that might help us debug this:\n"); | 2074 | printk("\nother info that might help us debug this:\n"); |
| 1909 | lockdep_print_held_locks(curr); | 2075 | lockdep_print_held_locks(curr); |
| 1910 | 2076 | ||
| 1911 | printk("\nthe first lock's dependencies:\n"); | 2077 | printk("\nthe shortest dependencies between 2nd lock and 1st lock:\n"); |
| 1912 | print_lock_dependencies(hlock_class(this), 0); | 2078 | if (!save_trace(&root->trace)) |
| 1913 | 2079 | return 0; | |
| 1914 | printk("\nthe second lock's dependencies:\n"); | 2080 | print_shortest_lock_dependencies(other, root); |
| 1915 | print_lock_dependencies(other, 0); | ||
| 1916 | 2081 | ||
| 1917 | printk("\nstack backtrace:\n"); | 2082 | printk("\nstack backtrace:\n"); |
| 1918 | dump_stack(); | 2083 | dump_stack(); |
| @@ -1929,14 +2094,19 @@ check_usage_forwards(struct task_struct *curr, struct held_lock *this, | |||
| 1929 | enum lock_usage_bit bit, const char *irqclass) | 2094 | enum lock_usage_bit bit, const char *irqclass) |
| 1930 | { | 2095 | { |
| 1931 | int ret; | 2096 | int ret; |
| 1932 | 2097 | struct lock_list root; | |
| 1933 | find_usage_bit = bit; | 2098 | struct lock_list *uninitialized_var(target_entry); |
| 1934 | /* fills in <forwards_match> */ | 2099 | |
| 1935 | ret = find_usage_forwards(hlock_class(this), 0); | 2100 | root.parent = NULL; |
| 1936 | if (!ret || ret == 1) | 2101 | root.class = hlock_class(this); |
| 2102 | ret = find_usage_forwards(&root, bit, &target_entry); | ||
| 2103 | if (ret < 0) | ||
| 2104 | return print_bfs_bug(ret); | ||
| 2105 | if (ret == 1) | ||
| 1937 | return ret; | 2106 | return ret; |
| 1938 | 2107 | ||
| 1939 | return print_irq_inversion_bug(curr, forwards_match, this, 1, irqclass); | 2108 | return print_irq_inversion_bug(curr, &root, target_entry, |
| 2109 | this, 1, irqclass); | ||
| 1940 | } | 2110 | } |
| 1941 | 2111 | ||
| 1942 | /* | 2112 | /* |
| @@ -1948,14 +2118,19 @@ check_usage_backwards(struct task_struct *curr, struct held_lock *this, | |||
| 1948 | enum lock_usage_bit bit, const char *irqclass) | 2118 | enum lock_usage_bit bit, const char *irqclass) |
| 1949 | { | 2119 | { |
| 1950 | int ret; | 2120 | int ret; |
| 1951 | 2121 | struct lock_list root; | |
| 1952 | find_usage_bit = bit; | 2122 | struct lock_list *uninitialized_var(target_entry); |
| 1953 | /* fills in <backwards_match> */ | 2123 | |
| 1954 | ret = find_usage_backwards(hlock_class(this), 0); | 2124 | root.parent = NULL; |
| 1955 | if (!ret || ret == 1) | 2125 | root.class = hlock_class(this); |
| 2126 | ret = find_usage_backwards(&root, bit, &target_entry); | ||
| 2127 | if (ret < 0) | ||
| 2128 | return print_bfs_bug(ret); | ||
| 2129 | if (ret == 1) | ||
| 1956 | return ret; | 2130 | return ret; |
| 1957 | 2131 | ||
| 1958 | return print_irq_inversion_bug(curr, backwards_match, this, 0, irqclass); | 2132 | return print_irq_inversion_bug(curr, &root, target_entry, |
| 2133 | this, 1, irqclass); | ||
| 1959 | } | 2134 | } |
| 1960 | 2135 | ||
| 1961 | void print_irqtrace_events(struct task_struct *curr) | 2136 | void print_irqtrace_events(struct task_struct *curr) |
| @@ -2530,13 +2705,15 @@ EXPORT_SYMBOL_GPL(lockdep_init_map); | |||
| 2530 | */ | 2705 | */ |
| 2531 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | 2706 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, |
| 2532 | int trylock, int read, int check, int hardirqs_off, | 2707 | int trylock, int read, int check, int hardirqs_off, |
| 2533 | struct lockdep_map *nest_lock, unsigned long ip) | 2708 | struct lockdep_map *nest_lock, unsigned long ip, |
| 2709 | int references) | ||
| 2534 | { | 2710 | { |
| 2535 | struct task_struct *curr = current; | 2711 | struct task_struct *curr = current; |
| 2536 | struct lock_class *class = NULL; | 2712 | struct lock_class *class = NULL; |
| 2537 | struct held_lock *hlock; | 2713 | struct held_lock *hlock; |
| 2538 | unsigned int depth, id; | 2714 | unsigned int depth, id; |
| 2539 | int chain_head = 0; | 2715 | int chain_head = 0; |
| 2716 | int class_idx; | ||
| 2540 | u64 chain_key; | 2717 | u64 chain_key; |
| 2541 | 2718 | ||
| 2542 | if (!prove_locking) | 2719 | if (!prove_locking) |
| @@ -2584,10 +2761,24 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2584 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) | 2761 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) |
| 2585 | return 0; | 2762 | return 0; |
| 2586 | 2763 | ||
| 2764 | class_idx = class - lock_classes + 1; | ||
| 2765 | |||
| 2766 | if (depth) { | ||
| 2767 | hlock = curr->held_locks + depth - 1; | ||
| 2768 | if (hlock->class_idx == class_idx && nest_lock) { | ||
| 2769 | if (hlock->references) | ||
| 2770 | hlock->references++; | ||
| 2771 | else | ||
| 2772 | hlock->references = 2; | ||
| 2773 | |||
| 2774 | return 1; | ||
| 2775 | } | ||
| 2776 | } | ||
| 2777 | |||
| 2587 | hlock = curr->held_locks + depth; | 2778 | hlock = curr->held_locks + depth; |
| 2588 | if (DEBUG_LOCKS_WARN_ON(!class)) | 2779 | if (DEBUG_LOCKS_WARN_ON(!class)) |
| 2589 | return 0; | 2780 | return 0; |
| 2590 | hlock->class_idx = class - lock_classes + 1; | 2781 | hlock->class_idx = class_idx; |
| 2591 | hlock->acquire_ip = ip; | 2782 | hlock->acquire_ip = ip; |
| 2592 | hlock->instance = lock; | 2783 | hlock->instance = lock; |
| 2593 | hlock->nest_lock = nest_lock; | 2784 | hlock->nest_lock = nest_lock; |
| @@ -2595,6 +2786,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2595 | hlock->read = read; | 2786 | hlock->read = read; |
| 2596 | hlock->check = check; | 2787 | hlock->check = check; |
| 2597 | hlock->hardirqs_off = !!hardirqs_off; | 2788 | hlock->hardirqs_off = !!hardirqs_off; |
| 2789 | hlock->references = references; | ||
| 2598 | #ifdef CONFIG_LOCK_STAT | 2790 | #ifdef CONFIG_LOCK_STAT |
| 2599 | hlock->waittime_stamp = 0; | 2791 | hlock->waittime_stamp = 0; |
| 2600 | hlock->holdtime_stamp = sched_clock(); | 2792 | hlock->holdtime_stamp = sched_clock(); |
| @@ -2703,6 +2895,30 @@ static int check_unlock(struct task_struct *curr, struct lockdep_map *lock, | |||
| 2703 | return 1; | 2895 | return 1; |
| 2704 | } | 2896 | } |
| 2705 | 2897 | ||
| 2898 | static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock) | ||
| 2899 | { | ||
| 2900 | if (hlock->instance == lock) | ||
| 2901 | return 1; | ||
| 2902 | |||
| 2903 | if (hlock->references) { | ||
| 2904 | struct lock_class *class = lock->class_cache; | ||
| 2905 | |||
| 2906 | if (!class) | ||
| 2907 | class = look_up_lock_class(lock, 0); | ||
| 2908 | |||
| 2909 | if (DEBUG_LOCKS_WARN_ON(!class)) | ||
| 2910 | return 0; | ||
| 2911 | |||
| 2912 | if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) | ||
| 2913 | return 0; | ||
| 2914 | |||
| 2915 | if (hlock->class_idx == class - lock_classes + 1) | ||
| 2916 | return 1; | ||
| 2917 | } | ||
| 2918 | |||
| 2919 | return 0; | ||
| 2920 | } | ||
| 2921 | |||
| 2706 | static int | 2922 | static int |
| 2707 | __lock_set_class(struct lockdep_map *lock, const char *name, | 2923 | __lock_set_class(struct lockdep_map *lock, const char *name, |
| 2708 | struct lock_class_key *key, unsigned int subclass, | 2924 | struct lock_class_key *key, unsigned int subclass, |
| @@ -2726,7 +2942,7 @@ __lock_set_class(struct lockdep_map *lock, const char *name, | |||
| 2726 | */ | 2942 | */ |
| 2727 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 2943 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 2728 | break; | 2944 | break; |
| 2729 | if (hlock->instance == lock) | 2945 | if (match_held_lock(hlock, lock)) |
| 2730 | goto found_it; | 2946 | goto found_it; |
| 2731 | prev_hlock = hlock; | 2947 | prev_hlock = hlock; |
| 2732 | } | 2948 | } |
| @@ -2745,7 +2961,8 @@ found_it: | |||
| 2745 | if (!__lock_acquire(hlock->instance, | 2961 | if (!__lock_acquire(hlock->instance, |
| 2746 | hlock_class(hlock)->subclass, hlock->trylock, | 2962 | hlock_class(hlock)->subclass, hlock->trylock, |
| 2747 | hlock->read, hlock->check, hlock->hardirqs_off, | 2963 | hlock->read, hlock->check, hlock->hardirqs_off, |
| 2748 | hlock->nest_lock, hlock->acquire_ip)) | 2964 | hlock->nest_lock, hlock->acquire_ip, |
| 2965 | hlock->references)) | ||
| 2749 | return 0; | 2966 | return 0; |
| 2750 | } | 2967 | } |
| 2751 | 2968 | ||
| @@ -2784,20 +3001,34 @@ lock_release_non_nested(struct task_struct *curr, | |||
| 2784 | */ | 3001 | */ |
| 2785 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3002 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 2786 | break; | 3003 | break; |
| 2787 | if (hlock->instance == lock) | 3004 | if (match_held_lock(hlock, lock)) |
| 2788 | goto found_it; | 3005 | goto found_it; |
| 2789 | prev_hlock = hlock; | 3006 | prev_hlock = hlock; |
| 2790 | } | 3007 | } |
| 2791 | return print_unlock_inbalance_bug(curr, lock, ip); | 3008 | return print_unlock_inbalance_bug(curr, lock, ip); |
| 2792 | 3009 | ||
| 2793 | found_it: | 3010 | found_it: |
| 2794 | lock_release_holdtime(hlock); | 3011 | if (hlock->instance == lock) |
| 3012 | lock_release_holdtime(hlock); | ||
| 3013 | |||
| 3014 | if (hlock->references) { | ||
| 3015 | hlock->references--; | ||
| 3016 | if (hlock->references) { | ||
| 3017 | /* | ||
| 3018 | * We had, and after removing one, still have | ||
| 3019 | * references, the current lock stack is still | ||
| 3020 | * valid. We're done! | ||
| 3021 | */ | ||
| 3022 | return 1; | ||
| 3023 | } | ||
| 3024 | } | ||
| 2795 | 3025 | ||
| 2796 | /* | 3026 | /* |
| 2797 | * We have the right lock to unlock, 'hlock' points to it. | 3027 | * We have the right lock to unlock, 'hlock' points to it. |
| 2798 | * Now we remove it from the stack, and add back the other | 3028 | * Now we remove it from the stack, and add back the other |
| 2799 | * entries (if any), recalculating the hash along the way: | 3029 | * entries (if any), recalculating the hash along the way: |
| 2800 | */ | 3030 | */ |
| 3031 | |||
| 2801 | curr->lockdep_depth = i; | 3032 | curr->lockdep_depth = i; |
| 2802 | curr->curr_chain_key = hlock->prev_chain_key; | 3033 | curr->curr_chain_key = hlock->prev_chain_key; |
| 2803 | 3034 | ||
| @@ -2806,7 +3037,8 @@ found_it: | |||
| 2806 | if (!__lock_acquire(hlock->instance, | 3037 | if (!__lock_acquire(hlock->instance, |
| 2807 | hlock_class(hlock)->subclass, hlock->trylock, | 3038 | hlock_class(hlock)->subclass, hlock->trylock, |
| 2808 | hlock->read, hlock->check, hlock->hardirqs_off, | 3039 | hlock->read, hlock->check, hlock->hardirqs_off, |
| 2809 | hlock->nest_lock, hlock->acquire_ip)) | 3040 | hlock->nest_lock, hlock->acquire_ip, |
| 3041 | hlock->references)) | ||
| 2810 | return 0; | 3042 | return 0; |
| 2811 | } | 3043 | } |
| 2812 | 3044 | ||
| @@ -2836,7 +3068,7 @@ static int lock_release_nested(struct task_struct *curr, | |||
| 2836 | /* | 3068 | /* |
| 2837 | * Is the unlock non-nested: | 3069 | * Is the unlock non-nested: |
| 2838 | */ | 3070 | */ |
| 2839 | if (hlock->instance != lock) | 3071 | if (hlock->instance != lock || hlock->references) |
| 2840 | return lock_release_non_nested(curr, lock, ip); | 3072 | return lock_release_non_nested(curr, lock, ip); |
| 2841 | curr->lockdep_depth--; | 3073 | curr->lockdep_depth--; |
| 2842 | 3074 | ||
| @@ -2881,6 +3113,21 @@ __lock_release(struct lockdep_map *lock, int nested, unsigned long ip) | |||
| 2881 | check_chain_key(curr); | 3113 | check_chain_key(curr); |
| 2882 | } | 3114 | } |
| 2883 | 3115 | ||
| 3116 | static int __lock_is_held(struct lockdep_map *lock) | ||
| 3117 | { | ||
| 3118 | struct task_struct *curr = current; | ||
| 3119 | int i; | ||
| 3120 | |||
| 3121 | for (i = 0; i < curr->lockdep_depth; i++) { | ||
| 3122 | struct held_lock *hlock = curr->held_locks + i; | ||
| 3123 | |||
| 3124 | if (match_held_lock(hlock, lock)) | ||
| 3125 | return 1; | ||
| 3126 | } | ||
| 3127 | |||
| 3128 | return 0; | ||
| 3129 | } | ||
| 3130 | |||
| 2884 | /* | 3131 | /* |
| 2885 | * Check whether we follow the irq-flags state precisely: | 3132 | * Check whether we follow the irq-flags state precisely: |
| 2886 | */ | 3133 | */ |
| @@ -2957,7 +3204,7 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2957 | 3204 | ||
| 2958 | current->lockdep_recursion = 1; | 3205 | current->lockdep_recursion = 1; |
| 2959 | __lock_acquire(lock, subclass, trylock, read, check, | 3206 | __lock_acquire(lock, subclass, trylock, read, check, |
| 2960 | irqs_disabled_flags(flags), nest_lock, ip); | 3207 | irqs_disabled_flags(flags), nest_lock, ip, 0); |
| 2961 | current->lockdep_recursion = 0; | 3208 | current->lockdep_recursion = 0; |
| 2962 | raw_local_irq_restore(flags); | 3209 | raw_local_irq_restore(flags); |
| 2963 | } | 3210 | } |
| @@ -2982,6 +3229,26 @@ void lock_release(struct lockdep_map *lock, int nested, | |||
| 2982 | } | 3229 | } |
| 2983 | EXPORT_SYMBOL_GPL(lock_release); | 3230 | EXPORT_SYMBOL_GPL(lock_release); |
| 2984 | 3231 | ||
| 3232 | int lock_is_held(struct lockdep_map *lock) | ||
| 3233 | { | ||
| 3234 | unsigned long flags; | ||
| 3235 | int ret = 0; | ||
| 3236 | |||
| 3237 | if (unlikely(current->lockdep_recursion)) | ||
| 3238 | return ret; | ||
| 3239 | |||
| 3240 | raw_local_irq_save(flags); | ||
| 3241 | check_flags(flags); | ||
| 3242 | |||
| 3243 | current->lockdep_recursion = 1; | ||
| 3244 | ret = __lock_is_held(lock); | ||
| 3245 | current->lockdep_recursion = 0; | ||
| 3246 | raw_local_irq_restore(flags); | ||
| 3247 | |||
| 3248 | return ret; | ||
| 3249 | } | ||
| 3250 | EXPORT_SYMBOL_GPL(lock_is_held); | ||
| 3251 | |||
| 2985 | void lockdep_set_current_reclaim_state(gfp_t gfp_mask) | 3252 | void lockdep_set_current_reclaim_state(gfp_t gfp_mask) |
| 2986 | { | 3253 | { |
| 2987 | current->lockdep_reclaim_gfp = gfp_mask; | 3254 | current->lockdep_reclaim_gfp = gfp_mask; |
| @@ -3041,7 +3308,7 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
| 3041 | */ | 3308 | */ |
| 3042 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3309 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 3043 | break; | 3310 | break; |
| 3044 | if (hlock->instance == lock) | 3311 | if (match_held_lock(hlock, lock)) |
| 3045 | goto found_it; | 3312 | goto found_it; |
| 3046 | prev_hlock = hlock; | 3313 | prev_hlock = hlock; |
| 3047 | } | 3314 | } |
| @@ -3049,6 +3316,9 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
| 3049 | return; | 3316 | return; |
| 3050 | 3317 | ||
| 3051 | found_it: | 3318 | found_it: |
| 3319 | if (hlock->instance != lock) | ||
| 3320 | return; | ||
| 3321 | |||
| 3052 | hlock->waittime_stamp = sched_clock(); | 3322 | hlock->waittime_stamp = sched_clock(); |
| 3053 | 3323 | ||
| 3054 | contention_point = lock_point(hlock_class(hlock)->contention_point, ip); | 3324 | contention_point = lock_point(hlock_class(hlock)->contention_point, ip); |
| @@ -3088,7 +3358,7 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) | |||
| 3088 | */ | 3358 | */ |
| 3089 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3359 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 3090 | break; | 3360 | break; |
| 3091 | if (hlock->instance == lock) | 3361 | if (match_held_lock(hlock, lock)) |
| 3092 | goto found_it; | 3362 | goto found_it; |
| 3093 | prev_hlock = hlock; | 3363 | prev_hlock = hlock; |
| 3094 | } | 3364 | } |
| @@ -3096,6 +3366,9 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) | |||
| 3096 | return; | 3366 | return; |
| 3097 | 3367 | ||
| 3098 | found_it: | 3368 | found_it: |
| 3369 | if (hlock->instance != lock) | ||
| 3370 | return; | ||
| 3371 | |||
| 3099 | cpu = smp_processor_id(); | 3372 | cpu = smp_processor_id(); |
| 3100 | if (hlock->waittime_stamp) { | 3373 | if (hlock->waittime_stamp) { |
| 3101 | now = sched_clock(); | 3374 | now = sched_clock(); |
| @@ -3326,7 +3599,12 @@ void __init lockdep_info(void) | |||
| 3326 | sizeof(struct list_head) * CLASSHASH_SIZE + | 3599 | sizeof(struct list_head) * CLASSHASH_SIZE + |
| 3327 | sizeof(struct lock_list) * MAX_LOCKDEP_ENTRIES + | 3600 | sizeof(struct lock_list) * MAX_LOCKDEP_ENTRIES + |
| 3328 | sizeof(struct lock_chain) * MAX_LOCKDEP_CHAINS + | 3601 | sizeof(struct lock_chain) * MAX_LOCKDEP_CHAINS + |
| 3329 | sizeof(struct list_head) * CHAINHASH_SIZE) / 1024); | 3602 | sizeof(struct list_head) * CHAINHASH_SIZE |
| 3603 | #ifdef CONFIG_PROVE_LOCKING | ||
| 3604 | + sizeof(struct circular_queue) | ||
| 3605 | #endif | ||
| 3606 | ) / 1024 | ||
| 3607 | ); | ||
| 3330 | 3608 | ||
| 3331 | printk(" per task-struct memory footprint: %lu bytes\n", | 3609 | printk(" per task-struct memory footprint: %lu bytes\n", |
| 3332 | sizeof(struct held_lock) * MAX_LOCK_DEPTH); | 3610 | sizeof(struct held_lock) * MAX_LOCK_DEPTH); |
diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h index 699a2ac3a0d7..a2ee95ad1313 100644 --- a/kernel/lockdep_internals.h +++ b/kernel/lockdep_internals.h | |||
| @@ -91,6 +91,8 @@ extern unsigned int nr_process_chains; | |||
| 91 | extern unsigned int max_lockdep_depth; | 91 | extern unsigned int max_lockdep_depth; |
| 92 | extern unsigned int max_recursion_depth; | 92 | extern unsigned int max_recursion_depth; |
| 93 | 93 | ||
| 94 | extern unsigned int max_bfs_queue_depth; | ||
| 95 | |||
| 94 | #ifdef CONFIG_PROVE_LOCKING | 96 | #ifdef CONFIG_PROVE_LOCKING |
| 95 | extern unsigned long lockdep_count_forward_deps(struct lock_class *); | 97 | extern unsigned long lockdep_count_forward_deps(struct lock_class *); |
| 96 | extern unsigned long lockdep_count_backward_deps(struct lock_class *); | 98 | extern unsigned long lockdep_count_backward_deps(struct lock_class *); |
diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c index e94caa666dba..d4b3dbc79fdb 100644 --- a/kernel/lockdep_proc.c +++ b/kernel/lockdep_proc.c | |||
| @@ -25,38 +25,12 @@ | |||
| 25 | 25 | ||
| 26 | static void *l_next(struct seq_file *m, void *v, loff_t *pos) | 26 | static void *l_next(struct seq_file *m, void *v, loff_t *pos) |
| 27 | { | 27 | { |
| 28 | struct lock_class *class; | 28 | return seq_list_next(v, &all_lock_classes, pos); |
| 29 | |||
| 30 | (*pos)++; | ||
| 31 | |||
| 32 | if (v == SEQ_START_TOKEN) | ||
| 33 | class = m->private; | ||
| 34 | else { | ||
| 35 | class = v; | ||
| 36 | |||
| 37 | if (class->lock_entry.next != &all_lock_classes) | ||
| 38 | class = list_entry(class->lock_entry.next, | ||
| 39 | struct lock_class, lock_entry); | ||
| 40 | else | ||
| 41 | class = NULL; | ||
| 42 | } | ||
| 43 | |||
| 44 | return class; | ||
| 45 | } | 29 | } |
| 46 | 30 | ||
| 47 | static void *l_start(struct seq_file *m, loff_t *pos) | 31 | static void *l_start(struct seq_file *m, loff_t *pos) |
| 48 | { | 32 | { |
| 49 | struct lock_class *class; | 33 | return seq_list_start_head(&all_lock_classes, *pos); |
| 50 | loff_t i = 0; | ||
| 51 | |||
| 52 | if (*pos == 0) | ||
| 53 | return SEQ_START_TOKEN; | ||
| 54 | |||
| 55 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | ||
| 56 | if (++i == *pos) | ||
| 57 | return class; | ||
| 58 | } | ||
| 59 | return NULL; | ||
| 60 | } | 34 | } |
| 61 | 35 | ||
| 62 | static void l_stop(struct seq_file *m, void *v) | 36 | static void l_stop(struct seq_file *m, void *v) |
| @@ -82,11 +56,11 @@ static void print_name(struct seq_file *m, struct lock_class *class) | |||
| 82 | 56 | ||
| 83 | static int l_show(struct seq_file *m, void *v) | 57 | static int l_show(struct seq_file *m, void *v) |
| 84 | { | 58 | { |
| 85 | struct lock_class *class = v; | 59 | struct lock_class *class = list_entry(v, struct lock_class, lock_entry); |
| 86 | struct lock_list *entry; | 60 | struct lock_list *entry; |
| 87 | char usage[LOCK_USAGE_CHARS]; | 61 | char usage[LOCK_USAGE_CHARS]; |
| 88 | 62 | ||
| 89 | if (v == SEQ_START_TOKEN) { | 63 | if (v == &all_lock_classes) { |
| 90 | seq_printf(m, "all lock classes:\n"); | 64 | seq_printf(m, "all lock classes:\n"); |
| 91 | return 0; | 65 | return 0; |
| 92 | } | 66 | } |
| @@ -128,17 +102,7 @@ static const struct seq_operations lockdep_ops = { | |||
| 128 | 102 | ||
| 129 | static int lockdep_open(struct inode *inode, struct file *file) | 103 | static int lockdep_open(struct inode *inode, struct file *file) |
| 130 | { | 104 | { |
| 131 | int res = seq_open(file, &lockdep_ops); | 105 | return seq_open(file, &lockdep_ops); |
| 132 | if (!res) { | ||
| 133 | struct seq_file *m = file->private_data; | ||
| 134 | |||
| 135 | if (!list_empty(&all_lock_classes)) | ||
| 136 | m->private = list_entry(all_lock_classes.next, | ||
| 137 | struct lock_class, lock_entry); | ||
| 138 | else | ||
| 139 | m->private = NULL; | ||
| 140 | } | ||
| 141 | return res; | ||
| 142 | } | 106 | } |
| 143 | 107 | ||
| 144 | static const struct file_operations proc_lockdep_operations = { | 108 | static const struct file_operations proc_lockdep_operations = { |
| @@ -149,37 +113,23 @@ static const struct file_operations proc_lockdep_operations = { | |||
| 149 | }; | 113 | }; |
| 150 | 114 | ||
| 151 | #ifdef CONFIG_PROVE_LOCKING | 115 | #ifdef CONFIG_PROVE_LOCKING |
| 152 | static void *lc_next(struct seq_file *m, void *v, loff_t *pos) | ||
| 153 | { | ||
| 154 | struct lock_chain *chain; | ||
| 155 | |||
| 156 | (*pos)++; | ||
| 157 | |||
| 158 | if (v == SEQ_START_TOKEN) | ||
| 159 | chain = m->private; | ||
| 160 | else { | ||
| 161 | chain = v; | ||
| 162 | |||
| 163 | if (*pos < nr_lock_chains) | ||
| 164 | chain = lock_chains + *pos; | ||
| 165 | else | ||
| 166 | chain = NULL; | ||
| 167 | } | ||
| 168 | |||
| 169 | return chain; | ||
| 170 | } | ||
| 171 | |||
| 172 | static void *lc_start(struct seq_file *m, loff_t *pos) | 116 | static void *lc_start(struct seq_file *m, loff_t *pos) |
| 173 | { | 117 | { |
| 174 | if (*pos == 0) | 118 | if (*pos == 0) |
| 175 | return SEQ_START_TOKEN; | 119 | return SEQ_START_TOKEN; |
| 176 | 120 | ||
| 177 | if (*pos < nr_lock_chains) | 121 | if (*pos - 1 < nr_lock_chains) |
| 178 | return lock_chains + *pos; | 122 | return lock_chains + (*pos - 1); |
| 179 | 123 | ||
| 180 | return NULL; | 124 | return NULL; |
| 181 | } | 125 | } |
| 182 | 126 | ||
| 127 | static void *lc_next(struct seq_file *m, void *v, loff_t *pos) | ||
| 128 | { | ||
| 129 | (*pos)++; | ||
| 130 | return lc_start(m, pos); | ||
| 131 | } | ||
| 132 | |||
| 183 | static void lc_stop(struct seq_file *m, void *v) | 133 | static void lc_stop(struct seq_file *m, void *v) |
| 184 | { | 134 | { |
| 185 | } | 135 | } |
| @@ -220,16 +170,7 @@ static const struct seq_operations lockdep_chains_ops = { | |||
| 220 | 170 | ||
| 221 | static int lockdep_chains_open(struct inode *inode, struct file *file) | 171 | static int lockdep_chains_open(struct inode *inode, struct file *file) |
| 222 | { | 172 | { |
| 223 | int res = seq_open(file, &lockdep_chains_ops); | 173 | return seq_open(file, &lockdep_chains_ops); |
| 224 | if (!res) { | ||
| 225 | struct seq_file *m = file->private_data; | ||
| 226 | |||
| 227 | if (nr_lock_chains) | ||
| 228 | m->private = lock_chains; | ||
| 229 | else | ||
| 230 | m->private = NULL; | ||
| 231 | } | ||
| 232 | return res; | ||
| 233 | } | 174 | } |
| 234 | 175 | ||
| 235 | static const struct file_operations proc_lockdep_chains_operations = { | 176 | static const struct file_operations proc_lockdep_chains_operations = { |
| @@ -258,16 +199,10 @@ static void lockdep_stats_debug_show(struct seq_file *m) | |||
| 258 | debug_atomic_read(&chain_lookup_hits)); | 199 | debug_atomic_read(&chain_lookup_hits)); |
| 259 | seq_printf(m, " cyclic checks: %11u\n", | 200 | seq_printf(m, " cyclic checks: %11u\n", |
| 260 | debug_atomic_read(&nr_cyclic_checks)); | 201 | debug_atomic_read(&nr_cyclic_checks)); |
| 261 | seq_printf(m, " cyclic-check recursions: %11u\n", | ||
| 262 | debug_atomic_read(&nr_cyclic_check_recursions)); | ||
| 263 | seq_printf(m, " find-mask forwards checks: %11u\n", | 202 | seq_printf(m, " find-mask forwards checks: %11u\n", |
| 264 | debug_atomic_read(&nr_find_usage_forwards_checks)); | 203 | debug_atomic_read(&nr_find_usage_forwards_checks)); |
| 265 | seq_printf(m, " find-mask forwards recursions: %11u\n", | ||
| 266 | debug_atomic_read(&nr_find_usage_forwards_recursions)); | ||
| 267 | seq_printf(m, " find-mask backwards checks: %11u\n", | 204 | seq_printf(m, " find-mask backwards checks: %11u\n", |
| 268 | debug_atomic_read(&nr_find_usage_backwards_checks)); | 205 | debug_atomic_read(&nr_find_usage_backwards_checks)); |
| 269 | seq_printf(m, " find-mask backwards recursions:%11u\n", | ||
| 270 | debug_atomic_read(&nr_find_usage_backwards_recursions)); | ||
| 271 | 206 | ||
| 272 | seq_printf(m, " hardirq on events: %11u\n", hi1); | 207 | seq_printf(m, " hardirq on events: %11u\n", hi1); |
| 273 | seq_printf(m, " hardirq off events: %11u\n", hi2); | 208 | seq_printf(m, " hardirq off events: %11u\n", hi2); |
| @@ -409,8 +344,10 @@ static int lockdep_stats_show(struct seq_file *m, void *v) | |||
| 409 | nr_unused); | 344 | nr_unused); |
| 410 | seq_printf(m, " max locking depth: %11u\n", | 345 | seq_printf(m, " max locking depth: %11u\n", |
| 411 | max_lockdep_depth); | 346 | max_lockdep_depth); |
| 412 | seq_printf(m, " max recursion depth: %11u\n", | 347 | #ifdef CONFIG_PROVE_LOCKING |
| 413 | max_recursion_depth); | 348 | seq_printf(m, " max bfs queue depth: %11u\n", |
| 349 | max_bfs_queue_depth); | ||
| 350 | #endif | ||
| 414 | lockdep_stats_debug_show(m); | 351 | lockdep_stats_debug_show(m); |
| 415 | seq_printf(m, " debug_locks: %11u\n", | 352 | seq_printf(m, " debug_locks: %11u\n", |
| 416 | debug_locks); | 353 | debug_locks); |
| @@ -438,7 +375,6 @@ struct lock_stat_data { | |||
| 438 | }; | 375 | }; |
| 439 | 376 | ||
| 440 | struct lock_stat_seq { | 377 | struct lock_stat_seq { |
| 441 | struct lock_stat_data *iter; | ||
| 442 | struct lock_stat_data *iter_end; | 378 | struct lock_stat_data *iter_end; |
| 443 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; | 379 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; |
| 444 | }; | 380 | }; |
| @@ -626,34 +562,22 @@ static void seq_header(struct seq_file *m) | |||
| 626 | static void *ls_start(struct seq_file *m, loff_t *pos) | 562 | static void *ls_start(struct seq_file *m, loff_t *pos) |
| 627 | { | 563 | { |
| 628 | struct lock_stat_seq *data = m->private; | 564 | struct lock_stat_seq *data = m->private; |
| 565 | struct lock_stat_data *iter; | ||
| 629 | 566 | ||
| 630 | if (*pos == 0) | 567 | if (*pos == 0) |
| 631 | return SEQ_START_TOKEN; | 568 | return SEQ_START_TOKEN; |
| 632 | 569 | ||
| 633 | data->iter = data->stats + *pos; | 570 | iter = data->stats + (*pos - 1); |
| 634 | if (data->iter >= data->iter_end) | 571 | if (iter >= data->iter_end) |
| 635 | data->iter = NULL; | 572 | iter = NULL; |
| 636 | 573 | ||
| 637 | return data->iter; | 574 | return iter; |
| 638 | } | 575 | } |
| 639 | 576 | ||
| 640 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) | 577 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) |
| 641 | { | 578 | { |
| 642 | struct lock_stat_seq *data = m->private; | ||
| 643 | |||
| 644 | (*pos)++; | 579 | (*pos)++; |
| 645 | 580 | return ls_start(m, pos); | |
| 646 | if (v == SEQ_START_TOKEN) | ||
| 647 | data->iter = data->stats; | ||
| 648 | else { | ||
| 649 | data->iter = v; | ||
| 650 | data->iter++; | ||
| 651 | } | ||
| 652 | |||
| 653 | if (data->iter == data->iter_end) | ||
| 654 | data->iter = NULL; | ||
| 655 | |||
| 656 | return data->iter; | ||
| 657 | } | 581 | } |
| 658 | 582 | ||
| 659 | static void ls_stop(struct seq_file *m, void *v) | 583 | static void ls_stop(struct seq_file *m, void *v) |
| @@ -691,7 +615,6 @@ static int lock_stat_open(struct inode *inode, struct file *file) | |||
| 691 | struct lock_stat_data *iter = data->stats; | 615 | struct lock_stat_data *iter = data->stats; |
| 692 | struct seq_file *m = file->private_data; | 616 | struct seq_file *m = file->private_data; |
| 693 | 617 | ||
| 694 | data->iter = iter; | ||
| 695 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | 618 | list_for_each_entry(class, &all_lock_classes, lock_entry) { |
| 696 | iter->class = class; | 619 | iter->class = class; |
| 697 | iter->stats = lock_stats(class); | 620 | iter->stats = lock_stats(class); |
| @@ -699,7 +622,7 @@ static int lock_stat_open(struct inode *inode, struct file *file) | |||
| 699 | } | 622 | } |
| 700 | data->iter_end = iter; | 623 | data->iter_end = iter; |
| 701 | 624 | ||
| 702 | sort(data->stats, data->iter_end - data->iter, | 625 | sort(data->stats, data->iter_end - data->stats, |
| 703 | sizeof(struct lock_stat_data), | 626 | sizeof(struct lock_stat_data), |
| 704 | lock_stat_cmp, NULL); | 627 | lock_stat_cmp, NULL); |
| 705 | 628 | ||
| @@ -734,7 +657,6 @@ static int lock_stat_release(struct inode *inode, struct file *file) | |||
| 734 | struct seq_file *seq = file->private_data; | 657 | struct seq_file *seq = file->private_data; |
| 735 | 658 | ||
| 736 | vfree(seq->private); | 659 | vfree(seq->private); |
| 737 | seq->private = NULL; | ||
| 738 | return seq_release(inode, file); | 660 | return seq_release(inode, file); |
| 739 | } | 661 | } |
| 740 | 662 | ||
diff --git a/kernel/module.c b/kernel/module.c index fd1411403558..2d537186191f 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
| @@ -909,16 +909,18 @@ void __symbol_put(const char *symbol) | |||
| 909 | } | 909 | } |
| 910 | EXPORT_SYMBOL(__symbol_put); | 910 | EXPORT_SYMBOL(__symbol_put); |
| 911 | 911 | ||
| 912 | /* Note this assumes addr is a function, which it currently always is. */ | ||
| 912 | void symbol_put_addr(void *addr) | 913 | void symbol_put_addr(void *addr) |
| 913 | { | 914 | { |
| 914 | struct module *modaddr; | 915 | struct module *modaddr; |
| 916 | unsigned long a = (unsigned long)dereference_function_descriptor(addr); | ||
| 915 | 917 | ||
| 916 | if (core_kernel_text((unsigned long)addr)) | 918 | if (core_kernel_text(a)) |
| 917 | return; | 919 | return; |
| 918 | 920 | ||
| 919 | /* module_text_address is safe here: we're supposed to have reference | 921 | /* module_text_address is safe here: we're supposed to have reference |
| 920 | * to module from symbol_get, so it can't go away. */ | 922 | * to module from symbol_get, so it can't go away. */ |
| 921 | modaddr = __module_text_address((unsigned long)addr); | 923 | modaddr = __module_text_address(a); |
| 922 | BUG_ON(!modaddr); | 924 | BUG_ON(!modaddr); |
| 923 | module_put(modaddr); | 925 | module_put(modaddr); |
| 924 | } | 926 | } |
| @@ -1272,6 +1274,10 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
| 1272 | struct module_notes_attrs *notes_attrs; | 1274 | struct module_notes_attrs *notes_attrs; |
| 1273 | struct bin_attribute *nattr; | 1275 | struct bin_attribute *nattr; |
| 1274 | 1276 | ||
| 1277 | /* failed to create section attributes, so can't create notes */ | ||
| 1278 | if (!mod->sect_attrs) | ||
| 1279 | return; | ||
| 1280 | |||
| 1275 | /* Count notes sections and allocate structures. */ | 1281 | /* Count notes sections and allocate structures. */ |
| 1276 | notes = 0; | 1282 | notes = 0; |
| 1277 | for (i = 0; i < nsect; i++) | 1283 | for (i = 0; i < nsect; i++) |
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c index 36f65e2b8b57..d7cbc579fc80 100644 --- a/kernel/perf_counter.c +++ b/kernel/perf_counter.c | |||
| @@ -50,7 +50,7 @@ static atomic_t nr_task_counters __read_mostly; | |||
| 50 | * 1 - disallow cpu counters to unpriv | 50 | * 1 - disallow cpu counters to unpriv |
| 51 | * 2 - disallow kernel profiling to unpriv | 51 | * 2 - disallow kernel profiling to unpriv |
| 52 | */ | 52 | */ |
| 53 | int sysctl_perf_counter_paranoid __read_mostly; | 53 | int sysctl_perf_counter_paranoid __read_mostly = 1; |
| 54 | 54 | ||
| 55 | static inline bool perf_paranoid_cpu(void) | 55 | static inline bool perf_paranoid_cpu(void) |
| 56 | { | 56 | { |
| @@ -1791,7 +1791,7 @@ static int perf_counter_read_group(struct perf_counter *counter, | |||
| 1791 | size += err; | 1791 | size += err; |
| 1792 | 1792 | ||
| 1793 | list_for_each_entry(sub, &leader->sibling_list, list_entry) { | 1793 | list_for_each_entry(sub, &leader->sibling_list, list_entry) { |
| 1794 | err = perf_counter_read_entry(counter, read_format, | 1794 | err = perf_counter_read_entry(sub, read_format, |
| 1795 | buf + size); | 1795 | buf + size); |
| 1796 | if (err < 0) | 1796 | if (err < 0) |
| 1797 | return err; | 1797 | return err; |
| @@ -4066,6 +4066,7 @@ perf_counter_alloc(struct perf_counter_attr *attr, | |||
| 4066 | hwc->sample_period = attr->sample_period; | 4066 | hwc->sample_period = attr->sample_period; |
| 4067 | if (attr->freq && attr->sample_freq) | 4067 | if (attr->freq && attr->sample_freq) |
| 4068 | hwc->sample_period = 1; | 4068 | hwc->sample_period = 1; |
| 4069 | hwc->last_period = hwc->sample_period; | ||
| 4069 | 4070 | ||
| 4070 | atomic64_set(&hwc->period_left, hwc->sample_period); | 4071 | atomic64_set(&hwc->period_left, hwc->sample_period); |
| 4071 | 4072 | ||
diff --git a/kernel/printk.c b/kernel/printk.c index b4d97b54c1ec..e10d193a833a 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
| @@ -37,6 +37,12 @@ | |||
| 37 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
| 38 | 38 | ||
| 39 | /* | 39 | /* |
| 40 | * for_each_console() allows you to iterate on each console | ||
| 41 | */ | ||
| 42 | #define for_each_console(con) \ | ||
| 43 | for (con = console_drivers; con != NULL; con = con->next) | ||
| 44 | |||
| 45 | /* | ||
| 40 | * Architectures can override it: | 46 | * Architectures can override it: |
| 41 | */ | 47 | */ |
| 42 | void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...) | 48 | void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...) |
| @@ -61,6 +67,8 @@ int console_printk[4] = { | |||
| 61 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ | 67 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ |
| 62 | }; | 68 | }; |
| 63 | 69 | ||
| 70 | static int saved_console_loglevel = -1; | ||
| 71 | |||
| 64 | /* | 72 | /* |
| 65 | * Low level drivers may need that to know if they can schedule in | 73 | * Low level drivers may need that to know if they can schedule in |
| 66 | * their unblank() callback or not. So let's export it. | 74 | * their unblank() callback or not. So let's export it. |
| @@ -372,10 +380,15 @@ int do_syslog(int type, char __user *buf, int len) | |||
| 372 | logged_chars = 0; | 380 | logged_chars = 0; |
| 373 | break; | 381 | break; |
| 374 | case 6: /* Disable logging to console */ | 382 | case 6: /* Disable logging to console */ |
| 383 | if (saved_console_loglevel == -1) | ||
| 384 | saved_console_loglevel = console_loglevel; | ||
| 375 | console_loglevel = minimum_console_loglevel; | 385 | console_loglevel = minimum_console_loglevel; |
| 376 | break; | 386 | break; |
| 377 | case 7: /* Enable logging to console */ | 387 | case 7: /* Enable logging to console */ |
| 378 | console_loglevel = default_console_loglevel; | 388 | if (saved_console_loglevel != -1) { |
| 389 | console_loglevel = saved_console_loglevel; | ||
| 390 | saved_console_loglevel = -1; | ||
| 391 | } | ||
| 379 | break; | 392 | break; |
| 380 | case 8: /* Set level of messages printed to console */ | 393 | case 8: /* Set level of messages printed to console */ |
| 381 | error = -EINVAL; | 394 | error = -EINVAL; |
| @@ -384,6 +397,8 @@ int do_syslog(int type, char __user *buf, int len) | |||
| 384 | if (len < minimum_console_loglevel) | 397 | if (len < minimum_console_loglevel) |
| 385 | len = minimum_console_loglevel; | 398 | len = minimum_console_loglevel; |
| 386 | console_loglevel = len; | 399 | console_loglevel = len; |
| 400 | /* Implicitly re-enable logging to console */ | ||
| 401 | saved_console_loglevel = -1; | ||
| 387 | error = 0; | 402 | error = 0; |
| 388 | break; | 403 | break; |
| 389 | case 9: /* Number of chars in the log buffer */ | 404 | case 9: /* Number of chars in the log buffer */ |
| @@ -412,7 +427,7 @@ static void __call_console_drivers(unsigned start, unsigned end) | |||
| 412 | { | 427 | { |
| 413 | struct console *con; | 428 | struct console *con; |
| 414 | 429 | ||
| 415 | for (con = console_drivers; con; con = con->next) { | 430 | for_each_console(con) { |
| 416 | if ((con->flags & CON_ENABLED) && con->write && | 431 | if ((con->flags & CON_ENABLED) && con->write && |
| 417 | (cpu_online(smp_processor_id()) || | 432 | (cpu_online(smp_processor_id()) || |
| 418 | (con->flags & CON_ANYTIME))) | 433 | (con->flags & CON_ANYTIME))) |
| @@ -544,7 +559,7 @@ static int have_callable_console(void) | |||
| 544 | { | 559 | { |
| 545 | struct console *con; | 560 | struct console *con; |
| 546 | 561 | ||
| 547 | for (con = console_drivers; con; con = con->next) | 562 | for_each_console(con) |
| 548 | if (con->flags & CON_ANYTIME) | 563 | if (con->flags & CON_ANYTIME) |
| 549 | return 1; | 564 | return 1; |
| 550 | 565 | ||
| @@ -1082,7 +1097,7 @@ void console_unblank(void) | |||
| 1082 | 1097 | ||
| 1083 | console_locked = 1; | 1098 | console_locked = 1; |
| 1084 | console_may_schedule = 0; | 1099 | console_may_schedule = 0; |
| 1085 | for (c = console_drivers; c != NULL; c = c->next) | 1100 | for_each_console(c) |
| 1086 | if ((c->flags & CON_ENABLED) && c->unblank) | 1101 | if ((c->flags & CON_ENABLED) && c->unblank) |
| 1087 | c->unblank(); | 1102 | c->unblank(); |
| 1088 | release_console_sem(); | 1103 | release_console_sem(); |
| @@ -1097,7 +1112,7 @@ struct tty_driver *console_device(int *index) | |||
| 1097 | struct tty_driver *driver = NULL; | 1112 | struct tty_driver *driver = NULL; |
| 1098 | 1113 | ||
| 1099 | acquire_console_sem(); | 1114 | acquire_console_sem(); |
| 1100 | for (c = console_drivers; c != NULL; c = c->next) { | 1115 | for_each_console(c) { |
| 1101 | if (!c->device) | 1116 | if (!c->device) |
| 1102 | continue; | 1117 | continue; |
| 1103 | driver = c->device(c, index); | 1118 | driver = c->device(c, index); |
| @@ -1134,25 +1149,49 @@ EXPORT_SYMBOL(console_start); | |||
| 1134 | * to register the console printing procedure with printk() and to | 1149 | * to register the console printing procedure with printk() and to |
| 1135 | * print any messages that were printed by the kernel before the | 1150 | * print any messages that were printed by the kernel before the |
| 1136 | * console driver was initialized. | 1151 | * console driver was initialized. |
| 1152 | * | ||
| 1153 | * This can happen pretty early during the boot process (because of | ||
| 1154 | * early_printk) - sometimes before setup_arch() completes - be careful | ||
| 1155 | * of what kernel features are used - they may not be initialised yet. | ||
| 1156 | * | ||
| 1157 | * There are two types of consoles - bootconsoles (early_printk) and | ||
| 1158 | * "real" consoles (everything which is not a bootconsole) which are | ||
| 1159 | * handled differently. | ||
| 1160 | * - Any number of bootconsoles can be registered at any time. | ||
| 1161 | * - As soon as a "real" console is registered, all bootconsoles | ||
| 1162 | * will be unregistered automatically. | ||
| 1163 | * - Once a "real" console is registered, any attempt to register a | ||
| 1164 | * bootconsoles will be rejected | ||
| 1137 | */ | 1165 | */ |
| 1138 | void register_console(struct console *console) | 1166 | void register_console(struct console *newcon) |
| 1139 | { | 1167 | { |
| 1140 | int i; | 1168 | int i; |
| 1141 | unsigned long flags; | 1169 | unsigned long flags; |
| 1142 | struct console *bootconsole = NULL; | 1170 | struct console *bcon = NULL; |
| 1143 | 1171 | ||
| 1144 | if (console_drivers) { | 1172 | /* |
| 1145 | if (console->flags & CON_BOOT) | 1173 | * before we register a new CON_BOOT console, make sure we don't |
| 1146 | return; | 1174 | * already have a valid console |
| 1147 | if (console_drivers->flags & CON_BOOT) | 1175 | */ |
| 1148 | bootconsole = console_drivers; | 1176 | if (console_drivers && newcon->flags & CON_BOOT) { |
| 1177 | /* find the last or real console */ | ||
| 1178 | for_each_console(bcon) { | ||
| 1179 | if (!(bcon->flags & CON_BOOT)) { | ||
| 1180 | printk(KERN_INFO "Too late to register bootconsole %s%d\n", | ||
| 1181 | newcon->name, newcon->index); | ||
| 1182 | return; | ||
| 1183 | } | ||
| 1184 | } | ||
| 1149 | } | 1185 | } |
| 1150 | 1186 | ||
| 1151 | if (preferred_console < 0 || bootconsole || !console_drivers) | 1187 | if (console_drivers && console_drivers->flags & CON_BOOT) |
| 1188 | bcon = console_drivers; | ||
| 1189 | |||
| 1190 | if (preferred_console < 0 || bcon || !console_drivers) | ||
| 1152 | preferred_console = selected_console; | 1191 | preferred_console = selected_console; |
| 1153 | 1192 | ||
| 1154 | if (console->early_setup) | 1193 | if (newcon->early_setup) |
| 1155 | console->early_setup(); | 1194 | newcon->early_setup(); |
| 1156 | 1195 | ||
| 1157 | /* | 1196 | /* |
| 1158 | * See if we want to use this console driver. If we | 1197 | * See if we want to use this console driver. If we |
| @@ -1160,13 +1199,13 @@ void register_console(struct console *console) | |||
| 1160 | * that registers here. | 1199 | * that registers here. |
| 1161 | */ | 1200 | */ |
| 1162 | if (preferred_console < 0) { | 1201 | if (preferred_console < 0) { |
| 1163 | if (console->index < 0) | 1202 | if (newcon->index < 0) |
| 1164 | console->index = 0; | 1203 | newcon->index = 0; |
| 1165 | if (console->setup == NULL || | 1204 | if (newcon->setup == NULL || |
| 1166 | console->setup(console, NULL) == 0) { | 1205 | newcon->setup(newcon, NULL) == 0) { |
| 1167 | console->flags |= CON_ENABLED; | 1206 | newcon->flags |= CON_ENABLED; |
| 1168 | if (console->device) { | 1207 | if (newcon->device) { |
| 1169 | console->flags |= CON_CONSDEV; | 1208 | newcon->flags |= CON_CONSDEV; |
| 1170 | preferred_console = 0; | 1209 | preferred_console = 0; |
| 1171 | } | 1210 | } |
| 1172 | } | 1211 | } |
| @@ -1178,64 +1217,62 @@ void register_console(struct console *console) | |||
| 1178 | */ | 1217 | */ |
| 1179 | for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; | 1218 | for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; |
| 1180 | i++) { | 1219 | i++) { |
| 1181 | if (strcmp(console_cmdline[i].name, console->name) != 0) | 1220 | if (strcmp(console_cmdline[i].name, newcon->name) != 0) |
| 1182 | continue; | 1221 | continue; |
| 1183 | if (console->index >= 0 && | 1222 | if (newcon->index >= 0 && |
| 1184 | console->index != console_cmdline[i].index) | 1223 | newcon->index != console_cmdline[i].index) |
| 1185 | continue; | 1224 | continue; |
| 1186 | if (console->index < 0) | 1225 | if (newcon->index < 0) |
| 1187 | console->index = console_cmdline[i].index; | 1226 | newcon->index = console_cmdline[i].index; |
| 1188 | #ifdef CONFIG_A11Y_BRAILLE_CONSOLE | 1227 | #ifdef CONFIG_A11Y_BRAILLE_CONSOLE |
| 1189 | if (console_cmdline[i].brl_options) { | 1228 | if (console_cmdline[i].brl_options) { |
| 1190 | console->flags |= CON_BRL; | 1229 | newcon->flags |= CON_BRL; |
| 1191 | braille_register_console(console, | 1230 | braille_register_console(newcon, |
| 1192 | console_cmdline[i].index, | 1231 | console_cmdline[i].index, |
| 1193 | console_cmdline[i].options, | 1232 | console_cmdline[i].options, |
| 1194 | console_cmdline[i].brl_options); | 1233 | console_cmdline[i].brl_options); |
| 1195 | return; | 1234 | return; |
| 1196 | } | 1235 | } |
| 1197 | #endif | 1236 | #endif |
| 1198 | if (console->setup && | 1237 | if (newcon->setup && |
| 1199 | console->setup(console, console_cmdline[i].options) != 0) | 1238 | newcon->setup(newcon, console_cmdline[i].options) != 0) |
| 1200 | break; | 1239 | break; |
| 1201 | console->flags |= CON_ENABLED; | 1240 | newcon->flags |= CON_ENABLED; |
| 1202 | console->index = console_cmdline[i].index; | 1241 | newcon->index = console_cmdline[i].index; |
| 1203 | if (i == selected_console) { | 1242 | if (i == selected_console) { |
| 1204 | console->flags |= CON_CONSDEV; | 1243 | newcon->flags |= CON_CONSDEV; |
| 1205 | preferred_console = selected_console; | 1244 | preferred_console = selected_console; |
| 1206 | } | 1245 | } |
| 1207 | break; | 1246 | break; |
| 1208 | } | 1247 | } |
| 1209 | 1248 | ||
| 1210 | if (!(console->flags & CON_ENABLED)) | 1249 | if (!(newcon->flags & CON_ENABLED)) |
| 1211 | return; | 1250 | return; |
| 1212 | 1251 | ||
| 1213 | if (bootconsole && (console->flags & CON_CONSDEV)) { | 1252 | /* |
| 1214 | printk(KERN_INFO "console handover: boot [%s%d] -> real [%s%d]\n", | 1253 | * If we have a bootconsole, and are switching to a real console, |
| 1215 | bootconsole->name, bootconsole->index, | 1254 | * don't print everything out again, since when the boot console, and |
| 1216 | console->name, console->index); | 1255 | * the real console are the same physical device, it's annoying to |
| 1217 | unregister_console(bootconsole); | 1256 | * see the beginning boot messages twice |
| 1218 | console->flags &= ~CON_PRINTBUFFER; | 1257 | */ |
| 1219 | } else { | 1258 | if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) |
| 1220 | printk(KERN_INFO "console [%s%d] enabled\n", | 1259 | newcon->flags &= ~CON_PRINTBUFFER; |
| 1221 | console->name, console->index); | ||
| 1222 | } | ||
| 1223 | 1260 | ||
| 1224 | /* | 1261 | /* |
| 1225 | * Put this console in the list - keep the | 1262 | * Put this console in the list - keep the |
| 1226 | * preferred driver at the head of the list. | 1263 | * preferred driver at the head of the list. |
| 1227 | */ | 1264 | */ |
| 1228 | acquire_console_sem(); | 1265 | acquire_console_sem(); |
| 1229 | if ((console->flags & CON_CONSDEV) || console_drivers == NULL) { | 1266 | if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) { |
| 1230 | console->next = console_drivers; | 1267 | newcon->next = console_drivers; |
| 1231 | console_drivers = console; | 1268 | console_drivers = newcon; |
| 1232 | if (console->next) | 1269 | if (newcon->next) |
| 1233 | console->next->flags &= ~CON_CONSDEV; | 1270 | newcon->next->flags &= ~CON_CONSDEV; |
| 1234 | } else { | 1271 | } else { |
| 1235 | console->next = console_drivers->next; | 1272 | newcon->next = console_drivers->next; |
| 1236 | console_drivers->next = console; | 1273 | console_drivers->next = newcon; |
| 1237 | } | 1274 | } |
| 1238 | if (console->flags & CON_PRINTBUFFER) { | 1275 | if (newcon->flags & CON_PRINTBUFFER) { |
| 1239 | /* | 1276 | /* |
| 1240 | * release_console_sem() will print out the buffered messages | 1277 | * release_console_sem() will print out the buffered messages |
| 1241 | * for us. | 1278 | * for us. |
| @@ -1245,6 +1282,28 @@ void register_console(struct console *console) | |||
| 1245 | spin_unlock_irqrestore(&logbuf_lock, flags); | 1282 | spin_unlock_irqrestore(&logbuf_lock, flags); |
| 1246 | } | 1283 | } |
| 1247 | release_console_sem(); | 1284 | release_console_sem(); |
| 1285 | |||
| 1286 | /* | ||
| 1287 | * By unregistering the bootconsoles after we enable the real console | ||
| 1288 | * we get the "console xxx enabled" message on all the consoles - | ||
| 1289 | * boot consoles, real consoles, etc - this is to ensure that end | ||
| 1290 | * users know there might be something in the kernel's log buffer that | ||
| 1291 | * went to the bootconsole (that they do not see on the real console) | ||
| 1292 | */ | ||
| 1293 | if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) { | ||
| 1294 | /* we need to iterate through twice, to make sure we print | ||
| 1295 | * everything out, before we unregister the console(s) | ||
| 1296 | */ | ||
| 1297 | printk(KERN_INFO "console [%s%d] enabled, bootconsole disabled\n", | ||
| 1298 | newcon->name, newcon->index); | ||
| 1299 | for_each_console(bcon) | ||
| 1300 | if (bcon->flags & CON_BOOT) | ||
| 1301 | unregister_console(bcon); | ||
| 1302 | } else { | ||
| 1303 | printk(KERN_INFO "%sconsole [%s%d] enabled\n", | ||
| 1304 | (newcon->flags & CON_BOOT) ? "boot" : "" , | ||
| 1305 | newcon->name, newcon->index); | ||
| 1306 | } | ||
| 1248 | } | 1307 | } |
| 1249 | EXPORT_SYMBOL(register_console); | 1308 | EXPORT_SYMBOL(register_console); |
| 1250 | 1309 | ||
| @@ -1287,11 +1346,13 @@ EXPORT_SYMBOL(unregister_console); | |||
| 1287 | 1346 | ||
| 1288 | static int __init disable_boot_consoles(void) | 1347 | static int __init disable_boot_consoles(void) |
| 1289 | { | 1348 | { |
| 1290 | if (console_drivers != NULL) { | 1349 | struct console *con; |
| 1291 | if (console_drivers->flags & CON_BOOT) { | 1350 | |
| 1351 | for_each_console(con) { | ||
| 1352 | if (con->flags & CON_BOOT) { | ||
| 1292 | printk(KERN_INFO "turn off boot console %s%d\n", | 1353 | printk(KERN_INFO "turn off boot console %s%d\n", |
| 1293 | console_drivers->name, console_drivers->index); | 1354 | con->name, con->index); |
| 1294 | return unregister_console(console_drivers); | 1355 | unregister_console(con); |
| 1295 | } | 1356 | } |
| 1296 | } | 1357 | } |
| 1297 | return 0; | 1358 | return 0; |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 082c320e4dbf..307c285af59e 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
| @@ -152,7 +152,7 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode) | |||
| 152 | if (!dumpable && !capable(CAP_SYS_PTRACE)) | 152 | if (!dumpable && !capable(CAP_SYS_PTRACE)) |
| 153 | return -EPERM; | 153 | return -EPERM; |
| 154 | 154 | ||
| 155 | return security_ptrace_may_access(task, mode); | 155 | return security_ptrace_access_check(task, mode); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) | 158 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) |
diff --git a/kernel/rcuclassic.c b/kernel/rcuclassic.c deleted file mode 100644 index 0f2b0b311304..000000000000 --- a/kernel/rcuclassic.c +++ /dev/null | |||
| @@ -1,807 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | * | ||
| 18 | * Copyright IBM Corporation, 2001 | ||
| 19 | * | ||
| 20 | * Authors: Dipankar Sarma <dipankar@in.ibm.com> | ||
| 21 | * Manfred Spraul <manfred@colorfullife.com> | ||
| 22 | * | ||
| 23 | * Based on the original work by Paul McKenney <paulmck@us.ibm.com> | ||
| 24 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. | ||
| 25 | * Papers: | ||
| 26 | * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf | ||
| 27 | * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001) | ||
| 28 | * | ||
| 29 | * For detailed explanation of Read-Copy Update mechanism see - | ||
| 30 | * Documentation/RCU | ||
| 31 | * | ||
| 32 | */ | ||
| 33 | #include <linux/types.h> | ||
| 34 | #include <linux/kernel.h> | ||
| 35 | #include <linux/init.h> | ||
| 36 | #include <linux/spinlock.h> | ||
| 37 | #include <linux/smp.h> | ||
| 38 | #include <linux/rcupdate.h> | ||
| 39 | #include <linux/interrupt.h> | ||
| 40 | #include <linux/sched.h> | ||
| 41 | #include <asm/atomic.h> | ||
| 42 | #include <linux/bitops.h> | ||
| 43 | #include <linux/module.h> | ||
| 44 | #include <linux/completion.h> | ||
| 45 | #include <linux/moduleparam.h> | ||
| 46 | #include <linux/percpu.h> | ||
| 47 | #include <linux/notifier.h> | ||
| 48 | #include <linux/cpu.h> | ||
| 49 | #include <linux/mutex.h> | ||
| 50 | #include <linux/time.h> | ||
| 51 | |||
| 52 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
| 53 | static struct lock_class_key rcu_lock_key; | ||
| 54 | struct lockdep_map rcu_lock_map = | ||
| 55 | STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key); | ||
| 56 | EXPORT_SYMBOL_GPL(rcu_lock_map); | ||
| 57 | #endif | ||
| 58 | |||
| 59 | |||
| 60 | /* Definition for rcupdate control block. */ | ||
| 61 | static struct rcu_ctrlblk rcu_ctrlblk = { | ||
| 62 | .cur = -300, | ||
| 63 | .completed = -300, | ||
| 64 | .pending = -300, | ||
| 65 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock), | ||
| 66 | .cpumask = CPU_BITS_NONE, | ||
| 67 | }; | ||
| 68 | |||
| 69 | static struct rcu_ctrlblk rcu_bh_ctrlblk = { | ||
| 70 | .cur = -300, | ||
| 71 | .completed = -300, | ||
| 72 | .pending = -300, | ||
| 73 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_bh_ctrlblk.lock), | ||
| 74 | .cpumask = CPU_BITS_NONE, | ||
| 75 | }; | ||
| 76 | |||
| 77 | static DEFINE_PER_CPU(struct rcu_data, rcu_data); | ||
| 78 | static DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); | ||
| 79 | |||
| 80 | /* | ||
| 81 | * Increment the quiescent state counter. | ||
| 82 | * The counter is a bit degenerated: We do not need to know | ||
| 83 | * how many quiescent states passed, just if there was at least | ||
| 84 | * one since the start of the grace period. Thus just a flag. | ||
| 85 | */ | ||
| 86 | void rcu_qsctr_inc(int cpu) | ||
| 87 | { | ||
| 88 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | ||
| 89 | rdp->passed_quiesc = 1; | ||
| 90 | } | ||
| 91 | |||
| 92 | void rcu_bh_qsctr_inc(int cpu) | ||
| 93 | { | ||
| 94 | struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu); | ||
| 95 | rdp->passed_quiesc = 1; | ||
| 96 | } | ||
| 97 | |||
| 98 | static int blimit = 10; | ||
| 99 | static int qhimark = 10000; | ||
| 100 | static int qlowmark = 100; | ||
| 101 | |||
| 102 | #ifdef CONFIG_SMP | ||
| 103 | static void force_quiescent_state(struct rcu_data *rdp, | ||
| 104 | struct rcu_ctrlblk *rcp) | ||
| 105 | { | ||
| 106 | int cpu; | ||
| 107 | unsigned long flags; | ||
| 108 | |||
| 109 | set_need_resched(); | ||
| 110 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 111 | if (unlikely(!rcp->signaled)) { | ||
| 112 | rcp->signaled = 1; | ||
| 113 | /* | ||
| 114 | * Don't send IPI to itself. With irqs disabled, | ||
| 115 | * rdp->cpu is the current cpu. | ||
| 116 | * | ||
| 117 | * cpu_online_mask is updated by the _cpu_down() | ||
| 118 | * using __stop_machine(). Since we're in irqs disabled | ||
| 119 | * section, __stop_machine() is not exectuting, hence | ||
| 120 | * the cpu_online_mask is stable. | ||
| 121 | * | ||
| 122 | * However, a cpu might have been offlined _just_ before | ||
| 123 | * we disabled irqs while entering here. | ||
| 124 | * And rcu subsystem might not yet have handled the CPU_DEAD | ||
| 125 | * notification, leading to the offlined cpu's bit | ||
| 126 | * being set in the rcp->cpumask. | ||
| 127 | * | ||
| 128 | * Hence cpumask = (rcp->cpumask & cpu_online_mask) to prevent | ||
| 129 | * sending smp_reschedule() to an offlined CPU. | ||
| 130 | */ | ||
| 131 | for_each_cpu_and(cpu, | ||
| 132 | to_cpumask(rcp->cpumask), cpu_online_mask) { | ||
| 133 | if (cpu != rdp->cpu) | ||
| 134 | smp_send_reschedule(cpu); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 138 | } | ||
| 139 | #else | ||
| 140 | static inline void force_quiescent_state(struct rcu_data *rdp, | ||
| 141 | struct rcu_ctrlblk *rcp) | ||
| 142 | { | ||
| 143 | set_need_resched(); | ||
| 144 | } | ||
| 145 | #endif | ||
| 146 | |||
| 147 | static void __call_rcu(struct rcu_head *head, struct rcu_ctrlblk *rcp, | ||
| 148 | struct rcu_data *rdp) | ||
| 149 | { | ||
| 150 | long batch; | ||
| 151 | |||
| 152 | head->next = NULL; | ||
| 153 | smp_mb(); /* Read of rcu->cur must happen after any change by caller. */ | ||
| 154 | |||
| 155 | /* | ||
| 156 | * Determine the batch number of this callback. | ||
| 157 | * | ||
| 158 | * Using ACCESS_ONCE to avoid the following error when gcc eliminates | ||
| 159 | * local variable "batch" and emits codes like this: | ||
| 160 | * 1) rdp->batch = rcp->cur + 1 # gets old value | ||
| 161 | * ...... | ||
| 162 | * 2)rcu_batch_after(rcp->cur + 1, rdp->batch) # gets new value | ||
| 163 | * then [*nxttail[0], *nxttail[1]) may contain callbacks | ||
| 164 | * that batch# = rdp->batch, see the comment of struct rcu_data. | ||
| 165 | */ | ||
| 166 | batch = ACCESS_ONCE(rcp->cur) + 1; | ||
| 167 | |||
| 168 | if (rdp->nxtlist && rcu_batch_after(batch, rdp->batch)) { | ||
| 169 | /* process callbacks */ | ||
| 170 | rdp->nxttail[0] = rdp->nxttail[1]; | ||
| 171 | rdp->nxttail[1] = rdp->nxttail[2]; | ||
| 172 | if (rcu_batch_after(batch - 1, rdp->batch)) | ||
| 173 | rdp->nxttail[0] = rdp->nxttail[2]; | ||
| 174 | } | ||
| 175 | |||
| 176 | rdp->batch = batch; | ||
| 177 | *rdp->nxttail[2] = head; | ||
| 178 | rdp->nxttail[2] = &head->next; | ||
| 179 | |||
| 180 | if (unlikely(++rdp->qlen > qhimark)) { | ||
| 181 | rdp->blimit = INT_MAX; | ||
| 182 | force_quiescent_state(rdp, &rcu_ctrlblk); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 187 | |||
| 188 | static void record_gp_stall_check_time(struct rcu_ctrlblk *rcp) | ||
| 189 | { | ||
| 190 | rcp->gp_start = jiffies; | ||
| 191 | rcp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_CHECK; | ||
| 192 | } | ||
| 193 | |||
| 194 | static void print_other_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 195 | { | ||
| 196 | int cpu; | ||
| 197 | long delta; | ||
| 198 | unsigned long flags; | ||
| 199 | |||
| 200 | /* Only let one CPU complain about others per time interval. */ | ||
| 201 | |||
| 202 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 203 | delta = jiffies - rcp->jiffies_stall; | ||
| 204 | if (delta < 2 || rcp->cur != rcp->completed) { | ||
| 205 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 206 | return; | ||
| 207 | } | ||
| 208 | rcp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | ||
| 209 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 210 | |||
| 211 | /* OK, time to rat on our buddy... */ | ||
| 212 | |||
| 213 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); | ||
| 214 | for_each_possible_cpu(cpu) { | ||
| 215 | if (cpumask_test_cpu(cpu, to_cpumask(rcp->cpumask))) | ||
| 216 | printk(" %d", cpu); | ||
| 217 | } | ||
| 218 | printk(" (detected by %d, t=%ld jiffies)\n", | ||
| 219 | smp_processor_id(), (long)(jiffies - rcp->gp_start)); | ||
| 220 | } | ||
| 221 | |||
| 222 | static void print_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 223 | { | ||
| 224 | unsigned long flags; | ||
| 225 | |||
| 226 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu/%lu jiffies)\n", | ||
| 227 | smp_processor_id(), jiffies, | ||
| 228 | jiffies - rcp->gp_start); | ||
| 229 | dump_stack(); | ||
| 230 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 231 | if ((long)(jiffies - rcp->jiffies_stall) >= 0) | ||
| 232 | rcp->jiffies_stall = | ||
| 233 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | ||
| 234 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 235 | set_need_resched(); /* kick ourselves to get things going. */ | ||
| 236 | } | ||
| 237 | |||
| 238 | static void check_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 239 | { | ||
| 240 | long delta; | ||
| 241 | |||
| 242 | delta = jiffies - rcp->jiffies_stall; | ||
| 243 | if (cpumask_test_cpu(smp_processor_id(), to_cpumask(rcp->cpumask)) && | ||
| 244 | delta >= 0) { | ||
| 245 | |||
| 246 | /* We haven't checked in, so go dump stack. */ | ||
| 247 | print_cpu_stall(rcp); | ||
| 248 | |||
| 249 | } else if (rcp->cur != rcp->completed && delta >= 2) { | ||
| 250 | |||
| 251 | /* They had two seconds to dump stack, so complain. */ | ||
| 252 | print_other_cpu_stall(rcp); | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 257 | |||
| 258 | static void record_gp_stall_check_time(struct rcu_ctrlblk *rcp) | ||
| 259 | { | ||
| 260 | } | ||
| 261 | |||
| 262 | static inline void check_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 263 | { | ||
| 264 | } | ||
| 265 | |||
| 266 | #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 267 | |||
| 268 | /** | ||
| 269 | * call_rcu - Queue an RCU callback for invocation after a grace period. | ||
| 270 | * @head: structure to be used for queueing the RCU updates. | ||
| 271 | * @func: actual update function to be invoked after the grace period | ||
| 272 | * | ||
| 273 | * The update function will be invoked some time after a full grace | ||
| 274 | * period elapses, in other words after all currently executing RCU | ||
| 275 | * read-side critical sections have completed. RCU read-side critical | ||
| 276 | * sections are delimited by rcu_read_lock() and rcu_read_unlock(), | ||
| 277 | * and may be nested. | ||
| 278 | */ | ||
| 279 | void call_rcu(struct rcu_head *head, | ||
| 280 | void (*func)(struct rcu_head *rcu)) | ||
| 281 | { | ||
| 282 | unsigned long flags; | ||
| 283 | |||
| 284 | head->func = func; | ||
| 285 | local_irq_save(flags); | ||
| 286 | __call_rcu(head, &rcu_ctrlblk, &__get_cpu_var(rcu_data)); | ||
| 287 | local_irq_restore(flags); | ||
| 288 | } | ||
| 289 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 290 | |||
| 291 | /** | ||
| 292 | * call_rcu_bh - Queue an RCU for invocation after a quicker grace period. | ||
| 293 | * @head: structure to be used for queueing the RCU updates. | ||
| 294 | * @func: actual update function to be invoked after the grace period | ||
| 295 | * | ||
| 296 | * The update function will be invoked some time after a full grace | ||
| 297 | * period elapses, in other words after all currently executing RCU | ||
| 298 | * read-side critical sections have completed. call_rcu_bh() assumes | ||
| 299 | * that the read-side critical sections end on completion of a softirq | ||
| 300 | * handler. This means that read-side critical sections in process | ||
| 301 | * context must not be interrupted by softirqs. This interface is to be | ||
| 302 | * used when most of the read-side critical sections are in softirq context. | ||
| 303 | * RCU read-side critical sections are delimited by rcu_read_lock() and | ||
| 304 | * rcu_read_unlock(), * if in interrupt context or rcu_read_lock_bh() | ||
| 305 | * and rcu_read_unlock_bh(), if in process context. These may be nested. | ||
| 306 | */ | ||
| 307 | void call_rcu_bh(struct rcu_head *head, | ||
| 308 | void (*func)(struct rcu_head *rcu)) | ||
| 309 | { | ||
| 310 | unsigned long flags; | ||
| 311 | |||
| 312 | head->func = func; | ||
| 313 | local_irq_save(flags); | ||
| 314 | __call_rcu(head, &rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data)); | ||
| 315 | local_irq_restore(flags); | ||
| 316 | } | ||
| 317 | EXPORT_SYMBOL_GPL(call_rcu_bh); | ||
| 318 | |||
| 319 | /* | ||
| 320 | * Return the number of RCU batches processed thus far. Useful | ||
| 321 | * for debug and statistics. | ||
| 322 | */ | ||
| 323 | long rcu_batches_completed(void) | ||
| 324 | { | ||
| 325 | return rcu_ctrlblk.completed; | ||
| 326 | } | ||
| 327 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 328 | |||
| 329 | /* | ||
| 330 | * Return the number of RCU batches processed thus far. Useful | ||
| 331 | * for debug and statistics. | ||
| 332 | */ | ||
| 333 | long rcu_batches_completed_bh(void) | ||
| 334 | { | ||
| 335 | return rcu_bh_ctrlblk.completed; | ||
| 336 | } | ||
| 337 | EXPORT_SYMBOL_GPL(rcu_batches_completed_bh); | ||
| 338 | |||
| 339 | /* Raises the softirq for processing rcu_callbacks. */ | ||
| 340 | static inline void raise_rcu_softirq(void) | ||
| 341 | { | ||
| 342 | raise_softirq(RCU_SOFTIRQ); | ||
| 343 | } | ||
| 344 | |||
| 345 | /* | ||
| 346 | * Invoke the completed RCU callbacks. They are expected to be in | ||
| 347 | * a per-cpu list. | ||
| 348 | */ | ||
| 349 | static void rcu_do_batch(struct rcu_data *rdp) | ||
| 350 | { | ||
| 351 | unsigned long flags; | ||
| 352 | struct rcu_head *next, *list; | ||
| 353 | int count = 0; | ||
| 354 | |||
| 355 | list = rdp->donelist; | ||
| 356 | while (list) { | ||
| 357 | next = list->next; | ||
| 358 | prefetch(next); | ||
| 359 | list->func(list); | ||
| 360 | list = next; | ||
| 361 | if (++count >= rdp->blimit) | ||
| 362 | break; | ||
| 363 | } | ||
| 364 | rdp->donelist = list; | ||
| 365 | |||
| 366 | local_irq_save(flags); | ||
| 367 | rdp->qlen -= count; | ||
| 368 | local_irq_restore(flags); | ||
| 369 | if (rdp->blimit == INT_MAX && rdp->qlen <= qlowmark) | ||
| 370 | rdp->blimit = blimit; | ||
| 371 | |||
| 372 | if (!rdp->donelist) | ||
| 373 | rdp->donetail = &rdp->donelist; | ||
| 374 | else | ||
| 375 | raise_rcu_softirq(); | ||
| 376 | } | ||
| 377 | |||
| 378 | /* | ||
| 379 | * Grace period handling: | ||
| 380 | * The grace period handling consists out of two steps: | ||
| 381 | * - A new grace period is started. | ||
| 382 | * This is done by rcu_start_batch. The start is not broadcasted to | ||
| 383 | * all cpus, they must pick this up by comparing rcp->cur with | ||
| 384 | * rdp->quiescbatch. All cpus are recorded in the | ||
| 385 | * rcu_ctrlblk.cpumask bitmap. | ||
| 386 | * - All cpus must go through a quiescent state. | ||
| 387 | * Since the start of the grace period is not broadcasted, at least two | ||
| 388 | * calls to rcu_check_quiescent_state are required: | ||
| 389 | * The first call just notices that a new grace period is running. The | ||
| 390 | * following calls check if there was a quiescent state since the beginning | ||
| 391 | * of the grace period. If so, it updates rcu_ctrlblk.cpumask. If | ||
| 392 | * the bitmap is empty, then the grace period is completed. | ||
| 393 | * rcu_check_quiescent_state calls rcu_start_batch(0) to start the next grace | ||
| 394 | * period (if necessary). | ||
| 395 | */ | ||
| 396 | |||
| 397 | /* | ||
| 398 | * Register a new batch of callbacks, and start it up if there is currently no | ||
| 399 | * active batch and the batch to be registered has not already occurred. | ||
| 400 | * Caller must hold rcu_ctrlblk.lock. | ||
| 401 | */ | ||
| 402 | static void rcu_start_batch(struct rcu_ctrlblk *rcp) | ||
| 403 | { | ||
| 404 | if (rcp->cur != rcp->pending && | ||
| 405 | rcp->completed == rcp->cur) { | ||
| 406 | rcp->cur++; | ||
| 407 | record_gp_stall_check_time(rcp); | ||
| 408 | |||
| 409 | /* | ||
| 410 | * Accessing nohz_cpu_mask before incrementing rcp->cur needs a | ||
| 411 | * Barrier Otherwise it can cause tickless idle CPUs to be | ||
| 412 | * included in rcp->cpumask, which will extend graceperiods | ||
| 413 | * unnecessarily. | ||
| 414 | */ | ||
| 415 | smp_mb(); | ||
| 416 | cpumask_andnot(to_cpumask(rcp->cpumask), | ||
| 417 | cpu_online_mask, nohz_cpu_mask); | ||
| 418 | |||
| 419 | rcp->signaled = 0; | ||
| 420 | } | ||
| 421 | } | ||
| 422 | |||
| 423 | /* | ||
| 424 | * cpu went through a quiescent state since the beginning of the grace period. | ||
| 425 | * Clear it from the cpu mask and complete the grace period if it was the last | ||
| 426 | * cpu. Start another grace period if someone has further entries pending | ||
| 427 | */ | ||
| 428 | static void cpu_quiet(int cpu, struct rcu_ctrlblk *rcp) | ||
| 429 | { | ||
| 430 | cpumask_clear_cpu(cpu, to_cpumask(rcp->cpumask)); | ||
| 431 | if (cpumask_empty(to_cpumask(rcp->cpumask))) { | ||
| 432 | /* batch completed ! */ | ||
| 433 | rcp->completed = rcp->cur; | ||
| 434 | rcu_start_batch(rcp); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | /* | ||
| 439 | * Check if the cpu has gone through a quiescent state (say context | ||
| 440 | * switch). If so and if it already hasn't done so in this RCU | ||
| 441 | * quiescent cycle, then indicate that it has done so. | ||
| 442 | */ | ||
| 443 | static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp, | ||
| 444 | struct rcu_data *rdp) | ||
| 445 | { | ||
| 446 | unsigned long flags; | ||
| 447 | |||
| 448 | if (rdp->quiescbatch != rcp->cur) { | ||
| 449 | /* start new grace period: */ | ||
| 450 | rdp->qs_pending = 1; | ||
| 451 | rdp->passed_quiesc = 0; | ||
| 452 | rdp->quiescbatch = rcp->cur; | ||
| 453 | return; | ||
| 454 | } | ||
| 455 | |||
| 456 | /* Grace period already completed for this cpu? | ||
| 457 | * qs_pending is checked instead of the actual bitmap to avoid | ||
| 458 | * cacheline trashing. | ||
| 459 | */ | ||
| 460 | if (!rdp->qs_pending) | ||
| 461 | return; | ||
| 462 | |||
| 463 | /* | ||
| 464 | * Was there a quiescent state since the beginning of the grace | ||
| 465 | * period? If no, then exit and wait for the next call. | ||
| 466 | */ | ||
| 467 | if (!rdp->passed_quiesc) | ||
| 468 | return; | ||
| 469 | rdp->qs_pending = 0; | ||
| 470 | |||
| 471 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 472 | /* | ||
| 473 | * rdp->quiescbatch/rcp->cur and the cpu bitmap can come out of sync | ||
| 474 | * during cpu startup. Ignore the quiescent state. | ||
| 475 | */ | ||
| 476 | if (likely(rdp->quiescbatch == rcp->cur)) | ||
| 477 | cpu_quiet(rdp->cpu, rcp); | ||
| 478 | |||
| 479 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 480 | } | ||
| 481 | |||
| 482 | |||
| 483 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 484 | |||
| 485 | /* warning! helper for rcu_offline_cpu. do not use elsewhere without reviewing | ||
| 486 | * locking requirements, the list it's pulling from has to belong to a cpu | ||
| 487 | * which is dead and hence not processing interrupts. | ||
| 488 | */ | ||
| 489 | static void rcu_move_batch(struct rcu_data *this_rdp, struct rcu_head *list, | ||
| 490 | struct rcu_head **tail, long batch) | ||
| 491 | { | ||
| 492 | unsigned long flags; | ||
| 493 | |||
| 494 | if (list) { | ||
| 495 | local_irq_save(flags); | ||
| 496 | this_rdp->batch = batch; | ||
| 497 | *this_rdp->nxttail[2] = list; | ||
| 498 | this_rdp->nxttail[2] = tail; | ||
| 499 | local_irq_restore(flags); | ||
| 500 | } | ||
| 501 | } | ||
| 502 | |||
| 503 | static void __rcu_offline_cpu(struct rcu_data *this_rdp, | ||
| 504 | struct rcu_ctrlblk *rcp, struct rcu_data *rdp) | ||
| 505 | { | ||
| 506 | unsigned long flags; | ||
| 507 | |||
| 508 | /* | ||
| 509 | * if the cpu going offline owns the grace period | ||
| 510 | * we can block indefinitely waiting for it, so flush | ||
| 511 | * it here | ||
| 512 | */ | ||
| 513 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 514 | if (rcp->cur != rcp->completed) | ||
| 515 | cpu_quiet(rdp->cpu, rcp); | ||
| 516 | rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail, rcp->cur + 1); | ||
| 517 | rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail[2], rcp->cur + 1); | ||
| 518 | spin_unlock(&rcp->lock); | ||
| 519 | |||
| 520 | this_rdp->qlen += rdp->qlen; | ||
| 521 | local_irq_restore(flags); | ||
| 522 | } | ||
| 523 | |||
| 524 | static void rcu_offline_cpu(int cpu) | ||
| 525 | { | ||
| 526 | struct rcu_data *this_rdp = &get_cpu_var(rcu_data); | ||
| 527 | struct rcu_data *this_bh_rdp = &get_cpu_var(rcu_bh_data); | ||
| 528 | |||
| 529 | __rcu_offline_cpu(this_rdp, &rcu_ctrlblk, | ||
| 530 | &per_cpu(rcu_data, cpu)); | ||
| 531 | __rcu_offline_cpu(this_bh_rdp, &rcu_bh_ctrlblk, | ||
| 532 | &per_cpu(rcu_bh_data, cpu)); | ||
| 533 | put_cpu_var(rcu_data); | ||
| 534 | put_cpu_var(rcu_bh_data); | ||
| 535 | } | ||
| 536 | |||
| 537 | #else | ||
| 538 | |||
| 539 | static void rcu_offline_cpu(int cpu) | ||
| 540 | { | ||
| 541 | } | ||
| 542 | |||
| 543 | #endif | ||
| 544 | |||
| 545 | /* | ||
| 546 | * This does the RCU processing work from softirq context. | ||
| 547 | */ | ||
| 548 | static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp, | ||
| 549 | struct rcu_data *rdp) | ||
| 550 | { | ||
| 551 | unsigned long flags; | ||
| 552 | long completed_snap; | ||
| 553 | |||
| 554 | if (rdp->nxtlist) { | ||
| 555 | local_irq_save(flags); | ||
| 556 | completed_snap = ACCESS_ONCE(rcp->completed); | ||
| 557 | |||
| 558 | /* | ||
| 559 | * move the other grace-period-completed entries to | ||
| 560 | * [rdp->nxtlist, *rdp->nxttail[0]) temporarily | ||
| 561 | */ | ||
| 562 | if (!rcu_batch_before(completed_snap, rdp->batch)) | ||
| 563 | rdp->nxttail[0] = rdp->nxttail[1] = rdp->nxttail[2]; | ||
| 564 | else if (!rcu_batch_before(completed_snap, rdp->batch - 1)) | ||
| 565 | rdp->nxttail[0] = rdp->nxttail[1]; | ||
| 566 | |||
| 567 | /* | ||
| 568 | * the grace period for entries in | ||
| 569 | * [rdp->nxtlist, *rdp->nxttail[0]) has completed and | ||
| 570 | * move these entries to donelist | ||
| 571 | */ | ||
| 572 | if (rdp->nxttail[0] != &rdp->nxtlist) { | ||
| 573 | *rdp->donetail = rdp->nxtlist; | ||
| 574 | rdp->donetail = rdp->nxttail[0]; | ||
| 575 | rdp->nxtlist = *rdp->nxttail[0]; | ||
| 576 | *rdp->donetail = NULL; | ||
| 577 | |||
| 578 | if (rdp->nxttail[1] == rdp->nxttail[0]) | ||
| 579 | rdp->nxttail[1] = &rdp->nxtlist; | ||
| 580 | if (rdp->nxttail[2] == rdp->nxttail[0]) | ||
| 581 | rdp->nxttail[2] = &rdp->nxtlist; | ||
| 582 | rdp->nxttail[0] = &rdp->nxtlist; | ||
| 583 | } | ||
| 584 | |||
| 585 | local_irq_restore(flags); | ||
| 586 | |||
| 587 | if (rcu_batch_after(rdp->batch, rcp->pending)) { | ||
| 588 | unsigned long flags2; | ||
| 589 | |||
| 590 | /* and start it/schedule start if it's a new batch */ | ||
| 591 | spin_lock_irqsave(&rcp->lock, flags2); | ||
| 592 | if (rcu_batch_after(rdp->batch, rcp->pending)) { | ||
| 593 | rcp->pending = rdp->batch; | ||
| 594 | rcu_start_batch(rcp); | ||
| 595 | } | ||
| 596 | spin_unlock_irqrestore(&rcp->lock, flags2); | ||
| 597 | } | ||
| 598 | } | ||
| 599 | |||
| 600 | rcu_check_quiescent_state(rcp, rdp); | ||
| 601 | if (rdp->donelist) | ||
| 602 | rcu_do_batch(rdp); | ||
| 603 | } | ||
| 604 | |||
| 605 | static void rcu_process_callbacks(struct softirq_action *unused) | ||
| 606 | { | ||
| 607 | /* | ||
| 608 | * Memory references from any prior RCU read-side critical sections | ||
| 609 | * executed by the interrupted code must be see before any RCU | ||
| 610 | * grace-period manupulations below. | ||
| 611 | */ | ||
| 612 | |||
| 613 | smp_mb(); /* See above block comment. */ | ||
| 614 | |||
| 615 | __rcu_process_callbacks(&rcu_ctrlblk, &__get_cpu_var(rcu_data)); | ||
| 616 | __rcu_process_callbacks(&rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data)); | ||
| 617 | |||
| 618 | /* | ||
| 619 | * Memory references from any later RCU read-side critical sections | ||
| 620 | * executed by the interrupted code must be see after any RCU | ||
| 621 | * grace-period manupulations above. | ||
| 622 | */ | ||
| 623 | |||
| 624 | smp_mb(); /* See above block comment. */ | ||
| 625 | } | ||
| 626 | |||
| 627 | static int __rcu_pending(struct rcu_ctrlblk *rcp, struct rcu_data *rdp) | ||
| 628 | { | ||
| 629 | /* Check for CPU stalls, if enabled. */ | ||
| 630 | check_cpu_stall(rcp); | ||
| 631 | |||
| 632 | if (rdp->nxtlist) { | ||
| 633 | long completed_snap = ACCESS_ONCE(rcp->completed); | ||
| 634 | |||
| 635 | /* | ||
| 636 | * This cpu has pending rcu entries and the grace period | ||
| 637 | * for them has completed. | ||
| 638 | */ | ||
| 639 | if (!rcu_batch_before(completed_snap, rdp->batch)) | ||
| 640 | return 1; | ||
| 641 | if (!rcu_batch_before(completed_snap, rdp->batch - 1) && | ||
| 642 | rdp->nxttail[0] != rdp->nxttail[1]) | ||
| 643 | return 1; | ||
| 644 | if (rdp->nxttail[0] != &rdp->nxtlist) | ||
| 645 | return 1; | ||
| 646 | |||
| 647 | /* | ||
| 648 | * This cpu has pending rcu entries and the new batch | ||
| 649 | * for then hasn't been started nor scheduled start | ||
| 650 | */ | ||
| 651 | if (rcu_batch_after(rdp->batch, rcp->pending)) | ||
| 652 | return 1; | ||
| 653 | } | ||
| 654 | |||
| 655 | /* This cpu has finished callbacks to invoke */ | ||
| 656 | if (rdp->donelist) | ||
| 657 | return 1; | ||
| 658 | |||
| 659 | /* The rcu core waits for a quiescent state from the cpu */ | ||
| 660 | if (rdp->quiescbatch != rcp->cur || rdp->qs_pending) | ||
| 661 | return 1; | ||
| 662 | |||
| 663 | /* nothing to do */ | ||
| 664 | return 0; | ||
| 665 | } | ||
| 666 | |||
| 667 | /* | ||
| 668 | * Check to see if there is any immediate RCU-related work to be done | ||
| 669 | * by the current CPU, returning 1 if so. This function is part of the | ||
| 670 | * RCU implementation; it is -not- an exported member of the RCU API. | ||
| 671 | */ | ||
| 672 | int rcu_pending(int cpu) | ||
| 673 | { | ||
| 674 | return __rcu_pending(&rcu_ctrlblk, &per_cpu(rcu_data, cpu)) || | ||
| 675 | __rcu_pending(&rcu_bh_ctrlblk, &per_cpu(rcu_bh_data, cpu)); | ||
| 676 | } | ||
| 677 | |||
| 678 | /* | ||
| 679 | * Check to see if any future RCU-related work will need to be done | ||
| 680 | * by the current CPU, even if none need be done immediately, returning | ||
| 681 | * 1 if so. This function is part of the RCU implementation; it is -not- | ||
| 682 | * an exported member of the RCU API. | ||
| 683 | */ | ||
| 684 | int rcu_needs_cpu(int cpu) | ||
| 685 | { | ||
| 686 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | ||
| 687 | struct rcu_data *rdp_bh = &per_cpu(rcu_bh_data, cpu); | ||
| 688 | |||
| 689 | return !!rdp->nxtlist || !!rdp_bh->nxtlist || rcu_pending(cpu); | ||
| 690 | } | ||
| 691 | |||
| 692 | /* | ||
| 693 | * Top-level function driving RCU grace-period detection, normally | ||
| 694 | * invoked from the scheduler-clock interrupt. This function simply | ||
| 695 | * increments counters that are read only from softirq by this same | ||
| 696 | * CPU, so there are no memory barriers required. | ||
| 697 | */ | ||
| 698 | void rcu_check_callbacks(int cpu, int user) | ||
| 699 | { | ||
| 700 | if (user || | ||
| 701 | (idle_cpu(cpu) && rcu_scheduler_active && | ||
| 702 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | ||
| 703 | |||
| 704 | /* | ||
| 705 | * Get here if this CPU took its interrupt from user | ||
| 706 | * mode or from the idle loop, and if this is not a | ||
| 707 | * nested interrupt. In this case, the CPU is in | ||
| 708 | * a quiescent state, so count it. | ||
| 709 | * | ||
| 710 | * Also do a memory barrier. This is needed to handle | ||
| 711 | * the case where writes from a preempt-disable section | ||
| 712 | * of code get reordered into schedule() by this CPU's | ||
| 713 | * write buffer. The memory barrier makes sure that | ||
| 714 | * the rcu_qsctr_inc() and rcu_bh_qsctr_inc() are see | ||
| 715 | * by other CPUs to happen after any such write. | ||
| 716 | */ | ||
| 717 | |||
| 718 | smp_mb(); /* See above block comment. */ | ||
| 719 | rcu_qsctr_inc(cpu); | ||
| 720 | rcu_bh_qsctr_inc(cpu); | ||
| 721 | |||
| 722 | } else if (!in_softirq()) { | ||
| 723 | |||
| 724 | /* | ||
| 725 | * Get here if this CPU did not take its interrupt from | ||
| 726 | * softirq, in other words, if it is not interrupting | ||
| 727 | * a rcu_bh read-side critical section. This is an _bh | ||
| 728 | * critical section, so count it. The memory barrier | ||
| 729 | * is needed for the same reason as is the above one. | ||
| 730 | */ | ||
| 731 | |||
| 732 | smp_mb(); /* See above block comment. */ | ||
| 733 | rcu_bh_qsctr_inc(cpu); | ||
| 734 | } | ||
| 735 | raise_rcu_softirq(); | ||
| 736 | } | ||
| 737 | |||
| 738 | static void __cpuinit rcu_init_percpu_data(int cpu, struct rcu_ctrlblk *rcp, | ||
| 739 | struct rcu_data *rdp) | ||
| 740 | { | ||
| 741 | unsigned long flags; | ||
| 742 | |||
| 743 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 744 | memset(rdp, 0, sizeof(*rdp)); | ||
| 745 | rdp->nxttail[0] = rdp->nxttail[1] = rdp->nxttail[2] = &rdp->nxtlist; | ||
| 746 | rdp->donetail = &rdp->donelist; | ||
| 747 | rdp->quiescbatch = rcp->completed; | ||
| 748 | rdp->qs_pending = 0; | ||
| 749 | rdp->cpu = cpu; | ||
| 750 | rdp->blimit = blimit; | ||
| 751 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 752 | } | ||
| 753 | |||
| 754 | static void __cpuinit rcu_online_cpu(int cpu) | ||
| 755 | { | ||
| 756 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | ||
| 757 | struct rcu_data *bh_rdp = &per_cpu(rcu_bh_data, cpu); | ||
| 758 | |||
| 759 | rcu_init_percpu_data(cpu, &rcu_ctrlblk, rdp); | ||
| 760 | rcu_init_percpu_data(cpu, &rcu_bh_ctrlblk, bh_rdp); | ||
| 761 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | ||
| 762 | } | ||
| 763 | |||
| 764 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | ||
| 765 | unsigned long action, void *hcpu) | ||
| 766 | { | ||
| 767 | long cpu = (long)hcpu; | ||
| 768 | |||
| 769 | switch (action) { | ||
| 770 | case CPU_UP_PREPARE: | ||
| 771 | case CPU_UP_PREPARE_FROZEN: | ||
| 772 | rcu_online_cpu(cpu); | ||
| 773 | break; | ||
| 774 | case CPU_DEAD: | ||
| 775 | case CPU_DEAD_FROZEN: | ||
| 776 | rcu_offline_cpu(cpu); | ||
| 777 | break; | ||
| 778 | default: | ||
| 779 | break; | ||
| 780 | } | ||
| 781 | return NOTIFY_OK; | ||
| 782 | } | ||
| 783 | |||
| 784 | static struct notifier_block __cpuinitdata rcu_nb = { | ||
| 785 | .notifier_call = rcu_cpu_notify, | ||
| 786 | }; | ||
| 787 | |||
| 788 | /* | ||
| 789 | * Initializes rcu mechanism. Assumed to be called early. | ||
| 790 | * That is before local timer(SMP) or jiffie timer (uniproc) is setup. | ||
| 791 | * Note that rcu_qsctr and friends are implicitly | ||
| 792 | * initialized due to the choice of ``0'' for RCU_CTR_INVALID. | ||
| 793 | */ | ||
| 794 | void __init __rcu_init(void) | ||
| 795 | { | ||
| 796 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 797 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); | ||
| 798 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 799 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, | ||
| 800 | (void *)(long)smp_processor_id()); | ||
| 801 | /* Register notifier for non-boot CPUs */ | ||
| 802 | register_cpu_notifier(&rcu_nb); | ||
| 803 | } | ||
| 804 | |||
| 805 | module_param(blimit, int, 0); | ||
| 806 | module_param(qhimark, int, 0); | ||
| 807 | module_param(qlowmark, int, 0); | ||
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c index a967c9feb90a..bd5d5c8e5140 100644 --- a/kernel/rcupdate.c +++ b/kernel/rcupdate.c | |||
| @@ -98,6 +98,30 @@ void synchronize_rcu(void) | |||
| 98 | } | 98 | } |
| 99 | EXPORT_SYMBOL_GPL(synchronize_rcu); | 99 | EXPORT_SYMBOL_GPL(synchronize_rcu); |
| 100 | 100 | ||
| 101 | /** | ||
| 102 | * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed. | ||
| 103 | * | ||
| 104 | * Control will return to the caller some time after a full rcu_bh grace | ||
| 105 | * period has elapsed, in other words after all currently executing rcu_bh | ||
| 106 | * read-side critical sections have completed. RCU read-side critical | ||
| 107 | * sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(), | ||
| 108 | * and may be nested. | ||
| 109 | */ | ||
| 110 | void synchronize_rcu_bh(void) | ||
| 111 | { | ||
| 112 | struct rcu_synchronize rcu; | ||
| 113 | |||
| 114 | if (rcu_blocking_is_gp()) | ||
| 115 | return; | ||
| 116 | |||
| 117 | init_completion(&rcu.completion); | ||
| 118 | /* Will wake me after RCU finished. */ | ||
| 119 | call_rcu_bh(&rcu.head, wakeme_after_rcu); | ||
| 120 | /* Wait for it. */ | ||
| 121 | wait_for_completion(&rcu.completion); | ||
| 122 | } | ||
| 123 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | ||
| 124 | |||
| 101 | static void rcu_barrier_callback(struct rcu_head *notused) | 125 | static void rcu_barrier_callback(struct rcu_head *notused) |
| 102 | { | 126 | { |
| 103 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | 127 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) |
| @@ -129,6 +153,7 @@ static void rcu_barrier_func(void *type) | |||
| 129 | static inline void wait_migrated_callbacks(void) | 153 | static inline void wait_migrated_callbacks(void) |
| 130 | { | 154 | { |
| 131 | wait_event(rcu_migrate_wq, !atomic_read(&rcu_migrate_type_count)); | 155 | wait_event(rcu_migrate_wq, !atomic_read(&rcu_migrate_type_count)); |
| 156 | smp_mb(); /* In case we didn't sleep. */ | ||
| 132 | } | 157 | } |
| 133 | 158 | ||
| 134 | /* | 159 | /* |
| @@ -192,9 +217,13 @@ static void rcu_migrate_callback(struct rcu_head *notused) | |||
| 192 | wake_up(&rcu_migrate_wq); | 217 | wake_up(&rcu_migrate_wq); |
| 193 | } | 218 | } |
| 194 | 219 | ||
| 220 | extern int rcu_cpu_notify(struct notifier_block *self, | ||
| 221 | unsigned long action, void *hcpu); | ||
| 222 | |||
| 195 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | 223 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, |
| 196 | unsigned long action, void *hcpu) | 224 | unsigned long action, void *hcpu) |
| 197 | { | 225 | { |
| 226 | rcu_cpu_notify(self, action, hcpu); | ||
| 198 | if (action == CPU_DYING) { | 227 | if (action == CPU_DYING) { |
| 199 | /* | 228 | /* |
| 200 | * preempt_disable() in on_each_cpu() prevents stop_machine(), | 229 | * preempt_disable() in on_each_cpu() prevents stop_machine(), |
| @@ -209,7 +238,8 @@ static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | |||
| 209 | call_rcu_bh(rcu_migrate_head, rcu_migrate_callback); | 238 | call_rcu_bh(rcu_migrate_head, rcu_migrate_callback); |
| 210 | call_rcu_sched(rcu_migrate_head + 1, rcu_migrate_callback); | 239 | call_rcu_sched(rcu_migrate_head + 1, rcu_migrate_callback); |
| 211 | call_rcu(rcu_migrate_head + 2, rcu_migrate_callback); | 240 | call_rcu(rcu_migrate_head + 2, rcu_migrate_callback); |
| 212 | } else if (action == CPU_POST_DEAD) { | 241 | } else if (action == CPU_DOWN_PREPARE) { |
| 242 | /* Don't need to wait until next removal operation. */ | ||
| 213 | /* rcu_migrate_head is protected by cpu_add_remove_lock */ | 243 | /* rcu_migrate_head is protected by cpu_add_remove_lock */ |
| 214 | wait_migrated_callbacks(); | 244 | wait_migrated_callbacks(); |
| 215 | } | 245 | } |
| @@ -219,8 +249,18 @@ static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | |||
| 219 | 249 | ||
| 220 | void __init rcu_init(void) | 250 | void __init rcu_init(void) |
| 221 | { | 251 | { |
| 252 | int i; | ||
| 253 | |||
| 222 | __rcu_init(); | 254 | __rcu_init(); |
| 223 | hotcpu_notifier(rcu_barrier_cpu_hotplug, 0); | 255 | cpu_notifier(rcu_barrier_cpu_hotplug, 0); |
| 256 | |||
| 257 | /* | ||
| 258 | * We don't need protection against CPU-hotplug here because | ||
| 259 | * this is called early in boot, before either interrupts | ||
| 260 | * or the scheduler are operational. | ||
| 261 | */ | ||
| 262 | for_each_online_cpu(i) | ||
| 263 | rcu_barrier_cpu_hotplug(NULL, CPU_UP_PREPARE, (void *)(long)i); | ||
| 224 | } | 264 | } |
| 225 | 265 | ||
| 226 | void rcu_scheduler_starting(void) | 266 | void rcu_scheduler_starting(void) |
diff --git a/kernel/rcupreempt.c b/kernel/rcupreempt.c deleted file mode 100644 index beb0e659adcc..000000000000 --- a/kernel/rcupreempt.c +++ /dev/null | |||
| @@ -1,1539 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion, realtime implementation | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | * | ||
| 18 | * Copyright IBM Corporation, 2006 | ||
| 19 | * | ||
| 20 | * Authors: Paul E. McKenney <paulmck@us.ibm.com> | ||
| 21 | * With thanks to Esben Nielsen, Bill Huey, and Ingo Molnar | ||
| 22 | * for pushing me away from locks and towards counters, and | ||
| 23 | * to Suparna Bhattacharya for pushing me completely away | ||
| 24 | * from atomic instructions on the read side. | ||
| 25 | * | ||
| 26 | * - Added handling of Dynamic Ticks | ||
| 27 | * Copyright 2007 - Paul E. Mckenney <paulmck@us.ibm.com> | ||
| 28 | * - Steven Rostedt <srostedt@redhat.com> | ||
| 29 | * | ||
| 30 | * Papers: http://www.rdrop.com/users/paulmck/RCU | ||
| 31 | * | ||
| 32 | * Design Document: http://lwn.net/Articles/253651/ | ||
| 33 | * | ||
| 34 | * For detailed explanation of Read-Copy Update mechanism see - | ||
| 35 | * Documentation/RCU/ *.txt | ||
| 36 | * | ||
| 37 | */ | ||
| 38 | #include <linux/types.h> | ||
| 39 | #include <linux/kernel.h> | ||
| 40 | #include <linux/init.h> | ||
| 41 | #include <linux/spinlock.h> | ||
| 42 | #include <linux/smp.h> | ||
| 43 | #include <linux/rcupdate.h> | ||
| 44 | #include <linux/interrupt.h> | ||
| 45 | #include <linux/sched.h> | ||
| 46 | #include <asm/atomic.h> | ||
| 47 | #include <linux/bitops.h> | ||
| 48 | #include <linux/module.h> | ||
| 49 | #include <linux/kthread.h> | ||
| 50 | #include <linux/completion.h> | ||
| 51 | #include <linux/moduleparam.h> | ||
| 52 | #include <linux/percpu.h> | ||
| 53 | #include <linux/notifier.h> | ||
| 54 | #include <linux/cpu.h> | ||
| 55 | #include <linux/random.h> | ||
| 56 | #include <linux/delay.h> | ||
| 57 | #include <linux/cpumask.h> | ||
| 58 | #include <linux/rcupreempt_trace.h> | ||
| 59 | #include <asm/byteorder.h> | ||
| 60 | |||
| 61 | /* | ||
| 62 | * PREEMPT_RCU data structures. | ||
| 63 | */ | ||
| 64 | |||
| 65 | /* | ||
| 66 | * GP_STAGES specifies the number of times the state machine has | ||
| 67 | * to go through the all the rcu_try_flip_states (see below) | ||
| 68 | * in a single Grace Period. | ||
| 69 | * | ||
| 70 | * GP in GP_STAGES stands for Grace Period ;) | ||
| 71 | */ | ||
| 72 | #define GP_STAGES 2 | ||
| 73 | struct rcu_data { | ||
| 74 | spinlock_t lock; /* Protect rcu_data fields. */ | ||
| 75 | long completed; /* Number of last completed batch. */ | ||
| 76 | int waitlistcount; | ||
| 77 | struct rcu_head *nextlist; | ||
| 78 | struct rcu_head **nexttail; | ||
| 79 | struct rcu_head *waitlist[GP_STAGES]; | ||
| 80 | struct rcu_head **waittail[GP_STAGES]; | ||
| 81 | struct rcu_head *donelist; /* from waitlist & waitschedlist */ | ||
| 82 | struct rcu_head **donetail; | ||
| 83 | long rcu_flipctr[2]; | ||
| 84 | struct rcu_head *nextschedlist; | ||
| 85 | struct rcu_head **nextschedtail; | ||
| 86 | struct rcu_head *waitschedlist; | ||
| 87 | struct rcu_head **waitschedtail; | ||
| 88 | int rcu_sched_sleeping; | ||
| 89 | #ifdef CONFIG_RCU_TRACE | ||
| 90 | struct rcupreempt_trace trace; | ||
| 91 | #endif /* #ifdef CONFIG_RCU_TRACE */ | ||
| 92 | }; | ||
| 93 | |||
| 94 | /* | ||
| 95 | * States for rcu_try_flip() and friends. | ||
| 96 | */ | ||
| 97 | |||
| 98 | enum rcu_try_flip_states { | ||
| 99 | |||
| 100 | /* | ||
| 101 | * Stay here if nothing is happening. Flip the counter if somthing | ||
| 102 | * starts happening. Denoted by "I" | ||
| 103 | */ | ||
| 104 | rcu_try_flip_idle_state, | ||
| 105 | |||
| 106 | /* | ||
| 107 | * Wait here for all CPUs to notice that the counter has flipped. This | ||
| 108 | * prevents the old set of counters from ever being incremented once | ||
| 109 | * we leave this state, which in turn is necessary because we cannot | ||
| 110 | * test any individual counter for zero -- we can only check the sum. | ||
| 111 | * Denoted by "A". | ||
| 112 | */ | ||
| 113 | rcu_try_flip_waitack_state, | ||
| 114 | |||
| 115 | /* | ||
| 116 | * Wait here for the sum of the old per-CPU counters to reach zero. | ||
| 117 | * Denoted by "Z". | ||
| 118 | */ | ||
| 119 | rcu_try_flip_waitzero_state, | ||
| 120 | |||
| 121 | /* | ||
| 122 | * Wait here for each of the other CPUs to execute a memory barrier. | ||
| 123 | * This is necessary to ensure that these other CPUs really have | ||
| 124 | * completed executing their RCU read-side critical sections, despite | ||
| 125 | * their CPUs wildly reordering memory. Denoted by "M". | ||
| 126 | */ | ||
| 127 | rcu_try_flip_waitmb_state, | ||
| 128 | }; | ||
| 129 | |||
| 130 | /* | ||
| 131 | * States for rcu_ctrlblk.rcu_sched_sleep. | ||
| 132 | */ | ||
| 133 | |||
| 134 | enum rcu_sched_sleep_states { | ||
| 135 | rcu_sched_not_sleeping, /* Not sleeping, callbacks need GP. */ | ||
| 136 | rcu_sched_sleep_prep, /* Thinking of sleeping, rechecking. */ | ||
| 137 | rcu_sched_sleeping, /* Sleeping, awaken if GP needed. */ | ||
| 138 | }; | ||
| 139 | |||
| 140 | struct rcu_ctrlblk { | ||
| 141 | spinlock_t fliplock; /* Protect state-machine transitions. */ | ||
| 142 | long completed; /* Number of last completed batch. */ | ||
| 143 | enum rcu_try_flip_states rcu_try_flip_state; /* The current state of | ||
| 144 | the rcu state machine */ | ||
| 145 | spinlock_t schedlock; /* Protect rcu_sched sleep state. */ | ||
| 146 | enum rcu_sched_sleep_states sched_sleep; /* rcu_sched state. */ | ||
| 147 | wait_queue_head_t sched_wq; /* Place for rcu_sched to sleep. */ | ||
| 148 | }; | ||
| 149 | |||
| 150 | struct rcu_dyntick_sched { | ||
| 151 | int dynticks; | ||
| 152 | int dynticks_snap; | ||
| 153 | int sched_qs; | ||
| 154 | int sched_qs_snap; | ||
| 155 | int sched_dynticks_snap; | ||
| 156 | }; | ||
| 157 | |||
| 158 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_dyntick_sched, rcu_dyntick_sched) = { | ||
| 159 | .dynticks = 1, | ||
| 160 | }; | ||
| 161 | |||
| 162 | void rcu_qsctr_inc(int cpu) | ||
| 163 | { | ||
| 164 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 165 | |||
| 166 | rdssp->sched_qs++; | ||
| 167 | } | ||
| 168 | |||
| 169 | #ifdef CONFIG_NO_HZ | ||
| 170 | |||
| 171 | void rcu_enter_nohz(void) | ||
| 172 | { | ||
| 173 | static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1); | ||
| 174 | |||
| 175 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | ||
| 176 | __get_cpu_var(rcu_dyntick_sched).dynticks++; | ||
| 177 | WARN_ON_RATELIMIT(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, &rs); | ||
| 178 | } | ||
| 179 | |||
| 180 | void rcu_exit_nohz(void) | ||
| 181 | { | ||
| 182 | static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1); | ||
| 183 | |||
| 184 | __get_cpu_var(rcu_dyntick_sched).dynticks++; | ||
| 185 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | ||
| 186 | WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1), | ||
| 187 | &rs); | ||
| 188 | } | ||
| 189 | |||
| 190 | #endif /* CONFIG_NO_HZ */ | ||
| 191 | |||
| 192 | |||
| 193 | static DEFINE_PER_CPU(struct rcu_data, rcu_data); | ||
| 194 | |||
| 195 | static struct rcu_ctrlblk rcu_ctrlblk = { | ||
| 196 | .fliplock = __SPIN_LOCK_UNLOCKED(rcu_ctrlblk.fliplock), | ||
| 197 | .completed = 0, | ||
| 198 | .rcu_try_flip_state = rcu_try_flip_idle_state, | ||
| 199 | .schedlock = __SPIN_LOCK_UNLOCKED(rcu_ctrlblk.schedlock), | ||
| 200 | .sched_sleep = rcu_sched_not_sleeping, | ||
| 201 | .sched_wq = __WAIT_QUEUE_HEAD_INITIALIZER(rcu_ctrlblk.sched_wq), | ||
| 202 | }; | ||
| 203 | |||
| 204 | static struct task_struct *rcu_sched_grace_period_task; | ||
| 205 | |||
| 206 | #ifdef CONFIG_RCU_TRACE | ||
| 207 | static char *rcu_try_flip_state_names[] = | ||
| 208 | { "idle", "waitack", "waitzero", "waitmb" }; | ||
| 209 | #endif /* #ifdef CONFIG_RCU_TRACE */ | ||
| 210 | |||
| 211 | static DECLARE_BITMAP(rcu_cpu_online_map, NR_CPUS) __read_mostly | ||
| 212 | = CPU_BITS_NONE; | ||
| 213 | |||
| 214 | /* | ||
| 215 | * Enum and per-CPU flag to determine when each CPU has seen | ||
| 216 | * the most recent counter flip. | ||
| 217 | */ | ||
| 218 | |||
| 219 | enum rcu_flip_flag_values { | ||
| 220 | rcu_flip_seen, /* Steady/initial state, last flip seen. */ | ||
| 221 | /* Only GP detector can update. */ | ||
| 222 | rcu_flipped /* Flip just completed, need confirmation. */ | ||
| 223 | /* Only corresponding CPU can update. */ | ||
| 224 | }; | ||
| 225 | static DEFINE_PER_CPU_SHARED_ALIGNED(enum rcu_flip_flag_values, rcu_flip_flag) | ||
| 226 | = rcu_flip_seen; | ||
| 227 | |||
| 228 | /* | ||
| 229 | * Enum and per-CPU flag to determine when each CPU has executed the | ||
| 230 | * needed memory barrier to fence in memory references from its last RCU | ||
| 231 | * read-side critical section in the just-completed grace period. | ||
| 232 | */ | ||
| 233 | |||
| 234 | enum rcu_mb_flag_values { | ||
| 235 | rcu_mb_done, /* Steady/initial state, no mb()s required. */ | ||
| 236 | /* Only GP detector can update. */ | ||
| 237 | rcu_mb_needed /* Flip just completed, need an mb(). */ | ||
| 238 | /* Only corresponding CPU can update. */ | ||
| 239 | }; | ||
| 240 | static DEFINE_PER_CPU_SHARED_ALIGNED(enum rcu_mb_flag_values, rcu_mb_flag) | ||
| 241 | = rcu_mb_done; | ||
| 242 | |||
| 243 | /* | ||
| 244 | * RCU_DATA_ME: find the current CPU's rcu_data structure. | ||
| 245 | * RCU_DATA_CPU: find the specified CPU's rcu_data structure. | ||
| 246 | */ | ||
| 247 | #define RCU_DATA_ME() (&__get_cpu_var(rcu_data)) | ||
| 248 | #define RCU_DATA_CPU(cpu) (&per_cpu(rcu_data, cpu)) | ||
| 249 | |||
| 250 | /* | ||
| 251 | * Helper macro for tracing when the appropriate rcu_data is not | ||
| 252 | * cached in a local variable, but where the CPU number is so cached. | ||
| 253 | */ | ||
| 254 | #define RCU_TRACE_CPU(f, cpu) RCU_TRACE(f, &(RCU_DATA_CPU(cpu)->trace)); | ||
| 255 | |||
| 256 | /* | ||
| 257 | * Helper macro for tracing when the appropriate rcu_data is not | ||
| 258 | * cached in a local variable. | ||
| 259 | */ | ||
| 260 | #define RCU_TRACE_ME(f) RCU_TRACE(f, &(RCU_DATA_ME()->trace)); | ||
| 261 | |||
| 262 | /* | ||
| 263 | * Helper macro for tracing when the appropriate rcu_data is pointed | ||
| 264 | * to by a local variable. | ||
| 265 | */ | ||
| 266 | #define RCU_TRACE_RDP(f, rdp) RCU_TRACE(f, &((rdp)->trace)); | ||
| 267 | |||
| 268 | #define RCU_SCHED_BATCH_TIME (HZ / 50) | ||
| 269 | |||
| 270 | /* | ||
| 271 | * Return the number of RCU batches processed thus far. Useful | ||
| 272 | * for debug and statistics. | ||
| 273 | */ | ||
| 274 | long rcu_batches_completed(void) | ||
| 275 | { | ||
| 276 | return rcu_ctrlblk.completed; | ||
| 277 | } | ||
| 278 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 279 | |||
| 280 | void __rcu_read_lock(void) | ||
| 281 | { | ||
| 282 | int idx; | ||
| 283 | struct task_struct *t = current; | ||
| 284 | int nesting; | ||
| 285 | |||
| 286 | nesting = ACCESS_ONCE(t->rcu_read_lock_nesting); | ||
| 287 | if (nesting != 0) { | ||
| 288 | |||
| 289 | /* An earlier rcu_read_lock() covers us, just count it. */ | ||
| 290 | |||
| 291 | t->rcu_read_lock_nesting = nesting + 1; | ||
| 292 | |||
| 293 | } else { | ||
| 294 | unsigned long flags; | ||
| 295 | |||
| 296 | /* | ||
| 297 | * We disable interrupts for the following reasons: | ||
| 298 | * - If we get scheduling clock interrupt here, and we | ||
| 299 | * end up acking the counter flip, it's like a promise | ||
| 300 | * that we will never increment the old counter again. | ||
| 301 | * Thus we will break that promise if that | ||
| 302 | * scheduling clock interrupt happens between the time | ||
| 303 | * we pick the .completed field and the time that we | ||
| 304 | * increment our counter. | ||
| 305 | * | ||
| 306 | * - We don't want to be preempted out here. | ||
| 307 | * | ||
| 308 | * NMIs can still occur, of course, and might themselves | ||
| 309 | * contain rcu_read_lock(). | ||
| 310 | */ | ||
| 311 | |||
| 312 | local_irq_save(flags); | ||
| 313 | |||
| 314 | /* | ||
| 315 | * Outermost nesting of rcu_read_lock(), so increment | ||
| 316 | * the current counter for the current CPU. Use volatile | ||
| 317 | * casts to prevent the compiler from reordering. | ||
| 318 | */ | ||
| 319 | |||
| 320 | idx = ACCESS_ONCE(rcu_ctrlblk.completed) & 0x1; | ||
| 321 | ACCESS_ONCE(RCU_DATA_ME()->rcu_flipctr[idx])++; | ||
| 322 | |||
| 323 | /* | ||
| 324 | * Now that the per-CPU counter has been incremented, we | ||
| 325 | * are protected from races with rcu_read_lock() invoked | ||
| 326 | * from NMI handlers on this CPU. We can therefore safely | ||
| 327 | * increment the nesting counter, relieving further NMIs | ||
| 328 | * of the need to increment the per-CPU counter. | ||
| 329 | */ | ||
| 330 | |||
| 331 | ACCESS_ONCE(t->rcu_read_lock_nesting) = nesting + 1; | ||
| 332 | |||
| 333 | /* | ||
| 334 | * Now that we have preventing any NMIs from storing | ||
| 335 | * to the ->rcu_flipctr_idx, we can safely use it to | ||
| 336 | * remember which counter to decrement in the matching | ||
| 337 | * rcu_read_unlock(). | ||
| 338 | */ | ||
| 339 | |||
| 340 | ACCESS_ONCE(t->rcu_flipctr_idx) = idx; | ||
| 341 | local_irq_restore(flags); | ||
| 342 | } | ||
| 343 | } | ||
| 344 | EXPORT_SYMBOL_GPL(__rcu_read_lock); | ||
| 345 | |||
| 346 | void __rcu_read_unlock(void) | ||
| 347 | { | ||
| 348 | int idx; | ||
| 349 | struct task_struct *t = current; | ||
| 350 | int nesting; | ||
| 351 | |||
| 352 | nesting = ACCESS_ONCE(t->rcu_read_lock_nesting); | ||
| 353 | if (nesting > 1) { | ||
| 354 | |||
| 355 | /* | ||
| 356 | * We are still protected by the enclosing rcu_read_lock(), | ||
| 357 | * so simply decrement the counter. | ||
| 358 | */ | ||
| 359 | |||
| 360 | t->rcu_read_lock_nesting = nesting - 1; | ||
| 361 | |||
| 362 | } else { | ||
| 363 | unsigned long flags; | ||
| 364 | |||
| 365 | /* | ||
| 366 | * Disable local interrupts to prevent the grace-period | ||
| 367 | * detection state machine from seeing us half-done. | ||
| 368 | * NMIs can still occur, of course, and might themselves | ||
| 369 | * contain rcu_read_lock() and rcu_read_unlock(). | ||
| 370 | */ | ||
| 371 | |||
| 372 | local_irq_save(flags); | ||
| 373 | |||
| 374 | /* | ||
| 375 | * Outermost nesting of rcu_read_unlock(), so we must | ||
| 376 | * decrement the current counter for the current CPU. | ||
| 377 | * This must be done carefully, because NMIs can | ||
| 378 | * occur at any point in this code, and any rcu_read_lock() | ||
| 379 | * and rcu_read_unlock() pairs in the NMI handlers | ||
| 380 | * must interact non-destructively with this code. | ||
| 381 | * Lots of volatile casts, and -very- careful ordering. | ||
| 382 | * | ||
| 383 | * Changes to this code, including this one, must be | ||
| 384 | * inspected, validated, and tested extremely carefully!!! | ||
| 385 | */ | ||
| 386 | |||
| 387 | /* | ||
| 388 | * First, pick up the index. | ||
| 389 | */ | ||
| 390 | |||
| 391 | idx = ACCESS_ONCE(t->rcu_flipctr_idx); | ||
| 392 | |||
| 393 | /* | ||
| 394 | * Now that we have fetched the counter index, it is | ||
| 395 | * safe to decrement the per-task RCU nesting counter. | ||
| 396 | * After this, any interrupts or NMIs will increment and | ||
| 397 | * decrement the per-CPU counters. | ||
| 398 | */ | ||
| 399 | ACCESS_ONCE(t->rcu_read_lock_nesting) = nesting - 1; | ||
| 400 | |||
| 401 | /* | ||
| 402 | * It is now safe to decrement this task's nesting count. | ||
| 403 | * NMIs that occur after this statement will route their | ||
| 404 | * rcu_read_lock() calls through this "else" clause, and | ||
| 405 | * will thus start incrementing the per-CPU counter on | ||
| 406 | * their own. They will also clobber ->rcu_flipctr_idx, | ||
| 407 | * but that is OK, since we have already fetched it. | ||
| 408 | */ | ||
| 409 | |||
| 410 | ACCESS_ONCE(RCU_DATA_ME()->rcu_flipctr[idx])--; | ||
| 411 | local_irq_restore(flags); | ||
| 412 | } | ||
| 413 | } | ||
| 414 | EXPORT_SYMBOL_GPL(__rcu_read_unlock); | ||
| 415 | |||
| 416 | /* | ||
| 417 | * If a global counter flip has occurred since the last time that we | ||
| 418 | * advanced callbacks, advance them. Hardware interrupts must be | ||
| 419 | * disabled when calling this function. | ||
| 420 | */ | ||
| 421 | static void __rcu_advance_callbacks(struct rcu_data *rdp) | ||
| 422 | { | ||
| 423 | int cpu; | ||
| 424 | int i; | ||
| 425 | int wlc = 0; | ||
| 426 | |||
| 427 | if (rdp->completed != rcu_ctrlblk.completed) { | ||
| 428 | if (rdp->waitlist[GP_STAGES - 1] != NULL) { | ||
| 429 | *rdp->donetail = rdp->waitlist[GP_STAGES - 1]; | ||
| 430 | rdp->donetail = rdp->waittail[GP_STAGES - 1]; | ||
| 431 | RCU_TRACE_RDP(rcupreempt_trace_move2done, rdp); | ||
| 432 | } | ||
| 433 | for (i = GP_STAGES - 2; i >= 0; i--) { | ||
| 434 | if (rdp->waitlist[i] != NULL) { | ||
| 435 | rdp->waitlist[i + 1] = rdp->waitlist[i]; | ||
| 436 | rdp->waittail[i + 1] = rdp->waittail[i]; | ||
| 437 | wlc++; | ||
| 438 | } else { | ||
| 439 | rdp->waitlist[i + 1] = NULL; | ||
| 440 | rdp->waittail[i + 1] = | ||
| 441 | &rdp->waitlist[i + 1]; | ||
| 442 | } | ||
| 443 | } | ||
| 444 | if (rdp->nextlist != NULL) { | ||
| 445 | rdp->waitlist[0] = rdp->nextlist; | ||
| 446 | rdp->waittail[0] = rdp->nexttail; | ||
| 447 | wlc++; | ||
| 448 | rdp->nextlist = NULL; | ||
| 449 | rdp->nexttail = &rdp->nextlist; | ||
| 450 | RCU_TRACE_RDP(rcupreempt_trace_move2wait, rdp); | ||
| 451 | } else { | ||
| 452 | rdp->waitlist[0] = NULL; | ||
| 453 | rdp->waittail[0] = &rdp->waitlist[0]; | ||
| 454 | } | ||
| 455 | rdp->waitlistcount = wlc; | ||
| 456 | rdp->completed = rcu_ctrlblk.completed; | ||
| 457 | } | ||
| 458 | |||
| 459 | /* | ||
| 460 | * Check to see if this CPU needs to report that it has seen | ||
| 461 | * the most recent counter flip, thereby declaring that all | ||
| 462 | * subsequent rcu_read_lock() invocations will respect this flip. | ||
| 463 | */ | ||
| 464 | |||
| 465 | cpu = raw_smp_processor_id(); | ||
| 466 | if (per_cpu(rcu_flip_flag, cpu) == rcu_flipped) { | ||
| 467 | smp_mb(); /* Subsequent counter accesses must see new value */ | ||
| 468 | per_cpu(rcu_flip_flag, cpu) = rcu_flip_seen; | ||
| 469 | smp_mb(); /* Subsequent RCU read-side critical sections */ | ||
| 470 | /* seen -after- acknowledgement. */ | ||
| 471 | } | ||
| 472 | } | ||
| 473 | |||
| 474 | #ifdef CONFIG_NO_HZ | ||
| 475 | static DEFINE_PER_CPU(int, rcu_update_flag); | ||
| 476 | |||
| 477 | /** | ||
| 478 | * rcu_irq_enter - Called from Hard irq handlers and NMI/SMI. | ||
| 479 | * | ||
| 480 | * If the CPU was idle with dynamic ticks active, this updates the | ||
| 481 | * rcu_dyntick_sched.dynticks to let the RCU handling know that the | ||
| 482 | * CPU is active. | ||
| 483 | */ | ||
| 484 | void rcu_irq_enter(void) | ||
| 485 | { | ||
| 486 | int cpu = smp_processor_id(); | ||
| 487 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 488 | |||
| 489 | if (per_cpu(rcu_update_flag, cpu)) | ||
| 490 | per_cpu(rcu_update_flag, cpu)++; | ||
| 491 | |||
| 492 | /* | ||
| 493 | * Only update if we are coming from a stopped ticks mode | ||
| 494 | * (rcu_dyntick_sched.dynticks is even). | ||
| 495 | */ | ||
| 496 | if (!in_interrupt() && | ||
| 497 | (rdssp->dynticks & 0x1) == 0) { | ||
| 498 | /* | ||
| 499 | * The following might seem like we could have a race | ||
| 500 | * with NMI/SMIs. But this really isn't a problem. | ||
| 501 | * Here we do a read/modify/write, and the race happens | ||
| 502 | * when an NMI/SMI comes in after the read and before | ||
| 503 | * the write. But NMI/SMIs will increment this counter | ||
| 504 | * twice before returning, so the zero bit will not | ||
| 505 | * be corrupted by the NMI/SMI which is the most important | ||
| 506 | * part. | ||
| 507 | * | ||
| 508 | * The only thing is that we would bring back the counter | ||
| 509 | * to a postion that it was in during the NMI/SMI. | ||
| 510 | * But the zero bit would be set, so the rest of the | ||
| 511 | * counter would again be ignored. | ||
| 512 | * | ||
| 513 | * On return from the IRQ, the counter may have the zero | ||
| 514 | * bit be 0 and the counter the same as the return from | ||
| 515 | * the NMI/SMI. If the state machine was so unlucky to | ||
| 516 | * see that, it still doesn't matter, since all | ||
| 517 | * RCU read-side critical sections on this CPU would | ||
| 518 | * have already completed. | ||
| 519 | */ | ||
| 520 | rdssp->dynticks++; | ||
| 521 | /* | ||
| 522 | * The following memory barrier ensures that any | ||
| 523 | * rcu_read_lock() primitives in the irq handler | ||
| 524 | * are seen by other CPUs to follow the above | ||
| 525 | * increment to rcu_dyntick_sched.dynticks. This is | ||
| 526 | * required in order for other CPUs to correctly | ||
| 527 | * determine when it is safe to advance the RCU | ||
| 528 | * grace-period state machine. | ||
| 529 | */ | ||
| 530 | smp_mb(); /* see above block comment. */ | ||
| 531 | /* | ||
| 532 | * Since we can't determine the dynamic tick mode from | ||
| 533 | * the rcu_dyntick_sched.dynticks after this routine, | ||
| 534 | * we use a second flag to acknowledge that we came | ||
| 535 | * from an idle state with ticks stopped. | ||
| 536 | */ | ||
| 537 | per_cpu(rcu_update_flag, cpu)++; | ||
| 538 | /* | ||
| 539 | * If we take an NMI/SMI now, they will also increment | ||
| 540 | * the rcu_update_flag, and will not update the | ||
| 541 | * rcu_dyntick_sched.dynticks on exit. That is for | ||
| 542 | * this IRQ to do. | ||
| 543 | */ | ||
| 544 | } | ||
| 545 | } | ||
| 546 | |||
| 547 | /** | ||
| 548 | * rcu_irq_exit - Called from exiting Hard irq context. | ||
| 549 | * | ||
| 550 | * If the CPU was idle with dynamic ticks active, update the | ||
| 551 | * rcu_dyntick_sched.dynticks to put let the RCU handling be | ||
| 552 | * aware that the CPU is going back to idle with no ticks. | ||
| 553 | */ | ||
| 554 | void rcu_irq_exit(void) | ||
| 555 | { | ||
| 556 | int cpu = smp_processor_id(); | ||
| 557 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 558 | |||
| 559 | /* | ||
| 560 | * rcu_update_flag is set if we interrupted the CPU | ||
| 561 | * when it was idle with ticks stopped. | ||
| 562 | * Once this occurs, we keep track of interrupt nesting | ||
| 563 | * because a NMI/SMI could also come in, and we still | ||
| 564 | * only want the IRQ that started the increment of the | ||
| 565 | * rcu_dyntick_sched.dynticks to be the one that modifies | ||
| 566 | * it on exit. | ||
| 567 | */ | ||
| 568 | if (per_cpu(rcu_update_flag, cpu)) { | ||
| 569 | if (--per_cpu(rcu_update_flag, cpu)) | ||
| 570 | return; | ||
| 571 | |||
| 572 | /* This must match the interrupt nesting */ | ||
| 573 | WARN_ON(in_interrupt()); | ||
| 574 | |||
| 575 | /* | ||
| 576 | * If an NMI/SMI happens now we are still | ||
| 577 | * protected by the rcu_dyntick_sched.dynticks being odd. | ||
| 578 | */ | ||
| 579 | |||
| 580 | /* | ||
| 581 | * The following memory barrier ensures that any | ||
| 582 | * rcu_read_unlock() primitives in the irq handler | ||
| 583 | * are seen by other CPUs to preceed the following | ||
| 584 | * increment to rcu_dyntick_sched.dynticks. This | ||
| 585 | * is required in order for other CPUs to determine | ||
| 586 | * when it is safe to advance the RCU grace-period | ||
| 587 | * state machine. | ||
| 588 | */ | ||
| 589 | smp_mb(); /* see above block comment. */ | ||
| 590 | rdssp->dynticks++; | ||
| 591 | WARN_ON(rdssp->dynticks & 0x1); | ||
| 592 | } | ||
| 593 | } | ||
| 594 | |||
| 595 | void rcu_nmi_enter(void) | ||
| 596 | { | ||
| 597 | rcu_irq_enter(); | ||
| 598 | } | ||
| 599 | |||
| 600 | void rcu_nmi_exit(void) | ||
| 601 | { | ||
| 602 | rcu_irq_exit(); | ||
| 603 | } | ||
| 604 | |||
| 605 | static void dyntick_save_progress_counter(int cpu) | ||
| 606 | { | ||
| 607 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 608 | |||
| 609 | rdssp->dynticks_snap = rdssp->dynticks; | ||
| 610 | } | ||
| 611 | |||
| 612 | static inline int | ||
| 613 | rcu_try_flip_waitack_needed(int cpu) | ||
| 614 | { | ||
| 615 | long curr; | ||
| 616 | long snap; | ||
| 617 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 618 | |||
| 619 | curr = rdssp->dynticks; | ||
| 620 | snap = rdssp->dynticks_snap; | ||
| 621 | smp_mb(); /* force ordering with cpu entering/leaving dynticks. */ | ||
| 622 | |||
| 623 | /* | ||
| 624 | * If the CPU remained in dynticks mode for the entire time | ||
| 625 | * and didn't take any interrupts, NMIs, SMIs, or whatever, | ||
| 626 | * then it cannot be in the middle of an rcu_read_lock(), so | ||
| 627 | * the next rcu_read_lock() it executes must use the new value | ||
| 628 | * of the counter. So we can safely pretend that this CPU | ||
| 629 | * already acknowledged the counter. | ||
| 630 | */ | ||
| 631 | |||
| 632 | if ((curr == snap) && ((curr & 0x1) == 0)) | ||
| 633 | return 0; | ||
| 634 | |||
| 635 | /* | ||
| 636 | * If the CPU passed through or entered a dynticks idle phase with | ||
| 637 | * no active irq handlers, then, as above, we can safely pretend | ||
| 638 | * that this CPU already acknowledged the counter. | ||
| 639 | */ | ||
| 640 | |||
| 641 | if ((curr - snap) > 2 || (curr & 0x1) == 0) | ||
| 642 | return 0; | ||
| 643 | |||
| 644 | /* We need this CPU to explicitly acknowledge the counter flip. */ | ||
| 645 | |||
| 646 | return 1; | ||
| 647 | } | ||
| 648 | |||
| 649 | static inline int | ||
| 650 | rcu_try_flip_waitmb_needed(int cpu) | ||
| 651 | { | ||
| 652 | long curr; | ||
| 653 | long snap; | ||
| 654 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 655 | |||
| 656 | curr = rdssp->dynticks; | ||
| 657 | snap = rdssp->dynticks_snap; | ||
| 658 | smp_mb(); /* force ordering with cpu entering/leaving dynticks. */ | ||
| 659 | |||
| 660 | /* | ||
| 661 | * If the CPU remained in dynticks mode for the entire time | ||
| 662 | * and didn't take any interrupts, NMIs, SMIs, or whatever, | ||
| 663 | * then it cannot have executed an RCU read-side critical section | ||
| 664 | * during that time, so there is no need for it to execute a | ||
| 665 | * memory barrier. | ||
| 666 | */ | ||
| 667 | |||
| 668 | if ((curr == snap) && ((curr & 0x1) == 0)) | ||
| 669 | return 0; | ||
| 670 | |||
| 671 | /* | ||
| 672 | * If the CPU either entered or exited an outermost interrupt, | ||
| 673 | * SMI, NMI, or whatever handler, then we know that it executed | ||
| 674 | * a memory barrier when doing so. So we don't need another one. | ||
| 675 | */ | ||
| 676 | if (curr != snap) | ||
| 677 | return 0; | ||
| 678 | |||
| 679 | /* We need the CPU to execute a memory barrier. */ | ||
| 680 | |||
| 681 | return 1; | ||
| 682 | } | ||
| 683 | |||
| 684 | static void dyntick_save_progress_counter_sched(int cpu) | ||
| 685 | { | ||
| 686 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 687 | |||
| 688 | rdssp->sched_dynticks_snap = rdssp->dynticks; | ||
| 689 | } | ||
| 690 | |||
| 691 | static int rcu_qsctr_inc_needed_dyntick(int cpu) | ||
| 692 | { | ||
| 693 | long curr; | ||
| 694 | long snap; | ||
| 695 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 696 | |||
| 697 | curr = rdssp->dynticks; | ||
| 698 | snap = rdssp->sched_dynticks_snap; | ||
| 699 | smp_mb(); /* force ordering with cpu entering/leaving dynticks. */ | ||
| 700 | |||
| 701 | /* | ||
| 702 | * If the CPU remained in dynticks mode for the entire time | ||
| 703 | * and didn't take any interrupts, NMIs, SMIs, or whatever, | ||
| 704 | * then it cannot be in the middle of an rcu_read_lock(), so | ||
| 705 | * the next rcu_read_lock() it executes must use the new value | ||
| 706 | * of the counter. Therefore, this CPU has been in a quiescent | ||
| 707 | * state the entire time, and we don't need to wait for it. | ||
| 708 | */ | ||
| 709 | |||
| 710 | if ((curr == snap) && ((curr & 0x1) == 0)) | ||
| 711 | return 0; | ||
| 712 | |||
| 713 | /* | ||
| 714 | * If the CPU passed through or entered a dynticks idle phase with | ||
| 715 | * no active irq handlers, then, as above, this CPU has already | ||
| 716 | * passed through a quiescent state. | ||
| 717 | */ | ||
| 718 | |||
| 719 | if ((curr - snap) > 2 || (snap & 0x1) == 0) | ||
| 720 | return 0; | ||
| 721 | |||
| 722 | /* We need this CPU to go through a quiescent state. */ | ||
| 723 | |||
| 724 | return 1; | ||
| 725 | } | ||
| 726 | |||
| 727 | #else /* !CONFIG_NO_HZ */ | ||
| 728 | |||
| 729 | # define dyntick_save_progress_counter(cpu) do { } while (0) | ||
| 730 | # define rcu_try_flip_waitack_needed(cpu) (1) | ||
| 731 | # define rcu_try_flip_waitmb_needed(cpu) (1) | ||
| 732 | |||
| 733 | # define dyntick_save_progress_counter_sched(cpu) do { } while (0) | ||
| 734 | # define rcu_qsctr_inc_needed_dyntick(cpu) (1) | ||
| 735 | |||
| 736 | #endif /* CONFIG_NO_HZ */ | ||
| 737 | |||
| 738 | static void save_qsctr_sched(int cpu) | ||
| 739 | { | ||
| 740 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 741 | |||
| 742 | rdssp->sched_qs_snap = rdssp->sched_qs; | ||
| 743 | } | ||
| 744 | |||
| 745 | static inline int rcu_qsctr_inc_needed(int cpu) | ||
| 746 | { | ||
| 747 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 748 | |||
| 749 | /* | ||
| 750 | * If there has been a quiescent state, no more need to wait | ||
| 751 | * on this CPU. | ||
| 752 | */ | ||
| 753 | |||
| 754 | if (rdssp->sched_qs != rdssp->sched_qs_snap) { | ||
| 755 | smp_mb(); /* force ordering with cpu entering schedule(). */ | ||
| 756 | return 0; | ||
| 757 | } | ||
| 758 | |||
| 759 | /* We need this CPU to go through a quiescent state. */ | ||
| 760 | |||
| 761 | return 1; | ||
| 762 | } | ||
| 763 | |||
| 764 | /* | ||
| 765 | * Get here when RCU is idle. Decide whether we need to | ||
| 766 | * move out of idle state, and return non-zero if so. | ||
| 767 | * "Straightforward" approach for the moment, might later | ||
| 768 | * use callback-list lengths, grace-period duration, or | ||
| 769 | * some such to determine when to exit idle state. | ||
| 770 | * Might also need a pre-idle test that does not acquire | ||
| 771 | * the lock, but let's get the simple case working first... | ||
| 772 | */ | ||
| 773 | |||
| 774 | static int | ||
| 775 | rcu_try_flip_idle(void) | ||
| 776 | { | ||
| 777 | int cpu; | ||
| 778 | |||
| 779 | RCU_TRACE_ME(rcupreempt_trace_try_flip_i1); | ||
| 780 | if (!rcu_pending(smp_processor_id())) { | ||
| 781 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ie1); | ||
| 782 | return 0; | ||
| 783 | } | ||
| 784 | |||
| 785 | /* | ||
| 786 | * Do the flip. | ||
| 787 | */ | ||
| 788 | |||
| 789 | RCU_TRACE_ME(rcupreempt_trace_try_flip_g1); | ||
| 790 | rcu_ctrlblk.completed++; /* stands in for rcu_try_flip_g2 */ | ||
| 791 | |||
| 792 | /* | ||
| 793 | * Need a memory barrier so that other CPUs see the new | ||
| 794 | * counter value before they see the subsequent change of all | ||
| 795 | * the rcu_flip_flag instances to rcu_flipped. | ||
| 796 | */ | ||
| 797 | |||
| 798 | smp_mb(); /* see above block comment. */ | ||
| 799 | |||
| 800 | /* Now ask each CPU for acknowledgement of the flip. */ | ||
| 801 | |||
| 802 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) { | ||
| 803 | per_cpu(rcu_flip_flag, cpu) = rcu_flipped; | ||
| 804 | dyntick_save_progress_counter(cpu); | ||
| 805 | } | ||
| 806 | |||
| 807 | return 1; | ||
| 808 | } | ||
| 809 | |||
| 810 | /* | ||
| 811 | * Wait for CPUs to acknowledge the flip. | ||
| 812 | */ | ||
| 813 | |||
| 814 | static int | ||
| 815 | rcu_try_flip_waitack(void) | ||
| 816 | { | ||
| 817 | int cpu; | ||
| 818 | |||
| 819 | RCU_TRACE_ME(rcupreempt_trace_try_flip_a1); | ||
| 820 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) | ||
| 821 | if (rcu_try_flip_waitack_needed(cpu) && | ||
| 822 | per_cpu(rcu_flip_flag, cpu) != rcu_flip_seen) { | ||
| 823 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ae1); | ||
| 824 | return 0; | ||
| 825 | } | ||
| 826 | |||
| 827 | /* | ||
| 828 | * Make sure our checks above don't bleed into subsequent | ||
| 829 | * waiting for the sum of the counters to reach zero. | ||
| 830 | */ | ||
| 831 | |||
| 832 | smp_mb(); /* see above block comment. */ | ||
| 833 | RCU_TRACE_ME(rcupreempt_trace_try_flip_a2); | ||
| 834 | return 1; | ||
| 835 | } | ||
| 836 | |||
| 837 | /* | ||
| 838 | * Wait for collective ``last'' counter to reach zero, | ||
| 839 | * then tell all CPUs to do an end-of-grace-period memory barrier. | ||
| 840 | */ | ||
| 841 | |||
| 842 | static int | ||
| 843 | rcu_try_flip_waitzero(void) | ||
| 844 | { | ||
| 845 | int cpu; | ||
| 846 | int lastidx = !(rcu_ctrlblk.completed & 0x1); | ||
| 847 | int sum = 0; | ||
| 848 | |||
| 849 | /* Check to see if the sum of the "last" counters is zero. */ | ||
| 850 | |||
| 851 | RCU_TRACE_ME(rcupreempt_trace_try_flip_z1); | ||
| 852 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) | ||
| 853 | sum += RCU_DATA_CPU(cpu)->rcu_flipctr[lastidx]; | ||
| 854 | if (sum != 0) { | ||
| 855 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ze1); | ||
| 856 | return 0; | ||
| 857 | } | ||
| 858 | |||
| 859 | /* | ||
| 860 | * This ensures that the other CPUs see the call for | ||
| 861 | * memory barriers -after- the sum to zero has been | ||
| 862 | * detected here | ||
| 863 | */ | ||
| 864 | smp_mb(); /* ^^^^^^^^^^^^ */ | ||
| 865 | |||
| 866 | /* Call for a memory barrier from each CPU. */ | ||
| 867 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) { | ||
| 868 | per_cpu(rcu_mb_flag, cpu) = rcu_mb_needed; | ||
| 869 | dyntick_save_progress_counter(cpu); | ||
| 870 | } | ||
| 871 | |||
| 872 | RCU_TRACE_ME(rcupreempt_trace_try_flip_z2); | ||
| 873 | return 1; | ||
| 874 | } | ||
| 875 | |||
| 876 | /* | ||
| 877 | * Wait for all CPUs to do their end-of-grace-period memory barrier. | ||
| 878 | * Return 0 once all CPUs have done so. | ||
| 879 | */ | ||
| 880 | |||
| 881 | static int | ||
| 882 | rcu_try_flip_waitmb(void) | ||
| 883 | { | ||
| 884 | int cpu; | ||
| 885 | |||
| 886 | RCU_TRACE_ME(rcupreempt_trace_try_flip_m1); | ||
| 887 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) | ||
| 888 | if (rcu_try_flip_waitmb_needed(cpu) && | ||
| 889 | per_cpu(rcu_mb_flag, cpu) != rcu_mb_done) { | ||
| 890 | RCU_TRACE_ME(rcupreempt_trace_try_flip_me1); | ||
| 891 | return 0; | ||
| 892 | } | ||
| 893 | |||
| 894 | smp_mb(); /* Ensure that the above checks precede any following flip. */ | ||
| 895 | RCU_TRACE_ME(rcupreempt_trace_try_flip_m2); | ||
| 896 | return 1; | ||
| 897 | } | ||
| 898 | |||
| 899 | /* | ||
| 900 | * Attempt a single flip of the counters. Remember, a single flip does | ||
| 901 | * -not- constitute a grace period. Instead, the interval between | ||
| 902 | * at least GP_STAGES consecutive flips is a grace period. | ||
| 903 | * | ||
| 904 | * If anyone is nuts enough to run this CONFIG_PREEMPT_RCU implementation | ||
| 905 | * on a large SMP, they might want to use a hierarchical organization of | ||
| 906 | * the per-CPU-counter pairs. | ||
| 907 | */ | ||
| 908 | static void rcu_try_flip(void) | ||
| 909 | { | ||
| 910 | unsigned long flags; | ||
| 911 | |||
| 912 | RCU_TRACE_ME(rcupreempt_trace_try_flip_1); | ||
| 913 | if (unlikely(!spin_trylock_irqsave(&rcu_ctrlblk.fliplock, flags))) { | ||
| 914 | RCU_TRACE_ME(rcupreempt_trace_try_flip_e1); | ||
| 915 | return; | ||
| 916 | } | ||
| 917 | |||
| 918 | /* | ||
| 919 | * Take the next transition(s) through the RCU grace-period | ||
| 920 | * flip-counter state machine. | ||
| 921 | */ | ||
| 922 | |||
| 923 | switch (rcu_ctrlblk.rcu_try_flip_state) { | ||
| 924 | case rcu_try_flip_idle_state: | ||
| 925 | if (rcu_try_flip_idle()) | ||
| 926 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 927 | rcu_try_flip_waitack_state; | ||
| 928 | break; | ||
| 929 | case rcu_try_flip_waitack_state: | ||
| 930 | if (rcu_try_flip_waitack()) | ||
| 931 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 932 | rcu_try_flip_waitzero_state; | ||
| 933 | break; | ||
| 934 | case rcu_try_flip_waitzero_state: | ||
| 935 | if (rcu_try_flip_waitzero()) | ||
| 936 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 937 | rcu_try_flip_waitmb_state; | ||
| 938 | break; | ||
| 939 | case rcu_try_flip_waitmb_state: | ||
| 940 | if (rcu_try_flip_waitmb()) | ||
| 941 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 942 | rcu_try_flip_idle_state; | ||
| 943 | } | ||
| 944 | spin_unlock_irqrestore(&rcu_ctrlblk.fliplock, flags); | ||
| 945 | } | ||
| 946 | |||
| 947 | /* | ||
| 948 | * Check to see if this CPU needs to do a memory barrier in order to | ||
| 949 | * ensure that any prior RCU read-side critical sections have committed | ||
| 950 | * their counter manipulations and critical-section memory references | ||
| 951 | * before declaring the grace period to be completed. | ||
| 952 | */ | ||
| 953 | static void rcu_check_mb(int cpu) | ||
| 954 | { | ||
| 955 | if (per_cpu(rcu_mb_flag, cpu) == rcu_mb_needed) { | ||
| 956 | smp_mb(); /* Ensure RCU read-side accesses are visible. */ | ||
| 957 | per_cpu(rcu_mb_flag, cpu) = rcu_mb_done; | ||
| 958 | } | ||
| 959 | } | ||
| 960 | |||
| 961 | void rcu_check_callbacks(int cpu, int user) | ||
| 962 | { | ||
| 963 | unsigned long flags; | ||
| 964 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 965 | |||
| 966 | /* | ||
| 967 | * If this CPU took its interrupt from user mode or from the | ||
| 968 | * idle loop, and this is not a nested interrupt, then | ||
| 969 | * this CPU has to have exited all prior preept-disable | ||
| 970 | * sections of code. So increment the counter to note this. | ||
| 971 | * | ||
| 972 | * The memory barrier is needed to handle the case where | ||
| 973 | * writes from a preempt-disable section of code get reordered | ||
| 974 | * into schedule() by this CPU's write buffer. So the memory | ||
| 975 | * barrier makes sure that the rcu_qsctr_inc() is seen by other | ||
| 976 | * CPUs to happen after any such write. | ||
| 977 | */ | ||
| 978 | |||
| 979 | if (user || | ||
| 980 | (idle_cpu(cpu) && !in_softirq() && | ||
| 981 | hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | ||
| 982 | smp_mb(); /* Guard against aggressive schedule(). */ | ||
| 983 | rcu_qsctr_inc(cpu); | ||
| 984 | } | ||
| 985 | |||
| 986 | rcu_check_mb(cpu); | ||
| 987 | if (rcu_ctrlblk.completed == rdp->completed) | ||
| 988 | rcu_try_flip(); | ||
| 989 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 990 | RCU_TRACE_RDP(rcupreempt_trace_check_callbacks, rdp); | ||
| 991 | __rcu_advance_callbacks(rdp); | ||
| 992 | if (rdp->donelist == NULL) { | ||
| 993 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 994 | } else { | ||
| 995 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 996 | raise_softirq(RCU_SOFTIRQ); | ||
| 997 | } | ||
| 998 | } | ||
| 999 | |||
| 1000 | /* | ||
| 1001 | * Needed by dynticks, to make sure all RCU processing has finished | ||
| 1002 | * when we go idle: | ||
| 1003 | */ | ||
| 1004 | void rcu_advance_callbacks(int cpu, int user) | ||
| 1005 | { | ||
| 1006 | unsigned long flags; | ||
| 1007 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1008 | |||
| 1009 | if (rcu_ctrlblk.completed == rdp->completed) { | ||
| 1010 | rcu_try_flip(); | ||
| 1011 | if (rcu_ctrlblk.completed == rdp->completed) | ||
| 1012 | return; | ||
| 1013 | } | ||
| 1014 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1015 | RCU_TRACE_RDP(rcupreempt_trace_check_callbacks, rdp); | ||
| 1016 | __rcu_advance_callbacks(rdp); | ||
| 1017 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 1021 | #define rcu_offline_cpu_enqueue(srclist, srctail, dstlist, dsttail) do { \ | ||
| 1022 | *dsttail = srclist; \ | ||
| 1023 | if (srclist != NULL) { \ | ||
| 1024 | dsttail = srctail; \ | ||
| 1025 | srclist = NULL; \ | ||
| 1026 | srctail = &srclist;\ | ||
| 1027 | } \ | ||
| 1028 | } while (0) | ||
| 1029 | |||
| 1030 | void rcu_offline_cpu(int cpu) | ||
| 1031 | { | ||
| 1032 | int i; | ||
| 1033 | struct rcu_head *list = NULL; | ||
| 1034 | unsigned long flags; | ||
| 1035 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1036 | struct rcu_head *schedlist = NULL; | ||
| 1037 | struct rcu_head **schedtail = &schedlist; | ||
| 1038 | struct rcu_head **tail = &list; | ||
| 1039 | |||
| 1040 | /* | ||
| 1041 | * Remove all callbacks from the newly dead CPU, retaining order. | ||
| 1042 | * Otherwise rcu_barrier() will fail | ||
| 1043 | */ | ||
| 1044 | |||
| 1045 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1046 | rcu_offline_cpu_enqueue(rdp->donelist, rdp->donetail, list, tail); | ||
| 1047 | for (i = GP_STAGES - 1; i >= 0; i--) | ||
| 1048 | rcu_offline_cpu_enqueue(rdp->waitlist[i], rdp->waittail[i], | ||
| 1049 | list, tail); | ||
| 1050 | rcu_offline_cpu_enqueue(rdp->nextlist, rdp->nexttail, list, tail); | ||
| 1051 | rcu_offline_cpu_enqueue(rdp->waitschedlist, rdp->waitschedtail, | ||
| 1052 | schedlist, schedtail); | ||
| 1053 | rcu_offline_cpu_enqueue(rdp->nextschedlist, rdp->nextschedtail, | ||
| 1054 | schedlist, schedtail); | ||
| 1055 | rdp->rcu_sched_sleeping = 0; | ||
| 1056 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1057 | rdp->waitlistcount = 0; | ||
| 1058 | |||
| 1059 | /* Disengage the newly dead CPU from the grace-period computation. */ | ||
| 1060 | |||
| 1061 | spin_lock_irqsave(&rcu_ctrlblk.fliplock, flags); | ||
| 1062 | rcu_check_mb(cpu); | ||
| 1063 | if (per_cpu(rcu_flip_flag, cpu) == rcu_flipped) { | ||
| 1064 | smp_mb(); /* Subsequent counter accesses must see new value */ | ||
| 1065 | per_cpu(rcu_flip_flag, cpu) = rcu_flip_seen; | ||
| 1066 | smp_mb(); /* Subsequent RCU read-side critical sections */ | ||
| 1067 | /* seen -after- acknowledgement. */ | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | RCU_DATA_ME()->rcu_flipctr[0] += RCU_DATA_CPU(cpu)->rcu_flipctr[0]; | ||
| 1071 | RCU_DATA_ME()->rcu_flipctr[1] += RCU_DATA_CPU(cpu)->rcu_flipctr[1]; | ||
| 1072 | |||
| 1073 | RCU_DATA_CPU(cpu)->rcu_flipctr[0] = 0; | ||
| 1074 | RCU_DATA_CPU(cpu)->rcu_flipctr[1] = 0; | ||
| 1075 | |||
| 1076 | cpumask_clear_cpu(cpu, to_cpumask(rcu_cpu_online_map)); | ||
| 1077 | |||
| 1078 | spin_unlock_irqrestore(&rcu_ctrlblk.fliplock, flags); | ||
| 1079 | |||
| 1080 | /* | ||
| 1081 | * Place the removed callbacks on the current CPU's queue. | ||
| 1082 | * Make them all start a new grace period: simple approach, | ||
| 1083 | * in theory could starve a given set of callbacks, but | ||
| 1084 | * you would need to be doing some serious CPU hotplugging | ||
| 1085 | * to make this happen. If this becomes a problem, adding | ||
| 1086 | * a synchronize_rcu() to the hotplug path would be a simple | ||
| 1087 | * fix. | ||
| 1088 | */ | ||
| 1089 | |||
| 1090 | local_irq_save(flags); /* disable preempt till we know what lock. */ | ||
| 1091 | rdp = RCU_DATA_ME(); | ||
| 1092 | spin_lock(&rdp->lock); | ||
| 1093 | *rdp->nexttail = list; | ||
| 1094 | if (list) | ||
| 1095 | rdp->nexttail = tail; | ||
| 1096 | *rdp->nextschedtail = schedlist; | ||
| 1097 | if (schedlist) | ||
| 1098 | rdp->nextschedtail = schedtail; | ||
| 1099 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1100 | } | ||
| 1101 | |||
| 1102 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 1103 | |||
| 1104 | void rcu_offline_cpu(int cpu) | ||
| 1105 | { | ||
| 1106 | } | ||
| 1107 | |||
| 1108 | #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 1109 | |||
| 1110 | void __cpuinit rcu_online_cpu(int cpu) | ||
| 1111 | { | ||
| 1112 | unsigned long flags; | ||
| 1113 | struct rcu_data *rdp; | ||
| 1114 | |||
| 1115 | spin_lock_irqsave(&rcu_ctrlblk.fliplock, flags); | ||
| 1116 | cpumask_set_cpu(cpu, to_cpumask(rcu_cpu_online_map)); | ||
| 1117 | spin_unlock_irqrestore(&rcu_ctrlblk.fliplock, flags); | ||
| 1118 | |||
| 1119 | /* | ||
| 1120 | * The rcu_sched grace-period processing might have bypassed | ||
| 1121 | * this CPU, given that it was not in the rcu_cpu_online_map | ||
| 1122 | * when the grace-period scan started. This means that the | ||
| 1123 | * grace-period task might sleep. So make sure that if this | ||
| 1124 | * should happen, the first callback posted to this CPU will | ||
| 1125 | * wake up the grace-period task if need be. | ||
| 1126 | */ | ||
| 1127 | |||
| 1128 | rdp = RCU_DATA_CPU(cpu); | ||
| 1129 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1130 | rdp->rcu_sched_sleeping = 1; | ||
| 1131 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | static void rcu_process_callbacks(struct softirq_action *unused) | ||
| 1135 | { | ||
| 1136 | unsigned long flags; | ||
| 1137 | struct rcu_head *next, *list; | ||
| 1138 | struct rcu_data *rdp; | ||
| 1139 | |||
| 1140 | local_irq_save(flags); | ||
| 1141 | rdp = RCU_DATA_ME(); | ||
| 1142 | spin_lock(&rdp->lock); | ||
| 1143 | list = rdp->donelist; | ||
| 1144 | if (list == NULL) { | ||
| 1145 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1146 | return; | ||
| 1147 | } | ||
| 1148 | rdp->donelist = NULL; | ||
| 1149 | rdp->donetail = &rdp->donelist; | ||
| 1150 | RCU_TRACE_RDP(rcupreempt_trace_done_remove, rdp); | ||
| 1151 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1152 | while (list) { | ||
| 1153 | next = list->next; | ||
| 1154 | list->func(list); | ||
| 1155 | list = next; | ||
| 1156 | RCU_TRACE_ME(rcupreempt_trace_invoke); | ||
| 1157 | } | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 1161 | { | ||
| 1162 | unsigned long flags; | ||
| 1163 | struct rcu_data *rdp; | ||
| 1164 | |||
| 1165 | head->func = func; | ||
| 1166 | head->next = NULL; | ||
| 1167 | local_irq_save(flags); | ||
| 1168 | rdp = RCU_DATA_ME(); | ||
| 1169 | spin_lock(&rdp->lock); | ||
| 1170 | __rcu_advance_callbacks(rdp); | ||
| 1171 | *rdp->nexttail = head; | ||
| 1172 | rdp->nexttail = &head->next; | ||
| 1173 | RCU_TRACE_RDP(rcupreempt_trace_next_add, rdp); | ||
| 1174 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1175 | } | ||
| 1176 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 1177 | |||
| 1178 | void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 1179 | { | ||
| 1180 | unsigned long flags; | ||
| 1181 | struct rcu_data *rdp; | ||
| 1182 | int wake_gp = 0; | ||
| 1183 | |||
| 1184 | head->func = func; | ||
| 1185 | head->next = NULL; | ||
| 1186 | local_irq_save(flags); | ||
| 1187 | rdp = RCU_DATA_ME(); | ||
| 1188 | spin_lock(&rdp->lock); | ||
| 1189 | *rdp->nextschedtail = head; | ||
| 1190 | rdp->nextschedtail = &head->next; | ||
| 1191 | if (rdp->rcu_sched_sleeping) { | ||
| 1192 | |||
| 1193 | /* Grace-period processing might be sleeping... */ | ||
| 1194 | |||
| 1195 | rdp->rcu_sched_sleeping = 0; | ||
| 1196 | wake_gp = 1; | ||
| 1197 | } | ||
| 1198 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1199 | if (wake_gp) { | ||
| 1200 | |||
| 1201 | /* Wake up grace-period processing, unless someone beat us. */ | ||
| 1202 | |||
| 1203 | spin_lock_irqsave(&rcu_ctrlblk.schedlock, flags); | ||
| 1204 | if (rcu_ctrlblk.sched_sleep != rcu_sched_sleeping) | ||
| 1205 | wake_gp = 0; | ||
| 1206 | rcu_ctrlblk.sched_sleep = rcu_sched_not_sleeping; | ||
| 1207 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1208 | if (wake_gp) | ||
| 1209 | wake_up_interruptible(&rcu_ctrlblk.sched_wq); | ||
| 1210 | } | ||
| 1211 | } | ||
| 1212 | EXPORT_SYMBOL_GPL(call_rcu_sched); | ||
| 1213 | |||
| 1214 | /* | ||
| 1215 | * Wait until all currently running preempt_disable() code segments | ||
| 1216 | * (including hardware-irq-disable segments) complete. Note that | ||
| 1217 | * in -rt this does -not- necessarily result in all currently executing | ||
| 1218 | * interrupt -handlers- having completed. | ||
| 1219 | */ | ||
| 1220 | void __synchronize_sched(void) | ||
| 1221 | { | ||
| 1222 | struct rcu_synchronize rcu; | ||
| 1223 | |||
| 1224 | if (num_online_cpus() == 1) | ||
| 1225 | return; /* blocking is gp if only one CPU! */ | ||
| 1226 | |||
| 1227 | init_completion(&rcu.completion); | ||
| 1228 | /* Will wake me after RCU finished. */ | ||
| 1229 | call_rcu_sched(&rcu.head, wakeme_after_rcu); | ||
| 1230 | /* Wait for it. */ | ||
| 1231 | wait_for_completion(&rcu.completion); | ||
| 1232 | } | ||
| 1233 | EXPORT_SYMBOL_GPL(__synchronize_sched); | ||
| 1234 | |||
| 1235 | /* | ||
| 1236 | * kthread function that manages call_rcu_sched grace periods. | ||
| 1237 | */ | ||
| 1238 | static int rcu_sched_grace_period(void *arg) | ||
| 1239 | { | ||
| 1240 | int couldsleep; /* might sleep after current pass. */ | ||
| 1241 | int couldsleepnext = 0; /* might sleep after next pass. */ | ||
| 1242 | int cpu; | ||
| 1243 | unsigned long flags; | ||
| 1244 | struct rcu_data *rdp; | ||
| 1245 | int ret; | ||
| 1246 | |||
| 1247 | /* | ||
| 1248 | * Each pass through the following loop handles one | ||
| 1249 | * rcu_sched grace period cycle. | ||
| 1250 | */ | ||
| 1251 | do { | ||
| 1252 | /* Save each CPU's current state. */ | ||
| 1253 | |||
| 1254 | for_each_online_cpu(cpu) { | ||
| 1255 | dyntick_save_progress_counter_sched(cpu); | ||
| 1256 | save_qsctr_sched(cpu); | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | /* | ||
| 1260 | * Sleep for about an RCU grace-period's worth to | ||
| 1261 | * allow better batching and to consume less CPU. | ||
| 1262 | */ | ||
| 1263 | schedule_timeout_interruptible(RCU_SCHED_BATCH_TIME); | ||
| 1264 | |||
| 1265 | /* | ||
| 1266 | * If there was nothing to do last time, prepare to | ||
| 1267 | * sleep at the end of the current grace period cycle. | ||
| 1268 | */ | ||
| 1269 | couldsleep = couldsleepnext; | ||
| 1270 | couldsleepnext = 1; | ||
| 1271 | if (couldsleep) { | ||
| 1272 | spin_lock_irqsave(&rcu_ctrlblk.schedlock, flags); | ||
| 1273 | rcu_ctrlblk.sched_sleep = rcu_sched_sleep_prep; | ||
| 1274 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | /* | ||
| 1278 | * Wait on each CPU in turn to have either visited | ||
| 1279 | * a quiescent state or been in dynticks-idle mode. | ||
| 1280 | */ | ||
| 1281 | for_each_online_cpu(cpu) { | ||
| 1282 | while (rcu_qsctr_inc_needed(cpu) && | ||
| 1283 | rcu_qsctr_inc_needed_dyntick(cpu)) { | ||
| 1284 | /* resched_cpu(cpu); @@@ */ | ||
| 1285 | schedule_timeout_interruptible(1); | ||
| 1286 | } | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | /* Advance callbacks for each CPU. */ | ||
| 1290 | |||
| 1291 | for_each_online_cpu(cpu) { | ||
| 1292 | |||
| 1293 | rdp = RCU_DATA_CPU(cpu); | ||
| 1294 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1295 | |||
| 1296 | /* | ||
| 1297 | * We are running on this CPU irq-disabled, so no | ||
| 1298 | * CPU can go offline until we re-enable irqs. | ||
| 1299 | * The current CPU might have already gone | ||
| 1300 | * offline (between the for_each_offline_cpu and | ||
| 1301 | * the spin_lock_irqsave), but in that case all its | ||
| 1302 | * callback lists will be empty, so no harm done. | ||
| 1303 | * | ||
| 1304 | * Advance the callbacks! We share normal RCU's | ||
| 1305 | * donelist, since callbacks are invoked the | ||
| 1306 | * same way in either case. | ||
| 1307 | */ | ||
| 1308 | if (rdp->waitschedlist != NULL) { | ||
| 1309 | *rdp->donetail = rdp->waitschedlist; | ||
| 1310 | rdp->donetail = rdp->waitschedtail; | ||
| 1311 | |||
| 1312 | /* | ||
| 1313 | * Next rcu_check_callbacks() will | ||
| 1314 | * do the required raise_softirq(). | ||
| 1315 | */ | ||
| 1316 | } | ||
| 1317 | if (rdp->nextschedlist != NULL) { | ||
| 1318 | rdp->waitschedlist = rdp->nextschedlist; | ||
| 1319 | rdp->waitschedtail = rdp->nextschedtail; | ||
| 1320 | couldsleep = 0; | ||
| 1321 | couldsleepnext = 0; | ||
| 1322 | } else { | ||
| 1323 | rdp->waitschedlist = NULL; | ||
| 1324 | rdp->waitschedtail = &rdp->waitschedlist; | ||
| 1325 | } | ||
| 1326 | rdp->nextschedlist = NULL; | ||
| 1327 | rdp->nextschedtail = &rdp->nextschedlist; | ||
| 1328 | |||
| 1329 | /* Mark sleep intention. */ | ||
| 1330 | |||
| 1331 | rdp->rcu_sched_sleeping = couldsleep; | ||
| 1332 | |||
| 1333 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1334 | } | ||
| 1335 | |||
| 1336 | /* If we saw callbacks on the last scan, go deal with them. */ | ||
| 1337 | |||
| 1338 | if (!couldsleep) | ||
| 1339 | continue; | ||
| 1340 | |||
| 1341 | /* Attempt to block... */ | ||
| 1342 | |||
| 1343 | spin_lock_irqsave(&rcu_ctrlblk.schedlock, flags); | ||
| 1344 | if (rcu_ctrlblk.sched_sleep != rcu_sched_sleep_prep) { | ||
| 1345 | |||
| 1346 | /* | ||
| 1347 | * Someone posted a callback after we scanned. | ||
| 1348 | * Go take care of it. | ||
| 1349 | */ | ||
| 1350 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1351 | couldsleepnext = 0; | ||
| 1352 | continue; | ||
| 1353 | } | ||
| 1354 | |||
| 1355 | /* Block until the next person posts a callback. */ | ||
| 1356 | |||
| 1357 | rcu_ctrlblk.sched_sleep = rcu_sched_sleeping; | ||
| 1358 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1359 | ret = 0; /* unused */ | ||
| 1360 | __wait_event_interruptible(rcu_ctrlblk.sched_wq, | ||
| 1361 | rcu_ctrlblk.sched_sleep != rcu_sched_sleeping, | ||
| 1362 | ret); | ||
| 1363 | |||
| 1364 | couldsleepnext = 0; | ||
| 1365 | |||
| 1366 | } while (!kthread_should_stop()); | ||
| 1367 | |||
| 1368 | return (0); | ||
| 1369 | } | ||
| 1370 | |||
| 1371 | /* | ||
| 1372 | * Check to see if any future RCU-related work will need to be done | ||
| 1373 | * by the current CPU, even if none need be done immediately, returning | ||
| 1374 | * 1 if so. Assumes that notifiers would take care of handling any | ||
| 1375 | * outstanding requests from the RCU core. | ||
| 1376 | * | ||
| 1377 | * This function is part of the RCU implementation; it is -not- | ||
| 1378 | * an exported member of the RCU API. | ||
| 1379 | */ | ||
| 1380 | int rcu_needs_cpu(int cpu) | ||
| 1381 | { | ||
| 1382 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1383 | |||
| 1384 | return (rdp->donelist != NULL || | ||
| 1385 | !!rdp->waitlistcount || | ||
| 1386 | rdp->nextlist != NULL || | ||
| 1387 | rdp->nextschedlist != NULL || | ||
| 1388 | rdp->waitschedlist != NULL); | ||
| 1389 | } | ||
| 1390 | |||
| 1391 | int rcu_pending(int cpu) | ||
| 1392 | { | ||
| 1393 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1394 | |||
| 1395 | /* The CPU has at least one callback queued somewhere. */ | ||
| 1396 | |||
| 1397 | if (rdp->donelist != NULL || | ||
| 1398 | !!rdp->waitlistcount || | ||
| 1399 | rdp->nextlist != NULL || | ||
| 1400 | rdp->nextschedlist != NULL || | ||
| 1401 | rdp->waitschedlist != NULL) | ||
| 1402 | return 1; | ||
| 1403 | |||
| 1404 | /* The RCU core needs an acknowledgement from this CPU. */ | ||
| 1405 | |||
| 1406 | if ((per_cpu(rcu_flip_flag, cpu) == rcu_flipped) || | ||
| 1407 | (per_cpu(rcu_mb_flag, cpu) == rcu_mb_needed)) | ||
| 1408 | return 1; | ||
| 1409 | |||
| 1410 | /* This CPU has fallen behind the global grace-period number. */ | ||
| 1411 | |||
| 1412 | if (rdp->completed != rcu_ctrlblk.completed) | ||
| 1413 | return 1; | ||
| 1414 | |||
| 1415 | /* Nothing needed from this CPU. */ | ||
| 1416 | |||
| 1417 | return 0; | ||
| 1418 | } | ||
| 1419 | |||
| 1420 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | ||
| 1421 | unsigned long action, void *hcpu) | ||
| 1422 | { | ||
| 1423 | long cpu = (long)hcpu; | ||
| 1424 | |||
| 1425 | switch (action) { | ||
| 1426 | case CPU_UP_PREPARE: | ||
| 1427 | case CPU_UP_PREPARE_FROZEN: | ||
| 1428 | rcu_online_cpu(cpu); | ||
| 1429 | break; | ||
| 1430 | case CPU_UP_CANCELED: | ||
| 1431 | case CPU_UP_CANCELED_FROZEN: | ||
| 1432 | case CPU_DEAD: | ||
| 1433 | case CPU_DEAD_FROZEN: | ||
| 1434 | rcu_offline_cpu(cpu); | ||
| 1435 | break; | ||
| 1436 | default: | ||
| 1437 | break; | ||
| 1438 | } | ||
| 1439 | return NOTIFY_OK; | ||
| 1440 | } | ||
| 1441 | |||
| 1442 | static struct notifier_block __cpuinitdata rcu_nb = { | ||
| 1443 | .notifier_call = rcu_cpu_notify, | ||
| 1444 | }; | ||
| 1445 | |||
| 1446 | void __init __rcu_init(void) | ||
| 1447 | { | ||
| 1448 | int cpu; | ||
| 1449 | int i; | ||
| 1450 | struct rcu_data *rdp; | ||
| 1451 | |||
| 1452 | printk(KERN_NOTICE "Preemptible RCU implementation.\n"); | ||
| 1453 | for_each_possible_cpu(cpu) { | ||
| 1454 | rdp = RCU_DATA_CPU(cpu); | ||
| 1455 | spin_lock_init(&rdp->lock); | ||
| 1456 | rdp->completed = 0; | ||
| 1457 | rdp->waitlistcount = 0; | ||
| 1458 | rdp->nextlist = NULL; | ||
| 1459 | rdp->nexttail = &rdp->nextlist; | ||
| 1460 | for (i = 0; i < GP_STAGES; i++) { | ||
| 1461 | rdp->waitlist[i] = NULL; | ||
| 1462 | rdp->waittail[i] = &rdp->waitlist[i]; | ||
| 1463 | } | ||
| 1464 | rdp->donelist = NULL; | ||
| 1465 | rdp->donetail = &rdp->donelist; | ||
| 1466 | rdp->rcu_flipctr[0] = 0; | ||
| 1467 | rdp->rcu_flipctr[1] = 0; | ||
| 1468 | rdp->nextschedlist = NULL; | ||
| 1469 | rdp->nextschedtail = &rdp->nextschedlist; | ||
| 1470 | rdp->waitschedlist = NULL; | ||
| 1471 | rdp->waitschedtail = &rdp->waitschedlist; | ||
| 1472 | rdp->rcu_sched_sleeping = 0; | ||
| 1473 | } | ||
| 1474 | register_cpu_notifier(&rcu_nb); | ||
| 1475 | |||
| 1476 | /* | ||
| 1477 | * We don't need protection against CPU-Hotplug here | ||
| 1478 | * since | ||
| 1479 | * a) If a CPU comes online while we are iterating over the | ||
| 1480 | * cpu_online_mask below, we would only end up making a | ||
| 1481 | * duplicate call to rcu_online_cpu() which sets the corresponding | ||
| 1482 | * CPU's mask in the rcu_cpu_online_map. | ||
| 1483 | * | ||
| 1484 | * b) A CPU cannot go offline at this point in time since the user | ||
| 1485 | * does not have access to the sysfs interface, nor do we | ||
| 1486 | * suspend the system. | ||
| 1487 | */ | ||
| 1488 | for_each_online_cpu(cpu) | ||
| 1489 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, (void *)(long) cpu); | ||
| 1490 | |||
| 1491 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | ||
| 1492 | } | ||
| 1493 | |||
| 1494 | /* | ||
| 1495 | * Late-boot-time RCU initialization that must wait until after scheduler | ||
| 1496 | * has been initialized. | ||
| 1497 | */ | ||
| 1498 | void __init rcu_init_sched(void) | ||
| 1499 | { | ||
| 1500 | rcu_sched_grace_period_task = kthread_run(rcu_sched_grace_period, | ||
| 1501 | NULL, | ||
| 1502 | "rcu_sched_grace_period"); | ||
| 1503 | WARN_ON(IS_ERR(rcu_sched_grace_period_task)); | ||
| 1504 | } | ||
| 1505 | |||
| 1506 | #ifdef CONFIG_RCU_TRACE | ||
| 1507 | long *rcupreempt_flipctr(int cpu) | ||
| 1508 | { | ||
| 1509 | return &RCU_DATA_CPU(cpu)->rcu_flipctr[0]; | ||
| 1510 | } | ||
| 1511 | EXPORT_SYMBOL_GPL(rcupreempt_flipctr); | ||
| 1512 | |||
| 1513 | int rcupreempt_flip_flag(int cpu) | ||
| 1514 | { | ||
| 1515 | return per_cpu(rcu_flip_flag, cpu); | ||
| 1516 | } | ||
| 1517 | EXPORT_SYMBOL_GPL(rcupreempt_flip_flag); | ||
| 1518 | |||
| 1519 | int rcupreempt_mb_flag(int cpu) | ||
| 1520 | { | ||
| 1521 | return per_cpu(rcu_mb_flag, cpu); | ||
| 1522 | } | ||
| 1523 | EXPORT_SYMBOL_GPL(rcupreempt_mb_flag); | ||
| 1524 | |||
| 1525 | char *rcupreempt_try_flip_state_name(void) | ||
| 1526 | { | ||
| 1527 | return rcu_try_flip_state_names[rcu_ctrlblk.rcu_try_flip_state]; | ||
| 1528 | } | ||
| 1529 | EXPORT_SYMBOL_GPL(rcupreempt_try_flip_state_name); | ||
| 1530 | |||
| 1531 | struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu) | ||
| 1532 | { | ||
| 1533 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1534 | |||
| 1535 | return &rdp->trace; | ||
| 1536 | } | ||
| 1537 | EXPORT_SYMBOL_GPL(rcupreempt_trace_cpu); | ||
| 1538 | |||
| 1539 | #endif /* #ifdef RCU_TRACE */ | ||
diff --git a/kernel/rcupreempt_trace.c b/kernel/rcupreempt_trace.c deleted file mode 100644 index 7c2665cac172..000000000000 --- a/kernel/rcupreempt_trace.c +++ /dev/null | |||
| @@ -1,334 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update tracing for realtime implementation | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | * | ||
| 18 | * Copyright IBM Corporation, 2006 | ||
| 19 | * | ||
| 20 | * Papers: http://www.rdrop.com/users/paulmck/RCU | ||
| 21 | * | ||
| 22 | * For detailed explanation of Read-Copy Update mechanism see - | ||
| 23 | * Documentation/RCU/ *.txt | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | #include <linux/types.h> | ||
| 27 | #include <linux/kernel.h> | ||
| 28 | #include <linux/init.h> | ||
| 29 | #include <linux/spinlock.h> | ||
| 30 | #include <linux/smp.h> | ||
| 31 | #include <linux/rcupdate.h> | ||
| 32 | #include <linux/interrupt.h> | ||
| 33 | #include <linux/sched.h> | ||
| 34 | #include <asm/atomic.h> | ||
| 35 | #include <linux/bitops.h> | ||
| 36 | #include <linux/module.h> | ||
| 37 | #include <linux/completion.h> | ||
| 38 | #include <linux/moduleparam.h> | ||
| 39 | #include <linux/percpu.h> | ||
| 40 | #include <linux/notifier.h> | ||
| 41 | #include <linux/cpu.h> | ||
| 42 | #include <linux/mutex.h> | ||
| 43 | #include <linux/rcupreempt_trace.h> | ||
| 44 | #include <linux/debugfs.h> | ||
| 45 | |||
| 46 | static struct mutex rcupreempt_trace_mutex; | ||
| 47 | static char *rcupreempt_trace_buf; | ||
| 48 | #define RCUPREEMPT_TRACE_BUF_SIZE 4096 | ||
| 49 | |||
| 50 | void rcupreempt_trace_move2done(struct rcupreempt_trace *trace) | ||
| 51 | { | ||
| 52 | trace->done_length += trace->wait_length; | ||
| 53 | trace->done_add += trace->wait_length; | ||
| 54 | trace->wait_length = 0; | ||
| 55 | } | ||
| 56 | void rcupreempt_trace_move2wait(struct rcupreempt_trace *trace) | ||
| 57 | { | ||
| 58 | trace->wait_length += trace->next_length; | ||
| 59 | trace->wait_add += trace->next_length; | ||
| 60 | trace->next_length = 0; | ||
| 61 | } | ||
| 62 | void rcupreempt_trace_try_flip_1(struct rcupreempt_trace *trace) | ||
| 63 | { | ||
| 64 | atomic_inc(&trace->rcu_try_flip_1); | ||
| 65 | } | ||
| 66 | void rcupreempt_trace_try_flip_e1(struct rcupreempt_trace *trace) | ||
| 67 | { | ||
| 68 | atomic_inc(&trace->rcu_try_flip_e1); | ||
| 69 | } | ||
| 70 | void rcupreempt_trace_try_flip_i1(struct rcupreempt_trace *trace) | ||
| 71 | { | ||
| 72 | trace->rcu_try_flip_i1++; | ||
| 73 | } | ||
| 74 | void rcupreempt_trace_try_flip_ie1(struct rcupreempt_trace *trace) | ||
| 75 | { | ||
| 76 | trace->rcu_try_flip_ie1++; | ||
| 77 | } | ||
| 78 | void rcupreempt_trace_try_flip_g1(struct rcupreempt_trace *trace) | ||
| 79 | { | ||
| 80 | trace->rcu_try_flip_g1++; | ||
| 81 | } | ||
| 82 | void rcupreempt_trace_try_flip_a1(struct rcupreempt_trace *trace) | ||
| 83 | { | ||
| 84 | trace->rcu_try_flip_a1++; | ||
| 85 | } | ||
| 86 | void rcupreempt_trace_try_flip_ae1(struct rcupreempt_trace *trace) | ||
| 87 | { | ||
| 88 | trace->rcu_try_flip_ae1++; | ||
| 89 | } | ||
| 90 | void rcupreempt_trace_try_flip_a2(struct rcupreempt_trace *trace) | ||
| 91 | { | ||
| 92 | trace->rcu_try_flip_a2++; | ||
| 93 | } | ||
| 94 | void rcupreempt_trace_try_flip_z1(struct rcupreempt_trace *trace) | ||
| 95 | { | ||
| 96 | trace->rcu_try_flip_z1++; | ||
| 97 | } | ||
| 98 | void rcupreempt_trace_try_flip_ze1(struct rcupreempt_trace *trace) | ||
| 99 | { | ||
| 100 | trace->rcu_try_flip_ze1++; | ||
| 101 | } | ||
| 102 | void rcupreempt_trace_try_flip_z2(struct rcupreempt_trace *trace) | ||
| 103 | { | ||
| 104 | trace->rcu_try_flip_z2++; | ||
| 105 | } | ||
| 106 | void rcupreempt_trace_try_flip_m1(struct rcupreempt_trace *trace) | ||
| 107 | { | ||
| 108 | trace->rcu_try_flip_m1++; | ||
| 109 | } | ||
| 110 | void rcupreempt_trace_try_flip_me1(struct rcupreempt_trace *trace) | ||
| 111 | { | ||
| 112 | trace->rcu_try_flip_me1++; | ||
| 113 | } | ||
| 114 | void rcupreempt_trace_try_flip_m2(struct rcupreempt_trace *trace) | ||
| 115 | { | ||
| 116 | trace->rcu_try_flip_m2++; | ||
| 117 | } | ||
| 118 | void rcupreempt_trace_check_callbacks(struct rcupreempt_trace *trace) | ||
| 119 | { | ||
| 120 | trace->rcu_check_callbacks++; | ||
| 121 | } | ||
| 122 | void rcupreempt_trace_done_remove(struct rcupreempt_trace *trace) | ||
| 123 | { | ||
| 124 | trace->done_remove += trace->done_length; | ||
| 125 | trace->done_length = 0; | ||
| 126 | } | ||
| 127 | void rcupreempt_trace_invoke(struct rcupreempt_trace *trace) | ||
| 128 | { | ||
| 129 | atomic_inc(&trace->done_invoked); | ||
| 130 | } | ||
| 131 | void rcupreempt_trace_next_add(struct rcupreempt_trace *trace) | ||
| 132 | { | ||
| 133 | trace->next_add++; | ||
| 134 | trace->next_length++; | ||
| 135 | } | ||
| 136 | |||
| 137 | static void rcupreempt_trace_sum(struct rcupreempt_trace *sp) | ||
| 138 | { | ||
| 139 | struct rcupreempt_trace *cp; | ||
| 140 | int cpu; | ||
| 141 | |||
| 142 | memset(sp, 0, sizeof(*sp)); | ||
| 143 | for_each_possible_cpu(cpu) { | ||
| 144 | cp = rcupreempt_trace_cpu(cpu); | ||
| 145 | sp->next_length += cp->next_length; | ||
| 146 | sp->next_add += cp->next_add; | ||
| 147 | sp->wait_length += cp->wait_length; | ||
| 148 | sp->wait_add += cp->wait_add; | ||
| 149 | sp->done_length += cp->done_length; | ||
| 150 | sp->done_add += cp->done_add; | ||
| 151 | sp->done_remove += cp->done_remove; | ||
| 152 | atomic_add(atomic_read(&cp->done_invoked), &sp->done_invoked); | ||
| 153 | sp->rcu_check_callbacks += cp->rcu_check_callbacks; | ||
| 154 | atomic_add(atomic_read(&cp->rcu_try_flip_1), | ||
| 155 | &sp->rcu_try_flip_1); | ||
| 156 | atomic_add(atomic_read(&cp->rcu_try_flip_e1), | ||
| 157 | &sp->rcu_try_flip_e1); | ||
| 158 | sp->rcu_try_flip_i1 += cp->rcu_try_flip_i1; | ||
| 159 | sp->rcu_try_flip_ie1 += cp->rcu_try_flip_ie1; | ||
| 160 | sp->rcu_try_flip_g1 += cp->rcu_try_flip_g1; | ||
| 161 | sp->rcu_try_flip_a1 += cp->rcu_try_flip_a1; | ||
| 162 | sp->rcu_try_flip_ae1 += cp->rcu_try_flip_ae1; | ||
| 163 | sp->rcu_try_flip_a2 += cp->rcu_try_flip_a2; | ||
| 164 | sp->rcu_try_flip_z1 += cp->rcu_try_flip_z1; | ||
| 165 | sp->rcu_try_flip_ze1 += cp->rcu_try_flip_ze1; | ||
| 166 | sp->rcu_try_flip_z2 += cp->rcu_try_flip_z2; | ||
| 167 | sp->rcu_try_flip_m1 += cp->rcu_try_flip_m1; | ||
| 168 | sp->rcu_try_flip_me1 += cp->rcu_try_flip_me1; | ||
| 169 | sp->rcu_try_flip_m2 += cp->rcu_try_flip_m2; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | static ssize_t rcustats_read(struct file *filp, char __user *buffer, | ||
| 174 | size_t count, loff_t *ppos) | ||
| 175 | { | ||
| 176 | struct rcupreempt_trace trace; | ||
| 177 | ssize_t bcount; | ||
| 178 | int cnt = 0; | ||
| 179 | |||
| 180 | rcupreempt_trace_sum(&trace); | ||
| 181 | mutex_lock(&rcupreempt_trace_mutex); | ||
| 182 | snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 183 | "ggp=%ld rcc=%ld\n", | ||
| 184 | rcu_batches_completed(), | ||
| 185 | trace.rcu_check_callbacks); | ||
| 186 | snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 187 | "na=%ld nl=%ld wa=%ld wl=%ld da=%ld dl=%ld dr=%ld di=%d\n" | ||
| 188 | "1=%d e1=%d i1=%ld ie1=%ld g1=%ld a1=%ld ae1=%ld a2=%ld\n" | ||
| 189 | "z1=%ld ze1=%ld z2=%ld m1=%ld me1=%ld m2=%ld\n", | ||
| 190 | |||
| 191 | trace.next_add, trace.next_length, | ||
| 192 | trace.wait_add, trace.wait_length, | ||
| 193 | trace.done_add, trace.done_length, | ||
| 194 | trace.done_remove, atomic_read(&trace.done_invoked), | ||
| 195 | atomic_read(&trace.rcu_try_flip_1), | ||
| 196 | atomic_read(&trace.rcu_try_flip_e1), | ||
| 197 | trace.rcu_try_flip_i1, trace.rcu_try_flip_ie1, | ||
| 198 | trace.rcu_try_flip_g1, | ||
| 199 | trace.rcu_try_flip_a1, trace.rcu_try_flip_ae1, | ||
| 200 | trace.rcu_try_flip_a2, | ||
| 201 | trace.rcu_try_flip_z1, trace.rcu_try_flip_ze1, | ||
| 202 | trace.rcu_try_flip_z2, | ||
| 203 | trace.rcu_try_flip_m1, trace.rcu_try_flip_me1, | ||
| 204 | trace.rcu_try_flip_m2); | ||
| 205 | bcount = simple_read_from_buffer(buffer, count, ppos, | ||
| 206 | rcupreempt_trace_buf, strlen(rcupreempt_trace_buf)); | ||
| 207 | mutex_unlock(&rcupreempt_trace_mutex); | ||
| 208 | return bcount; | ||
| 209 | } | ||
| 210 | |||
| 211 | static ssize_t rcugp_read(struct file *filp, char __user *buffer, | ||
| 212 | size_t count, loff_t *ppos) | ||
| 213 | { | ||
| 214 | long oldgp = rcu_batches_completed(); | ||
| 215 | ssize_t bcount; | ||
| 216 | |||
| 217 | mutex_lock(&rcupreempt_trace_mutex); | ||
| 218 | synchronize_rcu(); | ||
| 219 | snprintf(rcupreempt_trace_buf, RCUPREEMPT_TRACE_BUF_SIZE, | ||
| 220 | "oldggp=%ld newggp=%ld\n", oldgp, rcu_batches_completed()); | ||
| 221 | bcount = simple_read_from_buffer(buffer, count, ppos, | ||
| 222 | rcupreempt_trace_buf, strlen(rcupreempt_trace_buf)); | ||
| 223 | mutex_unlock(&rcupreempt_trace_mutex); | ||
| 224 | return bcount; | ||
| 225 | } | ||
| 226 | |||
| 227 | static ssize_t rcuctrs_read(struct file *filp, char __user *buffer, | ||
| 228 | size_t count, loff_t *ppos) | ||
| 229 | { | ||
| 230 | int cnt = 0; | ||
| 231 | int cpu; | ||
| 232 | int f = rcu_batches_completed() & 0x1; | ||
| 233 | ssize_t bcount; | ||
| 234 | |||
| 235 | mutex_lock(&rcupreempt_trace_mutex); | ||
| 236 | |||
| 237 | cnt += snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE, | ||
| 238 | "CPU last cur F M\n"); | ||
| 239 | for_each_online_cpu(cpu) { | ||
| 240 | long *flipctr = rcupreempt_flipctr(cpu); | ||
| 241 | cnt += snprintf(&rcupreempt_trace_buf[cnt], | ||
| 242 | RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 243 | "%3d %4ld %3ld %d %d\n", | ||
| 244 | cpu, | ||
| 245 | flipctr[!f], | ||
| 246 | flipctr[f], | ||
| 247 | rcupreempt_flip_flag(cpu), | ||
| 248 | rcupreempt_mb_flag(cpu)); | ||
| 249 | } | ||
| 250 | cnt += snprintf(&rcupreempt_trace_buf[cnt], | ||
| 251 | RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 252 | "ggp = %ld, state = %s\n", | ||
| 253 | rcu_batches_completed(), | ||
| 254 | rcupreempt_try_flip_state_name()); | ||
| 255 | cnt += snprintf(&rcupreempt_trace_buf[cnt], | ||
| 256 | RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 257 | "\n"); | ||
| 258 | bcount = simple_read_from_buffer(buffer, count, ppos, | ||
| 259 | rcupreempt_trace_buf, strlen(rcupreempt_trace_buf)); | ||
| 260 | mutex_unlock(&rcupreempt_trace_mutex); | ||
| 261 | return bcount; | ||
| 262 | } | ||
| 263 | |||
| 264 | static struct file_operations rcustats_fops = { | ||
| 265 | .owner = THIS_MODULE, | ||
| 266 | .read = rcustats_read, | ||
| 267 | }; | ||
| 268 | |||
| 269 | static struct file_operations rcugp_fops = { | ||
| 270 | .owner = THIS_MODULE, | ||
| 271 | .read = rcugp_read, | ||
| 272 | }; | ||
| 273 | |||
| 274 | static struct file_operations rcuctrs_fops = { | ||
| 275 | .owner = THIS_MODULE, | ||
| 276 | .read = rcuctrs_read, | ||
| 277 | }; | ||
| 278 | |||
| 279 | static struct dentry *rcudir, *statdir, *ctrsdir, *gpdir; | ||
| 280 | static int rcupreempt_debugfs_init(void) | ||
| 281 | { | ||
| 282 | rcudir = debugfs_create_dir("rcu", NULL); | ||
| 283 | if (!rcudir) | ||
| 284 | goto out; | ||
| 285 | statdir = debugfs_create_file("rcustats", 0444, rcudir, | ||
| 286 | NULL, &rcustats_fops); | ||
| 287 | if (!statdir) | ||
| 288 | goto free_out; | ||
| 289 | |||
| 290 | gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops); | ||
| 291 | if (!gpdir) | ||
| 292 | goto free_out; | ||
| 293 | |||
| 294 | ctrsdir = debugfs_create_file("rcuctrs", 0444, rcudir, | ||
| 295 | NULL, &rcuctrs_fops); | ||
| 296 | if (!ctrsdir) | ||
| 297 | goto free_out; | ||
| 298 | return 0; | ||
| 299 | free_out: | ||
| 300 | if (statdir) | ||
| 301 | debugfs_remove(statdir); | ||
| 302 | if (gpdir) | ||
| 303 | debugfs_remove(gpdir); | ||
| 304 | debugfs_remove(rcudir); | ||
| 305 | out: | ||
| 306 | return 1; | ||
| 307 | } | ||
| 308 | |||
| 309 | static int __init rcupreempt_trace_init(void) | ||
| 310 | { | ||
| 311 | int ret; | ||
| 312 | |||
| 313 | mutex_init(&rcupreempt_trace_mutex); | ||
| 314 | rcupreempt_trace_buf = kmalloc(RCUPREEMPT_TRACE_BUF_SIZE, GFP_KERNEL); | ||
| 315 | if (!rcupreempt_trace_buf) | ||
| 316 | return 1; | ||
| 317 | ret = rcupreempt_debugfs_init(); | ||
| 318 | if (ret) | ||
| 319 | kfree(rcupreempt_trace_buf); | ||
| 320 | return ret; | ||
| 321 | } | ||
| 322 | |||
| 323 | static void __exit rcupreempt_trace_cleanup(void) | ||
| 324 | { | ||
| 325 | debugfs_remove(statdir); | ||
| 326 | debugfs_remove(gpdir); | ||
| 327 | debugfs_remove(ctrsdir); | ||
| 328 | debugfs_remove(rcudir); | ||
| 329 | kfree(rcupreempt_trace_buf); | ||
| 330 | } | ||
| 331 | |||
| 332 | |||
| 333 | module_init(rcupreempt_trace_init); | ||
| 334 | module_exit(rcupreempt_trace_cleanup); | ||
diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 9b4a975a4b4a..b33db539a8ad 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c | |||
| @@ -257,14 +257,14 @@ struct rcu_torture_ops { | |||
| 257 | void (*init)(void); | 257 | void (*init)(void); |
| 258 | void (*cleanup)(void); | 258 | void (*cleanup)(void); |
| 259 | int (*readlock)(void); | 259 | int (*readlock)(void); |
| 260 | void (*readdelay)(struct rcu_random_state *rrsp); | 260 | void (*read_delay)(struct rcu_random_state *rrsp); |
| 261 | void (*readunlock)(int idx); | 261 | void (*readunlock)(int idx); |
| 262 | int (*completed)(void); | 262 | int (*completed)(void); |
| 263 | void (*deferredfree)(struct rcu_torture *p); | 263 | void (*deferred_free)(struct rcu_torture *p); |
| 264 | void (*sync)(void); | 264 | void (*sync)(void); |
| 265 | void (*cb_barrier)(void); | 265 | void (*cb_barrier)(void); |
| 266 | int (*stats)(char *page); | 266 | int (*stats)(char *page); |
| 267 | int irqcapable; | 267 | int irq_capable; |
| 268 | char *name; | 268 | char *name; |
| 269 | }; | 269 | }; |
| 270 | static struct rcu_torture_ops *cur_ops = NULL; | 270 | static struct rcu_torture_ops *cur_ops = NULL; |
| @@ -320,7 +320,7 @@ rcu_torture_cb(struct rcu_head *p) | |||
| 320 | rp->rtort_mbtest = 0; | 320 | rp->rtort_mbtest = 0; |
| 321 | rcu_torture_free(rp); | 321 | rcu_torture_free(rp); |
| 322 | } else | 322 | } else |
| 323 | cur_ops->deferredfree(rp); | 323 | cur_ops->deferred_free(rp); |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | static void rcu_torture_deferred_free(struct rcu_torture *p) | 326 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
| @@ -329,18 +329,18 @@ static void rcu_torture_deferred_free(struct rcu_torture *p) | |||
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | static struct rcu_torture_ops rcu_ops = { | 331 | static struct rcu_torture_ops rcu_ops = { |
| 332 | .init = NULL, | 332 | .init = NULL, |
| 333 | .cleanup = NULL, | 333 | .cleanup = NULL, |
| 334 | .readlock = rcu_torture_read_lock, | 334 | .readlock = rcu_torture_read_lock, |
| 335 | .readdelay = rcu_read_delay, | 335 | .read_delay = rcu_read_delay, |
| 336 | .readunlock = rcu_torture_read_unlock, | 336 | .readunlock = rcu_torture_read_unlock, |
| 337 | .completed = rcu_torture_completed, | 337 | .completed = rcu_torture_completed, |
| 338 | .deferredfree = rcu_torture_deferred_free, | 338 | .deferred_free = rcu_torture_deferred_free, |
| 339 | .sync = synchronize_rcu, | 339 | .sync = synchronize_rcu, |
| 340 | .cb_barrier = rcu_barrier, | 340 | .cb_barrier = rcu_barrier, |
| 341 | .stats = NULL, | 341 | .stats = NULL, |
| 342 | .irqcapable = 1, | 342 | .irq_capable = 1, |
| 343 | .name = "rcu" | 343 | .name = "rcu" |
| 344 | }; | 344 | }; |
| 345 | 345 | ||
| 346 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) | 346 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) |
| @@ -370,18 +370,18 @@ static void rcu_sync_torture_init(void) | |||
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | static struct rcu_torture_ops rcu_sync_ops = { | 372 | static struct rcu_torture_ops rcu_sync_ops = { |
| 373 | .init = rcu_sync_torture_init, | 373 | .init = rcu_sync_torture_init, |
| 374 | .cleanup = NULL, | 374 | .cleanup = NULL, |
| 375 | .readlock = rcu_torture_read_lock, | 375 | .readlock = rcu_torture_read_lock, |
| 376 | .readdelay = rcu_read_delay, | 376 | .read_delay = rcu_read_delay, |
| 377 | .readunlock = rcu_torture_read_unlock, | 377 | .readunlock = rcu_torture_read_unlock, |
| 378 | .completed = rcu_torture_completed, | 378 | .completed = rcu_torture_completed, |
| 379 | .deferredfree = rcu_sync_torture_deferred_free, | 379 | .deferred_free = rcu_sync_torture_deferred_free, |
| 380 | .sync = synchronize_rcu, | 380 | .sync = synchronize_rcu, |
| 381 | .cb_barrier = NULL, | 381 | .cb_barrier = NULL, |
| 382 | .stats = NULL, | 382 | .stats = NULL, |
| 383 | .irqcapable = 1, | 383 | .irq_capable = 1, |
| 384 | .name = "rcu_sync" | 384 | .name = "rcu_sync" |
| 385 | }; | 385 | }; |
| 386 | 386 | ||
| 387 | /* | 387 | /* |
| @@ -432,33 +432,33 @@ static void rcu_bh_torture_synchronize(void) | |||
| 432 | } | 432 | } |
| 433 | 433 | ||
| 434 | static struct rcu_torture_ops rcu_bh_ops = { | 434 | static struct rcu_torture_ops rcu_bh_ops = { |
| 435 | .init = NULL, | 435 | .init = NULL, |
| 436 | .cleanup = NULL, | 436 | .cleanup = NULL, |
| 437 | .readlock = rcu_bh_torture_read_lock, | 437 | .readlock = rcu_bh_torture_read_lock, |
| 438 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 438 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 439 | .readunlock = rcu_bh_torture_read_unlock, | 439 | .readunlock = rcu_bh_torture_read_unlock, |
| 440 | .completed = rcu_bh_torture_completed, | 440 | .completed = rcu_bh_torture_completed, |
| 441 | .deferredfree = rcu_bh_torture_deferred_free, | 441 | .deferred_free = rcu_bh_torture_deferred_free, |
| 442 | .sync = rcu_bh_torture_synchronize, | 442 | .sync = rcu_bh_torture_synchronize, |
| 443 | .cb_barrier = rcu_barrier_bh, | 443 | .cb_barrier = rcu_barrier_bh, |
| 444 | .stats = NULL, | 444 | .stats = NULL, |
| 445 | .irqcapable = 1, | 445 | .irq_capable = 1, |
| 446 | .name = "rcu_bh" | 446 | .name = "rcu_bh" |
| 447 | }; | 447 | }; |
| 448 | 448 | ||
| 449 | static struct rcu_torture_ops rcu_bh_sync_ops = { | 449 | static struct rcu_torture_ops rcu_bh_sync_ops = { |
| 450 | .init = rcu_sync_torture_init, | 450 | .init = rcu_sync_torture_init, |
| 451 | .cleanup = NULL, | 451 | .cleanup = NULL, |
| 452 | .readlock = rcu_bh_torture_read_lock, | 452 | .readlock = rcu_bh_torture_read_lock, |
| 453 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 453 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 454 | .readunlock = rcu_bh_torture_read_unlock, | 454 | .readunlock = rcu_bh_torture_read_unlock, |
| 455 | .completed = rcu_bh_torture_completed, | 455 | .completed = rcu_bh_torture_completed, |
| 456 | .deferredfree = rcu_sync_torture_deferred_free, | 456 | .deferred_free = rcu_sync_torture_deferred_free, |
| 457 | .sync = rcu_bh_torture_synchronize, | 457 | .sync = rcu_bh_torture_synchronize, |
| 458 | .cb_barrier = NULL, | 458 | .cb_barrier = NULL, |
| 459 | .stats = NULL, | 459 | .stats = NULL, |
| 460 | .irqcapable = 1, | 460 | .irq_capable = 1, |
| 461 | .name = "rcu_bh_sync" | 461 | .name = "rcu_bh_sync" |
| 462 | }; | 462 | }; |
| 463 | 463 | ||
| 464 | /* | 464 | /* |
| @@ -530,17 +530,17 @@ static int srcu_torture_stats(char *page) | |||
| 530 | } | 530 | } |
| 531 | 531 | ||
| 532 | static struct rcu_torture_ops srcu_ops = { | 532 | static struct rcu_torture_ops srcu_ops = { |
| 533 | .init = srcu_torture_init, | 533 | .init = srcu_torture_init, |
| 534 | .cleanup = srcu_torture_cleanup, | 534 | .cleanup = srcu_torture_cleanup, |
| 535 | .readlock = srcu_torture_read_lock, | 535 | .readlock = srcu_torture_read_lock, |
| 536 | .readdelay = srcu_read_delay, | 536 | .read_delay = srcu_read_delay, |
| 537 | .readunlock = srcu_torture_read_unlock, | 537 | .readunlock = srcu_torture_read_unlock, |
| 538 | .completed = srcu_torture_completed, | 538 | .completed = srcu_torture_completed, |
| 539 | .deferredfree = rcu_sync_torture_deferred_free, | 539 | .deferred_free = rcu_sync_torture_deferred_free, |
| 540 | .sync = srcu_torture_synchronize, | 540 | .sync = srcu_torture_synchronize, |
| 541 | .cb_barrier = NULL, | 541 | .cb_barrier = NULL, |
| 542 | .stats = srcu_torture_stats, | 542 | .stats = srcu_torture_stats, |
| 543 | .name = "srcu" | 543 | .name = "srcu" |
| 544 | }; | 544 | }; |
| 545 | 545 | ||
| 546 | /* | 546 | /* |
| @@ -574,32 +574,49 @@ static void sched_torture_synchronize(void) | |||
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | static struct rcu_torture_ops sched_ops = { | 576 | static struct rcu_torture_ops sched_ops = { |
| 577 | .init = rcu_sync_torture_init, | 577 | .init = rcu_sync_torture_init, |
| 578 | .cleanup = NULL, | 578 | .cleanup = NULL, |
| 579 | .readlock = sched_torture_read_lock, | 579 | .readlock = sched_torture_read_lock, |
| 580 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 580 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 581 | .readunlock = sched_torture_read_unlock, | 581 | .readunlock = sched_torture_read_unlock, |
| 582 | .completed = sched_torture_completed, | 582 | .completed = sched_torture_completed, |
| 583 | .deferredfree = rcu_sched_torture_deferred_free, | 583 | .deferred_free = rcu_sched_torture_deferred_free, |
| 584 | .sync = sched_torture_synchronize, | 584 | .sync = sched_torture_synchronize, |
| 585 | .cb_barrier = rcu_barrier_sched, | 585 | .cb_barrier = rcu_barrier_sched, |
| 586 | .stats = NULL, | 586 | .stats = NULL, |
| 587 | .irqcapable = 1, | 587 | .irq_capable = 1, |
| 588 | .name = "sched" | 588 | .name = "sched" |
| 589 | }; | 589 | }; |
| 590 | 590 | ||
| 591 | static struct rcu_torture_ops sched_ops_sync = { | 591 | static struct rcu_torture_ops sched_ops_sync = { |
| 592 | .init = rcu_sync_torture_init, | 592 | .init = rcu_sync_torture_init, |
| 593 | .cleanup = NULL, | 593 | .cleanup = NULL, |
| 594 | .readlock = sched_torture_read_lock, | 594 | .readlock = sched_torture_read_lock, |
| 595 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 595 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 596 | .readunlock = sched_torture_read_unlock, | 596 | .readunlock = sched_torture_read_unlock, |
| 597 | .completed = sched_torture_completed, | 597 | .completed = sched_torture_completed, |
| 598 | .deferredfree = rcu_sync_torture_deferred_free, | 598 | .deferred_free = rcu_sync_torture_deferred_free, |
| 599 | .sync = sched_torture_synchronize, | 599 | .sync = sched_torture_synchronize, |
| 600 | .cb_barrier = NULL, | 600 | .cb_barrier = NULL, |
| 601 | .stats = NULL, | 601 | .stats = NULL, |
| 602 | .name = "sched_sync" | 602 | .name = "sched_sync" |
| 603 | }; | ||
| 604 | |||
| 605 | extern int rcu_expedited_torture_stats(char *page); | ||
| 606 | |||
| 607 | static struct rcu_torture_ops sched_expedited_ops = { | ||
| 608 | .init = rcu_sync_torture_init, | ||
| 609 | .cleanup = NULL, | ||
| 610 | .readlock = sched_torture_read_lock, | ||
| 611 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | ||
| 612 | .readunlock = sched_torture_read_unlock, | ||
| 613 | .completed = sched_torture_completed, | ||
| 614 | .deferred_free = rcu_sync_torture_deferred_free, | ||
| 615 | .sync = synchronize_sched_expedited, | ||
| 616 | .cb_barrier = NULL, | ||
| 617 | .stats = rcu_expedited_torture_stats, | ||
| 618 | .irq_capable = 1, | ||
| 619 | .name = "sched_expedited" | ||
| 603 | }; | 620 | }; |
| 604 | 621 | ||
| 605 | /* | 622 | /* |
| @@ -635,7 +652,7 @@ rcu_torture_writer(void *arg) | |||
| 635 | i = RCU_TORTURE_PIPE_LEN; | 652 | i = RCU_TORTURE_PIPE_LEN; |
| 636 | atomic_inc(&rcu_torture_wcount[i]); | 653 | atomic_inc(&rcu_torture_wcount[i]); |
| 637 | old_rp->rtort_pipe_count++; | 654 | old_rp->rtort_pipe_count++; |
| 638 | cur_ops->deferredfree(old_rp); | 655 | cur_ops->deferred_free(old_rp); |
| 639 | } | 656 | } |
| 640 | rcu_torture_current_version++; | 657 | rcu_torture_current_version++; |
| 641 | oldbatch = cur_ops->completed(); | 658 | oldbatch = cur_ops->completed(); |
| @@ -700,7 +717,7 @@ static void rcu_torture_timer(unsigned long unused) | |||
| 700 | if (p->rtort_mbtest == 0) | 717 | if (p->rtort_mbtest == 0) |
| 701 | atomic_inc(&n_rcu_torture_mberror); | 718 | atomic_inc(&n_rcu_torture_mberror); |
| 702 | spin_lock(&rand_lock); | 719 | spin_lock(&rand_lock); |
| 703 | cur_ops->readdelay(&rand); | 720 | cur_ops->read_delay(&rand); |
| 704 | n_rcu_torture_timers++; | 721 | n_rcu_torture_timers++; |
| 705 | spin_unlock(&rand_lock); | 722 | spin_unlock(&rand_lock); |
| 706 | preempt_disable(); | 723 | preempt_disable(); |
| @@ -738,11 +755,11 @@ rcu_torture_reader(void *arg) | |||
| 738 | 755 | ||
| 739 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | 756 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); |
| 740 | set_user_nice(current, 19); | 757 | set_user_nice(current, 19); |
| 741 | if (irqreader && cur_ops->irqcapable) | 758 | if (irqreader && cur_ops->irq_capable) |
| 742 | setup_timer_on_stack(&t, rcu_torture_timer, 0); | 759 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
| 743 | 760 | ||
| 744 | do { | 761 | do { |
| 745 | if (irqreader && cur_ops->irqcapable) { | 762 | if (irqreader && cur_ops->irq_capable) { |
| 746 | if (!timer_pending(&t)) | 763 | if (!timer_pending(&t)) |
| 747 | mod_timer(&t, 1); | 764 | mod_timer(&t, 1); |
| 748 | } | 765 | } |
| @@ -757,7 +774,7 @@ rcu_torture_reader(void *arg) | |||
| 757 | } | 774 | } |
| 758 | if (p->rtort_mbtest == 0) | 775 | if (p->rtort_mbtest == 0) |
| 759 | atomic_inc(&n_rcu_torture_mberror); | 776 | atomic_inc(&n_rcu_torture_mberror); |
| 760 | cur_ops->readdelay(&rand); | 777 | cur_ops->read_delay(&rand); |
| 761 | preempt_disable(); | 778 | preempt_disable(); |
| 762 | pipe_count = p->rtort_pipe_count; | 779 | pipe_count = p->rtort_pipe_count; |
| 763 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | 780 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { |
| @@ -778,7 +795,7 @@ rcu_torture_reader(void *arg) | |||
| 778 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 795 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); |
| 779 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); | 796 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); |
| 780 | rcutorture_shutdown_absorb("rcu_torture_reader"); | 797 | rcutorture_shutdown_absorb("rcu_torture_reader"); |
| 781 | if (irqreader && cur_ops->irqcapable) | 798 | if (irqreader && cur_ops->irq_capable) |
| 782 | del_timer_sync(&t); | 799 | del_timer_sync(&t); |
| 783 | while (!kthread_should_stop()) | 800 | while (!kthread_should_stop()) |
| 784 | schedule_timeout_uninterruptible(1); | 801 | schedule_timeout_uninterruptible(1); |
| @@ -1078,6 +1095,7 @@ rcu_torture_init(void) | |||
| 1078 | int firsterr = 0; | 1095 | int firsterr = 0; |
| 1079 | static struct rcu_torture_ops *torture_ops[] = | 1096 | static struct rcu_torture_ops *torture_ops[] = |
| 1080 | { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, | 1097 | { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, |
| 1098 | &sched_expedited_ops, | ||
| 1081 | &srcu_ops, &sched_ops, &sched_ops_sync, }; | 1099 | &srcu_ops, &sched_ops, &sched_ops_sync, }; |
| 1082 | 1100 | ||
| 1083 | mutex_lock(&fullstop_mutex); | 1101 | mutex_lock(&fullstop_mutex); |
diff --git a/kernel/rcutree.c b/kernel/rcutree.c index 7717b95c2027..6b11b07cfe7f 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #include <linux/rcupdate.h> | 35 | #include <linux/rcupdate.h> |
| 36 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
| 37 | #include <linux/sched.h> | 37 | #include <linux/sched.h> |
| 38 | #include <linux/nmi.h> | ||
| 38 | #include <asm/atomic.h> | 39 | #include <asm/atomic.h> |
| 39 | #include <linux/bitops.h> | 40 | #include <linux/bitops.h> |
| 40 | #include <linux/module.h> | 41 | #include <linux/module.h> |
| @@ -46,6 +47,8 @@ | |||
| 46 | #include <linux/mutex.h> | 47 | #include <linux/mutex.h> |
| 47 | #include <linux/time.h> | 48 | #include <linux/time.h> |
| 48 | 49 | ||
| 50 | #include "rcutree.h" | ||
| 51 | |||
| 49 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 52 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 50 | static struct lock_class_key rcu_lock_key; | 53 | static struct lock_class_key rcu_lock_key; |
| 51 | struct lockdep_map rcu_lock_map = | 54 | struct lockdep_map rcu_lock_map = |
| @@ -72,30 +75,59 @@ EXPORT_SYMBOL_GPL(rcu_lock_map); | |||
| 72 | .n_force_qs_ngp = 0, \ | 75 | .n_force_qs_ngp = 0, \ |
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | struct rcu_state rcu_state = RCU_STATE_INITIALIZER(rcu_state); | 78 | struct rcu_state rcu_sched_state = RCU_STATE_INITIALIZER(rcu_sched_state); |
| 76 | DEFINE_PER_CPU(struct rcu_data, rcu_data); | 79 | DEFINE_PER_CPU(struct rcu_data, rcu_sched_data); |
| 77 | 80 | ||
| 78 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); | 81 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); |
| 79 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); | 82 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); |
| 80 | 83 | ||
| 84 | extern long rcu_batches_completed_sched(void); | ||
| 85 | static struct rcu_node *rcu_get_root(struct rcu_state *rsp); | ||
| 86 | static void cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, | ||
| 87 | struct rcu_node *rnp, unsigned long flags); | ||
| 88 | static void cpu_quiet_msk_finish(struct rcu_state *rsp, unsigned long flags); | ||
| 89 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 90 | static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp); | ||
| 91 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 92 | static void __rcu_process_callbacks(struct rcu_state *rsp, | ||
| 93 | struct rcu_data *rdp); | ||
| 94 | static void __call_rcu(struct rcu_head *head, | ||
| 95 | void (*func)(struct rcu_head *rcu), | ||
| 96 | struct rcu_state *rsp); | ||
| 97 | static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp); | ||
| 98 | static void __cpuinit rcu_init_percpu_data(int cpu, struct rcu_state *rsp, | ||
| 99 | int preemptable); | ||
| 100 | |||
| 101 | #include "rcutree_plugin.h" | ||
| 102 | |||
| 81 | /* | 103 | /* |
| 82 | * Increment the quiescent state counter. | 104 | * Note a quiescent state. Because we do not need to know |
| 83 | * The counter is a bit degenerated: We do not need to know | ||
| 84 | * how many quiescent states passed, just if there was at least | 105 | * how many quiescent states passed, just if there was at least |
| 85 | * one since the start of the grace period. Thus just a flag. | 106 | * one since the start of the grace period, this just sets a flag. |
| 86 | */ | 107 | */ |
| 87 | void rcu_qsctr_inc(int cpu) | 108 | void rcu_sched_qs(int cpu) |
| 88 | { | 109 | { |
| 89 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | 110 | unsigned long flags; |
| 111 | struct rcu_data *rdp; | ||
| 112 | |||
| 113 | local_irq_save(flags); | ||
| 114 | rdp = &per_cpu(rcu_sched_data, cpu); | ||
| 90 | rdp->passed_quiesc = 1; | 115 | rdp->passed_quiesc = 1; |
| 91 | rdp->passed_quiesc_completed = rdp->completed; | 116 | rdp->passed_quiesc_completed = rdp->completed; |
| 117 | rcu_preempt_qs(cpu); | ||
| 118 | local_irq_restore(flags); | ||
| 92 | } | 119 | } |
| 93 | 120 | ||
| 94 | void rcu_bh_qsctr_inc(int cpu) | 121 | void rcu_bh_qs(int cpu) |
| 95 | { | 122 | { |
| 96 | struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu); | 123 | unsigned long flags; |
| 124 | struct rcu_data *rdp; | ||
| 125 | |||
| 126 | local_irq_save(flags); | ||
| 127 | rdp = &per_cpu(rcu_bh_data, cpu); | ||
| 97 | rdp->passed_quiesc = 1; | 128 | rdp->passed_quiesc = 1; |
| 98 | rdp->passed_quiesc_completed = rdp->completed; | 129 | rdp->passed_quiesc_completed = rdp->completed; |
| 130 | local_irq_restore(flags); | ||
| 99 | } | 131 | } |
| 100 | 132 | ||
| 101 | #ifdef CONFIG_NO_HZ | 133 | #ifdef CONFIG_NO_HZ |
| @@ -110,15 +142,16 @@ static int qhimark = 10000; /* If this many pending, ignore blimit. */ | |||
| 110 | static int qlowmark = 100; /* Once only this many pending, use blimit. */ | 142 | static int qlowmark = 100; /* Once only this many pending, use blimit. */ |
| 111 | 143 | ||
| 112 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); | 144 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); |
| 145 | static int rcu_pending(int cpu); | ||
| 113 | 146 | ||
| 114 | /* | 147 | /* |
| 115 | * Return the number of RCU batches processed thus far for debug & stats. | 148 | * Return the number of RCU-sched batches processed thus far for debug & stats. |
| 116 | */ | 149 | */ |
| 117 | long rcu_batches_completed(void) | 150 | long rcu_batches_completed_sched(void) |
| 118 | { | 151 | { |
| 119 | return rcu_state.completed; | 152 | return rcu_sched_state.completed; |
| 120 | } | 153 | } |
| 121 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | 154 | EXPORT_SYMBOL_GPL(rcu_batches_completed_sched); |
| 122 | 155 | ||
| 123 | /* | 156 | /* |
| 124 | * Return the number of RCU BH batches processed thus far for debug & stats. | 157 | * Return the number of RCU BH batches processed thus far for debug & stats. |
| @@ -181,6 +214,10 @@ static int rcu_implicit_offline_qs(struct rcu_data *rdp) | |||
| 181 | return 1; | 214 | return 1; |
| 182 | } | 215 | } |
| 183 | 216 | ||
| 217 | /* If preemptable RCU, no point in sending reschedule IPI. */ | ||
| 218 | if (rdp->preemptable) | ||
| 219 | return 0; | ||
| 220 | |||
| 184 | /* The CPU is online, so send it a reschedule IPI. */ | 221 | /* The CPU is online, so send it a reschedule IPI. */ |
| 185 | if (rdp->cpu != smp_processor_id()) | 222 | if (rdp->cpu != smp_processor_id()) |
| 186 | smp_send_reschedule(rdp->cpu); | 223 | smp_send_reschedule(rdp->cpu); |
| @@ -193,7 +230,6 @@ static int rcu_implicit_offline_qs(struct rcu_data *rdp) | |||
| 193 | #endif /* #ifdef CONFIG_SMP */ | 230 | #endif /* #ifdef CONFIG_SMP */ |
| 194 | 231 | ||
| 195 | #ifdef CONFIG_NO_HZ | 232 | #ifdef CONFIG_NO_HZ |
| 196 | static DEFINE_RATELIMIT_STATE(rcu_rs, 10 * HZ, 5); | ||
| 197 | 233 | ||
| 198 | /** | 234 | /** |
| 199 | * rcu_enter_nohz - inform RCU that current CPU is entering nohz | 235 | * rcu_enter_nohz - inform RCU that current CPU is entering nohz |
| @@ -213,7 +249,7 @@ void rcu_enter_nohz(void) | |||
| 213 | rdtp = &__get_cpu_var(rcu_dynticks); | 249 | rdtp = &__get_cpu_var(rcu_dynticks); |
| 214 | rdtp->dynticks++; | 250 | rdtp->dynticks++; |
| 215 | rdtp->dynticks_nesting--; | 251 | rdtp->dynticks_nesting--; |
| 216 | WARN_ON_RATELIMIT(rdtp->dynticks & 0x1, &rcu_rs); | 252 | WARN_ON_ONCE(rdtp->dynticks & 0x1); |
| 217 | local_irq_restore(flags); | 253 | local_irq_restore(flags); |
| 218 | } | 254 | } |
| 219 | 255 | ||
| @@ -232,7 +268,7 @@ void rcu_exit_nohz(void) | |||
| 232 | rdtp = &__get_cpu_var(rcu_dynticks); | 268 | rdtp = &__get_cpu_var(rcu_dynticks); |
| 233 | rdtp->dynticks++; | 269 | rdtp->dynticks++; |
| 234 | rdtp->dynticks_nesting++; | 270 | rdtp->dynticks_nesting++; |
| 235 | WARN_ON_RATELIMIT(!(rdtp->dynticks & 0x1), &rcu_rs); | 271 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); |
| 236 | local_irq_restore(flags); | 272 | local_irq_restore(flags); |
| 237 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 273 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
| 238 | } | 274 | } |
| @@ -251,7 +287,7 @@ void rcu_nmi_enter(void) | |||
| 251 | if (rdtp->dynticks & 0x1) | 287 | if (rdtp->dynticks & 0x1) |
| 252 | return; | 288 | return; |
| 253 | rdtp->dynticks_nmi++; | 289 | rdtp->dynticks_nmi++; |
| 254 | WARN_ON_RATELIMIT(!(rdtp->dynticks_nmi & 0x1), &rcu_rs); | 290 | WARN_ON_ONCE(!(rdtp->dynticks_nmi & 0x1)); |
| 255 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 291 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
| 256 | } | 292 | } |
| 257 | 293 | ||
| @@ -270,7 +306,7 @@ void rcu_nmi_exit(void) | |||
| 270 | return; | 306 | return; |
| 271 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | 307 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ |
| 272 | rdtp->dynticks_nmi++; | 308 | rdtp->dynticks_nmi++; |
| 273 | WARN_ON_RATELIMIT(rdtp->dynticks_nmi & 0x1, &rcu_rs); | 309 | WARN_ON_ONCE(rdtp->dynticks_nmi & 0x1); |
| 274 | } | 310 | } |
| 275 | 311 | ||
| 276 | /** | 312 | /** |
| @@ -286,7 +322,7 @@ void rcu_irq_enter(void) | |||
| 286 | if (rdtp->dynticks_nesting++) | 322 | if (rdtp->dynticks_nesting++) |
| 287 | return; | 323 | return; |
| 288 | rdtp->dynticks++; | 324 | rdtp->dynticks++; |
| 289 | WARN_ON_RATELIMIT(!(rdtp->dynticks & 0x1), &rcu_rs); | 325 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); |
| 290 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 326 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
| 291 | } | 327 | } |
| 292 | 328 | ||
| @@ -305,10 +341,10 @@ void rcu_irq_exit(void) | |||
| 305 | return; | 341 | return; |
| 306 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | 342 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ |
| 307 | rdtp->dynticks++; | 343 | rdtp->dynticks++; |
| 308 | WARN_ON_RATELIMIT(rdtp->dynticks & 0x1, &rcu_rs); | 344 | WARN_ON_ONCE(rdtp->dynticks & 0x1); |
| 309 | 345 | ||
| 310 | /* If the interrupt queued a callback, get out of dyntick mode. */ | 346 | /* If the interrupt queued a callback, get out of dyntick mode. */ |
| 311 | if (__get_cpu_var(rcu_data).nxtlist || | 347 | if (__get_cpu_var(rcu_sched_data).nxtlist || |
| 312 | __get_cpu_var(rcu_bh_data).nxtlist) | 348 | __get_cpu_var(rcu_bh_data).nxtlist) |
| 313 | set_need_resched(); | 349 | set_need_resched(); |
| 314 | } | 350 | } |
| @@ -461,6 +497,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
| 461 | 497 | ||
| 462 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); | 498 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); |
| 463 | for (; rnp_cur < rnp_end; rnp_cur++) { | 499 | for (; rnp_cur < rnp_end; rnp_cur++) { |
| 500 | rcu_print_task_stall(rnp); | ||
| 464 | if (rnp_cur->qsmask == 0) | 501 | if (rnp_cur->qsmask == 0) |
| 465 | continue; | 502 | continue; |
| 466 | for (cpu = 0; cpu <= rnp_cur->grphi - rnp_cur->grplo; cpu++) | 503 | for (cpu = 0; cpu <= rnp_cur->grphi - rnp_cur->grplo; cpu++) |
| @@ -469,6 +506,8 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
| 469 | } | 506 | } |
| 470 | printk(" (detected by %d, t=%ld jiffies)\n", | 507 | printk(" (detected by %d, t=%ld jiffies)\n", |
| 471 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); | 508 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); |
| 509 | trigger_all_cpu_backtrace(); | ||
| 510 | |||
| 472 | force_quiescent_state(rsp, 0); /* Kick them all. */ | 511 | force_quiescent_state(rsp, 0); /* Kick them all. */ |
| 473 | } | 512 | } |
| 474 | 513 | ||
| @@ -479,12 +518,14 @@ static void print_cpu_stall(struct rcu_state *rsp) | |||
| 479 | 518 | ||
| 480 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n", | 519 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n", |
| 481 | smp_processor_id(), jiffies - rsp->gp_start); | 520 | smp_processor_id(), jiffies - rsp->gp_start); |
| 482 | dump_stack(); | 521 | trigger_all_cpu_backtrace(); |
| 522 | |||
| 483 | spin_lock_irqsave(&rnp->lock, flags); | 523 | spin_lock_irqsave(&rnp->lock, flags); |
| 484 | if ((long)(jiffies - rsp->jiffies_stall) >= 0) | 524 | if ((long)(jiffies - rsp->jiffies_stall) >= 0) |
| 485 | rsp->jiffies_stall = | 525 | rsp->jiffies_stall = |
| 486 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | 526 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; |
| 487 | spin_unlock_irqrestore(&rnp->lock, flags); | 527 | spin_unlock_irqrestore(&rnp->lock, flags); |
| 528 | |||
| 488 | set_need_resched(); /* kick ourselves to get things going. */ | 529 | set_need_resched(); /* kick ourselves to get things going. */ |
| 489 | } | 530 | } |
| 490 | 531 | ||
| @@ -674,6 +715,19 @@ rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp) | |||
| 674 | } | 715 | } |
| 675 | 716 | ||
| 676 | /* | 717 | /* |
| 718 | * Clean up after the prior grace period and let rcu_start_gp() start up | ||
| 719 | * the next grace period if one is needed. Note that the caller must | ||
| 720 | * hold rnp->lock, as required by rcu_start_gp(), which will release it. | ||
| 721 | */ | ||
| 722 | static void cpu_quiet_msk_finish(struct rcu_state *rsp, unsigned long flags) | ||
| 723 | __releases(rnp->lock) | ||
| 724 | { | ||
| 725 | rsp->completed = rsp->gpnum; | ||
| 726 | rcu_process_gp_end(rsp, rsp->rda[smp_processor_id()]); | ||
| 727 | rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */ | ||
| 728 | } | ||
| 729 | |||
| 730 | /* | ||
| 677 | * Similar to cpu_quiet(), for which it is a helper function. Allows | 731 | * Similar to cpu_quiet(), for which it is a helper function. Allows |
| 678 | * a group of CPUs to be quieted at one go, though all the CPUs in the | 732 | * a group of CPUs to be quieted at one go, though all the CPUs in the |
| 679 | * group must be represented by the same leaf rcu_node structure. | 733 | * group must be represented by the same leaf rcu_node structure. |
| @@ -694,7 +748,7 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp, | |||
| 694 | return; | 748 | return; |
| 695 | } | 749 | } |
| 696 | rnp->qsmask &= ~mask; | 750 | rnp->qsmask &= ~mask; |
| 697 | if (rnp->qsmask != 0) { | 751 | if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) { |
| 698 | 752 | ||
| 699 | /* Other bits still set at this level, so done. */ | 753 | /* Other bits still set at this level, so done. */ |
| 700 | spin_unlock_irqrestore(&rnp->lock, flags); | 754 | spin_unlock_irqrestore(&rnp->lock, flags); |
| @@ -714,14 +768,10 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp, | |||
| 714 | 768 | ||
| 715 | /* | 769 | /* |
| 716 | * Get here if we are the last CPU to pass through a quiescent | 770 | * Get here if we are the last CPU to pass through a quiescent |
| 717 | * state for this grace period. Clean up and let rcu_start_gp() | 771 | * state for this grace period. Invoke cpu_quiet_msk_finish() |
| 718 | * start up the next grace period if one is needed. Note that | 772 | * to clean up and start the next grace period if one is needed. |
| 719 | * we still hold rnp->lock, as required by rcu_start_gp(), which | ||
| 720 | * will release it. | ||
| 721 | */ | 773 | */ |
| 722 | rsp->completed = rsp->gpnum; | 774 | cpu_quiet_msk_finish(rsp, flags); /* releases rnp->lock. */ |
| 723 | rcu_process_gp_end(rsp, rsp->rda[smp_processor_id()]); | ||
| 724 | rcu_start_gp(rsp, flags); /* releases rnp->lock. */ | ||
| 725 | } | 775 | } |
| 726 | 776 | ||
| 727 | /* | 777 | /* |
| @@ -828,11 +878,12 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
| 828 | spin_lock(&rnp->lock); /* irqs already disabled. */ | 878 | spin_lock(&rnp->lock); /* irqs already disabled. */ |
| 829 | rnp->qsmaskinit &= ~mask; | 879 | rnp->qsmaskinit &= ~mask; |
| 830 | if (rnp->qsmaskinit != 0) { | 880 | if (rnp->qsmaskinit != 0) { |
| 831 | spin_unlock(&rnp->lock); /* irqs already disabled. */ | 881 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
| 832 | break; | 882 | break; |
| 833 | } | 883 | } |
| 884 | rcu_preempt_offline_tasks(rsp, rnp); | ||
| 834 | mask = rnp->grpmask; | 885 | mask = rnp->grpmask; |
| 835 | spin_unlock(&rnp->lock); /* irqs already disabled. */ | 886 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
| 836 | rnp = rnp->parent; | 887 | rnp = rnp->parent; |
| 837 | } while (rnp != NULL); | 888 | } while (rnp != NULL); |
| 838 | lastcomp = rsp->completed; | 889 | lastcomp = rsp->completed; |
| @@ -845,7 +896,7 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
| 845 | /* | 896 | /* |
| 846 | * Move callbacks from the outgoing CPU to the running CPU. | 897 | * Move callbacks from the outgoing CPU to the running CPU. |
| 847 | * Note that the outgoing CPU is now quiscent, so it is now | 898 | * Note that the outgoing CPU is now quiscent, so it is now |
| 848 | * (uncharacteristically) safe to access it rcu_data structure. | 899 | * (uncharacteristically) safe to access its rcu_data structure. |
| 849 | * Note also that we must carefully retain the order of the | 900 | * Note also that we must carefully retain the order of the |
| 850 | * outgoing CPU's callbacks in order for rcu_barrier() to work | 901 | * outgoing CPU's callbacks in order for rcu_barrier() to work |
| 851 | * correctly. Finally, note that we start all the callbacks | 902 | * correctly. Finally, note that we start all the callbacks |
| @@ -876,8 +927,9 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
| 876 | */ | 927 | */ |
| 877 | static void rcu_offline_cpu(int cpu) | 928 | static void rcu_offline_cpu(int cpu) |
| 878 | { | 929 | { |
| 879 | __rcu_offline_cpu(cpu, &rcu_state); | 930 | __rcu_offline_cpu(cpu, &rcu_sched_state); |
| 880 | __rcu_offline_cpu(cpu, &rcu_bh_state); | 931 | __rcu_offline_cpu(cpu, &rcu_bh_state); |
| 932 | rcu_preempt_offline_cpu(cpu); | ||
| 881 | } | 933 | } |
| 882 | 934 | ||
| 883 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | 935 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ |
| @@ -963,6 +1015,8 @@ static void rcu_do_batch(struct rcu_data *rdp) | |||
| 963 | */ | 1015 | */ |
| 964 | void rcu_check_callbacks(int cpu, int user) | 1016 | void rcu_check_callbacks(int cpu, int user) |
| 965 | { | 1017 | { |
| 1018 | if (!rcu_pending(cpu)) | ||
| 1019 | return; /* if nothing for RCU to do. */ | ||
| 966 | if (user || | 1020 | if (user || |
| 967 | (idle_cpu(cpu) && rcu_scheduler_active && | 1021 | (idle_cpu(cpu) && rcu_scheduler_active && |
| 968 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | 1022 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { |
| @@ -971,17 +1025,16 @@ void rcu_check_callbacks(int cpu, int user) | |||
| 971 | * Get here if this CPU took its interrupt from user | 1025 | * Get here if this CPU took its interrupt from user |
| 972 | * mode or from the idle loop, and if this is not a | 1026 | * mode or from the idle loop, and if this is not a |
| 973 | * nested interrupt. In this case, the CPU is in | 1027 | * nested interrupt. In this case, the CPU is in |
| 974 | * a quiescent state, so count it. | 1028 | * a quiescent state, so note it. |
| 975 | * | 1029 | * |
| 976 | * No memory barrier is required here because both | 1030 | * No memory barrier is required here because both |
| 977 | * rcu_qsctr_inc() and rcu_bh_qsctr_inc() reference | 1031 | * rcu_sched_qs() and rcu_bh_qs() reference only CPU-local |
| 978 | * only CPU-local variables that other CPUs neither | 1032 | * variables that other CPUs neither access nor modify, |
| 979 | * access nor modify, at least not while the corresponding | 1033 | * at least not while the corresponding CPU is online. |
| 980 | * CPU is online. | ||
| 981 | */ | 1034 | */ |
| 982 | 1035 | ||
| 983 | rcu_qsctr_inc(cpu); | 1036 | rcu_sched_qs(cpu); |
| 984 | rcu_bh_qsctr_inc(cpu); | 1037 | rcu_bh_qs(cpu); |
| 985 | 1038 | ||
| 986 | } else if (!in_softirq()) { | 1039 | } else if (!in_softirq()) { |
| 987 | 1040 | ||
| @@ -989,11 +1042,12 @@ void rcu_check_callbacks(int cpu, int user) | |||
| 989 | * Get here if this CPU did not take its interrupt from | 1042 | * Get here if this CPU did not take its interrupt from |
| 990 | * softirq, in other words, if it is not interrupting | 1043 | * softirq, in other words, if it is not interrupting |
| 991 | * a rcu_bh read-side critical section. This is an _bh | 1044 | * a rcu_bh read-side critical section. This is an _bh |
| 992 | * critical section, so count it. | 1045 | * critical section, so note it. |
| 993 | */ | 1046 | */ |
| 994 | 1047 | ||
| 995 | rcu_bh_qsctr_inc(cpu); | 1048 | rcu_bh_qs(cpu); |
| 996 | } | 1049 | } |
| 1050 | rcu_preempt_check_callbacks(cpu); | ||
| 997 | raise_softirq(RCU_SOFTIRQ); | 1051 | raise_softirq(RCU_SOFTIRQ); |
| 998 | } | 1052 | } |
| 999 | 1053 | ||
| @@ -1132,6 +1186,8 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | |||
| 1132 | { | 1186 | { |
| 1133 | unsigned long flags; | 1187 | unsigned long flags; |
| 1134 | 1188 | ||
| 1189 | WARN_ON_ONCE(rdp->beenonline == 0); | ||
| 1190 | |||
| 1135 | /* | 1191 | /* |
| 1136 | * If an RCU GP has gone long enough, go check for dyntick | 1192 | * If an RCU GP has gone long enough, go check for dyntick |
| 1137 | * idle CPUs and, if needed, send resched IPIs. | 1193 | * idle CPUs and, if needed, send resched IPIs. |
| @@ -1170,8 +1226,10 @@ static void rcu_process_callbacks(struct softirq_action *unused) | |||
| 1170 | */ | 1226 | */ |
| 1171 | smp_mb(); /* See above block comment. */ | 1227 | smp_mb(); /* See above block comment. */ |
| 1172 | 1228 | ||
| 1173 | __rcu_process_callbacks(&rcu_state, &__get_cpu_var(rcu_data)); | 1229 | __rcu_process_callbacks(&rcu_sched_state, |
| 1230 | &__get_cpu_var(rcu_sched_data)); | ||
| 1174 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); | 1231 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); |
| 1232 | rcu_preempt_process_callbacks(); | ||
| 1175 | 1233 | ||
| 1176 | /* | 1234 | /* |
| 1177 | * Memory references from any later RCU read-side critical sections | 1235 | * Memory references from any later RCU read-side critical sections |
| @@ -1227,13 +1285,13 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), | |||
| 1227 | } | 1285 | } |
| 1228 | 1286 | ||
| 1229 | /* | 1287 | /* |
| 1230 | * Queue an RCU callback for invocation after a grace period. | 1288 | * Queue an RCU-sched callback for invocation after a grace period. |
| 1231 | */ | 1289 | */ |
| 1232 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | 1290 | void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) |
| 1233 | { | 1291 | { |
| 1234 | __call_rcu(head, func, &rcu_state); | 1292 | __call_rcu(head, func, &rcu_sched_state); |
| 1235 | } | 1293 | } |
| 1236 | EXPORT_SYMBOL_GPL(call_rcu); | 1294 | EXPORT_SYMBOL_GPL(call_rcu_sched); |
| 1237 | 1295 | ||
| 1238 | /* | 1296 | /* |
| 1239 | * Queue an RCU for invocation after a quicker grace period. | 1297 | * Queue an RCU for invocation after a quicker grace period. |
| @@ -1305,10 +1363,11 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) | |||
| 1305 | * by the current CPU, returning 1 if so. This function is part of the | 1363 | * by the current CPU, returning 1 if so. This function is part of the |
| 1306 | * RCU implementation; it is -not- an exported member of the RCU API. | 1364 | * RCU implementation; it is -not- an exported member of the RCU API. |
| 1307 | */ | 1365 | */ |
| 1308 | int rcu_pending(int cpu) | 1366 | static int rcu_pending(int cpu) |
| 1309 | { | 1367 | { |
| 1310 | return __rcu_pending(&rcu_state, &per_cpu(rcu_data, cpu)) || | 1368 | return __rcu_pending(&rcu_sched_state, &per_cpu(rcu_sched_data, cpu)) || |
| 1311 | __rcu_pending(&rcu_bh_state, &per_cpu(rcu_bh_data, cpu)); | 1369 | __rcu_pending(&rcu_bh_state, &per_cpu(rcu_bh_data, cpu)) || |
| 1370 | rcu_preempt_pending(cpu); | ||
| 1312 | } | 1371 | } |
| 1313 | 1372 | ||
| 1314 | /* | 1373 | /* |
| @@ -1320,27 +1379,46 @@ int rcu_pending(int cpu) | |||
| 1320 | int rcu_needs_cpu(int cpu) | 1379 | int rcu_needs_cpu(int cpu) |
| 1321 | { | 1380 | { |
| 1322 | /* RCU callbacks either ready or pending? */ | 1381 | /* RCU callbacks either ready or pending? */ |
| 1323 | return per_cpu(rcu_data, cpu).nxtlist || | 1382 | return per_cpu(rcu_sched_data, cpu).nxtlist || |
| 1324 | per_cpu(rcu_bh_data, cpu).nxtlist; | 1383 | per_cpu(rcu_bh_data, cpu).nxtlist || |
| 1384 | rcu_preempt_needs_cpu(cpu); | ||
| 1325 | } | 1385 | } |
| 1326 | 1386 | ||
| 1327 | /* | 1387 | /* |
| 1328 | * Initialize a CPU's per-CPU RCU data. We take this "scorched earth" | 1388 | * Do boot-time initialization of a CPU's per-CPU RCU data. |
| 1329 | * approach so that we don't have to worry about how long the CPU has | ||
| 1330 | * been gone, or whether it ever was online previously. We do trust the | ||
| 1331 | * ->mynode field, as it is constant for a given struct rcu_data and | ||
| 1332 | * initialized during early boot. | ||
| 1333 | * | ||
| 1334 | * Note that only one online or offline event can be happening at a given | ||
| 1335 | * time. Note also that we can accept some slop in the rsp->completed | ||
| 1336 | * access due to the fact that this CPU cannot possibly have any RCU | ||
| 1337 | * callbacks in flight yet. | ||
| 1338 | */ | 1389 | */ |
| 1339 | static void __cpuinit | 1390 | static void __init |
| 1340 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | 1391 | rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp) |
| 1341 | { | 1392 | { |
| 1342 | unsigned long flags; | 1393 | unsigned long flags; |
| 1343 | int i; | 1394 | int i; |
| 1395 | struct rcu_data *rdp = rsp->rda[cpu]; | ||
| 1396 | struct rcu_node *rnp = rcu_get_root(rsp); | ||
| 1397 | |||
| 1398 | /* Set up local state, ensuring consistent view of global state. */ | ||
| 1399 | spin_lock_irqsave(&rnp->lock, flags); | ||
| 1400 | rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo); | ||
| 1401 | rdp->nxtlist = NULL; | ||
| 1402 | for (i = 0; i < RCU_NEXT_SIZE; i++) | ||
| 1403 | rdp->nxttail[i] = &rdp->nxtlist; | ||
| 1404 | rdp->qlen = 0; | ||
| 1405 | #ifdef CONFIG_NO_HZ | ||
| 1406 | rdp->dynticks = &per_cpu(rcu_dynticks, cpu); | ||
| 1407 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 1408 | rdp->cpu = cpu; | ||
| 1409 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 1410 | } | ||
| 1411 | |||
| 1412 | /* | ||
| 1413 | * Initialize a CPU's per-CPU RCU data. Note that only one online or | ||
| 1414 | * offline event can be happening at a given time. Note also that we | ||
| 1415 | * can accept some slop in the rsp->completed access due to the fact | ||
| 1416 | * that this CPU cannot possibly have any RCU callbacks in flight yet. | ||
| 1417 | */ | ||
| 1418 | static void __cpuinit | ||
| 1419 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) | ||
| 1420 | { | ||
| 1421 | unsigned long flags; | ||
| 1344 | long lastcomp; | 1422 | long lastcomp; |
| 1345 | unsigned long mask; | 1423 | unsigned long mask; |
| 1346 | struct rcu_data *rdp = rsp->rda[cpu]; | 1424 | struct rcu_data *rdp = rsp->rda[cpu]; |
| @@ -1354,17 +1432,9 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | |||
| 1354 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ | 1432 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ |
| 1355 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ | 1433 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ |
| 1356 | rdp->beenonline = 1; /* We have now been online. */ | 1434 | rdp->beenonline = 1; /* We have now been online. */ |
| 1435 | rdp->preemptable = preemptable; | ||
| 1357 | rdp->passed_quiesc_completed = lastcomp - 1; | 1436 | rdp->passed_quiesc_completed = lastcomp - 1; |
| 1358 | rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo); | ||
| 1359 | rdp->nxtlist = NULL; | ||
| 1360 | for (i = 0; i < RCU_NEXT_SIZE; i++) | ||
| 1361 | rdp->nxttail[i] = &rdp->nxtlist; | ||
| 1362 | rdp->qlen = 0; | ||
| 1363 | rdp->blimit = blimit; | 1437 | rdp->blimit = blimit; |
| 1364 | #ifdef CONFIG_NO_HZ | ||
| 1365 | rdp->dynticks = &per_cpu(rcu_dynticks, cpu); | ||
| 1366 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 1367 | rdp->cpu = cpu; | ||
| 1368 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | 1438 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
| 1369 | 1439 | ||
| 1370 | /* | 1440 | /* |
| @@ -1405,16 +1475,16 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | |||
| 1405 | 1475 | ||
| 1406 | static void __cpuinit rcu_online_cpu(int cpu) | 1476 | static void __cpuinit rcu_online_cpu(int cpu) |
| 1407 | { | 1477 | { |
| 1408 | rcu_init_percpu_data(cpu, &rcu_state); | 1478 | rcu_init_percpu_data(cpu, &rcu_sched_state, 0); |
| 1409 | rcu_init_percpu_data(cpu, &rcu_bh_state); | 1479 | rcu_init_percpu_data(cpu, &rcu_bh_state, 0); |
| 1410 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | 1480 | rcu_preempt_init_percpu_data(cpu); |
| 1411 | } | 1481 | } |
| 1412 | 1482 | ||
| 1413 | /* | 1483 | /* |
| 1414 | * Handle CPU online/offline notifcation events. | 1484 | * Handle CPU online/offline notification events. |
| 1415 | */ | 1485 | */ |
| 1416 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | 1486 | int __cpuinit rcu_cpu_notify(struct notifier_block *self, |
| 1417 | unsigned long action, void *hcpu) | 1487 | unsigned long action, void *hcpu) |
| 1418 | { | 1488 | { |
| 1419 | long cpu = (long)hcpu; | 1489 | long cpu = (long)hcpu; |
| 1420 | 1490 | ||
| @@ -1486,6 +1556,7 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
| 1486 | rnp = rsp->level[i]; | 1556 | rnp = rsp->level[i]; |
| 1487 | for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) { | 1557 | for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) { |
| 1488 | spin_lock_init(&rnp->lock); | 1558 | spin_lock_init(&rnp->lock); |
| 1559 | rnp->gpnum = 0; | ||
| 1489 | rnp->qsmask = 0; | 1560 | rnp->qsmask = 0; |
| 1490 | rnp->qsmaskinit = 0; | 1561 | rnp->qsmaskinit = 0; |
| 1491 | rnp->grplo = j * cpustride; | 1562 | rnp->grplo = j * cpustride; |
| @@ -1503,16 +1574,20 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
| 1503 | j / rsp->levelspread[i - 1]; | 1574 | j / rsp->levelspread[i - 1]; |
| 1504 | } | 1575 | } |
| 1505 | rnp->level = i; | 1576 | rnp->level = i; |
| 1577 | INIT_LIST_HEAD(&rnp->blocked_tasks[0]); | ||
| 1578 | INIT_LIST_HEAD(&rnp->blocked_tasks[1]); | ||
| 1506 | } | 1579 | } |
| 1507 | } | 1580 | } |
| 1508 | } | 1581 | } |
| 1509 | 1582 | ||
| 1510 | /* | 1583 | /* |
| 1511 | * Helper macro for __rcu_init(). To be used nowhere else! | 1584 | * Helper macro for __rcu_init() and __rcu_init_preempt(). To be used |
| 1512 | * Assigns leaf node pointers into each CPU's rcu_data structure. | 1585 | * nowhere else! Assigns leaf node pointers into each CPU's rcu_data |
| 1586 | * structure. | ||
| 1513 | */ | 1587 | */ |
| 1514 | #define RCU_DATA_PTR_INIT(rsp, rcu_data) \ | 1588 | #define RCU_INIT_FLAVOR(rsp, rcu_data) \ |
| 1515 | do { \ | 1589 | do { \ |
| 1590 | rcu_init_one(rsp); \ | ||
| 1516 | rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \ | 1591 | rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \ |
| 1517 | j = 0; \ | 1592 | j = 0; \ |
| 1518 | for_each_possible_cpu(i) { \ | 1593 | for_each_possible_cpu(i) { \ |
| @@ -1520,32 +1595,43 @@ do { \ | |||
| 1520 | j++; \ | 1595 | j++; \ |
| 1521 | per_cpu(rcu_data, i).mynode = &rnp[j]; \ | 1596 | per_cpu(rcu_data, i).mynode = &rnp[j]; \ |
| 1522 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ | 1597 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ |
| 1598 | rcu_boot_init_percpu_data(i, rsp); \ | ||
| 1523 | } \ | 1599 | } \ |
| 1524 | } while (0) | 1600 | } while (0) |
| 1525 | 1601 | ||
| 1526 | static struct notifier_block __cpuinitdata rcu_nb = { | 1602 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 1527 | .notifier_call = rcu_cpu_notify, | 1603 | |
| 1528 | }; | 1604 | void __init __rcu_init_preempt(void) |
| 1605 | { | ||
| 1606 | int i; /* All used by RCU_INIT_FLAVOR(). */ | ||
| 1607 | int j; | ||
| 1608 | struct rcu_node *rnp; | ||
| 1609 | |||
| 1610 | RCU_INIT_FLAVOR(&rcu_preempt_state, rcu_preempt_data); | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 1614 | |||
| 1615 | void __init __rcu_init_preempt(void) | ||
| 1616 | { | ||
| 1617 | } | ||
| 1618 | |||
| 1619 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 1529 | 1620 | ||
| 1530 | void __init __rcu_init(void) | 1621 | void __init __rcu_init(void) |
| 1531 | { | 1622 | { |
| 1532 | int i; /* All used by RCU_DATA_PTR_INIT(). */ | 1623 | int i; /* All used by RCU_INIT_FLAVOR(). */ |
| 1533 | int j; | 1624 | int j; |
| 1534 | struct rcu_node *rnp; | 1625 | struct rcu_node *rnp; |
| 1535 | 1626 | ||
| 1536 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); | 1627 | rcu_bootup_announce(); |
| 1537 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 1628 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR |
| 1538 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); | 1629 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); |
| 1539 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 1630 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
| 1540 | rcu_init_one(&rcu_state); | 1631 | RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data); |
| 1541 | RCU_DATA_PTR_INIT(&rcu_state, rcu_data); | 1632 | RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data); |
| 1542 | rcu_init_one(&rcu_bh_state); | 1633 | __rcu_init_preempt(); |
| 1543 | RCU_DATA_PTR_INIT(&rcu_bh_state, rcu_bh_data); | 1634 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); |
| 1544 | |||
| 1545 | for_each_online_cpu(i) | ||
| 1546 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, (void *)(long)i); | ||
| 1547 | /* Register notifier for non-boot CPUs */ | ||
| 1548 | register_cpu_notifier(&rcu_nb); | ||
| 1549 | } | 1635 | } |
| 1550 | 1636 | ||
| 1551 | module_param(blimit, int, 0); | 1637 | module_param(blimit, int, 0); |
diff --git a/kernel/rcutree.h b/kernel/rcutree.h index 5e872bbf07f5..bf8a6f9f134d 100644 --- a/kernel/rcutree.h +++ b/kernel/rcutree.h | |||
| @@ -1,10 +1,259 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion (tree-based version) | ||
| 3 | * Internal non-public definitions. | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | * | ||
| 19 | * Copyright IBM Corporation, 2008 | ||
| 20 | * | ||
| 21 | * Author: Ingo Molnar <mingo@elte.hu> | ||
| 22 | * Paul E. McKenney <paulmck@linux.vnet.ibm.com> | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <linux/cache.h> | ||
| 26 | #include <linux/spinlock.h> | ||
| 27 | #include <linux/threads.h> | ||
| 28 | #include <linux/cpumask.h> | ||
| 29 | #include <linux/seqlock.h> | ||
| 30 | |||
| 31 | /* | ||
| 32 | * Define shape of hierarchy based on NR_CPUS and CONFIG_RCU_FANOUT. | ||
| 33 | * In theory, it should be possible to add more levels straightforwardly. | ||
| 34 | * In practice, this has not been tested, so there is probably some | ||
| 35 | * bug somewhere. | ||
| 36 | */ | ||
| 37 | #define MAX_RCU_LVLS 3 | ||
| 38 | #define RCU_FANOUT (CONFIG_RCU_FANOUT) | ||
| 39 | #define RCU_FANOUT_SQ (RCU_FANOUT * RCU_FANOUT) | ||
| 40 | #define RCU_FANOUT_CUBE (RCU_FANOUT_SQ * RCU_FANOUT) | ||
| 41 | |||
| 42 | #if NR_CPUS <= RCU_FANOUT | ||
| 43 | # define NUM_RCU_LVLS 1 | ||
| 44 | # define NUM_RCU_LVL_0 1 | ||
| 45 | # define NUM_RCU_LVL_1 (NR_CPUS) | ||
| 46 | # define NUM_RCU_LVL_2 0 | ||
| 47 | # define NUM_RCU_LVL_3 0 | ||
| 48 | #elif NR_CPUS <= RCU_FANOUT_SQ | ||
| 49 | # define NUM_RCU_LVLS 2 | ||
| 50 | # define NUM_RCU_LVL_0 1 | ||
| 51 | # define NUM_RCU_LVL_1 (((NR_CPUS) + RCU_FANOUT - 1) / RCU_FANOUT) | ||
| 52 | # define NUM_RCU_LVL_2 (NR_CPUS) | ||
| 53 | # define NUM_RCU_LVL_3 0 | ||
| 54 | #elif NR_CPUS <= RCU_FANOUT_CUBE | ||
| 55 | # define NUM_RCU_LVLS 3 | ||
| 56 | # define NUM_RCU_LVL_0 1 | ||
| 57 | # define NUM_RCU_LVL_1 (((NR_CPUS) + RCU_FANOUT_SQ - 1) / RCU_FANOUT_SQ) | ||
| 58 | # define NUM_RCU_LVL_2 (((NR_CPUS) + (RCU_FANOUT) - 1) / (RCU_FANOUT)) | ||
| 59 | # define NUM_RCU_LVL_3 NR_CPUS | ||
| 60 | #else | ||
| 61 | # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS" | ||
| 62 | #endif /* #if (NR_CPUS) <= RCU_FANOUT */ | ||
| 63 | |||
| 64 | #define RCU_SUM (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3) | ||
| 65 | #define NUM_RCU_NODES (RCU_SUM - NR_CPUS) | ||
| 66 | |||
| 67 | /* | ||
| 68 | * Dynticks per-CPU state. | ||
| 69 | */ | ||
| 70 | struct rcu_dynticks { | ||
| 71 | int dynticks_nesting; /* Track nesting level, sort of. */ | ||
| 72 | int dynticks; /* Even value for dynticks-idle, else odd. */ | ||
| 73 | int dynticks_nmi; /* Even value for either dynticks-idle or */ | ||
| 74 | /* not in nmi handler, else odd. So this */ | ||
| 75 | /* remains even for nmi from irq handler. */ | ||
| 76 | }; | ||
| 77 | |||
| 78 | /* | ||
| 79 | * Definition for node within the RCU grace-period-detection hierarchy. | ||
| 80 | */ | ||
| 81 | struct rcu_node { | ||
| 82 | spinlock_t lock; | ||
| 83 | long gpnum; /* Current grace period for this node. */ | ||
| 84 | /* This will either be equal to or one */ | ||
| 85 | /* behind the root rcu_node's gpnum. */ | ||
| 86 | unsigned long qsmask; /* CPUs or groups that need to switch in */ | ||
| 87 | /* order for current grace period to proceed.*/ | ||
| 88 | unsigned long qsmaskinit; | ||
| 89 | /* Per-GP initialization for qsmask. */ | ||
| 90 | unsigned long grpmask; /* Mask to apply to parent qsmask. */ | ||
| 91 | int grplo; /* lowest-numbered CPU or group here. */ | ||
| 92 | int grphi; /* highest-numbered CPU or group here. */ | ||
| 93 | u8 grpnum; /* CPU/group number for next level up. */ | ||
| 94 | u8 level; /* root is at level 0. */ | ||
| 95 | struct rcu_node *parent; | ||
| 96 | struct list_head blocked_tasks[2]; | ||
| 97 | /* Tasks blocked in RCU read-side critsect. */ | ||
| 98 | } ____cacheline_internodealigned_in_smp; | ||
| 99 | |||
| 100 | /* Index values for nxttail array in struct rcu_data. */ | ||
| 101 | #define RCU_DONE_TAIL 0 /* Also RCU_WAIT head. */ | ||
| 102 | #define RCU_WAIT_TAIL 1 /* Also RCU_NEXT_READY head. */ | ||
| 103 | #define RCU_NEXT_READY_TAIL 2 /* Also RCU_NEXT head. */ | ||
| 104 | #define RCU_NEXT_TAIL 3 | ||
| 105 | #define RCU_NEXT_SIZE 4 | ||
| 106 | |||
| 107 | /* Per-CPU data for read-copy update. */ | ||
| 108 | struct rcu_data { | ||
| 109 | /* 1) quiescent-state and grace-period handling : */ | ||
| 110 | long completed; /* Track rsp->completed gp number */ | ||
| 111 | /* in order to detect GP end. */ | ||
| 112 | long gpnum; /* Highest gp number that this CPU */ | ||
| 113 | /* is aware of having started. */ | ||
| 114 | long passed_quiesc_completed; | ||
| 115 | /* Value of completed at time of qs. */ | ||
| 116 | bool passed_quiesc; /* User-mode/idle loop etc. */ | ||
| 117 | bool qs_pending; /* Core waits for quiesc state. */ | ||
| 118 | bool beenonline; /* CPU online at least once. */ | ||
| 119 | bool preemptable; /* Preemptable RCU? */ | ||
| 120 | struct rcu_node *mynode; /* This CPU's leaf of hierarchy */ | ||
| 121 | unsigned long grpmask; /* Mask to apply to leaf qsmask. */ | ||
| 122 | |||
| 123 | /* 2) batch handling */ | ||
| 124 | /* | ||
| 125 | * If nxtlist is not NULL, it is partitioned as follows. | ||
| 126 | * Any of the partitions might be empty, in which case the | ||
| 127 | * pointer to that partition will be equal to the pointer for | ||
| 128 | * the following partition. When the list is empty, all of | ||
| 129 | * the nxttail elements point to nxtlist, which is NULL. | ||
| 130 | * | ||
| 131 | * [*nxttail[RCU_NEXT_READY_TAIL], NULL = *nxttail[RCU_NEXT_TAIL]): | ||
| 132 | * Entries that might have arrived after current GP ended | ||
| 133 | * [*nxttail[RCU_WAIT_TAIL], *nxttail[RCU_NEXT_READY_TAIL]): | ||
| 134 | * Entries known to have arrived before current GP ended | ||
| 135 | * [*nxttail[RCU_DONE_TAIL], *nxttail[RCU_WAIT_TAIL]): | ||
| 136 | * Entries that batch # <= ->completed - 1: waiting for current GP | ||
| 137 | * [nxtlist, *nxttail[RCU_DONE_TAIL]): | ||
| 138 | * Entries that batch # <= ->completed | ||
| 139 | * The grace period for these entries has completed, and | ||
| 140 | * the other grace-period-completed entries may be moved | ||
| 141 | * here temporarily in rcu_process_callbacks(). | ||
| 142 | */ | ||
| 143 | struct rcu_head *nxtlist; | ||
| 144 | struct rcu_head **nxttail[RCU_NEXT_SIZE]; | ||
| 145 | long qlen; /* # of queued callbacks */ | ||
| 146 | long blimit; /* Upper limit on a processed batch */ | ||
| 147 | |||
| 148 | #ifdef CONFIG_NO_HZ | ||
| 149 | /* 3) dynticks interface. */ | ||
| 150 | struct rcu_dynticks *dynticks; /* Shared per-CPU dynticks state. */ | ||
| 151 | int dynticks_snap; /* Per-GP tracking for dynticks. */ | ||
| 152 | int dynticks_nmi_snap; /* Per-GP tracking for dynticks_nmi. */ | ||
| 153 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 154 | |||
| 155 | /* 4) reasons this CPU needed to be kicked by force_quiescent_state */ | ||
| 156 | #ifdef CONFIG_NO_HZ | ||
| 157 | unsigned long dynticks_fqs; /* Kicked due to dynticks idle. */ | ||
| 158 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 159 | unsigned long offline_fqs; /* Kicked due to being offline. */ | ||
| 160 | unsigned long resched_ipi; /* Sent a resched IPI. */ | ||
| 161 | |||
| 162 | /* 5) __rcu_pending() statistics. */ | ||
| 163 | long n_rcu_pending; /* rcu_pending() calls since boot. */ | ||
| 164 | long n_rp_qs_pending; | ||
| 165 | long n_rp_cb_ready; | ||
| 166 | long n_rp_cpu_needs_gp; | ||
| 167 | long n_rp_gp_completed; | ||
| 168 | long n_rp_gp_started; | ||
| 169 | long n_rp_need_fqs; | ||
| 170 | long n_rp_need_nothing; | ||
| 171 | |||
| 172 | int cpu; | ||
| 173 | }; | ||
| 174 | |||
| 175 | /* Values for signaled field in struct rcu_state. */ | ||
| 176 | #define RCU_GP_INIT 0 /* Grace period being initialized. */ | ||
| 177 | #define RCU_SAVE_DYNTICK 1 /* Need to scan dyntick state. */ | ||
| 178 | #define RCU_FORCE_QS 2 /* Need to force quiescent state. */ | ||
| 179 | #ifdef CONFIG_NO_HZ | ||
| 180 | #define RCU_SIGNAL_INIT RCU_SAVE_DYNTICK | ||
| 181 | #else /* #ifdef CONFIG_NO_HZ */ | ||
| 182 | #define RCU_SIGNAL_INIT RCU_FORCE_QS | ||
| 183 | #endif /* #else #ifdef CONFIG_NO_HZ */ | ||
| 184 | |||
| 185 | #define RCU_JIFFIES_TILL_FORCE_QS 3 /* for rsp->jiffies_force_qs */ | ||
| 186 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 187 | #define RCU_SECONDS_TILL_STALL_CHECK (10 * HZ) /* for rsp->jiffies_stall */ | ||
| 188 | #define RCU_SECONDS_TILL_STALL_RECHECK (30 * HZ) /* for rsp->jiffies_stall */ | ||
| 189 | #define RCU_STALL_RAT_DELAY 2 /* Allow other CPUs time */ | ||
| 190 | /* to take at least one */ | ||
| 191 | /* scheduling clock irq */ | ||
| 192 | /* before ratting on them. */ | ||
| 193 | |||
| 194 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 195 | |||
| 196 | /* | ||
| 197 | * RCU global state, including node hierarchy. This hierarchy is | ||
| 198 | * represented in "heap" form in a dense array. The root (first level) | ||
| 199 | * of the hierarchy is in ->node[0] (referenced by ->level[0]), the second | ||
| 200 | * level in ->node[1] through ->node[m] (->node[1] referenced by ->level[1]), | ||
| 201 | * and the third level in ->node[m+1] and following (->node[m+1] referenced | ||
| 202 | * by ->level[2]). The number of levels is determined by the number of | ||
| 203 | * CPUs and by CONFIG_RCU_FANOUT. Small systems will have a "hierarchy" | ||
| 204 | * consisting of a single rcu_node. | ||
| 205 | */ | ||
| 206 | struct rcu_state { | ||
| 207 | struct rcu_node node[NUM_RCU_NODES]; /* Hierarchy. */ | ||
| 208 | struct rcu_node *level[NUM_RCU_LVLS]; /* Hierarchy levels. */ | ||
| 209 | u32 levelcnt[MAX_RCU_LVLS + 1]; /* # nodes in each level. */ | ||
| 210 | u8 levelspread[NUM_RCU_LVLS]; /* kids/node in each level. */ | ||
| 211 | struct rcu_data *rda[NR_CPUS]; /* array of rdp pointers. */ | ||
| 212 | |||
| 213 | /* The following fields are guarded by the root rcu_node's lock. */ | ||
| 214 | |||
| 215 | u8 signaled ____cacheline_internodealigned_in_smp; | ||
| 216 | /* Force QS state. */ | ||
| 217 | long gpnum; /* Current gp number. */ | ||
| 218 | long completed; /* # of last completed gp. */ | ||
| 219 | spinlock_t onofflock; /* exclude on/offline and */ | ||
| 220 | /* starting new GP. */ | ||
| 221 | spinlock_t fqslock; /* Only one task forcing */ | ||
| 222 | /* quiescent states. */ | ||
| 223 | unsigned long jiffies_force_qs; /* Time at which to invoke */ | ||
| 224 | /* force_quiescent_state(). */ | ||
| 225 | unsigned long n_force_qs; /* Number of calls to */ | ||
| 226 | /* force_quiescent_state(). */ | ||
| 227 | unsigned long n_force_qs_lh; /* ~Number of calls leaving */ | ||
| 228 | /* due to lock unavailable. */ | ||
| 229 | unsigned long n_force_qs_ngp; /* Number of calls leaving */ | ||
| 230 | /* due to no GP active. */ | ||
| 231 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 232 | unsigned long gp_start; /* Time at which GP started, */ | ||
| 233 | /* but in jiffies. */ | ||
| 234 | unsigned long jiffies_stall; /* Time at which to check */ | ||
| 235 | /* for CPU stalls. */ | ||
| 236 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 237 | #ifdef CONFIG_NO_HZ | ||
| 238 | long dynticks_completed; /* Value of completed @ snap. */ | ||
| 239 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 240 | }; | ||
| 241 | |||
| 242 | #ifdef RCU_TREE_NONCORE | ||
| 1 | 243 | ||
| 2 | /* | 244 | /* |
| 3 | * RCU implementation internal declarations: | 245 | * RCU implementation internal declarations: |
| 4 | */ | 246 | */ |
| 5 | extern struct rcu_state rcu_state; | 247 | extern struct rcu_state rcu_sched_state; |
| 6 | DECLARE_PER_CPU(struct rcu_data, rcu_data); | 248 | DECLARE_PER_CPU(struct rcu_data, rcu_sched_data); |
| 7 | 249 | ||
| 8 | extern struct rcu_state rcu_bh_state; | 250 | extern struct rcu_state rcu_bh_state; |
| 9 | DECLARE_PER_CPU(struct rcu_data, rcu_bh_data); | 251 | DECLARE_PER_CPU(struct rcu_data, rcu_bh_data); |
| 10 | 252 | ||
| 253 | #ifdef CONFIG_TREE_PREEMPT_RCU | ||
| 254 | extern struct rcu_state rcu_preempt_state; | ||
| 255 | DECLARE_PER_CPU(struct rcu_data, rcu_preempt_data); | ||
| 256 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 257 | |||
| 258 | #endif /* #ifdef RCU_TREE_NONCORE */ | ||
| 259 | |||
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h new file mode 100644 index 000000000000..47789369ea59 --- /dev/null +++ b/kernel/rcutree_plugin.h | |||
| @@ -0,0 +1,532 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion (tree-based version) | ||
| 3 | * Internal non-public definitions that provide either classic | ||
| 4 | * or preemptable semantics. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | * | ||
| 20 | * Copyright Red Hat, 2009 | ||
| 21 | * Copyright IBM Corporation, 2009 | ||
| 22 | * | ||
| 23 | * Author: Ingo Molnar <mingo@elte.hu> | ||
| 24 | * Paul E. McKenney <paulmck@linux.vnet.ibm.com> | ||
| 25 | */ | ||
| 26 | |||
| 27 | |||
| 28 | #ifdef CONFIG_TREE_PREEMPT_RCU | ||
| 29 | |||
| 30 | struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state); | ||
| 31 | DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data); | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Tell them what RCU they are running. | ||
| 35 | */ | ||
| 36 | static inline void rcu_bootup_announce(void) | ||
| 37 | { | ||
| 38 | printk(KERN_INFO | ||
| 39 | "Experimental preemptable hierarchical RCU implementation.\n"); | ||
| 40 | } | ||
| 41 | |||
| 42 | /* | ||
| 43 | * Return the number of RCU-preempt batches processed thus far | ||
| 44 | * for debug and statistics. | ||
| 45 | */ | ||
| 46 | long rcu_batches_completed_preempt(void) | ||
| 47 | { | ||
| 48 | return rcu_preempt_state.completed; | ||
| 49 | } | ||
| 50 | EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt); | ||
| 51 | |||
| 52 | /* | ||
| 53 | * Return the number of RCU batches processed thus far for debug & stats. | ||
| 54 | */ | ||
| 55 | long rcu_batches_completed(void) | ||
| 56 | { | ||
| 57 | return rcu_batches_completed_preempt(); | ||
| 58 | } | ||
| 59 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 60 | |||
| 61 | /* | ||
| 62 | * Record a preemptable-RCU quiescent state for the specified CPU. Note | ||
| 63 | * that this just means that the task currently running on the CPU is | ||
| 64 | * not in a quiescent state. There might be any number of tasks blocked | ||
| 65 | * while in an RCU read-side critical section. | ||
| 66 | */ | ||
| 67 | static void rcu_preempt_qs_record(int cpu) | ||
| 68 | { | ||
| 69 | struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); | ||
| 70 | rdp->passed_quiesc = 1; | ||
| 71 | rdp->passed_quiesc_completed = rdp->completed; | ||
| 72 | } | ||
| 73 | |||
| 74 | /* | ||
| 75 | * We have entered the scheduler or are between softirqs in ksoftirqd. | ||
| 76 | * If we are in an RCU read-side critical section, we need to reflect | ||
| 77 | * that in the state of the rcu_node structure corresponding to this CPU. | ||
| 78 | * Caller must disable hardirqs. | ||
| 79 | */ | ||
| 80 | static void rcu_preempt_qs(int cpu) | ||
| 81 | { | ||
| 82 | struct task_struct *t = current; | ||
| 83 | int phase; | ||
| 84 | struct rcu_data *rdp; | ||
| 85 | struct rcu_node *rnp; | ||
| 86 | |||
| 87 | if (t->rcu_read_lock_nesting && | ||
| 88 | (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) { | ||
| 89 | |||
| 90 | /* Possibly blocking in an RCU read-side critical section. */ | ||
| 91 | rdp = rcu_preempt_state.rda[cpu]; | ||
| 92 | rnp = rdp->mynode; | ||
| 93 | spin_lock(&rnp->lock); | ||
| 94 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED; | ||
| 95 | t->rcu_blocked_node = rnp; | ||
| 96 | |||
| 97 | /* | ||
| 98 | * If this CPU has already checked in, then this task | ||
| 99 | * will hold up the next grace period rather than the | ||
| 100 | * current grace period. Queue the task accordingly. | ||
| 101 | * If the task is queued for the current grace period | ||
| 102 | * (i.e., this CPU has not yet passed through a quiescent | ||
| 103 | * state for the current grace period), then as long | ||
| 104 | * as that task remains queued, the current grace period | ||
| 105 | * cannot end. | ||
| 106 | */ | ||
| 107 | phase = !(rnp->qsmask & rdp->grpmask) ^ (rnp->gpnum & 0x1); | ||
| 108 | list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]); | ||
| 109 | smp_mb(); /* Ensure later ctxt swtch seen after above. */ | ||
| 110 | spin_unlock(&rnp->lock); | ||
| 111 | } | ||
| 112 | |||
| 113 | /* | ||
| 114 | * Either we were not in an RCU read-side critical section to | ||
| 115 | * begin with, or we have now recorded that critical section | ||
| 116 | * globally. Either way, we can now note a quiescent state | ||
| 117 | * for this CPU. Again, if we were in an RCU read-side critical | ||
| 118 | * section, and if that critical section was blocking the current | ||
| 119 | * grace period, then the fact that the task has been enqueued | ||
| 120 | * means that we continue to block the current grace period. | ||
| 121 | */ | ||
| 122 | rcu_preempt_qs_record(cpu); | ||
| 123 | t->rcu_read_unlock_special &= ~(RCU_READ_UNLOCK_NEED_QS | | ||
| 124 | RCU_READ_UNLOCK_GOT_QS); | ||
| 125 | } | ||
| 126 | |||
| 127 | /* | ||
| 128 | * Tree-preemptable RCU implementation for rcu_read_lock(). | ||
| 129 | * Just increment ->rcu_read_lock_nesting, shared state will be updated | ||
| 130 | * if we block. | ||
| 131 | */ | ||
| 132 | void __rcu_read_lock(void) | ||
| 133 | { | ||
| 134 | ACCESS_ONCE(current->rcu_read_lock_nesting)++; | ||
| 135 | barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */ | ||
| 136 | } | ||
| 137 | EXPORT_SYMBOL_GPL(__rcu_read_lock); | ||
| 138 | |||
| 139 | static void rcu_read_unlock_special(struct task_struct *t) | ||
| 140 | { | ||
| 141 | int empty; | ||
| 142 | unsigned long flags; | ||
| 143 | unsigned long mask; | ||
| 144 | struct rcu_node *rnp; | ||
| 145 | int special; | ||
| 146 | |||
| 147 | /* NMI handlers cannot block and cannot safely manipulate state. */ | ||
| 148 | if (in_nmi()) | ||
| 149 | return; | ||
| 150 | |||
| 151 | local_irq_save(flags); | ||
| 152 | |||
| 153 | /* | ||
| 154 | * If RCU core is waiting for this CPU to exit critical section, | ||
| 155 | * let it know that we have done so. | ||
| 156 | */ | ||
| 157 | special = t->rcu_read_unlock_special; | ||
| 158 | if (special & RCU_READ_UNLOCK_NEED_QS) { | ||
| 159 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; | ||
| 160 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_GOT_QS; | ||
| 161 | } | ||
| 162 | |||
| 163 | /* Hardware IRQ handlers cannot block. */ | ||
| 164 | if (in_irq()) { | ||
| 165 | local_irq_restore(flags); | ||
| 166 | return; | ||
| 167 | } | ||
| 168 | |||
| 169 | /* Clean up if blocked during RCU read-side critical section. */ | ||
| 170 | if (special & RCU_READ_UNLOCK_BLOCKED) { | ||
| 171 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED; | ||
| 172 | |||
| 173 | /* | ||
| 174 | * Remove this task from the list it blocked on. The | ||
| 175 | * task can migrate while we acquire the lock, but at | ||
| 176 | * most one time. So at most two passes through loop. | ||
| 177 | */ | ||
| 178 | for (;;) { | ||
| 179 | rnp = t->rcu_blocked_node; | ||
| 180 | spin_lock(&rnp->lock); | ||
| 181 | if (rnp == t->rcu_blocked_node) | ||
| 182 | break; | ||
| 183 | spin_unlock(&rnp->lock); | ||
| 184 | } | ||
| 185 | empty = list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]); | ||
| 186 | list_del_init(&t->rcu_node_entry); | ||
| 187 | t->rcu_blocked_node = NULL; | ||
| 188 | |||
| 189 | /* | ||
| 190 | * If this was the last task on the current list, and if | ||
| 191 | * we aren't waiting on any CPUs, report the quiescent state. | ||
| 192 | * Note that both cpu_quiet_msk_finish() and cpu_quiet_msk() | ||
| 193 | * drop rnp->lock and restore irq. | ||
| 194 | */ | ||
| 195 | if (!empty && rnp->qsmask == 0 && | ||
| 196 | list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1])) { | ||
| 197 | t->rcu_read_unlock_special &= | ||
| 198 | ~(RCU_READ_UNLOCK_NEED_QS | | ||
| 199 | RCU_READ_UNLOCK_GOT_QS); | ||
| 200 | if (rnp->parent == NULL) { | ||
| 201 | /* Only one rcu_node in the tree. */ | ||
| 202 | cpu_quiet_msk_finish(&rcu_preempt_state, flags); | ||
| 203 | return; | ||
| 204 | } | ||
| 205 | /* Report up the rest of the hierarchy. */ | ||
| 206 | mask = rnp->grpmask; | ||
| 207 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 208 | rnp = rnp->parent; | ||
| 209 | spin_lock_irqsave(&rnp->lock, flags); | ||
| 210 | cpu_quiet_msk(mask, &rcu_preempt_state, rnp, flags); | ||
| 211 | return; | ||
| 212 | } | ||
| 213 | spin_unlock(&rnp->lock); | ||
| 214 | } | ||
| 215 | local_irq_restore(flags); | ||
| 216 | } | ||
| 217 | |||
| 218 | /* | ||
| 219 | * Tree-preemptable RCU implementation for rcu_read_unlock(). | ||
| 220 | * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost | ||
| 221 | * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then | ||
| 222 | * invoke rcu_read_unlock_special() to clean up after a context switch | ||
| 223 | * in an RCU read-side critical section and other special cases. | ||
| 224 | */ | ||
| 225 | void __rcu_read_unlock(void) | ||
| 226 | { | ||
| 227 | struct task_struct *t = current; | ||
| 228 | |||
| 229 | barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */ | ||
| 230 | if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 && | ||
| 231 | unlikely(ACCESS_ONCE(t->rcu_read_unlock_special))) | ||
| 232 | rcu_read_unlock_special(t); | ||
| 233 | } | ||
| 234 | EXPORT_SYMBOL_GPL(__rcu_read_unlock); | ||
| 235 | |||
| 236 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 237 | |||
| 238 | /* | ||
| 239 | * Scan the current list of tasks blocked within RCU read-side critical | ||
| 240 | * sections, printing out the tid of each. | ||
| 241 | */ | ||
| 242 | static void rcu_print_task_stall(struct rcu_node *rnp) | ||
| 243 | { | ||
| 244 | unsigned long flags; | ||
| 245 | struct list_head *lp; | ||
| 246 | int phase = rnp->gpnum & 0x1; | ||
| 247 | struct task_struct *t; | ||
| 248 | |||
| 249 | if (!list_empty(&rnp->blocked_tasks[phase])) { | ||
| 250 | spin_lock_irqsave(&rnp->lock, flags); | ||
| 251 | phase = rnp->gpnum & 0x1; /* re-read under lock. */ | ||
| 252 | lp = &rnp->blocked_tasks[phase]; | ||
| 253 | list_for_each_entry(t, lp, rcu_node_entry) | ||
| 254 | printk(" P%d", t->pid); | ||
| 255 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 260 | |||
| 261 | /* | ||
| 262 | * Check for preempted RCU readers for the specified rcu_node structure. | ||
| 263 | * If the caller needs a reliable answer, it must hold the rcu_node's | ||
| 264 | * >lock. | ||
| 265 | */ | ||
| 266 | static int rcu_preempted_readers(struct rcu_node *rnp) | ||
| 267 | { | ||
| 268 | return !list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]); | ||
| 269 | } | ||
| 270 | |||
| 271 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 272 | |||
| 273 | /* | ||
| 274 | * Handle tasklist migration for case in which all CPUs covered by the | ||
| 275 | * specified rcu_node have gone offline. Move them up to the root | ||
| 276 | * rcu_node. The reason for not just moving them to the immediate | ||
| 277 | * parent is to remove the need for rcu_read_unlock_special() to | ||
| 278 | * make more than two attempts to acquire the target rcu_node's lock. | ||
| 279 | * | ||
| 280 | * The caller must hold rnp->lock with irqs disabled. | ||
| 281 | */ | ||
| 282 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, | ||
| 283 | struct rcu_node *rnp) | ||
| 284 | { | ||
| 285 | int i; | ||
| 286 | struct list_head *lp; | ||
| 287 | struct list_head *lp_root; | ||
| 288 | struct rcu_node *rnp_root = rcu_get_root(rsp); | ||
| 289 | struct task_struct *tp; | ||
| 290 | |||
| 291 | if (rnp == rnp_root) { | ||
| 292 | WARN_ONCE(1, "Last CPU thought to be offlined?"); | ||
| 293 | return; /* Shouldn't happen: at least one CPU online. */ | ||
| 294 | } | ||
| 295 | |||
| 296 | /* | ||
| 297 | * Move tasks up to root rcu_node. Rely on the fact that the | ||
| 298 | * root rcu_node can be at most one ahead of the rest of the | ||
| 299 | * rcu_nodes in terms of gp_num value. This fact allows us to | ||
| 300 | * move the blocked_tasks[] array directly, element by element. | ||
| 301 | */ | ||
| 302 | for (i = 0; i < 2; i++) { | ||
| 303 | lp = &rnp->blocked_tasks[i]; | ||
| 304 | lp_root = &rnp_root->blocked_tasks[i]; | ||
| 305 | while (!list_empty(lp)) { | ||
| 306 | tp = list_entry(lp->next, typeof(*tp), rcu_node_entry); | ||
| 307 | spin_lock(&rnp_root->lock); /* irqs already disabled */ | ||
| 308 | list_del(&tp->rcu_node_entry); | ||
| 309 | tp->rcu_blocked_node = rnp_root; | ||
| 310 | list_add(&tp->rcu_node_entry, lp_root); | ||
| 311 | spin_unlock(&rnp_root->lock); /* irqs remain disabled */ | ||
| 312 | } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | /* | ||
| 317 | * Do CPU-offline processing for preemptable RCU. | ||
| 318 | */ | ||
| 319 | static void rcu_preempt_offline_cpu(int cpu) | ||
| 320 | { | ||
| 321 | __rcu_offline_cpu(cpu, &rcu_preempt_state); | ||
| 322 | } | ||
| 323 | |||
| 324 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 325 | |||
| 326 | /* | ||
| 327 | * Check for a quiescent state from the current CPU. When a task blocks, | ||
| 328 | * the task is recorded in the corresponding CPU's rcu_node structure, | ||
| 329 | * which is checked elsewhere. | ||
| 330 | * | ||
| 331 | * Caller must disable hard irqs. | ||
| 332 | */ | ||
| 333 | static void rcu_preempt_check_callbacks(int cpu) | ||
| 334 | { | ||
| 335 | struct task_struct *t = current; | ||
| 336 | |||
| 337 | if (t->rcu_read_lock_nesting == 0) { | ||
| 338 | t->rcu_read_unlock_special &= | ||
| 339 | ~(RCU_READ_UNLOCK_NEED_QS | RCU_READ_UNLOCK_GOT_QS); | ||
| 340 | rcu_preempt_qs_record(cpu); | ||
| 341 | return; | ||
| 342 | } | ||
| 343 | if (per_cpu(rcu_preempt_data, cpu).qs_pending) { | ||
| 344 | if (t->rcu_read_unlock_special & RCU_READ_UNLOCK_GOT_QS) { | ||
| 345 | rcu_preempt_qs_record(cpu); | ||
| 346 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_GOT_QS; | ||
| 347 | } else if (!(t->rcu_read_unlock_special & | ||
| 348 | RCU_READ_UNLOCK_NEED_QS)) { | ||
| 349 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS; | ||
| 350 | } | ||
| 351 | } | ||
| 352 | } | ||
| 353 | |||
| 354 | /* | ||
| 355 | * Process callbacks for preemptable RCU. | ||
| 356 | */ | ||
| 357 | static void rcu_preempt_process_callbacks(void) | ||
| 358 | { | ||
| 359 | __rcu_process_callbacks(&rcu_preempt_state, | ||
| 360 | &__get_cpu_var(rcu_preempt_data)); | ||
| 361 | } | ||
| 362 | |||
| 363 | /* | ||
| 364 | * Queue a preemptable-RCU callback for invocation after a grace period. | ||
| 365 | */ | ||
| 366 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 367 | { | ||
| 368 | __call_rcu(head, func, &rcu_preempt_state); | ||
| 369 | } | ||
| 370 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 371 | |||
| 372 | /* | ||
| 373 | * Check to see if there is any immediate preemptable-RCU-related work | ||
| 374 | * to be done. | ||
| 375 | */ | ||
| 376 | static int rcu_preempt_pending(int cpu) | ||
| 377 | { | ||
| 378 | return __rcu_pending(&rcu_preempt_state, | ||
| 379 | &per_cpu(rcu_preempt_data, cpu)); | ||
| 380 | } | ||
| 381 | |||
| 382 | /* | ||
| 383 | * Does preemptable RCU need the CPU to stay out of dynticks mode? | ||
| 384 | */ | ||
| 385 | static int rcu_preempt_needs_cpu(int cpu) | ||
| 386 | { | ||
| 387 | return !!per_cpu(rcu_preempt_data, cpu).nxtlist; | ||
| 388 | } | ||
| 389 | |||
| 390 | /* | ||
| 391 | * Initialize preemptable RCU's per-CPU data. | ||
| 392 | */ | ||
| 393 | static void __cpuinit rcu_preempt_init_percpu_data(int cpu) | ||
| 394 | { | ||
| 395 | rcu_init_percpu_data(cpu, &rcu_preempt_state, 1); | ||
| 396 | } | ||
| 397 | |||
| 398 | /* | ||
| 399 | * Check for a task exiting while in a preemptable-RCU read-side | ||
| 400 | * critical section, clean up if so. No need to issue warnings, | ||
| 401 | * as debug_check_no_locks_held() already does this if lockdep | ||
| 402 | * is enabled. | ||
| 403 | */ | ||
| 404 | void exit_rcu(void) | ||
| 405 | { | ||
| 406 | struct task_struct *t = current; | ||
| 407 | |||
| 408 | if (t->rcu_read_lock_nesting == 0) | ||
| 409 | return; | ||
| 410 | t->rcu_read_lock_nesting = 1; | ||
| 411 | rcu_read_unlock(); | ||
| 412 | } | ||
| 413 | |||
| 414 | #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 415 | |||
| 416 | /* | ||
| 417 | * Tell them what RCU they are running. | ||
| 418 | */ | ||
| 419 | static inline void rcu_bootup_announce(void) | ||
| 420 | { | ||
| 421 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); | ||
| 422 | } | ||
| 423 | |||
| 424 | /* | ||
| 425 | * Return the number of RCU batches processed thus far for debug & stats. | ||
| 426 | */ | ||
| 427 | long rcu_batches_completed(void) | ||
| 428 | { | ||
| 429 | return rcu_batches_completed_sched(); | ||
| 430 | } | ||
| 431 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 432 | |||
| 433 | /* | ||
| 434 | * Because preemptable RCU does not exist, we never have to check for | ||
| 435 | * CPUs being in quiescent states. | ||
| 436 | */ | ||
| 437 | static void rcu_preempt_qs(int cpu) | ||
| 438 | { | ||
| 439 | } | ||
| 440 | |||
| 441 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 442 | |||
| 443 | /* | ||
| 444 | * Because preemptable RCU does not exist, we never have to check for | ||
| 445 | * tasks blocked within RCU read-side critical sections. | ||
| 446 | */ | ||
| 447 | static void rcu_print_task_stall(struct rcu_node *rnp) | ||
| 448 | { | ||
| 449 | } | ||
| 450 | |||
| 451 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 452 | |||
| 453 | /* | ||
| 454 | * Because preemptable RCU does not exist, there are never any preempted | ||
| 455 | * RCU readers. | ||
| 456 | */ | ||
| 457 | static int rcu_preempted_readers(struct rcu_node *rnp) | ||
| 458 | { | ||
| 459 | return 0; | ||
| 460 | } | ||
| 461 | |||
| 462 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 463 | |||
| 464 | /* | ||
| 465 | * Because preemptable RCU does not exist, it never needs to migrate | ||
| 466 | * tasks that were blocked within RCU read-side critical sections. | ||
| 467 | */ | ||
| 468 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, | ||
| 469 | struct rcu_node *rnp) | ||
| 470 | { | ||
| 471 | } | ||
| 472 | |||
| 473 | /* | ||
| 474 | * Because preemptable RCU does not exist, it never needs CPU-offline | ||
| 475 | * processing. | ||
| 476 | */ | ||
| 477 | static void rcu_preempt_offline_cpu(int cpu) | ||
| 478 | { | ||
| 479 | } | ||
| 480 | |||
| 481 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 482 | |||
| 483 | /* | ||
| 484 | * Because preemptable RCU does not exist, it never has any callbacks | ||
| 485 | * to check. | ||
| 486 | */ | ||
| 487 | void rcu_preempt_check_callbacks(int cpu) | ||
| 488 | { | ||
| 489 | } | ||
| 490 | |||
| 491 | /* | ||
| 492 | * Because preemptable RCU does not exist, it never has any callbacks | ||
| 493 | * to process. | ||
| 494 | */ | ||
| 495 | void rcu_preempt_process_callbacks(void) | ||
| 496 | { | ||
| 497 | } | ||
| 498 | |||
| 499 | /* | ||
| 500 | * In classic RCU, call_rcu() is just call_rcu_sched(). | ||
| 501 | */ | ||
| 502 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 503 | { | ||
| 504 | call_rcu_sched(head, func); | ||
| 505 | } | ||
| 506 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 507 | |||
| 508 | /* | ||
| 509 | * Because preemptable RCU does not exist, it never has any work to do. | ||
| 510 | */ | ||
| 511 | static int rcu_preempt_pending(int cpu) | ||
| 512 | { | ||
| 513 | return 0; | ||
| 514 | } | ||
| 515 | |||
| 516 | /* | ||
| 517 | * Because preemptable RCU does not exist, it never needs any CPU. | ||
| 518 | */ | ||
| 519 | static int rcu_preempt_needs_cpu(int cpu) | ||
| 520 | { | ||
| 521 | return 0; | ||
| 522 | } | ||
| 523 | |||
| 524 | /* | ||
| 525 | * Because preemptable RCU does not exist, there is no per-CPU | ||
| 526 | * data to initialize. | ||
| 527 | */ | ||
| 528 | static void __cpuinit rcu_preempt_init_percpu_data(int cpu) | ||
| 529 | { | ||
| 530 | } | ||
| 531 | |||
| 532 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c index fe1dcdbf1ca3..0ea1bff69727 100644 --- a/kernel/rcutree_trace.c +++ b/kernel/rcutree_trace.c | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #include <linux/debugfs.h> | 43 | #include <linux/debugfs.h> |
| 44 | #include <linux/seq_file.h> | 44 | #include <linux/seq_file.h> |
| 45 | 45 | ||
| 46 | #define RCU_TREE_NONCORE | ||
| 46 | #include "rcutree.h" | 47 | #include "rcutree.h" |
| 47 | 48 | ||
| 48 | static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) | 49 | static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) |
| @@ -76,8 +77,12 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) | |||
| 76 | 77 | ||
| 77 | static int show_rcudata(struct seq_file *m, void *unused) | 78 | static int show_rcudata(struct seq_file *m, void *unused) |
| 78 | { | 79 | { |
| 79 | seq_puts(m, "rcu:\n"); | 80 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 80 | PRINT_RCU_DATA(rcu_data, print_one_rcu_data, m); | 81 | seq_puts(m, "rcu_preempt:\n"); |
| 82 | PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data, m); | ||
| 83 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 84 | seq_puts(m, "rcu_sched:\n"); | ||
| 85 | PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data, m); | ||
| 81 | seq_puts(m, "rcu_bh:\n"); | 86 | seq_puts(m, "rcu_bh:\n"); |
| 82 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m); | 87 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m); |
| 83 | return 0; | 88 | return 0; |
| @@ -102,7 +107,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp) | |||
| 102 | return; | 107 | return; |
| 103 | seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d", | 108 | seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d", |
| 104 | rdp->cpu, | 109 | rdp->cpu, |
| 105 | cpu_is_offline(rdp->cpu) ? "\"Y\"" : "\"N\"", | 110 | cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"", |
| 106 | rdp->completed, rdp->gpnum, | 111 | rdp->completed, rdp->gpnum, |
| 107 | rdp->passed_quiesc, rdp->passed_quiesc_completed, | 112 | rdp->passed_quiesc, rdp->passed_quiesc_completed, |
| 108 | rdp->qs_pending); | 113 | rdp->qs_pending); |
| @@ -124,8 +129,12 @@ static int show_rcudata_csv(struct seq_file *m, void *unused) | |||
| 124 | seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\","); | 129 | seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\","); |
| 125 | #endif /* #ifdef CONFIG_NO_HZ */ | 130 | #endif /* #ifdef CONFIG_NO_HZ */ |
| 126 | seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\"\n"); | 131 | seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\"\n"); |
| 127 | seq_puts(m, "\"rcu:\"\n"); | 132 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 128 | PRINT_RCU_DATA(rcu_data, print_one_rcu_data_csv, m); | 133 | seq_puts(m, "\"rcu_preempt:\"\n"); |
| 134 | PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data_csv, m); | ||
| 135 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 136 | seq_puts(m, "\"rcu_sched:\"\n"); | ||
| 137 | PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data_csv, m); | ||
| 129 | seq_puts(m, "\"rcu_bh:\"\n"); | 138 | seq_puts(m, "\"rcu_bh:\"\n"); |
| 130 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m); | 139 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m); |
| 131 | return 0; | 140 | return 0; |
| @@ -171,8 +180,12 @@ static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp) | |||
| 171 | 180 | ||
| 172 | static int show_rcuhier(struct seq_file *m, void *unused) | 181 | static int show_rcuhier(struct seq_file *m, void *unused) |
| 173 | { | 182 | { |
| 174 | seq_puts(m, "rcu:\n"); | 183 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 175 | print_one_rcu_state(m, &rcu_state); | 184 | seq_puts(m, "rcu_preempt:\n"); |
| 185 | print_one_rcu_state(m, &rcu_preempt_state); | ||
| 186 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 187 | seq_puts(m, "rcu_sched:\n"); | ||
| 188 | print_one_rcu_state(m, &rcu_sched_state); | ||
| 176 | seq_puts(m, "rcu_bh:\n"); | 189 | seq_puts(m, "rcu_bh:\n"); |
| 177 | print_one_rcu_state(m, &rcu_bh_state); | 190 | print_one_rcu_state(m, &rcu_bh_state); |
| 178 | return 0; | 191 | return 0; |
| @@ -193,8 +206,12 @@ static struct file_operations rcuhier_fops = { | |||
| 193 | 206 | ||
| 194 | static int show_rcugp(struct seq_file *m, void *unused) | 207 | static int show_rcugp(struct seq_file *m, void *unused) |
| 195 | { | 208 | { |
| 196 | seq_printf(m, "rcu: completed=%ld gpnum=%ld\n", | 209 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 197 | rcu_state.completed, rcu_state.gpnum); | 210 | seq_printf(m, "rcu_preempt: completed=%ld gpnum=%ld\n", |
| 211 | rcu_preempt_state.completed, rcu_preempt_state.gpnum); | ||
| 212 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 213 | seq_printf(m, "rcu_sched: completed=%ld gpnum=%ld\n", | ||
| 214 | rcu_sched_state.completed, rcu_sched_state.gpnum); | ||
| 198 | seq_printf(m, "rcu_bh: completed=%ld gpnum=%ld\n", | 215 | seq_printf(m, "rcu_bh: completed=%ld gpnum=%ld\n", |
| 199 | rcu_bh_state.completed, rcu_bh_state.gpnum); | 216 | rcu_bh_state.completed, rcu_bh_state.gpnum); |
| 200 | return 0; | 217 | return 0; |
| @@ -243,8 +260,12 @@ static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp) | |||
| 243 | 260 | ||
| 244 | static int show_rcu_pending(struct seq_file *m, void *unused) | 261 | static int show_rcu_pending(struct seq_file *m, void *unused) |
| 245 | { | 262 | { |
| 246 | seq_puts(m, "rcu:\n"); | 263 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 247 | print_rcu_pendings(m, &rcu_state); | 264 | seq_puts(m, "rcu_preempt:\n"); |
| 265 | print_rcu_pendings(m, &rcu_preempt_state); | ||
| 266 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 267 | seq_puts(m, "rcu_sched:\n"); | ||
| 268 | print_rcu_pendings(m, &rcu_sched_state); | ||
| 248 | seq_puts(m, "rcu_bh:\n"); | 269 | seq_puts(m, "rcu_bh:\n"); |
| 249 | print_rcu_pendings(m, &rcu_bh_state); | 270 | print_rcu_pendings(m, &rcu_bh_state); |
| 250 | return 0; | 271 | return 0; |
| @@ -264,62 +285,47 @@ static struct file_operations rcu_pending_fops = { | |||
| 264 | }; | 285 | }; |
| 265 | 286 | ||
| 266 | static struct dentry *rcudir; | 287 | static struct dentry *rcudir; |
| 267 | static struct dentry *datadir; | ||
| 268 | static struct dentry *datadir_csv; | ||
| 269 | static struct dentry *gpdir; | ||
| 270 | static struct dentry *hierdir; | ||
| 271 | static struct dentry *rcu_pendingdir; | ||
| 272 | 288 | ||
| 273 | static int __init rcuclassic_trace_init(void) | 289 | static int __init rcuclassic_trace_init(void) |
| 274 | { | 290 | { |
| 291 | struct dentry *retval; | ||
| 292 | |||
| 275 | rcudir = debugfs_create_dir("rcu", NULL); | 293 | rcudir = debugfs_create_dir("rcu", NULL); |
| 276 | if (!rcudir) | 294 | if (!rcudir) |
| 277 | goto out; | 295 | goto free_out; |
| 278 | 296 | ||
| 279 | datadir = debugfs_create_file("rcudata", 0444, rcudir, | 297 | retval = debugfs_create_file("rcudata", 0444, rcudir, |
| 280 | NULL, &rcudata_fops); | 298 | NULL, &rcudata_fops); |
| 281 | if (!datadir) | 299 | if (!retval) |
| 282 | goto free_out; | 300 | goto free_out; |
| 283 | 301 | ||
| 284 | datadir_csv = debugfs_create_file("rcudata.csv", 0444, rcudir, | 302 | retval = debugfs_create_file("rcudata.csv", 0444, rcudir, |
| 285 | NULL, &rcudata_csv_fops); | 303 | NULL, &rcudata_csv_fops); |
| 286 | if (!datadir_csv) | 304 | if (!retval) |
| 287 | goto free_out; | 305 | goto free_out; |
| 288 | 306 | ||
| 289 | gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops); | 307 | retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops); |
| 290 | if (!gpdir) | 308 | if (!retval) |
| 291 | goto free_out; | 309 | goto free_out; |
| 292 | 310 | ||
| 293 | hierdir = debugfs_create_file("rcuhier", 0444, rcudir, | 311 | retval = debugfs_create_file("rcuhier", 0444, rcudir, |
| 294 | NULL, &rcuhier_fops); | 312 | NULL, &rcuhier_fops); |
| 295 | if (!hierdir) | 313 | if (!retval) |
| 296 | goto free_out; | 314 | goto free_out; |
| 297 | 315 | ||
| 298 | rcu_pendingdir = debugfs_create_file("rcu_pending", 0444, rcudir, | 316 | retval = debugfs_create_file("rcu_pending", 0444, rcudir, |
| 299 | NULL, &rcu_pending_fops); | 317 | NULL, &rcu_pending_fops); |
| 300 | if (!rcu_pendingdir) | 318 | if (!retval) |
| 301 | goto free_out; | 319 | goto free_out; |
| 302 | return 0; | 320 | return 0; |
| 303 | free_out: | 321 | free_out: |
| 304 | if (datadir) | 322 | debugfs_remove_recursive(rcudir); |
| 305 | debugfs_remove(datadir); | ||
| 306 | if (datadir_csv) | ||
| 307 | debugfs_remove(datadir_csv); | ||
| 308 | if (gpdir) | ||
| 309 | debugfs_remove(gpdir); | ||
| 310 | debugfs_remove(rcudir); | ||
| 311 | out: | ||
| 312 | return 1; | 323 | return 1; |
| 313 | } | 324 | } |
| 314 | 325 | ||
| 315 | static void __exit rcuclassic_trace_cleanup(void) | 326 | static void __exit rcuclassic_trace_cleanup(void) |
| 316 | { | 327 | { |
| 317 | debugfs_remove(datadir); | 328 | debugfs_remove_recursive(rcudir); |
| 318 | debugfs_remove(datadir_csv); | ||
| 319 | debugfs_remove(gpdir); | ||
| 320 | debugfs_remove(hierdir); | ||
| 321 | debugfs_remove(rcu_pendingdir); | ||
| 322 | debugfs_remove(rcudir); | ||
| 323 | } | 329 | } |
| 324 | 330 | ||
| 325 | 331 | ||
diff --git a/kernel/sched.c b/kernel/sched.c index 1b59e265273b..4066241ae9f4 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -5325,7 +5325,7 @@ need_resched: | |||
| 5325 | preempt_disable(); | 5325 | preempt_disable(); |
| 5326 | cpu = smp_processor_id(); | 5326 | cpu = smp_processor_id(); |
| 5327 | rq = cpu_rq(cpu); | 5327 | rq = cpu_rq(cpu); |
| 5328 | rcu_qsctr_inc(cpu); | 5328 | rcu_sched_qs(cpu); |
| 5329 | prev = rq->curr; | 5329 | prev = rq->curr; |
| 5330 | switch_count = &prev->nivcsw; | 5330 | switch_count = &prev->nivcsw; |
| 5331 | 5331 | ||
| @@ -6609,6 +6609,8 @@ int cond_resched_lock(spinlock_t *lock) | |||
| 6609 | int resched = should_resched(); | 6609 | int resched = should_resched(); |
| 6610 | int ret = 0; | 6610 | int ret = 0; |
| 6611 | 6611 | ||
| 6612 | lockdep_assert_held(lock); | ||
| 6613 | |||
| 6612 | if (spin_needbreak(lock) || resched) { | 6614 | if (spin_needbreak(lock) || resched) { |
| 6613 | spin_unlock(lock); | 6615 | spin_unlock(lock); |
| 6614 | if (resched) | 6616 | if (resched) |
| @@ -7051,6 +7053,11 @@ fail: | |||
| 7051 | return ret; | 7053 | return ret; |
| 7052 | } | 7054 | } |
| 7053 | 7055 | ||
| 7056 | #define RCU_MIGRATION_IDLE 0 | ||
| 7057 | #define RCU_MIGRATION_NEED_QS 1 | ||
| 7058 | #define RCU_MIGRATION_GOT_QS 2 | ||
| 7059 | #define RCU_MIGRATION_MUST_SYNC 3 | ||
| 7060 | |||
| 7054 | /* | 7061 | /* |
| 7055 | * migration_thread - this is a highprio system thread that performs | 7062 | * migration_thread - this is a highprio system thread that performs |
| 7056 | * thread migration by bumping thread off CPU then 'pushing' onto | 7063 | * thread migration by bumping thread off CPU then 'pushing' onto |
| @@ -7058,6 +7065,7 @@ fail: | |||
| 7058 | */ | 7065 | */ |
| 7059 | static int migration_thread(void *data) | 7066 | static int migration_thread(void *data) |
| 7060 | { | 7067 | { |
| 7068 | int badcpu; | ||
| 7061 | int cpu = (long)data; | 7069 | int cpu = (long)data; |
| 7062 | struct rq *rq; | 7070 | struct rq *rq; |
| 7063 | 7071 | ||
| @@ -7092,8 +7100,17 @@ static int migration_thread(void *data) | |||
| 7092 | req = list_entry(head->next, struct migration_req, list); | 7100 | req = list_entry(head->next, struct migration_req, list); |
| 7093 | list_del_init(head->next); | 7101 | list_del_init(head->next); |
| 7094 | 7102 | ||
| 7095 | spin_unlock(&rq->lock); | 7103 | if (req->task != NULL) { |
| 7096 | __migrate_task(req->task, cpu, req->dest_cpu); | 7104 | spin_unlock(&rq->lock); |
| 7105 | __migrate_task(req->task, cpu, req->dest_cpu); | ||
| 7106 | } else if (likely(cpu == (badcpu = smp_processor_id()))) { | ||
| 7107 | req->dest_cpu = RCU_MIGRATION_GOT_QS; | ||
| 7108 | spin_unlock(&rq->lock); | ||
| 7109 | } else { | ||
| 7110 | req->dest_cpu = RCU_MIGRATION_MUST_SYNC; | ||
| 7111 | spin_unlock(&rq->lock); | ||
| 7112 | WARN_ONCE(1, "migration_thread() on CPU %d, expected %d\n", badcpu, cpu); | ||
| 7113 | } | ||
| 7097 | local_irq_enable(); | 7114 | local_irq_enable(); |
| 7098 | 7115 | ||
| 7099 | complete(&req->done); | 7116 | complete(&req->done); |
| @@ -10581,3 +10598,113 @@ struct cgroup_subsys cpuacct_subsys = { | |||
| 10581 | .subsys_id = cpuacct_subsys_id, | 10598 | .subsys_id = cpuacct_subsys_id, |
| 10582 | }; | 10599 | }; |
| 10583 | #endif /* CONFIG_CGROUP_CPUACCT */ | 10600 | #endif /* CONFIG_CGROUP_CPUACCT */ |
| 10601 | |||
| 10602 | #ifndef CONFIG_SMP | ||
| 10603 | |||
| 10604 | int rcu_expedited_torture_stats(char *page) | ||
| 10605 | { | ||
| 10606 | return 0; | ||
| 10607 | } | ||
| 10608 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
| 10609 | |||
| 10610 | void synchronize_sched_expedited(void) | ||
| 10611 | { | ||
| 10612 | } | ||
| 10613 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | ||
| 10614 | |||
| 10615 | #else /* #ifndef CONFIG_SMP */ | ||
| 10616 | |||
| 10617 | static DEFINE_PER_CPU(struct migration_req, rcu_migration_req); | ||
| 10618 | static DEFINE_MUTEX(rcu_sched_expedited_mutex); | ||
| 10619 | |||
| 10620 | #define RCU_EXPEDITED_STATE_POST -2 | ||
| 10621 | #define RCU_EXPEDITED_STATE_IDLE -1 | ||
| 10622 | |||
| 10623 | static int rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | ||
| 10624 | |||
| 10625 | int rcu_expedited_torture_stats(char *page) | ||
| 10626 | { | ||
| 10627 | int cnt = 0; | ||
| 10628 | int cpu; | ||
| 10629 | |||
| 10630 | cnt += sprintf(&page[cnt], "state: %d /", rcu_expedited_state); | ||
| 10631 | for_each_online_cpu(cpu) { | ||
| 10632 | cnt += sprintf(&page[cnt], " %d:%d", | ||
| 10633 | cpu, per_cpu(rcu_migration_req, cpu).dest_cpu); | ||
| 10634 | } | ||
| 10635 | cnt += sprintf(&page[cnt], "\n"); | ||
| 10636 | return cnt; | ||
| 10637 | } | ||
| 10638 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
| 10639 | |||
| 10640 | static long synchronize_sched_expedited_count; | ||
| 10641 | |||
| 10642 | /* | ||
| 10643 | * Wait for an rcu-sched grace period to elapse, but use "big hammer" | ||
| 10644 | * approach to force grace period to end quickly. This consumes | ||
| 10645 | * significant time on all CPUs, and is thus not recommended for | ||
| 10646 | * any sort of common-case code. | ||
| 10647 | * | ||
| 10648 | * Note that it is illegal to call this function while holding any | ||
| 10649 | * lock that is acquired by a CPU-hotplug notifier. Failing to | ||
| 10650 | * observe this restriction will result in deadlock. | ||
| 10651 | */ | ||
| 10652 | void synchronize_sched_expedited(void) | ||
| 10653 | { | ||
| 10654 | int cpu; | ||
| 10655 | unsigned long flags; | ||
| 10656 | bool need_full_sync = 0; | ||
| 10657 | struct rq *rq; | ||
| 10658 | struct migration_req *req; | ||
| 10659 | long snap; | ||
| 10660 | int trycount = 0; | ||
| 10661 | |||
| 10662 | smp_mb(); /* ensure prior mod happens before capturing snap. */ | ||
| 10663 | snap = ACCESS_ONCE(synchronize_sched_expedited_count) + 1; | ||
| 10664 | get_online_cpus(); | ||
| 10665 | while (!mutex_trylock(&rcu_sched_expedited_mutex)) { | ||
| 10666 | put_online_cpus(); | ||
| 10667 | if (trycount++ < 10) | ||
| 10668 | udelay(trycount * num_online_cpus()); | ||
| 10669 | else { | ||
| 10670 | synchronize_sched(); | ||
| 10671 | return; | ||
| 10672 | } | ||
| 10673 | if (ACCESS_ONCE(synchronize_sched_expedited_count) - snap > 0) { | ||
| 10674 | smp_mb(); /* ensure test happens before caller kfree */ | ||
| 10675 | return; | ||
| 10676 | } | ||
| 10677 | get_online_cpus(); | ||
| 10678 | } | ||
| 10679 | rcu_expedited_state = RCU_EXPEDITED_STATE_POST; | ||
| 10680 | for_each_online_cpu(cpu) { | ||
| 10681 | rq = cpu_rq(cpu); | ||
| 10682 | req = &per_cpu(rcu_migration_req, cpu); | ||
| 10683 | init_completion(&req->done); | ||
| 10684 | req->task = NULL; | ||
| 10685 | req->dest_cpu = RCU_MIGRATION_NEED_QS; | ||
| 10686 | spin_lock_irqsave(&rq->lock, flags); | ||
| 10687 | list_add(&req->list, &rq->migration_queue); | ||
| 10688 | spin_unlock_irqrestore(&rq->lock, flags); | ||
| 10689 | wake_up_process(rq->migration_thread); | ||
| 10690 | } | ||
| 10691 | for_each_online_cpu(cpu) { | ||
| 10692 | rcu_expedited_state = cpu; | ||
| 10693 | req = &per_cpu(rcu_migration_req, cpu); | ||
| 10694 | rq = cpu_rq(cpu); | ||
| 10695 | wait_for_completion(&req->done); | ||
| 10696 | spin_lock_irqsave(&rq->lock, flags); | ||
| 10697 | if (unlikely(req->dest_cpu == RCU_MIGRATION_MUST_SYNC)) | ||
| 10698 | need_full_sync = 1; | ||
| 10699 | req->dest_cpu = RCU_MIGRATION_IDLE; | ||
| 10700 | spin_unlock_irqrestore(&rq->lock, flags); | ||
| 10701 | } | ||
| 10702 | rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | ||
| 10703 | mutex_unlock(&rcu_sched_expedited_mutex); | ||
| 10704 | put_online_cpus(); | ||
| 10705 | if (need_full_sync) | ||
| 10706 | synchronize_sched(); | ||
| 10707 | } | ||
| 10708 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | ||
| 10709 | |||
| 10710 | #endif /* #else #ifndef CONFIG_SMP */ | ||
diff --git a/kernel/softirq.c b/kernel/softirq.c index eb5e131a0485..7db25067cd2d 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c | |||
| @@ -227,7 +227,7 @@ restart: | |||
| 227 | preempt_count() = prev_count; | 227 | preempt_count() = prev_count; |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | rcu_bh_qsctr_inc(cpu); | 230 | rcu_bh_qs(cpu); |
| 231 | } | 231 | } |
| 232 | h++; | 232 | h++; |
| 233 | pending >>= 1; | 233 | pending >>= 1; |
| @@ -721,7 +721,7 @@ static int ksoftirqd(void * __bind_cpu) | |||
| 721 | preempt_enable_no_resched(); | 721 | preempt_enable_no_resched(); |
| 722 | cond_resched(); | 722 | cond_resched(); |
| 723 | preempt_disable(); | 723 | preempt_disable(); |
| 724 | rcu_qsctr_inc((long)__bind_cpu); | 724 | rcu_sched_qs((long)__bind_cpu); |
| 725 | } | 725 | } |
| 726 | preempt_enable(); | 726 | preempt_enable(); |
| 727 | set_current_state(TASK_INTERRUPTIBLE); | 727 | set_current_state(TASK_INTERRUPTIBLE); |
diff --git a/kernel/spinlock.c b/kernel/spinlock.c index 7932653c4ebd..5ddab730cb2f 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c | |||
| @@ -21,44 +21,29 @@ | |||
| 21 | #include <linux/debug_locks.h> | 21 | #include <linux/debug_locks.h> |
| 22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
| 23 | 23 | ||
| 24 | #ifndef _spin_trylock | ||
| 24 | int __lockfunc _spin_trylock(spinlock_t *lock) | 25 | int __lockfunc _spin_trylock(spinlock_t *lock) |
| 25 | { | 26 | { |
| 26 | preempt_disable(); | 27 | return __spin_trylock(lock); |
| 27 | if (_raw_spin_trylock(lock)) { | ||
| 28 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 29 | return 1; | ||
| 30 | } | ||
| 31 | |||
| 32 | preempt_enable(); | ||
| 33 | return 0; | ||
| 34 | } | 28 | } |
| 35 | EXPORT_SYMBOL(_spin_trylock); | 29 | EXPORT_SYMBOL(_spin_trylock); |
| 30 | #endif | ||
| 36 | 31 | ||
| 32 | #ifndef _read_trylock | ||
| 37 | int __lockfunc _read_trylock(rwlock_t *lock) | 33 | int __lockfunc _read_trylock(rwlock_t *lock) |
| 38 | { | 34 | { |
| 39 | preempt_disable(); | 35 | return __read_trylock(lock); |
| 40 | if (_raw_read_trylock(lock)) { | ||
| 41 | rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 42 | return 1; | ||
| 43 | } | ||
| 44 | |||
| 45 | preempt_enable(); | ||
| 46 | return 0; | ||
| 47 | } | 36 | } |
| 48 | EXPORT_SYMBOL(_read_trylock); | 37 | EXPORT_SYMBOL(_read_trylock); |
| 38 | #endif | ||
| 49 | 39 | ||
| 40 | #ifndef _write_trylock | ||
| 50 | int __lockfunc _write_trylock(rwlock_t *lock) | 41 | int __lockfunc _write_trylock(rwlock_t *lock) |
| 51 | { | 42 | { |
| 52 | preempt_disable(); | 43 | return __write_trylock(lock); |
| 53 | if (_raw_write_trylock(lock)) { | ||
| 54 | rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 55 | return 1; | ||
| 56 | } | ||
| 57 | |||
| 58 | preempt_enable(); | ||
| 59 | return 0; | ||
| 60 | } | 44 | } |
| 61 | EXPORT_SYMBOL(_write_trylock); | 45 | EXPORT_SYMBOL(_write_trylock); |
| 46 | #endif | ||
| 62 | 47 | ||
| 63 | /* | 48 | /* |
| 64 | * If lockdep is enabled then we use the non-preemption spin-ops | 49 | * If lockdep is enabled then we use the non-preemption spin-ops |
| @@ -67,132 +52,101 @@ EXPORT_SYMBOL(_write_trylock); | |||
| 67 | */ | 52 | */ |
| 68 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) | 53 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) |
| 69 | 54 | ||
| 55 | #ifndef _read_lock | ||
| 70 | void __lockfunc _read_lock(rwlock_t *lock) | 56 | void __lockfunc _read_lock(rwlock_t *lock) |
| 71 | { | 57 | { |
| 72 | preempt_disable(); | 58 | __read_lock(lock); |
| 73 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 74 | LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock); | ||
| 75 | } | 59 | } |
| 76 | EXPORT_SYMBOL(_read_lock); | 60 | EXPORT_SYMBOL(_read_lock); |
| 61 | #endif | ||
| 77 | 62 | ||
| 63 | #ifndef _spin_lock_irqsave | ||
| 78 | unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock) | 64 | unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock) |
| 79 | { | 65 | { |
| 80 | unsigned long flags; | 66 | return __spin_lock_irqsave(lock); |
| 81 | |||
| 82 | local_irq_save(flags); | ||
| 83 | preempt_disable(); | ||
| 84 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 85 | /* | ||
| 86 | * On lockdep we dont want the hand-coded irq-enable of | ||
| 87 | * _raw_spin_lock_flags() code, because lockdep assumes | ||
| 88 | * that interrupts are not re-enabled during lock-acquire: | ||
| 89 | */ | ||
| 90 | #ifdef CONFIG_LOCKDEP | ||
| 91 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 92 | #else | ||
| 93 | _raw_spin_lock_flags(lock, &flags); | ||
| 94 | #endif | ||
| 95 | return flags; | ||
| 96 | } | 67 | } |
| 97 | EXPORT_SYMBOL(_spin_lock_irqsave); | 68 | EXPORT_SYMBOL(_spin_lock_irqsave); |
| 69 | #endif | ||
| 98 | 70 | ||
| 71 | #ifndef _spin_lock_irq | ||
| 99 | void __lockfunc _spin_lock_irq(spinlock_t *lock) | 72 | void __lockfunc _spin_lock_irq(spinlock_t *lock) |
| 100 | { | 73 | { |
| 101 | local_irq_disable(); | 74 | __spin_lock_irq(lock); |
| 102 | preempt_disable(); | ||
| 103 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 104 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 105 | } | 75 | } |
| 106 | EXPORT_SYMBOL(_spin_lock_irq); | 76 | EXPORT_SYMBOL(_spin_lock_irq); |
| 77 | #endif | ||
| 107 | 78 | ||
| 79 | #ifndef _spin_lock_bh | ||
| 108 | void __lockfunc _spin_lock_bh(spinlock_t *lock) | 80 | void __lockfunc _spin_lock_bh(spinlock_t *lock) |
| 109 | { | 81 | { |
| 110 | local_bh_disable(); | 82 | __spin_lock_bh(lock); |
| 111 | preempt_disable(); | ||
| 112 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 113 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 114 | } | 83 | } |
| 115 | EXPORT_SYMBOL(_spin_lock_bh); | 84 | EXPORT_SYMBOL(_spin_lock_bh); |
| 85 | #endif | ||
| 116 | 86 | ||
| 87 | #ifndef _read_lock_irqsave | ||
| 117 | unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock) | 88 | unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock) |
| 118 | { | 89 | { |
| 119 | unsigned long flags; | 90 | return __read_lock_irqsave(lock); |
| 120 | |||
| 121 | local_irq_save(flags); | ||
| 122 | preempt_disable(); | ||
| 123 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 124 | LOCK_CONTENDED_FLAGS(lock, _raw_read_trylock, _raw_read_lock, | ||
| 125 | _raw_read_lock_flags, &flags); | ||
| 126 | return flags; | ||
| 127 | } | 91 | } |
| 128 | EXPORT_SYMBOL(_read_lock_irqsave); | 92 | EXPORT_SYMBOL(_read_lock_irqsave); |
| 93 | #endif | ||
| 129 | 94 | ||
| 95 | #ifndef _read_lock_irq | ||
| 130 | void __lockfunc _read_lock_irq(rwlock_t *lock) | 96 | void __lockfunc _read_lock_irq(rwlock_t *lock) |
| 131 | { | 97 | { |
| 132 | local_irq_disable(); | 98 | __read_lock_irq(lock); |
| 133 | preempt_disable(); | ||
| 134 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 135 | LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock); | ||
| 136 | } | 99 | } |
| 137 | EXPORT_SYMBOL(_read_lock_irq); | 100 | EXPORT_SYMBOL(_read_lock_irq); |
| 101 | #endif | ||
| 138 | 102 | ||
| 103 | #ifndef _read_lock_bh | ||
| 139 | void __lockfunc _read_lock_bh(rwlock_t *lock) | 104 | void __lockfunc _read_lock_bh(rwlock_t *lock) |
| 140 | { | 105 | { |
| 141 | local_bh_disable(); | 106 | __read_lock_bh(lock); |
| 142 | preempt_disable(); | ||
| 143 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 144 | LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock); | ||
| 145 | } | 107 | } |
| 146 | EXPORT_SYMBOL(_read_lock_bh); | 108 | EXPORT_SYMBOL(_read_lock_bh); |
| 109 | #endif | ||
| 147 | 110 | ||
| 111 | #ifndef _write_lock_irqsave | ||
| 148 | unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock) | 112 | unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock) |
| 149 | { | 113 | { |
| 150 | unsigned long flags; | 114 | return __write_lock_irqsave(lock); |
| 151 | |||
| 152 | local_irq_save(flags); | ||
| 153 | preempt_disable(); | ||
| 154 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 155 | LOCK_CONTENDED_FLAGS(lock, _raw_write_trylock, _raw_write_lock, | ||
| 156 | _raw_write_lock_flags, &flags); | ||
| 157 | return flags; | ||
| 158 | } | 115 | } |
| 159 | EXPORT_SYMBOL(_write_lock_irqsave); | 116 | EXPORT_SYMBOL(_write_lock_irqsave); |
| 117 | #endif | ||
| 160 | 118 | ||
| 119 | #ifndef _write_lock_irq | ||
| 161 | void __lockfunc _write_lock_irq(rwlock_t *lock) | 120 | void __lockfunc _write_lock_irq(rwlock_t *lock) |
| 162 | { | 121 | { |
| 163 | local_irq_disable(); | 122 | __write_lock_irq(lock); |
| 164 | preempt_disable(); | ||
| 165 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 166 | LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock); | ||
| 167 | } | 123 | } |
| 168 | EXPORT_SYMBOL(_write_lock_irq); | 124 | EXPORT_SYMBOL(_write_lock_irq); |
| 125 | #endif | ||
| 169 | 126 | ||
| 127 | #ifndef _write_lock_bh | ||
| 170 | void __lockfunc _write_lock_bh(rwlock_t *lock) | 128 | void __lockfunc _write_lock_bh(rwlock_t *lock) |
| 171 | { | 129 | { |
| 172 | local_bh_disable(); | 130 | __write_lock_bh(lock); |
| 173 | preempt_disable(); | ||
| 174 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 175 | LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock); | ||
| 176 | } | 131 | } |
| 177 | EXPORT_SYMBOL(_write_lock_bh); | 132 | EXPORT_SYMBOL(_write_lock_bh); |
| 133 | #endif | ||
| 178 | 134 | ||
| 135 | #ifndef _spin_lock | ||
| 179 | void __lockfunc _spin_lock(spinlock_t *lock) | 136 | void __lockfunc _spin_lock(spinlock_t *lock) |
| 180 | { | 137 | { |
| 181 | preempt_disable(); | 138 | __spin_lock(lock); |
| 182 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 183 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 184 | } | 139 | } |
| 185 | |||
| 186 | EXPORT_SYMBOL(_spin_lock); | 140 | EXPORT_SYMBOL(_spin_lock); |
| 141 | #endif | ||
| 187 | 142 | ||
| 143 | #ifndef _write_lock | ||
| 188 | void __lockfunc _write_lock(rwlock_t *lock) | 144 | void __lockfunc _write_lock(rwlock_t *lock) |
| 189 | { | 145 | { |
| 190 | preempt_disable(); | 146 | __write_lock(lock); |
| 191 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 192 | LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock); | ||
| 193 | } | 147 | } |
| 194 | |||
| 195 | EXPORT_SYMBOL(_write_lock); | 148 | EXPORT_SYMBOL(_write_lock); |
| 149 | #endif | ||
| 196 | 150 | ||
| 197 | #else /* CONFIG_PREEMPT: */ | 151 | #else /* CONFIG_PREEMPT: */ |
| 198 | 152 | ||
| @@ -318,125 +272,109 @@ EXPORT_SYMBOL(_spin_lock_nest_lock); | |||
| 318 | 272 | ||
| 319 | #endif | 273 | #endif |
| 320 | 274 | ||
| 275 | #ifndef _spin_unlock | ||
| 321 | void __lockfunc _spin_unlock(spinlock_t *lock) | 276 | void __lockfunc _spin_unlock(spinlock_t *lock) |
| 322 | { | 277 | { |
| 323 | spin_release(&lock->dep_map, 1, _RET_IP_); | 278 | __spin_unlock(lock); |
| 324 | _raw_spin_unlock(lock); | ||
| 325 | preempt_enable(); | ||
| 326 | } | 279 | } |
| 327 | EXPORT_SYMBOL(_spin_unlock); | 280 | EXPORT_SYMBOL(_spin_unlock); |
| 281 | #endif | ||
| 328 | 282 | ||
| 283 | #ifndef _write_unlock | ||
| 329 | void __lockfunc _write_unlock(rwlock_t *lock) | 284 | void __lockfunc _write_unlock(rwlock_t *lock) |
| 330 | { | 285 | { |
| 331 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 286 | __write_unlock(lock); |
| 332 | _raw_write_unlock(lock); | ||
| 333 | preempt_enable(); | ||
| 334 | } | 287 | } |
| 335 | EXPORT_SYMBOL(_write_unlock); | 288 | EXPORT_SYMBOL(_write_unlock); |
| 289 | #endif | ||
| 336 | 290 | ||
| 291 | #ifndef _read_unlock | ||
| 337 | void __lockfunc _read_unlock(rwlock_t *lock) | 292 | void __lockfunc _read_unlock(rwlock_t *lock) |
| 338 | { | 293 | { |
| 339 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 294 | __read_unlock(lock); |
| 340 | _raw_read_unlock(lock); | ||
| 341 | preempt_enable(); | ||
| 342 | } | 295 | } |
| 343 | EXPORT_SYMBOL(_read_unlock); | 296 | EXPORT_SYMBOL(_read_unlock); |
| 297 | #endif | ||
| 344 | 298 | ||
| 299 | #ifndef _spin_unlock_irqrestore | ||
| 345 | void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) | 300 | void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) |
| 346 | { | 301 | { |
| 347 | spin_release(&lock->dep_map, 1, _RET_IP_); | 302 | __spin_unlock_irqrestore(lock, flags); |
| 348 | _raw_spin_unlock(lock); | ||
| 349 | local_irq_restore(flags); | ||
| 350 | preempt_enable(); | ||
| 351 | } | 303 | } |
| 352 | EXPORT_SYMBOL(_spin_unlock_irqrestore); | 304 | EXPORT_SYMBOL(_spin_unlock_irqrestore); |
| 305 | #endif | ||
| 353 | 306 | ||
| 307 | #ifndef _spin_unlock_irq | ||
| 354 | void __lockfunc _spin_unlock_irq(spinlock_t *lock) | 308 | void __lockfunc _spin_unlock_irq(spinlock_t *lock) |
| 355 | { | 309 | { |
| 356 | spin_release(&lock->dep_map, 1, _RET_IP_); | 310 | __spin_unlock_irq(lock); |
| 357 | _raw_spin_unlock(lock); | ||
| 358 | local_irq_enable(); | ||
| 359 | preempt_enable(); | ||
| 360 | } | 311 | } |
| 361 | EXPORT_SYMBOL(_spin_unlock_irq); | 312 | EXPORT_SYMBOL(_spin_unlock_irq); |
| 313 | #endif | ||
| 362 | 314 | ||
| 315 | #ifndef _spin_unlock_bh | ||
| 363 | void __lockfunc _spin_unlock_bh(spinlock_t *lock) | 316 | void __lockfunc _spin_unlock_bh(spinlock_t *lock) |
| 364 | { | 317 | { |
| 365 | spin_release(&lock->dep_map, 1, _RET_IP_); | 318 | __spin_unlock_bh(lock); |
| 366 | _raw_spin_unlock(lock); | ||
| 367 | preempt_enable_no_resched(); | ||
| 368 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 369 | } | 319 | } |
| 370 | EXPORT_SYMBOL(_spin_unlock_bh); | 320 | EXPORT_SYMBOL(_spin_unlock_bh); |
| 321 | #endif | ||
| 371 | 322 | ||
| 323 | #ifndef _read_unlock_irqrestore | ||
| 372 | void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) | 324 | void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
| 373 | { | 325 | { |
| 374 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 326 | __read_unlock_irqrestore(lock, flags); |
| 375 | _raw_read_unlock(lock); | ||
| 376 | local_irq_restore(flags); | ||
| 377 | preempt_enable(); | ||
| 378 | } | 327 | } |
| 379 | EXPORT_SYMBOL(_read_unlock_irqrestore); | 328 | EXPORT_SYMBOL(_read_unlock_irqrestore); |
| 329 | #endif | ||
| 380 | 330 | ||
| 331 | #ifndef _read_unlock_irq | ||
| 381 | void __lockfunc _read_unlock_irq(rwlock_t *lock) | 332 | void __lockfunc _read_unlock_irq(rwlock_t *lock) |
| 382 | { | 333 | { |
| 383 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 334 | __read_unlock_irq(lock); |
| 384 | _raw_read_unlock(lock); | ||
| 385 | local_irq_enable(); | ||
| 386 | preempt_enable(); | ||
| 387 | } | 335 | } |
| 388 | EXPORT_SYMBOL(_read_unlock_irq); | 336 | EXPORT_SYMBOL(_read_unlock_irq); |
| 337 | #endif | ||
| 389 | 338 | ||
| 339 | #ifndef _read_unlock_bh | ||
| 390 | void __lockfunc _read_unlock_bh(rwlock_t *lock) | 340 | void __lockfunc _read_unlock_bh(rwlock_t *lock) |
| 391 | { | 341 | { |
| 392 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 342 | __read_unlock_bh(lock); |
| 393 | _raw_read_unlock(lock); | ||
| 394 | preempt_enable_no_resched(); | ||
| 395 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 396 | } | 343 | } |
| 397 | EXPORT_SYMBOL(_read_unlock_bh); | 344 | EXPORT_SYMBOL(_read_unlock_bh); |
| 345 | #endif | ||
| 398 | 346 | ||
| 347 | #ifndef _write_unlock_irqrestore | ||
| 399 | void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) | 348 | void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
| 400 | { | 349 | { |
| 401 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 350 | __write_unlock_irqrestore(lock, flags); |
| 402 | _raw_write_unlock(lock); | ||
| 403 | local_irq_restore(flags); | ||
| 404 | preempt_enable(); | ||
| 405 | } | 351 | } |
| 406 | EXPORT_SYMBOL(_write_unlock_irqrestore); | 352 | EXPORT_SYMBOL(_write_unlock_irqrestore); |
| 353 | #endif | ||
| 407 | 354 | ||
| 355 | #ifndef _write_unlock_irq | ||
| 408 | void __lockfunc _write_unlock_irq(rwlock_t *lock) | 356 | void __lockfunc _write_unlock_irq(rwlock_t *lock) |
| 409 | { | 357 | { |
| 410 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 358 | __write_unlock_irq(lock); |
| 411 | _raw_write_unlock(lock); | ||
| 412 | local_irq_enable(); | ||
| 413 | preempt_enable(); | ||
| 414 | } | 359 | } |
| 415 | EXPORT_SYMBOL(_write_unlock_irq); | 360 | EXPORT_SYMBOL(_write_unlock_irq); |
| 361 | #endif | ||
| 416 | 362 | ||
| 363 | #ifndef _write_unlock_bh | ||
| 417 | void __lockfunc _write_unlock_bh(rwlock_t *lock) | 364 | void __lockfunc _write_unlock_bh(rwlock_t *lock) |
| 418 | { | 365 | { |
| 419 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 366 | __write_unlock_bh(lock); |
| 420 | _raw_write_unlock(lock); | ||
| 421 | preempt_enable_no_resched(); | ||
| 422 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 423 | } | 367 | } |
| 424 | EXPORT_SYMBOL(_write_unlock_bh); | 368 | EXPORT_SYMBOL(_write_unlock_bh); |
| 369 | #endif | ||
| 425 | 370 | ||
| 371 | #ifndef _spin_trylock_bh | ||
| 426 | int __lockfunc _spin_trylock_bh(spinlock_t *lock) | 372 | int __lockfunc _spin_trylock_bh(spinlock_t *lock) |
| 427 | { | 373 | { |
| 428 | local_bh_disable(); | 374 | return __spin_trylock_bh(lock); |
| 429 | preempt_disable(); | ||
| 430 | if (_raw_spin_trylock(lock)) { | ||
| 431 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 432 | return 1; | ||
| 433 | } | ||
| 434 | |||
| 435 | preempt_enable_no_resched(); | ||
| 436 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 437 | return 0; | ||
| 438 | } | 375 | } |
| 439 | EXPORT_SYMBOL(_spin_trylock_bh); | 376 | EXPORT_SYMBOL(_spin_trylock_bh); |
| 377 | #endif | ||
| 440 | 378 | ||
| 441 | notrace int in_lock_functions(unsigned long addr) | 379 | notrace int in_lock_functions(unsigned long addr) |
| 442 | { | 380 | { |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 58be76017fd0..71d8dc7f9920 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
| @@ -49,7 +49,6 @@ | |||
| 49 | #include <linux/acpi.h> | 49 | #include <linux/acpi.h> |
| 50 | #include <linux/reboot.h> | 50 | #include <linux/reboot.h> |
| 51 | #include <linux/ftrace.h> | 51 | #include <linux/ftrace.h> |
| 52 | #include <linux/security.h> | ||
| 53 | #include <linux/slow-work.h> | 52 | #include <linux/slow-work.h> |
| 54 | #include <linux/perf_counter.h> | 53 | #include <linux/perf_counter.h> |
| 55 | 54 | ||
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index a6dcd67b041d..620b58abdc32 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c | |||
| @@ -137,11 +137,12 @@ int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, | |||
| 137 | */ | 137 | */ |
| 138 | int clockevents_register_notifier(struct notifier_block *nb) | 138 | int clockevents_register_notifier(struct notifier_block *nb) |
| 139 | { | 139 | { |
| 140 | unsigned long flags; | ||
| 140 | int ret; | 141 | int ret; |
| 141 | 142 | ||
| 142 | spin_lock(&clockevents_lock); | 143 | spin_lock_irqsave(&clockevents_lock, flags); |
| 143 | ret = raw_notifier_chain_register(&clockevents_chain, nb); | 144 | ret = raw_notifier_chain_register(&clockevents_chain, nb); |
| 144 | spin_unlock(&clockevents_lock); | 145 | spin_unlock_irqrestore(&clockevents_lock, flags); |
| 145 | 146 | ||
| 146 | return ret; | 147 | return ret; |
| 147 | } | 148 | } |
| @@ -178,16 +179,18 @@ static void clockevents_notify_released(void) | |||
| 178 | */ | 179 | */ |
| 179 | void clockevents_register_device(struct clock_event_device *dev) | 180 | void clockevents_register_device(struct clock_event_device *dev) |
| 180 | { | 181 | { |
| 182 | unsigned long flags; | ||
| 183 | |||
| 181 | BUG_ON(dev->mode != CLOCK_EVT_MODE_UNUSED); | 184 | BUG_ON(dev->mode != CLOCK_EVT_MODE_UNUSED); |
| 182 | BUG_ON(!dev->cpumask); | 185 | BUG_ON(!dev->cpumask); |
| 183 | 186 | ||
| 184 | spin_lock(&clockevents_lock); | 187 | spin_lock_irqsave(&clockevents_lock, flags); |
| 185 | 188 | ||
| 186 | list_add(&dev->list, &clockevent_devices); | 189 | list_add(&dev->list, &clockevent_devices); |
| 187 | clockevents_do_notify(CLOCK_EVT_NOTIFY_ADD, dev); | 190 | clockevents_do_notify(CLOCK_EVT_NOTIFY_ADD, dev); |
| 188 | clockevents_notify_released(); | 191 | clockevents_notify_released(); |
| 189 | 192 | ||
| 190 | spin_unlock(&clockevents_lock); | 193 | spin_unlock_irqrestore(&clockevents_lock, flags); |
| 191 | } | 194 | } |
| 192 | EXPORT_SYMBOL_GPL(clockevents_register_device); | 195 | EXPORT_SYMBOL_GPL(clockevents_register_device); |
| 193 | 196 | ||
| @@ -235,8 +238,9 @@ void clockevents_exchange_device(struct clock_event_device *old, | |||
| 235 | void clockevents_notify(unsigned long reason, void *arg) | 238 | void clockevents_notify(unsigned long reason, void *arg) |
| 236 | { | 239 | { |
| 237 | struct list_head *node, *tmp; | 240 | struct list_head *node, *tmp; |
| 241 | unsigned long flags; | ||
| 238 | 242 | ||
| 239 | spin_lock(&clockevents_lock); | 243 | spin_lock_irqsave(&clockevents_lock, flags); |
| 240 | clockevents_do_notify(reason, arg); | 244 | clockevents_do_notify(reason, arg); |
| 241 | 245 | ||
| 242 | switch (reason) { | 246 | switch (reason) { |
| @@ -251,7 +255,7 @@ void clockevents_notify(unsigned long reason, void *arg) | |||
| 251 | default: | 255 | default: |
| 252 | break; | 256 | break; |
| 253 | } | 257 | } |
| 254 | spin_unlock(&clockevents_lock); | 258 | spin_unlock_irqrestore(&clockevents_lock, flags); |
| 255 | } | 259 | } |
| 256 | EXPORT_SYMBOL_GPL(clockevents_notify); | 260 | EXPORT_SYMBOL_GPL(clockevents_notify); |
| 257 | #endif | 261 | #endif |
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index 877dbedc3118..c2ec25087a35 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c | |||
| @@ -205,11 +205,11 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev) | |||
| 205 | * Powerstate information: The system enters/leaves a state, where | 205 | * Powerstate information: The system enters/leaves a state, where |
| 206 | * affected devices might stop | 206 | * affected devices might stop |
| 207 | */ | 207 | */ |
| 208 | static void tick_do_broadcast_on_off(void *why) | 208 | static void tick_do_broadcast_on_off(unsigned long *reason) |
| 209 | { | 209 | { |
| 210 | struct clock_event_device *bc, *dev; | 210 | struct clock_event_device *bc, *dev; |
| 211 | struct tick_device *td; | 211 | struct tick_device *td; |
| 212 | unsigned long flags, *reason = why; | 212 | unsigned long flags; |
| 213 | int cpu, bc_stopped; | 213 | int cpu, bc_stopped; |
| 214 | 214 | ||
| 215 | spin_lock_irqsave(&tick_broadcast_lock, flags); | 215 | spin_lock_irqsave(&tick_broadcast_lock, flags); |
| @@ -276,8 +276,7 @@ void tick_broadcast_on_off(unsigned long reason, int *oncpu) | |||
| 276 | printk(KERN_ERR "tick-broadcast: ignoring broadcast for " | 276 | printk(KERN_ERR "tick-broadcast: ignoring broadcast for " |
| 277 | "offline CPU #%d\n", *oncpu); | 277 | "offline CPU #%d\n", *oncpu); |
| 278 | else | 278 | else |
| 279 | smp_call_function_single(*oncpu, tick_do_broadcast_on_off, | 279 | tick_do_broadcast_on_off(&reason); |
| 280 | &reason, 1); | ||
| 281 | } | 280 | } |
| 282 | 281 | ||
| 283 | /* | 282 | /* |
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index a999b92a1277..fddd69d16e03 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c | |||
| @@ -286,7 +286,7 @@ static int __init init_timer_list_procfs(void) | |||
| 286 | { | 286 | { |
| 287 | struct proc_dir_entry *pe; | 287 | struct proc_dir_entry *pe; |
| 288 | 288 | ||
| 289 | pe = proc_create("timer_list", 0644, NULL, &timer_list_fops); | 289 | pe = proc_create("timer_list", 0444, NULL, &timer_list_fops); |
| 290 | if (!pe) | 290 | if (!pe) |
| 291 | return -ENOMEM; | 291 | return -ENOMEM; |
| 292 | return 0; | 292 | return 0; |
diff --git a/kernel/timer.c b/kernel/timer.c index a7f07d5a6241..a3d25f415019 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
| @@ -1156,8 +1156,7 @@ void update_process_times(int user_tick) | |||
| 1156 | /* Note: this timer irq context must be accounted for as well. */ | 1156 | /* Note: this timer irq context must be accounted for as well. */ |
| 1157 | account_process_tick(p, user_tick); | 1157 | account_process_tick(p, user_tick); |
| 1158 | run_local_timers(); | 1158 | run_local_timers(); |
| 1159 | if (rcu_pending(cpu)) | 1159 | rcu_check_callbacks(cpu, user_tick); |
| 1160 | rcu_check_callbacks(cpu, user_tick); | ||
| 1161 | printk_tick(); | 1160 | printk_tick(); |
| 1162 | scheduler_tick(); | 1161 | scheduler_tick(); |
| 1163 | run_posix_cpu_timers(p); | 1162 | run_posix_cpu_timers(p); |
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 1e1d23c26308..25edd5cc5935 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
| @@ -2278,7 +2278,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
| 2278 | read++; | 2278 | read++; |
| 2279 | cnt--; | 2279 | cnt--; |
| 2280 | 2280 | ||
| 2281 | if (!(iter->flags & ~FTRACE_ITER_CONT)) { | 2281 | /* |
| 2282 | * If the parser haven't finished with the last write, | ||
| 2283 | * continue reading the user input without skipping spaces. | ||
| 2284 | */ | ||
| 2285 | if (!(iter->flags & FTRACE_ITER_CONT)) { | ||
| 2282 | /* skip white space */ | 2286 | /* skip white space */ |
| 2283 | while (cnt && isspace(ch)) { | 2287 | while (cnt && isspace(ch)) { |
| 2284 | ret = get_user(ch, ubuf++); | 2288 | ret = get_user(ch, ubuf++); |
| @@ -2288,8 +2292,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
| 2288 | cnt--; | 2292 | cnt--; |
| 2289 | } | 2293 | } |
| 2290 | 2294 | ||
| 2295 | /* only spaces were written */ | ||
| 2291 | if (isspace(ch)) { | 2296 | if (isspace(ch)) { |
| 2292 | file->f_pos += read; | 2297 | *ppos += read; |
| 2293 | ret = read; | 2298 | ret = read; |
| 2294 | goto out; | 2299 | goto out; |
| 2295 | } | 2300 | } |
| @@ -2319,12 +2324,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
| 2319 | if (ret) | 2324 | if (ret) |
| 2320 | goto out; | 2325 | goto out; |
| 2321 | iter->buffer_idx = 0; | 2326 | iter->buffer_idx = 0; |
| 2322 | } else | 2327 | } else { |
| 2323 | iter->flags |= FTRACE_ITER_CONT; | 2328 | iter->flags |= FTRACE_ITER_CONT; |
| 2329 | iter->buffer[iter->buffer_idx++] = ch; | ||
| 2330 | } | ||
| 2324 | 2331 | ||
| 2325 | 2332 | *ppos += read; | |
| 2326 | file->f_pos += read; | ||
| 2327 | |||
| 2328 | ret = read; | 2333 | ret = read; |
| 2329 | out: | 2334 | out: |
| 2330 | mutex_unlock(&ftrace_regex_lock); | 2335 | mutex_unlock(&ftrace_regex_lock); |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index c22b40f8f576..8c358395d338 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -3896,17 +3896,9 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
| 3896 | if (ret < 0) | 3896 | if (ret < 0) |
| 3897 | return ret; | 3897 | return ret; |
| 3898 | 3898 | ||
| 3899 | switch (val) { | 3899 | if (val != 0 && val != 1) |
| 3900 | case 0: | ||
| 3901 | trace_flags &= ~(1 << index); | ||
| 3902 | break; | ||
| 3903 | case 1: | ||
| 3904 | trace_flags |= 1 << index; | ||
| 3905 | break; | ||
| 3906 | |||
| 3907 | default: | ||
| 3908 | return -EINVAL; | 3900 | return -EINVAL; |
| 3909 | } | 3901 | set_tracer_flags(1 << index, val); |
| 3910 | 3902 | ||
| 3911 | *ppos += cnt; | 3903 | *ppos += cnt; |
| 3912 | 3904 | ||
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 0668795d8818..3c44b56b0da7 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
| @@ -600,7 +600,12 @@ static struct workqueue_struct *keventd_wq __read_mostly; | |||
| 600 | * schedule_work - put work task in global workqueue | 600 | * schedule_work - put work task in global workqueue |
| 601 | * @work: job to be done | 601 | * @work: job to be done |
| 602 | * | 602 | * |
| 603 | * This puts a job in the kernel-global workqueue. | 603 | * Returns zero if @work was already on the kernel-global workqueue and |
| 604 | * non-zero otherwise. | ||
| 605 | * | ||
| 606 | * This puts a job in the kernel-global workqueue if it was not already | ||
| 607 | * queued and leaves it in the same position on the kernel-global | ||
| 608 | * workqueue otherwise. | ||
| 604 | */ | 609 | */ |
| 605 | int schedule_work(struct work_struct *work) | 610 | int schedule_work(struct work_struct *work) |
| 606 | { | 611 | { |
