Showing the changes to kernel (47 of 1642 files). Show all
Unified · Split
| @@ -125,8 +125,12 @@ static int bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key, · 124 unmodified lines | ||
| 125 | 125 | |
| 126 | 126 | fd = *(int *)key; |
| 127 | 127 | f = fget_raw(fd); |
| 128 | − if (!f || !inode_storage_ptr(f->f_inode)) | |
| 128 | + if (!f) | |
| 129 | + return -EBADF; | |
| 130 | + if (!inode_storage_ptr(f->f_inode)) { | |
| 131 | + fput(f); | |
| 129 | 132 | return -EBADF; |
| 133 | + } | |
| 130 | 134 | |
| 131 | 135 | sdata = bpf_local_storage_update(f->f_inode, |
| 132 | 136 | (struct bpf_local_storage_map *)map, |
| @@ -176,14 +180,14 @@ BPF_CALL_4(bpf_inode_storage_get, struct bpf_map *, map, struct inode *, inode, · 43 unmodified lines | ||
| 176 | 180 | * bpf_local_storage_update expects the owner to have a |
| 177 | 181 | * valid storage pointer. |
| 178 | 182 | */ |
| 179 | − if (!inode_storage_ptr(inode)) | |
| 183 | + if (!inode || !inode_storage_ptr(inode)) | |
| 180 | 184 | return (unsigned long)NULL; |
| 181 | 185 | |
| 182 | 186 | sdata = inode_storage_lookup(inode, map, true); |
| 183 | 187 | if (sdata) |
| 184 | 188 | return (unsigned long)sdata->data; |
| 185 | 189 | |
| 186 | − /* This helper must only called from where the inode is gurranteed | |
| 190 | + /* This helper must only called from where the inode is guaranteed | |
| 187 | 191 | * to have a refcount and cannot be freed. |
| 188 | 192 | */ |
| 189 | 193 | if (flags & BPF_LOCAL_STORAGE_GET_F_CREATE) { |
| @@ -200,7 +204,10 @@ BPF_CALL_4(bpf_inode_storage_get, struct bpf_map *, map, struct inode *, inode, · 10 unmodified lines | ||
| 200 | 204 | BPF_CALL_2(bpf_inode_storage_delete, |
| 201 | 205 | struct bpf_map *, map, struct inode *, inode) |
| 202 | 206 | { |
| 203 | − /* This helper must only called from where the inode is gurranteed | |
| 207 | + if (!inode) | |
| 208 | + return -EINVAL; | |
| 209 | + | |
| 210 | + /* This helper must only called from where the inode is guaranteed | |
| 204 | 211 | * to have a refcount and cannot be freed. |
| 205 | 212 | */ |
| 206 | 213 | return inode_storage_delete(inode, map); |
| @@ -149,7 +149,11 @@ BTF_ID(func, bpf_lsm_file_ioctl) · 148 unmodified lines | ||
| 149 | 149 | BTF_ID(func, bpf_lsm_file_lock) |
| 150 | 150 | BTF_ID(func, bpf_lsm_file_open) |
| 151 | 151 | BTF_ID(func, bpf_lsm_file_receive) |
| 152 | + | |
| 153 | +#ifdef CONFIG_SECURITY_NETWORK | |
| 152 | 154 | BTF_ID(func, bpf_lsm_inet_conn_established) |
| 155 | +#endif /* CONFIG_SECURITY_NETWORK */ | |
| 156 | + | |
| 153 | 157 | BTF_ID(func, bpf_lsm_inode_create) |
| 154 | 158 | BTF_ID(func, bpf_lsm_inode_free_security) |
| 155 | 159 | BTF_ID(func, bpf_lsm_inode_getattr) |
| @@ -166,7 +170,11 @@ BTF_ID(func, bpf_lsm_inode_symlink) · 10 unmodified lines | ||
| 166 | 170 | BTF_ID(func, bpf_lsm_inode_unlink) |
| 167 | 171 | BTF_ID(func, bpf_lsm_kernel_module_request) |
| 168 | 172 | BTF_ID(func, bpf_lsm_kernfs_init_security) |
| 173 | + | |
| 174 | +#ifdef CONFIG_KEYS | |
| 169 | 175 | BTF_ID(func, bpf_lsm_key_free) |
| 176 | +#endif /* CONFIG_KEYS */ | |
| 177 | + | |
| 170 | 178 | BTF_ID(func, bpf_lsm_mmap_file) |
| 171 | 179 | BTF_ID(func, bpf_lsm_netlink_send) |
| 172 | 180 | BTF_ID(func, bpf_lsm_path_notify) |
| @@ -181,6 +189,8 @@ BTF_ID(func, bpf_lsm_sb_show_options) · 8 unmodified lines | ||
| 181 | 189 | BTF_ID(func, bpf_lsm_sb_statfs) |
| 182 | 190 | BTF_ID(func, bpf_lsm_sb_umount) |
| 183 | 191 | BTF_ID(func, bpf_lsm_settime) |
| 192 | + | |
| 193 | +#ifdef CONFIG_SECURITY_NETWORK | |
| 184 | 194 | BTF_ID(func, bpf_lsm_socket_accept) |
| 185 | 195 | BTF_ID(func, bpf_lsm_socket_bind) |
| 186 | 196 | BTF_ID(func, bpf_lsm_socket_connect) |
| @@ -195,6 +205,8 @@ BTF_ID(func, bpf_lsm_socket_recvmsg) · 8 unmodified lines | ||
| 195 | 205 | BTF_ID(func, bpf_lsm_socket_sendmsg) |
| 196 | 206 | BTF_ID(func, bpf_lsm_socket_shutdown) |
| 197 | 207 | BTF_ID(func, bpf_lsm_socket_socketpair) |
| 208 | +#endif /* CONFIG_SECURITY_NETWORK */ | |
| 209 | + | |
| 198 | 210 | BTF_ID(func, bpf_lsm_syslog) |
| 199 | 211 | BTF_ID(func, bpf_lsm_task_alloc) |
| 200 | 212 | BTF_ID(func, bpf_lsm_task_getsecid) |
| @@ -218,7 +218,7 @@ BPF_CALL_4(bpf_task_storage_get, struct bpf_map *, map, struct task_struct *, · 217 unmodified lines | ||
| 218 | 218 | * bpf_local_storage_update expects the owner to have a |
| 219 | 219 | * valid storage pointer. |
| 220 | 220 | */ |
| 221 | − if (!task_storage_ptr(task)) | |
| 221 | + if (!task || !task_storage_ptr(task)) | |
| 222 | 222 | return (unsigned long)NULL; |
| 223 | 223 | |
| 224 | 224 | sdata = task_storage_lookup(task, map, true); |
| @@ -243,6 +243,9 @@ BPF_CALL_4(bpf_task_storage_get, struct bpf_map *, map, struct task_struct *, · 18 unmodified lines | ||
| 243 | 243 | BPF_CALL_2(bpf_task_storage_delete, struct bpf_map *, map, struct task_struct *, |
| 244 | 244 | task) |
| 245 | 245 | { |
| 246 | + if (!task) | |
| 247 | + return -EINVAL; | |
| 248 | + | |
| 246 | 249 | /* This helper must only be called from places where the lifetime of the task |
| 247 | 250 | * is guaranteed. Either by being refcounted or by being protected |
| 248 | 251 | * by an RCU read-side critical section. |
| @@ -4172,7 +4172,7 @@ static int btf_parse_hdr(struct btf_verifier_env *env) · 4171 unmodified lines | ||
| 4172 | 4172 | return -ENOTSUPP; |
| 4173 | 4173 | } |
| 4174 | 4174 | |
| 4175 | − if (btf_data_size == hdr->hdr_len) { | |
| 4175 | + if (!btf->base_btf && btf_data_size == hdr->hdr_len) { | |
| 4176 | 4176 | btf_verifier_log(env, "No data"); |
| 4177 | 4177 | return -EINVAL; |
| 4178 | 4178 | } |
| @@ -1391,12 +1391,13 @@ int __cgroup_bpf_run_filter_setsockopt(struct sock *sk, int *level, · 1390 unmodified lines | ||
| 1391 | 1391 | if (ctx.optlen != 0) { |
| 1392 | 1392 | *optlen = ctx.optlen; |
| 1393 | 1393 | *kernel_optval = ctx.optval; |
| 1394 | + /* export and don't free sockopt buf */ | |
| 1395 | + return 0; | |
| 1394 | 1396 | } |
| 1395 | 1397 | } |
| 1396 | 1398 | |
| 1397 | 1399 | out: |
| 1398 | − if (ret) | |
| 1399 | − sockopt_free_buf(&ctx); | |
| 1400 | + sockopt_free_buf(&ctx); | |
| 1400 | 1401 | return ret; |
| 1401 | 1402 | } |
| 1402 | 1403 | |
| @@ -1441,6 +1442,11 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level, · 38 unmodified lines | ||
| 1441 | 1442 | goto out; |
| 1442 | 1443 | } |
| 1443 | 1444 | |
| 1445 | + if (ctx.optlen < 0) { | |
| 1446 | + ret = -EFAULT; | |
| 1447 | + goto out; | |
| 1448 | + } | |
| 1449 | + | |
| 1444 | 1450 | if (copy_from_user(ctx.optval, optval, |
| 1445 | 1451 | min(ctx.optlen, max_optlen)) != 0) { |
| 1446 | 1452 | ret = -EFAULT; |
| @@ -1458,7 +1464,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level, · 11 unmodified lines | ||
| 1458 | 1464 | goto out; |
| 1459 | 1465 | } |
| 1460 | 1466 | |
| 1461 | − if (ctx.optlen > max_optlen) { | |
| 1467 | + if (ctx.optlen > max_optlen || ctx.optlen < 0) { | |
| 1462 | 1468 | ret = -EFAULT; |
| 1463 | 1469 | goto out; |
| 1464 | 1470 | } |
| @@ -152,6 +152,7 @@ static void htab_init_buckets(struct bpf_htab *htab) · 151 unmodified lines | ||
| 152 | 152 | lockdep_set_class(&htab->buckets[i].lock, |
| 153 | 153 | &htab->lockdep_key); |
| 154 | 154 | } |
| 155 | + cond_resched(); | |
| 155 | 156 | } |
| 156 | 157 | } |
| 157 | 158 | |
| @@ -108,7 +108,7 @@ BPF_CALL_2(bpf_map_peek_elem, struct bpf_map *, map, void *, value) · 107 unmodified lines | ||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | const struct bpf_func_proto bpf_map_peek_elem_proto = { |
| 111 | − .func = bpf_map_pop_elem, | |
| 111 | + .func = bpf_map_peek_elem, | |
| 112 | 112 | .gpl_only = false, |
| 113 | 113 | .ret_type = RET_INTEGER, |
| 114 | 114 | .arg1_type = ARG_CONST_MAP_PTR, |
| @@ -4,8 +4,11 @@ LIBBPF_SRCS = $(srctree)/tools/lib/bpf/ · 3 unmodified lines | ||
| 4 | 4 | LIBBPF_A = $(obj)/libbpf.a |
| 5 | 5 | LIBBPF_OUT = $(abspath $(obj)) |
| 6 | 6 | |
| 7 | +# Although not in use by libbpf's Makefile, set $(O) so that the "dummy" test | |
| 8 | +# in tools/scripts/Makefile.include always succeeds when building the kernel | |
| 9 | +# with $(O) pointing to a relative path, as in "make O=build bindeb-pkg". | |
| 7 | 10 | $(LIBBPF_A): |
| 8 | − $(Q)$(MAKE) -C $(LIBBPF_SRCS) OUTPUT=$(LIBBPF_OUT)/ $(LIBBPF_OUT)/libbpf.a | |
| 11 | + $(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/ $(LIBBPF_OUT)/libbpf.a | |
| 9 | 12 | |
| 10 | 13 | userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi \ |
| 11 | 14 | -I $(srctree)/tools/lib/ -Wno-unused-result |
| @@ -115,6 +115,8 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr) · 114 unmodified lines | ||
| 115 | 115 | |
| 116 | 116 | /* hash table size must be power of 2 */ |
| 117 | 117 | n_buckets = roundup_pow_of_two(attr->max_entries); |
| 118 | + if (!n_buckets) | |
| 119 | + return ERR_PTR(-E2BIG); | |
| 118 | 120 | |
| 119 | 121 | cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); |
| 120 | 122 | cost += n_buckets * (value_size + sizeof(struct stack_map_bucket)); |
| @@ -17,7 +17,6 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <linux/fs.h> |
| 18 | 18 | #include <linux/license.h> |
| 19 | 19 | #include <linux/filter.h> |
| 20 | −#include <linux/version.h> | |
| 21 | 20 | #include <linux/kernel.h> |
| 22 | 21 | #include <linux/idr.h> |
| 23 | 22 | #include <linux/cred.h> |
| @@ -2713,7 +2712,6 @@ out_unlock: · 2689 unmodified lines | ||
| 2713 | 2712 | out_put_prog: |
| 2714 | 2713 | if (tgt_prog_fd && tgt_prog) |
| 2715 | 2714 | bpf_prog_put(tgt_prog); |
| 2716 | − bpf_prog_put(prog); | |
| 2717 | 2715 | return err; |
| 2718 | 2716 | } |
| 2719 | 2717 | |
| @@ -2826,7 +2824,10 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr) · 106 unmodified lines | ||
| 2826 | 2824 | tp_name = prog->aux->attach_func_name; |
| 2827 | 2825 | break; |
| 2828 | 2826 | } |
| 2829 | − return bpf_tracing_prog_attach(prog, 0, 0); | |
| 2827 | + err = bpf_tracing_prog_attach(prog, 0, 0); | |
| 2828 | + if (err >= 0) | |
| 2829 | + return err; | |
| 2830 | + goto out_put_prog; | |
| 2830 | 2831 | case BPF_PROG_TYPE_RAW_TRACEPOINT: |
| 2831 | 2832 | case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE: |
| 2832 | 2833 | if (strncpy_from_user(buf, |
| @@ -37,7 +37,7 @@ retry: · 36 unmodified lines | ||
| 37 | 37 | if (!task) { |
| 38 | 38 | ++*tid; |
| 39 | 39 | goto retry; |
| 40 | − } else if (skip_if_dup_files && task->tgid != task->pid && | |
| 40 | + } else if (skip_if_dup_files && !thread_group_leader(task) && | |
| 41 | 41 | task->files == task->group_leader->files) { |
| 42 | 42 | put_task_struct(task); |
| 43 | 43 | task = NULL; |
| @@ -151,13 +151,14 @@ again: · 107 unmodified lines | ||
| 151 | 151 | curr_task = info->task; |
| 152 | 152 | curr_fd = info->fd; |
| 153 | 153 | } else { |
| 154 | − curr_task = task_seq_get_next(ns, &curr_tid, true); | |
| 155 | − if (!curr_task) { | |
| 156 | − info->task = NULL; | |
| 157 | − return NULL; | |
| 158 | − } | |
| 159 | − | |
| 160 | − /* set info->task and info->tid */ | |
| 154 | + curr_task = task_seq_get_next(ns, &curr_tid, true); | |
| 155 | + if (!curr_task) { | |
| 156 | + info->task = NULL; | |
| 157 | + info->tid = curr_tid; | |
| 158 | + return NULL; | |
| 159 | + } | |
| 160 | + | |
| 161 | + /* set info->task and info->tid */ | |
| 161 | 162 | info->task = curr_task; |
| 162 | 163 | if (curr_tid == info->tid) { |
| 163 | 164 | curr_fd = info->fd; |
| @@ -2217,6 +2217,8 @@ static bool is_spillable_regtype(enum bpf_reg_type type) · 2216 unmodified lines | ||
| 2217 | 2217 | case PTR_TO_RDWR_BUF: |
| 2218 | 2218 | case PTR_TO_RDWR_BUF_OR_NULL: |
| 2219 | 2219 | case PTR_TO_PERCPU_BTF_ID: |
| 2220 | + case PTR_TO_MEM: | |
| 2221 | + case PTR_TO_MEM_OR_NULL: | |
| 2220 | 2222 | return true; |
| 2221 | 2223 | default: |
| 2222 | 2224 | return false; |
| @@ -5311,7 +5313,7 @@ static bool signed_add_overflows(s64 a, s64 b) · 3088 unmodified lines | ||
| 5311 | 5313 | return res < a; |
| 5312 | 5314 | } |
| 5313 | 5315 | |
| 5314 | −static bool signed_add32_overflows(s64 a, s64 b) | |
| 5316 | +static bool signed_add32_overflows(s32 a, s32 b) | |
| 5315 | 5317 | { |
| 5316 | 5318 | /* Do the add in u32, where overflow is well-defined */ |
| 5317 | 5319 | s32 res = (s32)((u32)a + (u32)b); |
| @@ -5321,7 +5323,7 @@ static bool signed_add32_overflows(s64 a, s64 b) · 3 unmodified lines | ||
| 5321 | 5323 | return res < a; |
| 5322 | 5324 | } |
| 5323 | 5325 | |
| 5324 | −static bool signed_sub_overflows(s32 a, s32 b) | |
| 5326 | +static bool signed_sub_overflows(s64 a, s64 b) | |
| 5325 | 5327 | { |
| 5326 | 5328 | /* Do the sub in u64, where overflow is well-defined */ |
| 5327 | 5329 | s64 res = (s64)((u64)a - (u64)b); |
| @@ -5333,7 +5335,7 @@ static bool signed_sub_overflows(s32 a, s32 b) · 5 unmodified lines | ||
| 5333 | 5335 | |
| 5334 | 5336 | static bool signed_sub32_overflows(s32 a, s32 b) |
| 5335 | 5337 | { |
| 5336 | − /* Do the sub in u64, where overflow is well-defined */ | |
| 5338 | + /* Do the sub in u32, where overflow is well-defined */ | |
| 5337 | 5339 | s32 res = (s32)((u32)a - (u32)b); |
| 5338 | 5340 | |
| 5339 | 5341 | if (b < 0) |
| @@ -6875,7 +6877,7 @@ static int is_branch32_taken(struct bpf_reg_state *reg, u32 val, u8 opcode) · 1535 unmodified lines | ||
| 6875 | 6877 | case BPF_JSGT: |
| 6876 | 6878 | if (reg->s32_min_value > sval) |
| 6877 | 6879 | return 1; |
| 6878 | − else if (reg->s32_max_value < sval) | |
| 6880 | + else if (reg->s32_max_value <= sval) | |
| 6879 | 6881 | return 0; |
| 6880 | 6882 | break; |
| 6881 | 6883 | case BPF_JLT: |
| @@ -6948,7 +6950,7 @@ static int is_branch64_taken(struct bpf_reg_state *reg, u64 val, u8 opcode) · 66 unmodified lines | ||
| 6948 | 6950 | case BPF_JSGT: |
| 6949 | 6951 | if (reg->smin_value > sval) |
| 6950 | 6952 | return 1; |
| 6951 | − else if (reg->smax_value < sval) | |
| 6953 | + else if (reg->smax_value <= sval) | |
| 6952 | 6954 | return 0; |
| 6953 | 6955 | break; |
| 6954 | 6956 | case BPF_JLT: |
| @@ -8588,7 +8590,11 @@ static bool range_within(struct bpf_reg_state *old, · 1633 unmodified lines | ||
| 8588 | 8590 | return old->umin_value <= cur->umin_value && |
| 8589 | 8591 | old->umax_value >= cur->umax_value && |
| 8590 | 8592 | old->smin_value <= cur->smin_value && |
| 8591 | − old->smax_value >= cur->smax_value; | |
| 8593 | + old->smax_value >= cur->smax_value && | |
| 8594 | + old->u32_min_value <= cur->u32_min_value && | |
| 8595 | + old->u32_max_value >= cur->u32_max_value && | |
| 8596 | + old->s32_min_value <= cur->s32_min_value && | |
| 8597 | + old->s32_max_value >= cur->s32_max_value; | |
| 8592 | 8598 | } |
| 8593 | 8599 | |
| 8594 | 8600 | /* Maximum number of register states that can exist at once */ |
| @@ -10997,30 +11003,28 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) · 2402 unmodified lines | ||
| 10997 | 11003 | insn->code == (BPF_ALU | BPF_MOD | BPF_X) || |
| 10998 | 11004 | insn->code == (BPF_ALU | BPF_DIV | BPF_X)) { |
| 10999 | 11005 | bool is64 = BPF_CLASS(insn->code) == BPF_ALU64; |
| 11000 | − struct bpf_insn mask_and_div[] = { | |
| 11001 | − BPF_MOV32_REG(insn->src_reg, insn->src_reg), | |
| 11006 | + bool isdiv = BPF_OP(insn->code) == BPF_DIV; | |
| 11007 | + struct bpf_insn *patchlet; | |
| 11008 | + struct bpf_insn chk_and_div[] = { | |
| 11002 | 11009 | /* Rx div 0 -> 0 */ |
| 11003 | − BPF_JMP_IMM(BPF_JNE, insn->src_reg, 0, 2), | |
| 11010 | + BPF_RAW_INSN((is64 ? BPF_JMP : BPF_JMP32) | | |
| 11011 | + BPF_JNE | BPF_K, insn->src_reg, | |
| 11012 | + 0, 2, 0), | |
| 11004 | 11013 | BPF_ALU32_REG(BPF_XOR, insn->dst_reg, insn->dst_reg), |
| 11005 | 11014 | BPF_JMP_IMM(BPF_JA, 0, 0, 1), |
| 11006 | 11015 | *insn, |
| 11007 | 11016 | }; |
| 11008 | − struct bpf_insn mask_and_mod[] = { | |
| 11009 | − BPF_MOV32_REG(insn->src_reg, insn->src_reg), | |
| 11017 | + struct bpf_insn chk_and_mod[] = { | |
| 11010 | 11018 | /* Rx mod 0 -> Rx */ |
| 11011 | − BPF_JMP_IMM(BPF_JEQ, insn->src_reg, 0, 1), | |
| 11019 | + BPF_RAW_INSN((is64 ? BPF_JMP : BPF_JMP32) | | |
| 11020 | + BPF_JEQ | BPF_K, insn->src_reg, | |
| 11021 | + 0, 1, 0), | |
| 11012 | 11022 | *insn, |
| 11013 | 11023 | }; |
| 11014 | − struct bpf_insn *patchlet; | |
| 11015 | 11024 | |
| 11016 | − if (insn->code == (BPF_ALU64 | BPF_DIV | BPF_X) || | |
| 11017 | − insn->code == (BPF_ALU | BPF_DIV | BPF_X)) { | |
| 11018 | − patchlet = mask_and_div + (is64 ? 1 : 0); | |
| 11019 | − cnt = ARRAY_SIZE(mask_and_div) - (is64 ? 1 : 0); | |
| 11020 | − } else { | |
| 11021 | − patchlet = mask_and_mod + (is64 ? 1 : 0); | |
| 11022 | − cnt = ARRAY_SIZE(mask_and_mod) - (is64 ? 1 : 0); | |
| 11023 | − } | |
| 11025 | + patchlet = isdiv ? chk_and_div : chk_and_mod; | |
| 11026 | + cnt = isdiv ? ARRAY_SIZE(chk_and_div) : | |
| 11027 | + ARRAY_SIZE(chk_and_mod); | |
| 11024 | 11028 | |
| 11025 | 11029 | new_prog = bpf_patch_insn_data(env, i + delta, patchlet, cnt); |
| 11026 | 11030 | if (!new_prog) |
| @@ -917,6 +917,9 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param) · 916 unmodified lines | ||
| 917 | 917 | for_each_subsys(ss, i) { |
| 918 | 918 | if (strcmp(param->key, ss->legacy_name)) |
| 919 | 919 | continue; |
| 920 | + if (!cgroup_ssid_enabled(i) || cgroup1_ssid_disabled(i)) | |
| 921 | + return invalfc(fc, "Disabled controller '%s'", | |
| 922 | + param->key); | |
| 920 | 923 | ctx->subsys_mask |= (1 << i); |
| 921 | 924 | return 0; |
| 922 | 925 | } |
| @@ -3564,6 +3564,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf, · 3563 unmodified lines | ||
| 3564 | 3564 | { |
| 3565 | 3565 | struct psi_trigger *new; |
| 3566 | 3566 | struct cgroup *cgrp; |
| 3567 | + struct psi_group *psi; | |
| 3567 | 3568 | |
| 3568 | 3569 | cgrp = cgroup_kn_lock_live(of->kn, false); |
| 3569 | 3570 | if (!cgrp) |
| @@ -3572,7 +3573,8 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf, · 2 unmodified lines | ||
| 3572 | 3573 | cgroup_get(cgrp); |
| 3573 | 3574 | cgroup_kn_unlock(of->kn); |
| 3574 | 3575 | |
| 3575 | − new = psi_trigger_create(&cgrp->psi, buf, nbytes, res); | |
| 3576 | + psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi; | |
| 3577 | + new = psi_trigger_create(psi, buf, nbytes, res); | |
| 3576 | 3578 | if (IS_ERR(new)) { |
| 3577 | 3579 | cgroup_put(cgrp); |
| 3578 | 3580 | return PTR_ERR(new); |
| @@ -81,7 +81,6 @@ CONFIG_INPUT_JOYSTICK=y · 80 unmodified lines | ||
| 81 | 81 | CONFIG_INPUT_MISC=y |
| 82 | 82 | CONFIG_INPUT_TABLET=y |
| 83 | 83 | CONFIG_INPUT_UINPUT=y |
| 84 | −CONFIG_ION=y | |
| 85 | 84 | CONFIG_JOYSTICK_XPAD=y |
| 86 | 85 | CONFIG_JOYSTICK_XPAD_FF=y |
| 87 | 86 | CONFIG_JOYSTICK_XPAD_LEDS=y |
| @@ -36,7 +36,7 @@ struct map_benchmark { · 35 unmodified lines | ||
| 36 | 36 | __s32 node; /* which numa node this benchmark will run on */ |
| 37 | 37 | __u32 dma_bits; /* DMA addressing capability */ |
| 38 | 38 | __u32 dma_dir; /* DMA data direction */ |
| 39 | − __u64 expansion[10]; /* For future use */ | |
| 39 | + __u8 expansion[84]; /* For future use */ | |
| 40 | 40 | }; |
| 41 | 41 | |
| 42 | 42 | struct map_benchmark_data { |
| @@ -147,8 +147,10 @@ static int do_map_benchmark(struct map_benchmark_data *map) · 104 unmodified lines | ||
| 147 | 147 | atomic64_set(&map->sum_sq_unmap, 0); |
| 148 | 148 | atomic64_set(&map->loops, 0); |
| 149 | 149 | |
| 150 | − for (i = 0; i < threads; i++) | |
| 150 | + for (i = 0; i < threads; i++) { | |
| 151 | + get_task_struct(tsk[i]); | |
| 151 | 152 | wake_up_process(tsk[i]); |
| 153 | + } | |
| 152 | 154 | |
| 153 | 155 | msleep_interruptible(map->bparam.seconds * 1000); |
| 154 | 156 | |
| @@ -183,6 +185,8 @@ static int do_map_benchmark(struct map_benchmark_data *map) · 28 unmodified lines | ||
| 183 | 185 | } |
| 184 | 186 | |
| 185 | 187 | out: |
| 188 | + for (i = 0; i < threads; i++) | |
| 189 | + put_task_struct(tsk[i]); | |
| 186 | 190 | put_device(map->dev); |
| 187 | 191 | kfree(tsk); |
| 188 | 192 | return ret; |
| @@ -209,26 +209,18 @@ static void exit_to_user_mode_prepare(struct pt_regs *regs) · 208 unmodified lines | ||
| 209 | 209 | lockdep_sys_exit(); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | −#ifndef _TIF_SINGLESTEP | |
| 213 | −static inline bool report_single_step(unsigned long work) | |
| 214 | −{ | |
| 215 | − return false; | |
| 216 | −} | |
| 217 | −#else | |
| 218 | 212 | /* |
| 219 | 213 | * If SYSCALL_EMU is set, then the only reason to report is when |
| 220 | − * TIF_SINGLESTEP is set (i.e. PTRACE_SYSEMU_SINGLESTEP). This syscall | |
| 214 | + * SINGLESTEP is set (i.e. PTRACE_SYSEMU_SINGLESTEP). This syscall | |
| 221 | 215 | * instruction has been already reported in syscall_enter_from_user_mode(). |
| 222 | 216 | */ |
| 223 | 217 | static inline bool report_single_step(unsigned long work) |
| 224 | 218 | { |
| 225 | − if (!(work & SYSCALL_WORK_SYSCALL_EMU)) | |
| 219 | + if (work & SYSCALL_WORK_SYSCALL_EMU) | |
| 226 | 220 | return false; |
| 227 | 221 | |
| 228 | − return !!(current_thread_info()->flags & _TIF_SINGLESTEP); | |
| 222 | + return work & SYSCALL_WORK_SYSCALL_EXIT_TRAP; | |
| 229 | 223 | } |
| 230 | −#endif | |
| 231 | − | |
| 232 | 224 | |
| 233 | 225 | static void syscall_exit_work(struct pt_regs *regs, unsigned long work) |
| 234 | 226 | { |
| @@ -50,10 +50,10 @@ bool syscall_user_dispatch(struct pt_regs *regs) · 49 unmodified lines | ||
| 50 | 50 | if (unlikely(__get_user(state, sd->selector))) |
| 51 | 51 | do_exit(SIGSEGV); |
| 52 | 52 | |
| 53 | − if (likely(state == PR_SYS_DISPATCH_OFF)) | |
| 53 | + if (likely(state == SYSCALL_DISPATCH_FILTER_ALLOW)) | |
| 54 | 54 | return false; |
| 55 | 55 | |
| 56 | − if (state != PR_SYS_DISPATCH_ON) | |
| 56 | + if (state != SYSCALL_DISPATCH_FILTER_BLOCK) | |
| 57 | 57 | do_exit(SIGSYS); |
| 58 | 58 | } |
| 59 | 59 | |
| @@ -819,9 +819,8 @@ void __init fork_init(void) · 818 unmodified lines | ||
| 819 | 819 | init_task.signal->rlim[RLIMIT_SIGPENDING] = |
| 820 | 820 | init_task.signal->rlim[RLIMIT_NPROC]; |
| 821 | 821 | |
| 822 | − for (i = 0; i < UCOUNT_COUNTS; i++) { | |
| 822 | + for (i = 0; i < UCOUNT_COUNTS; i++) | |
| 823 | 823 | init_user_ns.ucount_max[i] = max_threads/2; |
| 824 | − } | |
| 825 | 824 | |
| 826 | 825 | #ifdef CONFIG_VMAP_STACK |
| 827 | 826 | cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "fork:vm_stack_cache", |
| @@ -1654,9 +1653,8 @@ static inline void init_task_pid_links(struct task_struct *task) · 826 unmodified lines | ||
| 1654 | 1653 | { |
| 1655 | 1654 | enum pid_type type; |
| 1656 | 1655 | |
| 1657 | − for (type = PIDTYPE_PID; type < PIDTYPE_MAX; ++type) { | |
| 1656 | + for (type = PIDTYPE_PID; type < PIDTYPE_MAX; ++type) | |
| 1658 | 1657 | INIT_HLIST_NODE(&task->pid_links[type]); |
| 1659 | − } | |
| 1660 | 1658 | } |
| 1661 | 1659 | |
| 1662 | 1660 | static inline void |
| @@ -763,6 +763,29 @@ static struct futex_pi_state *alloc_pi_state(void) · 762 unmodified lines | ||
| 763 | 763 | return pi_state; |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | +static void pi_state_update_owner(struct futex_pi_state *pi_state, | |
| 767 | + struct task_struct *new_owner) | |
| 768 | +{ | |
| 769 | + struct task_struct *old_owner = pi_state->owner; | |
| 770 | + | |
| 771 | + lockdep_assert_held(&pi_state->pi_mutex.wait_lock); | |
| 772 | + | |
| 773 | + if (old_owner) { | |
| 774 | + raw_spin_lock(&old_owner->pi_lock); | |
| 775 | + WARN_ON(list_empty(&pi_state->list)); | |
| 776 | + list_del_init(&pi_state->list); | |
| 777 | + raw_spin_unlock(&old_owner->pi_lock); | |
| 778 | + } | |
| 779 | + | |
| 780 | + if (new_owner) { | |
| 781 | + raw_spin_lock(&new_owner->pi_lock); | |
| 782 | + WARN_ON(!list_empty(&pi_state->list)); | |
| 783 | + list_add(&pi_state->list, &new_owner->pi_state_list); | |
| 784 | + pi_state->owner = new_owner; | |
| 785 | + raw_spin_unlock(&new_owner->pi_lock); | |
| 786 | + } | |
| 787 | +} | |
| 788 | + | |
| 766 | 789 | static void get_pi_state(struct futex_pi_state *pi_state) |
| 767 | 790 | { |
| 768 | 791 | WARN_ON_ONCE(!refcount_inc_not_zero(&pi_state->refcount)); |
| @@ -785,17 +808,11 @@ static void put_pi_state(struct futex_pi_state *pi_state) · 16 unmodified lines | ||
| 785 | 808 | * and has cleaned up the pi_state already |
| 786 | 809 | */ |
| 787 | 810 | if (pi_state->owner) { |
| 788 | − struct task_struct *owner; | |
| 789 | 811 | unsigned long flags; |
| 790 | 812 | |
| 791 | 813 | raw_spin_lock_irqsave(&pi_state->pi_mutex.wait_lock, flags); |
| 792 | − owner = pi_state->owner; | |
| 793 | − if (owner) { | |
| 794 | − raw_spin_lock(&owner->pi_lock); | |
| 795 | − list_del_init(&pi_state->list); | |
| 796 | − raw_spin_unlock(&owner->pi_lock); | |
| 797 | − } | |
| 798 | − rt_mutex_proxy_unlock(&pi_state->pi_mutex, owner); | |
| 814 | + pi_state_update_owner(pi_state, NULL); | |
| 815 | + rt_mutex_proxy_unlock(&pi_state->pi_mutex); | |
| 799 | 816 | raw_spin_unlock_irqrestore(&pi_state->pi_mutex.wait_lock, flags); |
| 800 | 817 | } |
| 801 | 818 | |
| @@ -941,7 +958,8 @@ static inline void exit_pi_state_list(struct task_struct *curr) { } · 139 unmodified lines | ||
| 941 | 958 | * FUTEX_OWNER_DIED bit. See [4] |
| 942 | 959 | * |
| 943 | 960 | * [10] There is no transient state which leaves owner and user space |
| 944 | − * TID out of sync. | |
| 961 | + * TID out of sync. Except one error case where the kernel is denied | |
| 962 | + * write access to the user address, see fixup_pi_state_owner(). | |
| 945 | 963 | * |
| 946 | 964 | * |
| 947 | 965 | * Serialization and lifetime rules: |
| @@ -1521,26 +1539,15 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_pi_state *pi_ · 573 unmodified lines | ||
| 1521 | 1539 | ret = -EINVAL; |
| 1522 | 1540 | } |
| 1523 | 1541 | |
| 1524 | − if (ret) | |
| 1525 | − goto out_unlock; | |
| 1526 | − | |
| 1527 | − /* | |
| 1528 | − * This is a point of no return; once we modify the uval there is no | |
| 1529 | − * going back and subsequent operations must not fail. | |
| 1530 | − */ | |
| 1531 | − | |
| 1532 | − raw_spin_lock(&pi_state->owner->pi_lock); | |
| 1533 | − WARN_ON(list_empty(&pi_state->list)); | |
| 1534 | − list_del_init(&pi_state->list); | |
| 1535 | − raw_spin_unlock(&pi_state->owner->pi_lock); | |
| 1536 | − | |
| 1537 | − raw_spin_lock(&new_owner->pi_lock); | |
| 1538 | − WARN_ON(!list_empty(&pi_state->list)); | |
| 1539 | − list_add(&pi_state->list, &new_owner->pi_state_list); | |
| 1540 | − pi_state->owner = new_owner; | |
| 1541 | − raw_spin_unlock(&new_owner->pi_lock); | |
| 1542 | − | |
| 1543 | − postunlock = __rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q); | |
| 1542 | + if (!ret) { | |
| 1543 | + /* | |
| 1544 | + * This is a point of no return; once we modified the uval | |
| 1545 | + * there is no going back and subsequent operations must | |
| 1546 | + * not fail. | |
| 1547 | + */ | |
| 1548 | + pi_state_update_owner(pi_state, new_owner); | |
| 1549 | + postunlock = __rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q); | |
| 1550 | + } | |
| 1544 | 1551 | |
| 1545 | 1552 | out_unlock: |
| 1546 | 1553 | raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); |
| @@ -2323,18 +2330,13 @@ static void unqueue_me_pi(struct futex_q *q) · 776 unmodified lines | ||
| 2323 | 2330 | spin_unlock(q->lock_ptr); |
| 2324 | 2331 | } |
| 2325 | 2332 | |
| 2326 | −static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, | |
| 2327 | − struct task_struct *argowner) | |
| 2333 | +static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, | |
| 2334 | + struct task_struct *argowner) | |
| 2328 | 2335 | { |
| 2329 | 2336 | struct futex_pi_state *pi_state = q->pi_state; |
| 2330 | − u32 uval, curval, newval; | |
| 2331 | 2337 | struct task_struct *oldowner, *newowner; |
| 2332 | − u32 newtid; | |
| 2333 | − int ret, err = 0; | |
| 2334 | − | |
| 2335 | − lockdep_assert_held(q->lock_ptr); | |
| 2336 | − | |
| 2337 | − raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); | |
| 2338 | + u32 uval, curval, newval, newtid; | |
| 2339 | + int err = 0; | |
| 2338 | 2340 | |
| 2339 | 2341 | oldowner = pi_state->owner; |
| 2340 | 2342 | |
| @@ -2368,14 +2370,12 @@ retry: · 27 unmodified lines | ||
| 2368 | 2370 | * We raced against a concurrent self; things are |
| 2369 | 2371 | * already fixed up. Nothing to do. |
| 2370 | 2372 | */ |
| 2371 | − ret = 0; | |
| 2372 | − goto out_unlock; | |
| 2373 | + return 0; | |
| 2373 | 2374 | } |
| 2374 | 2375 | |
| 2375 | 2376 | if (__rt_mutex_futex_trylock(&pi_state->pi_mutex)) { |
| 2376 | − /* We got the lock after all, nothing to fix. */ | |
| 2377 | − ret = 0; | |
| 2378 | − goto out_unlock; | |
| 2377 | + /* We got the lock. pi_state is correct. Tell caller. */ | |
| 2378 | + return 1; | |
| 2379 | 2379 | } |
| 2380 | 2380 | |
| 2381 | 2381 | /* |
| @@ -2402,8 +2402,7 @@ retry: · 20 unmodified lines | ||
| 2402 | 2402 | * We raced against a concurrent self; things are |
| 2403 | 2403 | * already fixed up. Nothing to do. |
| 2404 | 2404 | */ |
| 2405 | − ret = 0; | |
| 2406 | − goto out_unlock; | |
| 2405 | + return 1; | |
| 2407 | 2406 | } |
| 2408 | 2407 | newowner = argowner; |
| 2409 | 2408 | } |
| @@ -2433,22 +2432,9 @@ retry: · 23 unmodified lines | ||
| 2433 | 2432 | * We fixed up user space. Now we need to fix the pi_state |
| 2434 | 2433 | * itself. |
| 2435 | 2434 | */ |
| 2436 | − if (pi_state->owner != NULL) { | |
| 2437 | − raw_spin_lock(&pi_state->owner->pi_lock); | |
| 2438 | − WARN_ON(list_empty(&pi_state->list)); | |
| 2439 | − list_del_init(&pi_state->list); | |
| 2440 | − raw_spin_unlock(&pi_state->owner->pi_lock); | |
| 2441 | − } | |
| 2435 | + pi_state_update_owner(pi_state, newowner); | |
| 2442 | 2436 | |
| 2443 | − pi_state->owner = newowner; | |
| 2444 | − | |
| 2445 | − raw_spin_lock(&newowner->pi_lock); | |
| 2446 | − WARN_ON(!list_empty(&pi_state->list)); | |
| 2447 | − list_add(&pi_state->list, &newowner->pi_state_list); | |
| 2448 | − raw_spin_unlock(&newowner->pi_lock); | |
| 2449 | − raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); | |
| 2450 | − | |
| 2451 | − return 0; | |
| 2437 | + return argowner == current; | |
| 2452 | 2438 | |
| 2453 | 2439 | /* |
| 2454 | 2440 | * In order to reschedule or handle a page fault, we need to drop the |
| @@ -2469,17 +2455,16 @@ handle_err: · 14 unmodified lines | ||
| 2469 | 2455 | |
| 2470 | 2456 | switch (err) { |
| 2471 | 2457 | case -EFAULT: |
| 2472 | − ret = fault_in_user_writeable(uaddr); | |
| 2458 | + err = fault_in_user_writeable(uaddr); | |
| 2473 | 2459 | break; |
| 2474 | 2460 | |
| 2475 | 2461 | case -EAGAIN: |
| 2476 | 2462 | cond_resched(); |
| 2477 | − ret = 0; | |
| 2463 | + err = 0; | |
| 2478 | 2464 | break; |
| 2479 | 2465 | |
| 2480 | 2466 | default: |
| 2481 | 2467 | WARN_ON_ONCE(1); |
| 2482 | − ret = err; | |
| 2483 | 2468 | break; |
| 2484 | 2469 | } |
| 2485 | 2470 | |
| @@ -2489,17 +2474,44 @@ handle_err: · 3 unmodified lines | ||
| 2489 | 2474 | /* |
| 2490 | 2475 | * Check if someone else fixed it for us: |
| 2491 | 2476 | */ |
| 2492 | − if (pi_state->owner != oldowner) { | |
| 2493 | − ret = 0; | |
| 2494 | − goto out_unlock; | |
| 2495 | − } | |
| 2477 | + if (pi_state->owner != oldowner) | |
| 2478 | + return argowner == current; | |
| 2496 | 2479 | |
| 2497 | − if (ret) | |
| 2498 | − goto out_unlock; | |
| 2480 | + /* Retry if err was -EAGAIN or the fault in succeeded */ | |
| 2481 | + if (!err) | |
| 2482 | + goto retry; | |
| 2499 | 2483 | |
| 2500 | − goto retry; | |
| 2484 | + /* | |
| 2485 | + * fault_in_user_writeable() failed so user state is immutable. At | |
| 2486 | + * best we can make the kernel state consistent but user state will | |
| 2487 | + * be most likely hosed and any subsequent unlock operation will be | |
| 2488 | + * rejected due to PI futex rule [10]. | |
| 2489 | + * | |
| 2490 | + * Ensure that the rtmutex owner is also the pi_state owner despite | |
| 2491 | + * the user space value claiming something different. There is no | |
| 2492 | + * point in unlocking the rtmutex if current is the owner as it | |
| 2493 | + * would need to wait until the next waiter has taken the rtmutex | |
| 2494 | + * to guarantee consistent state. Keep it simple. Userspace asked | |
| 2495 | + * for this wreckaged state. | |
| 2496 | + * | |
| 2497 | + * The rtmutex has an owner - either current or some other | |
| 2498 | + * task. See the EAGAIN loop above. | |
| 2499 | + */ | |
| 2500 | + pi_state_update_owner(pi_state, rt_mutex_owner(&pi_state->pi_mutex)); | |
| 2501 | 2501 | |
| 2502 | −out_unlock: | |
| 2502 | + return err; | |
| 2503 | +} | |
| 2504 | + | |
| 2505 | +static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, | |
| 2506 | + struct task_struct *argowner) | |
| 2507 | +{ | |
| 2508 | + struct futex_pi_state *pi_state = q->pi_state; | |
| 2509 | + int ret; | |
| 2510 | + | |
| 2511 | + lockdep_assert_held(q->lock_ptr); | |
| 2512 | + | |
| 2513 | + raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); | |
| 2514 | + ret = __fixup_pi_state_owner(uaddr, q, argowner); | |
| 2503 | 2515 | raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); |
| 2504 | 2516 | return ret; |
| 2505 | 2517 | } |
| @@ -2523,8 +2535,6 @@ static long futex_wait_restart(struct restart_block *restart); · 17 unmodified lines | ||
| 2523 | 2535 | */ |
| 2524 | 2536 | static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked) |
| 2525 | 2537 | { |
| 2526 | − int ret = 0; | |
| 2527 | − | |
| 2528 | 2538 | if (locked) { |
| 2529 | 2539 | /* |
| 2530 | 2540 | * Got the lock. We might not be the anticipated owner if we |
| @@ -2535,8 +2545,8 @@ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked) · 4 unmodified lines | ||
| 2535 | 2545 | * stable state, anything else needs more attention. |
| 2536 | 2546 | */ |
| 2537 | 2547 | if (q->pi_state->owner != current) |
| 2538 | − ret = fixup_pi_state_owner(uaddr, q, current); | |
| 2539 | − return ret ? ret : locked; | |
| 2548 | + return fixup_pi_state_owner(uaddr, q, current); | |
| 2549 | + return 1; | |
| 2540 | 2550 | } |
| 2541 | 2551 | |
| 2542 | 2552 | /* |
| @@ -2547,23 +2557,17 @@ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked) · 4 unmodified lines | ||
| 2547 | 2557 | * Another speculative read; pi_state->owner == current is unstable |
| 2548 | 2558 | * but needs our attention. |
| 2549 | 2559 | */ |
| 2550 | − if (q->pi_state->owner == current) { | |
| 2551 | − ret = fixup_pi_state_owner(uaddr, q, NULL); | |
| 2552 | − return ret; | |
| 2553 | − } | |
| 2560 | + if (q->pi_state->owner == current) | |
| 2561 | + return fixup_pi_state_owner(uaddr, q, NULL); | |
| 2554 | 2562 | |
| 2555 | 2563 | /* |
| 2556 | 2564 | * Paranoia check. If we did not take the lock, then we should not be |
| 2557 | − * the owner of the rt_mutex. | |
| 2565 | + * the owner of the rt_mutex. Warn and establish consistent state. | |
| 2558 | 2566 | */ |
| 2559 | − if (rt_mutex_owner(&q->pi_state->pi_mutex) == current) { | |
| 2560 | − printk(KERN_ERR "fixup_owner: ret = %d pi-mutex: %p " | |
| 2561 | − "pi-state %p\n", ret, | |
| 2562 | − q->pi_state->pi_mutex.owner, | |
| 2563 | − q->pi_state->owner); | |
| 2564 | − } | |
| 2567 | + if (WARN_ON_ONCE(rt_mutex_owner(&q->pi_state->pi_mutex) == current)) | |
| 2568 | + return fixup_pi_state_owner(uaddr, q, current); | |
| 2565 | 2569 | |
| 2566 | − return ret; | |
| 2570 | + return 0; | |
| 2567 | 2571 | } |
| 2568 | 2572 | |
| 2569 | 2573 | /** |
| @@ -2771,7 +2775,6 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, · 201 unmodified lines | ||
| 2771 | 2775 | ktime_t *time, int trylock) |
| 2772 | 2776 | { |
| 2773 | 2777 | struct hrtimer_sleeper timeout, *to; |
| 2774 | − struct futex_pi_state *pi_state = NULL; | |
| 2775 | 2778 | struct task_struct *exiting = NULL; |
| 2776 | 2779 | struct rt_mutex_waiter rt_waiter; |
| 2777 | 2780 | struct futex_hash_bucket *hb; |
| @@ -2907,23 +2910,8 @@ no_block: · 129 unmodified lines | ||
| 2907 | 2910 | if (res) |
| 2908 | 2911 | ret = (res < 0) ? res : 0; |
| 2909 | 2912 | |
| 2910 | − /* | |
| 2911 | − * If fixup_owner() faulted and was unable to handle the fault, unlock | |
| 2912 | − * it and return the fault to userspace. | |
| 2913 | − */ | |
| 2914 | − if (ret && (rt_mutex_owner(&q.pi_state->pi_mutex) == current)) { | |
| 2915 | − pi_state = q.pi_state; | |
| 2916 | − get_pi_state(pi_state); | |
| 2917 | − } | |
| 2918 | − | |
| 2919 | 2913 | /* Unqueue and drop the lock */ |
| 2920 | 2914 | unqueue_me_pi(&q); |
| 2921 | − | |
| 2922 | − if (pi_state) { | |
| 2923 | − rt_mutex_futex_unlock(&pi_state->pi_mutex); | |
| 2924 | − put_pi_state(pi_state); | |
| 2925 | − } | |
| 2926 | − | |
| 2927 | 2915 | goto out; |
| 2928 | 2916 | |
| 2929 | 2917 | out_unlock_put_key: |
| @@ -3183,7 +3171,6 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, · 253 unmodified lines | ||
| 3183 | 3171 | u32 __user *uaddr2) |
| 3184 | 3172 | { |
| 3185 | 3173 | struct hrtimer_sleeper timeout, *to; |
| 3186 | − struct futex_pi_state *pi_state = NULL; | |
| 3187 | 3174 | struct rt_mutex_waiter rt_waiter; |
| 3188 | 3175 | struct futex_hash_bucket *hb; |
| 3189 | 3176 | union futex_key key2 = FUTEX_KEY_INIT; |
| @@ -3261,16 +3248,17 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, · 71 unmodified lines | ||
| 3261 | 3248 | if (q.pi_state && (q.pi_state->owner != current)) { |
| 3262 | 3249 | spin_lock(q.lock_ptr); |
| 3263 | 3250 | ret = fixup_pi_state_owner(uaddr2, &q, current); |
| 3264 | − if (ret && rt_mutex_owner(&q.pi_state->pi_mutex) == current) { | |
| 3265 | − pi_state = q.pi_state; | |
| 3266 | − get_pi_state(pi_state); | |
| 3267 | − } | |
| 3268 | 3251 | /* |
| 3269 | 3252 | * Drop the reference to the pi state which |
| 3270 | 3253 | * the requeue_pi() code acquired for us. |
| 3271 | 3254 | */ |
| 3272 | 3255 | put_pi_state(q.pi_state); |
| 3273 | 3256 | spin_unlock(q.lock_ptr); |
| 3257 | + /* | |
| 3258 | + * Adjust the return value. It's either -EFAULT or | |
| 3259 | + * success (1) but the caller expects 0 for success. | |
| 3260 | + */ | |
| 3261 | + ret = ret < 0 ? ret : 0; | |
| 3274 | 3262 | } |
| 3275 | 3263 | } else { |
| 3276 | 3264 | struct rt_mutex *pi_mutex; |
| @@ -3301,25 +3289,10 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, · 24 unmodified lines | ||
| 3301 | 3289 | if (res) |
| 3302 | 3290 | ret = (res < 0) ? res : 0; |
| 3303 | 3291 | |
| 3304 | − /* | |
| 3305 | − * If fixup_pi_state_owner() faulted and was unable to handle | |
| 3306 | − * the fault, unlock the rt_mutex and return the fault to | |
| 3307 | − * userspace. | |
| 3308 | − */ | |
| 3309 | − if (ret && rt_mutex_owner(&q.pi_state->pi_mutex) == current) { | |
| 3310 | − pi_state = q.pi_state; | |
| 3311 | − get_pi_state(pi_state); | |
| 3312 | − } | |
| 3313 | − | |
| 3314 | 3292 | /* Unqueue and drop the lock. */ |
| 3315 | 3293 | unqueue_me_pi(&q); |
| 3316 | 3294 | } |
| 3317 | 3295 | |
| 3318 | − if (pi_state) { | |
| 3319 | − rt_mutex_futex_unlock(&pi_state->pi_mutex); | |
| 3320 | − put_pi_state(pi_state); | |
| 3321 | − } | |
| 3322 | − | |
| 3323 | 3296 | if (ret == -EINTR) { |
| 3324 | 3297 | /* |
| 3325 | 3298 | * We've already been requeued, but cannot restart by calling |
| @@ -4,7 +4,7 @@ menu "GCOV-based kernel profiling" · 3 unmodified lines | ||
| 4 | 4 | config GCOV_KERNEL |
| 5 | 5 | bool "Enable gcov-based kernel profiling" |
| 6 | 6 | depends on DEBUG_FS |
| 7 | − select CONSTRUCTORS if !UML | |
| 7 | + select CONSTRUCTORS | |
| 8 | 8 | default n |
| 9 | 9 | help |
| 10 | 10 | This option enables gcov-based code profiling (e.g. for code coverage |
| @@ -2859,3 +2859,4 @@ bool irq_check_status_bit(unsigned int irq, unsigned int bitmask) · 2858 unmodified lines | ||
| 2859 | 2859 | rcu_read_unlock(); |
| 2860 | 2860 | return res; |
| 2861 | 2861 | } |
| 2862 | +EXPORT_SYMBOL_GPL(irq_check_status_bit); | |
| @@ -402,7 +402,7 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, · 401 unmodified lines | ||
| 402 | 402 | struct msi_domain_ops *ops = info->ops; |
| 403 | 403 | struct irq_data *irq_data; |
| 404 | 404 | struct msi_desc *desc; |
| 405 | − msi_alloc_info_t arg; | |
| 405 | + msi_alloc_info_t arg = { }; | |
| 406 | 406 | int i, ret, virq; |
| 407 | 407 | bool can_reserve; |
| 408 | 408 | |
| @@ -436,22 +436,22 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, · 27 unmodified lines | ||
| 436 | 436 | |
| 437 | 437 | can_reserve = msi_check_reservation_mode(domain, info, dev); |
| 438 | 438 | |
| 439 | − for_each_msi_entry(desc, dev) { | |
| 440 | − virq = desc->irq; | |
| 441 | − if (desc->nvec_used == 1) | |
| 442 | − dev_dbg(dev, "irq %d for MSI\n", virq); | |
| 443 | − else | |
| 439 | + /* | |
| 440 | + * This flag is set by the PCI layer as we need to activate | |
| 441 | + * the MSI entries before the PCI layer enables MSI in the | |
| 442 | + * card. Otherwise the card latches a random msi message. | |
| 443 | + */ | |
| 444 | + if (!(info->flags & MSI_FLAG_ACTIVATE_EARLY)) | |
| 445 | + goto skip_activate; | |
| 446 | + | |
| 447 | + for_each_msi_vector(desc, i, dev) { | |
| 448 | + if (desc->irq == i) { | |
| 449 | + virq = desc->irq; | |
| 444 | 450 | dev_dbg(dev, "irq [%d-%d] for MSI\n", |
| 445 | 451 | virq, virq + desc->nvec_used - 1); |
| 446 | − /* | |
| 447 | − * This flag is set by the PCI layer as we need to activate | |
| 448 | − * the MSI entries before the PCI layer enables MSI in the | |
| 449 | − * card. Otherwise the card latches a random msi message. | |
| 450 | − */ | |
| 451 | − if (!(info->flags & MSI_FLAG_ACTIVATE_EARLY)) | |
| 452 | − continue; | |
| 452 | + } | |
| 453 | 453 | |
| 454 | − irq_data = irq_domain_get_irq_data(domain, desc->irq); | |
| 454 | + irq_data = irq_domain_get_irq_data(domain, i); | |
| 455 | 455 | if (!can_reserve) { |
| 456 | 456 | irqd_clr_can_reserve(irq_data); |
| 457 | 457 | if (domain->flags & IRQ_DOMAIN_MSI_NOMASK_QUIRK) |
| @@ -462,28 +462,24 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, · 4 unmodified lines | ||
| 462 | 462 | goto cleanup; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | +skip_activate: | |
| 465 | 466 | /* |
| 466 | 467 | * If these interrupts use reservation mode, clear the activated bit |
| 467 | 468 | * so request_irq() will assign the final vector. |
| 468 | 469 | */ |
| 469 | 470 | if (can_reserve) { |
| 470 | − for_each_msi_entry(desc, dev) { | |
| 471 | − irq_data = irq_domain_get_irq_data(domain, desc->irq); | |
| 471 | + for_each_msi_vector(desc, i, dev) { | |
| 472 | + irq_data = irq_domain_get_irq_data(domain, i); | |
| 472 | 473 | irqd_clr_activated(irq_data); |
| 473 | 474 | } |
| 474 | 475 | } |
| 475 | 476 | return 0; |
| 476 | 477 | |
| 477 | 478 | cleanup: |
| 478 | − for_each_msi_entry(desc, dev) { | |
| 479 | − struct irq_data *irqd; | |
| 480 | − | |
| 481 | − if (desc->irq == virq) | |
| 482 | − break; | |
| 483 | − | |
| 484 | − irqd = irq_domain_get_irq_data(domain, desc->irq); | |
| 485 | − if (irqd_is_activated(irqd)) | |
| 486 | − irq_domain_deactivate_irq(irqd); | |
| 479 | + for_each_msi_vector(desc, i, dev) { | |
| 480 | + irq_data = irq_domain_get_irq_data(domain, i); | |
| 481 | + if (irqd_is_activated(irq_data)) | |
| 482 | + irq_domain_deactivate_irq(irq_data); | |
| 487 | 483 | } |
| 488 | 484 | msi_domain_free_irqs(domain, dev); |
| 489 | 485 | return ret; |
| @@ -1134,7 +1134,6 @@ int kernel_kexec(void) · 1133 unmodified lines | ||
| 1134 | 1134 | |
| 1135 | 1135 | #ifdef CONFIG_KEXEC_JUMP |
| 1136 | 1136 | if (kexec_image->preserve_context) { |
| 1137 | − lock_system_sleep(); | |
| 1138 | 1137 | pm_prepare_console(); |
| 1139 | 1138 | error = freeze_processes(); |
| 1140 | 1139 | if (error) { |
| @@ -1197,7 +1196,6 @@ int kernel_kexec(void) · 56 unmodified lines | ||
| 1197 | 1196 | thaw_processes(); |
| 1198 | 1197 | Restore_console: |
| 1199 | 1198 | pm_restore_console(); |
| 1200 | − unlock_system_sleep(); | |
| 1201 | 1199 | } |
| 1202 | 1200 | #endif |
| 1203 | 1201 | |
| @@ -1954,28 +1954,48 @@ bool __weak arch_kprobe_on_func_entry(unsigned long offset) · 1953 unmodified lines | ||
| 1954 | 1954 | return !offset; |
| 1955 | 1955 | } |
| 1956 | 1956 | |
| 1957 | −bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset) | |
| 1957 | +/** | |
| 1958 | + * kprobe_on_func_entry() -- check whether given address is function entry | |
| 1959 | + * @addr: Target address | |
| 1960 | + * @sym: Target symbol name | |
| 1961 | + * @offset: The offset from the symbol or the address | |
| 1962 | + * | |
| 1963 | + * This checks whether the given @addr+@offset or @sym+@offset is on the | |
| 1964 | + * function entry address or not. | |
| 1965 | + * This returns 0 if it is the function entry, or -EINVAL if it is not. | |
| 1966 | + * And also it returns -ENOENT if it fails the symbol or address lookup. | |
| 1967 | + * Caller must pass @addr or @sym (either one must be NULL), or this | |
| 1968 | + * returns -EINVAL. | |
| 1969 | + */ | |
| 1970 | +int kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset) | |
| 1958 | 1971 | { |
| 1959 | 1972 | kprobe_opcode_t *kp_addr = _kprobe_addr(addr, sym, offset); |
| 1960 | 1973 | |
| 1961 | 1974 | if (IS_ERR(kp_addr)) |
| 1962 | − return false; | |
| 1975 | + return PTR_ERR(kp_addr); | |
| 1963 | 1976 | |
| 1964 | − if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset) || | |
| 1965 | − !arch_kprobe_on_func_entry(offset)) | |
| 1966 | − return false; | |
| 1977 | + if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset)) | |
| 1978 | + return -ENOENT; | |
| 1967 | 1979 | |
| 1968 | − return true; | |
| 1980 | + if (!arch_kprobe_on_func_entry(offset)) | |
| 1981 | + return -EINVAL; | |
| 1982 | + | |
| 1983 | + return 0; | |
| 1969 | 1984 | } |
| 1970 | 1985 | |
| 1971 | 1986 | int register_kretprobe(struct kretprobe *rp) |
| 1972 | 1987 | { |
| 1973 | − int ret = 0; | |
| 1988 | + int ret; | |
| 1974 | 1989 | struct kretprobe_instance *inst; |
| 1975 | 1990 | int i; |
| 1976 | 1991 | void *addr; |
| 1977 | 1992 | |
| 1978 | − if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset)) | |
| 1993 | + ret = kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset); | |
| 1994 | + if (ret) | |
| 1995 | + return ret; | |
| 1996 | + | |
| 1997 | + /* If only rp->kp.addr is specified, check reregistering kprobes */ | |
| 1998 | + if (rp->kp.addr && check_kprobe_rereg(&rp->kp)) | |
| 1979 | 1999 | return -EINVAL; |
| 1980 | 2000 | |
| 1981 | 2001 | if (kretprobe_blacklist_size) { |
| @@ -294,7 +294,7 @@ static int kthread(void *_create) · 293 unmodified lines | ||
| 294 | 294 | do_exit(ret); |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | −/* called from do_fork() to get node information for about to be created task */ | |
| 297 | +/* called from kernel_clone() to get node information for about to be created task */ | |
| 298 | 298 | int tsk_fork_get_node(struct task_struct *tsk) |
| 299 | 299 | { |
| 300 | 300 | #ifdef CONFIG_NUMA |
| @@ -493,11 +493,36 @@ struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data), · 192 unmodified lines | ||
| 493 | 493 | return p; |
| 494 | 494 | kthread_bind(p, cpu); |
| 495 | 495 | /* CPU hotplug need to bind once again when unparking the thread. */ |
| 496 | − set_bit(KTHREAD_IS_PER_CPU, &to_kthread(p)->flags); | |
| 497 | 496 | to_kthread(p)->cpu = cpu; |
| 498 | 497 | return p; |
| 499 | 498 | } |
| 500 | 499 | |
| 500 | +void kthread_set_per_cpu(struct task_struct *k, int cpu) | |
| 501 | +{ | |
| 502 | + struct kthread *kthread = to_kthread(k); | |
| 503 | + if (!kthread) | |
| 504 | + return; | |
| 505 | + | |
| 506 | + WARN_ON_ONCE(!(k->flags & PF_NO_SETAFFINITY)); | |
| 507 | + | |
| 508 | + if (cpu < 0) { | |
| 509 | + clear_bit(KTHREAD_IS_PER_CPU, &kthread->flags); | |
| 510 | + return; | |
| 511 | + } | |
| 512 | + | |
| 513 | + kthread->cpu = cpu; | |
| 514 | + set_bit(KTHREAD_IS_PER_CPU, &kthread->flags); | |
| 515 | +} | |
| 516 | + | |
| 517 | +bool kthread_is_per_cpu(struct task_struct *k) | |
| 518 | +{ | |
| 519 | + struct kthread *kthread = to_kthread(k); | |
| 520 | + if (!kthread) | |
| 521 | + return false; | |
| 522 | + | |
| 523 | + return test_bit(KTHREAD_IS_PER_CPU, &kthread->flags); | |
| 524 | +} | |
| 525 | + | |
| 501 | 526 | /** |
| 502 | 527 | * kthread_unpark - unpark a thread created by kthread_create(). |
| 503 | 528 | * @k: thread created by kthread_create(). |
| @@ -79,7 +79,7 @@ module_param(lock_stat, int, 0644); · 78 unmodified lines | ||
| 79 | 79 | DEFINE_PER_CPU(unsigned int, lockdep_recursion); |
| 80 | 80 | EXPORT_PER_CPU_SYMBOL_GPL(lockdep_recursion); |
| 81 | 81 | |
| 82 | −static inline bool lockdep_enabled(void) | |
| 82 | +static __always_inline bool lockdep_enabled(void) | |
| 83 | 83 | { |
| 84 | 84 | if (!debug_locks) |
| 85 | 85 | return false; |
| @@ -5271,12 +5271,15 @@ static void __lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie cookie · 5185 unmodified lines | ||
| 5271 | 5271 | /* |
| 5272 | 5272 | * Check whether we follow the irq-flags state precisely: |
| 5273 | 5273 | */ |
| 5274 | −static void check_flags(unsigned long flags) | |
| 5274 | +static noinstr void check_flags(unsigned long flags) | |
| 5275 | 5275 | { |
| 5276 | 5276 | #if defined(CONFIG_PROVE_LOCKING) && defined(CONFIG_DEBUG_LOCKDEP) |
| 5277 | 5277 | if (!debug_locks) |
| 5278 | 5278 | return; |
| 5279 | 5279 | |
| 5280 | + /* Get the warning out.. */ | |
| 5281 | + instrumentation_begin(); | |
| 5282 | + | |
| 5280 | 5283 | if (irqs_disabled_flags(flags)) { |
| 5281 | 5284 | if (DEBUG_LOCKS_WARN_ON(lockdep_hardirqs_enabled())) { |
| 5282 | 5285 | printk("possible reason: unannotated irqs-off.\n"); |
| @@ -5304,6 +5307,8 @@ static void check_flags(unsigned long flags) · 21 unmodified lines | ||
| 5304 | 5307 | |
| 5305 | 5308 | if (!debug_locks) |
| 5306 | 5309 | print_irqtrace_events(current); |
| 5310 | + | |
| 5311 | + instrumentation_end(); | |
| 5307 | 5312 | #endif |
| 5308 | 5313 | } |
| 5309 | 5314 | |
| @@ -1716,8 +1716,7 @@ void rt_mutex_init_proxy_locked(struct rt_mutex *lock, · 1715 unmodified lines | ||
| 1716 | 1716 | * possible because it belongs to the pi_state which is about to be freed |
| 1717 | 1717 | * and it is not longer visible to other tasks. |
| 1718 | 1718 | */ |
| 1719 | −void rt_mutex_proxy_unlock(struct rt_mutex *lock, | |
| 1720 | − struct task_struct *proxy_owner) | |
| 1719 | +void rt_mutex_proxy_unlock(struct rt_mutex *lock) | |
| 1721 | 1720 | { |
| 1722 | 1721 | debug_rt_mutex_proxy_unlock(lock); |
| 1723 | 1722 | rt_mutex_set_owner(lock, NULL); |
| @@ -133,8 +133,7 @@ enum rtmutex_chainwalk { · 132 unmodified lines | ||
| 133 | 133 | extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock); |
| 134 | 134 | extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock, |
| 135 | 135 | struct task_struct *proxy_owner); |
| 136 | −extern void rt_mutex_proxy_unlock(struct rt_mutex *lock, | |
| 137 | − struct task_struct *proxy_owner); | |
| 136 | +extern void rt_mutex_proxy_unlock(struct rt_mutex *lock); | |
| 138 | 137 | extern void rt_mutex_init_waiter(struct rt_mutex_waiter *waiter); |
| 139 | 138 | extern int __rt_mutex_start_proxy_lock(struct rt_mutex *lock, |
| 140 | 139 | struct rt_mutex_waiter *waiter, |
| @@ -497,10 +497,10 @@ static int swap_writer_finish(struct swap_map_handle *handle, · 496 unmodified lines | ||
| 497 | 497 | unsigned int flags, int error) |
| 498 | 498 | { |
| 499 | 499 | if (!error) { |
| 500 | − flush_swap_writer(handle); | |
| 501 | 500 | pr_info("S"); |
| 502 | 501 | error = mark_swapfiles(handle, flags); |
| 503 | 502 | pr_cont("|\n"); |
| 503 | + flush_swap_writer(handle); | |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | if (error) |
| @@ -1291,11 +1291,16 @@ static size_t info_print_prefix(const struct printk_info *info, bool syslog, · 1290 unmodified lines | ||
| 1291 | 1291 | * done: |
| 1292 | 1292 | * |
| 1293 | 1293 | * - Add prefix for each line. |
| 1294 | + * - Drop truncated lines that no longer fit into the buffer. | |
| 1294 | 1295 | * - Add the trailing newline that has been removed in vprintk_store(). |
| 1295 | − * - Drop truncated lines that do not longer fit into the buffer. | |
| 1296 | + * - Add a string terminator. | |
| 1297 | + * | |
| 1298 | + * Since the produced string is always terminated, the maximum possible | |
| 1299 | + * return value is @r->text_buf_size - 1; | |
| 1296 | 1300 | * |
| 1297 | 1301 | * Return: The length of the updated/prepared text, including the added |
| 1298 | − * prefixes and the newline. The dropped line(s) are not counted. | |
| 1302 | + * prefixes and the newline. The terminator is not counted. The dropped | |
| 1303 | + * line(s) are not counted. | |
| 1299 | 1304 | */ |
| 1300 | 1305 | static size_t record_print_text(struct printk_record *r, bool syslog, |
| 1301 | 1306 | bool time) |
| @@ -1338,26 +1343,31 @@ static size_t record_print_text(struct printk_record *r, bool syslog, · 36 unmodified lines | ||
| 1338 | 1343 | |
| 1339 | 1344 | /* |
| 1340 | 1345 | * Truncate the text if there is not enough space to add the |
| 1341 | − * prefix and a trailing newline. | |
| 1346 | + * prefix and a trailing newline and a terminator. | |
| 1342 | 1347 | */ |
| 1343 | − if (len + prefix_len + text_len + 1 > buf_size) { | |
| 1348 | + if (len + prefix_len + text_len + 1 + 1 > buf_size) { | |
| 1344 | 1349 | /* Drop even the current line if no space. */ |
| 1345 | − if (len + prefix_len + line_len + 1 > buf_size) | |
| 1350 | + if (len + prefix_len + line_len + 1 + 1 > buf_size) | |
| 1346 | 1351 | break; |
| 1347 | 1352 | |
| 1348 | − text_len = buf_size - len - prefix_len - 1; | |
| 1353 | + text_len = buf_size - len - prefix_len - 1 - 1; | |
| 1349 | 1354 | truncated = true; |
| 1350 | 1355 | } |
| 1351 | 1356 | |
| 1352 | 1357 | memmove(text + prefix_len, text, text_len); |
| 1353 | 1358 | memcpy(text, prefix, prefix_len); |
| 1354 | 1359 | |
| 1360 | + /* | |
| 1361 | + * Increment the prepared length to include the text and | |
| 1362 | + * prefix that were just moved+copied. Also increment for the | |
| 1363 | + * newline at the end of this line. If this is the last line, | |
| 1364 | + * there is no newline, but it will be added immediately below. | |
| 1365 | + */ | |
| 1355 | 1366 | len += prefix_len + line_len + 1; |
| 1356 | − | |
| 1357 | 1367 | if (text_len == line_len) { |
| 1358 | 1368 | /* |
| 1359 | − * Add the trailing newline removed in | |
| 1360 | − * vprintk_store(). | |
| 1369 | + * This is the last line. Add the trailing newline | |
| 1370 | + * removed in vprintk_store(). | |
| 1361 | 1371 | */ |
| 1362 | 1372 | text[prefix_len + line_len] = '\n'; |
| 1363 | 1373 | break; |
| @@ -1382,6 +1392,14 @@ static size_t record_print_text(struct printk_record *r, bool syslog, · 18 unmodified lines | ||
| 1382 | 1392 | text_len -= line_len + 1; |
| 1383 | 1393 | } |
| 1384 | 1394 | |
| 1395 | + /* | |
| 1396 | + * If a buffer was provided, it will be terminated. Space for the | |
| 1397 | + * string terminator is guaranteed to be available. The terminator is | |
| 1398 | + * not counted in the return value. | |
| 1399 | + */ | |
| 1400 | + if (buf_size > 0) | |
| 1401 | + r->text_buf[len] = 0; | |
| 1402 | + | |
| 1385 | 1403 | return len; |
| 1386 | 1404 | } |
| 1387 | 1405 | |
| @@ -3427,7 +3445,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, · 2039 unmodified lines | ||
| 3427 | 3445 | while (prb_read_valid_info(prb, seq, &info, &line_count)) { |
| 3428 | 3446 | if (r.info->seq >= dumper->next_seq) |
| 3429 | 3447 | break; |
| 3430 | − l += get_record_print_text_size(&info, line_count, true, time); | |
| 3448 | + l += get_record_print_text_size(&info, line_count, syslog, time); | |
| 3431 | 3449 | seq = r.info->seq + 1; |
| 3432 | 3450 | } |
| 3433 | 3451 | |
| @@ -3437,7 +3455,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, · 3 unmodified lines | ||
| 3437 | 3455 | &info, &line_count)) { |
| 3438 | 3456 | if (r.info->seq >= dumper->next_seq) |
| 3439 | 3457 | break; |
| 3440 | − l -= get_record_print_text_size(&info, line_count, true, time); | |
| 3458 | + l -= get_record_print_text_size(&info, line_count, syslog, time); | |
| 3441 | 3459 | seq = r.info->seq + 1; |
| 3442 | 3460 | } |
| 3443 | 3461 | |
| @@ -1718,7 +1718,7 @@ static bool copy_data(struct prb_data_ring *data_ring, · 1717 unmodified lines | ||
| 1718 | 1718 | |
| 1719 | 1719 | /* Caller interested in the line count? */ |
| 1720 | 1720 | if (line_count) |
| 1721 | − *line_count = count_lines(data, data_size); | |
| 1721 | + *line_count = count_lines(data, len); | |
| 1722 | 1722 | |
| 1723 | 1723 | /* Caller interested in the data content? */ |
| 1724 | 1724 | if (!buf || !buf_size) |
| @@ -241,7 +241,7 @@ static int __noreturn rcu_tasks_kthread(void *arg) · 240 unmodified lines | ||
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | −/* Spawn RCU-tasks grace-period kthread, e.g., at core_initcall() time. */ | |
| 244 | +/* Spawn RCU-tasks grace-period kthread. */ | |
| 245 | 245 | static void __init rcu_spawn_tasks_kthread_generic(struct rcu_tasks *rtp) |
| 246 | 246 | { |
| 247 | 247 | struct task_struct *t; |
| @@ -564,7 +564,6 @@ static int __init rcu_spawn_tasks_kthread(void) · 316 unmodified lines | ||
| 564 | 564 | rcu_spawn_tasks_kthread_generic(&rcu_tasks); |
| 565 | 565 | return 0; |
| 566 | 566 | } |
| 567 | −core_initcall(rcu_spawn_tasks_kthread); | |
| 568 | 567 | |
| 569 | 568 | #if !defined(CONFIG_TINY_RCU) |
| 570 | 569 | void show_rcu_tasks_classic_gp_kthread(void) |
| @@ -692,7 +691,6 @@ static int __init rcu_spawn_tasks_rude_kthread(void) · 121 unmodified lines | ||
| 692 | 691 | rcu_spawn_tasks_kthread_generic(&rcu_tasks_rude); |
| 693 | 692 | return 0; |
| 694 | 693 | } |
| 695 | −core_initcall(rcu_spawn_tasks_rude_kthread); | |
| 696 | 694 | |
| 697 | 695 | #if !defined(CONFIG_TINY_RCU) |
| 698 | 696 | void show_rcu_tasks_rude_gp_kthread(void) |
| @@ -968,6 +966,11 @@ static void rcu_tasks_trace_pregp_step(void) · 269 unmodified lines | ||
| 968 | 966 | static void rcu_tasks_trace_pertask(struct task_struct *t, |
| 969 | 967 | struct list_head *hop) |
| 970 | 968 | { |
| 969 | + // During early boot when there is only the one boot CPU, there | |
| 970 | + // is no idle task for the other CPUs. Just return. | |
| 971 | + if (unlikely(t == NULL)) | |
| 972 | + return; | |
| 973 | + | |
| 971 | 974 | WRITE_ONCE(t->trc_reader_special.b.need_qs, false); |
| 972 | 975 | WRITE_ONCE(t->trc_reader_checked, false); |
| 973 | 976 | t->trc_ipi_to_cpu = -1; |
| @@ -1193,7 +1196,6 @@ static int __init rcu_spawn_tasks_trace_kthread(void) · 219 unmodified lines | ||
| 1193 | 1196 | rcu_spawn_tasks_kthread_generic(&rcu_tasks_trace); |
| 1194 | 1197 | return 0; |
| 1195 | 1198 | } |
| 1196 | −core_initcall(rcu_spawn_tasks_trace_kthread); | |
| 1197 | 1199 | |
| 1198 | 1200 | #if !defined(CONFIG_TINY_RCU) |
| 1199 | 1201 | void show_rcu_tasks_trace_gp_kthread(void) |
| @@ -1222,6 +1224,21 @@ void show_rcu_tasks_gp_kthreads(void) · 22 unmodified lines | ||
| 1222 | 1224 | } |
| 1223 | 1225 | #endif /* #ifndef CONFIG_TINY_RCU */ |
| 1224 | 1226 | |
| 1227 | +void __init rcu_init_tasks_generic(void) | |
| 1228 | +{ | |
| 1229 | +#ifdef CONFIG_TASKS_RCU | |
| 1230 | + rcu_spawn_tasks_kthread(); | |
| 1231 | +#endif | |
| 1232 | + | |
| 1233 | +#ifdef CONFIG_TASKS_RUDE_RCU | |
| 1234 | + rcu_spawn_tasks_rude_kthread(); | |
| 1235 | +#endif | |
| 1236 | + | |
| 1237 | +#ifdef CONFIG_TASKS_TRACE_RCU | |
| 1238 | + rcu_spawn_tasks_trace_kthread(); | |
| 1239 | +#endif | |
| 1240 | +} | |
| 1241 | + | |
| 1225 | 1242 | #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */ |
| 1226 | 1243 | static inline void rcu_tasks_bootup_oddness(void) {} |
| 1227 | 1244 | void show_rcu_tasks_gp_kthreads(void) {} |
| @@ -1796,13 +1796,28 @@ static inline bool rq_has_pinned_tasks(struct rq *rq) · 1795 unmodified lines | ||
| 1796 | 1796 | */ |
| 1797 | 1797 | static inline bool is_cpu_allowed(struct task_struct *p, int cpu) |
| 1798 | 1798 | { |
| 1799 | + /* When not in the task's cpumask, no point in looking further. */ | |
| 1799 | 1800 | if (!cpumask_test_cpu(cpu, p->cpus_ptr)) |
| 1800 | 1801 | return false; |
| 1801 | 1802 | |
| 1802 | − if (is_per_cpu_kthread(p) || is_migration_disabled(p)) | |
| 1803 | + /* migrate_disabled() must be allowed to finish. */ | |
| 1804 | + if (is_migration_disabled(p)) | |
| 1803 | 1805 | return cpu_online(cpu); |
| 1804 | 1806 | |
| 1805 | − return cpu_active(cpu); | |
| 1807 | + /* Non kernel threads are not allowed during either online or offline. */ | |
| 1808 | + if (!(p->flags & PF_KTHREAD)) | |
| 1809 | + return cpu_active(cpu); | |
| 1810 | + | |
| 1811 | + /* KTHREAD_IS_PER_CPU is always allowed. */ | |
| 1812 | + if (kthread_is_per_cpu(p)) | |
| 1813 | + return cpu_online(cpu); | |
| 1814 | + | |
| 1815 | + /* Regular kernel threads don't get to stay during offline. */ | |
| 1816 | + if (cpu_rq(cpu)->balance_push) | |
| 1817 | + return false; | |
| 1818 | + | |
| 1819 | + /* But are allowed during online. */ | |
| 1820 | + return cpu_online(cpu); | |
| 1806 | 1821 | } |
| 1807 | 1822 | |
| 1808 | 1823 | /* |
| @@ -2327,7 +2342,9 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, · 518 unmodified lines | ||
| 2327 | 2342 | |
| 2328 | 2343 | if (p->flags & PF_KTHREAD || is_migration_disabled(p)) { |
| 2329 | 2344 | /* |
| 2330 | − * Kernel threads are allowed on online && !active CPUs. | |
| 2345 | + * Kernel threads are allowed on online && !active CPUs, | |
| 2346 | + * however, during cpu-hot-unplug, even these might get pushed | |
| 2347 | + * away if not KTHREAD_IS_PER_CPU. | |
| 2331 | 2348 | * |
| 2332 | 2349 | * Specifically, migration_disabled() tasks must not fail the |
| 2333 | 2350 | * cpumask_any_and_distribute() pick below, esp. so on |
| @@ -2371,16 +2388,6 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, · 37 unmodified lines | ||
| 2371 | 2388 | |
| 2372 | 2389 | __do_set_cpus_allowed(p, new_mask, flags); |
| 2373 | 2390 | |
| 2374 | − if (p->flags & PF_KTHREAD) { | |
| 2375 | − /* | |
| 2376 | − * For kernel threads that do indeed end up on online && | |
| 2377 | − * !active we want to ensure they are strict per-CPU threads. | |
| 2378 | − */ | |
| 2379 | − WARN_ON(cpumask_intersects(new_mask, cpu_online_mask) && | |
| 2380 | − !cpumask_intersects(new_mask, cpu_active_mask) && | |
| 2381 | − p->nr_cpus_allowed != 1); | |
| 2382 | − } | |
| 2383 | − | |
| 2384 | 2391 | return affine_move_task(rq, p, &rf, dest_cpu, flags); |
| 2385 | 2392 | |
| 2386 | 2393 | out: |
| @@ -3121,6 +3128,13 @@ bool cpus_share_cache(int this_cpu, int that_cpu) · 734 unmodified lines | ||
| 3121 | 3128 | |
| 3122 | 3129 | static inline bool ttwu_queue_cond(int cpu, int wake_flags) |
| 3123 | 3130 | { |
| 3131 | + /* | |
| 3132 | + * Do not complicate things with the async wake_list while the CPU is | |
| 3133 | + * in hotplug state. | |
| 3134 | + */ | |
| 3135 | + if (!cpu_active(cpu)) | |
| 3136 | + return false; | |
| 3137 | + | |
| 3124 | 3138 | /* |
| 3125 | 3139 | * If the CPU does not share cache, then queue the task on the |
| 3126 | 3140 | * remote rqs wakelist to avoid accessing remote data. |
| @@ -7390,8 +7404,14 @@ static void balance_push(struct rq *rq) · 4263 unmodified lines | ||
| 7390 | 7404 | /* |
| 7391 | 7405 | * Both the cpu-hotplug and stop task are in this case and are |
| 7392 | 7406 | * required to complete the hotplug process. |
| 7407 | + * | |
| 7408 | + * XXX: the idle task does not match kthread_is_per_cpu() due to | |
| 7409 | + * histerical raisins. | |
| 7393 | 7410 | */ |
| 7394 | − if (is_per_cpu_kthread(push_task) || is_migration_disabled(push_task)) { | |
| 7411 | + if (rq->idle == push_task || | |
| 7412 | + ((push_task->flags & PF_KTHREAD) && kthread_is_per_cpu(push_task)) || | |
| 7413 | + is_migration_disabled(push_task)) { | |
| 7414 | + | |
| 7395 | 7415 | /* |
| 7396 | 7416 | * If this is the idle task on the outgoing CPU try to wake |
| 7397 | 7417 | * up the hotplug control thread which might wait for the |
| @@ -7423,7 +7443,7 @@ static void balance_push(struct rq *rq) · 25 unmodified lines | ||
| 7423 | 7443 | /* |
| 7424 | 7444 | * At this point need_resched() is true and we'll take the loop in |
| 7425 | 7445 | * schedule(). The next pick is obviously going to be the stop task |
| 7426 | − * which is_per_cpu_kthread() and will push this task away. | |
| 7446 | + * which kthread_is_per_cpu() and will push this task away. | |
| 7427 | 7447 | */ |
| 7428 | 7448 | raw_spin_lock(&rq->lock); |
| 7429 | 7449 | } |
| @@ -7434,10 +7454,13 @@ static void balance_push_set(int cpu, bool on) · 4 unmodified lines | ||
| 7434 | 7454 | struct rq_flags rf; |
| 7435 | 7455 | |
| 7436 | 7456 | rq_lock_irqsave(rq, &rf); |
| 7437 | − if (on) | |
| 7457 | + rq->balance_push = on; | |
| 7458 | + if (on) { | |
| 7459 | + WARN_ON_ONCE(rq->balance_callback); | |
| 7438 | 7460 | rq->balance_callback = &balance_push_callback; |
| 7439 | − else | |
| 7461 | + } else if (rq->balance_callback == &balance_push_callback) { | |
| 7440 | 7462 | rq->balance_callback = NULL; |
| 7463 | + } | |
| 7441 | 7464 | rq_unlock_irqrestore(rq, &rf); |
| 7442 | 7465 | } |
| 7443 | 7466 | |
| @@ -7555,6 +7578,10 @@ int sched_cpu_activate(unsigned int cpu) · 111 unmodified lines | ||
| 7555 | 7578 | struct rq *rq = cpu_rq(cpu); |
| 7556 | 7579 | struct rq_flags rf; |
| 7557 | 7580 | |
| 7581 | + /* | |
| 7582 | + * Make sure that when the hotplug state machine does a roll-back | |
| 7583 | + * we clear balance_push. Ideally that would happen earlier... | |
| 7584 | + */ | |
| 7558 | 7585 | balance_push_set(cpu, false); |
| 7559 | 7586 | |
| 7560 | 7587 | #ifdef CONFIG_SCHED_SMT |
| @@ -7603,17 +7630,27 @@ int sched_cpu_deactivate(unsigned int cpu) · 42 unmodified lines | ||
| 7603 | 7630 | nohz_balance_exit_idle(rq); |
| 7604 | 7631 | |
| 7605 | 7632 | set_cpu_active(cpu, false); |
| 7633 | + | |
| 7634 | + /* | |
| 7635 | + * From this point forward, this CPU will refuse to run any task that | |
| 7636 | + * is not: migrate_disable() or KTHREAD_IS_PER_CPU, and will actively | |
| 7637 | + * push those tasks away until this gets cleared, see | |
| 7638 | + * sched_cpu_dying(). | |
| 7639 | + */ | |
| 7640 | + balance_push_set(cpu, true); | |
| 7641 | + | |
| 7606 | 7642 | /* |
| 7607 | − * We've cleared cpu_active_mask, wait for all preempt-disabled and RCU | |
| 7608 | − * users of this state to go away such that all new such users will | |
| 7609 | − * observe it. | |
| 7643 | + * We've cleared cpu_active_mask / set balance_push, wait for all | |
| 7644 | + * preempt-disabled and RCU users of this state to go away such that | |
| 7645 | + * all new such users will observe it. | |
| 7646 | + * | |
| 7647 | + * Specifically, we rely on ttwu to no longer target this CPU, see | |
| 7648 | + * ttwu_queue_cond() and is_cpu_allowed(). | |
| 7610 | 7649 | * |
| 7611 | 7650 | * Do sync before park smpboot threads to take care the rcu boost case. |
| 7612 | 7651 | */ |
| 7613 | 7652 | synchronize_rcu(); |
| 7614 | 7653 | |
| 7615 | − balance_push_set(cpu, true); | |
| 7616 | − | |
| 7617 | 7654 | rq_lock_irqsave(rq, &rf); |
| 7618 | 7655 | if (rq->rd) { |
| 7619 | 7656 | update_rq_clock(rq); |
| @@ -7694,6 +7731,25 @@ static void calc_load_migrate(struct rq *rq) · 74 unmodified lines | ||
| 7694 | 7731 | atomic_long_add(delta, &calc_load_tasks); |
| 7695 | 7732 | } |
| 7696 | 7733 | |
| 7734 | +static void dump_rq_tasks(struct rq *rq, const char *loglvl) | |
| 7735 | +{ | |
| 7736 | + struct task_struct *g, *p; | |
| 7737 | + int cpu = cpu_of(rq); | |
| 7738 | + | |
| 7739 | + lockdep_assert_held(&rq->lock); | |
| 7740 | + | |
| 7741 | + printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running); | |
| 7742 | + for_each_process_thread(g, p) { | |
| 7743 | + if (task_cpu(p) != cpu) | |
| 7744 | + continue; | |
| 7745 | + | |
| 7746 | + if (!task_on_rq_queued(p)) | |
| 7747 | + continue; | |
| 7748 | + | |
| 7749 | + printk("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm); | |
| 7750 | + } | |
| 7751 | +} | |
| 7752 | + | |
| 7697 | 7753 | int sched_cpu_dying(unsigned int cpu) |
| 7698 | 7754 | { |
| 7699 | 7755 | struct rq *rq = cpu_rq(cpu); |
| @@ -7703,9 +7759,18 @@ int sched_cpu_dying(unsigned int cpu) · 3 unmodified lines | ||
| 7703 | 7759 | sched_tick_stop(cpu); |
| 7704 | 7760 | |
| 7705 | 7761 | rq_lock_irqsave(rq, &rf); |
| 7706 | − BUG_ON(rq->nr_running != 1 || rq_has_pinned_tasks(rq)); | |
| 7762 | + if (rq->nr_running != 1 || rq_has_pinned_tasks(rq)) { | |
| 7763 | + WARN(true, "Dying CPU not properly vacated!"); | |
| 7764 | + dump_rq_tasks(rq, KERN_WARNING); | |
| 7765 | + } | |
| 7707 | 7766 | rq_unlock_irqrestore(rq, &rf); |
| 7708 | 7767 | |
| 7768 | + /* | |
| 7769 | + * Now that the CPU is offline, make sure we're welcome | |
| 7770 | + * to new tasks once we come back up. | |
| 7771 | + */ | |
| 7772 | + balance_push_set(cpu, false); | |
| 7773 | + | |
| 7709 | 7774 | calc_load_migrate(rq); |
| 7710 | 7775 | update_max_interval(); |
| 7711 | 7776 | hrtick_clear(rq); |
| @@ -975,6 +975,7 @@ struct rq { · 974 unmodified lines | ||
| 975 | 975 | unsigned long cpu_capacity_orig; |
| 976 | 976 | |
| 977 | 977 | struct callback_head *balance_callback; |
| 978 | + unsigned char balance_push; | |
| 978 | 979 | |
| 979 | 980 | unsigned char nohz_idle_balance; |
| 980 | 981 | unsigned char idle_balance; |
| @@ -2550,6 +2550,9 @@ bool get_signal(struct ksignal *ksig) · 2549 unmodified lines | ||
| 2550 | 2550 | struct signal_struct *signal = current->signal; |
| 2551 | 2551 | int signr; |
| 2552 | 2552 | |
| 2553 | + if (unlikely(current->task_works)) | |
| 2554 | + task_work_run(); | |
| 2555 | + | |
| 2553 | 2556 | /* |
| 2554 | 2557 | * For non-generic architectures, check for TIF_NOTIFY_SIGNAL so |
| 2555 | 2558 | * that the arch handlers don't all have to do it. If we get here |
| @@ -3701,7 +3704,8 @@ static bool access_pidfd_pidns(struct pid *pid) · 1145 unmodified lines | ||
| 3701 | 3704 | return true; |
| 3702 | 3705 | } |
| 3703 | 3706 | |
| 3704 | −static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info) | |
| 3707 | +static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, | |
| 3708 | + siginfo_t __user *info) | |
| 3705 | 3709 | { |
| 3706 | 3710 | #ifdef CONFIG_COMPAT |
| 3707 | 3711 | /* |
| @@ -188,6 +188,7 @@ __smpboot_create_thread(struct smp_hotplug_thread *ht, unsigned int cpu) · 187 unmodified lines | ||
| 188 | 188 | kfree(td); |
| 189 | 189 | return PTR_ERR(tsk); |
| 190 | 190 | } |
| 191 | + kthread_set_per_cpu(tsk, cpu); | |
| 191 | 192 | /* |
| 192 | 193 | * Park the thread so that it could start right on the CPU |
| 193 | 194 | * when it is available. |
| @@ -498,11 +498,11 @@ out: · 497 unmodified lines | ||
| 498 | 498 | static void sync_hw_clock(struct work_struct *work); |
| 499 | 499 | static DECLARE_WORK(sync_work, sync_hw_clock); |
| 500 | 500 | static struct hrtimer sync_hrtimer; |
| 501 | −#define SYNC_PERIOD_NS (11UL * 60 * NSEC_PER_SEC) | |
| 501 | +#define SYNC_PERIOD_NS (11ULL * 60 * NSEC_PER_SEC) | |
| 502 | 502 | |
| 503 | 503 | static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer) |
| 504 | 504 | { |
| 505 | − queue_work(system_power_efficient_wq, &sync_work); | |
| 505 | + queue_work(system_freezable_power_efficient_wq, &sync_work); | |
| 506 | 506 | |
| 507 | 507 | return HRTIMER_NORESTART; |
| 508 | 508 | } |
| @@ -512,7 +512,7 @@ static void sched_sync_hw_clock(unsigned long offset_nsec, bool retry) · 3 unmodified lines | ||
| 512 | 512 | ktime_t exp = ktime_set(ktime_get_real_seconds(), 0); |
| 513 | 513 | |
| 514 | 514 | if (retry) |
| 515 | − exp = ktime_add_ns(exp, 2 * NSEC_PER_SEC - offset_nsec); | |
| 515 | + exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec); | |
| 516 | 516 | else |
| 517 | 517 | exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec); |
| 518 | 518 | |
| @@ -668,7 +668,7 @@ void ntp_notify_cmos_timer(void) · 149 unmodified lines | ||
| 668 | 668 | * just a pointless work scheduled. |
| 669 | 669 | */ |
| 670 | 670 | if (ntp_synced() && !hrtimer_is_queued(&sync_hrtimer)) |
| 671 | − queue_work(system_power_efficient_wq, &sync_work); | |
| 671 | + queue_work(system_freezable_power_efficient_wq, &sync_work); | |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | static void __init ntp_init_cmos_sync(void) |
| @@ -991,8 +991,7 @@ EXPORT_SYMBOL_GPL(ktime_get_seconds); · 990 unmodified lines | ||
| 991 | 991 | /** |
| 992 | 992 | * ktime_get_real_seconds - Get the seconds portion of CLOCK_REALTIME |
| 993 | 993 | * |
| 994 | − * Returns the wall clock seconds since 1970. This replaces the | |
| 995 | − * get_seconds() interface which is not y2038 safe on 32bit systems. | |
| 994 | + * Returns the wall clock seconds since 1970. | |
| 996 | 995 | * |
| 997 | 996 | * For 64bit systems the fast access to tk->xtime_sec is preserved. On |
| 998 | 997 | * 32bit systems the access must be protected with the sequence |
| @@ -538,7 +538,7 @@ config KPROBE_EVENTS · 537 unmodified lines | ||
| 538 | 538 | config KPROBE_EVENTS_ON_NOTRACE |
| 539 | 539 | bool "Do NOT protect notrace function from kprobe events" |
| 540 | 540 | depends on KPROBE_EVENTS |
| 541 | − depends on KPROBES_ON_FTRACE | |
| 541 | + depends on DYNAMIC_FTRACE | |
| 542 | 542 | default n |
| 543 | 543 | help |
| 544 | 544 | This is only for the developers who want to debug ftrace itself |
| @@ -96,9 +96,6 @@ unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx) · 95 unmodified lines | ||
| 96 | 96 | { |
| 97 | 97 | unsigned int ret; |
| 98 | 98 | |
| 99 | − if (in_nmi()) /* not supported yet */ | |
| 100 | − return 1; | |
| 101 | − | |
| 102 | 99 | cant_sleep(); |
| 103 | 100 | |
| 104 | 101 | if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) { |
| @@ -394,7 +394,6 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) · 393 unmodified lines | ||
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | if (t->ret_stack == NULL) { |
| 397 | − atomic_set(&t->tracing_graph_pause, 0); | |
| 398 | 397 | atomic_set(&t->trace_overrun, 0); |
| 399 | 398 | t->curr_ret_stack = -1; |
| 400 | 399 | t->curr_ret_depth = -1; |
| @@ -489,7 +488,6 @@ static DEFINE_PER_CPU(struct ftrace_ret_stack *, idle_ret_stack); · 88 unmodified lines | ||
| 489 | 488 | static void |
| 490 | 489 | graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack) |
| 491 | 490 | { |
| 492 | − atomic_set(&t->tracing_graph_pause, 0); | |
| 493 | 491 | atomic_set(&t->trace_overrun, 0); |
| 494 | 492 | t->ftrace_timestamp = 0; |
| 495 | 493 | /* make curr_ret_stack visible before we add the ret_stack */ |
| @@ -2745,7 +2745,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb, · 2744 unmodified lines | ||
| 2745 | 2745 | (entry = this_cpu_read(trace_buffered_event))) { |
| 2746 | 2746 | /* Try to use the per cpu buffer first */ |
| 2747 | 2747 | val = this_cpu_inc_return(trace_buffered_event_cnt); |
| 2748 | − if (val == 1) { | |
| 2748 | + if ((len < (PAGE_SIZE - sizeof(*entry))) && val == 1) { | |
| 2749 | 2749 | trace_event_setup(entry, type, flags, pc); |
| 2750 | 2750 | entry->array[0] = len; |
| 2751 | 2751 | return entry; |
| @@ -1212,7 +1212,8 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, · 1211 unmodified lines | ||
| 1212 | 1212 | mutex_lock(&event_mutex); |
| 1213 | 1213 | list_for_each_entry(file, &tr->events, list) { |
| 1214 | 1214 | call = file->event_call; |
| 1215 | − if (!trace_event_name(call) || !call->class || !call->class->reg) | |
| 1215 | + if ((call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) || | |
| 1216 | + !trace_event_name(call) || !call->class || !call->class->reg) | |
| 1216 | 1217 | continue; |
| 1217 | 1218 | |
| 1218 | 1219 | if (system && strcmp(call->class->system, system->name) != 0) |
| @@ -562,6 +562,8 @@ static int __irqsoff_tracer_init(struct trace_array *tr) · 561 unmodified lines | ||
| 562 | 562 | /* non overwrite screws up the latency tracers */ |
| 563 | 563 | set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1); |
| 564 | 564 | set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1); |
| 565 | + /* without pause, we will produce garbage if another latency occurs */ | |
| 566 | + set_tracer_flag(tr, TRACE_ITER_PAUSE_ON_TRACE, 1); | |
| 565 | 567 | |
| 566 | 568 | tr->max_latency = 0; |
| 567 | 569 | irqsoff_trace = tr; |
| @@ -583,11 +585,13 @@ static void __irqsoff_tracer_reset(struct trace_array *tr) · 15 unmodified lines | ||
| 583 | 585 | { |
| 584 | 586 | int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT; |
| 585 | 587 | int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE; |
| 588 | + int pause_flag = save_flags & TRACE_ITER_PAUSE_ON_TRACE; | |
| 586 | 589 | |
| 587 | 590 | stop_irqsoff_tracer(tr, is_graph(tr)); |
| 588 | 591 | |
| 589 | 592 | set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag); |
| 590 | 593 | set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag); |
| 594 | + set_tracer_flag(tr, TRACE_ITER_PAUSE_ON_TRACE, pause_flag); | |
| 591 | 595 | ftrace_reset_array_ops(tr); |
| 592 | 596 | |
| 593 | 597 | irqsoff_busy = false; |
| @@ -221,9 +221,9 @@ bool trace_kprobe_on_func_entry(struct trace_event_call *call) · 220 unmodified lines | ||
| 221 | 221 | { |
| 222 | 222 | struct trace_kprobe *tk = trace_kprobe_primary_from_call(call); |
| 223 | 223 | |
| 224 | − return tk ? kprobe_on_func_entry(tk->rp.kp.addr, | |
| 224 | + return tk ? (kprobe_on_func_entry(tk->rp.kp.addr, | |
| 225 | 225 | tk->rp.kp.addr ? NULL : tk->rp.kp.symbol_name, |
| 226 | − tk->rp.kp.addr ? 0 : tk->rp.kp.offset) : false; | |
| 226 | + tk->rp.kp.addr ? 0 : tk->rp.kp.offset) == 0) : false; | |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | bool trace_kprobe_error_injectable(struct trace_event_call *call) |
| @@ -434,7 +434,7 @@ static int disable_trace_kprobe(struct trace_event_call *call, · 204 unmodified lines | ||
| 434 | 434 | return 0; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | −#if defined(CONFIG_KPROBES_ON_FTRACE) && \ | |
| 437 | +#if defined(CONFIG_DYNAMIC_FTRACE) && \ | |
| 438 | 438 | !defined(CONFIG_KPROBE_EVENTS_ON_NOTRACE) |
| 439 | 439 | static bool __within_notrace_func(unsigned long addr) |
| 440 | 440 | { |
| @@ -828,9 +828,11 @@ static int trace_kprobe_create(int argc, const char *argv[]) · 387 unmodified lines | ||
| 828 | 828 | } |
| 829 | 829 | if (is_return) |
| 830 | 830 | flags |= TPARG_FL_RETURN; |
| 831 | − if (kprobe_on_func_entry(NULL, symbol, offset)) | |
| 831 | + ret = kprobe_on_func_entry(NULL, symbol, offset); | |
| 832 | + if (ret == 0) | |
| 832 | 833 | flags |= TPARG_FL_FENTRY; |
| 833 | − if (offset && is_return && !(flags & TPARG_FL_FENTRY)) { | |
| 834 | + /* Defer the ENOENT case until register kprobe */ | |
| 835 | + if (ret == -EINVAL && is_return) { | |
| 834 | 836 | trace_probe_log_err(0, BAD_RETPROBE); |
| 835 | 837 | goto parse_error; |
| 836 | 838 | } |
| @@ -1848,12 +1848,6 @@ static void worker_attach_to_pool(struct worker *worker, · 1847 unmodified lines | ||
| 1848 | 1848 | { |
| 1849 | 1849 | mutex_lock(&wq_pool_attach_mutex); |
| 1850 | 1850 | |
| 1851 | − /* | |
| 1852 | − * set_cpus_allowed_ptr() will fail if the cpumask doesn't have any | |
| 1853 | − * online CPUs. It'll be re-applied when any of the CPUs come up. | |
| 1854 | − */ | |
| 1855 | − set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); | |
| 1856 | − | |
| 1857 | 1851 | /* |
| 1858 | 1852 | * The wq_pool_attach_mutex ensures %POOL_DISASSOCIATED remains |
| 1859 | 1853 | * stable across this function. See the comments above the flag |
| @@ -1861,6 +1855,11 @@ static void worker_attach_to_pool(struct worker *worker, · 1 unmodified line | ||
| 1861 | 1855 | */ |
| 1862 | 1856 | if (pool->flags & POOL_DISASSOCIATED) |
| 1863 | 1857 | worker->flags |= WORKER_UNBOUND; |
| 1858 | + else | |
| 1859 | + kthread_set_per_cpu(worker->task, pool->cpu); | |
| 1860 | + | |
| 1861 | + if (worker->rescue_wq) | |
| 1862 | + set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); | |
| 1864 | 1863 | |
| 1865 | 1864 | list_add_tail(&worker->node, &pool->workers); |
| 1866 | 1865 | worker->pool = pool; |
| @@ -1883,6 +1882,7 @@ static void worker_detach_from_pool(struct worker *worker) · 16 unmodified lines | ||
| 1883 | 1882 | |
| 1884 | 1883 | mutex_lock(&wq_pool_attach_mutex); |
| 1885 | 1884 | |
| 1885 | + kthread_set_per_cpu(worker->task, -1); | |
| 1886 | 1886 | list_del(&worker->node); |
| 1887 | 1887 | worker->pool = NULL; |
| 1888 | 1888 | |
| @@ -4919,8 +4919,10 @@ static void unbind_workers(int cpu) · 3030 unmodified lines | ||
| 4919 | 4919 | |
| 4920 | 4920 | raw_spin_unlock_irq(&pool->lock); |
| 4921 | 4921 | |
| 4922 | − for_each_pool_worker(worker, pool) | |
| 4923 | − WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_active_mask) < 0); | |
| 4922 | + for_each_pool_worker(worker, pool) { | |
| 4923 | + kthread_set_per_cpu(worker->task, -1); | |
| 4924 | + WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0); | |
| 4925 | + } | |
| 4924 | 4926 | |
| 4925 | 4927 | mutex_unlock(&wq_pool_attach_mutex); |
| 4926 | 4928 | |
| @@ -4972,9 +4974,11 @@ static void rebind_workers(struct worker_pool *pool) · 45 unmodified lines | ||
| 4972 | 4974 | * of all workers first and then clear UNBOUND. As we're called |
| 4973 | 4975 | * from CPU_ONLINE, the following shouldn't fail. |
| 4974 | 4976 | */ |
| 4975 | − for_each_pool_worker(worker, pool) | |
| 4977 | + for_each_pool_worker(worker, pool) { | |
| 4978 | + kthread_set_per_cpu(worker->task, pool->cpu); | |
| 4976 | 4979 | WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, |
| 4977 | 4980 | pool->attrs->cpumask) < 0); |
| 4981 | + } | |
| 4978 | 4982 | |
| 4979 | 4983 | raw_spin_lock_irq(&pool->lock); |
| 4980 | 4984 | |