diff options
Diffstat (limited to 'kernel')
57 files changed, 2197 insertions, 1064 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index bc010ee272b6..5c0e7666811d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -93,6 +93,7 @@ obj-$(CONFIG_PADATA) += padata.o | |||
93 | obj-$(CONFIG_CRASH_DUMP) += crash_dump.o | 93 | obj-$(CONFIG_CRASH_DUMP) += crash_dump.o |
94 | obj-$(CONFIG_JUMP_LABEL) += jump_label.o | 94 | obj-$(CONFIG_JUMP_LABEL) += jump_label.o |
95 | obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o | 95 | obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o |
96 | obj-$(CONFIG_TORTURE_TEST) += torture.o | ||
96 | 97 | ||
97 | $(obj)/configs.o: $(obj)/config_data.h | 98 | $(obj)/configs.o: $(obj)/config_data.h |
98 | 99 | ||
diff --git a/kernel/audit.c b/kernel/audit.c index 34c5a2310fbf..95a20f3f52f1 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
@@ -182,7 +182,7 @@ struct audit_buffer { | |||
182 | 182 | ||
183 | struct audit_reply { | 183 | struct audit_reply { |
184 | __u32 portid; | 184 | __u32 portid; |
185 | pid_t pid; | 185 | struct net *net; |
186 | struct sk_buff *skb; | 186 | struct sk_buff *skb; |
187 | }; | 187 | }; |
188 | 188 | ||
@@ -500,7 +500,7 @@ int audit_send_list(void *_dest) | |||
500 | { | 500 | { |
501 | struct audit_netlink_list *dest = _dest; | 501 | struct audit_netlink_list *dest = _dest; |
502 | struct sk_buff *skb; | 502 | struct sk_buff *skb; |
503 | struct net *net = get_net_ns_by_pid(dest->pid); | 503 | struct net *net = dest->net; |
504 | struct audit_net *aunet = net_generic(net, audit_net_id); | 504 | struct audit_net *aunet = net_generic(net, audit_net_id); |
505 | 505 | ||
506 | /* wait for parent to finish and send an ACK */ | 506 | /* wait for parent to finish and send an ACK */ |
@@ -510,6 +510,7 @@ int audit_send_list(void *_dest) | |||
510 | while ((skb = __skb_dequeue(&dest->q)) != NULL) | 510 | while ((skb = __skb_dequeue(&dest->q)) != NULL) |
511 | netlink_unicast(aunet->nlsk, skb, dest->portid, 0); | 511 | netlink_unicast(aunet->nlsk, skb, dest->portid, 0); |
512 | 512 | ||
513 | put_net(net); | ||
513 | kfree(dest); | 514 | kfree(dest); |
514 | 515 | ||
515 | return 0; | 516 | return 0; |
@@ -543,7 +544,7 @@ out_kfree_skb: | |||
543 | static int audit_send_reply_thread(void *arg) | 544 | static int audit_send_reply_thread(void *arg) |
544 | { | 545 | { |
545 | struct audit_reply *reply = (struct audit_reply *)arg; | 546 | struct audit_reply *reply = (struct audit_reply *)arg; |
546 | struct net *net = get_net_ns_by_pid(reply->pid); | 547 | struct net *net = reply->net; |
547 | struct audit_net *aunet = net_generic(net, audit_net_id); | 548 | struct audit_net *aunet = net_generic(net, audit_net_id); |
548 | 549 | ||
549 | mutex_lock(&audit_cmd_mutex); | 550 | mutex_lock(&audit_cmd_mutex); |
@@ -552,12 +553,13 @@ static int audit_send_reply_thread(void *arg) | |||
552 | /* Ignore failure. It'll only happen if the sender goes away, | 553 | /* Ignore failure. It'll only happen if the sender goes away, |
553 | because our timeout is set to infinite. */ | 554 | because our timeout is set to infinite. */ |
554 | netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); | 555 | netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); |
556 | put_net(net); | ||
555 | kfree(reply); | 557 | kfree(reply); |
556 | return 0; | 558 | return 0; |
557 | } | 559 | } |
558 | /** | 560 | /** |
559 | * audit_send_reply - send an audit reply message via netlink | 561 | * audit_send_reply - send an audit reply message via netlink |
560 | * @portid: netlink port to which to send reply | 562 | * @request_skb: skb of request we are replying to (used to target the reply) |
561 | * @seq: sequence number | 563 | * @seq: sequence number |
562 | * @type: audit message type | 564 | * @type: audit message type |
563 | * @done: done (last) flag | 565 | * @done: done (last) flag |
@@ -568,9 +570,11 @@ static int audit_send_reply_thread(void *arg) | |||
568 | * Allocates an skb, builds the netlink message, and sends it to the port id. | 570 | * Allocates an skb, builds the netlink message, and sends it to the port id. |
569 | * No failure notifications. | 571 | * No failure notifications. |
570 | */ | 572 | */ |
571 | static void audit_send_reply(__u32 portid, int seq, int type, int done, | 573 | static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int done, |
572 | int multi, const void *payload, int size) | 574 | int multi, const void *payload, int size) |
573 | { | 575 | { |
576 | u32 portid = NETLINK_CB(request_skb).portid; | ||
577 | struct net *net = sock_net(NETLINK_CB(request_skb).sk); | ||
574 | struct sk_buff *skb; | 578 | struct sk_buff *skb; |
575 | struct task_struct *tsk; | 579 | struct task_struct *tsk; |
576 | struct audit_reply *reply = kmalloc(sizeof(struct audit_reply), | 580 | struct audit_reply *reply = kmalloc(sizeof(struct audit_reply), |
@@ -583,8 +587,8 @@ static void audit_send_reply(__u32 portid, int seq, int type, int done, | |||
583 | if (!skb) | 587 | if (!skb) |
584 | goto out; | 588 | goto out; |
585 | 589 | ||
590 | reply->net = get_net(net); | ||
586 | reply->portid = portid; | 591 | reply->portid = portid; |
587 | reply->pid = task_pid_vnr(current); | ||
588 | reply->skb = skb; | 592 | reply->skb = skb; |
589 | 593 | ||
590 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); | 594 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); |
@@ -604,9 +608,19 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type) | |||
604 | int err = 0; | 608 | int err = 0; |
605 | 609 | ||
606 | /* Only support the initial namespaces for now. */ | 610 | /* Only support the initial namespaces for now. */ |
611 | /* | ||
612 | * We return ECONNREFUSED because it tricks userspace into thinking | ||
613 | * that audit was not configured into the kernel. Lots of users | ||
614 | * configure their PAM stack (because that's what the distro does) | ||
615 | * to reject login if unable to send messages to audit. If we return | ||
616 | * ECONNREFUSED the PAM stack thinks the kernel does not have audit | ||
617 | * configured in and will let login proceed. If we return EPERM | ||
618 | * userspace will reject all logins. This should be removed when we | ||
619 | * support non init namespaces!! | ||
620 | */ | ||
607 | if ((current_user_ns() != &init_user_ns) || | 621 | if ((current_user_ns() != &init_user_ns) || |
608 | (task_active_pid_ns(current) != &init_pid_ns)) | 622 | (task_active_pid_ns(current) != &init_pid_ns)) |
609 | return -EPERM; | 623 | return -ECONNREFUSED; |
610 | 624 | ||
611 | switch (msg_type) { | 625 | switch (msg_type) { |
612 | case AUDIT_LIST: | 626 | case AUDIT_LIST: |
@@ -673,8 +687,7 @@ static int audit_get_feature(struct sk_buff *skb) | |||
673 | 687 | ||
674 | seq = nlmsg_hdr(skb)->nlmsg_seq; | 688 | seq = nlmsg_hdr(skb)->nlmsg_seq; |
675 | 689 | ||
676 | audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, | 690 | audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &af, sizeof(af)); |
677 | &af, sizeof(af)); | ||
678 | 691 | ||
679 | return 0; | 692 | return 0; |
680 | } | 693 | } |
@@ -794,8 +807,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
794 | s.backlog = skb_queue_len(&audit_skb_queue); | 807 | s.backlog = skb_queue_len(&audit_skb_queue); |
795 | s.version = AUDIT_VERSION_LATEST; | 808 | s.version = AUDIT_VERSION_LATEST; |
796 | s.backlog_wait_time = audit_backlog_wait_time; | 809 | s.backlog_wait_time = audit_backlog_wait_time; |
797 | audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, | 810 | audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &s, sizeof(s)); |
798 | &s, sizeof(s)); | ||
799 | break; | 811 | break; |
800 | } | 812 | } |
801 | case AUDIT_SET: { | 813 | case AUDIT_SET: { |
@@ -905,7 +917,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
905 | seq, data, nlmsg_len(nlh)); | 917 | seq, data, nlmsg_len(nlh)); |
906 | break; | 918 | break; |
907 | case AUDIT_LIST_RULES: | 919 | case AUDIT_LIST_RULES: |
908 | err = audit_list_rules_send(NETLINK_CB(skb).portid, seq); | 920 | err = audit_list_rules_send(skb, seq); |
909 | break; | 921 | break; |
910 | case AUDIT_TRIM: | 922 | case AUDIT_TRIM: |
911 | audit_trim_trees(); | 923 | audit_trim_trees(); |
@@ -970,8 +982,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
970 | memcpy(sig_data->ctx, ctx, len); | 982 | memcpy(sig_data->ctx, ctx, len); |
971 | security_release_secctx(ctx, len); | 983 | security_release_secctx(ctx, len); |
972 | } | 984 | } |
973 | audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_SIGNAL_INFO, | 985 | audit_send_reply(skb, seq, AUDIT_SIGNAL_INFO, 0, 0, |
974 | 0, 0, sig_data, sizeof(*sig_data) + len); | 986 | sig_data, sizeof(*sig_data) + len); |
975 | kfree(sig_data); | 987 | kfree(sig_data); |
976 | break; | 988 | break; |
977 | case AUDIT_TTY_GET: { | 989 | case AUDIT_TTY_GET: { |
@@ -983,8 +995,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
983 | s.log_passwd = tsk->signal->audit_tty_log_passwd; | 995 | s.log_passwd = tsk->signal->audit_tty_log_passwd; |
984 | spin_unlock(&tsk->sighand->siglock); | 996 | spin_unlock(&tsk->sighand->siglock); |
985 | 997 | ||
986 | audit_send_reply(NETLINK_CB(skb).portid, seq, | 998 | audit_send_reply(skb, seq, AUDIT_TTY_GET, 0, 0, &s, sizeof(s)); |
987 | AUDIT_TTY_GET, 0, 0, &s, sizeof(s)); | ||
988 | break; | 999 | break; |
989 | } | 1000 | } |
990 | case AUDIT_TTY_SET: { | 1001 | case AUDIT_TTY_SET: { |
diff --git a/kernel/audit.h b/kernel/audit.h index 57cc64d67718..8df132214606 100644 --- a/kernel/audit.h +++ b/kernel/audit.h | |||
@@ -247,7 +247,7 @@ extern void audit_panic(const char *message); | |||
247 | 247 | ||
248 | struct audit_netlink_list { | 248 | struct audit_netlink_list { |
249 | __u32 portid; | 249 | __u32 portid; |
250 | pid_t pid; | 250 | struct net *net; |
251 | struct sk_buff_head q; | 251 | struct sk_buff_head q; |
252 | }; | 252 | }; |
253 | 253 | ||
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index 67ccf0e7cca9..135944a7b28a 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c | |||
@@ -916,7 +916,7 @@ static int audit_tree_handle_event(struct fsnotify_group *group, | |||
916 | struct fsnotify_mark *inode_mark, | 916 | struct fsnotify_mark *inode_mark, |
917 | struct fsnotify_mark *vfsmount_mark, | 917 | struct fsnotify_mark *vfsmount_mark, |
918 | u32 mask, void *data, int data_type, | 918 | u32 mask, void *data, int data_type, |
919 | const unsigned char *file_name) | 919 | const unsigned char *file_name, u32 cookie) |
920 | { | 920 | { |
921 | return 0; | 921 | return 0; |
922 | } | 922 | } |
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c index 2596fac5dcb4..70b4554d2fbe 100644 --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c | |||
@@ -471,7 +471,7 @@ static int audit_watch_handle_event(struct fsnotify_group *group, | |||
471 | struct fsnotify_mark *inode_mark, | 471 | struct fsnotify_mark *inode_mark, |
472 | struct fsnotify_mark *vfsmount_mark, | 472 | struct fsnotify_mark *vfsmount_mark, |
473 | u32 mask, void *data, int data_type, | 473 | u32 mask, void *data, int data_type, |
474 | const unsigned char *dname) | 474 | const unsigned char *dname, u32 cookie) |
475 | { | 475 | { |
476 | struct inode *inode; | 476 | struct inode *inode; |
477 | struct audit_parent *parent; | 477 | struct audit_parent *parent; |
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 14a78cca384e..92062fd6cc8c 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <linux/sched.h> | 29 | #include <linux/sched.h> |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | #include <linux/security.h> | 31 | #include <linux/security.h> |
32 | #include <net/net_namespace.h> | ||
33 | #include <net/sock.h> | ||
32 | #include "audit.h" | 34 | #include "audit.h" |
33 | 35 | ||
34 | /* | 36 | /* |
@@ -1065,11 +1067,13 @@ int audit_rule_change(int type, __u32 portid, int seq, void *data, | |||
1065 | 1067 | ||
1066 | /** | 1068 | /** |
1067 | * audit_list_rules_send - list the audit rules | 1069 | * audit_list_rules_send - list the audit rules |
1068 | * @portid: target portid for netlink audit messages | 1070 | * @request_skb: skb of request we are replying to (used to target the reply) |
1069 | * @seq: netlink audit message sequence (serial) number | 1071 | * @seq: netlink audit message sequence (serial) number |
1070 | */ | 1072 | */ |
1071 | int audit_list_rules_send(__u32 portid, int seq) | 1073 | int audit_list_rules_send(struct sk_buff *request_skb, int seq) |
1072 | { | 1074 | { |
1075 | u32 portid = NETLINK_CB(request_skb).portid; | ||
1076 | struct net *net = sock_net(NETLINK_CB(request_skb).sk); | ||
1073 | struct task_struct *tsk; | 1077 | struct task_struct *tsk; |
1074 | struct audit_netlink_list *dest; | 1078 | struct audit_netlink_list *dest; |
1075 | int err = 0; | 1079 | int err = 0; |
@@ -1083,8 +1087,8 @@ int audit_list_rules_send(__u32 portid, int seq) | |||
1083 | dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL); | 1087 | dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL); |
1084 | if (!dest) | 1088 | if (!dest) |
1085 | return -ENOMEM; | 1089 | return -ENOMEM; |
1090 | dest->net = get_net(net); | ||
1086 | dest->portid = portid; | 1091 | dest->portid = portid; |
1087 | dest->pid = task_pid_vnr(current); | ||
1088 | skb_queue_head_init(&dest->q); | 1092 | skb_queue_head_init(&dest->q); |
1089 | 1093 | ||
1090 | mutex_lock(&audit_filter_mutex); | 1094 | mutex_lock(&audit_filter_mutex); |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index e2f46ba37f72..0c753ddd223b 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -886,7 +886,9 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode) | |||
886 | * per-subsystem and moved to css->id so that lookups are | 886 | * per-subsystem and moved to css->id so that lookups are |
887 | * successful until the target css is released. | 887 | * successful until the target css is released. |
888 | */ | 888 | */ |
889 | mutex_lock(&cgroup_mutex); | ||
889 | idr_remove(&cgrp->root->cgroup_idr, cgrp->id); | 890 | idr_remove(&cgrp->root->cgroup_idr, cgrp->id); |
891 | mutex_unlock(&cgroup_mutex); | ||
890 | cgrp->id = -1; | 892 | cgrp->id = -1; |
891 | 893 | ||
892 | call_rcu(&cgrp->rcu_head, cgroup_free_rcu); | 894 | call_rcu(&cgrp->rcu_head, cgroup_free_rcu); |
@@ -1566,10 +1568,10 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type, | |||
1566 | mutex_lock(&cgroup_mutex); | 1568 | mutex_lock(&cgroup_mutex); |
1567 | mutex_lock(&cgroup_root_mutex); | 1569 | mutex_lock(&cgroup_root_mutex); |
1568 | 1570 | ||
1569 | root_cgrp->id = idr_alloc(&root->cgroup_idr, root_cgrp, | 1571 | ret = idr_alloc(&root->cgroup_idr, root_cgrp, 0, 1, GFP_KERNEL); |
1570 | 0, 1, GFP_KERNEL); | 1572 | if (ret < 0) |
1571 | if (root_cgrp->id < 0) | ||
1572 | goto unlock_drop; | 1573 | goto unlock_drop; |
1574 | root_cgrp->id = ret; | ||
1573 | 1575 | ||
1574 | /* Check for name clashes with existing mounts */ | 1576 | /* Check for name clashes with existing mounts */ |
1575 | ret = -EBUSY; | 1577 | ret = -EBUSY; |
@@ -2763,10 +2765,7 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add) | |||
2763 | */ | 2765 | */ |
2764 | update_before = cgroup_serial_nr_next; | 2766 | update_before = cgroup_serial_nr_next; |
2765 | 2767 | ||
2766 | mutex_unlock(&cgroup_mutex); | ||
2767 | |||
2768 | /* add/rm files for all cgroups created before */ | 2768 | /* add/rm files for all cgroups created before */ |
2769 | rcu_read_lock(); | ||
2770 | css_for_each_descendant_pre(css, cgroup_css(root, ss)) { | 2769 | css_for_each_descendant_pre(css, cgroup_css(root, ss)) { |
2771 | struct cgroup *cgrp = css->cgroup; | 2770 | struct cgroup *cgrp = css->cgroup; |
2772 | 2771 | ||
@@ -2775,23 +2774,19 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add) | |||
2775 | 2774 | ||
2776 | inode = cgrp->dentry->d_inode; | 2775 | inode = cgrp->dentry->d_inode; |
2777 | dget(cgrp->dentry); | 2776 | dget(cgrp->dentry); |
2778 | rcu_read_unlock(); | ||
2779 | |||
2780 | dput(prev); | 2777 | dput(prev); |
2781 | prev = cgrp->dentry; | 2778 | prev = cgrp->dentry; |
2782 | 2779 | ||
2780 | mutex_unlock(&cgroup_mutex); | ||
2783 | mutex_lock(&inode->i_mutex); | 2781 | mutex_lock(&inode->i_mutex); |
2784 | mutex_lock(&cgroup_mutex); | 2782 | mutex_lock(&cgroup_mutex); |
2785 | if (cgrp->serial_nr < update_before && !cgroup_is_dead(cgrp)) | 2783 | if (cgrp->serial_nr < update_before && !cgroup_is_dead(cgrp)) |
2786 | ret = cgroup_addrm_files(cgrp, cfts, is_add); | 2784 | ret = cgroup_addrm_files(cgrp, cfts, is_add); |
2787 | mutex_unlock(&cgroup_mutex); | ||
2788 | mutex_unlock(&inode->i_mutex); | 2785 | mutex_unlock(&inode->i_mutex); |
2789 | |||
2790 | rcu_read_lock(); | ||
2791 | if (ret) | 2786 | if (ret) |
2792 | break; | 2787 | break; |
2793 | } | 2788 | } |
2794 | rcu_read_unlock(); | 2789 | mutex_unlock(&cgroup_mutex); |
2795 | dput(prev); | 2790 | dput(prev); |
2796 | deactivate_super(sb); | 2791 | deactivate_super(sb); |
2797 | return ret; | 2792 | return ret; |
@@ -2910,9 +2905,14 @@ static void cgroup_enable_task_cg_lists(void) | |||
2910 | * We should check if the process is exiting, otherwise | 2905 | * We should check if the process is exiting, otherwise |
2911 | * it will race with cgroup_exit() in that the list | 2906 | * it will race with cgroup_exit() in that the list |
2912 | * entry won't be deleted though the process has exited. | 2907 | * entry won't be deleted though the process has exited. |
2908 | * Do it while holding siglock so that we don't end up | ||
2909 | * racing against cgroup_exit(). | ||
2913 | */ | 2910 | */ |
2911 | spin_lock_irq(&p->sighand->siglock); | ||
2914 | if (!(p->flags & PF_EXITING) && list_empty(&p->cg_list)) | 2912 | if (!(p->flags & PF_EXITING) && list_empty(&p->cg_list)) |
2915 | list_add(&p->cg_list, &task_css_set(p)->tasks); | 2913 | list_add(&p->cg_list, &task_css_set(p)->tasks); |
2914 | spin_unlock_irq(&p->sighand->siglock); | ||
2915 | |||
2916 | task_unlock(p); | 2916 | task_unlock(p); |
2917 | } while_each_thread(g, p); | 2917 | } while_each_thread(g, p); |
2918 | read_unlock(&tasklist_lock); | 2918 | read_unlock(&tasklist_lock); |
@@ -4112,17 +4112,17 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss) | |||
4112 | 4112 | ||
4113 | err = percpu_ref_init(&css->refcnt, css_release); | 4113 | err = percpu_ref_init(&css->refcnt, css_release); |
4114 | if (err) | 4114 | if (err) |
4115 | goto err_free; | 4115 | goto err_free_css; |
4116 | 4116 | ||
4117 | init_css(css, ss, cgrp); | 4117 | init_css(css, ss, cgrp); |
4118 | 4118 | ||
4119 | err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id); | 4119 | err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id); |
4120 | if (err) | 4120 | if (err) |
4121 | goto err_free; | 4121 | goto err_free_percpu_ref; |
4122 | 4122 | ||
4123 | err = online_css(css); | 4123 | err = online_css(css); |
4124 | if (err) | 4124 | if (err) |
4125 | goto err_free; | 4125 | goto err_clear_dir; |
4126 | 4126 | ||
4127 | dget(cgrp->dentry); | 4127 | dget(cgrp->dentry); |
4128 | css_get(css->parent); | 4128 | css_get(css->parent); |
@@ -4138,8 +4138,11 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss) | |||
4138 | 4138 | ||
4139 | return 0; | 4139 | return 0; |
4140 | 4140 | ||
4141 | err_free: | 4141 | err_clear_dir: |
4142 | cgroup_clear_dir(css->cgroup, 1 << css->ss->subsys_id); | ||
4143 | err_free_percpu_ref: | ||
4142 | percpu_ref_cancel_init(&css->refcnt); | 4144 | percpu_ref_cancel_init(&css->refcnt); |
4145 | err_free_css: | ||
4143 | ss->css_free(css); | 4146 | ss->css_free(css); |
4144 | return err; | 4147 | return err; |
4145 | } | 4148 | } |
@@ -4158,7 +4161,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4158 | struct cgroup *cgrp; | 4161 | struct cgroup *cgrp; |
4159 | struct cgroup_name *name; | 4162 | struct cgroup_name *name; |
4160 | struct cgroupfs_root *root = parent->root; | 4163 | struct cgroupfs_root *root = parent->root; |
4161 | int ssid, err = 0; | 4164 | int ssid, err; |
4162 | struct cgroup_subsys *ss; | 4165 | struct cgroup_subsys *ss; |
4163 | struct super_block *sb = root->sb; | 4166 | struct super_block *sb = root->sb; |
4164 | 4167 | ||
@@ -4168,19 +4171,13 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4168 | return -ENOMEM; | 4171 | return -ENOMEM; |
4169 | 4172 | ||
4170 | name = cgroup_alloc_name(dentry); | 4173 | name = cgroup_alloc_name(dentry); |
4171 | if (!name) | 4174 | if (!name) { |
4175 | err = -ENOMEM; | ||
4172 | goto err_free_cgrp; | 4176 | goto err_free_cgrp; |
4177 | } | ||
4173 | rcu_assign_pointer(cgrp->name, name); | 4178 | rcu_assign_pointer(cgrp->name, name); |
4174 | 4179 | ||
4175 | /* | 4180 | /* |
4176 | * Temporarily set the pointer to NULL, so idr_find() won't return | ||
4177 | * a half-baked cgroup. | ||
4178 | */ | ||
4179 | cgrp->id = idr_alloc(&root->cgroup_idr, NULL, 1, 0, GFP_KERNEL); | ||
4180 | if (cgrp->id < 0) | ||
4181 | goto err_free_name; | ||
4182 | |||
4183 | /* | ||
4184 | * Only live parents can have children. Note that the liveliness | 4181 | * Only live parents can have children. Note that the liveliness |
4185 | * check isn't strictly necessary because cgroup_mkdir() and | 4182 | * check isn't strictly necessary because cgroup_mkdir() and |
4186 | * cgroup_rmdir() are fully synchronized by i_mutex; however, do it | 4183 | * cgroup_rmdir() are fully synchronized by i_mutex; however, do it |
@@ -4189,7 +4186,17 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4189 | */ | 4186 | */ |
4190 | if (!cgroup_lock_live_group(parent)) { | 4187 | if (!cgroup_lock_live_group(parent)) { |
4191 | err = -ENODEV; | 4188 | err = -ENODEV; |
4192 | goto err_free_id; | 4189 | goto err_free_name; |
4190 | } | ||
4191 | |||
4192 | /* | ||
4193 | * Temporarily set the pointer to NULL, so idr_find() won't return | ||
4194 | * a half-baked cgroup. | ||
4195 | */ | ||
4196 | cgrp->id = idr_alloc(&root->cgroup_idr, NULL, 1, 0, GFP_KERNEL); | ||
4197 | if (cgrp->id < 0) { | ||
4198 | err = -ENOMEM; | ||
4199 | goto err_unlock; | ||
4193 | } | 4200 | } |
4194 | 4201 | ||
4195 | /* Grab a reference on the superblock so the hierarchy doesn't | 4202 | /* Grab a reference on the superblock so the hierarchy doesn't |
@@ -4221,7 +4228,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4221 | */ | 4228 | */ |
4222 | err = cgroup_create_file(dentry, S_IFDIR | mode, sb); | 4229 | err = cgroup_create_file(dentry, S_IFDIR | mode, sb); |
4223 | if (err < 0) | 4230 | if (err < 0) |
4224 | goto err_unlock; | 4231 | goto err_free_id; |
4225 | lockdep_assert_held(&dentry->d_inode->i_mutex); | 4232 | lockdep_assert_held(&dentry->d_inode->i_mutex); |
4226 | 4233 | ||
4227 | cgrp->serial_nr = cgroup_serial_nr_next++; | 4234 | cgrp->serial_nr = cgroup_serial_nr_next++; |
@@ -4257,12 +4264,12 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4257 | 4264 | ||
4258 | return 0; | 4265 | return 0; |
4259 | 4266 | ||
4260 | err_unlock: | ||
4261 | mutex_unlock(&cgroup_mutex); | ||
4262 | /* Release the reference count that we took on the superblock */ | ||
4263 | deactivate_super(sb); | ||
4264 | err_free_id: | 4267 | err_free_id: |
4265 | idr_remove(&root->cgroup_idr, cgrp->id); | 4268 | idr_remove(&root->cgroup_idr, cgrp->id); |
4269 | /* Release the reference count that we took on the superblock */ | ||
4270 | deactivate_super(sb); | ||
4271 | err_unlock: | ||
4272 | mutex_unlock(&cgroup_mutex); | ||
4266 | err_free_name: | 4273 | err_free_name: |
4267 | kfree(rcu_dereference_raw(cgrp->name)); | 4274 | kfree(rcu_dereference_raw(cgrp->name)); |
4268 | err_free_cgrp: | 4275 | err_free_cgrp: |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 4410ac6a55f1..e6b1b66afe52 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -974,12 +974,6 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, | |||
974 | * Temporarilly set tasks mems_allowed to target nodes of migration, | 974 | * Temporarilly set tasks mems_allowed to target nodes of migration, |
975 | * so that the migration code can allocate pages on these nodes. | 975 | * so that the migration code can allocate pages on these nodes. |
976 | * | 976 | * |
977 | * Call holding cpuset_mutex, so current's cpuset won't change | ||
978 | * during this call, as manage_mutex holds off any cpuset_attach() | ||
979 | * calls. Therefore we don't need to take task_lock around the | ||
980 | * call to guarantee_online_mems(), as we know no one is changing | ||
981 | * our task's cpuset. | ||
982 | * | ||
983 | * While the mm_struct we are migrating is typically from some | 977 | * While the mm_struct we are migrating is typically from some |
984 | * other task, the task_struct mems_allowed that we are hacking | 978 | * other task, the task_struct mems_allowed that we are hacking |
985 | * is for our current task, which must allocate new pages for that | 979 | * is for our current task, which must allocate new pages for that |
@@ -996,8 +990,10 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from, | |||
996 | 990 | ||
997 | do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); | 991 | do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL); |
998 | 992 | ||
993 | rcu_read_lock(); | ||
999 | mems_cs = effective_nodemask_cpuset(task_cs(tsk)); | 994 | mems_cs = effective_nodemask_cpuset(task_cs(tsk)); |
1000 | guarantee_online_mems(mems_cs, &tsk->mems_allowed); | 995 | guarantee_online_mems(mems_cs, &tsk->mems_allowed); |
996 | rcu_read_unlock(); | ||
1001 | } | 997 | } |
1002 | 998 | ||
1003 | /* | 999 | /* |
@@ -2486,9 +2482,9 @@ int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask) | |||
2486 | 2482 | ||
2487 | task_lock(current); | 2483 | task_lock(current); |
2488 | cs = nearest_hardwall_ancestor(task_cs(current)); | 2484 | cs = nearest_hardwall_ancestor(task_cs(current)); |
2485 | allowed = node_isset(node, cs->mems_allowed); | ||
2489 | task_unlock(current); | 2486 | task_unlock(current); |
2490 | 2487 | ||
2491 | allowed = node_isset(node, cs->mems_allowed); | ||
2492 | mutex_unlock(&callback_mutex); | 2488 | mutex_unlock(&callback_mutex); |
2493 | return allowed; | 2489 | return allowed; |
2494 | } | 2490 | } |
diff --git a/kernel/events/core.c b/kernel/events/core.c index 56003c6edfd3..fa0b2d4ad83c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -7856,14 +7856,14 @@ static void perf_pmu_rotate_stop(struct pmu *pmu) | |||
7856 | static void __perf_event_exit_context(void *__info) | 7856 | static void __perf_event_exit_context(void *__info) |
7857 | { | 7857 | { |
7858 | struct perf_event_context *ctx = __info; | 7858 | struct perf_event_context *ctx = __info; |
7859 | struct perf_event *event, *tmp; | 7859 | struct perf_event *event; |
7860 | 7860 | ||
7861 | perf_pmu_rotate_stop(ctx->pmu); | 7861 | perf_pmu_rotate_stop(ctx->pmu); |
7862 | 7862 | ||
7863 | list_for_each_entry_safe(event, tmp, &ctx->pinned_groups, group_entry) | 7863 | rcu_read_lock(); |
7864 | __perf_remove_from_context(event); | 7864 | list_for_each_entry_rcu(event, &ctx->event_list, event_entry) |
7865 | list_for_each_entry_safe(event, tmp, &ctx->flexible_groups, group_entry) | ||
7866 | __perf_remove_from_context(event); | 7865 | __perf_remove_from_context(event); |
7866 | rcu_read_unlock(); | ||
7867 | } | 7867 | } |
7868 | 7868 | ||
7869 | static void perf_event_exit_cpu_context(int cpu) | 7869 | static void perf_event_exit_cpu_context(int cpu) |
@@ -7887,11 +7887,11 @@ static void perf_event_exit_cpu(int cpu) | |||
7887 | { | 7887 | { |
7888 | struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu); | 7888 | struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu); |
7889 | 7889 | ||
7890 | perf_event_exit_cpu_context(cpu); | ||
7891 | |||
7890 | mutex_lock(&swhash->hlist_mutex); | 7892 | mutex_lock(&swhash->hlist_mutex); |
7891 | swevent_hlist_release(swhash); | 7893 | swevent_hlist_release(swhash); |
7892 | mutex_unlock(&swhash->hlist_mutex); | 7894 | mutex_unlock(&swhash->hlist_mutex); |
7893 | |||
7894 | perf_event_exit_cpu_context(cpu); | ||
7895 | } | 7895 | } |
7896 | #else | 7896 | #else |
7897 | static inline void perf_event_exit_cpu(int cpu) { } | 7897 | static inline void perf_event_exit_cpu(int cpu) { } |
diff --git a/kernel/futex.c b/kernel/futex.c index 44a1261cb9ff..67dacaf93e56 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
@@ -157,7 +157,9 @@ | |||
157 | * enqueue. | 157 | * enqueue. |
158 | */ | 158 | */ |
159 | 159 | ||
160 | #ifndef CONFIG_HAVE_FUTEX_CMPXCHG | ||
160 | int __read_mostly futex_cmpxchg_enabled; | 161 | int __read_mostly futex_cmpxchg_enabled; |
162 | #endif | ||
161 | 163 | ||
162 | /* | 164 | /* |
163 | * Futex flags used to encode options to functions and preserve them across | 165 | * Futex flags used to encode options to functions and preserve them across |
@@ -234,6 +236,7 @@ static const struct futex_q futex_q_init = { | |||
234 | * waiting on a futex. | 236 | * waiting on a futex. |
235 | */ | 237 | */ |
236 | struct futex_hash_bucket { | 238 | struct futex_hash_bucket { |
239 | atomic_t waiters; | ||
237 | spinlock_t lock; | 240 | spinlock_t lock; |
238 | struct plist_head chain; | 241 | struct plist_head chain; |
239 | } ____cacheline_aligned_in_smp; | 242 | } ____cacheline_aligned_in_smp; |
@@ -253,22 +256,37 @@ static inline void futex_get_mm(union futex_key *key) | |||
253 | smp_mb__after_atomic_inc(); | 256 | smp_mb__after_atomic_inc(); |
254 | } | 257 | } |
255 | 258 | ||
256 | static inline bool hb_waiters_pending(struct futex_hash_bucket *hb) | 259 | /* |
260 | * Reflects a new waiter being added to the waitqueue. | ||
261 | */ | ||
262 | static inline void hb_waiters_inc(struct futex_hash_bucket *hb) | ||
257 | { | 263 | { |
258 | #ifdef CONFIG_SMP | 264 | #ifdef CONFIG_SMP |
265 | atomic_inc(&hb->waiters); | ||
259 | /* | 266 | /* |
260 | * Tasks trying to enter the critical region are most likely | 267 | * Full barrier (A), see the ordering comment above. |
261 | * potential waiters that will be added to the plist. Ensure | ||
262 | * that wakers won't miss to-be-slept tasks in the window between | ||
263 | * the wait call and the actual plist_add. | ||
264 | */ | 268 | */ |
265 | if (spin_is_locked(&hb->lock)) | 269 | smp_mb__after_atomic_inc(); |
266 | return true; | 270 | #endif |
267 | smp_rmb(); /* Make sure we check the lock state first */ | 271 | } |
272 | |||
273 | /* | ||
274 | * Reflects a waiter being removed from the waitqueue by wakeup | ||
275 | * paths. | ||
276 | */ | ||
277 | static inline void hb_waiters_dec(struct futex_hash_bucket *hb) | ||
278 | { | ||
279 | #ifdef CONFIG_SMP | ||
280 | atomic_dec(&hb->waiters); | ||
281 | #endif | ||
282 | } | ||
268 | 283 | ||
269 | return !plist_head_empty(&hb->chain); | 284 | static inline int hb_waiters_pending(struct futex_hash_bucket *hb) |
285 | { | ||
286 | #ifdef CONFIG_SMP | ||
287 | return atomic_read(&hb->waiters); | ||
270 | #else | 288 | #else |
271 | return true; | 289 | return 1; |
272 | #endif | 290 | #endif |
273 | } | 291 | } |
274 | 292 | ||
@@ -954,6 +972,7 @@ static void __unqueue_futex(struct futex_q *q) | |||
954 | 972 | ||
955 | hb = container_of(q->lock_ptr, struct futex_hash_bucket, lock); | 973 | hb = container_of(q->lock_ptr, struct futex_hash_bucket, lock); |
956 | plist_del(&q->list, &hb->chain); | 974 | plist_del(&q->list, &hb->chain); |
975 | hb_waiters_dec(hb); | ||
957 | } | 976 | } |
958 | 977 | ||
959 | /* | 978 | /* |
@@ -1257,7 +1276,9 @@ void requeue_futex(struct futex_q *q, struct futex_hash_bucket *hb1, | |||
1257 | */ | 1276 | */ |
1258 | if (likely(&hb1->chain != &hb2->chain)) { | 1277 | if (likely(&hb1->chain != &hb2->chain)) { |
1259 | plist_del(&q->list, &hb1->chain); | 1278 | plist_del(&q->list, &hb1->chain); |
1279 | hb_waiters_dec(hb1); | ||
1260 | plist_add(&q->list, &hb2->chain); | 1280 | plist_add(&q->list, &hb2->chain); |
1281 | hb_waiters_inc(hb2); | ||
1261 | q->lock_ptr = &hb2->lock; | 1282 | q->lock_ptr = &hb2->lock; |
1262 | } | 1283 | } |
1263 | get_futex_key_refs(key2); | 1284 | get_futex_key_refs(key2); |
@@ -1600,6 +1621,17 @@ static inline struct futex_hash_bucket *queue_lock(struct futex_q *q) | |||
1600 | struct futex_hash_bucket *hb; | 1621 | struct futex_hash_bucket *hb; |
1601 | 1622 | ||
1602 | hb = hash_futex(&q->key); | 1623 | hb = hash_futex(&q->key); |
1624 | |||
1625 | /* | ||
1626 | * Increment the counter before taking the lock so that | ||
1627 | * a potential waker won't miss a to-be-slept task that is | ||
1628 | * waiting for the spinlock. This is safe as all queue_lock() | ||
1629 | * users end up calling queue_me(). Similarly, for housekeeping, | ||
1630 | * decrement the counter at queue_unlock() when some error has | ||
1631 | * occurred and we don't end up adding the task to the list. | ||
1632 | */ | ||
1633 | hb_waiters_inc(hb); | ||
1634 | |||
1603 | q->lock_ptr = &hb->lock; | 1635 | q->lock_ptr = &hb->lock; |
1604 | 1636 | ||
1605 | spin_lock(&hb->lock); /* implies MB (A) */ | 1637 | spin_lock(&hb->lock); /* implies MB (A) */ |
@@ -1611,6 +1643,7 @@ queue_unlock(struct futex_hash_bucket *hb) | |||
1611 | __releases(&hb->lock) | 1643 | __releases(&hb->lock) |
1612 | { | 1644 | { |
1613 | spin_unlock(&hb->lock); | 1645 | spin_unlock(&hb->lock); |
1646 | hb_waiters_dec(hb); | ||
1614 | } | 1647 | } |
1615 | 1648 | ||
1616 | /** | 1649 | /** |
@@ -2342,6 +2375,7 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb, | |||
2342 | * Unqueue the futex_q and determine which it was. | 2375 | * Unqueue the futex_q and determine which it was. |
2343 | */ | 2376 | */ |
2344 | plist_del(&q->list, &hb->chain); | 2377 | plist_del(&q->list, &hb->chain); |
2378 | hb_waiters_dec(hb); | ||
2345 | 2379 | ||
2346 | /* Handle spurious wakeups gracefully */ | 2380 | /* Handle spurious wakeups gracefully */ |
2347 | ret = -EWOULDBLOCK; | 2381 | ret = -EWOULDBLOCK; |
@@ -2843,9 +2877,28 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, | |||
2843 | return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); | 2877 | return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); |
2844 | } | 2878 | } |
2845 | 2879 | ||
2846 | static int __init futex_init(void) | 2880 | static void __init futex_detect_cmpxchg(void) |
2847 | { | 2881 | { |
2882 | #ifndef CONFIG_HAVE_FUTEX_CMPXCHG | ||
2848 | u32 curval; | 2883 | u32 curval; |
2884 | |||
2885 | /* | ||
2886 | * This will fail and we want it. Some arch implementations do | ||
2887 | * runtime detection of the futex_atomic_cmpxchg_inatomic() | ||
2888 | * functionality. We want to know that before we call in any | ||
2889 | * of the complex code paths. Also we want to prevent | ||
2890 | * registration of robust lists in that case. NULL is | ||
2891 | * guaranteed to fault and we get -EFAULT on functional | ||
2892 | * implementation, the non-functional ones will return | ||
2893 | * -ENOSYS. | ||
2894 | */ | ||
2895 | if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT) | ||
2896 | futex_cmpxchg_enabled = 1; | ||
2897 | #endif | ||
2898 | } | ||
2899 | |||
2900 | static int __init futex_init(void) | ||
2901 | { | ||
2849 | unsigned int futex_shift; | 2902 | unsigned int futex_shift; |
2850 | unsigned long i; | 2903 | unsigned long i; |
2851 | 2904 | ||
@@ -2861,20 +2914,11 @@ static int __init futex_init(void) | |||
2861 | &futex_shift, NULL, | 2914 | &futex_shift, NULL, |
2862 | futex_hashsize, futex_hashsize); | 2915 | futex_hashsize, futex_hashsize); |
2863 | futex_hashsize = 1UL << futex_shift; | 2916 | futex_hashsize = 1UL << futex_shift; |
2864 | /* | 2917 | |
2865 | * This will fail and we want it. Some arch implementations do | 2918 | futex_detect_cmpxchg(); |
2866 | * runtime detection of the futex_atomic_cmpxchg_inatomic() | ||
2867 | * functionality. We want to know that before we call in any | ||
2868 | * of the complex code paths. Also we want to prevent | ||
2869 | * registration of robust lists in that case. NULL is | ||
2870 | * guaranteed to fault and we get -EFAULT on functional | ||
2871 | * implementation, the non-functional ones will return | ||
2872 | * -ENOSYS. | ||
2873 | */ | ||
2874 | if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT) | ||
2875 | futex_cmpxchg_enabled = 1; | ||
2876 | 2919 | ||
2877 | for (i = 0; i < futex_hashsize; i++) { | 2920 | for (i = 0; i < futex_hashsize; i++) { |
2921 | atomic_set(&futex_queues[i].waiters, 0); | ||
2878 | plist_head_init(&futex_queues[i].chain); | 2922 | plist_head_init(&futex_queues[i].chain); |
2879 | spin_lock_init(&futex_queues[i].lock); | 2923 | spin_lock_init(&futex_queues[i].lock); |
2880 | } | 2924 | } |
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c index bd8e788d71e0..1ef0606797c9 100644 --- a/kernel/irq/devres.c +++ b/kernel/irq/devres.c | |||
@@ -73,6 +73,51 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq, | |||
73 | EXPORT_SYMBOL(devm_request_threaded_irq); | 73 | EXPORT_SYMBOL(devm_request_threaded_irq); |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * devm_request_any_context_irq - allocate an interrupt line for a managed device | ||
77 | * @dev: device to request interrupt for | ||
78 | * @irq: Interrupt line to allocate | ||
79 | * @handler: Function to be called when the IRQ occurs | ||
80 | * @thread_fn: function to be called in a threaded interrupt context. NULL | ||
81 | * for devices which handle everything in @handler | ||
82 | * @irqflags: Interrupt type flags | ||
83 | * @devname: An ascii name for the claiming device | ||
84 | * @dev_id: A cookie passed back to the handler function | ||
85 | * | ||
86 | * Except for the extra @dev argument, this function takes the | ||
87 | * same arguments and performs the same function as | ||
88 | * request_any_context_irq(). IRQs requested with this function will be | ||
89 | * automatically freed on driver detach. | ||
90 | * | ||
91 | * If an IRQ allocated with this function needs to be freed | ||
92 | * separately, devm_free_irq() must be used. | ||
93 | */ | ||
94 | int devm_request_any_context_irq(struct device *dev, unsigned int irq, | ||
95 | irq_handler_t handler, unsigned long irqflags, | ||
96 | const char *devname, void *dev_id) | ||
97 | { | ||
98 | struct irq_devres *dr; | ||
99 | int rc; | ||
100 | |||
101 | dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres), | ||
102 | GFP_KERNEL); | ||
103 | if (!dr) | ||
104 | return -ENOMEM; | ||
105 | |||
106 | rc = request_any_context_irq(irq, handler, irqflags, devname, dev_id); | ||
107 | if (rc) { | ||
108 | devres_free(dr); | ||
109 | return rc; | ||
110 | } | ||
111 | |||
112 | dr->irq = irq; | ||
113 | dr->dev_id = dev_id; | ||
114 | devres_add(dev, dr); | ||
115 | |||
116 | return 0; | ||
117 | } | ||
118 | EXPORT_SYMBOL(devm_request_any_context_irq); | ||
119 | |||
120 | /** | ||
76 | * devm_free_irq - free an interrupt | 121 | * devm_free_irq - free an interrupt |
77 | * @dev: device to free interrupt for | 122 | * @dev: device to free interrupt for |
78 | * @irq: Interrupt line to free | 123 | * @irq: Interrupt line to free |
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 192a302d6cfd..8ab8e9390297 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c | |||
@@ -274,6 +274,7 @@ struct irq_desc *irq_to_desc(unsigned int irq) | |||
274 | { | 274 | { |
275 | return (irq < NR_IRQS) ? irq_desc + irq : NULL; | 275 | return (irq < NR_IRQS) ? irq_desc + irq : NULL; |
276 | } | 276 | } |
277 | EXPORT_SYMBOL(irq_to_desc); | ||
277 | 278 | ||
278 | static void free_desc(unsigned int irq) | 279 | static void free_desc(unsigned int irq) |
279 | { | 280 | { |
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index cf68bb36fe58..f14033700c25 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/mutex.h> | 10 | #include <linux/mutex.h> |
11 | #include <linux/of.h> | 11 | #include <linux/of.h> |
12 | #include <linux/of_address.h> | 12 | #include <linux/of_address.h> |
13 | #include <linux/of_irq.h> | ||
13 | #include <linux/topology.h> | 14 | #include <linux/topology.h> |
14 | #include <linux/seq_file.h> | 15 | #include <linux/seq_file.h> |
15 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 481a13c43b17..d3bf660cb57f 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c | |||
@@ -802,8 +802,7 @@ static irqreturn_t irq_thread_fn(struct irq_desc *desc, | |||
802 | 802 | ||
803 | static void wake_threads_waitq(struct irq_desc *desc) | 803 | static void wake_threads_waitq(struct irq_desc *desc) |
804 | { | 804 | { |
805 | if (atomic_dec_and_test(&desc->threads_active) && | 805 | if (atomic_dec_and_test(&desc->threads_active)) |
806 | waitqueue_active(&desc->wait_for_threads)) | ||
807 | wake_up(&desc->wait_for_threads); | 806 | wake_up(&desc->wait_for_threads); |
808 | } | 807 | } |
809 | 808 | ||
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index d945a949760f..e660964086e2 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c | |||
@@ -19,6 +19,8 @@ | |||
19 | #include <linux/sched.h> | 19 | #include <linux/sched.h> |
20 | #include <linux/capability.h> | 20 | #include <linux/capability.h> |
21 | 21 | ||
22 | #include <linux/rcupdate.h> /* rcu_expedited */ | ||
23 | |||
22 | #define KERNEL_ATTR_RO(_name) \ | 24 | #define KERNEL_ATTR_RO(_name) \ |
23 | static struct kobj_attribute _name##_attr = __ATTR_RO(_name) | 25 | static struct kobj_attribute _name##_attr = __ATTR_RO(_name) |
24 | 26 | ||
diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile index baab8e5e7f66..306a76b51e0f 100644 --- a/kernel/locking/Makefile +++ b/kernel/locking/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | 1 | ||
2 | obj-y += mutex.o semaphore.o rwsem.o lglock.o | 2 | obj-y += mutex.o semaphore.o rwsem.o lglock.o mcs_spinlock.o |
3 | 3 | ||
4 | ifdef CONFIG_FUNCTION_TRACER | 4 | ifdef CONFIG_FUNCTION_TRACER |
5 | CFLAGS_REMOVE_lockdep.o = -pg | 5 | CFLAGS_REMOVE_lockdep.o = -pg |
@@ -23,3 +23,4 @@ obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o | |||
23 | obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o | 23 | obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o |
24 | obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o | 24 | obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o |
25 | obj-$(CONFIG_PERCPU_RWSEM) += percpu-rwsem.o | 25 | obj-$(CONFIG_PERCPU_RWSEM) += percpu-rwsem.o |
26 | obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o | ||
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index eb8a54783fa0..bf0c6b0dd9c5 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c | |||
@@ -1936,12 +1936,12 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next) | |||
1936 | 1936 | ||
1937 | for (;;) { | 1937 | for (;;) { |
1938 | int distance = curr->lockdep_depth - depth + 1; | 1938 | int distance = curr->lockdep_depth - depth + 1; |
1939 | hlock = curr->held_locks + depth-1; | 1939 | hlock = curr->held_locks + depth - 1; |
1940 | /* | 1940 | /* |
1941 | * Only non-recursive-read entries get new dependencies | 1941 | * Only non-recursive-read entries get new dependencies |
1942 | * added: | 1942 | * added: |
1943 | */ | 1943 | */ |
1944 | if (hlock->read != 2) { | 1944 | if (hlock->read != 2 && hlock->check) { |
1945 | if (!check_prev_add(curr, hlock, next, | 1945 | if (!check_prev_add(curr, hlock, next, |
1946 | distance, trylock_loop)) | 1946 | distance, trylock_loop)) |
1947 | return 0; | 1947 | return 0; |
@@ -2098,7 +2098,7 @@ static int validate_chain(struct task_struct *curr, struct lockdep_map *lock, | |||
2098 | * (If lookup_chain_cache() returns with 1 it acquires | 2098 | * (If lookup_chain_cache() returns with 1 it acquires |
2099 | * graph_lock for us) | 2099 | * graph_lock for us) |
2100 | */ | 2100 | */ |
2101 | if (!hlock->trylock && (hlock->check == 2) && | 2101 | if (!hlock->trylock && hlock->check && |
2102 | lookup_chain_cache(curr, hlock, chain_key)) { | 2102 | lookup_chain_cache(curr, hlock, chain_key)) { |
2103 | /* | 2103 | /* |
2104 | * Check whether last held lock: | 2104 | * Check whether last held lock: |
@@ -2517,7 +2517,7 @@ mark_held_locks(struct task_struct *curr, enum mark_type mark) | |||
2517 | 2517 | ||
2518 | BUG_ON(usage_bit >= LOCK_USAGE_STATES); | 2518 | BUG_ON(usage_bit >= LOCK_USAGE_STATES); |
2519 | 2519 | ||
2520 | if (hlock_class(hlock)->key == __lockdep_no_validate__.subkeys) | 2520 | if (!hlock->check) |
2521 | continue; | 2521 | continue; |
2522 | 2522 | ||
2523 | if (!mark_lock(curr, hlock, usage_bit)) | 2523 | if (!mark_lock(curr, hlock, usage_bit)) |
@@ -3055,9 +3055,6 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
3055 | int class_idx; | 3055 | int class_idx; |
3056 | u64 chain_key; | 3056 | u64 chain_key; |
3057 | 3057 | ||
3058 | if (!prove_locking) | ||
3059 | check = 1; | ||
3060 | |||
3061 | if (unlikely(!debug_locks)) | 3058 | if (unlikely(!debug_locks)) |
3062 | return 0; | 3059 | return 0; |
3063 | 3060 | ||
@@ -3069,8 +3066,8 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
3069 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 3066 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
3070 | return 0; | 3067 | return 0; |
3071 | 3068 | ||
3072 | if (lock->key == &__lockdep_no_validate__) | 3069 | if (!prove_locking || lock->key == &__lockdep_no_validate__) |
3073 | check = 1; | 3070 | check = 0; |
3074 | 3071 | ||
3075 | if (subclass < NR_LOCKDEP_CACHING_CLASSES) | 3072 | if (subclass < NR_LOCKDEP_CACHING_CLASSES) |
3076 | class = lock->class_cache[subclass]; | 3073 | class = lock->class_cache[subclass]; |
@@ -3138,7 +3135,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
3138 | hlock->holdtime_stamp = lockstat_clock(); | 3135 | hlock->holdtime_stamp = lockstat_clock(); |
3139 | #endif | 3136 | #endif |
3140 | 3137 | ||
3141 | if (check == 2 && !mark_irqflags(curr, hlock)) | 3138 | if (check && !mark_irqflags(curr, hlock)) |
3142 | return 0; | 3139 | return 0; |
3143 | 3140 | ||
3144 | /* mark it as used: */ | 3141 | /* mark it as used: */ |
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c new file mode 100644 index 000000000000..f26b1a18e34e --- /dev/null +++ b/kernel/locking/locktorture.c | |||
@@ -0,0 +1,452 @@ | |||
1 | /* | ||
2 | * Module-based torture test facility for locking | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, you can access it online at | ||
16 | * http://www.gnu.org/licenses/gpl-2.0.html. | ||
17 | * | ||
18 | * Copyright (C) IBM Corporation, 2014 | ||
19 | * | ||
20 | * Author: Paul E. McKenney <paulmck@us.ibm.com> | ||
21 | * Based on kernel/rcu/torture.c. | ||
22 | */ | ||
23 | #include <linux/types.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/kthread.h> | ||
28 | #include <linux/err.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/smp.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <linux/atomic.h> | ||
34 | #include <linux/bitops.h> | ||
35 | #include <linux/completion.h> | ||
36 | #include <linux/moduleparam.h> | ||
37 | #include <linux/percpu.h> | ||
38 | #include <linux/notifier.h> | ||
39 | #include <linux/reboot.h> | ||
40 | #include <linux/freezer.h> | ||
41 | #include <linux/cpu.h> | ||
42 | #include <linux/delay.h> | ||
43 | #include <linux/stat.h> | ||
44 | #include <linux/slab.h> | ||
45 | #include <linux/trace_clock.h> | ||
46 | #include <asm/byteorder.h> | ||
47 | #include <linux/torture.h> | ||
48 | |||
49 | MODULE_LICENSE("GPL"); | ||
50 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>"); | ||
51 | |||
52 | torture_param(int, nwriters_stress, -1, | ||
53 | "Number of write-locking stress-test threads"); | ||
54 | torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)"); | ||
55 | torture_param(int, onoff_interval, 0, | ||
56 | "Time between CPU hotplugs (s), 0=disable"); | ||
57 | torture_param(int, shuffle_interval, 3, | ||
58 | "Number of jiffies between shuffles, 0=disable"); | ||
59 | torture_param(int, shutdown_secs, 0, "Shutdown time (j), <= zero to disable."); | ||
60 | torture_param(int, stat_interval, 60, | ||
61 | "Number of seconds between stats printk()s"); | ||
62 | torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable"); | ||
63 | torture_param(bool, verbose, true, | ||
64 | "Enable verbose debugging printk()s"); | ||
65 | |||
66 | static char *torture_type = "spin_lock"; | ||
67 | module_param(torture_type, charp, 0444); | ||
68 | MODULE_PARM_DESC(torture_type, | ||
69 | "Type of lock to torture (spin_lock, spin_lock_irq, ...)"); | ||
70 | |||
71 | static atomic_t n_lock_torture_errors; | ||
72 | |||
73 | static struct task_struct *stats_task; | ||
74 | static struct task_struct **writer_tasks; | ||
75 | |||
76 | static int nrealwriters_stress; | ||
77 | static bool lock_is_write_held; | ||
78 | |||
79 | struct lock_writer_stress_stats { | ||
80 | long n_write_lock_fail; | ||
81 | long n_write_lock_acquired; | ||
82 | }; | ||
83 | static struct lock_writer_stress_stats *lwsa; | ||
84 | |||
85 | #if defined(MODULE) || defined(CONFIG_LOCK_TORTURE_TEST_RUNNABLE) | ||
86 | #define LOCKTORTURE_RUNNABLE_INIT 1 | ||
87 | #else | ||
88 | #define LOCKTORTURE_RUNNABLE_INIT 0 | ||
89 | #endif | ||
90 | int locktorture_runnable = LOCKTORTURE_RUNNABLE_INIT; | ||
91 | module_param(locktorture_runnable, int, 0444); | ||
92 | MODULE_PARM_DESC(locktorture_runnable, "Start locktorture at boot"); | ||
93 | |||
94 | /* Forward reference. */ | ||
95 | static void lock_torture_cleanup(void); | ||
96 | |||
97 | /* | ||
98 | * Operations vector for selecting different types of tests. | ||
99 | */ | ||
100 | struct lock_torture_ops { | ||
101 | void (*init)(void); | ||
102 | int (*writelock)(void); | ||
103 | void (*write_delay)(struct torture_random_state *trsp); | ||
104 | void (*writeunlock)(void); | ||
105 | unsigned long flags; | ||
106 | const char *name; | ||
107 | }; | ||
108 | |||
109 | static struct lock_torture_ops *cur_ops; | ||
110 | |||
111 | /* | ||
112 | * Definitions for lock torture testing. | ||
113 | */ | ||
114 | |||
115 | static int torture_lock_busted_write_lock(void) | ||
116 | { | ||
117 | return 0; /* BUGGY, do not use in real life!!! */ | ||
118 | } | ||
119 | |||
120 | static void torture_lock_busted_write_delay(struct torture_random_state *trsp) | ||
121 | { | ||
122 | const unsigned long longdelay_us = 100; | ||
123 | |||
124 | /* We want a long delay occasionally to force massive contention. */ | ||
125 | if (!(torture_random(trsp) % | ||
126 | (nrealwriters_stress * 2000 * longdelay_us))) | ||
127 | mdelay(longdelay_us); | ||
128 | #ifdef CONFIG_PREEMPT | ||
129 | if (!(torture_random(trsp) % (nrealwriters_stress * 20000))) | ||
130 | preempt_schedule(); /* Allow test to be preempted. */ | ||
131 | #endif | ||
132 | } | ||
133 | |||
134 | static void torture_lock_busted_write_unlock(void) | ||
135 | { | ||
136 | /* BUGGY, do not use in real life!!! */ | ||
137 | } | ||
138 | |||
139 | static struct lock_torture_ops lock_busted_ops = { | ||
140 | .writelock = torture_lock_busted_write_lock, | ||
141 | .write_delay = torture_lock_busted_write_delay, | ||
142 | .writeunlock = torture_lock_busted_write_unlock, | ||
143 | .name = "lock_busted" | ||
144 | }; | ||
145 | |||
146 | static DEFINE_SPINLOCK(torture_spinlock); | ||
147 | |||
148 | static int torture_spin_lock_write_lock(void) __acquires(torture_spinlock) | ||
149 | { | ||
150 | spin_lock(&torture_spinlock); | ||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | static void torture_spin_lock_write_delay(struct torture_random_state *trsp) | ||
155 | { | ||
156 | const unsigned long shortdelay_us = 2; | ||
157 | const unsigned long longdelay_us = 100; | ||
158 | |||
159 | /* We want a short delay mostly to emulate likely code, and | ||
160 | * we want a long delay occasionally to force massive contention. | ||
161 | */ | ||
162 | if (!(torture_random(trsp) % | ||
163 | (nrealwriters_stress * 2000 * longdelay_us))) | ||
164 | mdelay(longdelay_us); | ||
165 | if (!(torture_random(trsp) % | ||
166 | (nrealwriters_stress * 2 * shortdelay_us))) | ||
167 | udelay(shortdelay_us); | ||
168 | #ifdef CONFIG_PREEMPT | ||
169 | if (!(torture_random(trsp) % (nrealwriters_stress * 20000))) | ||
170 | preempt_schedule(); /* Allow test to be preempted. */ | ||
171 | #endif | ||
172 | } | ||
173 | |||
174 | static void torture_spin_lock_write_unlock(void) __releases(torture_spinlock) | ||
175 | { | ||
176 | spin_unlock(&torture_spinlock); | ||
177 | } | ||
178 | |||
179 | static struct lock_torture_ops spin_lock_ops = { | ||
180 | .writelock = torture_spin_lock_write_lock, | ||
181 | .write_delay = torture_spin_lock_write_delay, | ||
182 | .writeunlock = torture_spin_lock_write_unlock, | ||
183 | .name = "spin_lock" | ||
184 | }; | ||
185 | |||
186 | static int torture_spin_lock_write_lock_irq(void) | ||
187 | __acquires(torture_spinlock_irq) | ||
188 | { | ||
189 | unsigned long flags; | ||
190 | |||
191 | spin_lock_irqsave(&torture_spinlock, flags); | ||
192 | cur_ops->flags = flags; | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | static void torture_lock_spin_write_unlock_irq(void) | ||
197 | __releases(torture_spinlock) | ||
198 | { | ||
199 | spin_unlock_irqrestore(&torture_spinlock, cur_ops->flags); | ||
200 | } | ||
201 | |||
202 | static struct lock_torture_ops spin_lock_irq_ops = { | ||
203 | .writelock = torture_spin_lock_write_lock_irq, | ||
204 | .write_delay = torture_spin_lock_write_delay, | ||
205 | .writeunlock = torture_lock_spin_write_unlock_irq, | ||
206 | .name = "spin_lock_irq" | ||
207 | }; | ||
208 | |||
209 | /* | ||
210 | * Lock torture writer kthread. Repeatedly acquires and releases | ||
211 | * the lock, checking for duplicate acquisitions. | ||
212 | */ | ||
213 | static int lock_torture_writer(void *arg) | ||
214 | { | ||
215 | struct lock_writer_stress_stats *lwsp = arg; | ||
216 | static DEFINE_TORTURE_RANDOM(rand); | ||
217 | |||
218 | VERBOSE_TOROUT_STRING("lock_torture_writer task started"); | ||
219 | set_user_nice(current, 19); | ||
220 | |||
221 | do { | ||
222 | schedule_timeout_uninterruptible(1); | ||
223 | cur_ops->writelock(); | ||
224 | if (WARN_ON_ONCE(lock_is_write_held)) | ||
225 | lwsp->n_write_lock_fail++; | ||
226 | lock_is_write_held = 1; | ||
227 | lwsp->n_write_lock_acquired++; | ||
228 | cur_ops->write_delay(&rand); | ||
229 | lock_is_write_held = 0; | ||
230 | cur_ops->writeunlock(); | ||
231 | stutter_wait("lock_torture_writer"); | ||
232 | } while (!torture_must_stop()); | ||
233 | torture_kthread_stopping("lock_torture_writer"); | ||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | /* | ||
238 | * Create an lock-torture-statistics message in the specified buffer. | ||
239 | */ | ||
240 | static void lock_torture_printk(char *page) | ||
241 | { | ||
242 | bool fail = 0; | ||
243 | int i; | ||
244 | long max = 0; | ||
245 | long min = lwsa[0].n_write_lock_acquired; | ||
246 | long long sum = 0; | ||
247 | |||
248 | for (i = 0; i < nrealwriters_stress; i++) { | ||
249 | if (lwsa[i].n_write_lock_fail) | ||
250 | fail = true; | ||
251 | sum += lwsa[i].n_write_lock_acquired; | ||
252 | if (max < lwsa[i].n_write_lock_fail) | ||
253 | max = lwsa[i].n_write_lock_fail; | ||
254 | if (min > lwsa[i].n_write_lock_fail) | ||
255 | min = lwsa[i].n_write_lock_fail; | ||
256 | } | ||
257 | page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG); | ||
258 | page += sprintf(page, | ||
259 | "Writes: Total: %lld Max/Min: %ld/%ld %s Fail: %d %s\n", | ||
260 | sum, max, min, max / 2 > min ? "???" : "", | ||
261 | fail, fail ? "!!!" : ""); | ||
262 | if (fail) | ||
263 | atomic_inc(&n_lock_torture_errors); | ||
264 | } | ||
265 | |||
266 | /* | ||
267 | * Print torture statistics. Caller must ensure that there is only one | ||
268 | * call to this function at a given time!!! This is normally accomplished | ||
269 | * by relying on the module system to only have one copy of the module | ||
270 | * loaded, and then by giving the lock_torture_stats kthread full control | ||
271 | * (or the init/cleanup functions when lock_torture_stats thread is not | ||
272 | * running). | ||
273 | */ | ||
274 | static void lock_torture_stats_print(void) | ||
275 | { | ||
276 | int size = nrealwriters_stress * 200 + 8192; | ||
277 | char *buf; | ||
278 | |||
279 | buf = kmalloc(size, GFP_KERNEL); | ||
280 | if (!buf) { | ||
281 | pr_err("lock_torture_stats_print: Out of memory, need: %d", | ||
282 | size); | ||
283 | return; | ||
284 | } | ||
285 | lock_torture_printk(buf); | ||
286 | pr_alert("%s", buf); | ||
287 | kfree(buf); | ||
288 | } | ||
289 | |||
290 | /* | ||
291 | * Periodically prints torture statistics, if periodic statistics printing | ||
292 | * was specified via the stat_interval module parameter. | ||
293 | * | ||
294 | * No need to worry about fullstop here, since this one doesn't reference | ||
295 | * volatile state or register callbacks. | ||
296 | */ | ||
297 | static int lock_torture_stats(void *arg) | ||
298 | { | ||
299 | VERBOSE_TOROUT_STRING("lock_torture_stats task started"); | ||
300 | do { | ||
301 | schedule_timeout_interruptible(stat_interval * HZ); | ||
302 | lock_torture_stats_print(); | ||
303 | torture_shutdown_absorb("lock_torture_stats"); | ||
304 | } while (!torture_must_stop()); | ||
305 | torture_kthread_stopping("lock_torture_stats"); | ||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | static inline void | ||
310 | lock_torture_print_module_parms(struct lock_torture_ops *cur_ops, | ||
311 | const char *tag) | ||
312 | { | ||
313 | pr_alert("%s" TORTURE_FLAG | ||
314 | "--- %s: nwriters_stress=%d stat_interval=%d verbose=%d shuffle_interval=%d stutter=%d shutdown_secs=%d onoff_interval=%d onoff_holdoff=%d\n", | ||
315 | torture_type, tag, nrealwriters_stress, stat_interval, verbose, | ||
316 | shuffle_interval, stutter, shutdown_secs, | ||
317 | onoff_interval, onoff_holdoff); | ||
318 | } | ||
319 | |||
320 | static void lock_torture_cleanup(void) | ||
321 | { | ||
322 | int i; | ||
323 | |||
324 | if (torture_cleanup()) | ||
325 | return; | ||
326 | |||
327 | if (writer_tasks) { | ||
328 | for (i = 0; i < nrealwriters_stress; i++) | ||
329 | torture_stop_kthread(lock_torture_writer, | ||
330 | writer_tasks[i]); | ||
331 | kfree(writer_tasks); | ||
332 | writer_tasks = NULL; | ||
333 | } | ||
334 | |||
335 | torture_stop_kthread(lock_torture_stats, stats_task); | ||
336 | lock_torture_stats_print(); /* -After- the stats thread is stopped! */ | ||
337 | |||
338 | if (atomic_read(&n_lock_torture_errors)) | ||
339 | lock_torture_print_module_parms(cur_ops, | ||
340 | "End of test: FAILURE"); | ||
341 | else if (torture_onoff_failures()) | ||
342 | lock_torture_print_module_parms(cur_ops, | ||
343 | "End of test: LOCK_HOTPLUG"); | ||
344 | else | ||
345 | lock_torture_print_module_parms(cur_ops, | ||
346 | "End of test: SUCCESS"); | ||
347 | } | ||
348 | |||
349 | static int __init lock_torture_init(void) | ||
350 | { | ||
351 | int i; | ||
352 | int firsterr = 0; | ||
353 | static struct lock_torture_ops *torture_ops[] = { | ||
354 | &lock_busted_ops, &spin_lock_ops, &spin_lock_irq_ops, | ||
355 | }; | ||
356 | |||
357 | torture_init_begin(torture_type, verbose, &locktorture_runnable); | ||
358 | |||
359 | /* Process args and tell the world that the torturer is on the job. */ | ||
360 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { | ||
361 | cur_ops = torture_ops[i]; | ||
362 | if (strcmp(torture_type, cur_ops->name) == 0) | ||
363 | break; | ||
364 | } | ||
365 | if (i == ARRAY_SIZE(torture_ops)) { | ||
366 | pr_alert("lock-torture: invalid torture type: \"%s\"\n", | ||
367 | torture_type); | ||
368 | pr_alert("lock-torture types:"); | ||
369 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) | ||
370 | pr_alert(" %s", torture_ops[i]->name); | ||
371 | pr_alert("\n"); | ||
372 | torture_init_end(); | ||
373 | return -EINVAL; | ||
374 | } | ||
375 | if (cur_ops->init) | ||
376 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ | ||
377 | |||
378 | if (nwriters_stress >= 0) | ||
379 | nrealwriters_stress = nwriters_stress; | ||
380 | else | ||
381 | nrealwriters_stress = 2 * num_online_cpus(); | ||
382 | lock_torture_print_module_parms(cur_ops, "Start of test"); | ||
383 | |||
384 | /* Initialize the statistics so that each run gets its own numbers. */ | ||
385 | |||
386 | lock_is_write_held = 0; | ||
387 | lwsa = kmalloc(sizeof(*lwsa) * nrealwriters_stress, GFP_KERNEL); | ||
388 | if (lwsa == NULL) { | ||
389 | VERBOSE_TOROUT_STRING("lwsa: Out of memory"); | ||
390 | firsterr = -ENOMEM; | ||
391 | goto unwind; | ||
392 | } | ||
393 | for (i = 0; i < nrealwriters_stress; i++) { | ||
394 | lwsa[i].n_write_lock_fail = 0; | ||
395 | lwsa[i].n_write_lock_acquired = 0; | ||
396 | } | ||
397 | |||
398 | /* Start up the kthreads. */ | ||
399 | |||
400 | if (onoff_interval > 0) { | ||
401 | firsterr = torture_onoff_init(onoff_holdoff * HZ, | ||
402 | onoff_interval * HZ); | ||
403 | if (firsterr) | ||
404 | goto unwind; | ||
405 | } | ||
406 | if (shuffle_interval > 0) { | ||
407 | firsterr = torture_shuffle_init(shuffle_interval); | ||
408 | if (firsterr) | ||
409 | goto unwind; | ||
410 | } | ||
411 | if (shutdown_secs > 0) { | ||
412 | firsterr = torture_shutdown_init(shutdown_secs, | ||
413 | lock_torture_cleanup); | ||
414 | if (firsterr) | ||
415 | goto unwind; | ||
416 | } | ||
417 | if (stutter > 0) { | ||
418 | firsterr = torture_stutter_init(stutter); | ||
419 | if (firsterr) | ||
420 | goto unwind; | ||
421 | } | ||
422 | |||
423 | writer_tasks = kzalloc(nrealwriters_stress * sizeof(writer_tasks[0]), | ||
424 | GFP_KERNEL); | ||
425 | if (writer_tasks == NULL) { | ||
426 | VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory"); | ||
427 | firsterr = -ENOMEM; | ||
428 | goto unwind; | ||
429 | } | ||
430 | for (i = 0; i < nrealwriters_stress; i++) { | ||
431 | firsterr = torture_create_kthread(lock_torture_writer, &lwsa[i], | ||
432 | writer_tasks[i]); | ||
433 | if (firsterr) | ||
434 | goto unwind; | ||
435 | } | ||
436 | if (stat_interval > 0) { | ||
437 | firsterr = torture_create_kthread(lock_torture_stats, NULL, | ||
438 | stats_task); | ||
439 | if (firsterr) | ||
440 | goto unwind; | ||
441 | } | ||
442 | torture_init_end(); | ||
443 | return 0; | ||
444 | |||
445 | unwind: | ||
446 | torture_init_end(); | ||
447 | lock_torture_cleanup(); | ||
448 | return firsterr; | ||
449 | } | ||
450 | |||
451 | module_init(lock_torture_init); | ||
452 | module_exit(lock_torture_cleanup); | ||
diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c new file mode 100644 index 000000000000..838dc9e00669 --- /dev/null +++ b/kernel/locking/mcs_spinlock.c | |||
@@ -0,0 +1,178 @@ | |||
1 | |||
2 | #include <linux/percpu.h> | ||
3 | #include <linux/mutex.h> | ||
4 | #include <linux/sched.h> | ||
5 | #include "mcs_spinlock.h" | ||
6 | |||
7 | #ifdef CONFIG_SMP | ||
8 | |||
9 | /* | ||
10 | * An MCS like lock especially tailored for optimistic spinning for sleeping | ||
11 | * lock implementations (mutex, rwsem, etc). | ||
12 | * | ||
13 | * Using a single mcs node per CPU is safe because sleeping locks should not be | ||
14 | * called from interrupt context and we have preemption disabled while | ||
15 | * spinning. | ||
16 | */ | ||
17 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct optimistic_spin_queue, osq_node); | ||
18 | |||
19 | /* | ||
20 | * Get a stable @node->next pointer, either for unlock() or unqueue() purposes. | ||
21 | * Can return NULL in case we were the last queued and we updated @lock instead. | ||
22 | */ | ||
23 | static inline struct optimistic_spin_queue * | ||
24 | osq_wait_next(struct optimistic_spin_queue **lock, | ||
25 | struct optimistic_spin_queue *node, | ||
26 | struct optimistic_spin_queue *prev) | ||
27 | { | ||
28 | struct optimistic_spin_queue *next = NULL; | ||
29 | |||
30 | for (;;) { | ||
31 | if (*lock == node && cmpxchg(lock, node, prev) == node) { | ||
32 | /* | ||
33 | * We were the last queued, we moved @lock back. @prev | ||
34 | * will now observe @lock and will complete its | ||
35 | * unlock()/unqueue(). | ||
36 | */ | ||
37 | break; | ||
38 | } | ||
39 | |||
40 | /* | ||
41 | * We must xchg() the @node->next value, because if we were to | ||
42 | * leave it in, a concurrent unlock()/unqueue() from | ||
43 | * @node->next might complete Step-A and think its @prev is | ||
44 | * still valid. | ||
45 | * | ||
46 | * If the concurrent unlock()/unqueue() wins the race, we'll | ||
47 | * wait for either @lock to point to us, through its Step-B, or | ||
48 | * wait for a new @node->next from its Step-C. | ||
49 | */ | ||
50 | if (node->next) { | ||
51 | next = xchg(&node->next, NULL); | ||
52 | if (next) | ||
53 | break; | ||
54 | } | ||
55 | |||
56 | arch_mutex_cpu_relax(); | ||
57 | } | ||
58 | |||
59 | return next; | ||
60 | } | ||
61 | |||
62 | bool osq_lock(struct optimistic_spin_queue **lock) | ||
63 | { | ||
64 | struct optimistic_spin_queue *node = this_cpu_ptr(&osq_node); | ||
65 | struct optimistic_spin_queue *prev, *next; | ||
66 | |||
67 | node->locked = 0; | ||
68 | node->next = NULL; | ||
69 | |||
70 | node->prev = prev = xchg(lock, node); | ||
71 | if (likely(prev == NULL)) | ||
72 | return true; | ||
73 | |||
74 | ACCESS_ONCE(prev->next) = node; | ||
75 | |||
76 | /* | ||
77 | * Normally @prev is untouchable after the above store; because at that | ||
78 | * moment unlock can proceed and wipe the node element from stack. | ||
79 | * | ||
80 | * However, since our nodes are static per-cpu storage, we're | ||
81 | * guaranteed their existence -- this allows us to apply | ||
82 | * cmpxchg in an attempt to undo our queueing. | ||
83 | */ | ||
84 | |||
85 | while (!smp_load_acquire(&node->locked)) { | ||
86 | /* | ||
87 | * If we need to reschedule bail... so we can block. | ||
88 | */ | ||
89 | if (need_resched()) | ||
90 | goto unqueue; | ||
91 | |||
92 | arch_mutex_cpu_relax(); | ||
93 | } | ||
94 | return true; | ||
95 | |||
96 | unqueue: | ||
97 | /* | ||
98 | * Step - A -- stabilize @prev | ||
99 | * | ||
100 | * Undo our @prev->next assignment; this will make @prev's | ||
101 | * unlock()/unqueue() wait for a next pointer since @lock points to us | ||
102 | * (or later). | ||
103 | */ | ||
104 | |||
105 | for (;;) { | ||
106 | if (prev->next == node && | ||
107 | cmpxchg(&prev->next, node, NULL) == node) | ||
108 | break; | ||
109 | |||
110 | /* | ||
111 | * We can only fail the cmpxchg() racing against an unlock(), | ||
112 | * in which case we should observe @node->locked becomming | ||
113 | * true. | ||
114 | */ | ||
115 | if (smp_load_acquire(&node->locked)) | ||
116 | return true; | ||
117 | |||
118 | arch_mutex_cpu_relax(); | ||
119 | |||
120 | /* | ||
121 | * Or we race against a concurrent unqueue()'s step-B, in which | ||
122 | * case its step-C will write us a new @node->prev pointer. | ||
123 | */ | ||
124 | prev = ACCESS_ONCE(node->prev); | ||
125 | } | ||
126 | |||
127 | /* | ||
128 | * Step - B -- stabilize @next | ||
129 | * | ||
130 | * Similar to unlock(), wait for @node->next or move @lock from @node | ||
131 | * back to @prev. | ||
132 | */ | ||
133 | |||
134 | next = osq_wait_next(lock, node, prev); | ||
135 | if (!next) | ||
136 | return false; | ||
137 | |||
138 | /* | ||
139 | * Step - C -- unlink | ||
140 | * | ||
141 | * @prev is stable because its still waiting for a new @prev->next | ||
142 | * pointer, @next is stable because our @node->next pointer is NULL and | ||
143 | * it will wait in Step-A. | ||
144 | */ | ||
145 | |||
146 | ACCESS_ONCE(next->prev) = prev; | ||
147 | ACCESS_ONCE(prev->next) = next; | ||
148 | |||
149 | return false; | ||
150 | } | ||
151 | |||
152 | void osq_unlock(struct optimistic_spin_queue **lock) | ||
153 | { | ||
154 | struct optimistic_spin_queue *node = this_cpu_ptr(&osq_node); | ||
155 | struct optimistic_spin_queue *next; | ||
156 | |||
157 | /* | ||
158 | * Fast path for the uncontended case. | ||
159 | */ | ||
160 | if (likely(cmpxchg(lock, node, NULL) == node)) | ||
161 | return; | ||
162 | |||
163 | /* | ||
164 | * Second most likely case. | ||
165 | */ | ||
166 | next = xchg(&node->next, NULL); | ||
167 | if (next) { | ||
168 | ACCESS_ONCE(next->locked) = 1; | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | next = osq_wait_next(lock, node, NULL); | ||
173 | if (next) | ||
174 | ACCESS_ONCE(next->locked) = 1; | ||
175 | } | ||
176 | |||
177 | #endif | ||
178 | |||
diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h new file mode 100644 index 000000000000..a2dbac4aca6b --- /dev/null +++ b/kernel/locking/mcs_spinlock.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * MCS lock defines | ||
3 | * | ||
4 | * This file contains the main data structure and API definitions of MCS lock. | ||
5 | * | ||
6 | * The MCS lock (proposed by Mellor-Crummey and Scott) is a simple spin-lock | ||
7 | * with the desirable properties of being fair, and with each cpu trying | ||
8 | * to acquire the lock spinning on a local variable. | ||
9 | * It avoids expensive cache bouncings that common test-and-set spin-lock | ||
10 | * implementations incur. | ||
11 | */ | ||
12 | #ifndef __LINUX_MCS_SPINLOCK_H | ||
13 | #define __LINUX_MCS_SPINLOCK_H | ||
14 | |||
15 | #include <asm/mcs_spinlock.h> | ||
16 | |||
17 | struct mcs_spinlock { | ||
18 | struct mcs_spinlock *next; | ||
19 | int locked; /* 1 if lock acquired */ | ||
20 | }; | ||
21 | |||
22 | #ifndef arch_mcs_spin_lock_contended | ||
23 | /* | ||
24 | * Using smp_load_acquire() provides a memory barrier that ensures | ||
25 | * subsequent operations happen after the lock is acquired. | ||
26 | */ | ||
27 | #define arch_mcs_spin_lock_contended(l) \ | ||
28 | do { \ | ||
29 | while (!(smp_load_acquire(l))) \ | ||
30 | arch_mutex_cpu_relax(); \ | ||
31 | } while (0) | ||
32 | #endif | ||
33 | |||
34 | #ifndef arch_mcs_spin_unlock_contended | ||
35 | /* | ||
36 | * smp_store_release() provides a memory barrier to ensure all | ||
37 | * operations in the critical section has been completed before | ||
38 | * unlocking. | ||
39 | */ | ||
40 | #define arch_mcs_spin_unlock_contended(l) \ | ||
41 | smp_store_release((l), 1) | ||
42 | #endif | ||
43 | |||
44 | /* | ||
45 | * Note: the smp_load_acquire/smp_store_release pair is not | ||
46 | * sufficient to form a full memory barrier across | ||
47 | * cpus for many architectures (except x86) for mcs_unlock and mcs_lock. | ||
48 | * For applications that need a full barrier across multiple cpus | ||
49 | * with mcs_unlock and mcs_lock pair, smp_mb__after_unlock_lock() should be | ||
50 | * used after mcs_lock. | ||
51 | */ | ||
52 | |||
53 | /* | ||
54 | * In order to acquire the lock, the caller should declare a local node and | ||
55 | * pass a reference of the node to this function in addition to the lock. | ||
56 | * If the lock has already been acquired, then this will proceed to spin | ||
57 | * on this node->locked until the previous lock holder sets the node->locked | ||
58 | * in mcs_spin_unlock(). | ||
59 | * | ||
60 | * We don't inline mcs_spin_lock() so that perf can correctly account for the | ||
61 | * time spent in this lock function. | ||
62 | */ | ||
63 | static inline | ||
64 | void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) | ||
65 | { | ||
66 | struct mcs_spinlock *prev; | ||
67 | |||
68 | /* Init node */ | ||
69 | node->locked = 0; | ||
70 | node->next = NULL; | ||
71 | |||
72 | prev = xchg(lock, node); | ||
73 | if (likely(prev == NULL)) { | ||
74 | /* | ||
75 | * Lock acquired, don't need to set node->locked to 1. Threads | ||
76 | * only spin on its own node->locked value for lock acquisition. | ||
77 | * However, since this thread can immediately acquire the lock | ||
78 | * and does not proceed to spin on its own node->locked, this | ||
79 | * value won't be used. If a debug mode is needed to | ||
80 | * audit lock status, then set node->locked value here. | ||
81 | */ | ||
82 | return; | ||
83 | } | ||
84 | ACCESS_ONCE(prev->next) = node; | ||
85 | |||
86 | /* Wait until the lock holder passes the lock down. */ | ||
87 | arch_mcs_spin_lock_contended(&node->locked); | ||
88 | } | ||
89 | |||
90 | /* | ||
91 | * Releases the lock. The caller should pass in the corresponding node that | ||
92 | * was used to acquire the lock. | ||
93 | */ | ||
94 | static inline | ||
95 | void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node) | ||
96 | { | ||
97 | struct mcs_spinlock *next = ACCESS_ONCE(node->next); | ||
98 | |||
99 | if (likely(!next)) { | ||
100 | /* | ||
101 | * Release the lock by setting it to NULL | ||
102 | */ | ||
103 | if (likely(cmpxchg(lock, node, NULL) == node)) | ||
104 | return; | ||
105 | /* Wait until the next pointer is set */ | ||
106 | while (!(next = ACCESS_ONCE(node->next))) | ||
107 | arch_mutex_cpu_relax(); | ||
108 | } | ||
109 | |||
110 | /* Pass lock to next waiter. */ | ||
111 | arch_mcs_spin_unlock_contended(&next->locked); | ||
112 | } | ||
113 | |||
114 | /* | ||
115 | * Cancellable version of the MCS lock above. | ||
116 | * | ||
117 | * Intended for adaptive spinning of sleeping locks: | ||
118 | * mutex_lock()/rwsem_down_{read,write}() etc. | ||
119 | */ | ||
120 | |||
121 | struct optimistic_spin_queue { | ||
122 | struct optimistic_spin_queue *next, *prev; | ||
123 | int locked; /* 1 if lock acquired */ | ||
124 | }; | ||
125 | |||
126 | extern bool osq_lock(struct optimistic_spin_queue **lock); | ||
127 | extern void osq_unlock(struct optimistic_spin_queue **lock); | ||
128 | |||
129 | #endif /* __LINUX_MCS_SPINLOCK_H */ | ||
diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c index faf6f5b53e77..e1191c996c59 100644 --- a/kernel/locking/mutex-debug.c +++ b/kernel/locking/mutex-debug.c | |||
@@ -83,6 +83,12 @@ void debug_mutex_unlock(struct mutex *lock) | |||
83 | 83 | ||
84 | DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next); | 84 | DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next); |
85 | mutex_clear_owner(lock); | 85 | mutex_clear_owner(lock); |
86 | |||
87 | /* | ||
88 | * __mutex_slowpath_needs_to_unlock() is explicitly 0 for debug | ||
89 | * mutexes so that we can do it here after we've verified state. | ||
90 | */ | ||
91 | atomic_set(&lock->count, 1); | ||
86 | } | 92 | } |
87 | 93 | ||
88 | void debug_mutex_init(struct mutex *lock, const char *name, | 94 | void debug_mutex_init(struct mutex *lock, const char *name, |
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 4dd6e4c219de..14fe72cc8ce7 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/spinlock.h> | 25 | #include <linux/spinlock.h> |
26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
27 | #include <linux/debug_locks.h> | 27 | #include <linux/debug_locks.h> |
28 | #include "mcs_spinlock.h" | ||
28 | 29 | ||
29 | /* | 30 | /* |
30 | * In the DEBUG case we are using the "NULL fastpath" for mutexes, | 31 | * In the DEBUG case we are using the "NULL fastpath" for mutexes, |
@@ -33,6 +34,13 @@ | |||
33 | #ifdef CONFIG_DEBUG_MUTEXES | 34 | #ifdef CONFIG_DEBUG_MUTEXES |
34 | # include "mutex-debug.h" | 35 | # include "mutex-debug.h" |
35 | # include <asm-generic/mutex-null.h> | 36 | # include <asm-generic/mutex-null.h> |
37 | /* | ||
38 | * Must be 0 for the debug case so we do not do the unlock outside of the | ||
39 | * wait_lock region. debug_mutex_unlock() will do the actual unlock in this | ||
40 | * case. | ||
41 | */ | ||
42 | # undef __mutex_slowpath_needs_to_unlock | ||
43 | # define __mutex_slowpath_needs_to_unlock() 0 | ||
36 | #else | 44 | #else |
37 | # include "mutex.h" | 45 | # include "mutex.h" |
38 | # include <asm/mutex.h> | 46 | # include <asm/mutex.h> |
@@ -52,7 +60,7 @@ __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) | |||
52 | INIT_LIST_HEAD(&lock->wait_list); | 60 | INIT_LIST_HEAD(&lock->wait_list); |
53 | mutex_clear_owner(lock); | 61 | mutex_clear_owner(lock); |
54 | #ifdef CONFIG_MUTEX_SPIN_ON_OWNER | 62 | #ifdef CONFIG_MUTEX_SPIN_ON_OWNER |
55 | lock->spin_mlock = NULL; | 63 | lock->osq = NULL; |
56 | #endif | 64 | #endif |
57 | 65 | ||
58 | debug_mutex_init(lock, name, key); | 66 | debug_mutex_init(lock, name, key); |
@@ -111,54 +119,7 @@ EXPORT_SYMBOL(mutex_lock); | |||
111 | * more or less simultaneously, the spinners need to acquire a MCS lock | 119 | * more or less simultaneously, the spinners need to acquire a MCS lock |
112 | * first before spinning on the owner field. | 120 | * first before spinning on the owner field. |
113 | * | 121 | * |
114 | * We don't inline mspin_lock() so that perf can correctly account for the | ||
115 | * time spent in this lock function. | ||
116 | */ | 122 | */ |
117 | struct mspin_node { | ||
118 | struct mspin_node *next ; | ||
119 | int locked; /* 1 if lock acquired */ | ||
120 | }; | ||
121 | #define MLOCK(mutex) ((struct mspin_node **)&((mutex)->spin_mlock)) | ||
122 | |||
123 | static noinline | ||
124 | void mspin_lock(struct mspin_node **lock, struct mspin_node *node) | ||
125 | { | ||
126 | struct mspin_node *prev; | ||
127 | |||
128 | /* Init node */ | ||
129 | node->locked = 0; | ||
130 | node->next = NULL; | ||
131 | |||
132 | prev = xchg(lock, node); | ||
133 | if (likely(prev == NULL)) { | ||
134 | /* Lock acquired */ | ||
135 | node->locked = 1; | ||
136 | return; | ||
137 | } | ||
138 | ACCESS_ONCE(prev->next) = node; | ||
139 | smp_wmb(); | ||
140 | /* Wait until the lock holder passes the lock down */ | ||
141 | while (!ACCESS_ONCE(node->locked)) | ||
142 | arch_mutex_cpu_relax(); | ||
143 | } | ||
144 | |||
145 | static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node) | ||
146 | { | ||
147 | struct mspin_node *next = ACCESS_ONCE(node->next); | ||
148 | |||
149 | if (likely(!next)) { | ||
150 | /* | ||
151 | * Release the lock by setting it to NULL | ||
152 | */ | ||
153 | if (cmpxchg(lock, node, NULL) == node) | ||
154 | return; | ||
155 | /* Wait until the next pointer is set */ | ||
156 | while (!(next = ACCESS_ONCE(node->next))) | ||
157 | arch_mutex_cpu_relax(); | ||
158 | } | ||
159 | ACCESS_ONCE(next->locked) = 1; | ||
160 | smp_wmb(); | ||
161 | } | ||
162 | 123 | ||
163 | /* | 124 | /* |
164 | * Mutex spinning code migrated from kernel/sched/core.c | 125 | * Mutex spinning code migrated from kernel/sched/core.c |
@@ -212,6 +173,9 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock) | |||
212 | struct task_struct *owner; | 173 | struct task_struct *owner; |
213 | int retval = 1; | 174 | int retval = 1; |
214 | 175 | ||
176 | if (need_resched()) | ||
177 | return 0; | ||
178 | |||
215 | rcu_read_lock(); | 179 | rcu_read_lock(); |
216 | owner = ACCESS_ONCE(lock->owner); | 180 | owner = ACCESS_ONCE(lock->owner); |
217 | if (owner) | 181 | if (owner) |
@@ -446,9 +410,11 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
446 | if (!mutex_can_spin_on_owner(lock)) | 410 | if (!mutex_can_spin_on_owner(lock)) |
447 | goto slowpath; | 411 | goto slowpath; |
448 | 412 | ||
413 | if (!osq_lock(&lock->osq)) | ||
414 | goto slowpath; | ||
415 | |||
449 | for (;;) { | 416 | for (;;) { |
450 | struct task_struct *owner; | 417 | struct task_struct *owner; |
451 | struct mspin_node node; | ||
452 | 418 | ||
453 | if (use_ww_ctx && ww_ctx->acquired > 0) { | 419 | if (use_ww_ctx && ww_ctx->acquired > 0) { |
454 | struct ww_mutex *ww; | 420 | struct ww_mutex *ww; |
@@ -463,19 +429,16 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
463 | * performed the optimistic spinning cannot be done. | 429 | * performed the optimistic spinning cannot be done. |
464 | */ | 430 | */ |
465 | if (ACCESS_ONCE(ww->ctx)) | 431 | if (ACCESS_ONCE(ww->ctx)) |
466 | goto slowpath; | 432 | break; |
467 | } | 433 | } |
468 | 434 | ||
469 | /* | 435 | /* |
470 | * If there's an owner, wait for it to either | 436 | * If there's an owner, wait for it to either |
471 | * release the lock or go to sleep. | 437 | * release the lock or go to sleep. |
472 | */ | 438 | */ |
473 | mspin_lock(MLOCK(lock), &node); | ||
474 | owner = ACCESS_ONCE(lock->owner); | 439 | owner = ACCESS_ONCE(lock->owner); |
475 | if (owner && !mutex_spin_on_owner(lock, owner)) { | 440 | if (owner && !mutex_spin_on_owner(lock, owner)) |
476 | mspin_unlock(MLOCK(lock), &node); | 441 | break; |
477 | goto slowpath; | ||
478 | } | ||
479 | 442 | ||
480 | if ((atomic_read(&lock->count) == 1) && | 443 | if ((atomic_read(&lock->count) == 1) && |
481 | (atomic_cmpxchg(&lock->count, 1, 0) == 1)) { | 444 | (atomic_cmpxchg(&lock->count, 1, 0) == 1)) { |
@@ -488,11 +451,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
488 | } | 451 | } |
489 | 452 | ||
490 | mutex_set_owner(lock); | 453 | mutex_set_owner(lock); |
491 | mspin_unlock(MLOCK(lock), &node); | 454 | osq_unlock(&lock->osq); |
492 | preempt_enable(); | 455 | preempt_enable(); |
493 | return 0; | 456 | return 0; |
494 | } | 457 | } |
495 | mspin_unlock(MLOCK(lock), &node); | ||
496 | 458 | ||
497 | /* | 459 | /* |
498 | * When there's no owner, we might have preempted between the | 460 | * When there's no owner, we might have preempted between the |
@@ -501,7 +463,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
501 | * the owner complete. | 463 | * the owner complete. |
502 | */ | 464 | */ |
503 | if (!owner && (need_resched() || rt_task(task))) | 465 | if (!owner && (need_resched() || rt_task(task))) |
504 | goto slowpath; | 466 | break; |
505 | 467 | ||
506 | /* | 468 | /* |
507 | * The cpu_relax() call is a compiler barrier which forces | 469 | * The cpu_relax() call is a compiler barrier which forces |
@@ -511,7 +473,15 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
511 | */ | 473 | */ |
512 | arch_mutex_cpu_relax(); | 474 | arch_mutex_cpu_relax(); |
513 | } | 475 | } |
476 | osq_unlock(&lock->osq); | ||
514 | slowpath: | 477 | slowpath: |
478 | /* | ||
479 | * If we fell out of the spin path because of need_resched(), | ||
480 | * reschedule now, before we try-lock the mutex. This avoids getting | ||
481 | * scheduled out right after we obtained the mutex. | ||
482 | */ | ||
483 | if (need_resched()) | ||
484 | schedule_preempt_disabled(); | ||
515 | #endif | 485 | #endif |
516 | spin_lock_mutex(&lock->wait_lock, flags); | 486 | spin_lock_mutex(&lock->wait_lock, flags); |
517 | 487 | ||
@@ -717,10 +687,6 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested) | |||
717 | struct mutex *lock = container_of(lock_count, struct mutex, count); | 687 | struct mutex *lock = container_of(lock_count, struct mutex, count); |
718 | unsigned long flags; | 688 | unsigned long flags; |
719 | 689 | ||
720 | spin_lock_mutex(&lock->wait_lock, flags); | ||
721 | mutex_release(&lock->dep_map, nested, _RET_IP_); | ||
722 | debug_mutex_unlock(lock); | ||
723 | |||
724 | /* | 690 | /* |
725 | * some architectures leave the lock unlocked in the fastpath failure | 691 | * some architectures leave the lock unlocked in the fastpath failure |
726 | * case, others need to leave it locked. In the later case we have to | 692 | * case, others need to leave it locked. In the later case we have to |
@@ -729,6 +695,10 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested) | |||
729 | if (__mutex_slowpath_needs_to_unlock()) | 695 | if (__mutex_slowpath_needs_to_unlock()) |
730 | atomic_set(&lock->count, 1); | 696 | atomic_set(&lock->count, 1); |
731 | 697 | ||
698 | spin_lock_mutex(&lock->wait_lock, flags); | ||
699 | mutex_release(&lock->dep_map, nested, _RET_IP_); | ||
700 | debug_mutex_unlock(lock); | ||
701 | |||
732 | if (!list_empty(&lock->wait_list)) { | 702 | if (!list_empty(&lock->wait_list)) { |
733 | /* get the first entry from the wait-list: */ | 703 | /* get the first entry from the wait-list: */ |
734 | struct mutex_waiter *waiter = | 704 | struct mutex_waiter *waiter = |
diff --git a/kernel/notifier.c b/kernel/notifier.c index 2d5cc4ccff7f..db4c8b08a50c 100644 --- a/kernel/notifier.c +++ b/kernel/notifier.c | |||
@@ -309,7 +309,7 @@ int __blocking_notifier_call_chain(struct blocking_notifier_head *nh, | |||
309 | * racy then it does not matter what the result of the test | 309 | * racy then it does not matter what the result of the test |
310 | * is, we re-check the list after having taken the lock anyway: | 310 | * is, we re-check the list after having taken the lock anyway: |
311 | */ | 311 | */ |
312 | if (rcu_dereference_raw(nh->head)) { | 312 | if (rcu_access_pointer(nh->head)) { |
313 | down_read(&nh->rwsem); | 313 | down_read(&nh->rwsem); |
314 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, | 314 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, |
315 | nr_calls); | 315 | nr_calls); |
diff --git a/kernel/power/console.c b/kernel/power/console.c index eacb8bd8cab4..aba9c545a0e3 100644 --- a/kernel/power/console.c +++ b/kernel/power/console.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/kbd_kern.h> | 9 | #include <linux/kbd_kern.h> |
10 | #include <linux/vt.h> | 10 | #include <linux/vt.h> |
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/slab.h> | ||
12 | #include "power.h" | 13 | #include "power.h" |
13 | 14 | ||
14 | #define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1) | 15 | #define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1) |
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b1d255f04135..4dae9cbe9259 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c | |||
@@ -1076,7 +1076,6 @@ static int syslog_print_all(char __user *buf, int size, bool clear) | |||
1076 | next_seq = log_next_seq; | 1076 | next_seq = log_next_seq; |
1077 | 1077 | ||
1078 | len = 0; | 1078 | len = 0; |
1079 | prev = 0; | ||
1080 | while (len >= 0 && seq < next_seq) { | 1079 | while (len >= 0 && seq < next_seq) { |
1081 | struct printk_log *msg = log_from_idx(idx); | 1080 | struct printk_log *msg = log_from_idx(idx); |
1082 | int textlen; | 1081 | int textlen; |
@@ -2788,7 +2787,6 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, | |||
2788 | next_idx = idx; | 2787 | next_idx = idx; |
2789 | 2788 | ||
2790 | l = 0; | 2789 | l = 0; |
2791 | prev = 0; | ||
2792 | while (seq < dumper->next_seq) { | 2790 | while (seq < dumper->next_seq) { |
2793 | struct printk_log *msg = log_from_idx(idx); | 2791 | struct printk_log *msg = log_from_idx(idx); |
2794 | 2792 | ||
diff --git a/kernel/profile.c b/kernel/profile.c index 6631e1ef55ab..ebdd9c1a86b4 100644 --- a/kernel/profile.c +++ b/kernel/profile.c | |||
@@ -549,14 +549,14 @@ static int create_hash_tables(void) | |||
549 | struct page *page; | 549 | struct page *page; |
550 | 550 | ||
551 | page = alloc_pages_exact_node(node, | 551 | page = alloc_pages_exact_node(node, |
552 | GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, | 552 | GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE, |
553 | 0); | 553 | 0); |
554 | if (!page) | 554 | if (!page) |
555 | goto out_cleanup; | 555 | goto out_cleanup; |
556 | per_cpu(cpu_profile_hits, cpu)[1] | 556 | per_cpu(cpu_profile_hits, cpu)[1] |
557 | = (struct profile_hit *)page_address(page); | 557 | = (struct profile_hit *)page_address(page); |
558 | page = alloc_pages_exact_node(node, | 558 | page = alloc_pages_exact_node(node, |
559 | GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, | 559 | GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE, |
560 | 0); | 560 | 0); |
561 | if (!page) | 561 | if (!page) |
562 | goto out_cleanup; | 562 | goto out_cleanup; |
diff --git a/kernel/rcu/Makefile b/kernel/rcu/Makefile index 01e9ec37a3e3..807ccfbf69b3 100644 --- a/kernel/rcu/Makefile +++ b/kernel/rcu/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | obj-y += update.o srcu.o | 1 | obj-y += update.o srcu.o |
2 | obj-$(CONFIG_RCU_TORTURE_TEST) += torture.o | 2 | obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o |
3 | obj-$(CONFIG_TREE_RCU) += tree.o | 3 | obj-$(CONFIG_TREE_RCU) += tree.o |
4 | obj-$(CONFIG_TREE_PREEMPT_RCU) += tree.o | 4 | obj-$(CONFIG_TREE_PREEMPT_RCU) += tree.o |
5 | obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o | 5 | obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o |
diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h index 79c3877e9c5b..bfda2726ca45 100644 --- a/kernel/rcu/rcu.h +++ b/kernel/rcu/rcu.h | |||
@@ -12,8 +12,8 @@ | |||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, you can access it online at |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
17 | * | 17 | * |
18 | * Copyright IBM Corporation, 2011 | 18 | * Copyright IBM Corporation, 2011 |
19 | * | 19 | * |
@@ -23,6 +23,7 @@ | |||
23 | #ifndef __LINUX_RCU_H | 23 | #ifndef __LINUX_RCU_H |
24 | #define __LINUX_RCU_H | 24 | #define __LINUX_RCU_H |
25 | 25 | ||
26 | #include <trace/events/rcu.h> | ||
26 | #ifdef CONFIG_RCU_TRACE | 27 | #ifdef CONFIG_RCU_TRACE |
27 | #define RCU_TRACE(stmt) stmt | 28 | #define RCU_TRACE(stmt) stmt |
28 | #else /* #ifdef CONFIG_RCU_TRACE */ | 29 | #else /* #ifdef CONFIG_RCU_TRACE */ |
@@ -116,8 +117,6 @@ static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) | |||
116 | } | 117 | } |
117 | } | 118 | } |
118 | 119 | ||
119 | extern int rcu_expedited; | ||
120 | |||
121 | #ifdef CONFIG_RCU_STALL_COMMON | 120 | #ifdef CONFIG_RCU_STALL_COMMON |
122 | 121 | ||
123 | extern int rcu_cpu_stall_suppress; | 122 | extern int rcu_cpu_stall_suppress; |
diff --git a/kernel/rcu/torture.c b/kernel/rcu/rcutorture.c index 732f8ae3086a..f59d48597dde 100644 --- a/kernel/rcu/torture.c +++ b/kernel/rcu/rcutorture.c | |||
@@ -12,8 +12,8 @@ | |||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, you can access it online at |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
17 | * | 17 | * |
18 | * Copyright (C) IBM Corporation, 2005, 2006 | 18 | * Copyright (C) IBM Corporation, 2005, 2006 |
19 | * | 19 | * |
@@ -48,110 +48,58 @@ | |||
48 | #include <linux/slab.h> | 48 | #include <linux/slab.h> |
49 | #include <linux/trace_clock.h> | 49 | #include <linux/trace_clock.h> |
50 | #include <asm/byteorder.h> | 50 | #include <asm/byteorder.h> |
51 | #include <linux/torture.h> | ||
51 | 52 | ||
52 | MODULE_LICENSE("GPL"); | 53 | MODULE_LICENSE("GPL"); |
53 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>"); | 54 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@freedesktop.org>"); |
54 | 55 | ||
55 | MODULE_ALIAS("rcutorture"); | 56 | |
56 | #ifdef MODULE_PARAM_PREFIX | 57 | torture_param(int, fqs_duration, 0, |
57 | #undef MODULE_PARAM_PREFIX | 58 | "Duration of fqs bursts (us), 0 to disable"); |
58 | #endif | 59 | torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)"); |
59 | #define MODULE_PARAM_PREFIX "rcutorture." | 60 | torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)"); |
60 | 61 | torture_param(bool, gp_exp, false, "Use expedited GP wait primitives"); | |
61 | static int fqs_duration; | 62 | torture_param(bool, gp_normal, false, |
62 | module_param(fqs_duration, int, 0444); | 63 | "Use normal (non-expedited) GP wait primitives"); |
63 | MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us), 0 to disable"); | 64 | torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers"); |
64 | static int fqs_holdoff; | 65 | torture_param(int, n_barrier_cbs, 0, |
65 | module_param(fqs_holdoff, int, 0444); | 66 | "# of callbacks/kthreads for barrier testing"); |
66 | MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)"); | 67 | torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads"); |
67 | static int fqs_stutter = 3; | 68 | torture_param(int, nreaders, -1, "Number of RCU reader threads"); |
68 | module_param(fqs_stutter, int, 0444); | 69 | torture_param(int, object_debug, 0, |
69 | MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)"); | 70 | "Enable debug-object double call_rcu() testing"); |
70 | static bool gp_exp; | 71 | torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)"); |
71 | module_param(gp_exp, bool, 0444); | 72 | torture_param(int, onoff_interval, 0, |
72 | MODULE_PARM_DESC(gp_exp, "Use expedited GP wait primitives"); | 73 | "Time between CPU hotplugs (s), 0=disable"); |
73 | static bool gp_normal; | 74 | torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles"); |
74 | module_param(gp_normal, bool, 0444); | 75 | torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable."); |
75 | MODULE_PARM_DESC(gp_normal, "Use normal (non-expedited) GP wait primitives"); | 76 | torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable."); |
76 | static int irqreader = 1; | 77 | torture_param(int, stall_cpu_holdoff, 10, |
77 | module_param(irqreader, int, 0444); | 78 | "Time to wait before starting stall (s)."); |
78 | MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers"); | 79 | torture_param(int, stat_interval, 60, |
79 | static int n_barrier_cbs; | 80 | "Number of seconds between stats printk()s"); |
80 | module_param(n_barrier_cbs, int, 0444); | 81 | torture_param(int, stutter, 5, "Number of seconds to run/halt test"); |
81 | MODULE_PARM_DESC(n_barrier_cbs, "# of callbacks/kthreads for barrier testing"); | 82 | torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes."); |
82 | static int nfakewriters = 4; | 83 | torture_param(int, test_boost_duration, 4, |
83 | module_param(nfakewriters, int, 0444); | 84 | "Duration of each boost test, seconds."); |
84 | MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); | 85 | torture_param(int, test_boost_interval, 7, |
85 | static int nreaders = -1; | 86 | "Interval between boost tests, seconds."); |
86 | module_param(nreaders, int, 0444); | 87 | torture_param(bool, test_no_idle_hz, true, |
87 | MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); | 88 | "Test support for tickless idle CPUs"); |
88 | static int object_debug; | 89 | torture_param(bool, verbose, true, |
89 | module_param(object_debug, int, 0444); | 90 | "Enable verbose debugging printk()s"); |
90 | MODULE_PARM_DESC(object_debug, "Enable debug-object double call_rcu() testing"); | 91 | |
91 | static int onoff_holdoff; | ||
92 | module_param(onoff_holdoff, int, 0444); | ||
93 | MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)"); | ||
94 | static int onoff_interval; | ||
95 | module_param(onoff_interval, int, 0444); | ||
96 | MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable"); | ||
97 | static int shuffle_interval = 3; | ||
98 | module_param(shuffle_interval, int, 0444); | ||
99 | MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles"); | ||
100 | static int shutdown_secs; | ||
101 | module_param(shutdown_secs, int, 0444); | ||
102 | MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), <= zero to disable."); | ||
103 | static int stall_cpu; | ||
104 | module_param(stall_cpu, int, 0444); | ||
105 | MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable."); | ||
106 | static int stall_cpu_holdoff = 10; | ||
107 | module_param(stall_cpu_holdoff, int, 0444); | ||
108 | MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s)."); | ||
109 | static int stat_interval = 60; | ||
110 | module_param(stat_interval, int, 0644); | ||
111 | MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s"); | ||
112 | static int stutter = 5; | ||
113 | module_param(stutter, int, 0444); | ||
114 | MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test"); | ||
115 | static int test_boost = 1; | ||
116 | module_param(test_boost, int, 0444); | ||
117 | MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes."); | ||
118 | static int test_boost_duration = 4; | ||
119 | module_param(test_boost_duration, int, 0444); | ||
120 | MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds."); | ||
121 | static int test_boost_interval = 7; | ||
122 | module_param(test_boost_interval, int, 0444); | ||
123 | MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds."); | ||
124 | static bool test_no_idle_hz = true; | ||
125 | module_param(test_no_idle_hz, bool, 0444); | ||
126 | MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs"); | ||
127 | static char *torture_type = "rcu"; | 92 | static char *torture_type = "rcu"; |
128 | module_param(torture_type, charp, 0444); | 93 | module_param(torture_type, charp, 0444); |
129 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)"); | 94 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)"); |
130 | static bool verbose; | ||
131 | module_param(verbose, bool, 0444); | ||
132 | MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); | ||
133 | |||
134 | #define TORTURE_FLAG "-torture:" | ||
135 | #define PRINTK_STRING(s) \ | ||
136 | do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0) | ||
137 | #define VERBOSE_PRINTK_STRING(s) \ | ||
138 | do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0) | ||
139 | #define VERBOSE_PRINTK_ERRSTRING(s) \ | ||
140 | do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) | ||
141 | 95 | ||
142 | static int nrealreaders; | 96 | static int nrealreaders; |
143 | static struct task_struct *writer_task; | 97 | static struct task_struct *writer_task; |
144 | static struct task_struct **fakewriter_tasks; | 98 | static struct task_struct **fakewriter_tasks; |
145 | static struct task_struct **reader_tasks; | 99 | static struct task_struct **reader_tasks; |
146 | static struct task_struct *stats_task; | 100 | static struct task_struct *stats_task; |
147 | static struct task_struct *shuffler_task; | ||
148 | static struct task_struct *stutter_task; | ||
149 | static struct task_struct *fqs_task; | 101 | static struct task_struct *fqs_task; |
150 | static struct task_struct *boost_tasks[NR_CPUS]; | 102 | static struct task_struct *boost_tasks[NR_CPUS]; |
151 | static struct task_struct *shutdown_task; | ||
152 | #ifdef CONFIG_HOTPLUG_CPU | ||
153 | static struct task_struct *onoff_task; | ||
154 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
155 | static struct task_struct *stall_task; | 103 | static struct task_struct *stall_task; |
156 | static struct task_struct **barrier_cbs_tasks; | 104 | static struct task_struct **barrier_cbs_tasks; |
157 | static struct task_struct *barrier_task; | 105 | static struct task_struct *barrier_task; |
@@ -170,10 +118,10 @@ static struct rcu_torture __rcu *rcu_torture_current; | |||
170 | static unsigned long rcu_torture_current_version; | 118 | static unsigned long rcu_torture_current_version; |
171 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; | 119 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; |
172 | static DEFINE_SPINLOCK(rcu_torture_lock); | 120 | static DEFINE_SPINLOCK(rcu_torture_lock); |
173 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = | 121 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], |
174 | { 0 }; | 122 | rcu_torture_count) = { 0 }; |
175 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = | 123 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], |
176 | { 0 }; | 124 | rcu_torture_batch) = { 0 }; |
177 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; | 125 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; |
178 | static atomic_t n_rcu_torture_alloc; | 126 | static atomic_t n_rcu_torture_alloc; |
179 | static atomic_t n_rcu_torture_alloc_fail; | 127 | static atomic_t n_rcu_torture_alloc_fail; |
@@ -186,22 +134,9 @@ static long n_rcu_torture_boost_rterror; | |||
186 | static long n_rcu_torture_boost_failure; | 134 | static long n_rcu_torture_boost_failure; |
187 | static long n_rcu_torture_boosts; | 135 | static long n_rcu_torture_boosts; |
188 | static long n_rcu_torture_timers; | 136 | static long n_rcu_torture_timers; |
189 | static long n_offline_attempts; | ||
190 | static long n_offline_successes; | ||
191 | static unsigned long sum_offline; | ||
192 | static int min_offline = -1; | ||
193 | static int max_offline; | ||
194 | static long n_online_attempts; | ||
195 | static long n_online_successes; | ||
196 | static unsigned long sum_online; | ||
197 | static int min_online = -1; | ||
198 | static int max_online; | ||
199 | static long n_barrier_attempts; | 137 | static long n_barrier_attempts; |
200 | static long n_barrier_successes; | 138 | static long n_barrier_successes; |
201 | static struct list_head rcu_torture_removed; | 139 | static struct list_head rcu_torture_removed; |
202 | static cpumask_var_t shuffle_tmp_mask; | ||
203 | |||
204 | static int stutter_pause_test; | ||
205 | 140 | ||
206 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) | 141 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) |
207 | #define RCUTORTURE_RUNNABLE_INIT 1 | 142 | #define RCUTORTURE_RUNNABLE_INIT 1 |
@@ -232,7 +167,6 @@ static u64 notrace rcu_trace_clock_local(void) | |||
232 | } | 167 | } |
233 | #endif /* #else #ifdef CONFIG_RCU_TRACE */ | 168 | #endif /* #else #ifdef CONFIG_RCU_TRACE */ |
234 | 169 | ||
235 | static unsigned long shutdown_time; /* jiffies to system shutdown. */ | ||
236 | static unsigned long boost_starttime; /* jiffies of next boost test start. */ | 170 | static unsigned long boost_starttime; /* jiffies of next boost test start. */ |
237 | DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ | 171 | DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ |
238 | /* and boost task create/destroy. */ | 172 | /* and boost task create/destroy. */ |
@@ -242,51 +176,6 @@ static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */ | |||
242 | static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */ | 176 | static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */ |
243 | static DECLARE_WAIT_QUEUE_HEAD(barrier_wq); | 177 | static DECLARE_WAIT_QUEUE_HEAD(barrier_wq); |
244 | 178 | ||
245 | /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */ | ||
246 | |||
247 | #define FULLSTOP_DONTSTOP 0 /* Normal operation. */ | ||
248 | #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */ | ||
249 | #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */ | ||
250 | static int fullstop = FULLSTOP_RMMOD; | ||
251 | /* | ||
252 | * Protect fullstop transitions and spawning of kthreads. | ||
253 | */ | ||
254 | static DEFINE_MUTEX(fullstop_mutex); | ||
255 | |||
256 | /* Forward reference. */ | ||
257 | static void rcu_torture_cleanup(void); | ||
258 | |||
259 | /* | ||
260 | * Detect and respond to a system shutdown. | ||
261 | */ | ||
262 | static int | ||
263 | rcutorture_shutdown_notify(struct notifier_block *unused1, | ||
264 | unsigned long unused2, void *unused3) | ||
265 | { | ||
266 | mutex_lock(&fullstop_mutex); | ||
267 | if (fullstop == FULLSTOP_DONTSTOP) | ||
268 | fullstop = FULLSTOP_SHUTDOWN; | ||
269 | else | ||
270 | pr_warn(/* but going down anyway, so... */ | ||
271 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); | ||
272 | mutex_unlock(&fullstop_mutex); | ||
273 | return NOTIFY_DONE; | ||
274 | } | ||
275 | |||
276 | /* | ||
277 | * Absorb kthreads into a kernel function that won't return, so that | ||
278 | * they won't ever access module text or data again. | ||
279 | */ | ||
280 | static void rcutorture_shutdown_absorb(const char *title) | ||
281 | { | ||
282 | if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { | ||
283 | pr_notice( | ||
284 | "rcutorture thread %s parking due to system shutdown\n", | ||
285 | title); | ||
286 | schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); | ||
287 | } | ||
288 | } | ||
289 | |||
290 | /* | 179 | /* |
291 | * Allocate an element from the rcu_tortures pool. | 180 | * Allocate an element from the rcu_tortures pool. |
292 | */ | 181 | */ |
@@ -320,44 +209,6 @@ rcu_torture_free(struct rcu_torture *p) | |||
320 | spin_unlock_bh(&rcu_torture_lock); | 209 | spin_unlock_bh(&rcu_torture_lock); |
321 | } | 210 | } |
322 | 211 | ||
323 | struct rcu_random_state { | ||
324 | unsigned long rrs_state; | ||
325 | long rrs_count; | ||
326 | }; | ||
327 | |||
328 | #define RCU_RANDOM_MULT 39916801 /* prime */ | ||
329 | #define RCU_RANDOM_ADD 479001701 /* prime */ | ||
330 | #define RCU_RANDOM_REFRESH 10000 | ||
331 | |||
332 | #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 } | ||
333 | |||
334 | /* | ||
335 | * Crude but fast random-number generator. Uses a linear congruential | ||
336 | * generator, with occasional help from cpu_clock(). | ||
337 | */ | ||
338 | static unsigned long | ||
339 | rcu_random(struct rcu_random_state *rrsp) | ||
340 | { | ||
341 | if (--rrsp->rrs_count < 0) { | ||
342 | rrsp->rrs_state += (unsigned long)local_clock(); | ||
343 | rrsp->rrs_count = RCU_RANDOM_REFRESH; | ||
344 | } | ||
345 | rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD; | ||
346 | return swahw32(rrsp->rrs_state); | ||
347 | } | ||
348 | |||
349 | static void | ||
350 | rcu_stutter_wait(const char *title) | ||
351 | { | ||
352 | while (stutter_pause_test || !rcutorture_runnable) { | ||
353 | if (rcutorture_runnable) | ||
354 | schedule_timeout_interruptible(1); | ||
355 | else | ||
356 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); | ||
357 | rcutorture_shutdown_absorb(title); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | /* | 212 | /* |
362 | * Operations vector for selecting different types of tests. | 213 | * Operations vector for selecting different types of tests. |
363 | */ | 214 | */ |
@@ -365,7 +216,7 @@ rcu_stutter_wait(const char *title) | |||
365 | struct rcu_torture_ops { | 216 | struct rcu_torture_ops { |
366 | void (*init)(void); | 217 | void (*init)(void); |
367 | int (*readlock)(void); | 218 | int (*readlock)(void); |
368 | void (*read_delay)(struct rcu_random_state *rrsp); | 219 | void (*read_delay)(struct torture_random_state *rrsp); |
369 | void (*readunlock)(int idx); | 220 | void (*readunlock)(int idx); |
370 | int (*completed)(void); | 221 | int (*completed)(void); |
371 | void (*deferred_free)(struct rcu_torture *p); | 222 | void (*deferred_free)(struct rcu_torture *p); |
@@ -392,7 +243,7 @@ static int rcu_torture_read_lock(void) __acquires(RCU) | |||
392 | return 0; | 243 | return 0; |
393 | } | 244 | } |
394 | 245 | ||
395 | static void rcu_read_delay(struct rcu_random_state *rrsp) | 246 | static void rcu_read_delay(struct torture_random_state *rrsp) |
396 | { | 247 | { |
397 | const unsigned long shortdelay_us = 200; | 248 | const unsigned long shortdelay_us = 200; |
398 | const unsigned long longdelay_ms = 50; | 249 | const unsigned long longdelay_ms = 50; |
@@ -401,12 +252,13 @@ static void rcu_read_delay(struct rcu_random_state *rrsp) | |||
401 | * period, and we want a long delay occasionally to trigger | 252 | * period, and we want a long delay occasionally to trigger |
402 | * force_quiescent_state. */ | 253 | * force_quiescent_state. */ |
403 | 254 | ||
404 | if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) | 255 | if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) |
405 | mdelay(longdelay_ms); | 256 | mdelay(longdelay_ms); |
406 | if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) | 257 | if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) |
407 | udelay(shortdelay_us); | 258 | udelay(shortdelay_us); |
408 | #ifdef CONFIG_PREEMPT | 259 | #ifdef CONFIG_PREEMPT |
409 | if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000))) | 260 | if (!preempt_count() && |
261 | !(torture_random(rrsp) % (nrealreaders * 20000))) | ||
410 | preempt_schedule(); /* No QS if preempt_disable() in effect */ | 262 | preempt_schedule(); /* No QS if preempt_disable() in effect */ |
411 | #endif | 263 | #endif |
412 | } | 264 | } |
@@ -427,7 +279,7 @@ rcu_torture_cb(struct rcu_head *p) | |||
427 | int i; | 279 | int i; |
428 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); | 280 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); |
429 | 281 | ||
430 | if (fullstop != FULLSTOP_DONTSTOP) { | 282 | if (torture_must_stop_irq()) { |
431 | /* Test is ending, just drop callbacks on the floor. */ | 283 | /* Test is ending, just drop callbacks on the floor. */ |
432 | /* The next initialization will pick up the pieces. */ | 284 | /* The next initialization will pick up the pieces. */ |
433 | return; | 285 | return; |
@@ -520,6 +372,48 @@ static struct rcu_torture_ops rcu_bh_ops = { | |||
520 | }; | 372 | }; |
521 | 373 | ||
522 | /* | 374 | /* |
375 | * Don't even think about trying any of these in real life!!! | ||
376 | * The names includes "busted", and they really means it! | ||
377 | * The only purpose of these functions is to provide a buggy RCU | ||
378 | * implementation to make sure that rcutorture correctly emits | ||
379 | * buggy-RCU error messages. | ||
380 | */ | ||
381 | static void rcu_busted_torture_deferred_free(struct rcu_torture *p) | ||
382 | { | ||
383 | /* This is a deliberate bug for testing purposes only! */ | ||
384 | rcu_torture_cb(&p->rtort_rcu); | ||
385 | } | ||
386 | |||
387 | static void synchronize_rcu_busted(void) | ||
388 | { | ||
389 | /* This is a deliberate bug for testing purposes only! */ | ||
390 | } | ||
391 | |||
392 | static void | ||
393 | call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
394 | { | ||
395 | /* This is a deliberate bug for testing purposes only! */ | ||
396 | func(head); | ||
397 | } | ||
398 | |||
399 | static struct rcu_torture_ops rcu_busted_ops = { | ||
400 | .init = rcu_sync_torture_init, | ||
401 | .readlock = rcu_torture_read_lock, | ||
402 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | ||
403 | .readunlock = rcu_torture_read_unlock, | ||
404 | .completed = rcu_no_completed, | ||
405 | .deferred_free = rcu_busted_torture_deferred_free, | ||
406 | .sync = synchronize_rcu_busted, | ||
407 | .exp_sync = synchronize_rcu_busted, | ||
408 | .call = call_rcu_busted, | ||
409 | .cb_barrier = NULL, | ||
410 | .fqs = NULL, | ||
411 | .stats = NULL, | ||
412 | .irq_capable = 1, | ||
413 | .name = "rcu_busted" | ||
414 | }; | ||
415 | |||
416 | /* | ||
523 | * Definitions for srcu torture testing. | 417 | * Definitions for srcu torture testing. |
524 | */ | 418 | */ |
525 | 419 | ||
@@ -530,7 +424,7 @@ static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) | |||
530 | return srcu_read_lock(&srcu_ctl); | 424 | return srcu_read_lock(&srcu_ctl); |
531 | } | 425 | } |
532 | 426 | ||
533 | static void srcu_read_delay(struct rcu_random_state *rrsp) | 427 | static void srcu_read_delay(struct torture_random_state *rrsp) |
534 | { | 428 | { |
535 | long delay; | 429 | long delay; |
536 | const long uspertick = 1000000 / HZ; | 430 | const long uspertick = 1000000 / HZ; |
@@ -538,7 +432,8 @@ static void srcu_read_delay(struct rcu_random_state *rrsp) | |||
538 | 432 | ||
539 | /* We want there to be long-running readers, but not all the time. */ | 433 | /* We want there to be long-running readers, but not all the time. */ |
540 | 434 | ||
541 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); | 435 | delay = torture_random(rrsp) % |
436 | (nrealreaders * 2 * longdelay * uspertick); | ||
542 | if (!delay) | 437 | if (!delay) |
543 | schedule_timeout_interruptible(longdelay); | 438 | schedule_timeout_interruptible(longdelay); |
544 | else | 439 | else |
@@ -677,12 +572,12 @@ static int rcu_torture_boost(void *arg) | |||
677 | struct rcu_boost_inflight rbi = { .inflight = 0 }; | 572 | struct rcu_boost_inflight rbi = { .inflight = 0 }; |
678 | struct sched_param sp; | 573 | struct sched_param sp; |
679 | 574 | ||
680 | VERBOSE_PRINTK_STRING("rcu_torture_boost started"); | 575 | VERBOSE_TOROUT_STRING("rcu_torture_boost started"); |
681 | 576 | ||
682 | /* Set real-time priority. */ | 577 | /* Set real-time priority. */ |
683 | sp.sched_priority = 1; | 578 | sp.sched_priority = 1; |
684 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { | 579 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { |
685 | VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!"); | 580 | VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!"); |
686 | n_rcu_torture_boost_rterror++; | 581 | n_rcu_torture_boost_rterror++; |
687 | } | 582 | } |
688 | 583 | ||
@@ -693,9 +588,8 @@ static int rcu_torture_boost(void *arg) | |||
693 | oldstarttime = boost_starttime; | 588 | oldstarttime = boost_starttime; |
694 | while (ULONG_CMP_LT(jiffies, oldstarttime)) { | 589 | while (ULONG_CMP_LT(jiffies, oldstarttime)) { |
695 | schedule_timeout_interruptible(oldstarttime - jiffies); | 590 | schedule_timeout_interruptible(oldstarttime - jiffies); |
696 | rcu_stutter_wait("rcu_torture_boost"); | 591 | stutter_wait("rcu_torture_boost"); |
697 | if (kthread_should_stop() || | 592 | if (torture_must_stop()) |
698 | fullstop != FULLSTOP_DONTSTOP) | ||
699 | goto checkwait; | 593 | goto checkwait; |
700 | } | 594 | } |
701 | 595 | ||
@@ -710,15 +604,14 @@ static int rcu_torture_boost(void *arg) | |||
710 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); | 604 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); |
711 | if (jiffies - call_rcu_time > | 605 | if (jiffies - call_rcu_time > |
712 | test_boost_duration * HZ - HZ / 2) { | 606 | test_boost_duration * HZ - HZ / 2) { |
713 | VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed"); | 607 | VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed"); |
714 | n_rcu_torture_boost_failure++; | 608 | n_rcu_torture_boost_failure++; |
715 | } | 609 | } |
716 | call_rcu_time = jiffies; | 610 | call_rcu_time = jiffies; |
717 | } | 611 | } |
718 | cond_resched(); | 612 | cond_resched(); |
719 | rcu_stutter_wait("rcu_torture_boost"); | 613 | stutter_wait("rcu_torture_boost"); |
720 | if (kthread_should_stop() || | 614 | if (torture_must_stop()) |
721 | fullstop != FULLSTOP_DONTSTOP) | ||
722 | goto checkwait; | 615 | goto checkwait; |
723 | } | 616 | } |
724 | 617 | ||
@@ -742,16 +635,17 @@ static int rcu_torture_boost(void *arg) | |||
742 | } | 635 | } |
743 | 636 | ||
744 | /* Go do the stutter. */ | 637 | /* Go do the stutter. */ |
745 | checkwait: rcu_stutter_wait("rcu_torture_boost"); | 638 | checkwait: stutter_wait("rcu_torture_boost"); |
746 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 639 | } while (!torture_must_stop()); |
747 | 640 | ||
748 | /* Clean up and exit. */ | 641 | /* Clean up and exit. */ |
749 | VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping"); | 642 | while (!kthread_should_stop() || rbi.inflight) { |
750 | rcutorture_shutdown_absorb("rcu_torture_boost"); | 643 | torture_shutdown_absorb("rcu_torture_boost"); |
751 | while (!kthread_should_stop() || rbi.inflight) | ||
752 | schedule_timeout_uninterruptible(1); | 644 | schedule_timeout_uninterruptible(1); |
645 | } | ||
753 | smp_mb(); /* order accesses to ->inflight before stack-frame death. */ | 646 | smp_mb(); /* order accesses to ->inflight before stack-frame death. */ |
754 | destroy_rcu_head_on_stack(&rbi.rcu); | 647 | destroy_rcu_head_on_stack(&rbi.rcu); |
648 | torture_kthread_stopping("rcu_torture_boost"); | ||
755 | return 0; | 649 | return 0; |
756 | } | 650 | } |
757 | 651 | ||
@@ -766,7 +660,7 @@ rcu_torture_fqs(void *arg) | |||
766 | unsigned long fqs_resume_time; | 660 | unsigned long fqs_resume_time; |
767 | int fqs_burst_remaining; | 661 | int fqs_burst_remaining; |
768 | 662 | ||
769 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task started"); | 663 | VERBOSE_TOROUT_STRING("rcu_torture_fqs task started"); |
770 | do { | 664 | do { |
771 | fqs_resume_time = jiffies + fqs_stutter * HZ; | 665 | fqs_resume_time = jiffies + fqs_stutter * HZ; |
772 | while (ULONG_CMP_LT(jiffies, fqs_resume_time) && | 666 | while (ULONG_CMP_LT(jiffies, fqs_resume_time) && |
@@ -780,12 +674,9 @@ rcu_torture_fqs(void *arg) | |||
780 | udelay(fqs_holdoff); | 674 | udelay(fqs_holdoff); |
781 | fqs_burst_remaining -= fqs_holdoff; | 675 | fqs_burst_remaining -= fqs_holdoff; |
782 | } | 676 | } |
783 | rcu_stutter_wait("rcu_torture_fqs"); | 677 | stutter_wait("rcu_torture_fqs"); |
784 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 678 | } while (!torture_must_stop()); |
785 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping"); | 679 | torture_kthread_stopping("rcu_torture_fqs"); |
786 | rcutorture_shutdown_absorb("rcu_torture_fqs"); | ||
787 | while (!kthread_should_stop()) | ||
788 | schedule_timeout_uninterruptible(1); | ||
789 | return 0; | 680 | return 0; |
790 | } | 681 | } |
791 | 682 | ||
@@ -802,9 +693,9 @@ rcu_torture_writer(void *arg) | |||
802 | struct rcu_torture *rp; | 693 | struct rcu_torture *rp; |
803 | struct rcu_torture *rp1; | 694 | struct rcu_torture *rp1; |
804 | struct rcu_torture *old_rp; | 695 | struct rcu_torture *old_rp; |
805 | static DEFINE_RCU_RANDOM(rand); | 696 | static DEFINE_TORTURE_RANDOM(rand); |
806 | 697 | ||
807 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); | 698 | VERBOSE_TOROUT_STRING("rcu_torture_writer task started"); |
808 | set_user_nice(current, 19); | 699 | set_user_nice(current, 19); |
809 | 700 | ||
810 | do { | 701 | do { |
@@ -813,7 +704,7 @@ rcu_torture_writer(void *arg) | |||
813 | if (rp == NULL) | 704 | if (rp == NULL) |
814 | continue; | 705 | continue; |
815 | rp->rtort_pipe_count = 0; | 706 | rp->rtort_pipe_count = 0; |
816 | udelay(rcu_random(&rand) & 0x3ff); | 707 | udelay(torture_random(&rand) & 0x3ff); |
817 | old_rp = rcu_dereference_check(rcu_torture_current, | 708 | old_rp = rcu_dereference_check(rcu_torture_current, |
818 | current == writer_task); | 709 | current == writer_task); |
819 | rp->rtort_mbtest = 1; | 710 | rp->rtort_mbtest = 1; |
@@ -826,7 +717,7 @@ rcu_torture_writer(void *arg) | |||
826 | atomic_inc(&rcu_torture_wcount[i]); | 717 | atomic_inc(&rcu_torture_wcount[i]); |
827 | old_rp->rtort_pipe_count++; | 718 | old_rp->rtort_pipe_count++; |
828 | if (gp_normal == gp_exp) | 719 | if (gp_normal == gp_exp) |
829 | exp = !!(rcu_random(&rand) & 0x80); | 720 | exp = !!(torture_random(&rand) & 0x80); |
830 | else | 721 | else |
831 | exp = gp_exp; | 722 | exp = gp_exp; |
832 | if (!exp) { | 723 | if (!exp) { |
@@ -852,12 +743,9 @@ rcu_torture_writer(void *arg) | |||
852 | } | 743 | } |
853 | } | 744 | } |
854 | rcutorture_record_progress(++rcu_torture_current_version); | 745 | rcutorture_record_progress(++rcu_torture_current_version); |
855 | rcu_stutter_wait("rcu_torture_writer"); | 746 | stutter_wait("rcu_torture_writer"); |
856 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 747 | } while (!torture_must_stop()); |
857 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); | 748 | torture_kthread_stopping("rcu_torture_writer"); |
858 | rcutorture_shutdown_absorb("rcu_torture_writer"); | ||
859 | while (!kthread_should_stop()) | ||
860 | schedule_timeout_uninterruptible(1); | ||
861 | return 0; | 749 | return 0; |
862 | } | 750 | } |
863 | 751 | ||
@@ -868,19 +756,19 @@ rcu_torture_writer(void *arg) | |||
868 | static int | 756 | static int |
869 | rcu_torture_fakewriter(void *arg) | 757 | rcu_torture_fakewriter(void *arg) |
870 | { | 758 | { |
871 | DEFINE_RCU_RANDOM(rand); | 759 | DEFINE_TORTURE_RANDOM(rand); |
872 | 760 | ||
873 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); | 761 | VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started"); |
874 | set_user_nice(current, 19); | 762 | set_user_nice(current, 19); |
875 | 763 | ||
876 | do { | 764 | do { |
877 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); | 765 | schedule_timeout_uninterruptible(1 + torture_random(&rand)%10); |
878 | udelay(rcu_random(&rand) & 0x3ff); | 766 | udelay(torture_random(&rand) & 0x3ff); |
879 | if (cur_ops->cb_barrier != NULL && | 767 | if (cur_ops->cb_barrier != NULL && |
880 | rcu_random(&rand) % (nfakewriters * 8) == 0) { | 768 | torture_random(&rand) % (nfakewriters * 8) == 0) { |
881 | cur_ops->cb_barrier(); | 769 | cur_ops->cb_barrier(); |
882 | } else if (gp_normal == gp_exp) { | 770 | } else if (gp_normal == gp_exp) { |
883 | if (rcu_random(&rand) & 0x80) | 771 | if (torture_random(&rand) & 0x80) |
884 | cur_ops->sync(); | 772 | cur_ops->sync(); |
885 | else | 773 | else |
886 | cur_ops->exp_sync(); | 774 | cur_ops->exp_sync(); |
@@ -889,13 +777,10 @@ rcu_torture_fakewriter(void *arg) | |||
889 | } else { | 777 | } else { |
890 | cur_ops->exp_sync(); | 778 | cur_ops->exp_sync(); |
891 | } | 779 | } |
892 | rcu_stutter_wait("rcu_torture_fakewriter"); | 780 | stutter_wait("rcu_torture_fakewriter"); |
893 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 781 | } while (!torture_must_stop()); |
894 | 782 | ||
895 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); | 783 | torture_kthread_stopping("rcu_torture_fakewriter"); |
896 | rcutorture_shutdown_absorb("rcu_torture_fakewriter"); | ||
897 | while (!kthread_should_stop()) | ||
898 | schedule_timeout_uninterruptible(1); | ||
899 | return 0; | 784 | return 0; |
900 | } | 785 | } |
901 | 786 | ||
@@ -921,7 +806,7 @@ static void rcu_torture_timer(unsigned long unused) | |||
921 | int idx; | 806 | int idx; |
922 | int completed; | 807 | int completed; |
923 | int completed_end; | 808 | int completed_end; |
924 | static DEFINE_RCU_RANDOM(rand); | 809 | static DEFINE_TORTURE_RANDOM(rand); |
925 | static DEFINE_SPINLOCK(rand_lock); | 810 | static DEFINE_SPINLOCK(rand_lock); |
926 | struct rcu_torture *p; | 811 | struct rcu_torture *p; |
927 | int pipe_count; | 812 | int pipe_count; |
@@ -980,13 +865,13 @@ rcu_torture_reader(void *arg) | |||
980 | int completed; | 865 | int completed; |
981 | int completed_end; | 866 | int completed_end; |
982 | int idx; | 867 | int idx; |
983 | DEFINE_RCU_RANDOM(rand); | 868 | DEFINE_TORTURE_RANDOM(rand); |
984 | struct rcu_torture *p; | 869 | struct rcu_torture *p; |
985 | int pipe_count; | 870 | int pipe_count; |
986 | struct timer_list t; | 871 | struct timer_list t; |
987 | unsigned long long ts; | 872 | unsigned long long ts; |
988 | 873 | ||
989 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | 874 | VERBOSE_TOROUT_STRING("rcu_torture_reader task started"); |
990 | set_user_nice(current, 19); | 875 | set_user_nice(current, 19); |
991 | if (irqreader && cur_ops->irq_capable) | 876 | if (irqreader && cur_ops->irq_capable) |
992 | setup_timer_on_stack(&t, rcu_torture_timer, 0); | 877 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
@@ -1034,14 +919,11 @@ rcu_torture_reader(void *arg) | |||
1034 | preempt_enable(); | 919 | preempt_enable(); |
1035 | cur_ops->readunlock(idx); | 920 | cur_ops->readunlock(idx); |
1036 | schedule(); | 921 | schedule(); |
1037 | rcu_stutter_wait("rcu_torture_reader"); | 922 | stutter_wait("rcu_torture_reader"); |
1038 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 923 | } while (!torture_must_stop()); |
1039 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); | ||
1040 | rcutorture_shutdown_absorb("rcu_torture_reader"); | ||
1041 | if (irqreader && cur_ops->irq_capable) | 924 | if (irqreader && cur_ops->irq_capable) |
1042 | del_timer_sync(&t); | 925 | del_timer_sync(&t); |
1043 | while (!kthread_should_stop()) | 926 | torture_kthread_stopping("rcu_torture_reader"); |
1044 | schedule_timeout_uninterruptible(1); | ||
1045 | return 0; | 927 | return 0; |
1046 | } | 928 | } |
1047 | 929 | ||
@@ -1083,13 +965,7 @@ rcu_torture_printk(char *page) | |||
1083 | n_rcu_torture_boost_failure, | 965 | n_rcu_torture_boost_failure, |
1084 | n_rcu_torture_boosts, | 966 | n_rcu_torture_boosts, |
1085 | n_rcu_torture_timers); | 967 | n_rcu_torture_timers); |
1086 | page += sprintf(page, | 968 | page = torture_onoff_stats(page); |
1087 | "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ", | ||
1088 | n_online_successes, n_online_attempts, | ||
1089 | n_offline_successes, n_offline_attempts, | ||
1090 | min_online, max_online, | ||
1091 | min_offline, max_offline, | ||
1092 | sum_online, sum_offline, HZ); | ||
1093 | page += sprintf(page, "barrier: %ld/%ld:%ld", | 969 | page += sprintf(page, "barrier: %ld/%ld:%ld", |
1094 | n_barrier_successes, | 970 | n_barrier_successes, |
1095 | n_barrier_attempts, | 971 | n_barrier_attempts, |
@@ -1150,123 +1026,17 @@ rcu_torture_stats_print(void) | |||
1150 | /* | 1026 | /* |
1151 | * Periodically prints torture statistics, if periodic statistics printing | 1027 | * Periodically prints torture statistics, if periodic statistics printing |
1152 | * was specified via the stat_interval module parameter. | 1028 | * was specified via the stat_interval module parameter. |
1153 | * | ||
1154 | * No need to worry about fullstop here, since this one doesn't reference | ||
1155 | * volatile state or register callbacks. | ||
1156 | */ | 1029 | */ |
1157 | static int | 1030 | static int |
1158 | rcu_torture_stats(void *arg) | 1031 | rcu_torture_stats(void *arg) |
1159 | { | 1032 | { |
1160 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); | 1033 | VERBOSE_TOROUT_STRING("rcu_torture_stats task started"); |
1161 | do { | 1034 | do { |
1162 | schedule_timeout_interruptible(stat_interval * HZ); | 1035 | schedule_timeout_interruptible(stat_interval * HZ); |
1163 | rcu_torture_stats_print(); | 1036 | rcu_torture_stats_print(); |
1164 | rcutorture_shutdown_absorb("rcu_torture_stats"); | 1037 | torture_shutdown_absorb("rcu_torture_stats"); |
1165 | } while (!kthread_should_stop()); | 1038 | } while (!torture_must_stop()); |
1166 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); | 1039 | torture_kthread_stopping("rcu_torture_stats"); |
1167 | return 0; | ||
1168 | } | ||
1169 | |||
1170 | static int rcu_idle_cpu; /* Force all torture tasks off this CPU */ | ||
1171 | |||
1172 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case | ||
1173 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. | ||
1174 | */ | ||
1175 | static void rcu_torture_shuffle_tasks(void) | ||
1176 | { | ||
1177 | int i; | ||
1178 | |||
1179 | cpumask_setall(shuffle_tmp_mask); | ||
1180 | get_online_cpus(); | ||
1181 | |||
1182 | /* No point in shuffling if there is only one online CPU (ex: UP) */ | ||
1183 | if (num_online_cpus() == 1) { | ||
1184 | put_online_cpus(); | ||
1185 | return; | ||
1186 | } | ||
1187 | |||
1188 | if (rcu_idle_cpu != -1) | ||
1189 | cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask); | ||
1190 | |||
1191 | set_cpus_allowed_ptr(current, shuffle_tmp_mask); | ||
1192 | |||
1193 | if (reader_tasks) { | ||
1194 | for (i = 0; i < nrealreaders; i++) | ||
1195 | if (reader_tasks[i]) | ||
1196 | set_cpus_allowed_ptr(reader_tasks[i], | ||
1197 | shuffle_tmp_mask); | ||
1198 | } | ||
1199 | if (fakewriter_tasks) { | ||
1200 | for (i = 0; i < nfakewriters; i++) | ||
1201 | if (fakewriter_tasks[i]) | ||
1202 | set_cpus_allowed_ptr(fakewriter_tasks[i], | ||
1203 | shuffle_tmp_mask); | ||
1204 | } | ||
1205 | if (writer_task) | ||
1206 | set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask); | ||
1207 | if (stats_task) | ||
1208 | set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask); | ||
1209 | if (stutter_task) | ||
1210 | set_cpus_allowed_ptr(stutter_task, shuffle_tmp_mask); | ||
1211 | if (fqs_task) | ||
1212 | set_cpus_allowed_ptr(fqs_task, shuffle_tmp_mask); | ||
1213 | if (shutdown_task) | ||
1214 | set_cpus_allowed_ptr(shutdown_task, shuffle_tmp_mask); | ||
1215 | #ifdef CONFIG_HOTPLUG_CPU | ||
1216 | if (onoff_task) | ||
1217 | set_cpus_allowed_ptr(onoff_task, shuffle_tmp_mask); | ||
1218 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
1219 | if (stall_task) | ||
1220 | set_cpus_allowed_ptr(stall_task, shuffle_tmp_mask); | ||
1221 | if (barrier_cbs_tasks) | ||
1222 | for (i = 0; i < n_barrier_cbs; i++) | ||
1223 | if (barrier_cbs_tasks[i]) | ||
1224 | set_cpus_allowed_ptr(barrier_cbs_tasks[i], | ||
1225 | shuffle_tmp_mask); | ||
1226 | if (barrier_task) | ||
1227 | set_cpus_allowed_ptr(barrier_task, shuffle_tmp_mask); | ||
1228 | |||
1229 | if (rcu_idle_cpu == -1) | ||
1230 | rcu_idle_cpu = num_online_cpus() - 1; | ||
1231 | else | ||
1232 | rcu_idle_cpu--; | ||
1233 | |||
1234 | put_online_cpus(); | ||
1235 | } | ||
1236 | |||
1237 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the | ||
1238 | * system to become idle at a time and cut off its timer ticks. This is meant | ||
1239 | * to test the support for such tickless idle CPU in RCU. | ||
1240 | */ | ||
1241 | static int | ||
1242 | rcu_torture_shuffle(void *arg) | ||
1243 | { | ||
1244 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); | ||
1245 | do { | ||
1246 | schedule_timeout_interruptible(shuffle_interval * HZ); | ||
1247 | rcu_torture_shuffle_tasks(); | ||
1248 | rcutorture_shutdown_absorb("rcu_torture_shuffle"); | ||
1249 | } while (!kthread_should_stop()); | ||
1250 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); | ||
1251 | return 0; | ||
1252 | } | ||
1253 | |||
1254 | /* Cause the rcutorture test to "stutter", starting and stopping all | ||
1255 | * threads periodically. | ||
1256 | */ | ||
1257 | static int | ||
1258 | rcu_torture_stutter(void *arg) | ||
1259 | { | ||
1260 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task started"); | ||
1261 | do { | ||
1262 | schedule_timeout_interruptible(stutter * HZ); | ||
1263 | stutter_pause_test = 1; | ||
1264 | if (!kthread_should_stop()) | ||
1265 | schedule_timeout_interruptible(stutter * HZ); | ||
1266 | stutter_pause_test = 0; | ||
1267 | rcutorture_shutdown_absorb("rcu_torture_stutter"); | ||
1268 | } while (!kthread_should_stop()); | ||
1269 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping"); | ||
1270 | return 0; | 1040 | return 0; |
1271 | } | 1041 | } |
1272 | 1042 | ||
@@ -1293,10 +1063,6 @@ rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag) | |||
1293 | onoff_interval, onoff_holdoff); | 1063 | onoff_interval, onoff_holdoff); |
1294 | } | 1064 | } |
1295 | 1065 | ||
1296 | static struct notifier_block rcutorture_shutdown_nb = { | ||
1297 | .notifier_call = rcutorture_shutdown_notify, | ||
1298 | }; | ||
1299 | |||
1300 | static void rcutorture_booster_cleanup(int cpu) | 1066 | static void rcutorture_booster_cleanup(int cpu) |
1301 | { | 1067 | { |
1302 | struct task_struct *t; | 1068 | struct task_struct *t; |
@@ -1304,14 +1070,12 @@ static void rcutorture_booster_cleanup(int cpu) | |||
1304 | if (boost_tasks[cpu] == NULL) | 1070 | if (boost_tasks[cpu] == NULL) |
1305 | return; | 1071 | return; |
1306 | mutex_lock(&boost_mutex); | 1072 | mutex_lock(&boost_mutex); |
1307 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task"); | ||
1308 | t = boost_tasks[cpu]; | 1073 | t = boost_tasks[cpu]; |
1309 | boost_tasks[cpu] = NULL; | 1074 | boost_tasks[cpu] = NULL; |
1310 | mutex_unlock(&boost_mutex); | 1075 | mutex_unlock(&boost_mutex); |
1311 | 1076 | ||
1312 | /* This must be outside of the mutex, otherwise deadlock! */ | 1077 | /* This must be outside of the mutex, otherwise deadlock! */ |
1313 | kthread_stop(t); | 1078 | torture_stop_kthread(rcu_torture_boost, t); |
1314 | boost_tasks[cpu] = NULL; | ||
1315 | } | 1079 | } |
1316 | 1080 | ||
1317 | static int rcutorture_booster_init(int cpu) | 1081 | static int rcutorture_booster_init(int cpu) |
@@ -1323,13 +1087,13 @@ static int rcutorture_booster_init(int cpu) | |||
1323 | 1087 | ||
1324 | /* Don't allow time recalculation while creating a new task. */ | 1088 | /* Don't allow time recalculation while creating a new task. */ |
1325 | mutex_lock(&boost_mutex); | 1089 | mutex_lock(&boost_mutex); |
1326 | VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task"); | 1090 | VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task"); |
1327 | boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, | 1091 | boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, |
1328 | cpu_to_node(cpu), | 1092 | cpu_to_node(cpu), |
1329 | "rcu_torture_boost"); | 1093 | "rcu_torture_boost"); |
1330 | if (IS_ERR(boost_tasks[cpu])) { | 1094 | if (IS_ERR(boost_tasks[cpu])) { |
1331 | retval = PTR_ERR(boost_tasks[cpu]); | 1095 | retval = PTR_ERR(boost_tasks[cpu]); |
1332 | VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed"); | 1096 | VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed"); |
1333 | n_rcu_torture_boost_ktrerror++; | 1097 | n_rcu_torture_boost_ktrerror++; |
1334 | boost_tasks[cpu] = NULL; | 1098 | boost_tasks[cpu] = NULL; |
1335 | mutex_unlock(&boost_mutex); | 1099 | mutex_unlock(&boost_mutex); |
@@ -1342,175 +1106,6 @@ static int rcutorture_booster_init(int cpu) | |||
1342 | } | 1106 | } |
1343 | 1107 | ||
1344 | /* | 1108 | /* |
1345 | * Cause the rcutorture test to shutdown the system after the test has | ||
1346 | * run for the time specified by the shutdown_secs module parameter. | ||
1347 | */ | ||
1348 | static int | ||
1349 | rcu_torture_shutdown(void *arg) | ||
1350 | { | ||
1351 | long delta; | ||
1352 | unsigned long jiffies_snap; | ||
1353 | |||
1354 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started"); | ||
1355 | jiffies_snap = ACCESS_ONCE(jiffies); | ||
1356 | while (ULONG_CMP_LT(jiffies_snap, shutdown_time) && | ||
1357 | !kthread_should_stop()) { | ||
1358 | delta = shutdown_time - jiffies_snap; | ||
1359 | if (verbose) | ||
1360 | pr_alert("%s" TORTURE_FLAG | ||
1361 | "rcu_torture_shutdown task: %lu jiffies remaining\n", | ||
1362 | torture_type, delta); | ||
1363 | schedule_timeout_interruptible(delta); | ||
1364 | jiffies_snap = ACCESS_ONCE(jiffies); | ||
1365 | } | ||
1366 | if (kthread_should_stop()) { | ||
1367 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping"); | ||
1368 | return 0; | ||
1369 | } | ||
1370 | |||
1371 | /* OK, shut down the system. */ | ||
1372 | |||
1373 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system"); | ||
1374 | shutdown_task = NULL; /* Avoid self-kill deadlock. */ | ||
1375 | rcu_torture_cleanup(); /* Get the success/failure message. */ | ||
1376 | kernel_power_off(); /* Shut down the system. */ | ||
1377 | return 0; | ||
1378 | } | ||
1379 | |||
1380 | #ifdef CONFIG_HOTPLUG_CPU | ||
1381 | |||
1382 | /* | ||
1383 | * Execute random CPU-hotplug operations at the interval specified | ||
1384 | * by the onoff_interval. | ||
1385 | */ | ||
1386 | static int | ||
1387 | rcu_torture_onoff(void *arg) | ||
1388 | { | ||
1389 | int cpu; | ||
1390 | unsigned long delta; | ||
1391 | int maxcpu = -1; | ||
1392 | DEFINE_RCU_RANDOM(rand); | ||
1393 | int ret; | ||
1394 | unsigned long starttime; | ||
1395 | |||
1396 | VERBOSE_PRINTK_STRING("rcu_torture_onoff task started"); | ||
1397 | for_each_online_cpu(cpu) | ||
1398 | maxcpu = cpu; | ||
1399 | WARN_ON(maxcpu < 0); | ||
1400 | if (onoff_holdoff > 0) { | ||
1401 | VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff"); | ||
1402 | schedule_timeout_interruptible(onoff_holdoff * HZ); | ||
1403 | VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff"); | ||
1404 | } | ||
1405 | while (!kthread_should_stop()) { | ||
1406 | cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1); | ||
1407 | if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) { | ||
1408 | if (verbose) | ||
1409 | pr_alert("%s" TORTURE_FLAG | ||
1410 | "rcu_torture_onoff task: offlining %d\n", | ||
1411 | torture_type, cpu); | ||
1412 | starttime = jiffies; | ||
1413 | n_offline_attempts++; | ||
1414 | ret = cpu_down(cpu); | ||
1415 | if (ret) { | ||
1416 | if (verbose) | ||
1417 | pr_alert("%s" TORTURE_FLAG | ||
1418 | "rcu_torture_onoff task: offline %d failed: errno %d\n", | ||
1419 | torture_type, cpu, ret); | ||
1420 | } else { | ||
1421 | if (verbose) | ||
1422 | pr_alert("%s" TORTURE_FLAG | ||
1423 | "rcu_torture_onoff task: offlined %d\n", | ||
1424 | torture_type, cpu); | ||
1425 | n_offline_successes++; | ||
1426 | delta = jiffies - starttime; | ||
1427 | sum_offline += delta; | ||
1428 | if (min_offline < 0) { | ||
1429 | min_offline = delta; | ||
1430 | max_offline = delta; | ||
1431 | } | ||
1432 | if (min_offline > delta) | ||
1433 | min_offline = delta; | ||
1434 | if (max_offline < delta) | ||
1435 | max_offline = delta; | ||
1436 | } | ||
1437 | } else if (cpu_is_hotpluggable(cpu)) { | ||
1438 | if (verbose) | ||
1439 | pr_alert("%s" TORTURE_FLAG | ||
1440 | "rcu_torture_onoff task: onlining %d\n", | ||
1441 | torture_type, cpu); | ||
1442 | starttime = jiffies; | ||
1443 | n_online_attempts++; | ||
1444 | ret = cpu_up(cpu); | ||
1445 | if (ret) { | ||
1446 | if (verbose) | ||
1447 | pr_alert("%s" TORTURE_FLAG | ||
1448 | "rcu_torture_onoff task: online %d failed: errno %d\n", | ||
1449 | torture_type, cpu, ret); | ||
1450 | } else { | ||
1451 | if (verbose) | ||
1452 | pr_alert("%s" TORTURE_FLAG | ||
1453 | "rcu_torture_onoff task: onlined %d\n", | ||
1454 | torture_type, cpu); | ||
1455 | n_online_successes++; | ||
1456 | delta = jiffies - starttime; | ||
1457 | sum_online += delta; | ||
1458 | if (min_online < 0) { | ||
1459 | min_online = delta; | ||
1460 | max_online = delta; | ||
1461 | } | ||
1462 | if (min_online > delta) | ||
1463 | min_online = delta; | ||
1464 | if (max_online < delta) | ||
1465 | max_online = delta; | ||
1466 | } | ||
1467 | } | ||
1468 | schedule_timeout_interruptible(onoff_interval * HZ); | ||
1469 | } | ||
1470 | VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping"); | ||
1471 | return 0; | ||
1472 | } | ||
1473 | |||
1474 | static int | ||
1475 | rcu_torture_onoff_init(void) | ||
1476 | { | ||
1477 | int ret; | ||
1478 | |||
1479 | if (onoff_interval <= 0) | ||
1480 | return 0; | ||
1481 | onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff"); | ||
1482 | if (IS_ERR(onoff_task)) { | ||
1483 | ret = PTR_ERR(onoff_task); | ||
1484 | onoff_task = NULL; | ||
1485 | return ret; | ||
1486 | } | ||
1487 | return 0; | ||
1488 | } | ||
1489 | |||
1490 | static void rcu_torture_onoff_cleanup(void) | ||
1491 | { | ||
1492 | if (onoff_task == NULL) | ||
1493 | return; | ||
1494 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task"); | ||
1495 | kthread_stop(onoff_task); | ||
1496 | onoff_task = NULL; | ||
1497 | } | ||
1498 | |||
1499 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
1500 | |||
1501 | static int | ||
1502 | rcu_torture_onoff_init(void) | ||
1503 | { | ||
1504 | return 0; | ||
1505 | } | ||
1506 | |||
1507 | static void rcu_torture_onoff_cleanup(void) | ||
1508 | { | ||
1509 | } | ||
1510 | |||
1511 | #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */ | ||
1512 | |||
1513 | /* | ||
1514 | * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then | 1109 | * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then |
1515 | * induces a CPU stall for the time specified by stall_cpu. | 1110 | * induces a CPU stall for the time specified by stall_cpu. |
1516 | */ | 1111 | */ |
@@ -1518,11 +1113,11 @@ static int rcu_torture_stall(void *args) | |||
1518 | { | 1113 | { |
1519 | unsigned long stop_at; | 1114 | unsigned long stop_at; |
1520 | 1115 | ||
1521 | VERBOSE_PRINTK_STRING("rcu_torture_stall task started"); | 1116 | VERBOSE_TOROUT_STRING("rcu_torture_stall task started"); |
1522 | if (stall_cpu_holdoff > 0) { | 1117 | if (stall_cpu_holdoff > 0) { |
1523 | VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff"); | 1118 | VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff"); |
1524 | schedule_timeout_interruptible(stall_cpu_holdoff * HZ); | 1119 | schedule_timeout_interruptible(stall_cpu_holdoff * HZ); |
1525 | VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff"); | 1120 | VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff"); |
1526 | } | 1121 | } |
1527 | if (!kthread_should_stop()) { | 1122 | if (!kthread_should_stop()) { |
1528 | stop_at = get_seconds() + stall_cpu; | 1123 | stop_at = get_seconds() + stall_cpu; |
@@ -1536,7 +1131,7 @@ static int rcu_torture_stall(void *args) | |||
1536 | rcu_read_unlock(); | 1131 | rcu_read_unlock(); |
1537 | pr_alert("rcu_torture_stall end.\n"); | 1132 | pr_alert("rcu_torture_stall end.\n"); |
1538 | } | 1133 | } |
1539 | rcutorture_shutdown_absorb("rcu_torture_stall"); | 1134 | torture_shutdown_absorb("rcu_torture_stall"); |
1540 | while (!kthread_should_stop()) | 1135 | while (!kthread_should_stop()) |
1541 | schedule_timeout_interruptible(10 * HZ); | 1136 | schedule_timeout_interruptible(10 * HZ); |
1542 | return 0; | 1137 | return 0; |
@@ -1545,27 +1140,9 @@ static int rcu_torture_stall(void *args) | |||
1545 | /* Spawn CPU-stall kthread, if stall_cpu specified. */ | 1140 | /* Spawn CPU-stall kthread, if stall_cpu specified. */ |
1546 | static int __init rcu_torture_stall_init(void) | 1141 | static int __init rcu_torture_stall_init(void) |
1547 | { | 1142 | { |
1548 | int ret; | ||
1549 | |||
1550 | if (stall_cpu <= 0) | 1143 | if (stall_cpu <= 0) |
1551 | return 0; | 1144 | return 0; |
1552 | stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall"); | 1145 | return torture_create_kthread(rcu_torture_stall, NULL, stall_task); |
1553 | if (IS_ERR(stall_task)) { | ||
1554 | ret = PTR_ERR(stall_task); | ||
1555 | stall_task = NULL; | ||
1556 | return ret; | ||
1557 | } | ||
1558 | return 0; | ||
1559 | } | ||
1560 | |||
1561 | /* Clean up after the CPU-stall kthread, if one was spawned. */ | ||
1562 | static void rcu_torture_stall_cleanup(void) | ||
1563 | { | ||
1564 | if (stall_task == NULL) | ||
1565 | return; | ||
1566 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task."); | ||
1567 | kthread_stop(stall_task); | ||
1568 | stall_task = NULL; | ||
1569 | } | 1146 | } |
1570 | 1147 | ||
1571 | /* Callback function for RCU barrier testing. */ | 1148 | /* Callback function for RCU barrier testing. */ |
@@ -1583,28 +1160,24 @@ static int rcu_torture_barrier_cbs(void *arg) | |||
1583 | struct rcu_head rcu; | 1160 | struct rcu_head rcu; |
1584 | 1161 | ||
1585 | init_rcu_head_on_stack(&rcu); | 1162 | init_rcu_head_on_stack(&rcu); |
1586 | VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started"); | 1163 | VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started"); |
1587 | set_user_nice(current, 19); | 1164 | set_user_nice(current, 19); |
1588 | do { | 1165 | do { |
1589 | wait_event(barrier_cbs_wq[myid], | 1166 | wait_event(barrier_cbs_wq[myid], |
1590 | (newphase = | 1167 | (newphase = |
1591 | ACCESS_ONCE(barrier_phase)) != lastphase || | 1168 | ACCESS_ONCE(barrier_phase)) != lastphase || |
1592 | kthread_should_stop() || | 1169 | torture_must_stop()); |
1593 | fullstop != FULLSTOP_DONTSTOP); | ||
1594 | lastphase = newphase; | 1170 | lastphase = newphase; |
1595 | smp_mb(); /* ensure barrier_phase load before ->call(). */ | 1171 | smp_mb(); /* ensure barrier_phase load before ->call(). */ |
1596 | if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP) | 1172 | if (torture_must_stop()) |
1597 | break; | 1173 | break; |
1598 | cur_ops->call(&rcu, rcu_torture_barrier_cbf); | 1174 | cur_ops->call(&rcu, rcu_torture_barrier_cbf); |
1599 | if (atomic_dec_and_test(&barrier_cbs_count)) | 1175 | if (atomic_dec_and_test(&barrier_cbs_count)) |
1600 | wake_up(&barrier_wq); | 1176 | wake_up(&barrier_wq); |
1601 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 1177 | } while (!torture_must_stop()); |
1602 | VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task stopping"); | ||
1603 | rcutorture_shutdown_absorb("rcu_torture_barrier_cbs"); | ||
1604 | while (!kthread_should_stop()) | ||
1605 | schedule_timeout_interruptible(1); | ||
1606 | cur_ops->cb_barrier(); | 1178 | cur_ops->cb_barrier(); |
1607 | destroy_rcu_head_on_stack(&rcu); | 1179 | destroy_rcu_head_on_stack(&rcu); |
1180 | torture_kthread_stopping("rcu_torture_barrier_cbs"); | ||
1608 | return 0; | 1181 | return 0; |
1609 | } | 1182 | } |
1610 | 1183 | ||
@@ -1613,7 +1186,7 @@ static int rcu_torture_barrier(void *arg) | |||
1613 | { | 1186 | { |
1614 | int i; | 1187 | int i; |
1615 | 1188 | ||
1616 | VERBOSE_PRINTK_STRING("rcu_torture_barrier task starting"); | 1189 | VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting"); |
1617 | do { | 1190 | do { |
1618 | atomic_set(&barrier_cbs_invoked, 0); | 1191 | atomic_set(&barrier_cbs_invoked, 0); |
1619 | atomic_set(&barrier_cbs_count, n_barrier_cbs); | 1192 | atomic_set(&barrier_cbs_count, n_barrier_cbs); |
@@ -1623,9 +1196,8 @@ static int rcu_torture_barrier(void *arg) | |||
1623 | wake_up(&barrier_cbs_wq[i]); | 1196 | wake_up(&barrier_cbs_wq[i]); |
1624 | wait_event(barrier_wq, | 1197 | wait_event(barrier_wq, |
1625 | atomic_read(&barrier_cbs_count) == 0 || | 1198 | atomic_read(&barrier_cbs_count) == 0 || |
1626 | kthread_should_stop() || | 1199 | torture_must_stop()); |
1627 | fullstop != FULLSTOP_DONTSTOP); | 1200 | if (torture_must_stop()) |
1628 | if (kthread_should_stop() || fullstop != FULLSTOP_DONTSTOP) | ||
1629 | break; | 1201 | break; |
1630 | n_barrier_attempts++; | 1202 | n_barrier_attempts++; |
1631 | cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */ | 1203 | cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */ |
@@ -1635,11 +1207,8 @@ static int rcu_torture_barrier(void *arg) | |||
1635 | } | 1207 | } |
1636 | n_barrier_successes++; | 1208 | n_barrier_successes++; |
1637 | schedule_timeout_interruptible(HZ / 10); | 1209 | schedule_timeout_interruptible(HZ / 10); |
1638 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 1210 | } while (!torture_must_stop()); |
1639 | VERBOSE_PRINTK_STRING("rcu_torture_barrier task stopping"); | 1211 | torture_kthread_stopping("rcu_torture_barrier"); |
1640 | rcutorture_shutdown_absorb("rcu_torture_barrier"); | ||
1641 | while (!kthread_should_stop()) | ||
1642 | schedule_timeout_interruptible(1); | ||
1643 | return 0; | 1212 | return 0; |
1644 | } | 1213 | } |
1645 | 1214 | ||
@@ -1672,24 +1241,13 @@ static int rcu_torture_barrier_init(void) | |||
1672 | return -ENOMEM; | 1241 | return -ENOMEM; |
1673 | for (i = 0; i < n_barrier_cbs; i++) { | 1242 | for (i = 0; i < n_barrier_cbs; i++) { |
1674 | init_waitqueue_head(&barrier_cbs_wq[i]); | 1243 | init_waitqueue_head(&barrier_cbs_wq[i]); |
1675 | barrier_cbs_tasks[i] = kthread_run(rcu_torture_barrier_cbs, | 1244 | ret = torture_create_kthread(rcu_torture_barrier_cbs, |
1676 | (void *)(long)i, | 1245 | (void *)(long)i, |
1677 | "rcu_torture_barrier_cbs"); | 1246 | barrier_cbs_tasks[i]); |
1678 | if (IS_ERR(barrier_cbs_tasks[i])) { | 1247 | if (ret) |
1679 | ret = PTR_ERR(barrier_cbs_tasks[i]); | ||
1680 | VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier_cbs"); | ||
1681 | barrier_cbs_tasks[i] = NULL; | ||
1682 | return ret; | 1248 | return ret; |
1683 | } | ||
1684 | } | 1249 | } |
1685 | barrier_task = kthread_run(rcu_torture_barrier, NULL, | 1250 | return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task); |
1686 | "rcu_torture_barrier"); | ||
1687 | if (IS_ERR(barrier_task)) { | ||
1688 | ret = PTR_ERR(barrier_task); | ||
1689 | VERBOSE_PRINTK_ERRSTRING("Failed to create rcu_torture_barrier"); | ||
1690 | barrier_task = NULL; | ||
1691 | } | ||
1692 | return 0; | ||
1693 | } | 1251 | } |
1694 | 1252 | ||
1695 | /* Clean up after RCU barrier testing. */ | 1253 | /* Clean up after RCU barrier testing. */ |
@@ -1697,19 +1255,11 @@ static void rcu_torture_barrier_cleanup(void) | |||
1697 | { | 1255 | { |
1698 | int i; | 1256 | int i; |
1699 | 1257 | ||
1700 | if (barrier_task != NULL) { | 1258 | torture_stop_kthread(rcu_torture_barrier, barrier_task); |
1701 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier task"); | ||
1702 | kthread_stop(barrier_task); | ||
1703 | barrier_task = NULL; | ||
1704 | } | ||
1705 | if (barrier_cbs_tasks != NULL) { | 1259 | if (barrier_cbs_tasks != NULL) { |
1706 | for (i = 0; i < n_barrier_cbs; i++) { | 1260 | for (i = 0; i < n_barrier_cbs; i++) |
1707 | if (barrier_cbs_tasks[i] != NULL) { | 1261 | torture_stop_kthread(rcu_torture_barrier_cbs, |
1708 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_barrier_cbs task"); | 1262 | barrier_cbs_tasks[i]); |
1709 | kthread_stop(barrier_cbs_tasks[i]); | ||
1710 | barrier_cbs_tasks[i] = NULL; | ||
1711 | } | ||
1712 | } | ||
1713 | kfree(barrier_cbs_tasks); | 1263 | kfree(barrier_cbs_tasks); |
1714 | barrier_cbs_tasks = NULL; | 1264 | barrier_cbs_tasks = NULL; |
1715 | } | 1265 | } |
@@ -1747,90 +1297,42 @@ rcu_torture_cleanup(void) | |||
1747 | { | 1297 | { |
1748 | int i; | 1298 | int i; |
1749 | 1299 | ||
1750 | mutex_lock(&fullstop_mutex); | ||
1751 | rcutorture_record_test_transition(); | 1300 | rcutorture_record_test_transition(); |
1752 | if (fullstop == FULLSTOP_SHUTDOWN) { | 1301 | if (torture_cleanup()) { |
1753 | pr_warn(/* but going down anyway, so... */ | ||
1754 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); | ||
1755 | mutex_unlock(&fullstop_mutex); | ||
1756 | schedule_timeout_uninterruptible(10); | ||
1757 | if (cur_ops->cb_barrier != NULL) | 1302 | if (cur_ops->cb_barrier != NULL) |
1758 | cur_ops->cb_barrier(); | 1303 | cur_ops->cb_barrier(); |
1759 | return; | 1304 | return; |
1760 | } | 1305 | } |
1761 | fullstop = FULLSTOP_RMMOD; | ||
1762 | mutex_unlock(&fullstop_mutex); | ||
1763 | unregister_reboot_notifier(&rcutorture_shutdown_nb); | ||
1764 | rcu_torture_barrier_cleanup(); | ||
1765 | rcu_torture_stall_cleanup(); | ||
1766 | if (stutter_task) { | ||
1767 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task"); | ||
1768 | kthread_stop(stutter_task); | ||
1769 | } | ||
1770 | stutter_task = NULL; | ||
1771 | if (shuffler_task) { | ||
1772 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); | ||
1773 | kthread_stop(shuffler_task); | ||
1774 | free_cpumask_var(shuffle_tmp_mask); | ||
1775 | } | ||
1776 | shuffler_task = NULL; | ||
1777 | 1306 | ||
1778 | if (writer_task) { | 1307 | rcu_torture_barrier_cleanup(); |
1779 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); | 1308 | torture_stop_kthread(rcu_torture_stall, stall_task); |
1780 | kthread_stop(writer_task); | 1309 | torture_stop_kthread(rcu_torture_writer, writer_task); |
1781 | } | ||
1782 | writer_task = NULL; | ||
1783 | 1310 | ||
1784 | if (reader_tasks) { | 1311 | if (reader_tasks) { |
1785 | for (i = 0; i < nrealreaders; i++) { | 1312 | for (i = 0; i < nrealreaders; i++) |
1786 | if (reader_tasks[i]) { | 1313 | torture_stop_kthread(rcu_torture_reader, |
1787 | VERBOSE_PRINTK_STRING( | 1314 | reader_tasks[i]); |
1788 | "Stopping rcu_torture_reader task"); | ||
1789 | kthread_stop(reader_tasks[i]); | ||
1790 | } | ||
1791 | reader_tasks[i] = NULL; | ||
1792 | } | ||
1793 | kfree(reader_tasks); | 1315 | kfree(reader_tasks); |
1794 | reader_tasks = NULL; | ||
1795 | } | 1316 | } |
1796 | rcu_torture_current = NULL; | 1317 | rcu_torture_current = NULL; |
1797 | 1318 | ||
1798 | if (fakewriter_tasks) { | 1319 | if (fakewriter_tasks) { |
1799 | for (i = 0; i < nfakewriters; i++) { | 1320 | for (i = 0; i < nfakewriters; i++) { |
1800 | if (fakewriter_tasks[i]) { | 1321 | torture_stop_kthread(rcu_torture_fakewriter, |
1801 | VERBOSE_PRINTK_STRING( | 1322 | fakewriter_tasks[i]); |
1802 | "Stopping rcu_torture_fakewriter task"); | ||
1803 | kthread_stop(fakewriter_tasks[i]); | ||
1804 | } | ||
1805 | fakewriter_tasks[i] = NULL; | ||
1806 | } | 1323 | } |
1807 | kfree(fakewriter_tasks); | 1324 | kfree(fakewriter_tasks); |
1808 | fakewriter_tasks = NULL; | 1325 | fakewriter_tasks = NULL; |
1809 | } | 1326 | } |
1810 | 1327 | ||
1811 | if (stats_task) { | 1328 | torture_stop_kthread(rcu_torture_stats, stats_task); |
1812 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); | 1329 | torture_stop_kthread(rcu_torture_fqs, fqs_task); |
1813 | kthread_stop(stats_task); | ||
1814 | } | ||
1815 | stats_task = NULL; | ||
1816 | |||
1817 | if (fqs_task) { | ||
1818 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task"); | ||
1819 | kthread_stop(fqs_task); | ||
1820 | } | ||
1821 | fqs_task = NULL; | ||
1822 | if ((test_boost == 1 && cur_ops->can_boost) || | 1330 | if ((test_boost == 1 && cur_ops->can_boost) || |
1823 | test_boost == 2) { | 1331 | test_boost == 2) { |
1824 | unregister_cpu_notifier(&rcutorture_cpu_nb); | 1332 | unregister_cpu_notifier(&rcutorture_cpu_nb); |
1825 | for_each_possible_cpu(i) | 1333 | for_each_possible_cpu(i) |
1826 | rcutorture_booster_cleanup(i); | 1334 | rcutorture_booster_cleanup(i); |
1827 | } | 1335 | } |
1828 | if (shutdown_task != NULL) { | ||
1829 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task"); | ||
1830 | kthread_stop(shutdown_task); | ||
1831 | } | ||
1832 | shutdown_task = NULL; | ||
1833 | rcu_torture_onoff_cleanup(); | ||
1834 | 1336 | ||
1835 | /* Wait for all RCU callbacks to fire. */ | 1337 | /* Wait for all RCU callbacks to fire. */ |
1836 | 1338 | ||
@@ -1841,8 +1343,7 @@ rcu_torture_cleanup(void) | |||
1841 | 1343 | ||
1842 | if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error) | 1344 | if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error) |
1843 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); | 1345 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); |
1844 | else if (n_online_successes != n_online_attempts || | 1346 | else if (torture_onoff_failures()) |
1845 | n_offline_successes != n_offline_attempts) | ||
1846 | rcu_torture_print_module_parms(cur_ops, | 1347 | rcu_torture_print_module_parms(cur_ops, |
1847 | "End of test: RCU_HOTPLUG"); | 1348 | "End of test: RCU_HOTPLUG"); |
1848 | else | 1349 | else |
@@ -1911,12 +1412,11 @@ rcu_torture_init(void) | |||
1911 | int i; | 1412 | int i; |
1912 | int cpu; | 1413 | int cpu; |
1913 | int firsterr = 0; | 1414 | int firsterr = 0; |
1914 | int retval; | ||
1915 | static struct rcu_torture_ops *torture_ops[] = { | 1415 | static struct rcu_torture_ops *torture_ops[] = { |
1916 | &rcu_ops, &rcu_bh_ops, &srcu_ops, &sched_ops, | 1416 | &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops, |
1917 | }; | 1417 | }; |
1918 | 1418 | ||
1919 | mutex_lock(&fullstop_mutex); | 1419 | torture_init_begin(torture_type, verbose, &rcutorture_runnable); |
1920 | 1420 | ||
1921 | /* Process args and tell the world that the torturer is on the job. */ | 1421 | /* Process args and tell the world that the torturer is on the job. */ |
1922 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { | 1422 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { |
@@ -1931,7 +1431,7 @@ rcu_torture_init(void) | |||
1931 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) | 1431 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) |
1932 | pr_alert(" %s", torture_ops[i]->name); | 1432 | pr_alert(" %s", torture_ops[i]->name); |
1933 | pr_alert("\n"); | 1433 | pr_alert("\n"); |
1934 | mutex_unlock(&fullstop_mutex); | 1434 | torture_init_end(); |
1935 | return -EINVAL; | 1435 | return -EINVAL; |
1936 | } | 1436 | } |
1937 | if (cur_ops->fqs == NULL && fqs_duration != 0) { | 1437 | if (cur_ops->fqs == NULL && fqs_duration != 0) { |
@@ -1946,7 +1446,6 @@ rcu_torture_init(void) | |||
1946 | else | 1446 | else |
1947 | nrealreaders = 2 * num_online_cpus(); | 1447 | nrealreaders = 2 * num_online_cpus(); |
1948 | rcu_torture_print_module_parms(cur_ops, "Start of test"); | 1448 | rcu_torture_print_module_parms(cur_ops, "Start of test"); |
1949 | fullstop = FULLSTOP_DONTSTOP; | ||
1950 | 1449 | ||
1951 | /* Set up the freelist. */ | 1450 | /* Set up the freelist. */ |
1952 | 1451 | ||
@@ -1982,108 +1481,61 @@ rcu_torture_init(void) | |||
1982 | 1481 | ||
1983 | /* Start up the kthreads. */ | 1482 | /* Start up the kthreads. */ |
1984 | 1483 | ||
1985 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); | 1484 | firsterr = torture_create_kthread(rcu_torture_writer, NULL, |
1986 | writer_task = kthread_create(rcu_torture_writer, NULL, | 1485 | writer_task); |
1987 | "rcu_torture_writer"); | 1486 | if (firsterr) |
1988 | if (IS_ERR(writer_task)) { | ||
1989 | firsterr = PTR_ERR(writer_task); | ||
1990 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); | ||
1991 | writer_task = NULL; | ||
1992 | goto unwind; | 1487 | goto unwind; |
1993 | } | ||
1994 | wake_up_process(writer_task); | ||
1995 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), | 1488 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), |
1996 | GFP_KERNEL); | 1489 | GFP_KERNEL); |
1997 | if (fakewriter_tasks == NULL) { | 1490 | if (fakewriter_tasks == NULL) { |
1998 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | 1491 | VERBOSE_TOROUT_ERRSTRING("out of memory"); |
1999 | firsterr = -ENOMEM; | 1492 | firsterr = -ENOMEM; |
2000 | goto unwind; | 1493 | goto unwind; |
2001 | } | 1494 | } |
2002 | for (i = 0; i < nfakewriters; i++) { | 1495 | for (i = 0; i < nfakewriters; i++) { |
2003 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); | 1496 | firsterr = torture_create_kthread(rcu_torture_fakewriter, |
2004 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, | 1497 | NULL, fakewriter_tasks[i]); |
2005 | "rcu_torture_fakewriter"); | 1498 | if (firsterr) |
2006 | if (IS_ERR(fakewriter_tasks[i])) { | ||
2007 | firsterr = PTR_ERR(fakewriter_tasks[i]); | ||
2008 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); | ||
2009 | fakewriter_tasks[i] = NULL; | ||
2010 | goto unwind; | 1499 | goto unwind; |
2011 | } | ||
2012 | } | 1500 | } |
2013 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), | 1501 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), |
2014 | GFP_KERNEL); | 1502 | GFP_KERNEL); |
2015 | if (reader_tasks == NULL) { | 1503 | if (reader_tasks == NULL) { |
2016 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | 1504 | VERBOSE_TOROUT_ERRSTRING("out of memory"); |
2017 | firsterr = -ENOMEM; | 1505 | firsterr = -ENOMEM; |
2018 | goto unwind; | 1506 | goto unwind; |
2019 | } | 1507 | } |
2020 | for (i = 0; i < nrealreaders; i++) { | 1508 | for (i = 0; i < nrealreaders; i++) { |
2021 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); | 1509 | firsterr = torture_create_kthread(rcu_torture_reader, NULL, |
2022 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, | 1510 | reader_tasks[i]); |
2023 | "rcu_torture_reader"); | 1511 | if (firsterr) |
2024 | if (IS_ERR(reader_tasks[i])) { | ||
2025 | firsterr = PTR_ERR(reader_tasks[i]); | ||
2026 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); | ||
2027 | reader_tasks[i] = NULL; | ||
2028 | goto unwind; | 1512 | goto unwind; |
2029 | } | ||
2030 | } | 1513 | } |
2031 | if (stat_interval > 0) { | 1514 | if (stat_interval > 0) { |
2032 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); | 1515 | firsterr = torture_create_kthread(rcu_torture_stats, NULL, |
2033 | stats_task = kthread_run(rcu_torture_stats, NULL, | 1516 | stats_task); |
2034 | "rcu_torture_stats"); | 1517 | if (firsterr) |
2035 | if (IS_ERR(stats_task)) { | ||
2036 | firsterr = PTR_ERR(stats_task); | ||
2037 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); | ||
2038 | stats_task = NULL; | ||
2039 | goto unwind; | 1518 | goto unwind; |
2040 | } | ||
2041 | } | 1519 | } |
2042 | if (test_no_idle_hz) { | 1520 | if (test_no_idle_hz) { |
2043 | rcu_idle_cpu = num_online_cpus() - 1; | 1521 | firsterr = torture_shuffle_init(shuffle_interval * HZ); |
2044 | 1522 | if (firsterr) | |
2045 | if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) { | ||
2046 | firsterr = -ENOMEM; | ||
2047 | VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask"); | ||
2048 | goto unwind; | ||
2049 | } | ||
2050 | |||
2051 | /* Create the shuffler thread */ | ||
2052 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, | ||
2053 | "rcu_torture_shuffle"); | ||
2054 | if (IS_ERR(shuffler_task)) { | ||
2055 | free_cpumask_var(shuffle_tmp_mask); | ||
2056 | firsterr = PTR_ERR(shuffler_task); | ||
2057 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); | ||
2058 | shuffler_task = NULL; | ||
2059 | goto unwind; | 1523 | goto unwind; |
2060 | } | ||
2061 | } | 1524 | } |
2062 | if (stutter < 0) | 1525 | if (stutter < 0) |
2063 | stutter = 0; | 1526 | stutter = 0; |
2064 | if (stutter) { | 1527 | if (stutter) { |
2065 | /* Create the stutter thread */ | 1528 | firsterr = torture_stutter_init(stutter * HZ); |
2066 | stutter_task = kthread_run(rcu_torture_stutter, NULL, | 1529 | if (firsterr) |
2067 | "rcu_torture_stutter"); | ||
2068 | if (IS_ERR(stutter_task)) { | ||
2069 | firsterr = PTR_ERR(stutter_task); | ||
2070 | VERBOSE_PRINTK_ERRSTRING("Failed to create stutter"); | ||
2071 | stutter_task = NULL; | ||
2072 | goto unwind; | 1530 | goto unwind; |
2073 | } | ||
2074 | } | 1531 | } |
2075 | if (fqs_duration < 0) | 1532 | if (fqs_duration < 0) |
2076 | fqs_duration = 0; | 1533 | fqs_duration = 0; |
2077 | if (fqs_duration) { | 1534 | if (fqs_duration) { |
2078 | /* Create the stutter thread */ | 1535 | /* Create the fqs thread */ |
2079 | fqs_task = kthread_run(rcu_torture_fqs, NULL, | 1536 | torture_create_kthread(rcu_torture_fqs, NULL, fqs_task); |
2080 | "rcu_torture_fqs"); | 1537 | if (firsterr) |
2081 | if (IS_ERR(fqs_task)) { | ||
2082 | firsterr = PTR_ERR(fqs_task); | ||
2083 | VERBOSE_PRINTK_ERRSTRING("Failed to create fqs"); | ||
2084 | fqs_task = NULL; | ||
2085 | goto unwind; | 1538 | goto unwind; |
2086 | } | ||
2087 | } | 1539 | } |
2088 | if (test_boost_interval < 1) | 1540 | if (test_boost_interval < 1) |
2089 | test_boost_interval = 1; | 1541 | test_boost_interval = 1; |
@@ -2097,49 +1549,31 @@ rcu_torture_init(void) | |||
2097 | for_each_possible_cpu(i) { | 1549 | for_each_possible_cpu(i) { |
2098 | if (cpu_is_offline(i)) | 1550 | if (cpu_is_offline(i)) |
2099 | continue; /* Heuristic: CPU can go offline. */ | 1551 | continue; /* Heuristic: CPU can go offline. */ |
2100 | retval = rcutorture_booster_init(i); | 1552 | firsterr = rcutorture_booster_init(i); |
2101 | if (retval < 0) { | 1553 | if (firsterr) |
2102 | firsterr = retval; | ||
2103 | goto unwind; | 1554 | goto unwind; |
2104 | } | ||
2105 | } | 1555 | } |
2106 | } | 1556 | } |
2107 | if (shutdown_secs > 0) { | 1557 | firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup); |
2108 | shutdown_time = jiffies + shutdown_secs * HZ; | 1558 | if (firsterr) |
2109 | shutdown_task = kthread_create(rcu_torture_shutdown, NULL, | ||
2110 | "rcu_torture_shutdown"); | ||
2111 | if (IS_ERR(shutdown_task)) { | ||
2112 | firsterr = PTR_ERR(shutdown_task); | ||
2113 | VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown"); | ||
2114 | shutdown_task = NULL; | ||
2115 | goto unwind; | ||
2116 | } | ||
2117 | wake_up_process(shutdown_task); | ||
2118 | } | ||
2119 | i = rcu_torture_onoff_init(); | ||
2120 | if (i != 0) { | ||
2121 | firsterr = i; | ||
2122 | goto unwind; | 1559 | goto unwind; |
2123 | } | 1560 | firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ); |
2124 | register_reboot_notifier(&rcutorture_shutdown_nb); | 1561 | if (firsterr) |
2125 | i = rcu_torture_stall_init(); | ||
2126 | if (i != 0) { | ||
2127 | firsterr = i; | ||
2128 | goto unwind; | 1562 | goto unwind; |
2129 | } | 1563 | firsterr = rcu_torture_stall_init(); |
2130 | retval = rcu_torture_barrier_init(); | 1564 | if (firsterr) |
2131 | if (retval != 0) { | 1565 | goto unwind; |
2132 | firsterr = retval; | 1566 | firsterr = rcu_torture_barrier_init(); |
1567 | if (firsterr) | ||
2133 | goto unwind; | 1568 | goto unwind; |
2134 | } | ||
2135 | if (object_debug) | 1569 | if (object_debug) |
2136 | rcu_test_debug_objects(); | 1570 | rcu_test_debug_objects(); |
2137 | rcutorture_record_test_transition(); | 1571 | rcutorture_record_test_transition(); |
2138 | mutex_unlock(&fullstop_mutex); | 1572 | torture_init_end(); |
2139 | return 0; | 1573 | return 0; |
2140 | 1574 | ||
2141 | unwind: | 1575 | unwind: |
2142 | mutex_unlock(&fullstop_mutex); | 1576 | torture_init_end(); |
2143 | rcu_torture_cleanup(); | 1577 | rcu_torture_cleanup(); |
2144 | return firsterr; | 1578 | return firsterr; |
2145 | } | 1579 | } |
diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c index 3318d8284384..c639556f3fa0 100644 --- a/kernel/rcu/srcu.c +++ b/kernel/rcu/srcu.c | |||
@@ -12,8 +12,8 @@ | |||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, you can access it online at |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
17 | * | 17 | * |
18 | * Copyright (C) IBM Corporation, 2006 | 18 | * Copyright (C) IBM Corporation, 2006 |
19 | * Copyright (C) Fujitsu, 2012 | 19 | * Copyright (C) Fujitsu, 2012 |
@@ -36,8 +36,6 @@ | |||
36 | #include <linux/delay.h> | 36 | #include <linux/delay.h> |
37 | #include <linux/srcu.h> | 37 | #include <linux/srcu.h> |
38 | 38 | ||
39 | #include <trace/events/rcu.h> | ||
40 | |||
41 | #include "rcu.h" | 39 | #include "rcu.h" |
42 | 40 | ||
43 | /* | 41 | /* |
@@ -398,7 +396,7 @@ void call_srcu(struct srcu_struct *sp, struct rcu_head *head, | |||
398 | rcu_batch_queue(&sp->batch_queue, head); | 396 | rcu_batch_queue(&sp->batch_queue, head); |
399 | if (!sp->running) { | 397 | if (!sp->running) { |
400 | sp->running = true; | 398 | sp->running = true; |
401 | schedule_delayed_work(&sp->work, 0); | 399 | queue_delayed_work(system_power_efficient_wq, &sp->work, 0); |
402 | } | 400 | } |
403 | spin_unlock_irqrestore(&sp->queue_lock, flags); | 401 | spin_unlock_irqrestore(&sp->queue_lock, flags); |
404 | } | 402 | } |
@@ -674,7 +672,8 @@ static void srcu_reschedule(struct srcu_struct *sp) | |||
674 | } | 672 | } |
675 | 673 | ||
676 | if (pending) | 674 | if (pending) |
677 | schedule_delayed_work(&sp->work, SRCU_INTERVAL); | 675 | queue_delayed_work(system_power_efficient_wq, |
676 | &sp->work, SRCU_INTERVAL); | ||
678 | } | 677 | } |
679 | 678 | ||
680 | /* | 679 | /* |
diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c index 1254f312d024..d9efcc13008c 100644 --- a/kernel/rcu/tiny.c +++ b/kernel/rcu/tiny.c | |||
@@ -12,8 +12,8 @@ | |||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, you can access it online at |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
17 | * | 17 | * |
18 | * Copyright IBM Corporation, 2008 | 18 | * Copyright IBM Corporation, 2008 |
19 | * | 19 | * |
@@ -37,10 +37,6 @@ | |||
37 | #include <linux/prefetch.h> | 37 | #include <linux/prefetch.h> |
38 | #include <linux/ftrace_event.h> | 38 | #include <linux/ftrace_event.h> |
39 | 39 | ||
40 | #ifdef CONFIG_RCU_TRACE | ||
41 | #include <trace/events/rcu.h> | ||
42 | #endif /* #else #ifdef CONFIG_RCU_TRACE */ | ||
43 | |||
44 | #include "rcu.h" | 40 | #include "rcu.h" |
45 | 41 | ||
46 | /* Forward declarations for tiny_plugin.h. */ | 42 | /* Forward declarations for tiny_plugin.h. */ |
diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h index 280d06cae352..431528520562 100644 --- a/kernel/rcu/tiny_plugin.h +++ b/kernel/rcu/tiny_plugin.h | |||
@@ -14,8 +14,8 @@ | |||
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, you can access it online at |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * http://www.gnu.org/licenses/gpl-2.0.html. |
19 | * | 19 | * |
20 | * Copyright (c) 2010 Linaro | 20 | * Copyright (c) 2010 Linaro |
21 | * | 21 | * |
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index b3d116cd072d..0c47e300210a 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c | |||
@@ -12,8 +12,8 @@ | |||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, you can access it online at |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
17 | * | 17 | * |
18 | * Copyright IBM Corporation, 2008 | 18 | * Copyright IBM Corporation, 2008 |
19 | * | 19 | * |
@@ -58,8 +58,6 @@ | |||
58 | #include <linux/suspend.h> | 58 | #include <linux/suspend.h> |
59 | 59 | ||
60 | #include "tree.h" | 60 | #include "tree.h" |
61 | #include <trace/events/rcu.h> | ||
62 | |||
63 | #include "rcu.h" | 61 | #include "rcu.h" |
64 | 62 | ||
65 | MODULE_ALIAS("rcutree"); | 63 | MODULE_ALIAS("rcutree"); |
@@ -837,7 +835,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp, | |||
837 | * to the next. Only do this for the primary flavor of RCU. | 835 | * to the next. Only do this for the primary flavor of RCU. |
838 | */ | 836 | */ |
839 | if (rdp->rsp == rcu_state && | 837 | if (rdp->rsp == rcu_state && |
840 | ULONG_CMP_GE(ACCESS_ONCE(jiffies), rdp->rsp->jiffies_resched)) { | 838 | ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) { |
841 | rdp->rsp->jiffies_resched += 5; | 839 | rdp->rsp->jiffies_resched += 5; |
842 | resched_cpu(rdp->cpu); | 840 | resched_cpu(rdp->cpu); |
843 | } | 841 | } |
@@ -847,7 +845,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp, | |||
847 | 845 | ||
848 | static void record_gp_stall_check_time(struct rcu_state *rsp) | 846 | static void record_gp_stall_check_time(struct rcu_state *rsp) |
849 | { | 847 | { |
850 | unsigned long j = ACCESS_ONCE(jiffies); | 848 | unsigned long j = jiffies; |
851 | unsigned long j1; | 849 | unsigned long j1; |
852 | 850 | ||
853 | rsp->gp_start = j; | 851 | rsp->gp_start = j; |
@@ -1005,7 +1003,7 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1005 | 1003 | ||
1006 | if (rcu_cpu_stall_suppress || !rcu_gp_in_progress(rsp)) | 1004 | if (rcu_cpu_stall_suppress || !rcu_gp_in_progress(rsp)) |
1007 | return; | 1005 | return; |
1008 | j = ACCESS_ONCE(jiffies); | 1006 | j = jiffies; |
1009 | 1007 | ||
1010 | /* | 1008 | /* |
1011 | * Lots of memory barriers to reject false positives. | 1009 | * Lots of memory barriers to reject false positives. |
@@ -1423,13 +1421,14 @@ static int rcu_gp_init(struct rcu_state *rsp) | |||
1423 | 1421 | ||
1424 | /* Advance to a new grace period and initialize state. */ | 1422 | /* Advance to a new grace period and initialize state. */ |
1425 | record_gp_stall_check_time(rsp); | 1423 | record_gp_stall_check_time(rsp); |
1426 | smp_wmb(); /* Record GP times before starting GP. */ | 1424 | /* Record GP times before starting GP, hence smp_store_release(). */ |
1427 | rsp->gpnum++; | 1425 | smp_store_release(&rsp->gpnum, rsp->gpnum + 1); |
1428 | trace_rcu_grace_period(rsp->name, rsp->gpnum, TPS("start")); | 1426 | trace_rcu_grace_period(rsp->name, rsp->gpnum, TPS("start")); |
1429 | raw_spin_unlock_irq(&rnp->lock); | 1427 | raw_spin_unlock_irq(&rnp->lock); |
1430 | 1428 | ||
1431 | /* Exclude any concurrent CPU-hotplug operations. */ | 1429 | /* Exclude any concurrent CPU-hotplug operations. */ |
1432 | mutex_lock(&rsp->onoff_mutex); | 1430 | mutex_lock(&rsp->onoff_mutex); |
1431 | smp_mb__after_unlock_lock(); /* ->gpnum increment before GP! */ | ||
1433 | 1432 | ||
1434 | /* | 1433 | /* |
1435 | * Set the quiescent-state-needed bits in all the rcu_node | 1434 | * Set the quiescent-state-needed bits in all the rcu_node |
@@ -1557,10 +1556,11 @@ static void rcu_gp_cleanup(struct rcu_state *rsp) | |||
1557 | } | 1556 | } |
1558 | rnp = rcu_get_root(rsp); | 1557 | rnp = rcu_get_root(rsp); |
1559 | raw_spin_lock_irq(&rnp->lock); | 1558 | raw_spin_lock_irq(&rnp->lock); |
1560 | smp_mb__after_unlock_lock(); | 1559 | smp_mb__after_unlock_lock(); /* Order GP before ->completed update. */ |
1561 | rcu_nocb_gp_set(rnp, nocb); | 1560 | rcu_nocb_gp_set(rnp, nocb); |
1562 | 1561 | ||
1563 | rsp->completed = rsp->gpnum; /* Declare grace period done. */ | 1562 | /* Declare grace period done. */ |
1563 | ACCESS_ONCE(rsp->completed) = rsp->gpnum; | ||
1564 | trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end")); | 1564 | trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end")); |
1565 | rsp->fqs_state = RCU_GP_IDLE; | 1565 | rsp->fqs_state = RCU_GP_IDLE; |
1566 | rdp = this_cpu_ptr(rsp->rda); | 1566 | rdp = this_cpu_ptr(rsp->rda); |
@@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp) | |||
2304 | if (rnp_old != NULL) | 2304 | if (rnp_old != NULL) |
2305 | raw_spin_unlock(&rnp_old->fqslock); | 2305 | raw_spin_unlock(&rnp_old->fqslock); |
2306 | if (ret) { | 2306 | if (ret) { |
2307 | rsp->n_force_qs_lh++; | 2307 | ACCESS_ONCE(rsp->n_force_qs_lh)++; |
2308 | return; | 2308 | return; |
2309 | } | 2309 | } |
2310 | rnp_old = rnp; | 2310 | rnp_old = rnp; |
@@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp) | |||
2316 | smp_mb__after_unlock_lock(); | 2316 | smp_mb__after_unlock_lock(); |
2317 | raw_spin_unlock(&rnp_old->fqslock); | 2317 | raw_spin_unlock(&rnp_old->fqslock); |
2318 | if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) { | 2318 | if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) { |
2319 | rsp->n_force_qs_lh++; | 2319 | ACCESS_ONCE(rsp->n_force_qs_lh)++; |
2320 | raw_spin_unlock_irqrestore(&rnp_old->lock, flags); | 2320 | raw_spin_unlock_irqrestore(&rnp_old->lock, flags); |
2321 | return; /* Someone beat us to it. */ | 2321 | return; /* Someone beat us to it. */ |
2322 | } | 2322 | } |
@@ -2639,6 +2639,58 @@ void synchronize_rcu_bh(void) | |||
2639 | } | 2639 | } |
2640 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | 2640 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); |
2641 | 2641 | ||
2642 | /** | ||
2643 | * get_state_synchronize_rcu - Snapshot current RCU state | ||
2644 | * | ||
2645 | * Returns a cookie that is used by a later call to cond_synchronize_rcu() | ||
2646 | * to determine whether or not a full grace period has elapsed in the | ||
2647 | * meantime. | ||
2648 | */ | ||
2649 | unsigned long get_state_synchronize_rcu(void) | ||
2650 | { | ||
2651 | /* | ||
2652 | * Any prior manipulation of RCU-protected data must happen | ||
2653 | * before the load from ->gpnum. | ||
2654 | */ | ||
2655 | smp_mb(); /* ^^^ */ | ||
2656 | |||
2657 | /* | ||
2658 | * Make sure this load happens before the purportedly | ||
2659 | * time-consuming work between get_state_synchronize_rcu() | ||
2660 | * and cond_synchronize_rcu(). | ||
2661 | */ | ||
2662 | return smp_load_acquire(&rcu_state->gpnum); | ||
2663 | } | ||
2664 | EXPORT_SYMBOL_GPL(get_state_synchronize_rcu); | ||
2665 | |||
2666 | /** | ||
2667 | * cond_synchronize_rcu - Conditionally wait for an RCU grace period | ||
2668 | * | ||
2669 | * @oldstate: return value from earlier call to get_state_synchronize_rcu() | ||
2670 | * | ||
2671 | * If a full RCU grace period has elapsed since the earlier call to | ||
2672 | * get_state_synchronize_rcu(), just return. Otherwise, invoke | ||
2673 | * synchronize_rcu() to wait for a full grace period. | ||
2674 | * | ||
2675 | * Yes, this function does not take counter wrap into account. But | ||
2676 | * counter wrap is harmless. If the counter wraps, we have waited for | ||
2677 | * more than 2 billion grace periods (and way more on a 64-bit system!), | ||
2678 | * so waiting for one additional grace period should be just fine. | ||
2679 | */ | ||
2680 | void cond_synchronize_rcu(unsigned long oldstate) | ||
2681 | { | ||
2682 | unsigned long newstate; | ||
2683 | |||
2684 | /* | ||
2685 | * Ensure that this load happens before any RCU-destructive | ||
2686 | * actions the caller might carry out after we return. | ||
2687 | */ | ||
2688 | newstate = smp_load_acquire(&rcu_state->completed); | ||
2689 | if (ULONG_CMP_GE(oldstate, newstate)) | ||
2690 | synchronize_rcu(); | ||
2691 | } | ||
2692 | EXPORT_SYMBOL_GPL(cond_synchronize_rcu); | ||
2693 | |||
2642 | static int synchronize_sched_expedited_cpu_stop(void *data) | 2694 | static int synchronize_sched_expedited_cpu_stop(void *data) |
2643 | { | 2695 | { |
2644 | /* | 2696 | /* |
@@ -2880,7 +2932,7 @@ static int rcu_pending(int cpu) | |||
2880 | * non-NULL, store an indication of whether all callbacks are lazy. | 2932 | * non-NULL, store an indication of whether all callbacks are lazy. |
2881 | * (If there are no callbacks, all of them are deemed to be lazy.) | 2933 | * (If there are no callbacks, all of them are deemed to be lazy.) |
2882 | */ | 2934 | */ |
2883 | static int rcu_cpu_has_callbacks(int cpu, bool *all_lazy) | 2935 | static int __maybe_unused rcu_cpu_has_callbacks(int cpu, bool *all_lazy) |
2884 | { | 2936 | { |
2885 | bool al = true; | 2937 | bool al = true; |
2886 | bool hc = false; | 2938 | bool hc = false; |
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h index 8c19873f1ac9..75dc3c39a02a 100644 --- a/kernel/rcu/tree.h +++ b/kernel/rcu/tree.h | |||
@@ -13,8 +13,8 @@ | |||
13 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, you can access it online at |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | * http://www.gnu.org/licenses/gpl-2.0.html. |
18 | * | 18 | * |
19 | * Copyright IBM Corporation, 2008 | 19 | * Copyright IBM Corporation, 2008 |
20 | * | 20 | * |
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 6e2ef4b2b920..962d1d589929 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h | |||
@@ -14,8 +14,8 @@ | |||
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, you can access it online at |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * http://www.gnu.org/licenses/gpl-2.0.html. |
19 | * | 19 | * |
20 | * Copyright Red Hat, 2009 | 20 | * Copyright Red Hat, 2009 |
21 | * Copyright IBM Corporation, 2009 | 21 | * Copyright IBM Corporation, 2009 |
@@ -1586,11 +1586,13 @@ static void rcu_prepare_kthreads(int cpu) | |||
1586 | * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs | 1586 | * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs |
1587 | * any flavor of RCU. | 1587 | * any flavor of RCU. |
1588 | */ | 1588 | */ |
1589 | #ifndef CONFIG_RCU_NOCB_CPU_ALL | ||
1589 | int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies) | 1590 | int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies) |
1590 | { | 1591 | { |
1591 | *delta_jiffies = ULONG_MAX; | 1592 | *delta_jiffies = ULONG_MAX; |
1592 | return rcu_cpu_has_callbacks(cpu, NULL); | 1593 | return rcu_cpu_has_callbacks(cpu, NULL); |
1593 | } | 1594 | } |
1595 | #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */ | ||
1594 | 1596 | ||
1595 | /* | 1597 | /* |
1596 | * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up | 1598 | * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up |
@@ -1656,7 +1658,7 @@ extern int tick_nohz_active; | |||
1656 | * only if it has been awhile since the last time we did so. Afterwards, | 1658 | * only if it has been awhile since the last time we did so. Afterwards, |
1657 | * if there are any callbacks ready for immediate invocation, return true. | 1659 | * if there are any callbacks ready for immediate invocation, return true. |
1658 | */ | 1660 | */ |
1659 | static bool rcu_try_advance_all_cbs(void) | 1661 | static bool __maybe_unused rcu_try_advance_all_cbs(void) |
1660 | { | 1662 | { |
1661 | bool cbs_ready = false; | 1663 | bool cbs_ready = false; |
1662 | struct rcu_data *rdp; | 1664 | struct rcu_data *rdp; |
@@ -1696,6 +1698,7 @@ static bool rcu_try_advance_all_cbs(void) | |||
1696 | * | 1698 | * |
1697 | * The caller must have disabled interrupts. | 1699 | * The caller must have disabled interrupts. |
1698 | */ | 1700 | */ |
1701 | #ifndef CONFIG_RCU_NOCB_CPU_ALL | ||
1699 | int rcu_needs_cpu(int cpu, unsigned long *dj) | 1702 | int rcu_needs_cpu(int cpu, unsigned long *dj) |
1700 | { | 1703 | { |
1701 | struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu); | 1704 | struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu); |
@@ -1726,6 +1729,7 @@ int rcu_needs_cpu(int cpu, unsigned long *dj) | |||
1726 | } | 1729 | } |
1727 | return 0; | 1730 | return 0; |
1728 | } | 1731 | } |
1732 | #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */ | ||
1729 | 1733 | ||
1730 | /* | 1734 | /* |
1731 | * Prepare a CPU for idle from an RCU perspective. The first major task | 1735 | * Prepare a CPU for idle from an RCU perspective. The first major task |
@@ -1739,6 +1743,7 @@ int rcu_needs_cpu(int cpu, unsigned long *dj) | |||
1739 | */ | 1743 | */ |
1740 | static void rcu_prepare_for_idle(int cpu) | 1744 | static void rcu_prepare_for_idle(int cpu) |
1741 | { | 1745 | { |
1746 | #ifndef CONFIG_RCU_NOCB_CPU_ALL | ||
1742 | struct rcu_data *rdp; | 1747 | struct rcu_data *rdp; |
1743 | struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu); | 1748 | struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu); |
1744 | struct rcu_node *rnp; | 1749 | struct rcu_node *rnp; |
@@ -1790,6 +1795,7 @@ static void rcu_prepare_for_idle(int cpu) | |||
1790 | rcu_accelerate_cbs(rsp, rnp, rdp); | 1795 | rcu_accelerate_cbs(rsp, rnp, rdp); |
1791 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ | 1796 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
1792 | } | 1797 | } |
1798 | #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */ | ||
1793 | } | 1799 | } |
1794 | 1800 | ||
1795 | /* | 1801 | /* |
@@ -1799,11 +1805,12 @@ static void rcu_prepare_for_idle(int cpu) | |||
1799 | */ | 1805 | */ |
1800 | static void rcu_cleanup_after_idle(int cpu) | 1806 | static void rcu_cleanup_after_idle(int cpu) |
1801 | { | 1807 | { |
1802 | 1808 | #ifndef CONFIG_RCU_NOCB_CPU_ALL | |
1803 | if (rcu_is_nocb_cpu(cpu)) | 1809 | if (rcu_is_nocb_cpu(cpu)) |
1804 | return; | 1810 | return; |
1805 | if (rcu_try_advance_all_cbs()) | 1811 | if (rcu_try_advance_all_cbs()) |
1806 | invoke_rcu_core(); | 1812 | invoke_rcu_core(); |
1813 | #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */ | ||
1807 | } | 1814 | } |
1808 | 1815 | ||
1809 | /* | 1816 | /* |
@@ -2101,6 +2108,7 @@ static void rcu_init_one_nocb(struct rcu_node *rnp) | |||
2101 | init_waitqueue_head(&rnp->nocb_gp_wq[1]); | 2108 | init_waitqueue_head(&rnp->nocb_gp_wq[1]); |
2102 | } | 2109 | } |
2103 | 2110 | ||
2111 | #ifndef CONFIG_RCU_NOCB_CPU_ALL | ||
2104 | /* Is the specified CPU a no-CPUs CPU? */ | 2112 | /* Is the specified CPU a no-CPUs CPU? */ |
2105 | bool rcu_is_nocb_cpu(int cpu) | 2113 | bool rcu_is_nocb_cpu(int cpu) |
2106 | { | 2114 | { |
@@ -2108,6 +2116,7 @@ bool rcu_is_nocb_cpu(int cpu) | |||
2108 | return cpumask_test_cpu(cpu, rcu_nocb_mask); | 2116 | return cpumask_test_cpu(cpu, rcu_nocb_mask); |
2109 | return false; | 2117 | return false; |
2110 | } | 2118 | } |
2119 | #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */ | ||
2111 | 2120 | ||
2112 | /* | 2121 | /* |
2113 | * Enqueue the specified string of rcu_head structures onto the specified | 2122 | * Enqueue the specified string of rcu_head structures onto the specified |
@@ -2893,7 +2902,7 @@ static void rcu_sysidle_init_percpu_data(struct rcu_dynticks *rdtp) | |||
2893 | * CPU unless the grace period has extended for too long. | 2902 | * CPU unless the grace period has extended for too long. |
2894 | * | 2903 | * |
2895 | * This code relies on the fact that all NO_HZ_FULL CPUs are also | 2904 | * This code relies on the fact that all NO_HZ_FULL CPUs are also |
2896 | * CONFIG_RCU_NOCB_CPUs. | 2905 | * CONFIG_RCU_NOCB_CPU CPUs. |
2897 | */ | 2906 | */ |
2898 | static bool rcu_nohz_full_cpu(struct rcu_state *rsp) | 2907 | static bool rcu_nohz_full_cpu(struct rcu_state *rsp) |
2899 | { | 2908 | { |
diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c index 4def475336d4..5cdc62e1beeb 100644 --- a/kernel/rcu/tree_trace.c +++ b/kernel/rcu/tree_trace.c | |||
@@ -12,8 +12,8 @@ | |||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, you can access it online at |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
17 | * | 17 | * |
18 | * Copyright IBM Corporation, 2008 | 18 | * Copyright IBM Corporation, 2008 |
19 | * | 19 | * |
@@ -273,7 +273,7 @@ static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp) | |||
273 | seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n", | 273 | seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n", |
274 | rsp->n_force_qs, rsp->n_force_qs_ngp, | 274 | rsp->n_force_qs, rsp->n_force_qs_ngp, |
275 | rsp->n_force_qs - rsp->n_force_qs_ngp, | 275 | rsp->n_force_qs - rsp->n_force_qs_ngp, |
276 | rsp->n_force_qs_lh, rsp->qlen_lazy, rsp->qlen); | 276 | ACCESS_ONCE(rsp->n_force_qs_lh), rsp->qlen_lazy, rsp->qlen); |
277 | for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) { | 277 | for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) { |
278 | if (rnp->level != level) { | 278 | if (rnp->level != level) { |
279 | seq_puts(m, "\n"); | 279 | seq_puts(m, "\n"); |
diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c index c54609faf233..4c0a9b0af469 100644 --- a/kernel/rcu/update.c +++ b/kernel/rcu/update.c | |||
@@ -12,8 +12,8 @@ | |||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, you can access it online at |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
17 | * | 17 | * |
18 | * Copyright IBM Corporation, 2001 | 18 | * Copyright IBM Corporation, 2001 |
19 | * | 19 | * |
@@ -49,7 +49,6 @@ | |||
49 | #include <linux/module.h> | 49 | #include <linux/module.h> |
50 | 50 | ||
51 | #define CREATE_TRACE_POINTS | 51 | #define CREATE_TRACE_POINTS |
52 | #include <trace/events/rcu.h> | ||
53 | 52 | ||
54 | #include "rcu.h" | 53 | #include "rcu.h" |
55 | 54 | ||
diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index 43c2bcc35761..b30a2924ef14 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c | |||
@@ -301,14 +301,14 @@ u64 sched_clock_cpu(int cpu) | |||
301 | if (unlikely(!sched_clock_running)) | 301 | if (unlikely(!sched_clock_running)) |
302 | return 0ull; | 302 | return 0ull; |
303 | 303 | ||
304 | preempt_disable(); | 304 | preempt_disable_notrace(); |
305 | scd = cpu_sdc(cpu); | 305 | scd = cpu_sdc(cpu); |
306 | 306 | ||
307 | if (cpu != smp_processor_id()) | 307 | if (cpu != smp_processor_id()) |
308 | clock = sched_clock_remote(scd); | 308 | clock = sched_clock_remote(scd); |
309 | else | 309 | else |
310 | clock = sched_clock_local(scd); | 310 | clock = sched_clock_local(scd); |
311 | preempt_enable(); | 311 | preempt_enable_notrace(); |
312 | 312 | ||
313 | return clock; | 313 | return clock; |
314 | } | 314 | } |
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b46131ef6aab..f5c6635b806c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -1952,7 +1952,7 @@ static int dl_overflow(struct task_struct *p, int policy, | |||
1952 | { | 1952 | { |
1953 | 1953 | ||
1954 | struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); | 1954 | struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); |
1955 | u64 period = attr->sched_period; | 1955 | u64 period = attr->sched_period ?: attr->sched_deadline; |
1956 | u64 runtime = attr->sched_runtime; | 1956 | u64 runtime = attr->sched_runtime; |
1957 | u64 new_bw = dl_policy(policy) ? to_ratio(period, runtime) : 0; | 1957 | u64 new_bw = dl_policy(policy) ? to_ratio(period, runtime) : 0; |
1958 | int cpus, err = -1; | 1958 | int cpus, err = -1; |
@@ -3338,6 +3338,15 @@ recheck: | |||
3338 | return -EPERM; | 3338 | return -EPERM; |
3339 | } | 3339 | } |
3340 | 3340 | ||
3341 | /* | ||
3342 | * Can't set/change SCHED_DEADLINE policy at all for now | ||
3343 | * (safest behavior); in the future we would like to allow | ||
3344 | * unprivileged DL tasks to increase their relative deadline | ||
3345 | * or reduce their runtime (both ways reducing utilization) | ||
3346 | */ | ||
3347 | if (dl_policy(policy)) | ||
3348 | return -EPERM; | ||
3349 | |||
3341 | /* | 3350 | /* |
3342 | * Treat SCHED_IDLE as nice 20. Only allow a switch to | 3351 | * Treat SCHED_IDLE as nice 20. Only allow a switch to |
3343 | * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. | 3352 | * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. |
@@ -3661,13 +3670,14 @@ SYSCALL_DEFINE2(sched_setparam, pid_t, pid, struct sched_param __user *, param) | |||
3661 | * @pid: the pid in question. | 3670 | * @pid: the pid in question. |
3662 | * @uattr: structure containing the extended parameters. | 3671 | * @uattr: structure containing the extended parameters. |
3663 | */ | 3672 | */ |
3664 | SYSCALL_DEFINE2(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr) | 3673 | SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, |
3674 | unsigned int, flags) | ||
3665 | { | 3675 | { |
3666 | struct sched_attr attr; | 3676 | struct sched_attr attr; |
3667 | struct task_struct *p; | 3677 | struct task_struct *p; |
3668 | int retval; | 3678 | int retval; |
3669 | 3679 | ||
3670 | if (!uattr || pid < 0) | 3680 | if (!uattr || pid < 0 || flags) |
3671 | return -EINVAL; | 3681 | return -EINVAL; |
3672 | 3682 | ||
3673 | if (sched_copy_attr(uattr, &attr)) | 3683 | if (sched_copy_attr(uattr, &attr)) |
@@ -3786,7 +3796,7 @@ static int sched_read_attr(struct sched_attr __user *uattr, | |||
3786 | attr->size = usize; | 3796 | attr->size = usize; |
3787 | } | 3797 | } |
3788 | 3798 | ||
3789 | ret = copy_to_user(uattr, attr, usize); | 3799 | ret = copy_to_user(uattr, attr, attr->size); |
3790 | if (ret) | 3800 | if (ret) |
3791 | return -EFAULT; | 3801 | return -EFAULT; |
3792 | 3802 | ||
@@ -3804,8 +3814,8 @@ err_size: | |||
3804 | * @uattr: structure containing the extended parameters. | 3814 | * @uattr: structure containing the extended parameters. |
3805 | * @size: sizeof(attr) for fwd/bwd comp. | 3815 | * @size: sizeof(attr) for fwd/bwd comp. |
3806 | */ | 3816 | */ |
3807 | SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, | 3817 | SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, |
3808 | unsigned int, size) | 3818 | unsigned int, size, unsigned int, flags) |
3809 | { | 3819 | { |
3810 | struct sched_attr attr = { | 3820 | struct sched_attr attr = { |
3811 | .size = sizeof(struct sched_attr), | 3821 | .size = sizeof(struct sched_attr), |
@@ -3814,7 +3824,7 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, | |||
3814 | int retval; | 3824 | int retval; |
3815 | 3825 | ||
3816 | if (!uattr || pid < 0 || size > PAGE_SIZE || | 3826 | if (!uattr || pid < 0 || size > PAGE_SIZE || |
3817 | size < SCHED_ATTR_SIZE_VER0) | 3827 | size < SCHED_ATTR_SIZE_VER0 || flags) |
3818 | return -EINVAL; | 3828 | return -EINVAL; |
3819 | 3829 | ||
3820 | rcu_read_lock(); | 3830 | rcu_read_lock(); |
@@ -7422,6 +7432,7 @@ static int sched_dl_global_constraints(void) | |||
7422 | u64 period = global_rt_period(); | 7432 | u64 period = global_rt_period(); |
7423 | u64 new_bw = to_ratio(period, runtime); | 7433 | u64 new_bw = to_ratio(period, runtime); |
7424 | int cpu, ret = 0; | 7434 | int cpu, ret = 0; |
7435 | unsigned long flags; | ||
7425 | 7436 | ||
7426 | /* | 7437 | /* |
7427 | * Here we want to check the bandwidth not being set to some | 7438 | * Here we want to check the bandwidth not being set to some |
@@ -7435,10 +7446,10 @@ static int sched_dl_global_constraints(void) | |||
7435 | for_each_possible_cpu(cpu) { | 7446 | for_each_possible_cpu(cpu) { |
7436 | struct dl_bw *dl_b = dl_bw_of(cpu); | 7447 | struct dl_bw *dl_b = dl_bw_of(cpu); |
7437 | 7448 | ||
7438 | raw_spin_lock(&dl_b->lock); | 7449 | raw_spin_lock_irqsave(&dl_b->lock, flags); |
7439 | if (new_bw < dl_b->total_bw) | 7450 | if (new_bw < dl_b->total_bw) |
7440 | ret = -EBUSY; | 7451 | ret = -EBUSY; |
7441 | raw_spin_unlock(&dl_b->lock); | 7452 | raw_spin_unlock_irqrestore(&dl_b->lock, flags); |
7442 | 7453 | ||
7443 | if (ret) | 7454 | if (ret) |
7444 | break; | 7455 | break; |
@@ -7451,6 +7462,7 @@ static void sched_dl_do_global(void) | |||
7451 | { | 7462 | { |
7452 | u64 new_bw = -1; | 7463 | u64 new_bw = -1; |
7453 | int cpu; | 7464 | int cpu; |
7465 | unsigned long flags; | ||
7454 | 7466 | ||
7455 | def_dl_bandwidth.dl_period = global_rt_period(); | 7467 | def_dl_bandwidth.dl_period = global_rt_period(); |
7456 | def_dl_bandwidth.dl_runtime = global_rt_runtime(); | 7468 | def_dl_bandwidth.dl_runtime = global_rt_runtime(); |
@@ -7464,9 +7476,9 @@ static void sched_dl_do_global(void) | |||
7464 | for_each_possible_cpu(cpu) { | 7476 | for_each_possible_cpu(cpu) { |
7465 | struct dl_bw *dl_b = dl_bw_of(cpu); | 7477 | struct dl_bw *dl_b = dl_bw_of(cpu); |
7466 | 7478 | ||
7467 | raw_spin_lock(&dl_b->lock); | 7479 | raw_spin_lock_irqsave(&dl_b->lock, flags); |
7468 | dl_b->bw = new_bw; | 7480 | dl_b->bw = new_bw; |
7469 | raw_spin_unlock(&dl_b->lock); | 7481 | raw_spin_unlock_irqrestore(&dl_b->lock, flags); |
7470 | } | 7482 | } |
7471 | } | 7483 | } |
7472 | 7484 | ||
@@ -7475,7 +7487,8 @@ static int sched_rt_global_validate(void) | |||
7475 | if (sysctl_sched_rt_period <= 0) | 7487 | if (sysctl_sched_rt_period <= 0) |
7476 | return -EINVAL; | 7488 | return -EINVAL; |
7477 | 7489 | ||
7478 | if (sysctl_sched_rt_runtime > sysctl_sched_rt_period) | 7490 | if ((sysctl_sched_rt_runtime != RUNTIME_INF) && |
7491 | (sysctl_sched_rt_runtime > sysctl_sched_rt_period)) | ||
7479 | return -EINVAL; | 7492 | return -EINVAL; |
7480 | 7493 | ||
7481 | return 0; | 7494 | return 0; |
diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c index 045fc74e3f09..5b9bb42b2d47 100644 --- a/kernel/sched/cpudeadline.c +++ b/kernel/sched/cpudeadline.c | |||
@@ -70,7 +70,7 @@ static void cpudl_heapify(struct cpudl *cp, int idx) | |||
70 | 70 | ||
71 | static void cpudl_change_key(struct cpudl *cp, int idx, u64 new_dl) | 71 | static void cpudl_change_key(struct cpudl *cp, int idx, u64 new_dl) |
72 | { | 72 | { |
73 | WARN_ON(idx > num_present_cpus() || idx == IDX_INVALID); | 73 | WARN_ON(idx == IDX_INVALID || !cpu_present(idx)); |
74 | 74 | ||
75 | if (dl_time_before(new_dl, cp->elements[idx].dl)) { | 75 | if (dl_time_before(new_dl, cp->elements[idx].dl)) { |
76 | cp->elements[idx].dl = new_dl; | 76 | cp->elements[idx].dl = new_dl; |
@@ -117,7 +117,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p, | |||
117 | } | 117 | } |
118 | 118 | ||
119 | out: | 119 | out: |
120 | WARN_ON(best_cpu > num_present_cpus() && best_cpu != -1); | 120 | WARN_ON(best_cpu != -1 && !cpu_present(best_cpu)); |
121 | 121 | ||
122 | return best_cpu; | 122 | return best_cpu; |
123 | } | 123 | } |
@@ -137,7 +137,7 @@ void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid) | |||
137 | int old_idx, new_cpu; | 137 | int old_idx, new_cpu; |
138 | unsigned long flags; | 138 | unsigned long flags; |
139 | 139 | ||
140 | WARN_ON(cpu > num_present_cpus()); | 140 | WARN_ON(!cpu_present(cpu)); |
141 | 141 | ||
142 | raw_spin_lock_irqsave(&cp->lock, flags); | 142 | raw_spin_lock_irqsave(&cp->lock, flags); |
143 | old_idx = cp->cpu_to_idx[cpu]; | 143 | old_idx = cp->cpu_to_idx[cpu]; |
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 0dd5e0971a07..6e79b3faa4cd 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c | |||
@@ -121,7 +121,7 @@ static inline void dl_clear_overload(struct rq *rq) | |||
121 | 121 | ||
122 | static void update_dl_migration(struct dl_rq *dl_rq) | 122 | static void update_dl_migration(struct dl_rq *dl_rq) |
123 | { | 123 | { |
124 | if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_total > 1) { | 124 | if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_running > 1) { |
125 | if (!dl_rq->overloaded) { | 125 | if (!dl_rq->overloaded) { |
126 | dl_set_overload(rq_of_dl_rq(dl_rq)); | 126 | dl_set_overload(rq_of_dl_rq(dl_rq)); |
127 | dl_rq->overloaded = 1; | 127 | dl_rq->overloaded = 1; |
@@ -135,9 +135,7 @@ static void update_dl_migration(struct dl_rq *dl_rq) | |||
135 | static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) | 135 | static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
136 | { | 136 | { |
137 | struct task_struct *p = dl_task_of(dl_se); | 137 | struct task_struct *p = dl_task_of(dl_se); |
138 | dl_rq = &rq_of_dl_rq(dl_rq)->dl; | ||
139 | 138 | ||
140 | dl_rq->dl_nr_total++; | ||
141 | if (p->nr_cpus_allowed > 1) | 139 | if (p->nr_cpus_allowed > 1) |
142 | dl_rq->dl_nr_migratory++; | 140 | dl_rq->dl_nr_migratory++; |
143 | 141 | ||
@@ -147,9 +145,7 @@ static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) | |||
147 | static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) | 145 | static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
148 | { | 146 | { |
149 | struct task_struct *p = dl_task_of(dl_se); | 147 | struct task_struct *p = dl_task_of(dl_se); |
150 | dl_rq = &rq_of_dl_rq(dl_rq)->dl; | ||
151 | 148 | ||
152 | dl_rq->dl_nr_total--; | ||
153 | if (p->nr_cpus_allowed > 1) | 149 | if (p->nr_cpus_allowed > 1) |
154 | dl_rq->dl_nr_migratory--; | 150 | dl_rq->dl_nr_migratory--; |
155 | 151 | ||
@@ -566,6 +562,8 @@ int dl_runtime_exceeded(struct rq *rq, struct sched_dl_entity *dl_se) | |||
566 | return 1; | 562 | return 1; |
567 | } | 563 | } |
568 | 564 | ||
565 | extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq); | ||
566 | |||
569 | /* | 567 | /* |
570 | * Update the current task's runtime statistics (provided it is still | 568 | * Update the current task's runtime statistics (provided it is still |
571 | * a -deadline task and has not been removed from the dl_rq). | 569 | * a -deadline task and has not been removed from the dl_rq). |
@@ -629,11 +627,13 @@ static void update_curr_dl(struct rq *rq) | |||
629 | struct rt_rq *rt_rq = &rq->rt; | 627 | struct rt_rq *rt_rq = &rq->rt; |
630 | 628 | ||
631 | raw_spin_lock(&rt_rq->rt_runtime_lock); | 629 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
632 | rt_rq->rt_time += delta_exec; | ||
633 | /* | 630 | /* |
634 | * We'll let actual RT tasks worry about the overflow here, we | 631 | * We'll let actual RT tasks worry about the overflow here, we |
635 | * have our own CBS to keep us inline -- see above. | 632 | * have our own CBS to keep us inline; only account when RT |
633 | * bandwidth is relevant. | ||
636 | */ | 634 | */ |
635 | if (sched_rt_bandwidth_account(rt_rq)) | ||
636 | rt_rq->rt_time += delta_exec; | ||
637 | raw_spin_unlock(&rt_rq->rt_runtime_lock); | 637 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
638 | } | 638 | } |
639 | } | 639 | } |
@@ -717,6 +717,7 @@ void inc_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) | |||
717 | 717 | ||
718 | WARN_ON(!dl_prio(prio)); | 718 | WARN_ON(!dl_prio(prio)); |
719 | dl_rq->dl_nr_running++; | 719 | dl_rq->dl_nr_running++; |
720 | inc_nr_running(rq_of_dl_rq(dl_rq)); | ||
720 | 721 | ||
721 | inc_dl_deadline(dl_rq, deadline); | 722 | inc_dl_deadline(dl_rq, deadline); |
722 | inc_dl_migration(dl_se, dl_rq); | 723 | inc_dl_migration(dl_se, dl_rq); |
@@ -730,6 +731,7 @@ void dec_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) | |||
730 | WARN_ON(!dl_prio(prio)); | 731 | WARN_ON(!dl_prio(prio)); |
731 | WARN_ON(!dl_rq->dl_nr_running); | 732 | WARN_ON(!dl_rq->dl_nr_running); |
732 | dl_rq->dl_nr_running--; | 733 | dl_rq->dl_nr_running--; |
734 | dec_nr_running(rq_of_dl_rq(dl_rq)); | ||
733 | 735 | ||
734 | dec_dl_deadline(dl_rq, dl_se->deadline); | 736 | dec_dl_deadline(dl_rq, dl_se->deadline); |
735 | dec_dl_migration(dl_se, dl_rq); | 737 | dec_dl_migration(dl_se, dl_rq); |
@@ -836,8 +838,6 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) | |||
836 | 838 | ||
837 | if (!task_current(rq, p) && p->nr_cpus_allowed > 1) | 839 | if (!task_current(rq, p) && p->nr_cpus_allowed > 1) |
838 | enqueue_pushable_dl_task(rq, p); | 840 | enqueue_pushable_dl_task(rq, p); |
839 | |||
840 | inc_nr_running(rq); | ||
841 | } | 841 | } |
842 | 842 | ||
843 | static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) | 843 | static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) |
@@ -850,8 +850,6 @@ static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) | |||
850 | { | 850 | { |
851 | update_curr_dl(rq); | 851 | update_curr_dl(rq); |
852 | __dequeue_task_dl(rq, p, flags); | 852 | __dequeue_task_dl(rq, p, flags); |
853 | |||
854 | dec_nr_running(rq); | ||
855 | } | 853 | } |
856 | 854 | ||
857 | /* | 855 | /* |
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 966cc2bfcb77..9b4c4f320130 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c | |||
@@ -1757,6 +1757,8 @@ void task_numa_work(struct callback_head *work) | |||
1757 | start = end; | 1757 | start = end; |
1758 | if (pages <= 0) | 1758 | if (pages <= 0) |
1759 | goto out; | 1759 | goto out; |
1760 | |||
1761 | cond_resched(); | ||
1760 | } while (end != vma->vm_end); | 1762 | } while (end != vma->vm_end); |
1761 | } | 1763 | } |
1762 | 1764 | ||
@@ -6999,15 +7001,15 @@ static void switched_from_fair(struct rq *rq, struct task_struct *p) | |||
6999 | struct cfs_rq *cfs_rq = cfs_rq_of(se); | 7001 | struct cfs_rq *cfs_rq = cfs_rq_of(se); |
7000 | 7002 | ||
7001 | /* | 7003 | /* |
7002 | * Ensure the task's vruntime is normalized, so that when its | 7004 | * Ensure the task's vruntime is normalized, so that when it's |
7003 | * switched back to the fair class the enqueue_entity(.flags=0) will | 7005 | * switched back to the fair class the enqueue_entity(.flags=0) will |
7004 | * do the right thing. | 7006 | * do the right thing. |
7005 | * | 7007 | * |
7006 | * If it was on_rq, then the dequeue_entity(.flags=0) will already | 7008 | * If it's on_rq, then the dequeue_entity(.flags=0) will already |
7007 | * have normalized the vruntime, if it was !on_rq, then only when | 7009 | * have normalized the vruntime, if it's !on_rq, then only when |
7008 | * the task is sleeping will it still have non-normalized vruntime. | 7010 | * the task is sleeping will it still have non-normalized vruntime. |
7009 | */ | 7011 | */ |
7010 | if (!se->on_rq && p->state != TASK_RUNNING) { | 7012 | if (!p->on_rq && p->state != TASK_RUNNING) { |
7011 | /* | 7013 | /* |
7012 | * Fix up our vruntime so that the current sleep doesn't | 7014 | * Fix up our vruntime so that the current sleep doesn't |
7013 | * cause 'unlimited' sleep bonus. | 7015 | * cause 'unlimited' sleep bonus. |
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index a2740b775b45..1999021042c7 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c | |||
@@ -538,6 +538,14 @@ static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq) | |||
538 | 538 | ||
539 | #endif /* CONFIG_RT_GROUP_SCHED */ | 539 | #endif /* CONFIG_RT_GROUP_SCHED */ |
540 | 540 | ||
541 | bool sched_rt_bandwidth_account(struct rt_rq *rt_rq) | ||
542 | { | ||
543 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); | ||
544 | |||
545 | return (hrtimer_active(&rt_b->rt_period_timer) || | ||
546 | rt_rq->rt_time < rt_b->rt_runtime); | ||
547 | } | ||
548 | |||
541 | #ifdef CONFIG_SMP | 549 | #ifdef CONFIG_SMP |
542 | /* | 550 | /* |
543 | * We ran out of runtime, see if we can borrow some from our neighbours. | 551 | * We ran out of runtime, see if we can borrow some from our neighbours. |
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index c2119fd20f8b..f964add50f38 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h | |||
@@ -462,7 +462,6 @@ struct dl_rq { | |||
462 | } earliest_dl; | 462 | } earliest_dl; |
463 | 463 | ||
464 | unsigned long dl_nr_migratory; | 464 | unsigned long dl_nr_migratory; |
465 | unsigned long dl_nr_total; | ||
466 | int overloaded; | 465 | int overloaded; |
467 | 466 | ||
468 | /* | 467 | /* |
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 84571e09c907..01fbae5b97b7 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c | |||
@@ -293,7 +293,7 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void * | |||
293 | */ | 293 | */ |
294 | smp_call_function_single(min(cpu1, cpu2), | 294 | smp_call_function_single(min(cpu1, cpu2), |
295 | &irq_cpu_stop_queue_work, | 295 | &irq_cpu_stop_queue_work, |
296 | &call_args, 0); | 296 | &call_args, 1); |
297 | lg_local_unlock(&stop_cpus_lock); | 297 | lg_local_unlock(&stop_cpus_lock); |
298 | preempt_enable(); | 298 | preempt_enable(); |
299 | 299 | ||
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c index 7a925ba456fb..a6a5bf53e86d 100644 --- a/kernel/time/jiffies.c +++ b/kernel/time/jiffies.c | |||
@@ -51,7 +51,13 @@ | |||
51 | * HZ shrinks, so values greater than 8 overflow 32bits when | 51 | * HZ shrinks, so values greater than 8 overflow 32bits when |
52 | * HZ=100. | 52 | * HZ=100. |
53 | */ | 53 | */ |
54 | #if HZ < 34 | ||
55 | #define JIFFIES_SHIFT 6 | ||
56 | #elif HZ < 67 | ||
57 | #define JIFFIES_SHIFT 7 | ||
58 | #else | ||
54 | #define JIFFIES_SHIFT 8 | 59 | #define JIFFIES_SHIFT 8 |
60 | #endif | ||
55 | 61 | ||
56 | static cycle_t jiffies_read(struct clocksource *cs) | 62 | static cycle_t jiffies_read(struct clocksource *cs) |
57 | { | 63 | { |
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 0abb36464281..4d23dc4d8139 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c | |||
@@ -116,20 +116,42 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt) | |||
116 | void __init sched_clock_register(u64 (*read)(void), int bits, | 116 | void __init sched_clock_register(u64 (*read)(void), int bits, |
117 | unsigned long rate) | 117 | unsigned long rate) |
118 | { | 118 | { |
119 | u64 res, wrap, new_mask, new_epoch, cyc, ns; | ||
120 | u32 new_mult, new_shift; | ||
121 | ktime_t new_wrap_kt; | ||
119 | unsigned long r; | 122 | unsigned long r; |
120 | u64 res, wrap; | ||
121 | char r_unit; | 123 | char r_unit; |
122 | 124 | ||
123 | if (cd.rate > rate) | 125 | if (cd.rate > rate) |
124 | return; | 126 | return; |
125 | 127 | ||
126 | WARN_ON(!irqs_disabled()); | 128 | WARN_ON(!irqs_disabled()); |
127 | read_sched_clock = read; | ||
128 | sched_clock_mask = CLOCKSOURCE_MASK(bits); | ||
129 | cd.rate = rate; | ||
130 | 129 | ||
131 | /* calculate the mult/shift to convert counter ticks to ns. */ | 130 | /* calculate the mult/shift to convert counter ticks to ns. */ |
132 | clocks_calc_mult_shift(&cd.mult, &cd.shift, rate, NSEC_PER_SEC, 3600); | 131 | clocks_calc_mult_shift(&new_mult, &new_shift, rate, NSEC_PER_SEC, 3600); |
132 | |||
133 | new_mask = CLOCKSOURCE_MASK(bits); | ||
134 | |||
135 | /* calculate how many ns until we wrap */ | ||
136 | wrap = clocks_calc_max_nsecs(new_mult, new_shift, 0, new_mask); | ||
137 | new_wrap_kt = ns_to_ktime(wrap - (wrap >> 3)); | ||
138 | |||
139 | /* update epoch for new counter and update epoch_ns from old counter*/ | ||
140 | new_epoch = read(); | ||
141 | cyc = read_sched_clock(); | ||
142 | ns = cd.epoch_ns + cyc_to_ns((cyc - cd.epoch_cyc) & sched_clock_mask, | ||
143 | cd.mult, cd.shift); | ||
144 | |||
145 | raw_write_seqcount_begin(&cd.seq); | ||
146 | read_sched_clock = read; | ||
147 | sched_clock_mask = new_mask; | ||
148 | cd.rate = rate; | ||
149 | cd.wrap_kt = new_wrap_kt; | ||
150 | cd.mult = new_mult; | ||
151 | cd.shift = new_shift; | ||
152 | cd.epoch_cyc = new_epoch; | ||
153 | cd.epoch_ns = ns; | ||
154 | raw_write_seqcount_end(&cd.seq); | ||
133 | 155 | ||
134 | r = rate; | 156 | r = rate; |
135 | if (r >= 4000000) { | 157 | if (r >= 4000000) { |
@@ -141,22 +163,12 @@ void __init sched_clock_register(u64 (*read)(void), int bits, | |||
141 | } else | 163 | } else |
142 | r_unit = ' '; | 164 | r_unit = ' '; |
143 | 165 | ||
144 | /* calculate how many ns until we wrap */ | ||
145 | wrap = clocks_calc_max_nsecs(cd.mult, cd.shift, 0, sched_clock_mask); | ||
146 | cd.wrap_kt = ns_to_ktime(wrap - (wrap >> 3)); | ||
147 | |||
148 | /* calculate the ns resolution of this counter */ | 166 | /* calculate the ns resolution of this counter */ |
149 | res = cyc_to_ns(1ULL, cd.mult, cd.shift); | 167 | res = cyc_to_ns(1ULL, new_mult, new_shift); |
168 | |||
150 | pr_info("sched_clock: %u bits at %lu%cHz, resolution %lluns, wraps every %lluns\n", | 169 | pr_info("sched_clock: %u bits at %lu%cHz, resolution %lluns, wraps every %lluns\n", |
151 | bits, r, r_unit, res, wrap); | 170 | bits, r, r_unit, res, wrap); |
152 | 171 | ||
153 | update_sched_clock(); | ||
154 | |||
155 | /* | ||
156 | * Ensure that sched_clock() starts off at 0ns | ||
157 | */ | ||
158 | cd.epoch_ns = 0; | ||
159 | |||
160 | /* Enable IRQ time accounting if we have a fast enough sched_clock */ | 172 | /* Enable IRQ time accounting if we have a fast enough sched_clock */ |
161 | if (irqtime > 0 || (irqtime == -1 && rate >= 1000000)) | 173 | if (irqtime > 0 || (irqtime == -1 && rate >= 1000000)) |
162 | enable_sched_clock_irqtime(); | 174 | enable_sched_clock_irqtime(); |
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index 43780ab5e279..98977a57ac72 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c | |||
@@ -756,6 +756,7 @@ out: | |||
756 | static void tick_broadcast_clear_oneshot(int cpu) | 756 | static void tick_broadcast_clear_oneshot(int cpu) |
757 | { | 757 | { |
758 | cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask); | 758 | cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask); |
759 | cpumask_clear_cpu(cpu, tick_broadcast_pending_mask); | ||
759 | } | 760 | } |
760 | 761 | ||
761 | static void tick_broadcast_init_next_event(struct cpumask *mask, | 762 | static void tick_broadcast_init_next_event(struct cpumask *mask, |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 0aa4ce81bc16..5b40279ecd71 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -1435,7 +1435,8 @@ void update_wall_time(void) | |||
1435 | out: | 1435 | out: |
1436 | raw_spin_unlock_irqrestore(&timekeeper_lock, flags); | 1436 | raw_spin_unlock_irqrestore(&timekeeper_lock, flags); |
1437 | if (clock_set) | 1437 | if (clock_set) |
1438 | clock_was_set(); | 1438 | /* Have to call _delayed version, since in irq context*/ |
1439 | clock_was_set_delayed(); | ||
1439 | } | 1440 | } |
1440 | 1441 | ||
1441 | /** | 1442 | /** |
diff --git a/kernel/torture.c b/kernel/torture.c new file mode 100644 index 000000000000..acc9afc2f26e --- /dev/null +++ b/kernel/torture.c | |||
@@ -0,0 +1,719 @@ | |||
1 | /* | ||
2 | * Common functions for in-kernel torture tests. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, you can access it online at | ||
16 | * http://www.gnu.org/licenses/gpl-2.0.html. | ||
17 | * | ||
18 | * Copyright (C) IBM Corporation, 2014 | ||
19 | * | ||
20 | * Author: Paul E. McKenney <paulmck@us.ibm.com> | ||
21 | * Based on kernel/rcu/torture.c. | ||
22 | */ | ||
23 | #include <linux/types.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/kthread.h> | ||
28 | #include <linux/err.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/smp.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <linux/atomic.h> | ||
34 | #include <linux/bitops.h> | ||
35 | #include <linux/completion.h> | ||
36 | #include <linux/moduleparam.h> | ||
37 | #include <linux/percpu.h> | ||
38 | #include <linux/notifier.h> | ||
39 | #include <linux/reboot.h> | ||
40 | #include <linux/freezer.h> | ||
41 | #include <linux/cpu.h> | ||
42 | #include <linux/delay.h> | ||
43 | #include <linux/stat.h> | ||
44 | #include <linux/slab.h> | ||
45 | #include <linux/trace_clock.h> | ||
46 | #include <asm/byteorder.h> | ||
47 | #include <linux/torture.h> | ||
48 | |||
49 | MODULE_LICENSE("GPL"); | ||
50 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>"); | ||
51 | |||
52 | static char *torture_type; | ||
53 | static bool verbose; | ||
54 | |||
55 | /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */ | ||
56 | #define FULLSTOP_DONTSTOP 0 /* Normal operation. */ | ||
57 | #define FULLSTOP_SHUTDOWN 1 /* System shutdown with torture running. */ | ||
58 | #define FULLSTOP_RMMOD 2 /* Normal rmmod of torture. */ | ||
59 | static int fullstop = FULLSTOP_RMMOD; | ||
60 | static DEFINE_MUTEX(fullstop_mutex); | ||
61 | static int *torture_runnable; | ||
62 | |||
63 | #ifdef CONFIG_HOTPLUG_CPU | ||
64 | |||
65 | /* | ||
66 | * Variables for online-offline handling. Only present if CPU hotplug | ||
67 | * is enabled, otherwise does nothing. | ||
68 | */ | ||
69 | |||
70 | static struct task_struct *onoff_task; | ||
71 | static long onoff_holdoff; | ||
72 | static long onoff_interval; | ||
73 | static long n_offline_attempts; | ||
74 | static long n_offline_successes; | ||
75 | static unsigned long sum_offline; | ||
76 | static int min_offline = -1; | ||
77 | static int max_offline; | ||
78 | static long n_online_attempts; | ||
79 | static long n_online_successes; | ||
80 | static unsigned long sum_online; | ||
81 | static int min_online = -1; | ||
82 | static int max_online; | ||
83 | |||
84 | /* | ||
85 | * Execute random CPU-hotplug operations at the interval specified | ||
86 | * by the onoff_interval. | ||
87 | */ | ||
88 | static int | ||
89 | torture_onoff(void *arg) | ||
90 | { | ||
91 | int cpu; | ||
92 | unsigned long delta; | ||
93 | int maxcpu = -1; | ||
94 | DEFINE_TORTURE_RANDOM(rand); | ||
95 | int ret; | ||
96 | unsigned long starttime; | ||
97 | |||
98 | VERBOSE_TOROUT_STRING("torture_onoff task started"); | ||
99 | for_each_online_cpu(cpu) | ||
100 | maxcpu = cpu; | ||
101 | WARN_ON(maxcpu < 0); | ||
102 | if (onoff_holdoff > 0) { | ||
103 | VERBOSE_TOROUT_STRING("torture_onoff begin holdoff"); | ||
104 | schedule_timeout_interruptible(onoff_holdoff); | ||
105 | VERBOSE_TOROUT_STRING("torture_onoff end holdoff"); | ||
106 | } | ||
107 | while (!torture_must_stop()) { | ||
108 | cpu = (torture_random(&rand) >> 4) % (maxcpu + 1); | ||
109 | if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) { | ||
110 | if (verbose) | ||
111 | pr_alert("%s" TORTURE_FLAG | ||
112 | "torture_onoff task: offlining %d\n", | ||
113 | torture_type, cpu); | ||
114 | starttime = jiffies; | ||
115 | n_offline_attempts++; | ||
116 | ret = cpu_down(cpu); | ||
117 | if (ret) { | ||
118 | if (verbose) | ||
119 | pr_alert("%s" TORTURE_FLAG | ||
120 | "torture_onoff task: offline %d failed: errno %d\n", | ||
121 | torture_type, cpu, ret); | ||
122 | } else { | ||
123 | if (verbose) | ||
124 | pr_alert("%s" TORTURE_FLAG | ||
125 | "torture_onoff task: offlined %d\n", | ||
126 | torture_type, cpu); | ||
127 | n_offline_successes++; | ||
128 | delta = jiffies - starttime; | ||
129 | sum_offline += delta; | ||
130 | if (min_offline < 0) { | ||
131 | min_offline = delta; | ||
132 | max_offline = delta; | ||
133 | } | ||
134 | if (min_offline > delta) | ||
135 | min_offline = delta; | ||
136 | if (max_offline < delta) | ||
137 | max_offline = delta; | ||
138 | } | ||
139 | } else if (cpu_is_hotpluggable(cpu)) { | ||
140 | if (verbose) | ||
141 | pr_alert("%s" TORTURE_FLAG | ||
142 | "torture_onoff task: onlining %d\n", | ||
143 | torture_type, cpu); | ||
144 | starttime = jiffies; | ||
145 | n_online_attempts++; | ||
146 | ret = cpu_up(cpu); | ||
147 | if (ret) { | ||
148 | if (verbose) | ||
149 | pr_alert("%s" TORTURE_FLAG | ||
150 | "torture_onoff task: online %d failed: errno %d\n", | ||
151 | torture_type, cpu, ret); | ||
152 | } else { | ||
153 | if (verbose) | ||
154 | pr_alert("%s" TORTURE_FLAG | ||
155 | "torture_onoff task: onlined %d\n", | ||
156 | torture_type, cpu); | ||
157 | n_online_successes++; | ||
158 | delta = jiffies - starttime; | ||
159 | sum_online += delta; | ||
160 | if (min_online < 0) { | ||
161 | min_online = delta; | ||
162 | max_online = delta; | ||
163 | } | ||
164 | if (min_online > delta) | ||
165 | min_online = delta; | ||
166 | if (max_online < delta) | ||
167 | max_online = delta; | ||
168 | } | ||
169 | } | ||
170 | schedule_timeout_interruptible(onoff_interval); | ||
171 | } | ||
172 | torture_kthread_stopping("torture_onoff"); | ||
173 | return 0; | ||
174 | } | ||
175 | |||
176 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
177 | |||
178 | /* | ||
179 | * Initiate online-offline handling. | ||
180 | */ | ||
181 | int torture_onoff_init(long ooholdoff, long oointerval) | ||
182 | { | ||
183 | int ret = 0; | ||
184 | |||
185 | #ifdef CONFIG_HOTPLUG_CPU | ||
186 | onoff_holdoff = ooholdoff; | ||
187 | onoff_interval = oointerval; | ||
188 | if (onoff_interval <= 0) | ||
189 | return 0; | ||
190 | ret = torture_create_kthread(torture_onoff, NULL, onoff_task); | ||
191 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
192 | return ret; | ||
193 | } | ||
194 | EXPORT_SYMBOL_GPL(torture_onoff_init); | ||
195 | |||
196 | /* | ||
197 | * Clean up after online/offline testing. | ||
198 | */ | ||
199 | static void torture_onoff_cleanup(void) | ||
200 | { | ||
201 | #ifdef CONFIG_HOTPLUG_CPU | ||
202 | if (onoff_task == NULL) | ||
203 | return; | ||
204 | VERBOSE_TOROUT_STRING("Stopping torture_onoff task"); | ||
205 | kthread_stop(onoff_task); | ||
206 | onoff_task = NULL; | ||
207 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
208 | } | ||
209 | EXPORT_SYMBOL_GPL(torture_onoff_cleanup); | ||
210 | |||
211 | /* | ||
212 | * Print online/offline testing statistics. | ||
213 | */ | ||
214 | char *torture_onoff_stats(char *page) | ||
215 | { | ||
216 | #ifdef CONFIG_HOTPLUG_CPU | ||
217 | page += sprintf(page, | ||
218 | "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ", | ||
219 | n_online_successes, n_online_attempts, | ||
220 | n_offline_successes, n_offline_attempts, | ||
221 | min_online, max_online, | ||
222 | min_offline, max_offline, | ||
223 | sum_online, sum_offline, HZ); | ||
224 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
225 | return page; | ||
226 | } | ||
227 | EXPORT_SYMBOL_GPL(torture_onoff_stats); | ||
228 | |||
229 | /* | ||
230 | * Were all the online/offline operations successful? | ||
231 | */ | ||
232 | bool torture_onoff_failures(void) | ||
233 | { | ||
234 | #ifdef CONFIG_HOTPLUG_CPU | ||
235 | return n_online_successes != n_online_attempts || | ||
236 | n_offline_successes != n_offline_attempts; | ||
237 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
238 | return false; | ||
239 | #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */ | ||
240 | } | ||
241 | EXPORT_SYMBOL_GPL(torture_onoff_failures); | ||
242 | |||
243 | #define TORTURE_RANDOM_MULT 39916801 /* prime */ | ||
244 | #define TORTURE_RANDOM_ADD 479001701 /* prime */ | ||
245 | #define TORTURE_RANDOM_REFRESH 10000 | ||
246 | |||
247 | /* | ||
248 | * Crude but fast random-number generator. Uses a linear congruential | ||
249 | * generator, with occasional help from cpu_clock(). | ||
250 | */ | ||
251 | unsigned long | ||
252 | torture_random(struct torture_random_state *trsp) | ||
253 | { | ||
254 | if (--trsp->trs_count < 0) { | ||
255 | trsp->trs_state += (unsigned long)local_clock(); | ||
256 | trsp->trs_count = TORTURE_RANDOM_REFRESH; | ||
257 | } | ||
258 | trsp->trs_state = trsp->trs_state * TORTURE_RANDOM_MULT + | ||
259 | TORTURE_RANDOM_ADD; | ||
260 | return swahw32(trsp->trs_state); | ||
261 | } | ||
262 | EXPORT_SYMBOL_GPL(torture_random); | ||
263 | |||
264 | /* | ||
265 | * Variables for shuffling. The idea is to ensure that each CPU stays | ||
266 | * idle for an extended period to test interactions with dyntick idle, | ||
267 | * as well as interactions with any per-CPU varibles. | ||
268 | */ | ||
269 | struct shuffle_task { | ||
270 | struct list_head st_l; | ||
271 | struct task_struct *st_t; | ||
272 | }; | ||
273 | |||
274 | static long shuffle_interval; /* In jiffies. */ | ||
275 | static struct task_struct *shuffler_task; | ||
276 | static cpumask_var_t shuffle_tmp_mask; | ||
277 | static int shuffle_idle_cpu; /* Force all torture tasks off this CPU */ | ||
278 | static struct list_head shuffle_task_list = LIST_HEAD_INIT(shuffle_task_list); | ||
279 | static DEFINE_MUTEX(shuffle_task_mutex); | ||
280 | |||
281 | /* | ||
282 | * Register a task to be shuffled. If there is no memory, just splat | ||
283 | * and don't bother registering. | ||
284 | */ | ||
285 | void torture_shuffle_task_register(struct task_struct *tp) | ||
286 | { | ||
287 | struct shuffle_task *stp; | ||
288 | |||
289 | if (WARN_ON_ONCE(tp == NULL)) | ||
290 | return; | ||
291 | stp = kmalloc(sizeof(*stp), GFP_KERNEL); | ||
292 | if (WARN_ON_ONCE(stp == NULL)) | ||
293 | return; | ||
294 | stp->st_t = tp; | ||
295 | mutex_lock(&shuffle_task_mutex); | ||
296 | list_add(&stp->st_l, &shuffle_task_list); | ||
297 | mutex_unlock(&shuffle_task_mutex); | ||
298 | } | ||
299 | EXPORT_SYMBOL_GPL(torture_shuffle_task_register); | ||
300 | |||
301 | /* | ||
302 | * Unregister all tasks, for example, at the end of the torture run. | ||
303 | */ | ||
304 | static void torture_shuffle_task_unregister_all(void) | ||
305 | { | ||
306 | struct shuffle_task *stp; | ||
307 | struct shuffle_task *p; | ||
308 | |||
309 | mutex_lock(&shuffle_task_mutex); | ||
310 | list_for_each_entry_safe(stp, p, &shuffle_task_list, st_l) { | ||
311 | list_del(&stp->st_l); | ||
312 | kfree(stp); | ||
313 | } | ||
314 | mutex_unlock(&shuffle_task_mutex); | ||
315 | } | ||
316 | |||
317 | /* Shuffle tasks such that we allow shuffle_idle_cpu to become idle. | ||
318 | * A special case is when shuffle_idle_cpu = -1, in which case we allow | ||
319 | * the tasks to run on all CPUs. | ||
320 | */ | ||
321 | static void torture_shuffle_tasks(void) | ||
322 | { | ||
323 | struct shuffle_task *stp; | ||
324 | |||
325 | cpumask_setall(shuffle_tmp_mask); | ||
326 | get_online_cpus(); | ||
327 | |||
328 | /* No point in shuffling if there is only one online CPU (ex: UP) */ | ||
329 | if (num_online_cpus() == 1) { | ||
330 | put_online_cpus(); | ||
331 | return; | ||
332 | } | ||
333 | |||
334 | /* Advance to the next CPU. Upon overflow, don't idle any CPUs. */ | ||
335 | shuffle_idle_cpu = cpumask_next(shuffle_idle_cpu, shuffle_tmp_mask); | ||
336 | if (shuffle_idle_cpu >= nr_cpu_ids) | ||
337 | shuffle_idle_cpu = -1; | ||
338 | if (shuffle_idle_cpu != -1) { | ||
339 | cpumask_clear_cpu(shuffle_idle_cpu, shuffle_tmp_mask); | ||
340 | if (cpumask_empty(shuffle_tmp_mask)) { | ||
341 | put_online_cpus(); | ||
342 | return; | ||
343 | } | ||
344 | } | ||
345 | |||
346 | mutex_lock(&shuffle_task_mutex); | ||
347 | list_for_each_entry(stp, &shuffle_task_list, st_l) | ||
348 | set_cpus_allowed_ptr(stp->st_t, shuffle_tmp_mask); | ||
349 | mutex_unlock(&shuffle_task_mutex); | ||
350 | |||
351 | put_online_cpus(); | ||
352 | } | ||
353 | |||
354 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the | ||
355 | * system to become idle at a time and cut off its timer ticks. This is meant | ||
356 | * to test the support for such tickless idle CPU in RCU. | ||
357 | */ | ||
358 | static int torture_shuffle(void *arg) | ||
359 | { | ||
360 | VERBOSE_TOROUT_STRING("torture_shuffle task started"); | ||
361 | do { | ||
362 | schedule_timeout_interruptible(shuffle_interval); | ||
363 | torture_shuffle_tasks(); | ||
364 | torture_shutdown_absorb("torture_shuffle"); | ||
365 | } while (!torture_must_stop()); | ||
366 | torture_kthread_stopping("torture_shuffle"); | ||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | /* | ||
371 | * Start the shuffler, with shuffint in jiffies. | ||
372 | */ | ||
373 | int torture_shuffle_init(long shuffint) | ||
374 | { | ||
375 | shuffle_interval = shuffint; | ||
376 | |||
377 | shuffle_idle_cpu = -1; | ||
378 | |||
379 | if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) { | ||
380 | VERBOSE_TOROUT_ERRSTRING("Failed to alloc mask"); | ||
381 | return -ENOMEM; | ||
382 | } | ||
383 | |||
384 | /* Create the shuffler thread */ | ||
385 | return torture_create_kthread(torture_shuffle, NULL, shuffler_task); | ||
386 | } | ||
387 | EXPORT_SYMBOL_GPL(torture_shuffle_init); | ||
388 | |||
389 | /* | ||
390 | * Stop the shuffling. | ||
391 | */ | ||
392 | static void torture_shuffle_cleanup(void) | ||
393 | { | ||
394 | torture_shuffle_task_unregister_all(); | ||
395 | if (shuffler_task) { | ||
396 | VERBOSE_TOROUT_STRING("Stopping torture_shuffle task"); | ||
397 | kthread_stop(shuffler_task); | ||
398 | free_cpumask_var(shuffle_tmp_mask); | ||
399 | } | ||
400 | shuffler_task = NULL; | ||
401 | } | ||
402 | EXPORT_SYMBOL_GPL(torture_shuffle_cleanup); | ||
403 | |||
404 | /* | ||
405 | * Variables for auto-shutdown. This allows "lights out" torture runs | ||
406 | * to be fully scripted. | ||
407 | */ | ||
408 | static int shutdown_secs; /* desired test duration in seconds. */ | ||
409 | static struct task_struct *shutdown_task; | ||
410 | static unsigned long shutdown_time; /* jiffies to system shutdown. */ | ||
411 | static void (*torture_shutdown_hook)(void); | ||
412 | |||
413 | /* | ||
414 | * Absorb kthreads into a kernel function that won't return, so that | ||
415 | * they won't ever access module text or data again. | ||
416 | */ | ||
417 | void torture_shutdown_absorb(const char *title) | ||
418 | { | ||
419 | while (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { | ||
420 | pr_notice("torture thread %s parking due to system shutdown\n", | ||
421 | title); | ||
422 | schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); | ||
423 | } | ||
424 | } | ||
425 | EXPORT_SYMBOL_GPL(torture_shutdown_absorb); | ||
426 | |||
427 | /* | ||
428 | * Cause the torture test to shutdown the system after the test has | ||
429 | * run for the time specified by the shutdown_secs parameter. | ||
430 | */ | ||
431 | static int torture_shutdown(void *arg) | ||
432 | { | ||
433 | long delta; | ||
434 | unsigned long jiffies_snap; | ||
435 | |||
436 | VERBOSE_TOROUT_STRING("torture_shutdown task started"); | ||
437 | jiffies_snap = jiffies; | ||
438 | while (ULONG_CMP_LT(jiffies_snap, shutdown_time) && | ||
439 | !torture_must_stop()) { | ||
440 | delta = shutdown_time - jiffies_snap; | ||
441 | if (verbose) | ||
442 | pr_alert("%s" TORTURE_FLAG | ||
443 | "torture_shutdown task: %lu jiffies remaining\n", | ||
444 | torture_type, delta); | ||
445 | schedule_timeout_interruptible(delta); | ||
446 | jiffies_snap = jiffies; | ||
447 | } | ||
448 | if (torture_must_stop()) { | ||
449 | torture_kthread_stopping("torture_shutdown"); | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | /* OK, shut down the system. */ | ||
454 | |||
455 | VERBOSE_TOROUT_STRING("torture_shutdown task shutting down system"); | ||
456 | shutdown_task = NULL; /* Avoid self-kill deadlock. */ | ||
457 | if (torture_shutdown_hook) | ||
458 | torture_shutdown_hook(); | ||
459 | else | ||
460 | VERBOSE_TOROUT_STRING("No torture_shutdown_hook(), skipping."); | ||
461 | kernel_power_off(); /* Shut down the system. */ | ||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | /* | ||
466 | * Start up the shutdown task. | ||
467 | */ | ||
468 | int torture_shutdown_init(int ssecs, void (*cleanup)(void)) | ||
469 | { | ||
470 | int ret = 0; | ||
471 | |||
472 | shutdown_secs = ssecs; | ||
473 | torture_shutdown_hook = cleanup; | ||
474 | if (shutdown_secs > 0) { | ||
475 | shutdown_time = jiffies + shutdown_secs * HZ; | ||
476 | ret = torture_create_kthread(torture_shutdown, NULL, | ||
477 | shutdown_task); | ||
478 | } | ||
479 | return ret; | ||
480 | } | ||
481 | EXPORT_SYMBOL_GPL(torture_shutdown_init); | ||
482 | |||
483 | /* | ||
484 | * Detect and respond to a system shutdown. | ||
485 | */ | ||
486 | static int torture_shutdown_notify(struct notifier_block *unused1, | ||
487 | unsigned long unused2, void *unused3) | ||
488 | { | ||
489 | mutex_lock(&fullstop_mutex); | ||
490 | if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) { | ||
491 | VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected"); | ||
492 | ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN; | ||
493 | } else { | ||
494 | pr_warn("Concurrent rmmod and shutdown illegal!\n"); | ||
495 | } | ||
496 | mutex_unlock(&fullstop_mutex); | ||
497 | return NOTIFY_DONE; | ||
498 | } | ||
499 | |||
500 | static struct notifier_block torture_shutdown_nb = { | ||
501 | .notifier_call = torture_shutdown_notify, | ||
502 | }; | ||
503 | |||
504 | /* | ||
505 | * Shut down the shutdown task. Say what??? Heh! This can happen if | ||
506 | * the torture module gets an rmmod before the shutdown time arrives. ;-) | ||
507 | */ | ||
508 | static void torture_shutdown_cleanup(void) | ||
509 | { | ||
510 | unregister_reboot_notifier(&torture_shutdown_nb); | ||
511 | if (shutdown_task != NULL) { | ||
512 | VERBOSE_TOROUT_STRING("Stopping torture_shutdown task"); | ||
513 | kthread_stop(shutdown_task); | ||
514 | } | ||
515 | shutdown_task = NULL; | ||
516 | } | ||
517 | |||
518 | /* | ||
519 | * Variables for stuttering, which means to periodically pause and | ||
520 | * restart testing in order to catch bugs that appear when load is | ||
521 | * suddenly applied to or removed from the system. | ||
522 | */ | ||
523 | static struct task_struct *stutter_task; | ||
524 | static int stutter_pause_test; | ||
525 | static int stutter; | ||
526 | |||
527 | /* | ||
528 | * Block until the stutter interval ends. This must be called periodically | ||
529 | * by all running kthreads that need to be subject to stuttering. | ||
530 | */ | ||
531 | void stutter_wait(const char *title) | ||
532 | { | ||
533 | while (ACCESS_ONCE(stutter_pause_test) || | ||
534 | (torture_runnable && !ACCESS_ONCE(*torture_runnable))) { | ||
535 | if (stutter_pause_test) | ||
536 | schedule_timeout_interruptible(1); | ||
537 | else | ||
538 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); | ||
539 | torture_shutdown_absorb(title); | ||
540 | } | ||
541 | } | ||
542 | EXPORT_SYMBOL_GPL(stutter_wait); | ||
543 | |||
544 | /* | ||
545 | * Cause the torture test to "stutter", starting and stopping all | ||
546 | * threads periodically. | ||
547 | */ | ||
548 | static int torture_stutter(void *arg) | ||
549 | { | ||
550 | VERBOSE_TOROUT_STRING("torture_stutter task started"); | ||
551 | do { | ||
552 | if (!torture_must_stop()) { | ||
553 | schedule_timeout_interruptible(stutter); | ||
554 | ACCESS_ONCE(stutter_pause_test) = 1; | ||
555 | } | ||
556 | if (!torture_must_stop()) | ||
557 | schedule_timeout_interruptible(stutter); | ||
558 | ACCESS_ONCE(stutter_pause_test) = 0; | ||
559 | torture_shutdown_absorb("torture_stutter"); | ||
560 | } while (!torture_must_stop()); | ||
561 | torture_kthread_stopping("torture_stutter"); | ||
562 | return 0; | ||
563 | } | ||
564 | |||
565 | /* | ||
566 | * Initialize and kick off the torture_stutter kthread. | ||
567 | */ | ||
568 | int torture_stutter_init(int s) | ||
569 | { | ||
570 | int ret; | ||
571 | |||
572 | stutter = s; | ||
573 | ret = torture_create_kthread(torture_stutter, NULL, stutter_task); | ||
574 | return ret; | ||
575 | } | ||
576 | EXPORT_SYMBOL_GPL(torture_stutter_init); | ||
577 | |||
578 | /* | ||
579 | * Cleanup after the torture_stutter kthread. | ||
580 | */ | ||
581 | static void torture_stutter_cleanup(void) | ||
582 | { | ||
583 | if (!stutter_task) | ||
584 | return; | ||
585 | VERBOSE_TOROUT_STRING("Stopping torture_stutter task"); | ||
586 | kthread_stop(stutter_task); | ||
587 | stutter_task = NULL; | ||
588 | } | ||
589 | |||
590 | /* | ||
591 | * Initialize torture module. Please note that this is -not- invoked via | ||
592 | * the usual module_init() mechanism, but rather by an explicit call from | ||
593 | * the client torture module. This call must be paired with a later | ||
594 | * torture_init_end(). | ||
595 | * | ||
596 | * The runnable parameter points to a flag that controls whether or not | ||
597 | * the test is currently runnable. If there is no such flag, pass in NULL. | ||
598 | */ | ||
599 | void __init torture_init_begin(char *ttype, bool v, int *runnable) | ||
600 | { | ||
601 | mutex_lock(&fullstop_mutex); | ||
602 | torture_type = ttype; | ||
603 | verbose = v; | ||
604 | torture_runnable = runnable; | ||
605 | fullstop = FULLSTOP_DONTSTOP; | ||
606 | |||
607 | } | ||
608 | EXPORT_SYMBOL_GPL(torture_init_begin); | ||
609 | |||
610 | /* | ||
611 | * Tell the torture module that initialization is complete. | ||
612 | */ | ||
613 | void __init torture_init_end(void) | ||
614 | { | ||
615 | mutex_unlock(&fullstop_mutex); | ||
616 | register_reboot_notifier(&torture_shutdown_nb); | ||
617 | } | ||
618 | EXPORT_SYMBOL_GPL(torture_init_end); | ||
619 | |||
620 | /* | ||
621 | * Clean up torture module. Please note that this is -not- invoked via | ||
622 | * the usual module_exit() mechanism, but rather by an explicit call from | ||
623 | * the client torture module. Returns true if a race with system shutdown | ||
624 | * is detected, otherwise, all kthreads started by functions in this file | ||
625 | * will be shut down. | ||
626 | * | ||
627 | * This must be called before the caller starts shutting down its own | ||
628 | * kthreads. | ||
629 | */ | ||
630 | bool torture_cleanup(void) | ||
631 | { | ||
632 | mutex_lock(&fullstop_mutex); | ||
633 | if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { | ||
634 | pr_warn("Concurrent rmmod and shutdown illegal!\n"); | ||
635 | mutex_unlock(&fullstop_mutex); | ||
636 | schedule_timeout_uninterruptible(10); | ||
637 | return true; | ||
638 | } | ||
639 | ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD; | ||
640 | mutex_unlock(&fullstop_mutex); | ||
641 | torture_shutdown_cleanup(); | ||
642 | torture_shuffle_cleanup(); | ||
643 | torture_stutter_cleanup(); | ||
644 | torture_onoff_cleanup(); | ||
645 | return false; | ||
646 | } | ||
647 | EXPORT_SYMBOL_GPL(torture_cleanup); | ||
648 | |||
649 | /* | ||
650 | * Is it time for the current torture test to stop? | ||
651 | */ | ||
652 | bool torture_must_stop(void) | ||
653 | { | ||
654 | return torture_must_stop_irq() || kthread_should_stop(); | ||
655 | } | ||
656 | EXPORT_SYMBOL_GPL(torture_must_stop); | ||
657 | |||
658 | /* | ||
659 | * Is it time for the current torture test to stop? This is the irq-safe | ||
660 | * version, hence no check for kthread_should_stop(). | ||
661 | */ | ||
662 | bool torture_must_stop_irq(void) | ||
663 | { | ||
664 | return ACCESS_ONCE(fullstop) != FULLSTOP_DONTSTOP; | ||
665 | } | ||
666 | EXPORT_SYMBOL_GPL(torture_must_stop_irq); | ||
667 | |||
668 | /* | ||
669 | * Each kthread must wait for kthread_should_stop() before returning from | ||
670 | * its top-level function, otherwise segfaults ensue. This function | ||
671 | * prints a "stopping" message and waits for kthread_should_stop(), and | ||
672 | * should be called from all torture kthreads immediately prior to | ||
673 | * returning. | ||
674 | */ | ||
675 | void torture_kthread_stopping(char *title) | ||
676 | { | ||
677 | if (verbose) | ||
678 | VERBOSE_TOROUT_STRING(title); | ||
679 | while (!kthread_should_stop()) { | ||
680 | torture_shutdown_absorb(title); | ||
681 | schedule_timeout_uninterruptible(1); | ||
682 | } | ||
683 | } | ||
684 | EXPORT_SYMBOL_GPL(torture_kthread_stopping); | ||
685 | |||
686 | /* | ||
687 | * Create a generic torture kthread that is immediately runnable. If you | ||
688 | * need the kthread to be stopped so that you can do something to it before | ||
689 | * it starts, you will need to open-code your own. | ||
690 | */ | ||
691 | int _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, | ||
692 | char *f, struct task_struct **tp) | ||
693 | { | ||
694 | int ret = 0; | ||
695 | |||
696 | VERBOSE_TOROUT_STRING(m); | ||
697 | *tp = kthread_run(fn, arg, s); | ||
698 | if (IS_ERR(*tp)) { | ||
699 | ret = PTR_ERR(*tp); | ||
700 | VERBOSE_TOROUT_ERRSTRING(f); | ||
701 | *tp = NULL; | ||
702 | } | ||
703 | torture_shuffle_task_register(*tp); | ||
704 | return ret; | ||
705 | } | ||
706 | EXPORT_SYMBOL_GPL(_torture_create_kthread); | ||
707 | |||
708 | /* | ||
709 | * Stop a generic kthread, emitting a message. | ||
710 | */ | ||
711 | void _torture_stop_kthread(char *m, struct task_struct **tp) | ||
712 | { | ||
713 | if (*tp == NULL) | ||
714 | return; | ||
715 | VERBOSE_TOROUT_STRING(m); | ||
716 | kthread_stop(*tp); | ||
717 | *tp = NULL; | ||
718 | } | ||
719 | EXPORT_SYMBOL_GPL(_torture_stop_kthread); | ||
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 294b8a271a04..fc4da2d97f9b 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
@@ -2397,6 +2397,13 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, | |||
2397 | write &= RB_WRITE_MASK; | 2397 | write &= RB_WRITE_MASK; |
2398 | tail = write - length; | 2398 | tail = write - length; |
2399 | 2399 | ||
2400 | /* | ||
2401 | * If this is the first commit on the page, then it has the same | ||
2402 | * timestamp as the page itself. | ||
2403 | */ | ||
2404 | if (!tail) | ||
2405 | delta = 0; | ||
2406 | |||
2400 | /* See if we shot pass the end of this buffer page */ | 2407 | /* See if we shot pass the end of this buffer page */ |
2401 | if (unlikely(write > BUF_PAGE_SIZE)) | 2408 | if (unlikely(write > BUF_PAGE_SIZE)) |
2402 | return rb_move_tail(cpu_buffer, length, tail, | 2409 | return rb_move_tail(cpu_buffer, length, tail, |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 815c878f409b..24c1f2382557 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -1600,15 +1600,31 @@ void trace_buffer_unlock_commit(struct ring_buffer *buffer, | |||
1600 | } | 1600 | } |
1601 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); | 1601 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
1602 | 1602 | ||
1603 | static struct ring_buffer *temp_buffer; | ||
1604 | |||
1603 | struct ring_buffer_event * | 1605 | struct ring_buffer_event * |
1604 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, | 1606 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
1605 | struct ftrace_event_file *ftrace_file, | 1607 | struct ftrace_event_file *ftrace_file, |
1606 | int type, unsigned long len, | 1608 | int type, unsigned long len, |
1607 | unsigned long flags, int pc) | 1609 | unsigned long flags, int pc) |
1608 | { | 1610 | { |
1611 | struct ring_buffer_event *entry; | ||
1612 | |||
1609 | *current_rb = ftrace_file->tr->trace_buffer.buffer; | 1613 | *current_rb = ftrace_file->tr->trace_buffer.buffer; |
1610 | return trace_buffer_lock_reserve(*current_rb, | 1614 | entry = trace_buffer_lock_reserve(*current_rb, |
1611 | type, len, flags, pc); | 1615 | type, len, flags, pc); |
1616 | /* | ||
1617 | * If tracing is off, but we have triggers enabled | ||
1618 | * we still need to look at the event data. Use the temp_buffer | ||
1619 | * to store the trace event for the tigger to use. It's recusive | ||
1620 | * safe and will not be recorded anywhere. | ||
1621 | */ | ||
1622 | if (!entry && ftrace_file->flags & FTRACE_EVENT_FL_TRIGGER_COND) { | ||
1623 | *current_rb = temp_buffer; | ||
1624 | entry = trace_buffer_lock_reserve(*current_rb, | ||
1625 | type, len, flags, pc); | ||
1626 | } | ||
1627 | return entry; | ||
1612 | } | 1628 | } |
1613 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); | 1629 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
1614 | 1630 | ||
@@ -6494,11 +6510,16 @@ __init static int tracer_alloc_buffers(void) | |||
6494 | 6510 | ||
6495 | raw_spin_lock_init(&global_trace.start_lock); | 6511 | raw_spin_lock_init(&global_trace.start_lock); |
6496 | 6512 | ||
6513 | /* Used for event triggers */ | ||
6514 | temp_buffer = ring_buffer_alloc(PAGE_SIZE, RB_FL_OVERWRITE); | ||
6515 | if (!temp_buffer) | ||
6516 | goto out_free_cpumask; | ||
6517 | |||
6497 | /* TODO: make the number of buffers hot pluggable with CPUS */ | 6518 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
6498 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { | 6519 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
6499 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); | 6520 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
6500 | WARN_ON(1); | 6521 | WARN_ON(1); |
6501 | goto out_free_cpumask; | 6522 | goto out_free_temp_buffer; |
6502 | } | 6523 | } |
6503 | 6524 | ||
6504 | if (global_trace.buffer_disabled) | 6525 | if (global_trace.buffer_disabled) |
@@ -6540,6 +6561,8 @@ __init static int tracer_alloc_buffers(void) | |||
6540 | 6561 | ||
6541 | return 0; | 6562 | return 0; |
6542 | 6563 | ||
6564 | out_free_temp_buffer: | ||
6565 | ring_buffer_free(temp_buffer); | ||
6543 | out_free_cpumask: | 6566 | out_free_cpumask: |
6544 | free_percpu(global_trace.trace_buffer.data); | 6567 | free_percpu(global_trace.trace_buffer.data); |
6545 | #ifdef CONFIG_TRACER_MAX_TRACE | 6568 | #ifdef CONFIG_TRACER_MAX_TRACE |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index e71ffd4eccb5..7b16d40bd64d 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -27,12 +27,6 @@ | |||
27 | 27 | ||
28 | DEFINE_MUTEX(event_mutex); | 28 | DEFINE_MUTEX(event_mutex); |
29 | 29 | ||
30 | DEFINE_MUTEX(event_storage_mutex); | ||
31 | EXPORT_SYMBOL_GPL(event_storage_mutex); | ||
32 | |||
33 | char event_storage[EVENT_STORAGE_SIZE]; | ||
34 | EXPORT_SYMBOL_GPL(event_storage); | ||
35 | |||
36 | LIST_HEAD(ftrace_events); | 30 | LIST_HEAD(ftrace_events); |
37 | static LIST_HEAD(ftrace_common_fields); | 31 | static LIST_HEAD(ftrace_common_fields); |
38 | 32 | ||
@@ -1777,6 +1771,16 @@ static void trace_module_add_events(struct module *mod) | |||
1777 | { | 1771 | { |
1778 | struct ftrace_event_call **call, **start, **end; | 1772 | struct ftrace_event_call **call, **start, **end; |
1779 | 1773 | ||
1774 | if (!mod->num_trace_events) | ||
1775 | return; | ||
1776 | |||
1777 | /* Don't add infrastructure for mods without tracepoints */ | ||
1778 | if (trace_module_has_bad_taint(mod)) { | ||
1779 | pr_err("%s: module has bad taint, not creating trace events\n", | ||
1780 | mod->name); | ||
1781 | return; | ||
1782 | } | ||
1783 | |||
1780 | start = mod->trace_events; | 1784 | start = mod->trace_events; |
1781 | end = mod->trace_events + mod->num_trace_events; | 1785 | end = mod->trace_events + mod->num_trace_events; |
1782 | 1786 | ||
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c index 7c3e3e72e2b6..ee0a5098ac43 100644 --- a/kernel/trace/trace_export.c +++ b/kernel/trace/trace_export.c | |||
@@ -95,15 +95,12 @@ static void __always_unused ____ftrace_check_##name(void) \ | |||
95 | #undef __array | 95 | #undef __array |
96 | #define __array(type, item, len) \ | 96 | #define __array(type, item, len) \ |
97 | do { \ | 97 | do { \ |
98 | char *type_str = #type"["__stringify(len)"]"; \ | ||
98 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ | 99 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ |
99 | mutex_lock(&event_storage_mutex); \ | 100 | ret = trace_define_field(event_call, type_str, #item, \ |
100 | snprintf(event_storage, sizeof(event_storage), \ | ||
101 | "%s[%d]", #type, len); \ | ||
102 | ret = trace_define_field(event_call, event_storage, #item, \ | ||
103 | offsetof(typeof(field), item), \ | 101 | offsetof(typeof(field), item), \ |
104 | sizeof(field.item), \ | 102 | sizeof(field.item), \ |
105 | is_signed_type(type), filter_type); \ | 103 | is_signed_type(type), filter_type); \ |
106 | mutex_unlock(&event_storage_mutex); \ | ||
107 | if (ret) \ | 104 | if (ret) \ |
108 | return ret; \ | 105 | return ret; \ |
109 | } while (0); | 106 | } while (0); |
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 29f26540e9c9..031cc5655a51 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c | |||
@@ -631,6 +631,11 @@ void tracepoint_iter_reset(struct tracepoint_iter *iter) | |||
631 | EXPORT_SYMBOL_GPL(tracepoint_iter_reset); | 631 | EXPORT_SYMBOL_GPL(tracepoint_iter_reset); |
632 | 632 | ||
633 | #ifdef CONFIG_MODULES | 633 | #ifdef CONFIG_MODULES |
634 | bool trace_module_has_bad_taint(struct module *mod) | ||
635 | { | ||
636 | return mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP)); | ||
637 | } | ||
638 | |||
634 | static int tracepoint_module_coming(struct module *mod) | 639 | static int tracepoint_module_coming(struct module *mod) |
635 | { | 640 | { |
636 | struct tp_module *tp_mod, *iter; | 641 | struct tp_module *tp_mod, *iter; |
@@ -641,7 +646,7 @@ static int tracepoint_module_coming(struct module *mod) | |||
641 | * module headers (for forced load), to make sure we don't cause a crash. | 646 | * module headers (for forced load), to make sure we don't cause a crash. |
642 | * Staging and out-of-tree GPL modules are fine. | 647 | * Staging and out-of-tree GPL modules are fine. |
643 | */ | 648 | */ |
644 | if (mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP))) | 649 | if (trace_module_has_bad_taint(mod)) |
645 | return 0; | 650 | return 0; |
646 | mutex_lock(&tracepoints_mutex); | 651 | mutex_lock(&tracepoints_mutex); |
647 | tp_mod = kmalloc(sizeof(struct tp_module), GFP_KERNEL); | 652 | tp_mod = kmalloc(sizeof(struct tp_module), GFP_KERNEL); |
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 240fb62cf394..dd06439b9c84 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
@@ -225,7 +225,7 @@ static u32 map_id_up(struct uid_gid_map *map, u32 id) | |||
225 | * | 225 | * |
226 | * When there is no mapping defined for the user-namespace uid | 226 | * When there is no mapping defined for the user-namespace uid |
227 | * pair INVALID_UID is returned. Callers are expected to test | 227 | * pair INVALID_UID is returned. Callers are expected to test |
228 | * for and handle handle INVALID_UID being returned. INVALID_UID | 228 | * for and handle INVALID_UID being returned. INVALID_UID |
229 | * may be tested for using uid_valid(). | 229 | * may be tested for using uid_valid(). |
230 | */ | 230 | */ |
231 | kuid_t make_kuid(struct user_namespace *ns, uid_t uid) | 231 | kuid_t make_kuid(struct user_namespace *ns, uid_t uid) |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 82ef9f3b7473..193e977a10ea 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -1851,6 +1851,12 @@ static void destroy_worker(struct worker *worker) | |||
1851 | if (worker->flags & WORKER_IDLE) | 1851 | if (worker->flags & WORKER_IDLE) |
1852 | pool->nr_idle--; | 1852 | pool->nr_idle--; |
1853 | 1853 | ||
1854 | /* | ||
1855 | * Once WORKER_DIE is set, the kworker may destroy itself at any | ||
1856 | * point. Pin to ensure the task stays until we're done with it. | ||
1857 | */ | ||
1858 | get_task_struct(worker->task); | ||
1859 | |||
1854 | list_del_init(&worker->entry); | 1860 | list_del_init(&worker->entry); |
1855 | worker->flags |= WORKER_DIE; | 1861 | worker->flags |= WORKER_DIE; |
1856 | 1862 | ||
@@ -1859,6 +1865,7 @@ static void destroy_worker(struct worker *worker) | |||
1859 | spin_unlock_irq(&pool->lock); | 1865 | spin_unlock_irq(&pool->lock); |
1860 | 1866 | ||
1861 | kthread_stop(worker->task); | 1867 | kthread_stop(worker->task); |
1868 | put_task_struct(worker->task); | ||
1862 | kfree(worker); | 1869 | kfree(worker); |
1863 | 1870 | ||
1864 | spin_lock_irq(&pool->lock); | 1871 | spin_lock_irq(&pool->lock); |