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: Don't allow unlocked kfuncs from ops.dump() and ops.init_cids()
Date: Mon, 23 Nov 2026 13:55:23 +0000	[thread overview]
Message-ID: <20261123135343.4131146-1-jpiecuch@google.com> (raw)

scx_kf_allow_flags[] grants SCX_KF_ALLOW_UNLOCKED to ops.dump() and
ops.init_cids(). That group contains scx_bpf_create_dsq(),
scx_bpf_dsq_move*(), scx_bpf_dsq_reenq_task(), and
scx_bpf_select_cpu_*().

1) ops.dump() had SCX_KF_UNLOCKED since commit 07814a9439a3
   ("sched_ext: Print debug dump after an error exit") because its
   caller holds no rq lock. Commit 4c30f5ce4f7a ("sched_ext: Implement
   scx_bpf_dispatch[_vtime]_from_dsq()") then made DSQ moves callable
   from SCX_KF_UNLOCKED contexts, and commit d1d3c1c6ae36 ("sched_ext:
   Add verifier-time kfunc context filter") carried the grant into
   scx_kf_allow_flags[].

   However, scx_dump_state() runs ops.dump() with IRQs disabled under
   scx_dump_lock, including from scx_disable_irq_workfn() (hardirq) and
   SysRq-D. On a live SysRq-D dump, an ops.dump() that calls
   scx_bpf_dsq_move() migrates tasks and runs nested SCX ops from
   inside the dump:

     sysrq_handle_sched_ext_dump()          /* may run in hardirq */
       scx_dump_state()
         raw_spin_lock_irqsave(&scx_dump_lock)
         ops_dump_init()                    /* arms scx_dump_data */
         ops.dump()
           scx_bpf_dsq_move()
             kf_switch_rq_lock(task_rq(p))
             raw_spin_lock(&dsq->lock)
             move_task_between_dsqs()
               move_remote_task_to_local_dsq()
                 deactivate_task(src_rq)
                 activate_task(dst_rq)
                   ...
                     ops.dequeue()          /* nested SCX op */

   Any scx_bpf_dump() call from the nested op also splices output into
   the active dump because scx_dump_data is armed on this CPU.
   scx_bpf_dsq_reenq_task() takes the same rq and DSQ locks, and
   scx_bpf_select_cpu_*() take p->pi_lock and run idle CPU selection.
   ops.dump_cpu() and ops.dump_task() already deny all
   context-sensitive kfuncs.

2) Commit 874fdc0e86e4 ("sched_ext: Add ops.init_cids() to finalize the
   cid layout before init") granted SCX_KF_ALLOW_UNLOCKED alongside
   SCX_KF_ALLOW_INIT_CIDS. ops.init_cids() runs before
   scx_cid_publish_tables(), scx_arena_pool_init(), and
   scx_alloc_pshards(). Its only job is to finalize the cid layout via
   scx_bpf_cid_override(), so it has no reason to create DSQs or call
   the DSQ move and re-enqueue kfuncs.

Patch 1 removes SCX_KF_ALLOW_UNLOCKED from ops.dump() and restricts
ops.init_cids() to SCX_KF_ALLOW_INIT_CIDS. All remaining
SCX_KF_ALLOW_UNLOCKED ops run in process context with IRQs enabled and
hold no rq, DSQ, or pi locks.

Patch 2 adds the unlocked_kfunc selftest. Without patch 1, the test
fails with:

  ERR: unlocked_kfunc.c:49
  unlocked_kfunc_fail_dump loaded when it should have been rejected
  not ok 1 unlocked_kfunc #

The patches were written with the help of an AI coding assistant.

Kuba Piecuch (2):
  sched_ext: Don't allow unlocked kfuncs from ops.dump() and
    ops.init_cids()
  selftests/sched_ext: Add unlocked_kfunc test

 kernel/sched/ext/ext.c                        |  8 +-
 tools/testing/selftests/sched_ext/Makefile    |  1 +
 .../selftests/sched_ext/unlocked_kfunc.bpf.c  | 69 ++++++++++++++++++
 .../selftests/sched_ext/unlocked_kfunc.c      | 73 +++++++++++++++++++
 .../sched_ext/unlocked_kfunc_cid.bpf.c        | 67 +++++++++++++++++
 .../sched_ext/unlocked_kfunc_fail_dump.bpf.c  | 26 +++++++
 .../unlocked_kfunc_fail_init_cids.bpf.c       | 22 ++++++
 7 files changed, 264 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/sched_ext/unlocked_kfunc.bpf.c
 create mode 100644 tools/testing/selftests/sched_ext/unlocked_kfunc.c
 create mode 100644 tools/testing/selftests/sched_ext/unlocked_kfunc_cid.bpf.c
 create mode 100644 tools/testing/selftests/sched_ext/unlocked_kfunc_fail_dump.bpf.c
 create mode 100644 tools/testing/selftests/sched_ext/unlocked_kfunc_fail_init_cids.bpf.c


base-commit: 2f7928516314f37d7cb334675656b4412edc8be3
-- 
2.56.1.750.gf70dc682cf-goog


             reply	other threads:[~2026-11-23 13:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 13:55 Kuba Piecuch [this message]
2026-11-23 13:55 ` [PATCH 1/2] sched_ext: Don't allow unlocked kfuncs from ops.dump() and ops.init_cids() Kuba Piecuch
2026-11-23 13:55 ` [PATCH 2/2] selftests/sched_ext: Add unlocked_kfunc test Kuba Piecuch
2026-11-24 19:52 ` [PATCHSET sched_ext/for-7.4-fixes] sched_ext: Don't allow unlocked kfuncs from ops.dump() and ops.init_cids() 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=20261123135343.4131146-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.