From patchwork Wed Feb 26 19:28:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13993061 X-Patchwork-Delegate: bpf@iogearbox.net Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazolkn19011038.outbound.protection.outlook.com [52.103.33.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73F2424290B; Wed, 26 Feb 2025 19:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.33.38 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598234; cv=fail; b=V96QpxAcaJe4Y832g+FzcofhOCxVPe39z87HqFoace+XlufjSbJeq5RYFBY4MCb8A1N3lJqweFiKBbg1tdkPjgQ3Bow1IVi17qwmELg0ojMiZwYVALCdIiukE3c8U0lh8IjtpkXzADjn9E5FZZPcAaO2Xlc6KSYmaZc2tbj4KiU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598234; c=relaxed/simple; bh=HmwH+cN60yxalTr1BHqponBP6iClfhXvpgjEJetVV3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mshw+D7T/AZRAS2Bg/gFQ4Yl+Hq57lxPF7KLh1z6O8KYzadwwS2FRG1l1Dlcvjwr6QQAuHKZQACImmVqulijtpOdouq+BqzE3jlCGQc3z4sHK3wem9eUMLIEpdR69Cdtt1i+3EqWPPkY5eT55BO2ebPwUG2qKDxeYXF1aVU1Jl4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=szxj+6MX; arc=fail smtp.client-ip=52.103.33.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="szxj+6MX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nzGjAAbWYiMpUoMa8MTe25EK+Ec5RG89udStaDGrBLqYXdLYxgUejIBvUtzUDYBnnte7ui/UXSmYClD0v/c8F6Stxd2k9MbO4nDp85pzpVtqAw0gyK5IHBjmGVN1jJCQpVp+zzzIRSkpzEPwh6lGDtZyRXJYGH8puRy0OFkdgPmk1wRFfuOD+ssnsn20m+wEncm8Ii8Ea8bSDSPbEmtdCdihxNfDRvEGf/vNR8XxRANO4tiOGUt53IC8mGagoF9mH3y926HJRPgMu9mc6fUFx6l0nvMITwe6FSSj/13jw9V8xWic6Y7zcIyLTScVzB8mOq1w6tLN4oBAWJrdo/q6ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gm7boR8lK/4PKwHNHfZm/xsiGobHGR94qtaOr9lLJdA=; b=NQuN6U0Cyxlct+JxUc/+7zUg1T3Q9E/ISRcxA/qUiK7k5mgT/uP5mkChTJmm8HV3HiJpJ82GQWBJc8JsS8AY47f6/47xEV20bLQlodZpuOij/jRx2PTXJ3EIZcbJUt4nvJRtWRQmLVFtt5T47c73YQ5W1Wz5uFQAGUs6cGr/FNPsvIQemUwe+rOVqhukl1H2gyfcp+35gY2Dva6r+hTtki9vLfDKlmtCKsWJ39hh4jFRsT6Gc2xODJdvKLpceYDq7X240T393DZS8UkB78QP+d1yhlaM/3qpTuRI5Jm+DImwn8Y8r9ySHRtw6Np1KrLnIRPpOdjNauP2Mh8N3NafVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gm7boR8lK/4PKwHNHfZm/xsiGobHGR94qtaOr9lLJdA=; b=szxj+6MXJZ5aaXT0xQgHSuA0pb0z30C011Poy/gKoNT6MNOUf0eEz2YHiWVQugM4hJzwJf0cqp0HjeZQZ7s/JAmgnXq1BVuvv4ClamzWslXbbKxMSb5YRZUl9Iw9S18zZ3b7fACcLFm7bBWIquDtu9IxUKe52sUAvgkVc5Uwa+STukRpx9Chg7wFg5BGwDDUcTrMgTWhAknS7u0r8MrwwIvLgQh0JlA/o34JQiLspnOu4Igrlfy9rTwDQ9Qx7wte8vswS22Vm0R4V967A14wcb5W2h8DszKtSpfa2+9FIhWl2oHmfNBwM3Y0C+AvTeUe1busmtWNZTOoXrEsIev/Mw== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by DBBPR03MB7451.eurprd03.prod.outlook.com (2603:10a6:10:20e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.19; Wed, 26 Feb 2025 19:30:29 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%5]) with mapi id 15.20.8466.016; Wed, 26 Feb 2025 19:30:29 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH sched_ext/for-6.15 v3 1/5] bpf: Add struct_ops context information to struct bpf_prog_aux Date: Wed, 26 Feb 2025 19:28:16 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0349.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250226192820.156545-1-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|DBBPR03MB7451:EE_ X-MS-Office365-Filtering-Correlation-Id: 6f0328c8-1ef5-4599-c14f-08dd569c0715 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|15080799006|19110799003|8060799006|5072599009|440099028|3412199025|41001999003; X-Microsoft-Antispam-Message-Info: Vf4h5OspN3Y2I73Q9XXpnPGUdRjduGfHZ4yOS73mlcnCjxrZTT7/i+YzFT384idseEWUz+iJtDiRdu40MV7c2N3qKxm+B2Mao1+bD+G5hdED7Rxzw2mkgPXqG82vvDY5i8cWIuQ0p/yxpKtE6ptgolYPYmb1lXtudQXZdIp7Zdyle03H6ET+KEFavtGo6ruf8wdcbj/44uCEZ8IPy2E2pLMEM1CT29Bc4/2qklYaNz7lSm48ujvCaZPjxx219EJLcWbrJF7PeAA4UozA70b2sAmngtsLYRDxMRPOfT8u+L7N2YktAEFFmb8QPW3CHi5/dIsgCS3/lgAznjfAM2Kq24kgtSYu3bh1HKVtGV18iSZd7wu7GAB6qNKrntDxWqAL+44Y9flHsJOfEFbn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QVIIXBHNUx4tkctUJWUofih7LH2weCGHd5IxEcK7EQLwV9ThwoeAAiCOBRhUTXkAdfBGc3JXHYcrUee1z9aRhtMuvwA1JBYPg6N+IyPtthN0f79SODEe2OXFrCxE/ztouuChTazZBYYvd2c2evWt+R/gY84q/PlFkQkHz02oVdjFlWeBH33TOh7qJ7qzsZikMIUJJmHqp2nToa6kNRTtOVW4GubMH2FFLAJXTvhQIfNPzu7o7QQC1Gr1FoJ0l1m7+P4Fnfm13L2kKRd1wMlA9GhSlBPffhQQGZS2pdJoj6GQdVjhk937ZBd+v0ahM1w78pmSPmz9+h/g2rZ/S7aNRKUMAbCT4zScxxUsLOqsghK1RsWowl17Oqr2bZyA9yjSqnO0oKSA0jHxQTuGsbZQVVG643t6G9zVgI43uCfWz2RvvsGx3pps/fp8oCrRGPR6OGO+HHjQkkNc++0EiC60/g4yRpJBlChFeWedLWzO074ODtya5FNfaApHel5zbsiCJFI4rewBpxO6WSMGaOFL1sr0FqjyCgDiSNlt7GtbVdTar7tw/z2SZBtRKecQPRpi5LJZL+6JwUHUCeeZp6lMymjIFmJQX1/MJVLQspPl4f5UMTQQjPRGfNziw/naXKFG79YNYHtiD3E+6j9TEAwreb8fNGrEZK1mdN5ohnavEkGfZHnP8YNJVv6uKsZb0O+YBjFybYAA4LTuPBm4RYMHuBeVaLq1UX68o3uSkqoUqMcRdpke4PPxrDGo2A/PHD6XJqCvRX7eVbBTS1eEO3FMg7ZpYG7qAMDwzfhO8/ffInL8i0LGs17nzW4soFOEX5QXWJrENBtpU2fceEzPIv9uXTwgVdEIxQ/7FHB435Ky5sG0KBHEvb/DMraJDGD9bqO6Z2pmaCddEegg/iP+Nl87ilPJO4cTxTIosj6bWNJquvLJhEtlg50jAQL9n8V2b+jWRm/R1ErNJn0ESl/FsVRa8ISwU6 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f0328c8-1ef5-4599-c14f-08dd569c0715 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2025 19:30:29.3926 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR03MB7451 X-Patchwork-Delegate: bpf@iogearbox.net This patch adds struct_ops context information to struct bpf_prog_aux. This context information will be used in the kfunc filter. Currently the added context information includes struct_ops member offset and a pointer to struct bpf_struct_ops. Signed-off-by: Juntong Deng Acked-by: Alexei Starovoitov --- include/linux/bpf.h | 2 ++ kernel/bpf/verifier.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index f3f50e29d639..e06348a59dcf 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1503,6 +1503,7 @@ struct bpf_prog_aux { u32 real_func_cnt; /* includes hidden progs, only used for JIT and freeing progs */ u32 func_idx; /* 0 for non-func prog, the index in func array for func prog */ u32 attach_btf_id; /* in-kernel BTF type id to attach to */ + u32 attach_st_ops_member_off; u32 ctx_arg_info_size; u32 max_rdonly_access; u32 max_rdwr_access; @@ -1547,6 +1548,7 @@ struct bpf_prog_aux { #endif struct bpf_ksym ksym; const struct bpf_prog_ops *ops; + const struct bpf_struct_ops *st_ops; struct bpf_map **used_maps; struct mutex used_maps_mutex; /* mutex for used_maps and used_map_cnt */ struct btf_mod_pair *used_btfs; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 9971c03adfd5..2dee3fd190a4 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -22384,7 +22384,7 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env) const struct bpf_struct_ops *st_ops; const struct btf_member *member; struct bpf_prog *prog = env->prog; - u32 btf_id, member_idx; + u32 btf_id, member_idx, member_off; struct btf *btf; const char *mname; int err; @@ -22435,7 +22435,8 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env) return -EINVAL; } - err = bpf_struct_ops_supported(st_ops, __btf_member_bit_offset(t, member) / 8); + member_off = __btf_member_bit_offset(t, member) / 8; + err = bpf_struct_ops_supported(st_ops, member_off); if (err) { verbose(env, "attach to unsupported member %s of struct %s\n", mname, st_ops->name); @@ -22463,6 +22464,9 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env) prog->aux->ctx_arg_info_size = st_ops_desc->arg_info[member_idx].cnt; + prog->aux->st_ops = st_ops; + prog->aux->attach_st_ops_member_off = member_off; + prog->aux->attach_func_proto = func_proto; prog->aux->attach_func_name = mname; env->ops = st_ops->verifier_ops; From patchwork Wed Feb 26 19:28:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13993075 Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazolkn19013081.outbound.protection.outlook.com [52.103.46.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C81021ABA9; Wed, 26 Feb 2025 19:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.46.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598302; cv=fail; b=Z+334S90cjBFwTnealpg3D9QaTikr7sLWq6aq7sTD77RO3Nb0toONEmrzaBUOQzRTGLtbsCIbpYxkQr+g/6L5kq01N0jyiOR6c1GSpcfJpZKTmSWIIoI1+KPAA9tEKtwBFEcb1K0hYQvbnRgWKleWOwDfcP/h3SDWFRn2bNru7o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598302; c=relaxed/simple; bh=IH3wKq6USU6wPOjQBZgjQWmtNZ/GcrG0I9gnWi2xGq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=nAYHgMmhwpREFmmRdQ5zxCGRQBu990w08Ox+udaz9b5S2CcGUJyFie+7IhetNTjAmPlHCdFLakmFB/D5vJHdcBOdcFED/8QId4w2ofCFcHUcdhA1VoCCxd+DA2Ep+2wlSGxigYyymPsovLbz5UqonpNgaykWCIXs6WJn3M60s4w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=ncB0tepn; arc=fail smtp.client-ip=52.103.46.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="ncB0tepn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dvSVdW6Yidu3Q780Q2Mjuor24aDo+22cSN8Ll2Qw//KdkCkiJZZ2c5jIRmhbHlGgbO7VhGIaw+3/v+1IIVV7pm0CwLOdtfcb9j+lJ9iEPIJQXs6fUBB7U4KWXo4vC7qUOGrJWSiMd9qLkdnC9oa9dRtajWeWxdJR6R6NQEvx0pwWfMP/3gYza6cV+SpYuBINfjSTD5VJbKFQaM+SlFjQa01Wo12R3TTxvYProx6+WWJKQgoCi3Ssrs+XM1phQuqBlbxqp7/ENd74xYrQtWDYcefC2xqzo2JLGkPosPleTLbyElwiPxj9cHF/ZScQ7uV6uVSWw8AAdV70CSCEk1Es8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GJn1KS2QtzN5zmkzWyOj1v4nTuLUZgcItlDeIfoYU/s=; b=Eaf3eVPFRIkJZjvEnllJXqT5DntVddBdTg2a6u5/k6JswWI8GkiiXxZTf0/joTh3BLhLw5qMGa8g3JnOtGOcBDtZUcUvx9dOxs5trtw07IePlVNkIKrtXEOd/Rl+iLzW4+8u9fvIJ7QT/Bnl4vWGC8hkx9xxyIhxshsqPsYhxBfuoDoIGoOTZd+ntMLtflsdgz36om2FjttLhHULDQahRnEx3hc+mSy4apGzVAjQN+NgQgOj6rlVNlM4/EQqdcmGI/CqE3I5tdcEoAKU/ldW6/oG65XLuvLQQocxddZKiZcEcD4DzNWAYzHdD9YCznBj8AGOp6cs1GgNjSJoZ4BGhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GJn1KS2QtzN5zmkzWyOj1v4nTuLUZgcItlDeIfoYU/s=; b=ncB0tepnhYEUtFzrnZnOyIPqaKkWEyfCrdsWGaTK+So2R+8aUMCXAw5bdTaCWhjNmRyOZSuteu083FsMWW5OAOP8ySg0YLUAZG3CECyCNO79ORxomY2Kp8OkVieE0+EuEtELFEQAouc4ZDk9vx/grwjcZKieWHX1tvLCl1s+VjXMDl6v8q8o6q1vbIaG682s7tHCucMm9OZIQZpUFoAeRtq7I4qi9qLn2Qt66IOOgw+aqD23SRcFziY3vbtj+evpBVJx0wpplfa5iniRHxNTfFZl3hdY3kiga9mBMZzyxAbXP/DQeqvYRzh2NYSIEWExeNcgIAOMdb1BPM6z2hwBTg== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by DBBPR03MB7451.eurprd03.prod.outlook.com (2603:10a6:10:20e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.19; Wed, 26 Feb 2025 19:31:37 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%5]) with mapi id 15.20.8466.016; Wed, 26 Feb 2025 19:31:37 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH sched_ext/for-6.15 v3 2/5] sched_ext: Declare context-sensitive kfunc groups that can be used by different SCX operations Date: Wed, 26 Feb 2025 19:28:17 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0349.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250226192820.156545-2-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|DBBPR03MB7451:EE_ X-MS-Office365-Filtering-Correlation-Id: dc60035a-f980-47fe-0f2e-08dd569c2f7b X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|15080799006|19110799003|8060799006|5072599009|13041999003|440099028|3412199025; X-Microsoft-Antispam-Message-Info: pwj1XCMOrLlrtEYdIQUGJgJIU0GHL8ok+K4KN7Ul0jbiCkTx8kszrxxmJNTRKVmKpvKZavCFuoNM77nwbiypGTkeYPoCQHlxbpzY6jdsZ8PVZ8nhDrsfYgt+WcFEAOxDSKA14AMR+KNCBf62Ya7CPu+ssIaU/Qb+Sb0zkQelP09xaLvKdMTiMOQ7tt0WZ0YfrpKMCoYFY77wmIrOXsRu0gDlWbsEPibNNlTSkaq+xBc8Ll7dKAFmbJsEskSMq0GN6nYfhFqCWP5OJv5lGWl2RfnVP/aM0AJvD7WrkTz6YXe0e3cX+LoPrahEwanMLgOdPQX5euVPOi/EcFfzoAaoX6xNNwdbIqbkX21NbM+C23KDhzCmYbadQan/23AF84gW3XBr4+sI836sN0gNqEIHXy/XcAAxD/9m/7CjERCrAuje14rlZXa9yW8KAMl2Qwwhr+X+4uj0ri229GpzqE/OGp6MkN8qWWFHayss5PnloC3dG5y1ZSeOG0blIFOF3pfF/ajYK2oGmqBzgLrQ+FR6JMQX4FFSt4t8lncf3FsaK7eGSo7+IOSxFzdwmzgDve54R0C5VzNsXDy2KAzKz83Xd7ekIl1jvqdlNZikuo353pSgR5pc+vYwUHaTgsgimqMoVbvu5OJ05VpUqeIZKv10yQG0V5jX66f25v84gjPHFvlZ+ZDgwX8HmjHxPNuF1YFWAcnCd4kkFjoYaT8jN4Rp0ulpgo336FyEBINzbH6QEESA30XrYnn7D0khCC2h24grpW4XLal713Cj1vQNcs6DJHA8kabH84TcKM/d1DtVG7RkhEg3r0avztx8VPgUdXIXva3Ipkc0bc7j1UXvYEbaB1+PZsYbJxYbv/zJykVQig1PbaULU9rBM/FV1GpUKeWNsCPOWnRiUJSEnN2L3uU8vP24UpKaDNKh0aXNdRsIu15T1Lf+Tp926AgaSlIha7nidzEUyUknMS326WKSS5JXwmXhJZ4v77Juh59+/Jj6gbQA9cMwc2DqJ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MbjKsT/+uXuF6JTA3Mxr9KUCxtH/bub2XmgZ8GaOo279leWLJ95NBN0dJWaI93rrvCIFuvbS5Jt3N0J5lcCg7sXpFsoVXblO912J6o6H7Jv5oW0H/+Zk3gaw9peetrFlMfDu152fWItyUlFGR1tUCRIWDTpk5aDiju//KTqgahVoQ+f35weBwVmSY3U+GyvQL/CXA3KWDrEFl3mJJGvouIhFntdxd+/8s47O50DZO4Njov4B/9XcX8eLHAZdIgevOtuTTh0D8HsRbii1nt2DvZIzbjaZoUtvT+zB2Jw1iGOO0UoDXn/Y9DcEMMmzM98/fVb0EoNk/VXkyZDIr+Y1VrhSSuo2/luSxGOmEq4my/r X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc60035a-f980-47fe-0f2e-08dd569c2f7b X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2025 19:31:37.0169 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR03MB7451 This patch declare context-sensitive kfunc groups that can be used by different SCX operations. In SCX, some kfuncs are context-sensitive and can only be used in specific SCX operations. Currently context-sensitive kfuncs can be grouped into UNLOCKED, CPU_RELEASE, DISPATCH, ENQUEUE, SELECT_CPU. In this patch enum scx_ops_kf_flags was added to represent these groups, which is based on scx_kf_mask. SCX_OPS_KF_ANY is a special value that indicates kfuncs can be used in any context. scx_ops_context_flags is used to declare the groups of kfuncs that can be used by each SCX operation. An SCX operation can use multiple groups of kfuncs. Signed-off-by: Juntong Deng --- kernel/sched/ext.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 74b247c36b3d..15fac968629e 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -730,6 +730,54 @@ struct sched_ext_ops { char name[SCX_OPS_NAME_LEN]; }; +/* Each flag corresponds to a btf kfunc id set */ +enum scx_ops_kf_flags { + SCX_OPS_KF_ANY = 0, + SCX_OPS_KF_UNLOCKED = 1 << 1, + SCX_OPS_KF_CPU_RELEASE = 1 << 2, + SCX_OPS_KF_DISPATCH = 1 << 3, + SCX_OPS_KF_ENQUEUE = 1 << 4, + SCX_OPS_KF_SELECT_CPU = 1 << 5, +}; + +static const u32 scx_ops_context_flags[] = { + [SCX_OP_IDX(select_cpu)] = SCX_OPS_KF_SELECT_CPU | SCX_OPS_KF_ENQUEUE, + [SCX_OP_IDX(enqueue)] = SCX_OPS_KF_ENQUEUE, + [SCX_OP_IDX(dequeue)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(dispatch)] = SCX_OPS_KF_DISPATCH | SCX_OPS_KF_ENQUEUE, + [SCX_OP_IDX(tick)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(runnable)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(running)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(stopping)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(quiescent)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(yield)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(core_sched_before)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(set_weight)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(set_cpumask)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(update_idle)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(cpu_acquire)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(cpu_release)] = SCX_OPS_KF_CPU_RELEASE, + [SCX_OP_IDX(init_task)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(exit_task)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(enable)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(disable)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(dump)] = SCX_OPS_KF_DISPATCH, + [SCX_OP_IDX(dump_cpu)] = SCX_OPS_KF_ANY, + [SCX_OP_IDX(dump_task)] = SCX_OPS_KF_ANY, +#ifdef CONFIG_EXT_GROUP_SCHED + [SCX_OP_IDX(cgroup_init)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(cgroup_exit)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(cgroup_prep_move)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(cgroup_move)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(cgroup_cancel_move)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(cgroup_set_weight)] = SCX_OPS_KF_UNLOCKED, +#endif /* CONFIG_EXT_GROUP_SCHED */ + [SCX_OP_IDX(cpu_online)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(cpu_offline)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(init)] = SCX_OPS_KF_UNLOCKED, + [SCX_OP_IDX(exit)] = SCX_OPS_KF_UNLOCKED, +}; + enum scx_opi { SCX_OPI_BEGIN = 0, SCX_OPI_NORMAL_BEGIN = 0, From patchwork Wed Feb 26 19:28:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13993076 Received: from AS8PR03CU001.outbound.protection.outlook.com (mail-westeuropeazolkn19012048.outbound.protection.outlook.com [52.103.33.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66746241688; Wed, 26 Feb 2025 19:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.33.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598390; cv=fail; b=MrxS2X2vatyH9RqMZNH8T1/+lT+5LysGo7yq7xN/NzjbHSn+5HAV4aeYlUovMqm7SG+qlUs7uTwidQJjGgnW/J6pLSTDZASClrg2QKLwyuZf7eG8WgMvDzmjRBQgi7heHd/fGwCoH94CUDKtyw7p3tresSHsM4VPPVT7pNZIVW4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598390; c=relaxed/simple; bh=XsrfMJpgmsn9RyPedTdq59gDV2Uzbf1W0Ie3Y94JG5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=fuKLt/DwqF2PMHz1BA/teDv0nKvPFupSVhk0gtYQG/LHvwVlEsODtQk5S6yyORtKeDdzKKKlfEMEbPjsUDM6FYEpeh00OziI/En/USvCBVUYkhnViKrRsUhPTX+ZqYwxAsKlD/RVVsIxmikFcuJJfnjfNnQu9HLN9JMtdyWsPiw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=NyORY6nu; arc=fail smtp.client-ip=52.103.33.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="NyORY6nu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mQ43e/NZcvdENSAAHZUaOGSrTqksbrMCy++Q34SKWi8ewyVhmYcsGAT/vFDBcY5B/6XzYxXeO1MBzOggZoDFPH+MCuZj0YlR4RfF3sk4U2P2sNst42vT5BtzDQLml8ZdozdrchcLiuAk52tPY1mZ5dlkX7UBSswVEllj5TOjdILUgGodKx/DBPsIl7rqO5eGEHBpUjdGIG+esx6Uj/2l2MgCmItu4pMGDPOaev2lNRvo/VMZVzkE3JLRneICXvqfj2GkarOdoV10mMQjELSWHy2PDU0kBf/HMaKBnd4bmFBpKUVPGOl3MenGi4yZKkXjMn/KBI17hwYlPQMwruWZeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=h5p+IAFZYSFBWo6hwL7YB4taBY+9DozD4tTI00KyKf4=; b=ygkq4mwRgxK2f6tcWnGcxsXI1bftIeboUgqkonLuViQC1KNJ70A49/DZXkKZxAdWFRH8M0yhG3lLIfaZ0qtsSZc7P03SbBiCXVs5jDcfkgKx+OrPkJ2gjzOJM6yYqB4MaRXkNaOBm40nNjBdjfa8nsIdHB/fWF0xS2VcuAXMsyw/OAazlB/yCUMCNr0XECJrOvDVtRjjAMJS2cawMBz7o7Buf6lCWs9vruvRBwdRxRhllq2/fjSYdntMfzZwVF9l4F0MEhDrvFOS7/d7YYjbYCKzqlhfsMlsXEOx3fOK9Rfn9e7ZJts/D06nWELw3ygPE89wBgShuUQkHzcS8llP3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h5p+IAFZYSFBWo6hwL7YB4taBY+9DozD4tTI00KyKf4=; b=NyORY6nu8/4aLHQTxlMN0QCSmT1IGcVnUgrmYseEStsBhfDWa0tjlkgOrx0xxGQNTKFiCfR6Tr1NmhLNp63+pBIwD1iIDt0NOHhOIBUkJEtkvO0/4kYcloqQ6ulMg/tJ4sucMEvzYNpL8V2lbivYYhVVGY6lFes6N0RCG5jn2Ilsl6tNzc5SB3PWO5vShMzfdXP3vKZQh2OIXqr6UlqtBCbqHk/vOze7/WRECDGuzfdlv3z/3jm6EdM6Lr3YxsdHE3bhm9sRmj5AQVORWeTLQN8XWWB0ZKmNczHVlR+e/VfDD+H9DMISyFhUGOB1Mz2misZcb5nGLiDA5VLyUdy/+w== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by DBBPR03MB7451.eurprd03.prod.outlook.com (2603:10a6:10:20e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.19; Wed, 26 Feb 2025 19:33:05 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%5]) with mapi id 15.20.8466.016; Wed, 26 Feb 2025 19:33:05 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH sched_ext/for-6.15 v3 3/5] sched_ext: Add scx_kfunc_ids_ops_context_sensitive for unified filtering of context-sensitive SCX kfuncs Date: Wed, 26 Feb 2025 19:28:18 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0349.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250226192820.156545-3-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|DBBPR03MB7451:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bd22db5-7285-4b0b-185b-08dd569c63f2 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|15080799006|19110799003|8060799006|5072599009|440099028|3412199025|41001999003; X-Microsoft-Antispam-Message-Info: TGP5BJ3xsk9wBve4CY24WAzl7XjnWM4E9qkK2pcG6gUe11mhE4UphcEXfhsp/JX2GlvcuVGzkFmu8jX32MM3od/coPnNCSDX525i8xEgOy7JgiR5OoyFp+EaSIWDPMgUkpRMfipPYqTrfoQbaJ41Q8tENFGaGSuC3CHVyALp4zA0+wGKn+RVznqaw1MdGj9dMbTyVrtBskS60GmdAgM6r24pGvFwJ63LINgdvUdPpKIoebarsvvqxgFx49mgmbhB+ML1ccdNjhhgXdy4aCAzpoL1rxC/vemFXsiMAzFEtP1e7AJeZnsr5lwmBapAeTphQhIMbgzAGtZHkdutu3KRkXdt5alToQ1SEcxtwAz+VxFCVuL7CYou++9/ukHMfOsjqkDKmM4tXga+oBYGtREN+5wQsrK9sLabcqLunBSOadfSuwQ9rk3ZYTFcIbNJbgOjTVPxZZQQrXAacuS9uKcK6e4Hrt20KUNuPQvstu+gcm1Tvf5XXYrDtVFCYnBI2oAxBzw3GRnN4SrmF9j+isDXwZPR6YxqV7Z/+5oEFo6F171kw148J6rAuLPw9NBobemx6ezU1yF4eW7vlcwrvU6CjC0vtBiH3G3Po18862vw1itjPpyGlv7fpypUhxP+UXr6a63qLy2bqrVnqtMwO1rpMMAGw7KW7//4SmitI3l9TVpxzfJQyosGYNpn8/D+0RitgGrAnkS1fJmzt7Wf+00/mrJyyWK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IBnIVvq/38iwOrU0aQTrUmtZKrIZUiaD+mTyoz3oDiEU27mArJQAblRRz2hrhA+2jqlGgF8pSTAMbebQ+z1ghic/2jw/6An29rRYgszoS6vDCCtvhGMqTzb4qbvQjuCb51MhtALdMKwF8hr7Z/fTJ7LwPVNAZtDJK6bxhW4jb48zDH7irXhkK89m3gUiZUrEEqiP7iZhLO/sueMI8XVP7GTIn0zWVOdwtmhLk6ynmbWQmwfG3U6Zoy+nMsWDu8VpIytC/MgOvozfs10aGr4W+fhslKQR6wbKSM2qWBKblxugtu5z7fHCUNxnPwg+YXqhdtMRDf37xbnq76t1GNCN9PK6PuMxar9Gv2GQ9Tu9dScpC4RJ4CePhZCn8Lq+DDAMGEGsD2+JhSSnigQaaPFasdJ8AuK7iJdAppf9jMeHdoaJBAZUk93WrvTMq8HcXJ6OWmJp+67dTzB9Ocf0KlxiWlk/zc3gqYcDxT5ntdxYohSQiJFO+CjgWgNuzN2TolqfSEXwBE1LC4uEawP7LuQQ1u8tjL1Qjzqbaar9BhEfbyJHEeYY7QMFdZ/Q3RnyUXgGA7PDxhN4Xu5htOMbrD/NO17OabVc9P+/Ftb6Ipx+2by/hmKAln+qcMDokhA0OyInE3oFb X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bd22db5-7285-4b0b-185b-08dd569c63f2 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2025 19:33:05.0678 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR03MB7451 This patch adds scx_kfunc_ids_ops_context_sensitive for unified filtering of context-sensitive SCX kfuncs. Currently we need to rely on kfunc id sets to group context-sensitive SCX kfuncs. If we add filters to each group kfunc id set separately, it will be cumbersome. A better approach would be to use different kfunc id sets for grouping purposes and filtering purposes. scx_kfunc_ids_ops_context_sensitive is a kfunc id set for filtering purposes, which contains all context-sensitive SCX kfuncs and implements filtering rules for different contexts in the filter (by searching the kfunc id sets used for grouping purposes). Now we only need to register scx_kfunc_ids_ops_context_sensitive, no longer need to register multiple context-sensitive kfunc id sets. In addition, this patch adds the SCX_MOFF_IDX macro to facilitate the calculation of idx based on moff. Signed-off-by: Juntong Deng --- kernel/sched/ext.c | 110 ++++++++++++++++++++++++++++++---------- kernel/sched/ext_idle.c | 8 +-- 2 files changed, 83 insertions(+), 35 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 15fac968629e..c337f6206ae5 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -10,6 +10,7 @@ #include "ext_idle.h" #define SCX_OP_IDX(op) (offsetof(struct sched_ext_ops, op) / sizeof(void (*)(void))) +#define SCX_MOFF_IDX(moff) (moff / sizeof(void (*)(void))) enum scx_consts { SCX_DSP_DFL_MAX_BATCH = 32, @@ -6300,11 +6301,6 @@ BTF_ID_FLAGS(func, scx_bpf_dispatch, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_dispatch_vtime, KF_RCU) BTF_KFUNCS_END(scx_kfunc_ids_enqueue_dispatch) -static const struct btf_kfunc_id_set scx_kfunc_set_enqueue_dispatch = { - .owner = THIS_MODULE, - .set = &scx_kfunc_ids_enqueue_dispatch, -}; - static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit, struct task_struct *p, u64 dsq_id, u64 enq_flags) { @@ -6620,11 +6616,6 @@ BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_dispatch_vtime_from_dsq, KF_RCU) BTF_KFUNCS_END(scx_kfunc_ids_dispatch) -static const struct btf_kfunc_id_set scx_kfunc_set_dispatch = { - .owner = THIS_MODULE, - .set = &scx_kfunc_ids_dispatch, -}; - __bpf_kfunc_start_defs(); /** @@ -6687,11 +6678,6 @@ BTF_KFUNCS_START(scx_kfunc_ids_cpu_release) BTF_ID_FLAGS(func, scx_bpf_reenqueue_local) BTF_KFUNCS_END(scx_kfunc_ids_cpu_release) -static const struct btf_kfunc_id_set scx_kfunc_set_cpu_release = { - .owner = THIS_MODULE, - .set = &scx_kfunc_ids_cpu_release, -}; - __bpf_kfunc_start_defs(); /** @@ -6724,11 +6710,6 @@ BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_dispatch_vtime_from_dsq, KF_RCU) BTF_KFUNCS_END(scx_kfunc_ids_unlocked) -static const struct btf_kfunc_id_set scx_kfunc_set_unlocked = { - .owner = THIS_MODULE, - .set = &scx_kfunc_ids_unlocked, -}; - __bpf_kfunc_start_defs(); /** @@ -7370,6 +7351,85 @@ __bpf_kfunc void scx_bpf_events(struct scx_event_stats *events, __bpf_kfunc_end_defs(); +BTF_KFUNCS_START(scx_kfunc_ids_ops_context_sensitive) +/* scx_kfunc_ids_select_cpu */ +BTF_ID_FLAGS(func, scx_bpf_select_cpu_dfl, KF_RCU) +/* scx_kfunc_ids_enqueue_dispatch */ +BTF_ID_FLAGS(func, scx_bpf_dsq_insert, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dsq_insert_vtime, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dispatch, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dispatch_vtime, KF_RCU) +/* scx_kfunc_ids_dispatch */ +BTF_ID_FLAGS(func, scx_bpf_dispatch_nr_slots) +BTF_ID_FLAGS(func, scx_bpf_dispatch_cancel) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_to_local) +BTF_ID_FLAGS(func, scx_bpf_consume) +/* scx_kfunc_ids_cpu_release */ +BTF_ID_FLAGS(func, scx_bpf_reenqueue_local) +/* scx_kfunc_ids_unlocked */ +BTF_ID_FLAGS(func, scx_bpf_create_dsq, KF_SLEEPABLE) +/* Intersection of scx_kfunc_ids_dispatch and scx_kfunc_ids_unlocked */ +BTF_ID_FLAGS(func, scx_bpf_dsq_move_set_slice) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_set_vtime) +BTF_ID_FLAGS(func, scx_bpf_dsq_move, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_vtime, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq_set_slice) +BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq_set_vtime) +BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dispatch_vtime_from_dsq, KF_RCU) +BTF_KFUNCS_END(scx_kfunc_ids_ops_context_sensitive) + +extern struct btf_id_set8 scx_kfunc_ids_select_cpu; + +static int scx_kfunc_ids_ops_context_sensitive_filter(const struct bpf_prog *prog, u32 kfunc_id) +{ + u32 moff, flags; + + if (!btf_id_set8_contains(&scx_kfunc_ids_ops_context_sensitive, kfunc_id)) + return 0; + + if (prog->type == BPF_PROG_TYPE_SYSCALL && + btf_id_set8_contains(&scx_kfunc_ids_unlocked, kfunc_id)) + return 0; + + if (prog->type == BPF_PROG_TYPE_STRUCT_OPS && + prog->aux->st_ops != &bpf_sched_ext_ops) + return 0; + + /* prog->type == BPF_PROG_TYPE_STRUCT_OPS && prog->aux->st_ops == &bpf_sched_ext_ops*/ + + moff = prog->aux->attach_st_ops_member_off; + flags = scx_ops_context_flags[SCX_MOFF_IDX(moff)]; + + if ((flags & SCX_OPS_KF_UNLOCKED) && + btf_id_set8_contains(&scx_kfunc_ids_unlocked, kfunc_id)) + return 0; + + if ((flags & SCX_OPS_KF_CPU_RELEASE) && + btf_id_set8_contains(&scx_kfunc_ids_cpu_release, kfunc_id)) + return 0; + + if ((flags & SCX_OPS_KF_DISPATCH) && + btf_id_set8_contains(&scx_kfunc_ids_dispatch, kfunc_id)) + return 0; + + if ((flags & SCX_OPS_KF_ENQUEUE) && + btf_id_set8_contains(&scx_kfunc_ids_enqueue_dispatch, kfunc_id)) + return 0; + + if ((flags & SCX_OPS_KF_SELECT_CPU) && + btf_id_set8_contains(&scx_kfunc_ids_select_cpu, kfunc_id)) + return 0; + + return -EACCES; +} + +static const struct btf_kfunc_id_set scx_kfunc_set_ops_context_sensitive = { + .owner = THIS_MODULE, + .set = &scx_kfunc_ids_ops_context_sensitive, + .filter = scx_kfunc_ids_ops_context_sensitive_filter, +}; + BTF_KFUNCS_START(scx_kfunc_ids_any) BTF_ID_FLAGS(func, scx_bpf_kick_cpu) BTF_ID_FLAGS(func, scx_bpf_dsq_nr_queued) @@ -7425,15 +7485,9 @@ static int __init scx_init(void) * check using scx_kf_allowed(). */ if ((ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, - &scx_kfunc_set_enqueue_dispatch)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, - &scx_kfunc_set_dispatch)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, - &scx_kfunc_set_cpu_release)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, - &scx_kfunc_set_unlocked)) || + &scx_kfunc_set_ops_context_sensitive)) || (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, - &scx_kfunc_set_unlocked)) || + &scx_kfunc_set_ops_context_sensitive)) || (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &scx_kfunc_set_any)) || (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c index dc40e0baf77c..efb6077810d8 100644 --- a/kernel/sched/ext_idle.c +++ b/kernel/sched/ext_idle.c @@ -1125,17 +1125,11 @@ BTF_KFUNCS_START(scx_kfunc_ids_select_cpu) BTF_ID_FLAGS(func, scx_bpf_select_cpu_dfl, KF_RCU) BTF_KFUNCS_END(scx_kfunc_ids_select_cpu) -static const struct btf_kfunc_id_set scx_kfunc_set_select_cpu = { - .owner = THIS_MODULE, - .set = &scx_kfunc_ids_select_cpu, -}; - int scx_idle_init(void) { int ret; - ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &scx_kfunc_set_select_cpu) || - register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &scx_kfunc_set_idle) || + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &scx_kfunc_set_idle) || register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &scx_kfunc_set_idle) || register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &scx_kfunc_set_idle); From patchwork Wed Feb 26 19:28:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13993077 Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazolkn19013077.outbound.protection.outlook.com [52.103.46.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4068419DF52; Wed, 26 Feb 2025 19:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.46.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598429; cv=fail; b=V1EcffZOw3ZUsH68iwJTsv5FzkOt7GYyU2q/wWvnomsGGeANOSAC8UL0qf3j/7wdgnXD/S6/+rAo7PvYAu3L8xzcuW7eWRVzzQLnQ0KUg1xWtnsSHGHxD/PKFRmk2dZrCI9n2jSk9rMp28i4UAxTw+e0MT0Hm0l3bOgBvsJxKp8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598429; c=relaxed/simple; bh=H2opES8LeX49Q/71BNpOZG8VI4PGaBymS99N49/xAvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=fSI15woptt/MTOnt8VqoRzKySGt6vVoiU+NmZeByhAd46CDWmulAuPuz3g+/Mdg0Y6VqPqCusEE6mC+eFIQcmG2jD/2lpu7VBhUBYfnCLujJrSQx3Dmg4wCYWemhR9t/o8InJx2lDpIAXGDQKUIV5gTeEzYOz3qLwdsr38MAyME= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=i0IQYf9l; arc=fail smtp.client-ip=52.103.46.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="i0IQYf9l" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oc6Cf9nAZF/jwOtQOpNnepdK3gu3CI5G/msLM3qZE+Vo3y1qMl8MzTuLYs01Vq3d5KutpoX+5rLf6poF0RjyCHhKD03zciufvYPWcu4i43JBIQqVq1TqDBjcXxQbdUlH6jIzCNTQfcpNR81wt/78jGXE79iadx9KJjRX/6v5k17UKWlUeca7c1Vs52dayq7iGB4Wa9lig4dinz3n4U9FfMIHNhRO9yVdo6jaes+SgC6DCNC9KG949j3pL7l2VsIkD0dR4rxRVzu5Bst54dLWshiyHpcp8GObvqUi2+0V1IaAZoTU69R01VOW9I/Dp1+qa/BfS3KOAp1q2SEIVJW4DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yCFKNGzgYsEUOAJLCXtQGybtfSgMjpgBNQU7ZYkmGGQ=; b=keB6sGzkAoZX++jsdEliwsGth21NMhm91/ThE0Waju6c2KDFwjPvrAGsQfUWuq5zXsKJspkblCdHOwR+nmN7G1kLBVOcwl4GuOn3+X20E5QIGZma0iAbwGKFS3L3GvpfCNP6o6LDhuccz+zwQl/Hk8q7rBkmtDs8Cv8su4TTjNqBfKdmFw2dBYhI7SaOZE15hdZsYi0LeUDZtntmb9CCoV1jVWB94Axkt6m5OLuQEwBEUtr0YCuPY0hJJwJjAZyo8ec61v+TExNCPpzZoD6W9LcWI3kT1R3pn0opC+Cwgy6uFtmR86G4I+rUrAub63MeqexJflpHut6J74XyiA46yQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yCFKNGzgYsEUOAJLCXtQGybtfSgMjpgBNQU7ZYkmGGQ=; b=i0IQYf9ln9Jvy0dH2BSkirVNmrI56aUX3EUvQh2IYp57ZvElHkueSlQZpbhR5wXjxlv6594UnfVyMu/DZ3ktRTh4OmpbCgR5gXZ0KZtlWp70n+jg6jBw3GbC4LQt0fmoaLX/HZ2S2vm/0D/5o19Wrww9WgTTHrlazsHkM58tS+pMNsPROOwj3puRSsyVnlI3eldmhfIKKPSjSzFHmwN/y+zG3GFZ37GWcfgH+Jca0cvS+M7TGkRUkjc3fuQWpSdDk/+ObGLlyzlirHHPaH/vcwphvXKexSASPZ/jO7Demgd6uyfEUFS4PskaHMtg9bCfPaVohZ8X7+r5JkhTLc9UAA== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by DBBPR03MB7451.eurprd03.prod.outlook.com (2603:10a6:10:20e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.19; Wed, 26 Feb 2025 19:33:43 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%5]) with mapi id 15.20.8466.016; Wed, 26 Feb 2025 19:33:43 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH sched_ext/for-6.15 v3 4/5] sched_ext: Removed mask-based runtime restrictions on calling kfuncs in different contexts Date: Wed, 26 Feb 2025 19:28:19 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0349.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250226192820.156545-4-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|DBBPR03MB7451:EE_ X-MS-Office365-Filtering-Correlation-Id: 843fd18e-ac44-4648-6835-08dd569c7abc X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|12121999004|15080799006|19110799003|8060799006|5072599009|440099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eeiXhIuDDHi4r9lEq05srif/KnwD6VHCfEEQT4lvsYo000n4MUD3Zr3FvveoFO/Lw5bPcGaBmnKIvJ6ufhHx/M8KmybYJ82Q8byXi0rXd2i9Ed17zn57/X9CH+2oM1znGRT6Z/fi4iI/sl5meclLe/vshRFfX81VtFsnteAReGSLfdLRdGX1UGqMXniKst0et4FvL8ficLqQfJh1MzV/03g+Cdk4y+aebeZtbSzYcFvBPlBL+AC2eIM9j7oxP0sgWtu+CECDpbaXsfDsck05jlCIive1IOwSXRxPgFf/H8SuVxzovYqmFJsY+SCIbr7y0AgbSUcH2Z3f0cMe/tQBWyc7KE8OeSpl3YyqtaJks X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 843fd18e-ac44-4648-6835-08dd569c7abc X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2025 19:33:43.3161 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR03MB7451 Currently, kfunc filters already support filtering based on struct_ops context information. The BPF verifier can check context-sensitive kfuncs before the SCX program is run, avoiding runtime overhead. Therefore we no longer need mask-based runtime restrictions. This patch removes the mask-based runtime restrictions. Signed-off-by: Juntong Deng --- include/linux/sched/ext.h | 24 ---- kernel/sched/ext.c | 227 ++++++++------------------------------ kernel/sched/ext_idle.c | 5 +- 3 files changed, 50 insertions(+), 206 deletions(-) diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h index f7545430a548..9980d6b55c84 100644 --- a/include/linux/sched/ext.h +++ b/include/linux/sched/ext.h @@ -96,29 +96,6 @@ enum scx_ent_dsq_flags { SCX_TASK_DSQ_ON_PRIQ = 1 << 0, /* task is queued on the priority queue of a dsq */ }; -/* - * Mask bits for scx_entity.kf_mask. Not all kfuncs can be called from - * everywhere and the following bits track which kfunc sets are currently - * allowed for %current. This simple per-task tracking works because SCX ops - * nest in a limited way. BPF will likely implement a way to allow and disallow - * kfuncs depending on the calling context which will replace this manual - * mechanism. See scx_kf_allow(). - */ -enum scx_kf_mask { - SCX_KF_UNLOCKED = 0, /* sleepable and not rq locked */ - /* ENQUEUE and DISPATCH may be nested inside CPU_RELEASE */ - SCX_KF_CPU_RELEASE = 1 << 0, /* ops.cpu_release() */ - /* ops.dequeue (in REST) may be nested inside DISPATCH */ - SCX_KF_DISPATCH = 1 << 1, /* ops.dispatch() */ - SCX_KF_ENQUEUE = 1 << 2, /* ops.enqueue() and ops.select_cpu() */ - SCX_KF_SELECT_CPU = 1 << 3, /* ops.select_cpu() */ - SCX_KF_REST = 1 << 4, /* other rq-locked operations */ - - __SCX_KF_RQ_LOCKED = SCX_KF_CPU_RELEASE | SCX_KF_DISPATCH | - SCX_KF_ENQUEUE | SCX_KF_SELECT_CPU | SCX_KF_REST, - __SCX_KF_TERMINAL = SCX_KF_ENQUEUE | SCX_KF_SELECT_CPU | SCX_KF_REST, -}; - enum scx_dsq_lnode_flags { SCX_DSQ_LNODE_ITER_CURSOR = 1 << 0, @@ -147,7 +124,6 @@ struct sched_ext_entity { s32 sticky_cpu; s32 holding_cpu; s32 selected_cpu; - u32 kf_mask; /* see scx_kf_mask above */ struct task_struct *kf_tasks[2]; /* see SCX_CALL_OP_TASK() */ atomic_long_t ops_state; diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index c337f6206ae5..7dc5f11be66b 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1115,19 +1115,6 @@ static long jiffies_delta_msecs(unsigned long at, unsigned long now) return -(long)jiffies_to_msecs(now - at); } -/* if the highest set bit is N, return a mask with bits [N+1, 31] set */ -static u32 higher_bits(u32 flags) -{ - return ~((1 << fls(flags)) - 1); -} - -/* return the mask with only the highest bit set */ -static u32 highest_bit(u32 flags) -{ - int bit = fls(flags); - return ((u64)1 << bit) >> 1; -} - static bool u32_before(u32 a, u32 b) { return (s32)(a - b) < 0; @@ -1143,51 +1130,12 @@ static struct scx_dispatch_q *find_user_dsq(u64 dsq_id) return rhashtable_lookup_fast(&dsq_hash, &dsq_id, dsq_hash_params); } -/* - * scx_kf_mask enforcement. Some kfuncs can only be called from specific SCX - * ops. When invoking SCX ops, SCX_CALL_OP[_RET]() should be used to indicate - * the allowed kfuncs and those kfuncs should use scx_kf_allowed() to check - * whether it's running from an allowed context. - * - * @mask is constant, always inline to cull the mask calculations. - */ -static __always_inline void scx_kf_allow(u32 mask) -{ - /* nesting is allowed only in increasing scx_kf_mask order */ - WARN_ONCE((mask | higher_bits(mask)) & current->scx.kf_mask, - "invalid nesting current->scx.kf_mask=0x%x mask=0x%x\n", - current->scx.kf_mask, mask); - current->scx.kf_mask |= mask; - barrier(); -} - -static void scx_kf_disallow(u32 mask) -{ - barrier(); - current->scx.kf_mask &= ~mask; -} - -#define SCX_CALL_OP(mask, op, args...) \ -do { \ - if (mask) { \ - scx_kf_allow(mask); \ - scx_ops.op(args); \ - scx_kf_disallow(mask); \ - } else { \ - scx_ops.op(args); \ - } \ -} while (0) +#define SCX_CALL_OP(op, args...) scx_ops.op(args) -#define SCX_CALL_OP_RET(mask, op, args...) \ +#define SCX_CALL_OP_RET(op, args...) \ ({ \ __typeof__(scx_ops.op(args)) __ret; \ - if (mask) { \ - scx_kf_allow(mask); \ - __ret = scx_ops.op(args); \ - scx_kf_disallow(mask); \ - } else { \ - __ret = scx_ops.op(args); \ - } \ + __ret = scx_ops.op(args); \ __ret; \ }) @@ -1202,74 +1150,36 @@ do { \ * scx_kf_allowed_on_arg_tasks() to test whether the invocation is allowed on * the specific task. */ -#define SCX_CALL_OP_TASK(mask, op, task, args...) \ +#define SCX_CALL_OP_TASK(op, task, args...) \ do { \ - BUILD_BUG_ON((mask) & ~__SCX_KF_TERMINAL); \ current->scx.kf_tasks[0] = task; \ - SCX_CALL_OP(mask, op, task, ##args); \ + SCX_CALL_OP(op, task, ##args); \ current->scx.kf_tasks[0] = NULL; \ } while (0) -#define SCX_CALL_OP_TASK_RET(mask, op, task, args...) \ +#define SCX_CALL_OP_TASK_RET(op, task, args...) \ ({ \ __typeof__(scx_ops.op(task, ##args)) __ret; \ - BUILD_BUG_ON((mask) & ~__SCX_KF_TERMINAL); \ current->scx.kf_tasks[0] = task; \ - __ret = SCX_CALL_OP_RET(mask, op, task, ##args); \ + __ret = SCX_CALL_OP_RET(op, task, ##args); \ current->scx.kf_tasks[0] = NULL; \ __ret; \ }) -#define SCX_CALL_OP_2TASKS_RET(mask, op, task0, task1, args...) \ +#define SCX_CALL_OP_2TASKS_RET(op, task0, task1, args...) \ ({ \ __typeof__(scx_ops.op(task0, task1, ##args)) __ret; \ - BUILD_BUG_ON((mask) & ~__SCX_KF_TERMINAL); \ current->scx.kf_tasks[0] = task0; \ current->scx.kf_tasks[1] = task1; \ - __ret = SCX_CALL_OP_RET(mask, op, task0, task1, ##args); \ + __ret = SCX_CALL_OP_RET(op, task0, task1, ##args); \ current->scx.kf_tasks[0] = NULL; \ current->scx.kf_tasks[1] = NULL; \ __ret; \ }) -/* @mask is constant, always inline to cull unnecessary branches */ -static __always_inline bool scx_kf_allowed(u32 mask) -{ - if (unlikely(!(current->scx.kf_mask & mask))) { - scx_ops_error("kfunc with mask 0x%x called from an operation only allowing 0x%x", - mask, current->scx.kf_mask); - return false; - } - - /* - * Enforce nesting boundaries. e.g. A kfunc which can be called from - * DISPATCH must not be called if we're running DEQUEUE which is nested - * inside ops.dispatch(). We don't need to check boundaries for any - * blocking kfuncs as the verifier ensures they're only called from - * sleepable progs. - */ - if (unlikely(highest_bit(mask) == SCX_KF_CPU_RELEASE && - (current->scx.kf_mask & higher_bits(SCX_KF_CPU_RELEASE)))) { - scx_ops_error("cpu_release kfunc called from a nested operation"); - return false; - } - - if (unlikely(highest_bit(mask) == SCX_KF_DISPATCH && - (current->scx.kf_mask & higher_bits(SCX_KF_DISPATCH)))) { - scx_ops_error("dispatch kfunc called from a nested operation"); - return false; - } - - return true; -} - /* see SCX_CALL_OP_TASK() */ -static __always_inline bool scx_kf_allowed_on_arg_tasks(u32 mask, - struct task_struct *p) +static __always_inline bool scx_kf_allowed_on_arg_tasks(struct task_struct *p) { - if (!scx_kf_allowed(mask)) - return false; - if (unlikely((p != current->scx.kf_tasks[0] && p != current->scx.kf_tasks[1]))) { scx_ops_error("called on a task not being operated on"); @@ -1279,11 +1189,6 @@ static __always_inline bool scx_kf_allowed_on_arg_tasks(u32 mask, return true; } -static bool scx_kf_allowed_if_unlocked(void) -{ - return !current->scx.kf_mask; -} - /** * nldsq_next_task - Iterate to the next task in a non-local DSQ * @dsq: user dsq being iterated @@ -2219,7 +2124,7 @@ static void do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags, WARN_ON_ONCE(*ddsp_taskp); *ddsp_taskp = p; - SCX_CALL_OP_TASK(SCX_KF_ENQUEUE, enqueue, p, enq_flags); + SCX_CALL_OP_TASK(enqueue, p, enq_flags); *ddsp_taskp = NULL; if (p->scx.ddsp_dsq_id != SCX_DSQ_INVALID) @@ -2316,7 +2221,7 @@ static void enqueue_task_scx(struct rq *rq, struct task_struct *p, int enq_flags add_nr_running(rq, 1); if (SCX_HAS_OP(runnable) && !task_on_rq_migrating(p)) - SCX_CALL_OP_TASK(SCX_KF_REST, runnable, p, enq_flags); + SCX_CALL_OP_TASK(runnable, p, enq_flags); if (enq_flags & SCX_ENQ_WAKEUP) touch_core_sched(rq, p); @@ -2351,7 +2256,7 @@ static void ops_dequeue(struct task_struct *p, u64 deq_flags) BUG(); case SCX_OPSS_QUEUED: if (SCX_HAS_OP(dequeue)) - SCX_CALL_OP_TASK(SCX_KF_REST, dequeue, p, deq_flags); + SCX_CALL_OP_TASK(dequeue, p, deq_flags); if (atomic_long_try_cmpxchg(&p->scx.ops_state, &opss, SCX_OPSS_NONE)) @@ -2400,11 +2305,11 @@ static bool dequeue_task_scx(struct rq *rq, struct task_struct *p, int deq_flags */ if (SCX_HAS_OP(stopping) && task_current(rq, p)) { update_curr_scx(rq); - SCX_CALL_OP_TASK(SCX_KF_REST, stopping, p, false); + SCX_CALL_OP_TASK(stopping, p, false); } if (SCX_HAS_OP(quiescent) && !task_on_rq_migrating(p)) - SCX_CALL_OP_TASK(SCX_KF_REST, quiescent, p, deq_flags); + SCX_CALL_OP_TASK(quiescent, p, deq_flags); if (deq_flags & SCX_DEQ_SLEEP) p->scx.flags |= SCX_TASK_DEQD_FOR_SLEEP; @@ -2424,7 +2329,7 @@ static void yield_task_scx(struct rq *rq) struct task_struct *p = rq->curr; if (SCX_HAS_OP(yield)) - SCX_CALL_OP_2TASKS_RET(SCX_KF_REST, yield, p, NULL); + SCX_CALL_OP_2TASKS_RET(yield, p, NULL); else p->scx.slice = 0; } @@ -2434,7 +2339,7 @@ static bool yield_to_task_scx(struct rq *rq, struct task_struct *to) struct task_struct *from = rq->curr; if (SCX_HAS_OP(yield)) - return SCX_CALL_OP_2TASKS_RET(SCX_KF_REST, yield, from, to); + return SCX_CALL_OP_2TASKS_RET(yield, from, to); else return false; } @@ -2992,7 +2897,7 @@ static int balance_one(struct rq *rq, struct task_struct *prev) * emitted in switch_class(). */ if (SCX_HAS_OP(cpu_acquire)) - SCX_CALL_OP(SCX_KF_REST, cpu_acquire, cpu_of(rq), NULL); + SCX_CALL_OP(cpu_acquire, cpu_of(rq), NULL); rq->scx.cpu_released = false; } @@ -3037,8 +2942,7 @@ static int balance_one(struct rq *rq, struct task_struct *prev) do { dspc->nr_tasks = 0; - SCX_CALL_OP(SCX_KF_DISPATCH, dispatch, cpu_of(rq), - prev_on_scx ? prev : NULL); + SCX_CALL_OP(dispatch, cpu_of(rq), prev_on_scx ? prev : NULL); flush_dispatch_buf(rq); @@ -3159,7 +3063,7 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, bool first) /* see dequeue_task_scx() on why we skip when !QUEUED */ if (SCX_HAS_OP(running) && (p->scx.flags & SCX_TASK_QUEUED)) - SCX_CALL_OP_TASK(SCX_KF_REST, running, p); + SCX_CALL_OP_TASK(running, p); clr_task_runnable(p, true); @@ -3240,8 +3144,7 @@ static void switch_class(struct rq *rq, struct task_struct *next) .task = next, }; - SCX_CALL_OP(SCX_KF_CPU_RELEASE, - cpu_release, cpu_of(rq), &args); + SCX_CALL_OP(cpu_release, cpu_of(rq), &args); } rq->scx.cpu_released = true; } @@ -3254,7 +3157,7 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p, /* see dequeue_task_scx() on why we skip when !QUEUED */ if (SCX_HAS_OP(stopping) && (p->scx.flags & SCX_TASK_QUEUED)) - SCX_CALL_OP_TASK(SCX_KF_REST, stopping, p, true); + SCX_CALL_OP_TASK(stopping, p, true); if (p->scx.flags & SCX_TASK_QUEUED) { set_task_runnable(rq, p); @@ -3428,8 +3331,7 @@ static int select_task_rq_scx(struct task_struct *p, int prev_cpu, int wake_flag WARN_ON_ONCE(*ddsp_taskp); *ddsp_taskp = p; - cpu = SCX_CALL_OP_TASK_RET(SCX_KF_ENQUEUE | SCX_KF_SELECT_CPU, - select_cpu, p, prev_cpu, wake_flags); + cpu = SCX_CALL_OP_TASK_RET(select_cpu, p, prev_cpu, wake_flags); p->scx.selected_cpu = cpu; *ddsp_taskp = NULL; if (ops_cpu_valid(cpu, "from ops.select_cpu()")) @@ -3473,8 +3375,7 @@ static void set_cpus_allowed_scx(struct task_struct *p, * designation pointless. Cast it away when calling the operation. */ if (SCX_HAS_OP(set_cpumask)) - SCX_CALL_OP_TASK(SCX_KF_REST, set_cpumask, p, - (struct cpumask *)p->cpus_ptr); + SCX_CALL_OP_TASK(set_cpumask, p, (struct cpumask *)p->cpus_ptr); } static void handle_hotplug(struct rq *rq, bool online) @@ -3487,9 +3388,9 @@ static void handle_hotplug(struct rq *rq, bool online) scx_idle_update_selcpu_topology(&scx_ops); if (online && SCX_HAS_OP(cpu_online)) - SCX_CALL_OP(SCX_KF_UNLOCKED, cpu_online, cpu); + SCX_CALL_OP(cpu_online, cpu); else if (!online && SCX_HAS_OP(cpu_offline)) - SCX_CALL_OP(SCX_KF_UNLOCKED, cpu_offline, cpu); + SCX_CALL_OP(cpu_offline, cpu); else scx_ops_exit(SCX_ECODE_ACT_RESTART | SCX_ECODE_RSN_HOTPLUG, "cpu %d going %s, exiting scheduler", cpu, @@ -3593,7 +3494,7 @@ static void task_tick_scx(struct rq *rq, struct task_struct *curr, int queued) curr->scx.slice = 0; touch_core_sched(rq, curr); } else if (SCX_HAS_OP(tick)) { - SCX_CALL_OP(SCX_KF_REST, tick, curr); + SCX_CALL_OP(tick, curr); } if (!curr->scx.slice) @@ -3670,7 +3571,7 @@ static int scx_ops_init_task(struct task_struct *p, struct task_group *tg, bool .fork = fork, }; - ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, init_task, p, &args); + ret = SCX_CALL_OP_RET(init_task, p, &args); if (unlikely(ret)) { ret = ops_sanitize_err("init_task", ret); return ret; @@ -3727,11 +3628,11 @@ static void scx_ops_enable_task(struct task_struct *p) p->scx.weight = sched_weight_to_cgroup(weight); if (SCX_HAS_OP(enable)) - SCX_CALL_OP_TASK(SCX_KF_REST, enable, p); + SCX_CALL_OP_TASK(enable, p); scx_set_task_state(p, SCX_TASK_ENABLED); if (SCX_HAS_OP(set_weight)) - SCX_CALL_OP_TASK(SCX_KF_REST, set_weight, p, p->scx.weight); + SCX_CALL_OP_TASK(set_weight, p, p->scx.weight); } static void scx_ops_disable_task(struct task_struct *p) @@ -3740,7 +3641,7 @@ static void scx_ops_disable_task(struct task_struct *p) WARN_ON_ONCE(scx_get_task_state(p) != SCX_TASK_ENABLED); if (SCX_HAS_OP(disable)) - SCX_CALL_OP(SCX_KF_REST, disable, p); + SCX_CALL_OP(disable, p); scx_set_task_state(p, SCX_TASK_READY); } @@ -3769,7 +3670,7 @@ static void scx_ops_exit_task(struct task_struct *p) } if (SCX_HAS_OP(exit_task)) - SCX_CALL_OP(SCX_KF_REST, exit_task, p, &args); + SCX_CALL_OP(exit_task, p, &args); scx_set_task_state(p, SCX_TASK_NONE); } @@ -3878,7 +3779,7 @@ static void reweight_task_scx(struct rq *rq, struct task_struct *p, p->scx.weight = sched_weight_to_cgroup(scale_load_down(lw->weight)); if (SCX_HAS_OP(set_weight)) - SCX_CALL_OP_TASK(SCX_KF_REST, set_weight, p, p->scx.weight); + SCX_CALL_OP_TASK(set_weight, p, p->scx.weight); } static void prio_changed_scx(struct rq *rq, struct task_struct *p, int oldprio) @@ -3894,8 +3795,7 @@ static void switching_to_scx(struct rq *rq, struct task_struct *p) * different scheduler class. Keep the BPF scheduler up-to-date. */ if (SCX_HAS_OP(set_cpumask)) - SCX_CALL_OP_TASK(SCX_KF_REST, set_cpumask, p, - (struct cpumask *)p->cpus_ptr); + SCX_CALL_OP_TASK(set_cpumask, p, (struct cpumask *)p->cpus_ptr); } static void switched_from_scx(struct rq *rq, struct task_struct *p) @@ -3987,8 +3887,7 @@ int scx_tg_online(struct task_group *tg) struct scx_cgroup_init_args args = { .weight = tg->scx_weight }; - ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, cgroup_init, - tg->css.cgroup, &args); + ret = SCX_CALL_OP_RET(cgroup_init, tg->css.cgroup, &args); if (ret) ret = ops_sanitize_err("cgroup_init", ret); } @@ -4009,7 +3908,7 @@ void scx_tg_offline(struct task_group *tg) percpu_down_read(&scx_cgroup_rwsem); if (SCX_HAS_OP(cgroup_exit) && (tg->scx_flags & SCX_TG_INITED)) - SCX_CALL_OP(SCX_KF_UNLOCKED, cgroup_exit, tg->css.cgroup); + SCX_CALL_OP(cgroup_exit, tg->css.cgroup); tg->scx_flags &= ~(SCX_TG_ONLINE | SCX_TG_INITED); percpu_up_read(&scx_cgroup_rwsem); @@ -4042,8 +3941,7 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset) continue; if (SCX_HAS_OP(cgroup_prep_move)) { - ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, cgroup_prep_move, - p, from, css->cgroup); + ret = SCX_CALL_OP_RET(cgroup_prep_move, p, from, css->cgroup); if (ret) goto err; } @@ -4056,8 +3954,7 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset) err: cgroup_taskset_for_each(p, css, tset) { if (SCX_HAS_OP(cgroup_cancel_move) && p->scx.cgrp_moving_from) - SCX_CALL_OP(SCX_KF_UNLOCKED, cgroup_cancel_move, p, - p->scx.cgrp_moving_from, css->cgroup); + SCX_CALL_OP(cgroup_cancel_move, p, p->scx.cgrp_moving_from, css->cgroup); p->scx.cgrp_moving_from = NULL; } @@ -4075,8 +3972,7 @@ void scx_cgroup_move_task(struct task_struct *p) * cgrp_moving_from set. */ if (SCX_HAS_OP(cgroup_move) && !WARN_ON_ONCE(!p->scx.cgrp_moving_from)) - SCX_CALL_OP_TASK(SCX_KF_UNLOCKED, cgroup_move, p, - p->scx.cgrp_moving_from, tg_cgrp(task_group(p))); + SCX_CALL_OP_TASK(cgroup_move, p, p->scx.cgrp_moving_from, tg_cgrp(task_group(p))); p->scx.cgrp_moving_from = NULL; } @@ -4095,8 +3991,7 @@ void scx_cgroup_cancel_attach(struct cgroup_taskset *tset) cgroup_taskset_for_each(p, css, tset) { if (SCX_HAS_OP(cgroup_cancel_move) && p->scx.cgrp_moving_from) - SCX_CALL_OP(SCX_KF_UNLOCKED, cgroup_cancel_move, p, - p->scx.cgrp_moving_from, css->cgroup); + SCX_CALL_OP(cgroup_cancel_move, p, p->scx.cgrp_moving_from, css->cgroup); p->scx.cgrp_moving_from = NULL; } out_unlock: @@ -4109,8 +4004,7 @@ void scx_group_set_weight(struct task_group *tg, unsigned long weight) if (scx_cgroup_enabled && tg->scx_weight != weight) { if (SCX_HAS_OP(cgroup_set_weight)) - SCX_CALL_OP(SCX_KF_UNLOCKED, cgroup_set_weight, - tg_cgrp(tg), weight); + SCX_CALL_OP(cgroup_set_weight, tg_cgrp(tg), weight); tg->scx_weight = weight; } @@ -4300,7 +4194,7 @@ static void scx_cgroup_exit(void) continue; rcu_read_unlock(); - SCX_CALL_OP(SCX_KF_UNLOCKED, cgroup_exit, css->cgroup); + SCX_CALL_OP(cgroup_exit, css->cgroup); rcu_read_lock(); css_put(css); @@ -4343,8 +4237,7 @@ static int scx_cgroup_init(void) continue; rcu_read_unlock(); - ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, cgroup_init, - css->cgroup, &args); + ret = SCX_CALL_OP_RET(cgroup_init, css->cgroup, &args); if (ret) { css_put(css); scx_ops_error("ops.cgroup_init() failed (%d)", ret); @@ -4840,7 +4733,7 @@ static void scx_ops_disable_workfn(struct kthread_work *work) } if (scx_ops.exit) - SCX_CALL_OP(SCX_KF_UNLOCKED, exit, ei); + SCX_CALL_OP(exit, ei); cancel_delayed_work_sync(&scx_watchdog_work); @@ -5047,7 +4940,7 @@ static void scx_dump_task(struct seq_buf *s, struct scx_dump_ctx *dctx, if (SCX_HAS_OP(dump_task)) { ops_dump_init(s, " "); - SCX_CALL_OP(SCX_KF_REST, dump_task, dctx, p); + SCX_CALL_OP(dump_task, dctx, p); ops_dump_exit(); } @@ -5094,7 +4987,7 @@ static void scx_dump_state(struct scx_exit_info *ei, size_t dump_len) if (SCX_HAS_OP(dump)) { ops_dump_init(&s, ""); - SCX_CALL_OP(SCX_KF_UNLOCKED, dump, &dctx); + SCX_CALL_OP(dump, &dctx); ops_dump_exit(); } @@ -5151,7 +5044,7 @@ static void scx_dump_state(struct scx_exit_info *ei, size_t dump_len) used = seq_buf_used(&ns); if (SCX_HAS_OP(dump_cpu)) { ops_dump_init(&ns, " "); - SCX_CALL_OP(SCX_KF_REST, dump_cpu, &dctx, cpu, idle); + SCX_CALL_OP(dump_cpu, &dctx, cpu, idle); ops_dump_exit(); } @@ -5405,7 +5298,7 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link) cpus_read_lock(); if (scx_ops.init) { - ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, init); + ret = SCX_CALL_OP_RET(init); if (ret) { ret = ops_sanitize_err("init", ret); cpus_read_unlock(); @@ -6146,9 +6039,6 @@ void __init init_sched_ext_class(void) */ static bool scx_dsq_insert_preamble(struct task_struct *p, u64 enq_flags) { - if (!scx_kf_allowed(SCX_KF_ENQUEUE | SCX_KF_DISPATCH)) - return false; - lockdep_assert_irqs_disabled(); if (unlikely(!p)) { @@ -6310,9 +6200,6 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit, bool in_balance; unsigned long flags; - if (!scx_kf_allowed_if_unlocked() && !scx_kf_allowed(SCX_KF_DISPATCH)) - return false; - /* * Can be called from either ops.dispatch() locking this_rq() or any * context where no rq lock is held. If latter, lock @p's task_rq which @@ -6395,9 +6282,6 @@ __bpf_kfunc_start_defs(); */ __bpf_kfunc u32 scx_bpf_dispatch_nr_slots(void) { - if (!scx_kf_allowed(SCX_KF_DISPATCH)) - return 0; - return scx_dsp_max_batch - __this_cpu_read(scx_dsp_ctx->cursor); } @@ -6411,9 +6295,6 @@ __bpf_kfunc void scx_bpf_dispatch_cancel(void) { struct scx_dsp_ctx *dspc = this_cpu_ptr(scx_dsp_ctx); - if (!scx_kf_allowed(SCX_KF_DISPATCH)) - return; - if (dspc->cursor > 0) dspc->cursor--; else @@ -6439,9 +6320,6 @@ __bpf_kfunc bool scx_bpf_dsq_move_to_local(u64 dsq_id) struct scx_dsp_ctx *dspc = this_cpu_ptr(scx_dsp_ctx); struct scx_dispatch_q *dsq; - if (!scx_kf_allowed(SCX_KF_DISPATCH)) - return false; - flush_dispatch_buf(dspc->rq); dsq = find_user_dsq(dsq_id); @@ -6632,9 +6510,6 @@ __bpf_kfunc u32 scx_bpf_reenqueue_local(void) struct rq *rq; struct task_struct *p, *n; - if (!scx_kf_allowed(SCX_KF_CPU_RELEASE)) - return 0; - rq = cpu_rq(smp_processor_id()); lockdep_assert_rq_held(rq); @@ -7239,7 +7114,7 @@ __bpf_kfunc struct cgroup *scx_bpf_task_cgroup(struct task_struct *p) struct task_group *tg = p->sched_task_group; struct cgroup *cgrp = &cgrp_dfl_root.cgrp; - if (!scx_kf_allowed_on_arg_tasks(__SCX_KF_RQ_LOCKED, p)) + if (!scx_kf_allowed_on_arg_tasks(p)) goto out; cgrp = tg_cgrp(tg); @@ -7479,10 +7354,6 @@ static int __init scx_init(void) * * Some kfuncs are context-sensitive and can only be called from * specific SCX ops. They are grouped into BTF sets accordingly. - * Unfortunately, BPF currently doesn't have a way of enforcing such - * restrictions. Eventually, the verifier should be able to enforce - * them. For now, register them the same and make each kfunc explicitly - * check using scx_kf_allowed(). */ if ((ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &scx_kfunc_set_ops_context_sensitive)) || diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c index efb6077810d8..e241935021eb 100644 --- a/kernel/sched/ext_idle.c +++ b/kernel/sched/ext_idle.c @@ -658,7 +658,7 @@ void __scx_update_idle(struct rq *rq, bool idle, bool do_notify) * managed by put_prev_task_idle()/set_next_task_idle(). */ if (SCX_HAS_OP(update_idle) && do_notify && !scx_rq_bypassing(rq)) - SCX_CALL_OP(SCX_KF_REST, update_idle, cpu_of(rq), idle); + SCX_CALL_OP(update_idle, cpu_of(rq), idle); /* * Update the idle masks: @@ -803,9 +803,6 @@ __bpf_kfunc s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, if (!check_builtin_idle_enabled()) goto prev_cpu; - if (!scx_kf_allowed(SCX_KF_SELECT_CPU)) - goto prev_cpu; - #ifdef CONFIG_SMP return scx_select_cpu_dfl(p, prev_cpu, wake_flags, is_idle); #endif From patchwork Wed Feb 26 19:28:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13993078 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazolkn19011077.outbound.protection.outlook.com [52.103.32.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EF23238D2F; Wed, 26 Feb 2025 19:34:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.32.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598477; cv=fail; b=T2bJDc8FX7hqAcBP07XYGdFrXOxZyTopRGnIjLDcoo138GG4ums1MzRmhz1ebcxPXdEIOna/KOxSiis5gMS4FbASUfrpESdNLbEVYfSl4VkXSDlSrEKyjsaO7RXGiQPwDXd1snjxtJiFl+2xHDlh29R/apJvw8/qHCBUMdqhvOM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740598477; c=relaxed/simple; bh=ACOFdcjyzEMrrUEVtj8xsPuWQ6feABuf35kwC4CSxHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=JIuH69VL9u4dfiSNmQESb6KNpkXpQ3ASgqVD33wLdr+lMM7ocRwIvBE+Mc1EWqOO2Ul04OV7/19pN33WDYhB89RRGfO59rW1+yvTbAD4vVKe/CtzrdehJ/pIxDtJ9bRLTi2slNcfQBodzEg/+sNIw87bEADa3K2WqrDhs0DN4yI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=I5dNNmTd; arc=fail smtp.client-ip=52.103.32.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="I5dNNmTd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MsYMDFX0JD8++LSybR0w/tKbpUdnzt1rbQY+XG1S7PdeY66GEEJa0Ictj8f6I3NVBcn0gk0WHSUW/7lNMqOHn7duXAzcoax2yhK3GOaoomtgyVKQhbMVK+gRzehm7U01vRw6I4U3OugXOqlvFNZV04xfM+bhyUU8r/fbFdpUE9iuU6jqgtNsp8/Ud+2vti4QgRg0dIxPwrym2+TgUHr97hDFN0xV/ii47e7prhKfxdVL2YEHrG1U7whMm1Y5AOS+Kl1w37jnFZpIJ+ulgjQ1ao4L3M336acgyJVUQXpMie43sg/SRplrkTaIf4iorkNiU7yXwWZHrBOynJnbDi8gVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vFkNWT9qi7ZMq+d4X59uKo9TPr7WcNyc1CNt4P36duA=; b=LOpanNnLwm76m8A3PP/ARFbLk8Zsdkhp9Zu569ST9CYjLzBxrVs9B9kKZ13NYtCxeqkmxVccGrBAApKoz75Ro3uWfXYK8pF63b3oBrUccnveJDhfLAuUOhRlBtaAoG7n791LngoZcc7bnfRL3tHE1eWMNJ7xKkqxsXweVVCsbn/0dWyn6WFCULMsZ8uEBRqht+Yrrsq97pkt11jtHX9CXCTLRmgyantMug/Jx7Pc+H+3hOMk10WApdYBc9Al3LqEMSw73aXH5HNpVffgPPWU/HdCpZRRQyoZH2MGc15J9+xxRqUYbejQvmPfad0FFux67kSqqOokjVlM7PHRUgycVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vFkNWT9qi7ZMq+d4X59uKo9TPr7WcNyc1CNt4P36duA=; b=I5dNNmTdIC18qBiYF7G4lpleDQiJr6yqojRHtcPxZAF8BlWkSFoApdhJ7bR5xqbnxKpeQsDWuf89pMHzysnEfQC5jDwxBC59TFNJ4zBmQ9NRGNwAkvkC+FgENiffLE1ChxCtdChic/nypnBw4gaGNjuJaEz2XXEJ9vhoMBYwI8+/9dsaAgZeNp+GAZT0dZ1be5RKvq5VkkGVcDJ6wPCVXaNNIhz3MavzY4eXYylUH0f6l68Zudx6XMA7gGced7MptZtCdKbSDyAWwwnrV0P426fWSdOeYCPdWBTdtq3BICq25BIEAuUJjfJXK1RPUqDImz69eGtplrg4z4FnL8rSCg== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by DBBPR03MB7451.eurprd03.prod.outlook.com (2603:10a6:10:20e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.19; Wed, 26 Feb 2025 19:34:31 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%5]) with mapi id 15.20.8466.016; Wed, 26 Feb 2025 19:34:31 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH sched_ext/for-6.15 v3 5/5] selftests/sched_ext: Update enq_select_cpu_fails to adapt to struct_ops context filter Date: Wed, 26 Feb 2025 19:28:20 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0349.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250226192820.156545-5-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|DBBPR03MB7451:EE_ X-MS-Office365-Filtering-Correlation-Id: 47ee319f-607e-4f5e-11cb-08dd569c97a9 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|15080799006|19110799003|8060799006|5072599009|440099028|3412199025|21061999003|41001999003|12071999003; X-Microsoft-Antispam-Message-Info: OLVLa2/MSIDJo/L7uSQ418vgWT6lbHDzJIHObDR/1zu5k2CpOXb0DlNZSXDp2nyWVpSlaMoz7u9bc5EvTMMzmV6uhbjSDJdIbpXYrZ9MG0v/D8TgYhQk0DeWGy9lgpSMnvBRX/yna1EC+G8c3Jd3uCE6s8BmmTx3qnqXomYRTg5Wrp+ZvaL9OipWlJIgZnHMwvUDIJ/R82Stjsw+Dqo8hVstgzWSLOlbVvP1jRaFoLDXk+RlvGrbAELFhv5u8ZwwyutVYEwqh0ATlZ21zxwxbneUi7srM+QksWY3poLqheNGGAWCJMhFCpktxtUR10kH7wNqMPh28GhVluVRcO/VnLeCRU8Pah+eNeUl69deLe/DzT/BRrn94eBgIPXT6zaJztkIVCdpwiHmqqOlhWabNGr0SesouBdJg1J8btwR4Tp7zyJmaL1EzIbiyTqXPpF277QClSsNgCahkduRSekQNh7TkACq5hZpRy0jfyQevVwI1f0PUFZzhv66wjkw5M152gKPcqKdR4MiW1OLw4+Fc8jrK8zJ6232Ie0MPk2PTHukF1MT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TrXTcSiOjVGtPq1Xp7b+f8ulfQ3ATZ4oq2YSIcTh2WuU0DeVM1pVYEndgcpYrRAFpELIABPd1Bd8a8NkpUaqNhjtzYfo21Z/MKGQAFqqOmYyxWavKPs3pSG0F4yjWB922x93loRfcMKS8Rai91rgIWOksDjf6GYYN8BLL7S0F52QT8v8xK2qQ6ruMhe4VNExODKaOosR464D8yyDj+i92yT8u0O+ldTi4w9i1qerFgRDo6wFjNqeJUOn7BC71EckY7IcFTqAi8D9Hbhh/pUgMN4Z65jwBK+S6r+KXHAjoapxeDk+ha2lr9b20+3aZG1U0x3xFUjft5DJAIm/iIlOO9t1XyH6kgyeMuQpyqbItAOHUxvKJqdj/zmO11FMzoQhfF9sZQbXY+7EHO06nleizpj1Q+IDS21zgGOb8KV1NHDt+MornqMuXzbL9eeaIkCFN0dGlRFbSLK60JdoUp1YuN7kl/xSulcin71WWsxHJSp0grIqYhbe6td434Alshrk/OJJDSLxpxh+QtLJ/KsQvHTLbGVikT4vAPskGspFiG/2KUh5FaWUmEKrfNIlKWzHyGpXyiknm/yR3T0ByvPlI8zo+3h71GtqJhvZqrB/xlG5qt6JAVnAHdq4tp5AqqCOXCLtPGgN3C1lhz32uGWp62f6ejxP/5qZ7nbmmWJD/26oLG0CWiOEL2DUSdegdDS4Z4VTXdnDSIyuSb6yj6JFFFUePVgYB02XXmt1XPn9MhGkFeyP4UBefIlyvpD2cWuvs1OxJ1Nj9aT4REhzBdXkyVAYkI0Bj7z2+zVWpMf9cSvlx0flexcWVTaNNILxhBNcivsKynvpsARq3laDNpBZW0HJakvxduQzCT2fPb X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 47ee319f-607e-4f5e-11cb-08dd569c97a9 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2025 19:34:31.8208 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR03MB7451 After kfunc filters support struct_ops context information, SCX programs that call incorrect context-sensitive kfuncs will fail to load. This patch updates the enq_select_cpu_fails test case to adapt to the failed load situation. Signed-off-by: Juntong Deng --- .../sched_ext/enq_select_cpu_fails.c | 37 +++---------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/tools/testing/selftests/sched_ext/enq_select_cpu_fails.c b/tools/testing/selftests/sched_ext/enq_select_cpu_fails.c index a80e3a3b3698..a04ad9a48a8f 100644 --- a/tools/testing/selftests/sched_ext/enq_select_cpu_fails.c +++ b/tools/testing/selftests/sched_ext/enq_select_cpu_fails.c @@ -11,51 +11,24 @@ #include "enq_select_cpu_fails.bpf.skel.h" #include "scx_test.h" -static enum scx_test_status setup(void **ctx) -{ - struct enq_select_cpu_fails *skel; - - skel = enq_select_cpu_fails__open(); - SCX_FAIL_IF(!skel, "Failed to open"); - SCX_ENUM_INIT(skel); - SCX_FAIL_IF(enq_select_cpu_fails__load(skel), "Failed to load skel"); - - *ctx = skel; - - return SCX_TEST_PASS; -} - static enum scx_test_status run(void *ctx) { - struct enq_select_cpu_fails *skel = ctx; - struct bpf_link *link; + struct enq_select_cpu_fails *skel; - link = bpf_map__attach_struct_ops(skel->maps.enq_select_cpu_fails_ops); - if (!link) { - SCX_ERR("Failed to attach scheduler"); + skel = enq_select_cpu_fails__open_and_load(); + if (skel) { + enq_select_cpu_fails__destroy(skel); + SCX_ERR("This program should fail to load"); return SCX_TEST_FAIL; } - sleep(1); - - bpf_link__destroy(link); - return SCX_TEST_PASS; } -static void cleanup(void *ctx) -{ - struct enq_select_cpu_fails *skel = ctx; - - enq_select_cpu_fails__destroy(skel); -} - struct scx_test enq_select_cpu_fails = { .name = "enq_select_cpu_fails", .description = "Verify we fail to call scx_bpf_select_cpu_dfl() " "from ops.enqueue()", - .setup = setup, .run = run, - .cleanup = cleanup, }; REGISTER_SCX_TEST(&enq_select_cpu_fails)