From patchwork Fri Feb 14 20:09:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13975575 X-Patchwork-Delegate: bpf@iogearbox.net 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 9B07B1519AB; Fri, 14 Feb 2025 20:11:03 +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=1739563865; cv=fail; b=nKG+i0Dv1rj0miB/j5lYPWqr3Od7GZbqTsu3+vgR4x7cbu/o1sG+L8Kx6faXHj8bn8pagsa3L9kQlZ9dsAnV2U5rnaUfcFMhKip+EqFdT8hmFwevCy5k7ryg5ORhGzq5d3s6F/a0ilV8CPjDxefRi1bcuG/J8bAfJFGeIbOr690= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739563865; c=relaxed/simple; bh=xktCERVD5xDs4DnaIra1BMqHrMLfwVEyc+m63Zblc5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=NHjKSLkBX6BX8a0519ga2ssJFvdzH7nnUm+WDQYs43i39uXeEbTP2kC2RfRqhB/BQ+4YmEIGqRvmLpI3kiZO9JaREHpxHVsUiAa1giNkHZLMV6KOl+NPf28kDnGPb193055hbkAMOaDJCfGAUfSySQ5rOJyWayr0UeYLCShmmsM= 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=gRUERPLA; 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="gRUERPLA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pWSFjkpBhxKw0lckH8Ljwr6WJGYPe45tlgeHOCLa9IImrYCg6MupWFvDNuyDOE1WX2hOhDDKWzuVGvTB1tfWQNs/vwC0/99yUYOHkWh4ZiW44f89Ld01i1npRVbCr6ij+K+w6c6rw9lkNJBp7fqfiOZRRWT+SfBFLipbdSuWcLLrh9LbylmNcIjp+ZXaFxjNmGCWUwCs0oQFrGOZX0B8wEU6MbBp7Kg1owZliRGyDvrrTipkAjo4Jdp8SjrSYH5RGeXn9Tx/87JSRjKN/OBjglbWiyg1OYIIuSx/oYCNEmzbH7lYDkAmBMkJRYbxg0Uku7XFTn1PrJk98WF/dPzmsg== 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=qrsSAPEZMK7IeTUEHHx8wwr+wt9kOHcl7NyA1AgY888=; b=jeEhl1XEBKCWfCfupGVpRKVw2Ig1coUeji0iNAWbjv/NdC6fTBH/zdzyrWwnYOjdbvAWu8OeY3uh0RUZuCMfmb6SmrT4a3LcxkcRocFhci3eQPCTRxueRhV5aEvqSlszpLfkpglbJeu+dXm8nK5/N3wnVTWkfCdmonl8Uh18k+K1pcOomY7VP7jr26VXHbknyR3zHkerTJw957D9aSceMjBs1PlxaGZIMpXJrK0FnQhADv8dYcxBVWw5UElFomYcqZ206rPaNMXrkBinzH8IdRfSgSRDeDGPEM6v7DQJORc0cNqjDZQKG3jenyjq1dtB/15FCq8PLE3JzLf5oI3FjQ== 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=qrsSAPEZMK7IeTUEHHx8wwr+wt9kOHcl7NyA1AgY888=; b=gRUERPLAZSGvNKR+43yfHgo+nuj6xi4+yklmKwn2keMy4EVY/yOdy5xStjC3FvaG4+BumEYL6eKiySbQPu1hmvHtWbM9WZoJfobgwfjwJ8CIZecQZvCHf5IUZOA5boiX212I87GhsH351dnY+E2bi60utBS7dgSDvYdp0Aa9s8tW4juFqqyX08eu2fL8mknsMgBzlZU+MhPKOFGuD3avebdBXnJ4QRzXBRVv1qxh0I3pxgZvVdmpp3zFQhJtRKaTXtplRTI4Aa/v0jxRbB7wu/TaTQwA1W5Gv4nzfPwZOEYP/ZeVtmf5E90gfoPSMNxlGsp1AxRqSpMl5iYR92YyiQ== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS2PR03MB9931.eurprd03.prod.outlook.com (2603:10a6:20b:643::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.13; Fri, 14 Feb 2025 20:11:00 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%4]) with mapi id 15.20.8445.016; Fri, 14 Feb 2025 20:10:55 +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: [RFC PATCH bpf-next v2 1/5] bpf: Add struct_ops context information to struct bpf_prog_aux Date: Fri, 14 Feb 2025 20:09:25 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0277.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:195::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250214200929.190827-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_|AS2PR03MB9931:EE_ X-MS-Office365-Filtering-Correlation-Id: 6904d567-fe07-404a-1ff6-08dd4d33afe3 X-Microsoft-Antispam: BCL:0;ARA:14566002|5072599009|19110799003|461199028|15080799006|8060799006|3412199025|440099028|41001999003; X-Microsoft-Antispam-Message-Info: NusUOBO7/JaUWe9EV9QeE7OiYogRKW/312vQv9XkIeGDxFxq+y6WikvD0FSve6RmoeTbnHyybt9sWZEsPCEO2dh8fR6wjwqmu05EV8ooEwiy2YjXtpBcdGuOYE3xTDB6Tu2hC4+coAiQhAeshm7HWm4L0y3wft4ZH4lr2vEtXwr6DqMNdQWmpMNVpBt364U/b0YqPUOn7BnyLsr0Vzrkuoc7MHSorGzsmMlCMFHAg+YcnR1x4oimcOzMLGNRyxqRvpLVU3SYLtT+K/Qxf0HWPMhrao/M1bNOzv84UUqf6vRgZX96lmNm7chmBaiMWU7VFG5v2uRIrgIAmbUcYqrkOjivo2MZOFBT3U/GhEQgIPFLcl/kKtuWDeJcsU42lf/yfonVbR4YJVwRZdw/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2hWp6eoUixIBwmlvMNuy09h4kNEX2DjsY9CEaafTxO1INSZ5NfQnp7IHyc4oJbmjYxTGGIRaqYMI9GPFuDgpDbxbfcv2ANAmybc1IfB81f/GCoXTo7V28CP78jE9+VW/XaTfO8vblRygHzi3jz5dcW+wW98Tp8kieRp9XJx7gSKyIbB2QNQF3IRvNlCtm5xz9iv3SHbvtc/+arG2rPRAhWGhDpjdYK3ChejSUcMl1mtpnnukVTqzW26HfTCVxPdDJAk2q4Lp+Ahq8hHG4ROTlj95tlgL9di8k9VtRicZqLEUJqTy5gslV/T1KyhouS++HhqJMRUUg9oTPz8urN77yo0s5NIFzA4qd0h5cDS+Zg21PI9nKxOIT92lt6dObf7R+VuaAzMe0swHDMhWgez/VeluhK6j7xNVLf1DcPWg0D8KJHoKEJagl1Zb+jKYKBtuu559DHxJq6kajMeTraVUrCM1sJWDaZWLuNDjAb6BQvozxVPuoT/3Yr3Q8OtEmkIhatUYkV/kJ8atm1OPIVAhfBZeQko0toUTYEh1efQM2WwbmnO0pjBjremHl2PFYSBA5cwaP/p4VmYQ9Zh3zej02A3B/YmoV7Eat1KMcUmUE2K9AKiVdlAw/CosvHGM7RK24h9fT+ulVWW2985beDALRFhxxQafQqTYNmPcQv3xn2Vze89ksrBhrxZuluU73TbyzaKPKDqTeSbrfhngNHpoTKU8ttsaLawrim52Zd6Znnad8Bdr9XiMknXhi7cEv4o0T9UMNqMJGsQ5BfBn5lGbOINd0CInREgqRdrMvoDLF+WlKdjeJ1LmoIdOvnwBrOGFPjIlEkLzP+LHCLyXOOI/aZOUkNcdJsfFfOtZjz0Jru2WepKUZ6L4o2bHWpw9CZ+EVOoEbmngcoKkBr85kEZudfO70zphJ4U5toj8chiklSozTv4BNSMAVi7xbutN9HIhtaB578aERZ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6904d567-fe07-404a-1ff6-08dd4d33afe3 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2025 20:10:54.9999 (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: AS2PR03MB9931 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC 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 --- 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 Fri Feb 14 20:09:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13975576 X-Patchwork-Delegate: bpf@iogearbox.net Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazolkn19011029.outbound.protection.outlook.com [52.103.33.29]) (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 33C9B19259E; Fri, 14 Feb 2025 20:11:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.33.29 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739563920; cv=fail; b=DbxJlsK+35gZIzOrAPeZ8Zr6rAb+1nA3NjNyRtzawaGZqeemhHcte8bgv196Bp6EyBaOrmPyAn7oH67ABqKPochZFm97JaKWeTkm5T/Oqh0yDcbkSNSvn7t542sbr9xL8KwiHfA8yXd39xF+qXXnu5jjw7mvk0vOg/D6gQ6NLB8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739563920; c=relaxed/simple; bh=Z1LsCqTZaU1DcBqugsUpvKbcJnWQp5ZI16LeJ3p/r6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=IQTOQNA1qY4WWXyTE/FcQj410SFZE72tSLxse8e+AWMws8q6HwcT1dYvEQTLvC7wR2a772v1Yqsp0OjeEDg4IBFLgU47MYObkL7Logw0Io5+e3YnOjt8Zq3YOtLpR5E/pokfUzxa6R4PvD344gN7yIZHvUzRBkmXPZVKQTm1EnA= 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=j24j73iM; arc=fail smtp.client-ip=52.103.33.29 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="j24j73iM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cNmgzCXHlRwkEg2eqcdvYM3aJv1ZXjrUM91kToxZhSaI2Qo34QFc6tMwaScjb4wsqVBI9rTcskC3l4ilLA3Wo8jYJ0vmAVOVzYRaSDCJ8Y8ETe+IluRG7n/TwfbrPryzzN1mcuUPSK4RkSvAbjCTxQdv48z2sHfkuKLxpPRFYBndikzK9sBRskACMQK1OuIior/t7rAdEPOuAOfJc779al6GiCTx4cbYthdPD5ALVTqSynFu371ad+Bp+2gPTuqkrY5uiunFdhDKalEUZQ9+0RNljjmUWiLhOEclcD0VE+yzD+eL3wEWjcUmh9wjk5XikytOTwtGLiaps1Znw1GxZg== 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=OgVgrpxT8wpzN7jUhAp4RbhCDAbVsuOjanWmXLLoCKM=; b=futwx/gYXZ4BfG9VVzEVKsvkZFFtU4SsxH1xOj4hrceA9Q3+uowG4SYu1YLrd1kWBJUetF1q065rfaRT7p8hTw29JbBPOt7k5bA7/8QBP2CBpzRPzczCTwDshMliMGCDRf9H09MOt0Z1Cm8ayMexQUhDFD/o9uO3oDi7uiDudJSpsJ0rFP9J7Ammr7FXhHS3Y8pp2qOzeqqrcbsQDLXPGzW5YMLMHUYzXkbIAPxMI6iyfT94l15pUDfWUg8xd8MFz2AqzT2mlFQKPci2T39gjp7WpM9E6thufe1YCxNqAD4tavgBRZlU4bkz0k1L4m1IjdA230DWDe4d5BjOMIoC3A== 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=OgVgrpxT8wpzN7jUhAp4RbhCDAbVsuOjanWmXLLoCKM=; b=j24j73iM8meCjETL8ZPRZMTR2PGfpWZnrhOF4d92YROFctg3NakJsbKs4n2FazjvjdMKivmHVNNQAH7gCOqKftzWPXs7krcIpvk83iXR8mvaklg2qAcievGYlhuS+1FQK5TtYDK+f6sgR+4wZFLTIbq1xiTF1E8ZlxkSU9wnktW9Du38JyM/03hyeB97rwikxoGz7OoKYlzSbxFuz6de4fJzMt5ZoKO35CF0YqkkWJuwwomy5AYWrICf8EPv2d/uDmhi76gf7yzF8oh2pQ2e/V5P3MaiS/7z5ENi9wVksWUEQFVSDWZzo1vTq84Ie+QwyHZf5bPYLAcOT/BVs89uHg== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS2PR03MB9931.eurprd03.prod.outlook.com (2603:10a6:20b:643::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.13; Fri, 14 Feb 2025 20:11:56 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%4]) with mapi id 15.20.8445.016; Fri, 14 Feb 2025 20:11:55 +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: [RFC PATCH bpf-next v2 2/5] sched_ext: Declare context-sensitive kfunc groups that can be used by different SCX operations Date: Fri, 14 Feb 2025 20:09:26 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0277.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:195::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250214200929.190827-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_|AS2PR03MB9931:EE_ X-MS-Office365-Filtering-Correlation-Id: 031fd8ff-a139-4156-5cdb-08dd4d33d44b X-Microsoft-Antispam: BCL:0;ARA:14566002|5072599009|19110799003|461199028|15080799006|8060799006|3412199025|13041999003|440099028; X-Microsoft-Antispam-Message-Info: BTBGdMseaopMrUlp4murC3+z65A8IVOdZTCH5xY3yzUHni3j/IdWLQMlh5cCnUEvztfXN398fCp6mocQYrHLbjSS6BiPYNJzuW7/rYrAmLTcbNddcYdfbi4CZXcM58TGNi9Q8A+p08xZ37e8tJZIByBY+7vItChu3MOp+cB88tS0w7hKFHA0Zinin0QX9MGT8Fq0xF/Tk93kWgJuZlEgfPkRkdqZWze3U5LlwnCc/TAN0X+tBbPtHaNyeqcVpJZhSaEjRDq/sghif9vgJSB6akpkax884EZX2XC8VWdXWEHS6mUeAZgGE5OPc34r4zHrd8LtNe7rCWTgsezCPcKDYzb9sF/Ufe/p0ukKuGtbjmmbJmOheK0D9+tGfc8fr/xO9vnFbYfdqslJm7zb94EMO0BZ5jDUz1UPIgsJZMbCkPDi+TRQdgugx4izOfvMY7ikLgFQEXoSaUlWf86cFKprMA6vgx/wPEoDwWd7VGi2NRduYIBSFOASAJilQCD3UkH/Hyj4XgrtACIDJGiqNlpNFXYlPL1fdKnaxL/7Ufjdrj4t+Kglj8U4a6fjsVhFuC5hZYnQ92bP56OmW3Gg5GORd96q4PQ4pUfYBQf5z8fhYbn8VgZeAy7aO9WgUciW5dwo5pWR6knTXXtUqO7xktOel7vMru/kgawF4ZoIZCexmkw0n4jzG66FegPTbYMF8K1tgWPnbRkZKhhFLIrBdziqWwudv4RA1D+/JrKkUr3sBRa1H76KHOlviJUszkjDYW+y/wkcl1k4i5EPKSmPqelFWo6TDLjG1UqNxabAeJIkn6PkPtW+mArE2Y0AmNs+pjcyyY7HXKfOQo6jCYqV3uiy12a6++FeUdyR2vPSAoxbtIHCrGj9tAkzZacuIMDAIK8C0jNnhaP4Bk+GiXE8I5M4X9ZLrVFujRLt7heaRhlqwR3C7f7TUS2NvaiEB8iipJqp4vxiBItiMBbFGXiaoom5zjtmv2LrCzCPrjOvNMWE7WqDD27cOvgqIdYGjjMKCbTdqOyo+zlU2G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UgBhSeoYOYw1Wa4XZx8srRiPB9ypCEmgMygtJlmq09JobTpiZwhZ+cIqoZqa5rNooHE7N8NWNvEsP5qIWw2q/GaSNJgj5SbTjbsR0VRmBzcUPqt/Yt9AWbdYvJUmhnbZRIjBQ1yrVfszCbQ7Tk3FPzbEyHG6TCGBrcXX+Z12ZpM0+UiMF4+0LzeYzcD9QLx3BXrB0pqTRsMfF3hU23BCm3LSczPMIlp7j8rLhUM8EFbfXDxCp4DGMyU+Xlszo/uZbrckE7ZT0FQ0DL5nUykjtWifj0K05TANYrN52vm5y2xI1yKML4HnKAZFJwdgdk3MtjHhSnZNLLudHIxOwF+ZG/qDnM X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 031fd8ff-a139-4156-5cdb-08dd4d33d44b X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2025 20:11:55.9115 (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: AS2PR03MB9931 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC 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 8857c0709bdd..957a125b129f 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -689,6 +689,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 Fri Feb 14 20:09:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13975577 X-Patchwork-Delegate: bpf@iogearbox.net Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazolkn19011032.outbound.protection.outlook.com [52.103.33.32]) (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 1BFDC1519AB; Fri, 14 Feb 2025 20:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.33.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739564001; cv=fail; b=XqLXuD+vxsZ4A5DcVQg9hvLO0sm/fUgeLMaMM4PrdrJ3TDbfRBMvYuwn0/9i1unV6KdOmrVHmsWuWpMSFs07oOOoO9xJdAnNR2GmxA2Q61I8kJRhQ4A9CdVEM2WeIKxPm1frnwc38YMJXPGgvlZkv5M8oWIpof6rTgnyoRqQ/Xw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739564001; c=relaxed/simple; bh=0e8xQRHW3DcdTEoz3jvxqKrMWf9PuR4t00eCPxc/T8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=aL19tXCCKvKjJ63pqCYUSXp5i4PrPzfCYnSgc2rkqRakjokwvfaWTju5sTZC8p3FhI1g7EoSGH6Y9zJrtxHO7Nd/vO1ZOtEEHFmBNOM5Y8T5Fst09zngHh0JBS+h60vHvvXKjc6w5hHCtMAvYT9i58OJyxo84wEnCsO4VQ/tkcs= 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=cD6pF8Ap; arc=fail smtp.client-ip=52.103.33.32 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="cD6pF8Ap" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JymqPghAsN9Xe0LTiFY3Jqe7NjijzJsB5I151+2v2lmxPCup0x1SbaE2itAIjpqeW8pGiksPEmabXAcZ7+XIvTPQWphHZl3Tc14dwM0oavXwFcirrNTBb+YNXMi0S/OQcoHOGcT0N3O0K14wUwrFZooOnrzAoQg0i/4mUchjs6po2YqNVzv/7iMVmP5/Z3nkSSXzZ6o/GnFOOvvU1jiqdowoW7L9k1CVWh/x7+ef0dFHK/c/BGAqlgnYUCsFu/9Yd6yZ476ymiGGkJw0ZLeyxZqqniVXHYguXYlI2dCq/4MQl/XY4SP0beRDUq52zkpo8flX3v9A51MdHdr08X5VsQ== 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=X8RzG6hNBPzT3DnO5qeDp85e0CBrvieEIAVWu+qcCfs=; b=kHndJAE91pve7wZBPnUb3nt8zMuwDr4B+8PoxHiqXo0EVDZsesiRom8YKDw2feNy/jgxZYoY3m/8lnLbLb7EMCc9KvUofFX91/C3/mSXq7gfOji7TLfKnCKaPKiA2n4rs1pYOMBCyxZXmIS8wt/epOcWGnFJTQoYkWlNG6NN4g4pych4VSZ/2CC6Gc9vBlM/6PnFVPOT+vNktkrVwBJQ6rzsXM2M+1p5lOjtCI/3duZZoh1Ikb227aAXIlvJKtqIecq+KLlo8KLqpnXWWSDf2qun4WQ1AANkpYOCnXiBKfwKB51PPlHIgezV2xPr9QNmqzeYKcEKU2cn7uUxdzbv8g== 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=X8RzG6hNBPzT3DnO5qeDp85e0CBrvieEIAVWu+qcCfs=; b=cD6pF8Ap69bAw6Om3+ZfPFOe4NlUvmeUy3AIwW9ISa1PHiG/Yre6leXTjZOAGYVMibQ4sSxCXsTMxsG40t4HlmDvJFEyuXy8RU+7v8jBhIRWWM49DG0HD5XNaXD9zbVDVLm6Fd1crf9IwgHvT+29FJlBpxSJEpGIP80k+0iGuJrhWptJTO4hq+I60VlbVHeqCA9vaq2yuCt4SDpX6MBtKlwlzn4eOK+0Mv7QV726OBSVjK6pHdI6tzVtEoQNGu/vulYa8bHaD+sfJ892tLw/bO+SVXbpgwDXL57v2gDaVU5NCvUFq+NEWX7ms0UCbtJyMQjLZtPDYhmVrzTgcvJ7gg== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS2PR03MB9931.eurprd03.prod.outlook.com (2603:10a6:20b:643::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.13; Fri, 14 Feb 2025 20:13:16 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%4]) with mapi id 15.20.8445.016; Fri, 14 Feb 2025 20:13:16 +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: [RFC PATCH bpf-next v2 3/5] sched_ext: Add scx_kfunc_ids_ops_context for unified filtering of context-sensitive SCX kfuncs Date: Fri, 14 Feb 2025 20:09:27 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0277.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:195::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250214200929.190827-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_|AS2PR03MB9931:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c57dcb6-e266-44da-4131-08dd4d340472 X-Microsoft-Antispam: BCL:0;ARA:14566002|5072599009|19110799003|461199028|15080799006|8060799006|3412199025|440099028|41001999003; X-Microsoft-Antispam-Message-Info: XXp5lC5PgICo2Lu4AT5yQdo/0izl5BwXfw7BiLFcuBTGdFzE2QL/7GSn48dpNUtWU2pO7VVex+6Q3ovERI+v/vWBYrwHa6Zi21PrIpCN1HA9KZjlK0izuNoEc7+KRTbmISi0zHnfY336Ql+87Z8cLI22y5U3ZhzJezgAnAhLwAwKK/RSHPFbuop06tAg8o+OJjOMO03V46waTKWLb5VcJNs6Q4t52I8UfKDCEb4aHLumG1hWws7xND7KTH3sjDTHDW4zdC15s3X0Dhr+lAl7G0kWFu1YKt4zYKcCCbYlB6kVHIK6ECI+/LJsG0mmaJjvS5p3P876W6d0iX4K86IfdlxeKVzGc90DmJVY8Kyg/ZZJbvN10n02wUDgHC0nRBEys3hS5GJwz6Te1yk9Lh8UWr2uLgpvHLlaI3rI+UB1O0HcfCm22htqIn94FdLMam33OBkPJVaDTOC+FOoOzG4ducoX4gclOhXQxfNjHb7+SSF3WrI1Fe3Eis2T/3PySqnWA7rK8D0LGcSVK13XAcgxzxPNoRlJsFrGd6s+vz4XMNs9pUd9WZkjcwIVh0lTH/leSZIH4HinxNzwIPUjC494FAxp/twJ13l1fmwPAEQcWvHjIxUb0z1uwK01lQucQEU93u7GQf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JuH1hMLtrxumDhAqRaIan8t5iSJyOW1xQUp0hEc4DkOuD3FZUid6uokX2FJykvKGvdTzihVhsMfM3Eb2jez81T/nYQTfur6++38qwbBe9SoQPlew7Z7p3ABjvKK3KEKilRpHaZrihvQd8mg0AiGQF0WfzoJAcZ6BRaZ7/x7Mqqb9duvId4xVUP0nKQxOQLAYEyD08LCFYabPFKpbEm48GF5FcSkEIiYmK+23n/pQSaVaXqn/17zxLHtwfkmSoX1oXfjZqonSDF2cPSBDAght4h+RVlL4ZqCum7FLcYaVz3gBRmk/yL4WfDUTDqlvh2nibe9GUGimrjXvVqub/Gbcdaq23LDOqQOTRQmfCor/fIJg/CzDjEobSmGCggSwkdlENp86TDLmX/uyHY0zYUfzNBFu9Rtktd3rs6rvIqfpG1PNhZ/Po9MYtA2+LASP74e4Eu1O0/VD9NoSSnzCx7FkYie1+v5xNX0o04JsYUyzpQMVS5mGYLHGcMDmuA0/JtiHtnTkw+t3UVGe+eUH/E0m57SgbNfrWfIlgobgHj4gL1wrO+lEq02AOcG9BiUFHAXCP5JH9h46E/lZlZiO5IC49TjpzTaYXhiYUisKVa6JJpUNUlVEGG2nIa7YDD4cn3VZADtF61M0Bz8i1Z9XMW1bJwBMJt8XmDmhEkCET65ccI0Kw4NmNmyGsIa36eB9vBAUgxSFen8S14/DHuVbMWotPGKPuvMm3UmJwru X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c57dcb6-e266-44da-4131-08dd4d340472 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2025 20:13:16.7187 (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: AS2PR03MB9931 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch adds scx_kfunc_ids_ops_context 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 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, 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 | 115 +++++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 35 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 957a125b129f..d5eb82eada9c 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -7,6 +7,7 @@ * Copyright (c) 2022 David Vernet */ #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, @@ -6449,11 +6450,6 @@ 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, -}; - static bool scx_dsq_insert_preamble(struct task_struct *p, u64 enq_flags) { if (!scx_kf_allowed(SCX_KF_ENQUEUE | SCX_KF_DISPATCH)) @@ -6611,11 +6607,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) { @@ -6931,11 +6922,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(); /** @@ -6998,11 +6984,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(); /** @@ -7035,11 +7016,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(); /** @@ -7770,6 +7746,83 @@ __bpf_kfunc u64 scx_bpf_now(void) __bpf_kfunc_end_defs(); +BTF_KFUNCS_START(scx_kfunc_ids_ops_context) +/* 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) + +static int scx_kfunc_ids_ops_context_filter(const struct bpf_prog *prog, u32 kfunc_id) +{ + u32 moff, flags; + + if (!btf_id_set8_contains(&scx_kfunc_ids_ops_context, 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 = { + .owner = THIS_MODULE, + .set = &scx_kfunc_ids_ops_context, + .filter = scx_kfunc_ids_ops_context_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) @@ -7823,17 +7876,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_select_cpu)) || - (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)) || (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, - &scx_kfunc_set_unlocked)) || + &scx_kfunc_set_ops_context)) || (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, From patchwork Fri Feb 14 20:09:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13975578 X-Patchwork-Delegate: bpf@iogearbox.net Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazolkn19013081.outbound.protection.outlook.com [52.103.51.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 34A43196C7C; Fri, 14 Feb 2025 20:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.51.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739564038; cv=fail; b=HvGfVHwZpUCFaGAdxn4dBdbbJO2rj5AmenLH8Owa8TAdxF7E0bGYhbRG5GOtuvkH6lhMWiSYWnko6ZqWwX9SUwuSMvLTE1AYiv4dLxFe5GAP4HkVPeWojlgyoV+TNlx8uw91FJjrM8zDYwTg3f5TeMk0qIW1D+KMeFqV+tX8E30= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739564038; c=relaxed/simple; bh=PJqZj3uJ8McepCsp6BGUALsz9eI0Y4X1wZ7IUOxXfyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=BsM4ztWGOCF3RZcmGbuniWkndb1ULbCsRM4id4F4HczTjZ8PBKQeXFtMQcP5Q74n7fidTjxx4usQP3Ql1RFyzdw8lSyjm9lYbX1DfGiwTJERf28VwggPBvq93F4un+5vxP//FHjY/UfEaKTMxBMvVTHOViUlK2LivweD6EWXMTM= 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=HkVzmvPj; arc=fail smtp.client-ip=52.103.51.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="HkVzmvPj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fa+g6qOh/AuPFiN9lV10/sLlnESWw1oWT7/k+zpUdGzQJf0Lw/NJ1dhn452rINq0CxExF6Qg6Kz8KHIfrM2SnNslHeDEyCw3VTqsxvuw3dv4Cp8ddWwuOBt9uuvpzwrAW6gOfqeX0YzrHr9OgXtoiAkVx5r+QVCAxRM8z4+vLOP5WwxbdeOyE48HQX3q23LhikHu4wOdZqXHHDaUfMtdHBrctg/jj58VcxUtF96Cq/sym9Tk96M5jU6aqYMP6C0oE69Pe8w0hrNyWrU+KENIrEXvUayFn1S5sHFUPFpBOChUAOP2Q0FYtoRFdLdr9NA/6wJsRpjQICFzeYrmflMfVw== 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=XqbAAz2+FaeT49O0hChGkh4KBdPwAIoEBdYkjWe689E=; b=xSs/yAX7MtWveSfAVSYdH31RCG05HHL3nOAohLwPVRb9zzoCiPOpb81Z3kICakCslN7fieiEbtkmgITNZrNMZ+1ay+hfeyuC7pBJb+lQ8SbhiSl5p3Rxqb4KLWNOFdPF0Zz6681Qb3yvFEo9OGzeol7Y2dJh8cmROdNGYS4AffwvuJDGavU4umaD84thQfOnrzGFwQOg/Vcm+XmUbaphB8WcJIuI+M/jUb7S5w888waqO0CzuLRvq5d46eAh05eLZiXNvzCScUL2PAV2aZkCyJUG9ljGenFsU9qfB780GB3dSaKuYhjouRgveEe6sX0x7hEcgn+jxAX9S7/N7co4cg== 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=XqbAAz2+FaeT49O0hChGkh4KBdPwAIoEBdYkjWe689E=; b=HkVzmvPjcEg/b5ftUf5MUhQ2k+9vOR1+vCfbOSf+hHlSRLBrIflO0tGWCbf1U9nymDfaVKrRsBDc5vKJf4Q0CfLMyCjclx4AG1KXZFLFj52gHFAoyNGb4mayYdjafxKKN5PUwqrLcVDsWT4Z0biCRiiA6VwBzYulbBgKQIbfFcK+5K2jTSGVde9lSjAzy3Vi3tK4Ey3Ywjp3vBUyBuUHORPj98eQPxiWz7F/WynUaSV3ubaAi8GMEEFVRPcXCF8UvRE2hP+3srViE7B8lI5bBNTxk7+VxEwtc5Uq8uq0nzwsW6B5gE/l/EBiMp8h2ndhUEHq4kPklEpY+3fw3bIrSw== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS2PR03MB9931.eurprd03.prod.outlook.com (2603:10a6:20b:643::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.13; Fri, 14 Feb 2025 20:13:51 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%4]) with mapi id 15.20.8445.016; Fri, 14 Feb 2025 20:13:51 +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: [RFC PATCH bpf-next v2 4/5] sched_ext: Removed mask-based runtime restrictions on calling kfuncs in different contexts Date: Fri, 14 Feb 2025 20:09:28 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0277.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:195::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250214200929.190827-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_|AS2PR03MB9931:EE_ X-MS-Office365-Filtering-Correlation-Id: 0749b2ec-18de-44fe-ddb9-08dd4d3418e2 X-Microsoft-Antispam: BCL:0;ARA:14566002|5072599009|19110799003|461199028|15080799006|12121999004|8060799006|3412199025|440099028|41001999003; X-Microsoft-Antispam-Message-Info: /xtmAr9cSKb5+yIZOmg19xW1eKYj60hJnLiog2K1h1D/DPwa3exFZDGy7RFmKjr8T3mXTy8Ch0pY1f1km85dGJ78mgwDeoTgPziSDPld37+1lzBwjgjjsdgqYjXugsqOLsnB96SfJvybmBgzZMXdwqhsHoa3MSinMuqdE06O1/+4E7kBZAMm9xwu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Zr0xnm4wdbYI6JU1nZotR4Ibb3fH12ZAzWbiHBM1pJDq6gQYL+nemp1H2vgfqKHetqde5655ZY8z7EuxFROvLye7RlsXfoDVEHWqcDrJakN9BzLAHB+ZjfQf/6zcNz2mV X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0749b2ec-18de-44fe-ddb9-08dd4d3418e2 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2025 20:13:51.1430 (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: AS2PR03MB9931 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC 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 | 232 ++++++++------------------------------ 2 files changed, 50 insertions(+), 206 deletions(-) diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h index 1d70a9867fb1..867c24b88ace 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, @@ -146,7 +123,6 @@ struct sched_ext_entity { u32 weight; s32 sticky_cpu; s32 holding_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 d5eb82eada9c..d9b4b5e64674 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1092,19 +1092,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; @@ -1120,51 +1107,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(); -} +#define SCX_CALL_OP(op, args...) scx_ops.op(args) -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_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; \ }) @@ -1179,74 +1127,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"); @@ -1256,11 +1166,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 interated @@ -2076,7 +1981,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) @@ -2171,7 +2076,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); @@ -2202,7 +2107,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)) @@ -2251,11 +2156,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; @@ -2275,7 +2180,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; } @@ -2285,7 +2190,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; } @@ -2812,7 +2717,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; } @@ -2857,8 +2762,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); @@ -2978,7 +2882,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); @@ -3059,8 +2963,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; } @@ -3073,7 +2976,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); @@ -3651,8 +3554,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); *ddsp_taskp = NULL; if (ops_cpu_valid(cpu, "from ops.select_cpu()")) return cpu; @@ -3690,8 +3592,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 reset_idle_masks(void) @@ -3757,7 +3658,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: @@ -3788,9 +3689,9 @@ static void handle_hotplug(struct rq *rq, bool online) update_selcpu_topology(); 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, @@ -3900,7 +3801,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) @@ -3977,7 +3878,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; @@ -4034,11 +3935,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) @@ -4047,7 +3948,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); } @@ -4076,7 +3977,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); } @@ -4185,7 +4086,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) @@ -4201,8 +4102,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) @@ -4294,8 +4194,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); } @@ -4316,7 +4215,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); @@ -4349,8 +4248,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; } @@ -4363,8 +4261,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; } @@ -4395,8 +4292,7 @@ void scx_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; } @@ -4415,8 +4311,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: @@ -4429,8 +4324,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; } @@ -4620,7 +4514,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); @@ -4663,8 +4557,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); @@ -5127,7 +5020,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); @@ -5333,7 +5226,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(); } @@ -5379,7 +5272,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(); } @@ -5436,7 +5329,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(); } @@ -5656,7 +5549,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(); @@ -6432,9 +6325,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 @@ -6452,9 +6342,6 @@ BTF_KFUNCS_END(scx_kfunc_ids_select_cpu) 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)) { @@ -6616,9 +6503,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 @@ -6701,9 +6585,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); } @@ -6717,9 +6598,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 @@ -6745,9 +6623,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); @@ -6938,9 +6813,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); @@ -7671,7 +7543,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); @@ -7870,10 +7742,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)) || From patchwork Fri Feb 14 20:09:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13975579 X-Patchwork-Delegate: bpf@iogearbox.net Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazolkn19011023.outbound.protection.outlook.com [52.103.32.23]) (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 31C4D1C860F; Fri, 14 Feb 2025 20:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.32.23 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739564060; cv=fail; b=qOxpWtxxdUgII+FCSzXlofHeQrH5wiUhZ2+/uKlDrIfpnOdbCHu5XPUzlBsSm1qf9yyAEc2J+WmqDg/Fo6y9A57yeB2HWINkqF+Fh6AoltsUv366+fnl/ln3fxx4c/Z4MEXVyooRs/Rxd2OnWh5vd9qOT2cMZzX4E3WpYIElrRY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739564060; c=relaxed/simple; bh=ypXZfEqdh4D8qNVzzgsXTGxGo9Tzi11wS6e4bO+4Kk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Rs068gO682lIhDz2jf5uNRl0O3PHPUtv0nXdBz1esYVoC1nfU/BHQf44c+S2h1bf+F594CVg/VqjrK1W+caXDOs9ZzJ5KMRCpXCMAhuSfmOJfQXaD+0gi/ADwVYlOTZqAzl+elvE98B28raxmd1l51pC/4ygalrJZdmXaZ/v8GY= 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=DWEe7gkH; arc=fail smtp.client-ip=52.103.32.23 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="DWEe7gkH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=B7RAV9EdojyxYCRkorudhA3wm1kFz5FZ3+151MUDmYIHbZS1IKUfHbKKcg+HYDdezHUwzhkxeNYYdDwTeBLaOlYOHuyTBe+0w8gvBIntueJb/wY1kHoCl2So2tANCieyRzawfURQ790GMn/uuwC6TV/ZSRboJaG83N8lBnP1/iYvCA+udu/oa7visRND00o+BaFBUb/VtsR/Hw0dpTr5NNTbIr9eNEI4z6eQKIipro0uaDDPbqV4yLGRvSLFvktsl/u2kqjYPS3ll8TaVEByW+rJ99e8EQ42SbkuSWQwwKBLVeJfqvtyUCav0xt2dkNjIH4V1uBAhyKdBW/L+4WCpw== 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=GRnGQA+nOZThu23j/JO28tYgMaZH4gtrbP64dQJvHRI=; b=AE1Kkpmkg+4uIh1mG29pKwEDOayModpYoFTDGFL2H0WDwBW71qBhu9colTOWT+Zk5kx+iQ1o0H2FwgYnAce+dLJ5zYAduaRg5EoF1jBNIxX1xx42h5FExk2Xf+mGD/9Ay+NTWwdraOzyKDDCV+E8jrC1SypqvJCP3R2KqrT5WRc0Zs+Gw7JGhTFwrRUCp3VqPeYwdN3zHrE4nbYzee/SNE5mX+WwUgt8cW8GlFruQg21VtaNWHyNLaovHlBaFuvSj09/Xa4DEfnHpJKlAInKWjUtcfHAJ34FWS4Fjr0D+zvSBBmhlYc8KPsljpe6oIIDQkVTTovwjqQ3yzxH+H46aA== 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=GRnGQA+nOZThu23j/JO28tYgMaZH4gtrbP64dQJvHRI=; b=DWEe7gkHVZt68ZcWY/T16+U/5E3QVfy3UyCF9fm2ori/UBREee3ZNvL9mFFdP4VEth6nAy1fm/bsR6A2SgK/gqGVu+vwwWfrXxku8kHfcU29tZnehcmxafhttAVUXAHVkvhAaB7fVnhY7EPBqalP/zPAczA0MbrmuOrwH1LMG/lOh3BRYL7zOvvTdTspFE5LYnGwymAhepXXo/laFss7tlCXcM929BFvP9aE5Ttl7WmENXd5xHBvWDsr+InkpFVP6SPe1RQayhVf8cYJX/LQvSokIlYbFNMIYHGHuKe5IjdLy0GkMig+PbNVvfWFa+pyu4KHmltA0oZ8hHNnqRdTMw== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS2PR03MB9931.eurprd03.prod.outlook.com (2603:10a6:20b:643::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.13; Fri, 14 Feb 2025 20:14:17 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%4]) with mapi id 15.20.8445.016; Fri, 14 Feb 2025 20:14:17 +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: [RFC PATCH bpf-next v2 5/5] selftests/sched_ext: Update enq_select_cpu_fails to adapt to struct_ops context filter Date: Fri, 14 Feb 2025 20:09:29 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0277.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:195::12) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250214200929.190827-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_|AS2PR03MB9931:EE_ X-MS-Office365-Filtering-Correlation-Id: 51fc57a3-cf03-48ed-4516-08dd4d3426e4 X-Microsoft-Antispam: BCL:0;ARA:14566002|5072599009|19110799003|461199028|15080799006|8060799006|3412199025|440099028|21061999003|41001999003|12071999003; X-Microsoft-Antispam-Message-Info: ks1DE/1JZBmg+iJQ1y3+igQB3w8yyXYYUwltYxjbOrLSDJ4ebVKYHVBbLrKD+Y831lDoBNn0vuQF1uBl86BzE51JDabCqoo79uF/qCkZBnttPJ5fbtWABS3AomaINSSjbxi3kEDS0hFa6cib4sHaX5xAg0+ZLRg4RQoOdQoG4mKfIPcnbbGjQvssLIb36l+CHkEw8MVO0nvD0a/J//eRdGAO56sJlxeZSWr4KiTv/3jcfcZyMaBI2b4Ov+4ufYkuKYk73I1uv30paXtw8HHeoBh7jaEjc3we36Ykeh1gTHR05SmcqeCG4Rp/r/uxUkXpifiSoubJS2pxecGm6LMbZiNvEOJasefVuUVknQph2+JYorO0Ai49NI4exyBxuWKXw//5nu2iVjSmP5iSlHHgFcwq5mVj76/qJv2bU91Ly76upmWr9n/tttJcvjLGeMXYbiX1O9DUJcQoSjeLWR2NXkzv9XACwb3axsaMI8G+UI4LL18B7JncYWBXFxM13C5i59Pt0vRhSPs271f65rbBkX6vOY6lqm/mHoe6QMmC53afPlaIfSzzZc3NO3n5Di7Gi3HsVqOzAo2/J7LuicIKUibXglmoTGRWqVv/dT43bUCa6uo4j5eiS9Bs7OhpongS8cYH2hKQPd2oIi1H/Bzz6k1lcb2hliiUTaBzt7ATnZ7Qixg8jCvE37QWHbYv9kBWlGD5SI+rBBgX0t83JUJ2nWhm1l9z1CIyPFrAgZzM+GmeZwHdcDizaUCjhnyy3U0yJ3t3QSFvwpnIbJoWlA4BGBZ2R9uKkjU/45AwL9UCbAtyglMu8J8SZlJfy14icEShSQh5PX0wEXJ0wYxKeim+ojdjti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6N8fOAfZGOd0+R48wogd4duZi06EJcjfhpVZAY7tsgCyuCwZT8ckWTll3zwcVDfTcVISYaUQMXELLit6Pl2BwMvI7WKV5uKCrqL9tn6hW3ztahASdqeDOf63vAxs/1Dtivp38Yu9c7EAi6Lf/EiGY4+PZ2DNq6zcrwcD8ROx7UEe5rGQD+wrcD566GIbH+vGPdJJmivopX+Pk/v1kGzKuoHT4kaE9DK8sGe4J4gF+X8Sv41nUyVCze97TxhFznZgPzzyetv2hemalYWn80ACujyM64MDMRI/5icdwM0Wyn/S6WDtWnSFPWKgjX7lVhHF0f2lZ7NWjdzIDKk1/bacS1NSU8cA+8NCl8uLPeIemAR6RsZCKSbi9ele5lfaSKWylutUsGmfgoBA5MBoEmreQp3lXMJ8WdcOpiiTlGq60zYZgc8U4FJUbyviqAHa/49yEUJOVQt0UPipU3Epu5JIXRKnlQJKcziGrMLM+7EGxifQzV9tydgBm5ExtY6ruZNQSTIZk/nqM4WVZcGishKYfUth1vYWQe5EbudYw99bh5CdWuVOQBB2/4kAl8UpNX+/Q X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51fc57a3-cf03-48ed-4516-08dd4d3426e4 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2025 20:14:14.4963 (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: AS2PR03MB9931 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC 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 | 35 +++---------------- 1 file changed, 4 insertions(+), 31 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 dd1350e5f002..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) +static enum scx_test_status run(void *ctx) { struct enq_select_cpu_fails *skel; skel = enq_select_cpu_fails__open_and_load(); - if (!skel) { - SCX_ERR("Failed to open and load skel"); - return SCX_TEST_FAIL; - } - *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; - - link = bpf_map__attach_struct_ops(skel->maps.enq_select_cpu_fails_ops); - if (!link) { - SCX_ERR("Failed to attach scheduler"); + 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)