unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Linux 64-bit time_t socket fixes
@ 2021-07-05 18:30 Adhemerval Zanella via Libc-alpha
  2021-07-05 18:30 ` [PATCH 1/7] linux: Consolidate Linux getsockopt implementation Adhemerval Zanella via Libc-alpha
                   ` (6 more replies)
  0 siblings, 7 replies; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

This series fixes some issues with socket timestamps on legacy ABIs 
with 32-bit time_t support.
  
The first two patches consolidates the setsockopt and getsockopt, which
fixes the missing timestamp handling on some architectures (hppa,
mips32, arm, cksy, and nios2).
     
The third and forth patches fixes a wrong conversion for timestamps
and a wrong argument usage for setsockopt.

Finally the remaining patches adds proper tests for both recvmsg
and recvmmsg.  They check for timestamp on both syscalls() with
different ancilliary data sizes (to check if convertion take this in
consideration, and with different time_t sizes.
 
I checked it on x86_64-linux-gnu and i686-linux-gnu on both 
5.11 kernel and on 4.15 kernel.  I am planning to run on some
different system with different kernels as well.
 
It might worth to check if this series fix the ruby issue [1].
 
[1] https://sourceware.org/pipermail/libc-alpha/2021-June/128113.html

Adhemerval Zanella (7):
  linux: Consolidate Linux getsockopt implementation
  linux: Consolidate Linux setsockopt implementation
  linux: Use the expected size for SO_TIMESTAMP{NS} convertion
  linux: Fix setsockopt fallback
  support: Add support_socket_time64_timestamp
  socket: Add recvmsg timestamp test
  socket: Add recvmmsg timestamp test

 support/Makefile                              |   1 +
 support/support.h                             |   3 +
 support/support_socket_time64_timestamp.c     |  68 +++++++
 sysdeps/unix/sysv/linux/Makefile              |   3 +
 sysdeps/unix/sysv/linux/alpha/syscalls.list   |   2 -
 sysdeps/unix/sysv/linux/arm/syscalls.list     |   2 -
 .../unix/sysv/linux/convert_scm_timestamps.c  |   8 +-
 sysdeps/unix/sysv/linux/generic/syscalls.list |   2 -
 sysdeps/unix/sysv/linux/hppa/syscalls.list    |   2 -
 .../unix/sysv/linux/i386/kernel-features.h    |   4 +-
 sysdeps/unix/sysv/linux/ia64/syscalls.list    |   2 -
 sysdeps/unix/sysv/linux/kernel-features.h     |   2 +
 .../unix/sysv/linux/m68k/kernel-features.h    |   4 +-
 .../sysv/linux/microblaze/kernel-features.h   |   2 -
 sysdeps/unix/sysv/linux/mips/syscalls.list    |   2 -
 .../unix/sysv/linux/powerpc/kernel-features.h |   2 -
 .../unix/sysv/linux/s390/kernel-features.h    |   4 +-
 sysdeps/unix/sysv/linux/setsockopt.c          |   2 +-
 sysdeps/unix/sysv/linux/sh/kernel-features.h  |   2 -
 .../unix/sysv/linux/sparc/kernel-features.h   |   4 +-
 sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c |   1 +
 sysdeps/unix/sysv/linux/tst-recvmmsg.c        | 185 ++++++++++++++++++
 sysdeps/unix/sysv/linux/tst-recvmsg-time64.c  |   1 +
 sysdeps/unix/sysv/linux/tst-recvmsg.c         | 171 ++++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/syscalls.list  |   2 -
 25 files changed, 450 insertions(+), 31 deletions(-)
 create mode 100644 support/support_socket_time64_timestamp.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmmsg.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmsg-time64.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmsg.c

-- 
2.30.2


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 1/7] linux: Consolidate Linux getsockopt implementation
  2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:30 ` Adhemerval Zanella via Libc-alpha
  2021-07-05 18:58   ` Florian Weimer via Libc-alpha
  2021-07-05 18:30 ` [PATCH 2/7] linux: Consolidate Linux setsockopt implementation Adhemerval Zanella via Libc-alpha
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

This patch consolidates the getsockopt Linux syscall implementation on
sysdeps/unix/sysv/linux/getsockopt.c.  The changes are:

  1. Remove it from auto-generation syscalls.list on all architectures.

  2. Add __ASSUME_GETSOCKOPT_SYSCALL as default and undef if for
     specific kernel versions on some architectures.

This also fix a potential issue where 32-bit time_t ABI should use the
linux getsockopt which overrides the underlying SO_* constants used for
socket timestamping for _TIME_BITS=64.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/alpha/syscalls.list          | 1 -
 sysdeps/unix/sysv/linux/arm/syscalls.list            | 1 -
 sysdeps/unix/sysv/linux/generic/syscalls.list        | 1 -
 sysdeps/unix/sysv/linux/hppa/syscalls.list           | 1 -
 sysdeps/unix/sysv/linux/i386/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/ia64/syscalls.list           | 1 -
 sysdeps/unix/sysv/linux/kernel-features.h            | 1 +
 sysdeps/unix/sysv/linux/m68k/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/microblaze/kernel-features.h | 1 -
 sysdeps/unix/sysv/linux/mips/syscalls.list           | 1 -
 sysdeps/unix/sysv/linux/powerpc/kernel-features.h    | 1 -
 sysdeps/unix/sysv/linux/s390/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/sh/kernel-features.h         | 1 -
 sysdeps/unix/sysv/linux/sparc/kernel-features.h      | 2 +-
 sysdeps/unix/sysv/linux/x86_64/syscalls.list         | 1 -
 15 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index c848fcbd99..0a39d0871c 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -8,7 +8,6 @@ getpriority	-	getpriority	i:ii	__getpriority	getpriority
 bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
-getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list
index 13441f7eb4..b530057cd8 100644
--- a/sysdeps/unix/sysv/linux/arm/syscalls.list
+++ b/sysdeps/unix/sysv/linux/arm/syscalls.list
@@ -25,7 +25,6 @@ personality	EXTRA	personality	Ei:i	__personality	personality
 bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
-getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
index ed8b216d47..7397797571 100644
--- a/sysdeps/unix/sysv/linux/generic/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -8,5 +8,4 @@ listen		-	listen		i:ii	__listen	listen
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
-getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list
index cd37573b89..2451cc90f1 100644
--- a/sysdeps/unix/sysv/linux/hppa/syscalls.list
+++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list
@@ -4,7 +4,6 @@
 bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
-getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
index 923fa0b997..a6eca4092d 100644
--- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
@@ -23,7 +23,6 @@
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
@@ -41,6 +40,7 @@
 # undef __ASSUME_CONNECT_SYSCALL
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
+# undef __ASSUME_GETSOCKOPT_SYSCALL
 #endif
 
 /* i686 only supports ipc syscall before 5.1.  */
diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
index bd39441d3c..c0e9ea207c 100644
--- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -6,7 +6,6 @@ getpriority	-	getpriority	i:ii	__getpriority	getpriority
 bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
-getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 1680b10ca1..913c3fc222 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -77,6 +77,7 @@
 #define __ASSUME_ACCEPT4_SYSCALL	1
 #define __ASSUME_RECVMMSG_SYSCALL	1
 #define __ASSUME_SENDMMSG_SYSCALL	1
+#define __ASSUME_GETSOCKOPT_SYSCALL	1
 
 /* Support for SysV IPC through wired syscalls.  All supported architectures
    either support ipc syscall and/or all the ipc correspondent syscalls.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index 46bb9d8b26..e1fa35c784 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -23,7 +23,6 @@
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
@@ -43,6 +42,7 @@
 # undef __ASSUME_CONNECT_SYSCALL
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
+# undef __ASSUME_GETSOCKOPT_SYSCALL
 #endif
 
 /* No support for PI futexes or robust mutexes before 3.10 for m68k.  */
diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
index 69d8ccaa23..a09a9ea09d 100644
--- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
@@ -28,7 +28,6 @@
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
-#define __ASSUME_GETSOCKOPT_SYSCALL	1
 #define __ASSUME_SETSOCKOPT_SYSCALL	1
 
 #include_next <kernel-features.h>
diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list
index f3621cdd51..07e07dec03 100644
--- a/sysdeps/unix/sysv/linux/mips/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/syscalls.list
@@ -15,7 +15,6 @@ sysmips		-	sysmips		i:iiii	__sysmips	sysmips
 bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
-getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
index c2056959a5..769ef1386d 100644
--- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
@@ -28,7 +28,6 @@
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
-#define __ASSUME_GETSOCKOPT_SYSCALL	1
 #define __ASSUME_SETSOCKOPT_SYSCALL	1
 
 /* Define this if your 32-bit syscall API requires 64-bit register
diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
index 724f207e9f..0221a0e0bc 100644
--- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
@@ -23,7 +23,6 @@
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
@@ -43,6 +42,7 @@
 # undef __ASSUME_CONNECT_SYSCALL
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
+# undef __ASSUME_GETSOCKOPT_SYSCALL
 #endif
 
 /* s390 only supports ipc syscall before 5.1.  */
diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h
index 334e69b0c7..3b0c385260 100644
--- a/sysdeps/unix/sysv/linux/sh/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h
@@ -33,7 +33,6 @@
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
-#define __ASSUME_GETSOCKOPT_SYSCALL	1
 #define __ASSUME_SETSOCKOPT_SYSCALL	1
 
 #include_next <kernel-features.h>
diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
index 7ffafc9fd0..0b105eb849 100644
--- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
@@ -38,10 +38,10 @@
 # undef __ASSUME_CONNECT_SYSCALL
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
+# undef __ASSUME_GETSOCKOPT_SYSCALL
 #else
 # define __ASSUME_SOCKET_SYSCALL             1
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
-# define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
index d46524eff3..fceb6d2415 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -9,7 +9,6 @@ syscall_clock_gettime	EXTRA	clock_gettime	Ei:ip		__syscall_clock_gettime
 bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
-getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 2/7] linux: Consolidate Linux setsockopt implementation
  2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
  2021-07-05 18:30 ` [PATCH 1/7] linux: Consolidate Linux getsockopt implementation Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:30 ` Adhemerval Zanella via Libc-alpha
  2021-07-05 18:59   ` Florian Weimer via Libc-alpha
  2021-07-05 18:30 ` [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion Adhemerval Zanella via Libc-alpha
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

This patch consolidates the setsockopt implementation on
sysdeps/unix/sysv/linux/getsockopt.c.  The changes are:

  1. Remove it from auto-generation syscalls.list on all architectures.

  2. Add __ASSUME_SETSOCKOPT_SYSCALL as default and undef if for
     specific kernel versions on some architectures.

This also fix a potential issue where 32-bit time_t ABI should use the
linux setsockopt which overrides the underlying SO_* constants used for
socket timestamping for _TIME_BITS=64.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/alpha/syscalls.list          | 1 -
 sysdeps/unix/sysv/linux/arm/syscalls.list            | 1 -
 sysdeps/unix/sysv/linux/generic/syscalls.list        | 1 -
 sysdeps/unix/sysv/linux/hppa/syscalls.list           | 1 -
 sysdeps/unix/sysv/linux/i386/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/ia64/syscalls.list           | 1 -
 sysdeps/unix/sysv/linux/kernel-features.h            | 1 +
 sysdeps/unix/sysv/linux/m68k/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/microblaze/kernel-features.h | 1 -
 sysdeps/unix/sysv/linux/mips/syscalls.list           | 1 -
 sysdeps/unix/sysv/linux/powerpc/kernel-features.h    | 1 -
 sysdeps/unix/sysv/linux/s390/kernel-features.h       | 2 +-
 sysdeps/unix/sysv/linux/sh/kernel-features.h         | 1 -
 sysdeps/unix/sysv/linux/sparc/kernel-features.h      | 2 +-
 sysdeps/unix/sysv/linux/x86_64/syscalls.list         | 1 -
 15 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index 0a39d0871c..cbfd12588b 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -9,7 +9,6 @@ bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 listen		-	listen		i:ii	__listen	listen
-setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list
index b530057cd8..10c3ae9dae 100644
--- a/sysdeps/unix/sysv/linux/arm/syscalls.list
+++ b/sysdeps/unix/sysv/linux/arm/syscalls.list
@@ -26,7 +26,6 @@ bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 listen		-	listen		i:ii	__listen	listen
-setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
index 7397797571..f573f27c8b 100644
--- a/sysdeps/unix/sysv/linux/generic/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -7,5 +7,4 @@ bind		-	bind		i:ipi	__bind		bind
 listen		-	listen		i:ii	__listen	listen
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
-setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list
index 2451cc90f1..043d884bf9 100644
--- a/sysdeps/unix/sysv/linux/hppa/syscalls.list
+++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list
@@ -5,7 +5,6 @@ bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 listen		-	listen		i:ii	__listen	listen
-setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
index a6eca4092d..8327f822b0 100644
--- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
@@ -23,7 +23,6 @@
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
@@ -41,6 +40,7 @@
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
 # undef __ASSUME_GETSOCKOPT_SYSCALL
+# undef __ASSUME_SETSOCKOPT_SYSCALL
 #endif
 
 /* i686 only supports ipc syscall before 5.1.  */
diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
index c0e9ea207c..8aa85fcb02 100644
--- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -7,7 +7,6 @@ bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 listen		-	listen		i:ii	__listen	listen
-setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 913c3fc222..3930e14322 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -78,6 +78,7 @@
 #define __ASSUME_RECVMMSG_SYSCALL	1
 #define __ASSUME_SENDMMSG_SYSCALL	1
 #define __ASSUME_GETSOCKOPT_SYSCALL	1
+#define __ASSUME_SETSOCKOPT_SYSCALL	1
 
 /* Support for SysV IPC through wired syscalls.  All supported architectures
    either support ipc syscall and/or all the ipc correspondent syscalls.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index e1fa35c784..70f1154559 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -23,7 +23,6 @@
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
@@ -43,6 +42,7 @@
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
 # undef __ASSUME_GETSOCKOPT_SYSCALL
+# undef __ASSUME_SETSOCKOPT_SYSCALL
 #endif
 
 /* No support for PI futexes or robust mutexes before 3.10 for m68k.  */
diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
index a09a9ea09d..a8fbc67384 100644
--- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
@@ -28,7 +28,6 @@
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
-#define __ASSUME_SETSOCKOPT_SYSCALL	1
 
 #include_next <kernel-features.h>
 
diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list
index 07e07dec03..d99504774c 100644
--- a/sysdeps/unix/sysv/linux/mips/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/syscalls.list
@@ -16,7 +16,6 @@ bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 listen		-	listen		i:ii	__listen	listen
-setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
index 769ef1386d..6c04e187ce 100644
--- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
@@ -28,7 +28,6 @@
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
-#define __ASSUME_SETSOCKOPT_SYSCALL	1
 
 /* Define this if your 32-bit syscall API requires 64-bit register
    pairs to start with an even-number register.  */
diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
index 0221a0e0bc..4757e9eb02 100644
--- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
@@ -23,7 +23,6 @@
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
@@ -43,6 +42,7 @@
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
 # undef __ASSUME_GETSOCKOPT_SYSCALL
+# undef __ASSUME_SETSOCKOPT_SYSCALL
 #endif
 
 /* s390 only supports ipc syscall before 5.1.  */
diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h
index 3b0c385260..15f5cc2c85 100644
--- a/sysdeps/unix/sysv/linux/sh/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h
@@ -33,7 +33,6 @@
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
-#define __ASSUME_SETSOCKOPT_SYSCALL	1
 
 #include_next <kernel-features.h>
 
diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
index 0b105eb849..2c28393647 100644
--- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
@@ -39,6 +39,7 @@
 # undef __ASSUME_RECVFROM_SYSCALL
 # undef __ASSUME_SENDTO_SYSCALL
 # undef __ASSUME_GETSOCKOPT_SYSCALL
+# undef __ASSUME_SETSOCKOPT_SYSCALL
 #else
 # define __ASSUME_SOCKET_SYSCALL             1
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
@@ -49,7 +50,6 @@
 #if __LINUX_KERNEL_VERSION >= 0x040400
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_SETSOCKOPT_SYSCALL         1
 #endif
 
 #ifdef __arch64__
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
index fceb6d2415..4ce5913a86 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -10,7 +10,6 @@ bind		-	bind		i:ipi	__bind		bind
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 listen		-	listen		i:ii	__listen	listen
-setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion
  2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
  2021-07-05 18:30 ` [PATCH 1/7] linux: Consolidate Linux getsockopt implementation Adhemerval Zanella via Libc-alpha
  2021-07-05 18:30 ` [PATCH 2/7] linux: Consolidate Linux setsockopt implementation Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:30 ` Adhemerval Zanella via Libc-alpha
  2021-07-05 19:00   ` Florian Weimer via Libc-alpha
  2021-07-05 18:30 ` [PATCH 4/7] linux: Fix setsockopt fallback Adhemerval Zanella via Libc-alpha
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

Kernel returns 32-bit values for COMPAT_SO_TIMESTAMP{NS}_OLD,
no 64-bit ones.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/convert_scm_timestamps.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
index 5af71847f5..2db5750f50 100644
--- a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
+++ b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
@@ -44,7 +44,8 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
      'struct __kernel_sock_timeval' while for SO_TIMESTAMPNS_NEW is a
      'struct __kernel_timespec'.  In either case it is two uint64_t
      members.  */
-  uint64_t tvts[2];
+  int64_t tvts[2];
+  int32_t tmp;
 
   struct cmsghdr *cmsg, *last = NULL;
   int type = 0;
@@ -69,7 +70,10 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
 
 	/* fallthrough  */
 	common:
-	  memcpy (tvts, CMSG_DATA (cmsg), sizeof (tvts));
+	  memcpy (&tmp, CMSG_DATA (cmsg), sizeof (tmp));
+	  tvts[0] = tmp;
+	  memcpy (&tmp, CMSG_DATA (cmsg) + sizeof (tmp), sizeof (tmp));
+	  tvts[1] = tmp;
 	  break;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 4/7] linux: Fix setsockopt fallback
  2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
                   ` (2 preceding siblings ...)
  2021-07-05 18:30 ` [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:30 ` Adhemerval Zanella via Libc-alpha
  2021-07-05 19:07   ` Florian Weimer via Libc-alpha
  2021-07-05 18:30 ` [PATCH 5/7] support: Add support_socket_time64_timestamp Adhemerval Zanella via Libc-alpha
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

The final 2 arguments for SO_TIMESTAMP/SO_TIMESTAMPNS are being set
wrongly.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/setsockopt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c
index a4780a9d33..fae7305c9d 100644
--- a/sysdeps/unix/sysv/linux/setsockopt.c
+++ b/sysdeps/unix/sysv/linux/setsockopt.c
@@ -78,7 +78,7 @@ setsockopt32 (int fd, int level, int optname, const void *optval,
 	  optname = COMPAT_SO_TIMESTAMP_OLD;
 	if (optname == COMPAT_SO_TIMESTAMPNS_NEW)
 	  optname = COMPAT_SO_TIMESTAMPNS_OLD;
-	r = setsockopt_syscall (fd, level, optname, NULL, 0);
+	r = setsockopt_syscall (fd, level, optname, optval, len);
       }
       break;
     }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 5/7] support: Add support_socket_time64_timestamp
  2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
                   ` (3 preceding siblings ...)
  2021-07-05 18:30 ` [PATCH 4/7] linux: Fix setsockopt fallback Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:30 ` Adhemerval Zanella via Libc-alpha
  2021-07-05 18:46   ` Florian Weimer via Libc-alpha
  2021-07-05 18:30 ` [PATCH 6/7] socket: Add recvmsg timestamp test Adhemerval Zanella via Libc-alpha
  2021-07-05 18:30 ` [PATCH 7/7] socket: Add recvmmsg " Adhemerval Zanella via Libc-alpha
  6 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

Check if the socket support 64-bit network packages timestamps
(SO_TIMESTAMP and SO_TIMESTAMPNS).  This will be used on recvmsg
and recvmmsg tests to check if the timestamp should be generated.
---
 support/Makefile                          |  1 +
 support/support.h                         |  3 +
 support/support_socket_time64_timestamp.c | 68 +++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 support/support_socket_time64_timestamp.c

diff --git a/support/Makefile b/support/Makefile
index 5c69f0de4b..7659357b28 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -76,6 +76,7 @@ libsupport-routines = \
   support_set_small_thread_stack_size \
   support_shared_allocate \
   support_small_stack_thread_attribute \
+  support_socket_time64_timestamp \
   support_stat_nanoseconds \
   support_subprocess \
   support_test_compare_blob \
diff --git a/support/support.h b/support/support.h
index 9ec8ecb8d7..bf74a2584b 100644
--- a/support/support.h
+++ b/support/support.h
@@ -154,6 +154,9 @@ extern bool support_select_modifies_timeout (void);
    tv_usec larger than 1000000.  */
 extern bool support_select_normalizes_timeout (void);
 
+/* Return true if socket FD supports 64-bit timestamps.  */
+extern bool support_socket_time64_timestamp (int fd);
+
 /* Create a timer that trigger after SEC seconds and NSEC nanoseconds.  If
    REPEAT is true the timer will repeat indefinitely.  If CALLBACK is not
    NULL, the function will be called when the timer expires; otherwise a
diff --git a/support/support_socket_time64_timestamp.c b/support/support_socket_time64_timestamp.c
new file mode 100644
index 0000000000..2d5af65471
--- /dev/null
+++ b/support/support_socket_time64_timestamp.c
@@ -0,0 +1,68 @@
+/* Return whether socket supports 64-bit timestamps.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include <support/support.h>
+
+#ifdef __linux__
+# include <socket-constants-time64.h>
+
+static int
+__attribute_used__
+setsockopt_syscall (int fd, int enable)
+{
+  int level = SOL_SOCKET;
+  int optname = COMPAT_SO_TIMESTAMP_NEW;
+  int optval = enable;
+
+  int r = syscall (__NR_setsockopt, fd, level, optname, &optval,
+		   sizeof (optval));
+#  ifdef __NR_setsockopt
+  if (r == -1 && errno == ENOSYS)
+    {
+      long int args[] = { fd, level, optname, (long int) &optval,
+			  sizeof (optval) };
+      r = syscall (__NR_setsockopt, 14 /* SOCKOP_setsockopt  */ , args);
+    }
+#  endif
+  return r;
+}
+#endif
+
+bool
+support_socket_time64_timestamp (int fd)
+{
+#ifdef __linux__
+# if __LINUX_KERNEL_VERSION >= 0x050100                          \
+   || __WORDSIZE == 64                                           \
+   || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64)
+  return true;
+# else
+  int r = setsockopt_syscall (fd, 1);
+  if (r == -1 && errno == ENOPROTOOPT)
+    return false;
+  setsockopt_syscall (fd, 0);
+  return true;
+# endif
+#else
+  return false;
+#endif
+}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
                   ` (4 preceding siblings ...)
  2021-07-05 18:30 ` [PATCH 5/7] support: Add support_socket_time64_timestamp Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:30 ` Adhemerval Zanella via Libc-alpha
  2021-07-05 19:32   ` Florian Weimer via Libc-alpha
  2021-07-05 18:30 ` [PATCH 7/7] socket: Add recvmmsg " Adhemerval Zanella via Libc-alpha
  6 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

The test check if SO_TIMESTAMP and SO_TIMESTAMPNS is correctly
generated.  The recvmsg() is called with different ancilliary data
buffers, to check if the conversion for 64-bit time on 32-bit
legacy ABIs are handled correctly.

For such archicutures, depending of the remmaning ancially data
space the timestamp can not be appended and MSG_TRUNC is returned
instead.

Checked on x86_64-linux and on i686-linux-gnu on both 5.11 and
4.15 kernel.
---
 sysdeps/unix/sysv/linux/Makefile             |   3 +
 sysdeps/unix/sysv/linux/tst-recvmsg-time64.c |   1 +
 sysdeps/unix/sysv/linux/tst-recvmsg.c        | 171 +++++++++++++++++++
 3 files changed, 175 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmsg-time64.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmsg.c

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index faea02bd1b..be6fe08ac2 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -237,6 +237,9 @@ sysdep_routines += cmsg_nxthdr
 CFLAGS-recvmmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sendmmsg.c = -fexceptions -fasynchronous-unwind-tables
 
+tests += tst-recvmsg
+tests-time64 += tst-recvmsg-time64
+
 tests-special += $(objpfx)tst-socket-consts.out
 $(objpfx)tst-socket-consts.out: ../sysdeps/unix/sysv/linux/tst-socket-consts.py
 	PYTHONPATH=../scripts \
diff --git a/sysdeps/unix/sysv/linux/tst-recvmsg-time64.c b/sysdeps/unix/sysv/linux/tst-recvmsg-time64.c
new file mode 100644
index 0000000000..6cc8bbff6b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-recvmsg-time64.c
@@ -0,0 +1 @@
+#include "tst-recvmsg.c"
diff --git a/sysdeps/unix/sysv/linux/tst-recvmsg.c b/sysdeps/unix/sysv/linux/tst-recvmsg.c
new file mode 100644
index 0000000000..361dcbb8cc
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-recvmsg.c
@@ -0,0 +1,171 @@
+/* Check recvmsg timestamp support.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <array_length.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/xunistd.h>
+#include <support/xsocket.h>
+#include <sys/mman.h>
+
+/* Some extra space added for ancillary data, it might be used to convert
+   32-bit timestamp to 64-bit for _TIME_BITS=64 on older kernels.  */
+static const int slack[] = { 0, 4, 8, 16, 32, 64 };
+
+static size_t pagesize;
+
+static int
+do_test_send (const struct sockaddr_in *addr, int nmsgs)
+{
+  int s = xsocket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+  xconnect (s, (const struct sockaddr *) addr, sizeof (*addr));
+
+  for (int i = 0; i < nmsgs; i++)
+    xsendto (s, &i, sizeof (i), 0, (const struct sockaddr *) addr,
+	     sizeof (*addr));
+
+  return 0;
+}
+
+static void
+do_recvmsg (int s, bool support_64_timestamp, void *cmsg, size_t slack,
+	    size_t tsize, int exp_msg)
+{
+  /* A timestamp is expected if 32-bit timestamp are used (support in every
+     configuration) or if underlying kernel support 64-bit timestamps.
+     Otherwise recvmsg will need extra space do add the 64-bit timestamp.  */
+  bool exp_timestamp;
+  if (sizeof (time_t) == 4 || support_64_timestamp)
+    exp_timestamp = true;
+  else
+    exp_timestamp = slack >= CMSG_SPACE (tsize);
+
+  int msg;
+  struct iovec iov =
+    {
+      .iov_base = &msg,
+      .iov_len = sizeof (msg)
+    };
+  size_t msgs = CMSG_SPACE (tsize) + slack;
+  struct msghdr msghdr =
+    {
+      .msg_name = NULL,
+      .msg_namelen = 0,
+      .msg_iov = &iov,
+      .msg_iovlen = 1,
+      .msg_controllen = msgs,
+      .msg_control = cmsg != NULL ? cmsg + pagesize - msgs : NULL,
+    };
+  TEST_COMPARE (recvmsg (s, &msghdr, 0), sizeof (int));
+  TEST_COMPARE (msg, exp_msg);
+
+  if (cmsg == NULL)
+    return;
+
+  int timestamp = false;
+  for (struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msghdr);
+       cmsg != NULL;
+       cmsg = CMSG_NXTHDR (&msghdr, cmsg))
+    {
+      if (cmsg->cmsg_level != SOL_SOCKET)
+	continue;
+      if (cmsg->cmsg_type == SCM_TIMESTAMP
+	  && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timeval)))
+	{
+	  struct timeval tv;
+	  memcpy (&tv, CMSG_DATA (cmsg), sizeof (tv));
+	  printf ("SCM_TIMESTAMP:   {%jd, %jd}\n", (intmax_t)tv.tv_sec,
+		  (intmax_t)tv.tv_usec);
+	  timestamp = true;
+	}
+      else if (cmsg->cmsg_type == SCM_TIMESTAMPNS
+	       && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timespec)))
+	{
+	  struct timespec ts;
+	  memcpy (&ts, CMSG_DATA (cmsg), sizeof (ts));
+	  printf ("SCM_TIMESTAMPNS: {%jd, %jd}\n", (intmax_t)ts.tv_sec,
+		  (intmax_t)ts.tv_nsec);
+	  timestamp = true;
+	}
+    }
+
+  /* If there is not timestamp in the ancilliary data, recvmsg should set
+     the flag inidcating it.  */
+  if (exp_timestamp && !timestamp)
+    TEST_VERIFY (msghdr.msg_flags & MSG_TRUNC);
+  else
+    TEST_COMPARE (exp_timestamp, timestamp);
+}
+
+static int
+do_test (void)
+{
+  int srv = xsocket (AF_INET, SOCK_DGRAM, 0);
+  struct sockaddr_in srv_addr =
+    {
+      .sin_family = AF_INET,
+      .sin_addr = {.s_addr = htonl (INADDR_LOOPBACK) },
+    };
+  xbind (srv, (struct sockaddr *) &srv_addr, sizeof (srv_addr));
+  {
+    socklen_t sa_len = sizeof (srv_addr);
+    xgetsockname (srv, (struct sockaddr *) &srv_addr, &sa_len);
+    TEST_VERIFY (sa_len == sizeof (srv_addr));
+  }
+
+  TEST_COMPARE (recvmsg (-1, NULL, 0), -1);
+  TEST_COMPARE (errno, EBADF);
+
+  /* Setup the ancillary data buffer with an extra page with PROT_NONE to
+     check the possible timestamp conversion on some systems.  */
+  pagesize = sysconf (_SC_PAGESIZE);
+  if (pagesize == -1)
+    FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n");
+  void *msgbuf = xmmap (0, 2 * pagesize, PROT_NONE,
+		       	MAP_ANONYMOUS | MAP_PRIVATE, -1);
+  xmprotect (msgbuf, pagesize, PROT_READ | PROT_WRITE);
+
+  do_test_send (&srv_addr, 1);
+  do_recvmsg (srv, false, NULL, 0, 0, 0);
+
+  /* If underlying kernel does not support   */
+  bool support_64_timestamp = support_socket_time64_timestamp (srv);
+
+  /* Enable the timestamp using struct timeval precision.  */
+  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));
+  do_test_send (&srv_addr, array_length (slack));
+  for (int s = 0; s < array_length (slack); s++)
+    do_recvmsg (srv, support_64_timestamp, msgbuf, slack[s],
+		sizeof (struct timeval), s);
+
+  /* Now enable timestamp using a higher precision, it overwrites the previous
+     precision.  */
+  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS, &(int){1}, sizeof (int));
+  do_test_send (&srv_addr, array_length (slack));
+  for (int s = 0; s < array_length (slack); s++)
+    do_recvmsg (srv, support_64_timestamp, msgbuf, slack[s],
+		sizeof (struct timespec), s);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 7/7] socket: Add recvmmsg timestamp test
  2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
                   ` (5 preceding siblings ...)
  2021-07-05 18:30 ` [PATCH 6/7] socket: Add recvmsg timestamp test Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:30 ` Adhemerval Zanella via Libc-alpha
  2021-07-05 19:12   ` Florian Weimer via Libc-alpha
  6 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:30 UTC (permalink / raw
  To: libc-alpha

The test check if SO_TIMESTAMP and SO_TIMESTAMPNS is correctly
generated.  The recvmsg() is called with different ancilliary data
buffers, to check if the conversion for 64-bit time on 32-bit
legacy ABIs are handled correctly.

For such archicutures, depending of the remmaning ancially data
space the timestamp can not be appended and MSG_TRUNC is returned
instead.

Checked on x86_64-linux and on i686-linux-gnu on both 5.11 and
4.15 kernel.
---
 sysdeps/unix/sysv/linux/Makefile              |   4 +-
 sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c |   1 +
 sysdeps/unix/sysv/linux/tst-recvmmsg.c        | 185 ++++++++++++++++++
 3 files changed, 188 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-recvmmsg.c

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index be6fe08ac2..74a8d865b2 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -237,8 +237,8 @@ sysdep_routines += cmsg_nxthdr
 CFLAGS-recvmmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sendmmsg.c = -fexceptions -fasynchronous-unwind-tables
 
-tests += tst-recvmsg
-tests-time64 += tst-recvmsg-time64
+tests += tst-recvmsg tst-recvmmsg
+tests-time64 += tst-recvmsg-time64 tst-recvmmsg-time64
 
 tests-special += $(objpfx)tst-socket-consts.out
 $(objpfx)tst-socket-consts.out: ../sysdeps/unix/sysv/linux/tst-socket-consts.py
diff --git a/sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c b/sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c
new file mode 100644
index 0000000000..7b9b1bea03
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c
@@ -0,0 +1 @@
+#include "tst-recvmmsg.c"
diff --git a/sysdeps/unix/sysv/linux/tst-recvmmsg.c b/sysdeps/unix/sysv/linux/tst-recvmmsg.c
new file mode 100644
index 0000000000..012b364434
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-recvmmsg.c
@@ -0,0 +1,185 @@
+/* Check recvmmsg timestamp support.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <array_length.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/xunistd.h>
+#include <support/xsocket.h>
+#include <sys/mman.h>
+
+/* Some extra space added for ancillary data, it might be used to convert
+   32-bit timestamp to 64-bit for _TIME_BITS=64 on older kernels.  */
+static const int slack[] = { 0, 4, 8, 16, 32, 64 };
+
+static size_t pagesize;
+
+static int
+do_test_send (const struct sockaddr_in *addr, int nmsgs)
+{
+  int s = xsocket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+  xconnect (s, (const struct sockaddr *) addr, sizeof (*addr));
+
+  for (int i = 0; i < nmsgs; i++)
+    xsendto (s, &i, sizeof (i), 0, (const struct sockaddr *) addr,
+	     sizeof (*addr));
+
+  return 0;
+}
+
+#define NMSGS 5
+
+static void
+do_recvmmsg (int s, bool support_64_timestamp, void *cmsg[], size_t slack,
+	     size_t tsize)
+{
+  /* A timestamp is expected if 32-bit timestamp are used (support in every
+     configuration) or if underlying kernel support 64-bit timestamps.
+     Otherwise recvmsg will need extra space do add the 64-bit timestamp.  */
+  bool exp_timestamp;
+  if (sizeof (time_t) == 4 || support_64_timestamp)
+    exp_timestamp = true;
+  else
+    exp_timestamp = slack >= CMSG_SPACE (tsize);
+
+  int msg[5];
+  struct iovec iov[NMSGS];
+  for (int i = 0; i < NMSGS; i++)
+    {
+      iov[i].iov_base = &msg[i];
+      iov[i].iov_len = sizeof (msg[i]);
+    }
+  struct mmsghdr msghdr[NMSGS];
+  size_t msgs = CMSG_SPACE (tsize + slack);
+  for (int i = 0; i < NMSGS; i++)
+    {
+      msghdr[i].msg_hdr.msg_name = NULL;
+      msghdr[i].msg_hdr.msg_namelen = 0;
+      msghdr[i].msg_hdr.msg_iov = &iov[i];
+      msghdr[i].msg_hdr.msg_iovlen = 1;
+      msghdr[i].msg_hdr.msg_controllen = msgs,
+      msghdr[i].msg_hdr.msg_control = cmsg[i] != NULL
+				      ? cmsg[i] + pagesize - msgs : NULL;
+    }
+  
+  TEST_COMPARE (recvmmsg (s, msghdr, NMSGS, 0, NULL), NMSGS);
+  for (int i = 0; i < NMSGS; i++)
+    {
+      if (msghdr[i].msg_len == 0)
+	continue;
+
+      TEST_COMPARE (msg[i], i);
+
+      int timestamp = false;
+      for (struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msghdr[i].msg_hdr);
+	   cmsg != NULL;
+	   cmsg = CMSG_NXTHDR (&msghdr[i].msg_hdr, cmsg))
+	{
+	  if (cmsg->cmsg_level != SOL_SOCKET)
+	    continue;
+	  if (cmsg->cmsg_type == SCM_TIMESTAMP
+	      && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timeval)))
+	    {
+	      struct timeval tv;
+	      memcpy (&tv, CMSG_DATA (cmsg), sizeof (tv));
+	      printf ("SCM_TIMESTAMP:   {%jd, %jd}\n", (intmax_t)tv.tv_sec,
+		      (intmax_t)tv.tv_usec);
+	      timestamp = true;
+	    }
+	  else if (cmsg->cmsg_type == SCM_TIMESTAMPNS
+		   && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timespec)))
+	    {
+	      struct timespec ts;
+	      memcpy (&ts, CMSG_DATA (cmsg), sizeof (ts));
+	      printf ("SCM_TIMESTAMPNS: {%jd, %jd}\n", (intmax_t)ts.tv_sec,
+		      (intmax_t)ts.tv_nsec);
+	      timestamp = true;
+	    }
+	}
+
+      /* If there is not timestamp in the ancilliary data, recvmsg should set
+	 the flag inidcating it.  */
+      if (exp_timestamp && !timestamp)
+	TEST_VERIFY (msghdr[i].msg_hdr.msg_flags & MSG_TRUNC);
+      else
+	TEST_COMPARE (exp_timestamp, timestamp);
+    }
+}
+
+static int
+do_test (void)
+{
+  int srv = xsocket (AF_INET, SOCK_DGRAM, 0);
+  struct sockaddr_in srv_addr =
+    {
+      .sin_family = AF_INET,
+      .sin_addr = {.s_addr = htonl (INADDR_LOOPBACK) },
+    };
+  xbind (srv, (struct sockaddr *) &srv_addr, sizeof (srv_addr));
+  {
+    socklen_t sa_len = sizeof (srv_addr);
+    xgetsockname (srv, (struct sockaddr *) &srv_addr, &sa_len);
+    TEST_VERIFY (sa_len == sizeof (srv_addr));
+  }
+
+  TEST_COMPARE (recvmmsg (-1, NULL, 0, 0, NULL), -1);
+  TEST_COMPARE (errno, EBADF);
+
+  /* Setup the ancillary data buffer with an extra page with PROT_NONE to
+     check the possible timestamp conversion on some systems.  */
+  pagesize = sysconf (_SC_PAGESIZE);
+  if (pagesize == -1)
+    FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n");
+  void *msgbuf[NMSGS];
+  for (int i = 0; i < NMSGS; i++)
+    {
+      msgbuf[i] = xmmap (0, 2 * pagesize, PROT_NONE,
+			 MAP_ANONYMOUS | MAP_PRIVATE, -1);
+      xmprotect (msgbuf[i], pagesize, PROT_READ | PROT_WRITE);
+    }
+
+  /* If underlying kernel does not support   */
+  bool support_64_timestamp = support_socket_time64_timestamp (srv);
+
+  /* Enable the timestamp using struct timeval precision.  */
+  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));
+  for (int s = 0; s < array_length (slack); s++)
+    {
+      do_test_send (&srv_addr, NMSGS);
+      do_recvmmsg (srv, support_64_timestamp, msgbuf, slack[s],
+		   sizeof (struct timeval));
+    }
+
+  /* Now enable timestamp using a higher precision, it overwrites the previous
+     precision.  */
+  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS, &(int){1}, sizeof (int));
+  for (int s = 0; s < array_length (slack); s++)
+    {
+      do_test_send (&srv_addr, NMSGS);
+      do_recvmmsg (srv, support_64_timestamp, msgbuf, slack[s],
+		   sizeof (struct timespec));
+    }
+
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 5/7] support: Add support_socket_time64_timestamp
  2021-07-05 18:30 ` [PATCH 5/7] support: Add support_socket_time64_timestamp Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:46   ` Florian Weimer via Libc-alpha
  2021-07-05 18:51     ` Adhemerval Zanella via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 18:46 UTC (permalink / raw
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> Check if the socket support 64-bit network packages timestamps
> (SO_TIMESTAMP and SO_TIMESTAMPNS).  This will be used on recvmsg
> and recvmmsg tests to check if the timestamp should be generated.

Is it possible to probe with getsockopt instead?  Otherwise please
document that this function disables SO_TIMESTAMP.

> +      r = syscall (__NR_setsockopt, 14 /* SOCKOP_setsockopt  */ , args);

Should that be __NR_socketcall?

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 5/7] support: Add support_socket_time64_timestamp
  2021-07-05 18:46   ` Florian Weimer via Libc-alpha
@ 2021-07-05 18:51     ` Adhemerval Zanella via Libc-alpha
  0 siblings, 0 replies; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 18:51 UTC (permalink / raw
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 05/07/2021 15:46, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> Check if the socket support 64-bit network packages timestamps
>> (SO_TIMESTAMP and SO_TIMESTAMPNS).  This will be used on recvmsg
>> and recvmmsg tests to check if the timestamp should be generated.
> 
> Is it possible to probe with getsockopt instead?  Otherwise please
> document that this function disables SO_TIMESTAMP.

I think it would work.

> 
>> +      r = syscall (__NR_setsockopt, 14 /* SOCKOP_setsockopt  */ , args);
> 
> Should that be __NR_socketcall?

Indeed, I will send an updated version.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/7] linux: Consolidate Linux getsockopt implementation
  2021-07-05 18:30 ` [PATCH 1/7] linux: Consolidate Linux getsockopt implementation Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:58   ` Florian Weimer via Libc-alpha
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 18:58 UTC (permalink / raw
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> This patch consolidates the getsockopt Linux syscall implementation on
> sysdeps/unix/sysv/linux/getsockopt.c.  The changes are:
>
>   1. Remove it from auto-generation syscalls.list on all architectures.
>
>   2. Add __ASSUME_GETSOCKOPT_SYSCALL as default and undef if for
>      specific kernel versions on some architectures.
>
> This also fix a potential issue where 32-bit time_t ABI should use the
> linux getsockopt which overrides the underlying SO_* constants used for
> socket timestamping for _TIME_BITS=64.

Double-checked the changes for the generic and non-generic
architectures, and they look okay to me.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 2/7] linux: Consolidate Linux setsockopt implementation
  2021-07-05 18:30 ` [PATCH 2/7] linux: Consolidate Linux setsockopt implementation Adhemerval Zanella via Libc-alpha
@ 2021-07-05 18:59   ` Florian Weimer via Libc-alpha
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 18:59 UTC (permalink / raw
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> This patch consolidates the setsockopt implementation on
> sysdeps/unix/sysv/linux/getsockopt.c.  The changes are:
>
>   1. Remove it from auto-generation syscalls.list on all architectures.
>
>   2. Add __ASSUME_SETSOCKOPT_SYSCALL as default and undef if for
>      specific kernel versions on some architectures.
>
> This also fix a potential issue where 32-bit time_t ABI should use the
> linux setsockopt which overrides the underlying SO_* constants used for
> socket timestamping for _TIME_BITS=64.

Looks okay to me as well.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion
  2021-07-05 18:30 ` [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion Adhemerval Zanella via Libc-alpha
@ 2021-07-05 19:00   ` Florian Weimer via Libc-alpha
  2021-07-06 13:06     ` Adhemerval Zanella via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 19:00 UTC (permalink / raw
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> Kernel returns 32-bit values for COMPAT_SO_TIMESTAMP{NS}_OLD,
> no 64-bit ones.

“not 64-bit values”?

> diff --git a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
> index 5af71847f5..2db5750f50 100644
> --- a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
> +++ b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
> @@ -44,7 +44,8 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
>       'struct __kernel_sock_timeval' while for SO_TIMESTAMPNS_NEW is a
>       'struct __kernel_timespec'.  In either case it is two uint64_t
>       members.  */
> -  uint64_t tvts[2];
> +  int64_t tvts[2];
> +  int32_t tmp;
>  
>    struct cmsghdr *cmsg, *last = NULL;
>    int type = 0;
> @@ -69,7 +70,10 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
>  
>  	/* fallthrough  */
>  	common:
> -	  memcpy (tvts, CMSG_DATA (cmsg), sizeof (tvts));
> +	  memcpy (&tmp, CMSG_DATA (cmsg), sizeof (tmp));
> +	  tvts[0] = tmp;
> +	  memcpy (&tmp, CMSG_DATA (cmsg) + sizeof (tmp), sizeof (tmp));
> +	  tvts[1] = tmp;
>  	  break;

Maybe it's clearer to make tmp an array and use a single memcpy call?

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 4/7] linux: Fix setsockopt fallback
  2021-07-05 18:30 ` [PATCH 4/7] linux: Fix setsockopt fallback Adhemerval Zanella via Libc-alpha
@ 2021-07-05 19:07   ` Florian Weimer via Libc-alpha
  2021-07-06 13:07     ` Adhemerval Zanella via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 19:07 UTC (permalink / raw
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> The final 2 arguments for SO_TIMESTAMP/SO_TIMESTAMPNS are being set
> wrongly.
>
> Checked on x86_64-linux-gnu and i686-linux-gnu.
> ---
>  sysdeps/unix/sysv/linux/setsockopt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c
> index a4780a9d33..fae7305c9d 100644
> --- a/sysdeps/unix/sysv/linux/setsockopt.c
> +++ b/sysdeps/unix/sysv/linux/setsockopt.c
> @@ -78,7 +78,7 @@ setsockopt32 (int fd, int level, int optname, const void *optval,
>  	  optname = COMPAT_SO_TIMESTAMP_OLD;
>  	if (optname == COMPAT_SO_TIMESTAMPNS_NEW)
>  	  optname = COMPAT_SO_TIMESTAMPNS_OLD;
> -	r = setsockopt_syscall (fd, level, optname, NULL, 0);
> +	r = setsockopt_syscall (fd, level, optname, optval, len);
>        }
>        break;
>      }

Maybe add a comment that the recvmsg code does conversation, so the old
socket option is also acceptable?

The patch itself looks okay to me.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 7/7] socket: Add recvmmsg timestamp test
  2021-07-05 18:30 ` [PATCH 7/7] socket: Add recvmmsg " Adhemerval Zanella via Libc-alpha
@ 2021-07-05 19:12   ` Florian Weimer via Libc-alpha
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 19:12 UTC (permalink / raw
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> The test check if SO_TIMESTAMP and SO_TIMESTAMPNS is correctly
> generated.  The recvmsg() is called with different ancilliary data
> buffers, to check if the conversion for 64-bit time on 32-bit
> legacy ABIs are handled correctly.
>
> For such archicutures, depending of the remmaning ancially data
> space the timestamp can not be appended and MSG_TRUNC is returned
> instead.

I think you could have just one test source with a global flag that
switches between both tests.

struct msghdr can be nested in struct mmsghdr, so that the recvmsg and
recvmmsg paths are largely the same.  See my SCM_RIGHTS test.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-05 18:30 ` [PATCH 6/7] socket: Add recvmsg timestamp test Adhemerval Zanella via Libc-alpha
@ 2021-07-05 19:32   ` Florian Weimer via Libc-alpha
  2021-07-05 19:51     ` Adhemerval Zanella via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 19:32 UTC (permalink / raw
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> The test check if SO_TIMESTAMP and SO_TIMESTAMPNS is correctly
> generated.  The recvmsg() is called with different ancilliary data
> buffers, to check if the conversion for 64-bit time on 32-bit
> legacy ABIs are handled correctly.
>
> For such archicutures, depending of the remmaning ancially data

“architectures”, “remaining”

> space the timestamp can not be appended and MSG_TRUNC is returned
> instead.

“cannot”

> +static void
> +do_recvmsg (int s, bool support_64_timestamp, void *cmsg, size_t slack,
> +	    size_t tsize, int exp_msg)
> +{
> +  /* A timestamp is expected if 32-bit timestamp are used (support in every
> +     configuration) or if underlying kernel support 64-bit timestamps.

“if [the] underlying kernel support[s]”

> +     Otherwise recvmsg will need extra space do add the 64-bit timestamp.  */

“space [t]o add”

> +  /* If there is not timestamp in the ancilliary data, recvmsg should set

“no[] timestamp”

> +     the flag inidcating it.  */

“indicating”

> +  /* Setup the ancillary data buffer with an extra page with PROT_NONE to
> +     check the possible timestamp conversion on some systems.  */
> +  pagesize = sysconf (_SC_PAGESIZE);
> +  if (pagesize == -1)
> +    FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n");
> +  void *msgbuf = xmmap (0, 2 * pagesize, PROT_NONE,
> +		       	MAP_ANONYMOUS | MAP_PRIVATE, -1);
> +  xmprotect (msgbuf, pagesize, PROT_READ | PROT_WRITE);

Isn't this support_next_to_fault_allocate?

> +
> +  do_test_send (&srv_addr, 1);
> +  do_recvmsg (srv, false, NULL, 0, 0, 0);
> +
> +  /* If underlying kernel does not support   */
> +  bool support_64_timestamp = support_socket_time64_timestamp (srv);
> +
> +  /* Enable the timestamp using struct timeval precision.  */
> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));

Please use setsockopt here, nt the x wrapper, so that the ABI switches
with time64 support.

> +  do_test_send (&srv_addr, array_length (slack));
> +  for (int s = 0; s < array_length (slack); s++)
> +    do_recvmsg (srv, support_64_timestamp, msgbuf, slack[s],
> +		sizeof (struct timeval), s);
> +
> +  /* Now enable timestamp using a higher precision, it overwrites the previous
> +     precision.  */
> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS, &(int){1}, sizeof (int));

Likewise here.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-05 19:32   ` Florian Weimer via Libc-alpha
@ 2021-07-05 19:51     ` Adhemerval Zanella via Libc-alpha
  2021-07-05 20:02       ` Florian Weimer via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 19:51 UTC (permalink / raw
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 05/07/2021 16:32, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> The test check if SO_TIMESTAMP and SO_TIMESTAMPNS is correctly
>> generated.  The recvmsg() is called with different ancilliary data
>> buffers, to check if the conversion for 64-bit time on 32-bit
>> legacy ABIs are handled correctly.
>>
>> For such archicutures, depending of the remmaning ancially data
> 
> “architectures”, “remaining”
> 
>> space the timestamp can not be appended and MSG_TRUNC is returned
>> instead.
> 
> “cannot”
> 
>> +static void
>> +do_recvmsg (int s, bool support_64_timestamp, void *cmsg, size_t slack,
>> +	    size_t tsize, int exp_msg)
>> +{
>> +  /* A timestamp is expected if 32-bit timestamp are used (support in every
>> +     configuration) or if underlying kernel support 64-bit timestamps.
> 
> “if [the] underlying kernel support[s]”
> 
>> +     Otherwise recvmsg will need extra space do add the 64-bit timestamp.  */
> 
> “space [t]o add”
> 
>> +  /* If there is not timestamp in the ancilliary data, recvmsg should set
> 
> “no[] timestamp”
> 
>> +     the flag inidcating it.  */
> 
> “indicating”

Ack for the typos and semantic fixes.

> 
>> +  /* Setup the ancillary data buffer with an extra page with PROT_NONE to
>> +     check the possible timestamp conversion on some systems.  */
>> +  pagesize = sysconf (_SC_PAGESIZE);
>> +  if (pagesize == -1)
>> +    FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n");
>> +  void *msgbuf = xmmap (0, 2 * pagesize, PROT_NONE,
>> +		       	MAP_ANONYMOUS | MAP_PRIVATE, -1);
>> +  xmprotect (msgbuf, pagesize, PROT_READ | PROT_WRITE);
> 
> Isn't this support_next_to_fault_allocate?

It is, I will adjust.

> 
>> +
>> +  do_test_send (&srv_addr, 1);
>> +  do_recvmsg (srv, false, NULL, 0, 0, 0);
>> +
>> +  /* If underlying kernel does not support   */
>> +  bool support_64_timestamp = support_socket_time64_timestamp (srv);
>> +
>> +  /* Enable the timestamp using struct timeval precision.  */
>> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));
> 
> Please use setsockopt here, nt the x wrapper, so that the ABI switches
> with time64 support.

Currently it does not matter because SO_TIMESTAMP will be handled by
the kernel headers.

> 
>> +  do_test_send (&srv_addr, array_length (slack));
>> +  for (int s = 0; s < array_length (slack); s++)
>> +    do_recvmsg (srv, support_64_timestamp, msgbuf, slack[s],
>> +		sizeof (struct timeval), s);
>> +
>> +  /* Now enable timestamp using a higher precision, it overwrites the previous
>> +     precision.  */
>> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS, &(int){1}, sizeof (int));
> 
> Likewise here.
> 
> Thanks,
> Florian
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-05 19:51     ` Adhemerval Zanella via Libc-alpha
@ 2021-07-05 20:02       ` Florian Weimer via Libc-alpha
  2021-07-05 20:35         ` Adhemerval Zanella via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-05 20:02 UTC (permalink / raw
  To: Adhemerval Zanella; +Cc: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella:

>>> +  do_test_send (&srv_addr, 1);
>>> +  do_recvmsg (srv, false, NULL, 0, 0, 0);
>>> +
>>> +  /* If underlying kernel does not support   */
>>> +  bool support_64_timestamp = support_socket_time64_timestamp (srv);
>>> +
>>> +  /* Enable the timestamp using struct timeval precision.  */
>>> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));
>> 
>> Please use setsockopt here, nt the x wrapper, so that the ABI switches
>> with time64 support.
>
> Currently it does not matter because SO_TIMESTAMP will be handled by
> the kernel headers.

With my __setsockopt64 patch, the time64 version of the test will use a
different symbol.  This is what I meant.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-05 20:02       ` Florian Weimer via Libc-alpha
@ 2021-07-05 20:35         ` Adhemerval Zanella via Libc-alpha
  2021-07-06  9:29           ` Florian Weimer via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-05 20:35 UTC (permalink / raw
  To: Florian Weimer; +Cc: Adhemerval Zanella via Libc-alpha



On 05/07/2021 17:02, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>>>> +  do_test_send (&srv_addr, 1);
>>>> +  do_recvmsg (srv, false, NULL, 0, 0, 0);
>>>> +
>>>> +  /* If underlying kernel does not support   */
>>>> +  bool support_64_timestamp = support_socket_time64_timestamp (srv);
>>>> +
>>>> +  /* Enable the timestamp using struct timeval precision.  */
>>>> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));
>>>
>>> Please use setsockopt here, nt the x wrapper, so that the ABI switches
>>> with time64 support.
>>
>> Currently it does not matter because SO_TIMESTAMP will be handled by
>> the kernel headers.
> 
> With my __setsockopt64 patch, the time64 version of the test will use a
> different symbol.  This is what I meant.

Yeah, I am not really convinced we do need such newer symbols that do
not correlate to 64-bit time_t syscall since I think it is *highly* 
unlikely kernel will 64-bit time_t facilities for multiplexed syscall
(and I would consider this a bug) without any guards or checking
if the program is using 32-bit time_t.

Arnd, which would be kernel take in this regard? Will fcntl/ioctl/etc
exposes constants that might use 64-bit types if userland uses 32-bit
time_t?  For socket constants I see that kernel does take
case of define different SO_* values, but these are for facilities
that are present for old 32-bit syscalls as well.  

This would also require to use kernel types anyway, since the default
glibc provided ones will be 32-bit; and this won't be user-visible
(and not requiring any libc intervention). 

Florian, in any case *currently* this patch does not need to use
xsetsockopt.  I can adapt if your set get merged first.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-05 20:35         ` Adhemerval Zanella via Libc-alpha
@ 2021-07-06  9:29           ` Florian Weimer via Libc-alpha
  2021-07-06 12:55             ` Adhemerval Zanella via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-06  9:29 UTC (permalink / raw
  To: Adhemerval Zanella; +Cc: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella:

> On 05/07/2021 17:02, Florian Weimer wrote:
>> * Adhemerval Zanella:
>> 
>>>>> +  do_test_send (&srv_addr, 1);
>>>>> +  do_recvmsg (srv, false, NULL, 0, 0, 0);
>>>>> +
>>>>> +  /* If underlying kernel does not support   */
>>>>> +  bool support_64_timestamp = support_socket_time64_timestamp (srv);
>>>>> +
>>>>> +  /* Enable the timestamp using struct timeval precision.  */
>>>>> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));
>>>>
>>>> Please use setsockopt here, nt the x wrapper, so that the ABI switches
>>>> with time64 support.
>>>
>>> Currently it does not matter because SO_TIMESTAMP will be handled by
>>> the kernel headers.
>> 
>> With my __setsockopt64 patch, the time64 version of the test will use a
>> different symbol.  This is what I meant.
>
> Yeah, I am not really convinced we do need such newer symbols that do
> not correlate to 64-bit time_t syscall since I think it is *highly* 
> unlikely kernel will 64-bit time_t facilities for multiplexed syscall
> (and I would consider this a bug) without any guards or checking
> if the program is using 32-bit time_t.

What about SO_VM_SOCKETS_CONNECT_TIMEOUT? 

> Florian, in any case *currently* this patch does not need to use
> xsetsockopt.  I can adapt if your set get merged first.

Fine, go with xsetsockopt then.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-06  9:29           ` Florian Weimer via Libc-alpha
@ 2021-07-06 12:55             ` Adhemerval Zanella via Libc-alpha
  2021-07-06 14:50               ` Florian Weimer via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-06 12:55 UTC (permalink / raw
  To: Florian Weimer; +Cc: Adhemerval Zanella via Libc-alpha



On 06/07/2021 06:29, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> On 05/07/2021 17:02, Florian Weimer wrote:
>>> * Adhemerval Zanella:
>>>
>>>>>> +  do_test_send (&srv_addr, 1);
>>>>>> +  do_recvmsg (srv, false, NULL, 0, 0, 0);
>>>>>> +
>>>>>> +  /* If underlying kernel does not support   */
>>>>>> +  bool support_64_timestamp = support_socket_time64_timestamp (srv);
>>>>>> +
>>>>>> +  /* Enable the timestamp using struct timeval precision.  */
>>>>>> +  xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int));
>>>>>
>>>>> Please use setsockopt here, nt the x wrapper, so that the ABI switches
>>>>> with time64 support.
>>>>
>>>> Currently it does not matter because SO_TIMESTAMP will be handled by
>>>> the kernel headers.
>>>
>>> With my __setsockopt64 patch, the time64 version of the test will use a
>>> different symbol.  This is what I meant.
>>
>> Yeah, I am not really convinced we do need such newer symbols that do
>> not correlate to 64-bit time_t syscall since I think it is *highly* 
>> unlikely kernel will 64-bit time_t facilities for multiplexed syscall
>> (and I would consider this a bug) without any guards or checking
>> if the program is using 32-bit time_t.
> 
> What about SO_VM_SOCKETS_CONNECT_TIMEOUT? 

Should we paper over all drivers or kernel features that do not have
proper 64-bit support?  If so it would add a quite complex multiplex
handling on some syscall (ioctl).  I would expect we will have quite
a few drivers out there which miss proper 64-bit support.

I added support for SO_TIMESTAMP{NS} because it is a features that 
uses libc defined datatype and we include the kernel headers directly
(so user has no opt-out).  I consider most driver as opt-in, where
users usually have to explicit include linux headers and they should 
be aware that if we want to use _TIME_BITS=64 they would need care to
use libc-defined datatypes.

But this is also error prone (and I would consider that drivers using
libc-define datatypes are as well) and I see your point.  I would
prefer if we avoid extra 64-bit symbols, but if you think we would
improve support in the future we can add as a conservative way.

> 
>> Florian, in any case *currently* this patch does not need to use
>> xsetsockopt.  I can adapt if your set get merged first.
> 
> Fine, go with xsetsockopt then.
> 
> Thanks,
> Florian
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion
  2021-07-05 19:00   ` Florian Weimer via Libc-alpha
@ 2021-07-06 13:06     ` Adhemerval Zanella via Libc-alpha
  0 siblings, 0 replies; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-06 13:06 UTC (permalink / raw
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 05/07/2021 16:00, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> Kernel returns 32-bit values for COMPAT_SO_TIMESTAMP{NS}_OLD,
>> no 64-bit ones.
> 
> “not 64-bit values”?

Ack.

> 
>> diff --git a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
>> index 5af71847f5..2db5750f50 100644
>> --- a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
>> +++ b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
>> @@ -44,7 +44,8 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
>>       'struct __kernel_sock_timeval' while for SO_TIMESTAMPNS_NEW is a
>>       'struct __kernel_timespec'.  In either case it is two uint64_t
>>       members.  */
>> -  uint64_t tvts[2];
>> +  int64_t tvts[2];
>> +  int32_t tmp;
>>  
>>    struct cmsghdr *cmsg, *last = NULL;
>>    int type = 0;
>> @@ -69,7 +70,10 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
>>  
>>  	/* fallthrough  */
>>  	common:
>> -	  memcpy (tvts, CMSG_DATA (cmsg), sizeof (tvts));
>> +	  memcpy (&tmp, CMSG_DATA (cmsg), sizeof (tmp));
>> +	  tvts[0] = tmp;
>> +	  memcpy (&tmp, CMSG_DATA (cmsg) + sizeof (tmp), sizeof (tmp));
>> +	  tvts[1] = tmp;
>>  	  break;
> 
> Maybe it's clearer to make tmp an array and use a single memcpy call?

I agreed, I change it to your suggestion.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 4/7] linux: Fix setsockopt fallback
  2021-07-05 19:07   ` Florian Weimer via Libc-alpha
@ 2021-07-06 13:07     ` Adhemerval Zanella via Libc-alpha
  2021-07-06 14:08       ` Florian Weimer via Libc-alpha
  0 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella via Libc-alpha @ 2021-07-06 13:07 UTC (permalink / raw
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 05/07/2021 16:07, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> The final 2 arguments for SO_TIMESTAMP/SO_TIMESTAMPNS are being set
>> wrongly.
>>
>> Checked on x86_64-linux-gnu and i686-linux-gnu.
>> ---
>>  sysdeps/unix/sysv/linux/setsockopt.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c
>> index a4780a9d33..fae7305c9d 100644
>> --- a/sysdeps/unix/sysv/linux/setsockopt.c
>> +++ b/sysdeps/unix/sysv/linux/setsockopt.c
>> @@ -78,7 +78,7 @@ setsockopt32 (int fd, int level, int optname, const void *optval,
>>  	  optname = COMPAT_SO_TIMESTAMP_OLD;
>>  	if (optname == COMPAT_SO_TIMESTAMPNS_NEW)
>>  	  optname = COMPAT_SO_TIMESTAMPNS_OLD;
>> -	r = setsockopt_syscall (fd, level, optname, NULL, 0);
>> +	r = setsockopt_syscall (fd, level, optname, optval, len);
>>        }
>>        break;
>>      }
> 
> Maybe add a comment that the recvmsg code does conversation, so the old
> socket option is also acceptable?

I added the following comment:

  /* The expected type for the option is an 'int' for both
     types of timestamp formats, so there is no need to convert it.  */

> 
> The patch itself looks okay to me.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 4/7] linux: Fix setsockopt fallback
  2021-07-06 13:07     ` Adhemerval Zanella via Libc-alpha
@ 2021-07-06 14:08       ` Florian Weimer via Libc-alpha
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-06 14:08 UTC (permalink / raw
  To: Adhemerval Zanella; +Cc: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella:

> On 05/07/2021 16:07, Florian Weimer wrote:
>> * Adhemerval Zanella via Libc-alpha:
>> 
>>> The final 2 arguments for SO_TIMESTAMP/SO_TIMESTAMPNS are being set
>>> wrongly.
>>>
>>> Checked on x86_64-linux-gnu and i686-linux-gnu.
>>> ---
>>>  sysdeps/unix/sysv/linux/setsockopt.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c
>>> index a4780a9d33..fae7305c9d 100644
>>> --- a/sysdeps/unix/sysv/linux/setsockopt.c
>>> +++ b/sysdeps/unix/sysv/linux/setsockopt.c
>>> @@ -78,7 +78,7 @@ setsockopt32 (int fd, int level, int optname, const void *optval,
>>>  	  optname = COMPAT_SO_TIMESTAMP_OLD;
>>>  	if (optname == COMPAT_SO_TIMESTAMPNS_NEW)
>>>  	  optname = COMPAT_SO_TIMESTAMPNS_OLD;
>>> -	r = setsockopt_syscall (fd, level, optname, NULL, 0);
>>> +	r = setsockopt_syscall (fd, level, optname, optval, len);
>>>        }
>>>        break;
>>>      }
>> 
>> Maybe add a comment that the recvmsg code does conversation, so the old
>> socket option is also acceptable?
>
> I added the following comment:
>
>   /* The expected type for the option is an 'int' for both
>      types of timestamp formats, so there is no need to convert it.  */

And it's possible to request the old timestamp because of the
conversation in recvmsg/recvmmsg from the old to the new timestamp.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/7] socket: Add recvmsg timestamp test
  2021-07-06 12:55             ` Adhemerval Zanella via Libc-alpha
@ 2021-07-06 14:50               ` Florian Weimer via Libc-alpha
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer via Libc-alpha @ 2021-07-06 14:50 UTC (permalink / raw
  To: Adhemerval Zanella; +Cc: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella:

> But this is also error prone (and I would consider that drivers using
> libc-define datatypes are as well) and I see your point.  I would
> prefer if we avoid extra 64-bit symbols, but if you think we would
> improve support in the future we can add as a conservative way.

getsockopt/setsockopt is special because there is real length
information.  We don't have that for fcntl, and only sort-of for ioctl.
So the kernel at least has a chance of doing the right thing for
getsockopt/setsockopt.  And we don't need the time32-vs-time64
information in glibc for the present code because it's all encoded in
the option name.  So getsockopt/setsockopt is definitely a corner case.

For recvmsg, sendmsg, sendmmsg, I think we need the time64 alias so that
we can disable the rewriting if it turns out to be too disruptive.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2021-07-06 15:05 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-05 18:30 [PATCH 0/7] Linux 64-bit time_t socket fixes Adhemerval Zanella via Libc-alpha
2021-07-05 18:30 ` [PATCH 1/7] linux: Consolidate Linux getsockopt implementation Adhemerval Zanella via Libc-alpha
2021-07-05 18:58   ` Florian Weimer via Libc-alpha
2021-07-05 18:30 ` [PATCH 2/7] linux: Consolidate Linux setsockopt implementation Adhemerval Zanella via Libc-alpha
2021-07-05 18:59   ` Florian Weimer via Libc-alpha
2021-07-05 18:30 ` [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion Adhemerval Zanella via Libc-alpha
2021-07-05 19:00   ` Florian Weimer via Libc-alpha
2021-07-06 13:06     ` Adhemerval Zanella via Libc-alpha
2021-07-05 18:30 ` [PATCH 4/7] linux: Fix setsockopt fallback Adhemerval Zanella via Libc-alpha
2021-07-05 19:07   ` Florian Weimer via Libc-alpha
2021-07-06 13:07     ` Adhemerval Zanella via Libc-alpha
2021-07-06 14:08       ` Florian Weimer via Libc-alpha
2021-07-05 18:30 ` [PATCH 5/7] support: Add support_socket_time64_timestamp Adhemerval Zanella via Libc-alpha
2021-07-05 18:46   ` Florian Weimer via Libc-alpha
2021-07-05 18:51     ` Adhemerval Zanella via Libc-alpha
2021-07-05 18:30 ` [PATCH 6/7] socket: Add recvmsg timestamp test Adhemerval Zanella via Libc-alpha
2021-07-05 19:32   ` Florian Weimer via Libc-alpha
2021-07-05 19:51     ` Adhemerval Zanella via Libc-alpha
2021-07-05 20:02       ` Florian Weimer via Libc-alpha
2021-07-05 20:35         ` Adhemerval Zanella via Libc-alpha
2021-07-06  9:29           ` Florian Weimer via Libc-alpha
2021-07-06 12:55             ` Adhemerval Zanella via Libc-alpha
2021-07-06 14:50               ` Florian Weimer via Libc-alpha
2021-07-05 18:30 ` [PATCH 7/7] socket: Add recvmmsg " Adhemerval Zanella via Libc-alpha
2021-07-05 19:12   ` Florian Weimer via Libc-alpha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).