All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuba Piecuch <jpiecuch@google.com>
To: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
	Andrea Righi <arighi@nvidia.com>,
	 Changwoo Min <changwoo@igalia.com>
Cc: Kuba Piecuch <jpiecuch@google.com>,
	sched-ext@lists.linux.dev,  linux-kernel@vger.kernel.org
Subject: [PATCHSET sched_ext/for-7.4-fixes] sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated()
Date: Mon, 30 Nov 2026 15:53:14 +0000	[thread overview]
Message-ID: <20261130155148.2948874-1-jpiecuch@google.com> (raw)

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


             reply	other threads:[~2026-11-30 15:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 15:53 Kuba Piecuch [this message]
2026-11-30 15:53 ` [PATCH 1/2] sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated() 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130155148.2948874-1-jpiecuch@google.com \
    --to=jpiecuch@google.com \
    --cc=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.