mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCHSET sched_ext/for-7.4-fixes] sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated()
@ 2026-11-30 15:53 Kuba Piecuch
  2026-11-30 15:53 ` [PATCH 1/2] " Kuba Piecuch
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kuba Piecuch @ 2026-11-30 15:53 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
  Cc: Kuba Piecuch, sched-ext, linux-kernel

scx_bpf_sub_grant() and scx_bpf_sub_revoke() deliver ops.sub_caps_updated()
synchronously with locked_rq = NULL, so __SCX_CALL_OP() leaves
scx_locked_rq_state and scx_dump_data untouched, while scx_sub_seed_caps()
runs it unlocked. Depending on how the parent called grant or revoke,
ops.sub_caps_updated() either runs unlocked or inherits the parent's rq lock
or dump state:

- scx_bpf_cidperf_set() aborts the sub-scheduler with "Invalid target CPU"
  on any cid outside the parent's locked rq, or takes the target rq lock
  when unlocked.
- scx_bpf_locked_rq() aborts when unlocked and returns the parent's rq when
  locked.
- scx_bpf_dsq_nr_queued() (for SCX_DSQ_LOCAL), scx_bpf_dsq_reenq(),
  scx_bpf_reenqueue_local___v2(), and bpf_iter_scx_dsq_destroy() consult
  scx_locked_rq().
- scx_bpf_dump_bstr() aborts outside dump contexts and writes into the
  parent's dump buffer when called from ops.dump*().

As agreed on the list, ops.sub_caps_updated() is only for tracking held
caps and propagating grants and revokes to children (while cap-acting
operations like scx_bpf_cidperf_set() belong in ops.sub_ecaps_updated()),
so rejecting these kfuncs at BPF load time prevents the misuse up front.

Patch 1 adds scx_kfunc_ids_no_sub_caps (overlapping scx_kfunc_ids_any with
matching KF_* flags) and rejects those kfuncs from ops.sub_caps_updated()
in scx_kfunc_context_filter(). scx_bpf_cpuperf_set() is already rejected
because ops.sub_caps_updated() is only attachable on sched_ext_ops_cid,
where scx_kfunc_ids_cpu_only forbids it.

Patch 2 adds the sub_caps_kfunc selftest. Without patch 1, sub_caps_kfunc
fails because the verifier accepts the restricted kfuncs in
ops.sub_caps_updated():

  ERR: sub_caps_kfunc.c:91
  fail_cidperf loaded when it should have been rejected
  not ok 1 sub_caps_kfunc #

The patches were written with the help of an AI coding assistant. I have
reviewed the patches and verified the tests run by the tool.

Kuba Piecuch (2):
  sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated()
  selftests/sched_ext: Add sub_caps_kfunc test

 kernel/sched/ext/ext.c                        |  49 +++++++-
 tools/testing/selftests/sched_ext/Makefile    |   1 +
 .../selftests/sched_ext/sub_caps_kfunc.bpf.c  |  66 +++++++++++
 .../selftests/sched_ext/sub_caps_kfunc.c      | 107 +++++++++++++++++
 .../sched_ext/sub_caps_kfunc_fail.bpf.c       | 109 ++++++++++++++++++
 5 files changed, 331 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/sched_ext/sub_caps_kfunc.bpf.c
 create mode 100644 tools/testing/selftests/sched_ext/sub_caps_kfunc.c
 create mode 100644 tools/testing/selftests/sched_ext/sub_caps_kfunc_fail.bpf.c


base-commit: d43078a237230fd8fb6bf082ff285c93d0ccd763
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 16:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 15:53 [PATCHSET sched_ext/for-7.4-fixes] sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated() Kuba Piecuch
2026-11-30 15:53 ` [PATCH 1/2] " Kuba Piecuch
2026-11-30 15:53 ` [PATCH 2/2] selftests/sched_ext: Add sub_caps_kfunc test Kuba Piecuch
2026-11-30 16:59 ` [PATCHSET sched_ext/for-7.4-fixes] sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated() Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®