The branch main has been updated by emaste:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=2bdde76281130e8d2c4579f289179da44782cf85

commit 2bdde76281130e8d2c4579f289179da44782cf85
Author:     lin <[email protected]>
AuthorDate: 2026-12-03 01:17:51 +0000
Commit:     Ed Maste <[email protected]>
CommitDate: 2026-12-04 17:09:25 +0000

    linux(4): accept EPOLLOUT on inotify, timerfd and epoll descriptors
    
    On Linux, epoll_ctl() accepts any event mask on a pollable file; a
    descriptor that can never become writable simply never reports
    EPOLLOUT.  We turn EPOLLOUT into an EVFILT_WRITE knote, but inotify,
    timerfd and kqueue descriptors only support EVFILT_READ, so the call
    fails with EINVAL.
    
    Go's runtime registers every non-blocking descriptor with
    EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET.  When that fails for an inotify
    descriptor, fsnotify ends up reading it in a loop that only ever gets
    EAGAIN.  With a Go CLI tool under the Linuxulator this kept about eight
    cores busy per idle process and wrote megabytes of error logs per
    second.  Because the read knote is added before the write knote fails,
    the descriptor was also left half registered, and a later
    EPOLL_CTL_ADD returned EEXIST.
    
    Drop the write bits for these three descriptor types before building
    the kevents, so the registration succeeds and only read readiness is
    reported, as on Linux.
    
    MFC after:      1 week
    Signed-off-by:  lin <[email protected]>
    PR:             300076
    Reviewed by:    emaste, imp, markj
    Pull request:   https://github.com/freebsd/freebsd-src/pull/2606
---
 sys/compat/linux/linux_event.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sys/compat/linux/linux_event.c b/sys/compat/linux/linux_event.c
index f85f7dd9b6cd..bde15c6500ef 100644
--- a/sys/compat/linux/linux_event.c
+++ b/sys/compat/linux/linux_event.c
@@ -323,6 +323,20 @@ linux_epoll_ctl(struct thread *td, struct 
linux_epoll_ctl_args *args)
        ciargs.changelist = kev;
 
        if (args->op != LINUX_EPOLL_CTL_DEL) {
+               switch (fp->f_type) {
+               case DTYPE_INOTIFY:
+               case DTYPE_TIMERFD:
+               case DTYPE_KQUEUE:
+                       /*
+                        * Linux accepts interests in readiness these
+                        * descriptors cannot report; they only ever
+                        * report read readiness.
+                        */
+                       le.events &= ~LINUX_EPOLL_EVWR;
+                       break;
+               default:
+                       break;
+               }
                error = epoll_to_kevent(td, args->fd, &le, kev, &nchanges);
                if (error != 0)
                        goto leave0;

Reply via email to