diff --git a/fs/exec.c b/fs/exec.c index 2ac3ef80628f0d956c7472278b9e1570c9cf0ebf..3dd371dfa89ccf6079eecaa55efbc1d607fb6bfe 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -75,6 +75,7 @@ #include "internal.h" #include +#include static int bprm_creds_from_file(struct linux_binprm *bprm); @@ -1846,6 +1847,12 @@ static int exec_binprm(struct linux_binprm *bprm) trace_sched_process_exec(current, old_pid, bprm); ptrace_event(PTRACE_EVENT_EXEC, old_vpid); proc_exec_connector(current); + +#ifdef CONFIG_BPF_SCHED + if (bpf_sched_enabled()) + bpf_sched_cfs_exec_init(current); +#endif + return 0; } diff --git a/include/linux/sched_hook_defs.h b/include/linux/sched_hook_defs.h index 57b7f61d515cd4ae573490d67692bcf8bd0289f7..ef3feef2fee32c3b8bb73e40d198bafd9f8838b7 100644 --- a/include/linux/sched_hook_defs.h +++ b/include/linux/sched_hook_defs.h @@ -6,3 +6,4 @@ BPF_SCHED_HOOK(int, -1, cfs_tag_entity_eligible, struct sched_entity *se) BPF_SCHED_HOOK(int, -1, cfs_tag_pick_next_entity, const struct sched_entity *curr, const struct sched_entity *next) +BPF_SCHED_HOOK(void, (void) 0, cfs_exec_init, struct task_struct *tsk) diff --git a/kernel/sched/bpf_sched.c b/kernel/sched/bpf_sched.c index 1973cfacc079c9a69ef4653d62981e3f2c8d7f54..6849a58439b2e6ea586b54c1d3bae090f78f4d50 100644 --- a/kernel/sched/bpf_sched.c +++ b/kernel/sched/bpf_sched.c @@ -210,18 +210,30 @@ __bpf_kfunc long bpf_sched_tag_of_entity(struct sched_entity *se) return group_cfs_rq(se)->tg->tag; } -BTF_SET8_START(sched_entity_kfunc_btf_ids) +__bpf_kfunc int bpf_sched_set_task_prefer_nid(struct task_struct *task, int nid) +{ + if (!task) + return -EINVAL; + + if ((unsigned int)nid >= nr_node_ids) + return -EINVAL; + + return set_prefer_cpus_ptr(task, cpumask_of_node(nid)); +} + +BTF_SET8_START(sched_task_kfunc_btf_ids) BTF_ID_FLAGS(func, bpf_sched_entity_is_task) BTF_ID_FLAGS(func, bpf_sched_entity_to_task) BTF_ID_FLAGS(func, bpf_sched_tag_of_entity) -BTF_SET8_END(sched_entity_kfunc_btf_ids) +BTF_ID_FLAGS(func, bpf_sched_set_task_prefer_nid) +BTF_SET8_END(sched_task_kfunc_btf_ids) -static const struct btf_kfunc_id_set sched_entity_kfunc_set = { +static const struct btf_kfunc_id_set sched_task_kfunc_set = { .owner = THIS_MODULE, - .set = &sched_entity_kfunc_btf_ids, + .set = &sched_task_kfunc_btf_ids, }; -BTF_ID_LIST(sched_entity_dtor_ids) +BTF_ID_LIST(sched_task_dtor_ids) static int __init bpf_kfunc_init(void) { @@ -232,10 +244,10 @@ static int __init bpf_kfunc_init(void) .kfunc_btf_id = cpustats_dtor_ids[1] }, }; - const struct btf_id_dtor_kfunc sched_entity_dtors[] = { + const struct btf_id_dtor_kfunc sched_task_dtors[] = { { - .btf_id = sched_entity_dtor_ids[0], - .kfunc_btf_id = sched_entity_dtor_ids[1] + .btf_id = sched_task_dtor_ids[0], + .kfunc_btf_id = sched_task_dtor_ids[1] }, }; @@ -245,9 +257,9 @@ static int __init bpf_kfunc_init(void) ret = ret ?: register_btf_id_dtor_kfuncs(cpustats_dtors, ARRAY_SIZE(cpustats_dtors), THIS_MODULE); - ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED, &sched_entity_kfunc_set); - return ret ?: register_btf_id_dtor_kfuncs(sched_entity_dtors, - ARRAY_SIZE(sched_entity_dtors), + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED, &sched_task_kfunc_set); + return ret ?: register_btf_id_dtor_kfuncs(sched_task_dtors, + ARRAY_SIZE(sched_task_dtors), THIS_MODULE); } late_initcall(bpf_kfunc_init);