Skip to contentSkip to conversation

linux-user: fix eventfd()

PATCH Applied Laurent Vivier 2 participants 5 messages Mar 1, 2017 – May 19, 2017

lore
Share & tools
lore
#0 lore raw

cover linux-user: fix eventfd()

This patch series byte-swap the uint64_t data stream of a file-descriptor opened with eventfd().

It allows to pass more LTP test cases:

eventfd01    1  TPASS  :  counter value matches required
eventfd01    2  TPASS  :  read failed with EAGAIN as expected
eventfd01    3  TPASS  :  counter value matches required
eventfd01    4  TPASS  :  write failed with EAGAIN as expected
eventfd01    5  TPASS  :  read failed with EINVAL as expected
eventfd01    6  TPASS  :  write failed with EINVAL as expected
eventfd01    7  TPASS  :  write failed with EINVAL as expected
eventfd01    8  TPASS  :  fd is set in readfds
eventfd01    9  TPASS  :  fd is not set in readfds
eventfd01   10  TPASS  :  fd is set in writefds
eventfd01   11  TPASS  :  fd is not set in writefds
eventfd01    1  TPASS  :  counter value matches required
eventfd01    2  TPASS  :  read failed with EAGAIN as expected
eventfd01    3  TPASS  :  counter value matches required
eventfd01    4  TPASS  :  write failed with EAGAIN as expected
eventfd01    5  TPASS  :  read failed with EINVAL as expected
eventfd01    6  TPASS  :  write failed with EINVAL as expected
eventfd01    7  TPASS  :  write failed with EINVAL as expected
eventfd01    8  TPASS  :  fd is set in readfds
eventfd01    9  TPASS  :  fd is not set in readfds
eventfd01   10  TPASS  :  fd is set in writefds
eventfd01   11  TPASS  :  fd is not set in writefds
eventfd01   12  TPASS  :  counter value write from child successful
eventfd01   13  TCONF  :  eventfd01.c:642: eventfd support is not available in AIO subsystem
eventfd01   14  TCONF  :  eventfd01.c:647: eventfd support is not available in AIO subsystem
eventfd01   15  TCONF  :  eventfd01.c:652: eventfd support is not available in AIO subsystem

Laurent Vivier (2):
linux-user: call fd_trans_target_to_host_data() for write()
linux-user: fix eventfd

 linux-user/syscall.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/2 linux-user: call fd_trans_target_to_host_data() for write()

As for sendmsg() or sendto(), we must call the target to host data translator if it is defined. This is needed for eventfd(): the write() syscall allows to add a value to the internal counter, and so, it must be byte-swapped to the host order.

---
 linux-user/syscall.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
linux-user/syscall.c +11 -1
index cec8428..b2b563e 100644
@@ -7767,7 +7767,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_write:
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
             goto efault;
-        ret = get_errno(safe_write(arg1, p, arg3));
+        if (fd_trans_target_to_host_data(arg1)) {
+            void *copy = g_malloc(arg3);
+            memcpy(copy, p, arg3);
+            ret = fd_trans_target_to_host_data(arg1)(copy, arg3);
+            if (ret >= 0) {
+                ret = get_errno(safe_write(arg1, copy, ret));
+            }
+            g_free(copy);
+        } else {
+            ret = get_errno(safe_write(arg1, p, arg3));
+        }
         unlock_user(p, arg2, 0);
         break;
 #ifdef TARGET_NR_open
Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/2 linux-user: fix eventfd

In reply to Laurent Vivier

When a fd is opened using eventfd(), a read provides a 64bit counter in the host byte order, and a write increase the internal counter by the provided 64bit value.

---
 linux-user/syscall.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
linux-user/syscall.c +24 -2
index b2b563e..2da8426 100644
@@ -7671,6 +7671,28 @@ static target_timer_t get_timer_id(abi_long arg)
     return timerid;
 }
 
+static abi_long swap_data_eventfd(void *buf, size_t len)
+{
+    uint64_t *counter = buf;
+    int i;
+
+    if (len < sizeof(uint64_t)) {
+        return -EINVAL;
+    }
+
+    for (i = 0; i < len; i += sizeof(uint64_t)) {
+        *counter = tswap64(*counter);
+        counter++;
+    }
+
+    return len;
+}
+
+static TargetFdTrans target_eventfd_trans = {
+    .host_to_target_data = swap_data_eventfd,
+    .target_to_host_data = swap_data_eventfd,
+};
+
 /* do_syscall() should always have a single exit point at the end so
    that actions, such as logging of syscall results, can be performed.
    All errnos that do_syscall() returns must be -TARGET_<errcode>. */
@@ -11876,7 +11898,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #if defined(TARGET_NR_eventfd)
     case TARGET_NR_eventfd:
         ret = get_errno(eventfd(arg1, 0));
-        fd_trans_unregister(ret);
+        fd_trans_register(ret, &target_eventfd_trans);
         break;
 #endif
 #if defined(TARGET_NR_eventfd2)
@@ -11890,7 +11912,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             host_flags |= O_CLOEXEC;
         }
         ret = get_errno(eventfd(arg1, host_flags));
-        fd_trans_unregister(ret);
+        fd_trans_register(ret, &target_eventfd_trans);
         break;
     }
 #endif
Signature · 1 line
2.9.3
#3 lore raw
In reply to Laurent Vivier

Ping?

Laurent

Quoted 39 lines · Laurent Vivier

This patch series byte-swap the uint64_t data stream of a file-descriptor opened with eventfd().

It allows to pass more LTP test cases:

eventfd01    1  TPASS  :  counter value matches required
eventfd01    2  TPASS  :  read failed with EAGAIN as expected
eventfd01    3  TPASS  :  counter value matches required
eventfd01    4  TPASS  :  write failed with EAGAIN as expected
eventfd01    5  TPASS  :  read failed with EINVAL as expected
eventfd01    6  TPASS  :  write failed with EINVAL as expected
eventfd01    7  TPASS  :  write failed with EINVAL as expected
eventfd01    8  TPASS  :  fd is set in readfds
eventfd01    9  TPASS  :  fd is not set in readfds
eventfd01   10  TPASS  :  fd is set in writefds
eventfd01   11  TPASS  :  fd is not set in writefds
eventfd01    1  TPASS  :  counter value matches required
eventfd01    2  TPASS  :  read failed with EAGAIN as expected
eventfd01    3  TPASS  :  counter value matches required
eventfd01    4  TPASS  :  write failed with EAGAIN as expected
eventfd01    5  TPASS  :  read failed with EINVAL as expected
eventfd01    6  TPASS  :  write failed with EINVAL as expected
eventfd01    7  TPASS  :  write failed with EINVAL as expected
eventfd01    8  TPASS  :  fd is set in readfds
eventfd01    9  TPASS  :  fd is not set in readfds
eventfd01   10  TPASS  :  fd is set in writefds
eventfd01   11  TPASS  :  fd is not set in writefds
eventfd01   12  TPASS  :  counter value write from child successful
eventfd01   13  TCONF  :  eventfd01.c:642: eventfd support is not available in AIO subsystem
eventfd01   14  TCONF  :  eventfd01.c:647: eventfd support is not available in AIO subsystem
eventfd01   15  TCONF  :  eventfd01.c:652: eventfd support is not available in AIO subsystem

Laurent Vivier (2):
linux-user: call fd_trans_target_to_host_data() for write()
linux-user: fix eventfd

 linux-user/syscall.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
Applied
#4 lore raw
Quoted 1 line · Laurent Vivier

Ping?

Applied, thanks.

Quoted 43 lines

Laurent

Quoted 39 lines · Laurent Vivier

This patch series byte-swap the uint64_t data stream of a file-descriptor opened with eventfd().

It allows to pass more LTP test cases:

eventfd01    1  TPASS  :  counter value matches required
eventfd01    2  TPASS  :  read failed with EAGAIN as expected
eventfd01    3  TPASS  :  counter value matches required
eventfd01    4  TPASS  :  write failed with EAGAIN as expected
eventfd01    5  TPASS  :  read failed with EINVAL as expected
eventfd01    6  TPASS  :  write failed with EINVAL as expected
eventfd01    7  TPASS  :  write failed with EINVAL as expected
eventfd01    8  TPASS  :  fd is set in readfds
eventfd01    9  TPASS  :  fd is not set in readfds
eventfd01   10  TPASS  :  fd is set in writefds
eventfd01   11  TPASS  :  fd is not set in writefds
eventfd01    1  TPASS  :  counter value matches required
eventfd01    2  TPASS  :  read failed with EAGAIN as expected
eventfd01    3  TPASS  :  counter value matches required
eventfd01    4  TPASS  :  write failed with EAGAIN as expected
eventfd01    5  TPASS  :  read failed with EINVAL as expected
eventfd01    6  TPASS  :  write failed with EINVAL as expected
eventfd01    7  TPASS  :  write failed with EINVAL as expected
eventfd01    8  TPASS  :  fd is set in readfds
eventfd01    9  TPASS  :  fd is not set in readfds
eventfd01   10  TPASS  :  fd is set in writefds
eventfd01   11  TPASS  :  fd is not set in writefds
eventfd01   12  TPASS  :  counter value write from child successful
eventfd01   13  TCONF  :  eventfd01.c:642: eventfd support is not available in AIO subsystem
eventfd01   14  TCONF  :  eventfd01.c:647: eventfd support is not available in AIO subsystem
eventfd01   15  TCONF  :  eventfd01.c:652: eventfd support is not available in AIO subsystem

Laurent Vivier (2):
linux-user: call fd_trans_target_to_host_data() for write()
linux-user: fix eventfd

 linux-user/syscall.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)