From patchwork Wed Oct 30 00:14:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13855792 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2011.outbound.protection.outlook.com [40.92.89.11]) (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 3E9B710940; Wed, 30 Oct 2024 00:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.89.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730247452; cv=fail; b=qyxN3YejDqYW0s6M6mrEmYkO/bOYAcgw92dpde6Kl4Kf6mOPU7JKHnUp6xIwR5MJuXvis+hlq86wdvnb+wthdZiiwRVQI7rQub3WPskambuHjOwQCMWglZE98jLupPHRVVOCNL9S54UDZg0MG3ViEOx6h0fJ7B5NM5DQVcEgUjQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730247452; c=relaxed/simple; bh=dx0ybxqUrlzgqwmQ0ztItlfqUEB1SRgoqUxNidJDbjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=SqI4pwVUAGj2jsYmHDyDvOEqJaOcu5EG8Q7bhANKfpCveNFCiQDn3ygNvFQOiPBRHpB39SMLRMJUecTh3foUgyXgJ2B0L/K/ecF+vSsGA1gcIqmuPj/Oq4VJER+HN+19CA25uppvO6UMiC+eFb2w8zFyRWBF3XqMWl0PK5jWbig= 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=r/+xDNwz; arc=fail smtp.client-ip=40.92.89.11 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="r/+xDNwz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k1a4JXEjpK0sEb0rxiDzpVorAx4o6fJCH21ThKtE/BVEIXcWaQKtAigeOFjIK7/SJ3utn+GBp5hdrSBvuKm/jXs3jBzRIbT6WqqEj555jQsJmva+hE5/mRIFGI9hvnFg0tbdbPxS4wM+LPICS7wQibwxZzVtkO/JX8OkyZcAjLKErvSLI9gC9FHuUYcpjCjwR0U9mz8uITuNNJo3pKpXzqWDmKKGCDPN9mdmdzIYB7tVM9k93MPSh5vw2U3u3r+/TdpivmPU5av7+8Q95oJGKTXXOQg3sUl1PiZzSOe8T98/4NLNYx23ce32+SstOn4ceTNBCgTv2gEKq09brejqPQ== 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=V9pxNH/v7o/ozsnWjwtaN8YP8vTDpkqyZeoksCF/+G8=; b=lfOQVgooXnw/d8k2xM4aZv6XTNntg44DWfSndPieEARYnzF03MD6rb+i2LutNLtYj8MkGtASsT5vqTR2BjXyCudpj0cSguMZZ0wTA+/Pr15M4E9tAStZGFZLZcz8EXAvNwLfz1o/h5SE3w3kqA8do0/NJEW1A/cVu0OtfloyoITglI4IYkzLWpgkreWJc41s6NkxMIBc08a+74gxAlxbJCogdILvaDuHOIq5Jorj9okMMhEVOiVeExAbMKfvZ5GoBbv5m/ENLinTBTDdLtgRjcwZOfXFPWai+Rd84VT22/X08+pbtUoiZHmkKqTdi/BlWtMfXHcsGH/d+SOV8kIuNQ== 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=V9pxNH/v7o/ozsnWjwtaN8YP8vTDpkqyZeoksCF/+G8=; b=r/+xDNwzq/sULbYYrSE1XiuUbsv1E18J8H8jjLjTFIjBa6+eeUrIuwSBHgCBqth4zy5hk3EIi6G3aT2yUC/ZcT8xg10hAGYxx497xHufI6IjWjh6rV+Jz/576KxyOLkvlJombruynE60pG4WH+72jctBsKmsKEBfTGZZkvt1sv4zJEZYGikHmpoR1NtfJ5W+gQVcpYNNEB1+3kHfB49zi6TKnlT+nEinVMLbISlSi0MSICK45ZZojo76BGbtl0rqR/+zOF/InG4WBuNDu/9BqnUZSS0VGnvpLQlizs9xXMj/72GYboFzZjp4xrw+M8WJpjL3owjXOk4204BEyV1tTQ== Received: from AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) by DB4PR03MB10105.eurprd03.prod.outlook.com (2603:10a6:10:3ff::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.27; Wed, 30 Oct 2024 00:17:27 +0000 Received: from AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7]) by AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7%4]) with mapi id 15.20.8093.027; Wed, 30 Oct 2024 00:17: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 Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 3/4] bpf/crib: Add struct file related CRIB kfuncs Date: Wed, 30 Oct 2024 00:14:56 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0238.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:350::11) To AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) X-Microsoft-Original-Message-ID: <20241030001457.15593-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: AM6PR03MB5848:EE_|DB4PR03MB10105:EE_ X-MS-Office365-Filtering-Correlation-Id: 83d77c21-a597-420f-2df3-08dcf8783c16 X-Microsoft-Antispam: BCL:0;ARA:14566002|5072599009|19110799003|461199028|8060799006|15080799006|3412199025|440099028; X-Microsoft-Antispam-Message-Info: otqvHMVD/i6h1VQnpGHVMqjMSgCXg56Tm8kd/oF8OugBCqbMAnw3hQ7nC0XXBbFMEWjLUV6mqng6IFHpfc0sYCrOxTpZfo1/RcYr1DUacjmOAllyrEvld+W4veFZRIVPw2DMZqCD0pj/HNgcs1AXOPx+mmR0StdbY9cIKQDe4sTolmptkowpk5W3co8uX2UgdBzySzstIhbeRkJlSytspfzKZDp0z6zeqzf0RAwVt4e0rGp5r4aYwowqZVCgdFdDnn9bDMqznznJIq4Vn+7pJtDGcT1k4KY3EBOkFfD3hMVhScqQzHOZnLFWshaYY49cEYVwg+xjAGS3EVFnyyJwFDLUu1kZ2KLQ9ietIdwIBH8ssigPZOM/25ZUqS+oImcm99TV4Fwn7wyoJWyrmsHMaqtAvcpuwlHPE2zJ8wN9A5k6rwDgiQFHFcJQLvyz5PkgFygo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MNTz3aY5H9w7RMyMSEiUh/99yAuwZLipj31fN6Vhp6kPrL4SRm1NVA3mKc0nzk8BXrRoJGoFdyibv2szGPsy1PWgAjZL6z4E8We/tiEWjJsNr02wtxswakFBOaK6alBcr/5WpOWMUGpEHdEZiYf87FCPZjucJZaxupMA4542jFvfZTril6l5Sqmi3y/wYjdi4CU7eouLCd9Heh8NE64vpc3bGplOxsA6T+YWSEcXMiCjMcu3mappICe5UbgIInVaXxwsn0qJuGAYQ9h/VqWS3MbjYp0CrcgpEFCKVh5nCK+u6P53tnWne8Xv5PFZ4zOuAeA2QkSb8YT3z9pKJufG0n/sPgw+b1OvH7kTmHOetvwvmiKCFUpD6nuhP1QeQZ+1CHcN06YtVJrlOW2aqcpbot5de2vqF5ziiHlqyNa+C45o//fiBBAGKNcdlPcoCfXVEnKAUEHrkpixdsq9GVqs23iEy5VMHE3n1k4tmKxZXMUzkQ9ZJqd1YDEmYIMIGNRuChRrHqIDo+rEJoptiDbve1G20bWSzeoBQkQd46dbSdWpZHgZHQDUfQPBxbA9NJ9irH1S/iIo3M16ynC+9kJj4C5Ci5ol+eInzk98FGeCpdNJ9RU6y/ZHFBPMEv4rXPH6mK4FoE3hY+3ctGyClabZ8/k2iHn40qt8166xIGwwP2EbaFP3yjqFu0v8cZ8E1hZLvrioHy8lsYZ0kHG+6HJ5qPBHuNJj+1+kTrJI/3TQVeJx8xvk4zi7rCFEzRy2a4l0S0BHP3E302ClBt3fxzbbOPUDcRvO313wkabqToTRKgOBKyruJ/nYCG/qLoHTFOB3dYIljLeowf6m X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83d77c21-a597-420f-2df3-08dcf8783c16 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5848.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 00:17:27.4086 (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: DB4PR03MB10105 X-Patchwork-Delegate: bpf@iogearbox.net This patch adds struct file related CRIB kfuncs. 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. bpf_get_file_ops_type() is used to determine what exactly this file is based on the file operations, such as socket, eventfd, timerfd, pipe, etc, in order to perform different checkpoint/restore processing for different file types. This function currently has only one return value, FILE_OPS_UNKNOWN, but will increase with the file types that CRIB supports for checkpoint/restore. Signed-off-by: Juntong Deng --- kernel/bpf/crib/crib.c | 4 ++++ kernel/bpf/crib/files.c | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/kernel/bpf/crib/crib.c b/kernel/bpf/crib/crib.c index e6536ee9a845..78ddd19d5693 100644 --- a/kernel/bpf/crib/crib.c +++ b/kernel/bpf/crib/crib.c @@ -14,6 +14,10 @@ BTF_ID_FLAGS(func, bpf_iter_task_file_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_task_file_get_fd) BTF_ID_FLAGS(func, bpf_iter_task_file_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, bpf_fget_task, KF_ACQUIRE | KF_TRUSTED_ARGS | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_get_file_ops_type, KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_put_file, KF_RELEASE) + BTF_KFUNCS_END(bpf_crib_kfuncs) static const struct btf_kfunc_id_set bpf_crib_kfunc_set = { diff --git a/kernel/bpf/crib/files.c b/kernel/bpf/crib/files.c index ececf150303f..8e0e29877359 100644 --- a/kernel/bpf/crib/files.c +++ b/kernel/bpf/crib/files.c @@ -5,6 +5,14 @@ #include #include +/** + * This enum will grow with the file types that CRIB supports for + * checkpoint/restore. + */ +enum { + FILE_OPS_UNKNOWN = 0 +}; + struct bpf_iter_task_file { __u64 __opaque[3]; } __aligned(8); @@ -102,4 +110,40 @@ __bpf_kfunc void bpf_iter_task_file_destroy(struct bpf_iter_task_file *it) fput(kit->file); } +/** + * 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) +{ + struct file *file; + + file = fget_task(task, fd); + return file; +} + +/** + * bpf_get_file_ops_type() - Determine what exactly this file is based on + * the file operations, such as socket, eventfd, timerfd, pipe, etc + * + * This function will grow with the file types that CRIB supports for + * checkpoint/restore. + * + * @file: a pointer to the struct file + * + * @returns the file operations type + */ +__bpf_kfunc unsigned int bpf_get_file_ops_type(struct file *file) +{ + return FILE_OPS_UNKNOWN; +} + __bpf_kfunc_end_defs();