Skip to contentSkip to conversation

Polling on an io_uring file descriptor

DISCUSSION Drew DeVault 2 participants 9 messages Oct 20, 2021 – Oct 22, 2021 io_uring

lore
Share & tools
lore
#0 lore raw

I would like to poll on an io_uring file descriptor to be notified when CQE's are available, either via poll(2) or IORING_OP_POLL_ADD. This doesn't seem to work on 5.10. Is this feasible to add support for?

#1 lore raw

I found IOURING_REGISTER_EVENTFD, which does what I need. Pardon the noise.

#2 lore raw
In reply to Drew DeVault
Quoted 3 lines · Drew DeVault

I would like to poll on an io_uring file descriptor to be notified when CQE's are available, either via poll(2) or IORING_OP_POLL_ADD. This doesn't seem to work on 5.10. Is this feasible to add support for?

Not a canonical way, but both should work (POLLIN for CQEs). Do you have a simple test case for us to reproduce?

Signature · 1 line
Pavel Begunkov
#3 lore raw
Quoted 2 lines · Pavel Begunkov

Not a canonical way, but both should work (POLLIN for CQEs). Do you have a simple test case for us to reproduce?

Hm, no, I cannot. I must have faced another bug, I was not able to produce a minimal test case and my attempt to reproduce my earlier bug in a larger test case was not succesful.

One issue which remains is that attempting to use REGISTER_FILES on io_uring A with io_uring B's file descriptor returns EBADF. I saw a comment in the kernel source explaining this, but it's a bit contrived and the error case is not documented.

#4 lore raw
Quoted 7 lines · Drew DeVault
Quoted 2 lines · Pavel Begunkov

Not a canonical way, but both should work (POLLIN for CQEs). Do you have a simple test case for us to reproduce?

Hm, no, I cannot. I must have faced another bug, I was not able to produce a minimal test case and my attempt to reproduce my earlier bug in a larger test case was not succesful.

Sounds like polling is ok, let us know if there is any problem

Quoted 5 lines

One issue which remains is that attempting to use REGISTER_FILES on io_uring A with io_uring B's file descriptor returns EBADF. I saw a comment in the kernel source explaining this, but it's a bit contrived and the error case is not documented.

Surely should be updated if not mentioned

Signature · 1 line
Pavel Begunkov
#5 lore raw
Quoted 6 lines · Pavel Begunkov
Quoted 4 lines

One issue which remains is that attempting to use REGISTER_FILES on io_uring A with io_uring B's file descriptor returns EBADF. I saw a comment in the kernel source explaining this, but it's a bit contrived and the error case is not documented.

Surely should be updated if not mentioned

That, or the constraint removed? The reasoning is a bit obscure and I suspect that this case could be made possible.

#6 lore raw
Quoted 4 lines · Drew DeVault
Quoted 1 line

Surely should be updated if not mentioned

That, or the constraint removed? The reasoning is a bit obscure and I suspect that this case could be made possible.

So I dug into this a bit more, and the constraint seems to be to avoid a reference loop when CONFIG_UNIX=n. I grepped Google and SourceGraph for "CONFIG_UNIX=n" and only found two kernel configs with Unix sockets disabled, neither of which had io_uring enabled. Given the rather arbitrary restriction on registering io_urings with each other, and the apparent absence of a use-case for io_uring without Unix sockets, can we just require CONFIG_UNIX for io_uring and remove the limitation?

#7 lore raw
Quoted 6 lines · Drew DeVault
Quoted 4 lines · Drew DeVault
Quoted 1 line

Surely should be updated if not mentioned

That, or the constraint removed? The reasoning is a bit obscure and I suspect that this case could be made possible.

Quoted 7 lines

So I dug into this a bit more, and the constraint seems to be to avoid a reference loop when CONFIG_UNIX=n. I grepped Google and SourceGraph for "CONFIG_UNIX=n" and only found two kernel configs with Unix sockets disabled, neither of which had io_uring enabled. Given the rather arbitrary restriction on registering io_urings with each other, and the apparent absence of a use-case for io_uring without Unix sockets, can we just require CONFIG_UNIX for io_uring and remove the limitation?

It's potentially problematic, even now we have a couple of other spots relying on it. Is there a good reason why it's needed?

Signature · 1 line
Pavel Begunkov
#8 lore raw
Quoted 2 lines · Pavel Begunkov

It's potentially problematic, even now we have a couple of other spots relying on it. Is there a good reason why it's needed?

Yes, I have an application which uses one io_uring to manage a second io_uring. I can skip registering the fd (current approach) or I can use a different mechanism for managing the second uring (e.g. poll), but it seems awkward and poorly justified that this invariant would exist.