From patchwork Mon Jan 27 23:46:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13951908 X-Patchwork-Delegate: bpf@iogearbox.net Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazolkn19012032.outbound.protection.outlook.com [52.103.32.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 4F642481A3; Mon, 27 Jan 2025 23:50:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.32.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738021832; cv=fail; b=PwbiXQouXzA9AcxsUV+Wtwnvm8wuTpBaijURhV4QG4QH6X7LUGjTxuqs85eK60HbsMKIt+SeP7gyQRBCSHTRlSS4q7ksx8+3/zh2TQEsv+N+oWwJZeuRk5Dq2Nc403rG+Umdb97wuQQdnQStXfbYBLQY/XgNJspYDcva74CJbrg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738021832; c=relaxed/simple; bh=KIxnMIr3pjygOZQfnbAT4gl8laW2esmTBi9+dragCrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=qyKEfkw5UdxfiCXZlqGCvFhg39+PGfhxMhYw+fPHewKNvQ7zxY7x0ftm6qPqVsckyD8Tc/MgSW+wP8WNXVcqJ+gC91cBGPmrMHXgj3YZPXz5kQGpVHvC95Q/c4rduzVmxZmiiSr/ASU4I83cZ7Dx68RSIq+v9JyeWmdhBxQd2Q0= 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=OEObYzw+; arc=fail smtp.client-ip=52.103.32.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="OEObYzw+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ITnYjV0/49MRt3Xtwbho0oLkempRkAdT0KBONE+hOWIZ3LkRAxkUxTCwJuaT0cS6T0E0OmhgEE/mZrYt/Ix5F8org/hByNGKqRmkCdHNYhnjkesgPukDke5lpw0dhuJ5rPt30I4QjCV3TvSFAvhw2nPClGOXwtbUWS3Ib3g1okXPFbbSywqXD54CvGzotoIcab4u8dZuO4b+6bO1VpsE07q2/4YN9xfsV4gaHxsm6jicZSU4mK5ZlArQu2ZBs1jbUK4vTdESs4Wf/uNzlw6WVkm9lw75Sz2qku9X5BCesWaoxO1OcQXTSv/Ne6AkpH2Au5O8B/J29iqs01v6qt/U/Q== 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=QRVV0jX1KjzggGbvz87UhS2xPIc9n8VFZ0MWXdCk1fc=; b=kkY1qAgX66GkUa3Nii4DhL+zff564/Krzg8VpOMpXP1JU+Cp3DVXz71n6jH+o/BMs+ikCXxMhiKV4kjfOOhEfwqrhYJp6umeIo+UTDmHRv1FISzt14q/vohuSq42ml8DFka+1S8fIkqSZUEZuetmRUNxvelBIOpTxnPdPQty7xA+QJmX8Oq1FomY8gc9EIqfoLDMv+rfrs+TJXJVuUU68gOTsj3+FspjaCfjUA10f5Orm4KIyVxyt4QrtyTj9V2OcSGL7CIhFAycWjI64yOQiXcf2i8ldJESqdc4Z+DzB0z/qn/UOwle06l0Fq6i7Ta/2XB5ocuCFJBN2qxxX2DlXQ== 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=QRVV0jX1KjzggGbvz87UhS2xPIc9n8VFZ0MWXdCk1fc=; b=OEObYzw+6UlwYlhQy1TL24f3GDmD9mFYtKisb1A5hG1wixiYC87U0cKz7PgHf4OXfEvN9MP4YF0bkmo7kXtmiteV7mqcBPKHOUcH7+O5+VAmO8S+VxrXHTPaLq27WNFREHa0TIk8jmWKVSWQvNMd4HdA4J6XJSqY2oavkwpI/ibgHP1J2/IQOnzSo4I7r5dZhdeBCnMVTB+2AloLf7jkR5Z3XGoAni03igBSCT/wO7Krpb7DAZt74HBGfYdDt6x1Hq9ZPsU0EKl0x8mTGfVwfdPicc/XS5mJ0QBMIUksEshDkFpNbHF2PJa7NFjtCGCsSHpgZxmFt86RJeRtFjsGyw== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AM0PR03MB6209.eurprd03.prod.outlook.com (2603:10a6:20b:156::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.22; Mon, 27 Jan 2025 23:50:27 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8377.021; Mon, 27 Jan 2025 23:50:27 +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, snorcht@gmail.com, brauner@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH bpf-next v9 3/5] bpf: Add bpf_fget_task() kfunc Date: Mon, 27 Jan 2025 23:46:52 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO3P265CA0018.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:bb::23) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250127234654.89332-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_|AM0PR03MB6209:EE_ X-MS-Office365-Filtering-Correlation-Id: 37a8d3a1-6486-4766-ecf4-08dd3f2d6018 X-Microsoft-Antispam: BCL:0;ARA:14566002|8060799006|19110799003|5072599009|15080799006|461199028|440099028|3412199025|41001999003; X-Microsoft-Antispam-Message-Info: iotGClZvXE0tkLIIAFZlLK2HaMc+YneKzZAYyS6DK0Fvtvu7Axs/LtUrGQVurkKsZrccNNvNNADy0UhjzMkvgEymyagJE4mDP2eyyA0edSzvtkWVQJE+GJELZDxjTnhDAnJky3gpWqJxjOEFw6mIY7EwiXHduSHPsLcCCPZwENIA1wzYaHmkHSujvdYOsTrq+rrJYIhIMQzoW/kwC488atO6tzh/sla30GFylCgdfDHxo7d2/wDzWGuG27gd39e+8SRS9LXzetEMxFSO8WgGztuuTGGjLOyazRpLqBgwH/az/5ok+h4tzqmykiqj1xJ4YDg2QyXIi9V2aT08uZQny12abj/DerhjkKQxBMPoV8xATbx7JIsbdDV+sOv4rhanG+NnB9fD6cRSQdbg6hACtd6mNH8u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Hd4U0o/MKUD53+3RnpCbXEOhBH9EKU5tg/4VOWSB89NTRsSHD0hLdXdl3vXlWwiatcs402TB92TizkLBuovr5BWXIaijN6TYqpT/T5bejGFY3wasC12+8NPpOuAl5iUqWd1eXFfgFDMUbeUfic5CM1G7vav32OcLe8QEcENWa39KXzxROSbCfb0UzpDY1p+CynJzXDzN1rRmo4AS38uKk4gXtg0D23ajCl40b0kix25qgaPSIK2KZK1hOrZRHd6/zsZfwS4YYEg8BX31tC2cBU5G/F5iK1JrbwjpXCQypwTlojjvBa27RZGJMKci8BATB4QXtdToRyAdi/Ob15+jJ4osLYVIwGQFzrzQ6gLBYv8gf5dTB3GEq8KPMbDvz4w2Xvtf9rL8cffo4gGthrNVULXMfB5mBo872386tOaarah6RI9f/1uTeI/4rKckJc2oTnKQzdfglvDQm+SJUtLXNXAhBew4OJZ+utNUUI3CfkQfHfoizG3u3LChC8eGFNKpIQONVBe6FTwI7IAPFuFZccXtScja/o8wrMq+Vi81fFxvpW8lepcbu+DeluLc+pvU5GPYjfseknrdITN3oyvhOcBrcJUD0TJmTc+aagrCgN2WLpQadaiLoxkWi8CMJRkFlwuQgB4txlK+gHGxhDUkYoKP/krkrVYKuOxc7rusznGbqdWvgsDFuNlM78EjDAlHv0EdpOuUJrgRnXFZY77tNyMeYncYwoOlFvTNSx73bOtAPLBUz8pXKzFgD/H6ITvdRyownObwHksl4McZHkvP0k9ZJg+OWVE9R7+C5oX0zuLYxyxROcGu1FYSNur78Gswi4t5J5i8/Z6QGNUeisPEwlI7V3RNFbxFZ1BcTUtUSCW07GhRxkoF3O7IgIy5/wDQHCLZerXlDzF1MML6NWBiV0mFK2F+yfvvQxxt5zmm1jRjZLS9rWuo X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37a8d3a1-6486-4766-ecf4-08dd3f2d6018 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2025 23:50:27.7160 (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: AM0PR03MB6209 X-Patchwork-Delegate: bpf@iogearbox.net This patch adds bpf_fget_task() kfunc. bpf_fget_task() 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. Signed-off-by: Juntong Deng --- fs/bpf_fs_kfuncs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 3fe9f59ef867..4a810046dcf3 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -152,6 +152,23 @@ __bpf_kfunc int bpf_get_file_xattr(struct file *file, const char *name__str, return bpf_get_dentry_xattr(dentry, name__str, value_p); } +/** + * bpf_fget_task() - Get a pointer to the struct file corresponding to + * the task file descriptor + * + * Note that this function acquires a reference to struct file. + * + * @task: the specified struct task_struct + * @fd: the file descriptor + * + * @returns the corresponding struct file pointer if found, + * otherwise returns NULL + */ +__bpf_kfunc struct file *bpf_fget_task(struct task_struct *task, unsigned int fd) +{ + return fget_task(task, fd); +} + __bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_fs_kfunc_set_ids) @@ -161,6 +178,7 @@ BTF_ID_FLAGS(func, bpf_put_file, KF_RELEASE) BTF_ID_FLAGS(func, bpf_path_d_path, KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_get_dentry_xattr, KF_SLEEPABLE | KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE | KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_fget_task, KF_ACQUIRE | KF_TRUSTED_ARGS | KF_RET_NULL) BTF_KFUNCS_END(bpf_fs_kfunc_set_ids) static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id)