[v2,07/25] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}

Message ID 20210518205613.1487824-8-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Add 64 bit time support on legacy ABIs |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella May 18, 2021, 8:55 p.m. UTC
  Handle the SO_TIMESTAMP{NS} similar to recvmsg: for
!__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP
or SO_TIMESTAMPNS and appends it to the control buffer if has extra
space or returns MSG_CTRUNC otherwise.  The 32-bit time field is kept
as-is.

Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of
'struct mmsghdr *' to IOV_MAX (and also increases the stack size
requirement to IOV_MAX times sizeof (socklen_t)).  The Linux imposes
a similar limit to sendmmsg, so bound the array size on recvmmsg is not
unreasonable.  And this will be used only on older when building with
32-bit time support.

Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
kernel).
---
 sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
  

Comments

Lukasz Majewski May 19, 2021, 9:02 a.m. UTC | #1
On Tue, 18 May 2021 17:55:55 -0300
Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:

> Handle the SO_TIMESTAMP{NS} similar to recvmsg: for
> !__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time
> SO_TIMESTAMP or SO_TIMESTAMPNS and appends it to the control buffer
> if has extra space or returns MSG_CTRUNC otherwise.  The 32-bit time
> field is kept as-is.
> 
> Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of
> 'struct mmsghdr *' to IOV_MAX (and also increases the stack size
> requirement to IOV_MAX times sizeof (socklen_t)).  The Linux imposes
> a similar limit to sendmmsg, so bound the array size on recvmmsg is
> not unreasonable.  And this will be used only on older when building
> with 32-bit time support.
> 

Reviewed-by: Lukasz Majewski <lukma@denx.de>

> Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
> kernel).
> ---
>  sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c
> b/sysdeps/unix/sysv/linux/recvmmsg.c index 672ba20332..5cd107ffa9
> 100644 --- a/sysdeps/unix/sysv/linux/recvmmsg.c
> +++ b/sysdeps/unix/sysv/linux/recvmmsg.c
> @@ -44,13 +44,26 @@ __recvmmsg64 (int fd, struct mmsghdr *vmessages,
> unsigned int vlen, int flags, ts32 = valid_timespec64_to_timespec
> (*timeout); pts32 = &ts32;
>      }
> +
> +  socklen_t csize[IOV_MAX];
> +  if (vlen > IOV_MAX)
> +    vlen = IOV_MAX;
> +  for (int i = 0; i < vlen; i++)
> +    csize[i] = vmessages[i].msg_hdr.msg_controllen;
> +
>  # ifdef __ASSUME_RECVMMSG_SYSCALL
>    r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
>  # else
>    r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags,
> pts32); # endif
> -  if (r >= 0 && timeout != NULL)
> -    *timeout = valid_timespec_to_timespec64 (ts32);
> +  if (r >= 0)
> +    {
> +      if (timeout != NULL)
> +        *timeout = valid_timespec_to_timespec64 (ts32);
> +
> +      for (int i=0; i < r; i++)
> +        __convert_scm_timestamps (&vmessages[i].msg_hdr, csize[i]);
> +    }
>  #endif /* __ASSUME_TIME64_SYSCALLS  */
>    return r;
>  }



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
  
Carlos O'Donell June 4, 2021, 7:30 p.m. UTC | #2
On 5/18/21 4:55 PM, Adhemerval Zanella wrote:
> Handle the SO_TIMESTAMP{NS} similar to recvmsg: for
> !__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP
> or SO_TIMESTAMPNS and appends it to the control buffer if has extra
> space or returns MSG_CTRUNC otherwise.  The 32-bit time field is kept
> as-is.
> 
> Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of
> 'struct mmsghdr *' to IOV_MAX (and also increases the stack size
> requirement to IOV_MAX times sizeof (socklen_t)).  The Linux imposes
> a similar limit to sendmmsg, so bound the array size on recvmmsg is not
> unreasonable.  And this will be used only on older when building with
> 32-bit time support.
> 
> Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
> kernel).

LGTM.

No regressions on x86_64, i686, ppc64le, aarch64, s390x.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c
> index 672ba20332..5cd107ffa9 100644
> --- a/sysdeps/unix/sysv/linux/recvmmsg.c
> +++ b/sysdeps/unix/sysv/linux/recvmmsg.c
> @@ -44,13 +44,26 @@ __recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
>        ts32 = valid_timespec64_to_timespec (*timeout);
>        pts32 = &ts32;
>      }
> +
> +  socklen_t csize[IOV_MAX];
> +  if (vlen > IOV_MAX)
> +    vlen = IOV_MAX;
> +  for (int i = 0; i < vlen; i++)
> +    csize[i] = vmessages[i].msg_hdr.msg_controllen;
> +
>  # ifdef __ASSUME_RECVMMSG_SYSCALL
>    r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
>  # else
>    r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
>  # endif
> -  if (r >= 0 && timeout != NULL)
> -    *timeout = valid_timespec_to_timespec64 (ts32);
> +  if (r >= 0)
> +    {
> +      if (timeout != NULL)
> +        *timeout = valid_timespec_to_timespec64 (ts32);
> +
> +      for (int i=0; i < r; i++)
> +        __convert_scm_timestamps (&vmessages[i].msg_hdr, csize[i]);

OK. Use existing __convert_scm_timestamps (908d356af09284fbfedd25da3deb6af8898947e8).

> +    }
>  #endif /* __ASSUME_TIME64_SYSCALLS  */
>    return r;
>  }
>
  

Patch

diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c
index 672ba20332..5cd107ffa9 100644
--- a/sysdeps/unix/sysv/linux/recvmmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmmsg.c
@@ -44,13 +44,26 @@  __recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
       ts32 = valid_timespec64_to_timespec (*timeout);
       pts32 = &ts32;
     }
+
+  socklen_t csize[IOV_MAX];
+  if (vlen > IOV_MAX)
+    vlen = IOV_MAX;
+  for (int i = 0; i < vlen; i++)
+    csize[i] = vmessages[i].msg_hdr.msg_controllen;
+
 # ifdef __ASSUME_RECVMMSG_SYSCALL
   r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
 # else
   r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
 # endif
-  if (r >= 0 && timeout != NULL)
-    *timeout = valid_timespec_to_timespec64 (ts32);
+  if (r >= 0)
+    {
+      if (timeout != NULL)
+        *timeout = valid_timespec_to_timespec64 (ts32);
+
+      for (int i=0; i < r; i++)
+        __convert_scm_timestamps (&vmessages[i].msg_hdr, csize[i]);
+    }
 #endif /* __ASSUME_TIME64_SYSCALLS  */
   return r;
 }