]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
sched_ext: Add the @sch parameter to __bstr_format()
authorTejun Heo <tj@kernel.org>
Tue, 23 Sep 2025 19:03:26 +0000 (09:03 -1000)
committerTejun Heo <tj@kernel.org>
Tue, 23 Sep 2025 19:03:26 +0000 (09:03 -1000)
In preparation for multiple scheduler support, add the @sch parameter to
__bstr_format() and update the callers to read $scx_root, verify that it's
not NULL and pass it in. The passed in @sch parameter is not used yet.

Reviewed-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/sched/ext.c

index 12759b9769a54f31b2731de1d430d016c4245b27..7e8430ad06963be698c87a11d26640be49f50dbe 100644 (file)
@@ -6063,8 +6063,9 @@ __bpf_kfunc void bpf_iter_scx_dsq_destroy(struct bpf_iter_scx_dsq *it)
 
 __bpf_kfunc_end_defs();
 
-static s32 __bstr_format(u64 *data_buf, char *line_buf, size_t line_size,
-                        char *fmt, unsigned long long *data, u32 data__sz)
+static s32 __bstr_format(struct scx_sched *sch, u64 *data_buf, char *line_buf,
+                        size_t line_size, char *fmt, unsigned long long *data,
+                        u32 data__sz)
 {
        struct bpf_bprintf_data bprintf_data = { .get_bin_args = true };
        s32 ret;
@@ -6099,10 +6100,10 @@ static s32 __bstr_format(u64 *data_buf, char *line_buf, size_t line_size,
        return ret;
 }
 
-static s32 bstr_format(struct scx_bstr_buf *buf,
+static s32 bstr_format(struct scx_sched *sch, struct scx_bstr_buf *buf,
                       char *fmt, unsigned long long *data, u32 data__sz)
 {
-       return __bstr_format(buf->data, buf->line, sizeof(buf->line),
+       return __bstr_format(sch, buf->data, buf->line, sizeof(buf->line),
                             fmt, data, data__sz);
 }
 
@@ -6121,10 +6122,13 @@ __bpf_kfunc_start_defs();
 __bpf_kfunc void scx_bpf_exit_bstr(s64 exit_code, char *fmt,
                                   unsigned long long *data, u32 data__sz)
 {
+       struct scx_sched *sch;
        unsigned long flags;
 
        raw_spin_lock_irqsave(&scx_exit_bstr_buf_lock, flags);
-       if (bstr_format(&scx_exit_bstr_buf, fmt, data, data__sz) >= 0)
+       sch = rcu_dereference_bh(scx_root);
+       if (likely(sch) &&
+           bstr_format(sch, &scx_exit_bstr_buf, fmt, data, data__sz) >= 0)
                scx_kf_exit(SCX_EXIT_UNREG_BPF, exit_code, "%s", scx_exit_bstr_buf.line);
        raw_spin_unlock_irqrestore(&scx_exit_bstr_buf_lock, flags);
 }
@@ -6141,10 +6145,13 @@ __bpf_kfunc void scx_bpf_exit_bstr(s64 exit_code, char *fmt,
 __bpf_kfunc void scx_bpf_error_bstr(char *fmt, unsigned long long *data,
                                    u32 data__sz)
 {
+       struct scx_sched *sch;
        unsigned long flags;
 
        raw_spin_lock_irqsave(&scx_exit_bstr_buf_lock, flags);
-       if (bstr_format(&scx_exit_bstr_buf, fmt, data, data__sz) >= 0)
+       sch = rcu_dereference_bh(scx_root);
+       if (likely(sch) &&
+           bstr_format(sch, &scx_exit_bstr_buf, fmt, data, data__sz) >= 0)
                scx_kf_exit(SCX_EXIT_ERROR_BPF, 0, "%s", scx_exit_bstr_buf.line);
        raw_spin_unlock_irqrestore(&scx_exit_bstr_buf_lock, flags);
 }
@@ -6164,17 +6171,24 @@ __bpf_kfunc void scx_bpf_error_bstr(char *fmt, unsigned long long *data,
 __bpf_kfunc void scx_bpf_dump_bstr(char *fmt, unsigned long long *data,
                                   u32 data__sz)
 {
+       struct scx_sched *sch;
        struct scx_dump_data *dd = &scx_dump_data;
        struct scx_bstr_buf *buf = &dd->buf;
        s32 ret;
 
+       guard(rcu)();
+
+       sch = rcu_dereference(scx_root);
+       if (unlikely(!sch))
+               return;
+
        if (raw_smp_processor_id() != dd->cpu) {
                scx_kf_error("scx_bpf_dump() must only be called from ops.dump() and friends");
                return;
        }
 
        /* append the formatted string to the line buf */
-       ret = __bstr_format(buf->data, buf->line + dd->cursor,
+       ret = __bstr_format(sch, buf->data, buf->line + dd->cursor,
                            sizeof(buf->line) - dd->cursor, fmt, data, data__sz);
        if (ret < 0) {
                dump_line(dd->s, "%s[!] (\"%s\", %p, %u) failed to format (%d)",