diff options
Diffstat (limited to 'kernel')
52 files changed, 2413 insertions, 501 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 6aebdeb2aa34..a987aa1676b5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
| @@ -10,7 +10,8 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \ | |||
| 10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ | 10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ |
| 11 | hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ | 11 | hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ |
| 12 | notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \ | 12 | notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \ |
| 13 | async.o | 13 | async.o range.o |
| 14 | obj-$(CONFIG_HAVE_EARLY_RES) += early_res.o | ||
| 14 | obj-y += groups.o | 15 | obj-y += groups.o |
| 15 | 16 | ||
| 16 | ifdef CONFIG_FUNCTION_TRACER | 17 | ifdef CONFIG_FUNCTION_TRACER |
| @@ -90,6 +91,9 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o | |||
| 90 | obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o | 91 | obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o |
| 91 | obj-$(CONFIG_TRACEPOINTS) += tracepoint.o | 92 | obj-$(CONFIG_TRACEPOINTS) += tracepoint.o |
| 92 | obj-$(CONFIG_LATENCYTOP) += latencytop.o | 93 | obj-$(CONFIG_LATENCYTOP) += latencytop.o |
| 94 | obj-$(CONFIG_BINFMT_ELF) += elfcore.o | ||
| 95 | obj-$(CONFIG_COMPAT_BINFMT_ELF) += elfcore.o | ||
| 96 | obj-$(CONFIG_BINFMT_ELF_FDPIC) += elfcore.o | ||
| 93 | obj-$(CONFIG_FUNCTION_TRACER) += trace/ | 97 | obj-$(CONFIG_FUNCTION_TRACER) += trace/ |
| 94 | obj-$(CONFIG_TRACING) += trace/ | 98 | obj-$(CONFIG_TRACING) += trace/ |
| 95 | obj-$(CONFIG_X86_DS) += trace/ | 99 | obj-$(CONFIG_X86_DS) += trace/ |
diff --git a/kernel/acct.c b/kernel/acct.c index a6605ca921b6..24f8c81fc48d 100644 --- a/kernel/acct.c +++ b/kernel/acct.c | |||
| @@ -588,16 +588,6 @@ out: | |||
| 588 | } | 588 | } |
| 589 | 589 | ||
| 590 | /** | 590 | /** |
| 591 | * acct_init_pacct - initialize a new pacct_struct | ||
| 592 | * @pacct: per-process accounting info struct to initialize | ||
| 593 | */ | ||
| 594 | void acct_init_pacct(struct pacct_struct *pacct) | ||
| 595 | { | ||
| 596 | memset(pacct, 0, sizeof(struct pacct_struct)); | ||
| 597 | pacct->ac_utime = pacct->ac_stime = cputime_zero; | ||
| 598 | } | ||
| 599 | |||
| 600 | /** | ||
| 601 | * acct_collect - collect accounting information into pacct_struct | 591 | * acct_collect - collect accounting information into pacct_struct |
| 602 | * @exitcode: task exit code | 592 | * @exitcode: task exit code |
| 603 | * @group_dead: not 0, if this thread is the last one in the process. | 593 | * @group_dead: not 0, if this thread is the last one in the process. |
diff --git a/kernel/audit.c b/kernel/audit.c index 5feed232be9d..78f7f86aa238 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
| @@ -398,7 +398,7 @@ static void kauditd_send_skb(struct sk_buff *skb) | |||
| 398 | skb_get(skb); | 398 | skb_get(skb); |
| 399 | err = netlink_unicast(audit_sock, skb, audit_nlk_pid, 0); | 399 | err = netlink_unicast(audit_sock, skb, audit_nlk_pid, 0); |
| 400 | if (err < 0) { | 400 | if (err < 0) { |
| 401 | BUG_ON(err != -ECONNREFUSED); /* Shoudn't happen */ | 401 | BUG_ON(err != -ECONNREFUSED); /* Shouldn't happen */ |
| 402 | printk(KERN_ERR "audit: *NO* daemon at audit_pid=%d\n", audit_pid); | 402 | printk(KERN_ERR "audit: *NO* daemon at audit_pid=%d\n", audit_pid); |
| 403 | audit_log_lost("auditd dissapeared\n"); | 403 | audit_log_lost("auditd dissapeared\n"); |
| 404 | audit_pid = 0; | 404 | audit_pid = 0; |
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index 4b05bd9479db..028e85663f27 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c | |||
| @@ -548,6 +548,11 @@ int audit_remove_tree_rule(struct audit_krule *rule) | |||
| 548 | return 0; | 548 | return 0; |
| 549 | } | 549 | } |
| 550 | 550 | ||
| 551 | static int compare_root(struct vfsmount *mnt, void *arg) | ||
| 552 | { | ||
| 553 | return mnt->mnt_root->d_inode == arg; | ||
| 554 | } | ||
| 555 | |||
| 551 | void audit_trim_trees(void) | 556 | void audit_trim_trees(void) |
| 552 | { | 557 | { |
| 553 | struct list_head cursor; | 558 | struct list_head cursor; |
| @@ -559,7 +564,6 @@ void audit_trim_trees(void) | |||
| 559 | struct path path; | 564 | struct path path; |
| 560 | struct vfsmount *root_mnt; | 565 | struct vfsmount *root_mnt; |
| 561 | struct node *node; | 566 | struct node *node; |
| 562 | struct list_head list; | ||
| 563 | int err; | 567 | int err; |
| 564 | 568 | ||
| 565 | tree = container_of(cursor.next, struct audit_tree, list); | 569 | tree = container_of(cursor.next, struct audit_tree, list); |
| @@ -577,24 +581,16 @@ void audit_trim_trees(void) | |||
| 577 | if (!root_mnt) | 581 | if (!root_mnt) |
| 578 | goto skip_it; | 582 | goto skip_it; |
| 579 | 583 | ||
| 580 | list_add_tail(&list, &root_mnt->mnt_list); | ||
| 581 | spin_lock(&hash_lock); | 584 | spin_lock(&hash_lock); |
| 582 | list_for_each_entry(node, &tree->chunks, list) { | 585 | list_for_each_entry(node, &tree->chunks, list) { |
| 583 | struct audit_chunk *chunk = find_chunk(node); | 586 | struct inode *inode = find_chunk(node)->watch.inode; |
| 584 | struct inode *inode = chunk->watch.inode; | ||
| 585 | struct vfsmount *mnt; | ||
| 586 | node->index |= 1U<<31; | 587 | node->index |= 1U<<31; |
| 587 | list_for_each_entry(mnt, &list, mnt_list) { | 588 | if (iterate_mounts(compare_root, inode, root_mnt)) |
| 588 | if (mnt->mnt_root->d_inode == inode) { | 589 | node->index &= ~(1U<<31); |
| 589 | node->index &= ~(1U<<31); | ||
| 590 | break; | ||
| 591 | } | ||
| 592 | } | ||
| 593 | } | 590 | } |
| 594 | spin_unlock(&hash_lock); | 591 | spin_unlock(&hash_lock); |
| 595 | trim_marked(tree); | 592 | trim_marked(tree); |
| 596 | put_tree(tree); | 593 | put_tree(tree); |
| 597 | list_del_init(&list); | ||
| 598 | drop_collected_mounts(root_mnt); | 594 | drop_collected_mounts(root_mnt); |
| 599 | skip_it: | 595 | skip_it: |
| 600 | mutex_lock(&audit_filter_mutex); | 596 | mutex_lock(&audit_filter_mutex); |
| @@ -603,22 +599,6 @@ skip_it: | |||
| 603 | mutex_unlock(&audit_filter_mutex); | 599 | mutex_unlock(&audit_filter_mutex); |
| 604 | } | 600 | } |
| 605 | 601 | ||
| 606 | static int is_under(struct vfsmount *mnt, struct dentry *dentry, | ||
| 607 | struct path *path) | ||
| 608 | { | ||
| 609 | if (mnt != path->mnt) { | ||
| 610 | for (;;) { | ||
| 611 | if (mnt->mnt_parent == mnt) | ||
| 612 | return 0; | ||
| 613 | if (mnt->mnt_parent == path->mnt) | ||
| 614 | break; | ||
| 615 | mnt = mnt->mnt_parent; | ||
| 616 | } | ||
| 617 | dentry = mnt->mnt_mountpoint; | ||
| 618 | } | ||
| 619 | return is_subdir(dentry, path->dentry); | ||
| 620 | } | ||
| 621 | |||
| 622 | int audit_make_tree(struct audit_krule *rule, char *pathname, u32 op) | 602 | int audit_make_tree(struct audit_krule *rule, char *pathname, u32 op) |
| 623 | { | 603 | { |
| 624 | 604 | ||
| @@ -638,13 +618,17 @@ void audit_put_tree(struct audit_tree *tree) | |||
| 638 | put_tree(tree); | 618 | put_tree(tree); |
| 639 | } | 619 | } |
| 640 | 620 | ||
| 621 | static int tag_mount(struct vfsmount *mnt, void *arg) | ||
| 622 | { | ||
| 623 | return tag_chunk(mnt->mnt_root->d_inode, arg); | ||
| 624 | } | ||
| 625 | |||
| 641 | /* called with audit_filter_mutex */ | 626 | /* called with audit_filter_mutex */ |
| 642 | int audit_add_tree_rule(struct audit_krule *rule) | 627 | int audit_add_tree_rule(struct audit_krule *rule) |
| 643 | { | 628 | { |
| 644 | struct audit_tree *seed = rule->tree, *tree; | 629 | struct audit_tree *seed = rule->tree, *tree; |
| 645 | struct path path; | 630 | struct path path; |
| 646 | struct vfsmount *mnt, *p; | 631 | struct vfsmount *mnt; |
| 647 | struct list_head list; | ||
| 648 | int err; | 632 | int err; |
| 649 | 633 | ||
| 650 | list_for_each_entry(tree, &tree_list, list) { | 634 | list_for_each_entry(tree, &tree_list, list) { |
| @@ -670,16 +654,9 @@ int audit_add_tree_rule(struct audit_krule *rule) | |||
| 670 | err = -ENOMEM; | 654 | err = -ENOMEM; |
| 671 | goto Err; | 655 | goto Err; |
| 672 | } | 656 | } |
| 673 | list_add_tail(&list, &mnt->mnt_list); | ||
| 674 | 657 | ||
| 675 | get_tree(tree); | 658 | get_tree(tree); |
| 676 | list_for_each_entry(p, &list, mnt_list) { | 659 | err = iterate_mounts(tag_mount, tree, mnt); |
| 677 | err = tag_chunk(p->mnt_root->d_inode, tree); | ||
| 678 | if (err) | ||
| 679 | break; | ||
| 680 | } | ||
| 681 | |||
| 682 | list_del(&list); | ||
| 683 | drop_collected_mounts(mnt); | 660 | drop_collected_mounts(mnt); |
| 684 | 661 | ||
| 685 | if (!err) { | 662 | if (!err) { |
| @@ -714,31 +691,23 @@ int audit_tag_tree(char *old, char *new) | |||
| 714 | { | 691 | { |
| 715 | struct list_head cursor, barrier; | 692 | struct list_head cursor, barrier; |
| 716 | int failed = 0; | 693 | int failed = 0; |
| 717 | struct path path; | 694 | struct path path1, path2; |
| 718 | struct vfsmount *tagged; | 695 | struct vfsmount *tagged; |
| 719 | struct list_head list; | ||
| 720 | struct vfsmount *mnt; | ||
| 721 | struct dentry *dentry; | ||
| 722 | int err; | 696 | int err; |
| 723 | 697 | ||
| 724 | err = kern_path(new, 0, &path); | 698 | err = kern_path(new, 0, &path2); |
| 725 | if (err) | 699 | if (err) |
| 726 | return err; | 700 | return err; |
| 727 | tagged = collect_mounts(&path); | 701 | tagged = collect_mounts(&path2); |
| 728 | path_put(&path); | 702 | path_put(&path2); |
| 729 | if (!tagged) | 703 | if (!tagged) |
| 730 | return -ENOMEM; | 704 | return -ENOMEM; |
| 731 | 705 | ||
| 732 | err = kern_path(old, 0, &path); | 706 | err = kern_path(old, 0, &path1); |
| 733 | if (err) { | 707 | if (err) { |
| 734 | drop_collected_mounts(tagged); | 708 | drop_collected_mounts(tagged); |
| 735 | return err; | 709 | return err; |
| 736 | } | 710 | } |
| 737 | mnt = mntget(path.mnt); | ||
| 738 | dentry = dget(path.dentry); | ||
| 739 | path_put(&path); | ||
| 740 | |||
| 741 | list_add_tail(&list, &tagged->mnt_list); | ||
| 742 | 711 | ||
| 743 | mutex_lock(&audit_filter_mutex); | 712 | mutex_lock(&audit_filter_mutex); |
| 744 | list_add(&barrier, &tree_list); | 713 | list_add(&barrier, &tree_list); |
| @@ -746,7 +715,7 @@ int audit_tag_tree(char *old, char *new) | |||
| 746 | 715 | ||
| 747 | while (cursor.next != &tree_list) { | 716 | while (cursor.next != &tree_list) { |
| 748 | struct audit_tree *tree; | 717 | struct audit_tree *tree; |
| 749 | struct vfsmount *p; | 718 | int good_one = 0; |
| 750 | 719 | ||
| 751 | tree = container_of(cursor.next, struct audit_tree, list); | 720 | tree = container_of(cursor.next, struct audit_tree, list); |
| 752 | get_tree(tree); | 721 | get_tree(tree); |
| @@ -754,30 +723,19 @@ int audit_tag_tree(char *old, char *new) | |||
| 754 | list_add(&cursor, &tree->list); | 723 | list_add(&cursor, &tree->list); |
| 755 | mutex_unlock(&audit_filter_mutex); | 724 | mutex_unlock(&audit_filter_mutex); |
| 756 | 725 | ||
| 757 | err = kern_path(tree->pathname, 0, &path); | 726 | err = kern_path(tree->pathname, 0, &path2); |
| 758 | if (err) { | 727 | if (!err) { |
| 759 | put_tree(tree); | 728 | good_one = path_is_under(&path1, &path2); |
| 760 | mutex_lock(&audit_filter_mutex); | 729 | path_put(&path2); |
| 761 | continue; | ||
| 762 | } | 730 | } |
| 763 | 731 | ||
| 764 | spin_lock(&vfsmount_lock); | 732 | if (!good_one) { |
| 765 | if (!is_under(mnt, dentry, &path)) { | ||
| 766 | spin_unlock(&vfsmount_lock); | ||
| 767 | path_put(&path); | ||
| 768 | put_tree(tree); | 733 | put_tree(tree); |
| 769 | mutex_lock(&audit_filter_mutex); | 734 | mutex_lock(&audit_filter_mutex); |
| 770 | continue; | 735 | continue; |
| 771 | } | 736 | } |
| 772 | spin_unlock(&vfsmount_lock); | ||
| 773 | path_put(&path); | ||
| 774 | |||
| 775 | list_for_each_entry(p, &list, mnt_list) { | ||
| 776 | failed = tag_chunk(p->mnt_root->d_inode, tree); | ||
| 777 | if (failed) | ||
| 778 | break; | ||
| 779 | } | ||
| 780 | 737 | ||
| 738 | failed = iterate_mounts(tag_mount, tree, tagged); | ||
| 781 | if (failed) { | 739 | if (failed) { |
| 782 | put_tree(tree); | 740 | put_tree(tree); |
| 783 | mutex_lock(&audit_filter_mutex); | 741 | mutex_lock(&audit_filter_mutex); |
| @@ -818,10 +776,8 @@ int audit_tag_tree(char *old, char *new) | |||
| 818 | } | 776 | } |
| 819 | list_del(&barrier); | 777 | list_del(&barrier); |
| 820 | list_del(&cursor); | 778 | list_del(&cursor); |
| 821 | list_del(&list); | ||
| 822 | mutex_unlock(&audit_filter_mutex); | 779 | mutex_unlock(&audit_filter_mutex); |
| 823 | dput(dentry); | 780 | path_put(&path1); |
| 824 | mntput(mnt); | ||
| 825 | drop_collected_mounts(tagged); | 781 | drop_collected_mounts(tagged); |
| 826 | return failed; | 782 | return failed; |
| 827 | } | 783 | } |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index fc0f928167e7..f3a461c0970a 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
| @@ -1988,7 +1988,6 @@ void __audit_inode(const char *name, const struct dentry *dentry) | |||
| 1988 | 1988 | ||
| 1989 | /** | 1989 | /** |
| 1990 | * audit_inode_child - collect inode info for created/removed objects | 1990 | * audit_inode_child - collect inode info for created/removed objects |
| 1991 | * @dname: inode's dentry name | ||
| 1992 | * @dentry: dentry being audited | 1991 | * @dentry: dentry being audited |
| 1993 | * @parent: inode of dentry parent | 1992 | * @parent: inode of dentry parent |
| 1994 | * | 1993 | * |
| @@ -2000,13 +1999,14 @@ void __audit_inode(const char *name, const struct dentry *dentry) | |||
| 2000 | * must be hooked prior, in order to capture the target inode during | 1999 | * must be hooked prior, in order to capture the target inode during |
| 2001 | * unsuccessful attempts. | 2000 | * unsuccessful attempts. |
| 2002 | */ | 2001 | */ |
| 2003 | void __audit_inode_child(const char *dname, const struct dentry *dentry, | 2002 | void __audit_inode_child(const struct dentry *dentry, |
| 2004 | const struct inode *parent) | 2003 | const struct inode *parent) |
| 2005 | { | 2004 | { |
| 2006 | int idx; | 2005 | int idx; |
| 2007 | struct audit_context *context = current->audit_context; | 2006 | struct audit_context *context = current->audit_context; |
| 2008 | const char *found_parent = NULL, *found_child = NULL; | 2007 | const char *found_parent = NULL, *found_child = NULL; |
| 2009 | const struct inode *inode = dentry->d_inode; | 2008 | const struct inode *inode = dentry->d_inode; |
| 2009 | const char *dname = dentry->d_name.name; | ||
| 2010 | int dirlen = 0; | 2010 | int dirlen = 0; |
| 2011 | 2011 | ||
| 2012 | if (!context->in_syscall) | 2012 | if (!context->in_syscall) |
| @@ -2014,9 +2014,6 @@ void __audit_inode_child(const char *dname, const struct dentry *dentry, | |||
| 2014 | 2014 | ||
| 2015 | if (inode) | 2015 | if (inode) |
| 2016 | handle_one(inode); | 2016 | handle_one(inode); |
| 2017 | /* determine matching parent */ | ||
| 2018 | if (!dname) | ||
| 2019 | goto add_names; | ||
| 2020 | 2017 | ||
| 2021 | /* parent is more likely, look for it first */ | 2018 | /* parent is more likely, look for it first */ |
| 2022 | for (idx = 0; idx < context->name_count; idx++) { | 2019 | for (idx = 0; idx < context->name_count; idx++) { |
diff --git a/kernel/capability.c b/kernel/capability.c index 7f876e60521f..9e4697e9b276 100644 --- a/kernel/capability.c +++ b/kernel/capability.c | |||
| @@ -135,7 +135,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp, | |||
| 135 | if (pid && (pid != task_pid_vnr(current))) { | 135 | if (pid && (pid != task_pid_vnr(current))) { |
| 136 | struct task_struct *target; | 136 | struct task_struct *target; |
| 137 | 137 | ||
| 138 | read_lock(&tasklist_lock); | 138 | rcu_read_lock(); |
| 139 | 139 | ||
| 140 | target = find_task_by_vpid(pid); | 140 | target = find_task_by_vpid(pid); |
| 141 | if (!target) | 141 | if (!target) |
| @@ -143,7 +143,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp, | |||
| 143 | else | 143 | else |
| 144 | ret = security_capget(target, pEp, pIp, pPp); | 144 | ret = security_capget(target, pEp, pIp, pPp); |
| 145 | 145 | ||
| 146 | read_unlock(&tasklist_lock); | 146 | rcu_read_unlock(); |
| 147 | } else | 147 | } else |
| 148 | ret = security_capget(current, pEp, pIp, pPp); | 148 | ret = security_capget(current, pEp, pIp, pPp); |
| 149 | 149 | ||
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 4fd90e129772..ef909a329750 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
| @@ -4,6 +4,10 @@ | |||
| 4 | * Based originally on the cpuset system, extracted by Paul Menage | 4 | * Based originally on the cpuset system, extracted by Paul Menage |
| 5 | * Copyright (C) 2006 Google, Inc | 5 | * Copyright (C) 2006 Google, Inc |
| 6 | * | 6 | * |
| 7 | * Notifications support | ||
| 8 | * Copyright (C) 2009 Nokia Corporation | ||
| 9 | * Author: Kirill A. Shutemov | ||
| 10 | * | ||
| 7 | * Copyright notices from the original cpuset code: | 11 | * Copyright notices from the original cpuset code: |
| 8 | * -------------------------------------------------- | 12 | * -------------------------------------------------- |
| 9 | * Copyright (C) 2003 BULL SA. | 13 | * Copyright (C) 2003 BULL SA. |
| @@ -44,6 +48,7 @@ | |||
| 44 | #include <linux/string.h> | 48 | #include <linux/string.h> |
| 45 | #include <linux/sort.h> | 49 | #include <linux/sort.h> |
| 46 | #include <linux/kmod.h> | 50 | #include <linux/kmod.h> |
| 51 | #include <linux/module.h> | ||
| 47 | #include <linux/delayacct.h> | 52 | #include <linux/delayacct.h> |
| 48 | #include <linux/cgroupstats.h> | 53 | #include <linux/cgroupstats.h> |
| 49 | #include <linux/hash.h> | 54 | #include <linux/hash.h> |
| @@ -52,15 +57,21 @@ | |||
| 52 | #include <linux/pid_namespace.h> | 57 | #include <linux/pid_namespace.h> |
| 53 | #include <linux/idr.h> | 58 | #include <linux/idr.h> |
| 54 | #include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */ | 59 | #include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */ |
| 60 | #include <linux/eventfd.h> | ||
| 61 | #include <linux/poll.h> | ||
| 55 | 62 | ||
| 56 | #include <asm/atomic.h> | 63 | #include <asm/atomic.h> |
| 57 | 64 | ||
| 58 | static DEFINE_MUTEX(cgroup_mutex); | 65 | static DEFINE_MUTEX(cgroup_mutex); |
| 59 | 66 | ||
| 60 | /* Generate an array of cgroup subsystem pointers */ | 67 | /* |
| 68 | * Generate an array of cgroup subsystem pointers. At boot time, this is | ||
| 69 | * populated up to CGROUP_BUILTIN_SUBSYS_COUNT, and modular subsystems are | ||
| 70 | * registered after that. The mutable section of this array is protected by | ||
| 71 | * cgroup_mutex. | ||
| 72 | */ | ||
| 61 | #define SUBSYS(_x) &_x ## _subsys, | 73 | #define SUBSYS(_x) &_x ## _subsys, |
| 62 | 74 | static struct cgroup_subsys *subsys[CGROUP_SUBSYS_COUNT] = { | |
| 63 | static struct cgroup_subsys *subsys[] = { | ||
| 64 | #include <linux/cgroup_subsys.h> | 75 | #include <linux/cgroup_subsys.h> |
| 65 | }; | 76 | }; |
| 66 | 77 | ||
| @@ -147,6 +158,35 @@ struct css_id { | |||
| 147 | unsigned short stack[0]; /* Array of Length (depth+1) */ | 158 | unsigned short stack[0]; /* Array of Length (depth+1) */ |
| 148 | }; | 159 | }; |
| 149 | 160 | ||
| 161 | /* | ||
| 162 | * cgroup_event represents events which userspace want to recieve. | ||
| 163 | */ | ||
| 164 | struct cgroup_event { | ||
| 165 | /* | ||
| 166 | * Cgroup which the event belongs to. | ||
| 167 | */ | ||
| 168 | struct cgroup *cgrp; | ||
| 169 | /* | ||
| 170 | * Control file which the event associated. | ||
| 171 | */ | ||
| 172 | struct cftype *cft; | ||
| 173 | /* | ||
| 174 | * eventfd to signal userspace about the event. | ||
| 175 | */ | ||
| 176 | struct eventfd_ctx *eventfd; | ||
| 177 | /* | ||
| 178 | * Each of these stored in a list by the cgroup. | ||
| 179 | */ | ||
| 180 | struct list_head list; | ||
| 181 | /* | ||
| 182 | * All fields below needed to unregister event when | ||
| 183 | * userspace closes eventfd. | ||
| 184 | */ | ||
| 185 | poll_table pt; | ||
| 186 | wait_queue_head_t *wqh; | ||
| 187 | wait_queue_t wait; | ||
| 188 | struct work_struct remove; | ||
| 189 | }; | ||
| 150 | 190 | ||
| 151 | /* The list of hierarchy roots */ | 191 | /* The list of hierarchy roots */ |
| 152 | 192 | ||
| @@ -250,7 +290,8 @@ struct cg_cgroup_link { | |||
| 250 | static struct css_set init_css_set; | 290 | static struct css_set init_css_set; |
| 251 | static struct cg_cgroup_link init_css_set_link; | 291 | static struct cg_cgroup_link init_css_set_link; |
| 252 | 292 | ||
| 253 | static int cgroup_subsys_init_idr(struct cgroup_subsys *ss); | 293 | static int cgroup_init_idr(struct cgroup_subsys *ss, |
| 294 | struct cgroup_subsys_state *css); | ||
| 254 | 295 | ||
| 255 | /* css_set_lock protects the list of css_set objects, and the | 296 | /* css_set_lock protects the list of css_set objects, and the |
| 256 | * chain of tasks off each css_set. Nests outside task->alloc_lock | 297 | * chain of tasks off each css_set. Nests outside task->alloc_lock |
| @@ -448,8 +489,11 @@ static struct css_set *find_existing_css_set( | |||
| 448 | struct hlist_node *node; | 489 | struct hlist_node *node; |
| 449 | struct css_set *cg; | 490 | struct css_set *cg; |
| 450 | 491 | ||
| 451 | /* Built the set of subsystem state objects that we want to | 492 | /* |
| 452 | * see in the new css_set */ | 493 | * Build the set of subsystem state objects that we want to see in the |
| 494 | * new css_set. while subsystems can change globally, the entries here | ||
| 495 | * won't change, so no need for locking. | ||
| 496 | */ | ||
| 453 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 497 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 454 | if (root->subsys_bits & (1UL << i)) { | 498 | if (root->subsys_bits & (1UL << i)) { |
| 455 | /* Subsystem is in this hierarchy. So we want | 499 | /* Subsystem is in this hierarchy. So we want |
| @@ -696,6 +740,7 @@ void cgroup_lock(void) | |||
| 696 | { | 740 | { |
| 697 | mutex_lock(&cgroup_mutex); | 741 | mutex_lock(&cgroup_mutex); |
| 698 | } | 742 | } |
| 743 | EXPORT_SYMBOL_GPL(cgroup_lock); | ||
| 699 | 744 | ||
| 700 | /** | 745 | /** |
| 701 | * cgroup_unlock - release lock on cgroup changes | 746 | * cgroup_unlock - release lock on cgroup changes |
| @@ -706,6 +751,7 @@ void cgroup_unlock(void) | |||
| 706 | { | 751 | { |
| 707 | mutex_unlock(&cgroup_mutex); | 752 | mutex_unlock(&cgroup_mutex); |
| 708 | } | 753 | } |
| 754 | EXPORT_SYMBOL_GPL(cgroup_unlock); | ||
| 709 | 755 | ||
| 710 | /* | 756 | /* |
| 711 | * A couple of forward declarations required, due to cyclic reference loop: | 757 | * A couple of forward declarations required, due to cyclic reference loop: |
| @@ -757,6 +803,7 @@ static int cgroup_call_pre_destroy(struct cgroup *cgrp) | |||
| 757 | if (ret) | 803 | if (ret) |
| 758 | break; | 804 | break; |
| 759 | } | 805 | } |
| 806 | |||
| 760 | return ret; | 807 | return ret; |
| 761 | } | 808 | } |
| 762 | 809 | ||
| @@ -884,7 +931,11 @@ void cgroup_release_and_wakeup_rmdir(struct cgroup_subsys_state *css) | |||
| 884 | css_put(css); | 931 | css_put(css); |
| 885 | } | 932 | } |
| 886 | 933 | ||
| 887 | 934 | /* | |
| 935 | * Call with cgroup_mutex held. Drops reference counts on modules, including | ||
| 936 | * any duplicate ones that parse_cgroupfs_options took. If this function | ||
| 937 | * returns an error, no reference counts are touched. | ||
| 938 | */ | ||
| 888 | static int rebind_subsystems(struct cgroupfs_root *root, | 939 | static int rebind_subsystems(struct cgroupfs_root *root, |
| 889 | unsigned long final_bits) | 940 | unsigned long final_bits) |
| 890 | { | 941 | { |
| @@ -892,6 +943,8 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
| 892 | struct cgroup *cgrp = &root->top_cgroup; | 943 | struct cgroup *cgrp = &root->top_cgroup; |
| 893 | int i; | 944 | int i; |
| 894 | 945 | ||
| 946 | BUG_ON(!mutex_is_locked(&cgroup_mutex)); | ||
| 947 | |||
| 895 | removed_bits = root->actual_subsys_bits & ~final_bits; | 948 | removed_bits = root->actual_subsys_bits & ~final_bits; |
| 896 | added_bits = final_bits & ~root->actual_subsys_bits; | 949 | added_bits = final_bits & ~root->actual_subsys_bits; |
| 897 | /* Check that any added subsystems are currently free */ | 950 | /* Check that any added subsystems are currently free */ |
| @@ -900,6 +953,12 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
| 900 | struct cgroup_subsys *ss = subsys[i]; | 953 | struct cgroup_subsys *ss = subsys[i]; |
| 901 | if (!(bit & added_bits)) | 954 | if (!(bit & added_bits)) |
| 902 | continue; | 955 | continue; |
| 956 | /* | ||
| 957 | * Nobody should tell us to do a subsys that doesn't exist: | ||
| 958 | * parse_cgroupfs_options should catch that case and refcounts | ||
| 959 | * ensure that subsystems won't disappear once selected. | ||
| 960 | */ | ||
| 961 | BUG_ON(ss == NULL); | ||
| 903 | if (ss->root != &rootnode) { | 962 | if (ss->root != &rootnode) { |
| 904 | /* Subsystem isn't free */ | 963 | /* Subsystem isn't free */ |
| 905 | return -EBUSY; | 964 | return -EBUSY; |
| @@ -919,6 +978,7 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
| 919 | unsigned long bit = 1UL << i; | 978 | unsigned long bit = 1UL << i; |
| 920 | if (bit & added_bits) { | 979 | if (bit & added_bits) { |
| 921 | /* We're binding this subsystem to this hierarchy */ | 980 | /* We're binding this subsystem to this hierarchy */ |
| 981 | BUG_ON(ss == NULL); | ||
| 922 | BUG_ON(cgrp->subsys[i]); | 982 | BUG_ON(cgrp->subsys[i]); |
| 923 | BUG_ON(!dummytop->subsys[i]); | 983 | BUG_ON(!dummytop->subsys[i]); |
| 924 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); | 984 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); |
| @@ -930,8 +990,10 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
| 930 | if (ss->bind) | 990 | if (ss->bind) |
| 931 | ss->bind(ss, cgrp); | 991 | ss->bind(ss, cgrp); |
| 932 | mutex_unlock(&ss->hierarchy_mutex); | 992 | mutex_unlock(&ss->hierarchy_mutex); |
| 993 | /* refcount was already taken, and we're keeping it */ | ||
| 933 | } else if (bit & removed_bits) { | 994 | } else if (bit & removed_bits) { |
| 934 | /* We're removing this subsystem */ | 995 | /* We're removing this subsystem */ |
| 996 | BUG_ON(ss == NULL); | ||
| 935 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); | 997 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); |
| 936 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); | 998 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); |
| 937 | mutex_lock(&ss->hierarchy_mutex); | 999 | mutex_lock(&ss->hierarchy_mutex); |
| @@ -942,9 +1004,20 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
| 942 | subsys[i]->root = &rootnode; | 1004 | subsys[i]->root = &rootnode; |
| 943 | list_move(&ss->sibling, &rootnode.subsys_list); | 1005 | list_move(&ss->sibling, &rootnode.subsys_list); |
| 944 | mutex_unlock(&ss->hierarchy_mutex); | 1006 | mutex_unlock(&ss->hierarchy_mutex); |
| 1007 | /* subsystem is now free - drop reference on module */ | ||
| 1008 | module_put(ss->module); | ||
| 945 | } else if (bit & final_bits) { | 1009 | } else if (bit & final_bits) { |
| 946 | /* Subsystem state should already exist */ | 1010 | /* Subsystem state should already exist */ |
| 1011 | BUG_ON(ss == NULL); | ||
| 947 | BUG_ON(!cgrp->subsys[i]); | 1012 | BUG_ON(!cgrp->subsys[i]); |
| 1013 | /* | ||
| 1014 | * a refcount was taken, but we already had one, so | ||
| 1015 | * drop the extra reference. | ||
| 1016 | */ | ||
| 1017 | module_put(ss->module); | ||
| 1018 | #ifdef CONFIG_MODULE_UNLOAD | ||
| 1019 | BUG_ON(ss->module && !module_refcount(ss->module)); | ||
| 1020 | #endif | ||
| 948 | } else { | 1021 | } else { |
| 949 | /* Subsystem state shouldn't exist */ | 1022 | /* Subsystem state shouldn't exist */ |
| 950 | BUG_ON(cgrp->subsys[i]); | 1023 | BUG_ON(cgrp->subsys[i]); |
| @@ -986,13 +1059,20 @@ struct cgroup_sb_opts { | |||
| 986 | 1059 | ||
| 987 | }; | 1060 | }; |
| 988 | 1061 | ||
| 989 | /* Convert a hierarchy specifier into a bitmask of subsystems and | 1062 | /* |
| 990 | * flags. */ | 1063 | * Convert a hierarchy specifier into a bitmask of subsystems and flags. Call |
| 991 | static int parse_cgroupfs_options(char *data, | 1064 | * with cgroup_mutex held to protect the subsys[] array. This function takes |
| 992 | struct cgroup_sb_opts *opts) | 1065 | * refcounts on subsystems to be used, unless it returns error, in which case |
| 1066 | * no refcounts are taken. | ||
| 1067 | */ | ||
| 1068 | static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | ||
| 993 | { | 1069 | { |
| 994 | char *token, *o = data ?: "all"; | 1070 | char *token, *o = data ?: "all"; |
| 995 | unsigned long mask = (unsigned long)-1; | 1071 | unsigned long mask = (unsigned long)-1; |
| 1072 | int i; | ||
| 1073 | bool module_pin_failed = false; | ||
| 1074 | |||
| 1075 | BUG_ON(!mutex_is_locked(&cgroup_mutex)); | ||
| 996 | 1076 | ||
| 997 | #ifdef CONFIG_CPUSETS | 1077 | #ifdef CONFIG_CPUSETS |
| 998 | mask = ~(1UL << cpuset_subsys_id); | 1078 | mask = ~(1UL << cpuset_subsys_id); |
| @@ -1005,10 +1085,11 @@ static int parse_cgroupfs_options(char *data, | |||
| 1005 | return -EINVAL; | 1085 | return -EINVAL; |
| 1006 | if (!strcmp(token, "all")) { | 1086 | if (!strcmp(token, "all")) { |
| 1007 | /* Add all non-disabled subsystems */ | 1087 | /* Add all non-disabled subsystems */ |
| 1008 | int i; | ||
| 1009 | opts->subsys_bits = 0; | 1088 | opts->subsys_bits = 0; |
| 1010 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 1089 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 1011 | struct cgroup_subsys *ss = subsys[i]; | 1090 | struct cgroup_subsys *ss = subsys[i]; |
| 1091 | if (ss == NULL) | ||
| 1092 | continue; | ||
| 1012 | if (!ss->disabled) | 1093 | if (!ss->disabled) |
| 1013 | opts->subsys_bits |= 1ul << i; | 1094 | opts->subsys_bits |= 1ul << i; |
| 1014 | } | 1095 | } |
| @@ -1026,7 +1107,6 @@ static int parse_cgroupfs_options(char *data, | |||
| 1026 | if (!opts->release_agent) | 1107 | if (!opts->release_agent) |
| 1027 | return -ENOMEM; | 1108 | return -ENOMEM; |
| 1028 | } else if (!strncmp(token, "name=", 5)) { | 1109 | } else if (!strncmp(token, "name=", 5)) { |
| 1029 | int i; | ||
| 1030 | const char *name = token + 5; | 1110 | const char *name = token + 5; |
| 1031 | /* Can't specify an empty name */ | 1111 | /* Can't specify an empty name */ |
| 1032 | if (!strlen(name)) | 1112 | if (!strlen(name)) |
| @@ -1050,9 +1130,10 @@ static int parse_cgroupfs_options(char *data, | |||
| 1050 | return -ENOMEM; | 1130 | return -ENOMEM; |
| 1051 | } else { | 1131 | } else { |
| 1052 | struct cgroup_subsys *ss; | 1132 | struct cgroup_subsys *ss; |
| 1053 | int i; | ||
| 1054 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 1133 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 1055 | ss = subsys[i]; | 1134 | ss = subsys[i]; |
| 1135 | if (ss == NULL) | ||
| 1136 | continue; | ||
| 1056 | if (!strcmp(token, ss->name)) { | 1137 | if (!strcmp(token, ss->name)) { |
| 1057 | if (!ss->disabled) | 1138 | if (!ss->disabled) |
| 1058 | set_bit(i, &opts->subsys_bits); | 1139 | set_bit(i, &opts->subsys_bits); |
| @@ -1087,9 +1168,54 @@ static int parse_cgroupfs_options(char *data, | |||
| 1087 | if (!opts->subsys_bits && !opts->name) | 1168 | if (!opts->subsys_bits && !opts->name) |
| 1088 | return -EINVAL; | 1169 | return -EINVAL; |
| 1089 | 1170 | ||
| 1171 | /* | ||
| 1172 | * Grab references on all the modules we'll need, so the subsystems | ||
| 1173 | * don't dance around before rebind_subsystems attaches them. This may | ||
| 1174 | * take duplicate reference counts on a subsystem that's already used, | ||
| 1175 | * but rebind_subsystems handles this case. | ||
| 1176 | */ | ||
| 1177 | for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) { | ||
| 1178 | unsigned long bit = 1UL << i; | ||
| 1179 | |||
| 1180 | if (!(bit & opts->subsys_bits)) | ||
| 1181 | continue; | ||
| 1182 | if (!try_module_get(subsys[i]->module)) { | ||
| 1183 | module_pin_failed = true; | ||
| 1184 | break; | ||
| 1185 | } | ||
| 1186 | } | ||
| 1187 | if (module_pin_failed) { | ||
| 1188 | /* | ||
| 1189 | * oops, one of the modules was going away. this means that we | ||
| 1190 | * raced with a module_delete call, and to the user this is | ||
| 1191 | * essentially a "subsystem doesn't exist" case. | ||
| 1192 | */ | ||
| 1193 | for (i--; i >= CGROUP_BUILTIN_SUBSYS_COUNT; i--) { | ||
| 1194 | /* drop refcounts only on the ones we took */ | ||
| 1195 | unsigned long bit = 1UL << i; | ||
| 1196 | |||
| 1197 | if (!(bit & opts->subsys_bits)) | ||
| 1198 | continue; | ||
| 1199 | module_put(subsys[i]->module); | ||
| 1200 | } | ||
| 1201 | return -ENOENT; | ||
| 1202 | } | ||
| 1203 | |||
| 1090 | return 0; | 1204 | return 0; |
| 1091 | } | 1205 | } |
| 1092 | 1206 | ||
| 1207 | static void drop_parsed_module_refcounts(unsigned long subsys_bits) | ||
| 1208 | { | ||
| 1209 | int i; | ||
| 1210 | for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) { | ||
| 1211 | unsigned long bit = 1UL << i; | ||
| 1212 | |||
| 1213 | if (!(bit & subsys_bits)) | ||
| 1214 | continue; | ||
| 1215 | module_put(subsys[i]->module); | ||
| 1216 | } | ||
| 1217 | } | ||
| 1218 | |||
| 1093 | static int cgroup_remount(struct super_block *sb, int *flags, char *data) | 1219 | static int cgroup_remount(struct super_block *sb, int *flags, char *data) |
| 1094 | { | 1220 | { |
| 1095 | int ret = 0; | 1221 | int ret = 0; |
| @@ -1106,21 +1232,19 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data) | |||
| 1106 | if (ret) | 1232 | if (ret) |
| 1107 | goto out_unlock; | 1233 | goto out_unlock; |
| 1108 | 1234 | ||
| 1109 | /* Don't allow flags to change at remount */ | 1235 | /* Don't allow flags or name to change at remount */ |
| 1110 | if (opts.flags != root->flags) { | 1236 | if (opts.flags != root->flags || |
| 1111 | ret = -EINVAL; | 1237 | (opts.name && strcmp(opts.name, root->name))) { |
| 1112 | goto out_unlock; | ||
| 1113 | } | ||
| 1114 | |||
| 1115 | /* Don't allow name to change at remount */ | ||
| 1116 | if (opts.name && strcmp(opts.name, root->name)) { | ||
| 1117 | ret = -EINVAL; | 1238 | ret = -EINVAL; |
| 1239 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
| 1118 | goto out_unlock; | 1240 | goto out_unlock; |
| 1119 | } | 1241 | } |
| 1120 | 1242 | ||
| 1121 | ret = rebind_subsystems(root, opts.subsys_bits); | 1243 | ret = rebind_subsystems(root, opts.subsys_bits); |
| 1122 | if (ret) | 1244 | if (ret) { |
| 1245 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
| 1123 | goto out_unlock; | 1246 | goto out_unlock; |
| 1247 | } | ||
| 1124 | 1248 | ||
| 1125 | /* (re)populate subsystem files */ | 1249 | /* (re)populate subsystem files */ |
| 1126 | cgroup_populate_dir(cgrp); | 1250 | cgroup_populate_dir(cgrp); |
| @@ -1151,6 +1275,8 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp) | |||
| 1151 | INIT_LIST_HEAD(&cgrp->release_list); | 1275 | INIT_LIST_HEAD(&cgrp->release_list); |
| 1152 | INIT_LIST_HEAD(&cgrp->pidlists); | 1276 | INIT_LIST_HEAD(&cgrp->pidlists); |
| 1153 | mutex_init(&cgrp->pidlist_mutex); | 1277 | mutex_init(&cgrp->pidlist_mutex); |
| 1278 | INIT_LIST_HEAD(&cgrp->event_list); | ||
| 1279 | spin_lock_init(&cgrp->event_list_lock); | ||
| 1154 | } | 1280 | } |
| 1155 | 1281 | ||
| 1156 | static void init_cgroup_root(struct cgroupfs_root *root) | 1282 | static void init_cgroup_root(struct cgroupfs_root *root) |
| @@ -1306,7 +1432,9 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
| 1306 | struct cgroupfs_root *new_root; | 1432 | struct cgroupfs_root *new_root; |
| 1307 | 1433 | ||
| 1308 | /* First find the desired set of subsystems */ | 1434 | /* First find the desired set of subsystems */ |
| 1435 | mutex_lock(&cgroup_mutex); | ||
| 1309 | ret = parse_cgroupfs_options(data, &opts); | 1436 | ret = parse_cgroupfs_options(data, &opts); |
| 1437 | mutex_unlock(&cgroup_mutex); | ||
| 1310 | if (ret) | 1438 | if (ret) |
| 1311 | goto out_err; | 1439 | goto out_err; |
| 1312 | 1440 | ||
| @@ -1317,7 +1445,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
| 1317 | new_root = cgroup_root_from_opts(&opts); | 1445 | new_root = cgroup_root_from_opts(&opts); |
| 1318 | if (IS_ERR(new_root)) { | 1446 | if (IS_ERR(new_root)) { |
| 1319 | ret = PTR_ERR(new_root); | 1447 | ret = PTR_ERR(new_root); |
| 1320 | goto out_err; | 1448 | goto drop_modules; |
| 1321 | } | 1449 | } |
| 1322 | opts.new_root = new_root; | 1450 | opts.new_root = new_root; |
| 1323 | 1451 | ||
| @@ -1326,7 +1454,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
| 1326 | if (IS_ERR(sb)) { | 1454 | if (IS_ERR(sb)) { |
| 1327 | ret = PTR_ERR(sb); | 1455 | ret = PTR_ERR(sb); |
| 1328 | cgroup_drop_root(opts.new_root); | 1456 | cgroup_drop_root(opts.new_root); |
| 1329 | goto out_err; | 1457 | goto drop_modules; |
| 1330 | } | 1458 | } |
| 1331 | 1459 | ||
| 1332 | root = sb->s_fs_info; | 1460 | root = sb->s_fs_info; |
| @@ -1382,6 +1510,11 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
| 1382 | free_cg_links(&tmp_cg_links); | 1510 | free_cg_links(&tmp_cg_links); |
| 1383 | goto drop_new_super; | 1511 | goto drop_new_super; |
| 1384 | } | 1512 | } |
| 1513 | /* | ||
| 1514 | * There must be no failure case after here, since rebinding | ||
| 1515 | * takes care of subsystems' refcounts, which are explicitly | ||
| 1516 | * dropped in the failure exit path. | ||
| 1517 | */ | ||
| 1385 | 1518 | ||
| 1386 | /* EBUSY should be the only error here */ | 1519 | /* EBUSY should be the only error here */ |
| 1387 | BUG_ON(ret); | 1520 | BUG_ON(ret); |
| @@ -1420,6 +1553,8 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
| 1420 | * any) is not needed | 1553 | * any) is not needed |
| 1421 | */ | 1554 | */ |
| 1422 | cgroup_drop_root(opts.new_root); | 1555 | cgroup_drop_root(opts.new_root); |
| 1556 | /* no subsys rebinding, so refcounts don't change */ | ||
| 1557 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
| 1423 | } | 1558 | } |
| 1424 | 1559 | ||
| 1425 | simple_set_mnt(mnt, sb); | 1560 | simple_set_mnt(mnt, sb); |
| @@ -1429,6 +1564,8 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
| 1429 | 1564 | ||
| 1430 | drop_new_super: | 1565 | drop_new_super: |
| 1431 | deactivate_locked_super(sb); | 1566 | deactivate_locked_super(sb); |
| 1567 | drop_modules: | ||
| 1568 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
| 1432 | out_err: | 1569 | out_err: |
| 1433 | kfree(opts.release_agent); | 1570 | kfree(opts.release_agent); |
| 1434 | kfree(opts.name); | 1571 | kfree(opts.name); |
| @@ -1542,6 +1679,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) | |||
| 1542 | memmove(buf, start, buf + buflen - start); | 1679 | memmove(buf, start, buf + buflen - start); |
| 1543 | return 0; | 1680 | return 0; |
| 1544 | } | 1681 | } |
| 1682 | EXPORT_SYMBOL_GPL(cgroup_path); | ||
| 1545 | 1683 | ||
| 1546 | /** | 1684 | /** |
| 1547 | * cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp' | 1685 | * cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp' |
| @@ -1554,7 +1692,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) | |||
| 1554 | int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | 1692 | int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) |
| 1555 | { | 1693 | { |
| 1556 | int retval = 0; | 1694 | int retval = 0; |
| 1557 | struct cgroup_subsys *ss; | 1695 | struct cgroup_subsys *ss, *failed_ss = NULL; |
| 1558 | struct cgroup *oldcgrp; | 1696 | struct cgroup *oldcgrp; |
| 1559 | struct css_set *cg; | 1697 | struct css_set *cg; |
| 1560 | struct css_set *newcg; | 1698 | struct css_set *newcg; |
| @@ -1568,8 +1706,16 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | |||
| 1568 | for_each_subsys(root, ss) { | 1706 | for_each_subsys(root, ss) { |
| 1569 | if (ss->can_attach) { | 1707 | if (ss->can_attach) { |
| 1570 | retval = ss->can_attach(ss, cgrp, tsk, false); | 1708 | retval = ss->can_attach(ss, cgrp, tsk, false); |
| 1571 | if (retval) | 1709 | if (retval) { |
| 1572 | return retval; | 1710 | /* |
| 1711 | * Remember on which subsystem the can_attach() | ||
| 1712 | * failed, so that we only call cancel_attach() | ||
| 1713 | * against the subsystems whose can_attach() | ||
| 1714 | * succeeded. (See below) | ||
| 1715 | */ | ||
| 1716 | failed_ss = ss; | ||
| 1717 | goto out; | ||
| 1718 | } | ||
| 1573 | } | 1719 | } |
| 1574 | } | 1720 | } |
| 1575 | 1721 | ||
| @@ -1583,14 +1729,17 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | |||
| 1583 | */ | 1729 | */ |
| 1584 | newcg = find_css_set(cg, cgrp); | 1730 | newcg = find_css_set(cg, cgrp); |
| 1585 | put_css_set(cg); | 1731 | put_css_set(cg); |
| 1586 | if (!newcg) | 1732 | if (!newcg) { |
| 1587 | return -ENOMEM; | 1733 | retval = -ENOMEM; |
| 1734 | goto out; | ||
| 1735 | } | ||
| 1588 | 1736 | ||
| 1589 | task_lock(tsk); | 1737 | task_lock(tsk); |
| 1590 | if (tsk->flags & PF_EXITING) { | 1738 | if (tsk->flags & PF_EXITING) { |
| 1591 | task_unlock(tsk); | 1739 | task_unlock(tsk); |
| 1592 | put_css_set(newcg); | 1740 | put_css_set(newcg); |
| 1593 | return -ESRCH; | 1741 | retval = -ESRCH; |
| 1742 | goto out; | ||
| 1594 | } | 1743 | } |
| 1595 | rcu_assign_pointer(tsk->cgroups, newcg); | 1744 | rcu_assign_pointer(tsk->cgroups, newcg); |
| 1596 | task_unlock(tsk); | 1745 | task_unlock(tsk); |
| @@ -1616,7 +1765,22 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | |||
| 1616 | * is no longer empty. | 1765 | * is no longer empty. |
| 1617 | */ | 1766 | */ |
| 1618 | cgroup_wakeup_rmdir_waiter(cgrp); | 1767 | cgroup_wakeup_rmdir_waiter(cgrp); |
| 1619 | return 0; | 1768 | out: |
| 1769 | if (retval) { | ||
| 1770 | for_each_subsys(root, ss) { | ||
| 1771 | if (ss == failed_ss) | ||
| 1772 | /* | ||
| 1773 | * This subsystem was the one that failed the | ||
| 1774 | * can_attach() check earlier, so we don't need | ||
| 1775 | * to call cancel_attach() against it or any | ||
| 1776 | * remaining subsystems. | ||
| 1777 | */ | ||
| 1778 | break; | ||
| 1779 | if (ss->cancel_attach) | ||
| 1780 | ss->cancel_attach(ss, cgrp, tsk, false); | ||
| 1781 | } | ||
| 1782 | } | ||
| 1783 | return retval; | ||
| 1620 | } | 1784 | } |
| 1621 | 1785 | ||
| 1622 | /* | 1786 | /* |
| @@ -1682,6 +1846,7 @@ bool cgroup_lock_live_group(struct cgroup *cgrp) | |||
| 1682 | } | 1846 | } |
| 1683 | return true; | 1847 | return true; |
| 1684 | } | 1848 | } |
| 1849 | EXPORT_SYMBOL_GPL(cgroup_lock_live_group); | ||
| 1685 | 1850 | ||
| 1686 | static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, | 1851 | static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, |
| 1687 | const char *buffer) | 1852 | const char *buffer) |
| @@ -1950,6 +2115,16 @@ static const struct inode_operations cgroup_dir_inode_operations = { | |||
| 1950 | .rename = cgroup_rename, | 2115 | .rename = cgroup_rename, |
| 1951 | }; | 2116 | }; |
| 1952 | 2117 | ||
| 2118 | /* | ||
| 2119 | * Check if a file is a control file | ||
| 2120 | */ | ||
| 2121 | static inline struct cftype *__file_cft(struct file *file) | ||
| 2122 | { | ||
| 2123 | if (file->f_dentry->d_inode->i_fop != &cgroup_file_operations) | ||
| 2124 | return ERR_PTR(-EINVAL); | ||
| 2125 | return __d_cft(file->f_dentry); | ||
| 2126 | } | ||
| 2127 | |||
| 1953 | static int cgroup_create_file(struct dentry *dentry, mode_t mode, | 2128 | static int cgroup_create_file(struct dentry *dentry, mode_t mode, |
| 1954 | struct super_block *sb) | 2129 | struct super_block *sb) |
| 1955 | { | 2130 | { |
| @@ -2069,6 +2244,7 @@ int cgroup_add_file(struct cgroup *cgrp, | |||
| 2069 | error = PTR_ERR(dentry); | 2244 | error = PTR_ERR(dentry); |
| 2070 | return error; | 2245 | return error; |
| 2071 | } | 2246 | } |
| 2247 | EXPORT_SYMBOL_GPL(cgroup_add_file); | ||
| 2072 | 2248 | ||
| 2073 | int cgroup_add_files(struct cgroup *cgrp, | 2249 | int cgroup_add_files(struct cgroup *cgrp, |
| 2074 | struct cgroup_subsys *subsys, | 2250 | struct cgroup_subsys *subsys, |
| @@ -2083,6 +2259,7 @@ int cgroup_add_files(struct cgroup *cgrp, | |||
| 2083 | } | 2259 | } |
| 2084 | return 0; | 2260 | return 0; |
| 2085 | } | 2261 | } |
| 2262 | EXPORT_SYMBOL_GPL(cgroup_add_files); | ||
| 2086 | 2263 | ||
| 2087 | /** | 2264 | /** |
| 2088 | * cgroup_task_count - count the number of tasks in a cgroup. | 2265 | * cgroup_task_count - count the number of tasks in a cgroup. |
| @@ -2468,7 +2645,8 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, | |||
| 2468 | { | 2645 | { |
| 2469 | struct cgroup_pidlist *l; | 2646 | struct cgroup_pidlist *l; |
| 2470 | /* don't need task_nsproxy() if we're looking at ourself */ | 2647 | /* don't need task_nsproxy() if we're looking at ourself */ |
| 2471 | struct pid_namespace *ns = get_pid_ns(current->nsproxy->pid_ns); | 2648 | struct pid_namespace *ns = current->nsproxy->pid_ns; |
| 2649 | |||
| 2472 | /* | 2650 | /* |
| 2473 | * We can't drop the pidlist_mutex before taking the l->mutex in case | 2651 | * We can't drop the pidlist_mutex before taking the l->mutex in case |
| 2474 | * the last ref-holder is trying to remove l from the list at the same | 2652 | * the last ref-holder is trying to remove l from the list at the same |
| @@ -2478,8 +2656,6 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, | |||
| 2478 | mutex_lock(&cgrp->pidlist_mutex); | 2656 | mutex_lock(&cgrp->pidlist_mutex); |
| 2479 | list_for_each_entry(l, &cgrp->pidlists, links) { | 2657 | list_for_each_entry(l, &cgrp->pidlists, links) { |
| 2480 | if (l->key.type == type && l->key.ns == ns) { | 2658 | if (l->key.type == type && l->key.ns == ns) { |
| 2481 | /* found a matching list - drop the extra refcount */ | ||
| 2482 | put_pid_ns(ns); | ||
| 2483 | /* make sure l doesn't vanish out from under us */ | 2659 | /* make sure l doesn't vanish out from under us */ |
| 2484 | down_write(&l->mutex); | 2660 | down_write(&l->mutex); |
| 2485 | mutex_unlock(&cgrp->pidlist_mutex); | 2661 | mutex_unlock(&cgrp->pidlist_mutex); |
| @@ -2490,13 +2666,12 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, | |||
| 2490 | l = kmalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL); | 2666 | l = kmalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL); |
| 2491 | if (!l) { | 2667 | if (!l) { |
| 2492 | mutex_unlock(&cgrp->pidlist_mutex); | 2668 | mutex_unlock(&cgrp->pidlist_mutex); |
| 2493 | put_pid_ns(ns); | ||
| 2494 | return l; | 2669 | return l; |
| 2495 | } | 2670 | } |
| 2496 | init_rwsem(&l->mutex); | 2671 | init_rwsem(&l->mutex); |
| 2497 | down_write(&l->mutex); | 2672 | down_write(&l->mutex); |
| 2498 | l->key.type = type; | 2673 | l->key.type = type; |
| 2499 | l->key.ns = ns; | 2674 | l->key.ns = get_pid_ns(ns); |
| 2500 | l->use_count = 0; /* don't increment here */ | 2675 | l->use_count = 0; /* don't increment here */ |
| 2501 | l->list = NULL; | 2676 | l->list = NULL; |
| 2502 | l->owner = cgrp; | 2677 | l->owner = cgrp; |
| @@ -2804,6 +2979,174 @@ static int cgroup_write_notify_on_release(struct cgroup *cgrp, | |||
| 2804 | } | 2979 | } |
| 2805 | 2980 | ||
| 2806 | /* | 2981 | /* |
| 2982 | * Unregister event and free resources. | ||
| 2983 | * | ||
| 2984 | * Gets called from workqueue. | ||
| 2985 | */ | ||
| 2986 | static void cgroup_event_remove(struct work_struct *work) | ||
| 2987 | { | ||
| 2988 | struct cgroup_event *event = container_of(work, struct cgroup_event, | ||
| 2989 | remove); | ||
| 2990 | struct cgroup *cgrp = event->cgrp; | ||
| 2991 | |||
| 2992 | /* TODO: check return code */ | ||
| 2993 | event->cft->unregister_event(cgrp, event->cft, event->eventfd); | ||
| 2994 | |||
| 2995 | eventfd_ctx_put(event->eventfd); | ||
| 2996 | kfree(event); | ||
| 2997 | dput(cgrp->dentry); | ||
| 2998 | } | ||
| 2999 | |||
| 3000 | /* | ||
| 3001 | * Gets called on POLLHUP on eventfd when user closes it. | ||
| 3002 | * | ||
| 3003 | * Called with wqh->lock held and interrupts disabled. | ||
| 3004 | */ | ||
| 3005 | static int cgroup_event_wake(wait_queue_t *wait, unsigned mode, | ||
| 3006 | int sync, void *key) | ||
| 3007 | { | ||
| 3008 | struct cgroup_event *event = container_of(wait, | ||
| 3009 | struct cgroup_event, wait); | ||
| 3010 | struct cgroup *cgrp = event->cgrp; | ||
| 3011 | unsigned long flags = (unsigned long)key; | ||
| 3012 | |||
| 3013 | if (flags & POLLHUP) { | ||
| 3014 | remove_wait_queue_locked(event->wqh, &event->wait); | ||
| 3015 | spin_lock(&cgrp->event_list_lock); | ||
| 3016 | list_del(&event->list); | ||
| 3017 | spin_unlock(&cgrp->event_list_lock); | ||
| 3018 | /* | ||
| 3019 | * We are in atomic context, but cgroup_event_remove() may | ||
| 3020 | * sleep, so we have to call it in workqueue. | ||
| 3021 | */ | ||
| 3022 | schedule_work(&event->remove); | ||
| 3023 | } | ||
| 3024 | |||
| 3025 | return 0; | ||
| 3026 | } | ||
| 3027 | |||
| 3028 | static void cgroup_event_ptable_queue_proc(struct file *file, | ||
| 3029 | wait_queue_head_t *wqh, poll_table *pt) | ||
| 3030 | { | ||
| 3031 | struct cgroup_event *event = container_of(pt, | ||
| 3032 | struct cgroup_event, pt); | ||
| 3033 | |||
| 3034 | event->wqh = wqh; | ||
| 3035 | add_wait_queue(wqh, &event->wait); | ||
| 3036 | } | ||
| 3037 | |||
| 3038 | /* | ||
| 3039 | * Parse input and register new cgroup event handler. | ||
| 3040 | * | ||
| 3041 | * Input must be in format '<event_fd> <control_fd> <args>'. | ||
| 3042 | * Interpretation of args is defined by control file implementation. | ||
| 3043 | */ | ||
| 3044 | static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft, | ||
| 3045 | const char *buffer) | ||
| 3046 | { | ||
| 3047 | struct cgroup_event *event = NULL; | ||
| 3048 | unsigned int efd, cfd; | ||
| 3049 | struct file *efile = NULL; | ||
| 3050 | struct file *cfile = NULL; | ||
| 3051 | char *endp; | ||
| 3052 | int ret; | ||
| 3053 | |||
| 3054 | efd = simple_strtoul(buffer, &endp, 10); | ||
| 3055 | if (*endp != ' ') | ||
| 3056 | return -EINVAL; | ||
| 3057 | buffer = endp + 1; | ||
| 3058 | |||
| 3059 | cfd = simple_strtoul(buffer, &endp, 10); | ||
| 3060 | if ((*endp != ' ') && (*endp != '\0')) | ||
| 3061 | return -EINVAL; | ||
| 3062 | buffer = endp + 1; | ||
| 3063 | |||
| 3064 | event = kzalloc(sizeof(*event), GFP_KERNEL); | ||
| 3065 | if (!event) | ||
| 3066 | return -ENOMEM; | ||
| 3067 | event->cgrp = cgrp; | ||
| 3068 | INIT_LIST_HEAD(&event->list); | ||
| 3069 | init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc); | ||
| 3070 | init_waitqueue_func_entry(&event->wait, cgroup_event_wake); | ||
| 3071 | INIT_WORK(&event->remove, cgroup_event_remove); | ||
| 3072 | |||
| 3073 | efile = eventfd_fget(efd); | ||
| 3074 | if (IS_ERR(efile)) { | ||
| 3075 | ret = PTR_ERR(efile); | ||
| 3076 | goto fail; | ||
| 3077 | } | ||
| 3078 | |||
| 3079 | event->eventfd = eventfd_ctx_fileget(efile); | ||
| 3080 | if (IS_ERR(event->eventfd)) { | ||
| 3081 | ret = PTR_ERR(event->eventfd); | ||
| 3082 | goto fail; | ||
| 3083 | } | ||
| 3084 | |||
| 3085 | cfile = fget(cfd); | ||
| 3086 | if (!cfile) { | ||
| 3087 | ret = -EBADF; | ||
| 3088 | goto fail; | ||
| 3089 | } | ||
| 3090 | |||
| 3091 | /* the process need read permission on control file */ | ||
| 3092 | ret = file_permission(cfile, MAY_READ); | ||
| 3093 | if (ret < 0) | ||
| 3094 | goto fail; | ||
| 3095 | |||
| 3096 | event->cft = __file_cft(cfile); | ||
| 3097 | if (IS_ERR(event->cft)) { | ||
| 3098 | ret = PTR_ERR(event->cft); | ||
| 3099 | goto fail; | ||
| 3100 | } | ||
| 3101 | |||
| 3102 | if (!event->cft->register_event || !event->cft->unregister_event) { | ||
| 3103 | ret = -EINVAL; | ||
| 3104 | goto fail; | ||
| 3105 | } | ||
| 3106 | |||
| 3107 | ret = event->cft->register_event(cgrp, event->cft, | ||
| 3108 | event->eventfd, buffer); | ||
| 3109 | if (ret) | ||
| 3110 | goto fail; | ||
| 3111 | |||
| 3112 | if (efile->f_op->poll(efile, &event->pt) & POLLHUP) { | ||
| 3113 | event->cft->unregister_event(cgrp, event->cft, event->eventfd); | ||
| 3114 | ret = 0; | ||
| 3115 | goto fail; | ||
| 3116 | } | ||
| 3117 | |||
| 3118 | /* | ||
| 3119 | * Events should be removed after rmdir of cgroup directory, but before | ||
| 3120 | * destroying subsystem state objects. Let's take reference to cgroup | ||
| 3121 | * directory dentry to do that. | ||
| 3122 | */ | ||
| 3123 | dget(cgrp->dentry); | ||
| 3124 | |||
| 3125 | spin_lock(&cgrp->event_list_lock); | ||
| 3126 | list_add(&event->list, &cgrp->event_list); | ||
| 3127 | spin_unlock(&cgrp->event_list_lock); | ||
| 3128 | |||
| 3129 | fput(cfile); | ||
| 3130 | fput(efile); | ||
| 3131 | |||
| 3132 | return 0; | ||
| 3133 | |||
| 3134 | fail: | ||
| 3135 | if (cfile) | ||
| 3136 | fput(cfile); | ||
| 3137 | |||
| 3138 | if (event && event->eventfd && !IS_ERR(event->eventfd)) | ||
| 3139 | eventfd_ctx_put(event->eventfd); | ||
| 3140 | |||
| 3141 | if (!IS_ERR_OR_NULL(efile)) | ||
| 3142 | fput(efile); | ||
| 3143 | |||
| 3144 | kfree(event); | ||
| 3145 | |||
| 3146 | return ret; | ||
| 3147 | } | ||
| 3148 | |||
| 3149 | /* | ||
| 2807 | * for the common functions, 'private' gives the type of file | 3150 | * for the common functions, 'private' gives the type of file |
| 2808 | */ | 3151 | */ |
| 2809 | /* for hysterical raisins, we can't put this on the older files */ | 3152 | /* for hysterical raisins, we can't put this on the older files */ |
| @@ -2828,6 +3171,11 @@ static struct cftype files[] = { | |||
| 2828 | .read_u64 = cgroup_read_notify_on_release, | 3171 | .read_u64 = cgroup_read_notify_on_release, |
| 2829 | .write_u64 = cgroup_write_notify_on_release, | 3172 | .write_u64 = cgroup_write_notify_on_release, |
| 2830 | }, | 3173 | }, |
| 3174 | { | ||
| 3175 | .name = CGROUP_FILE_GENERIC_PREFIX "event_control", | ||
| 3176 | .write_string = cgroup_write_event_control, | ||
| 3177 | .mode = S_IWUGO, | ||
| 3178 | }, | ||
| 2831 | }; | 3179 | }; |
| 2832 | 3180 | ||
| 2833 | static struct cftype cft_release_agent = { | 3181 | static struct cftype cft_release_agent = { |
| @@ -2892,8 +3240,14 @@ static void cgroup_lock_hierarchy(struct cgroupfs_root *root) | |||
| 2892 | /* We need to take each hierarchy_mutex in a consistent order */ | 3240 | /* We need to take each hierarchy_mutex in a consistent order */ |
| 2893 | int i; | 3241 | int i; |
| 2894 | 3242 | ||
| 3243 | /* | ||
| 3244 | * No worry about a race with rebind_subsystems that might mess up the | ||
| 3245 | * locking order, since both parties are under cgroup_mutex. | ||
| 3246 | */ | ||
| 2895 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3247 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 2896 | struct cgroup_subsys *ss = subsys[i]; | 3248 | struct cgroup_subsys *ss = subsys[i]; |
| 3249 | if (ss == NULL) | ||
| 3250 | continue; | ||
| 2897 | if (ss->root == root) | 3251 | if (ss->root == root) |
| 2898 | mutex_lock(&ss->hierarchy_mutex); | 3252 | mutex_lock(&ss->hierarchy_mutex); |
| 2899 | } | 3253 | } |
| @@ -2905,6 +3259,8 @@ static void cgroup_unlock_hierarchy(struct cgroupfs_root *root) | |||
| 2905 | 3259 | ||
| 2906 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3260 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 2907 | struct cgroup_subsys *ss = subsys[i]; | 3261 | struct cgroup_subsys *ss = subsys[i]; |
| 3262 | if (ss == NULL) | ||
| 3263 | continue; | ||
| 2908 | if (ss->root == root) | 3264 | if (ss->root == root) |
| 2909 | mutex_unlock(&ss->hierarchy_mutex); | 3265 | mutex_unlock(&ss->hierarchy_mutex); |
| 2910 | } | 3266 | } |
| @@ -3028,11 +3384,16 @@ static int cgroup_has_css_refs(struct cgroup *cgrp) | |||
| 3028 | * synchronization other than RCU, and the subsystem linked | 3384 | * synchronization other than RCU, and the subsystem linked |
| 3029 | * list isn't RCU-safe */ | 3385 | * list isn't RCU-safe */ |
| 3030 | int i; | 3386 | int i; |
| 3387 | /* | ||
| 3388 | * We won't need to lock the subsys array, because the subsystems | ||
| 3389 | * we're concerned about aren't going anywhere since our cgroup root | ||
| 3390 | * has a reference on them. | ||
| 3391 | */ | ||
| 3031 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3392 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 3032 | struct cgroup_subsys *ss = subsys[i]; | 3393 | struct cgroup_subsys *ss = subsys[i]; |
| 3033 | struct cgroup_subsys_state *css; | 3394 | struct cgroup_subsys_state *css; |
| 3034 | /* Skip subsystems not in this hierarchy */ | 3395 | /* Skip subsystems not present or not in this hierarchy */ |
| 3035 | if (ss->root != cgrp->root) | 3396 | if (ss == NULL || ss->root != cgrp->root) |
| 3036 | continue; | 3397 | continue; |
| 3037 | css = cgrp->subsys[ss->subsys_id]; | 3398 | css = cgrp->subsys[ss->subsys_id]; |
| 3038 | /* When called from check_for_release() it's possible | 3399 | /* When called from check_for_release() it's possible |
| @@ -3106,6 +3467,7 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry) | |||
| 3106 | struct dentry *d; | 3467 | struct dentry *d; |
| 3107 | struct cgroup *parent; | 3468 | struct cgroup *parent; |
| 3108 | DEFINE_WAIT(wait); | 3469 | DEFINE_WAIT(wait); |
| 3470 | struct cgroup_event *event, *tmp; | ||
| 3109 | int ret; | 3471 | int ret; |
| 3110 | 3472 | ||
| 3111 | /* the vfs holds both inode->i_mutex already */ | 3473 | /* the vfs holds both inode->i_mutex already */ |
| @@ -3189,6 +3551,20 @@ again: | |||
| 3189 | set_bit(CGRP_RELEASABLE, &parent->flags); | 3551 | set_bit(CGRP_RELEASABLE, &parent->flags); |
| 3190 | check_for_release(parent); | 3552 | check_for_release(parent); |
| 3191 | 3553 | ||
| 3554 | /* | ||
| 3555 | * Unregister events and notify userspace. | ||
| 3556 | * Notify userspace about cgroup removing only after rmdir of cgroup | ||
| 3557 | * directory to avoid race between userspace and kernelspace | ||
| 3558 | */ | ||
| 3559 | spin_lock(&cgrp->event_list_lock); | ||
| 3560 | list_for_each_entry_safe(event, tmp, &cgrp->event_list, list) { | ||
| 3561 | list_del(&event->list); | ||
| 3562 | remove_wait_queue(event->wqh, &event->wait); | ||
| 3563 | eventfd_signal(event->eventfd, 1); | ||
| 3564 | schedule_work(&event->remove); | ||
| 3565 | } | ||
| 3566 | spin_unlock(&cgrp->event_list_lock); | ||
| 3567 | |||
| 3192 | mutex_unlock(&cgroup_mutex); | 3568 | mutex_unlock(&cgroup_mutex); |
| 3193 | return 0; | 3569 | return 0; |
| 3194 | } | 3570 | } |
| @@ -3223,7 +3599,196 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
| 3223 | mutex_init(&ss->hierarchy_mutex); | 3599 | mutex_init(&ss->hierarchy_mutex); |
| 3224 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | 3600 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); |
| 3225 | ss->active = 1; | 3601 | ss->active = 1; |
| 3602 | |||
| 3603 | /* this function shouldn't be used with modular subsystems, since they | ||
| 3604 | * need to register a subsys_id, among other things */ | ||
| 3605 | BUG_ON(ss->module); | ||
| 3606 | } | ||
| 3607 | |||
| 3608 | /** | ||
| 3609 | * cgroup_load_subsys: load and register a modular subsystem at runtime | ||
| 3610 | * @ss: the subsystem to load | ||
| 3611 | * | ||
| 3612 | * This function should be called in a modular subsystem's initcall. If the | ||
| 3613 | * subsytem is built as a module, it will be assigned a new subsys_id and set | ||
| 3614 | * up for use. If the subsystem is built-in anyway, work is delegated to the | ||
| 3615 | * simpler cgroup_init_subsys. | ||
| 3616 | */ | ||
| 3617 | int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) | ||
| 3618 | { | ||
| 3619 | int i; | ||
| 3620 | struct cgroup_subsys_state *css; | ||
| 3621 | |||
| 3622 | /* check name and function validity */ | ||
| 3623 | if (ss->name == NULL || strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN || | ||
| 3624 | ss->create == NULL || ss->destroy == NULL) | ||
| 3625 | return -EINVAL; | ||
| 3626 | |||
| 3627 | /* | ||
| 3628 | * we don't support callbacks in modular subsystems. this check is | ||
| 3629 | * before the ss->module check for consistency; a subsystem that could | ||
| 3630 | * be a module should still have no callbacks even if the user isn't | ||
| 3631 | * compiling it as one. | ||
| 3632 | */ | ||
| 3633 | if (ss->fork || ss->exit) | ||
| 3634 | return -EINVAL; | ||
| 3635 | |||
| 3636 | /* | ||
| 3637 | * an optionally modular subsystem is built-in: we want to do nothing, | ||
| 3638 | * since cgroup_init_subsys will have already taken care of it. | ||
| 3639 | */ | ||
| 3640 | if (ss->module == NULL) { | ||
| 3641 | /* a few sanity checks */ | ||
| 3642 | BUG_ON(ss->subsys_id >= CGROUP_BUILTIN_SUBSYS_COUNT); | ||
| 3643 | BUG_ON(subsys[ss->subsys_id] != ss); | ||
| 3644 | return 0; | ||
| 3645 | } | ||
| 3646 | |||
| 3647 | /* | ||
| 3648 | * need to register a subsys id before anything else - for example, | ||
| 3649 | * init_cgroup_css needs it. | ||
| 3650 | */ | ||
| 3651 | mutex_lock(&cgroup_mutex); | ||
| 3652 | /* find the first empty slot in the array */ | ||
| 3653 | for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) { | ||
| 3654 | if (subsys[i] == NULL) | ||
| 3655 | break; | ||
| 3656 | } | ||
| 3657 | if (i == CGROUP_SUBSYS_COUNT) { | ||
| 3658 | /* maximum number of subsystems already registered! */ | ||
| 3659 | mutex_unlock(&cgroup_mutex); | ||
| 3660 | return -EBUSY; | ||
| 3661 | } | ||
| 3662 | /* assign ourselves the subsys_id */ | ||
| 3663 | ss->subsys_id = i; | ||
| 3664 | subsys[i] = ss; | ||
| 3665 | |||
| 3666 | /* | ||
| 3667 | * no ss->create seems to need anything important in the ss struct, so | ||
| 3668 | * this can happen first (i.e. before the rootnode attachment). | ||
| 3669 | */ | ||
| 3670 | css = ss->create(ss, dummytop); | ||
| 3671 | if (IS_ERR(css)) { | ||
| 3672 | /* failure case - need to deassign the subsys[] slot. */ | ||
| 3673 | subsys[i] = NULL; | ||
| 3674 | mutex_unlock(&cgroup_mutex); | ||
| 3675 | return PTR_ERR(css); | ||
| 3676 | } | ||
| 3677 | |||
| 3678 | list_add(&ss->sibling, &rootnode.subsys_list); | ||
| 3679 | ss->root = &rootnode; | ||
| 3680 | |||
| 3681 | /* our new subsystem will be attached to the dummy hierarchy. */ | ||
| 3682 | init_cgroup_css(css, ss, dummytop); | ||
| 3683 | /* init_idr must be after init_cgroup_css because it sets css->id. */ | ||
| 3684 | if (ss->use_id) { | ||
| 3685 | int ret = cgroup_init_idr(ss, css); | ||
| 3686 | if (ret) { | ||
| 3687 | dummytop->subsys[ss->subsys_id] = NULL; | ||
| 3688 | ss->destroy(ss, dummytop); | ||
| 3689 | subsys[i] = NULL; | ||
| 3690 | mutex_unlock(&cgroup_mutex); | ||
| 3691 | return ret; | ||
| 3692 | } | ||
| 3693 | } | ||
| 3694 | |||
| 3695 | /* | ||
| 3696 | * Now we need to entangle the css into the existing css_sets. unlike | ||
| 3697 | * in cgroup_init_subsys, there are now multiple css_sets, so each one | ||
| 3698 | * will need a new pointer to it; done by iterating the css_set_table. | ||
| 3699 | * furthermore, modifying the existing css_sets will corrupt the hash | ||
| 3700 | * table state, so each changed css_set will need its hash recomputed. | ||
| 3701 | * this is all done under the css_set_lock. | ||
| 3702 | */ | ||
| 3703 | write_lock(&css_set_lock); | ||
| 3704 | for (i = 0; i < CSS_SET_TABLE_SIZE; i++) { | ||
| 3705 | struct css_set *cg; | ||
| 3706 | struct hlist_node *node, *tmp; | ||
| 3707 | struct hlist_head *bucket = &css_set_table[i], *new_bucket; | ||
| 3708 | |||
| 3709 | hlist_for_each_entry_safe(cg, node, tmp, bucket, hlist) { | ||
| 3710 | /* skip entries that we already rehashed */ | ||
| 3711 | if (cg->subsys[ss->subsys_id]) | ||
| 3712 | continue; | ||
| 3713 | /* remove existing entry */ | ||
| 3714 | hlist_del(&cg->hlist); | ||
| 3715 | /* set new value */ | ||
| 3716 | cg->subsys[ss->subsys_id] = css; | ||
| 3717 | /* recompute hash and restore entry */ | ||
| 3718 | new_bucket = css_set_hash(cg->subsys); | ||
| 3719 | hlist_add_head(&cg->hlist, new_bucket); | ||
| 3720 | } | ||
| 3721 | } | ||
| 3722 | write_unlock(&css_set_lock); | ||
| 3723 | |||
| 3724 | mutex_init(&ss->hierarchy_mutex); | ||
| 3725 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | ||
| 3726 | ss->active = 1; | ||
| 3727 | |||
| 3728 | /* success! */ | ||
| 3729 | mutex_unlock(&cgroup_mutex); | ||
| 3730 | return 0; | ||
| 3226 | } | 3731 | } |
| 3732 | EXPORT_SYMBOL_GPL(cgroup_load_subsys); | ||
| 3733 | |||
| 3734 | /** | ||
| 3735 | * cgroup_unload_subsys: unload a modular subsystem | ||
| 3736 | * @ss: the subsystem to unload | ||
| 3737 | * | ||
| 3738 | * This function should be called in a modular subsystem's exitcall. When this | ||
| 3739 | * function is invoked, the refcount on the subsystem's module will be 0, so | ||
| 3740 | * the subsystem will not be attached to any hierarchy. | ||
| 3741 | */ | ||
| 3742 | void cgroup_unload_subsys(struct cgroup_subsys *ss) | ||
| 3743 | { | ||
| 3744 | struct cg_cgroup_link *link; | ||
| 3745 | struct hlist_head *hhead; | ||
| 3746 | |||
| 3747 | BUG_ON(ss->module == NULL); | ||
| 3748 | |||
| 3749 | /* | ||
| 3750 | * we shouldn't be called if the subsystem is in use, and the use of | ||
| 3751 | * try_module_get in parse_cgroupfs_options should ensure that it | ||
| 3752 | * doesn't start being used while we're killing it off. | ||
| 3753 | */ | ||
| 3754 | BUG_ON(ss->root != &rootnode); | ||
| 3755 | |||
| 3756 | mutex_lock(&cgroup_mutex); | ||
| 3757 | /* deassign the subsys_id */ | ||
| 3758 | BUG_ON(ss->subsys_id < CGROUP_BUILTIN_SUBSYS_COUNT); | ||
| 3759 | subsys[ss->subsys_id] = NULL; | ||
| 3760 | |||
| 3761 | /* remove subsystem from rootnode's list of subsystems */ | ||
| 3762 | list_del(&ss->sibling); | ||
| 3763 | |||
| 3764 | /* | ||
| 3765 | * disentangle the css from all css_sets attached to the dummytop. as | ||
| 3766 | * in loading, we need to pay our respects to the hashtable gods. | ||
| 3767 | */ | ||
| 3768 | write_lock(&css_set_lock); | ||
| 3769 | list_for_each_entry(link, &dummytop->css_sets, cgrp_link_list) { | ||
| 3770 | struct css_set *cg = link->cg; | ||
| 3771 | |||
| 3772 | hlist_del(&cg->hlist); | ||
| 3773 | BUG_ON(!cg->subsys[ss->subsys_id]); | ||
| 3774 | cg->subsys[ss->subsys_id] = NULL; | ||
| 3775 | hhead = css_set_hash(cg->subsys); | ||
| 3776 | hlist_add_head(&cg->hlist, hhead); | ||
| 3777 | } | ||
| 3778 | write_unlock(&css_set_lock); | ||
| 3779 | |||
| 3780 | /* | ||
| 3781 | * remove subsystem's css from the dummytop and free it - need to free | ||
| 3782 | * before marking as null because ss->destroy needs the cgrp->subsys | ||
| 3783 | * pointer to find their state. note that this also takes care of | ||
| 3784 | * freeing the css_id. | ||
| 3785 | */ | ||
| 3786 | ss->destroy(ss, dummytop); | ||
| 3787 | dummytop->subsys[ss->subsys_id] = NULL; | ||
| 3788 | |||
| 3789 | mutex_unlock(&cgroup_mutex); | ||
| 3790 | } | ||
| 3791 | EXPORT_SYMBOL_GPL(cgroup_unload_subsys); | ||
| 3227 | 3792 | ||
| 3228 | /** | 3793 | /** |
| 3229 | * cgroup_init_early - cgroup initialization at system boot | 3794 | * cgroup_init_early - cgroup initialization at system boot |
| @@ -3253,7 +3818,8 @@ int __init cgroup_init_early(void) | |||
| 3253 | for (i = 0; i < CSS_SET_TABLE_SIZE; i++) | 3818 | for (i = 0; i < CSS_SET_TABLE_SIZE; i++) |
| 3254 | INIT_HLIST_HEAD(&css_set_table[i]); | 3819 | INIT_HLIST_HEAD(&css_set_table[i]); |
| 3255 | 3820 | ||
| 3256 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3821 | /* at bootup time, we don't worry about modular subsystems */ |
| 3822 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
| 3257 | struct cgroup_subsys *ss = subsys[i]; | 3823 | struct cgroup_subsys *ss = subsys[i]; |
| 3258 | 3824 | ||
| 3259 | BUG_ON(!ss->name); | 3825 | BUG_ON(!ss->name); |
| @@ -3288,12 +3854,13 @@ int __init cgroup_init(void) | |||
| 3288 | if (err) | 3854 | if (err) |
| 3289 | return err; | 3855 | return err; |
| 3290 | 3856 | ||
| 3291 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3857 | /* at bootup time, we don't worry about modular subsystems */ |
| 3858 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
| 3292 | struct cgroup_subsys *ss = subsys[i]; | 3859 | struct cgroup_subsys *ss = subsys[i]; |
| 3293 | if (!ss->early_init) | 3860 | if (!ss->early_init) |
| 3294 | cgroup_init_subsys(ss); | 3861 | cgroup_init_subsys(ss); |
| 3295 | if (ss->use_id) | 3862 | if (ss->use_id) |
| 3296 | cgroup_subsys_init_idr(ss); | 3863 | cgroup_init_idr(ss, init_css_set.subsys[ss->subsys_id]); |
| 3297 | } | 3864 | } |
| 3298 | 3865 | ||
| 3299 | /* Add init_css_set to the hash table */ | 3866 | /* Add init_css_set to the hash table */ |
| @@ -3397,9 +3964,16 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v) | |||
| 3397 | int i; | 3964 | int i; |
| 3398 | 3965 | ||
| 3399 | seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n"); | 3966 | seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n"); |
| 3967 | /* | ||
| 3968 | * ideally we don't want subsystems moving around while we do this. | ||
| 3969 | * cgroup_mutex is also necessary to guarantee an atomic snapshot of | ||
| 3970 | * subsys/hierarchy state. | ||
| 3971 | */ | ||
| 3400 | mutex_lock(&cgroup_mutex); | 3972 | mutex_lock(&cgroup_mutex); |
| 3401 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3973 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 3402 | struct cgroup_subsys *ss = subsys[i]; | 3974 | struct cgroup_subsys *ss = subsys[i]; |
| 3975 | if (ss == NULL) | ||
| 3976 | continue; | ||
| 3403 | seq_printf(m, "%s\t%d\t%d\t%d\n", | 3977 | seq_printf(m, "%s\t%d\t%d\t%d\n", |
| 3404 | ss->name, ss->root->hierarchy_id, | 3978 | ss->name, ss->root->hierarchy_id, |
| 3405 | ss->root->number_of_cgroups, !ss->disabled); | 3979 | ss->root->number_of_cgroups, !ss->disabled); |
| @@ -3457,7 +4031,12 @@ void cgroup_fork_callbacks(struct task_struct *child) | |||
| 3457 | { | 4031 | { |
| 3458 | if (need_forkexit_callback) { | 4032 | if (need_forkexit_callback) { |
| 3459 | int i; | 4033 | int i; |
| 3460 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 4034 | /* |
| 4035 | * forkexit callbacks are only supported for builtin | ||
| 4036 | * subsystems, and the builtin section of the subsys array is | ||
| 4037 | * immutable, so we don't need to lock the subsys array here. | ||
| 4038 | */ | ||
| 4039 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
| 3461 | struct cgroup_subsys *ss = subsys[i]; | 4040 | struct cgroup_subsys *ss = subsys[i]; |
| 3462 | if (ss->fork) | 4041 | if (ss->fork) |
| 3463 | ss->fork(ss, child); | 4042 | ss->fork(ss, child); |
| @@ -3526,7 +4105,11 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks) | |||
| 3526 | struct css_set *cg; | 4105 | struct css_set *cg; |
| 3527 | 4106 | ||
| 3528 | if (run_callbacks && need_forkexit_callback) { | 4107 | if (run_callbacks && need_forkexit_callback) { |
| 3529 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 4108 | /* |
| 4109 | * modular subsystems can't use callbacks, so no need to lock | ||
| 4110 | * the subsys array | ||
| 4111 | */ | ||
| 4112 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
| 3530 | struct cgroup_subsys *ss = subsys[i]; | 4113 | struct cgroup_subsys *ss = subsys[i]; |
| 3531 | if (ss->exit) | 4114 | if (ss->exit) |
| 3532 | ss->exit(ss, tsk); | 4115 | ss->exit(ss, tsk); |
| @@ -3720,12 +4303,13 @@ static void check_for_release(struct cgroup *cgrp) | |||
| 3720 | } | 4303 | } |
| 3721 | } | 4304 | } |
| 3722 | 4305 | ||
| 3723 | void __css_put(struct cgroup_subsys_state *css) | 4306 | /* Caller must verify that the css is not for root cgroup */ |
| 4307 | void __css_put(struct cgroup_subsys_state *css, int count) | ||
| 3724 | { | 4308 | { |
| 3725 | struct cgroup *cgrp = css->cgroup; | 4309 | struct cgroup *cgrp = css->cgroup; |
| 3726 | int val; | 4310 | int val; |
| 3727 | rcu_read_lock(); | 4311 | rcu_read_lock(); |
| 3728 | val = atomic_dec_return(&css->refcnt); | 4312 | val = atomic_sub_return(count, &css->refcnt); |
| 3729 | if (val == 1) { | 4313 | if (val == 1) { |
| 3730 | if (notify_on_release(cgrp)) { | 4314 | if (notify_on_release(cgrp)) { |
| 3731 | set_bit(CGRP_RELEASABLE, &cgrp->flags); | 4315 | set_bit(CGRP_RELEASABLE, &cgrp->flags); |
| @@ -3736,6 +4320,7 @@ void __css_put(struct cgroup_subsys_state *css) | |||
| 3736 | rcu_read_unlock(); | 4320 | rcu_read_unlock(); |
| 3737 | WARN_ON_ONCE(val < 1); | 4321 | WARN_ON_ONCE(val < 1); |
| 3738 | } | 4322 | } |
| 4323 | EXPORT_SYMBOL_GPL(__css_put); | ||
| 3739 | 4324 | ||
| 3740 | /* | 4325 | /* |
| 3741 | * Notify userspace when a cgroup is released, by running the | 4326 | * Notify userspace when a cgroup is released, by running the |
| @@ -3817,8 +4402,11 @@ static int __init cgroup_disable(char *str) | |||
| 3817 | while ((token = strsep(&str, ",")) != NULL) { | 4402 | while ((token = strsep(&str, ",")) != NULL) { |
| 3818 | if (!*token) | 4403 | if (!*token) |
| 3819 | continue; | 4404 | continue; |
| 3820 | 4405 | /* | |
| 3821 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 4406 | * cgroup_disable, being at boot time, can't know about module |
| 4407 | * subsystems, so we don't worry about them. | ||
| 4408 | */ | ||
| 4409 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
| 3822 | struct cgroup_subsys *ss = subsys[i]; | 4410 | struct cgroup_subsys *ss = subsys[i]; |
| 3823 | 4411 | ||
| 3824 | if (!strcmp(token, ss->name)) { | 4412 | if (!strcmp(token, ss->name)) { |
| @@ -3848,6 +4436,7 @@ unsigned short css_id(struct cgroup_subsys_state *css) | |||
| 3848 | return cssid->id; | 4436 | return cssid->id; |
| 3849 | return 0; | 4437 | return 0; |
| 3850 | } | 4438 | } |
| 4439 | EXPORT_SYMBOL_GPL(css_id); | ||
| 3851 | 4440 | ||
| 3852 | unsigned short css_depth(struct cgroup_subsys_state *css) | 4441 | unsigned short css_depth(struct cgroup_subsys_state *css) |
| 3853 | { | 4442 | { |
| @@ -3857,6 +4446,7 @@ unsigned short css_depth(struct cgroup_subsys_state *css) | |||
| 3857 | return cssid->depth; | 4446 | return cssid->depth; |
| 3858 | return 0; | 4447 | return 0; |
| 3859 | } | 4448 | } |
| 4449 | EXPORT_SYMBOL_GPL(css_depth); | ||
| 3860 | 4450 | ||
| 3861 | bool css_is_ancestor(struct cgroup_subsys_state *child, | 4451 | bool css_is_ancestor(struct cgroup_subsys_state *child, |
| 3862 | const struct cgroup_subsys_state *root) | 4452 | const struct cgroup_subsys_state *root) |
| @@ -3893,6 +4483,7 @@ void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css) | |||
| 3893 | spin_unlock(&ss->id_lock); | 4483 | spin_unlock(&ss->id_lock); |
| 3894 | call_rcu(&id->rcu_head, __free_css_id_cb); | 4484 | call_rcu(&id->rcu_head, __free_css_id_cb); |
| 3895 | } | 4485 | } |
| 4486 | EXPORT_SYMBOL_GPL(free_css_id); | ||
| 3896 | 4487 | ||
| 3897 | /* | 4488 | /* |
| 3898 | * This is called by init or create(). Then, calls to this function are | 4489 | * This is called by init or create(). Then, calls to this function are |
| @@ -3942,15 +4533,14 @@ err_out: | |||
| 3942 | 4533 | ||
| 3943 | } | 4534 | } |
| 3944 | 4535 | ||
| 3945 | static int __init cgroup_subsys_init_idr(struct cgroup_subsys *ss) | 4536 | static int __init_or_module cgroup_init_idr(struct cgroup_subsys *ss, |
| 4537 | struct cgroup_subsys_state *rootcss) | ||
| 3946 | { | 4538 | { |
| 3947 | struct css_id *newid; | 4539 | struct css_id *newid; |
| 3948 | struct cgroup_subsys_state *rootcss; | ||
| 3949 | 4540 | ||
| 3950 | spin_lock_init(&ss->id_lock); | 4541 | spin_lock_init(&ss->id_lock); |
| 3951 | idr_init(&ss->idr); | 4542 | idr_init(&ss->idr); |
| 3952 | 4543 | ||
| 3953 | rootcss = init_css_set.subsys[ss->subsys_id]; | ||
| 3954 | newid = get_new_cssid(ss, 0); | 4544 | newid = get_new_cssid(ss, 0); |
| 3955 | if (IS_ERR(newid)) | 4545 | if (IS_ERR(newid)) |
| 3956 | return PTR_ERR(newid); | 4546 | return PTR_ERR(newid); |
| @@ -4010,6 +4600,7 @@ struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id) | |||
| 4010 | 4600 | ||
| 4011 | return rcu_dereference(cssid->css); | 4601 | return rcu_dereference(cssid->css); |
| 4012 | } | 4602 | } |
| 4603 | EXPORT_SYMBOL_GPL(css_lookup); | ||
| 4013 | 4604 | ||
| 4014 | /** | 4605 | /** |
| 4015 | * css_get_next - lookup next cgroup under specified hierarchy. | 4606 | * css_get_next - lookup next cgroup under specified hierarchy. |
diff --git a/kernel/cpu.c b/kernel/cpu.c index 677f25376a38..f8cced2692b3 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
| @@ -338,7 +338,7 @@ int __cpuinit cpu_up(unsigned int cpu) | |||
| 338 | if (!cpu_possible(cpu)) { | 338 | if (!cpu_possible(cpu)) { |
| 339 | printk(KERN_ERR "can't online cpu %d because it is not " | 339 | printk(KERN_ERR "can't online cpu %d because it is not " |
| 340 | "configured as may-hotadd at boot time\n", cpu); | 340 | "configured as may-hotadd at boot time\n", cpu); |
| 341 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) | 341 | #if defined(CONFIG_IA64) |
| 342 | printk(KERN_ERR "please check additional_cpus= boot " | 342 | printk(KERN_ERR "please check additional_cpus= boot " |
| 343 | "parameter\n"); | 343 | "parameter\n"); |
| 344 | #endif | 344 | #endif |
diff --git a/kernel/early_res.c b/kernel/early_res.c new file mode 100644 index 000000000000..3cb2c661bb78 --- /dev/null +++ b/kernel/early_res.c | |||
| @@ -0,0 +1,578 @@ | |||
| 1 | /* | ||
| 2 | * early_res, could be used to replace bootmem | ||
| 3 | */ | ||
| 4 | #include <linux/kernel.h> | ||
| 5 | #include <linux/types.h> | ||
| 6 | #include <linux/init.h> | ||
| 7 | #include <linux/bootmem.h> | ||
| 8 | #include <linux/mm.h> | ||
| 9 | #include <linux/early_res.h> | ||
| 10 | |||
| 11 | /* | ||
| 12 | * Early reserved memory areas. | ||
| 13 | */ | ||
| 14 | /* | ||
| 15 | * need to make sure this one is bigger enough before | ||
| 16 | * find_fw_memmap_area could be used | ||
| 17 | */ | ||
| 18 | #define MAX_EARLY_RES_X 32 | ||
| 19 | |||
| 20 | struct early_res { | ||
| 21 | u64 start, end; | ||
| 22 | char name[15]; | ||
| 23 | char overlap_ok; | ||
| 24 | }; | ||
| 25 | static struct early_res early_res_x[MAX_EARLY_RES_X] __initdata; | ||
| 26 | |||
| 27 | static int max_early_res __initdata = MAX_EARLY_RES_X; | ||
| 28 | static struct early_res *early_res __initdata = &early_res_x[0]; | ||
| 29 | static int early_res_count __initdata; | ||
| 30 | |||
| 31 | static int __init find_overlapped_early(u64 start, u64 end) | ||
| 32 | { | ||
| 33 | int i; | ||
| 34 | struct early_res *r; | ||
| 35 | |||
| 36 | for (i = 0; i < max_early_res && early_res[i].end; i++) { | ||
| 37 | r = &early_res[i]; | ||
| 38 | if (end > r->start && start < r->end) | ||
| 39 | break; | ||
| 40 | } | ||
| 41 | |||
| 42 | return i; | ||
| 43 | } | ||
| 44 | |||
| 45 | /* | ||
| 46 | * Drop the i-th range from the early reservation map, | ||
| 47 | * by copying any higher ranges down one over it, and | ||
| 48 | * clearing what had been the last slot. | ||
| 49 | */ | ||
| 50 | static void __init drop_range(int i) | ||
| 51 | { | ||
| 52 | int j; | ||
| 53 | |||
| 54 | for (j = i + 1; j < max_early_res && early_res[j].end; j++) | ||
| 55 | ; | ||
| 56 | |||
| 57 | memmove(&early_res[i], &early_res[i + 1], | ||
| 58 | (j - 1 - i) * sizeof(struct early_res)); | ||
| 59 | |||
| 60 | early_res[j - 1].end = 0; | ||
| 61 | early_res_count--; | ||
| 62 | } | ||
| 63 | |||
| 64 | static void __init drop_range_partial(int i, u64 start, u64 end) | ||
| 65 | { | ||
| 66 | u64 common_start, common_end; | ||
| 67 | u64 old_start, old_end; | ||
| 68 | |||
| 69 | old_start = early_res[i].start; | ||
| 70 | old_end = early_res[i].end; | ||
| 71 | common_start = max(old_start, start); | ||
| 72 | common_end = min(old_end, end); | ||
| 73 | |||
| 74 | /* no overlap ? */ | ||
| 75 | if (common_start >= common_end) | ||
| 76 | return; | ||
| 77 | |||
| 78 | if (old_start < common_start) { | ||
| 79 | /* make head segment */ | ||
| 80 | early_res[i].end = common_start; | ||
| 81 | if (old_end > common_end) { | ||
| 82 | char name[15]; | ||
| 83 | |||
| 84 | /* | ||
| 85 | * Save a local copy of the name, since the | ||
| 86 | * early_res array could get resized inside | ||
| 87 | * reserve_early_without_check() -> | ||
| 88 | * __check_and_double_early_res(), which would | ||
| 89 | * make the current name pointer invalid. | ||
| 90 | */ | ||
| 91 | strncpy(name, early_res[i].name, | ||
| 92 | sizeof(early_res[i].name) - 1); | ||
| 93 | /* add another for left over on tail */ | ||
| 94 | reserve_early_without_check(common_end, old_end, name); | ||
| 95 | } | ||
| 96 | return; | ||
| 97 | } else { | ||
| 98 | if (old_end > common_end) { | ||
| 99 | /* reuse the entry for tail left */ | ||
| 100 | early_res[i].start = common_end; | ||
| 101 | return; | ||
| 102 | } | ||
| 103 | /* all covered */ | ||
| 104 | drop_range(i); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | /* | ||
| 109 | * Split any existing ranges that: | ||
| 110 | * 1) are marked 'overlap_ok', and | ||
| 111 | * 2) overlap with the stated range [start, end) | ||
| 112 | * into whatever portion (if any) of the existing range is entirely | ||
| 113 | * below or entirely above the stated range. Drop the portion | ||
| 114 | * of the existing range that overlaps with the stated range, | ||
| 115 | * which will allow the caller of this routine to then add that | ||
| 116 | * stated range without conflicting with any existing range. | ||
| 117 | */ | ||
| 118 | static void __init drop_overlaps_that_are_ok(u64 start, u64 end) | ||
| 119 | { | ||
| 120 | int i; | ||
| 121 | struct early_res *r; | ||
| 122 | u64 lower_start, lower_end; | ||
| 123 | u64 upper_start, upper_end; | ||
| 124 | char name[15]; | ||
| 125 | |||
| 126 | for (i = 0; i < max_early_res && early_res[i].end; i++) { | ||
| 127 | r = &early_res[i]; | ||
| 128 | |||
| 129 | /* Continue past non-overlapping ranges */ | ||
| 130 | if (end <= r->start || start >= r->end) | ||
| 131 | continue; | ||
| 132 | |||
| 133 | /* | ||
| 134 | * Leave non-ok overlaps as is; let caller | ||
| 135 | * panic "Overlapping early reservations" | ||
| 136 | * when it hits this overlap. | ||
| 137 | */ | ||
| 138 | if (!r->overlap_ok) | ||
| 139 | return; | ||
| 140 | |||
| 141 | /* | ||
| 142 | * We have an ok overlap. We will drop it from the early | ||
| 143 | * reservation map, and add back in any non-overlapping | ||
| 144 | * portions (lower or upper) as separate, overlap_ok, | ||
| 145 | * non-overlapping ranges. | ||
| 146 | */ | ||
| 147 | |||
| 148 | /* 1. Note any non-overlapping (lower or upper) ranges. */ | ||
| 149 | strncpy(name, r->name, sizeof(name) - 1); | ||
| 150 | |||
| 151 | lower_start = lower_end = 0; | ||
| 152 | upper_start = upper_end = 0; | ||
| 153 | if (r->start < start) { | ||
| 154 | lower_start = r->start; | ||
| 155 | lower_end = start; | ||
| 156 | } | ||
| 157 | if (r->end > end) { | ||
| 158 | upper_start = end; | ||
| 159 | upper_end = r->end; | ||
| 160 | } | ||
| 161 | |||
| 162 | /* 2. Drop the original ok overlapping range */ | ||
| 163 | drop_range(i); | ||
| 164 | |||
| 165 | i--; /* resume for-loop on copied down entry */ | ||
| 166 | |||
| 167 | /* 3. Add back in any non-overlapping ranges. */ | ||
| 168 | if (lower_end) | ||
| 169 | reserve_early_overlap_ok(lower_start, lower_end, name); | ||
| 170 | if (upper_end) | ||
| 171 | reserve_early_overlap_ok(upper_start, upper_end, name); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | static void __init __reserve_early(u64 start, u64 end, char *name, | ||
| 176 | int overlap_ok) | ||
| 177 | { | ||
| 178 | int i; | ||
| 179 | struct early_res *r; | ||
| 180 | |||
| 181 | i = find_overlapped_early(start, end); | ||
| 182 | if (i >= max_early_res) | ||
| 183 | panic("Too many early reservations"); | ||
| 184 | r = &early_res[i]; | ||
| 185 | if (r->end) | ||
| 186 | panic("Overlapping early reservations " | ||
| 187 | "%llx-%llx %s to %llx-%llx %s\n", | ||
| 188 | start, end - 1, name ? name : "", r->start, | ||
| 189 | r->end - 1, r->name); | ||
| 190 | r->start = start; | ||
| 191 | r->end = end; | ||
| 192 | r->overlap_ok = overlap_ok; | ||
| 193 | if (name) | ||
| 194 | strncpy(r->name, name, sizeof(r->name) - 1); | ||
| 195 | early_res_count++; | ||
| 196 | } | ||
| 197 | |||
| 198 | /* | ||
| 199 | * A few early reservtations come here. | ||
| 200 | * | ||
| 201 | * The 'overlap_ok' in the name of this routine does -not- mean it | ||
| 202 | * is ok for these reservations to overlap an earlier reservation. | ||
| 203 | * Rather it means that it is ok for subsequent reservations to | ||
| 204 | * overlap this one. | ||
| 205 | * | ||
| 206 | * Use this entry point to reserve early ranges when you are doing | ||
| 207 | * so out of "Paranoia", reserving perhaps more memory than you need, | ||
| 208 | * just in case, and don't mind a subsequent overlapping reservation | ||
| 209 | * that is known to be needed. | ||
| 210 | * | ||
| 211 | * The drop_overlaps_that_are_ok() call here isn't really needed. | ||
| 212 | * It would be needed if we had two colliding 'overlap_ok' | ||
| 213 | * reservations, so that the second such would not panic on the | ||
| 214 | * overlap with the first. We don't have any such as of this | ||
| 215 | * writing, but might as well tolerate such if it happens in | ||
| 216 | * the future. | ||
| 217 | */ | ||
| 218 | void __init reserve_early_overlap_ok(u64 start, u64 end, char *name) | ||
| 219 | { | ||
| 220 | drop_overlaps_that_are_ok(start, end); | ||
| 221 | __reserve_early(start, end, name, 1); | ||
| 222 | } | ||
| 223 | |||
| 224 | static void __init __check_and_double_early_res(u64 ex_start, u64 ex_end) | ||
| 225 | { | ||
| 226 | u64 start, end, size, mem; | ||
| 227 | struct early_res *new; | ||
| 228 | |||
| 229 | /* do we have enough slots left ? */ | ||
| 230 | if ((max_early_res - early_res_count) > max(max_early_res/8, 2)) | ||
| 231 | return; | ||
| 232 | |||
| 233 | /* double it */ | ||
| 234 | mem = -1ULL; | ||
| 235 | size = sizeof(struct early_res) * max_early_res * 2; | ||
| 236 | if (early_res == early_res_x) | ||
| 237 | start = 0; | ||
| 238 | else | ||
| 239 | start = early_res[0].end; | ||
| 240 | end = ex_start; | ||
| 241 | if (start + size < end) | ||
| 242 | mem = find_fw_memmap_area(start, end, size, | ||
| 243 | sizeof(struct early_res)); | ||
| 244 | if (mem == -1ULL) { | ||
| 245 | start = ex_end; | ||
| 246 | end = get_max_mapped(); | ||
| 247 | if (start + size < end) | ||
| 248 | mem = find_fw_memmap_area(start, end, size, | ||
| 249 | sizeof(struct early_res)); | ||
| 250 | } | ||
| 251 | if (mem == -1ULL) | ||
| 252 | panic("can not find more space for early_res array"); | ||
| 253 | |||
| 254 | new = __va(mem); | ||
| 255 | /* save the first one for own */ | ||
| 256 | new[0].start = mem; | ||
| 257 | new[0].end = mem + size; | ||
| 258 | new[0].overlap_ok = 0; | ||
| 259 | /* copy old to new */ | ||
| 260 | if (early_res == early_res_x) { | ||
| 261 | memcpy(&new[1], &early_res[0], | ||
| 262 | sizeof(struct early_res) * max_early_res); | ||
| 263 | memset(&new[max_early_res+1], 0, | ||
| 264 | sizeof(struct early_res) * (max_early_res - 1)); | ||
| 265 | early_res_count++; | ||
| 266 | } else { | ||
| 267 | memcpy(&new[1], &early_res[1], | ||
| 268 | sizeof(struct early_res) * (max_early_res - 1)); | ||
| 269 | memset(&new[max_early_res], 0, | ||
| 270 | sizeof(struct early_res) * max_early_res); | ||
| 271 | } | ||
| 272 | memset(&early_res[0], 0, sizeof(struct early_res) * max_early_res); | ||
| 273 | early_res = new; | ||
| 274 | max_early_res *= 2; | ||
| 275 | printk(KERN_DEBUG "early_res array is doubled to %d at [%llx - %llx]\n", | ||
| 276 | max_early_res, mem, mem + size - 1); | ||
| 277 | } | ||
| 278 | |||
| 279 | /* | ||
| 280 | * Most early reservations come here. | ||
| 281 | * | ||
| 282 | * We first have drop_overlaps_that_are_ok() drop any pre-existing | ||
| 283 | * 'overlap_ok' ranges, so that we can then reserve this memory | ||
| 284 | * range without risk of panic'ing on an overlapping overlap_ok | ||
| 285 | * early reservation. | ||
| 286 | */ | ||
| 287 | void __init reserve_early(u64 start, u64 end, char *name) | ||
| 288 | { | ||
| 289 | if (start >= end) | ||
| 290 | return; | ||
| 291 | |||
| 292 | __check_and_double_early_res(start, end); | ||
| 293 | |||
| 294 | drop_overlaps_that_are_ok(start, end); | ||
| 295 | __reserve_early(start, end, name, 0); | ||
| 296 | } | ||
| 297 | |||
| 298 | void __init reserve_early_without_check(u64 start, u64 end, char *name) | ||
| 299 | { | ||
| 300 | struct early_res *r; | ||
| 301 | |||
| 302 | if (start >= end) | ||
| 303 | return; | ||
| 304 | |||
| 305 | __check_and_double_early_res(start, end); | ||
| 306 | |||
| 307 | r = &early_res[early_res_count]; | ||
| 308 | |||
| 309 | r->start = start; | ||
| 310 | r->end = end; | ||
| 311 | r->overlap_ok = 0; | ||
| 312 | if (name) | ||
| 313 | strncpy(r->name, name, sizeof(r->name) - 1); | ||
| 314 | early_res_count++; | ||
| 315 | } | ||
| 316 | |||
| 317 | void __init free_early(u64 start, u64 end) | ||
| 318 | { | ||
| 319 | struct early_res *r; | ||
| 320 | int i; | ||
| 321 | |||
| 322 | i = find_overlapped_early(start, end); | ||
| 323 | r = &early_res[i]; | ||
| 324 | if (i >= max_early_res || r->end != end || r->start != start) | ||
| 325 | panic("free_early on not reserved area: %llx-%llx!", | ||
| 326 | start, end - 1); | ||
| 327 | |||
| 328 | drop_range(i); | ||
| 329 | } | ||
| 330 | |||
| 331 | void __init free_early_partial(u64 start, u64 end) | ||
| 332 | { | ||
| 333 | struct early_res *r; | ||
| 334 | int i; | ||
| 335 | |||
| 336 | try_next: | ||
| 337 | i = find_overlapped_early(start, end); | ||
| 338 | if (i >= max_early_res) | ||
| 339 | return; | ||
| 340 | |||
| 341 | r = &early_res[i]; | ||
| 342 | /* hole ? */ | ||
| 343 | if (r->end >= end && r->start <= start) { | ||
| 344 | drop_range_partial(i, start, end); | ||
| 345 | return; | ||
| 346 | } | ||
| 347 | |||
| 348 | drop_range_partial(i, start, end); | ||
| 349 | goto try_next; | ||
| 350 | } | ||
| 351 | |||
| 352 | #ifdef CONFIG_NO_BOOTMEM | ||
| 353 | static void __init subtract_early_res(struct range *range, int az) | ||
| 354 | { | ||
| 355 | int i, count; | ||
| 356 | u64 final_start, final_end; | ||
| 357 | int idx = 0; | ||
| 358 | |||
| 359 | count = 0; | ||
| 360 | for (i = 0; i < max_early_res && early_res[i].end; i++) | ||
| 361 | count++; | ||
| 362 | |||
| 363 | /* need to skip first one ?*/ | ||
| 364 | if (early_res != early_res_x) | ||
| 365 | idx = 1; | ||
| 366 | |||
| 367 | #define DEBUG_PRINT_EARLY_RES 1 | ||
| 368 | |||
| 369 | #if DEBUG_PRINT_EARLY_RES | ||
| 370 | printk(KERN_INFO "Subtract (%d early reservations)\n", count); | ||
| 371 | #endif | ||
| 372 | for (i = idx; i < count; i++) { | ||
| 373 | struct early_res *r = &early_res[i]; | ||
| 374 | #if DEBUG_PRINT_EARLY_RES | ||
| 375 | printk(KERN_INFO " #%d [%010llx - %010llx] %15s\n", i, | ||
| 376 | r->start, r->end, r->name); | ||
| 377 | #endif | ||
| 378 | final_start = PFN_DOWN(r->start); | ||
| 379 | final_end = PFN_UP(r->end); | ||
| 380 | if (final_start >= final_end) | ||
| 381 | continue; | ||
| 382 | subtract_range(range, az, final_start, final_end); | ||
| 383 | } | ||
| 384 | |||
| 385 | } | ||
| 386 | |||
| 387 | int __init get_free_all_memory_range(struct range **rangep, int nodeid) | ||
| 388 | { | ||
| 389 | int i, count; | ||
| 390 | u64 start = 0, end; | ||
| 391 | u64 size; | ||
| 392 | u64 mem; | ||
| 393 | struct range *range; | ||
| 394 | int nr_range; | ||
| 395 | |||
| 396 | count = 0; | ||
| 397 | for (i = 0; i < max_early_res && early_res[i].end; i++) | ||
| 398 | count++; | ||
| 399 | |||
| 400 | count *= 2; | ||
| 401 | |||
| 402 | size = sizeof(struct range) * count; | ||
| 403 | end = get_max_mapped(); | ||
| 404 | #ifdef MAX_DMA32_PFN | ||
| 405 | if (end > (MAX_DMA32_PFN << PAGE_SHIFT)) | ||
| 406 | start = MAX_DMA32_PFN << PAGE_SHIFT; | ||
| 407 | #endif | ||
| 408 | mem = find_fw_memmap_area(start, end, size, sizeof(struct range)); | ||
| 409 | if (mem == -1ULL) | ||
| 410 | panic("can not find more space for range free"); | ||
| 411 | |||
| 412 | range = __va(mem); | ||
| 413 | /* use early_node_map[] and early_res to get range array at first */ | ||
| 414 | memset(range, 0, size); | ||
| 415 | nr_range = 0; | ||
| 416 | |||
| 417 | /* need to go over early_node_map to find out good range for node */ | ||
| 418 | nr_range = add_from_early_node_map(range, count, nr_range, nodeid); | ||
| 419 | #ifdef CONFIG_X86_32 | ||
| 420 | subtract_range(range, count, max_low_pfn, -1ULL); | ||
| 421 | #endif | ||
| 422 | subtract_early_res(range, count); | ||
| 423 | nr_range = clean_sort_range(range, count); | ||
| 424 | |||
| 425 | /* need to clear it ? */ | ||
| 426 | if (nodeid == MAX_NUMNODES) { | ||
| 427 | memset(&early_res[0], 0, | ||
| 428 | sizeof(struct early_res) * max_early_res); | ||
| 429 | early_res = NULL; | ||
| 430 | max_early_res = 0; | ||
| 431 | } | ||
| 432 | |||
| 433 | *rangep = range; | ||
| 434 | return nr_range; | ||
| 435 | } | ||
| 436 | #else | ||
| 437 | void __init early_res_to_bootmem(u64 start, u64 end) | ||
| 438 | { | ||
| 439 | int i, count; | ||
| 440 | u64 final_start, final_end; | ||
| 441 | int idx = 0; | ||
| 442 | |||
| 443 | count = 0; | ||
| 444 | for (i = 0; i < max_early_res && early_res[i].end; i++) | ||
| 445 | count++; | ||
| 446 | |||
| 447 | /* need to skip first one ?*/ | ||
| 448 | if (early_res != early_res_x) | ||
| 449 | idx = 1; | ||
| 450 | |||
| 451 | printk(KERN_INFO "(%d/%d early reservations) ==> bootmem [%010llx - %010llx]\n", | ||
| 452 | count - idx, max_early_res, start, end); | ||
| 453 | for (i = idx; i < count; i++) { | ||
| 454 | struct early_res *r = &early_res[i]; | ||
| 455 | printk(KERN_INFO " #%d [%010llx - %010llx] %16s", i, | ||
| 456 | r->start, r->end, r->name); | ||
| 457 | final_start = max(start, r->start); | ||
| 458 | final_end = min(end, r->end); | ||
| 459 | if (final_start >= final_end) { | ||
| 460 | printk(KERN_CONT "\n"); | ||
| 461 | continue; | ||
| 462 | } | ||
| 463 | printk(KERN_CONT " ==> [%010llx - %010llx]\n", | ||
| 464 | final_start, final_end); | ||
| 465 | reserve_bootmem_generic(final_start, final_end - final_start, | ||
| 466 | BOOTMEM_DEFAULT); | ||
| 467 | } | ||
| 468 | /* clear them */ | ||
| 469 | memset(&early_res[0], 0, sizeof(struct early_res) * max_early_res); | ||
| 470 | early_res = NULL; | ||
| 471 | max_early_res = 0; | ||
| 472 | early_res_count = 0; | ||
| 473 | } | ||
| 474 | #endif | ||
| 475 | |||
| 476 | /* Check for already reserved areas */ | ||
| 477 | static inline int __init bad_addr(u64 *addrp, u64 size, u64 align) | ||
| 478 | { | ||
| 479 | int i; | ||
| 480 | u64 addr = *addrp; | ||
| 481 | int changed = 0; | ||
| 482 | struct early_res *r; | ||
| 483 | again: | ||
| 484 | i = find_overlapped_early(addr, addr + size); | ||
| 485 | r = &early_res[i]; | ||
| 486 | if (i < max_early_res && r->end) { | ||
| 487 | *addrp = addr = round_up(r->end, align); | ||
| 488 | changed = 1; | ||
| 489 | goto again; | ||
| 490 | } | ||
| 491 | return changed; | ||
| 492 | } | ||
| 493 | |||
| 494 | /* Check for already reserved areas */ | ||
| 495 | static inline int __init bad_addr_size(u64 *addrp, u64 *sizep, u64 align) | ||
| 496 | { | ||
| 497 | int i; | ||
| 498 | u64 addr = *addrp, last; | ||
| 499 | u64 size = *sizep; | ||
| 500 | int changed = 0; | ||
| 501 | again: | ||
| 502 | last = addr + size; | ||
| 503 | for (i = 0; i < max_early_res && early_res[i].end; i++) { | ||
| 504 | struct early_res *r = &early_res[i]; | ||
| 505 | if (last > r->start && addr < r->start) { | ||
| 506 | size = r->start - addr; | ||
| 507 | changed = 1; | ||
| 508 | goto again; | ||
| 509 | } | ||
| 510 | if (last > r->end && addr < r->end) { | ||
| 511 | addr = round_up(r->end, align); | ||
| 512 | size = last - addr; | ||
| 513 | changed = 1; | ||
| 514 | goto again; | ||
| 515 | } | ||
| 516 | if (last <= r->end && addr >= r->start) { | ||
| 517 | (*sizep)++; | ||
| 518 | return 0; | ||
| 519 | } | ||
| 520 | } | ||
| 521 | if (changed) { | ||
| 522 | *addrp = addr; | ||
| 523 | *sizep = size; | ||
| 524 | } | ||
| 525 | return changed; | ||
| 526 | } | ||
| 527 | |||
| 528 | /* | ||
| 529 | * Find a free area with specified alignment in a specific range. | ||
| 530 | * only with the area.between start to end is active range from early_node_map | ||
| 531 | * so they are good as RAM | ||
| 532 | */ | ||
| 533 | u64 __init find_early_area(u64 ei_start, u64 ei_last, u64 start, u64 end, | ||
| 534 | u64 size, u64 align) | ||
| 535 | { | ||
| 536 | u64 addr, last; | ||
| 537 | |||
| 538 | addr = round_up(ei_start, align); | ||
| 539 | if (addr < start) | ||
| 540 | addr = round_up(start, align); | ||
| 541 | if (addr >= ei_last) | ||
| 542 | goto out; | ||
| 543 | while (bad_addr(&addr, size, align) && addr+size <= ei_last) | ||
| 544 | ; | ||
| 545 | last = addr + size; | ||
| 546 | if (last > ei_last) | ||
| 547 | goto out; | ||
| 548 | if (last > end) | ||
| 549 | goto out; | ||
| 550 | |||
| 551 | return addr; | ||
| 552 | |||
| 553 | out: | ||
| 554 | return -1ULL; | ||
| 555 | } | ||
| 556 | |||
| 557 | u64 __init find_early_area_size(u64 ei_start, u64 ei_last, u64 start, | ||
| 558 | u64 *sizep, u64 align) | ||
| 559 | { | ||
| 560 | u64 addr, last; | ||
| 561 | |||
| 562 | addr = round_up(ei_start, align); | ||
| 563 | if (addr < start) | ||
| 564 | addr = round_up(start, align); | ||
| 565 | if (addr >= ei_last) | ||
| 566 | goto out; | ||
| 567 | *sizep = ei_last - addr; | ||
| 568 | while (bad_addr_size(&addr, sizep, align) && addr + *sizep <= ei_last) | ||
| 569 | ; | ||
| 570 | last = addr + *sizep; | ||
| 571 | if (last > ei_last) | ||
| 572 | goto out; | ||
| 573 | |||
| 574 | return addr; | ||
| 575 | |||
| 576 | out: | ||
| 577 | return -1ULL; | ||
| 578 | } | ||
diff --git a/kernel/elfcore.c b/kernel/elfcore.c new file mode 100644 index 000000000000..ff915efef66d --- /dev/null +++ b/kernel/elfcore.c | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #include <linux/elf.h> | ||
| 2 | #include <linux/fs.h> | ||
| 3 | #include <linux/mm.h> | ||
| 4 | |||
| 5 | #include <asm/elf.h> | ||
| 6 | |||
| 7 | |||
| 8 | Elf_Half __weak elf_core_extra_phdrs(void) | ||
| 9 | { | ||
| 10 | return 0; | ||
| 11 | } | ||
| 12 | |||
| 13 | int __weak elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size, | ||
| 14 | unsigned long limit) | ||
| 15 | { | ||
| 16 | return 1; | ||
| 17 | } | ||
| 18 | |||
| 19 | int __weak elf_core_write_extra_data(struct file *file, size_t *size, | ||
| 20 | unsigned long limit) | ||
| 21 | { | ||
| 22 | return 1; | ||
| 23 | } | ||
| 24 | |||
| 25 | size_t __weak elf_core_extra_data_size(void) | ||
| 26 | { | ||
| 27 | return 0; | ||
| 28 | } | ||
diff --git a/kernel/exit.c b/kernel/exit.c index 45ed043b8bf5..ce1e48c2d93d 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -952,7 +952,8 @@ NORET_TYPE void do_exit(long code) | |||
| 952 | preempt_count()); | 952 | preempt_count()); |
| 953 | 953 | ||
| 954 | acct_update_integrals(tsk); | 954 | acct_update_integrals(tsk); |
| 955 | 955 | /* sync mm's RSS info before statistics gathering */ | |
| 956 | sync_mm_rss(tsk, tsk->mm); | ||
| 956 | group_dead = atomic_dec_and_test(&tsk->signal->live); | 957 | group_dead = atomic_dec_and_test(&tsk->signal->live); |
| 957 | if (group_dead) { | 958 | if (group_dead) { |
| 958 | hrtimer_cancel(&tsk->signal->real_timer); | 959 | hrtimer_cancel(&tsk->signal->real_timer); |
| @@ -1188,7 +1189,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) | |||
| 1188 | 1189 | ||
| 1189 | if (unlikely(wo->wo_flags & WNOWAIT)) { | 1190 | if (unlikely(wo->wo_flags & WNOWAIT)) { |
| 1190 | int exit_code = p->exit_code; | 1191 | int exit_code = p->exit_code; |
| 1191 | int why, status; | 1192 | int why; |
| 1192 | 1193 | ||
| 1193 | get_task_struct(p); | 1194 | get_task_struct(p); |
| 1194 | read_unlock(&tasklist_lock); | 1195 | read_unlock(&tasklist_lock); |
diff --git a/kernel/fork.c b/kernel/fork.c index 17bbf093356d..1beb6c303c41 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
| @@ -329,15 +329,17 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) | |||
| 329 | if (!tmp) | 329 | if (!tmp) |
| 330 | goto fail_nomem; | 330 | goto fail_nomem; |
| 331 | *tmp = *mpnt; | 331 | *tmp = *mpnt; |
| 332 | INIT_LIST_HEAD(&tmp->anon_vma_chain); | ||
| 332 | pol = mpol_dup(vma_policy(mpnt)); | 333 | pol = mpol_dup(vma_policy(mpnt)); |
| 333 | retval = PTR_ERR(pol); | 334 | retval = PTR_ERR(pol); |
| 334 | if (IS_ERR(pol)) | 335 | if (IS_ERR(pol)) |
| 335 | goto fail_nomem_policy; | 336 | goto fail_nomem_policy; |
| 336 | vma_set_policy(tmp, pol); | 337 | vma_set_policy(tmp, pol); |
| 338 | if (anon_vma_fork(tmp, mpnt)) | ||
| 339 | goto fail_nomem_anon_vma_fork; | ||
| 337 | tmp->vm_flags &= ~VM_LOCKED; | 340 | tmp->vm_flags &= ~VM_LOCKED; |
| 338 | tmp->vm_mm = mm; | 341 | tmp->vm_mm = mm; |
| 339 | tmp->vm_next = NULL; | 342 | tmp->vm_next = NULL; |
| 340 | anon_vma_link(tmp); | ||
| 341 | file = tmp->vm_file; | 343 | file = tmp->vm_file; |
| 342 | if (file) { | 344 | if (file) { |
| 343 | struct inode *inode = file->f_path.dentry->d_inode; | 345 | struct inode *inode = file->f_path.dentry->d_inode; |
| @@ -392,6 +394,8 @@ out: | |||
| 392 | flush_tlb_mm(oldmm); | 394 | flush_tlb_mm(oldmm); |
| 393 | up_write(&oldmm->mmap_sem); | 395 | up_write(&oldmm->mmap_sem); |
| 394 | return retval; | 396 | return retval; |
| 397 | fail_nomem_anon_vma_fork: | ||
| 398 | mpol_put(pol); | ||
| 395 | fail_nomem_policy: | 399 | fail_nomem_policy: |
| 396 | kmem_cache_free(vm_area_cachep, tmp); | 400 | kmem_cache_free(vm_area_cachep, tmp); |
| 397 | fail_nomem: | 401 | fail_nomem: |
| @@ -455,8 +459,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p) | |||
| 455 | (current->mm->flags & MMF_INIT_MASK) : default_dump_filter; | 459 | (current->mm->flags & MMF_INIT_MASK) : default_dump_filter; |
| 456 | mm->core_state = NULL; | 460 | mm->core_state = NULL; |
| 457 | mm->nr_ptes = 0; | 461 | mm->nr_ptes = 0; |
| 458 | set_mm_counter(mm, file_rss, 0); | 462 | memset(&mm->rss_stat, 0, sizeof(mm->rss_stat)); |
| 459 | set_mm_counter(mm, anon_rss, 0); | ||
| 460 | spin_lock_init(&mm->page_table_lock); | 463 | spin_lock_init(&mm->page_table_lock); |
| 461 | mm->free_area_cache = TASK_UNMAPPED_BASE; | 464 | mm->free_area_cache = TASK_UNMAPPED_BASE; |
| 462 | mm->cached_hole_size = ~0UL; | 465 | mm->cached_hole_size = ~0UL; |
| @@ -825,23 +828,14 @@ void __cleanup_sighand(struct sighand_struct *sighand) | |||
| 825 | */ | 828 | */ |
| 826 | static void posix_cpu_timers_init_group(struct signal_struct *sig) | 829 | static void posix_cpu_timers_init_group(struct signal_struct *sig) |
| 827 | { | 830 | { |
| 831 | unsigned long cpu_limit; | ||
| 832 | |||
| 828 | /* Thread group counters. */ | 833 | /* Thread group counters. */ |
| 829 | thread_group_cputime_init(sig); | 834 | thread_group_cputime_init(sig); |
| 830 | 835 | ||
| 831 | /* Expiration times and increments. */ | 836 | cpu_limit = ACCESS_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur); |
| 832 | sig->it[CPUCLOCK_PROF].expires = cputime_zero; | 837 | if (cpu_limit != RLIM_INFINITY) { |
| 833 | sig->it[CPUCLOCK_PROF].incr = cputime_zero; | 838 | sig->cputime_expires.prof_exp = secs_to_cputime(cpu_limit); |
| 834 | sig->it[CPUCLOCK_VIRT].expires = cputime_zero; | ||
| 835 | sig->it[CPUCLOCK_VIRT].incr = cputime_zero; | ||
| 836 | |||
| 837 | /* Cached expiration times. */ | ||
| 838 | sig->cputime_expires.prof_exp = cputime_zero; | ||
| 839 | sig->cputime_expires.virt_exp = cputime_zero; | ||
| 840 | sig->cputime_expires.sched_exp = 0; | ||
| 841 | |||
| 842 | if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) { | ||
| 843 | sig->cputime_expires.prof_exp = | ||
| 844 | secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur); | ||
| 845 | sig->cputimer.running = 1; | 839 | sig->cputimer.running = 1; |
| 846 | } | 840 | } |
| 847 | 841 | ||
| @@ -858,7 +852,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
| 858 | if (clone_flags & CLONE_THREAD) | 852 | if (clone_flags & CLONE_THREAD) |
| 859 | return 0; | 853 | return 0; |
| 860 | 854 | ||
| 861 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); | 855 | sig = kmem_cache_zalloc(signal_cachep, GFP_KERNEL); |
| 862 | tsk->signal = sig; | 856 | tsk->signal = sig; |
| 863 | if (!sig) | 857 | if (!sig) |
| 864 | return -ENOMEM; | 858 | return -ENOMEM; |
| @@ -866,46 +860,21 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
| 866 | atomic_set(&sig->count, 1); | 860 | atomic_set(&sig->count, 1); |
| 867 | atomic_set(&sig->live, 1); | 861 | atomic_set(&sig->live, 1); |
| 868 | init_waitqueue_head(&sig->wait_chldexit); | 862 | init_waitqueue_head(&sig->wait_chldexit); |
| 869 | sig->flags = 0; | ||
| 870 | if (clone_flags & CLONE_NEWPID) | 863 | if (clone_flags & CLONE_NEWPID) |
| 871 | sig->flags |= SIGNAL_UNKILLABLE; | 864 | sig->flags |= SIGNAL_UNKILLABLE; |
| 872 | sig->group_exit_code = 0; | ||
| 873 | sig->group_exit_task = NULL; | ||
| 874 | sig->group_stop_count = 0; | ||
| 875 | sig->curr_target = tsk; | 865 | sig->curr_target = tsk; |
| 876 | init_sigpending(&sig->shared_pending); | 866 | init_sigpending(&sig->shared_pending); |
| 877 | INIT_LIST_HEAD(&sig->posix_timers); | 867 | INIT_LIST_HEAD(&sig->posix_timers); |
| 878 | 868 | ||
| 879 | hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 869 | hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 880 | sig->it_real_incr.tv64 = 0; | ||
| 881 | sig->real_timer.function = it_real_fn; | 870 | sig->real_timer.function = it_real_fn; |
| 882 | 871 | ||
| 883 | sig->leader = 0; /* session leadership doesn't inherit */ | ||
| 884 | sig->tty_old_pgrp = NULL; | ||
| 885 | sig->tty = NULL; | ||
| 886 | |||
| 887 | sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero; | ||
| 888 | sig->gtime = cputime_zero; | ||
| 889 | sig->cgtime = cputime_zero; | ||
| 890 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING | ||
| 891 | sig->prev_utime = sig->prev_stime = cputime_zero; | ||
| 892 | #endif | ||
| 893 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; | ||
| 894 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; | ||
| 895 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; | ||
| 896 | sig->maxrss = sig->cmaxrss = 0; | ||
| 897 | task_io_accounting_init(&sig->ioac); | ||
| 898 | sig->sum_sched_runtime = 0; | ||
| 899 | taskstats_tgid_init(sig); | ||
| 900 | |||
| 901 | task_lock(current->group_leader); | 872 | task_lock(current->group_leader); |
| 902 | memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); | 873 | memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); |
| 903 | task_unlock(current->group_leader); | 874 | task_unlock(current->group_leader); |
| 904 | 875 | ||
| 905 | posix_cpu_timers_init_group(sig); | 876 | posix_cpu_timers_init_group(sig); |
| 906 | 877 | ||
| 907 | acct_init_pacct(&sig->pacct); | ||
| 908 | |||
| 909 | tty_audit_fork(sig); | 878 | tty_audit_fork(sig); |
| 910 | 879 | ||
| 911 | sig->oom_adj = current->signal->oom_adj; | 880 | sig->oom_adj = current->signal->oom_adj; |
| @@ -1034,7 +1003,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
| 1034 | #endif | 1003 | #endif |
| 1035 | retval = -EAGAIN; | 1004 | retval = -EAGAIN; |
| 1036 | if (atomic_read(&p->real_cred->user->processes) >= | 1005 | if (atomic_read(&p->real_cred->user->processes) >= |
| 1037 | p->signal->rlim[RLIMIT_NPROC].rlim_cur) { | 1006 | task_rlimit(p, RLIMIT_NPROC)) { |
| 1038 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && | 1007 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && |
| 1039 | p->real_cred->user != INIT_USER) | 1008 | p->real_cred->user != INIT_USER) |
| 1040 | goto bad_fork_free; | 1009 | goto bad_fork_free; |
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index ecc3fa28f666..42ec11b2af8a 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c | |||
| @@ -18,11 +18,7 @@ | |||
| 18 | 18 | ||
| 19 | #include "internals.h" | 19 | #include "internals.h" |
| 20 | 20 | ||
| 21 | /** | 21 | static void dynamic_irq_init_x(unsigned int irq, bool keep_chip_data) |
| 22 | * dynamic_irq_init - initialize a dynamically allocated irq | ||
| 23 | * @irq: irq number to initialize | ||
| 24 | */ | ||
| 25 | void dynamic_irq_init(unsigned int irq) | ||
| 26 | { | 22 | { |
| 27 | struct irq_desc *desc; | 23 | struct irq_desc *desc; |
| 28 | unsigned long flags; | 24 | unsigned long flags; |
| @@ -41,7 +37,8 @@ void dynamic_irq_init(unsigned int irq) | |||
| 41 | desc->depth = 1; | 37 | desc->depth = 1; |
| 42 | desc->msi_desc = NULL; | 38 | desc->msi_desc = NULL; |
| 43 | desc->handler_data = NULL; | 39 | desc->handler_data = NULL; |
| 44 | desc->chip_data = NULL; | 40 | if (!keep_chip_data) |
| 41 | desc->chip_data = NULL; | ||
| 45 | desc->action = NULL; | 42 | desc->action = NULL; |
| 46 | desc->irq_count = 0; | 43 | desc->irq_count = 0; |
| 47 | desc->irqs_unhandled = 0; | 44 | desc->irqs_unhandled = 0; |
| @@ -55,10 +52,26 @@ void dynamic_irq_init(unsigned int irq) | |||
| 55 | } | 52 | } |
| 56 | 53 | ||
| 57 | /** | 54 | /** |
| 58 | * dynamic_irq_cleanup - cleanup a dynamically allocated irq | 55 | * dynamic_irq_init - initialize a dynamically allocated irq |
| 59 | * @irq: irq number to initialize | 56 | * @irq: irq number to initialize |
| 60 | */ | 57 | */ |
| 61 | void dynamic_irq_cleanup(unsigned int irq) | 58 | void dynamic_irq_init(unsigned int irq) |
| 59 | { | ||
| 60 | dynamic_irq_init_x(irq, false); | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 | * dynamic_irq_init_keep_chip_data - initialize a dynamically allocated irq | ||
| 65 | * @irq: irq number to initialize | ||
| 66 | * | ||
| 67 | * does not set irq_to_desc(irq)->chip_data to NULL | ||
| 68 | */ | ||
| 69 | void dynamic_irq_init_keep_chip_data(unsigned int irq) | ||
| 70 | { | ||
| 71 | dynamic_irq_init_x(irq, true); | ||
| 72 | } | ||
| 73 | |||
| 74 | static void dynamic_irq_cleanup_x(unsigned int irq, bool keep_chip_data) | ||
| 62 | { | 75 | { |
| 63 | struct irq_desc *desc = irq_to_desc(irq); | 76 | struct irq_desc *desc = irq_to_desc(irq); |
| 64 | unsigned long flags; | 77 | unsigned long flags; |
| @@ -77,7 +90,8 @@ void dynamic_irq_cleanup(unsigned int irq) | |||
| 77 | } | 90 | } |
| 78 | desc->msi_desc = NULL; | 91 | desc->msi_desc = NULL; |
| 79 | desc->handler_data = NULL; | 92 | desc->handler_data = NULL; |
| 80 | desc->chip_data = NULL; | 93 | if (!keep_chip_data) |
| 94 | desc->chip_data = NULL; | ||
| 81 | desc->handle_irq = handle_bad_irq; | 95 | desc->handle_irq = handle_bad_irq; |
| 82 | desc->chip = &no_irq_chip; | 96 | desc->chip = &no_irq_chip; |
| 83 | desc->name = NULL; | 97 | desc->name = NULL; |
| @@ -85,6 +99,26 @@ void dynamic_irq_cleanup(unsigned int irq) | |||
| 85 | raw_spin_unlock_irqrestore(&desc->lock, flags); | 99 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 86 | } | 100 | } |
| 87 | 101 | ||
| 102 | /** | ||
| 103 | * dynamic_irq_cleanup - cleanup a dynamically allocated irq | ||
| 104 | * @irq: irq number to initialize | ||
| 105 | */ | ||
| 106 | void dynamic_irq_cleanup(unsigned int irq) | ||
| 107 | { | ||
| 108 | dynamic_irq_cleanup_x(irq, false); | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * dynamic_irq_cleanup_keep_chip_data - cleanup a dynamically allocated irq | ||
| 113 | * @irq: irq number to initialize | ||
| 114 | * | ||
| 115 | * does not set irq_to_desc(irq)->chip_data to NULL | ||
| 116 | */ | ||
| 117 | void dynamic_irq_cleanup_keep_chip_data(unsigned int irq) | ||
| 118 | { | ||
| 119 | dynamic_irq_cleanup_x(irq, true); | ||
| 120 | } | ||
| 121 | |||
| 88 | 122 | ||
| 89 | /** | 123 | /** |
| 90 | * set_irq_chip - set the irq chip for an irq | 124 | * set_irq_chip - set the irq chip for an irq |
| @@ -520,7 +554,7 @@ out: | |||
| 520 | * signal. The occurence is latched into the irq controller hardware | 554 | * signal. The occurence is latched into the irq controller hardware |
| 521 | * and must be acked in order to be reenabled. After the ack another | 555 | * and must be acked in order to be reenabled. After the ack another |
| 522 | * interrupt can happen on the same source even before the first one | 556 | * interrupt can happen on the same source even before the first one |
| 523 | * is handled by the assosiacted event handler. If this happens it | 557 | * is handled by the associated event handler. If this happens it |
| 524 | * might be necessary to disable (mask) the interrupt depending on the | 558 | * might be necessary to disable (mask) the interrupt depending on the |
| 525 | * controller hardware. This requires to reenable the interrupt inside | 559 | * controller hardware. This requires to reenable the interrupt inside |
| 526 | * of the loop which handles the interrupts which have arrived while | 560 | * of the loop which handles the interrupts which have arrived while |
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c index d06df9c41cba..1ef4ffcdfa55 100644 --- a/kernel/irq/devres.c +++ b/kernel/irq/devres.c | |||
| @@ -42,7 +42,7 @@ static int devm_irq_match(struct device *dev, void *res, void *data) | |||
| 42 | * automatically freed on driver detach. | 42 | * automatically freed on driver detach. |
| 43 | * | 43 | * |
| 44 | * If an IRQ allocated with this function needs to be freed | 44 | * If an IRQ allocated with this function needs to be freed |
| 45 | * separately, dev_free_irq() must be used. | 45 | * separately, devm_free_irq() must be used. |
| 46 | */ | 46 | */ |
| 47 | int devm_request_threaded_irq(struct device *dev, unsigned int irq, | 47 | int devm_request_threaded_irq(struct device *dev, unsigned int irq, |
| 48 | irq_handler_t handler, irq_handler_t thread_fn, | 48 | irq_handler_t handler, irq_handler_t thread_fn, |
| @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_request_threaded_irq); | |||
| 81 | * Except for the extra @dev argument, this function takes the | 81 | * Except for the extra @dev argument, this function takes the |
| 82 | * same arguments and performs the same function as free_irq(). | 82 | * same arguments and performs the same function as free_irq(). |
| 83 | * This function instead of free_irq() should be used to manually | 83 | * This function instead of free_irq() should be used to manually |
| 84 | * free IRQs allocated with dev_request_irq(). | 84 | * free IRQs allocated with devm_request_irq(). |
| 85 | */ | 85 | */ |
| 86 | void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id) | 86 | void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id) |
| 87 | { | 87 | { |
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c index 814940e7f485..76d5a671bfe1 100644 --- a/kernel/irq/handle.c +++ b/kernel/irq/handle.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #include <linux/kernel_stat.h> | 19 | #include <linux/kernel_stat.h> |
| 20 | #include <linux/rculist.h> | 20 | #include <linux/rculist.h> |
| 21 | #include <linux/hash.h> | 21 | #include <linux/hash.h> |
| 22 | #include <linux/bootmem.h> | 22 | #include <linux/radix-tree.h> |
| 23 | #include <trace/events/irq.h> | 23 | #include <trace/events/irq.h> |
| 24 | 24 | ||
| 25 | #include "internals.h" | 25 | #include "internals.h" |
| @@ -87,12 +87,8 @@ void __ref init_kstat_irqs(struct irq_desc *desc, int node, int nr) | |||
| 87 | { | 87 | { |
| 88 | void *ptr; | 88 | void *ptr; |
| 89 | 89 | ||
| 90 | if (slab_is_available()) | 90 | ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), |
| 91 | ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), | 91 | GFP_ATOMIC, node); |
| 92 | GFP_ATOMIC, node); | ||
| 93 | else | ||
| 94 | ptr = alloc_bootmem_node(NODE_DATA(node), | ||
| 95 | nr * sizeof(*desc->kstat_irqs)); | ||
| 96 | 92 | ||
| 97 | /* | 93 | /* |
| 98 | * don't overwite if can not get new one | 94 | * don't overwite if can not get new one |
| @@ -132,7 +128,26 @@ static void init_one_irq_desc(int irq, struct irq_desc *desc, int node) | |||
| 132 | */ | 128 | */ |
| 133 | DEFINE_RAW_SPINLOCK(sparse_irq_lock); | 129 | DEFINE_RAW_SPINLOCK(sparse_irq_lock); |
| 134 | 130 | ||
| 135 | struct irq_desc **irq_desc_ptrs __read_mostly; | 131 | static RADIX_TREE(irq_desc_tree, GFP_ATOMIC); |
| 132 | |||
| 133 | static void set_irq_desc(unsigned int irq, struct irq_desc *desc) | ||
| 134 | { | ||
| 135 | radix_tree_insert(&irq_desc_tree, irq, desc); | ||
| 136 | } | ||
| 137 | |||
| 138 | struct irq_desc *irq_to_desc(unsigned int irq) | ||
| 139 | { | ||
| 140 | return radix_tree_lookup(&irq_desc_tree, irq); | ||
| 141 | } | ||
| 142 | |||
| 143 | void replace_irq_desc(unsigned int irq, struct irq_desc *desc) | ||
| 144 | { | ||
| 145 | void **ptr; | ||
| 146 | |||
| 147 | ptr = radix_tree_lookup_slot(&irq_desc_tree, irq); | ||
| 148 | if (ptr) | ||
| 149 | radix_tree_replace_slot(ptr, desc); | ||
| 150 | } | ||
| 136 | 151 | ||
| 137 | static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = { | 152 | static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = { |
| 138 | [0 ... NR_IRQS_LEGACY-1] = { | 153 | [0 ... NR_IRQS_LEGACY-1] = { |
| @@ -164,9 +179,6 @@ int __init early_irq_init(void) | |||
| 164 | legacy_count = ARRAY_SIZE(irq_desc_legacy); | 179 | legacy_count = ARRAY_SIZE(irq_desc_legacy); |
| 165 | node = first_online_node; | 180 | node = first_online_node; |
| 166 | 181 | ||
| 167 | /* allocate irq_desc_ptrs array based on nr_irqs */ | ||
| 168 | irq_desc_ptrs = kcalloc(nr_irqs, sizeof(void *), GFP_NOWAIT); | ||
| 169 | |||
| 170 | /* allocate based on nr_cpu_ids */ | 182 | /* allocate based on nr_cpu_ids */ |
| 171 | kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids * | 183 | kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids * |
| 172 | sizeof(int), GFP_NOWAIT, node); | 184 | sizeof(int), GFP_NOWAIT, node); |
| @@ -180,23 +192,12 @@ int __init early_irq_init(void) | |||
| 180 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); | 192 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); |
| 181 | alloc_desc_masks(&desc[i], node, true); | 193 | alloc_desc_masks(&desc[i], node, true); |
| 182 | init_desc_masks(&desc[i]); | 194 | init_desc_masks(&desc[i]); |
| 183 | irq_desc_ptrs[i] = desc + i; | 195 | set_irq_desc(i, &desc[i]); |
| 184 | } | 196 | } |
| 185 | 197 | ||
| 186 | for (i = legacy_count; i < nr_irqs; i++) | ||
| 187 | irq_desc_ptrs[i] = NULL; | ||
| 188 | |||
| 189 | return arch_early_irq_init(); | 198 | return arch_early_irq_init(); |
| 190 | } | 199 | } |
| 191 | 200 | ||
| 192 | struct irq_desc *irq_to_desc(unsigned int irq) | ||
| 193 | { | ||
| 194 | if (irq_desc_ptrs && irq < nr_irqs) | ||
| 195 | return irq_desc_ptrs[irq]; | ||
| 196 | |||
| 197 | return NULL; | ||
| 198 | } | ||
| 199 | |||
| 200 | struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) | 201 | struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) |
| 201 | { | 202 | { |
| 202 | struct irq_desc *desc; | 203 | struct irq_desc *desc; |
| @@ -208,21 +209,18 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) | |||
| 208 | return NULL; | 209 | return NULL; |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 211 | desc = irq_desc_ptrs[irq]; | 212 | desc = irq_to_desc(irq); |
| 212 | if (desc) | 213 | if (desc) |
| 213 | return desc; | 214 | return desc; |
| 214 | 215 | ||
| 215 | raw_spin_lock_irqsave(&sparse_irq_lock, flags); | 216 | raw_spin_lock_irqsave(&sparse_irq_lock, flags); |
| 216 | 217 | ||
| 217 | /* We have to check it to avoid races with another CPU */ | 218 | /* We have to check it to avoid races with another CPU */ |
| 218 | desc = irq_desc_ptrs[irq]; | 219 | desc = irq_to_desc(irq); |
| 219 | if (desc) | 220 | if (desc) |
| 220 | goto out_unlock; | 221 | goto out_unlock; |
| 221 | 222 | ||
| 222 | if (slab_is_available()) | 223 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); |
| 223 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); | ||
| 224 | else | ||
| 225 | desc = alloc_bootmem_node(NODE_DATA(node), sizeof(*desc)); | ||
| 226 | 224 | ||
| 227 | printk(KERN_DEBUG " alloc irq_desc for %d on node %d\n", irq, node); | 225 | printk(KERN_DEBUG " alloc irq_desc for %d on node %d\n", irq, node); |
| 228 | if (!desc) { | 226 | if (!desc) { |
| @@ -231,7 +229,7 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) | |||
| 231 | } | 229 | } |
| 232 | init_one_irq_desc(irq, desc, node); | 230 | init_one_irq_desc(irq, desc, node); |
| 233 | 231 | ||
| 234 | irq_desc_ptrs[irq] = desc; | 232 | set_irq_desc(irq, desc); |
| 235 | 233 | ||
| 236 | out_unlock: | 234 | out_unlock: |
| 237 | raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); | 235 | raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); |
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index b2821f070a3d..c63f3bc88f0b 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h | |||
| @@ -21,11 +21,7 @@ extern void clear_kstat_irqs(struct irq_desc *desc); | |||
| 21 | extern raw_spinlock_t sparse_irq_lock; | 21 | extern raw_spinlock_t sparse_irq_lock; |
| 22 | 22 | ||
| 23 | #ifdef CONFIG_SPARSE_IRQ | 23 | #ifdef CONFIG_SPARSE_IRQ |
| 24 | /* irq_desc_ptrs allocated at boot time */ | 24 | void replace_irq_desc(unsigned int irq, struct irq_desc *desc); |
| 25 | extern struct irq_desc **irq_desc_ptrs; | ||
| 26 | #else | ||
| 27 | /* irq_desc_ptrs is a fixed size array */ | ||
| 28 | extern struct irq_desc *irq_desc_ptrs[NR_IRQS]; | ||
| 29 | #endif | 25 | #endif |
| 30 | 26 | ||
| 31 | #ifdef CONFIG_PROC_FS | 27 | #ifdef CONFIG_PROC_FS |
diff --git a/kernel/irq/numa_migrate.c b/kernel/irq/numa_migrate.c index 26bac9d8f860..963559dbd858 100644 --- a/kernel/irq/numa_migrate.c +++ b/kernel/irq/numa_migrate.c | |||
| @@ -70,7 +70,7 @@ static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc, | |||
| 70 | raw_spin_lock_irqsave(&sparse_irq_lock, flags); | 70 | raw_spin_lock_irqsave(&sparse_irq_lock, flags); |
| 71 | 71 | ||
| 72 | /* We have to check it to avoid races with another CPU */ | 72 | /* We have to check it to avoid races with another CPU */ |
| 73 | desc = irq_desc_ptrs[irq]; | 73 | desc = irq_to_desc(irq); |
| 74 | 74 | ||
| 75 | if (desc && old_desc != desc) | 75 | if (desc && old_desc != desc) |
| 76 | goto out_unlock; | 76 | goto out_unlock; |
| @@ -90,7 +90,7 @@ static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc, | |||
| 90 | goto out_unlock; | 90 | goto out_unlock; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | irq_desc_ptrs[irq] = desc; | 93 | replace_irq_desc(irq, desc); |
| 94 | raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); | 94 | raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); |
| 95 | 95 | ||
| 96 | /* free the old one */ | 96 | /* free the old one */ |
diff --git a/kernel/kexec.c b/kernel/kexec.c index ef077fb73155..87ebe8adc474 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c | |||
| @@ -41,7 +41,7 @@ | |||
| 41 | #include <asm/sections.h> | 41 | #include <asm/sections.h> |
| 42 | 42 | ||
| 43 | /* Per cpu memory for storing cpu states in case of system crash. */ | 43 | /* Per cpu memory for storing cpu states in case of system crash. */ |
| 44 | note_buf_t* crash_notes; | 44 | note_buf_t __percpu *crash_notes; |
| 45 | 45 | ||
| 46 | /* vmcoreinfo stuff */ | 46 | /* vmcoreinfo stuff */ |
| 47 | static unsigned char vmcoreinfo_data[VMCOREINFO_BYTES]; | 47 | static unsigned char vmcoreinfo_data[VMCOREINFO_BYTES]; |
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index ccec774c716d..fa034d29cf73 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
| @@ -42,9 +42,11 @@ | |||
| 42 | #include <linux/freezer.h> | 42 | #include <linux/freezer.h> |
| 43 | #include <linux/seq_file.h> | 43 | #include <linux/seq_file.h> |
| 44 | #include <linux/debugfs.h> | 44 | #include <linux/debugfs.h> |
| 45 | #include <linux/sysctl.h> | ||
| 45 | #include <linux/kdebug.h> | 46 | #include <linux/kdebug.h> |
| 46 | #include <linux/memory.h> | 47 | #include <linux/memory.h> |
| 47 | #include <linux/ftrace.h> | 48 | #include <linux/ftrace.h> |
| 49 | #include <linux/cpu.h> | ||
| 48 | 50 | ||
| 49 | #include <asm-generic/sections.h> | 51 | #include <asm-generic/sections.h> |
| 50 | #include <asm/cacheflush.h> | 52 | #include <asm/cacheflush.h> |
| @@ -105,57 +107,74 @@ static struct kprobe_blackpoint kprobe_blacklist[] = { | |||
| 105 | * stepping on the instruction on a vmalloced/kmalloced/data page | 107 | * stepping on the instruction on a vmalloced/kmalloced/data page |
| 106 | * is a recipe for disaster | 108 | * is a recipe for disaster |
| 107 | */ | 109 | */ |
| 108 | #define INSNS_PER_PAGE (PAGE_SIZE/(MAX_INSN_SIZE * sizeof(kprobe_opcode_t))) | ||
| 109 | |||
| 110 | struct kprobe_insn_page { | 110 | struct kprobe_insn_page { |
| 111 | struct list_head list; | 111 | struct list_head list; |
| 112 | kprobe_opcode_t *insns; /* Page of instruction slots */ | 112 | kprobe_opcode_t *insns; /* Page of instruction slots */ |
| 113 | char slot_used[INSNS_PER_PAGE]; | ||
| 114 | int nused; | 113 | int nused; |
| 115 | int ngarbage; | 114 | int ngarbage; |
| 115 | char slot_used[]; | ||
| 116 | }; | ||
| 117 | |||
| 118 | #define KPROBE_INSN_PAGE_SIZE(slots) \ | ||
| 119 | (offsetof(struct kprobe_insn_page, slot_used) + \ | ||
| 120 | (sizeof(char) * (slots))) | ||
| 121 | |||
| 122 | struct kprobe_insn_cache { | ||
| 123 | struct list_head pages; /* list of kprobe_insn_page */ | ||
| 124 | size_t insn_size; /* size of instruction slot */ | ||
| 125 | int nr_garbage; | ||
| 116 | }; | 126 | }; |
| 117 | 127 | ||
| 128 | static int slots_per_page(struct kprobe_insn_cache *c) | ||
| 129 | { | ||
| 130 | return PAGE_SIZE/(c->insn_size * sizeof(kprobe_opcode_t)); | ||
| 131 | } | ||
| 132 | |||
| 118 | enum kprobe_slot_state { | 133 | enum kprobe_slot_state { |
| 119 | SLOT_CLEAN = 0, | 134 | SLOT_CLEAN = 0, |
| 120 | SLOT_DIRTY = 1, | 135 | SLOT_DIRTY = 1, |
| 121 | SLOT_USED = 2, | 136 | SLOT_USED = 2, |
| 122 | }; | 137 | }; |
| 123 | 138 | ||
| 124 | static DEFINE_MUTEX(kprobe_insn_mutex); /* Protects kprobe_insn_pages */ | 139 | static DEFINE_MUTEX(kprobe_insn_mutex); /* Protects kprobe_insn_slots */ |
| 125 | static LIST_HEAD(kprobe_insn_pages); | 140 | static struct kprobe_insn_cache kprobe_insn_slots = { |
| 126 | static int kprobe_garbage_slots; | 141 | .pages = LIST_HEAD_INIT(kprobe_insn_slots.pages), |
| 127 | static int collect_garbage_slots(void); | 142 | .insn_size = MAX_INSN_SIZE, |
| 143 | .nr_garbage = 0, | ||
| 144 | }; | ||
| 145 | static int __kprobes collect_garbage_slots(struct kprobe_insn_cache *c); | ||
| 128 | 146 | ||
| 129 | /** | 147 | /** |
| 130 | * __get_insn_slot() - Find a slot on an executable page for an instruction. | 148 | * __get_insn_slot() - Find a slot on an executable page for an instruction. |
| 131 | * We allocate an executable page if there's no room on existing ones. | 149 | * We allocate an executable page if there's no room on existing ones. |
| 132 | */ | 150 | */ |
| 133 | static kprobe_opcode_t __kprobes *__get_insn_slot(void) | 151 | static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c) |
| 134 | { | 152 | { |
| 135 | struct kprobe_insn_page *kip; | 153 | struct kprobe_insn_page *kip; |
| 136 | 154 | ||
| 137 | retry: | 155 | retry: |
| 138 | list_for_each_entry(kip, &kprobe_insn_pages, list) { | 156 | list_for_each_entry(kip, &c->pages, list) { |
| 139 | if (kip->nused < INSNS_PER_PAGE) { | 157 | if (kip->nused < slots_per_page(c)) { |
| 140 | int i; | 158 | int i; |
| 141 | for (i = 0; i < INSNS_PER_PAGE; i++) { | 159 | for (i = 0; i < slots_per_page(c); i++) { |
| 142 | if (kip->slot_used[i] == SLOT_CLEAN) { | 160 | if (kip->slot_used[i] == SLOT_CLEAN) { |
| 143 | kip->slot_used[i] = SLOT_USED; | 161 | kip->slot_used[i] = SLOT_USED; |
| 144 | kip->nused++; | 162 | kip->nused++; |
| 145 | return kip->insns + (i * MAX_INSN_SIZE); | 163 | return kip->insns + (i * c->insn_size); |
| 146 | } | 164 | } |
| 147 | } | 165 | } |
| 148 | /* Surprise! No unused slots. Fix kip->nused. */ | 166 | /* kip->nused is broken. Fix it. */ |
| 149 | kip->nused = INSNS_PER_PAGE; | 167 | kip->nused = slots_per_page(c); |
| 168 | WARN_ON(1); | ||
| 150 | } | 169 | } |
| 151 | } | 170 | } |
| 152 | 171 | ||
| 153 | /* If there are any garbage slots, collect it and try again. */ | 172 | /* If there are any garbage slots, collect it and try again. */ |
| 154 | if (kprobe_garbage_slots && collect_garbage_slots() == 0) { | 173 | if (c->nr_garbage && collect_garbage_slots(c) == 0) |
| 155 | goto retry; | 174 | goto retry; |
| 156 | } | 175 | |
| 157 | /* All out of space. Need to allocate a new page. Use slot 0. */ | 176 | /* All out of space. Need to allocate a new page. */ |
| 158 | kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL); | 177 | kip = kmalloc(KPROBE_INSN_PAGE_SIZE(slots_per_page(c)), GFP_KERNEL); |
| 159 | if (!kip) | 178 | if (!kip) |
| 160 | return NULL; | 179 | return NULL; |
| 161 | 180 | ||
| @@ -170,20 +189,23 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void) | |||
| 170 | return NULL; | 189 | return NULL; |
| 171 | } | 190 | } |
| 172 | INIT_LIST_HEAD(&kip->list); | 191 | INIT_LIST_HEAD(&kip->list); |
| 173 | list_add(&kip->list, &kprobe_insn_pages); | 192 | memset(kip->slot_used, SLOT_CLEAN, slots_per_page(c)); |
| 174 | memset(kip->slot_used, SLOT_CLEAN, INSNS_PER_PAGE); | ||
| 175 | kip->slot_used[0] = SLOT_USED; | 193 | kip->slot_used[0] = SLOT_USED; |
| 176 | kip->nused = 1; | 194 | kip->nused = 1; |
| 177 | kip->ngarbage = 0; | 195 | kip->ngarbage = 0; |
| 196 | list_add(&kip->list, &c->pages); | ||
| 178 | return kip->insns; | 197 | return kip->insns; |
| 179 | } | 198 | } |
| 180 | 199 | ||
| 200 | |||
| 181 | kprobe_opcode_t __kprobes *get_insn_slot(void) | 201 | kprobe_opcode_t __kprobes *get_insn_slot(void) |
| 182 | { | 202 | { |
| 183 | kprobe_opcode_t *ret; | 203 | kprobe_opcode_t *ret = NULL; |
| 204 | |||
| 184 | mutex_lock(&kprobe_insn_mutex); | 205 | mutex_lock(&kprobe_insn_mutex); |
| 185 | ret = __get_insn_slot(); | 206 | ret = __get_insn_slot(&kprobe_insn_slots); |
| 186 | mutex_unlock(&kprobe_insn_mutex); | 207 | mutex_unlock(&kprobe_insn_mutex); |
| 208 | |||
| 187 | return ret; | 209 | return ret; |
| 188 | } | 210 | } |
| 189 | 211 | ||
| @@ -199,7 +221,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx) | |||
| 199 | * so as not to have to set it up again the | 221 | * so as not to have to set it up again the |
| 200 | * next time somebody inserts a probe. | 222 | * next time somebody inserts a probe. |
| 201 | */ | 223 | */ |
| 202 | if (!list_is_singular(&kprobe_insn_pages)) { | 224 | if (!list_is_singular(&kip->list)) { |
| 203 | list_del(&kip->list); | 225 | list_del(&kip->list); |
| 204 | module_free(NULL, kip->insns); | 226 | module_free(NULL, kip->insns); |
| 205 | kfree(kip); | 227 | kfree(kip); |
| @@ -209,51 +231,84 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx) | |||
| 209 | return 0; | 231 | return 0; |
| 210 | } | 232 | } |
| 211 | 233 | ||
| 212 | static int __kprobes collect_garbage_slots(void) | 234 | static int __kprobes collect_garbage_slots(struct kprobe_insn_cache *c) |
| 213 | { | 235 | { |
| 214 | struct kprobe_insn_page *kip, *next; | 236 | struct kprobe_insn_page *kip, *next; |
| 215 | 237 | ||
| 216 | /* Ensure no-one is interrupted on the garbages */ | 238 | /* Ensure no-one is interrupted on the garbages */ |
| 217 | synchronize_sched(); | 239 | synchronize_sched(); |
| 218 | 240 | ||
| 219 | list_for_each_entry_safe(kip, next, &kprobe_insn_pages, list) { | 241 | list_for_each_entry_safe(kip, next, &c->pages, list) { |
| 220 | int i; | 242 | int i; |
| 221 | if (kip->ngarbage == 0) | 243 | if (kip->ngarbage == 0) |
| 222 | continue; | 244 | continue; |
| 223 | kip->ngarbage = 0; /* we will collect all garbages */ | 245 | kip->ngarbage = 0; /* we will collect all garbages */ |
| 224 | for (i = 0; i < INSNS_PER_PAGE; i++) { | 246 | for (i = 0; i < slots_per_page(c); i++) { |
| 225 | if (kip->slot_used[i] == SLOT_DIRTY && | 247 | if (kip->slot_used[i] == SLOT_DIRTY && |
| 226 | collect_one_slot(kip, i)) | 248 | collect_one_slot(kip, i)) |
| 227 | break; | 249 | break; |
| 228 | } | 250 | } |
| 229 | } | 251 | } |
| 230 | kprobe_garbage_slots = 0; | 252 | c->nr_garbage = 0; |
| 231 | return 0; | 253 | return 0; |
| 232 | } | 254 | } |
| 233 | 255 | ||
| 234 | void __kprobes free_insn_slot(kprobe_opcode_t * slot, int dirty) | 256 | static void __kprobes __free_insn_slot(struct kprobe_insn_cache *c, |
| 257 | kprobe_opcode_t *slot, int dirty) | ||
| 235 | { | 258 | { |
| 236 | struct kprobe_insn_page *kip; | 259 | struct kprobe_insn_page *kip; |
| 237 | 260 | ||
| 238 | mutex_lock(&kprobe_insn_mutex); | 261 | list_for_each_entry(kip, &c->pages, list) { |
| 239 | list_for_each_entry(kip, &kprobe_insn_pages, list) { | 262 | long idx = ((long)slot - (long)kip->insns) / c->insn_size; |
| 240 | if (kip->insns <= slot && | 263 | if (idx >= 0 && idx < slots_per_page(c)) { |
| 241 | slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) { | 264 | WARN_ON(kip->slot_used[idx] != SLOT_USED); |
| 242 | int i = (slot - kip->insns) / MAX_INSN_SIZE; | ||
| 243 | if (dirty) { | 265 | if (dirty) { |
| 244 | kip->slot_used[i] = SLOT_DIRTY; | 266 | kip->slot_used[idx] = SLOT_DIRTY; |
| 245 | kip->ngarbage++; | 267 | kip->ngarbage++; |
| 268 | if (++c->nr_garbage > slots_per_page(c)) | ||
| 269 | collect_garbage_slots(c); | ||
| 246 | } else | 270 | } else |
| 247 | collect_one_slot(kip, i); | 271 | collect_one_slot(kip, idx); |
| 248 | break; | 272 | return; |
| 249 | } | 273 | } |
| 250 | } | 274 | } |
| 275 | /* Could not free this slot. */ | ||
| 276 | WARN_ON(1); | ||
| 277 | } | ||
| 251 | 278 | ||
| 252 | if (dirty && ++kprobe_garbage_slots > INSNS_PER_PAGE) | 279 | void __kprobes free_insn_slot(kprobe_opcode_t * slot, int dirty) |
| 253 | collect_garbage_slots(); | 280 | { |
| 254 | 281 | mutex_lock(&kprobe_insn_mutex); | |
| 282 | __free_insn_slot(&kprobe_insn_slots, slot, dirty); | ||
| 255 | mutex_unlock(&kprobe_insn_mutex); | 283 | mutex_unlock(&kprobe_insn_mutex); |
| 256 | } | 284 | } |
| 285 | #ifdef CONFIG_OPTPROBES | ||
| 286 | /* For optimized_kprobe buffer */ | ||
| 287 | static DEFINE_MUTEX(kprobe_optinsn_mutex); /* Protects kprobe_optinsn_slots */ | ||
| 288 | static struct kprobe_insn_cache kprobe_optinsn_slots = { | ||
| 289 | .pages = LIST_HEAD_INIT(kprobe_optinsn_slots.pages), | ||
| 290 | /* .insn_size is initialized later */ | ||
| 291 | .nr_garbage = 0, | ||
| 292 | }; | ||
| 293 | /* Get a slot for optimized_kprobe buffer */ | ||
| 294 | kprobe_opcode_t __kprobes *get_optinsn_slot(void) | ||
| 295 | { | ||
| 296 | kprobe_opcode_t *ret = NULL; | ||
| 297 | |||
| 298 | mutex_lock(&kprobe_optinsn_mutex); | ||
| 299 | ret = __get_insn_slot(&kprobe_optinsn_slots); | ||
| 300 | mutex_unlock(&kprobe_optinsn_mutex); | ||
| 301 | |||
| 302 | return ret; | ||
| 303 | } | ||
| 304 | |||
| 305 | void __kprobes free_optinsn_slot(kprobe_opcode_t * slot, int dirty) | ||
| 306 | { | ||
| 307 | mutex_lock(&kprobe_optinsn_mutex); | ||
| 308 | __free_insn_slot(&kprobe_optinsn_slots, slot, dirty); | ||
| 309 | mutex_unlock(&kprobe_optinsn_mutex); | ||
| 310 | } | ||
| 311 | #endif | ||
| 257 | #endif | 312 | #endif |
| 258 | 313 | ||
| 259 | /* We have preemption disabled.. so it is safe to use __ versions */ | 314 | /* We have preemption disabled.. so it is safe to use __ versions */ |
| @@ -284,23 +339,401 @@ struct kprobe __kprobes *get_kprobe(void *addr) | |||
| 284 | if (p->addr == addr) | 339 | if (p->addr == addr) |
| 285 | return p; | 340 | return p; |
| 286 | } | 341 | } |
| 342 | |||
| 343 | return NULL; | ||
| 344 | } | ||
| 345 | |||
| 346 | static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs); | ||
| 347 | |||
| 348 | /* Return true if the kprobe is an aggregator */ | ||
| 349 | static inline int kprobe_aggrprobe(struct kprobe *p) | ||
| 350 | { | ||
| 351 | return p->pre_handler == aggr_pre_handler; | ||
| 352 | } | ||
| 353 | |||
| 354 | /* | ||
| 355 | * Keep all fields in the kprobe consistent | ||
| 356 | */ | ||
| 357 | static inline void copy_kprobe(struct kprobe *old_p, struct kprobe *p) | ||
| 358 | { | ||
| 359 | memcpy(&p->opcode, &old_p->opcode, sizeof(kprobe_opcode_t)); | ||
| 360 | memcpy(&p->ainsn, &old_p->ainsn, sizeof(struct arch_specific_insn)); | ||
| 361 | } | ||
| 362 | |||
| 363 | #ifdef CONFIG_OPTPROBES | ||
| 364 | /* NOTE: change this value only with kprobe_mutex held */ | ||
| 365 | static bool kprobes_allow_optimization; | ||
| 366 | |||
| 367 | /* | ||
| 368 | * Call all pre_handler on the list, but ignores its return value. | ||
| 369 | * This must be called from arch-dep optimized caller. | ||
| 370 | */ | ||
| 371 | void __kprobes opt_pre_handler(struct kprobe *p, struct pt_regs *regs) | ||
| 372 | { | ||
| 373 | struct kprobe *kp; | ||
| 374 | |||
| 375 | list_for_each_entry_rcu(kp, &p->list, list) { | ||
| 376 | if (kp->pre_handler && likely(!kprobe_disabled(kp))) { | ||
| 377 | set_kprobe_instance(kp); | ||
| 378 | kp->pre_handler(kp, regs); | ||
| 379 | } | ||
| 380 | reset_kprobe_instance(); | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | /* Return true(!0) if the kprobe is ready for optimization. */ | ||
| 385 | static inline int kprobe_optready(struct kprobe *p) | ||
| 386 | { | ||
| 387 | struct optimized_kprobe *op; | ||
| 388 | |||
| 389 | if (kprobe_aggrprobe(p)) { | ||
| 390 | op = container_of(p, struct optimized_kprobe, kp); | ||
| 391 | return arch_prepared_optinsn(&op->optinsn); | ||
| 392 | } | ||
| 393 | |||
| 394 | return 0; | ||
| 395 | } | ||
| 396 | |||
| 397 | /* | ||
| 398 | * Return an optimized kprobe whose optimizing code replaces | ||
| 399 | * instructions including addr (exclude breakpoint). | ||
| 400 | */ | ||
| 401 | struct kprobe *__kprobes get_optimized_kprobe(unsigned long addr) | ||
| 402 | { | ||
| 403 | int i; | ||
| 404 | struct kprobe *p = NULL; | ||
| 405 | struct optimized_kprobe *op; | ||
| 406 | |||
| 407 | /* Don't check i == 0, since that is a breakpoint case. */ | ||
| 408 | for (i = 1; !p && i < MAX_OPTIMIZED_LENGTH; i++) | ||
| 409 | p = get_kprobe((void *)(addr - i)); | ||
| 410 | |||
| 411 | if (p && kprobe_optready(p)) { | ||
| 412 | op = container_of(p, struct optimized_kprobe, kp); | ||
| 413 | if (arch_within_optimized_kprobe(op, addr)) | ||
| 414 | return p; | ||
| 415 | } | ||
| 416 | |||
| 287 | return NULL; | 417 | return NULL; |
| 288 | } | 418 | } |
| 289 | 419 | ||
| 420 | /* Optimization staging list, protected by kprobe_mutex */ | ||
| 421 | static LIST_HEAD(optimizing_list); | ||
| 422 | |||
| 423 | static void kprobe_optimizer(struct work_struct *work); | ||
| 424 | static DECLARE_DELAYED_WORK(optimizing_work, kprobe_optimizer); | ||
| 425 | #define OPTIMIZE_DELAY 5 | ||
| 426 | |||
| 427 | /* Kprobe jump optimizer */ | ||
| 428 | static __kprobes void kprobe_optimizer(struct work_struct *work) | ||
| 429 | { | ||
| 430 | struct optimized_kprobe *op, *tmp; | ||
| 431 | |||
| 432 | /* Lock modules while optimizing kprobes */ | ||
| 433 | mutex_lock(&module_mutex); | ||
| 434 | mutex_lock(&kprobe_mutex); | ||
| 435 | if (kprobes_all_disarmed || !kprobes_allow_optimization) | ||
| 436 | goto end; | ||
| 437 | |||
| 438 | /* | ||
| 439 | * Wait for quiesence period to ensure all running interrupts | ||
| 440 | * are done. Because optprobe may modify multiple instructions | ||
| 441 | * there is a chance that Nth instruction is interrupted. In that | ||
| 442 | * case, running interrupt can return to 2nd-Nth byte of jump | ||
| 443 | * instruction. This wait is for avoiding it. | ||
| 444 | */ | ||
| 445 | synchronize_sched(); | ||
| 446 | |||
| 447 | /* | ||
| 448 | * The optimization/unoptimization refers online_cpus via | ||
| 449 | * stop_machine() and cpu-hotplug modifies online_cpus. | ||
| 450 | * And same time, text_mutex will be held in cpu-hotplug and here. | ||
| 451 | * This combination can cause a deadlock (cpu-hotplug try to lock | ||
| 452 | * text_mutex but stop_machine can not be done because online_cpus | ||
| 453 | * has been changed) | ||
| 454 | * To avoid this deadlock, we need to call get_online_cpus() | ||
| 455 | * for preventing cpu-hotplug outside of text_mutex locking. | ||
| 456 | */ | ||
| 457 | get_online_cpus(); | ||
| 458 | mutex_lock(&text_mutex); | ||
| 459 | list_for_each_entry_safe(op, tmp, &optimizing_list, list) { | ||
| 460 | WARN_ON(kprobe_disabled(&op->kp)); | ||
| 461 | if (arch_optimize_kprobe(op) < 0) | ||
| 462 | op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; | ||
| 463 | list_del_init(&op->list); | ||
| 464 | } | ||
| 465 | mutex_unlock(&text_mutex); | ||
| 466 | put_online_cpus(); | ||
| 467 | end: | ||
| 468 | mutex_unlock(&kprobe_mutex); | ||
| 469 | mutex_unlock(&module_mutex); | ||
| 470 | } | ||
| 471 | |||
| 472 | /* Optimize kprobe if p is ready to be optimized */ | ||
| 473 | static __kprobes void optimize_kprobe(struct kprobe *p) | ||
| 474 | { | ||
| 475 | struct optimized_kprobe *op; | ||
| 476 | |||
| 477 | /* Check if the kprobe is disabled or not ready for optimization. */ | ||
| 478 | if (!kprobe_optready(p) || !kprobes_allow_optimization || | ||
| 479 | (kprobe_disabled(p) || kprobes_all_disarmed)) | ||
| 480 | return; | ||
| 481 | |||
| 482 | /* Both of break_handler and post_handler are not supported. */ | ||
| 483 | if (p->break_handler || p->post_handler) | ||
| 484 | return; | ||
| 485 | |||
| 486 | op = container_of(p, struct optimized_kprobe, kp); | ||
| 487 | |||
| 488 | /* Check there is no other kprobes at the optimized instructions */ | ||
| 489 | if (arch_check_optimized_kprobe(op) < 0) | ||
| 490 | return; | ||
| 491 | |||
| 492 | /* Check if it is already optimized. */ | ||
| 493 | if (op->kp.flags & KPROBE_FLAG_OPTIMIZED) | ||
| 494 | return; | ||
| 495 | |||
| 496 | op->kp.flags |= KPROBE_FLAG_OPTIMIZED; | ||
| 497 | list_add(&op->list, &optimizing_list); | ||
| 498 | if (!delayed_work_pending(&optimizing_work)) | ||
| 499 | schedule_delayed_work(&optimizing_work, OPTIMIZE_DELAY); | ||
| 500 | } | ||
| 501 | |||
| 502 | /* Unoptimize a kprobe if p is optimized */ | ||
| 503 | static __kprobes void unoptimize_kprobe(struct kprobe *p) | ||
| 504 | { | ||
| 505 | struct optimized_kprobe *op; | ||
| 506 | |||
| 507 | if ((p->flags & KPROBE_FLAG_OPTIMIZED) && kprobe_aggrprobe(p)) { | ||
| 508 | op = container_of(p, struct optimized_kprobe, kp); | ||
| 509 | if (!list_empty(&op->list)) | ||
| 510 | /* Dequeue from the optimization queue */ | ||
| 511 | list_del_init(&op->list); | ||
| 512 | else | ||
| 513 | /* Replace jump with break */ | ||
| 514 | arch_unoptimize_kprobe(op); | ||
| 515 | op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; | ||
| 516 | } | ||
| 517 | } | ||
| 518 | |||
| 519 | /* Remove optimized instructions */ | ||
| 520 | static void __kprobes kill_optimized_kprobe(struct kprobe *p) | ||
| 521 | { | ||
| 522 | struct optimized_kprobe *op; | ||
| 523 | |||
| 524 | op = container_of(p, struct optimized_kprobe, kp); | ||
| 525 | if (!list_empty(&op->list)) { | ||
| 526 | /* Dequeue from the optimization queue */ | ||
| 527 | list_del_init(&op->list); | ||
| 528 | op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; | ||
| 529 | } | ||
| 530 | /* Don't unoptimize, because the target code will be freed. */ | ||
| 531 | arch_remove_optimized_kprobe(op); | ||
| 532 | } | ||
| 533 | |||
| 534 | /* Try to prepare optimized instructions */ | ||
| 535 | static __kprobes void prepare_optimized_kprobe(struct kprobe *p) | ||
| 536 | { | ||
| 537 | struct optimized_kprobe *op; | ||
| 538 | |||
| 539 | op = container_of(p, struct optimized_kprobe, kp); | ||
| 540 | arch_prepare_optimized_kprobe(op); | ||
| 541 | } | ||
| 542 | |||
| 543 | /* Free optimized instructions and optimized_kprobe */ | ||
| 544 | static __kprobes void free_aggr_kprobe(struct kprobe *p) | ||
| 545 | { | ||
| 546 | struct optimized_kprobe *op; | ||
| 547 | |||
| 548 | op = container_of(p, struct optimized_kprobe, kp); | ||
| 549 | arch_remove_optimized_kprobe(op); | ||
| 550 | kfree(op); | ||
| 551 | } | ||
| 552 | |||
| 553 | /* Allocate new optimized_kprobe and try to prepare optimized instructions */ | ||
| 554 | static __kprobes struct kprobe *alloc_aggr_kprobe(struct kprobe *p) | ||
| 555 | { | ||
| 556 | struct optimized_kprobe *op; | ||
| 557 | |||
| 558 | op = kzalloc(sizeof(struct optimized_kprobe), GFP_KERNEL); | ||
| 559 | if (!op) | ||
| 560 | return NULL; | ||
| 561 | |||
| 562 | INIT_LIST_HEAD(&op->list); | ||
| 563 | op->kp.addr = p->addr; | ||
| 564 | arch_prepare_optimized_kprobe(op); | ||
| 565 | |||
| 566 | return &op->kp; | ||
| 567 | } | ||
| 568 | |||
| 569 | static void __kprobes init_aggr_kprobe(struct kprobe *ap, struct kprobe *p); | ||
| 570 | |||
| 571 | /* | ||
| 572 | * Prepare an optimized_kprobe and optimize it | ||
| 573 | * NOTE: p must be a normal registered kprobe | ||
| 574 | */ | ||
| 575 | static __kprobes void try_to_optimize_kprobe(struct kprobe *p) | ||
| 576 | { | ||
| 577 | struct kprobe *ap; | ||
| 578 | struct optimized_kprobe *op; | ||
| 579 | |||
| 580 | ap = alloc_aggr_kprobe(p); | ||
| 581 | if (!ap) | ||
| 582 | return; | ||
| 583 | |||
| 584 | op = container_of(ap, struct optimized_kprobe, kp); | ||
| 585 | if (!arch_prepared_optinsn(&op->optinsn)) { | ||
| 586 | /* If failed to setup optimizing, fallback to kprobe */ | ||
| 587 | free_aggr_kprobe(ap); | ||
| 588 | return; | ||
| 589 | } | ||
| 590 | |||
| 591 | init_aggr_kprobe(ap, p); | ||
| 592 | optimize_kprobe(ap); | ||
| 593 | } | ||
| 594 | |||
| 595 | #ifdef CONFIG_SYSCTL | ||
| 596 | static void __kprobes optimize_all_kprobes(void) | ||
| 597 | { | ||
| 598 | struct hlist_head *head; | ||
| 599 | struct hlist_node *node; | ||
| 600 | struct kprobe *p; | ||
| 601 | unsigned int i; | ||
| 602 | |||
| 603 | /* If optimization is already allowed, just return */ | ||
| 604 | if (kprobes_allow_optimization) | ||
| 605 | return; | ||
| 606 | |||
| 607 | kprobes_allow_optimization = true; | ||
| 608 | mutex_lock(&text_mutex); | ||
| 609 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | ||
| 610 | head = &kprobe_table[i]; | ||
| 611 | hlist_for_each_entry_rcu(p, node, head, hlist) | ||
| 612 | if (!kprobe_disabled(p)) | ||
| 613 | optimize_kprobe(p); | ||
| 614 | } | ||
| 615 | mutex_unlock(&text_mutex); | ||
| 616 | printk(KERN_INFO "Kprobes globally optimized\n"); | ||
| 617 | } | ||
| 618 | |||
| 619 | static void __kprobes unoptimize_all_kprobes(void) | ||
| 620 | { | ||
| 621 | struct hlist_head *head; | ||
| 622 | struct hlist_node *node; | ||
| 623 | struct kprobe *p; | ||
| 624 | unsigned int i; | ||
| 625 | |||
| 626 | /* If optimization is already prohibited, just return */ | ||
| 627 | if (!kprobes_allow_optimization) | ||
| 628 | return; | ||
| 629 | |||
| 630 | kprobes_allow_optimization = false; | ||
| 631 | printk(KERN_INFO "Kprobes globally unoptimized\n"); | ||
| 632 | get_online_cpus(); /* For avoiding text_mutex deadlock */ | ||
| 633 | mutex_lock(&text_mutex); | ||
| 634 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | ||
| 635 | head = &kprobe_table[i]; | ||
| 636 | hlist_for_each_entry_rcu(p, node, head, hlist) { | ||
| 637 | if (!kprobe_disabled(p)) | ||
| 638 | unoptimize_kprobe(p); | ||
| 639 | } | ||
| 640 | } | ||
| 641 | |||
| 642 | mutex_unlock(&text_mutex); | ||
| 643 | put_online_cpus(); | ||
| 644 | /* Allow all currently running kprobes to complete */ | ||
| 645 | synchronize_sched(); | ||
| 646 | } | ||
| 647 | |||
| 648 | int sysctl_kprobes_optimization; | ||
| 649 | int proc_kprobes_optimization_handler(struct ctl_table *table, int write, | ||
| 650 | void __user *buffer, size_t *length, | ||
| 651 | loff_t *ppos) | ||
| 652 | { | ||
| 653 | int ret; | ||
| 654 | |||
| 655 | mutex_lock(&kprobe_mutex); | ||
| 656 | sysctl_kprobes_optimization = kprobes_allow_optimization ? 1 : 0; | ||
| 657 | ret = proc_dointvec_minmax(table, write, buffer, length, ppos); | ||
| 658 | |||
| 659 | if (sysctl_kprobes_optimization) | ||
| 660 | optimize_all_kprobes(); | ||
| 661 | else | ||
| 662 | unoptimize_all_kprobes(); | ||
| 663 | mutex_unlock(&kprobe_mutex); | ||
| 664 | |||
| 665 | return ret; | ||
| 666 | } | ||
| 667 | #endif /* CONFIG_SYSCTL */ | ||
| 668 | |||
| 669 | static void __kprobes __arm_kprobe(struct kprobe *p) | ||
| 670 | { | ||
| 671 | struct kprobe *old_p; | ||
| 672 | |||
| 673 | /* Check collision with other optimized kprobes */ | ||
| 674 | old_p = get_optimized_kprobe((unsigned long)p->addr); | ||
| 675 | if (unlikely(old_p)) | ||
| 676 | unoptimize_kprobe(old_p); /* Fallback to unoptimized kprobe */ | ||
| 677 | |||
| 678 | arch_arm_kprobe(p); | ||
| 679 | optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */ | ||
| 680 | } | ||
| 681 | |||
| 682 | static void __kprobes __disarm_kprobe(struct kprobe *p) | ||
| 683 | { | ||
| 684 | struct kprobe *old_p; | ||
| 685 | |||
| 686 | unoptimize_kprobe(p); /* Try to unoptimize */ | ||
| 687 | arch_disarm_kprobe(p); | ||
| 688 | |||
| 689 | /* If another kprobe was blocked, optimize it. */ | ||
| 690 | old_p = get_optimized_kprobe((unsigned long)p->addr); | ||
| 691 | if (unlikely(old_p)) | ||
| 692 | optimize_kprobe(old_p); | ||
| 693 | } | ||
| 694 | |||
| 695 | #else /* !CONFIG_OPTPROBES */ | ||
| 696 | |||
| 697 | #define optimize_kprobe(p) do {} while (0) | ||
| 698 | #define unoptimize_kprobe(p) do {} while (0) | ||
| 699 | #define kill_optimized_kprobe(p) do {} while (0) | ||
| 700 | #define prepare_optimized_kprobe(p) do {} while (0) | ||
| 701 | #define try_to_optimize_kprobe(p) do {} while (0) | ||
| 702 | #define __arm_kprobe(p) arch_arm_kprobe(p) | ||
| 703 | #define __disarm_kprobe(p) arch_disarm_kprobe(p) | ||
| 704 | |||
| 705 | static __kprobes void free_aggr_kprobe(struct kprobe *p) | ||
| 706 | { | ||
| 707 | kfree(p); | ||
| 708 | } | ||
| 709 | |||
| 710 | static __kprobes struct kprobe *alloc_aggr_kprobe(struct kprobe *p) | ||
| 711 | { | ||
| 712 | return kzalloc(sizeof(struct kprobe), GFP_KERNEL); | ||
| 713 | } | ||
| 714 | #endif /* CONFIG_OPTPROBES */ | ||
| 715 | |||
| 290 | /* Arm a kprobe with text_mutex */ | 716 | /* Arm a kprobe with text_mutex */ |
| 291 | static void __kprobes arm_kprobe(struct kprobe *kp) | 717 | static void __kprobes arm_kprobe(struct kprobe *kp) |
| 292 | { | 718 | { |
| 719 | /* | ||
| 720 | * Here, since __arm_kprobe() doesn't use stop_machine(), | ||
| 721 | * this doesn't cause deadlock on text_mutex. So, we don't | ||
| 722 | * need get_online_cpus(). | ||
| 723 | */ | ||
| 293 | mutex_lock(&text_mutex); | 724 | mutex_lock(&text_mutex); |
| 294 | arch_arm_kprobe(kp); | 725 | __arm_kprobe(kp); |
| 295 | mutex_unlock(&text_mutex); | 726 | mutex_unlock(&text_mutex); |
| 296 | } | 727 | } |
| 297 | 728 | ||
| 298 | /* Disarm a kprobe with text_mutex */ | 729 | /* Disarm a kprobe with text_mutex */ |
| 299 | static void __kprobes disarm_kprobe(struct kprobe *kp) | 730 | static void __kprobes disarm_kprobe(struct kprobe *kp) |
| 300 | { | 731 | { |
| 732 | get_online_cpus(); /* For avoiding text_mutex deadlock */ | ||
| 301 | mutex_lock(&text_mutex); | 733 | mutex_lock(&text_mutex); |
| 302 | arch_disarm_kprobe(kp); | 734 | __disarm_kprobe(kp); |
| 303 | mutex_unlock(&text_mutex); | 735 | mutex_unlock(&text_mutex); |
| 736 | put_online_cpus(); | ||
| 304 | } | 737 | } |
| 305 | 738 | ||
| 306 | /* | 739 | /* |
| @@ -369,7 +802,7 @@ static int __kprobes aggr_break_handler(struct kprobe *p, struct pt_regs *regs) | |||
| 369 | void __kprobes kprobes_inc_nmissed_count(struct kprobe *p) | 802 | void __kprobes kprobes_inc_nmissed_count(struct kprobe *p) |
| 370 | { | 803 | { |
| 371 | struct kprobe *kp; | 804 | struct kprobe *kp; |
| 372 | if (p->pre_handler != aggr_pre_handler) { | 805 | if (!kprobe_aggrprobe(p)) { |
| 373 | p->nmissed++; | 806 | p->nmissed++; |
| 374 | } else { | 807 | } else { |
| 375 | list_for_each_entry_rcu(kp, &p->list, list) | 808 | list_for_each_entry_rcu(kp, &p->list, list) |
| @@ -493,21 +926,16 @@ static void __kprobes cleanup_rp_inst(struct kretprobe *rp) | |||
| 493 | } | 926 | } |
| 494 | 927 | ||
| 495 | /* | 928 | /* |
| 496 | * Keep all fields in the kprobe consistent | ||
| 497 | */ | ||
| 498 | static inline void copy_kprobe(struct kprobe *old_p, struct kprobe *p) | ||
| 499 | { | ||
| 500 | memcpy(&p->opcode, &old_p->opcode, sizeof(kprobe_opcode_t)); | ||
| 501 | memcpy(&p->ainsn, &old_p->ainsn, sizeof(struct arch_specific_insn)); | ||
| 502 | } | ||
| 503 | |||
| 504 | /* | ||
| 505 | * Add the new probe to ap->list. Fail if this is the | 929 | * Add the new probe to ap->list. Fail if this is the |
| 506 | * second jprobe at the address - two jprobes can't coexist | 930 | * second jprobe at the address - two jprobes can't coexist |
| 507 | */ | 931 | */ |
| 508 | static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) | 932 | static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) |
| 509 | { | 933 | { |
| 510 | BUG_ON(kprobe_gone(ap) || kprobe_gone(p)); | 934 | BUG_ON(kprobe_gone(ap) || kprobe_gone(p)); |
| 935 | |||
| 936 | if (p->break_handler || p->post_handler) | ||
| 937 | unoptimize_kprobe(ap); /* Fall back to normal kprobe */ | ||
| 938 | |||
| 511 | if (p->break_handler) { | 939 | if (p->break_handler) { |
| 512 | if (ap->break_handler) | 940 | if (ap->break_handler) |
| 513 | return -EEXIST; | 941 | return -EEXIST; |
| @@ -522,7 +950,7 @@ static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) | |||
| 522 | ap->flags &= ~KPROBE_FLAG_DISABLED; | 950 | ap->flags &= ~KPROBE_FLAG_DISABLED; |
| 523 | if (!kprobes_all_disarmed) | 951 | if (!kprobes_all_disarmed) |
| 524 | /* Arm the breakpoint again. */ | 952 | /* Arm the breakpoint again. */ |
| 525 | arm_kprobe(ap); | 953 | __arm_kprobe(ap); |
| 526 | } | 954 | } |
| 527 | return 0; | 955 | return 0; |
| 528 | } | 956 | } |
| @@ -531,12 +959,13 @@ static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) | |||
| 531 | * Fill in the required fields of the "manager kprobe". Replace the | 959 | * Fill in the required fields of the "manager kprobe". Replace the |
| 532 | * earlier kprobe in the hlist with the manager kprobe | 960 | * earlier kprobe in the hlist with the manager kprobe |
| 533 | */ | 961 | */ |
| 534 | static inline void add_aggr_kprobe(struct kprobe *ap, struct kprobe *p) | 962 | static void __kprobes init_aggr_kprobe(struct kprobe *ap, struct kprobe *p) |
| 535 | { | 963 | { |
| 964 | /* Copy p's insn slot to ap */ | ||
| 536 | copy_kprobe(p, ap); | 965 | copy_kprobe(p, ap); |
| 537 | flush_insn_slot(ap); | 966 | flush_insn_slot(ap); |
| 538 | ap->addr = p->addr; | 967 | ap->addr = p->addr; |
| 539 | ap->flags = p->flags; | 968 | ap->flags = p->flags & ~KPROBE_FLAG_OPTIMIZED; |
| 540 | ap->pre_handler = aggr_pre_handler; | 969 | ap->pre_handler = aggr_pre_handler; |
| 541 | ap->fault_handler = aggr_fault_handler; | 970 | ap->fault_handler = aggr_fault_handler; |
| 542 | /* We don't care the kprobe which has gone. */ | 971 | /* We don't care the kprobe which has gone. */ |
| @@ -546,8 +975,9 @@ static inline void add_aggr_kprobe(struct kprobe *ap, struct kprobe *p) | |||
| 546 | ap->break_handler = aggr_break_handler; | 975 | ap->break_handler = aggr_break_handler; |
| 547 | 976 | ||
| 548 | INIT_LIST_HEAD(&ap->list); | 977 | INIT_LIST_HEAD(&ap->list); |
| 549 | list_add_rcu(&p->list, &ap->list); | 978 | INIT_HLIST_NODE(&ap->hlist); |
| 550 | 979 | ||
| 980 | list_add_rcu(&p->list, &ap->list); | ||
| 551 | hlist_replace_rcu(&p->hlist, &ap->hlist); | 981 | hlist_replace_rcu(&p->hlist, &ap->hlist); |
| 552 | } | 982 | } |
| 553 | 983 | ||
| @@ -561,12 +991,12 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p, | |||
| 561 | int ret = 0; | 991 | int ret = 0; |
| 562 | struct kprobe *ap = old_p; | 992 | struct kprobe *ap = old_p; |
| 563 | 993 | ||
| 564 | if (old_p->pre_handler != aggr_pre_handler) { | 994 | if (!kprobe_aggrprobe(old_p)) { |
| 565 | /* If old_p is not an aggr_probe, create new aggr_kprobe. */ | 995 | /* If old_p is not an aggr_kprobe, create new aggr_kprobe. */ |
| 566 | ap = kzalloc(sizeof(struct kprobe), GFP_KERNEL); | 996 | ap = alloc_aggr_kprobe(old_p); |
| 567 | if (!ap) | 997 | if (!ap) |
| 568 | return -ENOMEM; | 998 | return -ENOMEM; |
| 569 | add_aggr_kprobe(ap, old_p); | 999 | init_aggr_kprobe(ap, old_p); |
| 570 | } | 1000 | } |
| 571 | 1001 | ||
| 572 | if (kprobe_gone(ap)) { | 1002 | if (kprobe_gone(ap)) { |
| @@ -585,6 +1015,9 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p, | |||
| 585 | */ | 1015 | */ |
| 586 | return ret; | 1016 | return ret; |
| 587 | 1017 | ||
| 1018 | /* Prepare optimized instructions if possible. */ | ||
| 1019 | prepare_optimized_kprobe(ap); | ||
| 1020 | |||
| 588 | /* | 1021 | /* |
| 589 | * Clear gone flag to prevent allocating new slot again, and | 1022 | * Clear gone flag to prevent allocating new slot again, and |
| 590 | * set disabled flag because it is not armed yet. | 1023 | * set disabled flag because it is not armed yet. |
| @@ -593,6 +1026,7 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p, | |||
| 593 | | KPROBE_FLAG_DISABLED; | 1026 | | KPROBE_FLAG_DISABLED; |
| 594 | } | 1027 | } |
| 595 | 1028 | ||
| 1029 | /* Copy ap's insn slot to p */ | ||
| 596 | copy_kprobe(ap, p); | 1030 | copy_kprobe(ap, p); |
| 597 | return add_new_kprobe(ap, p); | 1031 | return add_new_kprobe(ap, p); |
| 598 | } | 1032 | } |
| @@ -743,27 +1177,34 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
| 743 | p->nmissed = 0; | 1177 | p->nmissed = 0; |
| 744 | INIT_LIST_HEAD(&p->list); | 1178 | INIT_LIST_HEAD(&p->list); |
| 745 | mutex_lock(&kprobe_mutex); | 1179 | mutex_lock(&kprobe_mutex); |
| 1180 | |||
| 1181 | get_online_cpus(); /* For avoiding text_mutex deadlock. */ | ||
| 1182 | mutex_lock(&text_mutex); | ||
| 1183 | |||
| 746 | old_p = get_kprobe(p->addr); | 1184 | old_p = get_kprobe(p->addr); |
| 747 | if (old_p) { | 1185 | if (old_p) { |
| 1186 | /* Since this may unoptimize old_p, locking text_mutex. */ | ||
| 748 | ret = register_aggr_kprobe(old_p, p); | 1187 | ret = register_aggr_kprobe(old_p, p); |
| 749 | goto out; | 1188 | goto out; |
| 750 | } | 1189 | } |
| 751 | 1190 | ||
| 752 | mutex_lock(&text_mutex); | ||
| 753 | ret = arch_prepare_kprobe(p); | 1191 | ret = arch_prepare_kprobe(p); |
| 754 | if (ret) | 1192 | if (ret) |
| 755 | goto out_unlock_text; | 1193 | goto out; |
| 756 | 1194 | ||
| 757 | INIT_HLIST_NODE(&p->hlist); | 1195 | INIT_HLIST_NODE(&p->hlist); |
| 758 | hlist_add_head_rcu(&p->hlist, | 1196 | hlist_add_head_rcu(&p->hlist, |
| 759 | &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); | 1197 | &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); |
| 760 | 1198 | ||
| 761 | if (!kprobes_all_disarmed && !kprobe_disabled(p)) | 1199 | if (!kprobes_all_disarmed && !kprobe_disabled(p)) |
| 762 | arch_arm_kprobe(p); | 1200 | __arm_kprobe(p); |
| 1201 | |||
| 1202 | /* Try to optimize kprobe */ | ||
| 1203 | try_to_optimize_kprobe(p); | ||
| 763 | 1204 | ||
| 764 | out_unlock_text: | ||
| 765 | mutex_unlock(&text_mutex); | ||
| 766 | out: | 1205 | out: |
| 1206 | mutex_unlock(&text_mutex); | ||
| 1207 | put_online_cpus(); | ||
| 767 | mutex_unlock(&kprobe_mutex); | 1208 | mutex_unlock(&kprobe_mutex); |
| 768 | 1209 | ||
| 769 | if (probed_mod) | 1210 | if (probed_mod) |
| @@ -785,7 +1226,7 @@ static int __kprobes __unregister_kprobe_top(struct kprobe *p) | |||
| 785 | return -EINVAL; | 1226 | return -EINVAL; |
| 786 | 1227 | ||
| 787 | if (old_p == p || | 1228 | if (old_p == p || |
| 788 | (old_p->pre_handler == aggr_pre_handler && | 1229 | (kprobe_aggrprobe(old_p) && |
| 789 | list_is_singular(&old_p->list))) { | 1230 | list_is_singular(&old_p->list))) { |
| 790 | /* | 1231 | /* |
| 791 | * Only probe on the hash list. Disarm only if kprobes are | 1232 | * Only probe on the hash list. Disarm only if kprobes are |
| @@ -793,7 +1234,7 @@ static int __kprobes __unregister_kprobe_top(struct kprobe *p) | |||
| 793 | * already have been removed. We save on flushing icache. | 1234 | * already have been removed. We save on flushing icache. |
| 794 | */ | 1235 | */ |
| 795 | if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) | 1236 | if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) |
| 796 | disarm_kprobe(p); | 1237 | disarm_kprobe(old_p); |
| 797 | hlist_del_rcu(&old_p->hlist); | 1238 | hlist_del_rcu(&old_p->hlist); |
| 798 | } else { | 1239 | } else { |
| 799 | if (p->break_handler && !kprobe_gone(p)) | 1240 | if (p->break_handler && !kprobe_gone(p)) |
| @@ -809,8 +1250,13 @@ noclean: | |||
| 809 | list_del_rcu(&p->list); | 1250 | list_del_rcu(&p->list); |
| 810 | if (!kprobe_disabled(old_p)) { | 1251 | if (!kprobe_disabled(old_p)) { |
| 811 | try_to_disable_aggr_kprobe(old_p); | 1252 | try_to_disable_aggr_kprobe(old_p); |
| 812 | if (!kprobes_all_disarmed && kprobe_disabled(old_p)) | 1253 | if (!kprobes_all_disarmed) { |
| 813 | disarm_kprobe(old_p); | 1254 | if (kprobe_disabled(old_p)) |
| 1255 | disarm_kprobe(old_p); | ||
| 1256 | else | ||
| 1257 | /* Try to optimize this probe again */ | ||
| 1258 | optimize_kprobe(old_p); | ||
| 1259 | } | ||
| 814 | } | 1260 | } |
| 815 | } | 1261 | } |
| 816 | return 0; | 1262 | return 0; |
| @@ -827,7 +1273,7 @@ static void __kprobes __unregister_kprobe_bottom(struct kprobe *p) | |||
| 827 | old_p = list_entry(p->list.next, struct kprobe, list); | 1273 | old_p = list_entry(p->list.next, struct kprobe, list); |
| 828 | list_del(&p->list); | 1274 | list_del(&p->list); |
| 829 | arch_remove_kprobe(old_p); | 1275 | arch_remove_kprobe(old_p); |
| 830 | kfree(old_p); | 1276 | free_aggr_kprobe(old_p); |
| 831 | } | 1277 | } |
| 832 | } | 1278 | } |
| 833 | 1279 | ||
| @@ -1123,7 +1569,7 @@ static void __kprobes kill_kprobe(struct kprobe *p) | |||
| 1123 | struct kprobe *kp; | 1569 | struct kprobe *kp; |
| 1124 | 1570 | ||
| 1125 | p->flags |= KPROBE_FLAG_GONE; | 1571 | p->flags |= KPROBE_FLAG_GONE; |
| 1126 | if (p->pre_handler == aggr_pre_handler) { | 1572 | if (kprobe_aggrprobe(p)) { |
| 1127 | /* | 1573 | /* |
| 1128 | * If this is an aggr_kprobe, we have to list all the | 1574 | * If this is an aggr_kprobe, we have to list all the |
| 1129 | * chained probes and mark them GONE. | 1575 | * chained probes and mark them GONE. |
| @@ -1132,6 +1578,7 @@ static void __kprobes kill_kprobe(struct kprobe *p) | |||
| 1132 | kp->flags |= KPROBE_FLAG_GONE; | 1578 | kp->flags |= KPROBE_FLAG_GONE; |
| 1133 | p->post_handler = NULL; | 1579 | p->post_handler = NULL; |
| 1134 | p->break_handler = NULL; | 1580 | p->break_handler = NULL; |
| 1581 | kill_optimized_kprobe(p); | ||
| 1135 | } | 1582 | } |
| 1136 | /* | 1583 | /* |
| 1137 | * Here, we can remove insn_slot safely, because no thread calls | 1584 | * Here, we can remove insn_slot safely, because no thread calls |
| @@ -1241,6 +1688,15 @@ static int __init init_kprobes(void) | |||
| 1241 | } | 1688 | } |
| 1242 | } | 1689 | } |
| 1243 | 1690 | ||
| 1691 | #if defined(CONFIG_OPTPROBES) | ||
| 1692 | #if defined(__ARCH_WANT_KPROBES_INSN_SLOT) | ||
| 1693 | /* Init kprobe_optinsn_slots */ | ||
| 1694 | kprobe_optinsn_slots.insn_size = MAX_OPTINSN_SIZE; | ||
| 1695 | #endif | ||
| 1696 | /* By default, kprobes can be optimized */ | ||
| 1697 | kprobes_allow_optimization = true; | ||
| 1698 | #endif | ||
| 1699 | |||
| 1244 | /* By default, kprobes are armed */ | 1700 | /* By default, kprobes are armed */ |
| 1245 | kprobes_all_disarmed = false; | 1701 | kprobes_all_disarmed = false; |
| 1246 | 1702 | ||
| @@ -1259,7 +1715,7 @@ static int __init init_kprobes(void) | |||
| 1259 | 1715 | ||
| 1260 | #ifdef CONFIG_DEBUG_FS | 1716 | #ifdef CONFIG_DEBUG_FS |
| 1261 | static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p, | 1717 | static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p, |
| 1262 | const char *sym, int offset,char *modname) | 1718 | const char *sym, int offset, char *modname, struct kprobe *pp) |
| 1263 | { | 1719 | { |
| 1264 | char *kprobe_type; | 1720 | char *kprobe_type; |
| 1265 | 1721 | ||
| @@ -1269,19 +1725,21 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p, | |||
| 1269 | kprobe_type = "j"; | 1725 | kprobe_type = "j"; |
| 1270 | else | 1726 | else |
| 1271 | kprobe_type = "k"; | 1727 | kprobe_type = "k"; |
| 1728 | |||
| 1272 | if (sym) | 1729 | if (sym) |
| 1273 | seq_printf(pi, "%p %s %s+0x%x %s %s%s\n", | 1730 | seq_printf(pi, "%p %s %s+0x%x %s ", |
| 1274 | p->addr, kprobe_type, sym, offset, | 1731 | p->addr, kprobe_type, sym, offset, |
| 1275 | (modname ? modname : " "), | 1732 | (modname ? modname : " ")); |
| 1276 | (kprobe_gone(p) ? "[GONE]" : ""), | ||
| 1277 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? | ||
| 1278 | "[DISABLED]" : "")); | ||
| 1279 | else | 1733 | else |
| 1280 | seq_printf(pi, "%p %s %p %s%s\n", | 1734 | seq_printf(pi, "%p %s %p ", |
| 1281 | p->addr, kprobe_type, p->addr, | 1735 | p->addr, kprobe_type, p->addr); |
| 1282 | (kprobe_gone(p) ? "[GONE]" : ""), | 1736 | |
| 1283 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? | 1737 | if (!pp) |
| 1284 | "[DISABLED]" : "")); | 1738 | pp = p; |
| 1739 | seq_printf(pi, "%s%s%s\n", | ||
| 1740 | (kprobe_gone(p) ? "[GONE]" : ""), | ||
| 1741 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? "[DISABLED]" : ""), | ||
| 1742 | (kprobe_optimized(pp) ? "[OPTIMIZED]" : "")); | ||
| 1285 | } | 1743 | } |
| 1286 | 1744 | ||
| 1287 | static void __kprobes *kprobe_seq_start(struct seq_file *f, loff_t *pos) | 1745 | static void __kprobes *kprobe_seq_start(struct seq_file *f, loff_t *pos) |
| @@ -1317,11 +1775,11 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v) | |||
| 1317 | hlist_for_each_entry_rcu(p, node, head, hlist) { | 1775 | hlist_for_each_entry_rcu(p, node, head, hlist) { |
| 1318 | sym = kallsyms_lookup((unsigned long)p->addr, NULL, | 1776 | sym = kallsyms_lookup((unsigned long)p->addr, NULL, |
| 1319 | &offset, &modname, namebuf); | 1777 | &offset, &modname, namebuf); |
| 1320 | if (p->pre_handler == aggr_pre_handler) { | 1778 | if (kprobe_aggrprobe(p)) { |
| 1321 | list_for_each_entry_rcu(kp, &p->list, list) | 1779 | list_for_each_entry_rcu(kp, &p->list, list) |
| 1322 | report_probe(pi, kp, sym, offset, modname); | 1780 | report_probe(pi, kp, sym, offset, modname, p); |
| 1323 | } else | 1781 | } else |
| 1324 | report_probe(pi, p, sym, offset, modname); | 1782 | report_probe(pi, p, sym, offset, modname, NULL); |
| 1325 | } | 1783 | } |
| 1326 | preempt_enable(); | 1784 | preempt_enable(); |
| 1327 | return 0; | 1785 | return 0; |
| @@ -1399,12 +1857,13 @@ int __kprobes enable_kprobe(struct kprobe *kp) | |||
| 1399 | goto out; | 1857 | goto out; |
| 1400 | } | 1858 | } |
| 1401 | 1859 | ||
| 1402 | if (!kprobes_all_disarmed && kprobe_disabled(p)) | ||
| 1403 | arm_kprobe(p); | ||
| 1404 | |||
| 1405 | p->flags &= ~KPROBE_FLAG_DISABLED; | ||
| 1406 | if (p != kp) | 1860 | if (p != kp) |
| 1407 | kp->flags &= ~KPROBE_FLAG_DISABLED; | 1861 | kp->flags &= ~KPROBE_FLAG_DISABLED; |
| 1862 | |||
| 1863 | if (!kprobes_all_disarmed && kprobe_disabled(p)) { | ||
| 1864 | p->flags &= ~KPROBE_FLAG_DISABLED; | ||
| 1865 | arm_kprobe(p); | ||
| 1866 | } | ||
| 1408 | out: | 1867 | out: |
| 1409 | mutex_unlock(&kprobe_mutex); | 1868 | mutex_unlock(&kprobe_mutex); |
| 1410 | return ret; | 1869 | return ret; |
| @@ -1424,12 +1883,13 @@ static void __kprobes arm_all_kprobes(void) | |||
| 1424 | if (!kprobes_all_disarmed) | 1883 | if (!kprobes_all_disarmed) |
| 1425 | goto already_enabled; | 1884 | goto already_enabled; |
| 1426 | 1885 | ||
| 1886 | /* Arming kprobes doesn't optimize kprobe itself */ | ||
| 1427 | mutex_lock(&text_mutex); | 1887 | mutex_lock(&text_mutex); |
| 1428 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 1888 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
| 1429 | head = &kprobe_table[i]; | 1889 | head = &kprobe_table[i]; |
| 1430 | hlist_for_each_entry_rcu(p, node, head, hlist) | 1890 | hlist_for_each_entry_rcu(p, node, head, hlist) |
| 1431 | if (!kprobe_disabled(p)) | 1891 | if (!kprobe_disabled(p)) |
| 1432 | arch_arm_kprobe(p); | 1892 | __arm_kprobe(p); |
| 1433 | } | 1893 | } |
| 1434 | mutex_unlock(&text_mutex); | 1894 | mutex_unlock(&text_mutex); |
| 1435 | 1895 | ||
| @@ -1456,16 +1916,23 @@ static void __kprobes disarm_all_kprobes(void) | |||
| 1456 | 1916 | ||
| 1457 | kprobes_all_disarmed = true; | 1917 | kprobes_all_disarmed = true; |
| 1458 | printk(KERN_INFO "Kprobes globally disabled\n"); | 1918 | printk(KERN_INFO "Kprobes globally disabled\n"); |
| 1919 | |||
| 1920 | /* | ||
| 1921 | * Here we call get_online_cpus() for avoiding text_mutex deadlock, | ||
| 1922 | * because disarming may also unoptimize kprobes. | ||
| 1923 | */ | ||
| 1924 | get_online_cpus(); | ||
| 1459 | mutex_lock(&text_mutex); | 1925 | mutex_lock(&text_mutex); |
| 1460 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 1926 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
| 1461 | head = &kprobe_table[i]; | 1927 | head = &kprobe_table[i]; |
| 1462 | hlist_for_each_entry_rcu(p, node, head, hlist) { | 1928 | hlist_for_each_entry_rcu(p, node, head, hlist) { |
| 1463 | if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) | 1929 | if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) |
| 1464 | arch_disarm_kprobe(p); | 1930 | __disarm_kprobe(p); |
| 1465 | } | 1931 | } |
| 1466 | } | 1932 | } |
| 1467 | 1933 | ||
| 1468 | mutex_unlock(&text_mutex); | 1934 | mutex_unlock(&text_mutex); |
| 1935 | put_online_cpus(); | ||
| 1469 | mutex_unlock(&kprobe_mutex); | 1936 | mutex_unlock(&kprobe_mutex); |
| 1470 | /* Allow all currently running kprobes to complete */ | 1937 | /* Allow all currently running kprobes to complete */ |
| 1471 | synchronize_sched(); | 1938 | synchronize_sched(); |
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index 6b1ccc3f0205..21fe3c426948 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c | |||
| @@ -33,7 +33,7 @@ static ssize_t uevent_seqnum_show(struct kobject *kobj, | |||
| 33 | } | 33 | } |
| 34 | KERNEL_ATTR_RO(uevent_seqnum); | 34 | KERNEL_ATTR_RO(uevent_seqnum); |
| 35 | 35 | ||
| 36 | /* uevent helper program, used during early boo */ | 36 | /* uevent helper program, used during early boot */ |
| 37 | static ssize_t uevent_helper_show(struct kobject *kobj, | 37 | static ssize_t uevent_helper_show(struct kobject *kobj, |
| 38 | struct kobj_attribute *attr, char *buf) | 38 | struct kobj_attribute *attr, char *buf) |
| 39 | { | 39 | { |
diff --git a/kernel/module.c b/kernel/module.c index f82386bd9ee9..c968d3606dca 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
| @@ -474,9 +474,10 @@ static void module_unload_init(struct module *mod) | |||
| 474 | 474 | ||
| 475 | INIT_LIST_HEAD(&mod->modules_which_use_me); | 475 | INIT_LIST_HEAD(&mod->modules_which_use_me); |
| 476 | for_each_possible_cpu(cpu) | 476 | for_each_possible_cpu(cpu) |
| 477 | local_set(__module_ref_addr(mod, cpu), 0); | 477 | per_cpu_ptr(mod->refptr, cpu)->count = 0; |
| 478 | |||
| 478 | /* Hold reference count during initialization. */ | 479 | /* Hold reference count during initialization. */ |
| 479 | local_set(__module_ref_addr(mod, raw_smp_processor_id()), 1); | 480 | __this_cpu_write(mod->refptr->count, 1); |
| 480 | /* Backwards compatibility macros put refcount during init. */ | 481 | /* Backwards compatibility macros put refcount during init. */ |
| 481 | mod->waiter = current; | 482 | mod->waiter = current; |
| 482 | } | 483 | } |
| @@ -619,7 +620,7 @@ unsigned int module_refcount(struct module *mod) | |||
| 619 | int cpu; | 620 | int cpu; |
| 620 | 621 | ||
| 621 | for_each_possible_cpu(cpu) | 622 | for_each_possible_cpu(cpu) |
| 622 | total += local_read(__module_ref_addr(mod, cpu)); | 623 | total += per_cpu_ptr(mod->refptr, cpu)->count; |
| 623 | return total; | 624 | return total; |
| 624 | } | 625 | } |
| 625 | EXPORT_SYMBOL(module_refcount); | 626 | EXPORT_SYMBOL(module_refcount); |
| @@ -796,14 +797,15 @@ static struct module_attribute refcnt = { | |||
| 796 | void module_put(struct module *module) | 797 | void module_put(struct module *module) |
| 797 | { | 798 | { |
| 798 | if (module) { | 799 | if (module) { |
| 799 | unsigned int cpu = get_cpu(); | 800 | preempt_disable(); |
| 800 | local_dec(__module_ref_addr(module, cpu)); | 801 | __this_cpu_dec(module->refptr->count); |
| 802 | |||
| 801 | trace_module_put(module, _RET_IP_, | 803 | trace_module_put(module, _RET_IP_, |
| 802 | local_read(__module_ref_addr(module, cpu))); | 804 | __this_cpu_read(module->refptr->count)); |
| 803 | /* Maybe they're waiting for us to drop reference? */ | 805 | /* Maybe they're waiting for us to drop reference? */ |
| 804 | if (unlikely(!module_is_live(module))) | 806 | if (unlikely(!module_is_live(module))) |
| 805 | wake_up_process(module->waiter); | 807 | wake_up_process(module->waiter); |
| 806 | put_cpu(); | 808 | preempt_enable(); |
| 807 | } | 809 | } |
| 808 | } | 810 | } |
| 809 | EXPORT_SYMBOL(module_put); | 811 | EXPORT_SYMBOL(module_put); |
| @@ -1083,6 +1085,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect, | |||
| 1083 | if (sattr->name == NULL) | 1085 | if (sattr->name == NULL) |
| 1084 | goto out; | 1086 | goto out; |
| 1085 | sect_attrs->nsections++; | 1087 | sect_attrs->nsections++; |
| 1088 | sysfs_attr_init(&sattr->mattr.attr); | ||
| 1086 | sattr->mattr.show = module_sect_show; | 1089 | sattr->mattr.show = module_sect_show; |
| 1087 | sattr->mattr.store = NULL; | 1090 | sattr->mattr.store = NULL; |
| 1088 | sattr->mattr.attr.name = sattr->name; | 1091 | sattr->mattr.attr.name = sattr->name; |
| @@ -1178,6 +1181,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
| 1178 | if (sect_empty(&sechdrs[i])) | 1181 | if (sect_empty(&sechdrs[i])) |
| 1179 | continue; | 1182 | continue; |
| 1180 | if (sechdrs[i].sh_type == SHT_NOTE) { | 1183 | if (sechdrs[i].sh_type == SHT_NOTE) { |
| 1184 | sysfs_bin_attr_init(nattr); | ||
| 1181 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; | 1185 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; |
| 1182 | nattr->attr.mode = S_IRUGO; | 1186 | nattr->attr.mode = S_IRUGO; |
| 1183 | nattr->size = sechdrs[i].sh_size; | 1187 | nattr->size = sechdrs[i].sh_size; |
| @@ -1250,6 +1254,7 @@ int module_add_modinfo_attrs(struct module *mod) | |||
| 1250 | if (!attr->test || | 1254 | if (!attr->test || |
| 1251 | (attr->test && attr->test(mod))) { | 1255 | (attr->test && attr->test(mod))) { |
| 1252 | memcpy(temp_attr, attr, sizeof(*temp_attr)); | 1256 | memcpy(temp_attr, attr, sizeof(*temp_attr)); |
| 1257 | sysfs_attr_init(&temp_attr->attr); | ||
| 1253 | error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); | 1258 | error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); |
| 1254 | ++temp_attr; | 1259 | ++temp_attr; |
| 1255 | } | 1260 | } |
| @@ -1397,9 +1402,9 @@ static void free_module(struct module *mod) | |||
| 1397 | kfree(mod->args); | 1402 | kfree(mod->args); |
| 1398 | if (mod->percpu) | 1403 | if (mod->percpu) |
| 1399 | percpu_modfree(mod->percpu); | 1404 | percpu_modfree(mod->percpu); |
| 1400 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | 1405 | #if defined(CONFIG_MODULE_UNLOAD) |
| 1401 | if (mod->refptr) | 1406 | if (mod->refptr) |
| 1402 | percpu_modfree(mod->refptr); | 1407 | free_percpu(mod->refptr); |
| 1403 | #endif | 1408 | #endif |
| 1404 | /* Free lock-classes: */ | 1409 | /* Free lock-classes: */ |
| 1405 | lockdep_free_key_range(mod->module_core, mod->core_size); | 1410 | lockdep_free_key_range(mod->module_core, mod->core_size); |
| @@ -2162,9 +2167,8 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2162 | mod = (void *)sechdrs[modindex].sh_addr; | 2167 | mod = (void *)sechdrs[modindex].sh_addr; |
| 2163 | kmemleak_load_module(mod, hdr, sechdrs, secstrings); | 2168 | kmemleak_load_module(mod, hdr, sechdrs, secstrings); |
| 2164 | 2169 | ||
| 2165 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | 2170 | #if defined(CONFIG_MODULE_UNLOAD) |
| 2166 | mod->refptr = percpu_modalloc(sizeof(local_t), __alignof__(local_t), | 2171 | mod->refptr = alloc_percpu(struct module_ref); |
| 2167 | mod->name); | ||
| 2168 | if (!mod->refptr) { | 2172 | if (!mod->refptr) { |
| 2169 | err = -ENOMEM; | 2173 | err = -ENOMEM; |
| 2170 | goto free_init; | 2174 | goto free_init; |
| @@ -2396,8 +2400,8 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2396 | kobject_put(&mod->mkobj.kobj); | 2400 | kobject_put(&mod->mkobj.kobj); |
| 2397 | free_unload: | 2401 | free_unload: |
| 2398 | module_unload_free(mod); | 2402 | module_unload_free(mod); |
| 2399 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | 2403 | #if defined(CONFIG_MODULE_UNLOAD) |
| 2400 | percpu_modfree(mod->refptr); | 2404 | free_percpu(mod->refptr); |
| 2401 | free_init: | 2405 | free_init: |
| 2402 | #endif | 2406 | #endif |
| 2403 | module_free(mod, mod->module_init); | 2407 | module_free(mod, mod->module_init); |
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index 09b4ff9711b2..2ab67233ee8f 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c | |||
| @@ -24,7 +24,18 @@ | |||
| 24 | 24 | ||
| 25 | static struct kmem_cache *nsproxy_cachep; | 25 | static struct kmem_cache *nsproxy_cachep; |
| 26 | 26 | ||
| 27 | struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy); | 27 | struct nsproxy init_nsproxy = { |
| 28 | .count = ATOMIC_INIT(1), | ||
| 29 | .uts_ns = &init_uts_ns, | ||
| 30 | #if defined(CONFIG_POSIX_MQUEUE) || defined(CONFIG_SYSVIPC) | ||
| 31 | .ipc_ns = &init_ipc_ns, | ||
| 32 | #endif | ||
| 33 | .mnt_ns = NULL, | ||
| 34 | .pid_ns = &init_pid_ns, | ||
| 35 | #ifdef CONFIG_NET | ||
| 36 | .net_ns = &init_net, | ||
| 37 | #endif | ||
| 38 | }; | ||
| 28 | 39 | ||
| 29 | static inline struct nsproxy *create_nsproxy(void) | 40 | static inline struct nsproxy *create_nsproxy(void) |
| 30 | { | 41 | { |
diff --git a/kernel/padata.c b/kernel/padata.c index 6f9bcb8313d6..93caf65ff57c 100644 --- a/kernel/padata.c +++ b/kernel/padata.c | |||
| @@ -642,6 +642,9 @@ struct padata_instance *padata_alloc(const struct cpumask *cpumask, | |||
| 642 | if (!pd) | 642 | if (!pd) |
| 643 | goto err_free_inst; | 643 | goto err_free_inst; |
| 644 | 644 | ||
| 645 | if (!alloc_cpumask_var(&pinst->cpumask, GFP_KERNEL)) | ||
| 646 | goto err_free_pd; | ||
| 647 | |||
| 645 | rcu_assign_pointer(pinst->pd, pd); | 648 | rcu_assign_pointer(pinst->pd, pd); |
| 646 | 649 | ||
| 647 | pinst->wq = wq; | 650 | pinst->wq = wq; |
| @@ -654,12 +657,14 @@ struct padata_instance *padata_alloc(const struct cpumask *cpumask, | |||
| 654 | pinst->cpu_notifier.priority = 0; | 657 | pinst->cpu_notifier.priority = 0; |
| 655 | err = register_hotcpu_notifier(&pinst->cpu_notifier); | 658 | err = register_hotcpu_notifier(&pinst->cpu_notifier); |
| 656 | if (err) | 659 | if (err) |
| 657 | goto err_free_pd; | 660 | goto err_free_cpumask; |
| 658 | 661 | ||
| 659 | mutex_init(&pinst->lock); | 662 | mutex_init(&pinst->lock); |
| 660 | 663 | ||
| 661 | return pinst; | 664 | return pinst; |
| 662 | 665 | ||
| 666 | err_free_cpumask: | ||
| 667 | free_cpumask_var(pinst->cpumask); | ||
| 663 | err_free_pd: | 668 | err_free_pd: |
| 664 | padata_free_pd(pd); | 669 | padata_free_pd(pd); |
| 665 | err_free_inst: | 670 | err_free_inst: |
| @@ -685,6 +690,7 @@ void padata_free(struct padata_instance *pinst) | |||
| 685 | 690 | ||
| 686 | unregister_hotcpu_notifier(&pinst->cpu_notifier); | 691 | unregister_hotcpu_notifier(&pinst->cpu_notifier); |
| 687 | padata_free_pd(pinst->pd); | 692 | padata_free_pd(pinst->pd); |
| 693 | free_cpumask_var(pinst->cpumask); | ||
| 688 | kfree(pinst); | 694 | kfree(pinst); |
| 689 | } | 695 | } |
| 690 | EXPORT_SYMBOL(padata_free); | 696 | EXPORT_SYMBOL(padata_free); |
diff --git a/kernel/panic.c b/kernel/panic.c index c787333282b8..13d966b4c14a 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
| @@ -36,15 +36,36 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list); | |||
| 36 | 36 | ||
| 37 | EXPORT_SYMBOL(panic_notifier_list); | 37 | EXPORT_SYMBOL(panic_notifier_list); |
| 38 | 38 | ||
| 39 | static long no_blink(long time) | ||
| 40 | { | ||
| 41 | return 0; | ||
| 42 | } | ||
| 43 | |||
| 44 | /* Returns how long it waited in ms */ | 39 | /* Returns how long it waited in ms */ |
| 45 | long (*panic_blink)(long time); | 40 | long (*panic_blink)(long time); |
| 46 | EXPORT_SYMBOL(panic_blink); | 41 | EXPORT_SYMBOL(panic_blink); |
| 47 | 42 | ||
| 43 | static void panic_blink_one_second(void) | ||
| 44 | { | ||
| 45 | static long i = 0, end; | ||
| 46 | |||
| 47 | if (panic_blink) { | ||
| 48 | end = i + MSEC_PER_SEC; | ||
| 49 | |||
| 50 | while (i < end) { | ||
| 51 | i += panic_blink(i); | ||
| 52 | mdelay(1); | ||
| 53 | i++; | ||
| 54 | } | ||
| 55 | } else { | ||
| 56 | /* | ||
| 57 | * When running under a hypervisor a small mdelay may get | ||
| 58 | * rounded up to the hypervisor timeslice. For example, with | ||
| 59 | * a 1ms in 10ms hypervisor timeslice we might inflate a | ||
| 60 | * mdelay(1) loop by 10x. | ||
| 61 | * | ||
| 62 | * If we have nothing to blink, spin on 1 second calls to | ||
| 63 | * mdelay to avoid this. | ||
| 64 | */ | ||
| 65 | mdelay(MSEC_PER_SEC); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 48 | /** | 69 | /** |
| 49 | * panic - halt the system | 70 | * panic - halt the system |
| 50 | * @fmt: The text string to print | 71 | * @fmt: The text string to print |
| @@ -95,9 +116,6 @@ NORET_TYPE void panic(const char * fmt, ...) | |||
| 95 | 116 | ||
| 96 | bust_spinlocks(0); | 117 | bust_spinlocks(0); |
| 97 | 118 | ||
| 98 | if (!panic_blink) | ||
| 99 | panic_blink = no_blink; | ||
| 100 | |||
| 101 | if (panic_timeout > 0) { | 119 | if (panic_timeout > 0) { |
| 102 | /* | 120 | /* |
| 103 | * Delay timeout seconds before rebooting the machine. | 121 | * Delay timeout seconds before rebooting the machine. |
| @@ -105,11 +123,9 @@ NORET_TYPE void panic(const char * fmt, ...) | |||
| 105 | */ | 123 | */ |
| 106 | printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout); | 124 | printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout); |
| 107 | 125 | ||
| 108 | for (i = 0; i < panic_timeout*1000; ) { | 126 | for (i = 0; i < panic_timeout; i++) { |
| 109 | touch_nmi_watchdog(); | 127 | touch_nmi_watchdog(); |
| 110 | i += panic_blink(i); | 128 | panic_blink_one_second(); |
| 111 | mdelay(1); | ||
| 112 | i++; | ||
| 113 | } | 129 | } |
| 114 | /* | 130 | /* |
| 115 | * This will not be a clean reboot, with everything | 131 | * This will not be a clean reboot, with everything |
| @@ -135,11 +151,9 @@ NORET_TYPE void panic(const char * fmt, ...) | |||
| 135 | } | 151 | } |
| 136 | #endif | 152 | #endif |
| 137 | local_irq_enable(); | 153 | local_irq_enable(); |
| 138 | for (i = 0; ; ) { | 154 | while (1) { |
| 139 | touch_softlockup_watchdog(); | 155 | touch_softlockup_watchdog(); |
| 140 | i += panic_blink(i); | 156 | panic_blink_one_second(); |
| 141 | mdelay(1); | ||
| 142 | i++; | ||
| 143 | } | 157 | } |
| 144 | } | 158 | } |
| 145 | 159 | ||
diff --git a/kernel/params.c b/kernel/params.c index cf1b69183127..0b30ecd53a52 100644 --- a/kernel/params.c +++ b/kernel/params.c | |||
| @@ -24,7 +24,6 @@ | |||
| 24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
| 25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
| 26 | #include <linux/ctype.h> | 26 | #include <linux/ctype.h> |
| 27 | #include <linux/string.h> | ||
| 28 | 27 | ||
| 29 | #if 0 | 28 | #if 0 |
| 30 | #define DEBUGP printk | 29 | #define DEBUGP printk |
| @@ -402,8 +401,8 @@ int param_get_string(char *buffer, struct kernel_param *kp) | |||
| 402 | } | 401 | } |
| 403 | 402 | ||
| 404 | /* sysfs output in /sys/modules/XYZ/parameters/ */ | 403 | /* sysfs output in /sys/modules/XYZ/parameters/ */ |
| 405 | #define to_module_attr(n) container_of(n, struct module_attribute, attr); | 404 | #define to_module_attr(n) container_of(n, struct module_attribute, attr) |
| 406 | #define to_module_kobject(n) container_of(n, struct module_kobject, kobj); | 405 | #define to_module_kobject(n) container_of(n, struct module_kobject, kobj) |
| 407 | 406 | ||
| 408 | extern struct kernel_param __start___param[], __stop___param[]; | 407 | extern struct kernel_param __start___param[], __stop___param[]; |
| 409 | 408 | ||
| @@ -421,7 +420,7 @@ struct module_param_attrs | |||
| 421 | }; | 420 | }; |
| 422 | 421 | ||
| 423 | #ifdef CONFIG_SYSFS | 422 | #ifdef CONFIG_SYSFS |
| 424 | #define to_param_attr(n) container_of(n, struct param_attribute, mattr); | 423 | #define to_param_attr(n) container_of(n, struct param_attribute, mattr) |
| 425 | 424 | ||
| 426 | static ssize_t param_attr_show(struct module_attribute *mattr, | 425 | static ssize_t param_attr_show(struct module_attribute *mattr, |
| 427 | struct module *mod, char *buf) | 426 | struct module *mod, char *buf) |
| @@ -517,6 +516,7 @@ static __modinit int add_sysfs_param(struct module_kobject *mk, | |||
| 517 | new->grp.attrs = attrs; | 516 | new->grp.attrs = attrs; |
| 518 | 517 | ||
| 519 | /* Tack new one on the end. */ | 518 | /* Tack new one on the end. */ |
| 519 | sysfs_attr_init(&new->attrs[num].mattr.attr); | ||
| 520 | new->attrs[num].param = kp; | 520 | new->attrs[num].param = kp; |
| 521 | new->attrs[num].mattr.show = param_attr_show; | 521 | new->attrs[num].mattr.show = param_attr_show; |
| 522 | new->attrs[num].mattr.store = param_attr_store; | 522 | new->attrs[num].mattr.store = param_attr_store; |
| @@ -723,7 +723,7 @@ static ssize_t module_attr_store(struct kobject *kobj, | |||
| 723 | return ret; | 723 | return ret; |
| 724 | } | 724 | } |
| 725 | 725 | ||
| 726 | static struct sysfs_ops module_sysfs_ops = { | 726 | static const struct sysfs_ops module_sysfs_ops = { |
| 727 | .show = module_attr_show, | 727 | .show = module_attr_show, |
| 728 | .store = module_attr_store, | 728 | .store = module_attr_store, |
| 729 | }; | 729 | }; |
| @@ -737,7 +737,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj) | |||
| 737 | return 0; | 737 | return 0; |
| 738 | } | 738 | } |
| 739 | 739 | ||
| 740 | static struct kset_uevent_ops module_uevent_ops = { | 740 | static const struct kset_uevent_ops module_uevent_ops = { |
| 741 | .filter = uevent_filter, | 741 | .filter = uevent_filter, |
| 742 | }; | 742 | }; |
| 743 | 743 | ||
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index a661e7991865..f40560b86544 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
| @@ -2610,7 +2610,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) | |||
| 2610 | if (user_locked > user_lock_limit) | 2610 | if (user_locked > user_lock_limit) |
| 2611 | extra = user_locked - user_lock_limit; | 2611 | extra = user_locked - user_lock_limit; |
| 2612 | 2612 | ||
| 2613 | lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; | 2613 | lock_limit = rlimit(RLIMIT_MEMLOCK); |
| 2614 | lock_limit >>= PAGE_SHIFT; | 2614 | lock_limit >>= PAGE_SHIFT; |
| 2615 | locked = vma->vm_mm->locked_vm + extra; | 2615 | locked = vma->vm_mm->locked_vm + extra; |
| 2616 | 2616 | ||
| @@ -5481,13 +5481,16 @@ void __init perf_event_init(void) | |||
| 5481 | register_cpu_notifier(&perf_cpu_nb); | 5481 | register_cpu_notifier(&perf_cpu_nb); |
| 5482 | } | 5482 | } |
| 5483 | 5483 | ||
| 5484 | static ssize_t perf_show_reserve_percpu(struct sysdev_class *class, char *buf) | 5484 | static ssize_t perf_show_reserve_percpu(struct sysdev_class *class, |
| 5485 | struct sysdev_class_attribute *attr, | ||
| 5486 | char *buf) | ||
| 5485 | { | 5487 | { |
| 5486 | return sprintf(buf, "%d\n", perf_reserved_percpu); | 5488 | return sprintf(buf, "%d\n", perf_reserved_percpu); |
| 5487 | } | 5489 | } |
| 5488 | 5490 | ||
| 5489 | static ssize_t | 5491 | static ssize_t |
| 5490 | perf_set_reserve_percpu(struct sysdev_class *class, | 5492 | perf_set_reserve_percpu(struct sysdev_class *class, |
| 5493 | struct sysdev_class_attribute *attr, | ||
| 5491 | const char *buf, | 5494 | const char *buf, |
| 5492 | size_t count) | 5495 | size_t count) |
| 5493 | { | 5496 | { |
| @@ -5516,13 +5519,17 @@ perf_set_reserve_percpu(struct sysdev_class *class, | |||
| 5516 | return count; | 5519 | return count; |
| 5517 | } | 5520 | } |
| 5518 | 5521 | ||
| 5519 | static ssize_t perf_show_overcommit(struct sysdev_class *class, char *buf) | 5522 | static ssize_t perf_show_overcommit(struct sysdev_class *class, |
| 5523 | struct sysdev_class_attribute *attr, | ||
| 5524 | char *buf) | ||
| 5520 | { | 5525 | { |
| 5521 | return sprintf(buf, "%d\n", perf_overcommit); | 5526 | return sprintf(buf, "%d\n", perf_overcommit); |
| 5522 | } | 5527 | } |
| 5523 | 5528 | ||
| 5524 | static ssize_t | 5529 | static ssize_t |
| 5525 | perf_set_overcommit(struct sysdev_class *class, const char *buf, size_t count) | 5530 | perf_set_overcommit(struct sysdev_class *class, |
| 5531 | struct sysdev_class_attribute *attr, | ||
| 5532 | const char *buf, size_t count) | ||
| 5526 | { | 5533 | { |
| 5527 | unsigned long val; | 5534 | unsigned long val; |
| 5528 | int err; | 5535 | int err; |
diff --git a/kernel/pid.c b/kernel/pid.c index b08e697cd83f..86b296943e5f 100644 --- a/kernel/pid.c +++ b/kernel/pid.c | |||
| @@ -376,7 +376,7 @@ struct task_struct *pid_task(struct pid *pid, enum pid_type type) | |||
| 376 | EXPORT_SYMBOL(pid_task); | 376 | EXPORT_SYMBOL(pid_task); |
| 377 | 377 | ||
| 378 | /* | 378 | /* |
| 379 | * Must be called under rcu_read_lock() or with tasklist_lock read-held. | 379 | * Must be called under rcu_read_lock(). |
| 380 | */ | 380 | */ |
| 381 | struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns) | 381 | struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns) |
| 382 | { | 382 | { |
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 86b3796b0436..79aac93acf99 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
| @@ -161,13 +161,12 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) | |||
| 161 | rcu_read_lock(); | 161 | rcu_read_lock(); |
| 162 | 162 | ||
| 163 | /* | 163 | /* |
| 164 | * Use force_sig() since it clears SIGNAL_UNKILLABLE ensuring | 164 | * Any nested-container's init processes won't ignore the |
| 165 | * any nested-container's init processes don't ignore the | 165 | * SEND_SIG_NOINFO signal, see send_signal()->si_fromuser(). |
| 166 | * signal | ||
| 167 | */ | 166 | */ |
| 168 | task = pid_task(find_vpid(nr), PIDTYPE_PID); | 167 | task = pid_task(find_vpid(nr), PIDTYPE_PID); |
| 169 | if (task) | 168 | if (task) |
| 170 | force_sig(SIGKILL, task); | 169 | send_sig_info(SIGKILL, SEND_SIG_NOINFO, task); |
| 171 | 170 | ||
| 172 | rcu_read_unlock(); | 171 | rcu_read_unlock(); |
| 173 | 172 | ||
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index 438ff4523513..1a22dfd42df9 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
| @@ -982,6 +982,7 @@ static void check_thread_timers(struct task_struct *tsk, | |||
| 982 | int maxfire; | 982 | int maxfire; |
| 983 | struct list_head *timers = tsk->cpu_timers; | 983 | struct list_head *timers = tsk->cpu_timers; |
| 984 | struct signal_struct *const sig = tsk->signal; | 984 | struct signal_struct *const sig = tsk->signal; |
| 985 | unsigned long soft; | ||
| 985 | 986 | ||
| 986 | maxfire = 20; | 987 | maxfire = 20; |
| 987 | tsk->cputime_expires.prof_exp = cputime_zero; | 988 | tsk->cputime_expires.prof_exp = cputime_zero; |
| @@ -1030,9 +1031,10 @@ static void check_thread_timers(struct task_struct *tsk, | |||
| 1030 | /* | 1031 | /* |
| 1031 | * Check for the special case thread timers. | 1032 | * Check for the special case thread timers. |
| 1032 | */ | 1033 | */ |
| 1033 | if (sig->rlim[RLIMIT_RTTIME].rlim_cur != RLIM_INFINITY) { | 1034 | soft = ACCESS_ONCE(sig->rlim[RLIMIT_RTTIME].rlim_cur); |
| 1034 | unsigned long hard = sig->rlim[RLIMIT_RTTIME].rlim_max; | 1035 | if (soft != RLIM_INFINITY) { |
| 1035 | unsigned long *soft = &sig->rlim[RLIMIT_RTTIME].rlim_cur; | 1036 | unsigned long hard = |
| 1037 | ACCESS_ONCE(sig->rlim[RLIMIT_RTTIME].rlim_max); | ||
| 1036 | 1038 | ||
| 1037 | if (hard != RLIM_INFINITY && | 1039 | if (hard != RLIM_INFINITY && |
| 1038 | tsk->rt.timeout > DIV_ROUND_UP(hard, USEC_PER_SEC/HZ)) { | 1040 | tsk->rt.timeout > DIV_ROUND_UP(hard, USEC_PER_SEC/HZ)) { |
| @@ -1043,14 +1045,13 @@ static void check_thread_timers(struct task_struct *tsk, | |||
| 1043 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); | 1045 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); |
| 1044 | return; | 1046 | return; |
| 1045 | } | 1047 | } |
| 1046 | if (tsk->rt.timeout > DIV_ROUND_UP(*soft, USEC_PER_SEC/HZ)) { | 1048 | if (tsk->rt.timeout > DIV_ROUND_UP(soft, USEC_PER_SEC/HZ)) { |
| 1047 | /* | 1049 | /* |
| 1048 | * At the soft limit, send a SIGXCPU every second. | 1050 | * At the soft limit, send a SIGXCPU every second. |
| 1049 | */ | 1051 | */ |
| 1050 | if (sig->rlim[RLIMIT_RTTIME].rlim_cur | 1052 | if (soft < hard) { |
| 1051 | < sig->rlim[RLIMIT_RTTIME].rlim_max) { | 1053 | soft += USEC_PER_SEC; |
| 1052 | sig->rlim[RLIMIT_RTTIME].rlim_cur += | 1054 | sig->rlim[RLIMIT_RTTIME].rlim_cur = soft; |
| 1053 | USEC_PER_SEC; | ||
| 1054 | } | 1055 | } |
| 1055 | printk(KERN_INFO | 1056 | printk(KERN_INFO |
| 1056 | "RT Watchdog Timeout: %s[%d]\n", | 1057 | "RT Watchdog Timeout: %s[%d]\n", |
| @@ -1121,6 +1122,7 @@ static void check_process_timers(struct task_struct *tsk, | |||
| 1121 | unsigned long long sum_sched_runtime, sched_expires; | 1122 | unsigned long long sum_sched_runtime, sched_expires; |
| 1122 | struct list_head *timers = sig->cpu_timers; | 1123 | struct list_head *timers = sig->cpu_timers; |
| 1123 | struct task_cputime cputime; | 1124 | struct task_cputime cputime; |
| 1125 | unsigned long soft; | ||
| 1124 | 1126 | ||
| 1125 | /* | 1127 | /* |
| 1126 | * Don't sample the current process CPU clocks if there are no timers. | 1128 | * Don't sample the current process CPU clocks if there are no timers. |
| @@ -1193,11 +1195,13 @@ static void check_process_timers(struct task_struct *tsk, | |||
| 1193 | SIGPROF); | 1195 | SIGPROF); |
| 1194 | check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime, | 1196 | check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime, |
| 1195 | SIGVTALRM); | 1197 | SIGVTALRM); |
| 1196 | 1198 | soft = ACCESS_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur); | |
| 1197 | if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) { | 1199 | if (soft != RLIM_INFINITY) { |
| 1198 | unsigned long psecs = cputime_to_secs(ptime); | 1200 | unsigned long psecs = cputime_to_secs(ptime); |
| 1201 | unsigned long hard = | ||
| 1202 | ACCESS_ONCE(sig->rlim[RLIMIT_CPU].rlim_max); | ||
| 1199 | cputime_t x; | 1203 | cputime_t x; |
| 1200 | if (psecs >= sig->rlim[RLIMIT_CPU].rlim_max) { | 1204 | if (psecs >= hard) { |
| 1201 | /* | 1205 | /* |
| 1202 | * At the hard limit, we just die. | 1206 | * At the hard limit, we just die. |
| 1203 | * No need to calculate anything else now. | 1207 | * No need to calculate anything else now. |
| @@ -1205,17 +1209,17 @@ static void check_process_timers(struct task_struct *tsk, | |||
| 1205 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); | 1209 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); |
| 1206 | return; | 1210 | return; |
| 1207 | } | 1211 | } |
| 1208 | if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) { | 1212 | if (psecs >= soft) { |
| 1209 | /* | 1213 | /* |
| 1210 | * At the soft limit, send a SIGXCPU every second. | 1214 | * At the soft limit, send a SIGXCPU every second. |
| 1211 | */ | 1215 | */ |
| 1212 | __group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk); | 1216 | __group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk); |
| 1213 | if (sig->rlim[RLIMIT_CPU].rlim_cur | 1217 | if (soft < hard) { |
| 1214 | < sig->rlim[RLIMIT_CPU].rlim_max) { | 1218 | soft++; |
| 1215 | sig->rlim[RLIMIT_CPU].rlim_cur++; | 1219 | sig->rlim[RLIMIT_CPU].rlim_cur = soft; |
| 1216 | } | 1220 | } |
| 1217 | } | 1221 | } |
| 1218 | x = secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur); | 1222 | x = secs_to_cputime(soft); |
| 1219 | if (cputime_eq(prof_expires, cputime_zero) || | 1223 | if (cputime_eq(prof_expires, cputime_zero) || |
| 1220 | cputime_lt(x, prof_expires)) { | 1224 | cputime_lt(x, prof_expires)) { |
| 1221 | prof_expires = x; | 1225 | prof_expires = x; |
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index bbfe472d7524..da5288ec2392 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c | |||
| @@ -323,6 +323,7 @@ static int create_image(int platform_mode) | |||
| 323 | int hibernation_snapshot(int platform_mode) | 323 | int hibernation_snapshot(int platform_mode) |
| 324 | { | 324 | { |
| 325 | int error; | 325 | int error; |
| 326 | gfp_t saved_mask; | ||
| 326 | 327 | ||
| 327 | error = platform_begin(platform_mode); | 328 | error = platform_begin(platform_mode); |
| 328 | if (error) | 329 | if (error) |
| @@ -334,6 +335,7 @@ int hibernation_snapshot(int platform_mode) | |||
| 334 | goto Close; | 335 | goto Close; |
| 335 | 336 | ||
| 336 | suspend_console(); | 337 | suspend_console(); |
| 338 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
| 337 | error = dpm_suspend_start(PMSG_FREEZE); | 339 | error = dpm_suspend_start(PMSG_FREEZE); |
| 338 | if (error) | 340 | if (error) |
| 339 | goto Recover_platform; | 341 | goto Recover_platform; |
| @@ -351,6 +353,7 @@ int hibernation_snapshot(int platform_mode) | |||
| 351 | 353 | ||
| 352 | dpm_resume_end(in_suspend ? | 354 | dpm_resume_end(in_suspend ? |
| 353 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); | 355 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); |
| 356 | set_gfp_allowed_mask(saved_mask); | ||
| 354 | resume_console(); | 357 | resume_console(); |
| 355 | Close: | 358 | Close: |
| 356 | platform_end(platform_mode); | 359 | platform_end(platform_mode); |
| @@ -445,14 +448,17 @@ static int resume_target_kernel(bool platform_mode) | |||
| 445 | int hibernation_restore(int platform_mode) | 448 | int hibernation_restore(int platform_mode) |
| 446 | { | 449 | { |
| 447 | int error; | 450 | int error; |
| 451 | gfp_t saved_mask; | ||
| 448 | 452 | ||
| 449 | pm_prepare_console(); | 453 | pm_prepare_console(); |
| 450 | suspend_console(); | 454 | suspend_console(); |
| 455 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
| 451 | error = dpm_suspend_start(PMSG_QUIESCE); | 456 | error = dpm_suspend_start(PMSG_QUIESCE); |
| 452 | if (!error) { | 457 | if (!error) { |
| 453 | error = resume_target_kernel(platform_mode); | 458 | error = resume_target_kernel(platform_mode); |
| 454 | dpm_resume_end(PMSG_RECOVER); | 459 | dpm_resume_end(PMSG_RECOVER); |
| 455 | } | 460 | } |
| 461 | set_gfp_allowed_mask(saved_mask); | ||
| 456 | resume_console(); | 462 | resume_console(); |
| 457 | pm_restore_console(); | 463 | pm_restore_console(); |
| 458 | return error; | 464 | return error; |
| @@ -466,6 +472,7 @@ int hibernation_restore(int platform_mode) | |||
| 466 | int hibernation_platform_enter(void) | 472 | int hibernation_platform_enter(void) |
| 467 | { | 473 | { |
| 468 | int error; | 474 | int error; |
| 475 | gfp_t saved_mask; | ||
| 469 | 476 | ||
| 470 | if (!hibernation_ops) | 477 | if (!hibernation_ops) |
| 471 | return -ENOSYS; | 478 | return -ENOSYS; |
| @@ -481,6 +488,7 @@ int hibernation_platform_enter(void) | |||
| 481 | 488 | ||
| 482 | entering_platform_hibernation = true; | 489 | entering_platform_hibernation = true; |
| 483 | suspend_console(); | 490 | suspend_console(); |
| 491 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
| 484 | error = dpm_suspend_start(PMSG_HIBERNATE); | 492 | error = dpm_suspend_start(PMSG_HIBERNATE); |
| 485 | if (error) { | 493 | if (error) { |
| 486 | if (hibernation_ops->recover) | 494 | if (hibernation_ops->recover) |
| @@ -518,6 +526,7 @@ int hibernation_platform_enter(void) | |||
| 518 | Resume_devices: | 526 | Resume_devices: |
| 519 | entering_platform_hibernation = false; | 527 | entering_platform_hibernation = false; |
| 520 | dpm_resume_end(PMSG_RESTORE); | 528 | dpm_resume_end(PMSG_RESTORE); |
| 529 | set_gfp_allowed_mask(saved_mask); | ||
| 521 | resume_console(); | 530 | resume_console(); |
| 522 | 531 | ||
| 523 | Close: | 532 | Close: |
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index 6f10dfc2d3e9..44cce10b582d 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c | |||
| @@ -189,6 +189,7 @@ static int suspend_enter(suspend_state_t state) | |||
| 189 | int suspend_devices_and_enter(suspend_state_t state) | 189 | int suspend_devices_and_enter(suspend_state_t state) |
| 190 | { | 190 | { |
| 191 | int error; | 191 | int error; |
| 192 | gfp_t saved_mask; | ||
| 192 | 193 | ||
| 193 | if (!suspend_ops) | 194 | if (!suspend_ops) |
| 194 | return -ENOSYS; | 195 | return -ENOSYS; |
| @@ -199,6 +200,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
| 199 | goto Close; | 200 | goto Close; |
| 200 | } | 201 | } |
| 201 | suspend_console(); | 202 | suspend_console(); |
| 203 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
| 202 | suspend_test_start(); | 204 | suspend_test_start(); |
| 203 | error = dpm_suspend_start(PMSG_SUSPEND); | 205 | error = dpm_suspend_start(PMSG_SUSPEND); |
| 204 | if (error) { | 206 | if (error) { |
| @@ -215,6 +217,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
| 215 | suspend_test_start(); | 217 | suspend_test_start(); |
| 216 | dpm_resume_end(PMSG_RESUME); | 218 | dpm_resume_end(PMSG_RESUME); |
| 217 | suspend_test_finish("resume devices"); | 219 | suspend_test_finish("resume devices"); |
| 220 | set_gfp_allowed_mask(saved_mask); | ||
| 218 | resume_console(); | 221 | resume_console(); |
| 219 | Close: | 222 | Close: |
| 220 | if (suspend_ops->end) | 223 | if (suspend_ops->end) |
diff --git a/kernel/printk.c b/kernel/printk.c index 1751c456b71f..75077ad0b537 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #include <linux/kexec.h> | 35 | #include <linux/kexec.h> |
| 36 | #include <linux/ratelimit.h> | 36 | #include <linux/ratelimit.h> |
| 37 | #include <linux/kmsg_dump.h> | 37 | #include <linux/kmsg_dump.h> |
| 38 | #include <linux/syslog.h> | ||
| 38 | 39 | ||
| 39 | #include <asm/uaccess.h> | 40 | #include <asm/uaccess.h> |
| 40 | 41 | ||
| @@ -69,8 +70,6 @@ int console_printk[4] = { | |||
| 69 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ | 70 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ |
| 70 | }; | 71 | }; |
| 71 | 72 | ||
| 72 | static int saved_console_loglevel = -1; | ||
| 73 | |||
| 74 | /* | 73 | /* |
| 75 | * Low level drivers may need that to know if they can schedule in | 74 | * Low level drivers may need that to know if they can schedule in |
| 76 | * their unblank() callback or not. So let's export it. | 75 | * their unblank() callback or not. So let's export it. |
| @@ -145,6 +144,7 @@ static char __log_buf[__LOG_BUF_LEN]; | |||
| 145 | static char *log_buf = __log_buf; | 144 | static char *log_buf = __log_buf; |
| 146 | static int log_buf_len = __LOG_BUF_LEN; | 145 | static int log_buf_len = __LOG_BUF_LEN; |
| 147 | static unsigned logged_chars; /* Number of chars produced since last read+clear operation */ | 146 | static unsigned logged_chars; /* Number of chars produced since last read+clear operation */ |
| 147 | static int saved_console_loglevel = -1; | ||
| 148 | 148 | ||
| 149 | #ifdef CONFIG_KEXEC | 149 | #ifdef CONFIG_KEXEC |
| 150 | /* | 150 | /* |
| @@ -258,38 +258,23 @@ static inline void boot_delay_msec(void) | |||
| 258 | } | 258 | } |
| 259 | #endif | 259 | #endif |
| 260 | 260 | ||
| 261 | /* | 261 | int do_syslog(int type, char __user *buf, int len, bool from_file) |
| 262 | * Commands to do_syslog: | ||
| 263 | * | ||
| 264 | * 0 -- Close the log. Currently a NOP. | ||
| 265 | * 1 -- Open the log. Currently a NOP. | ||
| 266 | * 2 -- Read from the log. | ||
| 267 | * 3 -- Read all messages remaining in the ring buffer. | ||
| 268 | * 4 -- Read and clear all messages remaining in the ring buffer | ||
| 269 | * 5 -- Clear ring buffer. | ||
| 270 | * 6 -- Disable printk's to console | ||
| 271 | * 7 -- Enable printk's to console | ||
| 272 | * 8 -- Set level of messages printed to console | ||
| 273 | * 9 -- Return number of unread characters in the log buffer | ||
| 274 | * 10 -- Return size of the log buffer | ||
| 275 | */ | ||
| 276 | int do_syslog(int type, char __user *buf, int len) | ||
| 277 | { | 262 | { |
| 278 | unsigned i, j, limit, count; | 263 | unsigned i, j, limit, count; |
| 279 | int do_clear = 0; | 264 | int do_clear = 0; |
| 280 | char c; | 265 | char c; |
| 281 | int error = 0; | 266 | int error = 0; |
| 282 | 267 | ||
| 283 | error = security_syslog(type); | 268 | error = security_syslog(type, from_file); |
| 284 | if (error) | 269 | if (error) |
| 285 | return error; | 270 | return error; |
| 286 | 271 | ||
| 287 | switch (type) { | 272 | switch (type) { |
| 288 | case 0: /* Close log */ | 273 | case SYSLOG_ACTION_CLOSE: /* Close log */ |
| 289 | break; | 274 | break; |
| 290 | case 1: /* Open log */ | 275 | case SYSLOG_ACTION_OPEN: /* Open log */ |
| 291 | break; | 276 | break; |
| 292 | case 2: /* Read from log */ | 277 | case SYSLOG_ACTION_READ: /* Read from log */ |
| 293 | error = -EINVAL; | 278 | error = -EINVAL; |
| 294 | if (!buf || len < 0) | 279 | if (!buf || len < 0) |
| 295 | goto out; | 280 | goto out; |
| @@ -320,10 +305,12 @@ int do_syslog(int type, char __user *buf, int len) | |||
| 320 | if (!error) | 305 | if (!error) |
| 321 | error = i; | 306 | error = i; |
| 322 | break; | 307 | break; |
| 323 | case 4: /* Read/clear last kernel messages */ | 308 | /* Read/clear last kernel messages */ |
| 309 | case SYSLOG_ACTION_READ_CLEAR: | ||
| 324 | do_clear = 1; | 310 | do_clear = 1; |
| 325 | /* FALL THRU */ | 311 | /* FALL THRU */ |
| 326 | case 3: /* Read last kernel messages */ | 312 | /* Read last kernel messages */ |
| 313 | case SYSLOG_ACTION_READ_ALL: | ||
| 327 | error = -EINVAL; | 314 | error = -EINVAL; |
| 328 | if (!buf || len < 0) | 315 | if (!buf || len < 0) |
| 329 | goto out; | 316 | goto out; |
| @@ -376,21 +363,25 @@ int do_syslog(int type, char __user *buf, int len) | |||
| 376 | } | 363 | } |
| 377 | } | 364 | } |
| 378 | break; | 365 | break; |
| 379 | case 5: /* Clear ring buffer */ | 366 | /* Clear ring buffer */ |
| 367 | case SYSLOG_ACTION_CLEAR: | ||
| 380 | logged_chars = 0; | 368 | logged_chars = 0; |
| 381 | break; | 369 | break; |
| 382 | case 6: /* Disable logging to console */ | 370 | /* Disable logging to console */ |
| 371 | case SYSLOG_ACTION_CONSOLE_OFF: | ||
| 383 | if (saved_console_loglevel == -1) | 372 | if (saved_console_loglevel == -1) |
| 384 | saved_console_loglevel = console_loglevel; | 373 | saved_console_loglevel = console_loglevel; |
| 385 | console_loglevel = minimum_console_loglevel; | 374 | console_loglevel = minimum_console_loglevel; |
| 386 | break; | 375 | break; |
| 387 | case 7: /* Enable logging to console */ | 376 | /* Enable logging to console */ |
| 377 | case SYSLOG_ACTION_CONSOLE_ON: | ||
| 388 | if (saved_console_loglevel != -1) { | 378 | if (saved_console_loglevel != -1) { |
| 389 | console_loglevel = saved_console_loglevel; | 379 | console_loglevel = saved_console_loglevel; |
| 390 | saved_console_loglevel = -1; | 380 | saved_console_loglevel = -1; |
| 391 | } | 381 | } |
| 392 | break; | 382 | break; |
| 393 | case 8: /* Set level of messages printed to console */ | 383 | /* Set level of messages printed to console */ |
| 384 | case SYSLOG_ACTION_CONSOLE_LEVEL: | ||
| 394 | error = -EINVAL; | 385 | error = -EINVAL; |
| 395 | if (len < 1 || len > 8) | 386 | if (len < 1 || len > 8) |
| 396 | goto out; | 387 | goto out; |
| @@ -401,10 +392,12 @@ int do_syslog(int type, char __user *buf, int len) | |||
| 401 | saved_console_loglevel = -1; | 392 | saved_console_loglevel = -1; |
| 402 | error = 0; | 393 | error = 0; |
| 403 | break; | 394 | break; |
| 404 | case 9: /* Number of chars in the log buffer */ | 395 | /* Number of chars in the log buffer */ |
| 396 | case SYSLOG_ACTION_SIZE_UNREAD: | ||
| 405 | error = log_end - log_start; | 397 | error = log_end - log_start; |
| 406 | break; | 398 | break; |
| 407 | case 10: /* Size of the log buffer */ | 399 | /* Size of the log buffer */ |
| 400 | case SYSLOG_ACTION_SIZE_BUFFER: | ||
| 408 | error = log_buf_len; | 401 | error = log_buf_len; |
| 409 | break; | 402 | break; |
| 410 | default: | 403 | default: |
| @@ -417,7 +410,7 @@ out: | |||
| 417 | 410 | ||
| 418 | SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len) | 411 | SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len) |
| 419 | { | 412 | { |
| 420 | return do_syslog(type, buf, len); | 413 | return do_syslog(type, buf, len, SYSLOG_FROM_CALL); |
| 421 | } | 414 | } |
| 422 | 415 | ||
| 423 | /* | 416 | /* |
diff --git a/kernel/range.c b/kernel/range.c new file mode 100644 index 000000000000..74e2e6114927 --- /dev/null +++ b/kernel/range.c | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | /* | ||
| 2 | * Range add and subtract | ||
| 3 | */ | ||
| 4 | #include <linux/module.h> | ||
| 5 | #include <linux/init.h> | ||
| 6 | #include <linux/sort.h> | ||
| 7 | |||
| 8 | #include <linux/range.h> | ||
| 9 | |||
| 10 | #ifndef ARRAY_SIZE | ||
| 11 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | ||
| 12 | #endif | ||
| 13 | |||
| 14 | int add_range(struct range *range, int az, int nr_range, u64 start, u64 end) | ||
| 15 | { | ||
| 16 | if (start >= end) | ||
| 17 | return nr_range; | ||
| 18 | |||
| 19 | /* Out of slots: */ | ||
| 20 | if (nr_range >= az) | ||
| 21 | return nr_range; | ||
| 22 | |||
| 23 | range[nr_range].start = start; | ||
| 24 | range[nr_range].end = end; | ||
| 25 | |||
| 26 | nr_range++; | ||
| 27 | |||
| 28 | return nr_range; | ||
| 29 | } | ||
| 30 | |||
| 31 | int add_range_with_merge(struct range *range, int az, int nr_range, | ||
| 32 | u64 start, u64 end) | ||
| 33 | { | ||
| 34 | int i; | ||
| 35 | |||
| 36 | if (start >= end) | ||
| 37 | return nr_range; | ||
| 38 | |||
| 39 | /* Try to merge it with old one: */ | ||
| 40 | for (i = 0; i < nr_range; i++) { | ||
| 41 | u64 final_start, final_end; | ||
| 42 | u64 common_start, common_end; | ||
| 43 | |||
| 44 | if (!range[i].end) | ||
| 45 | continue; | ||
| 46 | |||
| 47 | common_start = max(range[i].start, start); | ||
| 48 | common_end = min(range[i].end, end); | ||
| 49 | if (common_start > common_end) | ||
| 50 | continue; | ||
| 51 | |||
| 52 | final_start = min(range[i].start, start); | ||
| 53 | final_end = max(range[i].end, end); | ||
| 54 | |||
| 55 | range[i].start = final_start; | ||
| 56 | range[i].end = final_end; | ||
| 57 | return nr_range; | ||
| 58 | } | ||
| 59 | |||
| 60 | /* Need to add it: */ | ||
| 61 | return add_range(range, az, nr_range, start, end); | ||
| 62 | } | ||
| 63 | |||
| 64 | void subtract_range(struct range *range, int az, u64 start, u64 end) | ||
| 65 | { | ||
| 66 | int i, j; | ||
| 67 | |||
| 68 | if (start >= end) | ||
| 69 | return; | ||
| 70 | |||
| 71 | for (j = 0; j < az; j++) { | ||
| 72 | if (!range[j].end) | ||
| 73 | continue; | ||
| 74 | |||
| 75 | if (start <= range[j].start && end >= range[j].end) { | ||
| 76 | range[j].start = 0; | ||
| 77 | range[j].end = 0; | ||
| 78 | continue; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (start <= range[j].start && end < range[j].end && | ||
| 82 | range[j].start < end) { | ||
| 83 | range[j].start = end; | ||
| 84 | continue; | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | if (start > range[j].start && end >= range[j].end && | ||
| 89 | range[j].end > start) { | ||
| 90 | range[j].end = start; | ||
| 91 | continue; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (start > range[j].start && end < range[j].end) { | ||
| 95 | /* Find the new spare: */ | ||
| 96 | for (i = 0; i < az; i++) { | ||
| 97 | if (range[i].end == 0) | ||
| 98 | break; | ||
| 99 | } | ||
| 100 | if (i < az) { | ||
| 101 | range[i].end = range[j].end; | ||
| 102 | range[i].start = end; | ||
| 103 | } else { | ||
| 104 | printk(KERN_ERR "run of slot in ranges\n"); | ||
| 105 | } | ||
| 106 | range[j].end = start; | ||
| 107 | continue; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | static int cmp_range(const void *x1, const void *x2) | ||
| 113 | { | ||
| 114 | const struct range *r1 = x1; | ||
| 115 | const struct range *r2 = x2; | ||
| 116 | s64 start1, start2; | ||
| 117 | |||
| 118 | start1 = r1->start; | ||
| 119 | start2 = r2->start; | ||
| 120 | |||
| 121 | return start1 - start2; | ||
| 122 | } | ||
| 123 | |||
| 124 | int clean_sort_range(struct range *range, int az) | ||
| 125 | { | ||
| 126 | int i, j, k = az - 1, nr_range = 0; | ||
| 127 | |||
| 128 | for (i = 0; i < k; i++) { | ||
| 129 | if (range[i].end) | ||
| 130 | continue; | ||
| 131 | for (j = k; j > i; j--) { | ||
| 132 | if (range[j].end) { | ||
| 133 | k = j; | ||
| 134 | break; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | if (j == i) | ||
| 138 | break; | ||
| 139 | range[i].start = range[k].start; | ||
| 140 | range[i].end = range[k].end; | ||
| 141 | range[k].start = 0; | ||
| 142 | range[k].end = 0; | ||
| 143 | k--; | ||
| 144 | } | ||
| 145 | /* count it */ | ||
| 146 | for (i = 0; i < az; i++) { | ||
| 147 | if (!range[i].end) { | ||
| 148 | nr_range = i; | ||
| 149 | break; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | /* sort them */ | ||
| 154 | sort(range, nr_range, sizeof(struct range), cmp_range, NULL); | ||
| 155 | |||
| 156 | return nr_range; | ||
| 157 | } | ||
| 158 | |||
| 159 | void sort_range(struct range *range, int nr_range) | ||
| 160 | { | ||
| 161 | /* sort them */ | ||
| 162 | sort(range, nr_range, sizeof(struct range), cmp_range, NULL); | ||
| 163 | } | ||
diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 258cdf0a91eb..58df55bf83ed 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c | |||
| @@ -818,13 +818,13 @@ static void rcu_torture_timer(unsigned long unused) | |||
| 818 | /* Should not happen, but... */ | 818 | /* Should not happen, but... */ |
| 819 | pipe_count = RCU_TORTURE_PIPE_LEN; | 819 | pipe_count = RCU_TORTURE_PIPE_LEN; |
| 820 | } | 820 | } |
| 821 | __this_cpu_inc(per_cpu_var(rcu_torture_count)[pipe_count]); | 821 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
| 822 | completed = cur_ops->completed() - completed; | 822 | completed = cur_ops->completed() - completed; |
| 823 | if (completed > RCU_TORTURE_PIPE_LEN) { | 823 | if (completed > RCU_TORTURE_PIPE_LEN) { |
| 824 | /* Should not happen, but... */ | 824 | /* Should not happen, but... */ |
| 825 | completed = RCU_TORTURE_PIPE_LEN; | 825 | completed = RCU_TORTURE_PIPE_LEN; |
| 826 | } | 826 | } |
| 827 | __this_cpu_inc(per_cpu_var(rcu_torture_batch)[completed]); | 827 | __this_cpu_inc(rcu_torture_batch[completed]); |
| 828 | preempt_enable(); | 828 | preempt_enable(); |
| 829 | cur_ops->readunlock(idx); | 829 | cur_ops->readunlock(idx); |
| 830 | } | 830 | } |
| @@ -877,13 +877,13 @@ rcu_torture_reader(void *arg) | |||
| 877 | /* Should not happen, but... */ | 877 | /* Should not happen, but... */ |
| 878 | pipe_count = RCU_TORTURE_PIPE_LEN; | 878 | pipe_count = RCU_TORTURE_PIPE_LEN; |
| 879 | } | 879 | } |
| 880 | __this_cpu_inc(per_cpu_var(rcu_torture_count)[pipe_count]); | 880 | __this_cpu_inc(rcu_torture_count[pipe_count]); |
| 881 | completed = cur_ops->completed() - completed; | 881 | completed = cur_ops->completed() - completed; |
| 882 | if (completed > RCU_TORTURE_PIPE_LEN) { | 882 | if (completed > RCU_TORTURE_PIPE_LEN) { |
| 883 | /* Should not happen, but... */ | 883 | /* Should not happen, but... */ |
| 884 | completed = RCU_TORTURE_PIPE_LEN; | 884 | completed = RCU_TORTURE_PIPE_LEN; |
| 885 | } | 885 | } |
| 886 | __this_cpu_inc(per_cpu_var(rcu_torture_batch)[completed]); | 886 | __this_cpu_inc(rcu_torture_batch[completed]); |
| 887 | preempt_enable(); | 887 | preempt_enable(); |
| 888 | cur_ops->readunlock(idx); | 888 | cur_ops->readunlock(idx); |
| 889 | schedule(); | 889 | schedule(); |
diff --git a/kernel/relay.c b/kernel/relay.c index c705a41b4ba3..3d97f2821611 100644 --- a/kernel/relay.c +++ b/kernel/relay.c | |||
| @@ -1215,14 +1215,14 @@ static void relay_page_release(struct splice_pipe_desc *spd, unsigned int i) | |||
| 1215 | /* | 1215 | /* |
| 1216 | * subbuf_splice_actor - splice up to one subbuf's worth of data | 1216 | * subbuf_splice_actor - splice up to one subbuf's worth of data |
| 1217 | */ | 1217 | */ |
| 1218 | static int subbuf_splice_actor(struct file *in, | 1218 | static ssize_t subbuf_splice_actor(struct file *in, |
| 1219 | loff_t *ppos, | 1219 | loff_t *ppos, |
| 1220 | struct pipe_inode_info *pipe, | 1220 | struct pipe_inode_info *pipe, |
| 1221 | size_t len, | 1221 | size_t len, |
| 1222 | unsigned int flags, | 1222 | unsigned int flags, |
| 1223 | int *nonpad_ret) | 1223 | int *nonpad_ret) |
| 1224 | { | 1224 | { |
| 1225 | unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret; | 1225 | unsigned int pidx, poff, total_len, subbuf_pages, nr_pages; |
| 1226 | struct rchan_buf *rbuf = in->private_data; | 1226 | struct rchan_buf *rbuf = in->private_data; |
| 1227 | unsigned int subbuf_size = rbuf->chan->subbuf_size; | 1227 | unsigned int subbuf_size = rbuf->chan->subbuf_size; |
| 1228 | uint64_t pos = (uint64_t) *ppos; | 1228 | uint64_t pos = (uint64_t) *ppos; |
| @@ -1241,6 +1241,7 @@ static int subbuf_splice_actor(struct file *in, | |||
| 1241 | .ops = &relay_pipe_buf_ops, | 1241 | .ops = &relay_pipe_buf_ops, |
| 1242 | .spd_release = relay_page_release, | 1242 | .spd_release = relay_page_release, |
| 1243 | }; | 1243 | }; |
| 1244 | ssize_t ret; | ||
| 1244 | 1245 | ||
| 1245 | if (rbuf->subbufs_produced == rbuf->subbufs_consumed) | 1246 | if (rbuf->subbufs_produced == rbuf->subbufs_consumed) |
| 1246 | return 0; | 1247 | return 0; |
diff --git a/kernel/resource.c b/kernel/resource.c index 4e9d87fd7bc5..2d5be5d9bf5f 100644 --- a/kernel/resource.c +++ b/kernel/resource.c | |||
| @@ -304,7 +304,7 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, | |||
| 304 | void *arg, int (*func)(unsigned long, unsigned long, void *)) | 304 | void *arg, int (*func)(unsigned long, unsigned long, void *)) |
| 305 | { | 305 | { |
| 306 | struct resource res; | 306 | struct resource res; |
| 307 | unsigned long pfn, len; | 307 | unsigned long pfn, end_pfn; |
| 308 | u64 orig_end; | 308 | u64 orig_end; |
| 309 | int ret = -1; | 309 | int ret = -1; |
| 310 | 310 | ||
| @@ -314,9 +314,10 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, | |||
| 314 | orig_end = res.end; | 314 | orig_end = res.end; |
| 315 | while ((res.start < res.end) && | 315 | while ((res.start < res.end) && |
| 316 | (find_next_system_ram(&res, "System RAM") >= 0)) { | 316 | (find_next_system_ram(&res, "System RAM") >= 0)) { |
| 317 | pfn = (unsigned long)(res.start >> PAGE_SHIFT); | 317 | pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 318 | len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT); | 318 | end_pfn = (res.end + 1) >> PAGE_SHIFT; |
| 319 | ret = (*func)(pfn, len, arg); | 319 | if (end_pfn > pfn) |
| 320 | ret = (*func)(pfn, end_pfn - pfn, arg); | ||
| 320 | if (ret) | 321 | if (ret) |
| 321 | break; | 322 | break; |
| 322 | res.start = res.end + 1; | 323 | res.start = res.end + 1; |
diff --git a/kernel/sched.c b/kernel/sched.c index 6a212c97f523..150b6988de49 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -1521,7 +1521,7 @@ static unsigned long cpu_avg_load_per_task(int cpu) | |||
| 1521 | 1521 | ||
| 1522 | #ifdef CONFIG_FAIR_GROUP_SCHED | 1522 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 1523 | 1523 | ||
| 1524 | static __read_mostly unsigned long *update_shares_data; | 1524 | static __read_mostly unsigned long __percpu *update_shares_data; |
| 1525 | 1525 | ||
| 1526 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); | 1526 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); |
| 1527 | 1527 | ||
| @@ -4353,7 +4353,7 @@ int can_nice(const struct task_struct *p, const int nice) | |||
| 4353 | /* convert nice value [19,-20] to rlimit style value [1,40] */ | 4353 | /* convert nice value [19,-20] to rlimit style value [1,40] */ |
| 4354 | int nice_rlim = 20 - nice; | 4354 | int nice_rlim = 20 - nice; |
| 4355 | 4355 | ||
| 4356 | return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur || | 4356 | return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) || |
| 4357 | capable(CAP_SYS_NICE)); | 4357 | capable(CAP_SYS_NICE)); |
| 4358 | } | 4358 | } |
| 4359 | 4359 | ||
| @@ -4530,7 +4530,7 @@ recheck: | |||
| 4530 | 4530 | ||
| 4531 | if (!lock_task_sighand(p, &flags)) | 4531 | if (!lock_task_sighand(p, &flags)) |
| 4532 | return -ESRCH; | 4532 | return -ESRCH; |
| 4533 | rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur; | 4533 | rlim_rtprio = task_rlimit(p, RLIMIT_RTPRIO); |
| 4534 | unlock_task_sighand(p, &flags); | 4534 | unlock_task_sighand(p, &flags); |
| 4535 | 4535 | ||
| 4536 | /* can't set/change the rt policy */ | 4536 | /* can't set/change the rt policy */ |
| @@ -7406,11 +7406,13 @@ static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | |||
| 7406 | 7406 | ||
| 7407 | #ifdef CONFIG_SCHED_MC | 7407 | #ifdef CONFIG_SCHED_MC |
| 7408 | static ssize_t sched_mc_power_savings_show(struct sysdev_class *class, | 7408 | static ssize_t sched_mc_power_savings_show(struct sysdev_class *class, |
| 7409 | struct sysdev_class_attribute *attr, | ||
| 7409 | char *page) | 7410 | char *page) |
| 7410 | { | 7411 | { |
| 7411 | return sprintf(page, "%u\n", sched_mc_power_savings); | 7412 | return sprintf(page, "%u\n", sched_mc_power_savings); |
| 7412 | } | 7413 | } |
| 7413 | static ssize_t sched_mc_power_savings_store(struct sysdev_class *class, | 7414 | static ssize_t sched_mc_power_savings_store(struct sysdev_class *class, |
| 7415 | struct sysdev_class_attribute *attr, | ||
| 7414 | const char *buf, size_t count) | 7416 | const char *buf, size_t count) |
| 7415 | { | 7417 | { |
| 7416 | return sched_power_savings_store(buf, count, 0); | 7418 | return sched_power_savings_store(buf, count, 0); |
| @@ -7422,11 +7424,13 @@ static SYSDEV_CLASS_ATTR(sched_mc_power_savings, 0644, | |||
| 7422 | 7424 | ||
| 7423 | #ifdef CONFIG_SCHED_SMT | 7425 | #ifdef CONFIG_SCHED_SMT |
| 7424 | static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev, | 7426 | static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev, |
| 7427 | struct sysdev_class_attribute *attr, | ||
| 7425 | char *page) | 7428 | char *page) |
| 7426 | { | 7429 | { |
| 7427 | return sprintf(page, "%u\n", sched_smt_power_savings); | 7430 | return sprintf(page, "%u\n", sched_smt_power_savings); |
| 7428 | } | 7431 | } |
| 7429 | static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev, | 7432 | static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev, |
| 7433 | struct sysdev_class_attribute *attr, | ||
| 7430 | const char *buf, size_t count) | 7434 | const char *buf, size_t count) |
| 7431 | { | 7435 | { |
| 7432 | return sched_power_savings_store(buf, count, 1); | 7436 | return sched_power_savings_store(buf, count, 1); |
| @@ -8813,7 +8817,7 @@ struct cgroup_subsys cpu_cgroup_subsys = { | |||
| 8813 | struct cpuacct { | 8817 | struct cpuacct { |
| 8814 | struct cgroup_subsys_state css; | 8818 | struct cgroup_subsys_state css; |
| 8815 | /* cpuusage holds pointer to a u64-type object on every cpu */ | 8819 | /* cpuusage holds pointer to a u64-type object on every cpu */ |
| 8816 | u64 *cpuusage; | 8820 | u64 __percpu *cpuusage; |
| 8817 | struct percpu_counter cpustat[CPUACCT_STAT_NSTATS]; | 8821 | struct percpu_counter cpustat[CPUACCT_STAT_NSTATS]; |
| 8818 | struct cpuacct *parent; | 8822 | struct cpuacct *parent; |
| 8819 | }; | 8823 | }; |
diff --git a/kernel/sched_cpupri.c b/kernel/sched_cpupri.c index eeb3506c4834..fccf9fbb0d7b 100644 --- a/kernel/sched_cpupri.c +++ b/kernel/sched_cpupri.c | |||
| @@ -47,7 +47,7 @@ static int convert_prio(int prio) | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | #define for_each_cpupri_active(array, idx) \ | 49 | #define for_each_cpupri_active(array, idx) \ |
| 50 | for_each_bit(idx, array, CPUPRI_NR_PRIORITIES) | 50 | for_each_set_bit(idx, array, CPUPRI_NR_PRIORITIES) |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * cpupri_find - find the best (lowest-pri) CPU in the system | 53 | * cpupri_find - find the best (lowest-pri) CPU in the system |
| @@ -56,7 +56,7 @@ static int convert_prio(int prio) | |||
| 56 | * @lowest_mask: A mask to fill in with selected CPUs (or NULL) | 56 | * @lowest_mask: A mask to fill in with selected CPUs (or NULL) |
| 57 | * | 57 | * |
| 58 | * Note: This function returns the recommended CPUs as calculated during the | 58 | * Note: This function returns the recommended CPUs as calculated during the |
| 59 | * current invokation. By the time the call returns, the CPUs may have in | 59 | * current invocation. By the time the call returns, the CPUs may have in |
| 60 | * fact changed priorities any number of times. While not ideal, it is not | 60 | * fact changed priorities any number of times. While not ideal, it is not |
| 61 | * an issue of correctness since the normal rebalancer logic will correct | 61 | * an issue of correctness since the normal rebalancer logic will correct |
| 62 | * any discrepancies created by racing against the uncertainty of the current | 62 | * any discrepancies created by racing against the uncertainty of the current |
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index bf3e38fdbe6d..5a6ed1f0990a 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
| @@ -1662,8 +1662,9 @@ static void watchdog(struct rq *rq, struct task_struct *p) | |||
| 1662 | if (!p->signal) | 1662 | if (!p->signal) |
| 1663 | return; | 1663 | return; |
| 1664 | 1664 | ||
| 1665 | soft = p->signal->rlim[RLIMIT_RTTIME].rlim_cur; | 1665 | /* max may change after cur was read, this will be fixed next tick */ |
| 1666 | hard = p->signal->rlim[RLIMIT_RTTIME].rlim_max; | 1666 | soft = task_rlimit(p, RLIMIT_RTTIME); |
| 1667 | hard = task_rlimit_max(p, RLIMIT_RTTIME); | ||
| 1667 | 1668 | ||
| 1668 | if (soft != RLIM_INFINITY) { | 1669 | if (soft != RLIM_INFINITY) { |
| 1669 | unsigned long next; | 1670 | unsigned long next; |
diff --git a/kernel/signal.c b/kernel/signal.c index 934ae5e687b9..dbd7fe073c55 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
| @@ -159,6 +159,10 @@ void recalc_sigpending(void) | |||
| 159 | 159 | ||
| 160 | /* Given the mask, find the first available signal that should be serviced. */ | 160 | /* Given the mask, find the first available signal that should be serviced. */ |
| 161 | 161 | ||
| 162 | #define SYNCHRONOUS_MASK \ | ||
| 163 | (sigmask(SIGSEGV) | sigmask(SIGBUS) | sigmask(SIGILL) | \ | ||
| 164 | sigmask(SIGTRAP) | sigmask(SIGFPE)) | ||
| 165 | |||
| 162 | int next_signal(struct sigpending *pending, sigset_t *mask) | 166 | int next_signal(struct sigpending *pending, sigset_t *mask) |
| 163 | { | 167 | { |
| 164 | unsigned long i, *s, *m, x; | 168 | unsigned long i, *s, *m, x; |
| @@ -166,26 +170,39 @@ int next_signal(struct sigpending *pending, sigset_t *mask) | |||
| 166 | 170 | ||
| 167 | s = pending->signal.sig; | 171 | s = pending->signal.sig; |
| 168 | m = mask->sig; | 172 | m = mask->sig; |
| 173 | |||
| 174 | /* | ||
| 175 | * Handle the first word specially: it contains the | ||
| 176 | * synchronous signals that need to be dequeued first. | ||
| 177 | */ | ||
| 178 | x = *s &~ *m; | ||
| 179 | if (x) { | ||
| 180 | if (x & SYNCHRONOUS_MASK) | ||
| 181 | x &= SYNCHRONOUS_MASK; | ||
| 182 | sig = ffz(~x) + 1; | ||
| 183 | return sig; | ||
| 184 | } | ||
| 185 | |||
| 169 | switch (_NSIG_WORDS) { | 186 | switch (_NSIG_WORDS) { |
| 170 | default: | 187 | default: |
| 171 | for (i = 0; i < _NSIG_WORDS; ++i, ++s, ++m) | 188 | for (i = 1; i < _NSIG_WORDS; ++i) { |
| 172 | if ((x = *s &~ *m) != 0) { | 189 | x = *++s &~ *++m; |
| 173 | sig = ffz(~x) + i*_NSIG_BPW + 1; | 190 | if (!x) |
| 174 | break; | 191 | continue; |
| 175 | } | 192 | sig = ffz(~x) + i*_NSIG_BPW + 1; |
| 193 | break; | ||
| 194 | } | ||
| 176 | break; | 195 | break; |
| 177 | 196 | ||
| 178 | case 2: if ((x = s[0] &~ m[0]) != 0) | 197 | case 2: |
| 179 | sig = 1; | 198 | x = s[1] &~ m[1]; |
| 180 | else if ((x = s[1] &~ m[1]) != 0) | 199 | if (!x) |
| 181 | sig = _NSIG_BPW + 1; | ||
| 182 | else | ||
| 183 | break; | 200 | break; |
| 184 | sig += ffz(~x); | 201 | sig = ffz(~x) + _NSIG_BPW + 1; |
| 185 | break; | 202 | break; |
| 186 | 203 | ||
| 187 | case 1: if ((x = *s &~ *m) != 0) | 204 | case 1: |
| 188 | sig = ffz(~x) + 1; | 205 | /* Nothing to do */ |
| 189 | break; | 206 | break; |
| 190 | } | 207 | } |
| 191 | 208 | ||
| @@ -228,7 +245,7 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi | |||
| 228 | 245 | ||
| 229 | if (override_rlimit || | 246 | if (override_rlimit || |
| 230 | atomic_read(&user->sigpending) <= | 247 | atomic_read(&user->sigpending) <= |
| 231 | t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur) { | 248 | task_rlimit(t, RLIMIT_SIGPENDING)) { |
| 232 | q = kmem_cache_alloc(sigqueue_cachep, flags); | 249 | q = kmem_cache_alloc(sigqueue_cachep, flags); |
| 233 | } else { | 250 | } else { |
| 234 | print_dropped_signal(sig); | 251 | print_dropped_signal(sig); |
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 912823e2a11b..9bb9fb1bd79c 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c | |||
| @@ -45,7 +45,7 @@ static int refcount; | |||
| 45 | static struct workqueue_struct *stop_machine_wq; | 45 | static struct workqueue_struct *stop_machine_wq; |
| 46 | static struct stop_machine_data active, idle; | 46 | static struct stop_machine_data active, idle; |
| 47 | static const struct cpumask *active_cpus; | 47 | static const struct cpumask *active_cpus; |
| 48 | static void *stop_machine_work; | 48 | static void __percpu *stop_machine_work; |
| 49 | 49 | ||
| 50 | static void set_state(enum stopmachine_state newstate) | 50 | static void set_state(enum stopmachine_state newstate) |
| 51 | { | 51 | { |
diff --git a/kernel/sys.c b/kernel/sys.c index 877fe4f8e05e..8298878f4f71 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
| @@ -33,6 +33,7 @@ | |||
| 33 | #include <linux/task_io_accounting_ops.h> | 33 | #include <linux/task_io_accounting_ops.h> |
| 34 | #include <linux/seccomp.h> | 34 | #include <linux/seccomp.h> |
| 35 | #include <linux/cpu.h> | 35 | #include <linux/cpu.h> |
| 36 | #include <linux/personality.h> | ||
| 36 | #include <linux/ptrace.h> | 37 | #include <linux/ptrace.h> |
| 37 | #include <linux/fs_struct.h> | 38 | #include <linux/fs_struct.h> |
| 38 | 39 | ||
| @@ -571,8 +572,7 @@ static int set_user(struct cred *new) | |||
| 571 | if (!new_user) | 572 | if (!new_user) |
| 572 | return -EAGAIN; | 573 | return -EAGAIN; |
| 573 | 574 | ||
| 574 | if (atomic_read(&new_user->processes) >= | 575 | if (atomic_read(&new_user->processes) >= rlimit(RLIMIT_NPROC) && |
| 575 | current->signal->rlim[RLIMIT_NPROC].rlim_cur && | ||
| 576 | new_user != INIT_USER) { | 576 | new_user != INIT_USER) { |
| 577 | free_uid(new_user); | 577 | free_uid(new_user); |
| 578 | return -EAGAIN; | 578 | return -EAGAIN; |
| @@ -1115,6 +1115,15 @@ out: | |||
| 1115 | 1115 | ||
| 1116 | DECLARE_RWSEM(uts_sem); | 1116 | DECLARE_RWSEM(uts_sem); |
| 1117 | 1117 | ||
| 1118 | #ifdef COMPAT_UTS_MACHINE | ||
| 1119 | #define override_architecture(name) \ | ||
| 1120 | (current->personality == PER_LINUX32 && \ | ||
| 1121 | copy_to_user(name->machine, COMPAT_UTS_MACHINE, \ | ||
| 1122 | sizeof(COMPAT_UTS_MACHINE))) | ||
| 1123 | #else | ||
| 1124 | #define override_architecture(name) 0 | ||
| 1125 | #endif | ||
| 1126 | |||
| 1118 | SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name) | 1127 | SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name) |
| 1119 | { | 1128 | { |
| 1120 | int errno = 0; | 1129 | int errno = 0; |
| @@ -1123,9 +1132,66 @@ SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name) | |||
| 1123 | if (copy_to_user(name, utsname(), sizeof *name)) | 1132 | if (copy_to_user(name, utsname(), sizeof *name)) |
| 1124 | errno = -EFAULT; | 1133 | errno = -EFAULT; |
| 1125 | up_read(&uts_sem); | 1134 | up_read(&uts_sem); |
| 1135 | |||
| 1136 | if (!errno && override_architecture(name)) | ||
| 1137 | errno = -EFAULT; | ||
| 1126 | return errno; | 1138 | return errno; |
| 1127 | } | 1139 | } |
| 1128 | 1140 | ||
| 1141 | #ifdef __ARCH_WANT_SYS_OLD_UNAME | ||
| 1142 | /* | ||
| 1143 | * Old cruft | ||
| 1144 | */ | ||
| 1145 | SYSCALL_DEFINE1(uname, struct old_utsname __user *, name) | ||
| 1146 | { | ||
| 1147 | int error = 0; | ||
| 1148 | |||
| 1149 | if (!name) | ||
| 1150 | return -EFAULT; | ||
| 1151 | |||
| 1152 | down_read(&uts_sem); | ||
| 1153 | if (copy_to_user(name, utsname(), sizeof(*name))) | ||
| 1154 | error = -EFAULT; | ||
| 1155 | up_read(&uts_sem); | ||
| 1156 | |||
| 1157 | if (!error && override_architecture(name)) | ||
| 1158 | error = -EFAULT; | ||
| 1159 | return error; | ||
| 1160 | } | ||
| 1161 | |||
| 1162 | SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name) | ||
| 1163 | { | ||
| 1164 | int error; | ||
| 1165 | |||
| 1166 | if (!name) | ||
| 1167 | return -EFAULT; | ||
| 1168 | if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname))) | ||
| 1169 | return -EFAULT; | ||
| 1170 | |||
| 1171 | down_read(&uts_sem); | ||
| 1172 | error = __copy_to_user(&name->sysname, &utsname()->sysname, | ||
| 1173 | __OLD_UTS_LEN); | ||
| 1174 | error |= __put_user(0, name->sysname + __OLD_UTS_LEN); | ||
| 1175 | error |= __copy_to_user(&name->nodename, &utsname()->nodename, | ||
| 1176 | __OLD_UTS_LEN); | ||
| 1177 | error |= __put_user(0, name->nodename + __OLD_UTS_LEN); | ||
| 1178 | error |= __copy_to_user(&name->release, &utsname()->release, | ||
| 1179 | __OLD_UTS_LEN); | ||
| 1180 | error |= __put_user(0, name->release + __OLD_UTS_LEN); | ||
| 1181 | error |= __copy_to_user(&name->version, &utsname()->version, | ||
| 1182 | __OLD_UTS_LEN); | ||
| 1183 | error |= __put_user(0, name->version + __OLD_UTS_LEN); | ||
| 1184 | error |= __copy_to_user(&name->machine, &utsname()->machine, | ||
| 1185 | __OLD_UTS_LEN); | ||
| 1186 | error |= __put_user(0, name->machine + __OLD_UTS_LEN); | ||
| 1187 | up_read(&uts_sem); | ||
| 1188 | |||
| 1189 | if (!error && override_architecture(name)) | ||
| 1190 | error = -EFAULT; | ||
| 1191 | return error ? -EFAULT : 0; | ||
| 1192 | } | ||
| 1193 | #endif | ||
| 1194 | |||
| 1129 | SYSCALL_DEFINE2(sethostname, char __user *, name, int, len) | 1195 | SYSCALL_DEFINE2(sethostname, char __user *, name, int, len) |
| 1130 | { | 1196 | { |
| 1131 | int errno; | 1197 | int errno; |
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 695384f12a7d..70f2ea758ffe 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c | |||
| @@ -126,6 +126,7 @@ cond_syscall(sys_setreuid16); | |||
| 126 | cond_syscall(sys_setuid16); | 126 | cond_syscall(sys_setuid16); |
| 127 | cond_syscall(sys_vm86old); | 127 | cond_syscall(sys_vm86old); |
| 128 | cond_syscall(sys_vm86); | 128 | cond_syscall(sys_vm86); |
| 129 | cond_syscall(sys_ipc); | ||
| 129 | cond_syscall(compat_sys_ipc); | 130 | cond_syscall(compat_sys_ipc); |
| 130 | cond_syscall(compat_sys_sysctl); | 131 | cond_syscall(compat_sys_sysctl); |
| 131 | cond_syscall(sys_flock); | 132 | cond_syscall(sys_flock); |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8a68b2448468..8686b0f5fc12 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include <linux/swap.h> | 23 | #include <linux/swap.h> |
| 24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
| 25 | #include <linux/sysctl.h> | 25 | #include <linux/sysctl.h> |
| 26 | #include <linux/signal.h> | ||
| 26 | #include <linux/proc_fs.h> | 27 | #include <linux/proc_fs.h> |
| 27 | #include <linux/security.h> | 28 | #include <linux/security.h> |
| 28 | #include <linux/ctype.h> | 29 | #include <linux/ctype.h> |
| @@ -50,6 +51,7 @@ | |||
| 50 | #include <linux/ftrace.h> | 51 | #include <linux/ftrace.h> |
| 51 | #include <linux/slow-work.h> | 52 | #include <linux/slow-work.h> |
| 52 | #include <linux/perf_event.h> | 53 | #include <linux/perf_event.h> |
| 54 | #include <linux/kprobes.h> | ||
| 53 | 55 | ||
| 54 | #include <asm/uaccess.h> | 56 | #include <asm/uaccess.h> |
| 55 | #include <asm/processor.h> | 57 | #include <asm/processor.h> |
| @@ -59,13 +61,23 @@ | |||
| 59 | #include <asm/stacktrace.h> | 61 | #include <asm/stacktrace.h> |
| 60 | #include <asm/io.h> | 62 | #include <asm/io.h> |
| 61 | #endif | 63 | #endif |
| 64 | #ifdef CONFIG_BSD_PROCESS_ACCT | ||
| 65 | #include <linux/acct.h> | ||
| 66 | #endif | ||
| 67 | #ifdef CONFIG_RT_MUTEXES | ||
| 68 | #include <linux/rtmutex.h> | ||
| 69 | #endif | ||
| 70 | #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT) | ||
| 71 | #include <linux/lockdep.h> | ||
| 72 | #endif | ||
| 73 | #ifdef CONFIG_CHR_DEV_SG | ||
| 74 | #include <scsi/sg.h> | ||
| 75 | #endif | ||
| 62 | 76 | ||
| 63 | 77 | ||
| 64 | #if defined(CONFIG_SYSCTL) | 78 | #if defined(CONFIG_SYSCTL) |
| 65 | 79 | ||
| 66 | /* External variables not in a header file. */ | 80 | /* External variables not in a header file. */ |
| 67 | extern int C_A_D; | ||
| 68 | extern int print_fatal_signals; | ||
| 69 | extern int sysctl_overcommit_memory; | 81 | extern int sysctl_overcommit_memory; |
| 70 | extern int sysctl_overcommit_ratio; | 82 | extern int sysctl_overcommit_ratio; |
| 71 | extern int sysctl_panic_on_oom; | 83 | extern int sysctl_panic_on_oom; |
| @@ -87,9 +99,6 @@ extern int sysctl_nr_open_min, sysctl_nr_open_max; | |||
| 87 | #ifndef CONFIG_MMU | 99 | #ifndef CONFIG_MMU |
| 88 | extern int sysctl_nr_trim_pages; | 100 | extern int sysctl_nr_trim_pages; |
| 89 | #endif | 101 | #endif |
| 90 | #ifdef CONFIG_RCU_TORTURE_TEST | ||
| 91 | extern int rcutorture_runnable; | ||
| 92 | #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ | ||
| 93 | #ifdef CONFIG_BLOCK | 102 | #ifdef CONFIG_BLOCK |
| 94 | extern int blk_iopoll_enabled; | 103 | extern int blk_iopoll_enabled; |
| 95 | #endif | 104 | #endif |
| @@ -119,14 +128,6 @@ static int min_percpu_pagelist_fract = 8; | |||
| 119 | 128 | ||
| 120 | static int ngroups_max = NGROUPS_MAX; | 129 | static int ngroups_max = NGROUPS_MAX; |
| 121 | 130 | ||
| 122 | #ifdef CONFIG_MODULES | ||
| 123 | extern char modprobe_path[]; | ||
| 124 | extern int modules_disabled; | ||
| 125 | #endif | ||
| 126 | #ifdef CONFIG_CHR_DEV_SG | ||
| 127 | extern int sg_big_buff; | ||
| 128 | #endif | ||
| 129 | |||
| 130 | #ifdef CONFIG_SPARC | 131 | #ifdef CONFIG_SPARC |
| 131 | #include <asm/system.h> | 132 | #include <asm/system.h> |
| 132 | #endif | 133 | #endif |
| @@ -148,10 +149,6 @@ extern int sysctl_userprocess_debug; | |||
| 148 | extern int spin_retry; | 149 | extern int spin_retry; |
| 149 | #endif | 150 | #endif |
| 150 | 151 | ||
| 151 | #ifdef CONFIG_BSD_PROCESS_ACCT | ||
| 152 | extern int acct_parm[]; | ||
| 153 | #endif | ||
| 154 | |||
| 155 | #ifdef CONFIG_IA64 | 152 | #ifdef CONFIG_IA64 |
| 156 | extern int no_unaligned_warning; | 153 | extern int no_unaligned_warning; |
| 157 | extern int unaligned_dump_stack; | 154 | extern int unaligned_dump_stack; |
| @@ -159,10 +156,6 @@ extern int unaligned_dump_stack; | |||
| 159 | 156 | ||
| 160 | extern struct ratelimit_state printk_ratelimit_state; | 157 | extern struct ratelimit_state printk_ratelimit_state; |
| 161 | 158 | ||
| 162 | #ifdef CONFIG_RT_MUTEXES | ||
| 163 | extern int max_lock_depth; | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #ifdef CONFIG_PROC_SYSCTL | 159 | #ifdef CONFIG_PROC_SYSCTL |
| 167 | static int proc_do_cad_pid(struct ctl_table *table, int write, | 160 | static int proc_do_cad_pid(struct ctl_table *table, int write, |
| 168 | void __user *buffer, size_t *lenp, loff_t *ppos); | 161 | void __user *buffer, size_t *lenp, loff_t *ppos); |
| @@ -201,9 +194,6 @@ extern struct ctl_table epoll_table[]; | |||
| 201 | int sysctl_legacy_va_layout; | 194 | int sysctl_legacy_va_layout; |
| 202 | #endif | 195 | #endif |
| 203 | 196 | ||
| 204 | extern int prove_locking; | ||
| 205 | extern int lock_stat; | ||
| 206 | |||
| 207 | /* The default sysctl tables: */ | 197 | /* The default sysctl tables: */ |
| 208 | 198 | ||
| 209 | static struct ctl_table root_table[] = { | 199 | static struct ctl_table root_table[] = { |
| @@ -1441,7 +1431,7 @@ static struct ctl_table fs_table[] = { | |||
| 1441 | }; | 1431 | }; |
| 1442 | 1432 | ||
| 1443 | static struct ctl_table debug_table[] = { | 1433 | static struct ctl_table debug_table[] = { |
| 1444 | #if defined(CONFIG_X86) || defined(CONFIG_PPC) | 1434 | #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) |
| 1445 | { | 1435 | { |
| 1446 | .procname = "exception-trace", | 1436 | .procname = "exception-trace", |
| 1447 | .data = &show_unhandled_signals, | 1437 | .data = &show_unhandled_signals, |
| @@ -1450,6 +1440,17 @@ static struct ctl_table debug_table[] = { | |||
| 1450 | .proc_handler = proc_dointvec | 1440 | .proc_handler = proc_dointvec |
| 1451 | }, | 1441 | }, |
| 1452 | #endif | 1442 | #endif |
| 1443 | #if defined(CONFIG_OPTPROBES) | ||
| 1444 | { | ||
| 1445 | .procname = "kprobes-optimization", | ||
| 1446 | .data = &sysctl_kprobes_optimization, | ||
| 1447 | .maxlen = sizeof(int), | ||
| 1448 | .mode = 0644, | ||
| 1449 | .proc_handler = proc_kprobes_optimization_handler, | ||
| 1450 | .extra1 = &zero, | ||
| 1451 | .extra2 = &one, | ||
| 1452 | }, | ||
| 1453 | #endif | ||
| 1453 | { } | 1454 | { } |
| 1454 | }; | 1455 | }; |
| 1455 | 1456 | ||
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c index 8f5d16e0707a..8cd50d8f9bde 100644 --- a/kernel/sysctl_binary.c +++ b/kernel/sysctl_binary.c | |||
| @@ -1331,7 +1331,7 @@ static ssize_t binary_sysctl(const int *name, int nlen, | |||
| 1331 | ssize_t result; | 1331 | ssize_t result; |
| 1332 | char *pathname; | 1332 | char *pathname; |
| 1333 | int flags; | 1333 | int flags; |
| 1334 | int acc_mode, fmode; | 1334 | int acc_mode; |
| 1335 | 1335 | ||
| 1336 | pathname = sysctl_getname(name, nlen, &table); | 1336 | pathname = sysctl_getname(name, nlen, &table); |
| 1337 | result = PTR_ERR(pathname); | 1337 | result = PTR_ERR(pathname); |
| @@ -1342,15 +1342,12 @@ static ssize_t binary_sysctl(const int *name, int nlen, | |||
| 1342 | if (oldval && oldlen && newval && newlen) { | 1342 | if (oldval && oldlen && newval && newlen) { |
| 1343 | flags = O_RDWR; | 1343 | flags = O_RDWR; |
| 1344 | acc_mode = MAY_READ | MAY_WRITE; | 1344 | acc_mode = MAY_READ | MAY_WRITE; |
| 1345 | fmode = FMODE_READ | FMODE_WRITE; | ||
| 1346 | } else if (newval && newlen) { | 1345 | } else if (newval && newlen) { |
| 1347 | flags = O_WRONLY; | 1346 | flags = O_WRONLY; |
| 1348 | acc_mode = MAY_WRITE; | 1347 | acc_mode = MAY_WRITE; |
| 1349 | fmode = FMODE_WRITE; | ||
| 1350 | } else if (oldval && oldlen) { | 1348 | } else if (oldval && oldlen) { |
| 1351 | flags = O_RDONLY; | 1349 | flags = O_RDONLY; |
| 1352 | acc_mode = MAY_READ; | 1350 | acc_mode = MAY_READ; |
| 1353 | fmode = FMODE_READ; | ||
| 1354 | } else { | 1351 | } else { |
| 1355 | result = 0; | 1352 | result = 0; |
| 1356 | goto out_putname; | 1353 | goto out_putname; |
| @@ -1361,7 +1358,7 @@ static ssize_t binary_sysctl(const int *name, int nlen, | |||
| 1361 | if (result) | 1358 | if (result) |
| 1362 | goto out_putname; | 1359 | goto out_putname; |
| 1363 | 1360 | ||
| 1364 | result = may_open(&nd.path, acc_mode, fmode); | 1361 | result = may_open(&nd.path, acc_mode, flags); |
| 1365 | if (result) | 1362 | if (result) |
| 1366 | goto out_putpath; | 1363 | goto out_putpath; |
| 1367 | 1364 | ||
diff --git a/kernel/taskstats.c b/kernel/taskstats.c index ea8384d3caa7..899ca51be5e8 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c | |||
| @@ -46,15 +46,13 @@ static struct genl_family family = { | |||
| 46 | .maxattr = TASKSTATS_CMD_ATTR_MAX, | 46 | .maxattr = TASKSTATS_CMD_ATTR_MAX, |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | static struct nla_policy taskstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] | 49 | static const struct nla_policy taskstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] = { |
| 50 | __read_mostly = { | ||
| 51 | [TASKSTATS_CMD_ATTR_PID] = { .type = NLA_U32 }, | 50 | [TASKSTATS_CMD_ATTR_PID] = { .type = NLA_U32 }, |
| 52 | [TASKSTATS_CMD_ATTR_TGID] = { .type = NLA_U32 }, | 51 | [TASKSTATS_CMD_ATTR_TGID] = { .type = NLA_U32 }, |
| 53 | [TASKSTATS_CMD_ATTR_REGISTER_CPUMASK] = { .type = NLA_STRING }, | 52 | [TASKSTATS_CMD_ATTR_REGISTER_CPUMASK] = { .type = NLA_STRING }, |
| 54 | [TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK] = { .type = NLA_STRING },}; | 53 | [TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK] = { .type = NLA_STRING },}; |
| 55 | 54 | ||
| 56 | static struct nla_policy | 55 | static const struct nla_policy cgroupstats_cmd_get_policy[CGROUPSTATS_CMD_ATTR_MAX+1] = { |
| 57 | cgroupstats_cmd_get_policy[CGROUPSTATS_CMD_ATTR_MAX+1] __read_mostly = { | ||
| 58 | [CGROUPSTATS_CMD_ATTR_FD] = { .type = NLA_U32 }, | 56 | [CGROUPSTATS_CMD_ATTR_FD] = { .type = NLA_U32 }, |
| 59 | }; | 57 | }; |
| 60 | 58 | ||
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 8c1b2d290718..a2f0fe951831 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/cpu.h> | 20 | #include <linux/cpu.h> |
| 21 | #include <linux/fs.h> | 21 | #include <linux/fs.h> |
| 22 | 22 | ||
| 23 | #include <asm/local.h> | ||
| 23 | #include "trace.h" | 24 | #include "trace.h" |
| 24 | 25 | ||
| 25 | /* | 26 | /* |
| @@ -2541,7 +2542,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_disable); | |||
| 2541 | * @buffer: The ring buffer to enable writes | 2542 | * @buffer: The ring buffer to enable writes |
| 2542 | * | 2543 | * |
| 2543 | * Note, multiple disables will need the same number of enables | 2544 | * Note, multiple disables will need the same number of enables |
| 2544 | * to truely enable the writing (much like preempt_disable). | 2545 | * to truly enable the writing (much like preempt_disable). |
| 2545 | */ | 2546 | */ |
| 2546 | void ring_buffer_record_enable(struct ring_buffer *buffer) | 2547 | void ring_buffer_record_enable(struct ring_buffer *buffer) |
| 2547 | { | 2548 | { |
| @@ -2577,7 +2578,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_disable_cpu); | |||
| 2577 | * @cpu: The CPU to enable. | 2578 | * @cpu: The CPU to enable. |
| 2578 | * | 2579 | * |
| 2579 | * Note, multiple disables will need the same number of enables | 2580 | * Note, multiple disables will need the same number of enables |
| 2580 | * to truely enable the writing (much like preempt_disable). | 2581 | * to truly enable the writing (much like preempt_disable). |
| 2581 | */ | 2582 | */ |
| 2582 | void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu) | 2583 | void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu) |
| 2583 | { | 2584 | { |
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c index b2477caf09c2..df74c7982255 100644 --- a/kernel/trace/ring_buffer_benchmark.c +++ b/kernel/trace/ring_buffer_benchmark.c | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <linux/kthread.h> | 8 | #include <linux/kthread.h> |
| 9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
| 10 | #include <linux/time.h> | 10 | #include <linux/time.h> |
| 11 | #include <asm/local.h> | ||
| 11 | 12 | ||
| 12 | struct rb_page { | 13 | struct rb_page { |
| 13 | u64 ts; | 14 | u64 ts; |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 032c57ca6502..ed01fdba4a55 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -92,12 +92,12 @@ DEFINE_PER_CPU(int, ftrace_cpu_disabled); | |||
| 92 | static inline void ftrace_disable_cpu(void) | 92 | static inline void ftrace_disable_cpu(void) |
| 93 | { | 93 | { |
| 94 | preempt_disable(); | 94 | preempt_disable(); |
| 95 | __this_cpu_inc(per_cpu_var(ftrace_cpu_disabled)); | 95 | __this_cpu_inc(ftrace_cpu_disabled); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | static inline void ftrace_enable_cpu(void) | 98 | static inline void ftrace_enable_cpu(void) |
| 99 | { | 99 | { |
| 100 | __this_cpu_dec(per_cpu_var(ftrace_cpu_disabled)); | 100 | __this_cpu_dec(ftrace_cpu_disabled); |
| 101 | preempt_enable(); | 101 | preempt_enable(); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| @@ -1166,7 +1166,7 @@ trace_function(struct trace_array *tr, | |||
| 1166 | struct ftrace_entry *entry; | 1166 | struct ftrace_entry *entry; |
| 1167 | 1167 | ||
| 1168 | /* If we are reading the ring buffer, don't trace */ | 1168 | /* If we are reading the ring buffer, don't trace */ |
| 1169 | if (unlikely(__this_cpu_read(per_cpu_var(ftrace_cpu_disabled)))) | 1169 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
| 1170 | return; | 1170 | return; |
| 1171 | 1171 | ||
| 1172 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), | 1172 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index fd05bcaf91b0..09b39112a5e2 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
| @@ -550,7 +550,7 @@ static inline int ftrace_trace_task(struct task_struct *task) | |||
| 550 | * struct trace_parser - servers for reading the user input separated by spaces | 550 | * struct trace_parser - servers for reading the user input separated by spaces |
| 551 | * @cont: set if the input is not complete - no final space char was found | 551 | * @cont: set if the input is not complete - no final space char was found |
| 552 | * @buffer: holds the parsed user input | 552 | * @buffer: holds the parsed user input |
| 553 | * @idx: user input lenght | 553 | * @idx: user input length |
| 554 | * @size: buffer size | 554 | * @size: buffer size |
| 555 | */ | 555 | */ |
| 556 | struct trace_parser { | 556 | struct trace_parser { |
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index e998a824e9db..3fc2a575664f 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
| @@ -188,7 +188,7 @@ static int __trace_graph_entry(struct trace_array *tr, | |||
| 188 | struct ring_buffer *buffer = tr->buffer; | 188 | struct ring_buffer *buffer = tr->buffer; |
| 189 | struct ftrace_graph_ent_entry *entry; | 189 | struct ftrace_graph_ent_entry *entry; |
| 190 | 190 | ||
| 191 | if (unlikely(__this_cpu_read(per_cpu_var(ftrace_cpu_disabled)))) | 191 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
| 192 | return 0; | 192 | return 0; |
| 193 | 193 | ||
| 194 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_ENT, | 194 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_ENT, |
| @@ -247,7 +247,7 @@ static void __trace_graph_return(struct trace_array *tr, | |||
| 247 | struct ring_buffer *buffer = tr->buffer; | 247 | struct ring_buffer *buffer = tr->buffer; |
| 248 | struct ftrace_graph_ret_entry *entry; | 248 | struct ftrace_graph_ret_entry *entry; |
| 249 | 249 | ||
| 250 | if (unlikely(__this_cpu_read(per_cpu_var(ftrace_cpu_disabled)))) | 250 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
| 251 | return; | 251 | return; |
| 252 | 252 | ||
| 253 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_RET, | 253 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_RET, |
diff --git a/kernel/tsacct.c b/kernel/tsacct.c index 00d59d048edf..0a67e041edf8 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/tsacct_kern.h> | 21 | #include <linux/tsacct_kern.h> |
| 22 | #include <linux/acct.h> | 22 | #include <linux/acct.h> |
| 23 | #include <linux/jiffies.h> | 23 | #include <linux/jiffies.h> |
| 24 | #include <linux/mm.h> | ||
| 24 | 25 | ||
| 25 | /* | 26 | /* |
| 26 | * fill in basic accounting fields | 27 | * fill in basic accounting fields |
