linux-user: fix eventfd()
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
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
@@ -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
PATCH 2/2 linux-user: fix eventfd
In reply to Laurent VivierWhen 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
@@ -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
Ping?
Laurent
Quoted 39 lines · Laurent Vivier
This patch series byte-swap the
uint64_tdata stream of a file-descriptor opened witheventfd().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 subsystemLaurent Vivier (2):
linux-user: callfd_trans_target_to_host_data()forwrite()
linux-user: fix eventfdlinux-user/syscall.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
Riku Voipio
AppliedQuoted 1 line · Laurent Vivier
Ping?
Applied, thanks.
Quoted 43 lines
Laurent
Quoted 39 lines · Laurent Vivier
This patch series byte-swap the
uint64_tdata stream of a file-descriptor opened witheventfd().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 subsystemLaurent Vivier (2):
linux-user: callfd_trans_target_to_host_data()forwrite()
linux-user: fix eventfdlinux-user/syscall.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)