Project

General

Profile

Actions

Bug #14005

closed

eventfd_read/write() don't return failure

Added by Andy Fiddaman 4 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
lib - userland libraries
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

While investigating a new test failure with Python 3.10, I found that our eventfd_read() function does not return a failure when the underlying read() returns -1 due to an unsigned comparison.

Here's a simple reproducer. With a non-blocking semaphore with an initial value of 2, the third read should fail with EAGAIN. It does not.


#include <stdio.h>
#include <sys/eventfd.h>
#include <errno.h>
#include <assert.h>

int
main()
{
        int fd = eventfd(2, EFD_NONBLOCK | EFD_CLOEXEC | EFD_SEMAPHORE);
        assert(fd >= 0);

        for (uint_t i = 0; i < 3; i++) {
                eventfd_t v = 0xdeadbeef;
                int ret = eventfd_read(fd, &v);
                printf("Ret: %d (errno %d, v %p)\n", ret, errno, v);
        }
}

Here's the output:

Ret: 0 (errno 0, v 1)
Ret: 0 (errno 0, v 1)
Ret: 0 (errno 11, v deadbeef)

With a bit of dtrace, one can see that the underlying read() is returning -1, and yet eventfd_read() is not:

%  pfexec dtrace -n 'pid$target::eventfd_read:return,syscall::read:return{trace(arg1)}' -c ./eventfd
  3   1338                      read:return                 8
  3  75386              eventfd_read:return                 0
  3   1338                      read:return                 8
  3  75386              eventfd_read:return                 0
  3   1338                      read:return                -1
  3  75386              eventfd_read:return                 0

Related issues

Related to illumos gate - Feature #6188: add support for eventfdClosedBryan Cantrill2015-08-31

Actions
Actions #1

Updated by Andy Fiddaman 4 months ago

Actions #2

Updated by Andy Fiddaman 4 months ago

  • Description updated (diff)
Actions #3

Updated by Andy Fiddaman 4 months ago

  • Description updated (diff)
Actions #4

Updated by Andy Fiddaman 4 months ago

  • Description updated (diff)
Actions #5

Updated by Andy Fiddaman 4 months ago

  • Description updated (diff)
Actions #6

Updated by Andy Fiddaman 4 months ago

Before the change in the associated Gerrit review, the new test program produces three errors:

bloody:illumos:ig_14005_eventfd% ./eventfd.64
eventfd.64: no semaphores read got ret 0 (expected -1)
eventfd.64: no semaphores read got ret 0 (expected -1)
eventfd.64: bad write got ret 0 (expected -1)

bloody:illumos:ig_14005_eventfd% ./eventfd.32
eventfd.32: no semaphores read got ret 0 (expected -1)
eventfd.32: no semaphores read got ret 0 (expected -1)
eventfd.32: bad write got ret 0 (expected -1)

and after, none:

The illumos Project     gate-ig_14005_eventfd-ce1e2c6b2bf       August 2021

bloody:illumos:ig_14005_eventfd% ./eventfd.32
bloody:illumos:ig_14005_eventfd% ./eventfd.64

The python 3.10rc1 os_tests module passes now too.

Actions #7

Updated by Andy Fiddaman 3 months ago

  • Gerrit CR set to 1642
Actions #8

Updated by Electric Monk 3 months ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

git commit d7159b37699523966f5e7af69b1bd84e2a084fa4

commit  d7159b37699523966f5e7af69b1bd84e2a084fa4
Author: Andy Fiddaman <omnios@citrus-it.co.uk>
Date:   2021-09-15T15:13:18.000Z

    14005 eventfd_read/write() don't return failure
    Reviewed by: Robert Mustacchi <rm@fingolfin.org>
    Reviewed by: Dan McDonald <danmcd@joyent.com>
    Approved by: Robert Mustacchi <rm@fingolfin.org>

Actions

Also available in: Atom PDF