We are applying further, lower-prio fixes on top of two ww_mutex fixes in locking/urgent.
Showing the changes to kernel (11 of 691 files). Show all
Unified · Split
| @@ -4321,8 +4321,6 @@ btf_get_prog_ctx_type(struct bpf_verifier_log *log, struct btf *btf, · 4320 unmodified lines | |||
| 4321 | * is not supported yet. | 4321 | * is not supported yet. |
| 4322 | * BPF_PROG_TYPE_RAW_TRACEPOINT is fine. | 4322 | * BPF_PROG_TYPE_RAW_TRACEPOINT is fine. |
| 4323 | */ | 4323 | */ |
| 4324 | if (log->level & BPF_LOG_LEVEL) | ||
| 4325 | bpf_log(log, "arg#%d type is not a struct\n", arg); | ||
| 4326 | return NULL; | 4324 | return NULL; |
| 4327 | } | 4325 | } |
| 4328 | tname = btf_name_by_offset(btf, t->name_off); | 4326 | tname = btf_name_by_offset(btf, t->name_off); |
| @@ -1118,6 +1118,8 @@ static void bpf_prog_clone_free(struct bpf_prog *fp) · 1117 unmodified lines | |||
| 1118 | * clone is guaranteed to not be locked. | 1118 | * clone is guaranteed to not be locked. |
| 1119 | */ | 1119 | */ |
| 1120 | fp->aux = NULL; | 1120 | fp->aux = NULL; |
| 1121 | fp->stats = NULL; | ||
| 1122 | fp->active = NULL; | ||
| 1121 | __bpf_prog_free(fp); | 1123 | __bpf_prog_free(fp); |
| 1122 | } | 1124 | } |
| 1123 | 1125 | ||
| @@ -2342,6 +2344,10 @@ bool __weak bpf_helper_changes_pkt_data(void *func) · 1218 unmodified lines | |||
| 2342 | /* Return TRUE if the JIT backend wants verifier to enable sub-register usage | 2344 | /* Return TRUE if the JIT backend wants verifier to enable sub-register usage |
| 2343 | * analysis code and wants explicit zero extension inserted by verifier. | 2345 | * analysis code and wants explicit zero extension inserted by verifier. |
| 2344 | * Otherwise, return FALSE. | 2346 | * Otherwise, return FALSE. |
| 2347 | * | ||
| 2348 | * The verifier inserts an explicit zero extension after BPF_CMPXCHGs even if | ||
| 2349 | * you don't override this. JITs that don't want these extra insns can detect | ||
| 2350 | * them using insn_is_zext. | ||
| 2345 | */ | 2351 | */ |
| 2346 | bool __weak bpf_jit_needs_zext(void) | 2352 | bool __weak bpf_jit_needs_zext(void) |
| 2347 | { | 2353 | { |
| @@ -504,6 +504,13 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id) · 503 unmodified lines | |||
| 504 | func_id == BPF_FUNC_skc_to_tcp_request_sock; | 504 | func_id == BPF_FUNC_skc_to_tcp_request_sock; |
| 505 | } | 505 | } |
| 506 | 506 | ||
| 507 | static bool is_cmpxchg_insn(const struct bpf_insn *insn) | ||
| 508 | { | ||
| 509 | return BPF_CLASS(insn->code) == BPF_STX && | ||
| 510 | BPF_MODE(insn->code) == BPF_ATOMIC && | ||
| 511 | insn->imm == BPF_CMPXCHG; | ||
| 512 | } | ||
| 513 | |||
| 507 | /* string representation of 'enum bpf_reg_type' */ | 514 | /* string representation of 'enum bpf_reg_type' */ |
| 508 | static const char * const reg_type_str[] = { | 515 | static const char * const reg_type_str[] = { |
| 509 | [NOT_INIT] = "?", | 516 | [NOT_INIT] = "?", |
| @@ -1120,7 +1127,7 @@ static void mark_ptr_not_null_reg(struct bpf_reg_state *reg) · 610 unmodified lines | |||
| 1120 | reg->type = PTR_TO_RDWR_BUF; | 1127 | reg->type = PTR_TO_RDWR_BUF; |
| 1121 | break; | 1128 | break; |
| 1122 | default: | 1129 | default: |
| 1123 | WARN_ON("unknown nullable register type"); | 1130 | WARN_ONCE(1, "unknown nullable register type"); |
| 1124 | } | 1131 | } |
| 1125 | } | 1132 | } |
| 1126 | 1133 | ||
| @@ -1703,7 +1710,11 @@ static bool is_reg64(struct bpf_verifier_env *env, struct bpf_insn *insn, · 576 unmodified lines | |||
| 1703 | } | 1710 | } |
| 1704 | 1711 | ||
| 1705 | if (class == BPF_STX) { | 1712 | if (class == BPF_STX) { |
| 1706 | if (reg->type != SCALAR_VALUE) | 1713 | /* BPF_STX (including atomic variants) has multiple source |
| 1714 | * operands, one of which is a ptr. Check whether the caller is | ||
| 1715 | * asking about it. | ||
| 1716 | */ | ||
| 1717 | if (t == SRC_OP && reg->type != SCALAR_VALUE) | ||
| 1707 | return true; | 1718 | return true; |
| 1708 | return BPF_SIZE(code) == BPF_DW; | 1719 | return BPF_SIZE(code) == BPF_DW; |
| 1709 | } | 1720 | } |
| @@ -1735,22 +1746,38 @@ static bool is_reg64(struct bpf_verifier_env *env, struct bpf_insn *insn, · 25 unmodified lines | |||
| 1735 | return true; | 1746 | return true; |
| 1736 | } | 1747 | } |
| 1737 | 1748 | ||
| 1738 | /* Return TRUE if INSN doesn't have explicit value define. */ | 1749 | /* Return the regno defined by the insn, or -1. */ |
| 1739 | static bool insn_no_def(struct bpf_insn *insn) | 1750 | static int insn_def_regno(const struct bpf_insn *insn) |
| 1740 | { | 1751 | { |
| 1741 | u8 class = BPF_CLASS(insn->code); | 1752 | switch (BPF_CLASS(insn->code)) { |
| 1742 | 1753 | case BPF_JMP: | |
| 1743 | return (class == BPF_JMP || class == BPF_JMP32 || | 1754 | case BPF_JMP32: |
| 1744 | class == BPF_STX || class == BPF_ST); | 1755 | case BPF_ST: |
| 1756 | return -1; | ||
| 1757 | case BPF_STX: | ||
| 1758 | if (BPF_MODE(insn->code) == BPF_ATOMIC && | ||
| 1759 | (insn->imm & BPF_FETCH)) { | ||
| 1760 | if (insn->imm == BPF_CMPXCHG) | ||
| 1761 | return BPF_REG_0; | ||
| 1762 | else | ||
| 1763 | return insn->src_reg; | ||
| 1764 | } else { | ||
| 1765 | return -1; | ||
| 1766 | } | ||
| 1767 | default: | ||
| 1768 | return insn->dst_reg; | ||
| 1769 | } | ||
| 1745 | } | 1770 | } |
| 1746 | 1771 | ||
| 1747 | /* Return TRUE if INSN has defined any 32-bit value explicitly. */ | 1772 | /* Return TRUE if INSN has defined any 32-bit value explicitly. */ |
| 1748 | static bool insn_has_def32(struct bpf_verifier_env *env, struct bpf_insn *insn) | 1773 | static bool insn_has_def32(struct bpf_verifier_env *env, struct bpf_insn *insn) |
| 1749 | { | 1774 | { |
| 1750 | if (insn_no_def(insn)) | 1775 | int dst_reg = insn_def_regno(insn); |
| 1776 | |||
| 1777 | if (dst_reg == -1) | ||
| 1751 | return false; | 1778 | return false; |
| 1752 | 1779 | ||
| 1753 | return !is_reg64(env, insn, insn->dst_reg, NULL, DST_OP); | 1780 | return !is_reg64(env, insn, dst_reg, NULL, DST_OP); |
| 1754 | } | 1781 | } |
| 1755 | 1782 | ||
| 1756 | static void mark_insn_zext(struct bpf_verifier_env *env, | 1783 | static void mark_insn_zext(struct bpf_verifier_env *env, |
| @@ -11006,9 +11033,10 @@ static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env, · 9249 unmodified lines | |||
| 11006 | for (i = 0; i < len; i++) { | 11033 | for (i = 0; i < len; i++) { |
| 11007 | int adj_idx = i + delta; | 11034 | int adj_idx = i + delta; |
| 11008 | struct bpf_insn insn; | 11035 | struct bpf_insn insn; |
| 11009 | u8 load_reg; | 11036 | int load_reg; |
| 11010 | 11037 | ||
| 11011 | insn = insns[adj_idx]; | 11038 | insn = insns[adj_idx]; |
| 11039 | load_reg = insn_def_regno(&insn); | ||
| 11012 | if (!aux[adj_idx].zext_dst) { | 11040 | if (!aux[adj_idx].zext_dst) { |
| 11013 | u8 code, class; | 11041 | u8 code, class; |
| 11014 | u32 imm_rnd; | 11042 | u32 imm_rnd; |
| @@ -11018,14 +11046,14 @@ static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env, · 3 unmodified lines | |||
| 11018 | 11046 | ||
| 11019 | code = insn.code; | 11047 | code = insn.code; |
| 11020 | class = BPF_CLASS(code); | 11048 | class = BPF_CLASS(code); |
| 11021 | if (insn_no_def(&insn)) | 11049 | if (load_reg == -1) |
| 11022 | continue; | 11050 | continue; |
| 11023 | 11051 | ||
| 11024 | /* NOTE: arg "reg" (the fourth one) is only used for | 11052 | /* NOTE: arg "reg" (the fourth one) is only used for |
| 11025 | * BPF_STX which has been ruled out in above | 11053 | * BPF_STX + SRC_OP, so it is safe to pass NULL |
| 11026 | * check, it is safe to pass NULL here. | 11054 | * here. |
| 11027 | */ | 11055 | */ |
| 11028 | if (is_reg64(env, &insn, insn.dst_reg, NULL, DST_OP)) { | 11056 | if (is_reg64(env, &insn, load_reg, NULL, DST_OP)) { |
| 11029 | if (class == BPF_LD && | 11057 | if (class == BPF_LD && |
| 11030 | BPF_MODE(code) == BPF_IMM) | 11058 | BPF_MODE(code) == BPF_IMM) |
| 11031 | i++; | 11059 | i++; |
| @@ -11040,31 +11068,28 @@ static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env, · 8 unmodified lines | |||
| 11040 | imm_rnd = get_random_int(); | 11068 | imm_rnd = get_random_int(); |
| 11041 | rnd_hi32_patch[0] = insn; | 11069 | rnd_hi32_patch[0] = insn; |
| 11042 | rnd_hi32_patch[1].imm = imm_rnd; | 11070 | rnd_hi32_patch[1].imm = imm_rnd; |
| 11043 | rnd_hi32_patch[3].dst_reg = insn.dst_reg; | 11071 | rnd_hi32_patch[3].dst_reg = load_reg; |
| 11044 | patch = rnd_hi32_patch; | 11072 | patch = rnd_hi32_patch; |
| 11045 | patch_len = 4; | 11073 | patch_len = 4; |
| 11046 | goto apply_patch_buffer; | 11074 | goto apply_patch_buffer; |
| 11047 | } | 11075 | } |
| 11048 | 11076 | ||
| 11049 | if (!bpf_jit_needs_zext()) | 11077 | /* Add in an zero-extend instruction if a) the JIT has requested |
| 11078 | * it or b) it's a CMPXCHG. | ||
| 11079 | * | ||
| 11080 | * The latter is because: BPF_CMPXCHG always loads a value into | ||
| 11081 | * R0, therefore always zero-extends. However some archs' | ||
| 11082 | * equivalent instruction only does this load when the | ||
| 11083 | * comparison is successful. This detail of CMPXCHG is | ||
| 11084 | * orthogonal to the general zero-extension behaviour of the | ||
| 11085 | * CPU, so it's treated independently of bpf_jit_needs_zext. | ||
| 11086 | */ | ||
| 11087 | if (!bpf_jit_needs_zext() && !is_cmpxchg_insn(&insn)) | ||
| 11050 | continue; | 11088 | continue; |
| 11051 | 11089 | ||
| 11052 | /* zext_dst means that we want to zero-extend whatever register | 11090 | if (WARN_ON(load_reg == -1)) { |
| 11053 | * the insn defines, which is dst_reg most of the time, with | 11091 | verbose(env, "verifier bug. zext_dst is set, but no reg is defined\n"); |
| 11054 | * the notable exception of BPF_STX + BPF_ATOMIC + BPF_FETCH. | 11092 | return -EFAULT; |
| 11055 | */ | ||
| 11056 | if (BPF_CLASS(insn.code) == BPF_STX && | ||
| 11057 | BPF_MODE(insn.code) == BPF_ATOMIC) { | ||
| 11058 | /* BPF_STX + BPF_ATOMIC insns without BPF_FETCH do not | ||
| 11059 | * define any registers, therefore zext_dst cannot be | ||
| 11060 | * set. | ||
| 11061 | */ | ||
| 11062 | if (WARN_ON(!(insn.imm & BPF_FETCH))) | ||
| 11063 | return -EINVAL; | ||
| 11064 | load_reg = insn.imm == BPF_CMPXCHG ? BPF_REG_0 | ||
| 11065 | : insn.src_reg; | ||
| 11066 | } else { | ||
| 11067 | load_reg = insn.dst_reg; | ||
| 11068 | } | 11093 | } |
| 11069 | 11094 | ||
| 11070 | zext_patch[0] = insn; | 11095 | zext_patch[0] = insn; |
| @@ -386,6 +386,7 @@ static DEFINE_MUTEX(perf_sched_mutex); · 385 unmodified lines | |||
| 386 | static atomic_t perf_sched_count; | 386 | static atomic_t perf_sched_count; |
| 387 | 387 | ||
| 388 | static DEFINE_PER_CPU(atomic_t, perf_cgroup_events); | 388 | static DEFINE_PER_CPU(atomic_t, perf_cgroup_events); |
| 389 | static DEFINE_PER_CPU(int, perf_sched_cb_usages); | ||
| 389 | static DEFINE_PER_CPU(struct pmu_event_list, pmu_sb_events); | 390 | static DEFINE_PER_CPU(struct pmu_event_list, pmu_sb_events); |
| 390 | 391 | ||
| 391 | static atomic_t nr_mmap_events __read_mostly; | 392 | static atomic_t nr_mmap_events __read_mostly; |
| @@ -3461,11 +3462,16 @@ unlock: · 3069 unmodified lines | |||
| 3461 | } | 3462 | } |
| 3462 | } | 3463 | } |
| 3463 | 3464 | ||
| 3465 | static DEFINE_PER_CPU(struct list_head, sched_cb_list); | ||
| 3466 | |||
| 3464 | void perf_sched_cb_dec(struct pmu *pmu) | 3467 | void perf_sched_cb_dec(struct pmu *pmu) |
| 3465 | { | 3468 | { |
| 3466 | struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); | 3469 | struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); |
| 3467 | 3470 | ||
| 3468 | --cpuctx->sched_cb_usage; | 3471 | this_cpu_dec(perf_sched_cb_usages); |
| 3472 | |||
| 3473 | if (!--cpuctx->sched_cb_usage) | ||
| 3474 | list_del(&cpuctx->sched_cb_entry); | ||
| 3469 | } | 3475 | } |
| 3470 | 3476 | ||
| 3471 | 3477 | ||
| @@ -3473,7 +3479,10 @@ void perf_sched_cb_inc(struct pmu *pmu) · 1 unmodified line | |||
| 3473 | { | 3479 | { |
| 3474 | struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); | 3480 | struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); |
| 3475 | 3481 | ||
| 3476 | cpuctx->sched_cb_usage++; | 3482 | if (!cpuctx->sched_cb_usage++) |
| 3483 | list_add(&cpuctx->sched_cb_entry, this_cpu_ptr(&sched_cb_list)); | ||
| 3484 | |||
| 3485 | this_cpu_inc(perf_sched_cb_usages); | ||
| 3477 | } | 3486 | } |
| 3478 | 3487 | ||
| 3479 | /* | 3488 | /* |
| @@ -3502,6 +3511,24 @@ static void __perf_pmu_sched_task(struct perf_cpu_context *cpuctx, bool sched_in · 22 unmodified lines | |||
| 3502 | perf_ctx_unlock(cpuctx, cpuctx->task_ctx); | 3511 | perf_ctx_unlock(cpuctx, cpuctx->task_ctx); |
| 3503 | } | 3512 | } |
| 3504 | 3513 | ||
| 3514 | static void perf_pmu_sched_task(struct task_struct *prev, | ||
| 3515 | struct task_struct *next, | ||
| 3516 | bool sched_in) | ||
| 3517 | { | ||
| 3518 | struct perf_cpu_context *cpuctx; | ||
| 3519 | |||
| 3520 | if (prev == next) | ||
| 3521 | return; | ||
| 3522 | |||
| 3523 | list_for_each_entry(cpuctx, this_cpu_ptr(&sched_cb_list), sched_cb_entry) { | ||
| 3524 | /* will be handled in perf_event_context_sched_in/out */ | ||
| 3525 | if (cpuctx->task_ctx) | ||
| 3526 | continue; | ||
| 3527 | |||
| 3528 | __perf_pmu_sched_task(cpuctx, sched_in); | ||
| 3529 | } | ||
| 3530 | } | ||
| 3531 | |||
| 3505 | static void perf_event_switch(struct task_struct *task, | 3532 | static void perf_event_switch(struct task_struct *task, |
| 3506 | struct task_struct *next_prev, bool sched_in); | 3533 | struct task_struct *next_prev, bool sched_in); |
| 3507 | 3534 | ||
| @@ -3524,6 +3551,9 @@ void __perf_event_task_sched_out(struct task_struct *task, · 16 unmodified lines | |||
| 3524 | { | 3551 | { |
| 3525 | int ctxn; | 3552 | int ctxn; |
| 3526 | 3553 | ||
| 3554 | if (__this_cpu_read(perf_sched_cb_usages)) | ||
| 3555 | perf_pmu_sched_task(task, next, false); | ||
| 3556 | |||
| 3527 | if (atomic_read(&nr_switch_events)) | 3557 | if (atomic_read(&nr_switch_events)) |
| 3528 | perf_event_switch(task, next, false); | 3558 | perf_event_switch(task, next, false); |
| 3529 | 3559 | ||
| @@ -3832,6 +3862,9 @@ void __perf_event_task_sched_in(struct task_struct *prev, · 302 unmodified lines | |||
| 3832 | 3862 | ||
| 3833 | if (atomic_read(&nr_switch_events)) | 3863 | if (atomic_read(&nr_switch_events)) |
| 3834 | perf_event_switch(task, prev, true); | 3864 | perf_event_switch(task, prev, true); |
| 3865 | |||
| 3866 | if (__this_cpu_read(perf_sched_cb_usages)) | ||
| 3867 | perf_pmu_sched_task(prev, task, true); | ||
| 3835 | } | 3868 | } |
| 3836 | 3869 | ||
| 3837 | static u64 perf_calculate_period(struct perf_event *event, u64 nsec, u64 count) | 3870 | static u64 perf_calculate_period(struct perf_event *event, u64 nsec, u64 count) |
| @@ -4656,7 +4689,7 @@ static void unaccount_event(struct perf_event *event) · 818 unmodified lines | |||
| 4656 | if (event->parent) | 4689 | if (event->parent) |
| 4657 | return; | 4690 | return; |
| 4658 | 4691 | ||
| 4659 | if (event->attach_state & PERF_ATTACH_TASK) | 4692 | if (event->attach_state & (PERF_ATTACH_TASK | PERF_ATTACH_SCHED_CB)) |
| 4660 | dec = true; | 4693 | dec = true; |
| 4661 | if (event->attr.mmap || event->attr.mmap_data) | 4694 | if (event->attr.mmap || event->attr.mmap_data) |
| 4662 | atomic_dec(&nr_mmap_events); | 4695 | atomic_dec(&nr_mmap_events); |
| @@ -11175,7 +11208,7 @@ static void account_event(struct perf_event *event) · 6512 unmodified lines | |||
| 11175 | if (event->parent) | 11208 | if (event->parent) |
| 11176 | return; | 11209 | return; |
| 11177 | 11210 | ||
| 11178 | if (event->attach_state & PERF_ATTACH_TASK) | 11211 | if (event->attach_state & (PERF_ATTACH_TASK | PERF_ATTACH_SCHED_CB)) |
| 11179 | inc = true; | 11212 | inc = true; |
| 11180 | if (event->attr.mmap || event->attr.mmap_data) | 11213 | if (event->attr.mmap || event->attr.mmap_data) |
| 11181 | atomic_inc(&nr_mmap_events); | 11214 | atomic_inc(&nr_mmap_events); |
| @@ -12972,6 +13005,7 @@ static void __init perf_event_init_all_cpus(void) · 1790 unmodified lines | |||
| 12972 | #ifdef CONFIG_CGROUP_PERF | 13005 | #ifdef CONFIG_CGROUP_PERF |
| 12973 | INIT_LIST_HEAD(&per_cpu(cgrp_cpuctx_list, cpu)); | 13006 | INIT_LIST_HEAD(&per_cpu(cgrp_cpuctx_list, cpu)); |
| 12974 | #endif | 13007 | #endif |
| 13008 | INIT_LIST_HEAD(&per_cpu(sched_cb_list, cpu)); | ||
| 12975 | } | 13009 | } |
| 12976 | } | 13010 | } |
| 12977 | 13011 | ||
| @@ -994,6 +994,13 @@ static void mm_init_owner(struct mm_struct *mm, struct task_struct *p) · 993 unmodified lines | |||
| 994 | #endif | 994 | #endif |
| 995 | } | 995 | } |
| 996 | 996 | ||
| 997 | static void mm_init_pasid(struct mm_struct *mm) | ||
| 998 | { | ||
| 999 | #ifdef CONFIG_IOMMU_SUPPORT | ||
| 1000 | mm->pasid = INIT_PASID; | ||
| 1001 | #endif | ||
| 1002 | } | ||
| 1003 | |||
| 997 | static void mm_init_uprobes_state(struct mm_struct *mm) | 1004 | static void mm_init_uprobes_state(struct mm_struct *mm) |
| 998 | { | 1005 | { |
| 999 | #ifdef CONFIG_UPROBES | 1006 | #ifdef CONFIG_UPROBES |
| @@ -1024,6 +1031,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, · 24 unmodified lines | |||
| 1024 | mm_init_cpumask(mm); | 1031 | mm_init_cpumask(mm); |
| 1025 | mm_init_aio(mm); | 1032 | mm_init_aio(mm); |
| 1026 | mm_init_owner(mm, p); | 1033 | mm_init_owner(mm, p); |
| 1034 | mm_init_pasid(mm); | ||
| 1027 | RCU_INIT_POINTER(mm->exe_file, NULL); | 1035 | RCU_INIT_POINTER(mm->exe_file, NULL); |
| 1028 | mmu_notifier_subscriptions_init(mm); | 1036 | mmu_notifier_subscriptions_init(mm); |
| 1029 | init_tlb_flush_pending(mm); | 1037 | init_tlb_flush_pending(mm); |
| @@ -2436,6 +2444,7 @@ struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node) · 1406 unmodified lines | |||
| 2436 | if (!IS_ERR(tsk)) { | 2444 | if (!IS_ERR(tsk)) { |
| 2437 | sigfillset(&tsk->blocked); | 2445 | sigfillset(&tsk->blocked); |
| 2438 | sigdelsetmask(&tsk->blocked, sigmask(SIGKILL)); | 2446 | sigdelsetmask(&tsk->blocked, sigmask(SIGKILL)); |
| 2447 | tsk->flags |= PF_NOFREEZE; | ||
| 2439 | } | 2448 | } |
| 2440 | return tsk; | 2449 | return tsk; |
| 2441 | } | 2450 | } |
| @@ -1898,16 +1898,15 @@ DEFINE_SHOW_ATTRIBUTE(irq_domain_debug); · 1897 unmodified lines | |||
| 1898 | 1898 | ||
| 1899 | static void debugfs_add_domain_dir(struct irq_domain *d) | 1899 | static void debugfs_add_domain_dir(struct irq_domain *d) |
| 1900 | { | 1900 | { |
| 1901 | if (!d->name || !domain_dir || d->debugfs_file) | 1901 | if (!d->name || !domain_dir) |
| 1902 | return; | 1902 | return; |
| 1903 | d->debugfs_file = debugfs_create_file(d->name, 0444, domain_dir, d, | 1903 | debugfs_create_file(d->name, 0444, domain_dir, d, |
| 1904 | &irq_domain_debug_fops); | 1904 | &irq_domain_debug_fops); |
| 1905 | } | 1905 | } |
| 1906 | 1906 | ||
| 1907 | static void debugfs_remove_domain_dir(struct irq_domain *d) | 1907 | static void debugfs_remove_domain_dir(struct irq_domain *d) |
| 1908 | { | 1908 | { |
| 1909 | debugfs_remove(d->debugfs_file); | 1909 | debugfs_remove(debugfs_lookup(d->name, domain_dir)); |
| 1910 | d->debugfs_file = NULL; | ||
| 1911 | } | 1910 | } |
| 1912 | 1911 | ||
| 1913 | void __init irq_domain_debugfs_init(struct dentry *root) | 1912 | void __init irq_domain_debugfs_init(struct dentry *root) |
| @@ -626,7 +626,7 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock) · 625 unmodified lines | |||
| 626 | */ | 626 | */ |
| 627 | static __always_inline bool | 627 | static __always_inline bool |
| 628 | mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, | 628 | mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, |
| 629 | const bool use_ww_ctx, struct mutex_waiter *waiter) | 629 | struct mutex_waiter *waiter) |
| 630 | { | 630 | { |
| 631 | if (!waiter) { | 631 | if (!waiter) { |
| 632 | /* | 632 | /* |
| @@ -702,7 +702,7 @@ fail: · 69 unmodified lines | |||
| 702 | #else | 702 | #else |
| 703 | static __always_inline bool | 703 | static __always_inline bool |
| 704 | mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, | 704 | mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, |
| 705 | const bool use_ww_ctx, struct mutex_waiter *waiter) | 705 | struct mutex_waiter *waiter) |
| 706 | { | 706 | { |
| 707 | return false; | 707 | return false; |
| 708 | } | 708 | } |
| @@ -922,6 +922,9 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 213 unmodified lines | |||
| 922 | struct ww_mutex *ww; | 922 | struct ww_mutex *ww; |
| 923 | int ret; | 923 | int ret; |
| 924 | 924 | ||
| 925 | if (!use_ww_ctx) | ||
| 926 | ww_ctx = NULL; | ||
| 927 | |||
| 925 | might_sleep(); | 928 | might_sleep(); |
| 926 | 929 | ||
| 927 | #ifdef CONFIG_DEBUG_MUTEXES | 930 | #ifdef CONFIG_DEBUG_MUTEXES |
| @@ -929,7 +932,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 1 unmodified line | |||
| 929 | #endif | 932 | #endif |
| 930 | 933 | ||
| 931 | ww = container_of(lock, struct ww_mutex, base); | 934 | ww = container_of(lock, struct ww_mutex, base); |
| 932 | if (use_ww_ctx && ww_ctx) { | 935 | if (ww_ctx) { |
| 933 | if (unlikely(ww_ctx == READ_ONCE(ww->ctx))) | 936 | if (unlikely(ww_ctx == READ_ONCE(ww->ctx))) |
| 934 | return -EALREADY; | 937 | return -EALREADY; |
| 935 | 938 | ||
| @@ -946,10 +949,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 10 unmodified lines | |||
| 946 | mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip); | 949 | mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip); |
| 947 | 950 | ||
| 948 | if (__mutex_trylock(lock) || | 951 | if (__mutex_trylock(lock) || |
| 949 | mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, NULL)) { | 952 | mutex_optimistic_spin(lock, ww_ctx, NULL)) { |
| 950 | /* got the lock, yay! */ | 953 | /* got the lock, yay! */ |
| 951 | lock_acquired(&lock->dep_map, ip); | 954 | lock_acquired(&lock->dep_map, ip); |
| 952 | if (use_ww_ctx && ww_ctx) | 955 | if (ww_ctx) |
| 953 | ww_mutex_set_context_fastpath(ww, ww_ctx); | 956 | ww_mutex_set_context_fastpath(ww, ww_ctx); |
| 954 | preempt_enable(); | 957 | preempt_enable(); |
| 955 | return 0; | 958 | return 0; |
| @@ -960,7 +963,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 4 unmodified lines | |||
| 960 | * After waiting to acquire the wait_lock, try again. | 963 | * After waiting to acquire the wait_lock, try again. |
| 961 | */ | 964 | */ |
| 962 | if (__mutex_trylock(lock)) { | 965 | if (__mutex_trylock(lock)) { |
| 963 | if (use_ww_ctx && ww_ctx) | 966 | if (ww_ctx) |
| 964 | __ww_mutex_check_waiters(lock, ww_ctx); | 967 | __ww_mutex_check_waiters(lock, ww_ctx); |
| 965 | 968 | ||
| 966 | goto skip_wait; | 969 | goto skip_wait; |
| @@ -1013,7 +1016,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 46 unmodified lines | |||
| 1013 | goto err; | 1016 | goto err; |
| 1014 | } | 1017 | } |
| 1015 | 1018 | ||
| 1016 | if (use_ww_ctx && ww_ctx) { | 1019 | if (ww_ctx) { |
| 1017 | ret = __ww_mutex_check_kill(lock, &waiter, ww_ctx); | 1020 | ret = __ww_mutex_check_kill(lock, &waiter, ww_ctx); |
| 1018 | if (ret) | 1021 | if (ret) |
| 1019 | goto err; | 1022 | goto err; |
| @@ -1026,7 +1029,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 6 unmodified lines | |||
| 1026 | * ww_mutex needs to always recheck its position since its waiter | 1029 | * ww_mutex needs to always recheck its position since its waiter |
| 1027 | * list is not FIFO ordered. | 1030 | * list is not FIFO ordered. |
| 1028 | */ | 1031 | */ |
| 1029 | if ((use_ww_ctx && ww_ctx) || !first) { | 1032 | if (ww_ctx || !first) { |
| 1030 | first = __mutex_waiter_is_first(lock, &waiter); | 1033 | first = __mutex_waiter_is_first(lock, &waiter); |
| 1031 | if (first) | 1034 | if (first) |
| 1032 | __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); | 1035 | __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); |
| @@ -1039,7 +1042,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 6 unmodified lines | |||
| 1039 | * or we must see its unlock and acquire. | 1042 | * or we must see its unlock and acquire. |
| 1040 | */ | 1043 | */ |
| 1041 | if (__mutex_trylock(lock) || | 1044 | if (__mutex_trylock(lock) || |
| 1042 | (first && mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, &waiter))) | 1045 | (first && mutex_optimistic_spin(lock, ww_ctx, &waiter))) |
| 1043 | break; | 1046 | break; |
| 1044 | 1047 | ||
| 1045 | spin_lock(&lock->wait_lock); | 1048 | spin_lock(&lock->wait_lock); |
| @@ -1048,7 +1051,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, · 2 unmodified lines | |||
| 1048 | acquired: | 1051 | acquired: |
| 1049 | __set_current_state(TASK_RUNNING); | 1052 | __set_current_state(TASK_RUNNING); |
| 1050 | 1053 | ||
| 1051 | if (use_ww_ctx && ww_ctx) { | 1054 | if (ww_ctx) { |
| 1052 | /* | 1055 | /* |
| 1053 | * Wound-Wait; we stole the lock (!first_waiter), check the | 1056 | * Wound-Wait; we stole the lock (!first_waiter), check the |
| 1054 | * waiters as anyone might want to wound us. | 1057 | * waiters as anyone might want to wound us. |
| @@ -1068,7 +1071,7 @@ skip_wait: · 13 unmodified lines | |||
| 1068 | /* got the lock - cleanup and rejoice! */ | 1071 | /* got the lock - cleanup and rejoice! */ |
| 1069 | lock_acquired(&lock->dep_map, ip); | 1072 | lock_acquired(&lock->dep_map, ip); |
| 1070 | 1073 | ||
| 1071 | if (use_ww_ctx && ww_ctx) | 1074 | if (ww_ctx) |
| 1072 | ww_mutex_lock_acquired(ww, ww_ctx); | 1075 | ww_mutex_lock_acquired(ww, ww_ctx); |
| 1073 | 1076 | ||
| 1074 | spin_unlock(&lock->wait_lock); | 1077 | spin_unlock(&lock->wait_lock); |
| @@ -1862,8 +1862,13 @@ struct migration_arg { · 1861 unmodified lines | |||
| 1862 | struct set_affinity_pending *pending; | 1862 | struct set_affinity_pending *pending; |
| 1863 | }; | 1863 | }; |
| 1864 | 1864 | ||
| 1865 | /* | ||
| 1866 | * @refs: number of wait_for_completion() | ||
| 1867 | * @stop_pending: is @stop_work in use | ||
| 1868 | */ | ||
| 1865 | struct set_affinity_pending { | 1869 | struct set_affinity_pending { |
| 1866 | refcount_t refs; | 1870 | refcount_t refs; |
| 1871 | unsigned int stop_pending; | ||
| 1867 | struct completion done; | 1872 | struct completion done; |
| 1868 | struct cpu_stop_work stop_work; | 1873 | struct cpu_stop_work stop_work; |
| 1869 | struct migration_arg arg; | 1874 | struct migration_arg arg; |
| @@ -1898,8 +1903,8 @@ static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf, · 28 unmodified lines | |||
| 1898 | */ | 1903 | */ |
| 1899 | static int migration_cpu_stop(void *data) | 1904 | static int migration_cpu_stop(void *data) |
| 1900 | { | 1905 | { |
| 1901 | struct set_affinity_pending *pending; | ||
| 1902 | struct migration_arg *arg = data; | 1906 | struct migration_arg *arg = data; |
| 1907 | struct set_affinity_pending *pending = arg->pending; | ||
| 1903 | struct task_struct *p = arg->task; | 1908 | struct task_struct *p = arg->task; |
| 1904 | int dest_cpu = arg->dest_cpu; | 1909 | int dest_cpu = arg->dest_cpu; |
| 1905 | struct rq *rq = this_rq(); | 1910 | struct rq *rq = this_rq(); |
| @@ -1921,7 +1926,6 @@ static int migration_cpu_stop(void *data) · 15 unmodified lines | |||
| 1921 | raw_spin_lock(&p->pi_lock); | 1926 | raw_spin_lock(&p->pi_lock); |
| 1922 | rq_lock(rq, &rf); | 1927 | rq_lock(rq, &rf); |
| 1923 | 1928 | ||
| 1924 | pending = p->migration_pending; | ||
| 1925 | /* | 1929 | /* |
| 1926 | * If task_rq(p) != rq, it cannot be migrated here, because we're | 1930 | * If task_rq(p) != rq, it cannot be migrated here, because we're |
| 1927 | * holding rq->lock, if p->on_rq == 0 it cannot get enqueued because | 1931 | * holding rq->lock, if p->on_rq == 0 it cannot get enqueued because |
| @@ -1932,21 +1936,14 @@ static int migration_cpu_stop(void *data) · 4 unmodified lines | |||
| 1932 | goto out; | 1936 | goto out; |
| 1933 | 1937 | ||
| 1934 | if (pending) { | 1938 | if (pending) { |
| 1935 | p->migration_pending = NULL; | 1939 | if (p->migration_pending == pending) |
| 1940 | p->migration_pending = NULL; | ||
| 1936 | complete = true; | 1941 | complete = true; |
| 1937 | } | 1942 | } |
| 1938 | 1943 | ||
| 1939 | /* migrate_enable() -- we must not race against SCA */ | ||
| 1940 | if (dest_cpu < 0) { | 1944 | if (dest_cpu < 0) { |
| 1941 | /* | 1945 | if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask)) |
| 1942 | * When this was migrate_enable() but we no longer | ||
| 1943 | * have a @pending, a concurrent SCA 'fixed' things | ||
| 1944 | * and we should be valid again. Nothing to do. | ||
| 1945 | */ | ||
| 1946 | if (!pending) { | ||
| 1947 | WARN_ON_ONCE(!cpumask_test_cpu(task_cpu(p), &p->cpus_mask)); | ||
| 1948 | goto out; | 1946 | goto out; |
| 1949 | } | ||
| 1950 | 1947 | ||
| 1951 | dest_cpu = cpumask_any_distribute(&p->cpus_mask); | 1948 | dest_cpu = cpumask_any_distribute(&p->cpus_mask); |
| 1952 | } | 1949 | } |
| @@ -1956,7 +1953,14 @@ static int migration_cpu_stop(void *data) · 3 unmodified lines | |||
| 1956 | else | 1953 | else |
| 1957 | p->wake_cpu = dest_cpu; | 1954 | p->wake_cpu = dest_cpu; |
| 1958 | 1955 | ||
| 1959 | } else if (dest_cpu < 0 || pending) { | 1956 | /* |
| 1957 | * XXX __migrate_task() can fail, at which point we might end | ||
| 1958 | * up running on a dodgy CPU, AFAICT this can only happen | ||
| 1959 | * during CPU hotplug, at which point we'll get pushed out | ||
| 1960 | * anyway, so it's probably not a big deal. | ||
| 1961 | */ | ||
| 1962 | |||
| 1963 | } else if (pending) { | ||
| 1960 | /* | 1964 | /* |
| 1961 | * This happens when we get migrated between migrate_enable()'s | 1965 | * This happens when we get migrated between migrate_enable()'s |
| 1962 | * preempt_enable() and scheduling the stopper task. At that | 1966 | * preempt_enable() and scheduling the stopper task. At that |
| @@ -1971,43 +1975,32 @@ static int migration_cpu_stop(void *data) · 8 unmodified lines | |||
| 1971 | * ->pi_lock, so the allowed mask is stable - if it got | 1975 | * ->pi_lock, so the allowed mask is stable - if it got |
| 1972 | * somewhere allowed, we're done. | 1976 | * somewhere allowed, we're done. |
| 1973 | */ | 1977 | */ |
| 1974 | if (pending && cpumask_test_cpu(task_cpu(p), p->cpus_ptr)) { | 1978 | if (cpumask_test_cpu(task_cpu(p), p->cpus_ptr)) { |
| 1975 | p->migration_pending = NULL; | 1979 | if (p->migration_pending == pending) |
| 1980 | p->migration_pending = NULL; | ||
| 1976 | complete = true; | 1981 | complete = true; |
| 1977 | goto out; | 1982 | goto out; |
| 1978 | } | 1983 | } |
| 1979 | 1984 | ||
| 1980 | /* | ||
| 1981 | * When this was migrate_enable() but we no longer have an | ||
| 1982 | * @pending, a concurrent SCA 'fixed' things and we should be | ||
| 1983 | * valid again. Nothing to do. | ||
| 1984 | */ | ||
| 1985 | if (!pending) { | ||
| 1986 | WARN_ON_ONCE(!cpumask_test_cpu(task_cpu(p), &p->cpus_mask)); | ||
| 1987 | goto out; | ||
| 1988 | } | ||
| 1989 | |||
| 1990 | /* | 1985 | /* |
| 1991 | * When migrate_enable() hits a rq mis-match we can't reliably | 1986 | * When migrate_enable() hits a rq mis-match we can't reliably |
| 1992 | * determine is_migration_disabled() and so have to chase after | 1987 | * determine is_migration_disabled() and so have to chase after |
| 1993 | * it. | 1988 | * it. |
| 1994 | */ | 1989 | */ |
| 1990 | WARN_ON_ONCE(!pending->stop_pending); | ||
| 1995 | task_rq_unlock(rq, p, &rf); | 1991 | task_rq_unlock(rq, p, &rf); |
| 1996 | stop_one_cpu_nowait(task_cpu(p), migration_cpu_stop, | 1992 | stop_one_cpu_nowait(task_cpu(p), migration_cpu_stop, |
| 1997 | &pending->arg, &pending->stop_work); | 1993 | &pending->arg, &pending->stop_work); |
| 1998 | return 0; | 1994 | return 0; |
| 1999 | } | 1995 | } |
| 2000 | out: | 1996 | out: |
| 1997 | if (pending) | ||
| 1998 | pending->stop_pending = false; | ||
| 2001 | task_rq_unlock(rq, p, &rf); | 1999 | task_rq_unlock(rq, p, &rf); |
| 2002 | 2000 | ||
| 2003 | if (complete) | 2001 | if (complete) |
| 2004 | complete_all(&pending->done); | 2002 | complete_all(&pending->done); |
| 2005 | 2003 | ||
| 2006 | /* For pending->{arg,stop_work} */ | ||
| 2007 | pending = arg->pending; | ||
| 2008 | if (pending && refcount_dec_and_test(&pending->refs)) | ||
| 2009 | wake_up_var(&pending->refs); | ||
| 2010 | |||
| 2011 | return 0; | 2004 | return 0; |
| 2012 | } | 2005 | } |
| 2013 | 2006 | ||
| @@ -2194,11 +2187,7 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag · 180 unmodified lines | |||
| 2194 | int dest_cpu, unsigned int flags) | 2187 | int dest_cpu, unsigned int flags) |
| 2195 | { | 2188 | { |
| 2196 | struct set_affinity_pending my_pending = { }, *pending = NULL; | 2189 | struct set_affinity_pending my_pending = { }, *pending = NULL; |
| 2197 | struct migration_arg arg = { | 2190 | bool stop_pending, complete = false; |
| 2198 | .task = p, | ||
| 2199 | .dest_cpu = dest_cpu, | ||
| 2200 | }; | ||
| 2201 | bool complete = false; | ||
| 2202 | 2191 | ||
| 2203 | /* Can the task run on the task's current CPU? If so, we're done */ | 2192 | /* Can the task run on the task's current CPU? If so, we're done */ |
| 2204 | if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask)) { | 2193 | if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask)) { |
| @@ -2210,12 +2199,16 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag · 5 unmodified lines | |||
| 2210 | push_task = get_task_struct(p); | 2199 | push_task = get_task_struct(p); |
| 2211 | } | 2200 | } |
| 2212 | 2201 | ||
| 2202 | /* | ||
| 2203 | * If there are pending waiters, but no pending stop_work, | ||
| 2204 | * then complete now. | ||
| 2205 | */ | ||
| 2213 | pending = p->migration_pending; | 2206 | pending = p->migration_pending; |
| 2214 | if (pending) { | 2207 | if (pending && !pending->stop_pending) { |
| 2215 | refcount_inc(&pending->refs); | ||
| 2216 | p->migration_pending = NULL; | 2208 | p->migration_pending = NULL; |
| 2217 | complete = true; | 2209 | complete = true; |
| 2218 | } | 2210 | } |
| 2211 | |||
| 2219 | task_rq_unlock(rq, p, rf); | 2212 | task_rq_unlock(rq, p, rf); |
| 2220 | 2213 | ||
| 2221 | if (push_task) { | 2214 | if (push_task) { |
| @@ -2224,7 +2217,7 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag · 2 unmodified lines | |||
| 2224 | } | 2217 | } |
| 2225 | 2218 | ||
| 2226 | if (complete) | 2219 | if (complete) |
| 2227 | goto do_complete; | 2220 | complete_all(&pending->done); |
| 2228 | 2221 | ||
| 2229 | return 0; | 2222 | return 0; |
| 2230 | } | 2223 | } |
| @@ -2235,6 +2228,12 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag · 4 unmodified lines | |||
| 2235 | /* Install the request */ | 2228 | /* Install the request */ |
| 2236 | refcount_set(&my_pending.refs, 1); | 2229 | refcount_set(&my_pending.refs, 1); |
| 2237 | init_completion(&my_pending.done); | 2230 | init_completion(&my_pending.done); |
| 2231 | my_pending.arg = (struct migration_arg) { | ||
| 2232 | .task = p, | ||
| 2233 | .dest_cpu = -1, /* any */ | ||
| 2234 | .pending = &my_pending, | ||
| 2235 | }; | ||
| 2236 | |||
| 2238 | p->migration_pending = &my_pending; | 2237 | p->migration_pending = &my_pending; |
| 2239 | } else { | 2238 | } else { |
| 2240 | pending = p->migration_pending; | 2239 | pending = p->migration_pending; |
| @@ -2259,45 +2258,41 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag · 18 unmodified lines | |||
| 2259 | return -EINVAL; | 2258 | return -EINVAL; |
| 2260 | } | 2259 | } |
| 2261 | 2260 | ||
| 2262 | if (flags & SCA_MIGRATE_ENABLE) { | ||
| 2263 | |||
| 2264 | refcount_inc(&pending->refs); /* pending->{arg,stop_work} */ | ||
| 2265 | p->migration_flags &= ~MDF_PUSH; | ||
| 2266 | task_rq_unlock(rq, p, rf); | ||
| 2267 | |||
| 2268 | pending->arg = (struct migration_arg) { | ||
| 2269 | .task = p, | ||
| 2270 | .dest_cpu = -1, | ||
| 2271 | .pending = pending, | ||
| 2272 | }; | ||
| 2273 | |||
| 2274 | stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop, | ||
| 2275 | &pending->arg, &pending->stop_work); | ||
| 2276 | |||
| 2277 | return 0; | ||
| 2278 | } | ||
| 2279 | |||
| 2280 | if (task_running(rq, p) || p->state == TASK_WAKING) { | 2261 | if (task_running(rq, p) || p->state == TASK_WAKING) { |
| 2281 | /* | 2262 | /* |
| 2282 | * Lessen races (and headaches) by delegating | 2263 | * MIGRATE_ENABLE gets here because 'p == current', but for |
| 2283 | * is_migration_disabled(p) checks to the stopper, which will | 2264 | * anything else we cannot do is_migration_disabled(), punt |
| 2284 | * run on the same CPU as said p. | 2265 | * and have the stopper function handle it all race-free. |
| 2285 | */ | 2266 | */ |
| 2267 | stop_pending = pending->stop_pending; | ||
| 2268 | if (!stop_pending) | ||
| 2269 | pending->stop_pending = true; | ||
| 2270 | |||
| 2271 | if (flags & SCA_MIGRATE_ENABLE) | ||
| 2272 | p->migration_flags &= ~MDF_PUSH; | ||
| 2273 | |||
| 2286 | task_rq_unlock(rq, p, rf); | 2274 | task_rq_unlock(rq, p, rf); |
| 2287 | stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); | ||
| 2288 | 2275 | ||
| 2276 | if (!stop_pending) { | ||
| 2277 | stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop, | ||
| 2278 | &pending->arg, &pending->stop_work); | ||
| 2279 | } | ||
| 2280 | |||
| 2281 | if (flags & SCA_MIGRATE_ENABLE) | ||
| 2282 | return 0; | ||
| 2289 | } else { | 2283 | } else { |
| 2290 | 2284 | ||
| 2291 | if (!is_migration_disabled(p)) { | 2285 | if (!is_migration_disabled(p)) { |
| 2292 | if (task_on_rq_queued(p)) | 2286 | if (task_on_rq_queued(p)) |
| 2293 | rq = move_queued_task(rq, rf, p, dest_cpu); | 2287 | rq = move_queued_task(rq, rf, p, dest_cpu); |
| 2294 | 2288 | ||
| 2295 | p->migration_pending = NULL; | 2289 | if (!pending->stop_pending) { |
| 2296 | complete = true; | 2290 | p->migration_pending = NULL; |
| 2291 | complete = true; | ||
| 2292 | } | ||
| 2297 | } | 2293 | } |
| 2298 | task_rq_unlock(rq, p, rf); | 2294 | task_rq_unlock(rq, p, rf); |
| 2299 | 2295 | ||
| 2300 | do_complete: | ||
| 2301 | if (complete) | 2296 | if (complete) |
| 2302 | complete_all(&pending->done); | 2297 | complete_all(&pending->done); |
| 2303 | } | 2298 | } |
| @@ -2305,7 +2300,7 @@ do_complete: · 1 unmodified line | |||
| 2305 | wait_for_completion(&pending->done); | 2300 | wait_for_completion(&pending->done); |
| 2306 | 2301 | ||
| 2307 | if (refcount_dec_and_test(&pending->refs)) | 2302 | if (refcount_dec_and_test(&pending->refs)) |
| 2308 | wake_up_var(&pending->refs); | 2303 | wake_up_var(&pending->refs); /* No UaF, just an address */ |
| 2309 | 2304 | ||
| 2310 | /* | 2305 | /* |
| 2311 | * Block the original owner of &pending until all subsequent callers | 2306 | * Block the original owner of &pending until all subsequent callers |
| @@ -2313,6 +2308,9 @@ do_complete: · 1 unmodified line | |||
| 2313 | */ | 2308 | */ |
| 2314 | wait_var_event(&my_pending.refs, !refcount_read(&my_pending.refs)); | 2309 | wait_var_event(&my_pending.refs, !refcount_read(&my_pending.refs)); |
| 2315 | 2310 | ||
| 2311 | /* ARGH */ | ||
| 2312 | WARN_ON_ONCE(my_pending.stop_pending); | ||
| 2313 | |||
| 2316 | return 0; | 2314 | return 0; |
| 2317 | } | 2315 | } |
| 2318 | 2316 | ||
| @@ -471,9 +471,7 @@ static int sync_runqueues_membarrier_state(struct mm_struct *mm) · 470 unmodified lines | |||
| 471 | } | 471 | } |
| 472 | rcu_read_unlock(); | 472 | rcu_read_unlock(); |
| 473 | 473 | ||
| 474 | preempt_disable(); | 474 | on_each_cpu_mask(tmpmask, ipi_sync_rq_state, mm, true); |
| 475 | smp_call_function_many(tmpmask, ipi_sync_rq_state, mm, 1); | ||
| 476 | preempt_enable(); | ||
| 477 | 475 | ||
| 478 | free_cpumask_var(tmpmask); | 476 | free_cpumask_var(tmpmask); |
| 479 | cpus_read_unlock(); | 477 | cpus_read_unlock(); |
| @@ -2079,7 +2079,7 @@ static int prctl_set_auxv(struct mm_struct *mm, unsigned long addr, · 2078 unmodified lines | |||
| 2079 | * up to the caller to provide sane values here, otherwise userspace | 2079 | * up to the caller to provide sane values here, otherwise userspace |
| 2080 | * tools which use this vector might be unhappy. | 2080 | * tools which use this vector might be unhappy. |
| 2081 | */ | 2081 | */ |
| 2082 | unsigned long user_auxv[AT_VECTOR_SIZE]; | 2082 | unsigned long user_auxv[AT_VECTOR_SIZE] = {}; |
| 2083 | 2083 | ||
| 2084 | if (len > sizeof(user_auxv)) | 2084 | if (len > sizeof(user_auxv)) |
| 2085 | return -EINVAL; | 2085 | return -EINVAL; |
| @@ -546,8 +546,11 @@ static ktime_t __hrtimer_next_event_base(struct hrtimer_cpu_base *cpu_base, · 545 unmodified lines | |||
| 546 | } | 546 | } |
| 547 | 547 | ||
| 548 | /* | 548 | /* |
| 549 | * Recomputes cpu_base::*next_timer and returns the earliest expires_next but | 549 | * Recomputes cpu_base::*next_timer and returns the earliest expires_next |
| 550 | * does not set cpu_base::*expires_next, that is done by hrtimer_reprogram. | 550 | * but does not set cpu_base::*expires_next, that is done by |
| 551 | * hrtimer[_force]_reprogram and hrtimer_interrupt only. When updating | ||
| 552 | * cpu_base::*expires_next right away, reprogramming logic would no longer | ||
| 553 | * work. | ||
| 551 | * | 554 | * |
| 552 | * When a softirq is pending, we can ignore the HRTIMER_ACTIVE_SOFT bases, | 555 | * When a softirq is pending, we can ignore the HRTIMER_ACTIVE_SOFT bases, |
| 553 | * those timers will get run whenever the softirq gets handled, at the end of | 556 | * those timers will get run whenever the softirq gets handled, at the end of |
| @@ -588,6 +591,37 @@ __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base, unsigned int active_ · 34 unmodified lines | |||
| 588 | return expires_next; | 591 | return expires_next; |
| 589 | } | 592 | } |
| 590 | 593 | ||
| 594 | static ktime_t hrtimer_update_next_event(struct hrtimer_cpu_base *cpu_base) | ||
| 595 | { | ||
| 596 | ktime_t expires_next, soft = KTIME_MAX; | ||
| 597 | |||
| 598 | /* | ||
| 599 | * If the soft interrupt has already been activated, ignore the | ||
| 600 | * soft bases. They will be handled in the already raised soft | ||
| 601 | * interrupt. | ||
| 602 | */ | ||
| 603 | if (!cpu_base->softirq_activated) { | ||
| 604 | soft = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_SOFT); | ||
| 605 | /* | ||
| 606 | * Update the soft expiry time. clock_settime() might have | ||
| 607 | * affected it. | ||
| 608 | */ | ||
| 609 | cpu_base->softirq_expires_next = soft; | ||
| 610 | } | ||
| 611 | |||
| 612 | expires_next = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_HARD); | ||
| 613 | /* | ||
| 614 | * If a softirq timer is expiring first, update cpu_base->next_timer | ||
| 615 | * and program the hardware with the soft expiry time. | ||
| 616 | */ | ||
| 617 | if (expires_next > soft) { | ||
| 618 | cpu_base->next_timer = cpu_base->softirq_next_timer; | ||
| 619 | expires_next = soft; | ||
| 620 | } | ||
| 621 | |||
| 622 | return expires_next; | ||
| 623 | } | ||
| 624 | |||
| 591 | static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base) | 625 | static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base) |
| 592 | { | 626 | { |
| 593 | ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset; | 627 | ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset; |
| @@ -628,23 +662,7 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) · 34 unmodified lines | |||
| 628 | { | 662 | { |
| 629 | ktime_t expires_next; | 663 | ktime_t expires_next; |
| 630 | 664 | ||
| 631 | /* | 665 | expires_next = hrtimer_update_next_event(cpu_base); |
| 632 | * Find the current next expiration time. | ||
| 633 | */ | ||
| 634 | expires_next = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_ALL); | ||
| 635 | |||
| 636 | if (cpu_base->next_timer && cpu_base->next_timer->is_soft) { | ||
| 637 | /* | ||
| 638 | * When the softirq is activated, hrtimer has to be | ||
| 639 | * programmed with the first hard hrtimer because soft | ||
| 640 | * timer interrupt could occur too late. | ||
| 641 | */ | ||
| 642 | if (cpu_base->softirq_activated) | ||
| 643 | expires_next = __hrtimer_get_next_event(cpu_base, | ||
| 644 | HRTIMER_ACTIVE_HARD); | ||
| 645 | else | ||
| 646 | cpu_base->softirq_expires_next = expires_next; | ||
| 647 | } | ||
| 648 | 666 | ||
| 649 | if (skip_equal && expires_next == cpu_base->expires_next) | 667 | if (skip_equal && expires_next == cpu_base->expires_next) |
| 650 | return; | 668 | return; |
| @@ -1644,8 +1662,8 @@ retry: · 993 unmodified lines | |||
| 1644 | 1662 | ||
| 1645 | __hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD); | 1663 | __hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD); |
| 1646 | 1664 | ||
| 1647 | /* Reevaluate the clock bases for the next expiry */ | 1665 | /* Reevaluate the clock bases for the [soft] next expiry */ |
| 1648 | expires_next = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_ALL); | 1666 | expires_next = hrtimer_update_next_event(cpu_base); |
| 1649 | /* | 1667 | /* |
| 1650 | * Store the new expiry value so the migration code can verify | 1668 | * Store the new expiry value so the migration code can verify |
| 1651 | * against it. | 1669 | * against it. |