[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zz3AG0htZjt9RTFl@krava>
Date: Wed, 20 Nov 2024 11:55:23 +0100
From: Jiri Olsa <olsajiri@...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, memxor@...il.com,
snorcht@...il.com, brauner@...nel.org, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH bpf-next v4 1/5] bpf: Introduce task_file open-coded
iterator kfuncs
On Tue, Nov 19, 2024 at 05:53:58PM +0000, Juntong Deng wrote:
SNIP
> +/**
> + * bpf_iter_task_file_next() - Get the next file in bpf_iter_task_file
> + *
> + * bpf_iter_task_file_next acquires a reference to the struct file.
> + *
> + * The reference to struct file acquired by the previous
> + * bpf_iter_task_file_next() is released in the next bpf_iter_task_file_next(),
> + * and the last reference is released in the last bpf_iter_task_file_next()
> + * that returns NULL.
> + *
> + * @it: the bpf_iter_task_file to be checked
> + *
> + * @returns a pointer to bpf_iter_task_file_item
> + */
> +__bpf_kfunc struct bpf_iter_task_file_item *bpf_iter_task_file_next(struct bpf_iter_task_file *it)
> +{
> + struct bpf_iter_task_file_kern *kit = (void *)it;
> + struct bpf_iter_task_file_item *item = &kit->item;
> +
> + if (item->file)
> + fput(item->file);
> +
missing rcu_read_lock ?
jirka
> + item->file = task_lookup_next_fdget_rcu(item->task, &kit->next_fd);
> + item->fd = kit->next_fd;
> +
> + kit->next_fd++;
> +
> + if (!item->file)
> + return NULL;
> +
> + return item;
> +}
> +
> +/**
> + * bpf_iter_task_file_destroy() - Destroy a bpf_iter_task_file
> + *
> + * If the iterator does not iterate to the end, then the last
> + * struct file reference is released at this time.
> + *
> + * @it: the bpf_iter_task_file to be destroyed
> + */
> +__bpf_kfunc void bpf_iter_task_file_destroy(struct bpf_iter_task_file *it)
> +{
> + struct bpf_iter_task_file_kern *kit = (void *)it;
> + struct bpf_iter_task_file_item *item = &kit->item;
> +
> + if (item->file)
> + fput(item->file);
> +}
> +
> __bpf_kfunc_end_defs();
>
> DEFINE_PER_CPU(struct mmap_unlock_irq_work, mmap_unlock_work);
> --
> 2.39.5
>
Powered by blists - more mailing lists