sched_ext: Fixes for v7.3-rc4

- The CPU topology helper for BPF schedulers took no buffer size, so its
   structure couldn't grow without breaking schedulers built against the
   older layout. Add a size argument.
 -----BEGIN PGP SIGNATURE-----
 
 iIQEABYKACwWIQTfIjM1kS57o3GsC/uxYfJx3gVYGQUCarjW+w4cdGpAa2VybmVs
 Lm9yZwAKCRCxYfJx3gVYGX2cAP0VlU9fUs+6zw+CPEvxDfRClCsMvwpbHEh9EtFQ
 1csnhQD+KnIhvmascPtuZLhcYScKfA9ZvvYw/Nme7RVmQ/I8HA8=
 =UsTG
 -----END PGP SIGNATURE-----

Merge tag 'sched_ext-for-7.3-rc4-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext

Pull sched_ext fix from Tejun Heo:

 - The CPU topology helper for BPF schedulers took no buffer size, so
   its structure couldn't grow without breaking schedulers built against
   the older layout. Add a size argument.

* tag 'sched_ext-for-7.3-rc4-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext:
  sched_ext: Add a size argument to scx_bpf_cid_topo() so struct scx_cid_topo can grow
This commit is contained in:
Linus Torvalds 2026-09-27 08:50:25 -07:00
commit 7cdf91542e
3 changed files with 21 additions and 11 deletions

View File

@ -912,30 +912,36 @@ bool scx_cmask_empty(const struct scx_cmask *m)
/**
* scx_bpf_cid_topo - Copy out per-cid topology info
* @cid: cid to look up
* @out__uninit: where to copy the topology info; fully written by this call
* @out: where to copy the topology info
* @out__sz: size of @out, the program's sizeof(struct scx_cid_topo)
* @aux: implicit BPF argument to access bpf_prog_aux hidden from BPF progs
*
* Fill @out__uninit with the topology info for @cid. Trigger scx_error() if
* @cid is out of range. If @cid is valid but in the no-topo section, all fields
* are set to -1. All fields are also set to -1 when no cid tables have been
* published yet, which a program may observe while racing the root enable.
* Fill @out with the topology info for @cid. Trigger scx_error() if @cid is out
* of range. If @cid is valid but in the no-topo section, all fields are set to
* -1. All fields are also set to -1 when no cid tables have been published yet,
* which a program may observe while racing the root enable.
*
* The program's struct may be older or newer than the kernel's. The smaller of
* @out__sz and the kernel's size is copied and the rest of @out is set to -1.
*/
__bpf_kfunc void scx_bpf_cid_topo(s32 cid, struct scx_cid_topo *out__uninit,
__bpf_kfunc void scx_bpf_cid_topo(s32 cid, struct scx_cid_topo *out, size_t out__sz,
const struct bpf_prog_aux *aux)
{
size_t len = min(out__sz, sizeof(*out));
struct scx_cid_topo *topo;
struct scx_sched *sch;
/* the error cases and fields the kernel lacks read as -1 */
memset(out, 0xff, out__sz);
guard(rcu)();
sch = scx_prog_sched(aux);
topo = rcu_dereference(scx_cid_topo);
if (unlikely(!sch) || !cid_valid(sch, cid) || unlikely(!topo)) {
*out__uninit = SCX_CID_TOPO_NEG;
if (unlikely(!sch) || !cid_valid(sch, cid) || unlikely(!topo))
return;
}
*out__uninit = topo[cid];
memcpy(out, &topo[cid], len);
}
__bpf_kfunc_end_defs();

View File

@ -70,6 +70,10 @@ enum scx_consts {
* smaller shards if the LLC exceeds the target size. No-topo cids are packed
* into their own max-sized shards.
*
* New fields are appended, never inserted: scx_bpf_cid_topo() copies this
* struct out sized by the program's own layout, and an older program's copy
* must stay a prefix of the kernel's.
*
* @core_cid: first cid of this cid's core (smt-sibling group)
* @core_idx: global index of that core, in [0, nr_cores_at_init)
* @llc_cid: first cid of this cid's LLC

View File

@ -106,7 +106,7 @@ u64 scx_bpf_now(void) __ksym __weak;
void scx_bpf_events(struct scx_event_stats *events, size_t events__sz) __ksym __weak;
s32 scx_bpf_cpu_to_cid(s32 cpu) __ksym __weak;
s32 scx_bpf_cid_to_cpu(s32 cid) __ksym __weak;
void scx_bpf_cid_topo(s32 cid, struct scx_cid_topo *out) __ksym __weak;
void scx_bpf_cid_topo(s32 cid, struct scx_cid_topo *out, size_t out__sz) __ksym __weak;
void scx_bpf_kick_cid(s32 cid, u64 flags) __ksym __weak;
s32 scx_bpf_task_cid(const struct task_struct *p) __ksym __weak;
s32 scx_bpf_this_cid(void) __ksym __weak;