[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzadfF8iSAnhWFDNmXE80ayJXDkucbeg0jv-+=FtoDg5Zg@mail.gmail.com>
Date: Fri, 1 Nov 2024 12:08:53 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Juntong Deng <juntong.deng@...look.com>
Cc: ast@...nel.org, daniel@...earbox.net, john.fastabend@...il.com,
andrii@...nel.org, martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
yonghong.song@...ux.dev, kpsingh@...nel.org, sdf@...ichev.me,
haoluo@...gle.com, jolsa@...nel.org, memxor@...il.com, snorcht@...il.com,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
Christian Brauner <brauner@...nel.org>, Linux-Fsdevel <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH bpf-next v2 3/4] bpf/crib: Add struct file related CRIB kfuncs
On Tue, Oct 29, 2024 at 5:17 PM Juntong Deng <juntong.deng@...look.com> wrote:
>
> 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 <juntong.deng@...look.com>
> ---
> kernel/bpf/crib/crib.c | 4 ++++
> kernel/bpf/crib/files.c | 44 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 48 insertions(+)
>
Please CC Christian Brauner and fs mailing list
(linux-fsdevel@...r.kernel.org, both cc'ed) on changes like this (this
entire patch set)
> 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 <linux/fdtable.h>
> #include <linux/net.h>
>
> +/**
> + * 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;
> +}
> +
this is not very supportable, users can do the same by accessing
file->f_op and comparing it to a set of known struct file_operations
references.
> __bpf_kfunc_end_defs();
> --
> 2.39.5
>
Powered by blists - more mailing lists