From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=124.71.93.99 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795698980; b=IDPIQrawo+uocmmylJ+ROypIIY8H6PsXDJOV6eFvwvCKfrhI35Za4/vTsqFInx+AQs5S dNu7Sq1Zs/+UT29U+pE2b8zRGOUIDKR5kMwleMN9eNBA02rZJR1zLhZrQF7l/UmPmRu+z CQzaxhSl8+mNGu0xkV1IzjgDvYeyBkVmPheJ/tJGS9AIHaQJf0UA425Qkm5tUFsqZN6iv IoFy6yW+myvuYBHtSi94FbAM+lYxdmjhrcj2y9rEYHWb9nSDMYqm/jpE6wi0olfCOsQKX foq2HdwmH3/t9pwV+Er+d4myXI06kY78tSsh0FHCqqg1bDLVH5WrD4x5izxLIvWuQ1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795698980; h=DMARC-Filter:Received:Received:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=fmm7/pB68+gWxYmuwu0MR327OVctgRgVrInq3l7G9e0=; b=t31a5hi/IqHu6Evo0ACQG41acBaY18KmLwKKTLWvyGcUMwJtba47F/r2zBk0N5bU1IQE 1dMuMmYgbQDCkHUL+Ex3vQl1J03NuHg2VhQ6QaiXga0aAwvnXQwYf0O4CdlzsINnAvk4Y YWyExfjoYgJgYPSLVY/lUZukbMkr388DrxjyRZZZZor/6/GG/dBZG1kNip2D1O6/7dctm UNTKd6c+fAP6LPgFwYPmsWzyUK25+T1Q86/wpJE7/13j1wVTPkJ2CaLgj5bbnvAOFGf8d pPAtmHd5hXoe7HIHmGFe12rqiAilLdxQRfOYDe2AbpySoBDG02aP09Wq/Nrc24V6Qgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.remote-ip=124.71.93.99 Received: from dggmsgout11.his.huawei.com (dggmsgout11.his.huawei.com [124.71.93.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D30B8606A33C for ; Thu, 26 Nov 2026 13:16:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D30B8606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggmsgout11.his.huawei.com (SkyGuard) with ESMTP id 4jZxrS4605z1c2B4 for ; Thu, 26 Nov 2026 21:16:08 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 8199A4056D for ; Thu, 26 Nov 2026 21:16:15 +0800 (CST) Received: from huawei.com (unknown [10.67.174.193]) by APP3 (Coremail) with UTF8SMTPA id _Ch0CgAHDgEOMQhrq143Fw--.33284S8; Thu, 26 Nov 2026 21:16:15 +0800 (CST) From: Luo Gengkun To: Peter Zijlstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Tim Chen , Chen Yu , K Prateek Nayak Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , linux-kernel@vger.kernel.org Subject: [RFC PATCH 6/7] sched/cache: Add BPF-facing hint submitters Date: Thu, 26 Nov 2026 13:48:27 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: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xAIcVC2z280aVAFwI 0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x 07UZTmfUUUUU= X-CM-SenderInfo: 5oxrwvpqjn3046kxt4xhlfz01xgou0bp/ Expose the hint queue to BPF programs as kfuncs: - scg_bpf_submit_hint(tid1, tid2) submits by vpid. - scg_bpf_submit_hint_tsk(t1, t2) submits by task pointer. Both pin the two tasks before submitting: the queue owns the references from there, and the worker drops what it consumes. Register them for the tracing, kprobe, tracepoint and syscall BPF program types. The queue machinery itself is in the previous commit. Signed-off-by: Luo Gengkun --- kernel/sched/build_utility.c | 3 ++ kernel/sched/cache_sched.c | 95 ++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/kernel/sched/build_utility.c b/kernel/sched/build_utility.c index 5f63dbd43714..b4a72fd2311a 100644 --- a/kernel/sched/build_utility.c +++ b/kernel/sched/build_utility.c @@ -19,6 +19,9 @@ #include #include +#include +#include +#include #include #include #include diff --git a/kernel/sched/cache_sched.c b/kernel/sched/cache_sched.c index fafb04bcdfa9..045c21e90505 100644 --- a/kernel/sched/cache_sched.c +++ b/kernel/sched/cache_sched.c @@ -753,6 +753,77 @@ static inline s32 scg_submit_hint_pinned(struct task_struct *t1, return ret; } +__bpf_kfunc_start_defs(); + +/* + * Submit a hint: two tasks, by vpid, are worth keeping in one cache group. + * The vpid is resolved in the caller's pid namespace here, because the + * worker consumes task pointers and the namespace context cannot shift + * between submit and flush. + */ +__bpf_kfunc s32 scg_bpf_submit_hint(u32 tid1, u32 tid2) +{ + struct task_struct *t1, *t2; + + if (!sched_cache_enabled()) + return -EOPNOTSUPP; + + if (!tid1 || !tid2 || tid1 == tid2) + return 0; + + t1 = find_get_task_by_vpid(tid1); + if (!t1) + return -ESRCH; + + t2 = find_get_task_by_vpid(tid2); + if (!t2) { + put_task_struct(t1); + return -ESRCH; + } + + return scg_submit_hint_pinned(t1, t2); +} + +/* + * Submit a hint using two task pointers. The caller passes pointers that + * are valid in its context (an fentry/fexit probe argument, or + * bpf_get_current_task_btf()); they are pinned with tryget_task_struct() + * here, so the asynchronous worker can use them safely. + */ +__bpf_kfunc s32 scg_bpf_submit_hint_tsk(struct task_struct *t1, + struct task_struct *t2) +{ + if (!sched_cache_enabled()) + return -EOPNOTSUPP; + + if (!t1 || !t2 || t1 == t2) + return 0; + + t1 = tryget_task_struct(t1); + if (!t1) + return -ESRCH; + + t2 = tryget_task_struct(t2); + if (!t2) { + put_task_struct(t1); + return -ESRCH; + } + + return scg_submit_hint_pinned(t1, t2); +} + +__bpf_kfunc_end_defs(); + +BTF_KFUNCS_START(scg_kfunc_ids_hint) +BTF_ID_FLAGS(func, scg_bpf_submit_hint) +BTF_ID_FLAGS(func, scg_bpf_submit_hint_tsk) +BTF_KFUNCS_END(scg_kfunc_ids_hint) + +static const struct btf_kfunc_id_set scg_kfunc_set_hint = { + .owner = THIS_MODULE, + .set = &scg_kfunc_ids_hint, +}; + static int scg_hint_should_run(unsigned int cpu) { return !llist_empty(&per_cpu_ptr(scg_hint_queues, cpu)->hints); @@ -878,6 +949,30 @@ static int __init scg_hint_init(void) return ret; } + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, + &scg_kfunc_set_hint); + if (ret) { + /* + * A registered kfunc set cannot be unregistered, so there is + * nothing to unwind here either. + */ + pr_err("sched_cache: Failed to register the hint kfuncs (%d)\n", + ret); + return ret; + } + + /* + * The remaining types are best-effort: keep the working queues and + * carry on without the types that fail to register. + */ + if (register_btf_kfunc_id_set(BPF_PROG_TYPE_KPROBE, + &scg_kfunc_set_hint) || + register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACEPOINT, + &scg_kfunc_set_hint) || + register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, + &scg_kfunc_set_hint)) + pr_err("sched_cache: some hint kfunc registrations failed\n"); + return 0; } late_initcall(scg_hint_init); -- 2.34.1