mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cheng-Yang Chou <yphbchou0911@gmail.com>
To: Zhao Mengmeng <zhaomzhao@126.com>
Cc: Tejun Heo <tj@kernel.org>,
	void@manifault.com, arighi@nvidia.com,  changwoo@igalia.com,
	sched-ext@lists.linux.dev, emil@etsalapatis.com,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH 12/16] sched_ext: Forbid cpu-form kfuncs from cid-form schedulers
Date: Thu, 23 Apr 2026 17:21:14 +0800	[thread overview]
Message-ID: <20260423171156.G698a@cchengyang.duckdns.org> (raw)
In-Reply-To: <177693500312.275653.17323765149266875001.b4-reply@b4>

Hi Zhao,

On Thu, Apr 23, 2026 at 05:03:23PM +0800, Zhao Mengmeng wrote:
> non_scx_kfunc_deny.bpf.c:17:6: error: conflicting types for 'scx_bpf_kick_cpu'
> 17 | void scx_bpf_kick_cpu(s32 cpu, u64 flags) __ksym;
> |      ^
> /root/work/source-code/linux-next/tools/testing/selftests/sched_ext/build/include/vmlinux.h:136300:13: note: previous declaration is here
> 136300 | extern void scx_bpf_kick_cpu(s32 cpu, u64 flags, const struct bpf_prog_aux *aux) __weak __ksym;
> |             ^
> non_scx_kfunc_deny.bpf.c:26:23: error: too few arguments to function call, expected 3, have 2
> 26 |         scx_bpf_kick_cpu(0, 0);
> |         ~~~~~~~~~~~~~~~~     ^
> /root/work/source-code/linux-next/tools/testing/selftests/sched_ext/build/include/vmlinux.h:136300:13: note: 'scx_bpf_kick_cpu' declared here
> 136300 | extern void scx_bpf_kick_cpu(s32 cpu, u64 flags, const struct bpf_prog_aux *aux) __weak __ksym;
> 
> On the one hand, non_scx_kfunc_deny.bpf.c has it own problem, it should
> not declare scx_bpf_kick_cpu(), on the other hand, the root cause is after

If your point is that a TCP program shouldn't declare scx_bpf_kick_cpu(),
you are correct. The main goal of non_scx_kfunc_deny is to ensure that,
witch commit 2d2b026c3ea7, no non-SCX programs can use SCX func.

> this commit, the signature of scx_bpf_kick_cpu() changes from
> 
> `extern void scx_bpf_kick_cpu(s32 cpu, u64 flags) __weak __ksym;` to
> `extern void scx_bpf_kick_cpu(s32 cpu, u64 flags, const struct bpf_prog_aux *aux) __weak __ksym` 

Regarding the non_scx_kfunc_deny.bpf.c build failure, I'll fix it. If
needed, we can test with another SCX function that doesn't require the
*aux parameter.

Thanks.

> 
> After code analysis and test, I believe scx_bpf_kick_cpu miss the 
> KF_IMPILCIT_ARGS, just like the defination in scx_kfunc_ids_any.
> 
> So here misses  KF_IMPLICIT_ARGS 
> > +BTF_ID_FLAGS(func, scx_bpf_task_cpu)
> Missing KF_RCU.
> > +BTF_ID_FLAGS(func, scx_bpf_cpu_rq)
> Missing KF_IMPLICIT_ARGS
> > +BTF_ID_FLAGS(func, scx_bpf_cpu_curr)
> Missing KF_IMPLICIT_ARGS | KF_RET_NULL | KF_RCU_PROTECTED
> > +BTF_ID_FLAGS(func, scx_bpf_cpu_node)
> > +BTF_ID_FLAGS(func, scx_bpf_cpuperf_cap)
> Missing KF_IMPLICIT_ARGS
> > +BTF_ID_FLAGS(func, scx_bpf_cpuperf_cur)
> Missing KF_IMPLICIT_ARGS
> > +BTF_ID_FLAGS(func, scx_bpf_cpuperf_set)
> Missing KF_IMPLICIT_ARGS
> > +BTF_ID_FLAGS(func, scx_bpf_get_possible_cpumask)
> Missing KF_ACQUIRE
> > +BTF_ID_FLAGS(func, scx_bpf_get_online_cpumask)
> Missing KF_ACQUIRE
> > +BTF_ID_FLAGS(func, scx_bpf_put_cpumask)
> Missing KF_RELEASE
> > +BTF_ID_FLAGS(func, scx_bpf_select_cpu_dfl)
> Missing KF_IMPLICIT_ARGS | KF_RCU
> > +BTF_ID_FLAGS(func, __scx_bpf_select_cpu_and)
> Missing KF_IMPLICIT_ARGS | KF_RCU
> > +BTF_ID_FLAGS(func, scx_bpf_select_cpu_and)
> Missing KF_RCU
> 
> Please correct me if I miss something.
> > +BTF_ID_FLAGS(func, scx_bpf_get_idle_cpumask)
> > +BTF_ID_FLAGS(func, scx_bpf_get_idle_cpumask_node)
> > +BTF_ID_FLAGS(func, scx_bpf_get_idle_smtmask)
> > +BTF_ID_FLAGS(func, scx_bpf_get_idle_smtmask_node)
> > +BTF_ID_FLAGS(func, scx_bpf_put_idle_cpumask)
> > +BTF_ID_FLAGS(func, scx_bpf_test_and_clear_cpu_idle)
> > +BTF_ID_FLAGS(func, scx_bpf_pick_idle_cpu)
> > +BTF_ID_FLAGS(func, scx_bpf_pick_idle_cpu_node)
> > +BTF_ID_FLAGS(func, scx_bpf_pick_any_cpu)
> > +BTF_ID_FLAGS(func, scx_bpf_pick_any_cpu_node)
> > +BTF_KFUNCS_END(scx_kfunc_ids_cpu_only)
> > +
> >  /*
> >   * Per-op kfunc allow flags. Each bit corresponds to a context-sensitive kfunc
> >   * group; an op may permit zero or more groups, with the union expressed in
> > @@ -10031,6 +10067,7 @@ int scx_kfunc_context_filter(const struct bpf_prog *prog, u32 kfunc_id)
> >  	bool in_cpu_release = btf_id_set8_contains(&scx_kfunc_ids_cpu_release, kfunc_id);
> >  	bool in_idle = btf_id_set8_contains(&scx_kfunc_ids_idle, kfunc_id);
> >  	bool in_any = btf_id_set8_contains(&scx_kfunc_ids_any, kfunc_id);
> > +	bool in_cpu_only = btf_id_set8_contains(&scx_kfunc_ids_cpu_only, kfunc_id);
> >  	u32 moff, flags;
> >  
> >  	/* Not an SCX kfunc - allow. */
> > @@ -10068,6 +10105,15 @@ int scx_kfunc_context_filter(const struct bpf_prog *prog, u32 kfunc_id)
> >  	    prog->aux->st_ops != &bpf_sched_ext_ops_cid)
> >  		return -EACCES;
> >  
> > +	/*
> > +	 * cid-form schedulers must use cid/cmask kfuncs. cid and cpu are both
> > +	 * small s32s and trivially confused, so cpu-only kfuncs are rejected at
> > +	 * load time. The reverse (cpu-form calling cid-form kfuncs) is
> > +	 * intentionally permissive to ease gradual cpumask -> cid migration.
> > +	 */
> > +	if (prog->aux->st_ops == &bpf_sched_ext_ops_cid && in_cpu_only)
> > +		return -EACCES;
> > +
> >  	/* SCX struct_ops: check the per-op allow list. */
> >  	if (in_any || in_idle)
> >  		return 0;
> > -- 
> > 2.53.0
> > 
> > 
> 
> 
> 

-- 
Cheers,
Cheng-Yang

  reply	other threads:[~2026-04-23  9:21 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21  7:19 [PATCHSET sched_ext/for-7.2] sched_ext: Topological CPU IDs and cid-form struct_ops Tejun Heo
2026-04-21  7:19 ` [PATCH 01/16] sched_ext: Rename ops_cpu_valid() to scx_cpu_valid() and expose it Tejun Heo
2026-04-21 13:31   ` Cheng-Yang Chou
2026-04-21  7:19 ` [PATCH 02/16] sched_ext: Move scx_exit(), scx_error() and friends to ext_internal.h Tejun Heo
2026-04-21 13:36   ` Cheng-Yang Chou
2026-04-21  7:19 ` [PATCH 03/16] sched_ext: Shift scx_kick_cpu() validity check to scx_bpf_kick_cpu() Tejun Heo
2026-04-21 13:49   ` Cheng-Yang Chou
2026-04-21  7:19 ` [PATCH 04/16] sched_ext: Relocate cpu_acquire/cpu_release to end of struct sched_ext_ops Tejun Heo
2026-04-21 13:58   ` Cheng-Yang Chou
2026-04-21  7:19 ` [PATCH 05/16] sched_ext: Make scx_enable() take scx_enable_cmd Tejun Heo
2026-04-21 14:25   ` Cheng-Yang Chou
2026-04-21  7:19 ` [PATCH 06/16] sched_ext: Add topological CPU IDs (cids) Tejun Heo
2026-04-21 17:15   ` [PATCH v2 sched_ext/for-7.2] " Tejun Heo
2026-04-21  7:19 ` [PATCH 07/16] sched_ext: Add scx_bpf_cid_override() kfunc Tejun Heo
2026-04-21  7:19 ` [PATCH 08/16] tools/sched_ext: Add struct_size() helpers to common.bpf.h Tejun Heo
2026-04-21  7:19 ` [PATCH 09/16] sched_ext: Add cmask, a base-windowed bitmap over cid space Tejun Heo
2026-04-21 17:30   ` Cheng-Yang Chou
2026-04-21 23:21   ` [PATCH v2] " Tejun Heo
2026-04-21  7:19 ` [PATCH 10/16] sched_ext: Add cid-form kfunc wrappers alongside cpu-form Tejun Heo
2026-04-21  7:19 ` [PATCH 11/16] sched_ext: Add bpf_sched_ext_ops_cid struct_ops type Tejun Heo
2026-04-21  7:19 ` [PATCH 12/16] sched_ext: Forbid cpu-form kfuncs from cid-form schedulers Tejun Heo
2026-04-23  9:03   ` Zhao Mengmeng
2026-04-23  9:21     ` Cheng-Yang Chou [this message]
2026-04-23  9:35       ` Zhao Mengmeng
2026-04-23  9:48         ` Cheng-Yang Chou
2026-04-23  9:53           ` Zhao Mengmeng
2026-04-23  9:57             ` Cheng-Yang Chou
2026-04-23 23:04   ` [PATCH v2 sched_ext/for-7.2] " Tejun Heo
2026-04-24  1:44     ` Zhao Mengmeng
2026-04-21  7:19 ` [PATCH 13/16] tools/sched_ext: scx_qmap: Restart on hotplug instead of cpu_online/offline Tejun Heo
2026-04-21  7:19 ` [PATCH 14/16] tools/sched_ext: scx_qmap: Add cmask-based idle tracking and cid-based idle pick Tejun Heo
2026-04-21  7:19 ` [PATCH 15/16] tools/sched_ext: scx_qmap: Port to cid-form struct_ops Tejun Heo
2026-04-21  7:19 ` [PATCH 16/16] sched_ext: Require cid-form struct_ops for sub-sched support Tejun Heo
2026-04-21 18:18 ` [PATCHSET sched_ext/for-7.2] sched_ext: Topological CPU IDs and cid-form struct_ops Cheng-Yang Chou
2026-04-21 18:33   ` Tejun Heo
2026-04-22  1:23     ` Cheng-Yang Chou

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=20260423171156.G698a@cchengyang.duckdns.org \
    --to=yphbchou0911@gmail.com \
    --cc=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=emil@etsalapatis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    --cc=zhaomzhao@126.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 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®