From patchwork Thu Jul 11 11:19:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13730519 X-Patchwork-Delegate: bpf@iogearbox.net Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazolkn19010014.outbound.protection.outlook.com [52.103.33.14]) (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 A09ED16B75F; Thu, 11 Jul 2024 11:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.33.14 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696938; cv=fail; b=ZZeC1/bfQ5Zw4UTyaffYB4miIhFZt9fqGTwv6zGln0fmABjHSDhyAsLjr1wBASYvlCeDK3bS6kf6PYdqasi99lKpW0k5rzPZsWLdWCDH9QNFxaRodGi8oSPmxmmx54huXNJMrUsPo+iI3ik9nA7GGlQr/54DWKKYmAtIkDgXcOQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696938; c=relaxed/simple; bh=nhvKRb+Yls5UR7AMA4Dx8jWAvsk+gA+QOEFw0H1E2Jc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=sKatjHUoKX4rAKi4N8LkgLlsSVlHJ3gjbwuKjaZ+KepnNeuP+aAPOQrAibw2TdWRWo8afrXQwOicSxU2Xod8juNn7Z/Vnj3tfxk8qtg5Zd+vlyjqTr93TsgG760qrapOVTNfPvalQ8cflUZzWRD/MKlM6Eo75jDpYwfeANBgfpg= 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=tWtCykOo; arc=fail smtp.client-ip=52.103.33.14 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="tWtCykOo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JZo2ydwzjpNGJ5160nJ/ik1fVsqPGFt5l4O5D5Y4SI+D2MtWb2NwiWSLwHQZPttECOoV5+t6Gqx4wvE1cunQuoI2c2i0mBX2KYNIHpYbq+f0mqJ8eyqZNX0L0Bqgs94PXF2mwAl7F9XdcfU7dp302LqwQpP6+xD+56RnaP6ZwnbpmuVphr0Kg0eW9zyxleKNA/Bko3kcD4CXUge2mh/nEaqeuswGgCiArM2gTwrf4THwWeaS55Tfgi6i190UdA9v/KOOsWNxUD71bcOBCn5XgDR/VsnnxHa14FHSzk6yEoSeMabSZTwRltz6EWEpcxLNYV8awxq1cREZ4ZJbk6Tyjg== 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=D01jDLQAupn+yFXzKYkZ/4dpOZ4AixU+vSFOGqybkRU=; b=Zs4bzAyAJT6j64cevxxAnp5Ol1NqoFtUYff7t/etZZ1v00HAZUDUOGoRtBqHIhRSzQdKViojn5PXt+SVKHjDUQ4gfw04LEcSm8jDrkeipwTYDbAqcjOd6Ert05p8Mn2BEQp47gjBY31APMVytQ9XoZtXQ1FiEe1ylFlsAZSnVSJ4pptJmHPOOjMCcl3pCOKax9fzY8M4KmXDAJuM1LlhnVqsGVchrOTCCadiHyk8bKEfGpr9e0JqzYc98494YnyWqD149CBvLORMC6nborpoAlRZ/Gc0qHIT38CXLzzmJXr7r7Ea/Ib7eLC7iEAhTYgTn3sKMTXq6VltvJrOKnQA4Q== 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=D01jDLQAupn+yFXzKYkZ/4dpOZ4AixU+vSFOGqybkRU=; b=tWtCykOoioKGGpff62Eqcv2MlOYsdLYW+Zei3u6zf481ksC/w5UWhetp4H8ipEd5xUsaO1iGr3nmH3Kp2k8sc+y5NIs2F/zoJrgGoeCsO89jS8yBgyVWHoiy4aqFHzKaAQIMHsnAME5dd7hJxKbpS/VYBPfzVkqw/zu3NM9r6+RSt2Ka57UKOWtlCCZzpERPCTHS2TYbwXc+ttwyTY5G9ltKtieBIxc4cJwiYa+amOxcTabdPypTm3WgXqNveV7DCheSvzjUkQxJx9+c5wXK0Zw89thyrRwzeZNL0ACXAhOMh9FWxrkFePKC/yhT5lSQ2cUhVtnvfBNx9WqlYzAz4Q== Received: from AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) by GV1PR03MB10233.eurprd03.prod.outlook.com (2603:10a6:150:166::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Thu, 11 Jul 2024 11:22:13 +0000 Received: from AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7]) by AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7%6]) with mapi id 15.20.7762.020; Thu, 11 Jul 2024 11:22:13 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, 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, andrii@kernel.org, avagin@gmail.com, snorcht@gmail.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next RESEND 05/16] bpf/crib: Add struct file related CRIB kfuncs Date: Thu, 11 Jul 2024 12:19:27 +0100 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-TMN: [q/Zb/uX7ndiqEOGPuH+FUeRqgzpjd/B6] X-ClientProxiedBy: SI2P153CA0031.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::7) To AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) X-Microsoft-Original-Message-ID: <20240711111938.11722-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: AM6PR03MB5848:EE_|GV1PR03MB10233:EE_ X-MS-Office365-Filtering-Correlation-Id: 843fdfe0-4773-4dcd-927e-08dca19bb66f X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|19110799003|8060799006|440099028|3412199025; X-Microsoft-Antispam-Message-Info: GZTjokqCpZ3Bzpk5Erx9rASI4Y54akaB4m6NOyZwOuQIUlGnVAHzF8AmRLYArN4HJqurrddafTulokRjwfvELek2ibQaC3yHjdqzSI8TqdWnCYEQ0UjllaWSNALJwfkRgNUnlqV+Idx1k58seUigIdsS71emxEqrQsF8kDJC+7wkBAeet4ou2YKZgqUtXjtGMMnATWM4uUIQuyCyxj5+7VYNd9rWos84nBidjkaE8L/pRh5QqVPewhMlY5vsbeapZguoeaqbkSV8g1mdND1EDzeIgAX24cEkUgUnMKNe831jDB2/iL39db6q3Zdh9WV/112c8Q9yXJTyCbFqMQuNBTLFqPFfvEH6Hn1hItyq4yKnxuJS+yJMLcODa03qdUVc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z4vhDUHclnkWzyR6seLhTOjNbVz24t2RYz6DXAeqolmwExuF8tkcPFPKTIlhzJ+bKufo5mC6J1Tj98vpBq7Za/rtrWGA0AJvduVPltCXGOZL86v2HkkcEdsI5JzbHlj/F37qH4LlFuNbU3+FfE6bzdAFD1JiPKXOL33HmadnHFNArBiu8iTfMpfHUmBr1Jh2jS4L4YPLAWqPdYr7cCTpsQnReac6MGbsA0l1mEVFdajaBynSbaHmSiVrVgj9ugoHaMVBfAdC4qZVjmMevbOBQL6/m3eAl37Kpwt3IOe/JpRqn2uvWObgCBxRmbvX5RLouxjDk9EjrSTaSDG0fj5MpwNSxaXzBBWonZ8GJp4nMcHRPxZppChTO7isp9kQg8r5DWYOawyMaywf33AZwq4aYOuIiDma/n49B1lcUr9qod6dFXeuitP9L3tjjRG2xkYvuaUqvvQbYMoqJWpOUEVpGZRetBisPHv7P16fiHhOreyZsH7Talm8XzpEGPP64= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 843fdfe0-4773-4dcd-927e-08dca19bb66f X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5848.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2024 11:22:13.4827 (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: GV1PR03MB10233 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch adds struct file related CRIB kfuncs. bpf_file_from_task_fd() is used to get a pointer to the struct file corresponding to the task file descriptor. Note that this function acquires a reference to struct file. bpf_file_release() is used to release the reference acquired on struct file. Signed-off-by: Juntong Deng --- kernel/bpf/crib/bpf_crib.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/kernel/bpf/crib/bpf_crib.c b/kernel/bpf/crib/bpf_crib.c index 9ef2d61955bf..1c1729ddf233 100644 --- a/kernel/bpf/crib/bpf_crib.c +++ b/kernel/bpf/crib/bpf_crib.c @@ -8,13 +8,50 @@ #include #include +#include __bpf_kfunc_start_defs(); +/** + * bpf_file_from_task_fd() - Get a pointer to the struct file + * corresponding to the task file descriptor. + * + * Note that this function acquires a reference to struct file. + * + * @task: specified struct task_struct + * @fd: file descriptor + * + * @returns the corresponding struct file pointer if found, + * otherwise returns NULL. + */ +__bpf_kfunc struct file *bpf_file_from_task_fd(struct task_struct *task, int fd) +{ + struct file *file; + + rcu_read_lock(); + file = task_lookup_fdget_rcu(task, fd); + rcu_read_unlock(); + + return file; +} + +/** + * bpf_file_release() - Release the reference acquired on struct file. + * + * @file: struct file that has acquired the reference + */ +__bpf_kfunc void bpf_file_release(struct file *file) +{ + fput(file); +} + __bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_crib_kfuncs) +BTF_ID_FLAGS(func, bpf_file_from_task_fd, KF_ACQUIRE | KF_TRUSTED_ARGS | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_file_release, KF_RELEASE) + BTF_KFUNCS_END(bpf_crib_kfuncs) static int bpf_prog_run_crib(struct bpf_prog *prog,