From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kui-Feng Lee <sinquersw@gmail.com>, Kui-Feng Lee <thinker.li@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, song@kernel.org,
kernel-team@meta.com, andrii@kernel.org, kuifeng@meta.com
Subject: Re: [PATCH bpf-next v4 3/7] bpf: support epoll from bpf struct_ops links.
Date: Thu, 23 May 2024 12:10:55 -0700 [thread overview]
Message-ID: <6570e32c-c3fc-4c2d-8ebb-f0080644cd13@linux.dev> (raw)
In-Reply-To: <d51165a1-c85f-4216-bb12-9615aee5f857@gmail.com>
On 5/23/24 12:03 PM, Kui-Feng Lee wrote:
>
>
> On 5/23/24 11:34, Martin KaFai Lau wrote:
>> On 5/23/24 11:24 AM, Kui-Feng Lee wrote:
>>>
>>>
>>> On 5/23/24 10:23, Martin KaFai Lau wrote:
>>>> On 5/21/24 3:51 PM, Kui-Feng Lee wrote:
>>>>> +static __poll_t bpf_link_poll(struct file *file, struct poll_table_struct
>>>>> *pts)
>>>>> +{
>>>>> + struct bpf_link *link = file->private_data;
>>>>> +
>>>>> + if (link->ops->poll)
>>>>> + return link->ops->poll(file, pts);
>>>>> +
>>>>> + return 0;
>>>>
>>>> The current bpf_link_fops.poll is NULL before this patch. From vfs_poll, it
>>>> seems to be DEFAULT_POLLMASK for this case. Please double check.
>>>
>>>
>>> Yes, it returns DEFAULT_POLLMASK if file->f_op->epoll is NULL. But,
>>> before this patch, link can not be added to an epoll. See the
>>> explanation below.
>>
>> How about select() and poll() that do not need epoll_ctl() setup?
>
> AFAIK, they just don't check it at all, calling vfs_poll() directly.
right, vfs_poll returns DEFAULT_POLLMASK which is not 0.
#define DEFAULT_POLLMASK (EPOLLIN | EPOLLOUT | EPOLLRDNORM | EPOLLWRNORM)
static inline __poll_t vfs_poll(struct file *file, struct poll_table_struct *pt)
{
if (unlikely(!file->f_op->poll))
return DEFAULT_POLLMASK;
return file->f_op->poll(file, pt);
}
but this discussion is moot if another file_operations instance is used.
>
>>
>>>
>>>>
>>>>> +}
>>>>> +
>>>>> static const struct file_operations bpf_link_fops = {
>>>>> #ifdef CONFIG_PROC_FS
>>>>> .show_fdinfo = bpf_link_show_fdinfo,
>>>>> @@ -3157,6 +3167,7 @@ static const struct file_operations bpf_link_fops = {
>>>>> .release = bpf_link_release,
>>>>> .read = bpf_dummy_read,
>>>>> .write = bpf_dummy_write,
>>>>> + .poll = bpf_link_poll,
>>>>
>>>> Same here. What does the epoll_ctl(EPOLL_CTL_ADD) currently expect for link
>>>> (e.g. cgroup) that does not support poll?
>>>>
>>>
>>> epoll_ctl() always returns -EPERM for files not supporting poll.
>>> Should I add another instance of struct file_operations to keep the
>>> consistency for other types of links?
>>
>> imo, it makes sense to have another instance for link that supports poll such
>> that epoll_ctl(EPOLL_CTL_ADD) can fail early for the unsupported links.
>
> Ok! I will add another instance.
next prev parent reply other threads:[~2024-05-23 19:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 22:51 [PATCH bpf-next v4 0/7] Notify user space when a struct_ops object is detached/unregistered Kui-Feng Lee
2024-05-21 22:51 ` [PATCH bpf-next v4 1/7] bpf: pass bpf_struct_ops_link to callbacks in bpf_struct_ops Kui-Feng Lee
2024-05-21 22:51 ` [PATCH bpf-next v4 2/7] bpf: enable detaching links of struct_ops objects Kui-Feng Lee
2024-05-23 18:09 ` Martin KaFai Lau
2024-05-23 18:28 ` Kui-Feng Lee
2024-05-21 22:51 ` [PATCH bpf-next v4 3/7] bpf: support epoll from bpf struct_ops links Kui-Feng Lee
2024-05-23 17:23 ` Martin KaFai Lau
2024-05-23 18:24 ` Kui-Feng Lee
2024-05-23 18:34 ` Martin KaFai Lau
2024-05-23 19:03 ` Kui-Feng Lee
2024-05-23 19:10 ` Martin KaFai Lau [this message]
2024-05-23 19:28 ` Kui-Feng Lee
2024-05-21 22:51 ` [PATCH bpf-next v4 4/7] bpf: export bpf_link_inc_not_zero Kui-Feng Lee
2024-05-21 22:51 ` [PATCH bpf-next v4 5/7] selftests/bpf: test struct_ops with epoll Kui-Feng Lee
2024-05-21 22:51 ` [PATCH bpf-next v4 6/7] selftests/bpf: detach a struct_ops link from the subsystem managing it Kui-Feng Lee
2024-05-21 22:51 ` [PATCH bpf-next v4 7/7] selftests/bpf: make sure bpf_testmod handling racing link destroying well Kui-Feng Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6570e32c-c3fc-4c2d-8ebb-f0080644cd13@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=sinquersw@gmail.com \
--cc=song@kernel.org \
--cc=thinker.li@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox