fcntl, sockopt, and ioctl options
cover fcntl, sockopt, and ioctl options
Hi Laurent,
This is a series of 6 patches in 4 groups, putting into a single thread for easier tracking.
[PATCH 1/6] linux-user: Support F_ADD_SEALS and F_GET_SEALS fcntls
An incidental follow up on
https://lists.nongnu.org/archive/html/qemu-devel/2019-09/msg01925.html
[PATCH 2/6] linux-user: add missing UDP and IPv6 get/setsockopt
Updated https://lists.nongnu.org/archive/html/qemu-devel/2019-09/msg01317.html
to consistently add them in get/setsockopt
[PATCH 3/6] linux-user: Update SO_TIMESTAMP to SO_TIMESTAMP_OLD/NEW [PATCH 4/6] linux-user: setsockopt() SO_TIMESTAMPNS and SO_TIMESTAMPING
Updated https://lists.nongnu.org/archive/html/qemu-devel/2019-09/msg01319.html
to only use TARGET_SO_*_OLD/NEW
[PATCH 5/6] thunk: supports flexible arrays
[PATCH 6/6] linux-user: Add support for SIOCETHTOOL ioctl
Updated https://lists.nongnu.org/archive/html/qemu-devel/2019-08/msg05090.html
Shu-Chun Weng (6):
linux-user: Support F_ADD_SEALS and F_GET_SEALS fcntls
linux-user: add missing UDP and IPv6 get/setsockopt options
linux-user: Update SO_TIMESTAMP to SO_TIMESTAMP_OLD/NEW
linux-user: setsockopt() SO_TIMESTAMPNS and SO_TIMESTAMPING
thunk: supports flexible arrays
linux-user: Add support for SIOCETHTOOL ioctl
include/exec/user/thunk.h | 20 + linux-user/Makefile.objs | 3 +- linux-user/alpha/sockbits.h | 21 +- linux-user/ethtool.c | 819 +++++++++++++++++++++++++ linux-user/ethtool.h | 19 + linux-user/ethtool_entries.h | 107 ++++ linux-user/fd-trans.h | 41 +- linux-user/generic/sockbits.h | 17 +- linux-user/hppa/sockbits.h | 20 +- linux-user/ioctls.h | 2 + linux-user/mips/sockbits.h | 16 +- linux-user/qemu.h | 1 + linux-user/sparc/sockbits.h | 21 +- linux-user/strace.c | 19 +- linux-user/syscall.c | 233 ++++++- linux-user/syscall_defs.h | 26 +- linux-user/syscall_types.h | 277 +++++++++ tests/tcg/multiarch/ethtool.c | 417 +++++++++++++ tests/tcg/multiarch/socket_timestamp.c | 542 ++++++++++++++++ thunk.c | 151 ++++- 20 files changed, 2706 insertions(+), 66 deletions(-) create mode 100644 linux-user/ethtool.c create mode 100644 linux-user/ethtool.h create mode 100644 linux-user/ethtool_entries.h create mode 100644 tests/tcg/multiarch/ethtool.c create mode 100644 tests/tcg/multiarch/socket_timestamp.c
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH 1/6 linux-user: Support F_ADD_SEALS and F_GET_SEALS fcntls
--- linux-user/syscall.c | 10 ++++++++++ linux-user/syscall_defs.h | 14 ++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-)
linux-user/syscall.c +10 -0
@@ -6312,6 +6312,14 @@ static int target_to_host_fcntl_cmd(int cmd)case TARGET_F_GETPIPE_SZ : ret =F_GETPIPE_SZ ;break ; +#endif +#ifdef F_ADD_SEALS +case TARGET_F_ADD_SEALS : + ret =F_ADD_SEALS ; +break ; +case TARGET_F_GET_SEALS : + ret =F_GET_SEALS ; +break ;#endif default : ret = -TARGET_EINVAL ;
@@ -6598,6 +6606,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)case TARGET_F_GETLEASE :case TARGET_F_SETPIPE_SZ :case TARGET_F_GETPIPE_SZ : +case TARGET_F_ADD_SEALS : +case TARGET_F_GET_SEALS : ret =get_errno (safe_fcntl (fd, host_cmd, arg));break ;
linux-user/syscall_defs.h +8 -6
@@ -2292,12 +2292,14 @@ struct target_statfs64 {#endif #define TARGET_F_LINUX_SPECIFIC_BASE 1024 -#define TARGET_F_SETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 0) -#define TARGET_F_GETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 1) -#define TARGET_F_DUPFD_CLOEXEC (TARGET_F_LINUX_SPECIFIC_BASE + 6) -#define TARGET_F_SETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 7) -#define TARGET_F_GETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 8) -#define TARGET_F_NOTIFY (TARGET_F_LINUX_SPECIFIC_BASE+2) +#define TARGET_F_SETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 0) +#define TARGET_F_GETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 1) +#define TARGET_F_DUPFD_CLOEXEC (TARGET_F_LINUX_SPECIFIC_BASE + 6) +#define TARGET_F_NOTIFY (TARGET_F_LINUX_SPECIFIC_BASE + 2) +#define TARGET_F_SETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 7) +#define TARGET_F_GETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 8) +#define TARGET_F_ADD_SEALS (TARGET_F_LINUX_SPECIFIC_BASE + 9) +#define TARGET_F_GET_SEALS (TARGET_F_LINUX_SPECIFIC_BASE + 10)#include "target_fcntl.h"
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH 1/6] linux-user: Support F_ADD_SEALS and F_GET_SEALS fcntls
Le 23/07/2020 à 02:19, Shu-Chun Weng a écrit :
Quoted 50 lines
Signed-off-by Shu-Chun Weng <[email protected]>--- linux-user/syscall.c | 10 ++++++++++ linux-user/syscall_defs.h | 14 ++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-)linux-user/syscall.c +10
-0@@ -6312,6 +6312,14 @@ static int target_to_host_fcntl_cmd(int cmd)case TARGET_F_GETPIPE_SZ : ret =F_GETPIPE_SZ ;break ; +#endif +#ifdef F_ADD_SEALS +case TARGET_F_ADD_SEALS : + ret =F_ADD_SEALS ; +break ; +case TARGET_F_GET_SEALS : + ret =F_GET_SEALS ; +break ;#endif default : ret = -TARGET_EINVAL ;@@ -6598,6 +6606,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)case TARGET_F_GETLEASE :case TARGET_F_SETPIPE_SZ :case TARGET_F_GETPIPE_SZ : +case TARGET_F_ADD_SEALS : +case TARGET_F_GET_SEALS : ret =get_errno (safe_fcntl (fd, host_cmd, arg));break ;linux-user/syscall_defs.h +1
-6@@ -2292,12 +2292,14 @@ struct target_statfs64 {#endif #define TARGET_F_LINUX_SPECIFIC_BASE 1024 -#define TARGET_F_SETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 0) -#define TARGET_F_GETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 1) -#define TARGET_F_DUPFD_CLOEXEC (TARGET_F_LINUX_SPECIFIC_BASE + 6) -#define TARGET_F_SETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 7) -#define TARGET_F_GETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 8) -#define TARGET_F_NOTIFY (TARGET_F_LINUX_SPECIFIC_BASE+2) +#define TARGET_F_SETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 0)
linux-user/syscall_defs.h struct target_statfs64 { · line 2305
Quoted 10 lines
linux-user/syscall_defs.h +7
-0+#define TARGET_F_GETLEASE (TARGET_F_LINUX_SPECIFIC_BASE + 1) +#define TARGET_F_DUPFD_CLOEXEC (TARGET_F_LINUX_SPECIFIC_BASE + 6) +#define TARGET_F_NOTIFY (TARGET_F_LINUX_SPECIFIC_BASE + 2) +#define TARGET_F_SETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 7) +#define TARGET_F_GETPIPE_SZ (TARGET_F_LINUX_SPECIFIC_BASE + 8) +#define TARGET_F_ADD_SEALS (TARGET_F_LINUX_SPECIFIC_BASE + 9) +#define TARGET_F_GET_SEALS (TARGET_F_LINUX_SPECIFIC_BASE + 10)#include "target_fcntl.h"
Looks good. Please also update print_fcntl() in linux-user/strace.c
Thanks,
Laurent
PATCH 2/6 linux-user: add missing UDP and IPv6 get/setsockopt options
In reply to Shu-Chun WengUDP: SOL_UDP manipulate options at UDP level. All six options currently defined in linux source include/uapi/linux/udp.h take integer values.
IPv6: IPV6_ADDR_PREFERENCES (RFC5014: Source address selection) was not supported.
--- linux-user/syscall.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
linux-user/syscall.c +8 -2
@@ -51,8 +51,10 @@#include <sys/sysinfo.h> #include <sys/signalfd.h> //#include <sys/user.h> +#include <netinet/in.h> #include <netinet/ip.h> #include <netinet/tcp.h> +#include <netinet/udp.h> #include <linux/wireless.h> #include <linux/icmp.h> #include <linux/icmpv6.h>
@@ -1945,7 +1947,8 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,switch (level) {case SOL_TCP : -/* TCP options all take an 'int' value. */ +case SOL_UDP : +/* TCP and UDP options all take an 'int' value. */ if (optlen <sizeof (uint32_t ))return -TARGET_EINVAL ;
@@ -2031,6 +2034,7 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,case IPV6_RECVDSTOPTS :case IPV6_2292DSTOPTS :case IPV6_TCLASS : +case IPV6_ADDR_PREFERENCES :#ifdef IPV6_RECVPATHMTU case IPV6_RECVPATHMTU :#endif
@@ -2593,7 +2597,8 @@ get_timeout: }break ;case SOL_TCP : -/* TCP options all take an 'int' value. */ +case SOL_UDP : +/* TCP and UDP options all take an 'int' value. */ int_case:if (get_user_u32 (len, optlen))return -TARGET_EFAULT ;
@@ -2684,6 +2689,7 @@ get_timeout:case IPV6_RECVDSTOPTS :case IPV6_2292DSTOPTS :case IPV6_TCLASS : +case IPV6_ADDR_PREFERENCES :#ifdef IPV6_RECVPATHMTU case IPV6_RECVPATHMTU :#endif
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH 2/6] linux-user: add missing UDP and IPv6 get/setsockopt options
Le 23/07/2020 à 02:19, Shu-Chun Weng a écrit :
Quoted 10 lines
UDP:
SOL_UDPmanipulate options at UDP level. All six options currently defined in linux sourceinclude/uapi/linux/udp.htake integer values.IPv6:
IPV6_ADDR_PREFERENCES(RFC5014: Source address selection) was not supported.Signed-off-by Shu-Chun Weng <[email protected]>--- linux-user/syscall.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
This might be really clearer if you split this patch in two: one to add SOL_UDP and one to add IPV6_ADDR_PREFERENCES.
Also update do_print_sockopt() in linux-use/strace.c
With that done, you can add my "Reviewed-by: Laurent Vivier <[email protected]>" to both.
Thanks,
Laurent
PATCH 3/6 linux-user: Update SO_TIMESTAMP to SO_TIMESTAMP_OLD/NEW
In reply to Shu-Chun WengBoth guest options map to host SO_TIMESTAMP while keeping a bit in fd_trans to remember if the guest expects the old or the new format.
Added a multiarch test to verify.
--- linux-user/alpha/sockbits.h | 8 +- linux-user/fd-trans.h | 41 +++- linux-user/generic/sockbits.h | 9 +- linux-user/hppa/sockbits.h | 8 +- linux-user/mips/sockbits.h | 8 +- linux-user/sparc/sockbits.h | 8 +- linux-user/strace.c | 7 +- linux-user/syscall.c | 69 ++++-- tests/tcg/multiarch/socket_timestamp.c | 292 +++++++++++++++++++++++++ 9 files changed, 419 insertions(+), 31 deletions(-) create mode 100644 tests/tcg/multiarch/socket_timestamp.c
linux-user/alpha/sockbits.h +6 -2
@@ -48,8 +48,6 @@#define TARGET_SO_DETACH_FILTER 27#define TARGET_SO_PEERNAME 28 -#define TARGET_SO_TIMESTAMP 29 -#define TARGET_SCM_TIMESTAMP TARGET_SO_TIMESTAMP#define TARGET_SO_PEERSEC 30#define TARGET_SO_PASSSEC 34
@@ -75,6 +73,12 @@/* Instruct lower device to use last 4-bytes of skb data as FCS */ #define TARGET_SO_NOFCS 43 +#define TARGET_SO_TIMESTAMP_OLD 29 +#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD + +#define TARGET_SO_TIMESTAMP_NEW 63 +#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +/* TARGET_O_NONBLOCK clashes with the bits used for socket types. Therefore we * have to define SOCK_NONBLOCK to a different value here. */
linux-user/fd-trans.h +40 -1
66 lines not on this page · raw message
linux-user/generic/sockbits.h +7 -2
@@ -49,10 +49,15 @@#define TARGET_SO_DETACH_FILTER 27#define TARGET_SO_PEERNAME 28 -#define TARGET_SO_TIMESTAMP 29 -#define TARGET_SCM_TIMESTAMP TARGET_SO_TIMESTAMP#define TARGET_SO_ACCEPTCONN 30#define TARGET_SO_PEERSEC 31 + +#define TARGET_SO_TIMESTAMP_OLD 29 +#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD + +#define TARGET_SO_TIMESTAMP_NEW 63 +#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +#endif
linux-user/hppa/sockbits.h +6 -2
@@ -29,8 +29,6 @@#define TARGET_SO_BSDCOMPAT 0x400e#define TARGET_SO_PASSCRED 0x4010#define TARGET_SO_PEERCRED 0x4011 -#define TARGET_SO_TIMESTAMP 0x4012 -#define TARGET_SCM_TIMESTAMP TARGET_SO_TIMESTAMP#define TARGET_SO_TIMESTAMPNS 0x4013#define TARGET_SCM_TIMESTAMPNS TARGET_SO_TIMESTAMPNS
@@ -67,6 +65,12 @@#define TARGET_SO_CNX_ADVICE 0x402E +#define TARGET_SO_TIMESTAMP_OLD 0x4012 +#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD + +#define TARGET_SO_TIMESTAMP_NEW 0x4038 +#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +/* TARGET_O_NONBLOCK clashes with the bits used for socket types. Therefore we * have to define SOCK_NONBLOCK to a different value here. */
linux-user/mips/sockbits.h +6 -2
@@ -61,14 +61,18 @@#define TARGET_SO_DETACH_FILTER 27#define TARGET_SO_PEERNAME 28 -#define TARGET_SO_TIMESTAMP 29 -#define SCM_TIMESTAMP SO_TIMESTAMP#define TARGET_SO_PEERSEC 30#define TARGET_SO_SNDBUFFORCE 31#define TARGET_SO_RCVBUFFORCE 33#define TARGET_SO_PASSSEC 34 +#define TARGET_SO_TIMESTAMP_OLD 29 +#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD + +#define TARGET_SO_TIMESTAMP_NEW 63 +#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +/** sock_type - Socket types * * Please notice that for binary compat reasons MIPS has to
linux-user/sparc/sockbits.h +6 -2
@@ -48,8 +48,6 @@#define TARGET_SO_GET_FILTER TARGET_SO_ATTACH_FILTER#define TARGET_SO_PEERNAME 0x001c -#define TARGET_SO_TIMESTAMP 0x001d -#define TARGET_SCM_TIMESTAMP TARGET_SO_TIMESTAMP#define TARGET_SO_PEERSEC 0x001e#define TARGET_SO_PASSSEC 0x001f
@@ -104,6 +102,12 @@#define TARGET_SO_ZEROCOPY 0x003e +#define TARGET_SO_TIMESTAMP_OLD 0x001d +#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD + +#define TARGET_SO_TIMESTAMP_NEW 0x0046 +#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +/* Security levels - as per NRL IPv6 - don't actually do anything */ #define TARGET_SO_SECURITY_AUTHENTICATION 0x5001#define TARGET_SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002
linux-user/strace.c +5 -2
@@ -2213,8 +2213,11 @@ print_optint:case TARGET_SO_PASSCRED :qemu_log ("SO_PASSCRED," ); goto print_optint; -case TARGET_SO_TIMESTAMP : -qemu_log ("SO_TIMESTAMP," ); +case TARGET_SO_TIMESTAMP_OLD : +qemu_log ("SO_TIMESTAMP_OLD," ); + goto print_optint; +case TARGET_SO_TIMESTAMP_NEW : +qemu_log ("SO_TIMESTAMP_NEW," ); goto print_optint;case TARGET_SO_RCVLOWAT :qemu_log ("SO_RCVLOWAT," );
linux-user/syscall.c +51 -18
134 lines not on this page · raw message
tests/tcg/multiarch/socket_timestamp.c new file +292 -0
292 lines not on this page · raw message
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH 3/6] linux-user: Update SO_TIMESTAMP to SO_TIMESTAMP_OLD/NEW
Le 23/07/2020 à 02:19, Shu-Chun Weng a écrit :
Quoted 2 lines
Both guest options map to host
SO_TIMESTAMPwhile keeping a bit infd_transto remember if the guest expects the old or the new format.
I don't think we need to keep this information for each fd.
Once a program has used the _NEW version it will always use the _NEW version. It's possible to mix, but I don't think we have to support this. This adds too much complexity.
Quoted 16 lines
Added a multiarch test to verify.
Signed-off-by Shu-Chun Weng <[email protected]>--- linux-user/alpha/sockbits.h | 8 +- linux-user/fd-trans.h | 41 +++- linux-user/generic/sockbits.h | 9 +- linux-user/hppa/sockbits.h | 8 +- linux-user/mips/sockbits.h | 8 +- linux-user/sparc/sockbits.h | 8 +- linux-user/strace.c | 7 +-(fd) linux-user/syscall.c | 69 ++++-- tests/tcg/multiarch/socket_timestamp.c | 292 +++++++++++++++++++++++++ 9 files changed, 419 insertions(+), 31 deletions(-) create mode 100644 tests/tcg/multiarch/socket_timestamp.c
Thanks,
Laurent
PATCH 4/6 linux-user: setsockopt() SO_TIMESTAMPNS and SO_TIMESTAMPING
In reply to Shu-Chun WengThis change supports SO_TIMESTAMPNS_OLD/NEW and SO_TIMESTAMPING_OLD/NEW for setsocketopt() with SOL_SOCKET. Based on the SO_TIMESTAMP_OLD/NEW framework. The three pairs share the same flag SOCK_TSTAMP_NEW in linux kernel for deciding if the old or the new format is used.
--- linux-user/alpha/sockbits.h | 13 +- linux-user/generic/sockbits.h | 8 + linux-user/hppa/sockbits.h | 12 +- linux-user/mips/sockbits.h | 8 + linux-user/sparc/sockbits.h | 13 +- linux-user/strace.c | 12 + linux-user/syscall.c | 119 ++++++- tests/tcg/multiarch/socket_timestamp.c | 458 +++++++++++++++++++------ 8 files changed, 521 insertions(+), 122 deletions(-)
linux-user/alpha/sockbits.h +8 -5
@@ -51,8 +51,6 @@#define TARGET_SO_PEERSEC 30#define TARGET_SO_PASSSEC 34 -#define TARGET_SO_TIMESTAMPNS 35 -#define TARGET_SCM_TIMESTAMPNS TARGET_SO_TIMESTAMPNS/* Security levels - as per NRL IPv6 - don't actually do anything */ #define TARGET_SO_SECURITY_AUTHENTICATION 19
@@ -61,9 +59,6 @@#define TARGET_SO_MARK 36 -#define TARGET_SO_TIMESTAMPING 37 -#define TARGET_SCM_TIMESTAMPING TARGET_SO_TIMESTAMPING -#define TARGET_SO_RXQ_OVFL 40#define TARGET_SO_WIFI_STATUS 41
@@ -75,9 +70,17 @@#define TARGET_SO_TIMESTAMP_OLD 29#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD +#define TARGET_SO_TIMESTAMPNS_OLD 35 +#define TARGET_SCM_TIMESTAMPNS_OLD TARGET_SO_TIMESTAMPNS_OLD +#define TARGET_SO_TIMESTAMPING_OLD 37 +#define TARGET_SCM_TIMESTAMPING_OLD TARGET_SO_TIMESTAMPING_OLD#define TARGET_SO_TIMESTAMP_NEW 63#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +#define TARGET_SO_TIMESTAMPNS_NEW 64 +#define TARGET_SCM_TIMESTAMPNS_NEW TARGET_SO_TIMESTAMPNS_NEW +#define TARGET_SO_TIMESTAMPING_NEW 65 +#define TARGET_SCM_TIMESTAMPING_NEW TARGET_SO_TIMESTAMPING_NEW/* TARGET_O_NONBLOCK clashes with the bits used for socket types. Therefore we * have to define SOCK_NONBLOCK to a different value here.
linux-user/generic/sockbits.h +8 -0
@@ -56,8 +56,16 @@#define TARGET_SO_TIMESTAMP_OLD 29#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD +#define TARGET_SO_TIMESTAMPNS_OLD 35 +#define TARGET_SCM_TIMESTAMPNS_OLD TARGET_SO_TIMESTAMPNS_OLD +#define TARGET_SO_TIMESTAMPING_OLD 37 +#define TARGET_SCM_TIMESTAMPING_OLD TARGET_SO_TIMESTAMPING_OLD#define TARGET_SO_TIMESTAMP_NEW 63#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +#define TARGET_SO_TIMESTAMPNS_NEW 64 +#define TARGET_SCM_TIMESTAMPNS_NEW TARGET_SO_TIMESTAMPNS_NEW +#define TARGET_SO_TIMESTAMPING_NEW 65 +#define TARGET_SCM_TIMESTAMPING_NEW TARGET_SO_TIMESTAMPING_NEW#endif
linux-user/hppa/sockbits.h +8 -4
@@ -29,8 +29,6 @@#define TARGET_SO_BSDCOMPAT 0x400e#define TARGET_SO_PASSCRED 0x4010#define TARGET_SO_PEERCRED 0x4011 -#define TARGET_SO_TIMESTAMPNS 0x4013 -#define TARGET_SCM_TIMESTAMPNS TARGET_SO_TIMESTAMPNS#define TARGET_SO_SECURITY_AUTHENTICATION 0x4016#define TARGET_SO_SECURITY_ENCRYPTION_TRANSPORT 0x4017
@@ -44,8 +42,6 @@#define TARGET_SO_PEERSEC 0x401d#define TARGET_SO_PASSSEC 0x401e#define TARGET_SO_MARK 0x401f -#define TARGET_SO_TIMESTAMPING 0x4020 -#define TARGET_SCM_TIMESTAMPING TARGET_SO_TIMESTAMPING#define TARGET_SO_RXQ_OVFL 0x4021#define TARGET_SO_WIFI_STATUS 0x4022#define TARGET_SCM_WIFI_STATUS TARGET_SO_WIFI_STATUS
@@ -67,9 +63,17 @@#define TARGET_SO_TIMESTAMP_OLD 0x4012#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD +#define TARGET_SO_TIMESTAMPNS_OLD 0x4013 +#define TARGET_SCM_TIMESTAMPNS_OLD TARGET_SO_TIMESTAMPNS_OLD +#define TARGET_SO_TIMESTAMPING_OLD 0x4020 +#define TARGET_SCM_TIMESTAMPING_OLD TARGET_SO_TIMESTAMPING_OLD#define TARGET_SO_TIMESTAMP_NEW 0x4038#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +#define TARGET_SO_TIMESTAMPNS_NEW 0x4039 +#define TARGET_SCM_TIMESTAMPNS_NEW TARGET_SO_TIMESTAMPNS_NEW +#define TARGET_SO_TIMESTAMPING_NEW 0x403A +#define TARGET_SCM_TIMESTAMPING_NEW TARGET_SO_TIMESTAMPING_NEW/* TARGET_O_NONBLOCK clashes with the bits used for socket types. Therefore we * have to define SOCK_NONBLOCK to a different value here.
linux-user/mips/sockbits.h +8 -0
@@ -69,9 +69,17 @@#define TARGET_SO_TIMESTAMP_OLD 29#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD +#define TARGET_SO_TIMESTAMPNS_OLD 35 +#define TARGET_SCM_TIMESTAMPNS_OLD TARGET_SO_TIMESTAMPNS_OLD +#define TARGET_SO_TIMESTAMPING_OLD 37 +#define TARGET_SCM_TIMESTAMPING_OLD TARGET_SO_TIMESTAMPING_OLD#define TARGET_SO_TIMESTAMP_NEW 63#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +#define TARGET_SO_TIMESTAMPNS_NEW 64 +#define TARGET_SCM_TIMESTAMPNS_NEW TARGET_SO_TIMESTAMPNS_NEW +#define TARGET_SO_TIMESTAMPING_NEW 65 +#define TARGET_SCM_TIMESTAMPING_NEW TARGET_SO_TIMESTAMPING_NEW/** sock_type - Socket types *
linux-user/sparc/sockbits.h +8 -5
@@ -51,14 +51,9 @@#define TARGET_SO_PEERSEC 0x001e#define TARGET_SO_PASSSEC 0x001f -#define TARGET_SO_TIMESTAMPNS 0x0021 -#define TARGET_SCM_TIMESTAMPNS TARGET_SO_TIMESTAMPNS#define TARGET_SO_MARK 0x0022 -#define TARGET_SO_TIMESTAMPING 0x0023 -#define TARGET_SCM_TIMESTAMPING TARGET_SO_TIMESTAMPING -#define TARGET_SO_RXQ_OVFL 0x0024#define TARGET_SO_WIFI_STATUS 0x0025
@@ -104,9 +99,17 @@#define TARGET_SO_TIMESTAMP_OLD 0x001d#define TARGET_SCM_TIMESTAMP_OLD TARGET_SO_TIMESTAMP_OLD +#define TARGET_SO_TIMESTAMPNS_OLD 0x0021 +#define TARGET_SCM_TIMESTAMPNS_OLD TARGET_SO_TIMESTAMPNS_OLD +#define TARGET_SO_TIMESTAMPING_OLD 0x0023 +#define TARGET_SCM_TIMESTAMPING_OLD TARGET_SO_TIMESTAMPING_OLD#define TARGET_SO_TIMESTAMP_NEW 0x0046#define TARGET_SCM_TIMESTAMP_NEW TARGET_SO_TIMESTAMP_NEW +#define TARGET_SO_TIMESTAMPNS_NEW 0x0042 +#define TARGET_SCM_TIMESTAMPNS_NEW TARGET_SO_TIMESTAMPNS_NEW +#define TARGET_SO_TIMESTAMPING_NEW 0x0043 +#define TARGET_SCM_TIMESTAMPING_NEW TARGET_SO_TIMESTAMPING_NEW/* Security levels - as per NRL IPv6 - don't actually do anything */ #define TARGET_SO_SECURITY_AUTHENTICATION 0x5001
linux-user/strace.c +12 -0
@@ -2216,9 +2216,21 @@ print_optint:case TARGET_SO_TIMESTAMP_OLD :qemu_log ("SO_TIMESTAMP_OLD," ); goto print_optint; +case TARGET_SO_TIMESTAMPNS_OLD : +qemu_log ("SO_TIMESTAMPNS_OLD," ); + goto print_optint; +case TARGET_SO_TIMESTAMPING_OLD : +qemu_log ("SO_TIMESTAMPING_OLD," ); + goto print_optint;case TARGET_SO_TIMESTAMP_NEW :qemu_log ("SO_TIMESTAMP_NEW," ); goto print_optint; +case TARGET_SO_TIMESTAMPNS_NEW : +qemu_log ("SO_TIMESTAMPNS_NEW," ); + goto print_optint; +case TARGET_SO_TIMESTAMPING_NEW : +qemu_log ("SO_TIMESTAMPING_NEW," ); + goto print_optint;case TARGET_SO_RCVLOWAT :qemu_log ("SO_RCVLOWAT," ); goto print_optint;
linux-user/syscall.c +115 -4
155 lines not on this page · raw message
tests/tcg/multiarch/socket_timestamp.c +354 -104
586 lines not on this page · raw message
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH 5/6 thunk: supports flexible arrays
In reply to Shu-Chun WengFlexible arrays may appear in the last field of a struct and are heavily used in the ioctl(SIOCETHTOOL) system call on Linux. E.g.
struct ethtool_regs {
__u32 cmd;
__u32 version; /* driver-specific, indicates different chips/revs */
__u32 len; /* bytes */
__u8 data[0];
};where number of elements in data is specified in len. It is translated into:
STRUCT(ethtool_regs,
TYPE_INT, /* cmd */
TYPE_INT, /* version */
TYPE_INT, /* len */
MK_FLEXIBLE_ARRAY(TYPE_CHAR, 2)) /* data[0]: len */where the "2" passed to MK_FLEXIBLE_ARRAY means the number of element is specified by field number 2 (0-index).
--- include/exec/user/thunk.h | 20 +++++ thunk.c | 151 +++++++++++++++++++++++++++++++++++++- 2 files changed, 169 insertions(+), 2 deletions(-)
include/exec/user/thunk.h +20 -0
@@ -39,12 +39,19 @@ typedef enum argtype {TYPE_ARRAY ,TYPE_STRUCT ,TYPE_OLDDEVT , +TYPE_FLEXIBLE_ARRAY , } argtype;#define MK_PTR (type) TYPE_PTR, type#define MK_ARRAY (type, size) TYPE_ARRAY, size, type#define MK_STRUCT (id) TYPE_STRUCT, id +/* Should only appear as the last element of a TYPE_STRUCT. `len_field_idx` is +* the index into the fields in the enclosing struct that specify the length of +* the flexibly array. The length field MUST be a TYPE_INT field. */ +#define MK_FLEXIBLE_ARRAY (type, len_field_idx) \ + TYPE_FLEXIBLE_ARRAY, len_field_idx, type +#define THUNK_TARGET 0#define THUNK_HOST 1
@@ -55,6 +62,8 @@ typedef struct {int *field_offsets[2 ];/* special handling */ void (*convert[2 ])(void *dst,const void *src); +int (*thunk_size[2 ])(const void *src); +int size[2 ];int align[2 ];const char *name;
@@ -75,6 +84,11 @@ const argtype *thunk_convert(void *dst, const void *src, const argtype *type_ptr, int to_host);const argtype *thunk_print (void *arg,const argtype *type_ptr); +bool thunk_type_has_flexible_array (const argtype *type_ptr); +/* thunk_type_size but can handle TYPE_FLEXIBLE_ARRAY */ +int thunk_type_size_with_src (const void *src,const argtype *type_ptr, +int is_host); +extern StructEntry *struct_entries;int thunk_type_size_array (const argtype *type_ptr,int is_host);
@@ -137,6 +151,10 @@ static inline int thunk_type_size(const argtype *type_ptr, int is_host)case TYPE_STRUCT : se = struct_entries + type_ptr[1 ];return se->size[is_host]; +case TYPE_FLEXIBLE_ARRAY : +/* Flexible arrays do not count toward sizeof(). Users of structures +* containing them need to calculate it themselves. */ +return 0 ;default :g_assert_not_reached (); }
@@ -187,6 +205,8 @@ static inline int thunk_type_align(const argtype *type_ptr, int is_host)case TYPE_STRUCT : se = struct_entries + type_ptr[1 ];return se->align[is_host]; +case TYPE_FLEXIBLE_ARRAY : +return thunk_type_align_array (type_ptr +2 , is_host);default :g_assert_not_reached (); }
thunk.c +149 -2
204 lines not on this page · raw message
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH 6/6 linux-user: Add support for SIOCETHTOOL ioctl
In reply to Shu-Chun WengThe ioctl numeric values are platform-independent and determined by the file include/uapi/linux/sockios.h in Linux kernel source code:
#define SIOCETHTOOL 0x8946
These ioctls get (or set) various structures pointed by the field ifr_data in the structure ifreq depending on the first 4 bytes of the memory region.
This change clones the ioctl framework into ethtool-specific dispatch logic in its own file. A number of definitions previously only visible in syscall.c are thus exported to syscall_defs.h to be used in the new files.
--- linux-user/Makefile.objs | 3 +- linux-user/ethtool.c | 819 ++++++++++++++++++++++++++++++++++ linux-user/ethtool.h | 19 + linux-user/ethtool_entries.h | 107 +++++ linux-user/ioctls.h | 2 + linux-user/qemu.h | 1 + linux-user/syscall.c | 35 +- linux-user/syscall_defs.h | 12 + linux-user/syscall_types.h | 277 ++++++++++++ tests/tcg/multiarch/ethtool.c | 417 +++++++++++++++++ 10 files changed, 1680 insertions(+), 12 deletions(-) create mode 100644 linux-user/ethtool.c create mode 100644 linux-user/ethtool.h create mode 100644 linux-user/ethtool_entries.h create mode 100644 tests/tcg/multiarch/ethtool.c
linux-user/Makefile.objs +2 -1
@@ -1,7 +1,8 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ elfload.o linuxload.o uaccess.o uname.o \ safe-syscall.o $(TARGET_ABI_DIR)/signal.o \ - $(TARGET_ABI_DIR)/cpu_loop.o exit.o fd-trans.o + $(TARGET_ABI_DIR)/cpu_loop.o exit.o fd-trans.o \ + ethtool.o obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o
linux-user/ethtool.c new file +819 -0
819 lines not on this page · raw message
linux-user/ethtool.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef ETHTOOL_H +#define ETHTOOL_H + +#include <linux/if.h> +#include "qemu.h" + +extern const StructEntry struct_ethtool_rxnfc_get_set_rxfh_def; +extern const StructEntry struct_ethtool_sset_info_def; +extern const StructEntry struct_ethtool_rxfh_def; +extern const StructEntry struct_ethtool_link_settings_def; +extern const StructEntry struct_ethtool_per_queue_op_def; + +/* Takes the file descriptor and the buffer for temporarily storing data read +* from / to be written to guest memory. `buf_temp` must now contain the host +* representation of `struct ifreq`. +*/ +abi_long dev_ethtool (int fd,uint8_t *buf_temp); + +#endif /* ETHTOOL_H */
linux-user/ethtool_entries.h new file +107 -0
107 lines not on this page · raw message
linux-user/ioctls.h +2 -0
@@ -238,6 +238,8 @@ IOCTL(SIOCSIFHWADDR, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) IOCTL(SIOCGIFTXQLEN, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) IOCTL(SIOCSIFTXQLEN, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) +IOCTL_SPECIAL (SIOCETHTOOL ,IOC_W |IOC_R , do_ioctl_ethtool, + MK_PTR(MK_STRUCT(STRUCT_ptr_ifreq))) IOCTL(SIOCGIFMETRIC, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_int_ifreq))) IOCTL(SIOCSIFMETRIC, IOC_W, MK_PTR(MK_STRUCT(STRUCT_int_ifreq)))IOCTL (SIOCGIFMTU ,IOC_W |IOC_R ,MK_PTR (MK_STRUCT (STRUCT_int_ifreq)))
linux-user/qemu.h +1 -0
@@ -231,6 +231,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7, abi_long arg8); +abi_long get_errno (abi_long ret);extern __threadCPUState *thread_cpu;void cpu_loop (CPUArchState *env);const char *target_strerror (int err);
linux-user/syscall.c +24 -11
@@ -127,6 +127,7 @@#include "qapi/error.h" #include "fd-trans.h" #include "tcg/tcg.h" +#include "ethtool.h" #ifndef CLONE_IO #define CLONE_IO 0x80000000/* Clone io context */
@@ -683,7 +684,7 @@ static inline int target_to_host_errno(int err)return err; } -static inline abi_long get_errno (abi_long ret) +abi_long get_errno (abi_long ret) {if (ret ==-1 )return -host_to_target_errno (errno);
@@ -4681,16 +4682,6 @@ static abi_long do_ipc(CPUArchState *cpu_env,#endif /* kernel structure types definitions */ - -#define STRUCT (name, ...) STRUCT_ ## name, -#define STRUCT_SPECIAL (name) STRUCT_ ## name, -enum { -#include "syscall_types.h" -STRUCT_MAX -}; -#undef STRUCT -#undef STRUCT_SPECIAL -#define STRUCT (name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };#define STRUCT_SPECIAL (name)#include "syscall_types.h"
@@ -4788,6 +4779,28 @@ static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry *ie, uint8_t *buf_temp, }#endif +static abi_long do_ioctl_ethtool (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +const argtype *arg_type = ie->arg_type; +int target_size; +void *argptr; + +assert (arg_type[0 ] ==TYPE_PTR ); +assert (ie->access ==IOC_RW ); + + arg_type++; + target_size =thunk_type_size (arg_type,0 ); + + argptr =lock_user (VERIFY_READ , arg, target_size,1 ); +if (!argptr) +return -TARGET_EFAULT ; +thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); +unlock_user (argptr, arg, target_size); + +return dev_ethtool (fd, buf_temp); +} +static abi_long do_ioctl_ifconf (const IOCTLEntry *ie,uint8_t *buf_temp,int fd,int cmd,abi_long arg) {
linux-user/syscall_defs.h +12 -0
@@ -866,6 +866,8 @@ struct target_rtc_pll_info {#define TARGET_SIOCGIFTXQLEN 0x8942/* Get the tx queue length */ #define TARGET_SIOCSIFTXQLEN 0x8943/* Set the tx queue length */ +#define TARGET_SIOCETHTOOL 0x8946/* Ethtool interface */ +/* ARP cache control calls. */ #define TARGET_OLD_SIOCDARP 0x8950/* old delete ARP table entry */ #define TARGET_OLD_SIOCGARP 0x8951/* old get ARP table entry */
@@ -2776,4 +2778,14 @@ struct target_statx {/* 0x100 */ }; +/* kernel structure types definitions */ +#define STRUCT (name, ...) STRUCT_ ## name, +#define STRUCT_SPECIAL (name) STRUCT_ ## name, +enum { +#include "syscall_types.h" +STRUCT_MAX +}; +#undef STRUCT +#undef STRUCT_SPECIAL +#endif
linux-user/syscall_types.h +277 -0
283 lines not on this page · raw message
tests/tcg/multiarch/ethtool.c new file +417 -0
417 lines not on this page · raw message
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Ping! Patchew: https://patchew.org/QEMU/[email protected]/
Quoted 64 lines · Shu-Chun Weng
Hi Laurent,
This is a series of 6 patches in 4 groups, putting into a single thread for easier tracking.
[PATCH 1/6] linux-user: Support
F_ADD_SEALSandF_GET_SEALSfcntls
An incidental follow up on
https://lists.nongnu.org/archive/html/qemu-devel/2019-09/msg01925.html[PATCH 2/6] linux-user: add missing UDP and IPv6 get/setsockopt
Updated
https://lists.nongnu.org/archive/html/qemu-devel/2019-09/msg01317.html
to consistently add them in get/setsockopt[PATCH 3/6] linux-user: Update
SO_TIMESTAMPto SO_TIMESTAMP_OLD/NEW [PATCH 4/6] linux-user:setsockopt()SO_TIMESTAMPNSandSO_TIMESTAMPING
Updated
https://lists.nongnu.org/archive/html/qemu-devel/2019-09/msg01319.html
to only use TARGET_SO_*_OLD/NEW[PATCH 5/6] thunk: supports flexible arrays [PATCH 6/6] linux-user: Add support for SIOCETHTOOL ioctl
Updated
https://lists.nongnu.org/archive/html/qemu-devel/2019-08/msg05090.htmlShu-Chun Weng (6):
linux-user: SupportF_ADD_SEALSandF_GET_SEALSfcntls
linux-user: add missing UDP and IPv6 get/setsockopt options
linux-user: UpdateSO_TIMESTAMPto SO_TIMESTAMP_OLD/NEW
linux-user:setsockopt()SO_TIMESTAMPNSandSO_TIMESTAMPING
thunk: supports flexible arrays
linux-user: Add support for SIOCETHTOOL ioctlinclude/exec/user/thunk.h | 20 + linux-user/Makefile.objs | 3 +- linux-user/alpha/sockbits.h | 21 +- linux-user/ethtool.c | 819 +++++++++++++++++++++++++ linux-user/ethtool.h | 19 + linux-user/ethtool_entries.h | 107 ++++ linux-user/fd-trans.h | 41 +- linux-user/generic/sockbits.h | 17 +- linux-user/hppa/sockbits.h | 20 +- linux-user/ioctls.h | 2 + linux-user/mips/sockbits.h | 16 +- linux-user/qemu.h | 1 + linux-user/sparc/sockbits.h | 21 +- linux-user/strace.c | 19 +- linux-user/syscall.c | 233 ++++++- linux-user/syscall_defs.h | 26 +- linux-user/syscall_types.h | 277 +++++++++ tests/tcg/multiarch/ethtool.c | 417 +++++++++++++ tests/tcg/multiarch/socket_timestamp.c | 542 ++++++++++++++++ thunk.c | 151 ++++- 20 files changed, 2706 insertions(+), 66 deletions(-) create mode 100644 linux-user/ethtool.c create mode 100644 linux-user/ethtool.h create mode 100644 linux-user/ethtool_entries.h create mode 100644 tests/tcg/multiarch/ethtool.c create mode 100644 tests/tcg/multiarch/socket_timestamp.c--
2.28.0.rc0.105.gf9edc3c819-goog