Merge tag 'v5.12-rc5' into locking/core, to pick up fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
@@ -109,7 +109,7 @@ static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)
|
||||
fd = *(int *)key;
|
||||
f = fget_raw(fd);
|
||||
if (!f)
|
||||
return NULL;
|
||||
return ERR_PTR(-EBADF);
|
||||
|
||||
sdata = inode_storage_lookup(f->f_inode, map, true);
|
||||
fput(f);
|
||||
|
||||
@@ -430,7 +430,7 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
|
||||
|
||||
tprogs[BPF_TRAMP_FENTRY].progs[0] = prog;
|
||||
tprogs[BPF_TRAMP_FENTRY].nr_progs = 1;
|
||||
err = arch_prepare_bpf_trampoline(image,
|
||||
err = arch_prepare_bpf_trampoline(NULL, image,
|
||||
st_map->image + PAGE_SIZE,
|
||||
&st_ops->func_models[i], 0,
|
||||
tprogs, NULL);
|
||||
|
||||
+2
-2
@@ -827,7 +827,7 @@ static int __init bpf_jit_charge_init(void)
|
||||
}
|
||||
pure_initcall(bpf_jit_charge_init);
|
||||
|
||||
static int bpf_jit_charge_modmem(u32 pages)
|
||||
int bpf_jit_charge_modmem(u32 pages)
|
||||
{
|
||||
if (atomic_long_add_return(pages, &bpf_jit_current) >
|
||||
(bpf_jit_limit >> PAGE_SHIFT)) {
|
||||
@@ -840,7 +840,7 @@ static int bpf_jit_charge_modmem(u32 pages)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void bpf_jit_uncharge_modmem(u32 pages)
|
||||
void bpf_jit_uncharge_modmem(u32 pages)
|
||||
{
|
||||
atomic_long_sub(pages, &bpf_jit_current);
|
||||
}
|
||||
|
||||
@@ -60,9 +60,12 @@ static int finish(void)
|
||||
&magic, sizeof(magic), &pos);
|
||||
if (n != sizeof(magic))
|
||||
return -EPIPE;
|
||||
|
||||
tgid = umd_ops.info.tgid;
|
||||
wait_event(tgid->wait_pidfd, thread_group_exited(tgid));
|
||||
umd_ops.info.tgid = NULL;
|
||||
if (tgid) {
|
||||
wait_event(tgid->wait_pidfd, thread_group_exited(tgid));
|
||||
umd_cleanup_helper(&umd_ops.info);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -80,10 +83,18 @@ static int __init load_umd(void)
|
||||
|
||||
static void __exit fini_umd(void)
|
||||
{
|
||||
struct pid *tgid;
|
||||
|
||||
bpf_preload_ops = NULL;
|
||||
|
||||
/* kill UMD in case it's still there due to earlier error */
|
||||
kill_pid(umd_ops.info.tgid, SIGKILL, 1);
|
||||
umd_ops.info.tgid = NULL;
|
||||
tgid = umd_ops.info.tgid;
|
||||
if (tgid) {
|
||||
kill_pid(tgid, SIGKILL, 1);
|
||||
|
||||
wait_event(tgid->wait_pidfd, thread_group_exited(tgid));
|
||||
umd_cleanup_helper(&umd_ops.info);
|
||||
}
|
||||
umd_unload_blob(&umd_ops.info);
|
||||
}
|
||||
late_initcall(load_umd);
|
||||
|
||||
@@ -854,6 +854,11 @@ static int map_create(union bpf_attr *attr)
|
||||
err = PTR_ERR(btf);
|
||||
goto free_map;
|
||||
}
|
||||
if (btf_is_kernel(btf)) {
|
||||
btf_put(btf);
|
||||
err = -EACCES;
|
||||
goto free_map;
|
||||
}
|
||||
map->btf = btf;
|
||||
|
||||
if (attr->btf_value_type_id) {
|
||||
|
||||
+168
-50
@@ -57,19 +57,10 @@ void bpf_image_ksym_del(struct bpf_ksym *ksym)
|
||||
PAGE_SIZE, true, ksym->name);
|
||||
}
|
||||
|
||||
static void bpf_trampoline_ksym_add(struct bpf_trampoline *tr)
|
||||
{
|
||||
struct bpf_ksym *ksym = &tr->ksym;
|
||||
|
||||
snprintf(ksym->name, KSYM_NAME_LEN, "bpf_trampoline_%llu", tr->key);
|
||||
bpf_image_ksym_add(tr->image, ksym);
|
||||
}
|
||||
|
||||
static struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
|
||||
{
|
||||
struct bpf_trampoline *tr;
|
||||
struct hlist_head *head;
|
||||
void *image;
|
||||
int i;
|
||||
|
||||
mutex_lock(&trampoline_mutex);
|
||||
@@ -84,14 +75,6 @@ static struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
|
||||
if (!tr)
|
||||
goto out;
|
||||
|
||||
/* is_root was checked earlier. No need for bpf_jit_charge_modmem() */
|
||||
image = bpf_jit_alloc_exec_page();
|
||||
if (!image) {
|
||||
kfree(tr);
|
||||
tr = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
tr->key = key;
|
||||
INIT_HLIST_NODE(&tr->hlist);
|
||||
hlist_add_head(&tr->hlist, head);
|
||||
@@ -99,9 +82,6 @@ static struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
|
||||
mutex_init(&tr->mutex);
|
||||
for (i = 0; i < BPF_TRAMP_MAX; i++)
|
||||
INIT_HLIST_HEAD(&tr->progs_hlist[i]);
|
||||
tr->image = image;
|
||||
INIT_LIST_HEAD_RCU(&tr->ksym.lnode);
|
||||
bpf_trampoline_ksym_add(tr);
|
||||
out:
|
||||
mutex_unlock(&trampoline_mutex);
|
||||
return tr;
|
||||
@@ -185,10 +165,142 @@ bpf_trampoline_get_progs(const struct bpf_trampoline *tr, int *total)
|
||||
return tprogs;
|
||||
}
|
||||
|
||||
static void __bpf_tramp_image_put_deferred(struct work_struct *work)
|
||||
{
|
||||
struct bpf_tramp_image *im;
|
||||
|
||||
im = container_of(work, struct bpf_tramp_image, work);
|
||||
bpf_image_ksym_del(&im->ksym);
|
||||
bpf_jit_free_exec(im->image);
|
||||
bpf_jit_uncharge_modmem(1);
|
||||
percpu_ref_exit(&im->pcref);
|
||||
kfree_rcu(im, rcu);
|
||||
}
|
||||
|
||||
/* callback, fexit step 3 or fentry step 2 */
|
||||
static void __bpf_tramp_image_put_rcu(struct rcu_head *rcu)
|
||||
{
|
||||
struct bpf_tramp_image *im;
|
||||
|
||||
im = container_of(rcu, struct bpf_tramp_image, rcu);
|
||||
INIT_WORK(&im->work, __bpf_tramp_image_put_deferred);
|
||||
schedule_work(&im->work);
|
||||
}
|
||||
|
||||
/* callback, fexit step 2. Called after percpu_ref_kill confirms. */
|
||||
static void __bpf_tramp_image_release(struct percpu_ref *pcref)
|
||||
{
|
||||
struct bpf_tramp_image *im;
|
||||
|
||||
im = container_of(pcref, struct bpf_tramp_image, pcref);
|
||||
call_rcu_tasks(&im->rcu, __bpf_tramp_image_put_rcu);
|
||||
}
|
||||
|
||||
/* callback, fexit or fentry step 1 */
|
||||
static void __bpf_tramp_image_put_rcu_tasks(struct rcu_head *rcu)
|
||||
{
|
||||
struct bpf_tramp_image *im;
|
||||
|
||||
im = container_of(rcu, struct bpf_tramp_image, rcu);
|
||||
if (im->ip_after_call)
|
||||
/* the case of fmod_ret/fexit trampoline and CONFIG_PREEMPTION=y */
|
||||
percpu_ref_kill(&im->pcref);
|
||||
else
|
||||
/* the case of fentry trampoline */
|
||||
call_rcu_tasks(&im->rcu, __bpf_tramp_image_put_rcu);
|
||||
}
|
||||
|
||||
static void bpf_tramp_image_put(struct bpf_tramp_image *im)
|
||||
{
|
||||
/* The trampoline image that calls original function is using:
|
||||
* rcu_read_lock_trace to protect sleepable bpf progs
|
||||
* rcu_read_lock to protect normal bpf progs
|
||||
* percpu_ref to protect trampoline itself
|
||||
* rcu tasks to protect trampoline asm not covered by percpu_ref
|
||||
* (which are few asm insns before __bpf_tramp_enter and
|
||||
* after __bpf_tramp_exit)
|
||||
*
|
||||
* The trampoline is unreachable before bpf_tramp_image_put().
|
||||
*
|
||||
* First, patch the trampoline to avoid calling into fexit progs.
|
||||
* The progs will be freed even if the original function is still
|
||||
* executing or sleeping.
|
||||
* In case of CONFIG_PREEMPT=y use call_rcu_tasks() to wait on
|
||||
* first few asm instructions to execute and call into
|
||||
* __bpf_tramp_enter->percpu_ref_get.
|
||||
* Then use percpu_ref_kill to wait for the trampoline and the original
|
||||
* function to finish.
|
||||
* Then use call_rcu_tasks() to make sure few asm insns in
|
||||
* the trampoline epilogue are done as well.
|
||||
*
|
||||
* In !PREEMPT case the task that got interrupted in the first asm
|
||||
* insns won't go through an RCU quiescent state which the
|
||||
* percpu_ref_kill will be waiting for. Hence the first
|
||||
* call_rcu_tasks() is not necessary.
|
||||
*/
|
||||
if (im->ip_after_call) {
|
||||
int err = bpf_arch_text_poke(im->ip_after_call, BPF_MOD_JUMP,
|
||||
NULL, im->ip_epilogue);
|
||||
WARN_ON(err);
|
||||
if (IS_ENABLED(CONFIG_PREEMPTION))
|
||||
call_rcu_tasks(&im->rcu, __bpf_tramp_image_put_rcu_tasks);
|
||||
else
|
||||
percpu_ref_kill(&im->pcref);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The trampoline without fexit and fmod_ret progs doesn't call original
|
||||
* function and doesn't use percpu_ref.
|
||||
* Use call_rcu_tasks_trace() to wait for sleepable progs to finish.
|
||||
* Then use call_rcu_tasks() to wait for the rest of trampoline asm
|
||||
* and normal progs.
|
||||
*/
|
||||
call_rcu_tasks_trace(&im->rcu, __bpf_tramp_image_put_rcu_tasks);
|
||||
}
|
||||
|
||||
static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key, u32 idx)
|
||||
{
|
||||
struct bpf_tramp_image *im;
|
||||
struct bpf_ksym *ksym;
|
||||
void *image;
|
||||
int err = -ENOMEM;
|
||||
|
||||
im = kzalloc(sizeof(*im), GFP_KERNEL);
|
||||
if (!im)
|
||||
goto out;
|
||||
|
||||
err = bpf_jit_charge_modmem(1);
|
||||
if (err)
|
||||
goto out_free_im;
|
||||
|
||||
err = -ENOMEM;
|
||||
im->image = image = bpf_jit_alloc_exec_page();
|
||||
if (!image)
|
||||
goto out_uncharge;
|
||||
|
||||
err = percpu_ref_init(&im->pcref, __bpf_tramp_image_release, 0, GFP_KERNEL);
|
||||
if (err)
|
||||
goto out_free_image;
|
||||
|
||||
ksym = &im->ksym;
|
||||
INIT_LIST_HEAD_RCU(&ksym->lnode);
|
||||
snprintf(ksym->name, KSYM_NAME_LEN, "bpf_trampoline_%llu_%u", key, idx);
|
||||
bpf_image_ksym_add(image, ksym);
|
||||
return im;
|
||||
|
||||
out_free_image:
|
||||
bpf_jit_free_exec(im->image);
|
||||
out_uncharge:
|
||||
bpf_jit_uncharge_modmem(1);
|
||||
out_free_im:
|
||||
kfree(im);
|
||||
out:
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
static int bpf_trampoline_update(struct bpf_trampoline *tr)
|
||||
{
|
||||
void *old_image = tr->image + ((tr->selector + 1) & 1) * PAGE_SIZE/2;
|
||||
void *new_image = tr->image + (tr->selector & 1) * PAGE_SIZE/2;
|
||||
struct bpf_tramp_image *im;
|
||||
struct bpf_tramp_progs *tprogs;
|
||||
u32 flags = BPF_TRAMP_F_RESTORE_REGS;
|
||||
int err, total;
|
||||
@@ -198,41 +310,42 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr)
|
||||
return PTR_ERR(tprogs);
|
||||
|
||||
if (total == 0) {
|
||||
err = unregister_fentry(tr, old_image);
|
||||
err = unregister_fentry(tr, tr->cur_image->image);
|
||||
bpf_tramp_image_put(tr->cur_image);
|
||||
tr->cur_image = NULL;
|
||||
tr->selector = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
im = bpf_tramp_image_alloc(tr->key, tr->selector);
|
||||
if (IS_ERR(im)) {
|
||||
err = PTR_ERR(im);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (tprogs[BPF_TRAMP_FEXIT].nr_progs ||
|
||||
tprogs[BPF_TRAMP_MODIFY_RETURN].nr_progs)
|
||||
flags = BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_SKIP_FRAME;
|
||||
|
||||
/* Though the second half of trampoline page is unused a task could be
|
||||
* preempted in the middle of the first half of trampoline and two
|
||||
* updates to trampoline would change the code from underneath the
|
||||
* preempted task. Hence wait for tasks to voluntarily schedule or go
|
||||
* to userspace.
|
||||
* The same trampoline can hold both sleepable and non-sleepable progs.
|
||||
* synchronize_rcu_tasks_trace() is needed to make sure all sleepable
|
||||
* programs finish executing.
|
||||
* Wait for these two grace periods together.
|
||||
*/
|
||||
synchronize_rcu_mult(call_rcu_tasks, call_rcu_tasks_trace);
|
||||
|
||||
err = arch_prepare_bpf_trampoline(new_image, new_image + PAGE_SIZE / 2,
|
||||
err = arch_prepare_bpf_trampoline(im, im->image, im->image + PAGE_SIZE,
|
||||
&tr->func.model, flags, tprogs,
|
||||
tr->func.addr);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
|
||||
if (tr->selector)
|
||||
WARN_ON(tr->cur_image && tr->selector == 0);
|
||||
WARN_ON(!tr->cur_image && tr->selector);
|
||||
if (tr->cur_image)
|
||||
/* progs already running at this address */
|
||||
err = modify_fentry(tr, old_image, new_image);
|
||||
err = modify_fentry(tr, tr->cur_image->image, im->image);
|
||||
else
|
||||
/* first time registering */
|
||||
err = register_fentry(tr, new_image);
|
||||
err = register_fentry(tr, im->image);
|
||||
if (err)
|
||||
goto out;
|
||||
if (tr->cur_image)
|
||||
bpf_tramp_image_put(tr->cur_image);
|
||||
tr->cur_image = im;
|
||||
tr->selector++;
|
||||
out:
|
||||
kfree(tprogs);
|
||||
@@ -364,17 +477,12 @@ void bpf_trampoline_put(struct bpf_trampoline *tr)
|
||||
goto out;
|
||||
if (WARN_ON_ONCE(!hlist_empty(&tr->progs_hlist[BPF_TRAMP_FEXIT])))
|
||||
goto out;
|
||||
bpf_image_ksym_del(&tr->ksym);
|
||||
/* This code will be executed when all bpf progs (both sleepable and
|
||||
* non-sleepable) went through
|
||||
* bpf_prog_put()->call_rcu[_tasks_trace]()->bpf_prog_free_deferred().
|
||||
* Hence no need for another synchronize_rcu_tasks_trace() here,
|
||||
* but synchronize_rcu_tasks() is still needed, since trampoline
|
||||
* may not have had any sleepable programs and we need to wait
|
||||
* for tasks to get out of trampoline code before freeing it.
|
||||
/* This code will be executed even when the last bpf_tramp_image
|
||||
* is alive. All progs are detached from the trampoline and the
|
||||
* trampoline image is patched with jmp into epilogue to skip
|
||||
* fexit progs. The fentry-only trampoline will be freed via
|
||||
* multiple rcu callbacks.
|
||||
*/
|
||||
synchronize_rcu_tasks();
|
||||
bpf_jit_free_exec(tr->image);
|
||||
hlist_del(&tr->hlist);
|
||||
kfree(tr);
|
||||
out:
|
||||
@@ -478,8 +586,18 @@ void notrace __bpf_prog_exit_sleepable(struct bpf_prog *prog, u64 start)
|
||||
rcu_read_unlock_trace();
|
||||
}
|
||||
|
||||
void notrace __bpf_tramp_enter(struct bpf_tramp_image *tr)
|
||||
{
|
||||
percpu_ref_get(&tr->pcref);
|
||||
}
|
||||
|
||||
void notrace __bpf_tramp_exit(struct bpf_tramp_image *tr)
|
||||
{
|
||||
percpu_ref_put(&tr->pcref);
|
||||
}
|
||||
|
||||
int __weak
|
||||
arch_prepare_bpf_trampoline(void *image, void *image_end,
|
||||
arch_prepare_bpf_trampoline(struct bpf_tramp_image *tr, void *image, void *image_end,
|
||||
const struct btf_func_model *m, u32 flags,
|
||||
struct bpf_tramp_progs *tprogs,
|
||||
void *orig_call)
|
||||
|
||||
+25
-12
@@ -5861,10 +5861,14 @@ static int retrieve_ptr_limit(const struct bpf_reg_state *ptr_reg,
|
||||
{
|
||||
bool mask_to_left = (opcode == BPF_ADD && off_is_neg) ||
|
||||
(opcode == BPF_SUB && !off_is_neg);
|
||||
u32 off;
|
||||
u32 off, max;
|
||||
|
||||
switch (ptr_reg->type) {
|
||||
case PTR_TO_STACK:
|
||||
/* Offset 0 is out-of-bounds, but acceptable start for the
|
||||
* left direction, see BPF_REG_FP.
|
||||
*/
|
||||
max = MAX_BPF_STACK + mask_to_left;
|
||||
/* Indirect variable offset stack access is prohibited in
|
||||
* unprivileged mode so it's not handled here.
|
||||
*/
|
||||
@@ -5872,16 +5876,17 @@ static int retrieve_ptr_limit(const struct bpf_reg_state *ptr_reg,
|
||||
if (mask_to_left)
|
||||
*ptr_limit = MAX_BPF_STACK + off;
|
||||
else
|
||||
*ptr_limit = -off;
|
||||
return 0;
|
||||
*ptr_limit = -off - 1;
|
||||
return *ptr_limit >= max ? -ERANGE : 0;
|
||||
case PTR_TO_MAP_VALUE:
|
||||
max = ptr_reg->map_ptr->value_size;
|
||||
if (mask_to_left) {
|
||||
*ptr_limit = ptr_reg->umax_value + ptr_reg->off;
|
||||
} else {
|
||||
off = ptr_reg->smin_value + ptr_reg->off;
|
||||
*ptr_limit = ptr_reg->map_ptr->value_size - off;
|
||||
*ptr_limit = ptr_reg->map_ptr->value_size - off - 1;
|
||||
}
|
||||
return 0;
|
||||
return *ptr_limit >= max ? -ERANGE : 0;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -5934,6 +5939,7 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
|
||||
u32 alu_state, alu_limit;
|
||||
struct bpf_reg_state tmp;
|
||||
bool ret;
|
||||
int err;
|
||||
|
||||
if (can_skip_alu_sanitation(env, insn))
|
||||
return 0;
|
||||
@@ -5949,10 +5955,13 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
|
||||
alu_state |= ptr_is_dst_reg ?
|
||||
BPF_ALU_SANITIZE_SRC : BPF_ALU_SANITIZE_DST;
|
||||
|
||||
if (retrieve_ptr_limit(ptr_reg, &alu_limit, opcode, off_is_neg))
|
||||
return 0;
|
||||
if (update_alu_sanitation_state(aux, alu_state, alu_limit))
|
||||
return -EACCES;
|
||||
err = retrieve_ptr_limit(ptr_reg, &alu_limit, opcode, off_is_neg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
err = update_alu_sanitation_state(aux, alu_state, alu_limit);
|
||||
if (err < 0)
|
||||
return err;
|
||||
do_sim:
|
||||
/* Simulate and find potential out-of-bounds access under
|
||||
* speculative execution from truncation as a result of
|
||||
@@ -6103,7 +6112,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
|
||||
case BPF_ADD:
|
||||
ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
|
||||
if (ret < 0) {
|
||||
verbose(env, "R%d tried to add from different maps or paths\n", dst);
|
||||
verbose(env, "R%d tried to add from different maps, paths, or prohibited types\n", dst);
|
||||
return ret;
|
||||
}
|
||||
/* We can take a fixed offset as long as it doesn't overflow
|
||||
@@ -6158,7 +6167,7 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
|
||||
case BPF_SUB:
|
||||
ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
|
||||
if (ret < 0) {
|
||||
verbose(env, "R%d tried to sub from different maps or paths\n", dst);
|
||||
verbose(env, "R%d tried to sub from different maps, paths, or prohibited types\n", dst);
|
||||
return ret;
|
||||
}
|
||||
if (dst_reg == off_reg) {
|
||||
@@ -9056,6 +9065,10 @@ static int check_btf_info(struct bpf_verifier_env *env,
|
||||
btf = btf_get_by_fd(attr->prog_btf_fd);
|
||||
if (IS_ERR(btf))
|
||||
return PTR_ERR(btf);
|
||||
if (btf_is_kernel(btf)) {
|
||||
btf_put(btf);
|
||||
return -EACCES;
|
||||
}
|
||||
env->prog->aux->btf = btf;
|
||||
|
||||
err = check_btf_func(env, attr, uattr);
|
||||
@@ -11660,7 +11673,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
|
||||
off_reg = issrc ? insn->src_reg : insn->dst_reg;
|
||||
if (isneg)
|
||||
*patch++ = BPF_ALU64_IMM(BPF_MUL, off_reg, -1);
|
||||
*patch++ = BPF_MOV32_IMM(BPF_REG_AX, aux->alu_limit - 1);
|
||||
*patch++ = BPF_MOV32_IMM(BPF_REG_AX, aux->alu_limit);
|
||||
*patch++ = BPF_ALU64_REG(BPF_SUB, BPF_REG_AX, off_reg);
|
||||
*patch++ = BPF_ALU64_REG(BPF_OR, BPF_REG_AX, off_reg);
|
||||
*patch++ = BPF_ALU64_IMM(BPF_NEG, BPF_REG_AX, 0);
|
||||
|
||||
+8
-9
@@ -1948,8 +1948,14 @@ static __latent_entropy struct task_struct *copy_process(
|
||||
p = dup_task_struct(current, node);
|
||||
if (!p)
|
||||
goto fork_out;
|
||||
if (args->io_thread)
|
||||
if (args->io_thread) {
|
||||
/*
|
||||
* Mark us an IO worker, and block any signal that isn't
|
||||
* fatal or STOP
|
||||
*/
|
||||
p->flags |= PF_IO_WORKER;
|
||||
siginitsetinv(&p->blocked, sigmask(SIGKILL)|sigmask(SIGSTOP));
|
||||
}
|
||||
|
||||
/*
|
||||
* This _must_ happen before we call free_task(), i.e. before we jump
|
||||
@@ -2438,15 +2444,8 @@ struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node)
|
||||
.stack_size = (unsigned long)arg,
|
||||
.io_thread = 1,
|
||||
};
|
||||
struct task_struct *tsk;
|
||||
|
||||
tsk = copy_process(NULL, 0, node, &args);
|
||||
if (!IS_ERR(tsk)) {
|
||||
sigfillset(&tsk->blocked);
|
||||
sigdelsetmask(&tsk->blocked, sigmask(SIGKILL));
|
||||
tsk->flags |= PF_NOFREEZE;
|
||||
}
|
||||
return tsk;
|
||||
return copy_process(NULL, 0, node, &args);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+1
-2
@@ -2728,14 +2728,13 @@ retry:
|
||||
goto out;
|
||||
|
||||
restart = ¤t->restart_block;
|
||||
restart->fn = futex_wait_restart;
|
||||
restart->futex.uaddr = uaddr;
|
||||
restart->futex.val = val;
|
||||
restart->futex.time = *abs_time;
|
||||
restart->futex.bitset = bitset;
|
||||
restart->futex.flags = flags | FLAGS_HAS_TIMEOUT;
|
||||
|
||||
ret = -ERESTART_RESTARTBLOCK;
|
||||
ret = set_restart_fn(restart, futex_wait_restart);
|
||||
|
||||
out:
|
||||
if (to) {
|
||||
|
||||
@@ -75,7 +75,9 @@ struct gcov_fn_info {
|
||||
|
||||
u32 num_counters;
|
||||
u64 *counters;
|
||||
#if CONFIG_CLANG_VERSION < 110000
|
||||
const char *function_name;
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct gcov_info *current_info;
|
||||
@@ -105,6 +107,7 @@ void llvm_gcov_init(llvm_gcov_callback writeout, llvm_gcov_callback flush)
|
||||
}
|
||||
EXPORT_SYMBOL(llvm_gcov_init);
|
||||
|
||||
#if CONFIG_CLANG_VERSION < 110000
|
||||
void llvm_gcda_start_file(const char *orig_filename, const char version[4],
|
||||
u32 checksum)
|
||||
{
|
||||
@@ -113,7 +116,17 @@ void llvm_gcda_start_file(const char *orig_filename, const char version[4],
|
||||
current_info->checksum = checksum;
|
||||
}
|
||||
EXPORT_SYMBOL(llvm_gcda_start_file);
|
||||
#else
|
||||
void llvm_gcda_start_file(const char *orig_filename, u32 version, u32 checksum)
|
||||
{
|
||||
current_info->filename = orig_filename;
|
||||
current_info->version = version;
|
||||
current_info->checksum = checksum;
|
||||
}
|
||||
EXPORT_SYMBOL(llvm_gcda_start_file);
|
||||
#endif
|
||||
|
||||
#if CONFIG_CLANG_VERSION < 110000
|
||||
void llvm_gcda_emit_function(u32 ident, const char *function_name,
|
||||
u32 func_checksum, u8 use_extra_checksum, u32 cfg_checksum)
|
||||
{
|
||||
@@ -133,6 +146,24 @@ void llvm_gcda_emit_function(u32 ident, const char *function_name,
|
||||
list_add_tail(&info->head, ¤t_info->functions);
|
||||
}
|
||||
EXPORT_SYMBOL(llvm_gcda_emit_function);
|
||||
#else
|
||||
void llvm_gcda_emit_function(u32 ident, u32 func_checksum,
|
||||
u8 use_extra_checksum, u32 cfg_checksum)
|
||||
{
|
||||
struct gcov_fn_info *info = kzalloc(sizeof(*info), GFP_KERNEL);
|
||||
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
INIT_LIST_HEAD(&info->head);
|
||||
info->ident = ident;
|
||||
info->checksum = func_checksum;
|
||||
info->use_extra_checksum = use_extra_checksum;
|
||||
info->cfg_checksum = cfg_checksum;
|
||||
list_add_tail(&info->head, ¤t_info->functions);
|
||||
}
|
||||
EXPORT_SYMBOL(llvm_gcda_emit_function);
|
||||
#endif
|
||||
|
||||
void llvm_gcda_emit_arcs(u32 num_counters, u64 *counters)
|
||||
{
|
||||
@@ -295,6 +326,7 @@ void gcov_info_add(struct gcov_info *dst, struct gcov_info *src)
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_CLANG_VERSION < 110000
|
||||
static struct gcov_fn_info *gcov_fn_info_dup(struct gcov_fn_info *fn)
|
||||
{
|
||||
size_t cv_size; /* counter values size */
|
||||
@@ -322,6 +354,28 @@ err_name:
|
||||
kfree(fn_dup);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
static struct gcov_fn_info *gcov_fn_info_dup(struct gcov_fn_info *fn)
|
||||
{
|
||||
size_t cv_size; /* counter values size */
|
||||
struct gcov_fn_info *fn_dup = kmemdup(fn, sizeof(*fn),
|
||||
GFP_KERNEL);
|
||||
if (!fn_dup)
|
||||
return NULL;
|
||||
INIT_LIST_HEAD(&fn_dup->head);
|
||||
|
||||
cv_size = fn->num_counters * sizeof(fn->counters[0]);
|
||||
fn_dup->counters = vmalloc(cv_size);
|
||||
if (!fn_dup->counters) {
|
||||
kfree(fn_dup);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(fn_dup->counters, fn->counters, cv_size);
|
||||
|
||||
return fn_dup;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* gcov_info_dup - duplicate profiling data set
|
||||
@@ -362,6 +416,7 @@ err:
|
||||
* gcov_info_free - release memory for profiling data set duplicate
|
||||
* @info: profiling data set duplicate to free
|
||||
*/
|
||||
#if CONFIG_CLANG_VERSION < 110000
|
||||
void gcov_info_free(struct gcov_info *info)
|
||||
{
|
||||
struct gcov_fn_info *fn, *tmp;
|
||||
@@ -375,6 +430,20 @@ void gcov_info_free(struct gcov_info *info)
|
||||
kfree(info->filename);
|
||||
kfree(info);
|
||||
}
|
||||
#else
|
||||
void gcov_info_free(struct gcov_info *info)
|
||||
{
|
||||
struct gcov_fn_info *fn, *tmp;
|
||||
|
||||
list_for_each_entry_safe(fn, tmp, &info->functions, head) {
|
||||
vfree(fn->counters);
|
||||
list_del(&fn->head);
|
||||
kfree(fn);
|
||||
}
|
||||
kfree(info->filename);
|
||||
kfree(info);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ITER_STRIDE PAGE_SIZE
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ static const struct irq_domain_ops irq_sim_domain_ops = {
|
||||
* irq_domain_create_sim - Create a new interrupt simulator irq_domain and
|
||||
* allocate a range of dummy interrupts.
|
||||
*
|
||||
* @fnode: struct fwnode_handle to be associated with this domain.
|
||||
* @fwnode: struct fwnode_handle to be associated with this domain.
|
||||
* @num_irqs: Number of interrupts to allocate.
|
||||
*
|
||||
* On success: return a new irq_domain object.
|
||||
@@ -228,7 +228,7 @@ static void devm_irq_domain_release_sim(struct device *dev, void *res)
|
||||
* a managed device.
|
||||
*
|
||||
* @dev: Device to initialize the simulator object for.
|
||||
* @fnode: struct fwnode_handle to be associated with this domain.
|
||||
* @fwnode: struct fwnode_handle to be associated with this domain.
|
||||
* @num_irqs: Number of interrupts to allocate
|
||||
*
|
||||
* On success: return a new irq_domain object.
|
||||
|
||||
@@ -1142,11 +1142,15 @@ irq_forced_thread_fn(struct irq_desc *desc, struct irqaction *action)
|
||||
irqreturn_t ret;
|
||||
|
||||
local_bh_disable();
|
||||
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
|
||||
local_irq_disable();
|
||||
ret = action->thread_fn(action->irq, action->dev_id);
|
||||
if (ret == IRQ_HANDLED)
|
||||
atomic_inc(&desc->threads_handled);
|
||||
|
||||
irq_finalize_oneshot(desc, action);
|
||||
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
|
||||
local_irq_enable();
|
||||
local_bh_enable();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -407,6 +407,14 @@ static bool jump_label_can_update(struct jump_entry *entry, bool init)
|
||||
return false;
|
||||
|
||||
if (!kernel_text_address(jump_entry_code(entry))) {
|
||||
/*
|
||||
* This skips patching built-in __exit, which
|
||||
* is part of init_section_contains() but is
|
||||
* not part of kernel_text_address().
|
||||
*
|
||||
* Skipping built-in __exit is fine since it
|
||||
* will never be executed.
|
||||
*/
|
||||
WARN_ONCE(!jump_entry_is_init(entry),
|
||||
"can't patch jump_label at %pS",
|
||||
(void *)jump_entry_code(entry));
|
||||
|
||||
@@ -98,7 +98,7 @@ static int __init em_debug_init(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
core_initcall(em_debug_init);
|
||||
fs_initcall(em_debug_init);
|
||||
#else /* CONFIG_DEBUG_FS */
|
||||
static void em_debug_create_pd(struct device *dev) {}
|
||||
static void em_debug_remove_pd(struct device *dev) {}
|
||||
|
||||
+1
-1
@@ -375,7 +375,7 @@ static int ptrace_attach(struct task_struct *task, long request,
|
||||
audit_ptrace(task);
|
||||
|
||||
retval = -EPERM;
|
||||
if (unlikely(task->flags & (PF_KTHREAD | PF_IO_WORKER)))
|
||||
if (unlikely(task->flags & PF_KTHREAD))
|
||||
goto out;
|
||||
if (same_thread_group(task, current))
|
||||
goto out;
|
||||
|
||||
@@ -244,8 +244,6 @@ void migrate_to_reboot_cpu(void)
|
||||
void kernel_restart(char *cmd)
|
||||
{
|
||||
kernel_restart_prepare(cmd);
|
||||
if (pm_power_off_prepare)
|
||||
pm_power_off_prepare();
|
||||
migrate_to_reboot_cpu();
|
||||
syscore_shutdown();
|
||||
if (!cmd)
|
||||
|
||||
+11
-3
@@ -91,7 +91,7 @@ static bool sig_task_ignored(struct task_struct *t, int sig, bool force)
|
||||
return true;
|
||||
|
||||
/* Only allow kernel generated signals to this kthread */
|
||||
if (unlikely((t->flags & (PF_KTHREAD | PF_IO_WORKER)) &&
|
||||
if (unlikely((t->flags & PF_KTHREAD) &&
|
||||
(handler == SIG_KTHREAD_KERNEL) && !force))
|
||||
return true;
|
||||
|
||||
@@ -1096,7 +1096,7 @@ static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struc
|
||||
/*
|
||||
* Skip useless siginfo allocation for SIGKILL and kernel threads.
|
||||
*/
|
||||
if ((sig == SIGKILL) || (t->flags & (PF_KTHREAD | PF_IO_WORKER)))
|
||||
if ((sig == SIGKILL) || (t->flags & PF_KTHREAD))
|
||||
goto out_set;
|
||||
|
||||
/*
|
||||
@@ -2767,6 +2767,14 @@ relock:
|
||||
do_coredump(&ksig->info);
|
||||
}
|
||||
|
||||
/*
|
||||
* PF_IO_WORKER threads will catch and exit on fatal signals
|
||||
* themselves. They have cleanup that must be performed, so
|
||||
* we cannot call do_exit() on their behalf.
|
||||
*/
|
||||
if (current->flags & PF_IO_WORKER)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Death signals, no core dump.
|
||||
*/
|
||||
@@ -2774,7 +2782,7 @@ relock:
|
||||
/* NOTREACHED */
|
||||
}
|
||||
spin_unlock_irq(&sighand->siglock);
|
||||
|
||||
out:
|
||||
ksig->sig = signr;
|
||||
|
||||
if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS))
|
||||
|
||||
+24
-18
@@ -35,27 +35,30 @@ static inline void *static_call_addr(struct static_call_site *site)
|
||||
return (void *)((long)site->addr + (long)&site->addr);
|
||||
}
|
||||
|
||||
static inline unsigned long __static_call_key(const struct static_call_site *site)
|
||||
{
|
||||
return (long)site->key + (long)&site->key;
|
||||
}
|
||||
|
||||
static inline struct static_call_key *static_call_key(const struct static_call_site *site)
|
||||
{
|
||||
return (struct static_call_key *)
|
||||
(((long)site->key + (long)&site->key) & ~STATIC_CALL_SITE_FLAGS);
|
||||
return (void *)(__static_call_key(site) & ~STATIC_CALL_SITE_FLAGS);
|
||||
}
|
||||
|
||||
/* These assume the key is word-aligned. */
|
||||
static inline bool static_call_is_init(struct static_call_site *site)
|
||||
{
|
||||
return ((long)site->key + (long)&site->key) & STATIC_CALL_SITE_INIT;
|
||||
return __static_call_key(site) & STATIC_CALL_SITE_INIT;
|
||||
}
|
||||
|
||||
static inline bool static_call_is_tail(struct static_call_site *site)
|
||||
{
|
||||
return ((long)site->key + (long)&site->key) & STATIC_CALL_SITE_TAIL;
|
||||
return __static_call_key(site) & STATIC_CALL_SITE_TAIL;
|
||||
}
|
||||
|
||||
static inline void static_call_set_init(struct static_call_site *site)
|
||||
{
|
||||
site->key = ((long)static_call_key(site) | STATIC_CALL_SITE_INIT) -
|
||||
site->key = (__static_call_key(site) | STATIC_CALL_SITE_INIT) -
|
||||
(long)&site->key;
|
||||
}
|
||||
|
||||
@@ -146,6 +149,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
|
||||
};
|
||||
|
||||
for (site_mod = &first; site_mod; site_mod = site_mod->next) {
|
||||
bool init = system_state < SYSTEM_RUNNING;
|
||||
struct module *mod = site_mod->mod;
|
||||
|
||||
if (!site_mod->sites) {
|
||||
@@ -165,6 +169,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
|
||||
if (mod) {
|
||||
stop = mod->static_call_sites +
|
||||
mod->num_static_call_sites;
|
||||
init = mod->state == MODULE_STATE_COMING;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -172,25 +177,26 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
|
||||
site < stop && static_call_key(site) == key; site++) {
|
||||
void *site_addr = static_call_addr(site);
|
||||
|
||||
if (static_call_is_init(site)) {
|
||||
/*
|
||||
* Don't write to call sites which were in
|
||||
* initmem and have since been freed.
|
||||
*/
|
||||
if (!mod && system_state >= SYSTEM_RUNNING)
|
||||
continue;
|
||||
if (mod && !within_module_init((unsigned long)site_addr, mod))
|
||||
continue;
|
||||
}
|
||||
if (!init && static_call_is_init(site))
|
||||
continue;
|
||||
|
||||
if (!kernel_text_address((unsigned long)site_addr)) {
|
||||
WARN_ONCE(1, "can't patch static call site at %pS",
|
||||
/*
|
||||
* This skips patching built-in __exit, which
|
||||
* is part of init_section_contains() but is
|
||||
* not part of kernel_text_address().
|
||||
*
|
||||
* Skipping built-in __exit is fine since it
|
||||
* will never be executed.
|
||||
*/
|
||||
WARN_ONCE(!static_call_is_init(site),
|
||||
"can't patch static call site at %pS",
|
||||
site_addr);
|
||||
continue;
|
||||
}
|
||||
|
||||
arch_static_call_transform(site_addr, NULL, func,
|
||||
static_call_is_tail(site));
|
||||
static_call_is_tail(site));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +355,7 @@ static int static_call_add_module(struct module *mod)
|
||||
struct static_call_site *site;
|
||||
|
||||
for (site = start; site != stop; site++) {
|
||||
unsigned long s_key = (long)site->key + (long)&site->key;
|
||||
unsigned long s_key = __static_call_key(site);
|
||||
unsigned long addr = s_key & ~STATIC_CALL_SITE_FLAGS;
|
||||
unsigned long key;
|
||||
|
||||
|
||||
@@ -854,9 +854,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
|
||||
if (flags == TIMER_ABSTIME)
|
||||
return -ERESTARTNOHAND;
|
||||
|
||||
restart->fn = alarm_timer_nsleep_restart;
|
||||
restart->nanosleep.clockid = type;
|
||||
restart->nanosleep.expires = exp;
|
||||
set_restart_fn(restart, alarm_timer_nsleep_restart);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1957,9 +1957,9 @@ long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode,
|
||||
}
|
||||
|
||||
restart = ¤t->restart_block;
|
||||
restart->fn = hrtimer_nanosleep_restart;
|
||||
restart->nanosleep.clockid = t.timer.base->clockid;
|
||||
restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);
|
||||
set_restart_fn(restart, hrtimer_nanosleep_restart);
|
||||
out:
|
||||
destroy_hrtimer_on_stack(&t.timer);
|
||||
return ret;
|
||||
|
||||
@@ -1480,8 +1480,8 @@ static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
|
||||
if (flags & TIMER_ABSTIME)
|
||||
return -ERESTARTNOHAND;
|
||||
|
||||
restart_block->fn = posix_cpu_nsleep_restart;
|
||||
restart_block->nanosleep.clockid = which_clock;
|
||||
set_restart_fn(restart_block, posix_cpu_nsleep_restart);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
+38
-5
@@ -5045,6 +5045,20 @@ struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct ftrace_direct_func *ftrace_alloc_direct_func(unsigned long addr)
|
||||
{
|
||||
struct ftrace_direct_func *direct;
|
||||
|
||||
direct = kmalloc(sizeof(*direct), GFP_KERNEL);
|
||||
if (!direct)
|
||||
return NULL;
|
||||
direct->addr = addr;
|
||||
direct->count = 0;
|
||||
list_add_rcu(&direct->next, &ftrace_direct_funcs);
|
||||
ftrace_direct_func_count++;
|
||||
return direct;
|
||||
}
|
||||
|
||||
/**
|
||||
* register_ftrace_direct - Call a custom trampoline directly
|
||||
* @ip: The address of the nop at the beginning of a function
|
||||
@@ -5120,15 +5134,11 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr)
|
||||
|
||||
direct = ftrace_find_direct_func(addr);
|
||||
if (!direct) {
|
||||
direct = kmalloc(sizeof(*direct), GFP_KERNEL);
|
||||
direct = ftrace_alloc_direct_func(addr);
|
||||
if (!direct) {
|
||||
kfree(entry);
|
||||
goto out_unlock;
|
||||
}
|
||||
direct->addr = addr;
|
||||
direct->count = 0;
|
||||
list_add_rcu(&direct->next, &ftrace_direct_funcs);
|
||||
ftrace_direct_func_count++;
|
||||
}
|
||||
|
||||
entry->ip = ip;
|
||||
@@ -5329,6 +5339,7 @@ int __weak ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
|
||||
int modify_ftrace_direct(unsigned long ip,
|
||||
unsigned long old_addr, unsigned long new_addr)
|
||||
{
|
||||
struct ftrace_direct_func *direct, *new_direct = NULL;
|
||||
struct ftrace_func_entry *entry;
|
||||
struct dyn_ftrace *rec;
|
||||
int ret = -ENODEV;
|
||||
@@ -5344,6 +5355,20 @@ int modify_ftrace_direct(unsigned long ip,
|
||||
if (entry->direct != old_addr)
|
||||
goto out_unlock;
|
||||
|
||||
direct = ftrace_find_direct_func(old_addr);
|
||||
if (WARN_ON(!direct))
|
||||
goto out_unlock;
|
||||
if (direct->count > 1) {
|
||||
ret = -ENOMEM;
|
||||
new_direct = ftrace_alloc_direct_func(new_addr);
|
||||
if (!new_direct)
|
||||
goto out_unlock;
|
||||
direct->count--;
|
||||
new_direct->count++;
|
||||
} else {
|
||||
direct->addr = new_addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there's no other ftrace callback on the rec->ip location,
|
||||
* then it can be changed directly by the architecture.
|
||||
@@ -5357,6 +5382,14 @@ int modify_ftrace_direct(unsigned long ip,
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
if (unlikely(ret && new_direct)) {
|
||||
direct->count++;
|
||||
list_del_rcu(&new_direct->next);
|
||||
synchronize_rcu_tasks();
|
||||
kfree(new_direct);
|
||||
ftrace_direct_func_count--;
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&ftrace_lock);
|
||||
mutex_unlock(&direct_mutex);
|
||||
|
||||
@@ -139,14 +139,23 @@ static void umd_cleanup(struct subprocess_info *info)
|
||||
struct umd_info *umd_info = info->data;
|
||||
|
||||
/* cleanup if umh_setup() was successful but exec failed */
|
||||
if (info->retval) {
|
||||
fput(umd_info->pipe_to_umh);
|
||||
fput(umd_info->pipe_from_umh);
|
||||
put_pid(umd_info->tgid);
|
||||
umd_info->tgid = NULL;
|
||||
}
|
||||
if (info->retval)
|
||||
umd_cleanup_helper(umd_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* umd_cleanup_helper - release the resources which were allocated in umd_setup
|
||||
* @info: information about usermode driver
|
||||
*/
|
||||
void umd_cleanup_helper(struct umd_info *info)
|
||||
{
|
||||
fput(info->pipe_to_umh);
|
||||
fput(info->pipe_from_umh);
|
||||
put_pid(info->tgid);
|
||||
info->tgid = NULL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(umd_cleanup_helper);
|
||||
|
||||
/**
|
||||
* fork_usermode_driver - fork a usermode driver
|
||||
* @info: information about usermode driver (shouldn't be NULL)
|
||||
|
||||
Reference in New Issue
Block a user