RFC sched_ext: Make kfunc filters support struct_ops context to reduce runtime overhead
Get series with b4
b4 am [email protected]Versions newest first
- v4 RFC Latest2 patches 1 replyIn review
Changes in v4 from the cover letter · 16 lines
- Rebase on tj/for-7.1 branch
- Remove TRACING access to select_cpu kfuncs. They call task_rq_lock() internally and are unsafe from arbitrary tracing contexts
- Update scx_bpf_task_cgroup() comment to reflect that the restriction no longer guarantees rq is locked, only that @p is one of the tasks being operated on
- Add prog->aux->st_ops check in the context filter to avoid incorrect kfunc restrictions in non-SCX struct_ops where member offsets carry a different meaning
- Fix ops.enqueue() to also allow select_cpu kfuncs (SCX_OPS_KF_SELECT_CPU), so it can call kfuncs such as scx_bpf_select_cpu_dfl()
- Allow select_cpu kfuncs from BPF_PROG_TYPE_SYSCALL progs in the filter
- Update scx_kf_allowed_if_unlocked() to use scx_locked_rq() and kf_tasks[0] now that kf_mask is removed
- Drop selftests update patch: ops.enqueue() now allows select_cpu kfuncs, so the expected-failure logic is no longer valid
- Use SCX_KFUNCS_* macros to deduplicate kfunc IDs across per-group sets and the aggregated set (Tejun Heo)
- Fix [SCX_OP_IDX(dump)] to use SCX_OPS_KF_UNLOCKED instead of SCX_OPS_KF_DISPATCH, since ops.dump() is a sleepable callback (Tejun Heo)
- Fix SCX_OPS_KF_UNLOCKED enum value to 1 << 0 (Tejun Heo)
- Fix non-SCX struct_ops filter to deny rq-locked kfuncs and only allow unlocked kfuncs (Tejun Heo)
- Fix missed SCX_KF_REST in scx_prio_less() (Andrea Righi)
- Merge "Declare context-sensitive kfunc groups" and "Add scx_kfunc_ids_ops_context_sensitive" into a single commit (Tejun Heo)
- Link to v3:
https://lore.kernel.org/r/AM6PR03MB50806070E3D56208DDB8131699C22@AM6PR03MB5080.eurprd03.prod.outlook.com/
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | sched_ext: Add verifier-time kfunc context filterkernel/ kernel/ kernel/ | +227 | 0 replies | |
| 2/2 | sched_ext: Remove runtime kfunc mask enforcementinclude/ kernel/ kernel/ +1 more | +66 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [RFC PATCHSET v4 sched_ext/for-7.1 0/2] sched_ext: Make kfunc filters support struct_ops context to reduce runtime overhead
Hi all,
First of all, thanks to Juntong for letting me continue his work! Since he is out of bandwidth to work on, and Andrea pointed out that this is a feature that may benefit the sched_ext community (thanks Andrea as well).
In this patchset I add myself as the author, while keeping Juntong as Co-developed-by/Signed-off-by to honor his work.
Please let me know if this is not appropriate!
---
This patchset makes kfunc filters support the use of struct_ops context information to enforce SCX kfunc restrictions at BPF load time instead of at runtime.
With the improved kfunc filters, SCX no longer needs the mask-based runtime kfunc call restriction, so this patch series removes it.
Test plan:
- All sched_ext selftests passed.
- Tested all demo schedulers (except scx_flatcg) and multiple upstream SCX schedulers (scx_beerland, scx_bpfland, scx_cosmos, scx_flash, scx_lavd) under stress (stress-ng --cpu 0 --timeout 10s) with no crashes.
[RFC]
I noticed some selftests are still missing, but I am not sure what kind of tests to implement here. Any suggestions would be appreciated.
Thanks,
Cheng-Yang
---
[Cheng-Yang Chou]
Changes in v4:
- Rebase on tj/for-7.1 branch
- Remove TRACING access to select_cpu kfuncs. They call task_rq_lock() internally and are unsafe from arbitrary tracing contexts
- Update scx_bpf_task_cgroup() comment to reflect that the restriction no longer guarantees rq is locked, only that @p is one of the tasks being operated on
- Add prog->aux->st_ops check in the context filter to avoid incorrect kfunc restrictions in non-SCX struct_ops where member offsets carry a different meaning
- Fix ops.enqueue() to also allow select_cpu kfuncs (SCX_OPS_KF_SELECT_CPU), so it can call kfuncs such as scx_bpf_select_cpu_dfl()
- Allow select_cpu kfuncs from BPF_PROG_TYPE_SYSCALL progs in the filter
- Update scx_kf_allowed_if_unlocked() to use scx_locked_rq() and kf_tasks[0] now that kf_mask is removed
- Drop selftests update patch: ops.enqueue() now allows select_cpu kfuncs, so the expected-failure logic is no longer valid
- Use SCX_KFUNCS_* macros to deduplicate kfunc IDs across per-group sets and the aggregated set (Tejun Heo)
- Fix [SCX_OP_IDX(dump)] to use SCX_OPS_KF_UNLOCKED instead of SCX_OPS_KF_DISPATCH, since ops.dump() is a sleepable callback (Tejun Heo)
- Fix SCX_OPS_KF_UNLOCKED enum value to 1 << 0 (Tejun Heo)
- Fix non-SCX struct_ops filter to deny rq-locked kfuncs and only allow unlocked kfuncs (Tejun Heo)
- Fix missed SCX_KF_REST in scx_prio_less() (Andrea Righi)
- Merge "Declare context-sensitive kfunc groups" and "Add scx_kfunc_ids_ops_context_sensitive" into a single commit (Tejun Heo)
- Link to v3:
https://lore.kernel.org/r/AM6PR03MB50806070E3D56208DDB8131699C22@AM6PR03MB5080.eurprd03.prod.outlook.com/
[Juntong Deng]
Changes in v3:
- Change scx_kfunc_ids_ops_context to the more descriptive scx_kfunc_ids_ops_context_sensitive
- Change the target to sched_ext/for-6.15
- Remove RFC tag
- Link to v2:
https://lore.kernel.org/r/AM6PR03MB5080855B90C3FE9B6C4243B099FE2@AM6PR03MB5080.eurprd03.prod.outlook.com/
[Juntong Deng]
Changes in v2:
- Use completely new design in filtering
- Link to v1:
https://lore.kernel.org/r/AM6PR03MB5080261D024B49D26F3FFF0099F72@AM6PR03MB5080.eurprd03.prod.outlook.com/
---
Cheng-Yang Chou (2):
sched_ext: Add verifier-time kfunc context filter
sched_ext: Remove runtime kfunc mask enforcement
include/linux/sched/ext.h | 27 --- kernel/sched/ext.c | 430 +++++++++++++++++------------------- kernel/sched/ext_idle.c | 20 +- kernel/sched/ext_internal.h | 71 +++++- 4 files changed, 288 insertions(+), 260 deletions(-)
Signature · 1 line
2.48.1