On 1/22/20 9:20 AM, Jann Horn wrote: > On Wed, Jan 22, 2020 at 5:02 PM Jens Axboe <axboe@xxxxxxxxx> wrote: >> Also make it available outside of epoll, along with the helper that >> decides if we need to copy the passed in epoll_event. > [...] >> diff --git a/fs/eventpoll.c b/fs/eventpoll.c >> index cd848e8d08e2..162af749ea50 100644 >> --- a/fs/eventpoll.c >> +++ b/fs/eventpoll.c > [...] >> -static int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds) >> +static inline int epoll_mutex_lock(struct mutex *mutex, int depth, >> + bool nonblock) >> +{ >> + if (!nonblock) { >> + mutex_lock_nested(mutex, depth); >> + return 0; >> + } >> + if (!mutex_trylock(mutex)) >> + return 0; >> + return -EAGAIN; > > The documentation for mutex_trylock() says: > > * Try to acquire the mutex atomically. Returns 1 if the mutex > * has been acquired successfully, and 0 on contention. > > So in the success case, this evaluates to: > > if (!1) > return 0; > return -EAGAIN; > > which is > > if (0) > return 0; > return -EAGAIN; > > which is > > return -EAGAIN; > > I think you'll have to get rid of the negation. Doh indeed. I'll rework and run the test case, just rebased this and I think I inadvertently used an older version. Ditto for the below. -- Jens Axboe